diff --git a/src/OpenMesh/Core/IO/Options.hh b/src/OpenMesh/Core/IO/Options.hh index f2667258..a703273c 100644 --- a/src/OpenMesh/Core/IO/Options.hh +++ b/src/OpenMesh/Core/IO/Options.hh @@ -115,7 +115,8 @@ public: FaceTexCoord = 0x0400, ///< Has (r) / store (w) face texture coordinates ColorAlpha = 0x0800, ///< Has (r) / store (w) alpha values for colors ColorFloat = 0x1000, ///< Has (r) / store (w) float values for colors (currently only implemented for PLY and OFF files) - Custom = 0x2000 ///< Has (r) custom properties (currently only implemented in PLY Reader ASCII version) + Custom = 0x2000, ///< Has (r) custom properties (currently only implemented in PLY Reader ASCII version) + Status = 0x4000 ///< Has (r) / store (w) status properties }; public: @@ -206,10 +207,14 @@ public: bool vertex_has_normal() const { return check(VertexNormal); } bool vertex_has_color() const { return check(VertexColor); } bool vertex_has_texcoord() const { return check(VertexTexCoord); } + bool vertex_has_status() const { return check(Status); } bool edge_has_color() const { return check(EdgeColor); } + bool edge_has_status() const { return check(Status); } + bool halfedge_has_status() const { return check(Status); } bool face_has_normal() const { return check(FaceNormal); } bool face_has_color() const { return check(FaceColor); } bool face_has_texcoord() const { return check(FaceTexCoord); } + bool face_has_status() const { return check(Status); } bool color_has_alpha() const { return check(ColorAlpha); } bool color_is_float() const { return check(ColorFloat); } diff --git a/src/OpenMesh/Core/IO/exporter/BaseExporter.hh b/src/OpenMesh/Core/IO/exporter/BaseExporter.hh index 39de363f..2c93e19c 100644 --- a/src/OpenMesh/Core/IO/exporter/BaseExporter.hh +++ b/src/OpenMesh/Core/IO/exporter/BaseExporter.hh @@ -158,10 +158,14 @@ public: virtual bool is_triangle_mesh() const { return false; } virtual bool has_vertex_normals() const { return false; } virtual bool has_vertex_colors() const { return false; } + virtual bool has_vertex_status() const { return false; } virtual bool has_vertex_texcoords() const { return false; } virtual bool has_edge_colors() const { return false; } + virtual bool has_edge_status() const { return false; } + virtual bool has_halfedge_status() const { return false; } virtual bool has_face_normals() const { return false; } virtual bool has_face_colors() const { return false; } + virtual bool has_face_status() const { return false; } }; diff --git a/src/OpenMesh/Core/IO/exporter/ExporterT.hh b/src/OpenMesh/Core/IO/exporter/ExporterT.hh index 15c6defe..0ea30e6e 100644 --- a/src/OpenMesh/Core/IO/exporter/ExporterT.hh +++ b/src/OpenMesh/Core/IO/exporter/ExporterT.hh @@ -345,9 +345,13 @@ public: bool has_vertex_normals() const { return mesh_.has_vertex_normals(); } bool has_vertex_colors() const { return mesh_.has_vertex_colors(); } bool has_vertex_texcoords() const { return mesh_.has_vertex_texcoords2D(); } + bool has_vertex_status() const { return mesh_.has_vertex_status(); } bool has_edge_colors() const { return mesh_.has_edge_colors(); } + bool has_edge_status() const { return mesh_.has_edge_status(); } + bool has_halfedge_status() const { return mesh_.has_halfedge_status(); } bool has_face_normals() const { return mesh_.has_face_normals(); } bool has_face_colors() const { return mesh_.has_face_colors(); } + bool has_face_status() const { return mesh_.has_face_status(); } private: diff --git a/src/OpenMesh/Core/IO/writer/OMWriter.cc b/src/OpenMesh/Core/IO/writer/OMWriter.cc index b48cd0d2..cc12d73d 100644 --- a/src/OpenMesh/Core/IO/writer/OMWriter.cc +++ b/src/OpenMesh/Core/IO/writer/OMWriter.cc @@ -417,6 +417,58 @@ bool _OMWriter_::write_binary(std::ostream& _os, BaseExporter& _be, #endif } + // ---------- write vertex status + if (_be.n_vertices() && _be.has_vertex_status() && _opt.check(Options::Status)) + { + //store status as costum property because that already works + auto prop = _be.kernel()->_get_vprop("v:status"); + assert(prop != nullptr); + bool persistent = prop->persistent(); + const_cast(prop)->set_persistent(true); + bytes += store_binary_custom_chunk(_os, *prop, + OMFormat::Chunk::Entity_Vertex, swap ); + const_cast(prop)->set_persistent(persistent); + } + + // ---------- write edge status + if (_be.n_edges() && _be.has_edge_status() && _opt.check(Options::Status)) + { + //store status as costum property because that already works + auto prop = _be.kernel()->_get_eprop("e:status"); + assert(prop != nullptr); + bool persistent = prop->persistent(); + const_cast(prop)->set_persistent(true); + bytes += store_binary_custom_chunk(_os, *prop, + OMFormat::Chunk::Entity_Edge, swap ); + const_cast(prop)->set_persistent(persistent); + } + + // ---------- write halfedge status + if (_be.n_edges() && _be.has_halfedge_status() && _opt.check(Options::Status)) + { + //store status as costum property because that already works + auto prop = _be.kernel()->_get_hprop("h:status"); + assert(prop != nullptr); + bool persistent = prop->persistent(); + const_cast(prop)->set_persistent(true); + bytes += store_binary_custom_chunk(_os, *prop, + OMFormat::Chunk::Entity_Halfedge, swap ); + const_cast(prop)->set_persistent(persistent); + } + + // ---------- write face status + if (_be.n_faces() && _be.has_face_status() && _opt.check(Options::Status)) + { + //store status as costum property because that already works + auto prop = _be.kernel()->_get_fprop("f:status"); + assert(prop != nullptr); + bool persistent = prop->persistent(); + const_cast(prop)->set_persistent(true); + bytes += store_binary_custom_chunk(_os, *prop, + OMFormat::Chunk::Entity_Face, swap ); + const_cast(prop)->set_persistent(persistent); + } + // -------------------- write custom properties @@ -426,7 +478,7 @@ bool _OMWriter_::write_binary(std::ostream& _os, BaseExporter& _be, prop != _be.kernel()->vprops_end(); ++prop) { if ( !*prop ) continue; - if ( ((*prop)->name()[1]==':') && ((*prop)->name() != "v:status")) continue; + if ( (*prop)->name()[1]==':') continue; bytes += store_binary_custom_chunk(_os, **prop, OMFormat::Chunk::Entity_Vertex, swap ); } @@ -434,7 +486,7 @@ bool _OMWriter_::write_binary(std::ostream& _os, BaseExporter& _be, prop != _be.kernel()->fprops_end(); ++prop) { if ( !*prop ) continue; - if ( ((*prop)->name()[1]==':') && ((*prop)->name() != "f:status")) continue; + if ( (*prop)->name()[1]==':') continue; bytes += store_binary_custom_chunk(_os, **prop, OMFormat::Chunk::Entity_Face, swap ); } @@ -442,7 +494,7 @@ bool _OMWriter_::write_binary(std::ostream& _os, BaseExporter& _be, prop != _be.kernel()->eprops_end(); ++prop) { if ( !*prop ) continue; - if ( ((*prop)->name()[1]==':') && ((*prop)->name() != "e:status")) continue; + if ( (*prop)->name()[1]==':') continue; bytes += store_binary_custom_chunk(_os, **prop, OMFormat::Chunk::Entity_Edge, swap ); } @@ -450,7 +502,7 @@ bool _OMWriter_::write_binary(std::ostream& _os, BaseExporter& _be, prop != _be.kernel()->hprops_end(); ++prop) { if ( !*prop ) continue; - if ( ((*prop)->name()[1]==':') && ((*prop)->name() != "h:status")) continue; + if ( (*prop)->name()[1]==':') continue; bytes += store_binary_custom_chunk(_os, **prop, OMFormat::Chunk::Entity_Halfedge, swap ); } diff --git a/src/Unittests/unittests_read_write_OM.cc b/src/Unittests/unittests_read_write_OM.cc index 336be479..899e86e5 100644 --- a/src/Unittests/unittests_read_write_OM.cc +++ b/src/Unittests/unittests_read_write_OM.cc @@ -723,8 +723,8 @@ TEST_F(OpenMeshReadWriteOM, WriteSplitTriangleStatusProperties) { } // save - OpenMesh::IO::Options options; - bool ok = OpenMesh::IO::write_mesh(mesh,filename); + OpenMesh::IO::Options options = OpenMesh::IO::Options::Status; + bool ok = OpenMesh::IO::write_mesh(mesh,filename, options); EXPECT_TRUE(ok) << "Unable to write "<