Skip to content
Snippets Groups Projects

De/Serialization for wavefront object files

Merged Ludwig Jaeck requested to merge serialization into main
All threads resolved!
@@ -2,7 +2,7 @@
//
// BornAgain: simulate and fit reflection and scattering
//
//! @file ff/WavefronSerializer.cpp
//! @file ff/WavefrontSerializer.cpp
//! @brief Implements serialization and deserialization for polyhedra.
//!
//! @homepage https://jugit.fz-juelich.de/mlz/libformfactor
@@ -16,23 +16,21 @@
#include <fstream>
#include <iomanip>
#include <iostream>
namespace {
std::ostream& serialize_as_wavefront(std::ostream& out, const ff::Polyhedron* polyhedron)
{
out << std::setprecision(10);
out << "o 1"
<< "\n";
out << "o 1 \n";
for (auto vertice : polyhedron->vertices())
out << "v"
<< " " << vertice.x() << " " << vertice.y() << " " << vertice.z() << "\n";
out << "v " << vertice.x() << " " << vertice.y() << " " << vertice.z() << "\n";
out << "usemtl Default\n";
for (auto& poly : polyhedron->topology().faces) {
if (poly.vertexIndices.size() == 0)
continue;
out << "f"
<< " ";
out << "f ";
for (size_t i = 0; i < poly.vertexIndices.size(); i++) {
out << poly.vertexIndices[i] + 1;
out << (i == poly.vertexIndices.size() - 1 ? "\n" : " ");
@@ -40,6 +38,7 @@ std::ostream& serialize_as_wavefront(std::ostream& out, const ff::Polyhedron* po
}
return out;
}
std::istream& deserialize_from_wavefront(std::istream& is, ff::Polyhedron*& polyhedron)
{
std::vector<R3> vertices;
Loading