@@ -51,7 +51,12 @@ namespace
5151 class FromModel
5252 {
5353 public:
54- FromModel ( const Model& model ) : model_( model ) {}
54+ FromModel ( const Model& model ) : model_( model )
55+ {
56+ OPENGEODE_EXCEPTION ( model.nb_unique_vertices () > 0 ,
57+ " [Convert Model to Mesh(es)] Given model should have unique "
58+ " vertices" );
59+ }
5560
5661 const Model& model () const
5762 {
@@ -71,6 +76,9 @@ namespace
7176
7277 geode::index_t create_vertex ( geode::index_t vertex_id )
7378 {
79+ OPENGEODE_EXCEPTION ( vertex_id != geode::NO_ID,
80+ " [Convert Model to Mesh(es)] At least one Component Mesh "
81+ " Vertex is not link to a unique vertex" );
7482 const geode::index_t new_id = vertices_.size ();
7583 vertices_.emplace ( vertex_id, new_id );
7684 return new_id;
@@ -88,6 +96,12 @@ namespace
8896 return points;
8997 }
9098
99+ const absl::flat_hash_map< geode::index_t , geode::index_t >&
100+ vertices () const
101+ {
102+ return vertices_;
103+ }
104+
91105 private:
92106 const Model& model_;
93107 absl::flat_hash_map< geode::index_t , geode::index_t > vertices_;
@@ -135,6 +149,10 @@ namespace
135149 const auto polyhedra = build_polyhedra ( block );
136150 set_polyhedra_adjacency ( block, polyhedra );
137151 }
152+ for ( const auto & v2uv : model_.vertices () )
153+ {
154+ attribute_unique_vertex_->set_value ( v2uv.first , v2uv.second );
155+ }
138156 }
139157
140158 std::unique_ptr< SolidType > get_result ()
@@ -147,12 +165,21 @@ namespace
147165 : model_( model ),
148166 mesh_{ SolidType::create () },
149167 builder_{ geode::SolidMeshBuilder3D::create ( *mesh_ ) },
150- attribute_{ mesh_->polyhedron_attribute_manager ()
151- .template find_or_create_attribute <
152- geode::VariableAttribute,
153- geode::uuid_from_conversion_attribute_type >(
154- geode::uuid_from_conversion_attribute_name,
155- {} ) }
168+ attribute_uuid_{
169+ mesh_->polyhedron_attribute_manager ()
170+ .template find_or_create_attribute <
171+ geode::VariableAttribute,
172+ geode::uuid_from_conversion_attribute_type >(
173+ geode::uuid_from_conversion_attribute_name, {} )
174+ },
175+ attribute_unique_vertex_{
176+ mesh_->vertex_attribute_manager ()
177+ .template find_or_create_attribute <
178+ geode::VariableAttribute,
179+ geode::unique_vertex_from_conversion_attribute_type >(
180+ geode::unique_vertex_from_conversion_attribute_name,
181+ geode::NO_ID )
182+ }
156183 {
157184 }
158185
@@ -219,7 +246,7 @@ namespace
219246 }
220247 polyhedra[p] = builder_->create_polyhedron (
221248 polyhedron_vertices, polyhedron_facet_vertices );
222- attribute_ ->set_value ( polyhedra[p], block.id () );
249+ attribute_uuid_ ->set_value ( polyhedra[p], block.id () );
223250 }
224251 return polyhedra;
225252 }
@@ -230,7 +257,10 @@ namespace
230257 std::unique_ptr< geode::SolidMeshBuilder3D > builder_;
231258 std::shared_ptr< geode::VariableAttribute<
232259 geode::uuid_from_conversion_attribute_type > >
233- attribute_;
260+ attribute_uuid_;
261+ std::shared_ptr< geode::VariableAttribute<
262+ geode::unique_vertex_from_conversion_attribute_type > >
263+ attribute_unique_vertex_;
234264 };
235265
236266 template < typename SurfaceType, typename Model, geode::index_t dimension >
@@ -242,12 +272,21 @@ namespace
242272 mesh_{ SurfaceType::create () },
243273 builder_{ geode::SurfaceMeshBuilder< dimension >::create (
244274 *mesh_ ) },
245- attribute_{ mesh_->polygon_attribute_manager ()
246- .template find_or_create_attribute <
247- geode::VariableAttribute,
248- geode::uuid_from_conversion_attribute_type >(
249- geode::uuid_from_conversion_attribute_name,
250- {} ) }
275+ attribute_uuid_{
276+ mesh_->polygon_attribute_manager ()
277+ .template find_or_create_attribute <
278+ geode::VariableAttribute,
279+ geode::uuid_from_conversion_attribute_type >(
280+ geode::uuid_from_conversion_attribute_name, {} )
281+ },
282+ attribute_unique_vertex_{
283+ mesh_->vertex_attribute_manager ()
284+ .template find_or_create_attribute <
285+ geode::VariableAttribute,
286+ geode::unique_vertex_from_conversion_attribute_type >(
287+ geode::unique_vertex_from_conversion_attribute_name,
288+ geode::NO_ID )
289+ }
251290 {
252291 }
253292
@@ -268,6 +307,10 @@ namespace
268307 const auto polygons = build_polygons ( surface );
269308 set_polygons_adjacency ( surface, polygons );
270309 }
310+ for ( const auto & v2uv : model_.vertices () )
311+ {
312+ attribute_unique_vertex_->set_value ( v2uv.first , v2uv.second );
313+ }
271314 }
272315
273316 std::unique_ptr< SurfaceType > get_result ()
@@ -320,7 +363,7 @@ namespace
320363 }
321364 }
322365 polygons[p] = builder_->create_polygon ( polygon );
323- attribute_ ->set_value ( polygons[p], surface.id () );
366+ attribute_uuid_ ->set_value ( polygons[p], surface.id () );
324367 }
325368 return polygons;
326369 }
@@ -331,7 +374,10 @@ namespace
331374 std::unique_ptr< geode::SurfaceMeshBuilder< dimension > > builder_;
332375 std::shared_ptr< geode::VariableAttribute<
333376 geode::uuid_from_conversion_attribute_type > >
334- attribute_;
377+ attribute_uuid_;
378+ std::shared_ptr< geode::VariableAttribute<
379+ geode::unique_vertex_from_conversion_attribute_type > >
380+ attribute_unique_vertex_;
335381 };
336382
337383 template < typename SurfaceType >
@@ -349,12 +395,21 @@ namespace
349395 mesh_{ geode::EdgedCurve< dimension >::create () },
350396 builder_{ geode::EdgedCurveBuilder< dimension >::create (
351397 *mesh_ ) },
352- attribute_{ mesh_->edge_attribute_manager ()
353- .template find_or_create_attribute <
354- geode::VariableAttribute,
355- geode::uuid_from_conversion_attribute_type >(
356- geode::uuid_from_conversion_attribute_name,
357- {} ) }
398+ attribute_uuid_{
399+ mesh_->edge_attribute_manager ()
400+ .template find_or_create_attribute <
401+ geode::VariableAttribute,
402+ geode::uuid_from_conversion_attribute_type >(
403+ geode::uuid_from_conversion_attribute_name, {} )
404+ },
405+ attribute_unique_vertex_{
406+ mesh_->vertex_attribute_manager ()
407+ .template find_or_create_attribute <
408+ geode::VariableAttribute,
409+ geode::unique_vertex_from_conversion_attribute_type >(
410+ geode::unique_vertex_from_conversion_attribute_name,
411+ geode::NO_ID )
412+ }
358413 {
359414 }
360415
@@ -364,6 +419,10 @@ namespace
364419 {
365420 build_edges ( line );
366421 }
422+ for ( const auto & v2uv : model_.vertices () )
423+ {
424+ attribute_unique_vertex_->set_value ( v2uv.first , v2uv.second );
425+ }
367426 }
368427
369428 std::unique_ptr< geode::EdgedCurve< dimension > > get_result ()
@@ -395,7 +454,7 @@ namespace
395454 }
396455 const auto edge =
397456 builder_->create_edge ( vertices[0 ], vertices[1 ] );
398- attribute_ ->set_value ( edge, line.id () );
457+ attribute_uuid_ ->set_value ( edge, line.id () );
399458 }
400459 }
401460
@@ -405,7 +464,10 @@ namespace
405464 std::unique_ptr< geode::EdgedCurveBuilder< dimension > > builder_;
406465 std::shared_ptr< geode::VariableAttribute<
407466 geode::uuid_from_conversion_attribute_type > >
408- attribute_;
467+ attribute_uuid_;
468+ std::shared_ptr< geode::VariableAttribute<
469+ geode::unique_vertex_from_conversion_attribute_type > >
470+ attribute_unique_vertex_;
409471 };
410472
411473 using CurveFromBRep = CurveFromModel< geode::BRep, 3 >;
0 commit comments