diff --git a/bindings/python/src/basic/attribute_manager.cpp b/bindings/python/src/basic/attribute_manager.cpp index 9957236ec..34ee8c867 100644 --- a/bindings/python/src/basic/attribute_manager.cpp +++ b/bindings/python/src/basic/attribute_manager.cpp @@ -36,30 +36,51 @@ namespace geode void python_attribute_class( pybind11::class_< AttributeManager >& manager, const std::string& suffix ) { - const auto read_suffix = absl::StrCat( "find_attribute_", suffix ); - manager.def( - read_suffix.c_str(), &AttributeManager::find_attribute< type > ); - const auto constant_suffix = - absl::StrCat( "find_or_create_attribute_constant_", suffix ); - manager.def( constant_suffix.c_str(), + const auto read_suffix = + absl::StrCat( "find_read_only_attribute_", suffix ); + manager.def( read_suffix.c_str(), + &AttributeManager::find_read_only_attribute< type > ); + const auto create_constant_suffix = + absl::StrCat( "create_attribute_constant_", suffix ); + manager.def( create_constant_suffix.c_str(), + static_cast< geode::uuid ( AttributeManager::* )( + std::string_view, type, AttributeProperties ) >( + &AttributeManager::create_attribute< ConstantAttribute, + type > ) ); + const auto find_constant_suffix = + absl::StrCat( "find_attribute_constant_", suffix ); + manager.def( find_constant_suffix.c_str(), static_cast< std::shared_ptr< ConstantAttribute< type > > ( - AttributeManager::* )( std::string_view, type ) >( - &AttributeManager::find_or_create_attribute< ConstantAttribute, + AttributeManager::* )( const geode::uuid& ) >( + &AttributeManager::find_attribute< ConstantAttribute, + type > ) ); + const auto create_variable_suffix = + absl::StrCat( "create_attribute_variable_", suffix ); + manager.def( create_variable_suffix.c_str(), + static_cast< geode::uuid ( AttributeManager::* )( + std::string_view, type, AttributeProperties ) >( + &AttributeManager::create_attribute< VariableAttribute, type > ) ); - const auto variable_suffix = - absl::StrCat( "find_or_create_attribute_variable_", suffix ); - manager.def( variable_suffix.c_str(), + const auto find_variable_suffix = + absl::StrCat( "find_attribute_variable_", suffix ); + manager.def( find_variable_suffix.c_str(), static_cast< std::shared_ptr< VariableAttribute< type > > ( - AttributeManager::* )( std::string_view, type ) >( - &AttributeManager::find_or_create_attribute< VariableAttribute, + AttributeManager::* )( const geode::uuid& ) >( + &AttributeManager::find_attribute< VariableAttribute, type > ) ); - const auto sparse_suffix = - absl::StrCat( "find_or_create_attribute_sparse_", suffix ); - manager.def( sparse_suffix.c_str(), - static_cast< std::shared_ptr< SparseAttribute< type > > ( - AttributeManager::* )( std::string_view, type ) >( - &AttributeManager::find_or_create_attribute< SparseAttribute, + const auto create_sparse_suffix = + absl::StrCat( "create_attribute_sparse_", suffix ); + manager.def( create_sparse_suffix.c_str(), + static_cast< geode::uuid ( AttributeManager::* )( + std::string_view, type, AttributeProperties ) >( + &AttributeManager::create_attribute< SparseAttribute, type > ) ); + const auto find_sparse_suffix = + absl::StrCat( "find_attribute_sparse_", suffix ); + manager.def( find_sparse_suffix.c_str(), + static_cast< std::shared_ptr< SparseAttribute< type > > ( + AttributeManager::* )( const geode::uuid& ) >( + &AttributeManager::find_attribute< SparseAttribute, type > ) ); } void define_attribute_manager( pybind11::module& module ) @@ -69,7 +90,7 @@ namespace geode manager.def( pybind11::init<>() ) .def( "find_generic_attribute", &AttributeManager::find_generic_attribute ) - .def( "attribute_names", &AttributeManager::attribute_names ) + .def( "attribute_ids", &AttributeManager::attribute_ids ) .def( "attribute_type", &AttributeManager::attribute_type ) .def( "attribute_exists", &AttributeManager::attribute_exists ) .def( "nb_elements", &AttributeManager::nb_elements ) @@ -80,7 +101,9 @@ namespace geode .def( "delete_attribute", &AttributeManager::delete_attribute ) .def( "set_attribute_properties", &AttributeManager::set_attribute_properties ) - .def( "delete_elements", &AttributeManager::delete_elements ); + .def( "delete_elements", &AttributeManager::delete_elements ) + .def( "attribute_ids_matching_name", + &AttributeManager::attribute_ids_matching_name ); python_attribute_class< bool >( manager, "bool" ); python_attribute_class< int >( manager, "int" ); python_attribute_class< unsigned int >( manager, "uint" ); diff --git a/bindings/python/tests/basic/test-py-attribute.py b/bindings/python/tests/basic/test-py-attribute.py index 672290471..3f4ee3e4e 100644 --- a/bindings/python/tests/basic/test-py-attribute.py +++ b/bindings/python/tests/basic/test-py-attribute.py @@ -30,61 +30,80 @@ def test_constant_attribute(manager): - constant_attribute = manager.find_or_create_attribute_constant_bool( - "bool", True) - - attribute = manager.find_attribute_bool("bool") + + constant_attribute_id = manager.create_attribute_constant_bool( + "bool", True, basic.AttributeProperties()) + constant_attribute = manager.find_attribute_constant_bool(constant_attribute_id) + attribute = manager.find_read_only_attribute_bool(constant_attribute_id) if not attribute.value(0): raise ValueError("[Test] Should be equal to True") constant_attribute.set_value(False) if attribute.value(12): raise ValueError("[Test] Should be equal to False") + return constant_attribute_id def test_int_variable_attribute(manager): - variable_attribute = manager.find_or_create_attribute_variable_int( - "int", 12) + variable_attribute_id = manager.create_attribute_variable_int( + "int", 12,basic.AttributeProperties()) + variable_attribute = manager.find_attribute_variable_int(variable_attribute_id) variable_attribute.set_value(3, 3) if not variable_attribute.is_genericable(): raise ValueError("[Test] Should be genericable") - manager.set_attribute_properties("int",basic.AttributeProperties(True,True)) + manager.set_attribute_properties(variable_attribute_id,basic.AttributeProperties(True,True)) if not variable_attribute.properties().assignable or not variable_attribute.properties().interpolable : raise ValueError("[Test] Should be assignable and interpolable") - attribute = manager.find_attribute_int("int") - if attribute.value(3) != 3: + find_read_only_attribute = manager.find_read_only_attribute_int(variable_attribute_id) + if variable_attribute.value(3) != 3: raise ValueError("[Test] Should be equal to 3") - if attribute.value(6) != 12: + if variable_attribute.value(6) != 12: + raise ValueError("[Test] Should be equal to 12") + if find_read_only_attribute.value(3) != 3: + raise ValueError("[Test] Should be equal to 3") + if find_read_only_attribute.value(6) != 12: raise ValueError("[Test] Should be equal to 12") variable_attribute.set_value(3, 5) - if attribute.value(3) != 5: + if variable_attribute.value(3) != 5: + raise ValueError("[Test] Should be equal to 5") + if find_read_only_attribute.value(3) != 5: raise ValueError("[Test] Should be equal to 5") def test_double_sparse_attribute(manager): - sparse_attribute = manager.find_or_create_attribute_sparse_double( - "double", 12) - sparse_attribute.set_value(3, 3) - sparse_attribute.set_value(7, 7) + sparse_attribute_id = manager.create_attribute_sparse_double( + "double", 12,basic.AttributeProperties()) + attribute = manager.find_attribute_sparse_double(sparse_attribute_id) + attribute.set_value(3, 3) + attribute.set_value(7, 7) - attribute = manager.find_attribute_double("double") + find_read_only_attribute = manager.find_read_only_attribute_double(sparse_attribute_id) if attribute.value(3) != 3: raise ValueError("[Test] Should be equal to 3") if attribute.value(6) != 12: raise ValueError("[Test] Should be equal to 12") if attribute.value(7) != 7: raise ValueError("[Test] Should be equal to 7") + if find_read_only_attribute.value(3) != 3: + raise ValueError("[Test] Should be equal to 3") + if find_read_only_attribute.value(6) != 12: + raise ValueError("[Test] Should be equal to 12") + if find_read_only_attribute.value(7) != 7: + raise ValueError("[Test] Should be equal to 7") - sparse_attribute.set_value(3, 5) + attribute.set_value(3, 5) if attribute.value(3) != 5: raise ValueError("[Test] Should be equal to 5") + if find_read_only_attribute.value(3) != 5: + raise ValueError("[Test] Should be equal to 5") + return sparse_attribute_id def test_number_of_attributes(manager, nb): - if len(manager.attribute_names()) != nb: + if len(manager.attribute_ids()) != nb: raise ValueError( "[Test] Not the correct number of attributes in the manager") @@ -99,8 +118,8 @@ def test_delete_attribute_elements(manager): "[Test] Two attribute elements should have been removed") -def test_sparse_attribute_after_element_deletion(manager): - sparse_attribute = manager.find_attribute_double("double") +def test_sparse_attribute_after_element_deletion(manager, double_attribute_id): + sparse_attribute = manager.find_read_only_attribute_double(double_attribute_id) if sparse_attribute.value(0) != 12: raise ValueError("Element 0 of sparse attribute should be 12 ") if sparse_attribute.value(5) != 7: @@ -114,17 +133,17 @@ def test_sparse_attribute_after_element_deletion(manager): manager.resize(10) if manager.nb_elements() != 10: raise ValueError("[Test] Manager should have 10 elements") - test_constant_attribute(manager) + bool_attribute_id = test_constant_attribute(manager) test_int_variable_attribute(manager) test_double_sparse_attribute(manager) - test_double_sparse_attribute(manager) + double_attribute_id = test_double_sparse_attribute(manager) test_delete_attribute_elements(manager) - test_sparse_attribute_after_element_deletion(manager) + test_sparse_attribute_after_element_deletion(manager,double_attribute_id) + test_number_of_attributes(manager, 4) + manager.delete_attribute(bool_attribute_id) test_number_of_attributes(manager, 3) - manager.delete_attribute("bool") - test_number_of_attributes(manager, 2) manager.clear_attributes() - test_number_of_attributes(manager, 2) + test_number_of_attributes(manager, 3) manager.resize(10) if manager.nb_elements() != 10: raise ValueError("[Test] Manager should have 10 elements") diff --git a/bindings/python/tests/mesh/test-py-edged-curve.py b/bindings/python/tests/mesh/test-py-edged-curve.py index cb1831f4e..ce2dc1bff 100644 --- a/bindings/python/tests/mesh/test-py-edged-curve.py +++ b/bindings/python/tests/mesh/test-py-edged-curve.py @@ -123,8 +123,10 @@ def test_edge_requests(edged_curve, builder): def test_clone(edged_curve): - attribute = edged_curve.edge_attribute_manager( - ).find_or_create_attribute_variable_int("test", 0) + attribute_id = edged_curve.edge_attribute_manager( + ).create_attribute_variable_int("test", 0,opengeode_py_basic.AttributeProperties()) + + attribute = edged_curve.edge_attribute_manager().find_attribute_variable_int(attribute_id) attribute.set_value(0, 42) edged_curve2 = edged_curve.clone() @@ -133,7 +135,7 @@ def test_clone(edged_curve): if edged_curve2.nb_edges() != 3: raise ValueError("[Test] EdgedCurve2 should have 3 edge") - attribute2 = edged_curve2.edge_attribute_manager().find_attribute_int("test") + attribute2 = edged_curve2.edge_attribute_manager().find_read_only_attribute_int(attribute_id) if attribute2.value(0) != 42: raise ValueError("[Test] EdgedCurve2 attribute should be 42") diff --git a/bindings/python/tests/mesh/test-py-gradient-computation.py b/bindings/python/tests/mesh/test-py-gradient-computation.py index 1b5cd4c31..26f2345f6 100644 --- a/bindings/python/tests/mesh/test-py-gradient-computation.py +++ b/bindings/python/tests/mesh/test-py-gradient-computation.py @@ -35,7 +35,8 @@ def test_gradient_grid2D(): builder = mesh.RegularGridBuilder2D.create( grid ) builder.initialize_cartesian_grid( geom.Point2D([ 0, 0 ] ), [ 3, 3 ], 1 ) scalar_function_name = "scalar_function" - attribute = grid.vertex_attribute_manager().find_or_create_attribute_variable_double( scalar_function_name, 0 ) + attribute_id = grid.vertex_attribute_manager().create_attribute_variable_double( scalar_function_name, 0,opengeode_py_basic.AttributeProperties() ) + attribute = grid.vertex_attribute_manager().find_attribute_variable_double( attribute_id ) attribute.set_value( 1, 1 ) attribute.set_value( 4, 1 ) attribute.set_value( 6, 1 ) @@ -50,7 +51,7 @@ def test_gradient_grid2D(): attribute.set_value( 13, 2 ) attribute.set_value( 14, 3 ) attribute.set_value( 15, 8 ) - gradient_name = mesh.compute_surface_scalar_function_gradient2D( grid, scalar_function_name ) + gradient_name = mesh.compute_surface_scalar_function_gradient2D( grid, attribute_id ) print("Gradient attribute name: ", gradient_name) mesh.save_regular_grid2D( grid, "grid_with_gradient.og_rgd2d" ) @@ -80,7 +81,8 @@ def test_gradient_triangulated_surface2D(): builder.create_polygon( [ 5, 6, 8 ] ) builder.compute_polygon_adjacencies() scalar_function_name = "scalar_function" - attribute = surface.vertex_attribute_manager().find_or_create_attribute_variable_double( scalar_function_name, 0 ) + attribute_id = surface.vertex_attribute_manager().create_attribute_variable_double( scalar_function_name, 0,opengeode_py_basic.AttributeProperties() ) + attribute = surface.vertex_attribute_manager().find_attribute_variable_double( attribute_id ) attribute.set_value( 1, 1 ) attribute.set_value( 2, 1 ) attribute.set_value( 3, 1 ) @@ -89,7 +91,7 @@ def test_gradient_triangulated_surface2D(): attribute.set_value( 9, 3 ) attribute.set_value( 7, 2 ) attribute.set_value( 8, 2 ) - gradient_name = mesh.compute_surface_scalar_function_gradient2D( surface, scalar_function_name ) + gradient_name = mesh.compute_surface_scalar_function_gradient2D( surface, attribute_id ) print("Gradient attribute name: ", gradient_name) mesh.save_triangulated_surface2D( surface, "mesh_with_gradient.og_tsf2d" ) @@ -98,7 +100,8 @@ def test_gradient_grid3D(): builder = mesh.RegularGridBuilder3D.create( grid ) builder.initialize_cartesian_grid( geom.Point3D([ 0, 0, 0 ]), [ 2, 2, 2 ], 1 ) scalar_function_name = "scalar_function" - attribute = grid.vertex_attribute_manager().find_or_create_attribute_variable_double( scalar_function_name, 0 ) + attribute_id = grid.vertex_attribute_manager().create_attribute_variable_double( scalar_function_name, 0,opengeode_py_basic.AttributeProperties() ) + attribute = grid.vertex_attribute_manager().find_attribute_variable_double( attribute_id ) attribute.set_value( 4, 1 ) attribute.set_value( 10, 1 ) attribute.set_value( 12, 1 ) @@ -125,8 +128,8 @@ def test_gradient_grid3D(): attribute.set_value( 20, 3 ) attribute.set_value( 24, 3 ) attribute.set_value( 26, 3 ) - gradient_name = mesh.compute_solid_scalar_function_gradient3D( grid, scalar_function_name ) - print("Gradient attribute name: ", gradient_name) + gradient_id= mesh.compute_solid_scalar_function_gradient3D( grid, attribute_id ) + print("Gradient attribute name: ", gradient_id) mesh.save_regular_grid3D( grid, "grid_with_gradient.og_rgd3d" ) if __name__ == '__main__': diff --git a/bindings/python/tests/mesh/test-py-light-regular-grid.py b/bindings/python/tests/mesh/test-py-light-regular-grid.py index ef2d98351..92dc94e2c 100644 --- a/bindings/python/tests/mesh/test-py-light-regular-grid.py +++ b/bindings/python/tests/mesh/test-py-light-regular-grid.py @@ -287,22 +287,26 @@ def test_closest_vertex(grid): def test_attribute_3d(grid): - attribute = grid.cell_attribute_manager().find_or_create_attribute_variable_double( - "toto", -1 + attribute_id = grid.cell_attribute_manager().create_attribute_variable_double( + "toto", -1,geode.AttributeProperties() ) + attribute = grid.cell_attribute_manager().find_attribute_variable_double(attribute_id) attribute.set_value(10, 10) - attribute = grid.cell_attribute_manager().find_attribute_double("toto") + attribute = grid.cell_attribute_manager().find_read_only_attribute_double(attribute_id) if attribute.value(0) != -1: raise ValueError("[Test] Wrong attribute value") if attribute.value(10) != 10: raise ValueError("[Test] Wrong attribute value") if attribute.value(grid.nb_cells() - 1) != -1: raise ValueError("[Test] Wrong attribute value") - attribute = ( - grid.grid_vertex_attribute_manager().find_or_create_attribute_variable_double( - "toto_vertex", 1 + attribute_id = ( + grid.grid_vertex_attribute_manager().create_attribute_variable_double( + "toto_vertex", 1,geode.AttributeProperties() ) ) + attribute = grid.grid_vertex_attribute_manager().find_attribute_variable_double( + attribute_id + ) attribute.set_value(10, 10) if attribute.value(0) != 1: raise ValueError("[Test] Wrong attribute value") @@ -314,22 +318,26 @@ def test_attribute_3d(grid): def test_attribute_2d(): grid = mesh.LightRegularGrid2D(geom.Point2D([1.5, 0]), [5, 10], [1.0, 2.0]) - attribute = grid.cell_attribute_manager().find_or_create_attribute_variable_double( - "toto", -1 + attribute_id = grid.cell_attribute_manager().create_attribute_variable_double( + "toto", -1,geode.AttributeProperties() ) + attribute = grid.cell_attribute_manager().find_attribute_variable_double(attribute_id) attribute.set_value(10, 10) - attribute = grid.cell_attribute_manager().find_attribute_double("toto") + attribute = grid.cell_attribute_manager().find_read_only_attribute_double(attribute_id) if attribute.value(0) != -1: raise ValueError("[Test] Wrong attribute value") if attribute.value(10) != 10: raise ValueError("[Test] Wrong attribute value") if attribute.value(grid.nb_cells() - 1) != -1: raise ValueError("[Test] Wrong attribute value") - attribute = ( - grid.grid_vertex_attribute_manager().find_or_create_attribute_variable_double( - "toto_vertex", 1 + attribute_id = ( + grid.grid_vertex_attribute_manager().create_attribute_variable_double( + "toto_vertex", 1,geode.AttributeProperties() ) ) + attribute = grid.grid_vertex_attribute_manager().find_attribute_variable_double( + attribute_id + ) attribute.set_value(10, 10) if attribute.value(0) != 1: raise ValueError("[Test] Wrong attribute value") diff --git a/bindings/python/tests/mesh/test-py-point-set.py b/bindings/python/tests/mesh/test-py-point-set.py index 8d710f872..ad6a25feb 100644 --- a/bindings/python/tests/mesh/test-py-point-set.py +++ b/bindings/python/tests/mesh/test-py-point-set.py @@ -58,10 +58,12 @@ def test_bounding_box(point_set): def test_create_vertex_attribute(point_set): manager = point_set.vertex_attribute_manager() - attribute = point_set.vertex_attribute_manager( - ).find_or_create_attribute_constant_bool("test", True) + attribute_id = point_set.vertex_attribute_manager( + ).create_attribute_constant_bool("test", True,opengeode_py_basic.AttributeProperties()) + attribute = manager.find_attribute_constant_bool(attribute_id) if attribute.constant_value() != True: raise ValueError("[Test] PointSet attribute value should be true") + return attribute_id def test_delete_vertex(point_set, builder): @@ -80,12 +82,12 @@ def test_io(point_set, filename): new_point_set = mesh.load_point_set3D(filename) -def test_clone(point_set): +def test_clone(point_set, attribute_id): point_set2 = point_set.clone() if point_set2.nb_vertices() != 3: raise ValueError("[Test] PointSet2 should have 3 vertices") - attribute = point_set2.vertex_attribute_manager().find_attribute_bool("test") + attribute = point_set2.vertex_attribute_manager().find_read_only_attribute_bool(attribute_id) if attribute.value(0) != True: raise ValueError("[Test] PointSet2 attribute value should be true") @@ -110,9 +112,9 @@ def test_permutation(point_set, builder): builder = mesh.PointSetBuilder3D.create(point_set) test_create_vertices(point_set, builder) test_bounding_box(point_set) - test_create_vertex_attribute(point_set) + test_attribute_id =test_create_vertex_attribute(point_set) test_io(point_set, "test." + point_set.native_extension()) test_permutation(point_set, builder) test_delete_vertex(point_set, builder) - test_clone(point_set) + test_clone(point_set, test_attribute_id) diff --git a/bindings/python/tests/mesh/test-py-polygonal-surface.py b/bindings/python/tests/mesh/test-py-polygonal-surface.py index d959f2806..9d0ab4bac 100644 --- a/bindings/python/tests/mesh/test-py-polygonal-surface.py +++ b/bindings/python/tests/mesh/test-py-polygonal-surface.py @@ -66,10 +66,13 @@ def test_create_polygons(polygonal_surface, builder): def test_create_edge_attribute(polygonal_surface): + attribute_id = polygonal_surface.edges().edge_attribute_manager( + ).create_attribute_variable_uint("test", basic.NO_ID,basic.AttributeProperties()) attribute = polygonal_surface.edges().edge_attribute_manager( - ).find_or_create_attribute_variable_uint("test", basic.NO_ID) + ).find_attribute_variable_uint(attribute_id) for e in range(polygonal_surface.edges().nb_edges()): attribute.set_value(e, e) + return attribute_id def test_polygon_adjacencies(polygonal_surface, builder): @@ -113,7 +116,7 @@ def test_previous_next_on_border(polygonal_surface): raise ValueError("[Test] Next edge on border index is not correct") -def test_delete_polygon(polygonal_surface, builder): +def test_delete_polygon(polygonal_surface, builder, attribute_id): to_delete = [False] * polygonal_surface.nb_polygons() to_delete[0] = True builder.delete_polygons(to_delete) @@ -133,7 +136,7 @@ def test_delete_polygon(polygonal_surface, builder): raise ValueError("[Test] PolygonalSurface should have 6 edges") attribute = polygonal_surface.edges( - ).edge_attribute_manager().find_attribute_uint("test") + ).edge_attribute_manager().find_read_only_attribute_uint(attribute_id) for e in range(6): if attribute.value(e) != e: raise ValueError("[Test] Update of edge attributes after " @@ -204,7 +207,7 @@ def test_polygon_vertex_normal(): "[Test] PolygonalSurface polygon vertex normal is not correct") -def test_io(polygonal_surface, filename): +def test_io(polygonal_surface, filename, attribute_id): mesh.save_polygonal_surface3D(polygonal_surface, filename) new_polygonal_surface = mesh.load_polygonal_surface3D(filename) @@ -218,7 +221,7 @@ def test_io(polygonal_surface, filename): raise ValueError( "[Test] Reloaded PolygonalSurface should have 3 polygons") attribute = new_polygonal_surface.edges( - ).edge_attribute_manager().find_attribute_uint("test") + ).edge_attribute_manager().find_read_only_attribute_uint(attribute_id) for e in range(new_polygonal_surface.edges().nb_edges()): if attribute.value(e) != e: raise ValueError( @@ -365,7 +368,7 @@ def test_permutation(surface, builder): test_create_vertices(polygonal_surface, builder) test_bounding_box(polygonal_surface) test_create_polygons(polygonal_surface, builder) - test_create_edge_attribute(polygonal_surface) + edge_attribute_id = test_create_edge_attribute(polygonal_surface) test_polygon_adjacencies(polygonal_surface, builder) test_polygon_edges_on_borders(polygonal_surface) test_previous_next_on_border(polygonal_surface) @@ -374,10 +377,10 @@ def test_permutation(surface, builder): test_polygon_normal() test_polygon_vertex_normal() - test_io(polygonal_surface, "test." + polygonal_surface.native_extension()) + test_io(polygonal_surface, "test." + polygonal_surface.native_extension(),edge_attribute_id) test_permutation(polygonal_surface, builder) - test_delete_polygon(polygonal_surface, builder) + test_delete_polygon(polygonal_surface, builder, edge_attribute_id) test_clone(polygonal_surface) test_set_polygon_vertex(polygonal_surface, builder) test_delete_all(polygonal_surface, builder) diff --git a/bindings/python/tests/mesh/test-py-polyhedral-solid.py b/bindings/python/tests/mesh/test-py-polyhedral-solid.py index 1255238b9..83c2c739d 100644 --- a/bindings/python/tests/mesh/test-py-polyhedral-solid.py +++ b/bindings/python/tests/mesh/test-py-polyhedral-solid.py @@ -72,15 +72,20 @@ def test_create_polyhedra(polyhedral_solid, builder): def test_create_facet_attribute(polyhedral_solid): + attribute_id = polyhedral_solid.facets().facet_attribute_manager( + ).create_attribute_variable_uint("test", basic.NO_ID, basic.AttributeProperties()) attribute = polyhedral_solid.facets().facet_attribute_manager( - ).find_or_create_attribute_variable_uint("test", basic.NO_ID) + ).find_attribute_variable_uint(attribute_id) for f in range(polyhedral_solid.facets().nb_facets()): attribute.set_value(f, f) + return attribute_id def test_create_edge_attribute(polyhedral_solid): + attribute_id = polyhedral_solid.edges().edge_attribute_manager( + ).create_attribute_variable_uint("test", basic.NO_ID, basic.AttributeProperties()) attribute = polyhedral_solid.edges().edge_attribute_manager( - ).find_or_create_attribute_variable_uint("test", basic.NO_ID) + ).find_attribute_variable_uint(attribute_id) for e in range(polyhedral_solid.edges().nb_edges()): vertices = polyhedral_solid.edges().edge_vertices(e) attribute.set_value(e, vertices[0] + vertices[1]) @@ -88,6 +93,7 @@ def test_create_edge_attribute(polyhedral_solid): raise ValueError("[Test] Wrong value for attribute on edge 0") if attribute.value(1) != 3: raise ValueError("[Test] Wrong value for attribute on edge 1") + return attribute_id def test_polyhedron_adjacencies(polyhedral_solid, builder): @@ -135,7 +141,7 @@ def test_polyhedron_adjacencies(polyhedral_solid, builder): raise ValueError("[Test] Polyhedra from facet should contain (2, 3)") -def test_delete_polyhedra(polyhedral_solid, builder): +def test_delete_polyhedra(polyhedral_solid, builder,edge_attribute_id): to_delete = [False] * polyhedral_solid.nb_polyhedra() to_delete[0] = True builder.delete_polyhedra(to_delete) @@ -160,7 +166,7 @@ def test_delete_polyhedra(polyhedral_solid, builder): if polyhedral_solid.edges().nb_edges() != 12: raise ValueError("[Test] PolyhedralSolid should have 12 edges") attribute = polyhedral_solid.edges( - ).edge_attribute_manager().find_attribute_uint("test") + ).edge_attribute_manager().find_read_only_attribute_uint(edge_attribute_id) if attribute.value(0) != 1: raise ValueError( "[Test] Wrong value for attribute on edge 0 after polyhedron deletion") @@ -169,7 +175,7 @@ def test_delete_polyhedra(polyhedral_solid, builder): "[Test] Wrong value for attribute on edge 1 after polyhedron deletion") -def test_io(polyhedral_solid, filename): +def test_io(polyhedral_solid, filename, facet_attribute_id): mesh.save_polyhedral_solid3D(polyhedral_solid, filename) new_polyhedral_solid = mesh.load_polyhedral_solid3D(filename) @@ -186,7 +192,7 @@ def test_io(polyhedral_solid, filename): raise ValueError( "[Test] Reloaded PolyhedralSolid should have 3 polyhedra") attribute = new_polyhedral_solid.facets( - ).facet_attribute_manager().find_attribute_uint("test") + ).facet_attribute_manager().find_read_only_attribute_uint(facet_attribute_id) for f in range(new_polyhedral_solid.facets().nb_facets()): if attribute.value(f) != f: raise ValueError( @@ -404,13 +410,13 @@ def test_permutation(solid, builder): test_create_vertices(polyhedral_solid, builder) test_create_polyhedra(polyhedral_solid, builder) - test_create_facet_attribute(polyhedral_solid) - test_create_edge_attribute(polyhedral_solid) + facet_attribute_id = test_create_facet_attribute(polyhedral_solid) + edge_attribute_id = test_create_edge_attribute(polyhedral_solid) test_polyhedron_adjacencies(polyhedral_solid, builder) - test_io(polyhedral_solid, "test." + polyhedral_solid.native_extension()) + test_io(polyhedral_solid, "test." + polyhedral_solid.native_extension(),facet_attribute_id) test_permutation(polyhedral_solid, builder) - test_delete_polyhedra(polyhedral_solid, builder) + test_delete_polyhedra(polyhedral_solid, builder,edge_attribute_id) test_clone(polyhedral_solid) test_set_polyhedron_vertex(polyhedral_solid, builder) test_delete_all(polyhedral_solid, builder) diff --git a/bindings/python/tests/mesh/test-py-regular-grid.py b/bindings/python/tests/mesh/test-py-regular-grid.py index 3e60366a3..1f31f73be 100644 --- a/bindings/python/tests/mesh/test-py-regular-grid.py +++ b/bindings/python/tests/mesh/test-py-regular-grid.py @@ -246,16 +246,22 @@ def test_closest_vertex(grid): def test_clone(grid): attribute_name = "int_attribute" attribute_name_d = "double_attribute" - attribute = ( - grid.polyhedron_attribute_manager().find_or_create_attribute_variable_int( - attribute_name, 0 + attribute_id = ( + grid.polyhedron_attribute_manager().create_attribute_variable_int( + attribute_name, 0,geode.AttributeProperties() ) ) - attribute_d = ( - grid.vertex_attribute_manager().find_or_create_attribute_variable_double( - attribute_name_d, 0 + attribute = grid.polyhedron_attribute_manager().find_attribute_variable_int( + attribute_id + ) + attribute_d_id = ( + grid.vertex_attribute_manager().create_attribute_variable_double( + attribute_name_d, 0,geode.AttributeProperties() ) ) + attribute_d = grid.vertex_attribute_manager().find_attribute_variable_double( + attribute_d_id + ) for c in range(grid.nb_cells()): attribute.set_value(c, 2 * c) for c in range(grid.nb_vertices()): @@ -263,18 +269,18 @@ def test_clone(grid): clone = grid.clone() if clone.grid_point([0, 0, 0]) != grid.grid_point([0, 0, 0]): raise ValueError("[Test] Wrong clone origin") - if not clone.polyhedron_attribute_manager().attribute_exists(attribute_name): + if not clone.polyhedron_attribute_manager().attribute_exists(attribute_id): raise ValueError("[Test] Clone missing attribute") - if not clone.vertex_attribute_manager().attribute_exists(attribute_name_d): + if not clone.vertex_attribute_manager().attribute_exists(attribute_d_id): raise ValueError("[Test] Clone missing attribute") - clone_attribute = clone.polyhedron_attribute_manager().find_attribute_int( - attribute_name + clone_attribute = clone.polyhedron_attribute_manager().find_read_only_attribute_int( + attribute_id ) for c in range(clone.nb_cells()): if clone_attribute.value(c) != 2 * c: raise ValueError("[Test] Wrong clone attribute") - clone_attribute_d = clone.vertex_attribute_manager().find_attribute_double( - attribute_name_d + clone_attribute_d = clone.vertex_attribute_manager().find_read_only_attribute_double( + attribute_d_id ) for c in range(clone.nb_vertices()): if clone_attribute_d.value(c) != 2 * c: diff --git a/include/geode/basic/attribute.hpp b/include/geode/basic/attribute.hpp index 64e240a43..3ef6851e1 100644 --- a/include/geode/basic/attribute.hpp +++ b/include/geode/basic/attribute.hpp @@ -35,6 +35,7 @@ #include #include #include +#include #include #include @@ -48,7 +49,7 @@ namespace geode /*! * Base class defining the virtual API used by the AttributeManager. */ - class AttributeBase + class AttributeBase : public Identifier { OPENGEODE_DISABLE_COPY( AttributeBase ); friend class bitsery::Access; @@ -69,11 +70,6 @@ namespace geode [[nodiscard]] virtual std::string_view type() = 0; - [[nodiscard]] std::string_view name() const - { - return name_; - } - [[nodiscard]] const AttributeProperties& properties() const { return properties_; @@ -85,11 +81,6 @@ namespace geode } public: - void set_name( std::string_view name, AttributeKey /*key*/ ) - { - name_ = to_string( name ); - } - [[nodiscard]] virtual std::shared_ptr< AttributeBase > clone( AttributeKey /*key*/ ) const = 0; @@ -147,20 +138,26 @@ namespace geode }, []( Archive& archive, AttributeBase& attribute ) { archive.object( attribute.properties_ ); - archive.text1b( - attribute.name_, attribute.name_.max_size() ); + std::string old_name; + archive.text1b( old_name, old_name.max_size() ); + attribute.set_name( old_name ); + }, + []( Archive& archive, AttributeBase& attribute ) { + archive.object( attribute.properties_ ); + archive.ext( attribute, + bitsery::ext::BaseClass< Identifier >{} ); } } } ); } protected: - AttributeBase( AttributeProperties properties ) + AttributeBase( std::string_view name, AttributeProperties properties ) : properties_( std::move( properties ) ) { + set_name( name ); } private: AttributeProperties properties_; - std::string name_; }; /*! @@ -204,8 +201,9 @@ namespace geode } protected: - ReadOnlyAttribute( AttributeProperties properties ) - : AttributeBase( std::move( properties ) ) + ReadOnlyAttribute( + std::string_view name, AttributeProperties properties ) + : AttributeBase( name, std::move( properties ) ) { } diff --git a/include/geode/basic/attribute_manager.hpp b/include/geode/basic/attribute_manager.hpp index 28c1eb444..a2139c147 100644 --- a/include/geode/basic/attribute_manager.hpp +++ b/include/geode/basic/attribute_manager.hpp @@ -33,7 +33,9 @@ #include #include +#include #include +#include namespace geode { @@ -59,10 +61,10 @@ namespace geode * @return nullptr if no attribute matches the given name. */ [[nodiscard]] std::shared_ptr< AttributeBase > find_generic_attribute( - std::string_view name ) const + const geode::uuid& attribute_id ) const { absl::ReaderMutexLock lock{ mutex() }; - return find_attribute_base( name ); + return find_attribute_base( attribute_id ); } /*! @@ -72,82 +74,76 @@ namespace geode * @exception OpenGeodeException if no Attribute found */ template < typename T > - [[nodiscard]] std::shared_ptr< ReadOnlyAttribute< T > > find_attribute( - std::string_view name ) const + [[nodiscard]] std::shared_ptr< ReadOnlyAttribute< T > > + find_read_only_attribute( const geode::uuid& attribute_id ) const { absl::ReaderMutexLock lock{ mutex() }; auto attribute = std::dynamic_pointer_cast< ReadOnlyAttribute< T > >( - find_attribute_base( name ) ); + find_attribute_base( attribute_id ) ); OpenGeodeBasicException::check_exception( attribute.get(), nullptr, OpenGeodeException::TYPE::data, - "[AttributeManager::find_attribute] Could not find attribute '", - name, + "[AttributeManager::find_read_only_attribute] Could not find " + "attribute " + "with id :'", + attribute_id.string(), "'. You have to create an attribute before using it. See " - "find_or_create_attribute method and derived classes of " + "create_attribute method and derived classes of " "ReadOnlyAttribute." ); return attribute; } - /*! - * Recover or create the attribute from the manager - * and the attribute name. - * If the recovered Attribute is not a of the same type than the - * attribute, it replaces it by the Attribute corresponding to the - * attribute. - * @param[in] name The associated attribute name to look for - * @param[in] default_value The default value to use when new attribute - * element are created - * @param[in] properties The AttributeProperties to set the attribute - * flags for future modifications - * @tparam Attribute The attribute type to look for, - * such as ConstantAttribute - * @tparam T The type of the Attribute element - * @exception OpenGeodeException if the Attribute replacement failed - */ template < template < typename > class Attribute, typename T > - std::shared_ptr< Attribute< T > > find_or_create_attribute( - std::string_view name, + [[nodiscard]] std::shared_ptr< Attribute< T > > find_attribute( + const geode::uuid& attribute_id ) + { + absl::ReaderMutexLock lock{ mutex() }; + auto attribute = std::dynamic_pointer_cast< Attribute< T > >( + find_attribute_base( attribute_id ) ); + OpenGeodeBasicException::check_exception( attribute.get(), nullptr, + OpenGeodeException::TYPE::data, + "[AttributeManager::find_attribute] Could not find attribute " + "with id : '", + attribute_id.string(), + "'. You have to create an attribute before using it. See " + "create_attribute method and derived classes of " + "ReadOnlyAttribute." ); + return attribute; + } + + template < template < typename > class Attribute, typename T > + void create_attribute( std::string_view attribute_name, + const geode::uuid& attribute_id, T default_value, AttributeProperties properties ) { - { - absl::ReaderMutexLock lock{ mutex() }; - auto attribute = find_attribute_base( name ); - auto typed_attribute = - std::dynamic_pointer_cast< Attribute< T > >( attribute ); - if( typed_attribute.get() ) - { - return typed_attribute; - } - } absl::MutexLock lock{ mutex() }; - auto attribute = find_attribute_base( name ); + auto attribute = find_attribute_base( attribute_id ); auto typed_attribute = std::dynamic_pointer_cast< Attribute< T > >( attribute ); - if( typed_attribute.get() ) - { - return typed_attribute; - } - OpenGeodeBasicException::check_exception( attribute.use_count() < 2, - nullptr, OpenGeodeException::TYPE::internal, - "[AttributeManager::find_or_create_attribute] Do not " - "instantiate an attribute " - "if an instantiated attribute of the same name " - "with different storage already exists." ); - - typed_attribute.reset( new Attribute< T >{ - std::move( default_value ), std::move( properties ), {} } ); - register_attribute( typed_attribute, name ); - return typed_attribute; + OpenGeodeBasicException::check_exception( + typed_attribute.get() == nullptr, nullptr, + OpenGeodeException::TYPE::data, + "[AttributeManager::create_attribute] Attribute with id '", + attribute_id.string(), "' already exists." ); + typed_attribute = std::make_unique< Attribute< T > >( + std::move( default_value ), attribute_name, + std::move( properties ), AttributeBase::AttributeKey{} ); + IdentifierBuilder builder{ *typed_attribute }; + builder.set_id( attribute_id ); + register_attribute( typed_attribute, attribute_id ); } template < template < typename > class Attribute, typename T > - std::shared_ptr< Attribute< T > > find_or_create_attribute( - std::string_view name, T default_value ) + [[nodiscard]] geode::uuid create_attribute( + std::string_view attribute_name, + T default_value, + AttributeProperties properties ) { - return find_or_create_attribute< Attribute, T >( - name, std::move( default_value ), AttributeProperties{} ); + geode::uuid attribute_id; + create_attribute< Attribute, T >( attribute_name, attribute_id, + std::move( default_value ), std::move( properties ) ); + return attribute_id; } /*! @@ -194,35 +190,31 @@ namespace geode [[nodiscard]] bool has_interpolable_attributes() const; /*! - * Get all the associated attribute names + * Get all the associated attribute ids */ - [[nodiscard]] absl::FixedArray< std::string_view > - attribute_names() const; + [[nodiscard]] absl::FixedArray< geode::uuid > attribute_ids() const; /*! - * Return true if an attribute matching the given name. - * @param[in] name The attribute name to use + * Return true if an attribute matching the given id. + * @param[in] id The attribute id to use */ - [[nodiscard]] bool attribute_exists( std::string_view name ) const; + [[nodiscard]] bool attribute_exists( const geode::uuid& ) const; /*! - * Delete the attribute matching the given name. - * Do nothing if the name does not exist. - * @param[in] name The attribute name to delete + * Delete the attribute matching the given id. + * Do nothing if the id does not exist. + * @param[in] id The attribute id to delete */ - void delete_attribute( std::string_view name ); + void delete_attribute( const geode::uuid& ); /*! - * Get the typeid name of the attribute type - * @param[in] name The attribute name to use + * Get the typeid id of the attribute type + * @param[in] id The attribute id to use */ [[nodiscard]] std::string_view attribute_type( - std::string_view name ) const; - - void rename_attribute( - std::string_view old_name, std::string_view new_name ); + const geode::uuid& ) const; - void set_attribute_properties( std::string_view attribute_name, + void set_attribute_properties( geode::uuid attribute_id, const AttributeProperties& new_properties ); /*! @@ -255,6 +247,12 @@ namespace geode */ [[nodiscard]] index_t nb_elements() const; + [[nodiscard]] std::optional< std::string_view > attribute_name( + const uuid& ) const; + + [[nodiscard]] std::optional< std::vector< uuid > > + attribute_ids_matching_name( std::string_view name ) const; + void copy( const AttributeManager& attribute_manager ); void import( const AttributeManager& attribute_manager, @@ -262,14 +260,14 @@ namespace geode void import( const AttributeManager& attribute_manager, absl::Span< const index_t > old2new, - std::string_view attribute_name ); + const uuid& attribute_id ); void import( const AttributeManager& attribute_manager, const GenericMapping< index_t >& old2new_mapping ); void import( const AttributeManager& attribute_manager, const GenericMapping< index_t >& old2new_mapping, - std::string_view attribute_name ); + const uuid& attribute_id ); private: friend class bitsery::Access; @@ -279,24 +277,24 @@ namespace geode [[nodiscard]] absl::Mutex& mutex() const; /*! - * Find the Attribute associated with the given name + * Find the Attribute associated with the given id * regardless the content type - * @param[in] name The attribute name to search for - * @return The associated store. If the name was not found, + * @param[in] id The attribute id to search for + * @return The associated store. If the id was not found, * the shared pointer is empty. */ [[nodiscard]] std::shared_ptr< AttributeBase > find_attribute_base( - std::string_view name ) const; + const geode::uuid& ) const; /*! - * Register an Attribute to the given name. - * If the given name already exists in the manager, the new attribute + * Register an Attribute to the given id. + * If the given id already exists in the manager, the new attribute * will override the old one. * @param[in] attribute The attribute to register - * @param[in] name The associated name to the store + * @param[in] id The associated id to the store */ void register_attribute( - std::shared_ptr< AttributeBase > attribute, std::string_view name ); + std::shared_ptr< AttributeBase > attribute, const geode::uuid& ); private: IMPLEMENTATION_MEMBER( impl_ ); diff --git a/include/geode/basic/bitsery_archive.hpp b/include/geode/basic/bitsery_archive.hpp index d53f99426..40ffc3486 100644 --- a/include/geode/basic/bitsery_archive.hpp +++ b/include/geode/basic/bitsery_archive.hpp @@ -31,6 +31,8 @@ #include #include +#include +#include #include #include @@ -46,6 +48,11 @@ namespace geode using Deserializer = bitsery::Deserializer< bitsery::InputStreamAdapter, TContext >; + enum struct BITSERY + { + constructor + }; + /*! * Register all the information needed by Bitsery to serialize the objects * in the basic library. diff --git a/include/geode/basic/constant_attribute.hpp b/include/geode/basic/constant_attribute.hpp index c57ee08b2..05eeba76a 100644 --- a/include/geode/basic/constant_attribute.hpp +++ b/include/geode/basic/constant_attribute.hpp @@ -36,6 +36,7 @@ #include #include #include +#include #include #include @@ -56,9 +57,11 @@ namespace geode public: ConstantAttribute( T value, + std::string_view name, AttributeProperties properties, AttributeBase::AttributeKey /*key*/ ) - : ConstantAttribute( std::move( value ), std::move( properties ) ) + : ConstantAttribute( + std::move( value ), name, std::move( properties ) ) { } @@ -102,14 +105,18 @@ namespace geode } private: - ConstantAttribute( T value, AttributeProperties properties ) - : ReadOnlyAttribute< T >( std::move( properties ) ) + ConstantAttribute( + T value, std::string_view name, AttributeProperties properties ) + : ReadOnlyAttribute< T >( name, std::move( properties ) ) { set_value( std::move( value ) ); } + ConstantAttribute( std::string_view name ) + : ReadOnlyAttribute< T >( name, AttributeProperties{} ) {}; + ConstantAttribute() - : ReadOnlyAttribute< T >( AttributeProperties{} ) {}; + : ReadOnlyAttribute< T >( "default", AttributeProperties{} ) {}; template < typename Archive > void serialize( Archive& serializer ) @@ -150,8 +157,11 @@ namespace geode AttributeBase::AttributeKey /*key*/ ) const override { std::shared_ptr< ConstantAttribute< T > > attribute{ - new ConstantAttribute< T >{ value_, this->properties() } + new ConstantAttribute< T >{ + value_, this->name().value(), this->properties() } }; + IdentifierBuilder builder{ *attribute }; + builder.set_id( this->id() ); return attribute; } @@ -169,7 +179,8 @@ namespace geode AttributeBase::AttributeKey /*key*/ ) const override { std::shared_ptr< ConstantAttribute< T > > attribute{ - new ConstantAttribute< T >{ value_, this->properties() } + new ConstantAttribute< T >{ + value_, this->name().value(), this->properties() } }; return attribute; } @@ -180,7 +191,8 @@ namespace geode AttributeBase::AttributeKey /*key*/ ) const override { std::shared_ptr< ConstantAttribute< T > > attribute{ - new ConstantAttribute< T >{ value_, this->properties() } + new ConstantAttribute< T >{ + value_, this->name().value(), this->properties() } }; return attribute; } diff --git a/include/geode/basic/growable.hpp b/include/geode/basic/growable.hpp index 8a9ebb472..d6c44064a 100644 --- a/include/geode/basic/growable.hpp +++ b/include/geode/basic/growable.hpp @@ -28,6 +28,7 @@ #include #include +#include #include namespace geode diff --git a/include/geode/basic/sparse_attribute.hpp b/include/geode/basic/sparse_attribute.hpp index b9449d551..1a2a0189d 100644 --- a/include/geode/basic/sparse_attribute.hpp +++ b/include/geode/basic/sparse_attribute.hpp @@ -41,6 +41,7 @@ #include #include #include +#include #include #include #include @@ -63,10 +64,11 @@ namespace geode public: SparseAttribute( T default_value, + std::string_view name, AttributeProperties properties, AttributeBase::AttributeKey /*key*/ ) : SparseAttribute( - std::move( default_value ), std::move( properties ) ) + std::move( default_value ), name, std::move( properties ) ) { } @@ -113,14 +115,24 @@ namespace geode } private: - SparseAttribute( T default_value, AttributeProperties properties ) - : ReadOnlyAttribute< T >( std::move( properties ) ), + SparseAttribute( T default_value, + std::string_view name, + AttributeProperties properties ) + : ReadOnlyAttribute< T >( name, std::move( properties ) ), default_value_( std::move( default_value ) ) { values_.reserve( 10 ); } - SparseAttribute() : ReadOnlyAttribute< T >( AttributeProperties{} ) {} + SparseAttribute( std::string_view name ) + : ReadOnlyAttribute< T >( name, AttributeProperties{} ) + { + } + + SparseAttribute() + : ReadOnlyAttribute< T >( "default", AttributeProperties{} ) + { + } template < typename Archive > void serialize( Archive& serializer ) @@ -186,8 +198,11 @@ namespace geode AttributeBase::AttributeKey /*key*/ ) const override { std::shared_ptr< SparseAttribute< T > > attribute{ - new SparseAttribute< T >{ default_value_, this->properties() } + new SparseAttribute< T >{ + default_value_, this->name().value(), this->properties() } }; + IdentifierBuilder builder{ *attribute }; + builder.set_id( this->id() ); attribute->values_ = values_; return attribute; } @@ -217,7 +232,8 @@ namespace geode AttributeBase::AttributeKey /*key*/ ) const override { std::shared_ptr< SparseAttribute< T > > attribute{ - new SparseAttribute< T >{ default_value_, this->properties() } + new SparseAttribute< T >{ + default_value_, this->name().value(), this->properties() } }; for( const auto i : Indices{ old2new } ) { @@ -242,7 +258,8 @@ namespace geode AttributeBase::AttributeKey /*key*/ ) const override { std::shared_ptr< SparseAttribute< T > > attribute{ - new SparseAttribute< T >{ default_value_, this->properties() } + new SparseAttribute< T >{ + default_value_, this->name().value(), this->properties() } }; for( const auto& [in, outs] : old2new_mapping.in2out_map() ) { diff --git a/include/geode/basic/variable_attribute.hpp b/include/geode/basic/variable_attribute.hpp index f9ccb5d5b..f46e65b6a 100644 --- a/include/geode/basic/variable_attribute.hpp +++ b/include/geode/basic/variable_attribute.hpp @@ -36,6 +36,7 @@ #include #include #include +#include #include #include #include @@ -57,10 +58,11 @@ namespace geode public: VariableAttribute( T default_value, + std::string_view name, AttributeProperties properties, AttributeBase::AttributeKey /*key*/ ) : VariableAttribute( - std::move( default_value ), std::move( properties ) ) + std::move( default_value ), name, std::move( properties ) ) { } @@ -106,15 +108,20 @@ namespace geode } protected: - VariableAttribute( T default_value, AttributeProperties properties ) - : ReadOnlyAttribute< T >( std::move( properties ) ), + VariableAttribute( T default_value, + std::string_view name, + AttributeProperties properties ) + : ReadOnlyAttribute< T >( name, std::move( properties ) ), default_value_( std::move( default_value ) ) { values_.reserve( 10 ); } + VariableAttribute( std::string_view name ) + : ReadOnlyAttribute< T >( name, AttributeProperties{} ) {}; + VariableAttribute() - : ReadOnlyAttribute< T >( AttributeProperties{} ) {}; + : ReadOnlyAttribute< T >( "default", AttributeProperties{} ) {}; template < typename Archive > void serialize( Archive& serializer ) @@ -170,8 +177,11 @@ namespace geode AttributeBase::AttributeKey /*key*/ ) const override { std::shared_ptr< VariableAttribute< T > > attribute{ - new VariableAttribute< T >{ default_value_, this->properties() } + new VariableAttribute< T >{ + default_value_, this->name().value(), this->properties() } }; + IdentifierBuilder builder{ *attribute }; + builder.set_id( this->id() ); attribute->values_ = values_; return attribute; } @@ -199,7 +209,8 @@ namespace geode AttributeBase::AttributeKey /*key*/ ) const override { std::shared_ptr< VariableAttribute< T > > attribute{ - new VariableAttribute< T >{ default_value_, this->properties() } + new VariableAttribute< T >{ + default_value_, this->name().value(), this->properties() } }; attribute->values_.resize( nb_elements, default_value_ ); for( const auto i : Indices{ old2new } ) @@ -228,7 +239,8 @@ namespace geode AttributeBase::AttributeKey /*key*/ ) const override { std::shared_ptr< VariableAttribute< T > > attribute{ - new VariableAttribute< T >{ default_value_, this->properties() } + new VariableAttribute< T >{ + default_value_, this->name().value(), this->properties() } }; attribute->values_.resize( nb_elements, default_value_ ); for( const auto& [input, outputs] : old2new_mapping.in2out_map() ) @@ -307,9 +319,10 @@ namespace geode public: VariableAttribute( bool default_value, + std::string_view name, AttributeProperties properties, AttributeBase::AttributeKey /*key*/ ) - : VariableAttribute( default_value, std::move( properties ) ) + : VariableAttribute( default_value, name, std::move( properties ) ) { } @@ -355,15 +368,22 @@ namespace geode } protected: - VariableAttribute( bool default_value, AttributeProperties properties ) - : ReadOnlyAttribute< bool >( std::move( properties ) ), + VariableAttribute( bool default_value, + std::string_view name, + AttributeProperties properties ) + : ReadOnlyAttribute< bool >( name, std::move( properties ) ), default_value_( default_value ) { values_.reserve( 10 ); } + VariableAttribute( std::string_view name ) + : ReadOnlyAttribute< bool >( name, AttributeProperties{} ) {}; + VariableAttribute() - : ReadOnlyAttribute< bool >( AttributeProperties{} ) {}; + : ReadOnlyAttribute< bool >( "default", AttributeProperties{} ) + { + } template < typename Archive > void serialize( Archive& serializer ) @@ -417,7 +437,8 @@ namespace geode { std::shared_ptr< VariableAttribute< bool > > attribute{ new VariableAttribute< bool >{ - static_cast< bool >( default_value_ ), this->properties() } + static_cast< bool >( default_value_ ), this->name().value(), + this->properties() } }; attribute->values_ = values_; return attribute; @@ -447,7 +468,8 @@ namespace geode { std::shared_ptr< VariableAttribute< bool > > attribute{ new VariableAttribute< bool >{ - static_cast< bool >( default_value_ ), this->properties() } + static_cast< bool >( default_value_ ), this->name().value(), + this->properties() } }; attribute->values_.resize( nb_elements, default_value_ ); for( const auto i : Indices{ old2new } ) @@ -477,7 +499,8 @@ namespace geode { std::shared_ptr< VariableAttribute< bool > > attribute{ new VariableAttribute< bool >{ - static_cast< bool >( default_value_ ), this->properties() } + static_cast< bool >( default_value_ ), this->name().value(), + this->properties() } }; attribute->values_.resize( nb_elements, default_value_ ); for( const auto& [in, outs] : old2new_mapping.in2out_map() ) diff --git a/include/geode/mesh/builder/geode/geode_vertex_set_builder.hpp b/include/geode/mesh/builder/geode/geode_vertex_set_builder.hpp index bf676c631..15446f63f 100644 --- a/include/geode/mesh/builder/geode/geode_vertex_set_builder.hpp +++ b/include/geode/mesh/builder/geode/geode_vertex_set_builder.hpp @@ -59,8 +59,5 @@ namespace geode void do_permute_vertices( absl::Span< const index_t > permutation, absl::Span< const index_t > old2new ) final; - - private: - [[maybe_unused]] OpenGeodeVertexSet& geode_vertex_set_; }; } // namespace geode diff --git a/include/geode/mesh/core/attribute_coordinate_reference_system.hpp b/include/geode/mesh/core/attribute_coordinate_reference_system.hpp index ad1374547..604f9ec9e 100644 --- a/include/geode/mesh/core/attribute_coordinate_reference_system.hpp +++ b/include/geode/mesh/core/attribute_coordinate_reference_system.hpp @@ -43,7 +43,7 @@ namespace geode public: explicit AttributeCoordinateReferenceSystem( - AttributeManager& manager ); + AttributeManager& manager, const geode::uuid& uuid ); AttributeCoordinateReferenceSystem( AttributeManager& manager, std::string_view attribute_name ); ~AttributeCoordinateReferenceSystem(); @@ -67,6 +67,8 @@ namespace geode [[nodiscard]] index_t nb_points() const; + [[nodiscard]] uuid attribute_id() const; + protected: AttributeCoordinateReferenceSystem(); diff --git a/include/geode/mesh/core/detail/facet_storage.hpp b/include/geode/mesh/core/detail/facet_storage.hpp index 16d7e68e3..37a855531 100644 --- a/include/geode/mesh/core/detail/facet_storage.hpp +++ b/include/geode/mesh/core/detail/facet_storage.hpp @@ -44,7 +44,6 @@ namespace geode class FacetStorage { using TypedVertexCycle = VertexCycle< VertexContainer >; - static constexpr auto ATTRIBUTE_NAME = "facet_vertices"; friend class bitsery::Access; public: @@ -58,17 +57,26 @@ namespace geode } protected: + FacetStorage( BITSERY ) {} + FacetStorage() - : counter_( facet_attribute_manager_ - .template find_or_create_attribute< VariableAttribute, - index_t >( - "counter", 1u, { false, false, false } ) ), - vertices_( facet_attribute_manager_ - .template find_or_create_attribute< VariableAttribute, - VertexContainer >( attribute_name(), - VertexContainer(), - { false, false, false } ) ) { + const auto counter_attribute_id = + facet_attribute_manager_ + .create_attribute< VariableAttribute, index_t >( + "counter", 1u, { false, false, false } ); + counter_ = facet_attribute_manager_ + .find_attribute< VariableAttribute, index_t >( + counter_attribute_id ); + const auto vertices_attribute_id = + facet_attribute_manager_ + .create_attribute< VariableAttribute, VertexContainer >( + "facet_vertices", VertexContainer{}, + { false, false, false } ); + vertices_ = + facet_attribute_manager_ + .find_attribute< VariableAttribute, VertexContainer >( + vertices_attribute_id ); } [[nodiscard]] AttributeManager& facet_attribute_manager() const @@ -221,17 +229,10 @@ namespace geode } protected: - static constexpr std::string_view attribute_name() - { - return ATTRIBUTE_NAME; - } - void update_attribute() { - vertices_ = - facet_attribute_manager_.template find_or_create_attribute< - VariableAttribute, VertexContainer >( attribute_name(), - VertexContainer{}, { false, false, false } ); + vertices_ = facet_attribute_manager_.template find_attribute< + VariableAttribute, VertexContainer >( vertices_->id() ); } [[nodiscard]] index_t get_counter( index_t facet_id ) const @@ -243,13 +244,13 @@ namespace geode { facet_attribute_manager_.copy( from.facet_attribute_manager() ); facet_indices_ = from.facet_indices_; - counter_ = + counter_ = facet_attribute_manager_ + .find_attribute< VariableAttribute, index_t >( + from.counter_->id() ); + vertices_ = facet_attribute_manager_ - .find_or_create_attribute< VariableAttribute, index_t >( - "counter", 1u, { false, false, false } ); - vertices_ = facet_attribute_manager_.find_or_create_attribute< - VariableAttribute, VertexContainer >( attribute_name(), - VertexContainer{}, { false, false, false } ); + .find_attribute< VariableAttribute, VertexContainer >( + from.vertices_->id() ); } private: diff --git a/include/geode/mesh/core/edged_curve.hpp b/include/geode/mesh/core/edged_curve.hpp index 008337456..fb77bc665 100644 --- a/include/geode/mesh/core/edged_curve.hpp +++ b/include/geode/mesh/core/edged_curve.hpp @@ -23,6 +23,7 @@ #pragma once +#include #include #include @@ -50,6 +51,8 @@ namespace geode using Builder = EdgedCurveBuilder< dimension >; static constexpr auto dim = dimension; + EdgedCurve( BITSERY ); + ~EdgedCurve(); [[nodiscard]] static std::unique_ptr< EdgedCurve< dimension > > diff --git a/include/geode/mesh/core/geode/geode_edged_curve.hpp b/include/geode/mesh/core/geode/geode_edged_curve.hpp index 847036685..4514eec26 100644 --- a/include/geode/mesh/core/geode/geode_edged_curve.hpp +++ b/include/geode/mesh/core/geode/geode_edged_curve.hpp @@ -23,6 +23,7 @@ #pragma once +#include #include #include @@ -49,6 +50,7 @@ namespace geode static constexpr auto dim = dimension; OpenGeodeEdgedCurve(); + OpenGeodeEdgedCurve( BITSERY ); OpenGeodeEdgedCurve( OpenGeodeEdgedCurve&& other ) noexcept; OpenGeodeEdgedCurve& operator=( OpenGeodeEdgedCurve&& other ) noexcept; ~OpenGeodeEdgedCurve(); @@ -82,10 +84,6 @@ namespace geode } public: - void set_vertex( index_t vertex_id, - Point< dimension > point, - OGEdgedCurveKey /*key*/ ); - void set_edge_vertex( const EdgeVertex& edge_vertex, index_t vertex_id, OGEdgedCurveKey /*key*/ ); diff --git a/include/geode/mesh/core/geode/geode_graph.hpp b/include/geode/mesh/core/geode/geode_graph.hpp index 76d9f4325..406ae3b97 100644 --- a/include/geode/mesh/core/geode/geode_graph.hpp +++ b/include/geode/mesh/core/geode/geode_graph.hpp @@ -23,6 +23,7 @@ #pragma once +#include #include #include @@ -44,6 +45,7 @@ namespace geode using Builder = OpenGeodeGraphBuilder; OpenGeodeGraph(); + OpenGeodeGraph( BITSERY ); OpenGeodeGraph( OpenGeodeGraph&& other ) noexcept; OpenGeodeGraph& operator=( OpenGeodeGraph&& other ) noexcept; ~OpenGeodeGraph(); diff --git a/include/geode/mesh/core/geode/geode_hybrid_solid.hpp b/include/geode/mesh/core/geode/geode_hybrid_solid.hpp index 203d45ffc..4e1997eae 100644 --- a/include/geode/mesh/core/geode/geode_hybrid_solid.hpp +++ b/include/geode/mesh/core/geode/geode_hybrid_solid.hpp @@ -25,6 +25,7 @@ #include +#include #include #include @@ -51,6 +52,7 @@ namespace geode static constexpr auto dim = dimension; OpenGeodeHybridSolid(); + OpenGeodeHybridSolid( BITSERY ); OpenGeodeHybridSolid( OpenGeodeHybridSolid&& other ) noexcept; OpenGeodeHybridSolid& operator=( OpenGeodeHybridSolid&& other ) noexcept; @@ -85,10 +87,6 @@ namespace geode } public: - void set_vertex( index_t vertex_id, - Point< dimension > point, - OGHybridSolidKey /*key*/ ); - void set_polyhedron_vertex( const PolyhedronVertex& polyhedron_vertex, index_t vertex_id, OGHybridSolidKey /*key*/ ); diff --git a/include/geode/mesh/core/geode/geode_point_set.hpp b/include/geode/mesh/core/geode/geode_point_set.hpp index 023dad010..9ef33a5a9 100644 --- a/include/geode/mesh/core/geode/geode_point_set.hpp +++ b/include/geode/mesh/core/geode/geode_point_set.hpp @@ -25,6 +25,7 @@ #include +#include #include #include @@ -50,6 +51,7 @@ namespace geode static constexpr auto dim = dimension; OpenGeodePointSet(); + OpenGeodePointSet( BITSERY ); OpenGeodePointSet( OpenGeodePointSet&& other ) noexcept; OpenGeodePointSet& operator=( OpenGeodePointSet&& other ) noexcept; ~OpenGeodePointSet(); @@ -82,11 +84,6 @@ namespace geode return native_extension_static(); } - public: - void set_vertex( index_t vertex_id, - Point< dimension > point, - OGPointSetKey /*key*/ ); - private: friend class bitsery::Access; template < typename Archive > diff --git a/include/geode/mesh/core/geode/geode_polygonal_surface.hpp b/include/geode/mesh/core/geode/geode_polygonal_surface.hpp index 7b1b570c1..1ca923754 100644 --- a/include/geode/mesh/core/geode/geode_polygonal_surface.hpp +++ b/include/geode/mesh/core/geode/geode_polygonal_surface.hpp @@ -23,6 +23,7 @@ #pragma once +#include #include #include @@ -49,6 +50,7 @@ namespace geode static constexpr auto dim = dimension; OpenGeodePolygonalSurface(); + OpenGeodePolygonalSurface( BITSERY ); OpenGeodePolygonalSurface( OpenGeodePolygonalSurface&& other ) noexcept; OpenGeodePolygonalSurface& operator=( OpenGeodePolygonalSurface&& other ) noexcept; @@ -83,10 +85,6 @@ namespace geode } public: - void set_vertex( index_t vertex_id, - Point< dimension > point, - OGPolygonalSurfaceKey /*key*/ ); - void set_polygon_vertex( const PolygonVertex& polygon_vertex, index_t vertex_id, OGPolygonalSurfaceKey /*key*/ ); diff --git a/include/geode/mesh/core/geode/geode_polyhedral_solid.hpp b/include/geode/mesh/core/geode/geode_polyhedral_solid.hpp index 2c0a92f19..bae5f00c9 100644 --- a/include/geode/mesh/core/geode/geode_polyhedral_solid.hpp +++ b/include/geode/mesh/core/geode/geode_polyhedral_solid.hpp @@ -23,6 +23,7 @@ #pragma once +#include #include #include @@ -49,6 +50,7 @@ namespace geode static constexpr auto dim = dimension; OpenGeodePolyhedralSolid(); + OpenGeodePolyhedralSolid( BITSERY ); OpenGeodePolyhedralSolid( OpenGeodePolyhedralSolid&& other ) noexcept; OpenGeodePolyhedralSolid& operator=( OpenGeodePolyhedralSolid&& other ) noexcept; @@ -83,10 +85,6 @@ namespace geode } public: - void set_vertex( index_t vertex_id, - Point< dimension > point, - OGPolyhedralSolidKey /*key*/ ); - void add_polyhedron( absl::Span< const index_t > vertices, absl::Span< const std::vector< local_index_t > > facets, OGPolyhedralSolidKey /*key*/ ); diff --git a/include/geode/mesh/core/geode/geode_regular_grid_solid.hpp b/include/geode/mesh/core/geode/geode_regular_grid_solid.hpp index 4fb139caa..c9dd2dd5c 100644 --- a/include/geode/mesh/core/geode/geode_regular_grid_solid.hpp +++ b/include/geode/mesh/core/geode/geode_regular_grid_solid.hpp @@ -25,6 +25,7 @@ #include +#include #include #include @@ -52,6 +53,7 @@ namespace geode static constexpr index_t dim{ 3 }; OpenGeodeRegularGrid(); + OpenGeodeRegularGrid( BITSERY ); OpenGeodeRegularGrid( OpenGeodeRegularGrid&& other ) noexcept; OpenGeodeRegularGrid& operator=( OpenGeodeRegularGrid&& other ) noexcept; diff --git a/include/geode/mesh/core/geode/geode_regular_grid_surface.hpp b/include/geode/mesh/core/geode/geode_regular_grid_surface.hpp index a19e7d219..467f5bd3a 100644 --- a/include/geode/mesh/core/geode/geode_regular_grid_surface.hpp +++ b/include/geode/mesh/core/geode/geode_regular_grid_surface.hpp @@ -25,6 +25,7 @@ #include +#include #include #include @@ -52,6 +53,7 @@ namespace geode static constexpr index_t dim{ 2 }; OpenGeodeRegularGrid(); + OpenGeodeRegularGrid( BITSERY ); OpenGeodeRegularGrid( OpenGeodeRegularGrid&& other ) noexcept; OpenGeodeRegularGrid& operator=( OpenGeodeRegularGrid&& other ) noexcept; diff --git a/include/geode/mesh/core/geode/geode_tetrahedral_solid.hpp b/include/geode/mesh/core/geode/geode_tetrahedral_solid.hpp index af8687649..f59af0f21 100644 --- a/include/geode/mesh/core/geode/geode_tetrahedral_solid.hpp +++ b/include/geode/mesh/core/geode/geode_tetrahedral_solid.hpp @@ -25,6 +25,7 @@ #include +#include #include #include @@ -51,6 +52,7 @@ namespace geode static constexpr auto dim = dimension; OpenGeodeTetrahedralSolid(); + OpenGeodeTetrahedralSolid( BITSERY ); OpenGeodeTetrahedralSolid( OpenGeodeTetrahedralSolid&& other ) noexcept; OpenGeodeTetrahedralSolid& operator=( OpenGeodeTetrahedralSolid&& other ) noexcept; @@ -85,10 +87,6 @@ namespace geode } public: - void set_vertex( index_t vertex_id, - Point< dimension > point, - OGTetrahedralSolidKey /*key*/ ); - void set_polyhedron_vertex( const PolyhedronVertex& polyhedron_vertex, index_t vertex_id, OGTetrahedralSolidKey /*key*/ ); diff --git a/include/geode/mesh/core/geode/geode_triangulated_surface.hpp b/include/geode/mesh/core/geode/geode_triangulated_surface.hpp index 9ce4844ca..97dc1b625 100644 --- a/include/geode/mesh/core/geode/geode_triangulated_surface.hpp +++ b/include/geode/mesh/core/geode/geode_triangulated_surface.hpp @@ -25,6 +25,7 @@ #include +#include #include #include @@ -51,6 +52,7 @@ namespace geode static constexpr auto dim = dimension; OpenGeodeTriangulatedSurface(); + OpenGeodeTriangulatedSurface( BITSERY bitsery ); OpenGeodeTriangulatedSurface( OpenGeodeTriangulatedSurface&& other ) noexcept; OpenGeodeTriangulatedSurface& operator=( @@ -86,10 +88,6 @@ namespace geode } public: - void set_vertex( index_t vertex_id, - Point< dimension > point, - OGTriangulatedSurfaceKey /*key*/ ); - void set_polygon_vertex( const PolygonVertex& polygon_vertex, index_t vertex_id, OGTriangulatedSurfaceKey /*key*/ ); diff --git a/include/geode/mesh/core/geode/geode_vertex_set.hpp b/include/geode/mesh/core/geode/geode_vertex_set.hpp index 067015c4b..f1eeb19c1 100644 --- a/include/geode/mesh/core/geode/geode_vertex_set.hpp +++ b/include/geode/mesh/core/geode/geode_vertex_set.hpp @@ -25,6 +25,7 @@ #include +#include #include #include @@ -42,6 +43,9 @@ namespace geode public: using Builder = OpenGeodeVertexSetBuilder; + OpenGeodeVertexSet() = default; + OpenGeodeVertexSet( BITSERY ) {}; + [[nodiscard]] static MeshImpl impl_name_static() { return MeshImpl{ "OpenGeodeVertexSet" }; diff --git a/include/geode/mesh/core/graph.hpp b/include/geode/mesh/core/graph.hpp index a9e0af3ef..2d00c9c04 100644 --- a/include/geode/mesh/core/graph.hpp +++ b/include/geode/mesh/core/graph.hpp @@ -29,6 +29,7 @@ #include #include +#include #include #include @@ -111,6 +112,8 @@ namespace geode public: using Builder = GraphBuilder; + Graph( BITSERY ); + ~Graph(); /*! diff --git a/include/geode/mesh/core/hybrid_solid.hpp b/include/geode/mesh/core/hybrid_solid.hpp index 52ab85443..9afcf86f1 100644 --- a/include/geode/mesh/core/hybrid_solid.hpp +++ b/include/geode/mesh/core/hybrid_solid.hpp @@ -26,6 +26,8 @@ #include #include +#include + namespace geode { FORWARD_DECLARATION_DIMENSION_CLASS( HybridSolidBuilder ); @@ -51,6 +53,8 @@ namespace geode pyramid }; + HybridSolid( BITSERY ); + /*! * Create a new HybridSolid using default data structure. */ diff --git a/include/geode/mesh/core/internal/edges_impl.hpp b/include/geode/mesh/core/internal/edges_impl.hpp index be63fe690..e90e90c2d 100644 --- a/include/geode/mesh/core/internal/edges_impl.hpp +++ b/include/geode/mesh/core/internal/edges_impl.hpp @@ -37,13 +37,20 @@ namespace geode class EdgesImpl { public: - explicit EdgesImpl( Graph& graph ) - : edges_( graph.edge_attribute_manager() - .template find_or_create_attribute< VariableAttribute, - std::array< index_t, 2 > >( "edges", - std::array< index_t, 2 >{ NO_ID, NO_ID }, - { false, false, false } ) ) + static constexpr auto EDGES_NAME = "edges"; + + explicit EdgesImpl( Graph& graph ) : edges_() { + const auto edge_attribute_id = + graph.edge_attribute_manager() + .template create_attribute< VariableAttribute, + std::array< index_t, 2 > >( "edges", + std::array< index_t, 2 >{ NO_ID, NO_ID }, + { false, false, false } ); + edges_ = + graph.edge_attribute_manager() + .template find_attribute< VariableAttribute, + std::array< index_t, 2 > >( edge_attribute_id ); } [[nodiscard]] index_t get_edge_vertex( @@ -63,6 +70,11 @@ namespace geode } ); } + [[nodiscard]] const uuid& edges_attribute_id() const + { + return edges_->id(); + } + protected: EdgesImpl() = default; @@ -93,6 +105,5 @@ namespace geode std::shared_ptr< VariableAttribute< std::array< index_t, 2 > > > edges_; }; - } // namespace internal } // namespace geode diff --git a/include/geode/mesh/core/internal/facet_edges_impl.hpp b/include/geode/mesh/core/internal/facet_edges_impl.hpp index 9a257a1b1..6749d1cdd 100644 --- a/include/geode/mesh/core/internal/facet_edges_impl.hpp +++ b/include/geode/mesh/core/internal/facet_edges_impl.hpp @@ -44,6 +44,10 @@ namespace geode public: FacetEdgesImpl() = default; + FacetEdgesImpl( BITSERY bitsery ) + : detail::FacetStorage< std::array< index_t, 2 > >( bitsery ) + { + } [[nodiscard]] std::optional< index_t > find_edge( const std::array< index_t, 2 >& edge_vertices ) const diff --git a/include/geode/mesh/core/internal/points_impl.hpp b/include/geode/mesh/core/internal/points_impl.hpp index 0c09c9610..3262665fb 100644 --- a/include/geode/mesh/core/internal/points_impl.hpp +++ b/include/geode/mesh/core/internal/points_impl.hpp @@ -52,6 +52,26 @@ namespace geode public: static constexpr auto POINTS_NAME = "points"; + PointsImpl() = default; + + PointsImpl( + AttributeManager& manager, std::string_view attribute_name ) + { + const auto attribute_id = + manager.template create_attribute< VariableAttribute, + Point< dimension > >( attribute_name, + Point< dimension >{}, { false, false, false } ); + points_ = manager.template find_attribute< VariableAttribute, + Point< dimension > >( attribute_id ); + } + + PointsImpl( + AttributeManager& manager, const geode::uuid& attribute_id ) + { + points_ = manager.template find_attribute< VariableAttribute, + Point< dimension > >( attribute_id ); + } + [[nodiscard]] const Point< dimension >& get_point( index_t vertex_id ) const { @@ -70,17 +90,12 @@ namespace geode [[nodiscard]] std::string_view attribute_name() const { - return points_->name(); + return points_->name().value(); } - template < typename Mesh > - void initialize_crs( Mesh& mesh ) + [[nodiscard]] const uuid& attribute_id() const { - CoordinateReferenceSystemManagersBuilder< dimension >{ mesh } - .main_coordinate_reference_system_manager_builder() - .delete_coordinate_reference_system( POINTS_NAME ); - register_as_active_crs( mesh ); - points_.reset(); + return points_->id(); } private: @@ -110,49 +125,6 @@ namespace geode } } } ); } - template < typename Mesh > - void register_as_active_crs( Mesh& mesh ) - { - auto crs_manager_builder = - CoordinateReferenceSystemManagersBuilder< dimension >{ - mesh - } - .main_coordinate_reference_system_manager_builder(); - crs_manager_builder.register_coordinate_reference_system( - POINTS_NAME, - std::shared_ptr< CoordinateReferenceSystem< dimension > >{ - std::make_shared< - AttributeCoordinateReferenceSystem< dimension > >( - mesh.vertex_attribute_manager() ) } ); - crs_manager_builder.set_active_coordinate_reference_system( - POINTS_NAME ); - } - - protected: - PointsImpl() = default; - - template < typename Mesh > - explicit PointsImpl( Mesh& mesh ) - : PointsImpl( mesh.vertex_attribute_manager() ) - { - register_as_active_crs( mesh ); - } - - explicit PointsImpl( AttributeManager& manager ) - : PointsImpl{ manager, POINTS_NAME } - { - } - - PointsImpl( - AttributeManager& manager, std::string_view attribute_name ) - : points_{ manager - .template find_or_create_attribute< VariableAttribute, - Point< dimension > >( attribute_name, - Point< dimension >{}, - { false, false, false } ) } - { - } - private: std::shared_ptr< VariableAttribute< Point< dimension > > > points_; }; diff --git a/include/geode/mesh/core/internal/texture_impl.hpp b/include/geode/mesh/core/internal/texture_impl.hpp index 17992db03..2922cfe61 100644 --- a/include/geode/mesh/core/internal/texture_impl.hpp +++ b/include/geode/mesh/core/internal/texture_impl.hpp @@ -52,6 +52,11 @@ namespace geode return image_; } + [[nodiscard]] const geode::uuid& texture_id() const + { + return coordinates_->id(); + } + void set_image( RasterImage< dimension >&& image ) { image_ = std::move( image ); @@ -86,11 +91,13 @@ namespace geode } TextureImpl( AttributeManager& manager, std::string_view name ) - : coordinates_{ - manager.find_or_create_attribute< VariableAttribute, - ElementTextureCoordinates >( name, {} ) - } { + const auto texture_id = + manager.create_attribute< VariableAttribute, + ElementTextureCoordinates >( + name, {}, geode::AttributeProperties{} ); + coordinates_ = manager.find_attribute< VariableAttribute, + ElementTextureCoordinates >( texture_id ); } TextureImpl() = default; diff --git a/include/geode/mesh/core/polygonal_surface.hpp b/include/geode/mesh/core/polygonal_surface.hpp index 885da1bf7..bae65223d 100644 --- a/include/geode/mesh/core/polygonal_surface.hpp +++ b/include/geode/mesh/core/polygonal_surface.hpp @@ -47,6 +47,8 @@ namespace geode using Builder = PolygonalSurfaceBuilder< dimension >; static constexpr auto dim = dimension; + PolygonalSurface( BITSERY ); + /*! * Create a new PolygonalSurface using default data structure. */ diff --git a/include/geode/mesh/core/polyhedral_solid.hpp b/include/geode/mesh/core/polyhedral_solid.hpp index de80c7649..3c808302a 100644 --- a/include/geode/mesh/core/polyhedral_solid.hpp +++ b/include/geode/mesh/core/polyhedral_solid.hpp @@ -27,6 +27,8 @@ #include +#include + #include #include @@ -52,6 +54,8 @@ namespace geode using Builder = PolyhedralSolidBuilder< dimension >; static constexpr auto dim = dimension; + PolyhedralSolid( BITSERY ); + /*! * Create a new PolyhedralSolid using default data structure. */ diff --git a/include/geode/mesh/core/regular_grid_solid.hpp b/include/geode/mesh/core/regular_grid_solid.hpp index 32f630955..6ad609e0c 100644 --- a/include/geode/mesh/core/regular_grid_solid.hpp +++ b/include/geode/mesh/core/regular_grid_solid.hpp @@ -23,6 +23,8 @@ #pragma once +#include + #include #include #include @@ -48,6 +50,8 @@ namespace geode using Builder = RegularGridBuilder< 3 >; static constexpr index_t dim{ 3 }; + RegularGrid( BITSERY ); + /*! * Create a new RegularGrid using default data structure. */ diff --git a/include/geode/mesh/core/regular_grid_surface.hpp b/include/geode/mesh/core/regular_grid_surface.hpp index 0e19b8dfc..1932257e4 100644 --- a/include/geode/mesh/core/regular_grid_surface.hpp +++ b/include/geode/mesh/core/regular_grid_surface.hpp @@ -23,6 +23,8 @@ #pragma once +#include + #include #include #include @@ -46,6 +48,8 @@ namespace geode using Builder = RegularGridBuilder< 2 >; static constexpr index_t dim{ 2 }; + RegularGrid( BITSERY ); + /*! * Create a new RegularGrid using default data structure. */ diff --git a/include/geode/mesh/core/solid_mesh.hpp b/include/geode/mesh/core/solid_mesh.hpp index 48058090a..e9ddfe3a3 100644 --- a/include/geode/mesh/core/solid_mesh.hpp +++ b/include/geode/mesh/core/solid_mesh.hpp @@ -29,6 +29,7 @@ #include #include +#include #include #include @@ -277,6 +278,8 @@ namespace geode static constexpr auto dim = dimension; using VerticesAroundVertex = absl::InlinedVector< index_t, 20 >; + SolidMesh( BITSERY ); + ~SolidMesh(); /*! diff --git a/include/geode/mesh/core/surface_edges.hpp b/include/geode/mesh/core/surface_edges.hpp index 261916dda..a5317dce3 100644 --- a/include/geode/mesh/core/surface_edges.hpp +++ b/include/geode/mesh/core/surface_edges.hpp @@ -27,6 +27,7 @@ #include +#include #include #include #include diff --git a/include/geode/mesh/core/surface_mesh.hpp b/include/geode/mesh/core/surface_mesh.hpp index 5cd43bc17..fd8d95b6f 100644 --- a/include/geode/mesh/core/surface_mesh.hpp +++ b/include/geode/mesh/core/surface_mesh.hpp @@ -28,6 +28,7 @@ #include #include +#include #include #include @@ -170,6 +171,8 @@ namespace geode static constexpr auto dim = dimension; using VerticesAroundVertex = absl::InlinedVector< index_t, 10 >; + SurfaceMesh( BITSERY ); + ~SurfaceMesh(); /*! diff --git a/include/geode/mesh/core/tetrahedral_solid.hpp b/include/geode/mesh/core/tetrahedral_solid.hpp index 1c1515111..83d62b6a3 100644 --- a/include/geode/mesh/core/tetrahedral_solid.hpp +++ b/include/geode/mesh/core/tetrahedral_solid.hpp @@ -25,6 +25,8 @@ #include +#include + #include #include @@ -46,6 +48,8 @@ namespace geode using Builder = TetrahedralSolidBuilder< dimension >; static constexpr auto dim = dimension; + TetrahedralSolid( BITSERY ); + /*! * Create a new TetrahedralSolid using default data structure. */ diff --git a/include/geode/mesh/core/texture1d.hpp b/include/geode/mesh/core/texture1d.hpp index b6565f05c..58b1dd941 100644 --- a/include/geode/mesh/core/texture1d.hpp +++ b/include/geode/mesh/core/texture1d.hpp @@ -61,6 +61,8 @@ namespace geode void set_texture_coordinates( const EdgeVertex& vertex, const Point1D& coordinates ) const; + [[nodiscard]] uuid texture_id() const; + private: Texture(); diff --git a/include/geode/mesh/core/texture2d.hpp b/include/geode/mesh/core/texture2d.hpp index 1f7e2545c..a3c13bdee 100644 --- a/include/geode/mesh/core/texture2d.hpp +++ b/include/geode/mesh/core/texture2d.hpp @@ -61,6 +61,8 @@ namespace geode void set_texture_coordinates( const PolygonVertex& vertex, const Point2D& coordinates ) const; + [[nodiscard]] uuid texture_id() const; + private: Texture(); diff --git a/include/geode/mesh/core/texture3d.hpp b/include/geode/mesh/core/texture3d.hpp index dc8cbee84..5ff9eafc9 100644 --- a/include/geode/mesh/core/texture3d.hpp +++ b/include/geode/mesh/core/texture3d.hpp @@ -61,6 +61,8 @@ namespace geode void set_texture_coordinates( const PolyhedronVertex& vertex, const Point3D& coordinates ) const; + [[nodiscard]] uuid texture_id() const; + private: Texture(); diff --git a/include/geode/mesh/core/triangulated_surface.hpp b/include/geode/mesh/core/triangulated_surface.hpp index a96390eb8..e264f1ce4 100644 --- a/include/geode/mesh/core/triangulated_surface.hpp +++ b/include/geode/mesh/core/triangulated_surface.hpp @@ -23,6 +23,8 @@ #pragma once +#include + #include #include @@ -45,6 +47,8 @@ namespace geode using Builder = TriangulatedSurfaceBuilder< dimension >; static constexpr auto dim = dimension; + TriangulatedSurface( BITSERY ); + /*! * Create a new TriangulatedSurface using default data structure. */ diff --git a/include/geode/mesh/helpers/detail/initialize_crs.hpp b/include/geode/mesh/helpers/detail/initialize_crs.hpp new file mode 100644 index 000000000..e8ceb80c4 --- /dev/null +++ b/include/geode/mesh/helpers/detail/initialize_crs.hpp @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2019 - 2026 Geode-solutions + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + */ + +#pragma once + +#include + +#include +#include +#include + +namespace geode +{ + namespace detail + { + template < typename Mesh > + void initialize_crs( Mesh &mesh ) + { + CoordinateReferenceSystemManagersBuilder< Mesh::dim >{ mesh } + .main_coordinate_reference_system_manager_builder() + .delete_coordinate_reference_system( + internal::PointsImpl< Mesh::dim >::POINTS_NAME ); + auto crs_manager_builder = + CoordinateReferenceSystemManagersBuilder< Mesh::dim >{ mesh } + .main_coordinate_reference_system_manager_builder(); + crs_manager_builder.register_coordinate_reference_system( + internal::PointsImpl< Mesh::dim >::POINTS_NAME, + std::shared_ptr< CoordinateReferenceSystem< Mesh::dim > >{ + std::make_shared< + AttributeCoordinateReferenceSystem< Mesh::dim > >( + mesh.vertex_attribute_manager(), + internal::PointsImpl< Mesh::dim >::POINTS_NAME ) } ); + crs_manager_builder.set_active_coordinate_reference_system( + internal::PointsImpl< Mesh::dim >::POINTS_NAME ); + } + + template < typename Mesh > + void initialize_crs( Mesh &mesh, const geode::uuid &attribute_id ) + { + CoordinateReferenceSystemManagersBuilder< Mesh::dim >{ mesh } + .main_coordinate_reference_system_manager_builder() + .delete_coordinate_reference_system( + internal::PointsImpl< Mesh::dim >::POINTS_NAME ); + auto crs_manager_builder = + CoordinateReferenceSystemManagersBuilder< Mesh::dim >{ mesh } + .main_coordinate_reference_system_manager_builder(); + crs_manager_builder.register_coordinate_reference_system( + internal::PointsImpl< Mesh::dim >::POINTS_NAME, + std::shared_ptr< CoordinateReferenceSystem< Mesh::dim > >{ + std::make_shared< + AttributeCoordinateReferenceSystem< Mesh::dim > >( + mesh.vertex_attribute_manager(), attribute_id ) } ); + crs_manager_builder.set_active_coordinate_reference_system( + internal::PointsImpl< Mesh::dim >::POINTS_NAME ); + } + } // namespace detail +} // namespace geode diff --git a/include/geode/mesh/helpers/gradient_computation.hpp b/include/geode/mesh/helpers/gradient_computation.hpp index 0bb78cc84..9258236ac 100644 --- a/include/geode/mesh/helpers/gradient_computation.hpp +++ b/include/geode/mesh/helpers/gradient_computation.hpp @@ -25,6 +25,8 @@ #include +#include + namespace geode { FORWARD_DECLARATION_DIMENSION_CLASS( SurfaceMesh ); @@ -36,27 +38,26 @@ namespace geode namespace geode { template < index_t dimension > - [[nodiscard]] std::string compute_surface_scalar_function_gradient( - const SurfaceMesh< dimension >& mesh, - std::string_view scalar_function_name ); + [[nodiscard]] geode::uuid compute_surface_scalar_function_gradient( + const SurfaceMesh< dimension >& mesh, const uuid& scalar_function_id ); - [[nodiscard]] std::string opengeode_mesh_api + [[nodiscard]] geode::uuid opengeode_mesh_api compute_solid_scalar_function_gradient( - const SolidMesh3D& mesh, std::string_view scalar_function_name ); + const SolidMesh3D& mesh, const uuid& scalar_function_id ); namespace internal { template < index_t dimension > - [[nodiscard]] std::tuple< std::string, std::vector< index_t > > + [[nodiscard]] std::tuple< geode::uuid, std::vector< index_t > > compute_surface_scalar_function_gradient( const SurfaceMesh< dimension >& mesh, - std::string_view scalar_function_name, + const uuid& scalar_function_id, absl::Span< const index_t > no_value_vertices ); - [[nodiscard]] std::tuple< std::string, std::vector< index_t > > + [[nodiscard]] std::tuple< geode::uuid, std::vector< index_t > > opengeode_mesh_api compute_solid_scalar_function_gradient( const SolidMesh3D& mesh, - std::string_view scalar_function_name, + const uuid& scalar_function_id, absl::Span< const index_t > no_value_vertices ); } // namespace internal } // namespace geode \ No newline at end of file diff --git a/include/geode/mesh/helpers/tetrahedral_solid_point_function.hpp b/include/geode/mesh/helpers/tetrahedral_solid_point_function.hpp index f2b150fd7..e35b346e3 100644 --- a/include/geode/mesh/helpers/tetrahedral_solid_point_function.hpp +++ b/include/geode/mesh/helpers/tetrahedral_solid_point_function.hpp @@ -24,6 +24,7 @@ #pragma once #include +#include #include @@ -59,13 +60,13 @@ namespace geode /*! * Finds an object function that already exists in the given - * TetrahedralSolid, from its given name. - * Throws an exception if no attribute with the same name exists. + * TetrahedralSolid, from its given uuid. + * Throws an exception if no attribute with the same uuid exists. */ [[nodiscard]] static TetrahedralSolidPointFunction< dimension, point_dimension > find( const TetrahedralSolid< dimension >& solid, - std::string_view function_name ); + const uuid& function_id ); void set_value( index_t vertex_index, Point< point_dimension > value ); @@ -75,10 +76,12 @@ namespace geode [[nodiscard]] Point< point_dimension > value( const Point< dimension >& point, index_t tetrahedron_id ) const; + [[nodiscard]] uuid attribute_function_id() const; + private: TetrahedralSolidPointFunction( const TetrahedralSolid< dimension >& solid, - std::string_view function_name ); + const uuid& function_id ); TetrahedralSolidPointFunction( const TetrahedralSolid< dimension >& solid, diff --git a/include/geode/mesh/helpers/tetrahedral_solid_scalar_function.hpp b/include/geode/mesh/helpers/tetrahedral_solid_scalar_function.hpp index 1e0cffe70..9584d2557 100644 --- a/include/geode/mesh/helpers/tetrahedral_solid_scalar_function.hpp +++ b/include/geode/mesh/helpers/tetrahedral_solid_scalar_function.hpp @@ -24,6 +24,7 @@ #pragma once #include +#include #include @@ -57,12 +58,12 @@ namespace geode /*! * Finds an object function that already exists in the given - * TetrahedralSolid, from its given name. - * Throws an exception if no attribute with the same name exists. + * TetrahedralSolid, from its given id. + * Throws an exception if no attribute with the same id exists. */ [[nodiscard]] static TetrahedralSolidScalarFunction< dimension > find( const TetrahedralSolid< dimension >& solid, - std::string_view function_name ); + const uuid& function_id ); void set_value( index_t vertex_index, double value ); @@ -71,15 +72,17 @@ namespace geode [[nodiscard]] double value( const Point< dimension >& point, index_t tetrahedron_id ) const; + [[nodiscard]] uuid attribute_function_id() const; + private: TetrahedralSolidScalarFunction( const TetrahedralSolid< dimension >& solid, - std::string_view function_name ); + std::string_view function_name, + double value ); TetrahedralSolidScalarFunction( const TetrahedralSolid< dimension >& solid, - std::string_view function_name, - double value ); + const uuid& function_id ); private: IMPLEMENTATION_MEMBER( impl_ ); diff --git a/include/geode/mesh/helpers/triangulated_surface_point_function.hpp b/include/geode/mesh/helpers/triangulated_surface_point_function.hpp index ddb81b749..df25323ec 100644 --- a/include/geode/mesh/helpers/triangulated_surface_point_function.hpp +++ b/include/geode/mesh/helpers/triangulated_surface_point_function.hpp @@ -24,6 +24,7 @@ #pragma once #include +#include #include @@ -57,13 +58,13 @@ namespace geode /*! * Finds an object function that already exists in the given - * TriangulatedSurface, from its given name. - * Throws an exception if no attribute with the same name exists. + * TriangulatedSurface, from its given id. + * Throws an exception if no attribute with the same id exists. */ [[nodiscard]] static TriangulatedSurfacePointFunction< dimension, point_dimension > find( const TriangulatedSurface< dimension >& solid, - std::string_view function_name ); + const uuid& function_id ); void set_value( index_t vertex_index, Point< point_dimension > value ); @@ -73,10 +74,12 @@ namespace geode [[nodiscard]] Point< point_dimension > value( const Point< dimension >& point, index_t tetrahedron_id ) const; + [[nodiscard]] uuid attribute_function_id() const; + private: TriangulatedSurfacePointFunction( const TriangulatedSurface< dimension >& solid, - std::string_view function_name ); + const uuid& function_id ); TriangulatedSurfacePointFunction( const TriangulatedSurface< dimension >& solid, diff --git a/include/geode/mesh/helpers/triangulated_surface_scalar_function.hpp b/include/geode/mesh/helpers/triangulated_surface_scalar_function.hpp index c7bed50f6..dbe19724b 100644 --- a/include/geode/mesh/helpers/triangulated_surface_scalar_function.hpp +++ b/include/geode/mesh/helpers/triangulated_surface_scalar_function.hpp @@ -24,6 +24,7 @@ #pragma once #include +#include #include @@ -60,7 +61,7 @@ namespace geode */ [[nodiscard]] static TriangulatedSurfaceScalarFunction< dimension > find( const TriangulatedSurface< dimension >& solid, - std::string_view function_name ); + const uuid& function_id ); void set_value( index_t vertex_index, double value ); @@ -69,10 +70,12 @@ namespace geode [[nodiscard]] double value( const Point< dimension >& point, index_t tetrahedron_id ) const; + [[nodiscard]] uuid attribute_function_id() const; + private: TriangulatedSurfaceScalarFunction( const TriangulatedSurface< dimension >& solid, - std::string_view function_name ); + const uuid& function_id ); TriangulatedSurfaceScalarFunction( const TriangulatedSurface< dimension >& solid, diff --git a/include/geode/mesh/io/geode/geode_bitsery_mesh_input.hpp b/include/geode/mesh/io/geode/geode_bitsery_mesh_input.hpp index aa45f6569..6717f9ec9 100644 --- a/include/geode/mesh/io/geode/geode_bitsery_mesh_input.hpp +++ b/include/geode/mesh/io/geode/geode_bitsery_mesh_input.hpp @@ -32,7 +32,8 @@ #include #define BITSERY_READ( Mesh ) \ - [[nodiscard]] std::unique_ptr< Mesh > read( const MeshImpl& impl ) final \ + [[nodiscard]] std::unique_ptr< Mesh > read( const MeshImpl& /*impl*/ ) \ + final \ { \ std::ifstream file{ to_string( this->filename() ), \ std::ifstream::binary }; \ @@ -44,7 +45,8 @@ BitseryExtensions::register_deserialize_pcontext( \ std::get< 0 >( context ) ); \ Deserializer archive{ context, file }; \ - auto mesh = Mesh::create( impl ); \ + std::unique_ptr< Mesh > mesh{ new OpenGeode##Mesh{ \ + BITSERY::constructor } }; \ archive.object( dynamic_cast< OpenGeode##Mesh& >( *mesh ) ); \ const auto& adapter = archive.adapter(); \ geode::OpenGeodeMeshException::check_exception( \ diff --git a/include/geode/model/mixin/builder/vertex_identifier_builder.hpp b/include/geode/model/mixin/builder/vertex_identifier_builder.hpp index 1aa562050..9ca87c805 100644 --- a/include/geode/model/mixin/builder/vertex_identifier_builder.hpp +++ b/include/geode/model/mixin/builder/vertex_identifier_builder.hpp @@ -47,6 +47,12 @@ namespace geode vertex_identifier_.register_mesh_component( component, {} ); } + template < typename MeshComponent > + void load_mesh_component( const MeshComponent& component ) + { + vertex_identifier_.load_mesh_component( component, {} ); + } + /*! * Remove a component from the VertexIdentifier and delete corresponding * information (i.e. the attribute on component mesh). diff --git a/include/geode/model/mixin/core/detail/relationships_impl.hpp b/include/geode/model/mixin/core/detail/relationships_impl.hpp index 266c6f92e..24e78ae26 100644 --- a/include/geode/model/mixin/core/detail/relationships_impl.hpp +++ b/include/geode/model/mixin/core/detail/relationships_impl.hpp @@ -26,8 +26,10 @@ #include #include +#include #include +#include #include #include @@ -48,6 +50,8 @@ namespace geode public: using Iterator = typename EdgesAroundVertex::const_iterator; + RelationshipsImpl( BITSERY ); + [[nodiscard]] index_t nb_components_with_relations() const; [[nodiscard]] index_t nb_relations( @@ -104,13 +108,23 @@ namespace geode serializer.ext( *this, Growable< Archive, RelationshipsImpl >{ { []( Archive& archive, RelationshipsImpl& impl ) { - archive.ext( - impl.graph_, bitsery::ext::StdSmartPtr{} ); - archive.object( impl.uuid2index_ ); - archive.ext( - impl.ids_, bitsery::ext::StdSmartPtr{} ); - impl.delete_isolated_vertices(); - } } } ); + impl.graph_ = std::make_unique< OpenGeodeGraph >( + BITSERY::constructor ); + archive.ext( + impl.graph_, bitsery::ext::StdSmartPtr{} ); + archive.object( impl.uuid2index_ ); + archive.ext( + impl.ids_, bitsery::ext::StdSmartPtr{} ); + impl.delete_isolated_vertices(); + }, + []( Archive& archive, RelationshipsImpl& impl ) { + archive.ext( + impl.graph_, bitsery::ext::StdSmartPtr{} ); + archive.object( impl.uuid2index_ ); + archive.ext( + impl.ids_, bitsery::ext::StdSmartPtr{} ); + impl.delete_isolated_vertices(); + } } } ); } index_t register_component( const ComponentID& id ); diff --git a/include/geode/model/mixin/core/relationships.hpp b/include/geode/model/mixin/core/relationships.hpp index 3dfa505f2..f968c4f14 100644 --- a/include/geode/model/mixin/core/relationships.hpp +++ b/include/geode/model/mixin/core/relationships.hpp @@ -25,6 +25,7 @@ #include +#include #include #include @@ -357,6 +358,7 @@ namespace geode public: Relationships(); + Relationships( BITSERY ); ~Relationships(); [[nodiscard]] index_t nb_components_with_relations() const; diff --git a/include/geode/model/mixin/core/topology.hpp b/include/geode/model/mixin/core/topology.hpp index b58fc4143..3c3ebbde1 100644 --- a/include/geode/model/mixin/core/topology.hpp +++ b/include/geode/model/mixin/core/topology.hpp @@ -46,6 +46,12 @@ namespace geode public Relationships, public VertexIdentifier { + public: + Topology( BITSERY bitsery ) + : Relationships{ bitsery }, VertexIdentifier{ bitsery } + { + } + protected: Topology() = default; Topology( Topology&& other ) = default; diff --git a/include/geode/model/mixin/core/vertex_identifier.hpp b/include/geode/model/mixin/core/vertex_identifier.hpp index cf1d425f2..df64563ee 100644 --- a/include/geode/model/mixin/core/vertex_identifier.hpp +++ b/include/geode/model/mixin/core/vertex_identifier.hpp @@ -28,6 +28,7 @@ #include #include +#include #include #include @@ -93,6 +94,7 @@ namespace geode public: VertexIdentifier(); + VertexIdentifier( BITSERY ); ~VertexIdentifier(); [[nodiscard]] index_t nb_unique_vertices() const; @@ -141,6 +143,13 @@ namespace geode void register_mesh_component( const MeshComponent& component, BuilderKey /*key*/ ); + /*! + * Add a component in the VertexIdentifier + */ + template < typename MeshComponent > + void load_mesh_component( + const MeshComponent& component, BuilderKey /*key*/ ); + /*! * Remove a component from the VertexIdentifier and delete corresponding * information (i.e. the attribute on component mesh). diff --git a/include/geode/model/representation/builder/detail/register.hpp b/include/geode/model/representation/builder/detail/register.hpp index e933cc818..933ac63e0 100644 --- a/include/geode/model/representation/builder/detail/register.hpp +++ b/include/geode/model/representation/builder/detail/register.hpp @@ -38,6 +38,15 @@ namespace geode component.component_type(), component.id() ); } + template < typename ModelBuilder, typename MeshComponent > + void add_loaded_mesh_component( + ModelBuilder& builder, const MeshComponent& component ) + { + builder.load_mesh_component( component ); + builder.add_mesh_component( + component.component_type(), component.id() ); + } + template < typename ModelBuilder, typename MeshComponent > void remove_mesh_component( ModelBuilder& builder, const MeshComponent& component ) @@ -76,14 +85,14 @@ namespace geode { for( const auto& component : model.First::components() ) { - detail::add_mesh_component( builder, component ); + detail::add_loaded_mesh_component( builder, component ); } } else { for( const auto& component : model.First::components() ) { - detail::add_mesh_component( builder, component ); + detail::add_loaded_mesh_component( builder, component ); } register_mesh_components< Model, MeshComponents... >( model, builder ); diff --git a/include/geode/model/representation/core/brep.hpp b/include/geode/model/representation/core/brep.hpp index fc35cc931..0cd7e89f3 100644 --- a/include/geode/model/representation/core/brep.hpp +++ b/include/geode/model/representation/core/brep.hpp @@ -23,6 +23,7 @@ #pragma once +#include #include #include @@ -388,6 +389,7 @@ namespace geode public: BRep(); + BRep( BITSERY ); BRep( BRep&& brep ) noexcept; BRep& operator=( BRep&& brep ); ~BRep(); diff --git a/include/geode/model/representation/core/section.hpp b/include/geode/model/representation/core/section.hpp index 012583a8a..c6d5b6be4 100644 --- a/include/geode/model/representation/core/section.hpp +++ b/include/geode/model/representation/core/section.hpp @@ -24,6 +24,7 @@ #pragma once #include +#include #include #include @@ -286,6 +287,7 @@ namespace geode public: Section(); + Section( BITSERY ); Section( Section&& section ) noexcept; Section& operator=( Section&& section ); ~Section(); diff --git a/src/geode/basic/attribute_manager.cpp b/src/geode/basic/attribute_manager.cpp index e596ea6b2..04d7f4f78 100644 --- a/src/geode/basic/attribute_manager.cpp +++ b/src/geode/basic/attribute_manager.cpp @@ -26,6 +26,7 @@ #include #include +#include #include #include @@ -38,16 +39,16 @@ namespace geode { class AttributeManager::Impl { - using AttributesMap = absl::flat_hash_map< std::string, - std::shared_ptr< AttributeBase > >; + using AttributesMap = + absl::linked_hash_map< uuid, std::shared_ptr< AttributeBase > >; using AttributesMapElement = std::pair< const AttributesMap::key_type, AttributesMap::mapped_type >; public: std::shared_ptr< AttributeBase > find_attribute_base( - std::string_view name ) const + const uuid &attribute_id ) const { - const auto attribute_it = attributes_.find( name ); + const auto attribute_it = attributes_.find( attribute_id ); if( attribute_it == attributes_.end() ) { return nullptr; @@ -56,12 +57,11 @@ namespace geode } void register_attribute( std::shared_ptr< AttributeBase > &attribute, - std::string_view name, + const uuid &attribute_id, const AttributeBase::AttributeKey &key ) { attribute->resize( nb_elements_, key ); - attribute->set_name( name, key ); - attributes_.emplace( name, attribute ); + attributes_.emplace( attribute_id, attribute ); } void resize( index_t size, const AttributeBase::AttributeKey &key ) @@ -145,35 +145,35 @@ namespace geode } ); } - absl::FixedArray< std::string_view > attribute_names() const + absl::FixedArray< uuid > attribute_ids() const { - absl::FixedArray< std::string_view > names( attributes_.size() ); + absl::FixedArray< uuid > ids( attributes_.size() ); index_t count{ 0 }; - for( const auto &[attribute_name, _] : attributes_ ) + for( const auto &[attribute_id, _] : attributes_ ) { - names[count++] = attribute_name; + ids[count++] = attribute_id; } - return names; + return ids; } - bool attribute_exists( std::string_view name ) const + bool attribute_exists( const uuid &attribute_id ) const { - return attributes_.find( name ) != attributes_.end(); + return attributes_.find( attribute_id ) != attributes_.end(); } - void delete_attribute( std::string_view name ) + void delete_attribute( const uuid &attribute_id ) { absl::MutexLock lock{ mutex_ }; - const auto attribute_it = attributes_.find( name ); + const auto attribute_it = attributes_.find( attribute_id ); if( attribute_it != attributes_.end() ) { attributes_.erase( attribute_it ); } } - std::string_view attribute_type( std::string_view name ) const + std::string_view attribute_type( const uuid &attribute_id ) const { - const auto attribute_it = attributes_.find( name ); + const auto attribute_it = attributes_.find( attribute_id ); if( attribute_it == attributes_.end() ) { static constexpr auto UNDEFINED = "undefined"; @@ -222,14 +222,41 @@ namespace geode return nb_elements_; } + std::optional< std::string_view > attribute_name( const uuid &id ) const + { + return attributes_.at( id )->name().value_or( "unknown" ); + } + + std::optional< std::vector< uuid > > attribute_ids_matching_name( + std::string_view name ) const + { + std::vector< uuid > ids; + for( const auto &[attribute_id, attribute] : attributes_ ) + { + if( !attribute->name().has_value() ) + { + continue; + } + if( attribute->name().value() == name ) + { + ids.push_back( attribute_id ); + } + } + if( ids.empty() ) + { + return std::nullopt; + } + return ids; + } + void copy( const AttributeManager::Impl &attribute_manager, const AttributeBase::AttributeKey &key ) { nb_elements_ = attribute_manager.nb_elements_; - for( const auto &[attribute_name, attribute] : + for( const auto &[attribute_id, attribute] : attribute_manager.attributes_ ) { - const auto attribute_it = attributes_.find( attribute_name ); + const auto attribute_it = attributes_.find( attribute_id ); if( attribute_it != attributes_.end() ) { try @@ -239,14 +266,14 @@ namespace geode } catch( const std::bad_cast &e ) { - Logger::error( "Attribute \"", attribute_name, + Logger::error( "Attribute \"", attribute_id.string(), "\" cannot be copied: ", e.what() ); } } else { attributes_.emplace( - attribute_name, attribute->clone( key ) ); + attribute_id, attribute->clone( key ) ); } } } @@ -256,28 +283,28 @@ namespace geode const T &old2new_mapping, const AttributeBase::AttributeKey &key ) { - for( const auto &[attribute_name, attribute_from] : + for( const auto &[attribute_id, attribute_from] : attribute_manager.attributes_ ) { if( !attribute_from->properties().transferable ) { continue; } - if( attribute_exists( attribute_name ) ) + if( attribute_exists( attribute_id ) ) { if( attribute_from->type() - != this->attributes_.at( attribute_name )->type() ) + != this->attributes_.at( attribute_id )->type() ) { continue; } - this->attributes_.at( attribute_name ) + this->attributes_.at( attribute_id ) ->import( old2new_mapping, attribute_from, key ); } else { - attributes_.emplace( attribute_name, - attribute_from->extract( - old2new_mapping, nb_elements_, key ) ); + attributes_.emplace( + attribute_id, attribute_from->extract( old2new_mapping, + nb_elements_, key ) ); } } } @@ -285,106 +312,121 @@ namespace geode template < typename T > void import( const AttributeManager::Impl &attribute_manager, const T &old2new_mapping, - std::string_view attribute_name, + geode::uuid attribute_id, const AttributeBase::AttributeKey &key ) { - auto it = attribute_manager.attributes_.find( attribute_name ); + auto it = attribute_manager.attributes_.find( attribute_id ); OpenGeodeBasicException::check_exception( it != attribute_manager.attributes_.end(), nullptr, OpenGeodeException::TYPE::data, "[AttributeManager::import] Could not import attribute '", - attribute_name, - "'. No attribute with this name exists in the source " + attribute_id.string(), + "'. No attribute with this id exists in the source " "AttributeManager." ); OpenGeodeBasicException::check_exception( it->second->properties().transferable, nullptr, OpenGeodeException::TYPE::data, "[AttributeManager::import] Could not import attribute '", - attribute_name, "'. The attribute is not transferable." ); - if( attribute_exists( attribute_name ) ) + attribute_id.string(), + "'. The attribute is not transferable." ); + if( attribute_exists( attribute_id ) ) { OpenGeodeBasicException::check_exception( it->second->type() - == this->attributes_.at( attribute_name )->type(), + == this->attributes_.at( attribute_id )->type(), nullptr, OpenGeodeException::TYPE::data, "[AttributeManager::import] Could not import attribute '", - attribute_name, - "'. An attribute with the same name but a different type " + attribute_id.string(), + "'. An attribute with the same id but a different type " "already exists in the destination AttributeManager." ); - this->attributes_.at( attribute_name ) + this->attributes_.at( attribute_id ) ->import( old2new_mapping, it->second, key ); } else { - attributes_.emplace( attribute_name, + attributes_.emplace( attribute_id, it->second->extract( old2new_mapping, nb_elements_, key ) ); } } - void initialize_attribute_names( - const AttributeBase::AttributeKey &key ) - { - for( auto &[attribute_name, attribute] : attributes_ ) - { - attribute->set_name( attribute_name, key ); - } - } - - void rename_attribute( std::string_view old_name, - std::string_view new_name, - const AttributeBase::AttributeKey &key ) - { - const auto attribute_it = attributes_.find( old_name ); - OpenGeodeBasicException::check_exception( - attribute_it != attributes_.end(), nullptr, - OpenGeodeException::TYPE::data, - "[AttributeManager::rename_attribute] Attribute ", old_name, - "does not exist" ); - auto attribute = attribute_it->second; - attributes_.erase( attribute_it ); - attribute->set_name( new_name, key ); - attributes_.emplace( new_name, attribute ); - } - - void set_attribute_properties( std::string_view attribute_name, + void set_attribute_properties( geode::uuid attribute_id, const AttributeProperties &new_properties ) { - const auto attribute_it = attributes_.find( attribute_name ); + const auto attribute_it = attributes_.find( attribute_id ); OpenGeodeBasicException::check_exception( attribute_it != attributes_.end(), nullptr, OpenGeodeException::TYPE::data, - "[AttributeManager::rename_attribute] Attribute ", - attribute_name, "does not exist" ); + "[AttributeManager::set_attribute_properties] Attribute ", + attribute_id.string(), "does not exist" ); attribute_it->second->set_properties( new_properties ); } template < typename Archive > void serialize( Archive &serializer ) { - serializer.ext( - *this, Growable< Archive, Impl >{ { []( Archive &local_archive, - Impl &impl ) { - local_archive.value4b( impl.nb_elements_ ); - local_archive.ext( impl.attributes_, - bitsery::ext::StdMap{ impl.attributes_.max_size() }, - []( Archive &local_archive2, std::string &name, - std::shared_ptr< AttributeBase > &attribute ) { - local_archive2.text1b( name, name.max_size() ); - try - { - local_archive2.ext( - attribute, bitsery::ext::StdSmartPtr{} ); - } - catch( ... ) - { - throw OpenGeodeBasicException{ nullptr, - OpenGeodeException::TYPE::internal, - "[AttributeManager::serialize] Cannot " - "serialize attribute ", - name, " holding type ", attribute->type() }; - } - } ); - } } } ); + serializer.ext( *this, + Growable< Archive, Impl >{ + { []( Archive &local_archive, Impl &impl ) { + local_archive.value4b( impl.nb_elements_ ); + absl::linked_hash_map< std::string, + std::shared_ptr< AttributeBase > > + old_map; + local_archive.ext( old_map, + bitsery::ext::StdMap{ old_map.max_size() }, + []( Archive &local_archive2, std::string &name, + std::shared_ptr< AttributeBase > &attribute ) { + local_archive2.text1b( name, name.max_size() ); + try + { + local_archive2.ext( attribute, + bitsery::ext::StdSmartPtr{} ); + } + catch( ... ) + { + throw OpenGeodeBasicException{ nullptr, + OpenGeodeException::TYPE::internal, + "[AttributeManager::serialize] Cannot " + "serialize attribute ", + name, " holding type ", + attribute->type() }; + } + } ); + for( auto &[attribute_name, attribute] : old_map ) + { + IdentifierBuilder builder{ *attribute }; + builder.set_name( attribute_name ); + impl.attributes_.emplace( + attribute->id(), std::move( attribute ) ); + } + }, + []( Archive &local_archive, Impl &impl ) { + local_archive.value4b( impl.nb_elements_ ); + local_archive.ext( impl.attributes_, + bitsery::ext::StdMap{ + impl.attributes_.max_size() }, + []( Archive &local_archive2, + geode::uuid &attribute_id, + std::shared_ptr< AttributeBase > + &attribute ) { + local_archive2.object( attribute_id ); + try + { + local_archive2.ext( attribute, + bitsery::ext::StdSmartPtr{} ); + } + catch( ... ) + { + throw OpenGeodeBasicException{ nullptr, + OpenGeodeException::TYPE::internal, + "[AttributeManager::serialize] " + "Cannot " + "serialize attribute with id ", + attribute_id.string(), + " holding type ", + attribute->type() }; + } + } ); + } } } ); } absl::Mutex &mutex() const @@ -406,15 +448,16 @@ namespace geode AttributeManager::~AttributeManager() = default; std::shared_ptr< AttributeBase > AttributeManager::find_attribute_base( - std::string_view name ) const + const geode::uuid &attribute_id ) const { - return impl_->find_attribute_base( name ); + return impl_->find_attribute_base( attribute_id ); } void AttributeManager::register_attribute( - std::shared_ptr< AttributeBase > attribute, std::string_view name ) + std::shared_ptr< AttributeBase > attribute, + const geode::uuid &attribute_id ) { - return impl_->register_attribute( attribute, name, {} ); + return impl_->register_attribute( attribute, attribute_id, {} ); } void AttributeManager::resize( index_t size ) @@ -455,26 +498,26 @@ namespace geode impl_->interpolate_attribute_value( interpolation, to_element, {} ); } - absl::FixedArray< std::string_view > - AttributeManager::attribute_names() const + absl::FixedArray< geode::uuid > AttributeManager::attribute_ids() const { - return impl_->attribute_names(); + return impl_->attribute_ids(); } - bool AttributeManager::attribute_exists( std::string_view name ) const + bool AttributeManager::attribute_exists( + const geode::uuid &attribute_id ) const { - return impl_->attribute_exists( name ); + return impl_->attribute_exists( attribute_id ); } - void AttributeManager::delete_attribute( std::string_view name ) + void AttributeManager::delete_attribute( const geode::uuid &attribute_id ) { - impl_->delete_attribute( name ); + impl_->delete_attribute( attribute_id ); } std::string_view AttributeManager::attribute_type( - std::string_view name ) const + const geode::uuid &attribute_id ) const { - return impl_->attribute_type( name ); + return impl_->attribute_type( attribute_id ); } void AttributeManager::clear() @@ -516,6 +559,19 @@ namespace geode impl_->copy( *attribute_manager.impl_, {} ); } + std::optional< std::vector< geode::uuid > > + AttributeManager::attribute_ids_matching_name( + std::string_view name ) const + { + return impl_->attribute_ids_matching_name( name ); + } + + std::optional< std::string_view > AttributeManager::attribute_name( + const uuid &id ) const + { + return impl_->attribute_name( id ); + } + void AttributeManager::import( const AttributeManager &attribute_manager, absl::Span< const index_t > old2new ) { @@ -524,9 +580,9 @@ namespace geode void AttributeManager::import( const AttributeManager &attribute_manager, absl::Span< const index_t > old2new, - std::string_view attribute_name ) + const geode::uuid &attribute_id ) { - impl_->import( *attribute_manager.impl_, old2new, attribute_name, {} ); + impl_->import( *attribute_manager.impl_, old2new, attribute_id, {} ); } void AttributeManager::import( const AttributeManager &attribute_manager, @@ -537,23 +593,16 @@ namespace geode void AttributeManager::import( const AttributeManager &attribute_manager, const GenericMapping< index_t > &old2new_mapping, - std::string_view attribute_name ) + const geode::uuid &attribute_id ) { impl_->import( - *attribute_manager.impl_, old2new_mapping, attribute_name, {} ); - } - - void AttributeManager::rename_attribute( - std::string_view old_name, std::string_view new_name ) - { - impl_->rename_attribute( old_name, new_name, {} ); + *attribute_manager.impl_, old2new_mapping, attribute_id, {} ); } void AttributeManager::set_attribute_properties( - std::string_view attribute_name, - const AttributeProperties &new_properties ) + geode::uuid attribute_id, const AttributeProperties &new_properties ) { - impl_->set_attribute_properties( attribute_name, new_properties ); + impl_->set_attribute_properties( attribute_id, new_properties ); } absl::Mutex &AttributeManager::mutex() const @@ -564,18 +613,16 @@ namespace geode template < typename Archive > void AttributeManager::serialize( Archive &serializer ) { - serializer.ext( *this, - Growable< Archive, AttributeManager >{ - { []( Archive &local_archive, - AttributeManager &attribute_manager ) { - local_archive.object( attribute_manager.impl_ ); - const AttributeBase::AttributeKey key; - attribute_manager.impl_->initialize_attribute_names( key ); - }, - []( Archive &local_archive, - AttributeManager &attribute_manager ) { - local_archive.object( attribute_manager.impl_ ); - } } } ); + serializer.ext( + *this, Growable< Archive, AttributeManager >{ + { []( Archive &local_archive, + AttributeManager &attribute_manager ) { + local_archive.object( attribute_manager.impl_ ); + }, + []( Archive &local_archive, + AttributeManager &attribute_manager ) { + local_archive.object( attribute_manager.impl_ ); + } } } ); } SERIALIZE_BITSERY_ARCHIVE( opengeode_basic_api, AttributeManager ); diff --git a/src/geode/mesh/CMakeLists.txt b/src/geode/mesh/CMakeLists.txt index 8b7b1d9db..65c0a5e81 100644 --- a/src/geode/mesh/CMakeLists.txt +++ b/src/geode/mesh/CMakeLists.txt @@ -326,6 +326,7 @@ add_geode_library( "helpers/detail/surface_merger.hpp" "helpers/detail/surface_mesh_validity_fix.hpp" "helpers/detail/vertex_merger.hpp" + "helpers/detail/initialize_crs.hpp" INTERNAL_HEADERS "core/internal/edges_impl.hpp" "core/internal/facet_edges_impl.hpp" diff --git a/src/geode/mesh/builder/edged_curve_builder.cpp b/src/geode/mesh/builder/edged_curve_builder.cpp index c07842aef..ce880405d 100644 --- a/src/geode/mesh/builder/edged_curve_builder.cpp +++ b/src/geode/mesh/builder/edged_curve_builder.cpp @@ -67,16 +67,9 @@ namespace geode "[EdgedCurveBuilder::copy] Cannot copy a mesh into an already " "initialized mesh." ); GraphBuilder::copy( edged_curve ); - if( edged_curve_.impl_name() == edged_curve.impl_name() ) + for( const auto p : Range{ edged_curve.nb_vertices() } ) { - do_copy_points( edged_curve ); - } - else - { - for( const auto p : Range{ edged_curve.nb_vertices() } ) - { - this->set_point( p, edged_curve.point( p ) ); - } + this->set_point( p, edged_curve.point( p ) ); } } diff --git a/src/geode/mesh/builder/geode/geode_vertex_set_builder.cpp b/src/geode/mesh/builder/geode/geode_vertex_set_builder.cpp index 9094efe40..50ab836db 100644 --- a/src/geode/mesh/builder/geode/geode_vertex_set_builder.cpp +++ b/src/geode/mesh/builder/geode/geode_vertex_set_builder.cpp @@ -37,7 +37,7 @@ namespace geode OpenGeodeVertexSetBuilder::OpenGeodeVertexSetBuilder( OpenGeodeVertexSet& mesh ) - : VertexSetBuilder( mesh ), geode_vertex_set_( mesh ) + : VertexSetBuilder( mesh ) { } diff --git a/src/geode/mesh/builder/graph_builder.cpp b/src/geode/mesh/builder/graph_builder.cpp index f629501ab..7c5413209 100644 --- a/src/geode/mesh/builder/graph_builder.cpp +++ b/src/geode/mesh/builder/graph_builder.cpp @@ -245,22 +245,15 @@ namespace geode VertexSetBuilder::copy( graph ); create_edges( graph.nb_edges() ); graph_.edge_attribute_manager().copy( graph.edge_attribute_manager() ); - if( graph_.impl_name() == graph.impl_name() ) + for( const auto e : Range{ graph.nb_edges() } ) { - do_copy_edges( graph ); - } - else - { - for( const auto e : Range{ graph.nb_edges() } ) + for( const auto v : LRange{ 2 } ) { - for( const auto v : LRange{ 2 } ) + const EdgeVertex id{ e, v }; + const auto vertex = graph.edge_vertex( id ); + if( vertex != NO_ID ) { - const EdgeVertex id{ e, v }; - const auto vertex = graph.edge_vertex( id ); - if( vertex != NO_ID ) - { - set_edge_vertex( id, vertex ); - } + set_edge_vertex( id, vertex ); } } } diff --git a/src/geode/mesh/builder/point_set_builder.cpp b/src/geode/mesh/builder/point_set_builder.cpp index 6aafe4757..385d952bd 100644 --- a/src/geode/mesh/builder/point_set_builder.cpp +++ b/src/geode/mesh/builder/point_set_builder.cpp @@ -65,16 +65,9 @@ namespace geode "[PointSetBuilder::copy] Cannot copy a mesh into an already " "initialized mesh." ); VertexSetBuilder::copy( point_set ); - if( point_set_.impl_name() == point_set.impl_name() ) + for( const auto p : Range{ point_set.nb_vertices() } ) { - do_copy_points( point_set ); - } - else - { - for( const auto p : Range{ point_set.nb_vertices() } ) - { - this->set_point( p, point_set.point( p ) ); - } + this->set_point( p, point_set.point( p ) ); } } diff --git a/src/geode/mesh/builder/regular_grid_solid_builder.cpp b/src/geode/mesh/builder/regular_grid_solid_builder.cpp index 5231370d4..81d6d65c6 100644 --- a/src/geode/mesh/builder/regular_grid_solid_builder.cpp +++ b/src/geode/mesh/builder/regular_grid_solid_builder.cpp @@ -195,7 +195,8 @@ namespace geode OpenGeodeException::TYPE::data, "[RegularGridBuilder::copy] Cannot copy a mesh into an " "already initialized mesh." ); - SolidMeshBuilder3D::copy( grid ); GridBuilder3D::copy( grid ); + + SolidMeshBuilder3D::copy( grid ); } } // namespace geode diff --git a/src/geode/mesh/builder/solid_mesh_builder.cpp b/src/geode/mesh/builder/solid_mesh_builder.cpp index 1b7b307f4..a7ed1aa0b 100644 --- a/src/geode/mesh/builder/solid_mesh_builder.cpp +++ b/src/geode/mesh/builder/solid_mesh_builder.cpp @@ -34,6 +34,8 @@ #include #include #include +#include +#include #include #include #include @@ -233,6 +235,11 @@ namespace void copy_polyhedra( const geode::SolidMesh< dimension >& solid, geode::SolidMeshBuilder< dimension >& builder ) { + if( solid.impl_name() + == geode::OpenGeodeRegularGrid< dimension >::impl_name_static() ) + { + return; + } for( const auto p : geode::Range{ solid.nb_polyhedra() } ) { absl::FixedArray< geode::index_t > vertices( @@ -277,6 +284,21 @@ namespace polyhedron.value(), v ); } } + for( const auto p : geode::Range{ solid.nb_polyhedra() } ) + { + for( const auto f : + geode::LRange{ solid.nb_polyhedron_facets( p ) } ) + { + const auto polyhedron_adjacent = + solid.polyhedron_adjacent( geode::PolyhedronFacet{ p, f } ); + if( polyhedron_adjacent ) + { + builder.set_polyhedron_adjacent( + geode::PolyhedronFacet{ p, f }, + polyhedron_adjacent.value() ); + } + } + } } template < geode::index_t dimension > @@ -958,16 +980,8 @@ namespace geode solid_mesh_.disable_facets(); } VertexSetBuilder::copy( solid_mesh ); - if( solid_mesh.impl_name() == solid_mesh_.impl_name() ) - { - do_copy_points( solid_mesh ); - do_copy_polyhedra( solid_mesh ); - } - else - { - copy_points( solid_mesh, *this ); - copy_polyhedra( solid_mesh, *this ); - } + copy_points( solid_mesh, *this ); + copy_polyhedra( solid_mesh, *this ); solid_mesh_.polyhedron_attribute_manager().copy( solid_mesh.polyhedron_attribute_manager() ); if( solid_mesh.are_edges_enabled() ) diff --git a/src/geode/mesh/builder/surface_mesh_builder.cpp b/src/geode/mesh/builder/surface_mesh_builder.cpp index 778ce2f2f..cbc59fe5e 100644 --- a/src/geode/mesh/builder/surface_mesh_builder.cpp +++ b/src/geode/mesh/builder/surface_mesh_builder.cpp @@ -301,6 +301,17 @@ namespace polygon.value(), v ); } } + for( const auto p : geode::Range{ surface.nb_polygons() } ) + { + for( const auto e : geode::LRange{ surface.nb_polygon_edges( p ) } ) + { + const geode::PolygonEdge edge{ p, e }; + if( const auto adj = surface.polygon_adjacent( edge ) ) + { + builder.set_polygon_adjacent( edge, adj.value() ); + } + } + } } template < geode::index_t dimension > @@ -832,22 +843,14 @@ namespace geode surface_mesh_.disable_edges(); } VertexSetBuilder::copy( surface_mesh ); - if( surface_mesh.impl_name() == surface_mesh_.impl_name() ) - { - do_copy_points( surface_mesh ); - do_copy_polygons( surface_mesh ); - } - else - { - copy_points( surface_mesh, *this ); - copy_polygons( surface_mesh, *this ); - } - surface_mesh_.polygon_attribute_manager().copy( - surface_mesh.polygon_attribute_manager() ); + copy_polygons( surface_mesh, *this ); if( surface_mesh.are_edges_enabled() ) { surface_mesh_.copy_edges( surface_mesh, {} ); } + surface_mesh_.polygon_attribute_manager().copy( + surface_mesh.polygon_attribute_manager() ); + copy_points( surface_mesh, *this ); } template class opengeode_mesh_api SurfaceMeshBuilder< 2 >; diff --git a/src/geode/mesh/builder/vertex_set_builder.cpp b/src/geode/mesh/builder/vertex_set_builder.cpp index 1193c9499..06d991c7b 100644 --- a/src/geode/mesh/builder/vertex_set_builder.cpp +++ b/src/geode/mesh/builder/vertex_set_builder.cpp @@ -75,9 +75,12 @@ namespace geode index_t VertexSetBuilder::create_vertices( index_t nb ) { + DEBUG( "create_vertices" ); const auto first_added_vertex = vertex_set_.nb_vertices(); + DEBUG( vertex_set_.vertex_attribute_manager().nb_elements() ); vertex_set_.vertex_attribute_manager().resize( first_added_vertex + nb ); + DEBUG( vertex_set_.vertex_attribute_manager().nb_elements() ); do_create_vertices( nb ); return first_added_vertex; } diff --git a/src/geode/mesh/core/attribute_coordinate_reference_system.cpp b/src/geode/mesh/core/attribute_coordinate_reference_system.cpp index 562f88b62..812ce1871 100644 --- a/src/geode/mesh/core/attribute_coordinate_reference_system.cpp +++ b/src/geode/mesh/core/attribute_coordinate_reference_system.cpp @@ -37,8 +37,8 @@ namespace geode friend class bitsery::Access; public: - Impl( AttributeManager& manager ) - : internal::PointsImpl< dimension >{ manager } + Impl( AttributeManager& manager, const geode::uuid& uuid ) + : internal::PointsImpl< dimension >{ manager, uuid } { } Impl( AttributeManager& manager, std::string_view attribute_name ) @@ -68,8 +68,9 @@ namespace geode template < index_t dimension > AttributeCoordinateReferenceSystem< dimension >:: - AttributeCoordinateReferenceSystem( AttributeManager& manager ) - : impl_{ manager } + AttributeCoordinateReferenceSystem( + AttributeManager& manager, const geode::uuid& uuid ) + : impl_{ manager, uuid } { } @@ -107,6 +108,12 @@ namespace geode return impl_->attribute_name(); } + template < index_t dimension > + uuid AttributeCoordinateReferenceSystem< dimension >::attribute_id() const + { + return impl_->attribute_id(); + } + template < index_t dimension > index_t AttributeCoordinateReferenceSystem< dimension >::nb_points() const { diff --git a/src/geode/mesh/core/edged_curve.cpp b/src/geode/mesh/core/edged_curve.cpp index 267bab09d..cf6008c46 100644 --- a/src/geode/mesh/core/edged_curve.cpp +++ b/src/geode/mesh/core/edged_curve.cpp @@ -67,6 +67,11 @@ namespace geode template < index_t dimension > EdgedCurve< dimension >::EdgedCurve() = default; + template < index_t dimension > + EdgedCurve< dimension >::EdgedCurve( BITSERY bitsery ) : Graph{ bitsery } + { + } + template < index_t dimension > EdgedCurve< dimension >::EdgedCurve( EdgedCurve&& ) noexcept = default; diff --git a/src/geode/mesh/core/geode/geode_edged_curve.cpp b/src/geode/mesh/core/geode/geode_edged_curve.cpp index 7cf0aa3b8..f9a7a81a8 100644 --- a/src/geode/mesh/core/geode/geode_edged_curve.cpp +++ b/src/geode/mesh/core/geode/geode_edged_curve.cpp @@ -38,22 +38,21 @@ namespace geode { template < index_t dimension > - class OpenGeodeEdgedCurve< dimension >::Impl - : public internal::EdgesImpl, - public internal::PointsImpl< dimension > + class OpenGeodeEdgedCurve< dimension >::Impl : public internal::EdgesImpl { friend class bitsery::Access; public: explicit Impl( OpenGeodeEdgedCurve< dimension >& mesh ) - : internal::EdgesImpl( mesh ), - internal::PointsImpl< dimension >( mesh ) + : internal::EdgesImpl( mesh ) { + detail::template initialize_crs< OpenGeodeEdgedCurve< dimension > >( + mesh ); } - private: Impl() = default; + private: template < typename Archive > void serialize( Archive& serializer ) { @@ -62,9 +61,8 @@ namespace geode { []( Archive& archive, Impl& impl ) { archive.ext( impl, bitsery::ext::BaseClass< internal::EdgesImpl >{} ); - archive.ext( - impl, bitsery::ext::BaseClass< - internal::PointsImpl< dimension > >{} ); + internal::PointsImpl< dimension > temp; + archive.object( temp ); } } } ); } }; @@ -74,6 +72,12 @@ namespace geode { } + template < index_t dimension > + OpenGeodeEdgedCurve< dimension >::OpenGeodeEdgedCurve( BITSERY bitsery ) + : EdgedCurve< dimension >{ bitsery } + { + } + template < index_t dimension > OpenGeodeEdgedCurve< dimension >::OpenGeodeEdgedCurve( OpenGeodeEdgedCurve&& ) noexcept = default; @@ -86,13 +90,6 @@ namespace geode template < index_t dimension > OpenGeodeEdgedCurve< dimension >::~OpenGeodeEdgedCurve() = default; - template < index_t dimension > - void OpenGeodeEdgedCurve< dimension >::set_vertex( - index_t vertex_id, Point< dimension > point, OGEdgedCurveKey /*key*/ ) - { - impl_->set_point( vertex_id, std::move( point ) ); - } - template < index_t dimension > index_t OpenGeodeEdgedCurve< dimension >::get_edge_vertex( const EdgeVertex& edge_vertex ) const @@ -119,8 +116,32 @@ namespace geode archive.ext( edged_curve, bitsery::ext::BaseClass< EdgedCurve< dimension > >{} ); archive.object( edged_curve.impl_ ); - edged_curve.impl_->initialize_crs( edged_curve ); + const auto new_point_attribute_id = + edged_curve.vertex_attribute_manager() + .attribute_ids_matching_name( internal::PointsImpl< + dimension >::POINTS_NAME ) + .value() + .at( 0 ); + detail::template initialize_crs< + OpenGeodeEdgedCurve< dimension > >( + edged_curve, new_point_attribute_id ); }, + []( Archive& archive, OpenGeodeEdgedCurve& edged_curve ) { + archive.ext( + edged_curve, bitsery::ext::BaseClass< + EdgedCurve< dimension > >{} ); + archive.object( edged_curve.impl_ ); + const auto new_point_attribute_id = + edged_curve.vertex_attribute_manager() + .attribute_ids_matching_name( + internal::PointsImpl< + dimension >::POINTS_NAME ) + .value() + .at( 0 ); + detail::template initialize_crs< + OpenGeodeEdgedCurve< dimension > >( + edged_curve, new_point_attribute_id ); + }, []( Archive& archive, OpenGeodeEdgedCurve& edged_curve ) { archive.ext( edged_curve, bitsery::ext::BaseClass< diff --git a/src/geode/mesh/core/geode/geode_graph.cpp b/src/geode/mesh/core/geode/geode_graph.cpp index eeff4b0fa..d8a74c8f4 100644 --- a/src/geode/mesh/core/geode/geode_graph.cpp +++ b/src/geode/mesh/core/geode/geode_graph.cpp @@ -39,9 +39,9 @@ namespace geode public: explicit Impl( OpenGeodeGraph& mesh ) : internal::EdgesImpl( mesh ) {} - private: Impl() = default; + private: template < typename Archive > void serialize( Archive& serializer ) { @@ -56,6 +56,8 @@ namespace geode OpenGeodeGraph::OpenGeodeGraph() : impl_( *this ) {} + OpenGeodeGraph::OpenGeodeGraph( BITSERY bitsery ) : Graph{ bitsery } {} + OpenGeodeGraph::OpenGeodeGraph( OpenGeodeGraph&& ) noexcept = default; OpenGeodeGraph& OpenGeodeGraph::operator=( diff --git a/src/geode/mesh/core/geode/geode_hybrid_solid.cpp b/src/geode/mesh/core/geode/geode_hybrid_solid.cpp index 9448476bb..8e75d2c40 100644 --- a/src/geode/mesh/core/geode/geode_hybrid_solid.cpp +++ b/src/geode/mesh/core/geode/geode_hybrid_solid.cpp @@ -37,6 +37,7 @@ #include #include +#include namespace { @@ -93,19 +94,21 @@ namespace geode { template < index_t dimension > class OpenGeodeHybridSolid< dimension >::Impl - : public internal::PointsImpl< dimension > { friend class bitsery::Access; using TYPE = HybridSolid3D::TYPE; public: explicit Impl( OpenGeodeHybridSolid< dimension >& mesh ) - : internal::PointsImpl< dimension >( mesh ) { + detail::template initialize_crs< + OpenGeodeHybridSolid< dimension > >( mesh ); polyhedron_vertex_ptr_.emplace_back( 0 ); polyhedron_adjacent_ptr_.emplace_back( 0 ); } + Impl() = default; + index_t get_polyhedron_vertex( const PolyhedronVertex& polyhedron_vertex ) const { @@ -409,8 +412,6 @@ namespace geode } private: - Impl() = default; - template < typename Archive > void serialize( Archive& serializer ) { @@ -425,9 +426,8 @@ namespace geode impl.polyhedron_adjacents_.max_size() ); archive.container4b( impl.polyhedron_adjacent_ptr_, impl.polyhedron_adjacent_ptr_.max_size() ); - archive.ext( - impl, bitsery::ext::BaseClass< - internal::PointsImpl< dimension > >{} ); + internal::PointsImpl< dimension > temp; + archive.object( temp ); } } } ); } @@ -470,6 +470,12 @@ namespace geode { } + template < index_t dimension > + OpenGeodeHybridSolid< dimension >::OpenGeodeHybridSolid( BITSERY bitsery ) + : HybridSolid< dimension >{ bitsery } + { + } + template < index_t dimension > OpenGeodeHybridSolid< dimension >::OpenGeodeHybridSolid( OpenGeodeHybridSolid&& ) noexcept = default; @@ -482,13 +488,6 @@ namespace geode template < index_t dimension > OpenGeodeHybridSolid< dimension >::~OpenGeodeHybridSolid() = default; - template < index_t dimension > - void OpenGeodeHybridSolid< dimension >::set_vertex( - index_t vertex_id, Point< dimension > point, OGHybridSolidKey /*key*/ ) - { - impl_->set_point( vertex_id, std::move( point ) ); - } - template < index_t dimension > index_t OpenGeodeHybridSolid< dimension >::get_polyhedron_vertex( const PolyhedronVertex& polyhedron_vertex ) const @@ -636,8 +635,31 @@ namespace geode archive.ext( solid, bitsery::ext::BaseClass< HybridSolid< dimension > >{} ); archive.object( solid.impl_ ); - solid.impl_->initialize_crs( solid ); + const auto new_point_attribute_id = + solid.vertex_attribute_manager() + .attribute_ids_matching_name( internal::PointsImpl< + dimension >::POINTS_NAME ) + .value() + .at( 0 ); + detail::template initialize_crs< + OpenGeodeHybridSolid< dimension > >( + solid, new_point_attribute_id ); }, + []( Archive& archive, OpenGeodeHybridSolid& solid ) { + archive.ext( solid, bitsery::ext::BaseClass< + HybridSolid< dimension > >{} ); + archive.object( solid.impl_ ); + const auto new_point_attribute_id = + solid.vertex_attribute_manager() + .attribute_ids_matching_name( + internal::PointsImpl< + dimension >::POINTS_NAME ) + .value() + .at( 0 ); + detail::template initialize_crs< + OpenGeodeHybridSolid< dimension > >( + solid, new_point_attribute_id ); + }, []( Archive& archive, OpenGeodeHybridSolid& solid ) { archive.ext( solid, bitsery::ext::BaseClass< HybridSolid< dimension > >{} ); diff --git a/src/geode/mesh/core/geode/geode_point_set.cpp b/src/geode/mesh/core/geode/geode_point_set.cpp index ee191eaed..d176a3214 100644 --- a/src/geode/mesh/core/geode/geode_point_set.cpp +++ b/src/geode/mesh/core/geode/geode_point_set.cpp @@ -31,33 +31,34 @@ #include #include +#include namespace geode { template < index_t dimension > class OpenGeodePointSet< dimension >::Impl - : public internal::PointsImpl< dimension > { friend class bitsery::Access; public: explicit Impl( OpenGeodePointSet< dimension >& mesh ) - : internal::PointsImpl< dimension >( mesh ) { + detail::template initialize_crs< OpenGeodePointSet< dimension > >( + mesh ); } - private: Impl() = default; + private: template < typename Archive > void serialize( Archive& serializer ) { serializer.ext( *this, Growable< Archive, Impl >{ { []( Archive& archive, Impl& impl ) { - archive.ext( impl, - bitsery::ext::BaseClass< - internal::PointsImpl< dimension > >{} ); + geode_unused( impl ); + internal::PointsImpl< dimension > temp; + archive.object( temp ); } } } ); } }; @@ -67,6 +68,11 @@ namespace geode { } + template < index_t dimension > + OpenGeodePointSet< dimension >::OpenGeodePointSet( BITSERY ) + { + } + template < index_t dimension > OpenGeodePointSet< dimension >::OpenGeodePointSet( OpenGeodePointSet&& ) noexcept = default; @@ -78,13 +84,6 @@ namespace geode template < index_t dimension > OpenGeodePointSet< dimension >::~OpenGeodePointSet() = default; - template < index_t dimension > - void OpenGeodePointSet< dimension >::set_vertex( - index_t vertex_id, Point< dimension > point, OGPointSetKey /*key*/ ) - { - impl_->set_point( vertex_id, std::move( point ) ); - } - template < index_t dimension > template < typename Archive > void OpenGeodePointSet< dimension >::serialize( Archive& serializer ) @@ -95,8 +94,31 @@ namespace geode archive.ext( point_set, bitsery::ext::BaseClass< PointSet< dimension > >{} ); archive.object( point_set.impl_ ); - point_set.impl_->initialize_crs( point_set ); + const auto new_attribute_id = + point_set.vertex_attribute_manager() + .attribute_ids_matching_name( internal::PointsImpl< + dimension >::POINTS_NAME ) + .value() + .at( 0 ); + detail::template initialize_crs< + OpenGeodePointSet< dimension > >( + point_set, new_attribute_id ); }, + []( Archive& archive, OpenGeodePointSet& point_set ) { + archive.ext( point_set, bitsery::ext::BaseClass< + PointSet< dimension > >{} ); + archive.object( point_set.impl_ ); + const auto new_attribute_id = + point_set.vertex_attribute_manager() + .attribute_ids_matching_name( + internal::PointsImpl< + dimension >::POINTS_NAME ) + .value() + .at( 0 ); + detail::template initialize_crs< + OpenGeodePointSet< dimension > >( + point_set, new_attribute_id ); + }, []( Archive& archive, OpenGeodePointSet& point_set ) { archive.ext( point_set, bitsery::ext::BaseClass< PointSet< dimension > >{} ); diff --git a/src/geode/mesh/core/geode/geode_polygonal_surface.cpp b/src/geode/mesh/core/geode/geode_polygonal_surface.cpp index 217a170a6..2e90f41c0 100644 --- a/src/geode/mesh/core/geode/geode_polygonal_surface.cpp +++ b/src/geode/mesh/core/geode/geode_polygonal_surface.cpp @@ -34,6 +34,8 @@ #include +#include + namespace geode { template < index_t dimension > @@ -44,11 +46,14 @@ namespace geode public: explicit Impl( OpenGeodePolygonalSurface< dimension >& mesh ) - : internal::PointsImpl< dimension >( mesh ) { + detail::template initialize_crs< + OpenGeodePolygonalSurface< dimension > >( mesh ); polygon_ptr_.emplace_back( 0 ); } + Impl() = default; + index_t get_polygon_vertex( const PolygonVertex& polygon_vertex ) const { return polygon_vertices_[starting_index( polygon_vertex.polygon_id ) @@ -179,24 +184,21 @@ namespace geode } private: - Impl() = default; - template < typename Archive > void serialize( Archive& serializer ) { - serializer.ext( *this, - Growable< Archive, Impl >{ - { []( Archive& archive, Impl& impl ) { - archive.container4b( impl.polygon_vertices_, - impl.polygon_vertices_.max_size() ); - archive.container4b( impl.polygon_adjacents_, - impl.polygon_adjacents_.max_size() ); - archive.container4b( - impl.polygon_ptr_, impl.polygon_ptr_.max_size() ); - archive.ext( - impl, bitsery::ext::BaseClass< - internal::PointsImpl< dimension > >{} ); - } } } ); + serializer.ext( + *this, Growable< Archive, Impl >{ + { []( Archive& archive, Impl& impl ) { + archive.container4b( impl.polygon_vertices_, + impl.polygon_vertices_.max_size() ); + archive.container4b( impl.polygon_adjacents_, + impl.polygon_adjacents_.max_size() ); + archive.container4b( impl.polygon_ptr_, + impl.polygon_ptr_.max_size() ); + internal::PointsImpl< dimension > temp; + archive.object( temp ); + } } } ); } index_t get_polygon_adjacent_impl( @@ -223,6 +225,13 @@ namespace geode { } + template < index_t dimension > + OpenGeodePolygonalSurface< dimension >::OpenGeodePolygonalSurface( + BITSERY bitsery ) + : PolygonalSurface< dimension >{ bitsery } + { + } + template < index_t dimension > OpenGeodePolygonalSurface< dimension >::OpenGeodePolygonalSurface( OpenGeodePolygonalSurface&& ) noexcept = default; @@ -236,14 +245,6 @@ namespace geode OpenGeodePolygonalSurface< dimension >::~OpenGeodePolygonalSurface() = default; - template < index_t dimension > - void OpenGeodePolygonalSurface< dimension >::set_vertex( index_t vertex_id, - Point< dimension > point, - OGPolygonalSurfaceKey /*key*/ ) - { - impl_->set_point( vertex_id, std::move( point ) ); - } - template < index_t dimension > index_t OpenGeodePolygonalSurface< dimension >::get_polygon_vertex( const PolygonVertex& polygon_vertex ) const @@ -279,8 +280,32 @@ namespace geode surface, bitsery::ext::BaseClass< PolygonalSurface< dimension > >{} ); archive.object( surface.impl_ ); - surface.impl_->initialize_crs( surface ); + const auto new_point_attribute_id = + surface.vertex_attribute_manager() + .attribute_ids_matching_name( internal::PointsImpl< + dimension >::POINTS_NAME ) + .value() + .at( 0 ); + detail::template initialize_crs< + OpenGeodePolygonalSurface< dimension > >( + surface, new_point_attribute_id ); }, + []( Archive& archive, OpenGeodePolygonalSurface& surface ) { + archive.ext( + surface, bitsery::ext::BaseClass< + PolygonalSurface< dimension > >{} ); + archive.object( surface.impl_ ); + const auto new_point_attribute_id = + surface.vertex_attribute_manager() + .attribute_ids_matching_name( + internal::PointsImpl< + dimension >::POINTS_NAME ) + .value() + .at( 0 ); + detail::template initialize_crs< + OpenGeodePolygonalSurface< dimension > >( + surface, new_point_attribute_id ); + }, []( Archive& archive, OpenGeodePolygonalSurface& surface ) { archive.ext( surface, bitsery::ext::BaseClass< diff --git a/src/geode/mesh/core/geode/geode_polyhedral_solid.cpp b/src/geode/mesh/core/geode/geode_polyhedral_solid.cpp index 70369a6b1..44aa7181f 100644 --- a/src/geode/mesh/core/geode/geode_polyhedral_solid.cpp +++ b/src/geode/mesh/core/geode/geode_polyhedral_solid.cpp @@ -33,24 +33,27 @@ #include #include +#include namespace geode { template < index_t dimension > class OpenGeodePolyhedralSolid< dimension >::Impl - : public internal::PointsImpl< dimension > { friend class bitsery::Access; public: explicit Impl( OpenGeodePolyhedralSolid< dimension >& mesh ) - : internal::PointsImpl< dimension >( mesh ) { + detail::template initialize_crs< + OpenGeodePolyhedralSolid< dimension > >( mesh ); polyhedron_vertex_ptr_.emplace_back( 0 ); polyhedron_facet_ptr_.emplace_back( 0 ); polyhedron_adjacent_ptr_.emplace_back( 0 ); } + Impl() = default; + index_t get_polyhedron_vertex( const PolyhedronVertex& polyhedron_vertex ) const { @@ -319,8 +322,6 @@ namespace geode } private: - Impl() = default; - template < typename Archive > void serialize( Archive& serializer ) { @@ -345,9 +346,8 @@ namespace geode impl.polyhedron_adjacents_.max_size() ); archive.container4b( impl.polyhedron_adjacent_ptr_, impl.polyhedron_adjacent_ptr_.max_size() ); - archive.ext( - impl, bitsery::ext::BaseClass< - internal::PointsImpl< dimension > >{} ); + internal::PointsImpl< dimension > temp; + archive.object( temp ); }, []( Archive& archive, Impl& impl ) { archive.container4b( impl.polyhedron_vertices_, @@ -362,9 +362,8 @@ namespace geode impl.polyhedron_adjacents_.max_size() ); archive.container4b( impl.polyhedron_adjacent_ptr_, impl.polyhedron_adjacent_ptr_.max_size() ); - archive.ext( impl, - bitsery::ext::BaseClass< - internal::PointsImpl< dimension > >{} ); + internal::PointsImpl< dimension > temp; + archive.object( temp ); } } } ); } @@ -414,6 +413,13 @@ namespace geode { } + template < index_t dimension > + OpenGeodePolyhedralSolid< dimension >::OpenGeodePolyhedralSolid( + BITSERY bitsery ) + : PolyhedralSolid< dimension >{ bitsery } + { + } + template < index_t dimension > OpenGeodePolyhedralSolid< dimension >::OpenGeodePolyhedralSolid( OpenGeodePolyhedralSolid&& ) noexcept = default; @@ -427,14 +433,6 @@ namespace geode OpenGeodePolyhedralSolid< dimension >::~OpenGeodePolyhedralSolid() = default; - template < index_t dimension > - void OpenGeodePolyhedralSolid< dimension >::set_vertex( index_t vertex_id, - Point< dimension > point, - OGPolyhedralSolidKey /*key*/ ) - { - impl_->set_point( vertex_id, std::move( point ) ); - } - template < index_t dimension > index_t OpenGeodePolyhedralSolid< dimension >::get_polyhedron_vertex( const PolyhedronVertex& polyhedron_vertex ) const @@ -541,8 +539,32 @@ namespace geode archive.ext( solid, bitsery::ext::BaseClass< PolyhedralSolid< dimension > >{} ); archive.object( solid.impl_ ); - solid.impl_->initialize_crs( solid ); + const auto new_point_attribute_id = + solid.vertex_attribute_manager() + .attribute_ids_matching_name( internal::PointsImpl< + dimension >::POINTS_NAME ) + .value() + .at( 0 ); + detail::template initialize_crs< + OpenGeodePolyhedralSolid< dimension > >( + solid, new_point_attribute_id ); }, + []( Archive& archive, OpenGeodePolyhedralSolid& solid ) { + archive.ext( + solid, bitsery::ext::BaseClass< + PolyhedralSolid< dimension > >{} ); + archive.object( solid.impl_ ); + const auto new_point_attribute_id = + solid.vertex_attribute_manager() + .attribute_ids_matching_name( + internal::PointsImpl< + dimension >::POINTS_NAME ) + .value() + .at( 0 ); + detail::template initialize_crs< + OpenGeodePolyhedralSolid< dimension > >( + solid, new_point_attribute_id ); + }, []( Archive& archive, OpenGeodePolyhedralSolid& solid ) { archive.ext( solid, bitsery::ext::BaseClass< diff --git a/src/geode/mesh/core/geode/geode_regular_grid_solid.cpp b/src/geode/mesh/core/geode/geode_regular_grid_solid.cpp index 3502956b7..a24b3b629 100644 --- a/src/geode/mesh/core/geode/geode_regular_grid_solid.cpp +++ b/src/geode/mesh/core/geode/geode_regular_grid_solid.cpp @@ -35,6 +35,7 @@ #include #include #include +#include namespace { @@ -58,10 +59,13 @@ namespace geode public: Impl( OpenGeodeRegularGrid< 3 >& mesh ) - : internal::PointsImpl< 3 >( mesh ) { + detail::template initialize_crs< OpenGeodeRegularGrid< 3 > >( + mesh ); } + Impl() = default; + void update_origin( RegularGrid3D& grid, const Point3D& origin ) { do_update_origin( grid, origin ); @@ -123,24 +127,27 @@ namespace geode } private: - Impl() = default; - template < typename Archive > void serialize( Archive& serializer ) { - serializer.ext( *this, Growable< Archive, - Impl >{ { []( Archive& archive, - Impl& impl ) { - archive.ext( impl, - bitsery::ext::BaseClass< internal::PointsImpl< 3 > >{} ); - archive.ext( impl, - bitsery::ext::BaseClass< internal::GridImpl< 3 > >{} ); - } } } ); + serializer.ext( + *this, Growable< Archive, Impl >{ { []( Archive& archive, + Impl& impl ) { + internal::PointsImpl< 3 > temp; + archive.object( temp ); + archive.ext( impl, + bitsery::ext::BaseClass< internal::GridImpl< 3 > >{} ); + } } } ); } }; OpenGeodeRegularGrid< 3 >::OpenGeodeRegularGrid() : impl_( *this ) {} + OpenGeodeRegularGrid< 3 >::OpenGeodeRegularGrid( BITSERY bitsery ) + : RegularGrid< 3 >{ bitsery } + { + } + OpenGeodeRegularGrid< 3 >::OpenGeodeRegularGrid( OpenGeodeRegularGrid&& ) noexcept = default; @@ -214,8 +221,30 @@ namespace geode archive.ext( grid, bitsery::ext::BaseClass< RegularGrid< 3 > >{} ); archive.object( grid.impl_ ); - grid.impl_->initialize_crs( grid ); + const auto new_point_attribute_id = + grid.vertex_attribute_manager() + .attribute_ids_matching_name( + internal::PointsImpl< 3 >::POINTS_NAME ) + .value() + .at( 0 ); + detail::template initialize_crs< + OpenGeodeRegularGrid< 3 > >( + grid, new_point_attribute_id ); }, + []( Archive& archive, OpenGeodeRegularGrid& grid ) { + archive.ext( grid, + bitsery::ext::BaseClass< RegularGrid< 3 > >{} ); + archive.object( grid.impl_ ); + const auto new_point_attribute_id = + grid.vertex_attribute_manager() + .attribute_ids_matching_name( + internal::PointsImpl< 3 >::POINTS_NAME ) + .value() + .at( 0 ); + detail::template initialize_crs< + OpenGeodeRegularGrid< 3 > >( + grid, new_point_attribute_id ); + }, []( Archive& archive, OpenGeodeRegularGrid& grid ) { archive.ext( grid, bitsery::ext::BaseClass< RegularGrid< 3 > >{} ); diff --git a/src/geode/mesh/core/geode/geode_regular_grid_surface.cpp b/src/geode/mesh/core/geode/geode_regular_grid_surface.cpp index 62ee9f0a4..e763c5b41 100644 --- a/src/geode/mesh/core/geode/geode_regular_grid_surface.cpp +++ b/src/geode/mesh/core/geode/geode_regular_grid_surface.cpp @@ -34,6 +34,7 @@ #include #include #include +#include namespace { @@ -47,17 +48,19 @@ namespace namespace geode { - class OpenGeodeRegularGrid< 2 >::Impl : public internal::PointsImpl< 2 >, - public internal::GridImpl< 2 > + class OpenGeodeRegularGrid< 2 >::Impl : public internal::GridImpl< 2 > { friend class bitsery::Access; public: Impl( OpenGeodeRegularGrid< 2 >& mesh ) - : internal::PointsImpl< 2 >( mesh ) { + detail::template initialize_crs< OpenGeodeRegularGrid< 2 > >( + mesh ); } + Impl() = default; + void update_origin( RegularGrid2D& grid, const Point2D& origin ) { do_update_origin( grid, origin ); @@ -108,24 +111,27 @@ namespace geode } private: - Impl() = default; - template < typename Archive > void serialize( Archive& serializer ) { - serializer.ext( *this, Growable< Archive, - Impl >{ { []( Archive& archive, - Impl& impl ) { - archive.ext( impl, - bitsery::ext::BaseClass< internal::PointsImpl< 2 > >{} ); - archive.ext( impl, - bitsery::ext::BaseClass< internal::GridImpl< 2 > >{} ); - } } } ); + serializer.ext( + *this, Growable< Archive, Impl >{ { []( Archive& archive, + Impl& impl ) { + internal::PointsImpl< 2 > temp; + archive.object( temp ); + archive.ext( impl, + bitsery::ext::BaseClass< internal::GridImpl< 2 > >{} ); + } } } ); } }; OpenGeodeRegularGrid< 2 >::OpenGeodeRegularGrid() : impl_( *this ) {} + OpenGeodeRegularGrid< 2 >::OpenGeodeRegularGrid( BITSERY bitsery ) + : RegularGrid< 2 >{ bitsery } + { + } + OpenGeodeRegularGrid< 2 >::OpenGeodeRegularGrid( OpenGeodeRegularGrid&& ) noexcept = default; @@ -193,8 +199,30 @@ namespace geode archive.ext( grid, bitsery::ext::BaseClass< RegularGrid< 2 > >{} ); archive.object( grid.impl_ ); - grid.impl_->initialize_crs( grid ); + const auto new_point_attribute_id = + grid.vertex_attribute_manager() + .attribute_ids_matching_name( + internal::PointsImpl< 2 >::POINTS_NAME ) + .value() + .at( 0 ); + detail::template initialize_crs< + OpenGeodeRegularGrid< 2 > >( + grid, new_point_attribute_id ); }, + []( Archive& archive, OpenGeodeRegularGrid& grid ) { + archive.ext( grid, + bitsery::ext::BaseClass< RegularGrid< 2 > >{} ); + archive.object( grid.impl_ ); + const auto new_point_attribute_id = + grid.vertex_attribute_manager() + .attribute_ids_matching_name( + internal::PointsImpl< 2 >::POINTS_NAME ) + .value() + .at( 0 ); + detail::template initialize_crs< + OpenGeodeRegularGrid< 2 > >( + grid, new_point_attribute_id ); + }, []( Archive& archive, OpenGeodeRegularGrid& grid ) { archive.ext( grid, bitsery::ext::BaseClass< RegularGrid< 2 > >{} ); diff --git a/src/geode/mesh/core/geode/geode_tetrahedral_solid.cpp b/src/geode/mesh/core/geode/geode_tetrahedral_solid.cpp index 9195fa167..d0ec55671 100644 --- a/src/geode/mesh/core/geode/geode_tetrahedral_solid.cpp +++ b/src/geode/mesh/core/geode/geode_tetrahedral_solid.cpp @@ -37,33 +37,44 @@ #include #include +#include namespace geode { template < index_t dimension > class OpenGeodeTetrahedralSolid< dimension >::Impl - : public internal::PointsImpl< dimension > { friend class bitsery::Access; public: explicit Impl( OpenGeodeTetrahedralSolid< dimension >& mesh ) - : internal::PointsImpl< dimension >( mesh ), - tetrahedron_vertices_( mesh.polyhedron_attribute_manager() - .template find_or_create_attribute< VariableAttribute, - std::array< index_t, 4 > >( "tetrahedron_vertices", - std::array< index_t, 4 >{ - NO_ID, NO_ID, NO_ID, NO_ID }, - { false, false, false } ) ), - tetrahedron_adjacents_( mesh.polyhedron_attribute_manager() - .template find_or_create_attribute< VariableAttribute, - std::array< index_t, 4 > >( "tetrahedron_adjacents", - std::array< index_t, 4 >{ - NO_ID, NO_ID, NO_ID, NO_ID }, - { false, false, false } ) ) { + detail::template initialize_crs< + OpenGeodeTetrahedralSolid< dimension > >( mesh ); + const auto tetrahedron_vertices_id = + mesh.polyhedron_attribute_manager() + .template create_attribute< VariableAttribute, + std::array< index_t, 4 > >( "tetrahedron_vertices", + std::array< index_t, 4 >{ NO_ID, NO_ID, NO_ID, NO_ID }, + { false, false, false } ); + tetrahedron_vertices_ = + mesh.polyhedron_attribute_manager() + .template find_attribute< VariableAttribute, + std::array< index_t, 4 > >( tetrahedron_vertices_id ); + const auto tetrahedron_adjacents_id = + mesh.polyhedron_attribute_manager() + .template create_attribute< VariableAttribute, + std::array< index_t, 4 > >( "tetrahedron_adjacents", + std::array< index_t, 4 >{ NO_ID, NO_ID, NO_ID, NO_ID }, + { false, false, false } ); + tetrahedron_adjacents_ = + mesh.polyhedron_attribute_manager() + .template find_attribute< VariableAttribute, + std::array< index_t, 4 > >( tetrahedron_adjacents_id ); } + Impl() = default; + index_t get_polyhedron_vertex( const PolyhedronVertex& polyhedron_vertex ) const { @@ -123,17 +134,14 @@ namespace geode } private: - Impl() = default; - template < typename Archive > void serialize( Archive& serializer ) { serializer.ext( *this, Growable< Archive, Impl >{ { []( Archive& archive, Impl& impl ) { - archive.ext( - impl, bitsery::ext::BaseClass< - internal::PointsImpl< dimension > >{} ); + internal::PointsImpl< dimension > temp; + archive.object( temp ); archive.ext( impl.tetrahedron_vertices_, bitsery::ext::StdSmartPtr{} ); archive.ext( impl.tetrahedron_adjacents_, @@ -154,9 +162,8 @@ namespace geode false } ); }, []( Archive& archive, Impl& impl ) { - archive.ext( impl, - bitsery::ext::BaseClass< - internal::PointsImpl< dimension > >{} ); + internal::PointsImpl< dimension > temp; + archive.object( temp ); archive.ext( impl.tetrahedron_vertices_, bitsery::ext::StdSmartPtr{} ); archive.ext( impl.tetrahedron_adjacents_, @@ -177,6 +184,13 @@ namespace geode { } + template < index_t dimension > + OpenGeodeTetrahedralSolid< dimension >::OpenGeodeTetrahedralSolid( + BITSERY bitsery ) + : TetrahedralSolid< dimension >{ bitsery } + { + } + template < index_t dimension > OpenGeodeTetrahedralSolid< dimension >::OpenGeodeTetrahedralSolid( OpenGeodeTetrahedralSolid&& ) noexcept = default; @@ -190,14 +204,6 @@ namespace geode OpenGeodeTetrahedralSolid< dimension >::~OpenGeodeTetrahedralSolid() = default; - template < index_t dimension > - void OpenGeodeTetrahedralSolid< dimension >::set_vertex( index_t vertex_id, - Point< dimension > point, - OGTetrahedralSolidKey /*key*/ ) - { - impl_->set_point( vertex_id, std::move( point ) ); - } - template < index_t dimension > index_t OpenGeodeTetrahedralSolid< dimension >::get_polyhedron_vertex( const PolyhedronVertex& polyhedron_vertex ) const @@ -233,8 +239,32 @@ namespace geode solid, bitsery::ext::BaseClass< TetrahedralSolid< dimension > >{} ); archive.object( solid.impl_ ); - solid.impl_->initialize_crs( solid ); + const auto new_point_attribute_id = + solid.vertex_attribute_manager() + .attribute_ids_matching_name( internal::PointsImpl< + dimension >::POINTS_NAME ) + .value() + .at( 0 ); + detail::template initialize_crs< + OpenGeodeTetrahedralSolid< dimension > >( + solid, new_point_attribute_id ); }, + []( Archive& archive, OpenGeodeTetrahedralSolid& solid ) { + archive.ext( + solid, bitsery::ext::BaseClass< + TetrahedralSolid< dimension > >{} ); + archive.object( solid.impl_ ); + const auto new_point_attribute_id = + solid.vertex_attribute_manager() + .attribute_ids_matching_name( + internal::PointsImpl< + dimension >::POINTS_NAME ) + .value() + .at( 0 ); + detail::template initialize_crs< + OpenGeodeTetrahedralSolid< dimension > >( + solid, new_point_attribute_id ); + }, []( Archive& archive, OpenGeodeTetrahedralSolid& solid ) { archive.ext( solid, bitsery::ext::BaseClass< diff --git a/src/geode/mesh/core/geode/geode_triangulated_surface.cpp b/src/geode/mesh/core/geode/geode_triangulated_surface.cpp index e0aa6c26e..04196ccc4 100644 --- a/src/geode/mesh/core/geode/geode_triangulated_surface.cpp +++ b/src/geode/mesh/core/geode/geode_triangulated_surface.cpp @@ -35,31 +35,44 @@ #include #include +#include namespace geode { template < index_t dimension > class OpenGeodeTriangulatedSurface< dimension >::Impl - : public internal::PointsImpl< dimension > { friend class bitsery::Access; public: explicit Impl( OpenGeodeTriangulatedSurface< dimension >& mesh ) - : internal::PointsImpl< dimension >( mesh ), - triangle_vertices_( mesh.polygon_attribute_manager() - .template find_or_create_attribute< VariableAttribute, - std::array< index_t, 3 > >( "triangle_vertices", - std::array< index_t, 3 >{ NO_ID, NO_ID, NO_ID }, - { false, false, false } ) ), - triangle_adjacents_( mesh.polygon_attribute_manager() - .template find_or_create_attribute< VariableAttribute, - std::array< index_t, 3 > >( "triangle_adjacents", - std::array< index_t, 3 >{ NO_ID, NO_ID, NO_ID }, - { false, false, false } ) ) { + detail::template initialize_crs< + OpenGeodeTriangulatedSurface< dimension > >( mesh ); + const auto triangle_vertices_id = + mesh.polygon_attribute_manager() + .template create_attribute< VariableAttribute, + std::array< index_t, 3 > >( "triangle_vertices", + std::array< index_t, 3 >{ NO_ID, NO_ID, NO_ID }, + { false, false, false } ); + triangle_vertices_ = + mesh.polygon_attribute_manager() + .template find_attribute< VariableAttribute, + std::array< index_t, 3 > >( triangle_vertices_id ); + const auto triangle_adjacents_id = + mesh.polygon_attribute_manager() + .template create_attribute< VariableAttribute, + std::array< index_t, 3 > >( "triangle_adjacents", + std::array< index_t, 3 >{ NO_ID, NO_ID, NO_ID }, + { false, false, false } ); + triangle_adjacents_ = + mesh.polygon_attribute_manager() + .template find_attribute< VariableAttribute, + std::array< index_t, 3 > >( triangle_adjacents_id ); } + Impl() = default; + index_t get_polygon_vertex( const PolygonVertex& polygon_vertex ) const { return triangle_vertices_->value( polygon_vertex.polygon_id ) @@ -108,17 +121,14 @@ namespace geode } private: - Impl() = default; - template < typename Archive > void serialize( Archive& serializer ) { serializer.ext( *this, Growable< Archive, Impl >{ { []( Archive& archive, Impl& impl ) { - archive.ext( - impl, bitsery::ext::BaseClass< - internal::PointsImpl< dimension > >{} ); + internal::PointsImpl< dimension > temp; + archive.object( temp ); archive.ext( impl.triangle_vertices_, bitsery::ext::StdSmartPtr{} ); archive.ext( impl.triangle_adjacents_, @@ -137,9 +147,8 @@ namespace geode false } ); }, []( Archive& archive, Impl& impl ) { - archive.ext( impl, - bitsery::ext::BaseClass< - internal::PointsImpl< dimension > >{} ); + internal::PointsImpl< dimension > temp; + archive.object( temp ); archive.ext( impl.triangle_vertices_, bitsery::ext::StdSmartPtr{} ); archive.ext( impl.triangle_adjacents_, @@ -160,6 +169,13 @@ namespace geode { } + template < index_t dimension > + OpenGeodeTriangulatedSurface< dimension >::OpenGeodeTriangulatedSurface( + BITSERY bitsery ) + : TriangulatedSurface< dimension >{ bitsery } + { + } + template < index_t dimension > OpenGeodeTriangulatedSurface< dimension >::OpenGeodeTriangulatedSurface( OpenGeodeTriangulatedSurface&& ) noexcept = default; @@ -173,15 +189,6 @@ namespace geode OpenGeodeTriangulatedSurface< dimension >::~OpenGeodeTriangulatedSurface() = default; - template < index_t dimension > - void OpenGeodeTriangulatedSurface< dimension >::set_vertex( - index_t vertex_id, - Point< dimension > point, - OGTriangulatedSurfaceKey /*key*/ ) - { - impl_->set_point( vertex_id, std::move( point ) ); - } - template < index_t dimension > index_t OpenGeodeTriangulatedSurface< dimension >::get_polygon_vertex( const PolygonVertex& polygon_vertex ) const @@ -210,8 +217,33 @@ namespace geode surface, bitsery::ext::BaseClass< TriangulatedSurface< dimension > >{} ); archive.object( surface.impl_ ); - surface.impl_->initialize_crs( surface ); + const auto new_point_attribute_id = + surface.vertex_attribute_manager() + .attribute_ids_matching_name( internal::PointsImpl< + dimension >::POINTS_NAME ) + .value() + .at( 0 ); + detail::template initialize_crs< + OpenGeodeTriangulatedSurface< dimension > >( + surface, new_point_attribute_id ); }, + []( Archive& archive, + OpenGeodeTriangulatedSurface& surface ) { + archive.ext( + surface, bitsery::ext::BaseClass< + TriangulatedSurface< dimension > >{} ); + archive.object( surface.impl_ ); + const auto new_point_attribute_id = + surface.vertex_attribute_manager() + .attribute_ids_matching_name( + internal::PointsImpl< + dimension >::POINTS_NAME ) + .value() + .at( 0 ); + detail::template initialize_crs< + OpenGeodeTriangulatedSurface< dimension > >( + surface, new_point_attribute_id ); + }, []( Archive& archive, OpenGeodeTriangulatedSurface& surface ) { archive.ext( diff --git a/src/geode/mesh/core/graph.cpp b/src/geode/mesh/core/graph.cpp index 4cb4eefa5..943bae5aa 100644 --- a/src/geode/mesh/core/graph.cpp +++ b/src/geode/mesh/core/graph.cpp @@ -47,14 +47,20 @@ namespace geode public: explicit Impl( Graph& graph ) - : edges_around_vertex_( graph.vertex_attribute_manager() - .template find_or_create_attribute< VariableAttribute, - EdgesAroundVertex >( ATTRIBUTE_NAME, - EdgesAroundVertex{}, - { false, false, false } ) ) { + const auto attribute_id = + graph.vertex_attribute_manager() + .template create_attribute< VariableAttribute, + EdgesAroundVertex >( ATTRIBUTE_NAME, + EdgesAroundVertex{}, { false, false, false } ); + edges_around_vertex_ = + graph.vertex_attribute_manager() + .template find_attribute< VariableAttribute, + EdgesAroundVertex >( attribute_id ); } + Impl() = default; + AttributeManager& edge_attribute_manager() const { return edge_attribute_manager_; @@ -108,8 +114,6 @@ namespace geode } private: - Impl() = default; - template < typename Archive > void serialize( Archive& serializer ) { @@ -159,6 +163,8 @@ namespace geode Graph::Graph() : impl_( *this ) {} + Graph::Graph( BITSERY ) {} + Graph::Graph( Graph&& ) noexcept = default; Graph& Graph::operator=( Graph&& ) noexcept = default; diff --git a/src/geode/mesh/core/hybrid_solid.cpp b/src/geode/mesh/core/hybrid_solid.cpp index 10f51aeee..3277fb456 100644 --- a/src/geode/mesh/core/hybrid_solid.cpp +++ b/src/geode/mesh/core/hybrid_solid.cpp @@ -30,6 +30,12 @@ namespace geode { + template < index_t dimension > + HybridSolid< dimension >::HybridSolid( BITSERY bitsery ) + : SolidMesh< dimension >{ bitsery } + { + } + template < index_t dimension > std::unique_ptr< HybridSolid< dimension > > HybridSolid< dimension >::create() diff --git a/src/geode/mesh/core/polygonal_surface.cpp b/src/geode/mesh/core/polygonal_surface.cpp index 70568e84c..6b3163edf 100644 --- a/src/geode/mesh/core/polygonal_surface.cpp +++ b/src/geode/mesh/core/polygonal_surface.cpp @@ -28,6 +28,12 @@ namespace geode { + template < index_t dimension > + PolygonalSurface< dimension >::PolygonalSurface( BITSERY bitsery ) + : SurfaceMesh< dimension >{ bitsery } + { + } + template < index_t dimension > std::unique_ptr< PolygonalSurface< dimension > > PolygonalSurface< dimension >::create() diff --git a/src/geode/mesh/core/polyhedral_solid.cpp b/src/geode/mesh/core/polyhedral_solid.cpp index 38d9c8a4b..d18d9fe4b 100644 --- a/src/geode/mesh/core/polyhedral_solid.cpp +++ b/src/geode/mesh/core/polyhedral_solid.cpp @@ -30,6 +30,12 @@ namespace geode { + template < index_t dimension > + PolyhedralSolid< dimension >::PolyhedralSolid( BITSERY bitsery ) + : SolidMesh< dimension >{ bitsery } + { + } + template < index_t dimension > std::unique_ptr< PolyhedralSolid< dimension > > PolyhedralSolid< dimension >::create() diff --git a/src/geode/mesh/core/regular_grid_solid.cpp b/src/geode/mesh/core/regular_grid_solid.cpp index 9c98bda2c..ba05efed8 100644 --- a/src/geode/mesh/core/regular_grid_solid.cpp +++ b/src/geode/mesh/core/regular_grid_solid.cpp @@ -32,6 +32,10 @@ namespace geode { + RegularGrid< 3 >::RegularGrid( BITSERY bitsery ) : SolidMesh< 3 >{ bitsery } + { + } + std::unique_ptr< RegularGrid< 3 > > RegularGrid< 3 >::create() { return MeshFactory::create_default_mesh< RegularGrid< 3 > >( diff --git a/src/geode/mesh/core/regular_grid_surface.cpp b/src/geode/mesh/core/regular_grid_surface.cpp index 8aba27c74..e84901e10 100644 --- a/src/geode/mesh/core/regular_grid_surface.cpp +++ b/src/geode/mesh/core/regular_grid_surface.cpp @@ -32,6 +32,11 @@ namespace geode { + RegularGrid< 2 >::RegularGrid( BITSERY bitsery ) + : SurfaceMesh< 2 >{ bitsery } + { + } + std::unique_ptr< RegularGrid< 2 > > RegularGrid< 2 >::create() { return MeshFactory::create_default_mesh< RegularGrid< 2 > >( diff --git a/src/geode/mesh/core/solid_edges.cpp b/src/geode/mesh/core/solid_edges.cpp index bf10fde3a..fe2d57459 100644 --- a/src/geode/mesh/core/solid_edges.cpp +++ b/src/geode/mesh/core/solid_edges.cpp @@ -65,7 +65,10 @@ namespace geode friend class bitsery::Access; public: - Impl() = default; + Impl() : internal::FacetEdgesImpl< dimension >{ BITSERY::constructor } + { + } + Impl( const SolidMesh< dimension >& solid ) { for( const auto p : Range{ solid.nb_polyhedra() } ) diff --git a/src/geode/mesh/core/solid_facets.cpp b/src/geode/mesh/core/solid_facets.cpp index 2991ea9a9..c5e49e203 100644 --- a/src/geode/mesh/core/solid_facets.cpp +++ b/src/geode/mesh/core/solid_facets.cpp @@ -68,7 +68,13 @@ namespace geode detail::VertexCycle< PolyhedronFacetVertices >; public: - Impl() = default; + Impl() + : detail::FacetStorage< PolyhedronFacetVertices >{ + BITSERY::constructor + } + { + } + Impl( const SolidMesh< dimension >& solid ) { for( const auto p : Range{ solid.nb_polyhedra() } ) diff --git a/src/geode/mesh/core/solid_mesh.cpp b/src/geode/mesh/core/solid_mesh.cpp index c5a06d876..72a3434e8 100644 --- a/src/geode/mesh/core/solid_mesh.cpp +++ b/src/geode/mesh/core/solid_mesh.cpp @@ -435,17 +435,20 @@ namespace geode using CachedPolyhedra = CachedValue< internal::PolyhedraAroundVertexImpl >; static constexpr auto POLYHEDRA_AROUND_VERTEX_NAME = - "polyhedra_around_vertex"; public: explicit Impl( SolidMesh& solid ) - : polyhedron_around_vertex_( solid.vertex_attribute_manager() - .template find_or_create_attribute< VariableAttribute, - PolyhedronVertex >( "polyhedron_around_vertex", - PolyhedronVertex{}, - { false, false, false } ) ) { + const auto attribute_id = + solid.vertex_attribute_manager() + .template create_attribute< VariableAttribute, + PolyhedronVertex >( "polyhedron_around_vertex", + PolyhedronVertex{}, { false, false, false } ); + polyhedron_around_vertex_ = + solid.vertex_attribute_manager() + .template find_attribute< VariableAttribute, + PolyhedronVertex >( attribute_id ); initialize_polyhedra_around_vertex( solid ); } @@ -678,11 +681,15 @@ namespace geode void initialize_polyhedra_around_vertex( const SolidMesh< dimension >& solid ) { - polyhedra_around_vertex_ = + const auto attribute_id = solid.vertex_attribute_manager() - .template find_or_create_attribute< VariableAttribute, + .template create_attribute< VariableAttribute, CachedPolyhedra >( POLYHEDRA_AROUND_VERTEX_NAME, CachedPolyhedra{}, { false, false, false } ); + polyhedra_around_vertex_ = + solid.vertex_attribute_manager() + .template find_attribute< VariableAttribute, + CachedPolyhedra >( attribute_id ); } const internal::PolyhedraAroundVertexImpl& @@ -705,9 +712,9 @@ namespace geode return cached.value(); } - private: Impl() = default; + private: template < typename Archive > void serialize( Archive& serializer ) { @@ -823,6 +830,11 @@ namespace geode { } + template < index_t dimension > + SolidMesh< dimension >::SolidMesh( BITSERY ) + { + } + template < index_t dimension > SolidMesh< dimension >::SolidMesh( SolidMesh&& ) noexcept = default; @@ -1735,8 +1747,8 @@ namespace geode { []( Archive& archive, SolidMesh& solid ) { archive.ext( solid, bitsery::ext::BaseClass< VertexSet >{} ); - archive.object( solid.impl_ ); solid.impl_->initialize_polyhedra_around_vertex( solid ); + archive.object( solid.impl_ ); }, []( Archive& archive, SolidMesh& solid ) { archive.ext( diff --git a/src/geode/mesh/core/surface_edges.cpp b/src/geode/mesh/core/surface_edges.cpp index 499ee7b81..f8f42ffce 100644 --- a/src/geode/mesh/core/surface_edges.cpp +++ b/src/geode/mesh/core/surface_edges.cpp @@ -64,7 +64,10 @@ namespace geode friend class bitsery::Access; public: - Impl() = default; + Impl() : internal::FacetEdgesImpl< dimension >{ BITSERY::constructor } + { + } + Impl( const SurfaceMesh< dimension >& surface ) { for( const auto p : Range{ surface.nb_polygons() } ) diff --git a/src/geode/mesh/core/surface_mesh.cpp b/src/geode/mesh/core/surface_mesh.cpp index 11fe1b75f..fb0e756bb 100644 --- a/src/geode/mesh/core/surface_mesh.cpp +++ b/src/geode/mesh/core/surface_mesh.cpp @@ -284,12 +284,16 @@ namespace geode public: Impl( SurfaceMesh& surface ) - : polygon_around_vertex_( surface.vertex_attribute_manager() - .template find_or_create_attribute< VariableAttribute, - PolygonVertex >( "polygon_around_vertex", - PolygonVertex{}, - { false, false, false } ) ) { + const auto attribute_id = + surface.vertex_attribute_manager() + .template create_attribute< VariableAttribute, + PolygonVertex >( "polygon_around_vertex", + PolygonVertex{}, { false, false, false } ); + polygon_around_vertex_ = + surface.vertex_attribute_manager() + .template find_attribute< VariableAttribute, + PolygonVertex >( attribute_id ); initialize_polygons_around_vertex( surface ); } @@ -387,7 +391,7 @@ namespace geode edges_.reset( new SurfaceEdges< dimension >{ surface } ); } - void copy_edges( const SurfaceMesh< dimension >& surface ) const + void copy_edges( const SurfaceMesh< dimension >& from_surface ) const { OpenGeodeMeshException::check_exception( !are_edges_enabled(), nullptr, OpenGeodeException::TYPE::data, @@ -395,7 +399,7 @@ namespace geode "already enabled." ); edges_.reset( new SurfaceEdges< dimension >{} ); SurfaceEdgesBuilder< dimension > edges_builder{ *edges_ }; - edges_builder.copy( surface.edges() ); + edges_builder.copy( from_surface.edges() ); } void disable_edges() const @@ -432,16 +436,20 @@ namespace geode void initialize_polygons_around_vertex( const SurfaceMesh< dimension >& surface ) { - polygons_around_vertex_ = + const auto attribute_id = surface.vertex_attribute_manager() - .template find_or_create_attribute< VariableAttribute, + .template create_attribute< VariableAttribute, CachedPolygons >( POLYGONS_AROUND_VERTEX_NAME, CachedPolygons{}, { false, false, false } ); + polygons_around_vertex_ = + surface.vertex_attribute_manager() + .template find_attribute< VariableAttribute, + CachedPolygons >( attribute_id ); } - private: Impl() = default; + private: template < typename Archive > void serialize( Archive& serializer ) { @@ -565,6 +573,11 @@ namespace geode { } + template < index_t dimension > + SurfaceMesh< dimension >::SurfaceMesh( BITSERY ) + { + } + template < index_t dimension > SurfaceMesh< dimension >::SurfaceMesh( SurfaceMesh&& ) noexcept = default; @@ -1091,9 +1104,9 @@ namespace geode { []( Archive& archive, SurfaceMesh& surface ) { archive.ext( surface, bitsery::ext::BaseClass< VertexSet >{} ); - archive.object( surface.impl_ ); surface.impl_->initialize_polygons_around_vertex( surface ); + archive.object( surface.impl_ ); }, []( Archive& archive, SurfaceMesh& surface ) { archive.ext( diff --git a/src/geode/mesh/core/tetrahedral_solid.cpp b/src/geode/mesh/core/tetrahedral_solid.cpp index e3a9d5507..507485ba8 100644 --- a/src/geode/mesh/core/tetrahedral_solid.cpp +++ b/src/geode/mesh/core/tetrahedral_solid.cpp @@ -156,6 +156,12 @@ namespace namespace geode { + template < index_t dimension > + TetrahedralSolid< dimension >::TetrahedralSolid( BITSERY bitsery ) + : SolidMesh< dimension >{ bitsery } + { + } + template < index_t dimension > std::unique_ptr< TetrahedralSolid< dimension > > TetrahedralSolid< dimension >::create() diff --git a/src/geode/mesh/core/texture1d.cpp b/src/geode/mesh/core/texture1d.cpp index 8a292f5e0..005c2fb2a 100644 --- a/src/geode/mesh/core/texture1d.cpp +++ b/src/geode/mesh/core/texture1d.cpp @@ -103,6 +103,11 @@ namespace geode impl_->set_texture_coordinates( vertex, coordinates ); } + geode::uuid Texture< 1 >::texture_id() const + { + return impl_->texture_id(); + } + template < typename Archive > void Texture< 1 >::serialize( Archive& serializer ) { diff --git a/src/geode/mesh/core/texture2d.cpp b/src/geode/mesh/core/texture2d.cpp index f2f3aa1f6..7888d657c 100644 --- a/src/geode/mesh/core/texture2d.cpp +++ b/src/geode/mesh/core/texture2d.cpp @@ -104,6 +104,11 @@ namespace geode impl_->set_texture_coordinates( vertex, coordinates ); } + geode::uuid Texture< 2 >::texture_id() const + { + return impl_->texture_id(); + } + template < typename Archive > void Texture< 2 >::serialize( Archive& serializer ) { diff --git a/src/geode/mesh/core/texture3d.cpp b/src/geode/mesh/core/texture3d.cpp index 912bc1411..c32d7aaa3 100644 --- a/src/geode/mesh/core/texture3d.cpp +++ b/src/geode/mesh/core/texture3d.cpp @@ -105,6 +105,11 @@ namespace geode impl_->set_texture_coordinates( vertex, coordinates ); } + geode::uuid Texture< 3 >::texture_id() const + { + return impl_->texture_id(); + } + template < typename Archive > void Texture< 3 >::serialize( Archive& serializer ) { diff --git a/src/geode/mesh/core/texture_manager.cpp b/src/geode/mesh/core/texture_manager.cpp index c1f426621..f77b155c9 100644 --- a/src/geode/mesh/core/texture_manager.cpp +++ b/src/geode/mesh/core/texture_manager.cpp @@ -73,8 +73,10 @@ namespace geode void delete_texture( std::string_view name ) { + const auto& texture = textures_.find_texture( name, {} ); + const auto texture_id = texture.texture_id(); textures_.delete_texture( name, {} ); - manager_.delete_attribute( name ); + manager_.delete_attribute( texture_id ); } private: diff --git a/src/geode/mesh/core/triangulated_surface.cpp b/src/geode/mesh/core/triangulated_surface.cpp index 99d3f59bd..723fcd2f2 100644 --- a/src/geode/mesh/core/triangulated_surface.cpp +++ b/src/geode/mesh/core/triangulated_surface.cpp @@ -32,6 +32,13 @@ namespace geode { + + template < index_t dimension > + TriangulatedSurface< dimension >::TriangulatedSurface( BITSERY bitsery ) + : SurfaceMesh< dimension >{ bitsery } + { + } + template < index_t dimension > std::unique_ptr< TriangulatedSurface< dimension > > TriangulatedSurface< dimension >::create() diff --git a/src/geode/mesh/helpers/convert_grid.cpp b/src/geode/mesh/helpers/convert_grid.cpp index ff8df0b11..f362f3227 100644 --- a/src/geode/mesh/helpers/convert_grid.cpp +++ b/src/geode/mesh/helpers/convert_grid.cpp @@ -51,9 +51,14 @@ namespace geode cells_number, cells_directions }; IdentifierBuilder builder{ grid }; internal::copy_meta_info( raster, builder ); - auto color = grid.cell_attribute_manager() - .template find_or_create_attribute< VariableAttribute, - RGBColor >( "RGB_data", {} ); + auto color_attribute_id = + grid.cell_attribute_manager() + .template create_attribute< VariableAttribute, RGBColor >( + "RGB_data", {}, geode::AttributeProperties{} ); + auto color = + grid.cell_attribute_manager() + .template find_attribute< VariableAttribute, RGBColor >( + color_attribute_id ); for( const auto cell_id : geode::Range{ raster.nb_cells() } ) { color->set_value( cell_id, raster.color( cell_id ) ); diff --git a/src/geode/mesh/helpers/euclidean_distance_transform.cpp b/src/geode/mesh/helpers/euclidean_distance_transform.cpp index 940e86cb4..ace718e1f 100644 --- a/src/geode/mesh/helpers/euclidean_distance_transform.cpp +++ b/src/geode/mesh/helpers/euclidean_distance_transform.cpp @@ -41,13 +41,17 @@ namespace geode EuclideanDistanceTransform( const Grid< dimension >& grid, absl::Span< const Index > grid_cell_id, std::string_view distance_map_name ) - : grid_( grid ), - squared_cell_length_{}, - distance_map_{ grid.cell_attribute_manager() - .template find_or_create_attribute< VariableAttribute, - double >( distance_map_name, - std::numeric_limits< double >::max() ) } + : grid_( grid ), squared_cell_length_{} { + const auto distance_map_id = + grid.cell_attribute_manager() + .template create_attribute< VariableAttribute, double >( + distance_map_name, std::numeric_limits< double >::max(), + geode::AttributeProperties{} ); + distance_map_ = + grid.cell_attribute_manager() + .template find_attribute< VariableAttribute, double >( + distance_map_id ); for( const auto d : LRange( dimension ) ) { squared_cell_length_[d] = grid_.cell_length_in_direction( d ) diff --git a/src/geode/mesh/helpers/gradient_computation.cpp b/src/geode/mesh/helpers/gradient_computation.cpp index 10a347ab7..69202df90 100644 --- a/src/geode/mesh/helpers/gradient_computation.cpp +++ b/src/geode/mesh/helpers/gradient_computation.cpp @@ -34,7 +34,6 @@ #include #include #include - namespace { template < typename Mesh > @@ -42,10 +41,10 @@ namespace { public: ScalarGradientComputer( - const Mesh& mesh, std::string_view scalar_function_name ) + const Mesh& mesh, const geode::uuid& scalar_function_id ) : mesh_( mesh ), vertex_has_value_( mesh.nb_vertices(), true ) { - initialize_attribute_and_name( scalar_function_name ); + initialize_attribute_and_id( scalar_function_id ); for( const auto vertex_id : geode::Range{ mesh_.nb_vertices() } ) { if( std::isnan( scalar_function_->value( vertex_id ) ) ) @@ -56,26 +55,32 @@ namespace } ScalarGradientComputer( const Mesh& mesh, - std::string_view scalar_function_name, + const geode::uuid& scalar_function_id, absl::Span< const geode::index_t > no_value_vertices ) : mesh_( mesh ), vertex_has_value_( mesh.nb_vertices(), true ) { - initialize_attribute_and_name( scalar_function_name ); + initialize_attribute_and_id( scalar_function_id ); for( const auto vertex_id : no_value_vertices ) { vertex_has_value_[vertex_id] = false; } } - std::tuple< std::string, std::vector< geode::index_t > > + std::tuple< geode::uuid, std::vector< geode::index_t > > compute_scalar_function_gradient() const { + const auto gradient_function_name = + absl::StrCat( scalar_function_->name().value(), "_gradient" ); + auto gradient_function_id = + mesh_.vertex_attribute_manager() + .template create_attribute< geode::VariableAttribute, + geode::Vector< Mesh::dim > >( gradient_function_name, + geode::Vector< Mesh::dim >{}, + geode::AttributeProperties{} ); auto gradient_function = mesh_.vertex_attribute_manager() - .template find_or_create_attribute< - geode::VariableAttribute, geode::Vector< Mesh::dim > >( - output_gradient_attribute_name_, - geode::Vector< Mesh::dim >{} ); + .template find_attribute< geode::VariableAttribute, + geode::Vector< Mesh::dim > >( gradient_function_id ); std::vector< geode::index_t > no_gradient_value_vertices; for( const auto vertex_id : geode::Range{ mesh_.nb_vertices() } ) { @@ -84,39 +89,30 @@ namespace no_gradient_value_vertices.push_back( vertex_id ); } } - return std::make_tuple( output_gradient_attribute_name_, - std::move( no_gradient_value_vertices ) ); + return std::make_tuple( + gradient_function_id, std::move( no_gradient_value_vertices ) ); } private: - void initialize_attribute_and_name( - std::string_view scalar_function_name ) + void initialize_attribute_and_id( + const geode::uuid& scalar_function_id ) { geode::OpenGeodeMeshException::check_exception( mesh_.vertex_attribute_manager().attribute_exists( - scalar_function_name ), + scalar_function_id ), nullptr, geode::OpenGeodeException::TYPE::data, "[compute_scalar_function_gradient] No attribute exists with " - "given name." ); + "given id." ); geode::OpenGeodeMeshException::check_exception( mesh_.vertex_attribute_manager().attribute_type( - scalar_function_name ) + scalar_function_id ) == typeid( double ).name(), nullptr, geode::OpenGeodeException::TYPE::data, "[compute_scalar_function_gradient] The attribute linked to " - "given name is not scalar." ); - scalar_function_ = - mesh_.vertex_attribute_manager() - .template find_attribute< double >( scalar_function_name ); - output_gradient_attribute_name_ = - absl::StrCat( scalar_function_name, "_gradient" ); - geode::index_t counter{ 0 }; - while( mesh_.vertex_attribute_manager().attribute_exists( - absl::StrCat( output_gradient_attribute_name_, counter ) ) ) - { - counter++; - } - absl::StrAppend( &output_gradient_attribute_name_, counter ); + "given id is not scalar." ); + scalar_function_ = mesh_.vertex_attribute_manager() + .template find_read_only_attribute< double >( + scalar_function_id ); } bool compute_gradient( @@ -197,7 +193,6 @@ namespace private: const Mesh& mesh_; std::shared_ptr< geode::ReadOnlyAttribute< double > > scalar_function_; - std::string output_gradient_attribute_name_; std::vector< bool > vertex_has_value_; }; } // namespace @@ -205,61 +200,60 @@ namespace namespace geode { template < index_t dimension > - std::string compute_surface_scalar_function_gradient( - const SurfaceMesh< dimension >& mesh, - std::string_view scalar_function_name ) + geode::uuid compute_surface_scalar_function_gradient( + const SurfaceMesh< dimension >& mesh, const uuid& scalar_function_id ) { - ::ScalarGradientComputer computer{ mesh, scalar_function_name }; + ::ScalarGradientComputer computer{ mesh, scalar_function_id }; return std::get< 0 >( computer.compute_scalar_function_gradient() ); } - std::string compute_solid_scalar_function_gradient( - const SolidMesh3D& mesh, std::string_view scalar_function_name ) + geode::uuid compute_solid_scalar_function_gradient( + const SolidMesh3D& mesh, const uuid& scalar_function_id ) { - ::ScalarGradientComputer computer{ mesh, scalar_function_name }; + ::ScalarGradientComputer computer{ mesh, scalar_function_id }; return std::get< 0 >( computer.compute_scalar_function_gradient() ); } - template std::string opengeode_mesh_api + template geode::uuid opengeode_mesh_api compute_surface_scalar_function_gradient( - const SurfaceMesh2D&, std::string_view ); - template std::string opengeode_mesh_api + const SurfaceMesh2D&, const uuid& ); + template geode::uuid opengeode_mesh_api compute_surface_scalar_function_gradient( - const SurfaceMesh3D&, std::string_view ); + const SurfaceMesh3D&, const uuid& ); namespace internal { template < index_t dimension > - std::tuple< std::string, std::vector< index_t > > + std::tuple< geode::uuid, std::vector< index_t > > compute_surface_scalar_function_gradient( const SurfaceMesh< dimension >& mesh, - std::string_view scalar_function_name, + const uuid& scalar_function_id, absl::Span< const index_t > no_value_vertices ) { - ::ScalarGradientComputer computer{ mesh, scalar_function_name, + ::ScalarGradientComputer computer{ mesh, scalar_function_id, no_value_vertices }; return computer.compute_scalar_function_gradient(); } - std::tuple< std::string, std::vector< index_t > > + std::tuple< geode::uuid, std::vector< index_t > > compute_solid_scalar_function_gradient( const SolidMesh3D& mesh, - std::string_view scalar_function_name, + const uuid& scalar_function_id, absl::Span< const index_t > no_value_vertices ) { - ::ScalarGradientComputer computer{ mesh, scalar_function_name, + ::ScalarGradientComputer computer{ mesh, scalar_function_id, no_value_vertices }; return computer.compute_scalar_function_gradient(); } - template std::tuple< std::string, std::vector< index_t > > + template std::tuple< geode::uuid, std::vector< index_t > > opengeode_mesh_api compute_surface_scalar_function_gradient( const SurfaceMesh2D&, - std::string_view, + const uuid&, absl::Span< const index_t > ); - template std::tuple< std::string, std::vector< index_t > > + template std::tuple< geode::uuid, std::vector< index_t > > opengeode_mesh_api compute_surface_scalar_function_gradient( const SurfaceMesh3D&, - std::string_view, + const uuid&, absl::Span< const index_t > ); } // namespace internal } // namespace geode \ No newline at end of file diff --git a/src/geode/mesh/helpers/grid_point_function.cpp b/src/geode/mesh/helpers/grid_point_function.cpp index aa573460f..79b3fc20f 100644 --- a/src/geode/mesh/helpers/grid_point_function.cpp +++ b/src/geode/mesh/helpers/grid_point_function.cpp @@ -44,33 +44,29 @@ namespace geode Point< point_dimension > value ) : grid_( grid ) { - OpenGeodeMeshException::check_exception( - !grid_.grid_vertex_attribute_manager().attribute_exists( - function_name ), - nullptr, OpenGeodeException::TYPE::data, - "Cannot create GridPointFunction: attribute with name ", - function_name, " already exists." ); - function_attribute_ = + const auto function_id = grid_.grid_vertex_attribute_manager() - .template find_or_create_attribute< VariableAttribute, + .template create_attribute< VariableAttribute, Point< point_dimension > >( function_name, std::move( value ), { false, true } ); + function_attribute_ = + grid_.grid_vertex_attribute_manager() + .template find_attribute< VariableAttribute, + Point< point_dimension > >( function_id ); } - Impl( const Grid< dimension >& grid, std::string_view function_name ) + Impl( const Grid< dimension >& grid, std::string_view attribute_name ) : grid_( grid ) { - OpenGeodeMeshException::check_exception( - grid_.grid_vertex_attribute_manager().attribute_exists( - function_name ), - nullptr, OpenGeodeException::TYPE::data, - "Cannot create GridPointFunction: attribute with name", - function_name, " does not exist." ); - function_attribute_ = + const auto attribute_id = grid_.grid_vertex_attribute_manager() - .template find_or_create_attribute< VariableAttribute, - Point< point_dimension > >( function_name, + .template create_attribute< VariableAttribute, + Point< point_dimension > >( attribute_name, Point< point_dimension >(), { false, true } ); + function_attribute_ = + grid_.grid_vertex_attribute_manager() + .template find_attribute< VariableAttribute, + Point< point_dimension > >( attribute_id ); } void set_value( diff --git a/src/geode/mesh/helpers/grid_scalar_function.cpp b/src/geode/mesh/helpers/grid_scalar_function.cpp index 9c19d3618..6e9bed147 100644 --- a/src/geode/mesh/helpers/grid_scalar_function.cpp +++ b/src/geode/mesh/helpers/grid_scalar_function.cpp @@ -44,31 +44,27 @@ namespace geode double value ) : grid_( grid ) { - OpenGeodeMeshException::check_exception( - !grid_.grid_vertex_attribute_manager().attribute_exists( - function_name ), - nullptr, OpenGeodeException::TYPE::data, - "Cannot create GridScalarFunction: attribute with name ", - function_name, " already exists." ); + const auto function_id = + grid_.grid_vertex_attribute_manager() + .template create_attribute< VariableAttribute, double >( + function_name, value, { false, true } ); function_attribute_ = grid_.grid_vertex_attribute_manager() - .template find_or_create_attribute< VariableAttribute, - double >( function_name, value, { false, true } ); + .template find_attribute< VariableAttribute, double >( + function_id ); } Impl( const Grid< dimension >& grid, std::string_view function_name ) : grid_( grid ) { - OpenGeodeMeshException::check_exception( - grid_.grid_vertex_attribute_manager().attribute_exists( - function_name ), - nullptr, OpenGeodeException::TYPE::data, - "Cannot create GridScalarFunction: attribute with name", - function_name, " does not exist." ); + const auto function_id = + grid_.grid_vertex_attribute_manager() + .template create_attribute< VariableAttribute, double >( + function_name, 0, { false, true } ); function_attribute_ = grid_.grid_vertex_attribute_manager() - .template find_or_create_attribute< VariableAttribute, - double >( function_name, 0, { false, true } ); + .template find_attribute< VariableAttribute, double >( + function_id ); } void set_value( diff --git a/src/geode/mesh/helpers/tetrahedral_solid_point_function.cpp b/src/geode/mesh/helpers/tetrahedral_solid_point_function.cpp index 00e1f07ee..49153f16a 100644 --- a/src/geode/mesh/helpers/tetrahedral_solid_point_function.cpp +++ b/src/geode/mesh/helpers/tetrahedral_solid_point_function.cpp @@ -44,36 +44,25 @@ namespace geode Point< point_dimension > value ) : solid_( solid ) { - OpenGeodeMeshException::check_exception( - !solid_.vertex_attribute_manager().attribute_exists( - function_name ), - nullptr, OpenGeodeException::TYPE::data, - "Cannot create TetrahedralSolidPointFunction: attribute with " - "name '", - function_name, "' already exists." ); - function_attribute_ = + const auto function_id = solid_.vertex_attribute_manager() - .template find_or_create_attribute< VariableAttribute, + .template create_attribute< VariableAttribute, Point< point_dimension > >( function_name, std::move( value ), { false, true } ); + function_attribute_ = + solid_.vertex_attribute_manager() + .template find_attribute< VariableAttribute, + Point< point_dimension > >( function_id ); } Impl( const TetrahedralSolid< dimension >& solid, - std::string_view function_name ) + const uuid& function_id ) : solid_( solid ) { - OpenGeodeMeshException::check_exception( - solid_.vertex_attribute_manager().attribute_exists( - function_name ), - nullptr, OpenGeodeException::TYPE::data, - "Cannot create TetrahedralSolidPointFunction: attribute with " - "name '", - function_name, "' does not exist." ); function_attribute_ = solid_.vertex_attribute_manager() - .template find_or_create_attribute< VariableAttribute, - Point< point_dimension > >( function_name, - Point< point_dimension >(), { false, true } ); + .template find_attribute< VariableAttribute, + Point< point_dimension > >( function_id ); } void set_value( index_t vertex_id, Point< point_dimension > value ) @@ -104,6 +93,11 @@ namespace geode return point_value; } + uuid attribute_function_id() const + { + return function_attribute_->id(); + } + private: const TetrahedralSolid< dimension >& solid_; std::shared_ptr< VariableAttribute< Point< point_dimension > > > @@ -133,8 +127,8 @@ namespace geode TetrahedralSolidPointFunction< dimension, point_dimension >:: TetrahedralSolidPointFunction( const TetrahedralSolid< dimension >& solid, - std::string_view function_name ) - : impl_{ solid, function_name } + const uuid& function_id ) + : impl_{ solid, function_id } { } @@ -156,9 +150,9 @@ namespace geode TetrahedralSolidPointFunction< dimension, point_dimension > TetrahedralSolidPointFunction< dimension, point_dimension >::find( const TetrahedralSolid< dimension >& solid, - std::string_view function_name ) + const uuid& function_id ) { - return { solid, function_name }; + return { solid, function_id }; } template < index_t dimension, index_t point_dimension > @@ -184,6 +178,13 @@ namespace geode return impl_->value( point, tetrahedron_id ); } + template < index_t dimension, index_t point_dimension > + uuid TetrahedralSolidPointFunction< dimension, + point_dimension >::attribute_function_id() const + { + return impl_->attribute_function_id(); + } + template class opengeode_mesh_api TetrahedralSolidPointFunction< 3, 3 >; template class opengeode_mesh_api TetrahedralSolidPointFunction< 3, 2 >; template class opengeode_mesh_api TetrahedralSolidPointFunction< 3, 1 >; diff --git a/src/geode/mesh/helpers/tetrahedral_solid_scalar_function.cpp b/src/geode/mesh/helpers/tetrahedral_solid_scalar_function.cpp index c8700d330..c269ab994 100644 --- a/src/geode/mesh/helpers/tetrahedral_solid_scalar_function.cpp +++ b/src/geode/mesh/helpers/tetrahedral_solid_scalar_function.cpp @@ -43,34 +43,24 @@ namespace geode double value ) : solid_( solid ) { - OpenGeodeMeshException::check_exception( - !solid_.vertex_attribute_manager().attribute_exists( - function_name ), - nullptr, OpenGeodeException::TYPE::data, - "Cannot create TetrahedralSolidScalarFunction: attribute with " - "name '", - function_name, "' already exists." ); + const auto function_id = + solid_.vertex_attribute_manager() + .template create_attribute< VariableAttribute, double >( + function_name, value, { false, true } ); function_attribute_ = solid_.vertex_attribute_manager() - .template find_or_create_attribute< VariableAttribute, - double >( function_name, value, { false, true } ); + .template find_attribute< VariableAttribute, double >( + function_id ); } Impl( const TetrahedralSolid< dimension >& solid, - std::string_view function_name ) + const uuid& function_id ) : solid_( solid ) { - OpenGeodeMeshException::check_exception( - solid_.vertex_attribute_manager().attribute_exists( - function_name ), - nullptr, OpenGeodeException::TYPE::data, - "Cannot create TetrahedralSolidScalarFunction: attribute with " - "name '", - function_name, "' does not exist." ); function_attribute_ = solid_.vertex_attribute_manager() - .template find_or_create_attribute< VariableAttribute, - double >( function_name, 0, { false, true } ); + .template find_attribute< VariableAttribute, double >( + function_id ); } void set_value( index_t vertex_id, double value ) @@ -101,6 +91,11 @@ namespace geode return point_value; } + uuid attribute_function_id() const + { + return function_attribute_->id(); + } + private: const TetrahedralSolid< dimension >& solid_; std::shared_ptr< VariableAttribute< double > > function_attribute_; @@ -121,9 +116,8 @@ namespace geode template < index_t dimension > TetrahedralSolidScalarFunction< dimension >::TetrahedralSolidScalarFunction( - const TetrahedralSolid< dimension >& solid, - std::string_view function_name ) - : impl_{ solid, function_name } + const TetrahedralSolid< dimension >& solid, const uuid& function_id ) + : impl_{ solid, function_id } { } @@ -145,9 +139,9 @@ namespace geode TetrahedralSolidScalarFunction< dimension > TetrahedralSolidScalarFunction< dimension >::find( const TetrahedralSolid< dimension >& solid, - std::string_view function_name ) + const uuid& function_id ) { - return { solid, function_name }; + return { solid, function_id }; } template < index_t dimension > @@ -171,5 +165,12 @@ namespace geode return impl_->value( point, tetrahedron_id ); } + template < index_t dimension > + uuid TetrahedralSolidScalarFunction< dimension >::attribute_function_id() + const + { + return impl_->attribute_function_id(); + } + template class opengeode_mesh_api TetrahedralSolidScalarFunction< 3 >; } // namespace geode \ No newline at end of file diff --git a/src/geode/mesh/helpers/triangulated_surface_point_function.cpp b/src/geode/mesh/helpers/triangulated_surface_point_function.cpp index 56d9e6395..191877bae 100644 --- a/src/geode/mesh/helpers/triangulated_surface_point_function.cpp +++ b/src/geode/mesh/helpers/triangulated_surface_point_function.cpp @@ -44,36 +44,25 @@ namespace geode Point< point_dimension > value ) : surface_( surface ) { - OpenGeodeMeshException::check_exception( - !surface_.vertex_attribute_manager().attribute_exists( - function_name ), - nullptr, OpenGeodeException::TYPE::data, - "Cannot create TriangulatedSurfacePointFunction: attribute " - "with name '", - function_name, "' already exists." ); - function_attribute_ = + const auto function_id = surface_.vertex_attribute_manager() - .template find_or_create_attribute< VariableAttribute, + .template create_attribute< VariableAttribute, Point< point_dimension > >( function_name, std::move( value ), { false, true } ); + function_attribute_ = + surface_.vertex_attribute_manager() + .template find_attribute< VariableAttribute, + Point< point_dimension > >( function_id ); } Impl( const TriangulatedSurface< dimension >& surface, - std::string_view function_name ) + const uuid& function_id ) : surface_( surface ) { - OpenGeodeMeshException::check_exception( - surface_.vertex_attribute_manager().attribute_exists( - function_name ), - nullptr, OpenGeodeException::TYPE::data, - "Cannot create TriangulatedSurfacePointFunction: attribute " - "with name '", - function_name, "' does not exist." ); function_attribute_ = surface_.vertex_attribute_manager() - .template find_or_create_attribute< VariableAttribute, - Point< point_dimension > >( function_name, - Point< point_dimension >(), { false, true } ); + .template find_attribute< VariableAttribute, + Point< point_dimension > >( function_id ); } void set_value( index_t vertex_id, Point< point_dimension > value ) @@ -104,6 +93,11 @@ namespace geode return point_value; } + uuid attribute_function_id() const + { + return function_attribute_->id(); + } + private: const TriangulatedSurface< dimension >& surface_; std::shared_ptr< VariableAttribute< Point< point_dimension > > > @@ -133,8 +127,8 @@ namespace geode TriangulatedSurfacePointFunction< dimension, point_dimension >:: TriangulatedSurfacePointFunction( const TriangulatedSurface< dimension >& surface, - std::string_view function_name ) - : impl_{ surface, function_name } + const uuid& function_id ) + : impl_{ surface, function_id } { } @@ -156,9 +150,9 @@ namespace geode TriangulatedSurfacePointFunction< dimension, point_dimension > TriangulatedSurfacePointFunction< dimension, point_dimension >::find( const TriangulatedSurface< dimension >& surface, - std::string_view function_name ) + const uuid& function_id ) { - return { surface, function_name }; + return { surface, function_id }; } template < index_t dimension, index_t point_dimension > @@ -185,6 +179,13 @@ namespace geode return impl_->value( point, triangle_id ); } + template < index_t dimension, index_t point_dimension > + uuid TriangulatedSurfacePointFunction< dimension, + point_dimension >::attribute_function_id() const + { + return impl_->attribute_function_id(); + } + template class opengeode_mesh_api TriangulatedSurfacePointFunction< 2, 2 >; template class opengeode_mesh_api TriangulatedSurfacePointFunction< 2, 1 >; template class opengeode_mesh_api TriangulatedSurfacePointFunction< 3, 3 >; diff --git a/src/geode/mesh/helpers/triangulated_surface_scalar_function.cpp b/src/geode/mesh/helpers/triangulated_surface_scalar_function.cpp index da24e3e03..596cee2b4 100644 --- a/src/geode/mesh/helpers/triangulated_surface_scalar_function.cpp +++ b/src/geode/mesh/helpers/triangulated_surface_scalar_function.cpp @@ -44,34 +44,24 @@ namespace geode double value ) : surface_( surface ) { - OpenGeodeMeshException::check_exception( - !surface_.vertex_attribute_manager().attribute_exists( - function_name ), - nullptr, OpenGeodeException::TYPE::data, - "Cannot create TriangulatedSurfaceScalarFunction: attribute " - "with name '", - function_name, "' already exists." ); + const auto function_id = + surface_.vertex_attribute_manager() + .template create_attribute< VariableAttribute, double >( + function_name, value, { false, true } ); function_attribute_ = surface_.vertex_attribute_manager() - .template find_or_create_attribute< VariableAttribute, - double >( function_name, value, { false, true } ); + .template find_attribute< VariableAttribute, double >( + function_id ); } Impl( const TriangulatedSurface< dimension >& surface, - std::string_view function_name ) + const uuid& function_id ) : surface_( surface ) { - OpenGeodeMeshException::check_exception( - surface_.vertex_attribute_manager().attribute_exists( - function_name ), - nullptr, OpenGeodeException::TYPE::data, - "Cannot create TriangulatedSurfaceScalarFunction: attribute " - "with name '", - function_name, "' does not exist." ); function_attribute_ = surface_.vertex_attribute_manager() - .template find_or_create_attribute< VariableAttribute, - double >( function_name, 0, { false, true } ); + .template find_attribute< VariableAttribute, double >( + function_id ); } void set_value( index_t vertex_id, double value ) @@ -102,6 +92,11 @@ namespace geode return point_value; } + uuid attribute_function_id() const + { + return function_attribute_->id(); + } + private: const TriangulatedSurface< dimension >& surface_; std::shared_ptr< VariableAttribute< double > > function_attribute_; @@ -127,8 +122,8 @@ namespace geode TriangulatedSurfaceScalarFunction< dimension >:: TriangulatedSurfaceScalarFunction( const TriangulatedSurface< dimension >& surface, - std::string_view function_name ) - : impl_{ surface, function_name } + const uuid& function_id ) + : impl_{ surface, function_id } { } @@ -150,9 +145,9 @@ namespace geode TriangulatedSurfaceScalarFunction< dimension > TriangulatedSurfaceScalarFunction< dimension >::find( const TriangulatedSurface< dimension >& surface, - std::string_view function_name ) + const uuid& function_id ) { - return { surface, function_name }; + return { surface, function_id }; } template < index_t dimension > @@ -176,6 +171,13 @@ namespace geode return impl_->value( point, triangle_id ); } + template < index_t dimension > + uuid TriangulatedSurfaceScalarFunction< dimension >::attribute_function_id() + const + { + return impl_->attribute_function_id(); + } + template class opengeode_mesh_api TriangulatedSurfaceScalarFunction< 2 >; template class opengeode_mesh_api TriangulatedSurfaceScalarFunction< 3 >; } // namespace geode \ No newline at end of file diff --git a/src/geode/model/helpers/detail/split_along_surface_mesh_borders.cpp b/src/geode/model/helpers/detail/split_along_surface_mesh_borders.cpp index edf55cb24..6cdc5b69f 100644 --- a/src/geode/model/helpers/detail/split_along_surface_mesh_borders.cpp +++ b/src/geode/model/helpers/detail/split_along_surface_mesh_borders.cpp @@ -126,7 +126,6 @@ namespace geode .get(); } ) .get(); - DEBUG( "end of split" ); return mapping; } diff --git a/src/geode/model/mixin/core/detail/relationships_impl.cpp b/src/geode/model/mixin/core/detail/relationships_impl.cpp index 0f6cf5c6f..6de351111 100644 --- a/src/geode/model/mixin/core/detail/relationships_impl.cpp +++ b/src/geode/model/mixin/core/detail/relationships_impl.cpp @@ -46,6 +46,8 @@ namespace geode initialize_attributes(); } + RelationshipsImpl::RelationshipsImpl( BITSERY ) {} + index_t RelationshipsImpl::nb_components_with_relations() const { return graph_->nb_vertices(); @@ -232,10 +234,22 @@ namespace geode void RelationshipsImpl::initialize_attributes() { - ids_ = + const auto ids = + graph_->vertex_attribute_manager().attribute_ids_matching_name( + "id" ); + if( ids.has_value() ) + { + ids_ = graph_->vertex_attribute_manager() + .find_attribute< VariableAttribute, ComponentID >( + ids.value()[0] ); + return; + } + const auto id = graph_->vertex_attribute_manager() - .find_or_create_attribute< VariableAttribute, ComponentID >( - "id", ComponentID{} ); + .create_attribute< VariableAttribute, ComponentID >( + "id", ComponentID{}, AttributeProperties{} ); + ids_ = graph_->vertex_attribute_manager() + .find_attribute< VariableAttribute, ComponentID >( id ); } std::optional< index_t > RelationshipsImpl::vertex_id( diff --git a/src/geode/model/mixin/core/relationships.cpp b/src/geode/model/mixin/core/relationships.cpp index 68a2e1e70..33883af6b 100644 --- a/src/geode/model/mixin/core/relationships.cpp +++ b/src/geode/model/mixin/core/relationships.cpp @@ -63,6 +63,8 @@ namespace geode initialize_relation_attribute(); } + Impl( BITSERY bitsery ) : RelationshipsImpl( bitsery ) {} + RelationType relation_type( const index_t edge_id ) const { return relation_type_->value( edge_id ); @@ -204,18 +206,21 @@ namespace geode serializer.ext( *this, Growable< Archive, Impl >{ { []( Archive& archive, Impl& impl ) { - OpenGeodeGraph graph; + OpenGeodeGraph graph{ BITSERY::constructor }; archive.object( graph ); archive.object( impl.uuid2index_ ); archive.ext( impl.relation_type_, bitsery::ext::StdSmartPtr{} ); archive.ext( impl.ids_, bitsery::ext::StdSmartPtr{} ); - impl.graph_ = graph.clone(); + impl.graph_ = std::make_unique< OpenGeodeGraph >( + std::move( graph ) ); impl.initialize_attributes(); impl.initialize_relation_attribute(); impl.delete_isolated_vertices(); }, []( Archive& archive, Impl& impl ) { + impl.graph_ = std::make_unique< OpenGeodeGraph >( + BITSERY::constructor ); archive.ext( impl.graph_, bitsery::ext::StdSmartPtr{} ); archive.object( impl.uuid2index_ ); @@ -236,9 +241,24 @@ namespace geode void initialize_relation_attribute() { - relation_type_ = relation_attribute_manager() - .find_or_create_attribute< VariableAttribute, - RelationType >( "relation_type", NO_ID ); + const auto ids = + relation_attribute_manager().attribute_ids_matching_name( + "relation_type" ); + if( ids.has_value() ) + { + relation_type_ = + relation_attribute_manager() + .find_attribute< VariableAttribute, RelationType >( + ids.value()[0] ); + return; + } + const auto id = + relation_attribute_manager() + .create_attribute< VariableAttribute, RelationType >( + "relation_type", NO_ID, geode::AttributeProperties{} ); + relation_type_ = + relation_attribute_manager() + .find_attribute< VariableAttribute, RelationType >( id ); } std::string relation_to_string( index_t relation_type ) const @@ -267,6 +287,7 @@ namespace geode }; Relationships::Relationships() = default; + Relationships::Relationships( BITSERY bitsery ) : impl_{ bitsery } {} Relationships::Relationships( Relationships&& ) noexcept = default; Relationships& Relationships::operator=( Relationships&& ) noexcept = default; diff --git a/src/geode/model/mixin/core/vertex_identifier.cpp b/src/geode/model/mixin/core/vertex_identifier.cpp index 3b8878233..667fc02fa 100644 --- a/src/geode/model/mixin/core/vertex_identifier.cpp +++ b/src/geode/model/mixin/core/vertex_identifier.cpp @@ -106,15 +106,22 @@ namespace geode public: Impl() - : component_vertices_( unique_vertices_.vertex_attribute_manager() - .find_or_create_attribute< VariableAttribute, - std::vector< ComponentMeshVertex > >( - "component vertices", - std::vector< ComponentMeshVertex >{}, - { false, false, false } ) ) { + const auto unique_vertices_attribute_id = + unique_vertices_.vertex_attribute_manager() + .create_attribute< VariableAttribute, + std::vector< ComponentMeshVertex > >( + "component vertices", + std::vector< ComponentMeshVertex >{}, + { false, false, false } ); + component_vertices_ = unique_vertices_.vertex_attribute_manager() + .find_attribute< VariableAttribute, + std::vector< ComponentMeshVertex > >( + unique_vertices_attribute_id ); } + Impl( BITSERY ) {} + index_t nb_unique_vertices() const { return unique_vertices_.nb_vertices(); @@ -174,49 +181,53 @@ namespace geode template < typename MeshComponent > void register_component( const MeshComponent& component ) { - auto it = vertex2unique_vertex_.find( component.id() ); const auto& mesh = component.mesh(); - if( it == vertex2unique_vertex_.end() ) - { - mesh.vertex_attribute_manager().delete_attribute( - unique_vertices_name ); + const auto unique_vertices_attribute_id = + mesh.vertex_attribute_manager() + .template create_attribute< VariableAttribute, index_t >( + unique_vertices_name, NO_ID, { false, false, false } ); + const auto [_, inserted] = vertex2unique_vertex_.emplace( component.id(), mesh.vertex_attribute_manager() - .template find_or_create_attribute< VariableAttribute, - index_t >( unique_vertices_name, NO_ID, - { false, false, false } ) ); - } - else - { - auto attribute = + .template find_attribute< VariableAttribute, index_t >( + unique_vertices_attribute_id ) ); + OpenGeodeModelException::check_exception( inserted, + component.component_id(), OpenGeodeException::TYPE::data, + "[VertexIdentifier::register_component] Component ", + component.id().string(), " is already registered." ); + } + + template < typename MeshComponent > + void load_component( const MeshComponent& component ) + { + const auto& mesh = component.mesh(); + const auto unique_vertices_ids = + mesh.vertex_attribute_manager().attribute_ids_matching_name( + unique_vertices_name ); + DEBUG( unique_vertices_ids.has_value() ); + OpenGeodeModelException::check_exception( + unique_vertices_ids.has_value(), nullptr, + OpenGeodeException::TYPE::data, + "[VertexIdentifier::load_component] Unique vertices " + "attribute not found." ); + const auto [_, inserted] = + vertex2unique_vertex_.emplace( component.id(), mesh.vertex_attribute_manager() - .template find_or_create_attribute< VariableAttribute, - index_t >( unique_vertices_name, NO_ID, - { false, false, false } ); - attribute->set_properties( { false, false, false } ); - try - { - for( const auto v : Range{ mesh.nb_vertices() } ) - { - attribute->set_value( v, it->second->value( v ) ); - } - } - catch( const std::out_of_range& ) - { - Logger::warn( - "Registering MeshComponent: ", component.id().string(), - " in VertexIdentifier, wrong number of vertices." ); - } - it->second = std::move( attribute ); - } + .template find_attribute< VariableAttribute, index_t >( + unique_vertices_ids.value().front() ) ); + OpenGeodeModelException::check_exception( inserted, + component.component_id(), OpenGeodeException::TYPE::data, + "[VertexIdentifier::load_component] Component ", + component.id().string(), " is already registered." ); } template < typename MeshComponent > void unregister_component( const MeshComponent& component ) { const auto& mesh = component.mesh(); - mesh.vertex_attribute_manager().delete_attribute( - unique_vertices_name ); + auto attribute = vertex2unique_vertex_.at( component.id() ); + const auto attribute_id = attribute->id(); + mesh.vertex_attribute_manager().delete_attribute( attribute_id ); vertex2unique_vertex_.erase( component.id() ); filter_component_vertices( component.id() ); } @@ -413,9 +424,11 @@ namespace geode archive.object( impl.unique_vertices_ ); archive.ext( impl.component_vertices_, bitsery::ext::StdSmartPtr{} ); - archive.ext( impl.vertex2unique_vertex_, - bitsery::ext::StdMap{ - impl.vertex2unique_vertex_.max_size() }, + absl::flat_hash_map< uuid, + std::shared_ptr< VariableAttribute< index_t > > > + old_map; + archive.ext( old_map, + bitsery::ext::StdMap{ old_map.max_size() }, []( Archive& archive2, uuid& id, std::shared_ptr< VariableAttribute< index_t > >& attribute ) { @@ -434,9 +447,12 @@ namespace geode archive.object( impl.unique_vertices_ ); archive.ext( impl.component_vertices_, bitsery::ext::StdSmartPtr{} ); - archive.ext( impl.vertex2unique_vertex_, - bitsery::ext::StdMap{ - impl.vertex2unique_vertex_.max_size() }, + absl::flat_hash_map< uuid, + std::shared_ptr< + VariableAttribute< index_t > > > + old_map; + archive.ext( old_map, + bitsery::ext::StdMap{ old_map.max_size() }, []( Archive& archive2, uuid& id, std::shared_ptr< VariableAttribute< index_t > >& attribute ) { @@ -444,6 +460,11 @@ namespace geode archive2.ext( attribute, bitsery::ext::StdSmartPtr{} ); } ); + }, + []( Archive& archive, Impl& impl ) { + archive.object( impl.unique_vertices_ ); + archive.ext( impl.component_vertices_, + bitsery::ext::StdSmartPtr{} ); } } } ); } @@ -486,6 +507,7 @@ namespace geode }; VertexIdentifier::VertexIdentifier() = default; + VertexIdentifier::VertexIdentifier( BITSERY bitsery ) : impl_{ bitsery } {} VertexIdentifier::VertexIdentifier( VertexIdentifier&& ) noexcept = default; VertexIdentifier& VertexIdentifier::operator=( @@ -531,6 +553,13 @@ namespace geode unique_vertex_id, component_id ); } + template < typename MeshComponent > + void VertexIdentifier::load_mesh_component( + const MeshComponent& component, BuilderKey /*key*/ ) + { + impl_->load_component( component ); + } + template < typename MeshComponent > void VertexIdentifier::register_mesh_component( const MeshComponent& component, BuilderKey /*key*/ ) @@ -599,6 +628,21 @@ namespace geode return impl_->delete_isolated_vertices(); } + template void opengeode_model_api VertexIdentifier::load_mesh_component( + const Corner2D&, BuilderKey /*key*/ ); + template void opengeode_model_api VertexIdentifier::load_mesh_component( + const Corner3D&, BuilderKey /*key*/ ); + template void opengeode_model_api VertexIdentifier::load_mesh_component( + const Line2D&, BuilderKey /*key*/ ); + template void opengeode_model_api VertexIdentifier::load_mesh_component( + const Line3D&, BuilderKey /*key*/ ); + template void opengeode_model_api VertexIdentifier::load_mesh_component( + const Surface2D&, BuilderKey /*key*/ ); + template void opengeode_model_api VertexIdentifier::load_mesh_component( + const Surface3D&, BuilderKey /*key*/ ); + template void opengeode_model_api VertexIdentifier::load_mesh_component( + const Block3D&, BuilderKey /*key*/ ); + template void opengeode_model_api VertexIdentifier::register_mesh_component( const Corner2D&, BuilderKey /*key*/ ); template void opengeode_model_api VertexIdentifier::register_mesh_component( diff --git a/src/geode/model/representation/core/brep.cpp b/src/geode/model/representation/core/brep.cpp index 6157f6456..7c2e2d14f 100644 --- a/src/geode/model/representation/core/brep.cpp +++ b/src/geode/model/representation/core/brep.cpp @@ -681,6 +681,8 @@ namespace geode BRep::BRep() = default; + BRep::BRep( BITSERY bitsery ) : Topology{ bitsery } {} + BRep::BRep( BRep&& brep ) noexcept : Topology{ std::move( brep ) }, Corners3D{ std::move( brep ) }, diff --git a/src/geode/model/representation/core/section.cpp b/src/geode/model/representation/core/section.cpp index b61973dbc..5e47abbc3 100644 --- a/src/geode/model/representation/core/section.cpp +++ b/src/geode/model/representation/core/section.cpp @@ -451,6 +451,8 @@ namespace geode Section::Section() = default; + Section::Section( BITSERY bitsery ) : Topology{ bitsery } {} + Section::Section( Section&& section ) noexcept : Topology{ std::move( section ) }, Corners2D{ std::move( section ) }, diff --git a/src/geode/model/representation/io/geode/geode_brep_input.cpp b/src/geode/model/representation/io/geode/geode_brep_input.cpp index aa612a366..ca1da282c 100644 --- a/src/geode/model/representation/io/geode/geode_brep_input.cpp +++ b/src/geode/model/representation/io/geode/geode_brep_input.cpp @@ -23,6 +23,7 @@ #include +#include #include #include @@ -43,7 +44,7 @@ namespace geode { const UnzipFile zip_reader{ filename(), uuid{}.string() }; zip_reader.extract_all(); - BRep brep; + BRep brep{ BITSERY::constructor }; detail::load_brep_files( brep, zip_reader.directory() ); return brep; } diff --git a/src/geode/model/representation/io/geode/geode_section_input.cpp b/src/geode/model/representation/io/geode/geode_section_input.cpp index 66a707c39..ecd25b4bb 100644 --- a/src/geode/model/representation/io/geode/geode_section_input.cpp +++ b/src/geode/model/representation/io/geode/geode_section_input.cpp @@ -25,6 +25,7 @@ #include +#include #include #include @@ -43,7 +44,7 @@ namespace geode { const UnzipFile zip_reader{ filename(), uuid{}.string() }; zip_reader.extract_all(); - Section section; + Section section{ BITSERY::constructor }; detail::load_section_files( section, zip_reader.directory() ); return section; } diff --git a/tests/basic/test-attribute.cpp b/tests/basic/test-attribute.cpp index a3f1d07cb..c52bad9fc 100644 --- a/tests/basic/test-attribute.cpp +++ b/tests/basic/test-attribute.cpp @@ -106,17 +106,20 @@ namespace geode }; } // namespace geode -void test_constant_attribute( geode::AttributeManager& manager ) +void test_constant_attribute( + geode::AttributeManager& manager, const geode::uuid& attribute_id ) { + manager.create_attribute< geode::ConstantAttribute, bool >( + "bool", attribute_id, true, { true, true } ); auto constant_attribute = - manager.find_or_create_attribute< geode::ConstantAttribute, bool >( - "bool", true, { true, true } ); + manager.find_attribute< geode::ConstantAttribute, bool >( + attribute_id ); geode::OpenGeodeBasicException::test( constant_attribute->name() == "bool", "Wrong attribute name" ); geode::OpenGeodeBasicException::test( constant_attribute->default_value() == true, "Wrong default value" ); - auto attribute = manager.find_attribute< bool >( "bool" ); + auto attribute = manager.find_read_only_attribute< bool >( attribute_id ); geode::OpenGeodeBasicException::test( attribute->value( 0 ), "Should be equal to true" ); geode::OpenGeodeBasicException::test( @@ -128,11 +131,13 @@ void test_constant_attribute( geode::AttributeManager& manager ) !attribute->value( 12 ), "Should be equal to false" ); } -void test_foo_constant_attribute( geode::AttributeManager& manager ) +void test_foo_constant_attribute( + geode::AttributeManager& manager, const geode::uuid& attribute_id ) { + manager.create_attribute< geode::ConstantAttribute, Foo >( + "foo", attribute_id, Foo{}, geode::AttributeProperties{} ); auto constant_attribute = - manager.find_or_create_attribute< geode::ConstantAttribute, Foo >( - "foo_cst", Foo{} ); + manager.find_attribute< geode::ConstantAttribute, Foo >( attribute_id ); constant_attribute->modify_value( []( Foo& foo ) { foo.double_ = 12.4; } ); @@ -141,12 +146,14 @@ void test_foo_constant_attribute( geode::AttributeManager& manager ) "Should be equal to 12.4" ); } -void test_foo_variable_attribute( geode::AttributeManager& manager ) +void test_foo_variable_attribute( + geode::AttributeManager& manager, const geode::uuid& attribute_id ) { + manager.create_attribute< geode::VariableAttribute, Foo >( + "foo2", attribute_id, Foo{}, { false, false, false } ); auto variable_attribute = - manager.find_or_create_attribute< geode::VariableAttribute, Foo >( - "foo_var", Foo{}, { false, false, false } ); - manager.set_attribute_properties( "foo_var", { true, false, true } ); + manager.find_attribute< geode::VariableAttribute, Foo >( attribute_id ); + manager.set_attribute_properties( attribute_id, { true, false, true } ); geode::OpenGeodeBasicException::test( variable_attribute->properties().assignable && !variable_attribute->properties().interpolable @@ -170,16 +177,19 @@ void test_foo_variable_attribute( geode::AttributeManager& manager ) "Should be equal to 12.4" ); } -void test_int_variable_attribute( geode::AttributeManager& manager ) +void test_int_variable_attribute( + geode::AttributeManager& manager, const geode::uuid& attribute_id ) { + manager.create_attribute< geode::VariableAttribute, int >( + "int", attribute_id, 12, { true, true } ); auto variable_attribute = - manager.find_or_create_attribute< geode::VariableAttribute, int >( - "int", 12, { true, true } ); + manager.find_attribute< geode::VariableAttribute, int >( attribute_id ); geode::OpenGeodeBasicException::test( variable_attribute->default_value() == 12, "Wrong default value" ); variable_attribute->set_value( 3, 3 ); - const auto attribute = manager.find_attribute< int >( "int" ); + const auto attribute = + manager.find_read_only_attribute< int >( attribute_id ); geode::OpenGeodeBasicException::test( attribute->value( 3 ) == 3, "Int variable value 3 should be equal to 3" ); geode::OpenGeodeBasicException::test( attribute->value( 6 ) == 12, @@ -190,11 +200,13 @@ void test_int_variable_attribute( geode::AttributeManager& manager ) "Int variable value 3 should be equal to 5" ); } -void test_foo_sparse_attribute( geode::AttributeManager& manager ) +void test_foo_sparse_attribute( + geode::AttributeManager& manager, const geode::uuid& attribute_id ) { + manager.create_attribute< geode::SparseAttribute, Foo >( + "foo", attribute_id, Foo{}, geode::AttributeProperties{} ); auto sparse_attribute = - manager.find_or_create_attribute< geode::SparseAttribute, Foo >( - "foo_spr", Foo{} ); + manager.find_attribute< geode::SparseAttribute, Foo >( attribute_id ); sparse_attribute->modify_value( 3, []( Foo& foo ) { foo.double_ = 12.4; } ); @@ -211,11 +223,14 @@ void test_foo_sparse_attribute( geode::AttributeManager& manager ) "Foo sparse value should be equal to 3" ); } -void test_double_sparse_attribute( geode::AttributeManager& manager ) +void test_double_sparse_attribute( + geode::AttributeManager& manager, const geode::uuid& attribute_id ) { + manager.create_attribute< geode::SparseAttribute, double >( + "double", attribute_id, 12., { true, true } ); auto sparse_attribute = - manager.find_or_create_attribute< geode::SparseAttribute, double >( - "double", 12., { true, true } ); + manager.find_attribute< geode::SparseAttribute, double >( + attribute_id ); geode::OpenGeodeBasicException::test( sparse_attribute->default_value() == 12, "Wrong default value" ); sparse_attribute->set_value( 3, 3 ); @@ -223,7 +238,7 @@ void test_double_sparse_attribute( geode::AttributeManager& manager ) manager.assign_attribute_value( 3, 2 ); manager.interpolate_attribute_value( { { 1, 7 }, { 0.5, 0.3 } }, 4 ); - auto attribute = manager.find_attribute< double >( "double" ); + auto attribute = manager.find_read_only_attribute< double >( attribute_id ); geode::OpenGeodeBasicException::test( attribute->value( 2 ) == 3, "Double sparse value 2 should be equal to 3" ); geode::OpenGeodeBasicException::test( attribute->value( 3 ) == 3, @@ -242,10 +257,12 @@ void test_double_sparse_attribute( geode::AttributeManager& manager ) void test_double_array_attribute( geode::AttributeManager& manager ) { - auto array_attribute = - manager.find_or_create_attribute< geode::VariableAttribute, + const auto attribute_id = + manager.create_attribute< geode::VariableAttribute, std::array< double, 3 > >( - "array_double_3", { { 10., 11., 12. } }, { true, true } ); + "double_array", { { 10., 11., 12. } }, { true, true } ); + auto array_attribute = manager.find_attribute< geode::VariableAttribute, + std::array< double, 3 > >( attribute_id ); geode::OpenGeodeBasicException::test( array_attribute->default_value()[0] == 10., "Wrong default value" ); geode::OpenGeodeBasicException::test( @@ -258,7 +275,8 @@ void test_double_array_attribute( geode::AttributeManager& manager ) manager.interpolate_attribute_value( { { 1, 7 }, { 0.5, 0.3 } }, 4 ); auto attribute = - manager.find_attribute< std::array< double, 3 > >( "array_double_3" ); + manager.find_read_only_attribute< std::array< double, 3 > >( + attribute_id ); geode::OpenGeodeBasicException::test( attribute->value( 2 )[0] == 1., "Value [2,0] Should be equal to 1., not ", attribute->value( 2 )[0] ); geode::OpenGeodeBasicException::test( attribute->value( 2 )[1] == 2., @@ -299,16 +317,21 @@ void test_double_array_attribute( geode::AttributeManager& manager ) attribute->value( 3 )[2] == 5., "Should be equal to 5." ); } -void test_bool_variable_attribute( geode::AttributeManager& manager ) +void test_bool_variable_attribute( + geode::AttributeManager& manager, const geode::uuid& attribute_id ) { + manager.create_attribute< geode::VariableAttribute, bool >( + "bool", attribute_id, false, { true, true } ); + auto variable_attribute = - manager.find_or_create_attribute< geode::VariableAttribute, bool >( - "bool_var", false, { true, true } ); + manager.find_attribute< geode::VariableAttribute, bool >( + attribute_id ); geode::OpenGeodeBasicException::test( variable_attribute->default_value() == false, "Wrong default value" ); variable_attribute->set_value( 3, true ); - const auto attribute = manager.find_attribute< bool >( "bool_var" ); + const auto attribute = + manager.find_read_only_attribute< bool >( attribute_id ); geode::OpenGeodeBasicException::test( attribute->value( 3 ), "Should be equal to true" ); @@ -320,23 +343,23 @@ void test_bool_variable_attribute( geode::AttributeManager& manager ) bool managers_have_same_attributes( const geode::AttributeManager& manager, const geode::AttributeManager& reloaded_manager ) { - const auto& attribute_names = manager.attribute_names(); - const auto& reloaded_attribute_names = reloaded_manager.attribute_names(); - if( attribute_names.size() != reloaded_attribute_names.size() ) + const auto& attribute_ids = manager.attribute_ids(); + const auto& reloaded_attribute_ids = reloaded_manager.attribute_ids(); + if( attribute_ids.size() != reloaded_attribute_ids.size() ) { return false; } - for( const auto& att : attribute_names ) + for( const auto& att : attribute_ids ) { - if( absl::c_find( reloaded_attribute_names, att ) - == reloaded_attribute_names.end() ) + if( absl::c_find( reloaded_attribute_ids, att ) + == reloaded_attribute_ids.end() ) { return false; } } - for( const auto& att : reloaded_attribute_names ) + for( const auto& att : reloaded_attribute_ids ) { - if( absl::c_find( attribute_names, att ) == attribute_names.end() ) + if( absl::c_find( attribute_ids, att ) == attribute_ids.end() ) { return false; } @@ -347,32 +370,42 @@ bool managers_have_same_attributes( const geode::AttributeManager& manager, template < typename T > void check_one_attribute_values( geode::AttributeManager& manager, geode::AttributeManager& reloaded_manager, - std::string_view name ) + const geode::uuid& attribute_id ) { - const auto in_att = manager.find_attribute< T >( name ); - const auto out_att = reloaded_manager.find_attribute< T >( name ); + const auto in_att = manager.find_read_only_attribute< T >( attribute_id ); + const auto out_att = + reloaded_manager.find_read_only_attribute< T >( attribute_id ); for( auto i : geode::Range{ manager.nb_elements() } ) { geode::OpenGeodeBasicException::test( in_att->value( i ) == out_att->value( i ), - "At least one value of Attribute ", name, + "At least one value of Attribute ", attribute_id.string(), " is not correct after reloading" ); } } void check_attribute_values( geode::AttributeManager& manager, - geode::AttributeManager& reloaded_manager ) + geode::AttributeManager& reloaded_manager, + const std::array< geode::uuid, 7 >& attribute_to_check ) { - check_one_attribute_values< bool >( manager, reloaded_manager, "bool" ); - check_one_attribute_values< int >( manager, reloaded_manager, "int" ); - check_one_attribute_values< double >( manager, reloaded_manager, "double" ); - check_one_attribute_values< bool >( manager, reloaded_manager, "bool_var" ); - check_one_attribute_values< Foo >( manager, reloaded_manager, "foo_cst" ); - check_one_attribute_values< Foo >( manager, reloaded_manager, "foo_var" ); - check_one_attribute_values< Foo >( manager, reloaded_manager, "foo_spr" ); + check_one_attribute_values< bool >( + manager, reloaded_manager, attribute_to_check[0] ); + check_one_attribute_values< int >( + manager, reloaded_manager, attribute_to_check[1] ); + check_one_attribute_values< double >( + manager, reloaded_manager, attribute_to_check[2] ); + check_one_attribute_values< bool >( + manager, reloaded_manager, attribute_to_check[3] ); + check_one_attribute_values< Foo >( + manager, reloaded_manager, attribute_to_check[4] ); + check_one_attribute_values< Foo >( + manager, reloaded_manager, attribute_to_check[5] ); + check_one_attribute_values< Foo >( + manager, reloaded_manager, attribute_to_check[6] ); } -void test_serialize_manager( geode::AttributeManager& manager ) +void test_serialize_manager( geode::AttributeManager& manager, + const std::array< geode::uuid, 7 >& attribute_to_check ) { const auto filename = "manager.out"; std::ofstream file{ filename, std::ofstream::binary }; @@ -417,36 +450,39 @@ void test_serialize_manager( geode::AttributeManager& manager ) managers_have_same_attributes( manager, reloaded_manager ), "Number and names of attributes in reloaded AttributeManager " "are not correct" ); - check_attribute_values( manager, reloaded_manager ); + check_attribute_values( manager, reloaded_manager, attribute_to_check ); } -void test_attribute_types( geode::AttributeManager& manager ) +void test_attribute_types( geode::AttributeManager& manager, + const geode::uuid& bool_variable_attribute_id ) { geode::OpenGeodeBasicException::test( - manager.attribute_type( "bool_var" ) == typeid( bool ).name(), + manager.attribute_type( bool_variable_attribute_id ) + == typeid( bool ).name(), "Returned attribute type is not correct (should be bool)" ); + geode::uuid not_registered_attribute_id; geode::OpenGeodeBasicException::test( - manager.attribute_type( "unknown_name" ) == "undefined", + manager.attribute_type( not_registered_attribute_id ) == "undefined", "Returned attribute type is not correct (should be undefined)" ); } -void test_attribute_rename( geode::AttributeManager& manager ) +void test_attribute_names( geode::AttributeManager& manager, + const geode::uuid& bool_variable_attribute_id ) { - manager.rename_attribute( "foo_cst", "foo_constant" ); - auto constant_attribute = - manager.find_or_create_attribute< geode::ConstantAttribute, Foo >( - "foo_constant", Foo{} ); geode::OpenGeodeBasicException::test( - constant_attribute->value().double_ == 12.4, - "Should be equal to 12.4" ); + manager.find_attribute< geode::VariableAttribute, bool >( + bool_variable_attribute_id ) + ->name() + .value() + == "bool", + "Returned attribute name is not correct (should be bool)" ); } void test_number_of_attributes( geode::AttributeManager& manager, geode::index_t nb ) { - geode::OpenGeodeBasicException::test( - manager.attribute_names().size() == nb, "Should have ", nb, - " attributes in the manager" ); + geode::OpenGeodeBasicException::test( manager.attribute_ids().size() == nb, + "Should have ", nb, " attributes in the manager" ); } void test_delete_attribute_elements( geode::AttributeManager& manager ) @@ -461,9 +497,10 @@ void test_delete_attribute_elements( geode::AttributeManager& manager ) } void test_sparse_attribute_after_element_deletion( - geode::AttributeManager& manager ) + geode::AttributeManager& manager, const geode::uuid& double_attribute_id ) { - const auto sparse_attribute = manager.find_attribute< double >( "double" ); + const auto sparse_attribute = + manager.find_read_only_attribute< double >( double_attribute_id ); geode::OpenGeodeBasicException::test( sparse_attribute->value( 0 ) == 12, "Element 0 of sparse attribute should be 12 " ); geode::OpenGeodeBasicException::test( sparse_attribute->value( 3 ) == 3, @@ -474,23 +511,28 @@ void test_sparse_attribute_after_element_deletion( "Element 7 of sparse attribute should be 7 " ); } -void test_generic_value( geode::AttributeManager& manager ) +geode::uuid test_generic_value( geode::AttributeManager& manager, + const geode::uuid& foo_sparse_id, + const geode::uuid& double_attribute_id ) { - const auto& foo_attr = manager.find_attribute< Foo >( "foo_spr" ); + const auto& foo_attr = + manager.find_read_only_attribute< Foo >( foo_sparse_id ); geode::OpenGeodeBasicException::test( foo_attr->is_genericable(), "Foo attribute should be genericable" ); geode::OpenGeodeBasicException::test( foo_attr->generic_value( 3 ) == 15.4f, "Generic value for element 3 of foo sparse attribute should be " "15.4" ); - const auto& double_attr = manager.find_attribute< double >( "double" ); + const auto& double_attr = + manager.find_read_only_attribute< double >( double_attribute_id ); geode::OpenGeodeBasicException::test( double_attr->generic_value( 7 ) == 7, "Generic value for element 7 of double attribute should be 7" ); - auto array_attr = - manager.find_or_create_attribute< geode::VariableAttribute, - std::array< double, 2 > >( - "array_double", std::array< double, 2 >() ); + auto array_attr_id = manager.create_attribute< geode::VariableAttribute, + std::array< double, 2 > >( "array_double_2", std::array< double, 2 >(), + geode::AttributeProperties{} ); + auto array_attr = manager.find_attribute< geode::VariableAttribute, + std::array< double, 2 > >( array_attr_id ); array_attr->set_value( 2, { 3.1, 1.3 } ); geode::OpenGeodeBasicException::test( array_attr->is_genericable(), "Foo attribute is genericable" ); @@ -505,25 +547,31 @@ void test_generic_value( geode::AttributeManager& manager ) array_attr->generic_item_value( 2, 1 ) == 1.3f, "Generic value for element 2,1 of array attribute should be " "1.3" ); + return array_attr_id; } -void test_copy_manager( geode::AttributeManager& manager ) +void test_copy_manager( geode::AttributeManager& manager, + const geode::uuid& bool_variable_attribute_id ) { geode::AttributeManager manager2; manager2.copy( manager ); manager2.reserve( 15 ); - test_attribute_types( manager2 ); + test_attribute_types( manager2, bool_variable_attribute_id ); test_number_of_attributes( manager2, 8 ); + test_attribute_names( manager2, bool_variable_attribute_id ); } -void test_import_manager( geode::AttributeManager& manager ) +void test_import_manager( geode::AttributeManager& manager, + const geode::uuid& bool_variable_attribute_id, + const geode::uuid& array_double_attribute_id, + const geode::uuid& double_attribute_id ) { const auto nb_elements = manager.nb_elements(); geode::AttributeManager manager2; std::vector< geode::index_t > old2new( nb_elements, geode::NO_ID ); manager2.resize( 0 ); manager2.import( manager, old2new ); - test_attribute_types( manager2 ); + test_attribute_types( manager2, bool_variable_attribute_id ); test_number_of_attributes( manager2, 8 ); geode::AttributeManager manager3; @@ -533,12 +581,14 @@ void test_import_manager( geode::AttributeManager& manager ) } manager3.resize( nb_elements - 2 ); manager3.import( manager, old2new ); - test_attribute_types( manager3 ); + test_attribute_types( manager3, bool_variable_attribute_id ); test_number_of_attributes( manager3, 8 ); auto array_attr = - manager.find_attribute< std::array< double, 2 > >( "array_double" ); + manager.find_read_only_attribute< std::array< double, 2 > >( + array_double_attribute_id ); auto array_attr2 = - manager3.find_attribute< std::array< double, 2 > >( "array_double" ); + manager3.find_read_only_attribute< std::array< double, 2 > >( + array_double_attribute_id ); geode::OpenGeodeBasicException::test( array_attr->value( 2 ) == array_attr2->value( 4 ), "Error in attribute import value." ); @@ -550,43 +600,59 @@ void test_import_manager( geode::AttributeManager& manager ) } manager4.resize( nb_elements ); manager4.import( manager, old2new ); - test_attribute_types( manager4 ); + test_attribute_types( manager4, bool_variable_attribute_id ); test_number_of_attributes( manager4, 8 ); - test_sparse_attribute_after_element_deletion( manager4 ); + test_sparse_attribute_after_element_deletion( + manager4, double_attribute_id ); } void test_multi_import_manager() { geode::AttributeManager from1; from1.resize( 10 ); - auto attr1_from1 = from1.find_or_create_attribute< geode::VariableAttribute, - geode::index_t >( "variable", 42 ); + auto attr1_from1_id = + from1.create_attribute< geode::VariableAttribute, geode::index_t >( + " variable", 42, geode::AttributeProperties{} ); + auto attr1_from1 = + from1.find_attribute< geode::VariableAttribute, geode::index_t >( + attr1_from1_id ); for( const auto i : geode::LRange( from1.nb_elements() ) ) { attr1_from1->set_value( i, i ); } - auto attr2_from1 = - from1.find_or_create_attribute< geode::ConstantAttribute, double >( - "constant", 1.0 ); + auto attr2_from1_id = + from1.create_attribute< geode::ConstantAttribute, double >( + "constant", 1.0, geode::AttributeProperties{} ); + auto attr2_from1 = from1.find_attribute< geode::ConstantAttribute, double >( + attr2_from1_id ); + auto attr3_from1_id = + from1.create_attribute< geode::SparseAttribute, std::string >( + "sparse", "default", geode::AttributeProperties{} ); auto attr3_from1 = - from1.find_or_create_attribute< geode::SparseAttribute, std::string >( - "sparse", "default" ); + from1.find_attribute< geode::SparseAttribute, std::string >( + attr3_from1_id ); attr3_from1->set_value( 1, "one" ); geode::AttributeManager from2; from2.resize( 10 ); - auto attr1_from2 = from2.find_or_create_attribute< geode::VariableAttribute, - geode::index_t >( "variable", 42 ); + from2.create_attribute< geode::VariableAttribute, geode::index_t >( + " variable", attr1_from1_id, 42, geode::AttributeProperties{} ); + auto attr1_from2 = + from2.find_attribute< geode::VariableAttribute, geode::index_t >( + attr1_from1_id ); for( const auto i : geode::LRange( from2.nb_elements() ) ) { attr1_from2->set_value( i, from2.nb_elements() - i ); } - auto attr2_from2 = - from2.find_or_create_attribute< geode::ConstantAttribute, double >( - "constant", 2.0 ); + from2.create_attribute< geode::ConstantAttribute, double >( + "constant", attr2_from1_id, 2.0, geode::AttributeProperties{} ); + auto attr2_from2 = from2.find_attribute< geode::ConstantAttribute, double >( + attr2_from1_id ); + from2.create_attribute< geode::SparseAttribute, std::string >( "sparse", + attr3_from1_id, "another_default", geode::AttributeProperties{} ); auto attr3_from2 = - from2.find_or_create_attribute< geode::SparseAttribute, std::string >( - "sparse", "another_default" ); + from2.find_attribute< geode::SparseAttribute, std::string >( + attr3_from1_id ); attr3_from2->set_value( 2, "two" ); geode::GenericMapping< geode::index_t > from1_to; @@ -618,9 +684,11 @@ void test_multi_import_manager() "default", "default", "another_default", "two", "another_default", "another_default", "another_default" }; const auto result_variable = - to.find_attribute< geode::index_t >( "variable" ); - const auto result_constant = to.find_attribute< double >( "constant" ); - const auto result_sparse = to.find_attribute< std::string >( "sparse" ); + to.find_read_only_attribute< geode::index_t >( attr1_from1_id ); + const auto result_constant = + to.find_read_only_attribute< double >( attr2_from1_id ); + const auto result_sparse = + to.find_read_only_attribute< std::string >( attr3_from1_id ); for( const auto i : geode::LRange( from2.nb_elements() ) ) { @@ -636,12 +704,15 @@ void test_multi_import_manager() } } -void test_permutation( geode::AttributeManager& manager ) +void test_permutation( geode::AttributeManager& manager, + const geode::uuid& int_att_id, + const geode::uuid& double_att_id ) { std::vector< geode::index_t > permutation{ 2, 1, 4, 6, 7, 8, 5, 9, 3, 0 }; manager.permute_elements( permutation ); - const auto int_attribute = manager.find_attribute< int >( "int" ); + const auto int_attribute = + manager.find_read_only_attribute< int >( int_att_id ); geode::OpenGeodeBasicException::test( int_attribute->value( 3 ) == 12, "Attribute value 3 should be equal to 12" ); geode::OpenGeodeBasicException::test( int_attribute->value( 0 ) == 5, @@ -649,7 +720,8 @@ void test_permutation( geode::AttributeManager& manager ) geode::OpenGeodeBasicException::test( int_attribute->value( 8 ) == 5, "Attribute value 8 should be equal to 5" ); - auto double_attribute = manager.find_attribute< double >( "double" ); + auto double_attribute = + manager.find_read_only_attribute< double >( double_att_id ); geode::OpenGeodeBasicException::test( double_attribute->value( 2 ) == 12, "Attribute value 2 should be equal to 3, not ", double_attribute->value( 2 ) ); @@ -667,27 +739,39 @@ void test() manager.resize( 10 ); geode::OpenGeodeBasicException::test( manager.nb_elements() == 10, "Manager should have 10 elements" ); - test_constant_attribute( manager ); - test_foo_constant_attribute( manager ); - test_int_variable_attribute( manager ); - test_bool_variable_attribute( manager ); - test_foo_variable_attribute( manager ); - test_double_sparse_attribute( manager ); - test_foo_sparse_attribute( manager ); - test_generic_value( manager ); - test_permutation( manager ); + geode::uuid constant_attribute_id; + test_constant_attribute( manager, constant_attribute_id ); + geode::uuid foo_constant_attribute_id; + test_foo_constant_attribute( manager, foo_constant_attribute_id ); + geode::uuid int_variable_attribute_id; + test_int_variable_attribute( manager, int_variable_attribute_id ); + geode::uuid bool_variable_attribute_id; + test_bool_variable_attribute( manager, bool_variable_attribute_id ); + geode::uuid foo_variable_attribute_id; + test_foo_variable_attribute( manager, foo_variable_attribute_id ); + geode::uuid double_sparse_attribute_id; + test_double_sparse_attribute( manager, double_sparse_attribute_id ); + geode::uuid foo_sparse_attribute_id; + test_foo_sparse_attribute( manager, foo_sparse_attribute_id ); + const auto array_double_attribute_id = test_generic_value( + manager, foo_sparse_attribute_id, double_sparse_attribute_id ); + test_permutation( + manager, int_variable_attribute_id, double_sparse_attribute_id ); test_delete_attribute_elements( manager ); - test_sparse_attribute_after_element_deletion( manager ); - - test_serialize_manager( manager ); - - test_copy_manager( manager ); - test_import_manager( manager ); + test_sparse_attribute_after_element_deletion( + manager, double_sparse_attribute_id ); + std::array< geode::uuid, 7 > attribute_to_check{ constant_attribute_id, + int_variable_attribute_id, double_sparse_attribute_id, + bool_variable_attribute_id, foo_variable_attribute_id, + foo_constant_attribute_id, foo_sparse_attribute_id }; + test_serialize_manager( manager, attribute_to_check ); + test_copy_manager( manager, bool_variable_attribute_id ); + test_import_manager( manager, bool_variable_attribute_id, + array_double_attribute_id, double_sparse_attribute_id ); test_multi_import_manager(); - test_attribute_types( manager ); - test_attribute_rename( manager ); + test_attribute_types( manager, bool_variable_attribute_id ); test_number_of_attributes( manager, 8 ); - manager.delete_attribute( "bool" ); + manager.delete_attribute( bool_variable_attribute_id ); test_number_of_attributes( manager, 7 ); manager.clear_attributes(); test_number_of_attributes( manager, 7 ); diff --git a/tests/data/test_v12.og_edc3d b/tests/data/backward_io/v12/test_v12.og_edc3d similarity index 100% rename from tests/data/test_v12.og_edc3d rename to tests/data/backward_io/v12/test_v12.og_edc3d diff --git a/tests/data/test_v12.og_psf3d b/tests/data/backward_io/v12/test_v12.og_psf3d similarity index 100% rename from tests/data/test_v12.og_psf3d rename to tests/data/backward_io/v12/test_v12.og_psf3d diff --git a/tests/data/test_v12.og_pso3d b/tests/data/backward_io/v12/test_v12.og_pso3d similarity index 100% rename from tests/data/test_v12.og_pso3d rename to tests/data/backward_io/v12/test_v12.og_pso3d diff --git a/tests/data/test_v12.og_rgd3d b/tests/data/backward_io/v12/test_v12.og_rgd3d similarity index 100% rename from tests/data/test_v12.og_rgd3d rename to tests/data/backward_io/v12/test_v12.og_rgd3d diff --git a/tests/data/backward_io/v17/v17.og_brep b/tests/data/backward_io/v17/v17.og_brep new file mode 100644 index 000000000..e59f30612 Binary files /dev/null and b/tests/data/backward_io/v17/v17.og_brep differ diff --git a/tests/data/backward_io/v17/v17.og_edc3d b/tests/data/backward_io/v17/v17.og_edc3d new file mode 100644 index 000000000..d7e3782e9 Binary files /dev/null and b/tests/data/backward_io/v17/v17.og_edc3d differ diff --git a/tests/data/backward_io/v17/v17.og_grp b/tests/data/backward_io/v17/v17.og_grp new file mode 100644 index 000000000..ae2095f0e Binary files /dev/null and b/tests/data/backward_io/v17/v17.og_grp differ diff --git a/tests/data/backward_io/v17/v17.og_hso3d b/tests/data/backward_io/v17/v17.og_hso3d new file mode 100644 index 000000000..bbfeb759e Binary files /dev/null and b/tests/data/backward_io/v17/v17.og_hso3d differ diff --git a/tests/data/backward_io/v17/v17.og_psf3d b/tests/data/backward_io/v17/v17.og_psf3d new file mode 100644 index 000000000..45283dc47 Binary files /dev/null and b/tests/data/backward_io/v17/v17.og_psf3d differ diff --git a/tests/data/backward_io/v17/v17.og_pso3d b/tests/data/backward_io/v17/v17.og_pso3d new file mode 100644 index 000000000..745f5e431 Binary files /dev/null and b/tests/data/backward_io/v17/v17.og_pso3d differ diff --git a/tests/data/backward_io/v17/v17.og_pts3d b/tests/data/backward_io/v17/v17.og_pts3d new file mode 100644 index 000000000..2d082c014 Binary files /dev/null and b/tests/data/backward_io/v17/v17.og_pts3d differ diff --git a/tests/data/backward_io/v17/v17.og_rgd3d b/tests/data/backward_io/v17/v17.og_rgd3d new file mode 100644 index 000000000..430f74ee1 Binary files /dev/null and b/tests/data/backward_io/v17/v17.og_rgd3d differ diff --git a/tests/data/backward_io/v17/v17.og_sctn b/tests/data/backward_io/v17/v17.og_sctn new file mode 100644 index 000000000..511e2eb40 Binary files /dev/null and b/tests/data/backward_io/v17/v17.og_sctn differ diff --git a/tests/data/backward_io/v17/v17.og_tsf3d b/tests/data/backward_io/v17/v17.og_tsf3d new file mode 100644 index 000000000..1f4495371 Binary files /dev/null and b/tests/data/backward_io/v17/v17.og_tsf3d differ diff --git a/tests/data/backward_io/v17/v17.og_tso3d b/tests/data/backward_io/v17/v17.og_tso3d new file mode 100644 index 000000000..c38671e6c Binary files /dev/null and b/tests/data/backward_io/v17/v17.og_tso3d differ diff --git a/tests/data/test_v7.og_grp b/tests/data/backward_io/v7/test_v7.og_grp similarity index 100% rename from tests/data/test_v7.og_grp rename to tests/data/backward_io/v7/test_v7.og_grp diff --git a/tests/data/test_v7.og_psf3d b/tests/data/backward_io/v7/test_v7.og_psf3d similarity index 100% rename from tests/data/test_v7.og_psf3d rename to tests/data/backward_io/v7/test_v7.og_psf3d diff --git a/tests/data/test_v7.og_pso3d b/tests/data/backward_io/v7/test_v7.og_pso3d similarity index 100% rename from tests/data/test_v7.og_pso3d rename to tests/data/backward_io/v7/test_v7.og_pso3d diff --git a/tests/geometry/test-point.cpp b/tests/geometry/test-point.cpp index bae2f7ae2..0d30d2f8f 100644 --- a/tests/geometry/test-point.cpp +++ b/tests/geometry/test-point.cpp @@ -65,9 +65,12 @@ void test_interpolation() { geode::AttributeManager manager; manager.resize( 10 ); - auto attribute = manager.find_or_create_attribute< geode::VariableAttribute, - geode::Point< 3 > >( - "point_3", geode::Point3D{ { 10., 11., 12. } }, { false, true } ); + auto attribute_id = + manager.create_attribute< geode::VariableAttribute, geode::Point< 3 > >( + "points", geode::Point3D{ { 10., 11., 12. } }, { false, true } ); + auto attribute = + manager.find_attribute< geode::VariableAttribute, geode::Point< 3 > >( + attribute_id ); geode::OpenGeodeGeometryException::test( attribute->default_value().value( 0 ) == 10., "Wrong default value" ); geode::OpenGeodeGeometryException::test( diff --git a/tests/image/test-colors.cpp b/tests/image/test-colors.cpp index de74a4d2b..cc0356728 100644 --- a/tests/image/test-colors.cpp +++ b/tests/image/test-colors.cpp @@ -46,14 +46,19 @@ void test_color_attribute() { geode::AttributeManager manager; manager.resize( 1 ); - const auto rgb_attribute = - manager.find_or_create_attribute< geode::VariableAttribute, - geode::RGBColor >( "rgb_color", geode::RGBColor{} ); + const auto rgb_attribute_id = + manager.create_attribute< geode::VariableAttribute, geode::RGBColor >( + "rgb_color", geode::RGBColor{}, geode::AttributeProperties{} ); + auto rgb_attribute = + manager.find_attribute< geode::VariableAttribute, geode::RGBColor >( + rgb_attribute_id ); rgb_attribute->set_value( 0, { 3, 254, 68 } ); - const auto greyscale_attribute = - manager.find_or_create_attribute< geode::VariableAttribute, - geode::GreyscaleColor >( - "greyscale_color", geode::GreyscaleColor{} ); + const auto greyscale_attribute_id = + manager.create_attribute< geode::VariableAttribute, + geode::GreyscaleColor >( "greyscale_color", geode::GreyscaleColor{}, + geode::AttributeProperties{} ); + auto greyscale_attribute = manager.find_attribute< geode::VariableAttribute, + geode::GreyscaleColor >( greyscale_attribute_id ); greyscale_attribute->set_value( 0, geode::GreyscaleColor{ 67 } ); geode::OpenGeodeImageException::test( rgb_attribute->is_genericable(), "[TEST] Attribute on RGBColor should be genericable." ); diff --git a/tests/mesh/test-convert-surface.cpp b/tests/mesh/test-convert-surface.cpp index 73f5762a2..9c2823fc6 100644 --- a/tests/mesh/test-convert-surface.cpp +++ b/tests/mesh/test-convert-surface.cpp @@ -115,22 +115,27 @@ void convert_grid_to_surface() absl::StrCat( geode::DATA_PATH, "old_regular_grid.og_rgd2d" ) ); const auto old_regular_grid_surface = geode::convert_grid_into_triangulated_surface( *old_regular_grid ); + auto test_attribute_id = + old_regular_grid_surface->vertex_attribute_manager() + .create_attribute< geode::VariableAttribute, geode::Point2D >( + "test", geode::Point2D{ { 0., 0. } }, + geode::AttributeProperties{} ); auto test_attribute = old_regular_grid_surface->vertex_attribute_manager() - .find_or_create_attribute< geode::VariableAttribute, - geode::Point2D >( "test", geode::Point2D{ { 0., 0. } } ); - auto pt_attribute = old_regular_grid_surface->vertex_attribute_manager() - .find_attribute< geode::Point2D >( "points" ); + .find_attribute< geode::VariableAttribute, geode::Point2D >( + test_attribute_id ); const auto old_regular_grid_surface2 = geode::convert_surface_mesh_into_triangulated_surface( *old_regular_grid ) .value(); + old_regular_grid_surface2->vertex_attribute_manager() + .create_attribute< geode::VariableAttribute, geode::Point2D >( "test", + test_attribute_id, geode::Point2D{ { 0., 0. } }, + geode::AttributeProperties{} ); auto test_attribute2 = old_regular_grid_surface2->vertex_attribute_manager() - .find_or_create_attribute< geode::VariableAttribute, - geode::Point2D >( "test", geode::Point2D{ { 0., 0. } } ); - auto pt_attribute2 = old_regular_grid_surface2->vertex_attribute_manager() - .find_attribute< geode::Point2D >( "points" ); + .find_attribute< geode::VariableAttribute, geode::Point2D >( + test_attribute_id ); } void triangulate_surface() diff --git a/tests/mesh/test-coordinate-reference-system.cpp b/tests/mesh/test-coordinate-reference-system.cpp index 679f96335..197a833bf 100644 --- a/tests/mesh/test-coordinate-reference-system.cpp +++ b/tests/mesh/test-coordinate-reference-system.cpp @@ -45,7 +45,7 @@ void test() const auto crs_name = "test"; crs_manager_builder.register_coordinate_reference_system( crs_name, std::make_shared< geode::AttributeCoordinateReferenceSystem3D >( - att_manager ) ); + att_manager, crs_name ) ); geode::OpenGeodeMeshException::test( crs_manager.nb_coordinate_reference_systems() == 1, "Wrong number of CRS" ); diff --git a/tests/mesh/test-edged-curve.cpp b/tests/mesh/test-edged-curve.cpp index 94f13d59c..8e2c41f4b 100644 --- a/tests/mesh/test-edged-curve.cpp +++ b/tests/mesh/test-edged-curve.cpp @@ -283,8 +283,16 @@ void test_backward_io( const std::string& filename ) const auto curve = geode::load_edged_curve< 3 >( filename ); geode::OpenGeodeMeshException::test( curve->nb_edges() == 4, "Backward EdgedCurve has wrong number of edges" ); + const geode::Point3D answer{ { 2.1, 9.4, 6.7 } }; + geode::OpenGeodeMeshException::test( curve->point( 1 ) == answer, + "Backward EdgedCurve vertex coordinates are not correct" ); + geode::OpenGeodeMeshException::test( curve->edge_vertex( { 0, 0 } ) == 0, + "Backward EdgedCurve edge vertex index is not correct" ); geode::OpenGeodeMeshException::test( curve->nb_vertices() == 4, "Backward EdgedCurve has wrong number of vertices" ); + geode::OpenGeodeMeshException::test( + curve->edges_around_vertex( 0 ).size() == 2, + "Backward EdgedCurve has wrong number of edges around vertex 0" ); } void test_edge_requests( const geode::EdgedCurve3D& edged_curve, @@ -303,12 +311,13 @@ void test_edge_requests( const geode::EdgedCurve3D& edged_curve, void test_clone( const geode::EdgedCurve3D& edged_curve ) { + auto attribute_id = edged_curve.edge_attribute_manager() + .create_attribute< geode::VariableAttribute, int >( + "edge", 0, geode::AttributeProperties{} ); auto attribute = edged_curve.edge_attribute_manager() - .find_or_create_attribute< geode::VariableAttribute, int >( - "test", 0 ); + .find_attribute< geode::VariableAttribute, int >( attribute_id ); attribute->set_value( 0, 42 ); - const auto edged_curve_clone = edged_curve.clone(); geode::OpenGeodeEdgedCurve3D edged_curve2{ std::move( *dynamic_cast< geode::OpenGeodeEdgedCurve3D* >( @@ -319,7 +328,8 @@ void test_clone( const geode::EdgedCurve3D& edged_curve ) edged_curve2.nb_edges() == 3, "EdgedCurve2 should have 3 edge" ); const auto attribute2 = - edged_curve2.edge_attribute_manager().find_attribute< int >( "test" ); + edged_curve2.edge_attribute_manager().find_read_only_attribute< int >( + attribute_id ); geode::OpenGeodeMeshException::test( attribute2->value( 0 ) == 42, "EdgedCurve2 attribute should be 42" ); } @@ -344,9 +354,10 @@ void test() test_io( *edged_curve, absl::StrCat( "test.", edged_curve->native_extension() ) ); - test_backward_io( absl::StrCat( - geode::DATA_PATH, "test_v12.", edged_curve->native_extension() ) ); - + test_backward_io( absl::StrCat( geode::DATA_PATH, + "backward_io/v12/test_v12.", edged_curve->native_extension() ) ); + test_backward_io( absl::StrCat( geode::DATA_PATH, "backward_io/v17/v17.", + edged_curve->native_extension() ) ); test_permutation( *edged_curve, *builder ); test_delete_edge( *edged_curve, *builder ); test_clone( *edged_curve ); diff --git a/tests/mesh/test-euclidean-distance-transform.cpp b/tests/mesh/test-euclidean-distance-transform.cpp index 4f0530a86..7a7faaa74 100644 --- a/tests/mesh/test-euclidean-distance-transform.cpp +++ b/tests/mesh/test-euclidean-distance-transform.cpp @@ -27,6 +27,7 @@ #include #include +#include #include diff --git a/tests/mesh/test-generic-mesh-accessor.cpp b/tests/mesh/test-generic-mesh-accessor.cpp index 9eb02063d..2753fd0ca 100644 --- a/tests/mesh/test-generic-mesh-accessor.cpp +++ b/tests/mesh/test-generic-mesh-accessor.cpp @@ -41,7 +41,8 @@ #include #include -std::unique_ptr< geode::EdgedCurve3D > create_edged_curve() +std::unique_ptr< geode::EdgedCurve3D > create_edged_curve( + const geode::uuid& attribute_id ) { auto edged_curve = geode::EdgedCurve3D::create(); auto builder = geode::EdgedCurveBuilder3D::create( *edged_curve ); @@ -50,14 +51,19 @@ std::unique_ptr< geode::EdgedCurve3D > create_edged_curve() builder->create_point( geode::Point3D{ { 0, 1, 0 } } ); builder->create_edge( 0, 1 ); builder->create_edge( 0, 2 ); - auto attribute = edged_curve->edge_attribute_manager() - .find_or_create_attribute< geode::VariableAttribute, - geode::index_t >( "test_attribute", 2 ); + edged_curve->edge_attribute_manager() + .create_attribute< geode::VariableAttribute, geode::index_t >( + "edge", attribute_id, 2, geode::AttributeProperties{} ); + auto attribute = + edged_curve->edge_attribute_manager() + .find_attribute< geode::VariableAttribute, geode::index_t >( + attribute_id ); attribute->set_value( 1, 5 ); return edged_curve; } -std::unique_ptr< geode::TriangulatedSurface2D > create_surface() +std::unique_ptr< geode::TriangulatedSurface2D > create_surface( + const geode::uuid& attribute_id ) { auto surface = geode::TriangulatedSurface2D::create(); auto builder = geode::TriangulatedSurfaceBuilder2D::create( *surface ); @@ -68,14 +74,19 @@ std::unique_ptr< geode::TriangulatedSurface2D > create_surface() builder->create_triangle( { 0, 1, 2 } ); builder->create_triangle( { 0, 3, 1 } ); builder->compute_polygon_adjacencies(); - auto attribute = surface->polygon_attribute_manager() - .find_or_create_attribute< geode::VariableAttribute, - geode::index_t >( "test_attribute", 2 ); + surface->polygon_attribute_manager() + .create_attribute< geode::VariableAttribute, geode::index_t >( + "surface", attribute_id, 2, geode::AttributeProperties{} ); + auto attribute = + surface->polygon_attribute_manager() + .find_attribute< geode::VariableAttribute, geode::index_t >( + attribute_id ); attribute->set_value( 1, 5 ); return surface; } -std::unique_ptr< geode::TetrahedralSolid3D > create_solid() +std::unique_ptr< geode::TetrahedralSolid3D > create_solid( + const geode::uuid& attribute_id ) { auto solid = geode::TetrahedralSolid3D::create(); auto builder = geode::TetrahedralSolidBuilder3D::create( *solid ); @@ -87,15 +98,21 @@ std::unique_ptr< geode::TetrahedralSolid3D > create_solid() builder->create_tetrahedron( { 0, 1, 2, 3 } ); builder->create_tetrahedron( { 3, 2, 4, 1 } ); builder->compute_polyhedron_adjacencies(); - auto attribute = solid->polyhedron_attribute_manager() - .find_or_create_attribute< geode::VariableAttribute, - geode::index_t >( "test_attribute", 2 ); + solid->polyhedron_attribute_manager() + .create_attribute< geode::VariableAttribute, geode::index_t >( + "solid", attribute_id, 2, geode::AttributeProperties{} ); + auto attribute = + solid->polyhedron_attribute_manager() + .find_attribute< geode::VariableAttribute, geode::index_t >( + attribute_id ); attribute->set_value( 1, 5 ); return solid; } template < typename Mesh > -void test_basic_accessor( const Mesh& mesh, geode::index_t nb_element_vertices ) +void test_basic_accessor( const Mesh& mesh, + geode::index_t nb_element_vertices, + const geode::uuid& attribute_id ) { using Accessor = geode::GenericMeshAccessor< Mesh >; const Accessor accessor{ mesh }; @@ -118,7 +135,8 @@ void test_basic_accessor( const Mesh& mesh, geode::index_t nb_element_vertices ) "Wrong size of element vertices container" ); const auto attribute = accessor.element_attribute_manager() - .template find_attribute< geode::index_t >( "test_attribute" ); + .template find_read_only_attribute< geode::index_t >( + attribute_id ); geode::OpenGeodeMeshException::test( attribute->value( 0 ) == 2 && attribute->value( 1 ) == 5, "Wrong values of the element attributes." ); @@ -157,14 +175,17 @@ void test() { geode::OpenGeodeMeshLibrary::initialize(); geode::Logger::info( "Test Surface" ); - const auto edged_curve = create_edged_curve(); - test_basic_accessor( *edged_curve, 2 ); - const auto surface = create_surface(); - test_basic_accessor( *surface, 3 ); + geode::uuid edge_curve_attribute_uuid; + const auto edged_curve = create_edged_curve( edge_curve_attribute_uuid ); + test_basic_accessor( *edged_curve, 2, edge_curve_attribute_uuid ); + geode::uuid surface_attribute_uuid; + const auto surface = create_surface( surface_attribute_uuid ); + test_basic_accessor( *surface, 3, surface_attribute_uuid ); test_adjacent_accessor( *surface ); geode::Logger::info( "Test Solid" ); - const auto solid = create_solid(); - test_basic_accessor( *solid, 4 ); + geode::uuid solid_attribute_uuid; + const auto solid = create_solid( solid_attribute_uuid ); + test_basic_accessor( *solid, 4, solid_attribute_uuid ); test_adjacent_accessor( *solid ); } diff --git a/tests/mesh/test-gradient-computation.cpp b/tests/mesh/test-gradient-computation.cpp index acf96d009..483b74016 100644 --- a/tests/mesh/test-gradient-computation.cpp +++ b/tests/mesh/test-gradient-computation.cpp @@ -48,11 +48,13 @@ void test_gradient_grid2D() auto builder = geode::RegularGridBuilder< 2 >::create( *grid ); builder->initialize_grid( geode::Point2D{ { 0, 0 } }, { 3, 3 }, { geode::Vector2D{ { 1, 0 } }, geode::Vector2D{ { 0, 1 } } } ); - const auto scalar_function_name = "scalar_function"; + auto attribute_id = + grid->vertex_attribute_manager() + .create_attribute< geode::VariableAttribute, double >( + "scalar_function", 0, geode::AttributeProperties{} ); auto attribute = grid->vertex_attribute_manager() - .find_or_create_attribute< geode::VariableAttribute, double >( - scalar_function_name, 0 ); + .find_attribute< geode::VariableAttribute, double >( attribute_id ); attribute->set_value( 1, 1 ); attribute->set_value( 4, 1 ); attribute->set_value( 6, 1 ); @@ -67,9 +69,9 @@ void test_gradient_grid2D() attribute->set_value( 13, 2 ); attribute->set_value( 14, 3 ); attribute->set_value( 15, 8 ); - const auto gradient_name = geode::compute_surface_scalar_function_gradient( - *grid, scalar_function_name ); - geode::Logger::info( "Gradient attribute name: ", gradient_name ); + const auto gradient_id = + geode::compute_surface_scalar_function_gradient( *grid, attribute_id ); + geode::Logger::info( "Gradient attribute id: ", gradient_id.string() ); geode::save_regular_grid< 2 >( *grid, "grid_with_gradient.og_rgd2d" ); } @@ -99,11 +101,13 @@ void test_gradient_triangulated_surface2D() builder->create_polygon( { 6, 9, 8 } ); builder->create_polygon( { 5, 6, 8 } ); builder->compute_polygon_adjacencies(); - const auto scalar_function_name = "scalar_function"; + auto attribute_id = + surface->vertex_attribute_manager() + .create_attribute< geode::VariableAttribute, double >( + "scalar_function", 0, geode::AttributeProperties{} ); auto attribute = surface->vertex_attribute_manager() - .find_or_create_attribute< geode::VariableAttribute, double >( - scalar_function_name, 0 ); + .find_attribute< geode::VariableAttribute, double >( attribute_id ); attribute->set_value( 1, 1 ); attribute->set_value( 2, 1 ); attribute->set_value( 3, 1 ); @@ -112,9 +116,9 @@ void test_gradient_triangulated_surface2D() attribute->set_value( 9, 3 ); attribute->set_value( 7, 2 ); attribute->set_value( 8, 2 ); - const auto gradient_name = geode::compute_surface_scalar_function_gradient( - *surface, scalar_function_name ); - geode::Logger::info( "Gradient attribute name: ", gradient_name ); + const auto gradient_id = geode::compute_surface_scalar_function_gradient( + *surface, attribute_id ); + geode::Logger::info( "Gradient attribute id: ", gradient_id.string() ); geode::save_triangulated_surface< 2 >( *surface, "mesh_with_gradient.og_tsf2d" ); } @@ -126,11 +130,13 @@ void test_gradient_grid3D() builder->initialize_grid( geode::Point3D{ { 0, 0, 0 } }, { 2, 2, 2 }, { geode::Vector3D{ { 1, 0, 0 } }, geode::Vector3D{ { 0, 1, 0 } }, geode::Vector3D{ { 0, 0, 1 } } } ); - const auto scalar_function_name = "scalar_function"; + auto attribute_id = + grid->vertex_attribute_manager() + .create_attribute< geode::VariableAttribute, double >( + "scalar_function", 0, geode::AttributeProperties{} ); auto attribute = grid->vertex_attribute_manager() - .find_or_create_attribute< geode::VariableAttribute, double >( - scalar_function_name, 0 ); + .find_attribute< geode::VariableAttribute, double >( attribute_id ); attribute->set_value( 4, 1 ); attribute->set_value( 10, 1 ); attribute->set_value( 12, 1 ); @@ -157,13 +163,14 @@ void test_gradient_grid3D() attribute->set_value( 20, 3 ); attribute->set_value( 24, 3 ); attribute->set_value( 26, 3 ); - const auto gradient_name = geode::compute_solid_scalar_function_gradient( - *grid, scalar_function_name ); - geode::Logger::info( "Gradient attribute name: ", gradient_name ); - const auto [gradient_name_2, vertices_with_no_value] = + const auto gradient_id = + geode::compute_solid_scalar_function_gradient( *grid, attribute_id ); + geode::Logger::info( "Gradient attribute name: ", gradient_id.string() ); + const auto [gradient_id_2, vertices_with_no_value] = geode::internal::compute_solid_scalar_function_gradient( - *grid, scalar_function_name, { 0, 1 } ); - geode::Logger::info( "Gradient attribute name 2: ", gradient_name_2 ); + *grid, attribute_id, { 0, 1 } ); + geode::Logger::info( + "Gradient attribute name 2: ", gradient_id_2.string() ); geode::OpenGeodeMeshException::test( vertices_with_no_value.size() == 7, "Wrong number of vertices without value for gradient " "computation, ", diff --git a/tests/mesh/test-graph.cpp b/tests/mesh/test-graph.cpp index 7fd4ee7ac..976614bd2 100644 --- a/tests/mesh/test-graph.cpp +++ b/tests/mesh/test-graph.cpp @@ -168,9 +168,10 @@ void test() test_create_vertices( *graph, *builder ); test_create_edges( *graph, *builder ); test_io( *graph, absl::StrCat( "test.", graph->native_extension() ) ); - test_backward_io( absl::StrCat( - geode::DATA_PATH, "test_v7.", graph->native_extension() ) ); - + test_backward_io( absl::StrCat( geode::DATA_PATH, + "/backward_io/v7/test_v7.", graph->native_extension() ) ); + test_backward_io( absl::StrCat( geode::DATA_PATH, "/backward_io/v17/v17.", + graph->native_extension() ) ); test_delete_edge( *graph, *builder ); test_clone( *graph ); test_delete_isolated_vertices( *graph, *builder ); diff --git a/tests/mesh/test-hybrid-solid.cpp b/tests/mesh/test-hybrid-solid.cpp index d0033c3a2..24a0fad53 100644 --- a/tests/mesh/test-hybrid-solid.cpp +++ b/tests/mesh/test-hybrid-solid.cpp @@ -414,6 +414,27 @@ void test_io( "Reloaded HybridSolid has wrong polyhedron facet index" ); } +void test_backward_io( const std::string& filename ) +{ + const auto solid = geode::load_hybrid_solid< 3 >( filename ); + geode::OpenGeodeMeshException::test( solid->nb_vertices() == 11, + "Backward HybridSolid should have 11 vertices" ); + geode::OpenGeodeMeshException::test( + solid->point( 2 ) == geode::Point3D{ { 2, 1, 0 } }, + "Backward HybridSolid has wrong point coordinates" ); + geode::OpenGeodeMeshException::test( solid->nb_polyhedra() == 4, + "Backward HybridSolid should have 4 polyhedra" ); + geode::OpenGeodeMeshException::test( solid->facets().nb_facets() == 16, + "Backward HybridSolid should have 16 facets" ); + geode::OpenGeodeMeshException::test( solid->edges().nb_edges() == 22, + "Backward HybridSolid should have 22 edges" ); + geode::OpenGeodeMeshException::test( + solid->facets().facet_from_vertices( + solid->polyhedron_facet_vertices( { 1, 0 } ) ) + == 6, + "Backward HybridSolid has wrong polyhedron facet index" ); +} + void test_clone( const geode::HybridSolid3D& hybrid_solid ) { const auto hybrid_solid_clone = hybrid_solid.clone(); @@ -474,7 +495,8 @@ void test() test_polyhedron_adjacencies( *hybrid_solid, *builder ); test_io( *hybrid_solid, absl::StrCat( "test.", hybrid_solid->native_extension() ) ); - + test_backward_io( absl::StrCat( geode::DATA_PATH, "backward_io/v17/v17.", + hybrid_solid->native_extension() ) ); test_permutation( *hybrid_solid, *builder ); test_delete_polyhedra( *hybrid_solid, *builder ); test_clone( *hybrid_solid ); diff --git a/tests/mesh/test-light-regular-grid.cpp b/tests/mesh/test-light-regular-grid.cpp index 79d34947d..ed559a51e 100644 --- a/tests/mesh/test-light-regular-grid.cpp +++ b/tests/mesh/test-light-regular-grid.cpp @@ -332,10 +332,13 @@ void test_closest_vertex( const geode::LightRegularGrid3D& grid ) void test_attribute( const geode::LightRegularGrid3D& grid ) { + auto attribute_id = + grid.cell_attribute_manager() + .create_attribute< geode::VariableAttribute, double >( + "test", -1, geode::AttributeProperties{} ); auto attribute = grid.cell_attribute_manager() - .find_or_create_attribute< geode::VariableAttribute, double >( - "toto", -1 ); + .find_attribute< geode::VariableAttribute, double >( attribute_id ); attribute->set_value( 10, 10 ); geode::OpenGeodeMeshException::test( attribute->value( 0 ) == -1, "Wrong attribute value" ); diff --git a/tests/mesh/test-merge-surface.cpp b/tests/mesh/test-merge-surface.cpp index 6c2c0d110..a94338a9b 100644 --- a/tests/mesh/test-merge-surface.cpp +++ b/tests/mesh/test-merge-surface.cpp @@ -142,7 +142,6 @@ void test_import() } geode::NNSearch3D nns( points ); const auto mappings = nns.colocated_index_mapping( geode::GLOBAL_EPSILON ); - DEBUG( mappings.nb_colocated_points() ); geode::OpenGeodeMeshException::test( mappings.nb_colocated_points() == 0, "Should be no more colocated points" ); for( const auto p : geode::Indices{ points } ) diff --git a/tests/mesh/test-point-set.cpp b/tests/mesh/test-point-set.cpp index 3ee8db458..dc2f85ba0 100644 --- a/tests/mesh/test-point-set.cpp +++ b/tests/mesh/test-point-set.cpp @@ -82,14 +82,17 @@ void test_bounding_box( const geode::PointSet3D& point_set ) "Wrong computation of bounding box (max)" ); } -void test_create_vertex_attribute( const geode::PointSet3D& point_set ) +geode::uuid test_create_vertex_attribute( const geode::PointSet3D& point_set ) { - auto attribute = + auto attribute_id = point_set.vertex_attribute_manager() + .create_attribute< geode::ConstantAttribute, bool >( + "bool", true, geode::AttributeProperties{} ); + const auto attribute = point_set.vertex_attribute_manager() - .find_or_create_attribute< geode::ConstantAttribute, bool >( - "test", true ); + .find_attribute< geode::ConstantAttribute, bool >( attribute_id ); geode::OpenGeodeMeshException::test( attribute->value() == true, "PointSet attribute value should be true" ); + return attribute_id; } void test_delete_vertex( @@ -121,14 +124,27 @@ void test_io( const geode::PointSet3D& point_set, std::string_view filename ) } } -void test_clone( const geode::PointSet3D& point_set ) +void test_backward_io( + std::string_view filename, const geode::uuid& attribute_id ) +{ + const auto point_set = geode::load_point_set< 3 >( filename ); + geode::OpenGeodeMeshException::test( + point_set->nb_vertices() == 4, "PointSet should have 4 vertices" ); + const geode::Point3D answer{ { 2.1, 9.4, 6.7 } }; + geode::OpenGeodeMeshException::test( point_set->point( 1 ) == answer, + "PointSet vertex coordinates are not correct" ); +} + +void test_clone( + const geode::PointSet3D& point_set, const geode::uuid& attribute_id ) { const auto point_set2 = point_set.clone(); geode::OpenGeodeMeshException::test( point_set2->nb_vertices() == 3, "PointSet2 should have 3 vertices" ); const auto attribute = - point_set2->vertex_attribute_manager().find_attribute< bool >( "test" ); + point_set2->vertex_attribute_manager().find_read_only_attribute< bool >( + attribute_id ); geode::OpenGeodeMeshException::test( attribute->value( 0 ) == true, "PointSet2 attribute value should be true" ); @@ -145,13 +161,15 @@ void test() auto builder = geode::PointSetBuilder3D::create( *point_set ); test_create_vertices( *point_set, *builder ); test_bounding_box( *point_set ); - test_create_vertex_attribute( *point_set ); + const auto vertex_attribute_id = test_create_vertex_attribute( *point_set ); test_io( *point_set, absl::StrCat( "test.", point_set->native_extension() ) ); - + test_backward_io( absl::StrCat( geode::DATA_PATH, "backward_io/v17/v17.", + point_set->native_extension() ), + vertex_attribute_id ); test_permutation( *point_set, *builder ); test_delete_vertex( *point_set, *builder ); - test_clone( *point_set ); + test_clone( *point_set, vertex_attribute_id ); } OPENGEODE_TEST( "point-set" ) \ No newline at end of file diff --git a/tests/mesh/test-polygonal-surface.cpp b/tests/mesh/test-polygonal-surface.cpp index 9f6f7d068..c706d11ea 100644 --- a/tests/mesh/test-polygonal-surface.cpp +++ b/tests/mesh/test-polygonal-surface.cpp @@ -68,13 +68,17 @@ void test_bounding_box( const geode::PolygonalSurface3D& polygonal_surface ) "Wrong computation of bounding box (max)" ); } -void test_create_vertex_attribute( +geode::uuid test_create_vertex_attribute( const geode::PolygonalSurface3D& polygonal_surface ) { + auto attribute_id = + polygonal_surface.vertex_attribute_manager() + .create_attribute< geode::VariableAttribute, geode::PolygonEdge >( + "test", geode::PolygonEdge{}, geode::AttributeProperties{} ); auto attribute = polygonal_surface.vertex_attribute_manager() - .find_or_create_attribute< geode::VariableAttribute, - geode::PolygonEdge >( "test", geode::PolygonEdge{} ); + .find_attribute< geode::VariableAttribute, geode::PolygonEdge >( + attribute_id ); for( const auto v : geode::Range{ polygonal_surface.nb_vertices() } ) { attribute->set_value( v, geode::PolygonEdge{ v, 0 } ); @@ -82,6 +86,7 @@ void test_create_vertex_attribute( geode::PolygonEdge{} != attribute->value( v ), "PolygonalSurface attribute assignation is not correct" ); } + return attribute_id; } void test_permutation( const geode::PolygonalSurface3D& surface, @@ -220,17 +225,24 @@ void test_create_polygons( const geode::PolygonalSurface3D& polygonal_surface, "Wrong polygon vertices list" ); } -void test_create_edge_attribute( +geode::uuid test_create_edge_attribute( const geode::PolygonalSurface3D& polygonal_surface ) { - auto attribute = polygonal_surface.edges() - .edge_attribute_manager() - .find_or_create_attribute< geode::VariableAttribute, - geode::index_t >( "test", geode::NO_ID ); + auto attribute_id = + polygonal_surface.edges() + .edge_attribute_manager() + .create_attribute< geode::VariableAttribute, geode::index_t >( + "edges", geode::NO_ID, geode::AttributeProperties{} ); + auto attribute = + polygonal_surface.edges() + .edge_attribute_manager() + .find_attribute< geode::VariableAttribute, geode::index_t >( + attribute_id ); for( const auto e : geode::Range{ polygonal_surface.edges().nb_edges() } ) { attribute->set_value( e, e ); } + return attribute_id; } void test_polygon_adjacencies( @@ -337,7 +349,8 @@ void test_polygon_edge_requests( } void test_delete_polygon( const geode::PolygonalSurface3D& polygonal_surface, - geode::PolygonalSurfaceBuilder3D& builder ) + geode::PolygonalSurfaceBuilder3D& builder, + const geode::uuid edge_attribute_id ) { std::vector< bool > to_delete( polygonal_surface.nb_polygons(), false ); to_delete.front() = true; @@ -362,9 +375,10 @@ void test_delete_polygon( const geode::PolygonalSurface3D& polygonal_surface, geode::OpenGeodeMeshException::test( polygonal_surface.edges().nb_edges() == 6, "PolygonalSurface should have 6 edges" ); - const auto attribute = polygonal_surface.edges() - .edge_attribute_manager() - .find_attribute< geode::index_t >( "test" ); + const auto attribute = + polygonal_surface.edges() + .edge_attribute_manager() + .find_read_only_attribute< geode::index_t >( edge_attribute_id ); for( const auto e : geode::Range{ 6 } ) { geode::OpenGeodeMeshException::test( attribute->value( e ) == e, @@ -461,7 +475,8 @@ void test_polygon_vertex_normal() } void test_io( const geode::PolygonalSurface3D& polygonal_surface, - const std::string& filename ) + const std::string& filename, + const geode::uuid edge_attribute_id ) { geode::save_polygonal_surface( polygonal_surface, filename ); const auto reloaded = geode::load_polygonal_surface< 3 >( filename ); @@ -490,9 +505,10 @@ void test_io( const geode::PolygonalSurface3D& polygonal_surface, new_polygonal_surface->edges().edge_from_vertices( { 1, 0 } ) == polygonal_surface.edges().edge_from_vertices( { 1, 0 } ), "Reloaded PolygonalSurface has wrong polygon edge index" ); - const auto attribute = new_polygonal_surface->edges() - .edge_attribute_manager() - .find_attribute< geode::index_t >( "test" ); + const auto attribute = + new_polygonal_surface->edges() + .edge_attribute_manager() + .find_read_only_attribute< geode::index_t >( edge_attribute_id ); for( const auto e : geode::Range{ new_polygonal_surface->edges().nb_edges() } ) { @@ -531,7 +547,8 @@ void test_backward_io( const std::string& filename ) "Backward polygons around failed" ); } -void test_clone( const geode::PolygonalSurface3D& polygonal_surface ) +void test_clone( const geode::PolygonalSurface3D& polygonal_surface, + geode::uuid vertex_attribute_id ) { const auto polygonal_surface_clone = polygonal_surface.clone(); geode::OpenGeodePolygonalSurface3D polygonal_surface2{ std::move( @@ -546,7 +563,8 @@ void test_clone( const geode::PolygonalSurface3D& polygonal_surface ) "PolygonalSurface2 should have 2 polygons" ); const auto attribute2 = polygonal_surface2.vertex_attribute_manager() - .find_attribute< geode::PolygonEdge >( "test" ); + .find_read_only_attribute< geode::PolygonEdge >( + vertex_attribute_id ); std::vector< geode::PolygonEdge > att_answer{ { 4, 0 }, { 2, 0 }, { 6, 0 }, { 1, 0 }, { 5, 0 }, { 0, 0 }, { 3, 0 } }; for( const auto v : geode::Range{ polygonal_surface2.nb_vertices() } ) @@ -576,9 +594,6 @@ void test_set_polygon_vertex( void test_replace_vertex( const geode::PolygonalSurface3D& polygonal_surface, geode::PolygonalSurfaceBuilder3D& builder ) { - const auto att = polygonal_surface.edges() - .edge_attribute_manager() - .find_attribute< geode::index_t >( "counter" ); const auto new_id = builder.create_vertex(); const auto polygons_around = polygonal_surface.polygons_around_vertex( 1 ); builder.replace_vertex( 1, new_id ); @@ -667,9 +682,11 @@ void test() test_create_vertices( *polygonal_surface, *builder ); test_bounding_box( *polygonal_surface ); - test_create_vertex_attribute( *polygonal_surface ); + const auto vertex_attribute_id = + test_create_vertex_attribute( *polygonal_surface ); test_create_polygons( *polygonal_surface, *builder ); - test_create_edge_attribute( *polygonal_surface ); + const auto edge_attribute_id = + test_create_edge_attribute( *polygonal_surface ); test_polygon_adjacencies( *polygonal_surface, *builder ); test_polygon_edges_on_borders( *polygonal_surface ); test_previous_next_on_border( *polygonal_surface ); @@ -681,16 +698,18 @@ void test() test_texture( *polygonal_surface ); test_io( *polygonal_surface, - absl::StrCat( "test.", polygonal_surface->native_extension() ) ); - test_backward_io( absl::StrCat( - geode::DATA_PATH, "test_v7.", polygonal_surface->native_extension() ) ); - test_backward_io( absl::StrCat( geode::DATA_PATH, "test_v12.", + absl::StrCat( "test.", polygonal_surface->native_extension() ), + edge_attribute_id ); + test_backward_io( absl::StrCat( geode::DATA_PATH, "backward_io/v7/test_v7.", + polygonal_surface->native_extension() ) ); + test_backward_io( absl::StrCat( geode::DATA_PATH, + "backward_io/v12/test_v12.", polygonal_surface->native_extension() ) ); + test_backward_io( absl::StrCat( geode::DATA_PATH, "backward_io/v17/v17.", polygonal_surface->native_extension() ) ); - test_permutation( *polygonal_surface, *builder ); test_replace_vertex( *polygonal_surface, *builder ); - test_delete_polygon( *polygonal_surface, *builder ); - test_clone( *polygonal_surface ); + test_delete_polygon( *polygonal_surface, *builder, edge_attribute_id ); + test_clone( *polygonal_surface, vertex_attribute_id ); test_set_polygon_vertex( *polygonal_surface, *builder ); test_delete_all( *polygonal_surface, *builder ); diff --git a/tests/mesh/test-polyhedral-solid.cpp b/tests/mesh/test-polyhedral-solid.cpp index 586dcee69..feeb9a0cb 100644 --- a/tests/mesh/test-polyhedral-solid.cpp +++ b/tests/mesh/test-polyhedral-solid.cpp @@ -127,26 +127,39 @@ void test_create_polyhedra( const geode::PolyhedralSolid3D& polyhedral_solid, "Wrong polyhedron vertices list" ); } -void test_create_facet_attribute( +geode::uuid test_create_facet_attribute( const geode::PolyhedralSolid3D& polyhedral_solid ) { - auto attribute = polyhedral_solid.facets() - .facet_attribute_manager() - .find_or_create_attribute< geode::VariableAttribute, - geode::index_t >( "test", geode::NO_ID ); + auto attribute_id = + polyhedral_solid.facets() + .facet_attribute_manager() + .create_attribute< geode::VariableAttribute, geode::index_t >( + "facet_attribute", geode::NO_ID, geode::AttributeProperties{} ); + auto attribute = + polyhedral_solid.facets() + .facet_attribute_manager() + .find_attribute< geode::VariableAttribute, geode::index_t >( + attribute_id ); for( const auto f : geode::Range{ polyhedral_solid.facets().nb_facets() } ) { attribute->set_value( f, f ); } + return attribute_id; } -void test_create_edge_attribute( +geode::uuid test_create_edge_attribute( const geode::PolyhedralSolid3D& polyhedral_solid ) { - auto attribute = polyhedral_solid.edges() - .edge_attribute_manager() - .find_or_create_attribute< geode::VariableAttribute, - geode::index_t >( "test", geode::NO_ID ); + auto attribute_id = + polyhedral_solid.edges() + .edge_attribute_manager() + .create_attribute< geode::VariableAttribute, geode::index_t >( + "test", geode::NO_ID, geode::AttributeProperties{} ); + auto attribute = + polyhedral_solid.edges() + .edge_attribute_manager() + .find_attribute< geode::VariableAttribute, geode::index_t >( + attribute_id ); for( const auto e : geode::Range{ polyhedral_solid.edges().nb_edges() } ) { const auto& vertices = polyhedral_solid.edges().edge_vertices( e ); @@ -156,6 +169,7 @@ void test_create_edge_attribute( attribute->value( 0 ) == 1, "Wrong value for attribute on edge 0" ); geode::OpenGeodeMeshException::test( attribute->value( 1 ) == 3, "Wrong value for attribute on edge 1" ); + return attribute_id; } void test_polyhedron_adjacencies( @@ -335,7 +349,8 @@ void test_permutation( const geode::PolyhedralSolid3D& solid, } void test_delete_polyhedra( const geode::PolyhedralSolid3D& polyhedral_solid, - geode::PolyhedralSolidBuilder3D& builder ) + geode::PolyhedralSolidBuilder3D& builder, + const geode::uuid& edge_attribute_id ) { std::vector< bool > to_delete( polyhedral_solid.nb_polyhedra(), false ); to_delete.front() = true; @@ -368,9 +383,10 @@ void test_delete_polyhedra( const geode::PolyhedralSolid3D& polyhedral_solid, geode::OpenGeodeMeshException::test( polyhedral_solid.edges().nb_edges() == 12, "PolyhedralSolid should have 12 edges" ); - auto attribute = polyhedral_solid.edges() - .edge_attribute_manager() - .find_attribute< geode::index_t >( "test" ); + auto attribute = + polyhedral_solid.edges() + .edge_attribute_manager() + .find_read_only_attribute< geode::index_t >( edge_attribute_id ); geode::OpenGeodeMeshException::test( attribute->value( 0 ) == 1, "Wrong value for attribute on edge 0 after vertex deletion" ); geode::OpenGeodeMeshException::test( attribute->value( 1 ) == 3, @@ -378,7 +394,8 @@ void test_delete_polyhedra( const geode::PolyhedralSolid3D& polyhedral_solid, } void test_io( const geode::PolyhedralSolid3D& polyhedral_solid, - const std::string& filename ) + const std::string& filename, + const geode::uuid& facet_attribute_id ) { geode::save_polyhedral_solid( polyhedral_solid, filename ); const auto reloaded = geode::load_polyhedral_solid< 3 >( filename ); @@ -411,9 +428,10 @@ void test_io( const geode::PolyhedralSolid3D& polyhedral_solid, == polyhedral_solid.facets().facet_from_vertices( polyhedral_solid.polyhedron_facet_vertices( { 1, 0 } ) ), "Reloaded PolyhedralSolid has wrong polyhedron facet index" ); - auto attribute = new_polyhedral_solid->facets() - .facet_attribute_manager() - .find_attribute< geode::index_t >( "test" ); + auto attribute = + new_polyhedral_solid->facets() + .facet_attribute_manager() + .find_read_only_attribute< geode::index_t >( facet_attribute_id ); for( auto f : geode::Range{ new_polyhedral_solid->facets().nb_facets() } ) { geode::OpenGeodeMeshException::test( attribute->value( f ) == f, @@ -520,20 +538,26 @@ void test_normals() "1)" ); } -void test_create_vertex_attribute( +geode::uuid test_create_vertex_attribute( const geode::PolyhedralSolid3D& polyhedral_solid ) { + auto attribute_id = + polyhedral_solid.vertex_attribute_manager() + .create_attribute< geode::VariableAttribute, + geode::PolyhedronFacetVertex >( "test", + geode::PolyhedronFacetVertex{}, geode::AttributeProperties{} ); auto attribute = polyhedral_solid.vertex_attribute_manager() - .find_or_create_attribute< geode::VariableAttribute, - geode::PolyhedronFacetVertex >( - "test", geode::PolyhedronFacetVertex{} ); + .find_attribute< geode::VariableAttribute, + geode::PolyhedronFacetVertex >( attribute_id ); for( const auto v : geode::Range{ polyhedral_solid.nb_vertices() } ) { attribute->set_value( v, geode::PolyhedronFacetVertex{ { v, 0 }, 1 } ); } + return attribute_id; } -void test_clone( const geode::PolyhedralSolid3D& polyhedral_solid ) +void test_clone( const geode::PolyhedralSolid3D& polyhedral_solid, + const geode::uuid vertex_attribute_id ) { const auto polyhedral_solid_clone = polyhedral_solid.clone(); geode::OpenGeodePolyhedralSolid3D polyhedral_solid2{ std::move( @@ -549,7 +573,8 @@ void test_clone( const geode::PolyhedralSolid3D& polyhedral_solid ) const auto attribute2 = polyhedral_solid2.vertex_attribute_manager() - .find_attribute< geode::PolyhedronFacetVertex >( "test" ); + .find_read_only_attribute< geode::PolyhedronFacetVertex >( + vertex_attribute_id ); std::vector< geode::PolyhedronFacetVertex > att_answer{ { { 4, 0 }, 1 }, { { 2, 0 }, 1 }, { { 6, 0 }, 1 }, { { 1, 0 }, 1 }, { { 5, 0 }, 1 }, { { 0, 0 }, 1 }, { { 7, 0 }, 1 }, { { 3, 0 }, 1 } }; @@ -635,25 +660,30 @@ void test() auto builder = geode::PolyhedralSolidBuilder3D::create( *polyhedral_solid ); test_create_vertices( *polyhedral_solid, *builder ); - test_create_vertex_attribute( *polyhedral_solid ); + const auto vertex_attribute_id = + test_create_vertex_attribute( *polyhedral_solid ); test_create_polyhedra( *polyhedral_solid, *builder ); - test_create_facet_attribute( *polyhedral_solid ); - test_create_edge_attribute( *polyhedral_solid ); + const auto facet_attribute_id = + test_create_facet_attribute( *polyhedral_solid ); + const auto edge_attribute_id = + test_create_edge_attribute( *polyhedral_solid ); test_edges( *polyhedral_solid ); test_facets( *polyhedral_solid ); test_polyhedron_adjacencies( *polyhedral_solid, *builder ); test_texture( *polyhedral_solid ); test_io( *polyhedral_solid, - absl::StrCat( "test.", polyhedral_solid->native_extension() ) ); - test_backward_io( absl::StrCat( - geode::DATA_PATH, "test_v7.", polyhedral_solid->native_extension() ) ); - test_backward_io( absl::StrCat( - geode::DATA_PATH, "test_v12.", polyhedral_solid->native_extension() ) ); - + absl::StrCat( "test.", polyhedral_solid->native_extension() ), + facet_attribute_id ); + test_backward_io( absl::StrCat( geode::DATA_PATH, "backward_io/v7/test_v7.", + polyhedral_solid->native_extension() ) ); + test_backward_io( absl::StrCat( geode::DATA_PATH, + "backward_io/v12/test_v12.", polyhedral_solid->native_extension() ) ); + test_backward_io( absl::StrCat( geode::DATA_PATH, "backward_io/v17/v17.", + polyhedral_solid->native_extension() ) ); test_permutation( *polyhedral_solid, *builder ); - test_delete_polyhedra( *polyhedral_solid, *builder ); - test_clone( *polyhedral_solid ); + test_delete_polyhedra( *polyhedral_solid, *builder, edge_attribute_id ); + test_clone( *polyhedral_solid, vertex_attribute_id ); test_set_polyhedron_vertex( *polyhedral_solid, *builder ); test_delete_all( *polyhedral_solid, *builder ); diff --git a/tests/mesh/test-regular-grid.cpp b/tests/mesh/test-regular-grid.cpp index 27f883f1c..ed208d9a6 100644 --- a/tests/mesh/test-regular-grid.cpp +++ b/tests/mesh/test-regular-grid.cpp @@ -353,16 +353,20 @@ void test_closest_vertex( const geode::RegularGrid3D& grid ) void test_clone( const geode::RegularGrid3D& grid ) { - const auto attribute_name = "int_attribute"; - const auto attribute_name_d = "double_attribute"; + auto attribute_id = + grid.polyhedron_attribute_manager() + .create_attribute< geode::VariableAttribute, int >( + "int_attribute", 0, geode::AttributeProperties{} ); auto attribute = grid.polyhedron_attribute_manager() - .find_or_create_attribute< geode::VariableAttribute, int >( - attribute_name, 0 ); - auto attribute_d = + .find_attribute< geode::VariableAttribute, int >( attribute_id ); + auto attribute_d_id = grid.vertex_attribute_manager() - .find_or_create_attribute< geode::VariableAttribute, double >( - attribute_name_d, 0 ); + .create_attribute< geode::VariableAttribute, double >( + "double_attribute", 0, geode::AttributeProperties{} ); + auto attribute_d = grid.vertex_attribute_manager() + .find_attribute< geode::VariableAttribute, double >( + attribute_d_id ); for( const auto c : geode::Range{ grid.nb_polyhedra() } ) { attribute->set_value( c, 2 * c ); @@ -414,23 +418,22 @@ void test_clone( const geode::RegularGrid3D& grid ) "Clone wrong cell length in direction 2" ); geode::OpenGeodeMeshException::test( - clone->polyhedron_attribute_manager().attribute_exists( - attribute_name ), + clone->polyhedron_attribute_manager().attribute_exists( attribute_id ), "Clone missing attribute" ); geode::OpenGeodeMeshException::test( - clone->vertex_attribute_manager().attribute_exists( attribute_name_d ), + clone->vertex_attribute_manager().attribute_exists( attribute_d_id ), "Clone missing attribute" ); const auto clone_attribute = - clone->polyhedron_attribute_manager().find_attribute< int >( - attribute_name ); + clone->polyhedron_attribute_manager().find_read_only_attribute< int >( + attribute_id ); for( const auto c : geode::TRange< int >{ clone->nb_polyhedra() } ) { geode::OpenGeodeMeshException::test( clone_attribute->value( c ) == 2 * c, "Wrong clone attribute" ); } const auto clone_attribute_d = - clone->vertex_attribute_manager().find_attribute< double >( - attribute_name_d ); + clone->vertex_attribute_manager().find_read_only_attribute< double >( + attribute_d_id ); for( const auto c : geode::TRange< int >{ clone->nb_vertices() } ) { geode::OpenGeodeMeshException::test( @@ -455,6 +458,19 @@ void test_io( const geode::RegularGrid3D& grid, std::string_view filename ) "Wrong reload nb_cells_in_direction(2)" ); } +void test_backward_io( std::string_view filename ) +{ + const auto grid = geode::load_regular_grid< 3 >( filename ); + geode::OpenGeodeMeshException::test( + grid->nb_cells() == 750, "Wrong Backward grid nb_cells()" ); + geode::OpenGeodeMeshException::test( grid->nb_cells_in_direction( 0 ) == 5, + "Wrong Backward grid nb_cells_in_direction(0)" ); + geode::OpenGeodeMeshException::test( grid->nb_cells_in_direction( 1 ) == 10, + "Wrong Backward grid nb_cells_in_direction(1)" ); + geode::OpenGeodeMeshException::test( grid->nb_cells_in_direction( 2 ) == 15, + "Wrong Backward grid nb_cells_in_direction(2)" ); +} + void test_adjacencies2D() { auto grid = geode::RegularGrid2D::create(); @@ -539,14 +555,16 @@ void test() geode::Vector3D{ { 0, -3, 0 } } } ); test_grid( *grid ); - auto grid_v12 = geode::load_regular_grid< 3 >( - absl::StrCat( geode::DATA_PATH, "test_v12.og_rgd3d" ) ); + auto grid_v12 = + geode::load_regular_grid< 3 >( absl::StrCat( geode::DATA_PATH, + "backward_io/v12/test_v12.", grid->native_extension() ) ); auto builder_v12 = geode::RegularGridBuilder3D::create( *grid_v12 ); builder_v12->update_origin_and_directions( geode::Point3D{ { 1.5, 0, 1 } }, { geode::Vector3D{ { 0, 0, 1 } }, geode::Vector3D{ { -2, 0, 0 } }, geode::Vector3D{ { 0, -3, 0 } } } ); test_grid( *grid_v12 ); - + test_backward_io( absl::StrCat( + geode::DATA_PATH, "backward_io/v17/v17.", grid->native_extension() ) ); test_adjacencies2D(); } diff --git a/tests/mesh/test-tetrahedral-solid.cpp b/tests/mesh/test-tetrahedral-solid.cpp index 5cc694de8..02fa6b5bc 100644 --- a/tests/mesh/test-tetrahedral-solid.cpp +++ b/tests/mesh/test-tetrahedral-solid.cpp @@ -323,21 +323,46 @@ void test_io( "Reloaded TetrahedralSolid should have 3 polyhedra" ); } +void test_backward_io( const std::string& filename ) +{ + const auto solid = geode::load_tetrahedral_solid< 3 >( filename ); + geode::OpenGeodeMeshException::test( solid->nb_vertices() == 6, + "Backward TetrahedralSolid should have 6 vertices" ); + geode::OpenGeodeMeshException::test( solid->nb_polyhedra() == 3, + "Backward TetrahedralSolid should have 3 polyhedra" ); + geode::OpenGeodeMeshException::test( solid->edges().nb_edges() == 12, + "Backward TetrahedralSolid should have 12 edges" ); + geode::OpenGeodeMeshException::test( solid->facets().nb_facets() == 10, + "Backward TetrahedralSolid should have 10 facets" ); + test_is_on_border( *solid ); +} + void test_clone( const geode::TetrahedralSolid3D& solid ) { - auto attr_from = solid.facets() - .facet_attribute_manager() - .find_or_create_attribute< geode::VariableAttribute, - geode::index_t >( "facet_id", 0 ); + auto attr_from_id = + solid.facets() + .facet_attribute_manager() + .create_attribute< geode::VariableAttribute, geode::index_t >( + "facet_id", 0, geode::AttributeProperties{} ); + auto attr_from = + solid.facets() + .facet_attribute_manager() + .find_attribute< geode::VariableAttribute, geode::index_t >( + attr_from_id ); for( const auto f : geode::Range{ solid.facets().nb_facets() } ) { attr_from->set_value( f, f ); } + auto attr_edge_from_id = + solid.edges() + .edge_attribute_manager() + .create_attribute< geode::VariableAttribute, geode::index_t >( + "edge_id", 0, geode::AttributeProperties{} ); auto attr_edge_from = solid.edges() .edge_attribute_manager() - .find_or_create_attribute< geode::VariableAttribute, - geode::index_t >( "edge_id", 0 ); + .find_attribute< geode::VariableAttribute, geode::index_t >( + attr_edge_from_id ); for( const auto e : geode::Range{ solid.edges().nb_edges() } ) { attr_edge_from->set_value( e, e ); @@ -347,9 +372,29 @@ void test_clone( const geode::TetrahedralSolid3D& solid ) geode::OpenGeodeTetrahedralSolid3D solid4{ std::move( *dynamic_cast< geode::OpenGeodeTetrahedralSolid3D* >( solid2.get() ) ) }; - const auto attr_to = solid4.facets() - .facet_attribute_manager() - .find_attribute< geode::index_t >( "facet_id" ); + const auto attr_to = + solid4.facets() + .facet_attribute_manager() + .find_read_only_attribute< geode::index_t >( attr_from_id ); + for( const auto v : geode::Range{ solid4.nb_vertices() } ) + { + geode::OpenGeodeMeshException::test( + solid4.point( v ) == solid.point( v ), + "Wrong cloned mesh point coordinates." ); + } + for( const auto p : geode::Range{ solid4.nb_polyhedra() } ) + { + for( const auto f : geode::LRange{ 4 } ) + { + for( const auto v : geode::LRange{ 3 } ) + { + geode::OpenGeodeMeshException::test( + solid4.polyhedron_facet_vertex( { { p, f }, v } ) + == solid.polyhedron_facet_vertex( { { p, f }, v } ), + "polyhedron_facet_vertex should match" ); + } + } + } for( const auto f : geode::Range{ solid.facets().nb_facets() } ) { geode::OpenGeodeMeshException::test( @@ -364,10 +409,17 @@ void test_clone( const geode::TetrahedralSolid3D& solid ) "Error in facet vertices transfer during cloning" ); } } + for( const auto v : geode::Range{ solid4.nb_vertices() } ) + { + geode::OpenGeodeMeshException::test( + solid.polyhedra_around_vertex( v ) + == solid4.polyhedra_around_vertex( v ), + "Polyhedra around vertex should match during cloning" ); + } const auto attr_edge_to = solid4.edges() .edge_attribute_manager() - .find_attribute< geode::index_t >( "edge_id" ); + .find_read_only_attribute< geode::index_t >( attr_edge_from_id ); for( const auto e : geode::Range{ solid.edges().nb_edges() } ) { geode::OpenGeodeMeshException::test( @@ -430,7 +482,8 @@ void test() test_polyhedron_adjacencies( *solid, *builder ); test_is_on_border( *solid ); test_io( *solid, absl::StrCat( "test.", solid->native_extension() ) ); - + test_backward_io( absl::StrCat( + geode::DATA_PATH, "backward_io/v17/v17.", solid->native_extension() ) ); test_permutation( *solid, *builder ); test_delete_polyhedron( *solid, *builder ); test_clone( *solid ); diff --git a/tests/mesh/test-triangulated-surface.cpp b/tests/mesh/test-triangulated-surface.cpp index a7469abb5..e06072701 100644 --- a/tests/mesh/test-triangulated-surface.cpp +++ b/tests/mesh/test-triangulated-surface.cpp @@ -225,6 +225,11 @@ void test_io( { geode::save_triangulated_surface( surface, filename ); const auto relaod = geode::load_triangulated_surface< 3 >( filename ); + const auto point_attributes = + relaod->vertex_attribute_manager().attribute_ids_matching_name( + "points" ); + geode::OpenGeodeMeshException::test( point_attributes.has_value(), + "TriangulatedSurface should have points attribute" ); geode_unused( relaod ); const auto surface2 = geode::load_triangulated_surface< 3 >( geode::OpenGeodeTriangulatedSurface3D::impl_name_static(), filename ); @@ -237,17 +242,72 @@ void test_io( } } +void test_backward_io( const std::string& filename ) +{ + const auto surface = geode::load_triangulated_surface< 3 >( filename ); + geode::OpenGeodeMeshException::test( surface->nb_vertices() == 5, + "Backward TriangulatedSurface should have 5 vertices" ); + geode::OpenGeodeMeshException::test( surface->nb_polygons() == 3, + "Backward TriangulatedSurface should have 3 polygons" ); + geode::OpenGeodeMeshException::test( + surface->point( 0 ) == geode::Point3D{ { 0.1, 0.2, 0.3 } }, + "Backward TriangulatedSurface should have point ( 0.1, 0.2, 0.3 ) at " + "index 0" ); + geode::OpenGeodeMeshException::test( + surface->polygon_adjacent( { 0, 1 } ) == 1, + "TriangulatedSurface adjacent index is not correct" ); + geode::OpenGeodeMeshException::test( surface->edges().nb_edges() == 7, + "Backward TriangulatedSurface should have 7 edges" ); + geode::OpenGeodeMeshException::test( + surface->polygon_around_vertex( 0 ).value().polygon_id == 0, + "Wrong polygon_around_vertex for backward triangulated surface" ); + geode::OpenGeodeMeshException::test( + surface->polygons_around_vertex( 0 ).size() == 1, + "Wrong polygons_around_vertex for backward triangulated surface" ); +} void test_clone( const geode::TriangulatedSurface3D& surface ) { - auto attr_from = surface.edges() - .edge_attribute_manager() - .find_or_create_attribute< geode::VariableAttribute, - geode::index_t >( "edge_id", 0 ); + auto attr_from_id = + surface.edges() + .edge_attribute_manager() + .create_attribute< geode::VariableAttribute, geode::index_t >( + "edge_id", 0, geode::AttributeProperties{} ); + auto attr_from = + surface.edges() + .edge_attribute_manager() + .find_attribute< geode::VariableAttribute, geode::index_t >( + attr_from_id ); for( const auto e : geode::Range{ surface.edges().nb_edges() } ) { attr_from->set_value( e, e ); } auto surface_clone = surface.clone(); + for( const auto v : geode::Range{ surface_clone->nb_vertices() } ) + { + geode::OpenGeodeMeshException::test( + surface.polygons_around_vertex( v ) + == surface_clone->polygons_around_vertex( v ), + "Polyhedra around vertex should match during cloning" ); + } + for( const auto v : geode::Range{ surface_clone->nb_vertices() } ) + { + geode::OpenGeodeMeshException::test( + surface_clone->point( v ) == surface.point( v ), + "Wrong cloned mesh point coordinates." ); + } + for( const auto p : geode::Range{ surface_clone->nb_polygons() } ) + { + for( const auto e : geode::LRange{ 3 } ) + { + for( const auto v : geode::LRange{ 2 } ) + { + geode::OpenGeodeMeshException::test( + surface_clone->polygon_edge_vertex( { p, e }, v ) + == surface.polygon_edge_vertex( { p, e }, v ), + "polyhedron_facet_vertex should match" ); + } + } + } geode::OpenGeodeTriangulatedSurface3D surface2{ std::move( *dynamic_cast< geode::OpenGeodeTriangulatedSurface3D* >( surface_clone.get() ) ) }; @@ -257,9 +317,10 @@ void test_clone( const geode::TriangulatedSurface3D& surface ) "TriangulatedSurface2 should have 5 edges" ); geode::OpenGeodeMeshException::test( surface2.nb_polygons() == 2, "TriangulatedSurface2 should have 2 polygons" ); - auto attr_to = surface2.edges() - .edge_attribute_manager() - .find_attribute< geode::index_t >( "edge_id" ); + auto attr_to = + surface2.edges() + .edge_attribute_manager() + .find_read_only_attribute< geode::index_t >( attr_from_id ); for( const auto e : geode::Range{ surface.edges().nb_edges() } ) { geode::OpenGeodeMeshException::test( @@ -315,7 +376,8 @@ void test() test_create_polygons( *surface, *builder ); test_polygon_adjacencies( *surface, *builder ); test_io( *surface, absl::StrCat( "test.", surface->native_extension() ) ); - + test_backward_io( absl::StrCat( geode::DATA_PATH, "backward_io/v17/v17.", + surface->native_extension() ) ); test_permutation( *surface, *builder ); test_delete_polygon( *surface, *builder ); test_clone( *surface ); diff --git a/tests/model/test-brep.cpp b/tests/model/test-brep.cpp index 7dba368c2..af474aa33 100644 --- a/tests/model/test-brep.cpp +++ b/tests/model/test-brep.cpp @@ -66,7 +66,6 @@ std::array< geode::uuid, 6 > add_corners( { uuids[c] = builder.add_corner(); builder.set_corner_name( uuids[c], absl::StrCat( "corner", c + 1 ) ); - SDEBUG( uuids[c] ); } const auto& temp_corner = model.corner( builder.add_corner( geode::OpenGeodePointSet3D::impl_name_static() ) ); @@ -164,11 +163,9 @@ geode::uuid add_block( const geode::BRep& model, geode::BRepBuilder& builder ) geode::detail::count_range_elements( model.blocks() ) == 1, message ); geode::OpenGeodeModelException::test( model.block( block_uuid ).name() == "block1", "Wrong Block name" ); - DEBUG( model.nb_active_blocks() ); geode::OpenGeodeModelException::test( model.nb_active_blocks() == 1, message ); builder.set_block_active( block_uuid, false ); - DEBUG( model.nb_active_blocks() ); geode::OpenGeodeModelException::test( model.nb_active_blocks() == 0, "BRep should have 0 active block" ); geode::OpenGeodeModelException::test( @@ -1223,7 +1220,7 @@ void test_clone( const geode::BRep& brep ) brep2.nb_blocks() == 2, "BRep should have 2 blocks" ); geode::OpenGeodeModelException::test( brep2.nb_model_boundaries() == 6, "BRep should have 6 model boundaries" ); - + DEBUG( "test_clone" ); for( const auto& corner : brep.corners() ) { const auto& new_corner = brep2.corner( @@ -1290,6 +1287,22 @@ void test_clone( const geode::BRep& brep ) found, "All Surfaces incidences are not correct" ); } } + DEBUG( brep2.nb_blocks() ); + for( const auto& block : brep2.blocks() ) + { + const auto& block_mesh = block.mesh(); + DEBUG( block_mesh.nb_polyhedra() ); + for( const auto p : geode::Range{ block_mesh.nb_polyhedra() } ) + { + DEBUG( p ); + for( const auto v : + geode::LRange{ block_mesh.nb_polyhedron_vertices( p ) } ) + { + DEBUG( v ); + DEBUG( block_mesh.polyhedron_vertex( { p, v } ) ); + } + } + } for( const auto& model_boundary : brep.model_boundaries() ) { const auto& new_model_boundary = brep2.model_boundary( @@ -1465,8 +1478,9 @@ void test_registry( const geode::BRep& brep, void test_backward_io() { - const auto brep = geode::load_brep( + auto brep = geode::load_brep( absl::StrCat( geode::DATA_PATH, "dangling.og_brep" ) ); + geode::BRepBuilder brep_builder{ brep }; for( const auto& block : brep.blocks() ) { geode::OpenGeodeModelException::test( block.id() == block.mesh().id(), @@ -1490,7 +1504,55 @@ void test_backward_io() "[Backward_IO] Brep corner should have the same uuid as its " "mesh." ); } + for( const auto& surface : brep.surfaces() ) + { + auto vertex_index = + brep_builder.surface_mesh_builder( surface.id() )->create_vertex(); + DEBUG( vertex_index ); + DEBUG( brep.unique_vertex( { surface.component_id(), vertex_index } ) ); + geode::OpenGeodeModelException::test( + brep.unique_vertex( { surface.component_id(), vertex_index } ) + == geode::NO_ID, + "[Backward_IO] Incorrect brep unique_vertex_id." ); + } test_registry( brep, 4, 13, 17, 7, 1, 0, 0, 0, 0, 0, 0 ); + auto brep_v17 = geode::load_brep( + absl::StrCat( geode::DATA_PATH, "backward_io/v17/v17.og_brep" ) ); + geode::BRepBuilder brep_builder_v17{ brep_v17 }; + for( const auto& block : brep_v17.blocks() ) + { + geode::OpenGeodeModelException::test( block.id() == block.mesh().id(), + "[Backward_IO] Brep block should have the same uuid as its mesh." ); + } + for( const auto& surface : brep_v17.surfaces() ) + { + geode::OpenGeodeModelException::test( + surface.id() == surface.mesh().id(), + "[Backward_IO] Brep surface should have the same uuid as its " + "mesh." ); + } + for( const auto& line : brep_v17.lines() ) + { + geode::OpenGeodeModelException::test( line.id() == line.mesh().id(), + "[Backward_IO] Brep line should have the same uuid as its mesh." ); + } + for( const auto& corner : brep_v17.corners() ) + { + geode::OpenGeodeModelException::test( corner.id() == corner.mesh().id(), + "[Backward_IO] Brep corner should have the same uuid as its " + "mesh." ); + } + for( const auto& surface : brep_v17.surfaces() ) + { + auto vertex_index = + brep_builder_v17.surface_mesh_builder( surface.id() ) + ->create_vertex(); + geode::OpenGeodeModelException::test( + brep_v17.unique_vertex( { surface.component_id(), vertex_index } ) + == geode::NO_ID, + "[Backward_IO] Incorrect brep unique_vertex_id." ); + } + test_registry( brep_v17, 4, 6, 9, 5, 1, 5, 2, 2, 2, 1, 3 ); } void test_components_filter() @@ -1584,11 +1646,24 @@ void test() test_block_collection_ranges( model, block_uuid, block_collection_uuid ); test_clone( model ); test_steal_mesh( model ); - + DEBUG( "io" ); const auto file_io = absl::StrCat( "test.", model.native_extension() ); geode::save_brep( model, file_io ); - + DEBUG( "start load" ); auto model2 = geode::load_brep( file_io ); + geode::BRepBuilder model2_builder{ model2 }; + for( const auto& surface : model2.surfaces() ) + { + auto vertex_index = model2_builder.surface_mesh_builder( surface.id() ) + ->create_vertex(); + DEBUG( vertex_index ); + DEBUG( + model2.unique_vertex( { surface.component_id(), vertex_index } ) ); + geode::OpenGeodeModelException::test( + model2.unique_vertex( { surface.component_id(), vertex_index } ) + == geode::NO_ID, + "[Backward_IO] Incorrect model2 unique_vertex_id." ); + } test_compare_brep( model, model2 ); test_registry( model2, 4, 6, 9, 5, 1, 5, 2, 2, 2, 1, 3 ); diff --git a/tests/model/test-convert-brep.cpp b/tests/model/test-convert-brep.cpp index a2ff52c2d..b5b32aab2 100644 --- a/tests/model/test-convert-brep.cpp +++ b/tests/model/test-convert-brep.cpp @@ -38,14 +38,12 @@ void test_convert_brep_section() absl::StrCat( geode::DATA_PATH, "random_dfn.og_brep" ) ); const auto section = std::get< 0 >( geode::convert_brep_into_section( brep, 2 ) ); - geode::OpenGeodeModelException::test( section.nb_corners() == 172, "Section should have 172 corners" ); geode::OpenGeodeModelException::test( section.nb_lines() == 288, "Section should have 288 lines" ); geode::OpenGeodeModelException::test( section.nb_surfaces() == 117, "Section should have 117 surfaces" ); - const auto brep2 = std::get< 0 >( geode::convert_section_into_brep( section, 2, 10. ) ); diff --git a/tests/model/test-relationships.cpp b/tests/model/test-relationships.cpp index 2ad692153..35753cfd7 100644 --- a/tests/model/test-relationships.cpp +++ b/tests/model/test-relationships.cpp @@ -167,10 +167,13 @@ void test_attributes( const geode::Relationships& relations, geode::OpenGeodeModelException::test( std::get< 1 >( output ).id() == uuids[0], "Wrong relation uuids from index" ); - auto relation_att = + auto relation_att_id = relations.relation_attribute_manager() - .find_or_create_attribute< geode::VariableAttribute, int >( - "int", 0 ); + .create_attribute< geode::VariableAttribute, int >( + "int", 0, geode::AttributeProperties{} ); + const auto relation_att = + relations.relation_attribute_manager() + .find_attribute< geode::VariableAttribute, int >( relation_att_id ); relation_att->set_value( 0, 1 ); geode::OpenGeodeModelException::test( relation_att->value( @@ -209,7 +212,6 @@ void test() add_items_in_collections( relationships, uuids ); test_relations( relationships, uuids ); test_attributes( relationships, uuids ); - relationships.save_relationships( "." ); test_io( absl::StrCat( geode::DATA_PATH, "relationships_v12" ), uuids ); test_io( ".", uuids ); diff --git a/tests/model/test-section.cpp b/tests/model/test-section.cpp index 8fa565e89..37b8e0bd0 100644 --- a/tests/model/test-section.cpp +++ b/tests/model/test-section.cpp @@ -1018,7 +1018,8 @@ void test() const auto file_io = absl::StrCat( "test.", model.native_extension() ); geode::save_section( model, file_io ); - + auto backward_model = geode::load_section( absl::StrCat( + geode::DATA_PATH, "backward_io/v17/v17.", model.native_extension() ) ); auto model2 = geode::load_section( file_io ); test_compare_section( model, model2 );