From de2aae1e7d865fb639044767daef5d9584977a69 Mon Sep 17 00:00:00 2001 From: panquez Date: Tue, 27 Sep 2022 17:13:47 +0200 Subject: [PATCH 1/4] fix(Convert): add attribute on mesh storing input model unique vertices --- include/geode/model/helpers/convert_to_mesh.h | 3 + src/geode/model/helpers/convert_to_mesh.cpp | 102 +++++++++++++----- 2 files changed, 81 insertions(+), 24 deletions(-) diff --git a/include/geode/model/helpers/convert_to_mesh.h b/include/geode/model/helpers/convert_to_mesh.h index ef18fb1c9..2575067de 100644 --- a/include/geode/model/helpers/convert_to_mesh.h +++ b/include/geode/model/helpers/convert_to_mesh.h @@ -45,6 +45,9 @@ namespace geode static constexpr auto uuid_from_conversion_attribute_name = "uuid_from_conversion"; using uuid_from_conversion_attribute_type = uuid; + static constexpr auto unique_vertex_from_conversion_attribute_name = + "unique_vertex_from_conversion"; + using unique_vertex_from_conversion_attribute_type = index_t; std::unique_ptr< EdgedCurve2D > opengeode_model_api convert_section_into_curve( const Section& section ); diff --git a/src/geode/model/helpers/convert_to_mesh.cpp b/src/geode/model/helpers/convert_to_mesh.cpp index 3bb8ef4c9..d2780daa7 100644 --- a/src/geode/model/helpers/convert_to_mesh.cpp +++ b/src/geode/model/helpers/convert_to_mesh.cpp @@ -88,6 +88,12 @@ namespace return points; } + const absl::flat_hash_map< geode::index_t, geode::index_t >& + vertices() const + { + return vertices_; + } + private: const Model& model_; absl::flat_hash_map< geode::index_t, geode::index_t > vertices_; @@ -135,6 +141,10 @@ namespace const auto polyhedra = build_polyhedra( block ); set_polyhedra_adjacency( block, polyhedra ); } + for( const auto& v2uv : model_.vertices() ) + { + attribute_unique_vertex_->set_value( v2uv.first, v2uv.second ); + } } std::unique_ptr< SolidType > get_result() @@ -147,12 +157,21 @@ namespace : model_( model ), mesh_{ SolidType::create() }, builder_{ geode::SolidMeshBuilder3D::create( *mesh_ ) }, - attribute_{ mesh_->polyhedron_attribute_manager() - .template find_or_create_attribute< - geode::VariableAttribute, - geode::uuid_from_conversion_attribute_type >( - geode::uuid_from_conversion_attribute_name, - {} ) } + attribute_uuid_{ + mesh_->polyhedron_attribute_manager() + .template find_or_create_attribute< + geode::VariableAttribute, + geode::uuid_from_conversion_attribute_type >( + geode::uuid_from_conversion_attribute_name, {} ) + }, + attribute_unique_vertex_{ + mesh_->vertex_attribute_manager() + .template find_or_create_attribute< + geode::VariableAttribute, + geode::unique_vertex_from_conversion_attribute_type >( + geode::unique_vertex_from_conversion_attribute_name, + geode::NO_ID ) + } { } @@ -219,7 +238,7 @@ namespace } polyhedra[p] = builder_->create_polyhedron( polyhedron_vertices, polyhedron_facet_vertices ); - attribute_->set_value( polyhedra[p], block.id() ); + attribute_uuid_->set_value( polyhedra[p], block.id() ); } return polyhedra; } @@ -230,7 +249,10 @@ namespace std::unique_ptr< geode::SolidMeshBuilder3D > builder_; std::shared_ptr< geode::VariableAttribute< geode::uuid_from_conversion_attribute_type > > - attribute_; + attribute_uuid_; + std::shared_ptr< geode::VariableAttribute< + geode::unique_vertex_from_conversion_attribute_type > > + attribute_unique_vertex_; }; template < typename SurfaceType, typename Model, geode::index_t dimension > @@ -242,12 +264,21 @@ namespace mesh_{ SurfaceType::create() }, builder_{ geode::SurfaceMeshBuilder< dimension >::create( *mesh_ ) }, - attribute_{ mesh_->polygon_attribute_manager() - .template find_or_create_attribute< - geode::VariableAttribute, - geode::uuid_from_conversion_attribute_type >( - geode::uuid_from_conversion_attribute_name, - {} ) } + attribute_uuid_{ + mesh_->polygon_attribute_manager() + .template find_or_create_attribute< + geode::VariableAttribute, + geode::uuid_from_conversion_attribute_type >( + geode::uuid_from_conversion_attribute_name, {} ) + }, + attribute_unique_vertex_{ + mesh_->vertex_attribute_manager() + .template find_or_create_attribute< + geode::VariableAttribute, + geode::unique_vertex_from_conversion_attribute_type >( + geode::unique_vertex_from_conversion_attribute_name, + geode::NO_ID ) + } { } @@ -268,6 +299,10 @@ namespace const auto polygons = build_polygons( surface ); set_polygons_adjacency( surface, polygons ); } + for( const auto& v2uv : model_.vertices() ) + { + attribute_unique_vertex_->set_value( v2uv.first, v2uv.second ); + } } std::unique_ptr< SurfaceType > get_result() @@ -320,7 +355,7 @@ namespace } } polygons[p] = builder_->create_polygon( polygon ); - attribute_->set_value( polygons[p], surface.id() ); + attribute_uuid_->set_value( polygons[p], surface.id() ); } return polygons; } @@ -331,7 +366,10 @@ namespace std::unique_ptr< geode::SurfaceMeshBuilder< dimension > > builder_; std::shared_ptr< geode::VariableAttribute< geode::uuid_from_conversion_attribute_type > > - attribute_; + attribute_uuid_; + std::shared_ptr< geode::VariableAttribute< + geode::unique_vertex_from_conversion_attribute_type > > + attribute_unique_vertex_; }; template < typename SurfaceType > @@ -349,12 +387,21 @@ namespace mesh_{ geode::EdgedCurve< dimension >::create() }, builder_{ geode::EdgedCurveBuilder< dimension >::create( *mesh_ ) }, - attribute_{ mesh_->edge_attribute_manager() - .template find_or_create_attribute< - geode::VariableAttribute, - geode::uuid_from_conversion_attribute_type >( - geode::uuid_from_conversion_attribute_name, - {} ) } + attribute_uuid_{ + mesh_->edge_attribute_manager() + .template find_or_create_attribute< + geode::VariableAttribute, + geode::uuid_from_conversion_attribute_type >( + geode::uuid_from_conversion_attribute_name, {} ) + }, + attribute_unique_vertex_{ + mesh_->vertex_attribute_manager() + .template find_or_create_attribute< + geode::VariableAttribute, + geode::unique_vertex_from_conversion_attribute_type >( + geode::unique_vertex_from_conversion_attribute_name, + geode::NO_ID ) + } { } @@ -364,6 +411,10 @@ namespace { build_edges( line ); } + for( const auto& v2uv : model_.vertices() ) + { + attribute_unique_vertex_->set_value( v2uv.first, v2uv.second ); + } } std::unique_ptr< geode::EdgedCurve< dimension > > get_result() @@ -395,7 +446,7 @@ namespace } const auto edge = builder_->create_edge( vertices[0], vertices[1] ); - attribute_->set_value( edge, line.id() ); + attribute_uuid_->set_value( edge, line.id() ); } } @@ -405,7 +456,10 @@ namespace std::unique_ptr< geode::EdgedCurveBuilder< dimension > > builder_; std::shared_ptr< geode::VariableAttribute< geode::uuid_from_conversion_attribute_type > > - attribute_; + attribute_uuid_; + std::shared_ptr< geode::VariableAttribute< + geode::unique_vertex_from_conversion_attribute_type > > + attribute_unique_vertex_; }; using CurveFromBRep = CurveFromModel< geode::BRep, 3 >; From d94ef1400d2a3f47b27b8d85003d800e95580908 Mon Sep 17 00:00:00 2001 From: panquez Date: Wed, 28 Sep 2022 11:45:41 +0200 Subject: [PATCH 2/4] fix test --- src/geode/model/helpers/convert_to_mesh.cpp | 11 ++++++++++- tests/data/quad.og_sctn | Bin 1829 -> 2287 bytes tests/model/test-convert-to-mesh.cpp | 6 +++--- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/geode/model/helpers/convert_to_mesh.cpp b/src/geode/model/helpers/convert_to_mesh.cpp index d2780daa7..44606b944 100644 --- a/src/geode/model/helpers/convert_to_mesh.cpp +++ b/src/geode/model/helpers/convert_to_mesh.cpp @@ -26,6 +26,7 @@ #include #include +#include #include @@ -51,7 +52,12 @@ namespace class FromModel { public: - FromModel( const Model& model ) : model_( model ) {} + FromModel( const Model& model ) : model_( model ) + { + OPENGEODE_EXCEPTION( model.nb_unique_vertices() > 0, + "[Convert Model to Mesh(es)] Given model should have unique " + "vertices" ); + } const Model& model() const { @@ -71,6 +77,9 @@ namespace geode::index_t create_vertex( geode::index_t vertex_id ) { + OPENGEODE_EXCEPTION( vertex_id != geode::NO_ID, + "[Convert Model to Mesh(es)] At least one Component Mesh " + "Vertex is not link to a unique vertex" ); const geode::index_t new_id = vertices_.size(); vertices_.emplace( vertex_id, new_id ); return new_id; diff --git a/tests/data/quad.og_sctn b/tests/data/quad.og_sctn index 94d2156c69c713aecb7c71fff33e2c39cc1f3c19..d5721e27b9ba696d4290c68d288df3a69b7c702a 100644 GIT binary patch literal 2287 zcmb7F&rj4q6rSmJe}IBU@kas@f(K*F;${Qr%>XJO8kT4X2V*VU0jgzM+OCQoTs#{8 z1CRO_paRLrNN;BEq_}iyF0HBvzF4vmLh zS$L`A^SW#5iR*+f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`4c@i`JfQgW)LiKwk4U^h^{)&q?T)PQt;*N-XG>T)gOISoUj6fuuB`F0p+xc?i zU;__u{2g{4PPf6Yp4Y(_28|3_-hbe0fbT*5OaxJ*VU9a&xou$ra~YETJzN#t)NLO} zm0tw5v|JGN4VEg4s=qZ))!?cY%9P{F$^|XFhujraCf`{VTBhcBNY~*_7Zp-Pm6<`> s#s>ERrARypgrto@KLJ#w@FX-+Hb&oqzmh<=U901^4Zjai{hLzn57#lX8~^|S diff --git a/tests/model/test-convert-to-mesh.cpp b/tests/model/test-convert-to-mesh.cpp index 21ece2da2..ba99a95da 100644 --- a/tests/model/test-convert-to-mesh.cpp +++ b/tests/model/test-convert-to-mesh.cpp @@ -40,7 +40,7 @@ void run_test_brep() { - auto model = + const auto model = geode::load_brep( absl::StrCat( geode::data_path, "layers.og_brep" ) ); const auto output = @@ -66,7 +66,7 @@ void run_test_brep() void run_test_section() { - auto model = + const auto model = geode::load_section( absl::StrCat( geode::data_path, "quad.og_sctn" ) ); const auto output = geode::convert_section_into_curve_and_surface( model ); @@ -77,7 +77,7 @@ void run_test_section() "[Test] Section - Wrong number of curve edges" ); const auto& surface = std::get< 1 >( output ); - OPENGEODE_EXCEPTION( surface->nb_vertices() == 1, + OPENGEODE_EXCEPTION( surface->nb_vertices() == 4, "[Test] Section - Wrong number of surface vertices" ); OPENGEODE_EXCEPTION( surface->nb_polygons() == 1, "[Test] Section - Wrong number of surface polygons" ); From aa78d8dc4e5955b1a5ef0084aa3a05cce133ac79 Mon Sep 17 00:00:00 2001 From: panquez Date: Wed, 28 Sep 2022 11:46:25 +0200 Subject: [PATCH 3/4] clean --- src/geode/model/helpers/convert_to_mesh.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/geode/model/helpers/convert_to_mesh.cpp b/src/geode/model/helpers/convert_to_mesh.cpp index 44606b944..7f2ac1708 100644 --- a/src/geode/model/helpers/convert_to_mesh.cpp +++ b/src/geode/model/helpers/convert_to_mesh.cpp @@ -26,7 +26,6 @@ #include #include -#include #include From 1a731266c187eb2172a649cae292875d1d300a39 Mon Sep 17 00:00:00 2001 From: panquez Date: Wed, 28 Sep 2022 13:13:51 +0200 Subject: [PATCH 4/4] fix test python --- bindings/python/tests/model/test-py-convert-to-mesh.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bindings/python/tests/model/test-py-convert-to-mesh.py b/bindings/python/tests/model/test-py-convert-to-mesh.py index 6f71dbe00..fae249631 100644 --- a/bindings/python/tests/model/test-py-convert-to-mesh.py +++ b/bindings/python/tests/model/test-py-convert-to-mesh.py @@ -67,7 +67,7 @@ def run_test_section(): if curve.nb_edges() != 0: raise ValueError("[Test] Section - Wrong number of curve edges") - if surface.nb_vertices() != 1: + if surface.nb_vertices() != 4: raise ValueError("[Test] Section - Wrong number of surface vertices") if surface.nb_polygons() != 1: raise ValueError("[Test] Section - Wrong number of surface polygons")