diff --git a/include/geode/io/image/detail/vtk_output.hpp b/include/geode/io/image/detail/vtk_output.hpp index cc9dd57c..244cfcad 100644 --- a/include/geode/io/image/detail/vtk_output.hpp +++ b/include/geode/io/image/detail/vtk_output.hpp @@ -83,16 +83,15 @@ namespace geode const AttributeManager& manager, absl::Span< const index_t > elements ) const { - for( const auto& name : manager.attribute_names() ) + for( const auto& id : manager.attribute_ids() ) { - const auto attribute = - manager.find_generic_attribute( name ); + const auto attribute = manager.find_generic_attribute( id ); if( !attribute || !attribute->is_genericable() ) { continue; } - auto data_array = write_attribute_header( - attribute_node, name, attribute->nb_items() ); + auto data_array = write_attribute_header( attribute_node, + attribute->name().value(), attribute->nb_items() ); auto min = std::numeric_limits< float >::max(); auto max = std::numeric_limits< float >::lowest(); std::string values; @@ -100,6 +99,12 @@ namespace geode { for( const auto i : LRange{ attribute->nb_items() } ) { + if( !attribute->has_value( e ) ) + { + absl::StrAppend( + &values, std::nanf( " " ), " " ); + continue; + } const auto value = attribute->generic_item_value( e, i ); absl::StrAppend( &values, value, " " ); diff --git a/include/geode/io/mesh/detail/vtk_input.hpp b/include/geode/io/mesh/detail/vtk_input.hpp index 40c7704a..73be1042 100644 --- a/include/geode/io/mesh/detail/vtk_input.hpp +++ b/include/geode/io/mesh/detail/vtk_input.hpp @@ -220,16 +220,21 @@ namespace geode OpenGeodeException::TYPE::data, "[VTKInput::build_attribute] Number of attribute " "values is not a multiple of number of components" ); - if( manager.find_generic_attribute( name ) ) - { - return; - } if( nb_components == 1 ) { + AttributeValues< T > default_values; + default_values.default_value = T{}; + default_values.no_value = T{}; + AttributeProperties properties; + properties.assignable = false; + properties.interpolable = false; + properties.transferable = true; + auto attribute_id = + manager.create_attribute< VariableAttribute, T >( + name, default_values, properties ); auto attribute = - manager - .find_or_create_attribute< VariableAttribute, T >( - name, T{} ); + manager.find_attribute< VariableAttribute, T >( + attribute_id ); for( const auto i : Indices{ values } ) { attribute->set_value( i + offset, values[i] ); @@ -374,9 +379,19 @@ namespace geode std::string_view name, index_t offset ) { + AttributeValues< Container > default_values; + default_values.default_value = default_value; + default_values.no_value = default_value; + AttributeProperties properties; + properties.assignable = false; + properties.interpolable = false; + properties.transferable = true; + const auto attribute_id = + manager.create_attribute< VariableAttribute, Container >( + name, default_values, properties ); auto attribute = - manager.find_or_create_attribute< VariableAttribute, - Container >( name, default_value ); + manager.find_attribute< VariableAttribute, Container >( + attribute_id ); for( const auto i : Range{ values.size() / nb_components } ) { for( const auto c : Range{ nb_components } ) diff --git a/include/geode/io/model/detail/vtm_output.hpp b/include/geode/io/model/detail/vtm_output.hpp index de45090d..9959655d 100644 --- a/include/geode/io/model/detail/vtm_output.hpp +++ b/include/geode/io/model/detail/vtm_output.hpp @@ -129,7 +129,7 @@ namespace geode { index_t counter{ 0 }; const auto level = Logger::level(); - Logger::set_level( Logger::LEVEL::warn ); + Logger::set_level( Logger::LEVEL::warning ); absl::FixedArray< async::task< void > > tasks( this->mesh().nb_corners() ); absl::FixedArray< uuid > corner_ids( @@ -187,7 +187,7 @@ namespace geode { index_t counter{ 0 }; const auto level = Logger::level(); - Logger::set_level( Logger::LEVEL::warn ); + Logger::set_level( Logger::LEVEL::warning ); absl::FixedArray< async::task< void > > tasks( this->mesh().nb_lines() ); absl::FixedArray< uuid > line_ids( this->mesh().nb_lines() ); @@ -243,7 +243,7 @@ namespace geode { index_t counter{ 0 }; const auto level = Logger::level(); - Logger::set_level( Logger::LEVEL::warn ); + Logger::set_level( Logger::LEVEL::warning ); absl::FixedArray< async::task< void > > tasks( this->mesh().nb_surfaces() ); absl::FixedArray< uuid > surface_ids( diff --git a/include/geode/io/model/internal/msh_common.hpp b/include/geode/io/model/internal/msh_common.hpp index ce5e403d..44e9f535 100644 --- a/include/geode/io/model/internal/msh_common.hpp +++ b/include/geode/io/model/internal/msh_common.hpp @@ -115,8 +115,8 @@ namespace geode { return physical_ids.find( physical_id ) != physical_ids.end(); } - absl::flat_hash_map< GmshElementID, geode::uuid > elementary_ids; - absl::flat_hash_map< GmshElementID, geode::uuid > physical_ids; + absl::flat_hash_map< GmshElementID, uuid > elementary_ids; + absl::flat_hash_map< GmshElementID, uuid > physical_ids; }; class GMSHElement @@ -215,7 +215,7 @@ namespace geode }; const auto existing_id = id_map.contains_elementary_id( cur_gmsh_id ); - geode::uuid corner_uuid; + uuid corner_uuid; geode::BRepBuilder builder{ brep }; if( existing_id ) { @@ -255,7 +255,7 @@ namespace geode const auto existing_id = id_map.contains_elementary_id( cur_gmsh_id ); geode::BRepBuilder builder{ brep }; - geode::uuid line_uuid; + uuid line_uuid; if( existing_id ) { line_uuid = id_map.elementary_ids.at( cur_gmsh_id ); @@ -303,7 +303,7 @@ namespace geode const auto existing_id = id_map.contains_elementary_id( cur_gmsh_id ); geode::BRepBuilder builder{ brep }; - geode::uuid surface_uuid; + uuid surface_uuid; if( existing_id ) { surface_uuid = id_map.elementary_ids.at( cur_gmsh_id ); @@ -372,7 +372,7 @@ namespace geode virtual geode::index_t create_gmsh_polyhedron( geode::BRepBuilder& builder, - const geode::uuid& block_uuid, + const uuid& block_uuid, const std::vector< geode::index_t >& v_ids ) = 0; void add_element( geode::BRep& brep, GmshId2Uuids& id_map ) final @@ -383,7 +383,7 @@ namespace geode const auto existing_id = id_map.contains_elementary_id( cur_gmsh_id ); geode::BRepBuilder builder{ brep }; - geode::uuid block_uuid; + uuid block_uuid; if( existing_id ) { block_uuid = id_map.elementary_ids.at( cur_gmsh_id ); @@ -427,7 +427,7 @@ namespace geode } geode::index_t create_gmsh_polyhedron( geode::BRepBuilder& builder, - const geode::uuid& block_uuid, + const uuid& block_uuid, const std::vector< geode::index_t >& v_ids ) override final { static const std::array< std::vector< geode::local_index_t >, @@ -451,7 +451,7 @@ namespace geode } geode::index_t create_gmsh_polyhedron( geode::BRepBuilder& builder, - const geode::uuid& block_uuid, + const uuid& block_uuid, const std::vector< geode::index_t >& v_ids ) override final { static const std::array< std::vector< geode::local_index_t >, @@ -476,7 +476,7 @@ namespace geode } geode::index_t create_gmsh_polyhedron( geode::BRepBuilder& builder, - const geode::uuid& block_uuid, + const uuid& block_uuid, const std::vector< geode::index_t >& v_ids ) override final { static const std::array< std::vector< geode::local_index_t >, @@ -500,7 +500,7 @@ namespace geode } geode::index_t create_gmsh_polyhedron( geode::BRepBuilder& builder, - const geode::uuid& block_uuid, + const uuid& block_uuid, const std::vector< geode::index_t >& v_ids ) override final { static const std::array< std::vector< geode::local_index_t >, diff --git a/src/geode/io/mesh/assimp_input.cpp b/src/geode/io/mesh/assimp_input.cpp index b95238c0..d7223f04 100644 --- a/src/geode/io/mesh/assimp_input.cpp +++ b/src/geode/io/mesh/assimp_input.cpp @@ -140,7 +140,7 @@ namespace geode } catch( const OpenGeodeException& e ) { - Logger::warn( e.what() ); + Logger::warning( e.what() ); } } } diff --git a/src/geode/io/mesh/csv_input_helpers.cpp b/src/geode/io/mesh/csv_input_helpers.cpp index 0d358234..40dafae8 100644 --- a/src/geode/io/mesh/csv_input_helpers.cpp +++ b/src/geode/io/mesh/csv_input_helpers.cpp @@ -154,9 +154,21 @@ namespace geode { continue; } + AttributeValues< double > default_values; + default_values.default_value = value; + default_values.no_value = value; + AttributeProperties properties; + properties.assignable = false; + properties.interpolable = false; + properties.transferable = true; + const auto attribute_id = + attribute_manager + .create_attribute< VariableAttribute, double >( + attribute_name, default_values, properties ); double_attrs[col] = - attribute_manager.find_or_create_attribute< - VariableAttribute, double >( attribute_name, 0.0 ); + attribute_manager + .find_attribute< VariableAttribute, double >( + attribute_id ); } } for( const auto col : geode::Range{ line_values.size() } ) diff --git a/src/geode/io/model/gid_output.cpp b/src/geode/io/model/gid_output.cpp index d3da4d02..2e86b3ff 100644 --- a/src/geode/io/model/gid_output.cpp +++ b/src/geode/io/model/gid_output.cpp @@ -50,23 +50,35 @@ namespace geode::index_t get_material_number_value( const geode::Surface3D& surface ) { - auto attribute = + const auto attribute_ids = surface.mesh() .polygon_attribute_manager() - .find_or_create_attribute< geode::ConstantAttribute, - geode::index_t >( - FRACSIMA_ATTRIBUTE_NAME, 1, { false, true, true } ); + .attribute_ids_matching_name( FRACSIMA_ATTRIBUTE_NAME ); + geode::OpenGeodeIOModelException::check_exception( + attribute_ids.has_value(), nullptr, + geode::OpenGeodeException::TYPE::data, + "The surface does not have a material number attribute" ); + auto attribute = surface.mesh() + .polygon_attribute_manager() + .find_read_only_attribute< geode::index_t >( + attribute_ids.value().at( 0 ) ); return attribute->value( 0 ); } geode::index_t get_material_number_value( const geode::Block3D& block ) { - auto attribute = + const auto attribute_ids = block.mesh() .polyhedron_attribute_manager() - .find_or_create_attribute< geode::ConstantAttribute, - geode::index_t >( - FRACSIMA_ATTRIBUTE_NAME, 1, { false, true, true } ); + .attribute_ids_matching_name( FRACSIMA_ATTRIBUTE_NAME ); + geode::OpenGeodeIOModelException::check_exception( + attribute_ids.has_value(), nullptr, + geode::OpenGeodeException::TYPE::data, + "The surface does not have a material number attribute" ); + auto attribute = block.mesh() + .polyhedron_attribute_manager() + .find_read_only_attribute< geode::index_t >( + attribute_ids.value().at( 0 ) ); return attribute->value( 0 ); } diff --git a/src/geode/io/model/vtm_brep_output.cpp b/src/geode/io/model/vtm_brep_output.cpp index 444eaec1..1590c457 100644 --- a/src/geode/io/model/vtm_brep_output.cpp +++ b/src/geode/io/model/vtm_brep_output.cpp @@ -72,7 +72,7 @@ namespace { geode::index_t counter{ 0 }; const auto level = geode::Logger::level(); - geode::Logger::set_level( geode::Logger::LEVEL::warn ); + geode::Logger::set_level( geode::Logger::LEVEL::warning ); absl::FixedArray< async::task< void > > tasks( mesh().nb_blocks() ); absl::FixedArray< geode::uuid > block_ids( this->mesh().nb_blocks() ); diff --git a/tests/image/test-raster-image.cpp b/tests/image/test-raster-image.cpp index a018e1cc..20f75c85 100644 --- a/tests/image/test-raster-image.cpp +++ b/tests/image/test-raster-image.cpp @@ -48,9 +48,13 @@ void test_jpg_from_gimp_input() geode::OpenGeodeIOImageException::test( raster.nb_cells() == grid->nb_cells(), "[TEST] Wrong number of cells." ); - auto comparison_attribute = - grid->cell_attribute_manager().find_attribute< geode::RGBColor >( + const auto attribute_ids = + grid->cell_attribute_manager().attribute_ids_matching_name( "RGB_data" ); + auto comparison_attribute = + grid->cell_attribute_manager() + .find_read_only_attribute< geode::RGBColor >( + attribute_ids.value().at( 0 ) ); for( const auto cell_id : geode::Range{ raster.nb_cells() } ) { geode::OpenGeodeIOImageException::test( @@ -71,9 +75,13 @@ void test_jpg_from_paraview_input() geode::OpenGeodeIOImageException::test( raster.nb_cells() == grid->nb_cells(), "[TEST] Wrong number of cells." ); - auto comparison_attribute = - grid->cell_attribute_manager().find_attribute< geode::RGBColor >( + const auto attribute_ids = + grid->cell_attribute_manager().attribute_ids_matching_name( "RGB_data" ); + auto comparison_attribute = + grid->cell_attribute_manager() + .find_read_only_attribute< geode::RGBColor >( + attribute_ids.value().at( 0 ) ); for( const auto cell_id : geode::Range{ raster.nb_cells() } ) { geode::OpenGeodeIOImageException::test( @@ -95,9 +103,13 @@ void test_png_input() geode::OpenGeodeIOImageException::test( raster.nb_cells() == grid->nb_cells(), "[TEST] Wrong number of cells." ); - auto comparison_attribute = - grid->cell_attribute_manager().find_attribute< geode::RGBColor >( + const auto attribute_ids = + grid->cell_attribute_manager().attribute_ids_matching_name( "RGB_data" ); + auto comparison_attribute = + grid->cell_attribute_manager() + .find_read_only_attribute< geode::RGBColor >( + attribute_ids.value().at( 0 ) ); for( const auto cell_id : geode::Range{ raster.nb_cells() } ) { geode::OpenGeodeIOImageException::test( diff --git a/tests/mesh/test-vti.cpp b/tests/mesh/test-vti.cpp index 008584d5..3bf3c00c 100644 --- a/tests/mesh/test-vti.cpp +++ b/tests/mesh/test-vti.cpp @@ -43,16 +43,32 @@ void put_attributes_on_grid( const geode::Grid3D& grid ) { + geode::AttributeValues< geode::index_t > default_values; + default_values.default_value = geode::NO_ID; + default_values.no_value = geode::NO_ID; + geode::AttributeProperties properties; + properties.assignable = false; + properties.interpolable = false; + properties.transferable = true; + const auto cell_attribute_id = + grid.cell_attribute_manager() + .create_attribute< geode::VariableAttribute, geode::index_t >( + "id", default_values, properties ); auto att = grid.cell_attribute_manager() - .find_or_create_attribute< geode::VariableAttribute, - geode::index_t >( "id", geode::NO_ID ); + .find_attribute< geode::VariableAttribute, geode::index_t >( + cell_attribute_id ); for( const auto c : geode::Range{ grid.nb_cells() } ) { att->set_value( c, c ); } - auto att_vertex = grid.grid_vertex_attribute_manager() - .find_or_create_attribute< geode::VariableAttribute, - geode::index_t >( "id_vertex", geode::NO_ID ); + const auto vertex_attribute_id = + grid.grid_vertex_attribute_manager() + .create_attribute< geode::VariableAttribute, geode::index_t >( + "id_vertex", default_values, properties ); + auto att_vertex = + grid.grid_vertex_attribute_manager() + .find_attribute< geode::VariableAttribute, geode::index_t >( + vertex_attribute_id ); for( const auto c : geode::Range{ grid.nb_grid_vertices() } ) { att_vertex->set_value( c, c ); diff --git a/tests/mesh/test-vtp.cpp b/tests/mesh/test-vtp.cpp index 20e5a7bc..97cb662e 100644 --- a/tests/mesh/test-vtp.cpp +++ b/tests/mesh/test-vtp.cpp @@ -35,8 +35,8 @@ void check( const geode::PolygonalSurface3D& surface, const std::array< geode::index_t, 2 >& test_answers, - absl::Span< const std::string_view > vertex_attributes, - absl::Span< const std::string_view > polygon_attributes ) + absl::Span< const geode::uuid > vertex_attributes, + absl::Span< const geode::uuid > polygon_attributes ) { geode::OpenGeodeIOMeshException::test( surface.nb_vertices() == test_answers[0], @@ -48,24 +48,26 @@ void check( const geode::PolygonalSurface3D& surface, "Number of polygons in the loaded Surface is not correct: " "should be ", test_answers[1], ", get ", surface.nb_polygons() ); - for( const auto& name : vertex_attributes ) + for( const auto& id : vertex_attributes ) { geode::OpenGeodeIOMeshException::test( - surface.vertex_attribute_manager().attribute_exists( name ), - "Attribute ", name, " was not be loaded as attribute on vertices" ); + surface.vertex_attribute_manager().attribute_exists( id ), + "Attribute ", id.string(), + " was not be loaded as attribute on vertices" ); } - for( const auto& name : polygon_attributes ) + for( const auto& id : polygon_attributes ) { geode::OpenGeodeIOMeshException::test( - surface.polygon_attribute_manager().attribute_exists( name ), - "Attribute ", name, " was not be loaded as attribute on polygons" ); + surface.polygon_attribute_manager().attribute_exists( id ), + "Attribute ", id.string(), + " was not be loaded as attribute on polygons" ); } } void run_test( std::string_view filename, const std::array< geode::index_t, 2 >& test_answers, - absl::Span< const std::string_view > vertex_attributes, - absl::Span< const std::string_view > polygon_attributes ) + absl::Span< const geode::uuid > vertex_attributes, + absl::Span< const geode::uuid > polygon_attributes ) { // Load file auto surface = geode::load_polygonal_surface< 3 >( @@ -103,17 +105,23 @@ int main() { geode::OpenGeodeIOMeshLibrary::initialize(); - run_test( "dfn1_ascii.vtp", { 187, 10 }, { "FractureSize" }, - { "FractureId", "FractureSize", "FractureArea" } ); + std::vector< geode::uuid > first_vertex_attribute_ids; + std::vector< geode::uuid > first_polygon_attribute_ids; + run_test( "dfn1_ascii.vtp", { 187, 10 }, first_vertex_attribute_ids, + first_polygon_attribute_ids ); + std::vector< geode::uuid > second_polygon_attribute_ids; run_test( "dfn2_mesh_compressed.vtp", { 33413, 58820 }, {}, - { "Fracture Label", "Fracture size", "Triangle size", "Border" } ); + second_polygon_attribute_ids ); + std::vector< geode::uuid > third_polygon_attribute_ids; run_test( "dfn2_mesh_append_encoded.vtp", { 33413, 58820 }, {}, - { "Fracture Label", "Fracture size", "Triangle size", "Border" } ); + third_polygon_attribute_ids ); + std::vector< geode::uuid > fourth_polygon_attribute_ids; run_test( "dfn2_mesh_append_encoded_compressed.vtp", { 33413, 58820 }, - {}, - { "Fracture Label", "Fracture size", "Triangle size", "Border" } ); - run_test( "dfn3.vtp", { 238819, 13032 }, { "FractureSize" }, - { "FractureId", "FractureSize", "FractureArea" } ); + {}, fourth_polygon_attribute_ids ); + std::vector< geode::uuid > fifth_vertex_attribute_ids; + std::vector< geode::uuid > fifth_polygon_attribute_ids; + run_test( "dfn3.vtp", { 238819, 13032 }, fifth_vertex_attribute_ids, + fifth_polygon_attribute_ids ); geode::Logger::info( "TEST SUCCESS" ); return 0; diff --git a/tests/model/test-gid.cpp b/tests/model/test-gid.cpp index 4c31c79a..668ed8a9 100644 --- a/tests/model/test-gid.cpp +++ b/tests/model/test-gid.cpp @@ -24,6 +24,7 @@ #include #include +#include #include #include @@ -178,6 +179,31 @@ namespace auto brep = geode::load_brep( absl::StrCat( geode::DATA_PATH, short_filename, ".og_brep" ) ); test( brep ); + geode::AttributeValues< geode::index_t > default_values; + default_values.default_value = 1; + default_values.no_value = geode::NO_ID; + geode::AttributeProperties properties; + properties.assignable = false; + properties.interpolable = true; + properties.transferable = true; + for( const auto& block : brep.blocks() ) + { + const auto& mesh = block.mesh(); + [[maybe_unused]] auto material_attribute = + mesh.polyhedron_attribute_manager() + .create_attribute< geode::ConstantAttribute, + geode::index_t >( + "material_number", default_values, properties ); + } + for( const auto& surface : brep.surfaces() ) + { + const auto& mesh = surface.mesh(); + [[maybe_unused]] auto material_attribute = + mesh.polygon_attribute_manager() + .create_attribute< geode::ConstantAttribute, + geode::index_t >( + "material_number", default_values, properties ); + } const auto filename_gid = absl::StrCat( short_filename, "_output.gid_msh" ); geode::save_brep( brep, filename_gid ); @@ -189,7 +215,6 @@ int main() try { geode::OpenGeodeIOModelLibrary::initialize(); - run_test( "mss", &test_brep_mss ); geode::Logger::info( "TEST SUCCESS" ); diff --git a/tests/model/test-vtm.cpp b/tests/model/test-vtm.cpp index cba351ce..df1cd933 100644 --- a/tests/model/test-vtm.cpp +++ b/tests/model/test-vtm.cpp @@ -47,7 +47,6 @@ int main() geode::load_brep( absl::StrCat( geode::DATA_PATH, "mss.og_brep" ) ); const auto filename = absl::StrCat( "mss.vtm" ); geode::save_brep( brep, filename ); - auto section = geode::load_section( absl::StrCat( geode::DATA_PATH, "mss_cut_section.og_sctn" ) ); const auto filename2 = absl::StrCat( "mss_cut_section.vtm" );