diff --git a/bindings/python/src/basic/attribute.cpp b/bindings/python/src/basic/attribute.cpp index 1c68ac9dd..6a8273057 100644 --- a/bindings/python/src/basic/attribute.cpp +++ b/bindings/python/src/basic/attribute.cpp @@ -53,23 +53,47 @@ namespace geode std::shared_ptr< VariableAttribute< type > > >( module, variable_name.c_str() ) .def( "set_value", &VariableAttribute< type >::set_value ) - .def( "default_value", &VariableAttribute< type >::default_value ); + .def( + "default_values", &VariableAttribute< type >::default_values ); const auto sparse_name = absl::StrCat( "SparseAttribute", typestr ); pybind11::class_< SparseAttribute< type >, ReadOnlyAttribute< type >, std::shared_ptr< SparseAttribute< type > > >( module, sparse_name.c_str() ) .def( "set_value", &SparseAttribute< type >::set_value ) - .def( "default_value", &SparseAttribute< type >::default_value ); + .def( "default_values", &SparseAttribute< type >::default_values ); + } + + template < typename type > + void python_attribute_values_class( + pybind11::module& module, const std::string& typestr ) + { + const auto values_name = absl::StrCat( "AttributeValues", typestr ); + pybind11::class_< AttributeValues< type > >( + module, values_name.c_str() ) + .def( pybind11::init<>() ) + .def_readwrite( + "default_value", &AttributeValues< type >::default_value ) + .def_readwrite( "no_value", &AttributeValues< type >::no_value ); } void define_attributes( pybind11::module& module ) { pybind11::class_< AttributeProperties >( module, "AttributeProperties" ) .def( pybind11::init<>() ) - .def( pybind11::init< bool, bool >() ) .def_readwrite( "assignable", &AttributeProperties::assignable ) + .def_readwrite( "interpolable", &AttributeProperties::interpolable ) .def_readwrite( - "interpolable", &AttributeProperties::interpolable ); + "transferable", &AttributeProperties::transferable ); + + python_attribute_values_class< bool >( module, "Bool" ); + python_attribute_values_class< int >( module, "Int" ); + python_attribute_values_class< unsigned int >( module, "UInt" ); + python_attribute_values_class< float >( module, "Float" ); + python_attribute_values_class< double >( module, "Double" ); + python_attribute_values_class< std::array< double, 2 > >( + module, "ArrayDouble2" ); + python_attribute_values_class< std::array< double, 3 > >( + module, "ArrayDouble3" ); pybind11::class_< AttributeBase, std::shared_ptr< AttributeBase > >( module, "AttributeBase" ) diff --git a/bindings/python/src/basic/attribute_manager.cpp b/bindings/python/src/basic/attribute_manager.cpp index 9957236ec..f58758da2 100644 --- a/bindings/python/src/basic/attribute_manager.cpp +++ b/bindings/python/src/basic/attribute_manager.cpp @@ -36,30 +36,66 @@ 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, + AttributeValues< type >, AttributeProperties ) >( + &AttributeManager::create_attribute< ConstantAttribute, + type > ) ); + manager.def( create_constant_suffix.c_str(), + static_cast< void ( AttributeManager::* )( std::string_view, + const uuid&, AttributeValues< 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, + AttributeValues< type >, AttributeProperties ) >( + &AttributeManager::create_attribute< VariableAttribute, + type > ) ); + manager.def( create_variable_suffix.c_str(), + static_cast< void ( AttributeManager::* )( std::string_view, + const uuid&, AttributeValues< 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, + AttributeValues< type >, AttributeProperties ) >( + &AttributeManager::create_attribute< SparseAttribute, + type > ) ); + manager.def( create_sparse_suffix.c_str(), + static_cast< void ( AttributeManager::* )( std::string_view, + const uuid&, AttributeValues< 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 +105,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 +116,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/src/geometry/sign.cpp b/bindings/python/src/geometry/sign.cpp index 0a0b91124..8e1f6d97f 100644 --- a/bindings/python/src/geometry/sign.cpp +++ b/bindings/python/src/geometry/sign.cpp @@ -34,10 +34,10 @@ namespace geode { module.def( "tetrahedron_volume_sign", &tetrahedron_volume_sign ); module.def( "triangle_area_sign2D", - static_cast< Sign ( * )( const Triangle2D& ) >( + static_cast< SIGN ( * )( const Triangle2D& ) >( &triangle_area_sign ) ); module.def( "triangle_area_sign3D", - static_cast< Sign ( * )( const Triangle3D&, local_index_t ) >( + static_cast< SIGN ( * )( const Triangle3D&, local_index_t ) >( &triangle_area_sign ) ); } } // namespace geode diff --git a/bindings/python/tests/basic/test-py-attribute.py b/bindings/python/tests/basic/test-py-attribute.py index 672290471..3fba29304 100644 --- a/bindings/python/tests/basic/test-py-attribute.py +++ b/bindings/python/tests/basic/test-py-attribute.py @@ -30,61 +30,108 @@ def test_constant_attribute(manager): - constant_attribute = manager.find_or_create_attribute_constant_bool( - "bool", True) - - attribute = manager.find_attribute_bool("bool") + + properties = basic.AttributeProperties() + properties.assignable = False + properties.interpolable = False + properties.transferable = True + values = basic.AttributeValuesBool() + values.default_value = True + values.no_value = False + constant_attribute_id = manager.create_attribute_constant_bool( + "bool", values, properties) + 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) + + properties = basic.AttributeProperties() + properties.assignable = False + properties.interpolable = False + properties.transferable = True + values = basic.AttributeValuesInt() + values.default_value = 12 + values.no_value = 12 + variable_attribute_id = manager.create_attribute_variable_int( + "int", values, properties) + 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") + + new_properties = basic.AttributeProperties() + new_properties.assignable = True + new_properties.interpolable = True + properties.transferable = True + manager.set_attribute_properties(variable_attribute_id,new_properties) - manager.set_attribute_properties("int",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) - attribute = manager.find_attribute_double("double") + properties = basic.AttributeProperties() + properties.assignable = False + properties.interpolable = False + properties.transferable = True + values = basic.AttributeValuesDouble() + values.default_value = 12 + values.no_value = 12 + sparse_attribute_id = manager.create_attribute_sparse_double( + "double", values,properties) + attribute = manager.find_attribute_sparse_double(sparse_attribute_id) + attribute.set_value(3, 3) + attribute.set_value(7, 7) + + 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 +146,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 +161,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..e3dfaa44a 100644 --- a/bindings/python/tests/mesh/test-py-edged-curve.py +++ b/bindings/python/tests/mesh/test-py-edged-curve.py @@ -123,8 +123,18 @@ 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) + + properties = opengeode_py_basic.AttributeProperties() + properties.assignable = False + properties.interpolable = False + properties.transferable = True + values = opengeode_py_basic.AttributeValuesInt() + values.default_value = 0 + values.no_value = 0 + attribute_id = edged_curve.edge_attribute_manager( + ).create_attribute_variable_int("test", values,properties) + + attribute = edged_curve.edge_attribute_manager().find_attribute_variable_int(attribute_id) attribute.set_value(0, 42) edged_curve2 = edged_curve.clone() @@ -133,7 +143,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..26195076e 100644 --- a/bindings/python/tests/mesh/test-py-gradient-computation.py +++ b/bindings/python/tests/mesh/test-py-gradient-computation.py @@ -35,7 +35,15 @@ 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 ) + properties = opengeode_py_basic.AttributeProperties() + properties.assignable = False + properties.interpolable = False + properties.transferable = True + values = opengeode_py_basic.AttributeValuesDouble() + values.default_value = 0 + values.no_value = 0 + attribute_id = grid.vertex_attribute_manager().create_attribute_variable_double( scalar_function_name, values,properties ) + 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 +58,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 +88,15 @@ 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 ) + properties = opengeode_py_basic.AttributeProperties() + properties.assignable = False + properties.interpolable = False + properties.transferable = True + values = opengeode_py_basic.AttributeValuesDouble() + values.default_value = 0 + values.no_value = 0 + attribute_id = surface.vertex_attribute_manager().create_attribute_variable_double( scalar_function_name, values,properties ) + 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 +105,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 +114,15 @@ 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 ) + properties = opengeode_py_basic.AttributeProperties() + properties.assignable = False + properties.interpolable = False + properties.transferable = True + values = opengeode_py_basic.AttributeValuesDouble() + values.default_value = 0 + values.no_value = 0 + attribute_id = grid.vertex_attribute_manager().create_attribute_variable_double( scalar_function_name, values,properties ) + 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 +149,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..5ea9f5d20 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,36 @@ def test_closest_vertex(grid): def test_attribute_3d(grid): - attribute = grid.cell_attribute_manager().find_or_create_attribute_variable_double( - "toto", -1 + properties = geode.AttributeProperties() + properties.assignable = False + properties.interpolable = False + properties.transferable = True + first_values = geode.AttributeValuesDouble() + first_values.default_value = -1 + first_values.no_value = -1 + attribute_id = grid.cell_attribute_manager().create_attribute_variable_double( + "toto", first_values,properties ) + 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 + second_values = geode.AttributeValuesDouble() + second_values.default_value = 1 + second_values.no_value = 1 + attribute_id = ( + grid.grid_vertex_attribute_manager().create_attribute_variable_double( + "toto_vertex", second_values,properties ) ) + 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 +328,36 @@ 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 + properties = geode.AttributeProperties() + properties.assignable = False + properties.interpolable = False + properties.transferable = True + first_values = geode.AttributeValuesDouble() + first_values.default_value = -1 + first_values.no_value = -1 + attribute_id = grid.cell_attribute_manager().create_attribute_variable_double( + "toto", first_values,properties ) + 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 + second_values = geode.AttributeValuesDouble() + second_values.default_value = 1 + second_values.no_value = 1 + attribute_id = ( + grid.grid_vertex_attribute_manager().create_attribute_variable_double( + "toto_vertex",second_values,properties ) ) + 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..d26e1f433 100644 --- a/bindings/python/tests/mesh/test-py-point-set.py +++ b/bindings/python/tests/mesh/test-py-point-set.py @@ -58,10 +58,19 @@ 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) + properties = opengeode_py_basic.AttributeProperties() + properties.assignable = False + properties.interpolable = False + properties.transferable = True + values = opengeode_py_basic.AttributeValuesBool() + values.default_value = True + values.no_value = True + attribute_id = point_set.vertex_attribute_manager( + ).create_attribute_constant_bool("test", values,properties) + 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 +89,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 +119,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..f6d250451 100644 --- a/bindings/python/tests/mesh/test-py-polygonal-surface.py +++ b/bindings/python/tests/mesh/test-py-polygonal-surface.py @@ -66,10 +66,20 @@ def test_create_polygons(polygonal_surface, builder): def test_create_edge_attribute(polygonal_surface): + properties = basic.AttributeProperties() + properties.assignable = False + properties.interpolable = False + properties.transferable = True + values = basic.AttributeValuesUInt() + values.default_value = basic.NO_ID + values.no_value = basic.NO_ID + attribute_id = polygonal_surface.edges().edge_attribute_manager( + ).create_attribute_variable_uint("test", values,properties) 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 +123,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 +143,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 +214,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 +228,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 +375,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 +384,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..ab48fd27c 100644 --- a/bindings/python/tests/mesh/test-py-polyhedral-solid.py +++ b/bindings/python/tests/mesh/test-py-polyhedral-solid.py @@ -72,15 +72,34 @@ def test_create_polyhedra(polyhedral_solid, builder): def test_create_facet_attribute(polyhedral_solid): + properties = basic.AttributeProperties() + properties.assignable = False + properties.interpolable = False + properties.transferable = True + values = basic.AttributeValuesUInt() + values.default_value = basic.NO_ID + values.no_value = basic.NO_ID + attribute_id = polyhedral_solid.facets().facet_attribute_manager( + ).create_attribute_variable_uint("test", values, properties) 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): + properties = basic.AttributeProperties() + properties.assignable = False + properties.interpolable = False + properties.transferable = True + values = basic.AttributeValuesUInt() + values.default_value = basic.NO_ID + values.no_value = basic.NO_ID + attribute_id = polyhedral_solid.edges().edge_attribute_manager( + ).create_attribute_variable_uint("test", values, properties) 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 +107,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 +155,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 +180,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 +189,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 +206,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 +424,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..2db6c61ad 100644 --- a/bindings/python/tests/mesh/test-py-regular-grid.py +++ b/bindings/python/tests/mesh/test-py-regular-grid.py @@ -246,16 +246,32 @@ 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 + properties = geode.AttributeProperties() + properties.assignable = False + properties.interpolable = False + properties.transferable = True + int_values = geode.AttributeValuesInt() + int_values.default_value = 0 + int_values.no_value = 0 + attribute_id = ( + grid.polyhedron_attribute_manager().create_attribute_variable_int( + attribute_name, int_values, properties ) ) - 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 + ) + double_values = geode.AttributeValuesDouble() + double_values.default_value = 0 + double_values.no_value = 0 + attribute_d_id = ( + grid.vertex_attribute_manager().create_attribute_variable_double( + attribute_name_d, double_values,properties ) ) + 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 +279,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..b29d69b6d 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,10 +70,7 @@ namespace geode [[nodiscard]] virtual std::string_view type() = 0; - [[nodiscard]] std::string_view name() const - { - return name_; - } + [[nodiscard]] virtual bool has_value( index_t element ) const = 0; [[nodiscard]] const AttributeProperties& properties() const { @@ -85,11 +83,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 +140,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_; }; /*! @@ -175,6 +174,8 @@ namespace geode public: [[nodiscard]] virtual const T& value( index_t element ) const = 0; + [[nodiscard]] bool has_value( index_t element ) const override = 0; + [[nodiscard]] std::string_view type() final { return typeid( T ).name(); @@ -204,8 +205,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..35df569ae 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, - T default_value, + [[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, + AttributeValues< T > default_values, 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_values ), 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, + AttributeValues< T > default_values, + 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_values ), 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; + const geode::uuid& ) const; - void rename_attribute( - std::string_view old_name, std::string_view new_name ); - - void set_attribute_properties( std::string_view attribute_name, + void set_attribute_properties( geode::uuid attribute_id, const AttributeProperties& new_properties ); /*! @@ -255,6 +247,9 @@ namespace geode */ [[nodiscard]] index_t nb_elements() 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 +257,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 +274,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/attribute_utils.hpp b/include/geode/basic/attribute_utils.hpp index f961ed6a9..14d56e452 100644 --- a/include/geode/basic/attribute_utils.hpp +++ b/include/geode/basic/attribute_utils.hpp @@ -45,19 +45,6 @@ namespace geode { AttributeProperties() = default; - AttributeProperties( bool is_assignable, bool is_interpolable ) - : assignable( is_assignable ), interpolable( is_interpolable ) - { - } - - AttributeProperties( - bool is_assignable, bool is_interpolable, bool is_transferable ) - : assignable( is_assignable ), - interpolable( is_interpolable ), - transferable( is_transferable ) - { - } - template < typename Archive > void serialize( Archive& serializer ) { @@ -80,6 +67,26 @@ namespace geode bool transferable{ true }; }; + template < typename AttributeType > + struct AttributeValues + { + AttributeValues() = default; + + template < typename Archive > + void serialize( Archive& serializer ) + { + serializer.ext( + *this, Growable< Archive, AttributeValues >{ + { []( Archive& archive, AttributeValues& values ) { + archive( values.default_value ); + archive( values.no_value ); + } } } ); + } + + AttributeType default_value; + AttributeType no_value; + }; + /*! * Helper struct to interpolate an Attribute value. * This struct may be customized for a given type. @@ -105,7 +112,7 @@ namespace geode const AttributeLinearInterpolation& /*unused*/, const Attribute< AttributeType >& attribute ) { - return attribute.default_value(); + return attribute.default_values().default_value; } }; 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/cached_value.hpp b/include/geode/basic/cached_value.hpp index f17648c8a..8ca0b32c0 100644 --- a/include/geode/basic/cached_value.hpp +++ b/include/geode/basic/cached_value.hpp @@ -84,6 +84,15 @@ namespace geode return value_; } + bool operator==( const CachedValue& other ) const + { + if( computed() && other.computed() ) + { + return value() == other.value(); + } + return false; + } + bool operator!=( const CachedValue& other ) const { if( computed() && other.computed() ) diff --git a/include/geode/basic/console_logger_client.hpp b/include/geode/basic/console_logger_client.hpp index f12df673d..c2bd25215 100644 --- a/include/geode/basic/console_logger_client.hpp +++ b/include/geode/basic/console_logger_client.hpp @@ -42,7 +42,7 @@ namespace geode void info( const std::string &message ) override; - void warn( const std::string &message ) override; + void warning( const std::string &message ) override; void error( const std::string &message ) override; diff --git a/include/geode/basic/constant_attribute.hpp b/include/geode/basic/constant_attribute.hpp index c57ee08b2..acbd5c898 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 @@ -55,10 +56,13 @@ namespace geode friend class bitsery::Access; public: - ConstantAttribute( T value, + ConstantAttribute( AttributeValues< T > values, + std::string_view name, AttributeProperties properties, AttributeBase::AttributeKey /*key*/ ) - : ConstantAttribute( std::move( value ), std::move( properties ) ) + : ConstantAttribute( std::move( values.default_value ), + name, + std::move( properties ) ) { } @@ -67,6 +71,11 @@ namespace geode return value_; } + [[nodiscard]] bool has_value( index_t /*unused*/ ) const override + { + return true; + } + [[nodiscard]] const T& value() const { return value_; @@ -102,14 +111,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 +163,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 +185,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 +197,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/factory.hpp b/include/geode/basic/factory.hpp index 5eca709a9..6bd4ee738 100644 --- a/include/geode/basic/factory.hpp +++ b/include/geode/basic/factory.hpp @@ -82,7 +82,7 @@ namespace geode Creator( create_function_impl< DerivedClass > ) ) .second ) { - Logger::warn( + Logger::warning( "Factory: Trying to register twice the same key" ); } } diff --git a/include/geode/basic/file_logger_client.hpp b/include/geode/basic/file_logger_client.hpp index 53f9a5f2e..a3d33a206 100644 --- a/include/geode/basic/file_logger_client.hpp +++ b/include/geode/basic/file_logger_client.hpp @@ -48,7 +48,7 @@ namespace geode void info( const std::string &message ) override; - void warn( const std::string &message ) override; + void warning( const std::string &message ) override; void error( const std::string &message ) override; 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/identifier.hpp b/include/geode/basic/identifier.hpp index 1524f1ffa..7346175cf 100644 --- a/include/geode/basic/identifier.hpp +++ b/include/geode/basic/identifier.hpp @@ -44,10 +44,11 @@ namespace geode { class opengeode_basic_api Identifier { - PASSKEY( IdentifierBuilder, IdentifierKey /*key*/ ); friend class bitsery::Access; public: + PASSKEY( IdentifierBuilder, IdentifierKey /*key*/ ); + Identifier( Identifier&& other ) noexcept; ~Identifier(); diff --git a/include/geode/basic/input.hpp b/include/geode/basic/input.hpp index 8fb46c363..6ab4e7c18 100644 --- a/include/geode/basic/input.hpp +++ b/include/geode/basic/input.hpp @@ -78,7 +78,7 @@ namespace geode { if( inspect_required_ ) { - geode::Logger::warn( + geode::Logger::warning( "[Input] The file loader notified INCONSISTENCIES in the " "given data file. In consequence, the loaded structure is " "likely BROKEN, and there is NO GUARANTEE that any further " diff --git a/include/geode/basic/logger.hpp b/include/geode/basic/logger.hpp index 8e86ddcc1..d9a857031 100644 --- a/include/geode/basic/logger.hpp +++ b/include/geode/basic/logger.hpp @@ -36,7 +36,7 @@ namespace geode /*! * Custom OpenGeode logger. Can be used with several levels: * Logger::info( "My information is ", 42 ); - * Logger::warn( "My warning is ", 42, " or more" ); + * Logger::warning( "My warning is ", 42, " or more" ); */ class opengeode_basic_api Logger { @@ -46,8 +46,8 @@ namespace geode trace, debug, info, - warn, - err, + warning, + error, critical, off }; @@ -81,7 +81,7 @@ namespace geode } template < typename... Args > - static void warn( const Args &...args ) + static void warning( const Args &...args ) { log_warn( absl::StrCat( args... ) ); } diff --git a/include/geode/basic/logger_client.hpp b/include/geode/basic/logger_client.hpp index 6aa57bd7c..83d80cc54 100644 --- a/include/geode/basic/logger_client.hpp +++ b/include/geode/basic/logger_client.hpp @@ -38,7 +38,7 @@ namespace geode virtual void info( const std::string &message ) = 0; - virtual void warn( const std::string &message ) = 0; + virtual void warning( const std::string &message ) = 0; virtual void error( const std::string &message ) = 0; diff --git a/include/geode/basic/logger_manager.hpp b/include/geode/basic/logger_manager.hpp index bbc9af305..aac00421a 100644 --- a/include/geode/basic/logger_manager.hpp +++ b/include/geode/basic/logger_manager.hpp @@ -47,7 +47,7 @@ namespace geode static void info( const std::string &message ); - static void warn( const std::string &message ); + static void warning( const std::string &message ); static void error( const std::string &message ); diff --git a/include/geode/basic/passkey.hpp b/include/geode/basic/passkey.hpp index 7f6912f35..b39c63364 100644 --- a/include/geode/basic/passkey.hpp +++ b/include/geode/basic/passkey.hpp @@ -57,7 +57,7 @@ namespace geode friend T; private: - PassKey() = default; + explicit PassKey() = default; }; #define PASSKEY( Friend, Key /*key*/ ) using Key = geode::PassKey< Friend > diff --git a/include/geode/basic/sparse_attribute.hpp b/include/geode/basic/sparse_attribute.hpp index b9449d551..304e8b20e 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 @@ -62,11 +63,12 @@ namespace geode friend class bitsery::Access; public: - SparseAttribute( T default_value, + SparseAttribute( AttributeValues< T > default_values, + std::string_view name, AttributeProperties properties, AttributeBase::AttributeKey /*key*/ ) : SparseAttribute( - std::move( default_value ), std::move( properties ) ) + std::move( default_values ), name, std::move( properties ) ) { } @@ -77,7 +79,16 @@ namespace geode { return value_it->second; } - return default_value_; + return default_values_.default_value; + } + + [[nodiscard]] bool has_value( index_t element ) const override + { + if( value( element ) == default_values_.no_value ) + { + return false; + } + return true; } void set_value( index_t element, T value ) @@ -85,15 +96,16 @@ namespace geode values_[element] = std::move( value ); } - [[nodiscard]] const T& default_value() const + [[nodiscard]] const AttributeValues< T >& default_values() const { - return default_value_; + return default_values_; } template < typename Modifier > void modify_value( index_t element, Modifier modifier ) { - auto [value_it, _] = values_.emplace( element, default_value_ ); + auto [value_it, _] = + values_.emplace( element, default_values_.default_value ); modifier( value_it->second ); } @@ -113,14 +125,24 @@ namespace geode } private: - SparseAttribute( T default_value, AttributeProperties properties ) - : ReadOnlyAttribute< T >( std::move( properties ) ), - default_value_( std::move( default_value ) ) + SparseAttribute( AttributeValues< T > default_values, + std::string_view name, + AttributeProperties properties ) + : ReadOnlyAttribute< T >( name, std::move( properties ) ), + default_values_( std::move( default_values ) ) { 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 ) @@ -128,18 +150,36 @@ namespace geode serializer.ext( *this, Growable< Archive, SparseAttribute< T > >{ { []( Archive& archive, SparseAttribute< T >& attribute ) { - archive.ext( - attribute, bitsery::ext::BaseClass< - ReadOnlyAttribute< T > >{} ); - archive( attribute.default_value_ ); - archive.ext( attribute.values_, - bitsery::ext::StdMap{ - attribute.values_.max_size() }, - []( Archive& archive2, index_t& i, T& item ) { - archive2.value4b( i ); - archive2( item ); - } ); - } } } ); + archive.ext( + attribute, bitsery::ext::BaseClass< + ReadOnlyAttribute< T > >{} ); + T old_default_value; + archive( old_default_value ); + attribute.default_values_.default_value = + old_default_value; + attribute.default_values_.no_value = old_default_value; + archive.ext( attribute.values_, + bitsery::ext::StdMap{ + attribute.values_.max_size() }, + []( Archive& archive2, index_t& i, T& item ) { + archive2.value4b( i ); + archive2( item ); + } ); + }, + []( Archive& archive, + SparseAttribute< T >& attribute ) { + archive.ext( + attribute, bitsery::ext::BaseClass< + ReadOnlyAttribute< T > >{} ); + archive( attribute.default_values_ ); + archive.ext( attribute.values_, + bitsery::ext::StdMap{ + attribute.values_.max_size() }, + []( Archive& archive2, index_t& i, T& item ) { + archive2.value4b( i ); + archive2( item ); + } ); + } } } ); values_.reserve( 10 ); } @@ -163,7 +203,8 @@ namespace geode values_.reserve( old_values.size() ); for( auto& [index, value] : old_values ) { - if( !to_delete[index] && value != default_value_ ) + if( !to_delete[index] + && value != default_values_.default_value ) { values_.emplace( old2new[index], std::move( value ) ); } @@ -186,8 +227,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_values_, this->name().value(), this->properties() } }; + IdentifierBuilder builder{ *attribute }; + builder.set_id( this->id() ); attribute->values_ = values_; return attribute; } @@ -198,12 +242,13 @@ namespace geode { const auto& typed_attribute = dynamic_cast< const SparseAttribute< T >& >( attribute ); - default_value_ = typed_attribute.default_value_; + default_values_ = typed_attribute.default_values_; if( nb_elements != 0 ) { for( const auto i : Range{ nb_elements } ) { - if( typed_attribute.value( i ) != default_value_ ) + if( typed_attribute.value( i ) + != default_values_.default_value ) { values_[i] = typed_attribute.value( i ); } @@ -217,12 +262,14 @@ namespace geode AttributeBase::AttributeKey /*key*/ ) const override { std::shared_ptr< SparseAttribute< T > > attribute{ - new SparseAttribute< T >{ default_value_, this->properties() } + new SparseAttribute< T >{ + default_values_, this->name().value(), this->properties() } }; for( const auto i : Indices{ old2new } ) { const auto new_index = old2new[i]; - if( value( i ) != default_value_ && new_index != NO_ID ) + if( value( i ) != default_values_.default_value + && new_index != NO_ID ) { OpenGeodeBasicException::check_exception( new_index < nb_elements, nullptr, @@ -242,11 +289,12 @@ namespace geode AttributeBase::AttributeKey /*key*/ ) const override { std::shared_ptr< SparseAttribute< T > > attribute{ - new SparseAttribute< T >{ default_value_, this->properties() } + new SparseAttribute< T >{ + default_values_, this->name().value(), this->properties() } }; for( const auto& [in, outs] : old2new_mapping.in2out_map() ) { - if( value( in ) != default_value_ ) + if( value( in ) != default_values_.default_value ) { for( const auto new_index : outs ) { @@ -285,7 +333,8 @@ namespace geode for( const auto i : Indices{ old2new } ) { const auto new_index = old2new[i]; - if( from.value( i ) != default_value_ && new_index != NO_ID ) + if( from.value( i ) != default_values_.default_value + && new_index != NO_ID ) { this->set_value( new_index, from.value( i ) ); } @@ -297,7 +346,7 @@ namespace geode { for( const auto& [in, outs] : old2new_mapping.in2out_map() ) { - if( from.value( in ) != default_value_ ) + if( from.value( in ) != default_values_.default_value ) { for( const auto new_index : outs ) { @@ -308,7 +357,7 @@ namespace geode } private: - T default_value_; + AttributeValues< T > default_values_; absl::flat_hash_map< index_t, T > values_{}; }; } // namespace geode diff --git a/include/geode/basic/variable_attribute.hpp b/include/geode/basic/variable_attribute.hpp index f9ccb5d5b..c4df6294f 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 @@ -56,11 +57,12 @@ namespace geode friend class bitsery::Access; public: - VariableAttribute( T default_value, + VariableAttribute( AttributeValues< T > default_values, + std::string_view name, AttributeProperties properties, AttributeBase::AttributeKey /*key*/ ) : VariableAttribute( - std::move( default_value ), std::move( properties ) ) + std::move( default_values ), name, std::move( properties ) ) { } @@ -69,14 +71,23 @@ namespace geode return values_[element]; } + [[nodiscard]] bool has_value( index_t element ) const override + { + if( values_[element] == default_values_.no_value ) + { + return false; + } + return true; + } + void set_value( index_t element, T value ) { values_[element] = std::move( value ); } - [[nodiscard]] const T& default_value() const + [[nodiscard]] const AttributeValues< T >& default_values() const { - return default_value_; + return default_values_; } template < typename Modifier > @@ -106,33 +117,53 @@ namespace geode } protected: - VariableAttribute( T default_value, AttributeProperties properties ) - : ReadOnlyAttribute< T >( std::move( properties ) ), - default_value_( std::move( default_value ) ) + VariableAttribute( AttributeValues< T > default_values, + std::string_view name, + AttributeProperties properties ) + : ReadOnlyAttribute< T >( name, std::move( properties ) ), + default_values_( std::move( default_values ) ) { 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 ) { - serializer.ext( - *this, Growable< Archive, VariableAttribute< T > >{ - { []( Archive& archive, - VariableAttribute< T >& attribute ) { - archive.ext( - attribute, bitsery::ext::BaseClass< - ReadOnlyAttribute< T > >{} ); - archive( attribute.default_value_ ); - archive.container( attribute.values_, - attribute.values_.max_size(), - []( Archive& archive2, T& item ) { - archive2( item ); - } ); - } } } ); + serializer.ext( *this, + Growable< Archive, VariableAttribute< T > >{ + { []( Archive& archive, + VariableAttribute< T >& attribute ) { + T old_value; + archive.ext( + attribute, bitsery::ext::BaseClass< + ReadOnlyAttribute< T > >{} ); + archive( old_value ); + attribute.default_values_.default_value = old_value; + attribute.default_values_.no_value = old_value; + archive.container( attribute.values_, + attribute.values_.max_size(), + []( Archive& archive2, T& item ) { + archive2( item ); + } ); + }, + []( Archive& archive, + VariableAttribute< T >& attribute ) { + archive.ext( + attribute, bitsery::ext::BaseClass< + ReadOnlyAttribute< T > >{} ); + archive( attribute.default_values_ ); + archive.container( attribute.values_, + attribute.values_.max_size(), + []( Archive& archive2, T& item ) { + archive2( item ); + } ); + } } } ); values_.reserve( 10 ); } @@ -145,7 +176,7 @@ namespace geode const auto next_capacity = capacity * 2; values_.reserve( std::max( size, next_capacity ) ); } - values_.resize( size, default_value_ ); + values_.resize( size, default_values_.default_value ); } void reserve( @@ -170,8 +201,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_values_, this->name().value(), this->properties() } }; + IdentifierBuilder builder{ *attribute }; + builder.set_id( this->id() ); attribute->values_ = values_; return attribute; } @@ -182,10 +216,10 @@ namespace geode { const auto& typed_attribute = dynamic_cast< const VariableAttribute< T >& >( attribute ); - default_value_ = typed_attribute.default_value_; + default_values_ = typed_attribute.default_values_; if( nb_elements != 0 ) { - values_.resize( nb_elements, default_value_ ); + values_.resize( nb_elements, default_values_.default_value ); for( const auto i : Range{ nb_elements } ) { values_[i] = typed_attribute.value( i ); @@ -199,9 +233,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_values_, this->name().value(), this->properties() } }; - attribute->values_.resize( nb_elements, default_value_ ); + attribute->values_.resize( + nb_elements, default_values_.default_value ); for( const auto i : Indices{ old2new } ) { const auto new_index = old2new[i]; @@ -228,9 +264,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_values_, this->name().value(), this->properties() } }; - attribute->values_.resize( nb_elements, default_value_ ); + attribute->values_.resize( + nb_elements, default_values_.default_value ); for( const auto& [input, outputs] : old2new_mapping.in2out_map() ) { for( const auto new_index : outputs ) @@ -291,7 +329,7 @@ namespace geode } private: - T default_value_; + AttributeValues< T > default_values_; std::vector< T > values_{}; }; @@ -306,10 +344,11 @@ namespace geode friend class bitsery::Access; public: - VariableAttribute( bool default_value, + VariableAttribute( AttributeValues< 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 ) ) { } @@ -318,14 +357,23 @@ namespace geode return reinterpret_cast< const bool& >( values_[element] ); } + [[nodiscard]] bool has_value( index_t element ) const override + { + if( value( element ) == default_values_.no_value ) + { + return false; + } + return true; + } + void set_value( index_t element, bool value ) { values_[element] = std::move( value ); } - [[nodiscard]] bool default_value() const + [[nodiscard]] AttributeValues< bool > default_values() const { - return default_value_; + return default_values_; } template < typename Modifier > @@ -355,15 +403,22 @@ namespace geode } protected: - VariableAttribute( bool default_value, AttributeProperties properties ) - : ReadOnlyAttribute< bool >( std::move( properties ) ), - default_value_( default_value ) + VariableAttribute( AttributeValues< bool > default_values, + std::string_view name, + AttributeProperties properties ) + : ReadOnlyAttribute< bool >( name, std::move( properties ) ), + default_values_( default_values ) { 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 ) @@ -372,13 +427,25 @@ namespace geode Growable< Archive, VariableAttribute< bool > >{ { []( Archive& archive, VariableAttribute< bool >& attribute ) { - archive.ext( - attribute, bitsery::ext::BaseClass< - ReadOnlyAttribute< bool > >{} ); - archive.value1b( attribute.default_value_ ); - archive.container1b( - attribute.values_, attribute.values_.max_size() ); - } } } ); + bool old_value; + archive.ext( + attribute, bitsery::ext::BaseClass< + ReadOnlyAttribute< bool > >{} ); + archive.value1b( old_value ); + attribute.default_values_.default_value = old_value; + attribute.default_values_.no_value = old_value; + archive.container1b( + attribute.values_, attribute.values_.max_size() ); + }, + []( Archive& archive, + VariableAttribute< bool >& attribute ) { + archive.ext( + attribute, bitsery::ext::BaseClass< + ReadOnlyAttribute< bool > >{} ); + archive( attribute.default_values_ ); + archive.container1b( attribute.values_, + attribute.values_.max_size() ); + } } } ); values_.reserve( 10 ); } @@ -391,7 +458,8 @@ namespace geode const auto next_capacity = capacity * 2; values_.reserve( std::max( size, next_capacity ) ); } - values_.resize( size, default_value_ ); + values_.resize( size, + static_cast< unsigned char >( default_values_.default_value ) ); } void reserve( @@ -417,7 +485,7 @@ namespace geode { std::shared_ptr< VariableAttribute< bool > > attribute{ new VariableAttribute< bool >{ - static_cast< bool >( default_value_ ), this->properties() } + default_values_, this->name().value(), this->properties() } }; attribute->values_ = values_; return attribute; @@ -429,7 +497,7 @@ namespace geode { const auto& typed_attribute = dynamic_cast< const VariableAttribute< bool >& >( attribute ); - default_value_ = typed_attribute.default_value_; + default_values_ = typed_attribute.default_values_; if( nb_elements != 0 ) { values_.resize( nb_elements ); @@ -447,9 +515,10 @@ namespace geode { std::shared_ptr< VariableAttribute< bool > > attribute{ new VariableAttribute< bool >{ - static_cast< bool >( default_value_ ), this->properties() } + default_values_, this->name().value(), this->properties() } }; - attribute->values_.resize( nb_elements, default_value_ ); + attribute->values_.resize( nb_elements, + static_cast< unsigned char >( default_values_.default_value ) ); for( const auto i : Indices{ old2new } ) { const auto new_index = old2new[i]; @@ -477,9 +546,10 @@ namespace geode { std::shared_ptr< VariableAttribute< bool > > attribute{ new VariableAttribute< bool >{ - static_cast< bool >( default_value_ ), this->properties() } + default_values_, this->name().value(), this->properties() } }; - attribute->values_.resize( nb_elements, default_value_ ); + attribute->values_.resize( nb_elements, + static_cast< unsigned char >( default_values_.default_value ) ); for( const auto& [in, outs] : old2new_mapping.in2out_map() ) { for( const auto new_index : outs ) @@ -541,7 +611,7 @@ namespace geode } private: - unsigned char default_value_; + AttributeValues< bool > default_values_; std::vector< unsigned char > values_{}; }; } // namespace geode diff --git a/include/geode/geometry/information.hpp b/include/geode/geometry/information.hpp index 5550c7865..8c2aedef8 100644 --- a/include/geode/geometry/information.hpp +++ b/include/geode/geometry/information.hpp @@ -34,7 +34,7 @@ namespace geode zero }; - using Sign = SIDE; + using SIGN = SIDE; enum struct POSITION { diff --git a/include/geode/geometry/sign.hpp b/include/geode/geometry/sign.hpp index 7284a9c10..b1d190653 100644 --- a/include/geode/geometry/sign.hpp +++ b/include/geode/geometry/sign.hpp @@ -33,7 +33,7 @@ namespace geode ALIAS_2D( Polygon ); class Tetrahedron; enum struct SIDE; - using Sign = SIDE; + using SIGN = SIDE; } // namespace geode namespace geode @@ -41,21 +41,21 @@ namespace geode /*! * Return the sign of a tetrahedron volume. */ - [[nodiscard]] Sign opengeode_geometry_api tetrahedron_volume_sign( + [[nodiscard]] SIGN opengeode_geometry_api tetrahedron_volume_sign( const Tetrahedron& tetra ); /*! * Return the sign of a 2D triangle area. */ - [[nodiscard]] Sign opengeode_geometry_api triangle_area_sign( + [[nodiscard]] SIGN opengeode_geometry_api triangle_area_sign( const Triangle2D& triangle ); - [[nodiscard]] Sign opengeode_geometry_api polygon_area_sign( + [[nodiscard]] SIGN opengeode_geometry_api polygon_area_sign( const Polygon2D& polygon ); /*! * Return the sign of a 3D triangle area aligned on X- Y- or Z-axis. */ - [[nodiscard]] Sign opengeode_geometry_api triangle_area_sign( + [[nodiscard]] SIGN opengeode_geometry_api triangle_area_sign( const Triangle3D& triangle, local_index_t axis ); } // namespace geode 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/builder/vertex_set_builder.hpp b/include/geode/mesh/builder/vertex_set_builder.hpp index 045e47d3f..ca14aae59 100644 --- a/include/geode/mesh/builder/vertex_set_builder.hpp +++ b/include/geode/mesh/builder/vertex_set_builder.hpp @@ -47,9 +47,9 @@ namespace geode class opengeode_mesh_api VertexSetBuilder : public IdentifierBuilder { OPENGEODE_DISABLE_COPY( VertexSetBuilder ); - PASSKEY( VertexSet, VertexSetKey /*key*/ ); public: + PASSKEY( VertexSet, VertexSetKey /*key*/ ); VertexSetBuilder( VertexSetBuilder&& ) noexcept = default; virtual ~VertexSetBuilder() = default; diff --git a/include/geode/mesh/core/attribute_coordinate_reference_system.hpp b/include/geode/mesh/core/attribute_coordinate_reference_system.hpp index ad1374547..5ef3d861a 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 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/coordinate_reference_system_manager.hpp b/include/geode/mesh/core/coordinate_reference_system_manager.hpp index 4185cf208..ee5f043bd 100644 --- a/include/geode/mesh/core/coordinate_reference_system_manager.hpp +++ b/include/geode/mesh/core/coordinate_reference_system_manager.hpp @@ -47,11 +47,11 @@ namespace geode template < index_t dimension > class CoordinateReferenceSystemManager { - PASSKEY( CoordinateReferenceSystemManagerBuilder< dimension >, - CRSManagerKey /*key*/ ); friend class bitsery::Access; public: + PASSKEY( CoordinateReferenceSystemManagerBuilder< dimension >, + CRSManagerKey /*key*/ ); CoordinateReferenceSystemManager(); CoordinateReferenceSystemManager( CoordinateReferenceSystemManager&& other ) noexcept; diff --git a/include/geode/mesh/core/coordinate_reference_system_managers.hpp b/include/geode/mesh/core/coordinate_reference_system_managers.hpp index 3885b5572..8059965ee 100644 --- a/include/geode/mesh/core/coordinate_reference_system_managers.hpp +++ b/include/geode/mesh/core/coordinate_reference_system_managers.hpp @@ -47,11 +47,12 @@ namespace geode template < index_t dimension > class CoordinateReferenceSystemManagers { - PASSKEY( CoordinateReferenceSystemManagersBuilder< dimension >, - CRSManagersKey /*key*/ ); friend class bitsery::Access; public: + PASSKEY( CoordinateReferenceSystemManagersBuilder< dimension >, + CRSManagersKey /*key*/ ); + ~CoordinateReferenceSystemManagers(); [[nodiscard]] const CoordinateReferenceSystemManager1D& diff --git a/include/geode/mesh/core/detail/facet_storage.hpp b/include/geode/mesh/core/detail/facet_storage.hpp index 16d7e68e3..a45aef0b2 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,36 @@ 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 } ) ) { + AttributeProperties attribute_properties; + attribute_properties.assignable = false; + attribute_properties.interpolable = false; + attribute_properties.transferable = false; + AttributeValues< index_t > counter_values; + counter_values.default_value = 1u; + counter_values.no_value = NO_ID; + const auto counter_attribute_id = + facet_attribute_manager_ + .create_attribute< VariableAttribute, index_t >( + "counter", counter_values, attribute_properties ); + counter_ = facet_attribute_manager_ + .find_attribute< VariableAttribute, index_t >( + counter_attribute_id ); + AttributeValues< VertexContainer > vertices_values; + vertices_values.default_value = VertexContainer{}; + vertices_values.no_value = VertexContainer{}; + const auto vertices_attribute_id = + facet_attribute_manager_ + .create_attribute< VariableAttribute, VertexContainer >( + "facet_vertices", vertices_values, + attribute_properties ); + vertices_ = + facet_attribute_manager_ + .find_attribute< VariableAttribute, VertexContainer >( + vertices_attribute_id ); } [[nodiscard]] AttributeManager& facet_attribute_manager() const @@ -221,17 +239,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 +254,49 @@ namespace geode { facet_attribute_manager_.copy( from.facet_attribute_manager() ); facet_indices_ = from.facet_indices_; - counter_ = + AttributeProperties attribute_properties; + attribute_properties.assignable = false; + attribute_properties.interpolable = false; + attribute_properties.transferable = false; + AttributeValues< index_t > counter_values; + counter_values.default_value = 1u; + counter_values.no_value = NO_ID; + const auto counter_id = 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 } ); + .create_attribute< VariableAttribute, index_t >( + "counter", counter_values, attribute_properties ); + counter_ = facet_attribute_manager_ + .find_attribute< VariableAttribute, index_t >( + counter_id ); + const auto old_counter_attribute = + from.facet_attribute_manager() + .template find_read_only_attribute< index_t >( + from.counter_->id() ); + AttributeValues< VertexContainer > vertices_values; + vertices_values.default_value = VertexContainer{}; + vertices_values.no_value = VertexContainer{}; + const auto vertices_id = + facet_attribute_manager_ + .create_attribute< VariableAttribute, VertexContainer >( + "facet_vertices", vertices_values, + attribute_properties ); + vertices_ = + facet_attribute_manager_ + .find_attribute< VariableAttribute, VertexContainer >( + vertices_id ); + const auto old_vertices_attribute = + from.facet_attribute_manager() + .template find_read_only_attribute< VertexContainer >( + from.vertices_->id() ); + for( const auto& [_, facet_id] : facet_indices_ ) + { + const auto old_counter_value = + old_counter_attribute->value( facet_id ); + counter_->set_value( facet_id, old_counter_value ); + const auto old_vertices_value = + old_vertices_attribute->value( facet_id ); + vertices_->set_value( facet_id, old_vertices_value ); + } } 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..b4b1b81e4 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 @@ -41,14 +42,15 @@ namespace geode class OpenGeodeEdgedCurve : public EdgedCurve< dimension > { OPENGEODE_DISABLE_COPY( OpenGeodeEdgedCurve ); - PASSKEY( - OpenGeodeEdgedCurveBuilder< dimension >, OGEdgedCurveKey /*key*/ ); public: + PASSKEY( + OpenGeodeEdgedCurveBuilder< dimension >, OGEdgedCurveKey /*key*/ ); using Builder = OpenGeodeEdgedCurveBuilder< dimension >; 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..a24bea0c3 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 @@ -38,12 +39,11 @@ namespace geode { class opengeode_mesh_api OpenGeodeGraph : public Graph { - PASSKEY( OpenGeodeGraphBuilder, OGGraphKey /*key*/ ); - public: using Builder = OpenGeodeGraphBuilder; - + PASSKEY( OpenGeodeGraphBuilder, OGGraphKey /*key*/ ); 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..2a44f33a3 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 @@ -43,14 +44,15 @@ namespace geode class OpenGeodeHybridSolid : public HybridSolid< dimension > { OPENGEODE_DISABLE_COPY( OpenGeodeHybridSolid ); - PASSKEY( OpenGeodeHybridSolidBuilder< dimension >, - OGHybridSolidKey /*key*/ ); public: + PASSKEY( OpenGeodeHybridSolidBuilder< dimension >, + OGHybridSolidKey /*key*/ ); using Builder = OpenGeodeHybridSolidBuilder< dimension >; 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..40cfe401d 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 @@ -43,13 +44,14 @@ namespace geode class OpenGeodePointSet : public PointSet< dimension > { OPENGEODE_DISABLE_COPY( OpenGeodePointSet ); - PASSKEY( OpenGeodePointSetBuilder< dimension >, OGPointSetKey /*key*/ ); public: + PASSKEY( OpenGeodePointSetBuilder< dimension >, OGPointSetKey /*key*/ ); using Builder = OpenGeodePointSetBuilder< dimension >; 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..14126fa24 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 @@ -41,14 +42,15 @@ namespace geode class OpenGeodePolygonalSurface : public PolygonalSurface< dimension > { OPENGEODE_DISABLE_COPY( OpenGeodePolygonalSurface ); - PASSKEY( OpenGeodePolygonalSurfaceBuilder< dimension >, - OGPolygonalSurfaceKey /*key*/ ); public: + PASSKEY( OpenGeodePolygonalSurfaceBuilder< dimension >, + OGPolygonalSurfaceKey /*key*/ ); using Builder = OpenGeodePolygonalSurfaceBuilder< dimension >; 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..547db5e44 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 @@ -41,14 +42,15 @@ namespace geode class OpenGeodePolyhedralSolid : public PolyhedralSolid< dimension > { OPENGEODE_DISABLE_COPY( OpenGeodePolyhedralSolid ); - PASSKEY( OpenGeodePolyhedralSolidBuilder< dimension >, - OGPolyhedralSolidKey /*key*/ ); public: + PASSKEY( OpenGeodePolyhedralSolidBuilder< dimension >, + OGPolyhedralSolidKey /*key*/ ); using Builder = OpenGeodePolyhedralSolidBuilder< dimension >; 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..c2cbab82d 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 @@ -45,13 +46,14 @@ namespace geode class opengeode_mesh_api OpenGeodeRegularGrid< 3 > : public RegularGrid< 3 > { OPENGEODE_DISABLE_COPY( OpenGeodeRegularGrid ); - PASSKEY( OpenGeodeRegularGridBuilder< 3 >, OGRegularGridKey /*key*/ ); public: + PASSKEY( OpenGeodeRegularGridBuilder< 3 >, OGRegularGridKey /*key*/ ); using Builder = OpenGeodeRegularGridBuilder< 3 >; 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..c99c8db2c 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 @@ -45,13 +46,14 @@ namespace geode class opengeode_mesh_api OpenGeodeRegularGrid< 2 > : public RegularGrid< 2 > { OPENGEODE_DISABLE_COPY( OpenGeodeRegularGrid ); - PASSKEY( OpenGeodeRegularGridBuilder< 2 >, OGRegularGridKey /*key*/ ); public: + PASSKEY( OpenGeodeRegularGridBuilder< 2 >, OGRegularGridKey /*key*/ ); using Builder = OpenGeodeRegularGridBuilder< 2 >; 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..375b38697 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 @@ -43,14 +44,15 @@ namespace geode class OpenGeodeTetrahedralSolid : public TetrahedralSolid< dimension > { OPENGEODE_DISABLE_COPY( OpenGeodeTetrahedralSolid ); - PASSKEY( OpenGeodeTetrahedralSolidBuilder< dimension >, - OGTetrahedralSolidKey /*key*/ ); public: + PASSKEY( OpenGeodeTetrahedralSolidBuilder< dimension >, + OGTetrahedralSolidKey /*key*/ ); using Builder = OpenGeodeTetrahedralSolidBuilder< dimension >; 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..9b3f81a6b 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 @@ -43,14 +44,15 @@ namespace geode class OpenGeodeTriangulatedSurface : public TriangulatedSurface< dimension > { OPENGEODE_DISABLE_COPY( OpenGeodeTriangulatedSurface ); - PASSKEY( OpenGeodeTriangulatedSurfaceBuilder< dimension >, - OGTriangulatedSurfaceKey /*key*/ ); public: + PASSKEY( OpenGeodeTriangulatedSurfaceBuilder< dimension >, + OGTriangulatedSurfaceKey /*key*/ ); using Builder = OpenGeodeTriangulatedSurfaceBuilder< dimension >; 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..b90933e78 100644 --- a/include/geode/mesh/core/graph.hpp +++ b/include/geode/mesh/core/graph.hpp @@ -29,6 +29,7 @@ #include #include +#include #include #include @@ -106,11 +107,13 @@ namespace geode */ class opengeode_mesh_api Graph : public VertexSet { + public: PASSKEY( GraphBuilder, GraphKey /*key*/ ); - public: using Builder = GraphBuilder; + Graph( BITSERY ); + ~Graph(); /*! diff --git a/include/geode/mesh/core/grid.hpp b/include/geode/mesh/core/grid.hpp index ffef49bdc..1c53c4be6 100644 --- a/include/geode/mesh/core/grid.hpp +++ b/include/geode/mesh/core/grid.hpp @@ -52,10 +52,10 @@ namespace geode class Grid : public CellArray< dimension > { OPENGEODE_DISABLE_COPY( Grid ); - PASSKEY( GridBuilder< dimension >, GridKey /*key*/ ); friend class bitsery::Access; public: + PASSKEY( GridBuilder< dimension >, GridKey /*key*/ ); using Builder = GridBuilder< dimension >; static constexpr auto dim = dimension; using CellIndices = typename CellArray< dimension >::CellIndices; 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..37fc93e55 100644 --- a/include/geode/mesh/core/internal/edges_impl.hpp +++ b/include/geode/mesh/core/internal/edges_impl.hpp @@ -37,13 +37,26 @@ 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_() { + AttributeProperties attribute_properties; + attribute_properties.assignable = false; + attribute_properties.interpolable = false; + attribute_properties.transferable = false; + AttributeValues< std::array< index_t, 2 > > edges_values; + edges_values.default_value = { NO_ID, NO_ID }; + edges_values.no_value = { NO_ID, NO_ID }; + const auto edge_attribute_id = + graph.edge_attribute_manager() + .template create_attribute< VariableAttribute, + std::array< index_t, 2 > >( + "edges", edges_values, attribute_properties ); + 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 +76,11 @@ namespace geode } ); } + [[nodiscard]] const uuid& edges_attribute_id() const + { + return edges_->id(); + } + protected: EdgesImpl() = default; @@ -93,6 +111,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..44e6e1b0f 100644 --- a/include/geode/mesh/core/internal/points_impl.hpp +++ b/include/geode/mesh/core/internal/points_impl.hpp @@ -52,6 +52,32 @@ namespace geode public: static constexpr auto POINTS_NAME = "points"; + PointsImpl() = default; + + PointsImpl( + AttributeManager& manager, std::string_view attribute_name ) + { + AttributeProperties attribute_properties; + attribute_properties.assignable = false; + attribute_properties.interpolable = false; + attribute_properties.transferable = false; + AttributeValues< Point< dimension > > points_values; + points_values.default_value = Point< dimension >{}; + points_values.no_value = Point< dimension >{}; + const auto attribute_id = + manager.template create_attribute< VariableAttribute, + Point< dimension > >( + attribute_name, points_values, attribute_properties ); + points_ = manager.template find_attribute< VariableAttribute, + Point< dimension > >( attribute_id ); + } + + PointsImpl( AttributeManager& manager, const 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 +96,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 +131,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/solid_mesh_impl.hpp b/include/geode/mesh/core/internal/solid_mesh_impl.hpp index a1fc1f2eb..9a13050ba 100644 --- a/include/geode/mesh/core/internal/solid_mesh_impl.hpp +++ b/include/geode/mesh/core/internal/solid_mesh_impl.hpp @@ -51,6 +51,12 @@ namespace geode return polyhedra != other.polyhedra; } + [[nodiscard]] bool operator==( + const PolyhedraAroundVertexImpl& other ) const + { + return !operator!=( other ); + } + friend class bitsery::Access; template < typename Archive > void serialize( Archive& serializer ) diff --git a/include/geode/mesh/core/internal/surface_mesh_impl.hpp b/include/geode/mesh/core/internal/surface_mesh_impl.hpp index a8d9006e5..21d5583d0 100644 --- a/include/geode/mesh/core/internal/surface_mesh_impl.hpp +++ b/include/geode/mesh/core/internal/surface_mesh_impl.hpp @@ -51,6 +51,12 @@ namespace geode return polygons != other.polygons; } + [[nodiscard]] bool operator==( + const PolygonsAroundVertexImpl& other ) const + { + return !operator!=( other ); + } + friend class bitsery::Access; template < typename Archive > void serialize( Archive& serializer ) diff --git a/include/geode/mesh/core/internal/texture_impl.hpp b/include/geode/mesh/core/internal/texture_impl.hpp index 17992db03..2af75e33b 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 uuid& texture_id() const + { + return coordinates_->id(); + } + void set_image( RasterImage< dimension >&& image ) { image_ = std::move( image ); @@ -86,11 +91,20 @@ namespace geode } TextureImpl( AttributeManager& manager, std::string_view name ) - : coordinates_{ - manager.find_or_create_attribute< VariableAttribute, - ElementTextureCoordinates >( name, {} ) - } { + AttributeProperties attribute_properties; + attribute_properties.assignable = false; + attribute_properties.interpolable = false; + attribute_properties.transferable = false; + AttributeValues< ElementTextureCoordinates > coordinates_values; + coordinates_values.default_value = {}; + coordinates_values.no_value = {}; + const auto texture_id = + manager.create_attribute< VariableAttribute, + ElementTextureCoordinates >( + name, coordinates_values, attribute_properties ); + 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_edges.hpp b/include/geode/mesh/core/solid_edges.hpp index 83e97ce23..531853cb7 100644 --- a/include/geode/mesh/core/solid_edges.hpp +++ b/include/geode/mesh/core/solid_edges.hpp @@ -49,9 +49,9 @@ namespace geode { OPENGEODE_DISABLE_COPY( SolidEdges ); OPENGEODE_TEMPLATE_ASSERT_3D( dimension ); - PASSKEY( SolidEdgesBuilder< dimension >, SolidEdgesKey /*key*/ ); public: + PASSKEY( SolidEdgesBuilder< dimension >, SolidEdgesKey /*key*/ ); using Builder = SolidEdgesBuilder< dimension >; static constexpr auto dim = dimension; diff --git a/include/geode/mesh/core/solid_facets.hpp b/include/geode/mesh/core/solid_facets.hpp index 7447e9334..9cc5c5bed 100644 --- a/include/geode/mesh/core/solid_facets.hpp +++ b/include/geode/mesh/core/solid_facets.hpp @@ -42,9 +42,9 @@ namespace geode { OPENGEODE_DISABLE_COPY( SolidFacets ); OPENGEODE_TEMPLATE_ASSERT_3D( dimension ); - PASSKEY( SolidFacetsBuilder< dimension >, SolidFacetsKey /*key*/ ); public: + PASSKEY( SolidFacetsBuilder< dimension >, SolidFacetsKey /*key*/ ); using Builder = SolidFacetsBuilder< dimension >; static constexpr auto dim = dimension; diff --git a/include/geode/mesh/core/solid_mesh.hpp b/include/geode/mesh/core/solid_mesh.hpp index 48058090a..b6e8c0c29 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 @@ -270,13 +271,15 @@ namespace geode { OPENGEODE_DISABLE_COPY( SolidMesh ); OPENGEODE_TEMPLATE_ASSERT_3D( dimension ); - PASSKEY( SolidMeshBuilder< dimension >, SolidMeshKey /*key*/ ); public: + PASSKEY( SolidMeshBuilder< dimension >, SolidMeshKey /*key*/ ); using Builder = SolidMeshBuilder< dimension >; 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..3f246c278 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 @@ -47,9 +48,9 @@ namespace geode class opengeode_mesh_api SurfaceEdges { OPENGEODE_DISABLE_COPY( SurfaceEdges ); - PASSKEY( SurfaceEdgesBuilder< dimension >, SurfaceEdgesKey /*key*/ ); public: + PASSKEY( SurfaceEdgesBuilder< dimension >, SurfaceEdgesKey /*key*/ ); using Builder = SurfaceEdgesBuilder< dimension >; static constexpr auto dim = dimension; diff --git a/include/geode/mesh/core/surface_mesh.hpp b/include/geode/mesh/core/surface_mesh.hpp index 8bb4996a8..07dc489a1 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 @@ -163,13 +164,15 @@ namespace geode public CoordinateReferenceSystemManagers< dimension > { OPENGEODE_DISABLE_COPY( SurfaceMesh ); - PASSKEY( SurfaceMeshBuilder< dimension >, SurfaceMeshKey /*key*/ ); public: + PASSKEY( SurfaceMeshBuilder< dimension >, SurfaceMeshKey /*key*/ ); using Builder = SurfaceMeshBuilder< dimension >; 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/texture_storage.hpp b/include/geode/mesh/core/texture_storage.hpp index 9d871b33e..dca915014 100644 --- a/include/geode/mesh/core/texture_storage.hpp +++ b/include/geode/mesh/core/texture_storage.hpp @@ -48,9 +48,9 @@ namespace geode class TextureStorage { friend class bitsery::Access; - PASSKEY( TextureManager< dimension >, TextureManagerKey /*key*/ ); public: + PASSKEY( TextureManager< dimension >, TextureManagerKey /*key*/ ); TextureStorage(); TextureStorage( TextureStorage&& other ) noexcept; ~TextureStorage(); 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..cdf33f5de --- /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 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..64a32d8a0 100644 --- a/include/geode/mesh/helpers/gradient_computation.hpp +++ b/include/geode/mesh/helpers/gradient_computation.hpp @@ -31,32 +31,32 @@ namespace geode FORWARD_DECLARATION_DIMENSION_CLASS( SolidMesh ); ALIAS_2D_AND_3D( SurfaceMesh ); ALIAS_3D( SolidMesh ); + struct uuid; } // 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]] uuid compute_surface_scalar_function_gradient( + const SurfaceMesh< dimension >& mesh, const uuid& scalar_function_id ); - [[nodiscard]] std::string opengeode_mesh_api + [[nodiscard]] 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< 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< 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/grid_scalar_function.hpp b/include/geode/mesh/helpers/grid_scalar_function.hpp index be27729a6..ebc5613b7 100644 --- a/include/geode/mesh/helpers/grid_scalar_function.hpp +++ b/include/geode/mesh/helpers/grid_scalar_function.hpp @@ -32,6 +32,7 @@ namespace geode { FORWARD_DECLARATION_DIMENSION_CLASS( Point ); FORWARD_DECLARATION_DIMENSION_CLASS( Grid ); + struct uuid; } // namespace geode namespace geode @@ -55,11 +56,11 @@ namespace geode /*! * Finds an object function that already exists in the given - * Grid, from its given name. + * Grid, from its given id. * Throws an exception if no attribute with the same name exists. */ [[nodiscard]] static GridScalarFunction< dimension > find( - const Grid< dimension >& grid, std::string_view function_name ); + const Grid< dimension >& grid, const uuid& function_id ); void set_value( const typename Grid< dimension >::VertexIndices& vertex_index, @@ -79,7 +80,7 @@ namespace geode private: GridScalarFunction( - const Grid< dimension >& grid, std::string_view function_name ); + const Grid< dimension >& grid, const uuid& function_id ); GridScalarFunction( const Grid< dimension >& grid, std::string_view function_name, diff --git a/include/geode/mesh/helpers/tetrahedral_solid_point_function.hpp b/include/geode/mesh/helpers/tetrahedral_solid_point_function.hpp index f2b150fd7..a88e6e439 100644 --- a/include/geode/mesh/helpers/tetrahedral_solid_point_function.hpp +++ b/include/geode/mesh/helpers/tetrahedral_solid_point_function.hpp @@ -31,6 +31,7 @@ namespace geode { FORWARD_DECLARATION_DIMENSION_CLASS( Point ); FORWARD_DECLARATION_DIMENSION_CLASS( TetrahedralSolid ); + struct uuid; } // namespace geode namespace geode @@ -55,17 +56,18 @@ namespace geode point_dimension > create( const TetrahedralSolid< dimension >& solid, std::string_view function_name, + const uuid& function_id, Point< point_dimension > value ); /*! * 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,14 +77,17 @@ 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, std::string_view function_name, + const uuid& function_id, Point< point_dimension > value ); private: diff --git a/include/geode/mesh/helpers/tetrahedral_solid_scalar_function.hpp b/include/geode/mesh/helpers/tetrahedral_solid_scalar_function.hpp index 1e0cffe70..78f32254e 100644 --- a/include/geode/mesh/helpers/tetrahedral_solid_scalar_function.hpp +++ b/include/geode/mesh/helpers/tetrahedral_solid_scalar_function.hpp @@ -31,6 +31,7 @@ namespace geode { FORWARD_DECLARATION_DIMENSION_CLASS( Point ); FORWARD_DECLARATION_DIMENSION_CLASS( TetrahedralSolid ); + struct uuid; } // namespace geode namespace geode @@ -53,16 +54,17 @@ namespace geode [[nodiscard]] static TetrahedralSolidScalarFunction< dimension > create( const TetrahedralSolid< dimension >& solid, std::string_view function_name, + const uuid& function_id, double value ); /*! * 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 +73,18 @@ 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, + const uuid& function_id, + 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..36ee2a585 100644 --- a/include/geode/mesh/helpers/triangulated_surface_point_function.hpp +++ b/include/geode/mesh/helpers/triangulated_surface_point_function.hpp @@ -31,6 +31,7 @@ namespace geode { FORWARD_DECLARATION_DIMENSION_CLASS( Point ); FORWARD_DECLARATION_DIMENSION_CLASS( TriangulatedSurface ); + struct uuid; } // namespace geode namespace geode @@ -53,17 +54,18 @@ namespace geode point_dimension > create( const TriangulatedSurface< dimension >& solid, std::string_view function_name, + const uuid& function_id, Point< point_dimension > value ); /*! * 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,14 +75,17 @@ 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, std::string_view function_name, + const uuid& function_id, Point< point_dimension > value ); private: diff --git a/include/geode/mesh/helpers/triangulated_surface_scalar_function.hpp b/include/geode/mesh/helpers/triangulated_surface_scalar_function.hpp index c7bed50f6..40e571a43 100644 --- a/include/geode/mesh/helpers/triangulated_surface_scalar_function.hpp +++ b/include/geode/mesh/helpers/triangulated_surface_scalar_function.hpp @@ -31,6 +31,7 @@ namespace geode { FORWARD_DECLARATION_DIMENSION_CLASS( Point ); FORWARD_DECLARATION_DIMENSION_CLASS( TriangulatedSurface ); + struct uuid; } // namespace geode namespace geode @@ -51,6 +52,7 @@ namespace geode [[nodiscard]] static TriangulatedSurfaceScalarFunction< dimension > create( const TriangulatedSurface< dimension >& solid, std::string_view function_name, + const uuid& function_id, double value ); /*! @@ -60,7 +62,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,14 +71,17 @@ namespace geode [[nodiscard]] double value( const Point< dimension >& point, index_t tetrahedron_id ) const; + [[nodiscard]] const 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, std::string_view function_name, + const uuid& function_id, double value ); private: 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/blocks_builder.hpp b/include/geode/model/mixin/builder/blocks_builder.hpp index ee70a2448..7e9bbd5fb 100644 --- a/include/geode/model/mixin/builder/blocks_builder.hpp +++ b/include/geode/model/mixin/builder/blocks_builder.hpp @@ -56,8 +56,12 @@ namespace geode [[nodiscard]] std::unique_ptr< typename Mesh::Builder > block_mesh_builder( const uuid& id ) { - auto& mesh = blocks_.modifiable_block( id, {} ).modifiable_mesh( - typename Block< dimension >::BlocksBuilderKey{} ); + auto& mesh = + blocks_ + .modifiable_block( + id, typename Block< dimension >::BlocksBuilderKey{} ) + .modifiable_mesh( + typename Block< dimension >::BlocksBuilderKey{} ); return MeshBuilderFactory::create_mesh_builder< typename Mesh::Builder >( dynamic_cast< Mesh& >( mesh ) ); } diff --git a/include/geode/model/mixin/builder/surfaces_builder.hpp b/include/geode/model/mixin/builder/surfaces_builder.hpp index 3a0bf5b16..2f063fed1 100644 --- a/include/geode/model/mixin/builder/surfaces_builder.hpp +++ b/include/geode/model/mixin/builder/surfaces_builder.hpp @@ -56,8 +56,12 @@ namespace geode [[nodiscard]] std::unique_ptr< typename Mesh::Builder > surface_mesh_builder( const uuid& id ) { - auto& mesh = surfaces_.modifiable_surface( id, {} ).modifiable_mesh( - typename Surface< dimension >::SurfacesBuilderKey{} ); + auto& mesh = + surfaces_ + .modifiable_surface( id, + typename Surface< dimension >::SurfacesBuilderKey{} ) + .modifiable_mesh( + typename Surface< dimension >::SurfacesBuilderKey{} ); return MeshBuilderFactory::create_mesh_builder< typename Mesh::Builder >( dynamic_cast< Mesh& >( mesh ) ); } diff --git a/include/geode/model/mixin/builder/vertex_identifier_builder.hpp b/include/geode/model/mixin/builder/vertex_identifier_builder.hpp index 1aa562050..9c3f6ff89 100644 --- a/include/geode/model/mixin/builder/vertex_identifier_builder.hpp +++ b/include/geode/model/mixin/builder/vertex_identifier_builder.hpp @@ -44,7 +44,15 @@ namespace geode template < typename MeshComponent > void register_mesh_component( const MeshComponent& component ) { - vertex_identifier_.register_mesh_component( component, {} ); + vertex_identifier_.register_mesh_component( + component, VertexIdentifier::BuilderKey{} ); + } + + template < typename MeshComponent > + void load_mesh_component( const MeshComponent& component ) + { + vertex_identifier_.load_mesh_component( + component, VertexIdentifier::BuilderKey{} ); } /*! @@ -54,7 +62,8 @@ namespace geode template < typename MeshComponent > void unregister_mesh_component( const MeshComponent& component ) { - vertex_identifier_.unregister_mesh_component( component, {} ); + vertex_identifier_.unregister_mesh_component( + component, VertexIdentifier::BuilderKey{} ); } /*! diff --git a/include/geode/model/mixin/core/block.hpp b/include/geode/model/mixin/core/block.hpp index ad3b76c39..e7f7c491c 100644 --- a/include/geode/model/mixin/core/block.hpp +++ b/include/geode/model/mixin/core/block.hpp @@ -52,11 +52,11 @@ namespace geode { OPENGEODE_DISABLE_COPY( Block ); OPENGEODE_TEMPLATE_ASSERT_3D( dimension ); - PASSKEY( Blocks< dimension >, BlocksKey /*key*/ ); - PASSKEY( BlocksBuilder< dimension >, BlocksBuilderKey /*key*/ ); friend class bitsery::Access; public: + PASSKEY( Blocks< dimension >, BlocksKey /*key*/ ); + PASSKEY( BlocksBuilder< dimension >, BlocksBuilderKey /*key*/ ); using Mesh = SolidMesh< dimension >; Block( Block&& other ) noexcept; diff --git a/include/geode/model/mixin/core/block_collection.hpp b/include/geode/model/mixin/core/block_collection.hpp index bb1f052d8..a5ffc4892 100644 --- a/include/geode/model/mixin/core/block_collection.hpp +++ b/include/geode/model/mixin/core/block_collection.hpp @@ -44,12 +44,12 @@ namespace geode class BlockCollection : public Component< dimension > { OPENGEODE_DISABLE_COPY( BlockCollection ); - PASSKEY( BlockCollections< dimension >, BlockCollectionsKey /*key*/ ); - PASSKEY( BlockCollectionsBuilder< dimension >, - BlockCollectionsBuilderKey /*key*/ ); friend class bitsery::Access; public: + PASSKEY( BlockCollections< dimension >, BlockCollectionsKey /*key*/ ); + PASSKEY( BlockCollectionsBuilder< dimension >, + BlockCollectionsBuilderKey /*key*/ ); BlockCollection( BlockCollection&& other ) noexcept = default; ~BlockCollection() = default; diff --git a/include/geode/model/mixin/core/block_collections.hpp b/include/geode/model/mixin/core/block_collections.hpp index 7456043db..526189d73 100644 --- a/include/geode/model/mixin/core/block_collections.hpp +++ b/include/geode/model/mixin/core/block_collections.hpp @@ -42,10 +42,10 @@ namespace geode class BlockCollections { OPENGEODE_DISABLE_COPY( BlockCollections ); - PASSKEY( BlockCollectionsBuilder< dimension >, - BlockCollectionsBuilderKey /*key*/ ); public: + PASSKEY( BlockCollectionsBuilder< dimension >, + BlockCollectionsBuilderKey /*key*/ ); using Builder = BlockCollectionsBuilder< dimension >; using Type = BlockCollection< dimension >; diff --git a/include/geode/model/mixin/core/blocks.hpp b/include/geode/model/mixin/core/blocks.hpp index b4e707c99..886508908 100644 --- a/include/geode/model/mixin/core/blocks.hpp +++ b/include/geode/model/mixin/core/blocks.hpp @@ -48,9 +48,9 @@ namespace geode { OPENGEODE_DISABLE_COPY( Blocks ); OPENGEODE_TEMPLATE_ASSERT_3D( dimension ); - PASSKEY( BlocksBuilder< dimension >, BlocksBuilderKey /*key*/ ); public: + PASSKEY( BlocksBuilder< dimension >, BlocksBuilderKey /*key*/ ); using Builder = BlocksBuilder< dimension >; using Type = Block< dimension >; diff --git a/include/geode/model/mixin/core/component_registry.hpp b/include/geode/model/mixin/core/component_registry.hpp index e52892f51..aace9b8c8 100644 --- a/include/geode/model/mixin/core/component_registry.hpp +++ b/include/geode/model/mixin/core/component_registry.hpp @@ -43,9 +43,8 @@ namespace geode { class opengeode_model_api ComponentRegistry { - PASSKEY( ComponentRegistryBuilder, RegistryBuilder ); - public: + PASSKEY( ComponentRegistryBuilder, RegistryBuilder ); using Registry = absl::flat_hash_map< ComponentType, std::vector< uuid > >; diff --git a/include/geode/model/mixin/core/corner.hpp b/include/geode/model/mixin/core/corner.hpp index 4433e1b8e..717cac1fd 100644 --- a/include/geode/model/mixin/core/corner.hpp +++ b/include/geode/model/mixin/core/corner.hpp @@ -52,11 +52,11 @@ namespace geode class Corner final : public Component< dimension > { OPENGEODE_DISABLE_COPY( Corner ); - PASSKEY( Corners< dimension >, CornersKey /*key*/ ); - PASSKEY( CornersBuilder< dimension >, CornersBuilderKey /*key*/ ); friend class bitsery::Access; public: + PASSKEY( Corners< dimension >, CornersKey /*key*/ ); + PASSKEY( CornersBuilder< dimension >, CornersBuilderKey /*key*/ ); using Mesh = PointSet< dimension >; Corner( Corner&& other ) noexcept; diff --git a/include/geode/model/mixin/core/corner_collection.hpp b/include/geode/model/mixin/core/corner_collection.hpp index 4295c02e8..76427dd71 100644 --- a/include/geode/model/mixin/core/corner_collection.hpp +++ b/include/geode/model/mixin/core/corner_collection.hpp @@ -44,12 +44,12 @@ namespace geode class CornerCollection : public Component< dimension > { OPENGEODE_DISABLE_COPY( CornerCollection ); - PASSKEY( CornerCollections< dimension >, CornerCollectionsKey /*key*/ ); - PASSKEY( CornerCollectionsBuilder< dimension >, - CornerCollectionsBuilderKey /*key*/ ); friend class bitsery::Access; public: + PASSKEY( CornerCollections< dimension >, CornerCollectionsKey /*key*/ ); + PASSKEY( CornerCollectionsBuilder< dimension >, + CornerCollectionsBuilderKey /*key*/ ); CornerCollection( CornerCollection&& other ) noexcept = default; ~CornerCollection() = default; diff --git a/include/geode/model/mixin/core/corner_collections.hpp b/include/geode/model/mixin/core/corner_collections.hpp index 9792cacb5..4f3b4710b 100644 --- a/include/geode/model/mixin/core/corner_collections.hpp +++ b/include/geode/model/mixin/core/corner_collections.hpp @@ -44,10 +44,10 @@ namespace geode class CornerCollections { OPENGEODE_DISABLE_COPY( CornerCollections ); - PASSKEY( CornerCollectionsBuilder< dimension >, - CornerCollectionsBuilderKey /*key*/ ); public: + PASSKEY( CornerCollectionsBuilder< dimension >, + CornerCollectionsBuilderKey /*key*/ ); using Builder = CornerCollectionsBuilder< dimension >; using Type = CornerCollection< dimension >; diff --git a/include/geode/model/mixin/core/corners.hpp b/include/geode/model/mixin/core/corners.hpp index 60a6f7e5b..8cc95b4d7 100644 --- a/include/geode/model/mixin/core/corners.hpp +++ b/include/geode/model/mixin/core/corners.hpp @@ -47,9 +47,9 @@ namespace geode class opengeode_model_api Corners { OPENGEODE_DISABLE_COPY( Corners ); - PASSKEY( CornersBuilder< dimension >, CornersBuilderKey /*key*/ ); public: + PASSKEY( CornersBuilder< dimension >, CornersBuilderKey /*key*/ ); using Builder = CornersBuilder< dimension >; using Type = Corner< dimension >; 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/line.hpp b/include/geode/model/mixin/core/line.hpp index 036626dcb..0bdd5c91c 100644 --- a/include/geode/model/mixin/core/line.hpp +++ b/include/geode/model/mixin/core/line.hpp @@ -51,11 +51,11 @@ namespace geode class Line final : public Component< dimension > { OPENGEODE_DISABLE_COPY( Line ); - PASSKEY( Lines< dimension >, LinesKey /*key*/ ); - PASSKEY( LinesBuilder< dimension >, LinesBuilderKey /*key*/ ); friend class bitsery::Access; public: + PASSKEY( Lines< dimension >, LinesKey /*key*/ ); + PASSKEY( LinesBuilder< dimension >, LinesBuilderKey /*key*/ ); using Mesh = EdgedCurve< dimension >; Line( Line&& other ) noexcept; diff --git a/include/geode/model/mixin/core/line_collection.hpp b/include/geode/model/mixin/core/line_collection.hpp index 2c614ccc3..edc0e7f75 100644 --- a/include/geode/model/mixin/core/line_collection.hpp +++ b/include/geode/model/mixin/core/line_collection.hpp @@ -44,12 +44,12 @@ namespace geode class LineCollection : public Component< dimension > { OPENGEODE_DISABLE_COPY( LineCollection ); - PASSKEY( LineCollections< dimension >, LineCollectionsKey /*key*/ ); - PASSKEY( LineCollectionsBuilder< dimension >, - LineCollectionsBuilderKey /*key*/ ); friend class bitsery::Access; public: + PASSKEY( LineCollections< dimension >, LineCollectionsKey /*key*/ ); + PASSKEY( LineCollectionsBuilder< dimension >, + LineCollectionsBuilderKey /*key*/ ); LineCollection( LineCollection&& other ) noexcept = default; ~LineCollection() = default; diff --git a/include/geode/model/mixin/core/line_collections.hpp b/include/geode/model/mixin/core/line_collections.hpp index dea12d6df..0016fd1eb 100644 --- a/include/geode/model/mixin/core/line_collections.hpp +++ b/include/geode/model/mixin/core/line_collections.hpp @@ -44,10 +44,10 @@ namespace geode class LineCollections { OPENGEODE_DISABLE_COPY( LineCollections ); - PASSKEY( LineCollectionsBuilder< dimension >, - LineCollectionsBuilderKey /*key*/ ); public: + PASSKEY( LineCollectionsBuilder< dimension >, + LineCollectionsBuilderKey /*key*/ ); using Builder = LineCollectionsBuilder< dimension >; using Type = LineCollection< dimension >; diff --git a/include/geode/model/mixin/core/lines.hpp b/include/geode/model/mixin/core/lines.hpp index ba10e27a4..2addfc2c8 100644 --- a/include/geode/model/mixin/core/lines.hpp +++ b/include/geode/model/mixin/core/lines.hpp @@ -44,9 +44,9 @@ namespace geode class opengeode_model_api Lines { OPENGEODE_DISABLE_COPY( Lines ); - PASSKEY( LinesBuilder< dimension >, LinesBuilderKey /*key*/ ); public: + PASSKEY( LinesBuilder< dimension >, LinesBuilderKey /*key*/ ); using Builder = LinesBuilder< dimension >; using Type = Line< dimension >; diff --git a/include/geode/model/mixin/core/model_boundaries.hpp b/include/geode/model/mixin/core/model_boundaries.hpp index e9a2663ab..53f6b96aa 100644 --- a/include/geode/model/mixin/core/model_boundaries.hpp +++ b/include/geode/model/mixin/core/model_boundaries.hpp @@ -44,10 +44,10 @@ namespace geode class ModelBoundaries { OPENGEODE_DISABLE_COPY( ModelBoundaries ); - PASSKEY( ModelBoundariesBuilder< dimension >, - ModelBoundariesBuilderKey /*key*/ ); public: + PASSKEY( ModelBoundariesBuilder< dimension >, + ModelBoundariesBuilderKey /*key*/ ); using Builder = ModelBoundariesBuilder< dimension >; using Type = ModelBoundary< dimension >; diff --git a/include/geode/model/mixin/core/model_boundary.hpp b/include/geode/model/mixin/core/model_boundary.hpp index f1b0a32c6..86a7ee42c 100644 --- a/include/geode/model/mixin/core/model_boundary.hpp +++ b/include/geode/model/mixin/core/model_boundary.hpp @@ -44,12 +44,12 @@ namespace geode class ModelBoundary : public Component< dimension > { OPENGEODE_DISABLE_COPY( ModelBoundary ); - PASSKEY( ModelBoundaries< dimension >, ModelBoundariesKey /*key*/ ); - PASSKEY( ModelBoundariesBuilder< dimension >, - ModelBoundariesBuilderKey /*key*/ ); friend class bitsery::Access; public: + PASSKEY( ModelBoundaries< dimension >, ModelBoundariesKey /*key*/ ); + PASSKEY( ModelBoundariesBuilder< dimension >, + ModelBoundariesBuilderKey /*key*/ ); ModelBoundary( ModelBoundary&& other ) noexcept = default; ~ModelBoundary() = default; diff --git a/include/geode/model/mixin/core/relationships.hpp b/include/geode/model/mixin/core/relationships.hpp index 3dfa505f2..64a9b1b44 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 @@ -50,6 +51,7 @@ namespace geode */ class opengeode_model_api Relationships { + public: PASSKEY( RelationshipsBuilder, RelationshipsBuilderKey /*key*/ ); public: @@ -357,6 +359,7 @@ namespace geode public: Relationships(); + Relationships( BITSERY ); ~Relationships(); [[nodiscard]] index_t nb_components_with_relations() const; diff --git a/include/geode/model/mixin/core/surface.hpp b/include/geode/model/mixin/core/surface.hpp index 39af02aa4..1099629c0 100644 --- a/include/geode/model/mixin/core/surface.hpp +++ b/include/geode/model/mixin/core/surface.hpp @@ -51,11 +51,11 @@ namespace geode class Surface final : public Component< dimension > { OPENGEODE_DISABLE_COPY( Surface ); - PASSKEY( Surfaces< dimension >, SurfacesKey /*key*/ ); - PASSKEY( SurfacesBuilder< dimension >, SurfacesBuilderKey /*key*/ ); friend class bitsery::Access; public: + PASSKEY( Surfaces< dimension >, SurfacesKey /*key*/ ); + PASSKEY( SurfacesBuilder< dimension >, SurfacesBuilderKey /*key*/ ); using Mesh = SurfaceMesh< dimension >; Surface( Surface&& other ) noexcept; diff --git a/include/geode/model/mixin/core/surface_collection.hpp b/include/geode/model/mixin/core/surface_collection.hpp index 5f9341cc1..47f79eba0 100644 --- a/include/geode/model/mixin/core/surface_collection.hpp +++ b/include/geode/model/mixin/core/surface_collection.hpp @@ -44,13 +44,13 @@ namespace geode class SurfaceCollection : public Component< dimension > { OPENGEODE_DISABLE_COPY( SurfaceCollection ); + friend class bitsery::Access; + + public: PASSKEY( SurfaceCollections< dimension >, SurfaceCollectionsKey /*key*/ ); PASSKEY( SurfaceCollectionsBuilder< dimension >, SurfaceCollectionsBuilderKey /*key*/ ); - friend class bitsery::Access; - - public: SurfaceCollection( SurfaceCollection&& other ) noexcept = default; ~SurfaceCollection() = default; diff --git a/include/geode/model/mixin/core/surface_collections.hpp b/include/geode/model/mixin/core/surface_collections.hpp index 98c6b885e..e7e438915 100644 --- a/include/geode/model/mixin/core/surface_collections.hpp +++ b/include/geode/model/mixin/core/surface_collections.hpp @@ -44,10 +44,10 @@ namespace geode class SurfaceCollections { OPENGEODE_DISABLE_COPY( SurfaceCollections ); - PASSKEY( SurfaceCollectionsBuilder< dimension >, - SurfaceCollectionsBuilderKey /*key*/ ); public: + PASSKEY( SurfaceCollectionsBuilder< dimension >, + SurfaceCollectionsBuilderKey /*key*/ ); using Builder = SurfaceCollectionsBuilder< dimension >; using Type = SurfaceCollection< dimension >; diff --git a/include/geode/model/mixin/core/surfaces.hpp b/include/geode/model/mixin/core/surfaces.hpp index 53cc028d8..985754b7e 100644 --- a/include/geode/model/mixin/core/surfaces.hpp +++ b/include/geode/model/mixin/core/surfaces.hpp @@ -44,9 +44,9 @@ namespace geode class opengeode_model_api Surfaces { OPENGEODE_DISABLE_COPY( Surfaces ); - PASSKEY( SurfacesBuilder< dimension >, SurfacesBuilderKey /*key*/ ); public: + PASSKEY( SurfacesBuilder< dimension >, SurfacesBuilderKey /*key*/ ); using Builder = SurfacesBuilder< dimension >; using Type = Surface< dimension >; 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..ee6e2cc99 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 @@ -89,10 +90,10 @@ namespace geode */ class opengeode_model_api VertexIdentifier { - PASSKEY( VertexIdentifierBuilder, BuilderKey /*key*/ ); - public: + PASSKEY( VertexIdentifierBuilder, BuilderKey /*key*/ ); VertexIdentifier(); + VertexIdentifier( BITSERY ); ~VertexIdentifier(); [[nodiscard]] index_t nb_unique_vertices() const; @@ -141,6 +142,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 bdb8de8a5..9d7854b9a 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 @@ -409,6 +410,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 b7c7c523c..594b0d39f 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 @@ -308,6 +309,7 @@ namespace geode public: Section(); + Section( BITSERY ); Section( Section&& section ) noexcept; Section& operator=( Section&& section ); ~Section(); diff --git a/include/geode/model/representation/io/geode/geode_brep_input.hpp b/include/geode/model/representation/io/geode/geode_brep_input.hpp index b77dd3084..cb49b4beb 100644 --- a/include/geode/model/representation/io/geode/geode_brep_input.hpp +++ b/include/geode/model/representation/io/geode/geode_brep_input.hpp @@ -71,7 +71,7 @@ namespace geode { BRepBuilder builder{ brep }; const auto level = Logger::level(); - Logger::set_level( Logger::LEVEL::warn ); + Logger::set_level( Logger::LEVEL::warning ); async::parallel_invoke( [&builder, &directory] { builder.load_identifier( directory ); diff --git a/include/geode/model/representation/io/geode/geode_section_input.hpp b/include/geode/model/representation/io/geode/geode_section_input.hpp index 6780c119a..394ad7e0a 100644 --- a/include/geode/model/representation/io/geode/geode_section_input.hpp +++ b/include/geode/model/representation/io/geode/geode_section_input.hpp @@ -71,7 +71,7 @@ namespace geode { SectionBuilder builder{ section }; const auto level = Logger::level(); - Logger::set_level( Logger::LEVEL::warn ); + Logger::set_level( Logger::LEVEL::warning ); async::parallel_invoke( [&builder, &directory] { builder.load_identifier( directory ); diff --git a/src/geode/basic/attribute_manager.cpp b/src/geode/basic/attribute_manager.cpp index e596ea6b2..f6f607ede 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,31 +222,58 @@ namespace geode return nb_elements_; } - void copy( const AttributeManager::Impl &attribute_manager, + 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_from, const AttributeBase::AttributeKey &key ) { - nb_elements_ = attribute_manager.nb_elements_; - for( const auto &[attribute_name, attribute] : - attribute_manager.attributes_ ) + nb_elements_ = attribute_manager_from.nb_elements_; + for( const auto &[attribute_id_from, attribute_from] : + attribute_manager_from.attributes_ ) { - const auto attribute_it = attributes_.find( attribute_name ); + if( !attribute_from->properties().transferable ) + { + continue; + } + const auto attribute_it = attributes_.find( attribute_id_from ); if( attribute_it != attributes_.end() ) { try { attribute_it->second->copy( - *attribute, nb_elements_, key ); + *attribute_from, nb_elements_, key ); } catch( const std::bad_cast &e ) { - Logger::error( "Attribute \"", attribute_name, + Logger::error( "Attribute \"", + attribute_id_from.string(), "\" cannot be copied: ", e.what() ); } } else { attributes_.emplace( - attribute_name, attribute->clone( key ) ); + attribute_id_from, attribute_from->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,25 +448,27 @@ 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, AttributeBase::AttributeKey{} ); } void AttributeManager::resize( index_t size ) { - impl_->resize( size, {} ); + impl_->resize( size, AttributeBase::AttributeKey{} ); } void AttributeManager::reserve( index_t capacity ) { - impl_->reserve( capacity, {} ); + impl_->reserve( capacity, AttributeBase::AttributeKey{} ); } bool AttributeManager::has_assignable_attributes() const @@ -440,41 +484,44 @@ namespace geode void AttributeManager::assign_attribute_value( index_t from_element, index_t to_element ) { - impl_->assign_attribute_value( from_element, to_element, {} ); + impl_->assign_attribute_value( + from_element, to_element, AttributeBase::AttributeKey{} ); } void AttributeManager::copy_attribute_value( index_t from_element, index_t to_element ) { - impl_->copy_attribute_value( from_element, to_element, {} ); + impl_->copy_attribute_value( + from_element, to_element, AttributeBase::AttributeKey{} ); } void AttributeManager::interpolate_attribute_value( const AttributeLinearInterpolation &interpolation, index_t to_element ) { - impl_->interpolate_attribute_value( interpolation, to_element, {} ); + impl_->interpolate_attribute_value( + interpolation, to_element, AttributeBase::AttributeKey{} ); } - 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() @@ -484,7 +531,7 @@ namespace geode void AttributeManager::clear_attributes() { - impl_->clear_attributes( {} ); + impl_->clear_attributes( AttributeBase::AttributeKey{} ); } void AttributeManager::delete_elements( @@ -496,14 +543,14 @@ namespace geode to_delete.size() == nb_elements(), "[AttributeManager::delete_elements] Vector to_delete should " "have the same size as the number of elements" ); - impl_->delete_elements( to_delete, {} ); + impl_->delete_elements( to_delete, AttributeBase::AttributeKey{} ); } } void AttributeManager::permute_elements( absl::Span< const index_t > permutation ) { - impl_->permute_elements( permutation, {} ); + impl_->permute_elements( permutation, AttributeBase::AttributeKey{} ); } index_t AttributeManager::nb_elements() const @@ -513,47 +560,50 @@ namespace geode void AttributeManager::copy( const AttributeManager &attribute_manager ) { - impl_->copy( *attribute_manager.impl_, {} ); + impl_->copy( *attribute_manager.impl_, AttributeBase::AttributeKey{} ); + } + + std::optional< std::vector< geode::uuid > > + AttributeManager::attribute_ids_matching_name( + std::string_view name ) const + { + return impl_->attribute_ids_matching_name( name ); } void AttributeManager::import( const AttributeManager &attribute_manager, absl::Span< const index_t > old2new ) { - impl_->import( *attribute_manager.impl_, old2new, {} ); + impl_->import( + *attribute_manager.impl_, old2new, AttributeBase::AttributeKey{} ); } 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, + AttributeBase::AttributeKey{} ); } void AttributeManager::import( const AttributeManager &attribute_manager, const GenericMapping< index_t > &old2new_mapping ) { - impl_->import( *attribute_manager.impl_, old2new_mapping, {} ); + impl_->import( *attribute_manager.impl_, old2new_mapping, + AttributeBase::AttributeKey{} ); } void AttributeManager::import( const AttributeManager &attribute_manager, const GenericMapping< index_t > &old2new_mapping, - std::string_view attribute_name ) - { - impl_->import( - *attribute_manager.impl_, old2new_mapping, attribute_name, {} ); - } - - void AttributeManager::rename_attribute( - std::string_view old_name, std::string_view new_name ) + const geode::uuid &attribute_id ) { - impl_->rename_attribute( old_name, new_name, {} ); + impl_->import( *attribute_manager.impl_, old2new_mapping, attribute_id, + AttributeBase::AttributeKey{} ); } 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 +614,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/basic/console_logger_client.cpp b/src/geode/basic/console_logger_client.cpp index cc996fd5f..d9af35606 100644 --- a/src/geode/basic/console_logger_client.cpp +++ b/src/geode/basic/console_logger_client.cpp @@ -57,7 +57,7 @@ namespace geode logger_impl_->info( message ); } - void warn( const std::string &message ) + void warning( const std::string &message ) { logger_impl_->warn( message ); } @@ -95,9 +95,9 @@ namespace geode impl_->info( message ); } - void ConsoleLoggerClient::warn( const std::string &message ) + void ConsoleLoggerClient::warning( const std::string &message ) { - impl_->warn( message ); + impl_->warning( message ); } void ConsoleLoggerClient::error( const std::string &message ) diff --git a/src/geode/basic/file_logger_client.cpp b/src/geode/basic/file_logger_client.cpp index b9b374ae7..273cb0bf5 100644 --- a/src/geode/basic/file_logger_client.cpp +++ b/src/geode/basic/file_logger_client.cpp @@ -76,7 +76,7 @@ namespace geode logger_impl_->info( message ); } - void warn( const std::string &message ) + void warning( const std::string &message ) { logger_impl_->warn( message ); } @@ -128,9 +128,9 @@ namespace geode impl_->info( message ); } - void FileLoggerClient::warn( const std::string &message ) + void FileLoggerClient::warning( const std::string &message ) { - impl_->warn( message ); + impl_->warning( message ); } void FileLoggerClient::error( const std::string &message ) diff --git a/src/geode/basic/identifier_builder.cpp b/src/geode/basic/identifier_builder.cpp index db5abd5b1..ced7ee485 100644 --- a/src/geode/basic/identifier_builder.cpp +++ b/src/geode/basic/identifier_builder.cpp @@ -35,22 +35,22 @@ namespace geode void IdentifierBuilder::set_id( const uuid& unique_id ) { - identifier_.set_id( unique_id, {} ); + identifier_.set_id( unique_id, Identifier::IdentifierKey{} ); } void IdentifierBuilder::set_name( std::string_view name ) { - identifier_.set_name( name, {} ); + identifier_.set_name( name, Identifier::IdentifierKey{} ); } void IdentifierBuilder::copy_identifier( const Identifier& other ) { - identifier_.copy_identifier( other, {} ); + identifier_.copy_identifier( other, Identifier::IdentifierKey{} ); } void IdentifierBuilder::load_identifier( std::string_view directory ) { - identifier_.load_identifier( directory, {} ); + identifier_.load_identifier( directory, Identifier::IdentifierKey{} ); } } // namespace geode diff --git a/src/geode/basic/logger.cpp b/src/geode/basic/logger.cpp index 62cc3f06c..45c875b3e 100644 --- a/src/geode/basic/logger.cpp +++ b/src/geode/basic/logger.cpp @@ -74,15 +74,15 @@ namespace geode void log_warn( const std::string &message ) { - if( level_ <= LEVEL::warn ) + if( level_ <= LEVEL::warning ) { - LoggerManager::warn( message ); + LoggerManager::warning( message ); } } void log_error( const std::string &message ) { - if( level_ <= LEVEL::err ) + if( level_ <= LEVEL::error ) { LoggerManager::error( message ); } @@ -103,8 +103,8 @@ namespace geode { geode::Logger::LEVEL::trace, geode::Logger::log_trace }, { geode::Logger::LEVEL::debug, geode::Logger::log_debug }, { geode::Logger::LEVEL::info, geode::Logger::log_info }, - { geode::Logger::LEVEL::warn, geode::Logger::log_warn }, - { geode::Logger::LEVEL::err, geode::Logger::log_error }, + { geode::Logger::LEVEL::warning, geode::Logger::log_warn }, + { geode::Logger::LEVEL::error, geode::Logger::log_error }, { geode::Logger::LEVEL::critical, geode::Logger::log_critical } }; diff --git a/src/geode/basic/logger_manager.cpp b/src/geode/basic/logger_manager.cpp index f8bbe25f2..6f21ae819 100644 --- a/src/geode/basic/logger_manager.cpp +++ b/src/geode/basic/logger_manager.cpp @@ -61,11 +61,11 @@ namespace geode } } - void warn( const std::string &message ) + void warning( const std::string &message ) { for( auto &logger : loggers_ ) { - logger->warn( message ); + logger->warning( message ); } } @@ -114,9 +114,9 @@ namespace geode instance().impl_->info( message ); } - void LoggerManager::warn( const std::string &message ) + void LoggerManager::warning( const std::string &message ) { - instance().impl_->warn( message ); + instance().impl_->warning( message ); } void LoggerManager::error( const std::string &message ) diff --git a/src/geode/geometry/intersection_detection.cpp b/src/geode/geometry/intersection_detection.cpp index fd2e4fb7e..2f52f02a0 100644 --- a/src/geode/geometry/intersection_detection.cpp +++ b/src/geode/geometry/intersection_detection.cpp @@ -197,7 +197,7 @@ namespace if( geode::tetrahedron_volume_sign( geode::Tetrahedron{ segment0.vertices()[0].get(), segment0.vertices()[1].get(), segment1.vertices()[0].get(), segment1.vertices()[1].get() } ) - != geode::Sign::zero ) + != geode::SIGN::zero ) { return { geode::POSITION::outside, geode::POSITION::outside }; } diff --git a/src/geode/geometry/sign.cpp b/src/geode/geometry/sign.cpp index 66ae59404..75e66e249 100644 --- a/src/geode/geometry/sign.cpp +++ b/src/geode/geometry/sign.cpp @@ -40,21 +40,21 @@ namespace namespace geode { - Sign tetrahedron_volume_sign( const Tetrahedron& tetra ) + SIGN tetrahedron_volume_sign( const Tetrahedron& tetra ) { const auto& vertices = tetra.vertices(); return internal::side( GEO::PCK::orient_3d( vertices[0], vertices[1], vertices[2], vertices[3] ) ); } - Sign triangle_area_sign( const Triangle2D& triangle ) + SIGN triangle_area_sign( const Triangle2D& triangle ) { const auto& vertices = triangle.vertices(); return internal::side( GEO::PCK::orient_2d( vertices[0], vertices[1], vertices[2] ) ); } - Sign polygon_area_sign( const Polygon2D& polygon ) + SIGN polygon_area_sign( const Polygon2D& polygon ) { const auto& polygon_vertices = polygon.vertices(); const auto& p1 = polygon_vertices[0]; @@ -64,15 +64,15 @@ namespace geode const auto& p3 = polygon_vertices[static_cast< local_index_t >( other_index + 1 )]; const auto sign = triangle_area_sign( { p1, p2, p3 } ); - if( sign != Sign::zero ) + if( sign != SIGN::zero ) { return sign; } } - return geode::Sign::zero; + return geode::SIGN::zero; } - Sign triangle_area_sign( const Triangle3D& triangle, local_index_t axis ) + SIGN triangle_area_sign( const Triangle3D& triangle, local_index_t axis ) { const auto axis1 = new_axis[axis][0]; const auto axis2 = new_axis[axis][1]; 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/coordinate_reference_system_manager_builder.cpp b/src/geode/mesh/builder/coordinate_reference_system_manager_builder.cpp index 97daa23b9..2120e6f13 100644 --- a/src/geode/mesh/builder/coordinate_reference_system_manager_builder.cpp +++ b/src/geode/mesh/builder/coordinate_reference_system_manager_builder.cpp @@ -32,22 +32,28 @@ namespace geode register_coordinate_reference_system( std::string_view name, std::shared_ptr< CoordinateReferenceSystem< dimension > >&& crs ) { - crs_manager_.register_coordinate_reference_system( - name, std::move( crs ), {} ); + crs_manager_.register_coordinate_reference_system( name, + std::move( crs ), + typename CoordinateReferenceSystemManager< + dimension >::CRSManagerKey{} ); } template < index_t dimension > void CoordinateReferenceSystemManagerBuilder< dimension >::delete_coordinate_reference_system( std::string_view name ) { - crs_manager_.delete_coordinate_reference_system( name, {} ); + crs_manager_.delete_coordinate_reference_system( + name, typename CoordinateReferenceSystemManager< + dimension >::CRSManagerKey{} ); } template < index_t dimension > void CoordinateReferenceSystemManagerBuilder< dimension >:: set_active_coordinate_reference_system( std::string_view name ) { - crs_manager_.set_active_coordinate_reference_system( name, {} ); + crs_manager_.set_active_coordinate_reference_system( + name, typename CoordinateReferenceSystemManager< + dimension >::CRSManagerKey{} ); } template < index_t dimension > @@ -55,7 +61,9 @@ namespace geode CoordinateReferenceSystemManagerBuilder< dimension >::active_coordinate_reference_system() { - return crs_manager_.modifiable_active_coordinate_reference_system( {} ); + return crs_manager_.modifiable_active_coordinate_reference_system( + typename CoordinateReferenceSystemManager< + dimension >::CRSManagerKey{} ); } template < index_t dimension > @@ -63,7 +71,9 @@ namespace geode CoordinateReferenceSystemManagerBuilder< dimension >::coordinate_reference_system( std::string_view name ) { - return crs_manager_.modifiable_coordinate_reference_system( name, {} ); + return crs_manager_.modifiable_coordinate_reference_system( + name, typename CoordinateReferenceSystemManager< + dimension >::CRSManagerKey{} ); } template class opengeode_mesh_api diff --git a/src/geode/mesh/builder/coordinate_reference_system_managers_builder.cpp b/src/geode/mesh/builder/coordinate_reference_system_managers_builder.cpp index 6e219465e..58259b04d 100644 --- a/src/geode/mesh/builder/coordinate_reference_system_managers_builder.cpp +++ b/src/geode/mesh/builder/coordinate_reference_system_managers_builder.cpp @@ -36,7 +36,9 @@ namespace geode dimension >::coordinate_reference_system_manager_builder1D() { return CoordinateReferenceSystemManagerBuilder1D{ - crs_managers_.coordinate_reference_system_manager1D( {} ) + crs_managers_.coordinate_reference_system_manager1D( + typename CoordinateReferenceSystemManagers< + dimension >::CRSManagersKey{} ) }; } @@ -46,7 +48,9 @@ namespace geode dimension >::coordinate_reference_system_manager_builder2D() { return CoordinateReferenceSystemManagerBuilder2D{ - crs_managers_.coordinate_reference_system_manager2D( {} ) + crs_managers_.coordinate_reference_system_manager2D( + typename CoordinateReferenceSystemManagers< + dimension >::CRSManagersKey{} ) }; } @@ -56,7 +60,9 @@ namespace geode dimension >::coordinate_reference_system_manager_builder3D() { return CoordinateReferenceSystemManagerBuilder3D{ - crs_managers_.coordinate_reference_system_manager3D( {} ) + crs_managers_.coordinate_reference_system_manager3D( + typename CoordinateReferenceSystemManagers< + dimension >::CRSManagersKey{} ) }; } @@ -66,7 +72,9 @@ namespace geode dimension >::main_coordinate_reference_system_manager_builder() { return CoordinateReferenceSystemManagerBuilder< dimension >{ - crs_managers_.main_coordinate_reference_system_manager( {} ) + crs_managers_.main_coordinate_reference_system_manager( + typename CoordinateReferenceSystemManagers< + dimension >::CRSManagersKey{} ) }; } @@ -74,7 +82,9 @@ namespace geode void CoordinateReferenceSystemManagersBuilder< dimension >::set_point( index_t vertex, Point< dimension > point ) { - crs_managers_.set_point( vertex, std::move( point ), {} ); + crs_managers_.set_point( vertex, std::move( point ), + typename CoordinateReferenceSystemManagers< + dimension >::CRSManagersKey{} ); } template class opengeode_mesh_api 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_edged_curve_builder.cpp b/src/geode/mesh/builder/geode/geode_edged_curve_builder.cpp index fa7fc4c86..b8cfebad0 100644 --- a/src/geode/mesh/builder/geode/geode_edged_curve_builder.cpp +++ b/src/geode/mesh/builder/geode/geode_edged_curve_builder.cpp @@ -82,7 +82,8 @@ namespace geode void OpenGeodeEdgedCurveBuilder< dimension >::do_set_edge_vertex( const EdgeVertex& edge_vertex, index_t vertex_id ) { - geode_edged_curve_.set_edge_vertex( edge_vertex, vertex_id, {} ); + geode_edged_curve_.set_edge_vertex( edge_vertex, vertex_id, + typename OpenGeodeEdgedCurve< dimension >::OGEdgedCurveKey() ); } template < index_t dimension > diff --git a/src/geode/mesh/builder/geode/geode_graph_builder.cpp b/src/geode/mesh/builder/geode/geode_graph_builder.cpp index a041282ff..7607a6db1 100644 --- a/src/geode/mesh/builder/geode/geode_graph_builder.cpp +++ b/src/geode/mesh/builder/geode/geode_graph_builder.cpp @@ -69,7 +69,8 @@ namespace geode void OpenGeodeGraphBuilder::do_set_edge_vertex( const EdgeVertex& edge_vertex, index_t vertex_id ) { - geode_graph_.set_edge_vertex( edge_vertex, vertex_id, {} ); + geode_graph_.set_edge_vertex( + edge_vertex, vertex_id, OpenGeodeGraph::OGGraphKey() ); } void OpenGeodeGraphBuilder::do_create_edge() diff --git a/src/geode/mesh/builder/geode/geode_hybrid_solid_builder.cpp b/src/geode/mesh/builder/geode/geode_hybrid_solid_builder.cpp index 783064ce1..be9c02e2e 100644 --- a/src/geode/mesh/builder/geode/geode_hybrid_solid_builder.cpp +++ b/src/geode/mesh/builder/geode/geode_hybrid_solid_builder.cpp @@ -82,52 +82,57 @@ namespace geode void OpenGeodeHybridSolidBuilder< dimension >::do_set_polyhedron_vertex( const PolyhedronVertex& polyhedron_vertex, index_t vertex_id ) { - geode_hybrid_solid_.set_polyhedron_vertex( - polyhedron_vertex, vertex_id, {} ); + geode_hybrid_solid_.set_polyhedron_vertex( polyhedron_vertex, vertex_id, + typename OpenGeodeHybridSolid< dimension >::OGHybridSolidKey() ); } template < index_t dimension > void OpenGeodeHybridSolidBuilder< dimension >::do_create_tetrahedron( const std::array< index_t, 4 >& vertices ) { - geode_hybrid_solid_.add_tetrahedron( vertices, {} ); + geode_hybrid_solid_.add_tetrahedron( vertices, + typename OpenGeodeHybridSolid< dimension >::OGHybridSolidKey() ); } template < index_t dimension > void OpenGeodeHybridSolidBuilder< dimension >::do_create_hexahedron( const std::array< index_t, 8 >& vertices ) { - geode_hybrid_solid_.add_hexahedron( vertices, {} ); + geode_hybrid_solid_.add_hexahedron( vertices, + typename OpenGeodeHybridSolid< dimension >::OGHybridSolidKey() ); } template < index_t dimension > void OpenGeodeHybridSolidBuilder< dimension >::do_create_prism( const std::array< index_t, 6 >& vertices ) { - geode_hybrid_solid_.add_prism( vertices, {} ); + geode_hybrid_solid_.add_prism( vertices, + typename OpenGeodeHybridSolid< dimension >::OGHybridSolidKey() ); } template < index_t dimension > void OpenGeodeHybridSolidBuilder< dimension >::do_create_pyramid( const std::array< index_t, 5 >& vertices ) { - geode_hybrid_solid_.add_pyramid( vertices, {} ); + geode_hybrid_solid_.add_pyramid( vertices, + typename OpenGeodeHybridSolid< dimension >::OGHybridSolidKey() ); } template < index_t dimension > void OpenGeodeHybridSolidBuilder< dimension >::do_set_polyhedron_adjacent( const PolyhedronFacet& polyhedron_facet, index_t adjacent_id ) { - geode_hybrid_solid_.set_polyhedron_adjacent( - polyhedron_facet, adjacent_id, {} ); + geode_hybrid_solid_.set_polyhedron_adjacent( polyhedron_facet, + adjacent_id, + typename OpenGeodeHybridSolid< dimension >::OGHybridSolidKey() ); } template < index_t dimension > void OpenGeodeHybridSolidBuilder< dimension >::do_unset_polyhedron_adjacent( const PolyhedronFacet& polyhedron_facet ) { - geode_hybrid_solid_.set_polyhedron_adjacent( - polyhedron_facet, NO_ID, {} ); + geode_hybrid_solid_.set_polyhedron_adjacent( polyhedron_facet, NO_ID, + typename OpenGeodeHybridSolid< dimension >::OGHybridSolidKey() ); } template < index_t dimension > @@ -135,7 +140,8 @@ namespace geode const std::vector< bool >& to_delete, absl::Span< const index_t > /*unused*/ ) { - geode_hybrid_solid_.remove_polyhedra( to_delete, {} ); + geode_hybrid_solid_.remove_polyhedra( to_delete, + typename OpenGeodeHybridSolid< dimension >::OGHybridSolidKey() ); } template < index_t dimension > @@ -143,7 +149,8 @@ namespace geode absl::Span< const index_t > permutation, absl::Span< const index_t > /*unused*/ ) { - geode_hybrid_solid_.permute_polyhedra( permutation, {} ); + geode_hybrid_solid_.permute_polyhedra( permutation, + typename OpenGeodeHybridSolid< dimension >::OGHybridSolidKey() ); } template < index_t dimension > @@ -160,7 +167,7 @@ namespace geode geode_hybrid_solid_.copy_polyhedra( dynamic_cast< const OpenGeodeHybridSolid< dimension >& >( solid_mesh ), - {} ); + typename OpenGeodeHybridSolid< dimension >::OGHybridSolidKey() ); } template class opengeode_mesh_api OpenGeodeHybridSolidBuilder< 3 >; diff --git a/src/geode/mesh/builder/geode/geode_polygonal_surface_builder.cpp b/src/geode/mesh/builder/geode/geode_polygonal_surface_builder.cpp index fcb985e1e..d46a0f0c9 100644 --- a/src/geode/mesh/builder/geode/geode_polygonal_surface_builder.cpp +++ b/src/geode/mesh/builder/geode/geode_polygonal_surface_builder.cpp @@ -87,31 +87,37 @@ namespace geode void OpenGeodePolygonalSurfaceBuilder< dimension >::do_set_polygon_vertex( const PolygonVertex& polygon_vertex, index_t vertex_id ) { - geode_polygonal_surface_.set_polygon_vertex( - polygon_vertex, vertex_id, {} ); + geode_polygonal_surface_.set_polygon_vertex( polygon_vertex, vertex_id, + typename OpenGeodePolygonalSurface< + dimension >::OGPolygonalSurfaceKey{} ); } template < index_t dimension > void OpenGeodePolygonalSurfaceBuilder< dimension >::do_create_polygon( absl::Span< const index_t > vertices ) { - geode_polygonal_surface_.add_polygon( vertices, {} ); + geode_polygonal_surface_.add_polygon( + vertices, typename OpenGeodePolygonalSurface< + dimension >::OGPolygonalSurfaceKey{} ); } template < index_t dimension > void OpenGeodePolygonalSurfaceBuilder< dimension >::do_set_polygon_adjacent( const PolygonEdge& polygon_edge, index_t adjacent_id ) { - geode_polygonal_surface_.set_polygon_adjacent( - polygon_edge, adjacent_id, {} ); + geode_polygonal_surface_.set_polygon_adjacent( polygon_edge, + adjacent_id, + typename OpenGeodePolygonalSurface< + dimension >::OGPolygonalSurfaceKey{} ); } template < index_t dimension > void OpenGeodePolygonalSurfaceBuilder< dimension >:: do_unset_polygon_adjacent( const PolygonEdge& polygon_edge ) { - geode_polygonal_surface_.set_polygon_adjacent( - polygon_edge, NO_ID, {} ); + geode_polygonal_surface_.set_polygon_adjacent( polygon_edge, NO_ID, + typename OpenGeodePolygonalSurface< + dimension >::OGPolygonalSurfaceKey{} ); } template < index_t dimension > @@ -119,7 +125,9 @@ namespace geode const std::vector< bool >& to_delete, absl::Span< const index_t > /*unused*/ ) { - geode_polygonal_surface_.remove_polygons( to_delete, {} ); + geode_polygonal_surface_.remove_polygons( + to_delete, typename OpenGeodePolygonalSurface< + dimension >::OGPolygonalSurfaceKey{} ); } template < index_t dimension > @@ -127,7 +135,9 @@ namespace geode absl::Span< const index_t > permutation, absl::Span< const index_t > /*unused*/ ) { - geode_polygonal_surface_.permute_polygons( permutation, {} ); + geode_polygonal_surface_.permute_polygons( + permutation, typename OpenGeodePolygonalSurface< + dimension >::OGPolygonalSurfaceKey{} ); } template < index_t dimension > @@ -144,7 +154,8 @@ namespace geode geode_polygonal_surface_.copy_polygons( dynamic_cast< const OpenGeodePolygonalSurface< dimension >& >( surface_mesh ), - {} ); + typename OpenGeodePolygonalSurface< + dimension >::OGPolygonalSurfaceKey{} ); } template class opengeode_mesh_api OpenGeodePolygonalSurfaceBuilder< 2 >; diff --git a/src/geode/mesh/builder/geode/geode_polyhedral_solid_builder.cpp b/src/geode/mesh/builder/geode/geode_polyhedral_solid_builder.cpp index bd9c27d17..d59d8013f 100644 --- a/src/geode/mesh/builder/geode/geode_polyhedral_solid_builder.cpp +++ b/src/geode/mesh/builder/geode/geode_polyhedral_solid_builder.cpp @@ -88,8 +88,10 @@ namespace geode void OpenGeodePolyhedralSolidBuilder< dimension >::do_set_polyhedron_vertex( const PolyhedronVertex& polyhedron_vertex, index_t vertex_id ) { - geode_polyhedral_solid_.set_polyhedron_vertex( - polyhedron_vertex, vertex_id, {} ); + geode_polyhedral_solid_.set_polyhedron_vertex( polyhedron_vertex, + vertex_id, + typename OpenGeodePolyhedralSolid< + dimension >::OGPolyhedralSolidKey() ); } template < index_t dimension > @@ -97,7 +99,9 @@ namespace geode absl::Span< const index_t > vertices, absl::Span< const std::vector< local_index_t > > facets ) { - geode_polyhedral_solid_.add_polyhedron( vertices, facets, {} ); + geode_polyhedral_solid_.add_polyhedron( vertices, facets, + typename OpenGeodePolyhedralSolid< + dimension >::OGPolyhedralSolidKey() ); } template < index_t dimension > @@ -105,16 +109,20 @@ namespace geode do_set_polyhedron_adjacent( const PolyhedronFacet& polyhedron_facet, index_t adjacent_id ) { - geode_polyhedral_solid_.set_polyhedron_adjacent( - polyhedron_facet, adjacent_id, {} ); + geode_polyhedral_solid_.set_polyhedron_adjacent( polyhedron_facet, + adjacent_id, + typename OpenGeodePolyhedralSolid< + dimension >::OGPolyhedralSolidKey() ); } template < index_t dimension > void OpenGeodePolyhedralSolidBuilder< dimension >:: do_unset_polyhedron_adjacent( const PolyhedronFacet& polyhedron_facet ) { - geode_polyhedral_solid_.set_polyhedron_adjacent( - polyhedron_facet, NO_ID, {} ); + geode_polyhedral_solid_.set_polyhedron_adjacent( polyhedron_facet, + NO_ID, + typename OpenGeodePolyhedralSolid< + dimension >::OGPolyhedralSolidKey() ); } template < index_t dimension > @@ -122,7 +130,9 @@ namespace geode const std::vector< bool >& to_delete, absl::Span< const index_t > /*unused*/ ) { - geode_polyhedral_solid_.remove_polyhedra( to_delete, {} ); + geode_polyhedral_solid_.remove_polyhedra( + to_delete, typename OpenGeodePolyhedralSolid< + dimension >::OGPolyhedralSolidKey() ); } template < index_t dimension > @@ -130,7 +140,9 @@ namespace geode absl::Span< const index_t > permutation, absl::Span< const index_t > /*unused*/ ) { - geode_polyhedral_solid_.permute_polyhedra( permutation, {} ); + geode_polyhedral_solid_.permute_polyhedra( + permutation, typename OpenGeodePolyhedralSolid< + dimension >::OGPolyhedralSolidKey() ); } template < index_t dimension > @@ -147,7 +159,8 @@ namespace geode geode_polyhedral_solid_.copy_polyhedra( dynamic_cast< const OpenGeodePolyhedralSolid< dimension >& >( solid_mesh ), - {} ); + typename OpenGeodePolyhedralSolid< + dimension >::OGPolyhedralSolidKey() ); } template class opengeode_mesh_api OpenGeodePolyhedralSolidBuilder< 3 >; diff --git a/src/geode/mesh/builder/geode/geode_regular_grid_solid_builder.cpp b/src/geode/mesh/builder/geode/geode_regular_grid_solid_builder.cpp index 9c38afcb1..0e29d4b7e 100644 --- a/src/geode/mesh/builder/geode/geode_regular_grid_solid_builder.cpp +++ b/src/geode/mesh/builder/geode/geode_regular_grid_solid_builder.cpp @@ -49,7 +49,8 @@ namespace geode void OpenGeodeRegularGridBuilder< 3 >::update_origin( const Point3D& origin ) { - geode_regular_grid_.update_origin( origin, {} ); + geode_regular_grid_.update_origin( + origin, OpenGeodeRegularGrid< 3 >::OGRegularGridKey{} ); this->set_grid_origin( origin ); } @@ -57,7 +58,7 @@ namespace geode Point3D origin, std::array< Vector3D, 3 > directions ) { geode_regular_grid_.update_origin_and_directions( - origin, directions, {} ); + origin, directions, OpenGeodeRegularGrid< 3 >::OGRegularGridKey{} ); this->set_grid_origin( std::move( origin ) ); this->set_grid_directions( std::move( directions ) ); } diff --git a/src/geode/mesh/builder/geode/geode_regular_grid_surface_builder.cpp b/src/geode/mesh/builder/geode/geode_regular_grid_surface_builder.cpp index 899377a95..b5348b8cb 100644 --- a/src/geode/mesh/builder/geode/geode_regular_grid_surface_builder.cpp +++ b/src/geode/mesh/builder/geode/geode_regular_grid_surface_builder.cpp @@ -49,7 +49,8 @@ namespace geode void OpenGeodeRegularGridBuilder< 2 >::update_origin( const Point2D& origin ) { - geode_regular_grid_.update_origin( origin, {} ); + geode_regular_grid_.update_origin( + origin, OpenGeodeRegularGrid< 2 >::OGRegularGridKey{} ); this->set_grid_origin( origin ); } @@ -57,7 +58,7 @@ namespace geode Point2D origin, std::array< Vector2D, 2 > directions ) { geode_regular_grid_.update_origin_and_directions( - origin, directions, {} ); + origin, directions, OpenGeodeRegularGrid< 2 >::OGRegularGridKey{} ); this->set_grid_origin( std::move( origin ) ); this->set_grid_directions( std::move( directions ) ); } diff --git a/src/geode/mesh/builder/geode/geode_tetrahedral_solid_builder.cpp b/src/geode/mesh/builder/geode/geode_tetrahedral_solid_builder.cpp index 34c7fa4b8..dbf65b73e 100644 --- a/src/geode/mesh/builder/geode/geode_tetrahedral_solid_builder.cpp +++ b/src/geode/mesh/builder/geode/geode_tetrahedral_solid_builder.cpp @@ -89,15 +89,19 @@ namespace geode OpenGeodeTetrahedralSolidBuilder< dimension >::do_set_polyhedron_vertex( const PolyhedronVertex& polyhedron_vertex, index_t vertex_id ) { - geode_tetrahedral_solid_.set_polyhedron_vertex( - polyhedron_vertex, vertex_id, {} ); + geode_tetrahedral_solid_.set_polyhedron_vertex( polyhedron_vertex, + vertex_id, + typename OpenGeodeTetrahedralSolid< + dimension >::OGTetrahedralSolidKey() ); } template < index_t dimension > void OpenGeodeTetrahedralSolidBuilder< dimension >::do_create_tetrahedron( const std::array< index_t, 4 >& vertices ) { - geode_tetrahedral_solid_.add_tetrahedron( vertices, {} ); + geode_tetrahedral_solid_.add_tetrahedron( + vertices, typename OpenGeodeTetrahedralSolid< + dimension >::OGTetrahedralSolidKey() ); } template < index_t dimension > @@ -112,16 +116,20 @@ namespace geode do_set_polyhedron_adjacent( const PolyhedronFacet& polyhedron_facet, index_t adjacent_id ) { - geode_tetrahedral_solid_.set_polyhedron_adjacent( - polyhedron_facet, adjacent_id, {} ); + geode_tetrahedral_solid_.set_polyhedron_adjacent( polyhedron_facet, + adjacent_id, + typename OpenGeodeTetrahedralSolid< + dimension >::OGTetrahedralSolidKey() ); } template < index_t dimension > void OpenGeodeTetrahedralSolidBuilder< dimension >:: do_unset_polyhedron_adjacent( const PolyhedronFacet& polyhedron_facet ) { - geode_tetrahedral_solid_.set_polyhedron_adjacent( - polyhedron_facet, NO_ID, {} ); + geode_tetrahedral_solid_.set_polyhedron_adjacent( polyhedron_facet, + NO_ID, + typename OpenGeodeTetrahedralSolid< + dimension >::OGTetrahedralSolidKey() ); } template < index_t dimension > diff --git a/src/geode/mesh/builder/geode/geode_triangulated_surface_builder.cpp b/src/geode/mesh/builder/geode/geode_triangulated_surface_builder.cpp index c860b2e06..060a9d2bb 100644 --- a/src/geode/mesh/builder/geode/geode_triangulated_surface_builder.cpp +++ b/src/geode/mesh/builder/geode/geode_triangulated_surface_builder.cpp @@ -88,15 +88,19 @@ namespace geode OpenGeodeTriangulatedSurfaceBuilder< dimension >::do_set_polygon_vertex( const PolygonVertex& polygon_vertex, index_t vertex_id ) { - geode_triangulated_surface_.set_polygon_vertex( - polygon_vertex, vertex_id, {} ); + geode_triangulated_surface_.set_polygon_vertex( polygon_vertex, + vertex_id, + typename OpenGeodeTriangulatedSurface< + dimension >::OGTriangulatedSurfaceKey{} ); } template < index_t dimension > void OpenGeodeTriangulatedSurfaceBuilder< dimension >::do_create_triangle( const std::array< index_t, 3 >& vertices ) { - geode_triangulated_surface_.add_triangle( vertices, {} ); + geode_triangulated_surface_.add_triangle( + vertices, typename OpenGeodeTriangulatedSurface< + dimension >::OGTriangulatedSurfaceKey{} ); } template < index_t dimension > @@ -111,16 +115,19 @@ namespace geode dimension >::do_set_polygon_adjacent( const PolygonEdge& polygon_edge, index_t adjacent_id ) { - geode_triangulated_surface_.set_polygon_adjacent( - polygon_edge, adjacent_id, {} ); + geode_triangulated_surface_.set_polygon_adjacent( polygon_edge, + adjacent_id, + typename OpenGeodeTriangulatedSurface< + dimension >::OGTriangulatedSurfaceKey{} ); } template < index_t dimension > void OpenGeodeTriangulatedSurfaceBuilder< dimension >:: do_unset_polygon_adjacent( const PolygonEdge& polygon_edge ) { - geode_triangulated_surface_.set_polygon_adjacent( - polygon_edge, NO_ID, {} ); + geode_triangulated_surface_.set_polygon_adjacent( polygon_edge, NO_ID, + typename OpenGeodeTriangulatedSurface< + dimension >::OGTriangulatedSurfaceKey{} ); } template < index_t dimension > 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..d89cc9566 100644 --- a/src/geode/mesh/builder/graph_builder.cpp +++ b/src/geode/mesh/builder/graph_builder.cpp @@ -114,13 +114,15 @@ namespace geode void GraphBuilder::associate_edge_vertex_to_vertex( const EdgeVertex& edge_vertex, index_t vertex_id ) { - graph_.associate_edge_vertex_to_vertex( edge_vertex, vertex_id, {} ); + graph_.associate_edge_vertex_to_vertex( + edge_vertex, vertex_id, Graph::GraphKey{} ); } void GraphBuilder::disassociate_edge_vertex_to_vertex( const EdgeVertex& edge_vertex ) { - graph_.disassociate_edge_vertex_to_vertex( edge_vertex, {} ); + graph_.disassociate_edge_vertex_to_vertex( + edge_vertex, Graph::GraphKey{} ); } index_t GraphBuilder::create_edge() @@ -166,7 +168,8 @@ namespace geode void GraphBuilder::set_edges_around_vertex( index_t vertex_id, EdgesAroundVertex edges ) { - graph_.set_edges_around_vertex( vertex_id, std::move( edges ), {} ); + graph_.set_edges_around_vertex( + vertex_id, std::move( edges ), Graph::GraphKey{} ); } std::vector< index_t > GraphBuilder::delete_edges( @@ -245,22 +248,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/grid_builder.cpp b/src/geode/mesh/builder/grid_builder.cpp index 7badac1b3..598d40e14 100644 --- a/src/geode/mesh/builder/grid_builder.cpp +++ b/src/geode/mesh/builder/grid_builder.cpp @@ -39,7 +39,7 @@ namespace geode template < index_t dimension > void GridBuilder< dimension >::set_grid_origin( Point< dimension > origin ) { - grid_.set_grid_origin( origin, {} ); + grid_.set_grid_origin( origin, typename Grid< dimension >::GridKey{} ); } template < index_t dimension > @@ -47,21 +47,22 @@ namespace geode std::array< index_t, dimension > cells_number, std::array< double, dimension > cells_length ) { - grid_.set_grid_dimensions( - std::move( cells_number ), std::move( cells_length ), {} ); + grid_.set_grid_dimensions( std::move( cells_number ), + std::move( cells_length ), typename Grid< dimension >::GridKey{} ); } template < index_t dimension > void GridBuilder< dimension >::set_grid_directions( std::array< Vector< dimension >, dimension > directions ) { - grid_.set_grid_directions( std::move( directions ), {} ); + grid_.set_grid_directions( + std::move( directions ), typename Grid< dimension >::GridKey{} ); } template < index_t dimension > void GridBuilder< dimension >::copy( const Grid< dimension >& grid ) { - grid_.copy( grid, {} ); + grid_.copy( grid, typename Grid< dimension >::GridKey{} ); } template class opengeode_mesh_api GridBuilder< 2 >; 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_edges_builder.cpp b/src/geode/mesh/builder/solid_edges_builder.cpp index 9c519357f..29976e6ba 100644 --- a/src/geode/mesh/builder/solid_edges_builder.cpp +++ b/src/geode/mesh/builder/solid_edges_builder.cpp @@ -44,21 +44,24 @@ namespace geode index_t SolidEdgesBuilder< dimension >::find_or_create_edge( std::array< index_t, 2 > edge_vertices ) { - return edges_->find_or_create_edge( std::move( edge_vertices ), {} ); + return edges_->find_or_create_edge( std::move( edge_vertices ), + typename SolidEdges< dimension >::SolidEdgesKey() ); } template < index_t dimension > void SolidEdgesBuilder< dimension >::remove_edge( std::array< index_t, 2 > edge_vertices ) { - edges_->remove_edge( std::move( edge_vertices ), {} ); + edges_->remove_edge( std::move( edge_vertices ), + typename SolidEdges< dimension >::SolidEdgesKey() ); } template < index_t dimension > std::vector< index_t > SolidEdgesBuilder< dimension >::delete_isolated_edges() { - return edges_->remove_isolated_edges( {} ); + return edges_->remove_isolated_edges( + typename SolidEdges< dimension >::SolidEdgesKey() ); } template < index_t dimension > @@ -68,15 +71,17 @@ namespace geode index_t edge_vertex_id, index_t new_vertex_id ) { - return edges_->update_edge_vertex( - std::move( edge_vertices ), edge_vertex_id, new_vertex_id, {} ); + return edges_->update_edge_vertex( std::move( edge_vertices ), + edge_vertex_id, new_vertex_id, + typename SolidEdges< dimension >::SolidEdgesKey() ); } template < index_t dimension > void SolidEdgesBuilder< dimension >::update_edge_vertices( absl::Span< const index_t > old2new ) { - edges_->update_edge_vertices( old2new, {} ); + edges_->update_edge_vertices( + old2new, typename SolidEdges< dimension >::SolidEdgesKey() ); } template < index_t dimension > @@ -87,14 +92,16 @@ namespace geode nullptr, OpenGeodeException::TYPE::data, "[SolidEdgesBuilder::copy] Cannot copy a mesh into an already " "initialized mesh." ); - edges_->overwrite_edges( edges, {} ); + edges_->overwrite_edges( + edges, typename SolidEdges< dimension >::SolidEdgesKey() ); } template < index_t dimension > std::vector< index_t > SolidEdgesBuilder< dimension >::delete_edges( const std::vector< bool >& to_delete ) { - return edges_->delete_edges( to_delete, {} ); + return edges_->delete_edges( + to_delete, typename SolidEdges< dimension >::SolidEdgesKey() ); } template class opengeode_mesh_api SolidEdgesBuilder< 3 >; diff --git a/src/geode/mesh/builder/solid_facets_builder.cpp b/src/geode/mesh/builder/solid_facets_builder.cpp index 3db2dc463..cd12be9be 100644 --- a/src/geode/mesh/builder/solid_facets_builder.cpp +++ b/src/geode/mesh/builder/solid_facets_builder.cpp @@ -42,14 +42,16 @@ namespace geode index_t SolidFacetsBuilder< dimension >::find_or_create_facet( PolyhedronFacetVertices facet_vertices ) { - return facets_->find_or_create_facet( std::move( facet_vertices ), {} ); + return facets_->find_or_create_facet( std::move( facet_vertices ), + typename SolidFacets< dimension >::SolidFacetsKey() ); } template < index_t dimension > std::vector< index_t > SolidFacetsBuilder< dimension >::delete_isolated_facets() { - return facets_->remove_isolated_facets( {} ); + return facets_->remove_isolated_facets( + typename SolidFacets< dimension >::SolidFacetsKey() ); } template < index_t dimension > @@ -57,7 +59,8 @@ namespace geode SolidFacetsBuilder< dimension >::update_facet_vertices( absl::Span< const index_t > old2new ) { - return facets_->update_facet_vertices( old2new, {} ); + return facets_->update_facet_vertices( + old2new, typename SolidFacets< dimension >::SolidFacetsKey() ); } template < index_t dimension > @@ -71,22 +74,25 @@ namespace geode facet_vertex_id < facet_vertices.size(), "[SolidFacetsBuilder::update_facet_vertex] " "Accessing an invalid vertex in facet" ); - return facets_->update_facet_vertex( - std::move( facet_vertices ), facet_vertex_id, new_vertex_id, {} ); + return facets_->update_facet_vertex( std::move( facet_vertices ), + facet_vertex_id, new_vertex_id, + typename SolidFacets< dimension >::SolidFacetsKey() ); } template < index_t dimension > void SolidFacetsBuilder< dimension >::remove_facet( PolyhedronFacetVertices facet_vertices ) { - facets_->remove_facet( std::move( facet_vertices ), {} ); + facets_->remove_facet( std::move( facet_vertices ), + typename SolidFacets< dimension >::SolidFacetsKey() ); } template < index_t dimension > std::vector< index_t > SolidFacetsBuilder< dimension >::delete_facets( const std::vector< bool >& to_delete ) { - return facets_->delete_facets( to_delete, {} ); + return facets_->delete_facets( + to_delete, typename SolidFacets< dimension >::SolidFacetsKey() ); } template < index_t dimension > @@ -97,7 +103,8 @@ namespace geode nullptr, OpenGeodeException::TYPE::data, "[SolidFacetsBuilder::copy] Cannot copy a mesh into an already " "initialized mesh." ); - facets_->overwrite_facets( facets, {} ); + facets_->overwrite_facets( + facets, typename SolidFacets< dimension >::SolidFacetsKey() ); } template class opengeode_mesh_api SolidFacetsBuilder< 3 >; diff --git a/src/geode/mesh/builder/solid_mesh_builder.cpp b/src/geode/mesh/builder/solid_mesh_builder.cpp index 1b7b307f4..d95341e6e 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 > @@ -625,7 +647,8 @@ namespace geode void SolidMeshBuilder< dimension >::reset_polyhedra_around_vertex( index_t vertex_id ) { - solid_mesh_.reset_polyhedra_around_vertex( vertex_id, {} ); + solid_mesh_.reset_polyhedra_around_vertex( + vertex_id, typename SolidMesh< dimension >::SolidMeshKey{} ); } template < index_t dimension > @@ -640,8 +663,8 @@ namespace geode polyhedron_vertex.vertex_id != NO_ID, "[SolidMeshBuilder::associate_polyhedron_vertex_to_vertex] " "PolyhedronVertex invalid" ); - solid_mesh_.associate_polyhedron_vertex_to_vertex( - polyhedron_vertex, vertex_id, {} ); + solid_mesh_.associate_polyhedron_vertex_to_vertex( polyhedron_vertex, + vertex_id, typename SolidMesh< dimension >::SolidMeshKey{} ); } template < index_t dimension > @@ -649,8 +672,8 @@ namespace geode SolidMeshBuilder< dimension >::disassociate_polyhedron_vertex_to_vertex( index_t vertex_id ) { - solid_mesh_.associate_polyhedron_vertex_to_vertex( - PolyhedronVertex{}, vertex_id, {} ); + solid_mesh_.associate_polyhedron_vertex_to_vertex( PolyhedronVertex{}, + vertex_id, typename SolidMesh< dimension >::SolidMeshKey{} ); } template < index_t dimension > @@ -776,7 +799,8 @@ namespace geode SolidEdgesBuilder< dimension > SolidMeshBuilder< dimension >::edges_builder() { - return SolidEdgesBuilder< dimension >{ solid_mesh_.edges( {} ) }; + return SolidEdgesBuilder< dimension >{ solid_mesh_.edges( + typename SolidMesh< dimension >::SolidMeshKey{} ) }; } template < index_t dimension > @@ -840,7 +864,8 @@ namespace geode SolidFacetsBuilder< dimension > SolidMeshBuilder< dimension >::facets_builder() { - return SolidFacetsBuilder< dimension >{ solid_mesh_.facets( {} ) }; + return SolidFacetsBuilder< dimension >{ solid_mesh_.facets( + typename SolidMesh< dimension >::SolidMeshKey{} ) }; } template < index_t dimension > @@ -958,25 +983,19 @@ 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() ) { - solid_mesh_.copy_edges( solid_mesh, {} ); + solid_mesh_.copy_edges( + solid_mesh, typename SolidMesh< dimension >::SolidMeshKey{} ); } if( solid_mesh.are_facets_enabled() ) { - solid_mesh_.copy_facets( solid_mesh, {} ); + solid_mesh_.copy_facets( + solid_mesh, typename SolidMesh< dimension >::SolidMeshKey{} ); } } diff --git a/src/geode/mesh/builder/surface_edges_builder.cpp b/src/geode/mesh/builder/surface_edges_builder.cpp index 046f1cd81..2483fd6c5 100644 --- a/src/geode/mesh/builder/surface_edges_builder.cpp +++ b/src/geode/mesh/builder/surface_edges_builder.cpp @@ -38,14 +38,16 @@ namespace geode std::vector< index_t > SurfaceEdgesBuilder< dimension >::delete_isolated_edges() { - return edges_->remove_isolated_edges( {} ); + return edges_->remove_isolated_edges( + typename SurfaceEdges< dimension >::SurfaceEdgesKey() ); } template < index_t dimension > void SurfaceEdgesBuilder< dimension >::update_edge_vertices( absl::Span< const index_t > old2new ) { - edges_->update_edge_vertices( old2new, {} ); + edges_->update_edge_vertices( + old2new, typename SurfaceEdges< dimension >::SurfaceEdgesKey() ); } template < index_t dimension > @@ -58,15 +60,17 @@ namespace geode OpenGeodeMeshException::check_assertion( edge_vertex_id < 2, "[SurfaceEdgesBuilder::update_edge_vertex] " "Accessing an invalid vertex in edge" ); - return edges_->update_edge_vertex( - std::move( edge_vertices ), edge_vertex_id, new_vertex_id, {} ); + return edges_->update_edge_vertex( std::move( edge_vertices ), + edge_vertex_id, new_vertex_id, + typename SurfaceEdges< dimension >::SurfaceEdgesKey() ); } template < index_t dimension > std::vector< index_t > SurfaceEdgesBuilder< dimension >::delete_edges( const std::vector< bool >& to_delete ) { - return edges_->delete_edges( to_delete, {} ); + return edges_->delete_edges( + to_delete, typename SurfaceEdges< dimension >::SurfaceEdgesKey() ); } template < index_t dimension > @@ -77,21 +81,24 @@ namespace geode nullptr, OpenGeodeException::TYPE::data, "[SurfaceEdgesBuilder::copy] Cannot copy a mesh into an already " "initialized mesh." ); - edges_->overwrite_edges( edges, {} ); + edges_->overwrite_edges( + edges, typename SurfaceEdges< dimension >::SurfaceEdgesKey() ); } template < index_t dimension > void SurfaceEdgesBuilder< dimension >::remove_edge( std::array< index_t, 2 > edge_vertices ) { - edges_->remove_edge( std::move( edge_vertices ), {} ); + edges_->remove_edge( std::move( edge_vertices ), + typename SurfaceEdges< dimension >::SurfaceEdgesKey() ); } template < index_t dimension > index_t SurfaceEdgesBuilder< dimension >::find_or_create_edge( std::array< index_t, 2 > edge_vertices ) { - return edges_->find_or_create_edge( std::move( edge_vertices ), {} ); + return edges_->find_or_create_edge( std::move( edge_vertices ), + typename SurfaceEdges< dimension >::SurfaceEdgesKey() ); } template class opengeode_mesh_api SurfaceEdgesBuilder< 2 >; diff --git a/src/geode/mesh/builder/surface_mesh_builder.cpp b/src/geode/mesh/builder/surface_mesh_builder.cpp index 778ce2f2f..eb752820b 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 > @@ -386,7 +397,8 @@ namespace geode void SurfaceMeshBuilder< dimension >::reset_polygons_around_vertex( index_t vertex_id ) { - surface_mesh_.reset_polygons_around_vertex( vertex_id, {} ); + surface_mesh_.reset_polygons_around_vertex( + vertex_id, typename SurfaceMesh< dimension >::SurfaceMeshKey{} ); } template < index_t dimension > @@ -401,16 +413,16 @@ namespace geode polygon_vertex.vertex_id != NO_LID, "[SurfaceMeshBuilder::associate_polygon_vertex_to_vertex] " "PolygonVertex invalid" ); - surface_mesh_.associate_polygon_vertex_to_vertex( - polygon_vertex, vertex_id, {} ); + surface_mesh_.associate_polygon_vertex_to_vertex( polygon_vertex, + vertex_id, typename SurfaceMesh< dimension >::SurfaceMeshKey{} ); } template < index_t dimension > void SurfaceMeshBuilder< dimension >::disassociate_polygon_vertex_to_vertex( index_t vertex_id ) { - surface_mesh_.associate_polygon_vertex_to_vertex( - PolygonVertex{}, vertex_id, {} ); + surface_mesh_.associate_polygon_vertex_to_vertex( PolygonVertex{}, + vertex_id, typename SurfaceMesh< dimension >::SurfaceMeshKey{} ); } template < index_t dimension > @@ -716,7 +728,8 @@ namespace geode SurfaceEdgesBuilder< dimension > SurfaceMeshBuilder< dimension >::edges_builder() { - return SurfaceEdgesBuilder< dimension >{ surface_mesh_.edges( {} ) }; + return SurfaceEdgesBuilder< dimension >{ surface_mesh_.edges( + typename SurfaceMesh< dimension >::SurfaceMeshKey{} ) }; } template < index_t dimension > @@ -832,22 +845,15 @@ 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_polygons( surface_mesh, *this ); + if( surface_mesh.are_edges_enabled() ) { - copy_points( surface_mesh, *this ); - copy_polygons( surface_mesh, *this ); + surface_mesh_.copy_edges( surface_mesh, + typename SurfaceMesh< dimension >::SurfaceMeshKey{} ); } surface_mesh_.polygon_attribute_manager().copy( surface_mesh.polygon_attribute_manager() ); - if( surface_mesh.are_edges_enabled() ) - { - surface_mesh_.copy_edges( surface_mesh, {} ); - } + copy_points( surface_mesh, *this ); } template class opengeode_mesh_api SurfaceMeshBuilder< 2 >; 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..a36703942 100644 --- a/src/geode/mesh/core/geode/geode_tetrahedral_solid.cpp +++ b/src/geode/mesh/core/geode/geode_tetrahedral_solid.cpp @@ -37,33 +37,49 @@ #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 ); + AttributeProperties attribute_properties; + attribute_properties.assignable = false; + attribute_properties.interpolable = false; + attribute_properties.transferable = false; + AttributeValues< std::array< index_t, 4 > > attribute_values; + attribute_values.default_value = { NO_ID, NO_ID, NO_ID, NO_ID }; + attribute_values.no_value = { NO_ID, NO_ID, NO_ID, NO_ID }; + const auto tetrahedron_vertices_id = + mesh.polyhedron_attribute_manager() + .template create_attribute< VariableAttribute, + std::array< index_t, 4 > >( "tetrahedron_vertices", + attribute_values, attribute_properties ); + 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", + attribute_values, attribute_properties ); + 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 +139,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 +167,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 +189,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 +209,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 +244,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..cef832922 100644 --- a/src/geode/mesh/core/geode/geode_triangulated_surface.cpp +++ b/src/geode/mesh/core/geode/geode_triangulated_surface.cpp @@ -35,31 +35,49 @@ #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 ); + AttributeProperties attribute_properties; + attribute_properties.assignable = false; + attribute_properties.interpolable = false; + attribute_properties.transferable = false; + AttributeValues< std::array< index_t, 3 > > attribute_values; + attribute_values.default_value = { NO_ID, NO_ID, NO_ID }; + attribute_values.no_value = { NO_ID, NO_ID, NO_ID }; + const auto triangle_vertices_id = + mesh.polygon_attribute_manager() + .template create_attribute< VariableAttribute, + std::array< index_t, 3 > >( "triangle_vertices", + attribute_values, attribute_properties ); + 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", + attribute_values, attribute_properties ); + 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 +126,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 +152,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 +174,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 +194,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 +222,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..2eaaf07e1 100644 --- a/src/geode/mesh/core/graph.cpp +++ b/src/geode/mesh/core/graph.cpp @@ -47,14 +47,27 @@ 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 } ) ) { + AttributeProperties attribute_properties; + attribute_properties.assignable = false; + attribute_properties.interpolable = false; + attribute_properties.transferable = false; + AttributeValues< EdgesAroundVertex > edges_around_vertex_values; + edges_around_vertex_values.default_value = EdgesAroundVertex{}; + edges_around_vertex_values.no_value = EdgesAroundVertex{}; + const auto attribute_id = + graph.vertex_attribute_manager() + .template create_attribute< VariableAttribute, + EdgesAroundVertex >( ATTRIBUTE_NAME, + edges_around_vertex_values, attribute_properties ); + 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 +121,6 @@ namespace geode } private: - Impl() = default; - template < typename Archive > void serialize( Archive& serializer ) { @@ -159,6 +170,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..489cf2f48 100644 --- a/src/geode/mesh/core/solid_mesh.cpp +++ b/src/geode/mesh/core/solid_mesh.cpp @@ -435,17 +435,27 @@ 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 } ) ) { + AttributeProperties attribute_properties; + attribute_properties.assignable = false; + attribute_properties.interpolable = false; + attribute_properties.transferable = false; + AttributeValues< PolyhedronVertex > polyhedron_around_vertex_values; + polyhedron_around_vertex_values.default_value = PolyhedronVertex{}; + polyhedron_around_vertex_values.no_value = PolyhedronVertex{}; + const auto attribute_id = + solid.vertex_attribute_manager() + .template create_attribute< VariableAttribute, + PolyhedronVertex >( "polyhedron_around_vertex", + polyhedron_around_vertex_values, attribute_properties ); + polyhedron_around_vertex_ = + solid.vertex_attribute_manager() + .template find_attribute< VariableAttribute, + PolyhedronVertex >( attribute_id ); initialize_polyhedra_around_vertex( solid ); } @@ -678,11 +688,22 @@ namespace geode void initialize_polyhedra_around_vertex( const SolidMesh< dimension >& solid ) { - polyhedra_around_vertex_ = + AttributeProperties attribute_properties; + attribute_properties.assignable = false; + attribute_properties.interpolable = false; + attribute_properties.transferable = false; + AttributeValues< CachedPolyhedra > polyhedron_around_vertex_values; + polyhedron_around_vertex_values.default_value = CachedPolyhedra{}; + polyhedron_around_vertex_values.no_value = CachedPolyhedra{}; + 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 } ); + polyhedron_around_vertex_values, attribute_properties ); + polyhedra_around_vertex_ = + solid.vertex_attribute_manager() + .template find_attribute< VariableAttribute, + CachedPolyhedra >( attribute_id ); } const internal::PolyhedraAroundVertexImpl& @@ -705,9 +726,9 @@ namespace geode return cached.value(); } - private: Impl() = default; + private: template < typename Archive > void serialize( Archive& serializer ) { @@ -823,6 +844,11 @@ namespace geode { } + template < index_t dimension > + SolidMesh< dimension >::SolidMesh( BITSERY ) + { + } + template < index_t dimension > SolidMesh< dimension >::SolidMesh( SolidMesh&& ) noexcept = default; @@ -1735,8 +1761,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 5d6c77054..483c39b57 100644 --- a/src/geode/mesh/core/surface_mesh.cpp +++ b/src/geode/mesh/core/surface_mesh.cpp @@ -284,12 +284,23 @@ 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 } ) ) { + AttributeProperties attribute_properties; + attribute_properties.assignable = false; + attribute_properties.interpolable = false; + attribute_properties.transferable = false; + AttributeValues< PolygonVertex > polygon_around_vertex_values; + polygon_around_vertex_values.default_value = PolygonVertex{}; + polygon_around_vertex_values.no_value = PolygonVertex{}; + const auto attribute_id = + surface.vertex_attribute_manager() + .template create_attribute< VariableAttribute, + PolygonVertex >( "polygon_around_vertex", + polygon_around_vertex_values, attribute_properties ); + polygon_around_vertex_ = + surface.vertex_attribute_manager() + .template find_attribute< VariableAttribute, + PolygonVertex >( attribute_id ); initialize_polygons_around_vertex( surface ); } @@ -387,7 +398,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 +406,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 +443,27 @@ namespace geode void initialize_polygons_around_vertex( const SurfaceMesh< dimension >& surface ) { - polygons_around_vertex_ = + AttributeProperties attribute_properties; + attribute_properties.assignable = false; + attribute_properties.interpolable = false; + attribute_properties.transferable = false; + AttributeValues< CachedPolygons > polygon_around_vertex_values; + polygon_around_vertex_values.default_value = CachedPolygons{}; + polygon_around_vertex_values.no_value = CachedPolygons{}; + 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 } ); + polygon_around_vertex_values, attribute_properties ); + 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 +587,11 @@ namespace geode { } + template < index_t dimension > + SurfaceMesh< dimension >::SurfaceMesh( BITSERY ) + { + } + template < index_t dimension > SurfaceMesh< dimension >::SurfaceMesh( SurfaceMesh&& ) noexcept = default; @@ -1091,9 +1118,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..fc1e164ef 100644 --- a/src/geode/mesh/core/texture_manager.cpp +++ b/src/geode/mesh/core/texture_manager.cpp @@ -48,33 +48,42 @@ namespace geode index_t nb_textures() const { - return textures_.nb_textures( {} ); + return textures_.nb_textures( + typename TextureStorage< dimension >::TextureManagerKey{} ); } Texture< dimension >& find_or_create_texture( std::string_view name ) { - return textures_.find_or_create_texture( manager_, name, {} ); + return textures_.find_or_create_texture( manager_, name, + typename TextureStorage< dimension >::TextureManagerKey{} ); } const Texture< dimension >& find_texture( std::string_view name ) const { - return textures_.find_texture( name, {} ); + return textures_.find_texture( name, + typename TextureStorage< dimension >::TextureManagerKey{} ); } absl::FixedArray< std::string_view > texture_names() const { - return textures_.texture_names( {} ); + return textures_.texture_names( + typename TextureStorage< dimension >::TextureManagerKey{} ); } bool texture_exists( std::string_view name ) const { - return textures_.texture_exists( name, {} ); + return textures_.texture_exists( name, + typename TextureStorage< dimension >::TextureManagerKey{} ); } void delete_texture( std::string_view name ) { - textures_.delete_texture( name, {} ); - manager_.delete_attribute( name ); + const auto& texture = textures_.find_texture( name, + typename TextureStorage< dimension >::TextureManagerKey{} ); + const auto texture_id = texture.texture_id(); + textures_.delete_texture( name, + typename TextureStorage< dimension >::TextureManagerKey{} ); + 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/core/vertex_set.cpp b/src/geode/mesh/core/vertex_set.cpp index 131ab3506..8fb717eef 100644 --- a/src/geode/mesh/core/vertex_set.cpp +++ b/src/geode/mesh/core/vertex_set.cpp @@ -110,7 +110,7 @@ namespace geode auto clone = create( impl_name() ); auto builder = VertexSetBuilder::create( *clone ); builder->copy_identifier( *this ); - builder->copy( *this, {} ); + builder->copy( *this, VertexSetBuilder::VertexSetKey{} ); return clone; } diff --git a/src/geode/mesh/helpers/convert_grid.cpp b/src/geode/mesh/helpers/convert_grid.cpp index ff8df0b11..5ba94404d 100644 --- a/src/geode/mesh/helpers/convert_grid.cpp +++ b/src/geode/mesh/helpers/convert_grid.cpp @@ -51,9 +51,21 @@ 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", {} ); + AttributeProperties attribute_properties; + attribute_properties.assignable = false; + attribute_properties.interpolable = false; + attribute_properties.transferable = true; + AttributeValues< RGBColor > color_values; + color_values.default_value = RGBColor{}; + color_values.no_value = RGBColor{}; + auto color_attribute_id = + grid.cell_attribute_manager() + .template create_attribute< VariableAttribute, RGBColor >( + "RGB_data", color_values, attribute_properties ); + 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/detail/surface_merger.cpp b/src/geode/mesh/helpers/detail/surface_merger.cpp index f3d3b2655..e27d56de9 100644 --- a/src/geode/mesh/helpers/detail/surface_merger.cpp +++ b/src/geode/mesh/helpers/detail/surface_merger.cpp @@ -140,7 +140,7 @@ namespace geode } catch( const OpenGeodeException& e ) { - Logger::warn( e.what() ); + Logger::warning( e.what() ); } } diff --git a/src/geode/mesh/helpers/euclidean_distance_transform.cpp b/src/geode/mesh/helpers/euclidean_distance_transform.cpp index 940e86cb4..8f1f697cb 100644 --- a/src/geode/mesh/helpers/euclidean_distance_transform.cpp +++ b/src/geode/mesh/helpers/euclidean_distance_transform.cpp @@ -41,13 +41,25 @@ 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_{} { + AttributeProperties attribute_properties; + attribute_properties.assignable = false; + attribute_properties.interpolable = false; + attribute_properties.transferable = true; + AttributeValues< double > distance_map_values; + distance_map_values.default_value = + std::numeric_limits< double >::max(); + distance_map_values.no_value = std::numeric_limits< double >::max(); + const auto distance_map_id = + grid.cell_attribute_manager() + .template create_attribute< VariableAttribute, double >( + distance_map_name, distance_map_values, + attribute_properties ); + 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..a5c7efffe 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,39 @@ 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 { + geode::AttributeProperties attribute_properties; + attribute_properties.assignable = false; + attribute_properties.interpolable = false; + attribute_properties.transferable = true; + geode::AttributeValues< geode::Vector< Mesh::dim > > + distance_map_values; + distance_map_values.default_value = geode::Vector< Mesh::dim >{}; + distance_map_values.no_value = geode::Vector< Mesh::dim >{}; + 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, + distance_map_values, attribute_properties ); 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 +96,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 +200,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 +207,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..f637f6bcf 100644 --- a/src/geode/mesh/helpers/grid_point_function.cpp +++ b/src/geode/mesh/helpers/grid_point_function.cpp @@ -44,33 +44,46 @@ 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." ); + AttributeProperties attribute_properties; + attribute_properties.assignable = false; + attribute_properties.interpolable = true; + attribute_properties.transferable = true; + AttributeValues< Point< point_dimension > > + function_attribute_values; + function_attribute_values.default_value = value; + function_attribute_values.no_value = Point< point_dimension >{}; + const auto function_id = + grid_.grid_vertex_attribute_manager() + .template create_attribute< VariableAttribute, + Point< point_dimension > >( function_name, + function_attribute_values, attribute_properties ); function_attribute_ = grid_.grid_vertex_attribute_manager() - .template find_or_create_attribute< VariableAttribute, - Point< point_dimension > >( - function_name, std::move( value ), { false, true } ); + .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." ); + AttributeProperties attribute_properties; + attribute_properties.assignable = false; + attribute_properties.interpolable = true; + attribute_properties.transferable = true; + AttributeValues< Point< point_dimension > > + function_attribute_values; + function_attribute_values.default_value = + Point< point_dimension >{}; + function_attribute_values.no_value = Point< point_dimension >{}; + const auto attribute_id = + grid_.grid_vertex_attribute_manager() + .template create_attribute< VariableAttribute, + Point< point_dimension > >( attribute_name, + function_attribute_values, attribute_properties ); function_attribute_ = grid_.grid_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 > >( 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..c77b302dd 100644 --- a/src/geode/mesh/helpers/grid_scalar_function.cpp +++ b/src/geode/mesh/helpers/grid_scalar_function.cpp @@ -44,31 +44,32 @@ 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." ); + AttributeProperties attribute_properties; + attribute_properties.assignable = false; + attribute_properties.interpolable = true; + attribute_properties.transferable = true; + AttributeValues< double > function_attribute_values; + function_attribute_values.default_value = value; + function_attribute_values.no_value = + std::numeric_limits< double >::max(); + const auto function_id = + grid_.grid_vertex_attribute_manager() + .template create_attribute< VariableAttribute, double >( + function_name, function_attribute_values, + attribute_properties ); 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 ) + Impl( const Grid< dimension >& grid, const uuid& function_id ) : 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." ); 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( @@ -134,8 +135,8 @@ namespace geode template < index_t dimension > GridScalarFunction< dimension >::GridScalarFunction( - const Grid< dimension >& grid, std::string_view function_name ) - : impl_{ grid, function_name } + const Grid< dimension >& grid, const uuid& function_id ) + : impl_{ grid, function_id } { } @@ -153,9 +154,9 @@ namespace geode template < index_t dimension > GridScalarFunction< dimension > GridScalarFunction< dimension >::find( - const Grid< dimension >& grid, std::string_view function_name ) + const Grid< dimension >& grid, const uuid& function_id ) { - return { grid, function_name }; + return { grid, function_id }; } template < index_t dimension > diff --git a/src/geode/mesh/helpers/repair_polygon_orientations.cpp b/src/geode/mesh/helpers/repair_polygon_orientations.cpp index 4d9aa373a..e31726f4d 100644 --- a/src/geode/mesh/helpers/repair_polygon_orientations.cpp +++ b/src/geode/mesh/helpers/repair_polygon_orientations.cpp @@ -158,30 +158,30 @@ namespace { polygons_area_sign_info( geode::index_t nb_init, geode::index_t nb_polygons, - geode::Sign sign_init ) + geode::SIGN sign_init ) : nb_bad_polygons{ nb_init }, area_sign{ nb_polygons, sign_init } { } geode::index_t nb_bad_polygons; std::queue< geode::index_t > queue; - absl::FixedArray< geode::Sign > area_sign; + absl::FixedArray< geode::SIGN > area_sign; }; polygons_area_sign_info compute_polygon_area_sign( const geode::SurfaceMesh2D& mesh ) { polygons_area_sign_info area_sign_info{ 0, mesh.nb_polygons(), - geode::Sign::zero }; + geode::SIGN::zero }; for( const auto polygon_id : geode::Range{ mesh.nb_polygons() } ) { area_sign_info.area_sign[polygon_id] = geode::polygon_area_sign( mesh.polygon( polygon_id ) ); - if( area_sign_info.area_sign[polygon_id] == geode::Sign::negative ) + if( area_sign_info.area_sign[polygon_id] == geode::SIGN::negative ) { area_sign_info.nb_bad_polygons++; } - else if( area_sign_info.area_sign[polygon_id] == geode::Sign::zero ) + else if( area_sign_info.area_sign[polygon_id] == geode::SIGN::zero ) { area_sign_info.queue.emplace( polygon_id ); } @@ -211,7 +211,7 @@ namespace } const auto adj = mesh.polygon_adjacent_edge( edge ).value(); if( area_sign_info.area_sign[adj.polygon_id] - == geode::Sign::zero ) + == geode::SIGN::zero ) { continue; } @@ -227,24 +227,24 @@ namespace break; } if( area_sign_info.area_sign[adj.polygon_id] - == geode::Sign::positive ) + == geode::SIGN::positive ) { area_sign_info.area_sign[cur_polygon] = - geode::Sign::negative; + geode::SIGN::negative; } else { area_sign_info.area_sign[cur_polygon] = - geode::Sign::positive; + geode::SIGN::positive; } break; } - if( area_sign_info.area_sign[cur_polygon] == geode::Sign::zero ) + if( area_sign_info.area_sign[cur_polygon] == geode::SIGN::zero ) { area_sign_info.queue.emplace( cur_polygon ); } else if( area_sign_info.area_sign[cur_polygon] - == geode::Sign::negative ) + == geode::SIGN::negative ) { area_sign_info.nb_bad_polygons++; } @@ -267,7 +267,7 @@ namespace geode::index_t count{ 0 }; for( const auto p : geode::Range{ mesh.nb_polygons() } ) { - if( area_sign_info.area_sign[p] == geode::Sign::negative ) + if( area_sign_info.area_sign[p] == geode::SIGN::negative ) { bad_polygons[count++] = p; } diff --git a/src/geode/mesh/helpers/tetrahedral_solid_point_function.cpp b/src/geode/mesh/helpers/tetrahedral_solid_point_function.cpp index 00e1f07ee..6030d3efd 100644 --- a/src/geode/mesh/helpers/tetrahedral_solid_point_function.cpp +++ b/src/geode/mesh/helpers/tetrahedral_solid_point_function.cpp @@ -41,39 +41,36 @@ namespace geode public: Impl( const TetrahedralSolid< dimension >& solid, std::string_view function_name, + const uuid& function_id, 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." ); + AttributeProperties attribute_properties; + attribute_properties.assignable = false; + attribute_properties.interpolable = true; + attribute_properties.transferable = true; + AttributeValues< Point< point_dimension > > + function_attribute_values; + function_attribute_values.default_value = value; + function_attribute_values.no_value = Point< point_dimension >{}; + solid_.vertex_attribute_manager() + .template create_attribute< VariableAttribute, + Point< point_dimension > >( function_name, function_id, + function_attribute_values, attribute_properties ); function_attribute_ = solid_.vertex_attribute_manager() - .template find_or_create_attribute< VariableAttribute, - Point< point_dimension > >( - function_name, std::move( value ), { false, true } ); + .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 +101,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 > > > @@ -124,8 +126,9 @@ namespace geode TetrahedralSolidPointFunction( const TetrahedralSolid< dimension >& solid, std::string_view function_name, + const uuid& function_id, Point< point_dimension > value ) - : impl_{ solid, function_name, value } + : impl_{ solid, function_name, function_id, value } { } @@ -133,8 +136,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 } { } @@ -147,18 +150,19 @@ namespace geode TetrahedralSolidPointFunction< dimension, point_dimension >::create( const TetrahedralSolid< dimension >& solid, std::string_view function_name, + const uuid& function_id, Point< point_dimension > value ) { - return { solid, function_name, value }; + return { solid, function_name, function_id, value }; } template < index_t dimension, index_t point_dimension > 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 +188,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..8a162abef 100644 --- a/src/geode/mesh/helpers/tetrahedral_solid_scalar_function.cpp +++ b/src/geode/mesh/helpers/tetrahedral_solid_scalar_function.cpp @@ -40,37 +40,36 @@ namespace geode public: Impl( const TetrahedralSolid< dimension >& solid, std::string_view function_name, + const uuid& function_id, 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." ); + AttributeProperties attribute_properties; + attribute_properties.assignable = false; + attribute_properties.interpolable = true; + attribute_properties.transferable = true; + AttributeValues< double > function_attribute_values; + function_attribute_values.default_value = value; + function_attribute_values.no_value = + std::numeric_limits< double >::max(); + solid_.vertex_attribute_manager() + .template create_attribute< VariableAttribute, double >( + function_name, function_id, function_attribute_values, + attribute_properties ); 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 +100,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_; @@ -114,16 +118,16 @@ namespace geode TetrahedralSolidScalarFunction< dimension >::TetrahedralSolidScalarFunction( const TetrahedralSolid< dimension >& solid, std::string_view function_name, + const uuid& function_id, double value ) - : impl_{ solid, function_name, value } + : impl_{ solid, function_name, function_id, value } { } 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 } { } @@ -136,18 +140,19 @@ namespace geode TetrahedralSolidScalarFunction< dimension >::create( const TetrahedralSolid< dimension >& solid, std::string_view function_name, + const uuid& function_id, double value ) { - return { solid, function_name, value }; + return { solid, function_name, function_id, value }; } template < index_t dimension > 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 +176,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..0fb405c01 100644 --- a/src/geode/mesh/helpers/triangulated_surface_point_function.cpp +++ b/src/geode/mesh/helpers/triangulated_surface_point_function.cpp @@ -41,39 +41,36 @@ namespace geode public: Impl( const TriangulatedSurface< dimension >& surface, std::string_view function_name, + const uuid& function_id, 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." ); + AttributeProperties attribute_properties; + attribute_properties.assignable = false; + attribute_properties.interpolable = true; + attribute_properties.transferable = true; + AttributeValues< Point< point_dimension > > + function_attribute_values; + function_attribute_values.default_value = value; + function_attribute_values.no_value = Point< point_dimension >{}; + surface_.vertex_attribute_manager() + .template create_attribute< VariableAttribute, + Point< point_dimension > >( function_name, function_id, + function_attribute_values, attribute_properties ); function_attribute_ = surface_.vertex_attribute_manager() - .template find_or_create_attribute< VariableAttribute, - Point< point_dimension > >( - function_name, std::move( value ), { false, true } ); + .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 +101,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 > > > @@ -124,8 +126,9 @@ namespace geode TriangulatedSurfacePointFunction( const TriangulatedSurface< dimension >& surface, std::string_view function_name, + const uuid& function_id, Point< point_dimension > value ) - : impl_{ surface, function_name, value } + : impl_{ surface, function_name, function_id, value } { } @@ -133,8 +136,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 } { } @@ -147,18 +150,19 @@ namespace geode TriangulatedSurfacePointFunction< dimension, point_dimension >::create( const TriangulatedSurface< dimension >& surface, std::string_view function_name, + const uuid& function_id, Point< point_dimension > value ) { - return { surface, function_name, value }; + return { surface, function_name, function_id, value }; } template < index_t dimension, index_t point_dimension > 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 +189,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..95614fc03 100644 --- a/src/geode/mesh/helpers/triangulated_surface_scalar_function.cpp +++ b/src/geode/mesh/helpers/triangulated_surface_scalar_function.cpp @@ -41,37 +41,36 @@ namespace geode public: Impl( const TriangulatedSurface< dimension >& surface, std::string_view function_name, + const uuid& function_id, 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." ); + AttributeProperties attribute_properties; + attribute_properties.assignable = false; + attribute_properties.interpolable = true; + attribute_properties.transferable = true; + AttributeValues< double > function_attribute_values; + function_attribute_values.default_value = value; + function_attribute_values.no_value = + std::numeric_limits< double >::max(); + surface_.vertex_attribute_manager() + .template create_attribute< VariableAttribute, double >( + function_name, function_id, function_attribute_values, + attribute_properties ); 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 +101,11 @@ namespace geode return point_value; } + const uuid& attribute_function_id() const + { + return function_attribute_->id(); + } + private: const TriangulatedSurface< dimension >& surface_; std::shared_ptr< VariableAttribute< double > > function_attribute_; @@ -118,8 +122,9 @@ namespace geode TriangulatedSurfaceScalarFunction( const TriangulatedSurface< dimension >& surface, std::string_view function_name, + const uuid& function_id, double value ) - : impl_{ surface, function_name, value } + : impl_{ surface, function_name, function_id, value } { } @@ -127,8 +132,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 } { } @@ -141,18 +146,19 @@ namespace geode TriangulatedSurfaceScalarFunction< dimension >::create( const TriangulatedSurface< dimension >& surface, std::string_view function_name, + const uuid& function_id, double value ) { - return { surface, function_name, value }; + return { surface, function_name, function_id, value }; } template < index_t dimension > 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 +182,14 @@ namespace geode return impl_->value( point, triangle_id ); } + template < index_t dimension > + const 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/aabb_model_helpers.cpp b/src/geode/model/helpers/aabb_model_helpers.cpp index f8bae5a47..41235dfe4 100644 --- a/src/geode/model/helpers/aabb_model_helpers.cpp +++ b/src/geode/model/helpers/aabb_model_helpers.cpp @@ -57,7 +57,7 @@ namespace } if( nb_non_empty_elements < nb_elements ) { - geode::Logger::warn( absl::StrCat( "[create_model_aabb] ", + geode::Logger::warning( absl::StrCat( "[create_model_aabb] ", nb_elements - nb_non_empty_elements, " out of ", nb_elements, " components have empty meshes, not included in the " "AABBTree." ) ); diff --git a/src/geode/model/helpers/component_mensurations.cpp b/src/geode/model/helpers/component_mensurations.cpp index 656b008e4..1f416952b 100644 --- a/src/geode/model/helpers/component_mensurations.cpp +++ b/src/geode/model/helpers/component_mensurations.cpp @@ -175,7 +175,7 @@ namespace } if( grouped_sided_surfaces.size() > 1 ) { - geode::Logger::warn( block.component_id().string(), + geode::Logger::warning( block.component_id().string(), " has unconnected boundaries. This block has either " "topologically distinct parts or there are holes between the " "block boundary surfaces." ); 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/helpers/surface_radial_sort.cpp b/src/geode/model/helpers/surface_radial_sort.cpp index bc7e846ed..1ac3c3a03 100644 --- a/src/geode/model/helpers/surface_radial_sort.cpp +++ b/src/geode/model/helpers/surface_radial_sort.cpp @@ -211,8 +211,9 @@ namespace geode { if( edge_id == mesh.nb_edges() - 1 ) { - Logger::warn( "[surface_radial_sort] Degenerated polygons " - "has been found on all the edges of Line ", + Logger::warning( + "[surface_radial_sort] Degenerated polygons " + "has been found on all the edges of Line ", line.id().string(), ". The result of surface_radial_sort is not " "guaranteed." ); diff --git a/src/geode/model/mixin/builder/block_collections_builder.cpp b/src/geode/model/mixin/builder/block_collections_builder.cpp index d60a2b84a..a76499383 100644 --- a/src/geode/model/mixin/builder/block_collections_builder.cpp +++ b/src/geode/model/mixin/builder/block_collections_builder.cpp @@ -31,7 +31,9 @@ namespace geode template < index_t dimension > const uuid& BlockCollectionsBuilder< dimension >::create_block_collection() { - return block_collections_.create_block_collection( {} ); + return block_collections_.create_block_collection( + typename BlockCollections< + dimension >::BlockCollectionsBuilderKey{} ); } template < index_t dimension > @@ -39,37 +41,53 @@ namespace geode uuid block_collection_id ) { block_collections_.create_block_collection( - std::move( block_collection_id ), {} ); + std::move( block_collection_id ), + typename BlockCollections< + dimension >::BlockCollectionsBuilderKey{} ); } template < index_t dimension > void BlockCollectionsBuilder< dimension >::delete_block_collection( const BlockCollection< dimension >& collection ) { - block_collections_.delete_block_collection( collection, {} ); + block_collections_.delete_block_collection( + collection, typename BlockCollections< + dimension >::BlockCollectionsBuilderKey{} ); } template < index_t dimension > void BlockCollectionsBuilder< dimension >::load_block_collections( std::string_view directory ) { - return block_collections_.load_block_collections( directory, {} ); + return block_collections_.load_block_collections( + directory, typename BlockCollections< + dimension >::BlockCollectionsBuilderKey{} ); } template < index_t dimension > void BlockCollectionsBuilder< dimension >::set_block_collection_name( const uuid& id, std::string_view name ) { - block_collections_.modifiable_block_collection( id, {} ) - .set_block_collection_name( name, {} ); + block_collections_ + .modifiable_block_collection( + id, typename BlockCollections< + dimension >::BlockCollectionsBuilderKey{} ) + .set_block_collection_name( + name, typename BlockCollections< + dimension >::BlockCollectionsBuilderKey{} ); } template < index_t dimension > void BlockCollectionsBuilder< dimension >::set_block_collection_active( const uuid& id, bool active ) { - block_collections_.modifiable_block_collection( id, {} ) - .set_block_collection_active( active, {} ); + block_collections_ + .modifiable_block_collection( + id, typename BlockCollections< + dimension >::BlockCollectionsBuilderKey{} ) + .set_block_collection_active( + active, typename BlockCollections< + dimension >::BlockCollectionsBuilderKey{} ); } template class opengeode_model_api BlockCollectionsBuilder< 2 >; diff --git a/src/geode/model/mixin/builder/blocks_builder.cpp b/src/geode/model/mixin/builder/blocks_builder.cpp index b63663e1d..02abcf4ca 100644 --- a/src/geode/model/mixin/builder/blocks_builder.cpp +++ b/src/geode/model/mixin/builder/blocks_builder.cpp @@ -41,40 +41,49 @@ namespace geode template < index_t dimension > const uuid& BlocksBuilder< dimension >::create_block( const MeshImpl& impl ) { - return blocks_.create_block( impl, {} ); + return blocks_.create_block( + impl, typename Blocks< dimension >::BlocksBuilderKey{} ); } template < index_t dimension > void BlocksBuilder< dimension >::create_block( uuid block_id ) { - blocks_.create_block( std::move( block_id ), {} ); + blocks_.create_block( std::move( block_id ), + typename Blocks< dimension >::BlocksBuilderKey{} ); } template < index_t dimension > void BlocksBuilder< dimension >::create_block( uuid block_id, const MeshImpl& impl ) { - blocks_.create_block( std::move( block_id ), impl, {} ); + blocks_.create_block( std::move( block_id ), impl, + typename Blocks< dimension >::BlocksBuilderKey{} ); } template < index_t dimension > void BlocksBuilder< dimension >::delete_block( const Block< dimension >& block ) { - blocks_.delete_block( block, {} ); + blocks_.delete_block( + block, typename Blocks< dimension >::BlocksBuilderKey{} ); } template < index_t dimension > void BlocksBuilder< dimension >::load_blocks( std::string_view directory ) { - return blocks_.load_blocks( directory, {} ); + return blocks_.load_blocks( + directory, typename Blocks< dimension >::BlocksBuilderKey{} ); } template < index_t dimension > void BlocksBuilder< dimension >::set_block_name( const uuid& id, std::string_view name ) { - blocks_.modifiable_block( id, {} ).set_block_name( name, {} ); + blocks_ + .modifiable_block( + id, typename Blocks< dimension >::BlocksBuilderKey{} ) + .set_block_name( + name, typename Blocks< dimension >::BlocksBuilderKey{} ); block_mesh_builder( id )->set_name( name ); } @@ -82,31 +91,42 @@ namespace geode void BlocksBuilder< dimension >::set_block_active( const uuid& id, bool active ) { - blocks_.modifiable_block( id, {} ).set_block_active( active, {} ); + blocks_ + .modifiable_block( + id, typename Blocks< dimension >::BlocksBuilderKey{} ) + .set_block_active( + active, typename Blocks< dimension >::BlocksBuilderKey{} ); } template < index_t dimension > void BlocksBuilder< dimension >::set_block_mesh( const uuid& id, std::unique_ptr< SolidMesh< dimension > > mesh ) { - blocks_.modifiable_block( id, {} ).set_mesh( std::move( mesh ), - typename Block< dimension >::BlocksBuilderKey{} ); + blocks_ + .modifiable_block( + id, typename Blocks< dimension >::BlocksBuilderKey{} ) + .set_mesh( std::move( mesh ), + typename Block< dimension >::BlocksBuilderKey{} ); } template < index_t dimension > SolidMesh< dimension >& BlocksBuilder< dimension >::modifiable_block_mesh( const uuid& id ) { - return blocks_.modifiable_block( id, {} ).modifiable_mesh( - typename Block< dimension >::BlocksBuilderKey{} ); + return blocks_ + .modifiable_block( + id, typename Blocks< dimension >::BlocksBuilderKey{} ) + .modifiable_mesh( typename Block< dimension >::BlocksBuilderKey{} ); } template < index_t dimension > std::unique_ptr< SolidMesh< dimension > > BlocksBuilder< dimension >::steal_block_mesh( const uuid& id ) { - return blocks_.modifiable_block( id, {} ).steal_mesh( - typename Block< dimension >::BlocksBuilderKey{} ); + return blocks_ + .modifiable_block( + id, typename Blocks< dimension >::BlocksBuilderKey{} ) + .steal_mesh( typename Block< dimension >::BlocksBuilderKey{} ); } template class opengeode_model_api BlocksBuilder< 3 >; diff --git a/src/geode/model/mixin/builder/component_registry_builder.cpp b/src/geode/model/mixin/builder/component_registry_builder.cpp index 0eb05e62f..b3c7937c2 100644 --- a/src/geode/model/mixin/builder/component_registry_builder.cpp +++ b/src/geode/model/mixin/builder/component_registry_builder.cpp @@ -38,24 +38,28 @@ namespace geode void ComponentRegistryBuilder::add_mesh_component( const ComponentType& type, const uuid& id ) { - registry_.add_mesh_component( type, id, {} ); + registry_.add_mesh_component( + type, id, ComponentRegistry::RegistryBuilder{} ); } void ComponentRegistryBuilder::add_collection_component( const ComponentType& type, const uuid& id ) { - registry_.add_collection_component( type, id, {} ); + registry_.add_collection_component( + type, id, ComponentRegistry::RegistryBuilder{} ); } void ComponentRegistryBuilder::remove_mesh_component( const ComponentType& type, const uuid& id ) { - registry_.remove_mesh_component( type, id, {} ); + registry_.remove_mesh_component( + type, id, ComponentRegistry::RegistryBuilder{} ); } void ComponentRegistryBuilder::remove_collection_component( const ComponentType& type, const uuid& id ) { - registry_.remove_collection_component( type, id, {} ); + registry_.remove_collection_component( + type, id, ComponentRegistry::RegistryBuilder{} ); } } // namespace geode diff --git a/src/geode/model/mixin/builder/corner_collections_builder.cpp b/src/geode/model/mixin/builder/corner_collections_builder.cpp index 6d7e588bc..89b4d279d 100644 --- a/src/geode/model/mixin/builder/corner_collections_builder.cpp +++ b/src/geode/model/mixin/builder/corner_collections_builder.cpp @@ -32,7 +32,9 @@ namespace geode const uuid& CornerCollectionsBuilder< dimension >::create_corner_collection() { - return corner_collections_.create_corner_collection( {} ); + return corner_collections_.create_corner_collection( + typename CornerCollections< + dimension >::CornerCollectionsBuilderKey{} ); } template < index_t dimension > @@ -40,37 +42,53 @@ namespace geode uuid corner_collection_id ) { corner_collections_.create_corner_collection( - std::move( corner_collection_id ), {} ); + std::move( corner_collection_id ), + typename CornerCollections< + dimension >::CornerCollectionsBuilderKey{} ); } template < index_t dimension > void CornerCollectionsBuilder< dimension >::delete_corner_collection( const CornerCollection< dimension >& collection ) { - corner_collections_.delete_corner_collection( collection, {} ); + corner_collections_.delete_corner_collection( + collection, typename CornerCollections< + dimension >::CornerCollectionsBuilderKey{} ); } template < index_t dimension > void CornerCollectionsBuilder< dimension >::load_corner_collections( std::string_view directory ) { - return corner_collections_.load_corner_collections( directory, {} ); + return corner_collections_.load_corner_collections( + directory, typename CornerCollections< + dimension >::CornerCollectionsBuilderKey{} ); } template < index_t dimension > void CornerCollectionsBuilder< dimension >::set_corner_collection_name( const uuid& id, std::string_view name ) { - corner_collections_.modifiable_corner_collection( id, {} ) - .set_corner_collection_name( name, {} ); + corner_collections_ + .modifiable_corner_collection( + id, typename CornerCollections< + dimension >::CornerCollectionsBuilderKey{} ) + .set_corner_collection_name( + name, typename CornerCollections< + dimension >::CornerCollectionsBuilderKey{} ); } template < index_t dimension > void CornerCollectionsBuilder< dimension >::set_corner_collection_active( const uuid& id, bool active ) { - corner_collections_.modifiable_corner_collection( id, {} ) - .set_corner_collection_active( active, {} ); + corner_collections_ + .modifiable_corner_collection( + id, typename CornerCollections< + dimension >::CornerCollectionsBuilderKey{} ) + .set_corner_collection_active( + active, typename CornerCollections< + dimension >::CornerCollectionsBuilderKey{} ); } template class opengeode_model_api CornerCollectionsBuilder< 2 >; diff --git a/src/geode/model/mixin/builder/corners_builder.cpp b/src/geode/model/mixin/builder/corners_builder.cpp index f30299d81..03a629dd1 100644 --- a/src/geode/model/mixin/builder/corners_builder.cpp +++ b/src/geode/model/mixin/builder/corners_builder.cpp @@ -42,49 +42,60 @@ namespace geode const uuid& CornersBuilder< dimension >::create_corner( const MeshImpl& impl ) { - return corners_.create_corner( impl, {} ); + return corners_.create_corner( + impl, typename Corners< dimension >::CornersBuilderKey{} ); } template < index_t dimension > void CornersBuilder< dimension >::create_corner( uuid corner_id ) { - corners_.create_corner( std::move( corner_id ), {} ); + corners_.create_corner( std::move( corner_id ), + typename Corners< dimension >::CornersBuilderKey{} ); } template < index_t dimension > void CornersBuilder< dimension >::create_corner( uuid corner_id, const MeshImpl& impl ) { - corners_.create_corner( std::move( corner_id ), impl, {} ); + corners_.create_corner( std::move( corner_id ), impl, + typename Corners< dimension >::CornersBuilderKey{} ); } template < index_t dimension > void CornersBuilder< dimension >::delete_corner( const Corner< dimension >& corner ) { - corners_.delete_corner( corner, {} ); + corners_.delete_corner( + corner, typename Corners< dimension >::CornersBuilderKey{} ); } template < index_t dimension > void CornersBuilder< dimension >::load_corners( std::string_view directory ) { - return corners_.load_corners( directory, {} ); + return corners_.load_corners( + directory, typename Corners< dimension >::CornersBuilderKey{} ); } template < index_t dimension > std::unique_ptr< PointSetBuilder< dimension > > CornersBuilder< dimension >::corner_mesh_builder( const uuid& id ) { - return PointSetBuilder< dimension >::create( - corners_.modifiable_corner( id, {} ).modifiable_mesh( - typename Corner< dimension >::CornersBuilderKey{} ) ); + return PointSetBuilder< dimension >::create( corners_ + .modifiable_corner( + id, typename Corners< dimension >::CornersBuilderKey{} ) + .modifiable_mesh( + typename Corner< dimension >::CornersBuilderKey{} ) ); } template < index_t dimension > void CornersBuilder< dimension >::set_corner_name( const uuid& id, std::string_view name ) { - corners_.modifiable_corner( id, {} ).set_corner_name( name, {} ); + corners_ + .modifiable_corner( + id, typename Corners< dimension >::CornersBuilderKey{} ) + .set_corner_name( + name, typename Corners< dimension >::CornersBuilderKey{} ); corner_mesh_builder( id )->set_name( name ); } @@ -92,31 +103,43 @@ namespace geode void CornersBuilder< dimension >::set_corner_active( const uuid& id, bool active ) { - corners_.modifiable_corner( id, {} ).set_corner_active( active, {} ); + corners_ + .modifiable_corner( + id, typename Corners< dimension >::CornersBuilderKey{} ) + .set_corner_active( + active, typename Corners< dimension >::CornersBuilderKey{} ); } template < index_t dimension > void CornersBuilder< dimension >::set_corner_mesh( const uuid& id, std::unique_ptr< PointSet< dimension > > mesh ) { - corners_.modifiable_corner( id, {} ).set_mesh( std::move( mesh ), - typename Corner< dimension >::CornersBuilderKey{} ); + corners_ + .modifiable_corner( + id, typename Corners< dimension >::CornersBuilderKey{} ) + .set_mesh( std::move( mesh ), + typename Corner< dimension >::CornersBuilderKey{} ); } template < index_t dimension > PointSet< dimension >& CornersBuilder< dimension >::modifiable_corner_mesh( const uuid& id ) { - return corners_.modifiable_corner( id, {} ).modifiable_mesh( - typename Corner< dimension >::CornersBuilderKey{} ); + return corners_ + .modifiable_corner( + id, typename Corner< dimension >::CornersBuilderKey{} ) + .modifiable_mesh( + typename Corner< dimension >::CornersBuilderKey{} ); } template < index_t dimension > std::unique_ptr< PointSet< dimension > > CornersBuilder< dimension >::steal_corner_mesh( const uuid& id ) { - return corners_.modifiable_corner( id, {} ).steal_mesh( - typename Corner< dimension >::CornersBuilderKey{} ); + return corners_ + .modifiable_corner( + id, typename Corner< dimension >::CornersBuilderKey{} ) + .steal_mesh( typename Corner< dimension >::CornersBuilderKey{} ); } template class opengeode_model_api CornersBuilder< 2 >; diff --git a/src/geode/model/mixin/builder/line_collections_builder.cpp b/src/geode/model/mixin/builder/line_collections_builder.cpp index 3e1fa945b..c50a12fd8 100644 --- a/src/geode/model/mixin/builder/line_collections_builder.cpp +++ b/src/geode/model/mixin/builder/line_collections_builder.cpp @@ -31,7 +31,9 @@ namespace geode template < index_t dimension > const uuid& LineCollectionsBuilder< dimension >::create_line_collection() { - return line_collections_.create_line_collection( {} ); + return line_collections_.create_line_collection( + typename LineCollections< + dimension >::LineCollectionsBuilderKey{} ); } template < index_t dimension > @@ -39,37 +41,53 @@ namespace geode uuid line_collection_id ) { line_collections_.create_line_collection( - std::move( line_collection_id ), {} ); + std::move( line_collection_id ), + typename LineCollections< + dimension >::LineCollectionsBuilderKey{} ); } template < index_t dimension > void LineCollectionsBuilder< dimension >::delete_line_collection( const LineCollection< dimension >& collection ) { - line_collections_.delete_line_collection( collection, {} ); + line_collections_.delete_line_collection( + collection, typename LineCollections< + dimension >::LineCollectionsBuilderKey{} ); } template < index_t dimension > void LineCollectionsBuilder< dimension >::load_line_collections( std::string_view directory ) { - return line_collections_.load_line_collections( directory, {} ); + return line_collections_.load_line_collections( + directory, typename LineCollections< + dimension >::LineCollectionsBuilderKey{} ); } template < index_t dimension > void LineCollectionsBuilder< dimension >::set_line_collection_name( const uuid& id, std::string_view name ) { - line_collections_.modifiable_line_collection( id, {} ) - .set_line_collection_name( name, {} ); + line_collections_ + .modifiable_line_collection( + id, typename LineCollections< + dimension >::LineCollectionsBuilderKey{} ) + .set_line_collection_name( + name, typename LineCollections< + dimension >::LineCollectionsBuilderKey{} ); } template < index_t dimension > void LineCollectionsBuilder< dimension >::set_line_collection_active( const uuid& id, bool active ) { - line_collections_.modifiable_line_collection( id, {} ) - .set_line_collection_active( active, {} ); + line_collections_ + .modifiable_line_collection( + id, typename LineCollections< + dimension >::LineCollectionsBuilderKey{} ) + .set_line_collection_active( + active, typename LineCollections< + dimension >::LineCollectionsBuilderKey{} ); } template class opengeode_model_api LineCollectionsBuilder< 2 >; diff --git a/src/geode/model/mixin/builder/lines_builder.cpp b/src/geode/model/mixin/builder/lines_builder.cpp index 255849ec7..899c85600 100644 --- a/src/geode/model/mixin/builder/lines_builder.cpp +++ b/src/geode/model/mixin/builder/lines_builder.cpp @@ -41,48 +41,59 @@ namespace geode template < index_t dimension > const uuid& LinesBuilder< dimension >::create_line( const MeshImpl& impl ) { - return lines_.create_line( impl, {} ); + return lines_.create_line( + impl, typename Lines< dimension >::LinesBuilderKey{} ); } template < index_t dimension > void LinesBuilder< dimension >::create_line( uuid line_id ) { - lines_.create_line( std::move( line_id ), {} ); + lines_.create_line( std::move( line_id ), + typename Lines< dimension >::LinesBuilderKey{} ); } template < index_t dimension > void LinesBuilder< dimension >::create_line( uuid line_id, const MeshImpl& impl ) { - lines_.create_line( std::move( line_id ), impl, {} ); + lines_.create_line( std::move( line_id ), impl, + typename Lines< dimension >::LinesBuilderKey{} ); } template < index_t dimension > void LinesBuilder< dimension >::delete_line( const Line< dimension >& line ) { - lines_.delete_line( line, {} ); + lines_.delete_line( + line, typename Lines< dimension >::LinesBuilderKey{} ); } template < index_t dimension > void LinesBuilder< dimension >::load_lines( std::string_view directory ) { - return lines_.load_lines( directory, {} ); + return lines_.load_lines( + directory, typename Lines< dimension >::LinesBuilderKey{} ); } template < index_t dimension > std::unique_ptr< EdgedCurveBuilder< dimension > > LinesBuilder< dimension >::line_mesh_builder( const uuid& id ) { - return EdgedCurveBuilder< dimension >::create( - lines_.modifiable_line( id, {} ).modifiable_mesh( - typename Line< dimension >::LinesBuilderKey{} ) ); + return EdgedCurveBuilder< dimension >::create( lines_ + .modifiable_line( + id, typename Lines< dimension >::LinesBuilderKey{} ) + .modifiable_mesh( + typename Line< dimension >::LinesBuilderKey{} ) ); } template < index_t dimension > void LinesBuilder< dimension >::set_line_name( const uuid& id, std::string_view name ) { - lines_.modifiable_line( id, {} ).set_line_name( name, {} ); + lines_ + .modifiable_line( + id, typename Lines< dimension >::LinesBuilderKey{} ) + .set_line_name( + name, typename Lines< dimension >::LinesBuilderKey{} ); line_mesh_builder( id )->set_name( name ); } @@ -90,31 +101,42 @@ namespace geode void LinesBuilder< dimension >::set_line_active( const uuid& id, bool active ) { - lines_.modifiable_line( id, {} ).set_line_active( active, {} ); + lines_ + .modifiable_line( + id, typename Lines< dimension >::LinesBuilderKey{} ) + .set_line_active( + active, typename Lines< dimension >::LinesBuilderKey{} ); } template < index_t dimension > void LinesBuilder< dimension >::set_line_mesh( const uuid& id, std::unique_ptr< EdgedCurve< dimension > > mesh ) { - lines_.modifiable_line( id, {} ).set_mesh( - std::move( mesh ), typename Line< dimension >::LinesBuilderKey{} ); + lines_ + .modifiable_line( + id, typename Lines< dimension >::LinesBuilderKey{} ) + .set_mesh( std::move( mesh ), + typename Line< dimension >::LinesBuilderKey{} ); } template < index_t dimension > EdgedCurve< dimension >& LinesBuilder< dimension >::modifiable_line_mesh( const uuid& id ) { - return lines_.modifiable_line( id, {} ).modifiable_mesh( - typename Line< dimension >::LinesBuilderKey{} ); + return lines_ + .modifiable_line( + id, typename Lines< dimension >::LinesBuilderKey{} ) + .modifiable_mesh( typename Line< dimension >::LinesBuilderKey{} ); } template < index_t dimension > std::unique_ptr< EdgedCurve< dimension > > LinesBuilder< dimension >::steal_line_mesh( const uuid& id ) { - return lines_.modifiable_line( id, {} ).steal_mesh( - typename Line< dimension >::LinesBuilderKey{} ); + return lines_ + .modifiable_line( + id, typename Lines< dimension >::LinesBuilderKey{} ) + .steal_mesh( typename Line< dimension >::LinesBuilderKey{} ); } template class opengeode_model_api LinesBuilder< 2 >; diff --git a/src/geode/model/mixin/builder/model_boundaries_builder.cpp b/src/geode/model/mixin/builder/model_boundaries_builder.cpp index 38a3ab117..de4742764 100644 --- a/src/geode/model/mixin/builder/model_boundaries_builder.cpp +++ b/src/geode/model/mixin/builder/model_boundaries_builder.cpp @@ -31,45 +31,62 @@ namespace geode template < index_t dimension > const uuid& ModelBoundariesBuilder< dimension >::create_model_boundary() { - return model_boundaries_.create_model_boundary( {} ); + return model_boundaries_.create_model_boundary( + typename ModelBoundaries< + dimension >::ModelBoundariesBuilderKey{} ); } template < index_t dimension > void ModelBoundariesBuilder< dimension >::create_model_boundary( uuid model_boundary_id ) { - model_boundaries_.create_model_boundary( - std::move( model_boundary_id ), {} ); + model_boundaries_.create_model_boundary( std::move( model_boundary_id ), + typename ModelBoundaries< + dimension >::ModelBoundariesBuilderKey{} ); } template < index_t dimension > void ModelBoundariesBuilder< dimension >::delete_model_boundary( const ModelBoundary< dimension >& boundary ) { - model_boundaries_.delete_model_boundary( boundary, {} ); + model_boundaries_.delete_model_boundary( + boundary, typename ModelBoundaries< + dimension >::ModelBoundariesBuilderKey{} ); } template < index_t dimension > void ModelBoundariesBuilder< dimension >::load_model_boundaries( std::string_view directory ) { - return model_boundaries_.load_model_boundaries( directory, {} ); + return model_boundaries_.load_model_boundaries( + directory, typename ModelBoundaries< + dimension >::ModelBoundariesBuilderKey{} ); } template < index_t dimension > void ModelBoundariesBuilder< dimension >::set_model_boundary_name( const uuid& id, std::string_view name ) { - model_boundaries_.modifiable_model_boundary( id, {} ) - .set_model_boundary_name( name, {} ); + model_boundaries_ + .modifiable_model_boundary( + id, typename ModelBoundaries< + dimension >::ModelBoundariesBuilderKey{} ) + .set_model_boundary_name( + name, typename ModelBoundaries< + dimension >::ModelBoundariesBuilderKey{} ); } template < index_t dimension > void ModelBoundariesBuilder< dimension >::set_model_boundary_active( const uuid& id, bool active ) { - model_boundaries_.modifiable_model_boundary( id, {} ) - .set_model_boundary_active( active, {} ); + model_boundaries_ + .modifiable_model_boundary( + id, typename ModelBoundaries< + dimension >::ModelBoundariesBuilderKey{} ) + .set_model_boundary_active( + active, typename ModelBoundaries< + dimension >::ModelBoundariesBuilderKey{} ); } template class opengeode_model_api ModelBoundariesBuilder< 2 >; diff --git a/src/geode/model/mixin/builder/relationships_builder.cpp b/src/geode/model/mixin/builder/relationships_builder.cpp index 9bda94a8e..9255834af 100644 --- a/src/geode/model/mixin/builder/relationships_builder.cpp +++ b/src/geode/model/mixin/builder/relationships_builder.cpp @@ -32,43 +32,49 @@ namespace geode void RelationshipsBuilder::unregister_component( const uuid& component_id ) { - relationships_.remove_component( component_id, {} ); + relationships_.remove_component( + component_id, Relationships::RelationshipsBuilderKey{} ); } index_t RelationshipsBuilder::add_boundary_relation( const ComponentID& boundary, const ComponentID& incidence ) { - return relationships_.add_boundary_relation( boundary, incidence, {} ); + return relationships_.add_boundary_relation( + boundary, incidence, Relationships::RelationshipsBuilderKey{} ); } index_t RelationshipsBuilder::add_internal_relation( const ComponentID& internal, const ComponentID& embedding ) { - return relationships_.add_internal_relation( internal, embedding, {} ); + return relationships_.add_internal_relation( + internal, embedding, Relationships::RelationshipsBuilderKey{} ); } index_t RelationshipsBuilder::add_item_in_collection( const ComponentID& item, const ComponentID& collection ) { - return relationships_.add_item_in_collection( item, collection, {} ); + return relationships_.add_item_in_collection( + item, collection, Relationships::RelationshipsBuilderKey{} ); } void RelationshipsBuilder::remove_relation( const uuid& component_id1, const uuid& component_id2 ) { - return relationships_.remove_relation( - component_id1, component_id2, {} ); + return relationships_.remove_relation( component_id1, component_id2, + Relationships::RelationshipsBuilderKey{} ); } void RelationshipsBuilder::copy_relationships( const ModelCopyMapping& mapping, const Relationships& relationships ) { - relationships_.copy_relationships( mapping, relationships, {} ); + relationships_.copy_relationships( + mapping, relationships, Relationships::RelationshipsBuilderKey{} ); } void RelationshipsBuilder::load_relationships( std::string_view directory ) { - relationships_.load_relationships( directory, {} ); + relationships_.load_relationships( + directory, Relationships::RelationshipsBuilderKey{} ); } } // namespace geode diff --git a/src/geode/model/mixin/builder/surface_collections_builder.cpp b/src/geode/model/mixin/builder/surface_collections_builder.cpp index 945bd11e3..10f7d8ce9 100644 --- a/src/geode/model/mixin/builder/surface_collections_builder.cpp +++ b/src/geode/model/mixin/builder/surface_collections_builder.cpp @@ -32,7 +32,9 @@ namespace geode const uuid& SurfaceCollectionsBuilder< dimension >::create_surface_collection() { - return surface_collections_.create_surface_collection( {} ); + return surface_collections_.create_surface_collection( + typename SurfaceCollections< + dimension >::SurfaceCollectionsBuilderKey{} ); } template < index_t dimension > @@ -40,37 +42,53 @@ namespace geode uuid surface_collection_id ) { surface_collections_.create_surface_collection( - std::move( surface_collection_id ), {} ); + std::move( surface_collection_id ), + typename SurfaceCollections< + dimension >::SurfaceCollectionsBuilderKey{} ); } template < index_t dimension > void SurfaceCollectionsBuilder< dimension >::delete_surface_collection( const SurfaceCollection< dimension >& collection ) { - surface_collections_.delete_surface_collection( collection, {} ); + surface_collections_.delete_surface_collection( + collection, typename SurfaceCollections< + dimension >::SurfaceCollectionsBuilderKey{} ); } template < index_t dimension > void SurfaceCollectionsBuilder< dimension >::load_surface_collections( std::string_view directory ) { - return surface_collections_.load_surface_collections( directory, {} ); + return surface_collections_.load_surface_collections( + directory, typename SurfaceCollections< + dimension >::SurfaceCollectionsBuilderKey{} ); } template < index_t dimension > void SurfaceCollectionsBuilder< dimension >::set_surface_collection_name( const uuid& id, std::string_view name ) { - surface_collections_.modifiable_surface_collection( id, {} ) - .set_surface_collection_name( name, {} ); + surface_collections_ + .modifiable_surface_collection( + id, typename SurfaceCollections< + dimension >::SurfaceCollectionsBuilderKey{} ) + .set_surface_collection_name( + name, typename SurfaceCollections< + dimension >::SurfaceCollectionsBuilderKey{} ); } template < index_t dimension > void SurfaceCollectionsBuilder< dimension >::set_surface_collection_active( const uuid& id, bool active ) { - surface_collections_.modifiable_surface_collection( id, {} ) - .set_surface_collection_active( active, {} ); + surface_collections_ + .modifiable_surface_collection( + id, typename SurfaceCollections< + dimension >::SurfaceCollectionsBuilderKey{} ) + .set_surface_collection_active( + active, typename SurfaceCollections< + dimension >::SurfaceCollectionsBuilderKey{} ); } template class opengeode_model_api SurfaceCollectionsBuilder< 2 >; diff --git a/src/geode/model/mixin/builder/surfaces_builder.cpp b/src/geode/model/mixin/builder/surfaces_builder.cpp index f796d9845..ac85dd79e 100644 --- a/src/geode/model/mixin/builder/surfaces_builder.cpp +++ b/src/geode/model/mixin/builder/surfaces_builder.cpp @@ -34,48 +34,58 @@ namespace geode template < index_t dimension > const uuid& SurfacesBuilder< dimension >::create_surface() { - return surfaces_.create_surface( {} ); + return surfaces_.create_surface( + typename Surface< dimension >::SurfacesBuilderKey{} ); } template < index_t dimension > const uuid& SurfacesBuilder< dimension >::create_surface( const MeshImpl& impl ) { - return surfaces_.create_surface( impl, {} ); + return surfaces_.create_surface( + impl, typename Surface< dimension >::SurfacesBuilderKey{} ); } template < index_t dimension > void SurfacesBuilder< dimension >::create_surface( uuid surface_id ) { - surfaces_.create_surface( std::move( surface_id ), {} ); + surfaces_.create_surface( std::move( surface_id ), + typename Surface< dimension >::SurfacesBuilderKey{} ); } template < index_t dimension > void SurfacesBuilder< dimension >::create_surface( uuid surface_id, const MeshImpl& impl ) { - surfaces_.create_surface( std::move( surface_id ), impl, {} ); + surfaces_.create_surface( std::move( surface_id ), impl, + typename Surface< dimension >::SurfacesBuilderKey{} ); } template < index_t dimension > void SurfacesBuilder< dimension >::delete_surface( const Surface< dimension >& surface ) { - surfaces_.delete_surface( surface, {} ); + surfaces_.delete_surface( + surface, typename Surface< dimension >::SurfacesBuilderKey{} ); } template < index_t dimension > void SurfacesBuilder< dimension >::load_surfaces( std::string_view directory ) { - return surfaces_.load_surfaces( directory, {} ); + return surfaces_.load_surfaces( + directory, typename Surface< dimension >::SurfacesBuilderKey{} ); } template < index_t dimension > void SurfacesBuilder< dimension >::set_surface_name( const uuid& id, std::string_view name ) { - surfaces_.modifiable_surface( id, {} ).set_surface_name( name, {} ); + surfaces_ + .modifiable_surface( + id, typename Surface< dimension >::SurfacesBuilderKey{} ) + .set_surface_name( + name, typename Surface< dimension >::SurfacesBuilderKey{} ); surface_mesh_builder( id )->set_name( name ); } @@ -83,31 +93,43 @@ namespace geode void SurfacesBuilder< dimension >::set_surface_active( const uuid& id, bool active ) { - surfaces_.modifiable_surface( id, {} ).set_surface_active( active, {} ); + surfaces_ + .modifiable_surface( + id, typename Surface< dimension >::SurfacesBuilderKey{} ) + .set_surface_active( + active, typename Surface< dimension >::SurfacesBuilderKey{} ); } template < index_t dimension > void SurfacesBuilder< dimension >::set_surface_mesh( const uuid& id, std::unique_ptr< SurfaceMesh< dimension > > mesh ) { - surfaces_.modifiable_surface( id, {} ).set_mesh( std::move( mesh ), - typename Surface< dimension >::SurfacesBuilderKey{} ); + surfaces_ + .modifiable_surface( + id, typename Surface< dimension >::SurfacesBuilderKey{} ) + .set_mesh( std::move( mesh ), + typename Surface< dimension >::SurfacesBuilderKey{} ); } template < index_t dimension > SurfaceMesh< dimension >& SurfacesBuilder< dimension >::modifiable_surface_mesh( const uuid& id ) { - return surfaces_.modifiable_surface( id, {} ).modifiable_mesh( - typename Surface< dimension >::SurfacesBuilderKey{} ); + return surfaces_ + .modifiable_surface( + id, typename Surface< dimension >::SurfacesBuilderKey{} ) + .modifiable_mesh( + typename Surface< dimension >::SurfacesBuilderKey{} ); } template < index_t dimension > std::unique_ptr< SurfaceMesh< dimension > > SurfacesBuilder< dimension >::steal_surface_mesh( const uuid& id ) { - return surfaces_.modifiable_surface( id, {} ).steal_mesh( - typename Surface< dimension >::SurfacesBuilderKey{} ); + return surfaces_ + .modifiable_surface( + id, typename Surface< dimension >::SurfacesBuilderKey{} ) + .steal_mesh( typename Surface< dimension >::SurfacesBuilderKey{} ); } template class opengeode_model_api SurfacesBuilder< 2 >; diff --git a/src/geode/model/mixin/builder/vertex_identifier_builder.cpp b/src/geode/model/mixin/builder/vertex_identifier_builder.cpp index f65381cc5..5596a4cc3 100644 --- a/src/geode/model/mixin/builder/vertex_identifier_builder.cpp +++ b/src/geode/model/mixin/builder/vertex_identifier_builder.cpp @@ -33,43 +33,48 @@ namespace geode index_t VertexIdentifierBuilder::create_unique_vertex() { - return vertex_identifier_.create_unique_vertex( {} ); + return vertex_identifier_.create_unique_vertex( + VertexIdentifier::BuilderKey{} ); } index_t VertexIdentifierBuilder::create_unique_vertices( index_t nb ) { - return vertex_identifier_.create_unique_vertices( nb, {} ); + return vertex_identifier_.create_unique_vertices( + nb, VertexIdentifier::BuilderKey{} ); } void VertexIdentifierBuilder::set_unique_vertex( ComponentMeshVertex component_vertex_id, index_t unique_vertex_id ) { - vertex_identifier_.set_unique_vertex( - component_vertex_id, unique_vertex_id, {} ); + vertex_identifier_.set_unique_vertex( component_vertex_id, + unique_vertex_id, VertexIdentifier::BuilderKey{} ); } void VertexIdentifierBuilder::unset_unique_vertex( const ComponentMeshVertex& component_vertex_id, index_t unique_vertex_id ) { - vertex_identifier_.unset_unique_vertex( - component_vertex_id, unique_vertex_id, {} ); + vertex_identifier_.unset_unique_vertex( component_vertex_id, + unique_vertex_id, VertexIdentifier::BuilderKey{} ); } void VertexIdentifierBuilder::update_unique_vertices( const ComponentID& component_id, absl::Span< const index_t > old2new ) { - vertex_identifier_.update_unique_vertices( component_id, old2new, {} ); + vertex_identifier_.update_unique_vertices( + component_id, old2new, VertexIdentifier::BuilderKey{} ); } void VertexIdentifierBuilder::load_unique_vertices( std::string_view directory ) { - vertex_identifier_.load_unique_vertices( directory, {} ); + vertex_identifier_.load_unique_vertices( + directory, VertexIdentifier::BuilderKey{} ); } std::vector< index_t > VertexIdentifierBuilder::delete_isolated_vertices() { - return vertex_identifier_.delete_isolated_vertices( {} ); + return vertex_identifier_.delete_isolated_vertices( + VertexIdentifier::BuilderKey{} ); } } // namespace geode diff --git a/src/geode/model/mixin/core/blocks.cpp b/src/geode/model/mixin/core/blocks.cpp index f15d490ca..1c0d1472f 100644 --- a/src/geode/model/mixin/core/blocks.cpp +++ b/src/geode/model/mixin/core/blocks.cpp @@ -145,13 +145,13 @@ namespace geode template < index_t dimension > void Blocks< dimension >::load_blocks( - std::string_view directory, BlocksBuilderKey /*unused*/ ) + std::string_view directory, BlocksBuilderKey builder_key ) { impl_->load_components( absl::StrCat( directory, "/blocks" ) ); const auto mapping = impl_->file_mapping( directory ); absl::FixedArray< async::task< void > > tasks( nb_blocks() ); index_t count{ 0 }; - for( auto& block : modifiable_blocks( {} ) ) + for( auto& block : modifiable_blocks( builder_key ) ) { tasks[count++] = async::spawn( [&block, &mapping] { const auto file = mapping.at( block.id().string() ); @@ -199,7 +199,8 @@ namespace geode const MeshImpl& impl, BlocksBuilderKey /*unused*/ ) { typename Blocks< dimension >::Impl::ComponentPtr block{ - new Block< dimension >{ impl, {} } + new Block< dimension >{ + impl, typename Block< dimension >::BlocksKey{} } }; const auto& id = block->id(); impl_->add_component( std::move( block ) ); @@ -222,7 +223,8 @@ namespace geode uuid block_id, const MeshImpl& impl, BlocksBuilderKey /*unused*/ ) { typename Blocks< dimension >::Impl::ComponentPtr block{ - new Block< dimension >{ impl, {} } + new Block< dimension >{ + impl, typename Block< dimension >::BlocksKey{} } }; IdentifierBuilder{ *block }.set_id( std::move( block_id ) ); impl_->add_component( std::move( block ) ); diff --git a/src/geode/model/mixin/core/corners.cpp b/src/geode/model/mixin/core/corners.cpp index 1347c3113..246f8603b 100644 --- a/src/geode/model/mixin/core/corners.cpp +++ b/src/geode/model/mixin/core/corners.cpp @@ -115,13 +115,13 @@ namespace geode template < index_t dimension > void Corners< dimension >::load_corners( - std::string_view directory, CornersBuilderKey /*key*/ ) + std::string_view directory, CornersBuilderKey key ) { impl_->load_components( absl::StrCat( directory, "/corners" ) ); const auto mapping = impl_->file_mapping( directory ); absl::FixedArray< async::task< void > > tasks( nb_corners() ); index_t count{ 0 }; - for( auto& corner : modifiable_corners( {} ) ) + for( auto& corner : modifiable_corners( key ) ) { tasks[count++] = async::spawn( [&corner, &mapping] { const auto file = mapping.at( corner.id().string() ); @@ -199,7 +199,8 @@ namespace geode uuid corner_id, const MeshImpl& impl, CornersBuilderKey /*key*/ ) { typename Corners< dimension >::Impl::ComponentPtr corner{ - new Corner< dimension >{ impl, {} } + new Corner< dimension >{ + impl, typename Corner< dimension >::CornersKey{} } }; IdentifierBuilder{ *corner }.set_id( std::move( corner_id ) ); impl_->add_component( std::move( corner ) ); diff --git a/src/geode/model/mixin/core/detail/relationships_impl.cpp b/src/geode/model/mixin/core/detail/relationships_impl.cpp index 0f6cf5c6f..e709d3320 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(); @@ -122,8 +124,8 @@ namespace geode if( const auto component_id = relation_edge_index( from.id(), to.id() ) ) { - Logger::warn( "This relation already exists (", from.string(), - " and ", to.string(), ")" ); + Logger::warning( "This relation already exists (", + from.string(), " and ", to.string(), ")" ); return component_id.value(); } const auto index = GraphBuilder::create( *graph_ )->create_edge( @@ -232,10 +234,29 @@ 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; + } + AttributeProperties attribute_properties; + attribute_properties.assignable = false; + attribute_properties.interpolable = false; + attribute_properties.transferable = true; + AttributeValues< ComponentID > ids_attribute_values; + ids_attribute_values.default_value = ComponentID{}; + ids_attribute_values.no_value = ComponentID{}; + const auto id = graph_->vertex_attribute_manager() - .find_or_create_attribute< VariableAttribute, ComponentID >( - "id", ComponentID{} ); + .create_attribute< VariableAttribute, ComponentID >( + "id", ids_attribute_values, attribute_properties ); + 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/lines.cpp b/src/geode/model/mixin/core/lines.cpp index aaf1f81b3..6a7643b43 100644 --- a/src/geode/model/mixin/core/lines.cpp +++ b/src/geode/model/mixin/core/lines.cpp @@ -113,13 +113,13 @@ namespace geode template < index_t dimension > void Lines< dimension >::load_lines( - std::string_view directory, LinesBuilderKey /*key*/ ) + std::string_view directory, LinesBuilderKey key ) { impl_->load_components( absl::StrCat( directory, "/lines" ) ); const auto mapping = impl_->file_mapping( directory ); absl::FixedArray< async::task< void > > tasks( nb_lines() ); index_t count{ 0 }; - for( auto& line : modifiable_lines( {} ) ) + for( auto& line : modifiable_lines( key ) ) { tasks[count++] = async::spawn( [&line, &mapping] { const auto file = mapping.at( line.id().string() ); @@ -195,7 +195,8 @@ namespace geode uuid line_id, const MeshImpl& impl, LinesBuilderKey /*key*/ ) { typename Lines< dimension >::Impl::ComponentPtr line{ - new Line< dimension >{ impl, {} } + new Line< dimension >{ + impl, typename Line< dimension >::LinesKey{} } }; IdentifierBuilder{ *line }.set_id( std::move( line_id ) ); impl_->add_component( std::move( line ) ); diff --git a/src/geode/model/mixin/core/relationships.cpp b/src/geode/model/mixin/core/relationships.cpp index 68a2e1e70..4fae8f60f 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 ); @@ -146,7 +148,7 @@ namespace geode { const auto relation_type = relation_type_->value( component_id.value() ); - Logger::warn( "There is already a ", + Logger::warning( "There is already a ", relation_to_string( relation_type ), " between (", from.string(), " and ", to.string(), ")" ); return component_id.value(); @@ -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,32 @@ 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; + } + AttributeProperties attribute_properties; + attribute_properties.assignable = false; + attribute_properties.interpolable = false; + attribute_properties.transferable = true; + AttributeValues< RelationType > ids_attribute_values; + ids_attribute_values.default_value = NO_ID; + ids_attribute_values.no_value = NO_ID; + const auto id = + relation_attribute_manager() + .create_attribute< VariableAttribute, RelationType >( + "relation_type", ids_attribute_values, + attribute_properties ); + relation_type_ = + relation_attribute_manager() + .find_attribute< VariableAttribute, RelationType >( id ); } std::string relation_to_string( index_t relation_type ) const @@ -267,6 +295,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/surfaces.cpp b/src/geode/model/mixin/core/surfaces.cpp index f3be6cbb1..87f3f46f4 100644 --- a/src/geode/model/mixin/core/surfaces.cpp +++ b/src/geode/model/mixin/core/surfaces.cpp @@ -137,13 +137,13 @@ namespace geode template < index_t dimension > void Surfaces< dimension >::load_surfaces( - std::string_view directory, SurfacesBuilderKey /*key*/ ) + std::string_view directory, SurfacesBuilderKey key ) { impl_->load_components( absl::StrCat( directory, "/surfaces" ) ); const auto mapping = impl_->file_mapping( directory ); absl::FixedArray< async::task< void > > tasks( nb_surfaces() ); index_t count{ 0 }; - for( auto& surface : modifiable_surfaces( {} ) ) + for( auto& surface : modifiable_surfaces( key ) ) { tasks[count++] = async::spawn( [&surface, &mapping] { const auto file = mapping.at( surface.id().string() ); @@ -232,7 +232,8 @@ namespace geode uuid surface_id, const MeshImpl& impl, SurfacesBuilderKey /*key*/ ) { typename Surfaces< dimension >::Impl::ComponentPtr surface{ - new Surface< dimension >{ impl, {} } + new Surface< dimension >{ + impl, typename Surface< dimension >::SurfacesKey{} } }; IdentifierBuilder{ *surface }.set_id( std::move( surface_id ) ); impl_->add_component( std::move( surface ) ); diff --git a/src/geode/model/mixin/core/vertex_identifier.cpp b/src/geode/model/mixin/core/vertex_identifier.cpp index 3b8878233..d21f9f217 100644 --- a/src/geode/model/mixin/core/vertex_identifier.cpp +++ b/src/geode/model/mixin/core/vertex_identifier.cpp @@ -102,19 +102,34 @@ namespace geode class VertexIdentifier::Impl { - const std::string unique_vertices_name = "unique vertices"; + constexpr static auto UNIQUE_VERTICES_NAME = "unique vertices"; 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 } ) ) { + AttributeProperties attribute_properties; + attribute_properties.assignable = false; + attribute_properties.interpolable = false; + attribute_properties.transferable = false; + AttributeValues< std::vector< ComponentMeshVertex > > + component_vertices_attribute_values; + component_vertices_attribute_values.default_value = {}; + component_vertices_attribute_values.no_value = {}; + const auto unique_vertices_attribute_id = + unique_vertices_.vertex_attribute_manager() + .create_attribute< VariableAttribute, + std::vector< ComponentMeshVertex > >( + "component vertices", + component_vertices_attribute_values, + attribute_properties ); + 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 +189,60 @@ namespace geode template < typename MeshComponent > void register_component( const MeshComponent& component ) { - auto it = vertex2unique_vertex_.find( component.id() ); + AttributeProperties attribute_properties; + attribute_properties.assignable = false; + attribute_properties.interpolable = false; + attribute_properties.transferable = false; + AttributeValues< index_t > unqiue_vertex_attribute_values; + unqiue_vertex_attribute_values.default_value = NO_ID; + unqiue_vertex_attribute_values.no_value = NO_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, unqiue_vertex_attribute_values, + attribute_properties ); + 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 ); + 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 +439,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 +462,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 +475,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 +522,7 @@ namespace geode }; VertexIdentifier::VertexIdentifier() = default; + VertexIdentifier::VertexIdentifier( BITSERY bitsery ) : impl_{ bitsery } {} VertexIdentifier::VertexIdentifier( VertexIdentifier&& ) noexcept = default; VertexIdentifier& VertexIdentifier::operator=( @@ -531,6 +568,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 +643,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 abba02ca6..e97f0b527 100644 --- a/src/geode/model/representation/core/brep.cpp +++ b/src/geode/model/representation/core/brep.cpp @@ -737,6 +737,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/detail/transfer_meshes.cpp b/src/geode/model/representation/core/detail/transfer_meshes.cpp index bbb0108e5..e180d601b 100644 --- a/src/geode/model/representation/core/detail/transfer_meshes.cpp +++ b/src/geode/model/representation/core/detail/transfer_meshes.cpp @@ -146,6 +146,7 @@ namespace other, other_corner.mesh().nb_vertices(), other_corner.component_id() ); const auto& corner = model.corner( corner_id ); + other_builder.unregister_mesh_component( other_corner ); builder.update_corner_mesh( corner, other_builder.steal_corner_mesh( other_corner_id ) ); auto mesh_builder = builder.corner_mesh_builder( corner_id ); @@ -175,6 +176,7 @@ namespace const auto line_unique_vertices = save_mesh_unique_vertices( other, other_line.mesh().nb_vertices(), other_line.component_id() ); const auto& line = model.line( line_id ); + other_builder.unregister_mesh_component( other_line ); builder.update_line_mesh( line, other_builder.steal_line_mesh( other_line_id ) ); auto mesh_builder = builder.line_mesh_builder( line_id ); @@ -205,6 +207,7 @@ namespace other, other_surface.mesh().nb_vertices(), other_surface.component_id() ); const auto& surface = model.surface( surface_id ); + other_builder.unregister_mesh_component( other_surface ); builder.update_surface_mesh( surface, other_builder.steal_surface_mesh( other_surface_id ) ); auto mesh_builder = builder.surface_mesh_builder( surface_id ); @@ -234,6 +237,7 @@ namespace const auto block_unique_vertices = save_mesh_unique_vertices( other, other_block.mesh().nb_vertices(), other_block.component_id() ); const auto& block = model.block( block_id ); + other_builder.unregister_mesh_component( other_block ); builder.update_block_mesh( block, other_builder.steal_block_mesh( other_block_id ) ); auto mesh_builder = builder.block_mesh_builder( block_id ); diff --git a/src/geode/model/representation/core/section.cpp b/src/geode/model/representation/core/section.cpp index 537250da0..ec6407708 100644 --- a/src/geode/model/representation/core/section.cpp +++ b/src/geode/model/representation/core/section.cpp @@ -510,6 +510,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_brep_output.cpp b/src/geode/model/representation/io/geode/geode_brep_output.cpp index d87bea054..00de03e73 100644 --- a/src/geode/model/representation/io/geode/geode_brep_output.cpp +++ b/src/geode/model/representation/io/geode/geode_brep_output.cpp @@ -50,7 +50,7 @@ namespace geode const BRep& brep, std::string_view directory ) const { const auto level = Logger::level(); - Logger::set_level( Logger::LEVEL::warn ); + Logger::set_level( Logger::LEVEL::warning ); async::parallel_invoke( [&directory, &brep] { brep.save_identifier( directory ); 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/src/geode/model/representation/io/geode/geode_section_output.cpp b/src/geode/model/representation/io/geode/geode_section_output.cpp index f785496f6..fefa57b11 100644 --- a/src/geode/model/representation/io/geode/geode_section_output.cpp +++ b/src/geode/model/representation/io/geode/geode_section_output.cpp @@ -40,7 +40,7 @@ namespace geode const Section& section, std::string_view directory ) const { const auto level = Logger::level(); - Logger::set_level( Logger::LEVEL::warn ); + Logger::set_level( Logger::LEVEL::warning ); async::parallel_invoke( [&directory, §ion] { section.save_identifier( directory ); diff --git a/tests/basic/test-attribute.cpp b/tests/basic/test-attribute.cpp index a3f1d07cb..666389748 100644 --- a/tests/basic/test-attribute.cpp +++ b/tests/basic/test-attribute.cpp @@ -106,17 +106,27 @@ namespace geode }; } // namespace geode -void test_constant_attribute( geode::AttributeManager& manager ) +void test_constant_attribute( + geode::AttributeManager& manager, const geode::uuid& attribute_id ) { + geode::AttributeProperties attribute_properties; + attribute_properties.assignable = true; + attribute_properties.interpolable = true; + attribute_properties.transferable = true; + geode::AttributeValues< bool > attribute_values; + attribute_values.default_value = true; + attribute_values.no_value = true; + manager.create_attribute< geode::ConstantAttribute, bool >( + "bool", attribute_id, attribute_values, attribute_properties ); 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 +138,20 @@ 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 ) { + geode::AttributeProperties attribute_properties; + attribute_properties.assignable = false; + attribute_properties.interpolable = false; + attribute_properties.transferable = true; + geode::AttributeValues< Foo > attribute_values; + attribute_values.default_value = Foo{}; + attribute_values.no_value = Foo{}; + manager.create_attribute< geode::ConstantAttribute, Foo >( + "foo", attribute_id, attribute_values, attribute_properties ); 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 +160,21 @@ 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 ) { + geode::AttributeProperties attribute_properties; + attribute_properties.assignable = false; + attribute_properties.interpolable = false; + attribute_properties.transferable = false; + geode::AttributeValues< Foo > attribute_values; + attribute_values.default_value = Foo{}; + attribute_values.no_value = Foo{}; + manager.create_attribute< geode::VariableAttribute, Foo >( + "foo2", attribute_id, attribute_values, attribute_properties ); 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 +198,27 @@ 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 ) { + geode::AttributeProperties attribute_properties; + attribute_properties.assignable = true; + attribute_properties.interpolable = true; + attribute_properties.transferable = true; + geode::AttributeValues< int > attribute_values; + attribute_values.default_value = 12; + attribute_values.no_value = geode::NO_ID; + manager.create_attribute< geode::VariableAttribute, int >( + "int", attribute_id, attribute_values, attribute_properties ); 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->default_values().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 +229,20 @@ 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 ) { + geode::AttributeProperties attribute_properties; + attribute_properties.assignable = false; + attribute_properties.interpolable = false; + attribute_properties.transferable = true; + geode::AttributeValues< Foo > attribute_values; + attribute_values.default_value = Foo{}; + attribute_values.no_value = Foo{}; + manager.create_attribute< geode::SparseAttribute, Foo >( + "foo", attribute_id, attribute_values, attribute_properties ); 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,19 +259,30 @@ 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 ) { + geode::AttributeProperties attribute_properties; + attribute_properties.assignable = true; + attribute_properties.interpolable = true; + attribute_properties.transferable = true; + geode::AttributeValues< double > attribute_values; + attribute_values.default_value = 12.; + attribute_values.no_value = geode::NO_ID; + manager.create_attribute< geode::SparseAttribute, double >( + "double", attribute_id, attribute_values, attribute_properties ); 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->default_values().default_value == 12, + "Wrong default value" ); sparse_attribute->set_value( 3, 3 ); sparse_attribute->set_value( 7, 7 ); 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,23 +301,36 @@ 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, + geode::AttributeProperties attribute_properties; + attribute_properties.assignable = true; + attribute_properties.interpolable = true; + attribute_properties.transferable = true; + geode::AttributeValues< std::array< double, 3 > > attribute_values; + attribute_values.default_value = { { 10., 11., 12. } }; + attribute_values.no_value = { { 0., 0., 0. } }; + const auto attribute_id = + manager.create_attribute< geode::VariableAttribute, std::array< double, 3 > >( - "array_double_3", { { 10., 11., 12. } }, { true, true } ); + "double_array", attribute_values, attribute_properties ); + 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" ); + array_attribute->default_values().default_value[0] == 10., + "Wrong default value" ); geode::OpenGeodeBasicException::test( - array_attribute->default_value()[1] == 11., "Wrong default value" ); + array_attribute->default_values().default_value[1] == 11., + "Wrong default value" ); geode::OpenGeodeBasicException::test( - array_attribute->default_value()[2] == 12., "Wrong default value" ); + array_attribute->default_values().default_value[2] == 12., + "Wrong default value" ); array_attribute->set_value( 3, { { 1., 2., 3. } } ); array_attribute->set_value( 7, { { 2., 5., 7. } } ); manager.assign_attribute_value( 3, 2 ); 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 +371,29 @@ 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 ) { + geode::AttributeProperties attribute_properties; + attribute_properties.assignable = true; + attribute_properties.interpolable = true; + attribute_properties.transferable = true; + geode::AttributeValues< bool > attribute_values; + attribute_values.default_value = false; + attribute_values.no_value = false; + manager.create_attribute< geode::VariableAttribute, bool >( + "bool", attribute_id, attribute_values, attribute_properties ); + 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->default_values().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 +405,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 +432,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 +512,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 +559,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 +573,34 @@ 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 >() ); + geode::AttributeProperties attribute_properties; + attribute_properties.assignable = true; + attribute_properties.interpolable = true; + attribute_properties.transferable = true; + geode::AttributeValues< std::array< double, 2 > > attribute_values; + attribute_values.default_value = {}; + attribute_values.no_value = {}; + auto array_attr_id = manager.create_attribute< geode::VariableAttribute, + std::array< double, 2 > >( + "array_double_2", attribute_values, attribute_properties ); + 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 +615,32 @@ 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; + test_number_of_attributes( manager, 8 ); 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 +650,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 +669,82 @@ 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 ); + geode::AttributeProperties attribute_properties; + attribute_properties.assignable = true; + attribute_properties.interpolable = true; + attribute_properties.transferable = true; + geode::AttributeValues< geode::index_t > attribute1_values; + attribute1_values.default_value = 42.; + attribute1_values.no_value = geode::NO_ID; + auto attr1_from1_id = + from1.create_attribute< geode::VariableAttribute, geode::index_t >( + " variable", attribute1_values, attribute_properties ); + 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 ); + geode::AttributeValues< double > attribute2_values; + attribute2_values.default_value = 1.0; + attribute2_values.no_value = std::numeric_limits< double >::max(); + auto attr2_from1_id = + from1.create_attribute< geode::ConstantAttribute, double >( + "constant", attribute2_values, attribute_properties ); + auto attr2_from1 = from1.find_attribute< geode::ConstantAttribute, double >( + attr2_from1_id ); + geode::AttributeValues< std::string > attribute3_values; + attribute3_values.default_value = "default"; + attribute3_values.no_value = "no_value"; + auto attr3_from1_id = + from1.create_attribute< geode::SparseAttribute, std::string >( + "sparse", attribute3_values, attribute_properties ); 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 ); + geode::AttributeValues< geode::index_t > second_attribute1_values; + second_attribute1_values.default_value = 42.; + second_attribute1_values.no_value = geode::NO_ID; + from2.create_attribute< geode::VariableAttribute, geode::index_t >( + " variable", attr1_from1_id, second_attribute1_values, + attribute_properties ); + 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 ); + geode::AttributeValues< double > second_attribute2_values; + second_attribute2_values.default_value = 2.0; + second_attribute2_values.no_value = std::numeric_limits< double >::max(); + from2.create_attribute< geode::ConstantAttribute, double >( "constant", + attr2_from1_id, second_attribute2_values, attribute_properties ); + auto attr2_from2 = from2.find_attribute< geode::ConstantAttribute, double >( + attr2_from1_id ); + geode::AttributeValues< std::string > second_attribute3_values; + second_attribute3_values.default_value = "another_default"; + second_attribute3_values.no_value = "another_no_value"; + from2.create_attribute< geode::SparseAttribute, std::string >( "sparse", + attr3_from1_id, second_attribute3_values, attribute_properties ); 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 +776,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 +796,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 +812,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 +831,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/basic/test-logger.cpp b/tests/basic/test-logger.cpp index 00af0ccb1..5f046f7e0 100644 --- a/tests/basic/test-logger.cpp +++ b/tests/basic/test-logger.cpp @@ -53,7 +53,7 @@ namespace std::cout << "Old school logger => " << message << '\n'; } - void warn( const std::string &message ) override + void warning( const std::string &message ) override { std::cout << "Old school logger => " << message << '\n'; } @@ -74,7 +74,7 @@ namespace geode::Logger::trace( "test ", "trace" ); geode::Logger::debug( "test ", "debug" ); geode::Logger::info( "test ", "info" ); - geode::Logger::warn( "test ", "warn" ); + geode::Logger::warning( "test ", "warning" ); geode::Logger::error( "test ", "error" ); geode::Logger::critical( "test ", "critial" ); } @@ -131,7 +131,7 @@ namespace const auto &huge_msg = test_huge_message(); test_change_log_file( huge_msg ); - geode::Logger::set_level( geode::Logger::LEVEL::err ); + geode::Logger::set_level( geode::Logger::LEVEL::error ); test_logger(); } } // namespace 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..00cb53b92 100644 --- a/tests/geometry/test-point.cpp +++ b/tests/geometry/test-point.cpp @@ -65,15 +65,28 @@ 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 } ); + geode::AttributeProperties attribute_properties; + attribute_properties.assignable = false; + attribute_properties.interpolable = true; + attribute_properties.transferable = true; + geode::AttributeValues< geode::Point< 3 > > attribute_values; + attribute_values.default_value = geode::Point3D{ { 10., 11., 12. } }; + attribute_values.no_value = geode::Point3D{}; + auto attribute_id = + manager.create_attribute< geode::VariableAttribute, geode::Point< 3 > >( + "points", attribute_values, attribute_properties ); + auto attribute = + manager.find_attribute< geode::VariableAttribute, geode::Point< 3 > >( + attribute_id ); geode::OpenGeodeGeometryException::test( - attribute->default_value().value( 0 ) == 10., "Wrong default value" ); + attribute->default_values().default_value.value( 0 ) == 10., + "Wrong default value" ); geode::OpenGeodeGeometryException::test( - attribute->default_value().value( 1 ) == 11., "Wrong default value" ); + attribute->default_values().default_value.value( 1 ) == 11., + "Wrong default value" ); geode::OpenGeodeGeometryException::test( - attribute->default_value().value( 2 ) == 12., "Wrong default value" ); + attribute->default_values().default_value.value( 2 ) == 12., + "Wrong default value" ); attribute->set_value( 3, geode::Point3D{ { 1., 2., 3. } } ); attribute->set_value( 7, geode::Point3D{ { 2., 5., 7. } } ); manager.interpolate_attribute_value( { { 1, 7 }, { 0.5, 0.3 } }, 4 ); diff --git a/tests/image/test-colors.cpp b/tests/image/test-colors.cpp index de74a4d2b..555732a8b 100644 --- a/tests/image/test-colors.cpp +++ b/tests/image/test-colors.cpp @@ -46,14 +46,29 @@ 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{} ); + geode::AttributeProperties attribute_properties; + attribute_properties.assignable = false; + attribute_properties.interpolable = true; + attribute_properties.transferable = true; + geode::AttributeValues< geode::RGBColor > attribute_values; + attribute_values.default_value = geode::RGBColor{}; + attribute_values.no_value = geode::RGBColor{}; + const auto rgb_attribute_id = + manager.create_attribute< geode::VariableAttribute, geode::RGBColor >( + "rgb_color", attribute_values, attribute_properties ); + 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::AttributeValues< geode::GreyscaleColor > grey_attribute_values; + grey_attribute_values.default_value = geode::GreyscaleColor{}; + grey_attribute_values.no_value = geode::GreyscaleColor{}; + const auto greyscale_attribute_id = + manager.create_attribute< geode::VariableAttribute, geode::GreyscaleColor >( - "greyscale_color", geode::GreyscaleColor{} ); + "greyscale_color", grey_attribute_values, attribute_properties ); + 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..6a87212a6 100644 --- a/tests/mesh/test-convert-surface.cpp +++ b/tests/mesh/test-convert-surface.cpp @@ -115,22 +115,32 @@ 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 ); + geode::AttributeProperties attribute_properties; + attribute_properties.assignable = false; + attribute_properties.interpolable = true; + attribute_properties.transferable = true; + geode::AttributeValues< geode::Point2D > attribute_values; + attribute_values.default_value = geode::Point2D{}; + attribute_values.no_value = geode::Point2D{}; + auto test_attribute_id = + old_regular_grid_surface->vertex_attribute_manager() + .create_attribute< geode::VariableAttribute, geode::Point2D >( + "test", attribute_values, attribute_properties ); 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, attribute_values, attribute_properties ); 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..89f19a35f 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,21 @@ void test_edge_requests( const geode::EdgedCurve3D& edged_curve, void test_clone( const geode::EdgedCurve3D& edged_curve ) { + geode::AttributeProperties attribute_properties; + attribute_properties.assignable = false; + attribute_properties.interpolable = true; + attribute_properties.transferable = true; + geode::AttributeValues< int > attribute_values; + attribute_values.default_value = 0; + attribute_values.no_value = 0; + auto attribute_id = + edged_curve.edge_attribute_manager() + .create_attribute< geode::VariableAttribute, int >( + "edge", attribute_values, attribute_properties ); 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 +336,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 +362,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..3d9767eea 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,26 @@ 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 ); + geode::AttributeProperties attribute_properties; + attribute_properties.assignable = false; + attribute_properties.interpolable = true; + attribute_properties.transferable = true; + geode::AttributeValues< geode::index_t > attribute_values; + attribute_values.default_value = 2; + attribute_values.no_value = 0; + edged_curve->edge_attribute_manager() + .create_attribute< geode::VariableAttribute, geode::index_t >( + "edge", attribute_id, attribute_values, attribute_properties ); + 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 +81,26 @@ 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 ); + geode::AttributeProperties attribute_properties; + attribute_properties.assignable = false; + attribute_properties.interpolable = true; + attribute_properties.transferable = true; + geode::AttributeValues< geode::index_t > attribute_values; + attribute_values.default_value = 2; + attribute_values.no_value = 0; + surface->polygon_attribute_manager() + .create_attribute< geode::VariableAttribute, geode::index_t >( + "surface", attribute_id, attribute_values, attribute_properties ); + 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 +112,28 @@ 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 ); + geode::AttributeProperties attribute_properties; + attribute_properties.assignable = false; + attribute_properties.interpolable = true; + attribute_properties.transferable = true; + geode::AttributeValues< geode::index_t > attribute_values; + attribute_values.default_value = 2; + attribute_values.no_value = 0; + solid->polyhedron_attribute_manager() + .create_attribute< geode::VariableAttribute, geode::index_t >( + "solid", attribute_id, attribute_values, attribute_properties ); + 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 +156,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 +196,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..7a7f2a9d8 100644 --- a/tests/mesh/test-gradient-computation.cpp +++ b/tests/mesh/test-gradient-computation.cpp @@ -48,11 +48,20 @@ 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"; + geode::AttributeProperties attribute_properties; + attribute_properties.assignable = false; + attribute_properties.interpolable = true; + attribute_properties.transferable = true; + geode::AttributeValues< double > attribute_values; + attribute_values.default_value = 0; + attribute_values.no_value = 0; + auto attribute_id = + grid->vertex_attribute_manager() + .create_attribute< geode::VariableAttribute, double >( + "scalar_function", attribute_values, attribute_properties ); 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 +76,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 +108,20 @@ 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"; + geode::AttributeProperties attribute_properties; + attribute_properties.assignable = false; + attribute_properties.interpolable = true; + attribute_properties.transferable = true; + geode::AttributeValues< double > attribute_values; + attribute_values.default_value = 0; + attribute_values.no_value = 0; + auto attribute_id = + surface->vertex_attribute_manager() + .create_attribute< geode::VariableAttribute, double >( + "scalar_function", attribute_values, attribute_properties ); 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 +130,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 +144,20 @@ 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"; + geode::AttributeProperties attribute_properties; + attribute_properties.assignable = false; + attribute_properties.interpolable = true; + attribute_properties.transferable = true; + geode::AttributeValues< double > attribute_values; + attribute_values.default_value = 0; + attribute_values.no_value = 0; + auto attribute_id = + grid->vertex_attribute_manager() + .create_attribute< geode::VariableAttribute, double >( + "scalar_function", attribute_values, attribute_properties ); 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 +184,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-hausdorff-distance.cpp b/tests/mesh/test-hausdorff-distance.cpp index 8cc865843..0f025ad83 100644 --- a/tests/mesh/test-hausdorff-distance.cpp +++ b/tests/mesh/test-hausdorff-distance.cpp @@ -14,6 +14,7 @@ void test() { geode::OpenGeodeMeshLibrary::initialize(); + geode::Logger::set_level( geode::Logger::LEVEL::debug ); const auto initial_mesh_filename = absl::StrCat( geode::DATA_PATH, "Armadillo.og_tsf3d" ); const auto mesh_A = 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..5a553fd81 100644 --- a/tests/mesh/test-light-regular-grid.cpp +++ b/tests/mesh/test-light-regular-grid.cpp @@ -332,10 +332,20 @@ void test_closest_vertex( const geode::LightRegularGrid3D& grid ) void test_attribute( const geode::LightRegularGrid3D& grid ) { + geode::AttributeProperties attribute_properties; + attribute_properties.assignable = false; + attribute_properties.interpolable = true; + attribute_properties.transferable = true; + geode::AttributeValues< double > attribute_values; + attribute_values.default_value = -1; + attribute_values.no_value = -1; + auto attribute_id = + grid.cell_attribute_manager() + .create_attribute< geode::VariableAttribute, double >( + "test", attribute_values, attribute_properties ); 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..9ca0bf4f6 100644 --- a/tests/mesh/test-point-set.cpp +++ b/tests/mesh/test-point-set.cpp @@ -82,14 +82,25 @@ 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 = + geode::AttributeProperties attribute_properties; + attribute_properties.assignable = false; + attribute_properties.interpolable = true; + attribute_properties.transferable = true; + geode::AttributeValues< bool > attribute_values; + attribute_values.default_value = true; + attribute_values.no_value = true; + auto attribute_id = point_set.vertex_attribute_manager() - .find_or_create_attribute< geode::ConstantAttribute, bool >( - "test", true ); + .create_attribute< geode::ConstantAttribute, bool >( + "bool", attribute_values, attribute_properties ); + const auto attribute = + point_set.vertex_attribute_manager() + .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 +132,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 +169,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..b7b59ddfa 100644 --- a/tests/mesh/test-polygonal-surface.cpp +++ b/tests/mesh/test-polygonal-surface.cpp @@ -68,13 +68,24 @@ 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 ) { + geode::AttributeProperties attribute_properties; + attribute_properties.assignable = false; + attribute_properties.interpolable = true; + attribute_properties.transferable = true; + geode::AttributeValues< geode::PolygonEdge > attribute_values; + attribute_values.default_value = geode::PolygonEdge{}; + attribute_values.no_value = geode::PolygonEdge{}; + auto attribute_id = + polygonal_surface.vertex_attribute_manager() + .create_attribute< geode::VariableAttribute, geode::PolygonEdge >( + "test", attribute_values, attribute_properties ); 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 +93,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 +232,31 @@ 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 ); + geode::AttributeProperties attribute_properties; + attribute_properties.assignable = false; + attribute_properties.interpolable = true; + attribute_properties.transferable = true; + geode::AttributeValues< geode::index_t > attribute_values; + attribute_values.default_value = geode::NO_ID; + attribute_values.no_value = geode::NO_ID; + auto attribute_id = + polygonal_surface.edges() + .edge_attribute_manager() + .create_attribute< geode::VariableAttribute, geode::index_t >( + "edges", attribute_values, attribute_properties ); + 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 +363,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 +389,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 +489,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 +519,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 +561,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 +577,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 +608,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 +696,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 +712,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..f4b80d264 100644 --- a/tests/mesh/test-polyhedral-solid.cpp +++ b/tests/mesh/test-polyhedral-solid.cpp @@ -127,26 +127,53 @@ 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 ); + geode::AttributeProperties attribute_properties; + attribute_properties.assignable = false; + attribute_properties.interpolable = true; + attribute_properties.transferable = true; + geode::AttributeValues< geode::index_t > attribute_values; + attribute_values.default_value = geode::NO_ID; + attribute_values.no_value = geode::NO_ID; + auto attribute_id = + polyhedral_solid.facets() + .facet_attribute_manager() + .create_attribute< geode::VariableAttribute, geode::index_t >( + "facet_attribute", attribute_values, attribute_properties ); + 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 ); + geode::AttributeProperties attribute_properties; + attribute_properties.assignable = false; + attribute_properties.interpolable = true; + attribute_properties.transferable = true; + geode::AttributeValues< geode::index_t > attribute_values; + attribute_values.default_value = geode::NO_ID; + attribute_values.no_value = geode::NO_ID; + auto attribute_id = + polyhedral_solid.edges() + .edge_attribute_manager() + .create_attribute< geode::VariableAttribute, geode::index_t >( + "test", attribute_values, attribute_properties ); + 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 +183,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 +363,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 +397,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 +408,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 +442,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 +552,32 @@ void test_normals() "1)" ); } -void test_create_vertex_attribute( +geode::uuid test_create_vertex_attribute( const geode::PolyhedralSolid3D& polyhedral_solid ) { + geode::AttributeProperties attribute_properties; + attribute_properties.assignable = false; + attribute_properties.interpolable = true; + attribute_properties.transferable = true; + geode::AttributeValues< geode::PolyhedronFacetVertex > attribute_values; + attribute_values.default_value = geode::PolyhedronFacetVertex{}; + attribute_values.no_value = geode::PolyhedronFacetVertex{}; + auto attribute_id = polyhedral_solid.vertex_attribute_manager() + .create_attribute< geode::VariableAttribute, + geode::PolyhedronFacetVertex >( "test", + attribute_values, attribute_properties ); 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 +593,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 +680,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..de796014a 100644 --- a/tests/mesh/test-regular-grid.cpp +++ b/tests/mesh/test-regular-grid.cpp @@ -353,16 +353,31 @@ 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"; + geode::AttributeProperties attribute_properties; + attribute_properties.assignable = false; + attribute_properties.interpolable = true; + attribute_properties.transferable = true; + geode::AttributeValues< int > attribute_values_int; + attribute_values_int.default_value = 0; + attribute_values_int.no_value = 0; + auto attribute_id = + grid.polyhedron_attribute_manager() + .create_attribute< geode::VariableAttribute, int >( + "int_attribute", attribute_values_int, attribute_properties ); 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 ); + geode::AttributeValues< double > attribute_values_double; + attribute_values_double.default_value = 0; + attribute_values_double.no_value = 0; + 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", attribute_values_double, + attribute_properties ); + 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 +429,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 +469,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 +566,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-function.cpp b/tests/mesh/test-tetrahedral-solid-function.cpp index 998419c74..af8c4ef28 100644 --- a/tests/mesh/test-tetrahedral-solid-function.cpp +++ b/tests/mesh/test-tetrahedral-solid-function.cpp @@ -73,7 +73,7 @@ void test_scalar_function( geode::TetrahedralSolid3D& solid ) { const auto function_name = "scalar_function"; auto scalar_function = geode::TetrahedralSolidScalarFunction3D::create( - solid, function_name, 26 ); + solid, function_name, geode::uuid{}, 26 ); scalar_function.set_value( 2, 22 ); for( const auto i : geode::LRange{ 8 } ) { @@ -110,8 +110,9 @@ void test_scalar_function( geode::TetrahedralSolid3D& solid ) void test_point_function( geode::TetrahedralSolid3D& solid ) { const auto function_name = "point_function"; + const geode::uuid function_id{}; auto point_function = geode::TetrahedralSolidPointFunction< 3, 3 >::create( - solid, function_name, geode::Point3D{ { 26, 3, -10 } } ); + solid, function_name, function_id, geode::Point3D{ { 26, 3, -10 } } ); point_function.set_value( 2, geode::Point3D{ { 22, -3, -20 } } ); for( const auto i : geode::LRange{ 8 } ) { diff --git a/tests/mesh/test-tetrahedral-solid.cpp b/tests/mesh/test-tetrahedral-solid.cpp index 5cc694de8..c965afd89 100644 --- a/tests/mesh/test-tetrahedral-solid.cpp +++ b/tests/mesh/test-tetrahedral-solid.cpp @@ -323,21 +323,53 @@ 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 ); + geode::AttributeProperties attribute_properties; + attribute_properties.assignable = false; + attribute_properties.interpolable = true; + attribute_properties.transferable = true; + geode::AttributeValues< geode::index_t > attribute_values; + attribute_values.default_value = 0; + attribute_values.no_value = geode::NO_ID; + auto attr_from_id = + solid.facets() + .facet_attribute_manager() + .create_attribute< geode::VariableAttribute, geode::index_t >( + "facet_id", attribute_values, attribute_properties ); + 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", attribute_values, attribute_properties ); 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 +379,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 +416,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 +489,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-function.cpp b/tests/mesh/test-triangulated-surface-function.cpp index 19df6ca26..50666ca57 100644 --- a/tests/mesh/test-triangulated-surface-function.cpp +++ b/tests/mesh/test-triangulated-surface-function.cpp @@ -75,7 +75,7 @@ void test_scalar_function( geode::TriangulatedSurface2D& surface ) { const auto function_name = "scalar_function"; auto scalar_function = geode::TriangulatedSurfaceScalarFunction2D::create( - surface, function_name, 26 ); + surface, function_name, geode::uuid{}, 26 ); scalar_function.set_value( 4, 22 ); scalar_function.set_value( 6, 22 ); for( const auto i : geode::LRange{ 7 } ) @@ -111,9 +111,10 @@ void test_scalar_function( geode::TriangulatedSurface2D& surface ) void test_point_function( geode::TriangulatedSurface2D& surface ) { const auto function_name = "point_function"; + const geode::uuid function_id{}; auto point_function = geode::TriangulatedSurfacePointFunction< 2, 2 >::create( - surface, function_name, geode::Point2D{ { 26, 3 } } ); + surface, function_name, function_id, geode::Point2D{ { 26, 3 } } ); point_function.set_value( 4, geode::Point2D{ { 22, -3 } } ); point_function.set_value( 6, geode::Point2D{ { 22, -3 } } ); for( const auto i : geode::LRange{ 7 } ) diff --git a/tests/mesh/test-triangulated-surface.cpp b/tests/mesh/test-triangulated-surface.cpp index a7469abb5..7d1523b83 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,79 @@ 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 ); + geode::AttributeProperties attribute_properties; + attribute_properties.assignable = false; + attribute_properties.interpolable = true; + attribute_properties.transferable = true; + geode::AttributeValues< geode::index_t > attribute_values; + attribute_values.default_value = 0; + attribute_values.no_value = geode::NO_ID; + auto attr_from_id = + surface.edges() + .edge_attribute_manager() + .create_attribute< geode::VariableAttribute, geode::index_t >( + "edge_id", attribute_values, attribute_properties ); + 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 +324,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 +383,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 ee257e5a6..80d6a9a9a 100644 --- a/tests/model/test-brep.cpp +++ b/tests/model/test-brep.cpp @@ -1245,7 +1245,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( @@ -1312,6 +1312,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( @@ -1487,8 +1503,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(), @@ -1512,7 +1529,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() @@ -1606,11 +1671,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..48d0b3c47 100644 --- a/tests/model/test-relationships.cpp +++ b/tests/model/test-relationships.cpp @@ -167,10 +167,20 @@ 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 = + geode::AttributeProperties attribute_properties; + attribute_properties.assignable = false; + attribute_properties.interpolable = true; + attribute_properties.transferable = true; + geode::AttributeValues< int > attribute_values; + attribute_values.default_value = 0; + attribute_values.no_value = 0; + auto relation_att_id = relations.relation_attribute_manager() - .find_or_create_attribute< geode::VariableAttribute, int >( - "int", 0 ); + .create_attribute< geode::VariableAttribute, int >( + "int", attribute_values, attribute_properties ); + 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 +219,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 );