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..0ccd6ac5 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 ) { @@ -229,7 +229,8 @@ namespace geode } const auto v_id = - builder.corner_mesh_builder( corner_uuid )->create_vertex(); + builder.corner_mesh_builder( brep.corner( corner_uuid ) ) + ->create_vertex(); builder.set_unique_vertex( { brep.corner( corner_uuid ).component_id(), v_id }, vertex_ids()[0] - GMSH_OFFSET_START ); @@ -255,7 +256,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 ); @@ -265,14 +266,13 @@ namespace geode line_uuid = builder.add_line(); id_map.elementary_ids.insert( { cur_gmsh_id, line_uuid } ); } + const auto& line = brep.line( line_uuid ); const auto first_v_id = - builder.line_mesh_builder( line_uuid ) - ->create_vertices( vertex_ids().size() ); + builder.line_mesh_builder( line )->create_vertices( + vertex_ids().size() ); const auto edge_id = - builder.line_mesh_builder( line_uuid ) - ->create_edge( first_v_id, first_v_id + 1 ); - - const auto& line = brep.line( line_uuid ); + builder.line_mesh_builder( line )->create_edge( + first_v_id, first_v_id + 1 ); for( const auto v_id : geode::LIndices{ vertex_ids() } ) { builder.set_unique_vertex( @@ -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 ); @@ -314,16 +314,16 @@ namespace geode id_map.elementary_ids.insert( { cur_gmsh_id, surface_uuid } ); } + const auto& surface = brep.surface( surface_uuid ); const auto first_v_id = - builder.surface_mesh_builder( surface_uuid ) - ->create_vertices( vertex_ids().size() ); + builder.surface_mesh_builder( surface )->create_vertices( + vertex_ids().size() ); std::vector< geode::index_t > v_ids( vertex_ids().size() ); std::iota( v_ids.begin(), v_ids.end(), first_v_id ); const auto polygon_id = - builder.surface_mesh_builder( surface_uuid ) - ->create_polygon( v_ids ); + builder.surface_mesh_builder( surface )->create_polygon( + v_ids ); - const auto& surface = brep.surface( surface_uuid ); for( const auto v_id : geode::LIndices{ vertex_ids() } ) { builder.set_unique_vertex( @@ -372,7 +372,7 @@ namespace geode virtual geode::index_t create_gmsh_polyhedron( geode::BRepBuilder& builder, - const geode::uuid& block_uuid, + const Block3D& block, 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 ); @@ -395,16 +395,16 @@ namespace geode geode::HybridSolid3D::type_name_static() ) ); id_map.elementary_ids.insert( { cur_gmsh_id, block_uuid } ); } + const auto& block = brep.block( block_uuid ); const auto first_v_id = - builder.block_mesh_builder( block_uuid ) - ->create_vertices( vertex_ids().size() ); + builder.block_mesh_builder( block )->create_vertices( + vertex_ids().size() ); std::vector< geode::index_t > v_ids( vertex_ids().size() ); std::iota( v_ids.begin(), v_ids.end(), first_v_id ); const auto polyhedron_id = - create_gmsh_polyhedron( builder, block_uuid, v_ids ); + create_gmsh_polyhedron( builder, block, v_ids ); - const auto& block = brep.block( block_uuid ); for( const auto v_id : geode::LIndices{ vertex_ids() } ) { builder.set_unique_vertex( @@ -427,15 +427,15 @@ namespace geode } geode::index_t create_gmsh_polyhedron( geode::BRepBuilder& builder, - const geode::uuid& block_uuid, + const Block3D& block, const std::vector< geode::index_t >& v_ids ) override final { static const std::array< std::vector< geode::local_index_t >, 4 > gmsh_tetrahedron_faces{ { { 0, 1, 2 }, { 0, 2, 3 }, { 1, 3, 2 }, { 0, 3, 1 } } }; - return builder.block_mesh_builder( block_uuid ) - ->create_polyhedron( v_ids, gmsh_tetrahedron_faces ); + return builder.block_mesh_builder( block )->create_polyhedron( + v_ids, gmsh_tetrahedron_faces ); } }; @@ -451,7 +451,7 @@ namespace geode } geode::index_t create_gmsh_polyhedron( geode::BRepBuilder& builder, - const geode::uuid& block_uuid, + const Block3D& block, const std::vector< geode::index_t >& v_ids ) override final { static const std::array< std::vector< geode::local_index_t >, @@ -459,8 +459,8 @@ namespace geode gmsh_hexahedron_faces{ { { 0, 1, 2, 3 }, { 7, 6, 5, 4 }, { 0, 3, 7, 4 }, { 1, 5, 6, 2 }, { 2, 6, 7, 3 }, { 0, 4, 5, 1 } } }; - return builder.block_mesh_builder( block_uuid ) - ->create_polyhedron( v_ids, gmsh_hexahedron_faces ); + return builder.block_mesh_builder( block )->create_polyhedron( + v_ids, gmsh_hexahedron_faces ); } }; @@ -476,15 +476,15 @@ namespace geode } geode::index_t create_gmsh_polyhedron( geode::BRepBuilder& builder, - const geode::uuid& block_uuid, + const Block3D& block, const std::vector< geode::index_t >& v_ids ) override final { static const std::array< std::vector< geode::local_index_t >, 5 > gmsh_prism_faces{ { { 0, 1, 2 }, { 5, 4, 3 }, { 0, 2, 5, 3 }, { 0, 3, 4, 1 }, { 1, 4, 5, 2 } } }; - return builder.block_mesh_builder( block_uuid ) - ->create_polyhedron( v_ids, gmsh_prism_faces ); + return builder.block_mesh_builder( block )->create_polyhedron( + v_ids, gmsh_prism_faces ); } }; @@ -500,15 +500,15 @@ namespace geode } geode::index_t create_gmsh_polyhedron( geode::BRepBuilder& builder, - const geode::uuid& block_uuid, + const Block3D& block, const std::vector< geode::index_t >& v_ids ) override final { static const std::array< std::vector< geode::local_index_t >, 5 > gmsh_pyramid_faces{ { { 0, 3, 4 }, { 0, 4, 1 }, { 4, 3, 2 }, { 1, 4, 2 }, { 0, 1, 2, 3 } } }; - return builder.block_mesh_builder( block_uuid ) - ->create_polyhedron( v_ids, gmsh_pyramid_faces ); + return builder.block_mesh_builder( block )->create_polyhedron( + v_ids, gmsh_pyramid_faces ); } }; 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..e138f76e 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 ); } @@ -109,11 +121,11 @@ namespace for( const auto& cmv : brep_.component_mesh_vertices( uv_index ) ) { - if( cmv.component_id.type() + if( cmv.component_id.type == geode::Block3D::component_type_static() ) { file_ << uv_index + NODE_OFFSET << geode::SPACE; - file_ << brep_.block( cmv.component_id.id() ) + file_ << brep_.block( cmv.component_id.id ) .mesh() .point( cmv.vertex ) .string() @@ -167,12 +179,12 @@ namespace bool is_vertex_in_block = false; for( const auto& cmv : brep_.component_mesh_vertices( uv_index ) ) { - if( cmv.component_id.type() + if( cmv.component_id.type == geode::Surface3D::component_type_static() ) { is_vertex_on_surface = true; } - else if( cmv.component_id.type() + else if( cmv.component_id.type == geode::Block3D::component_type_static() ) { is_vertex_in_block = true; @@ -196,7 +208,7 @@ namespace brep_.component_mesh_vertices( uv_index ) ) { file_ << uv_index + NODE_OFFSET << geode::SPACE; - file_ << brep_.surface( cmv.component_id.id() ) + file_ << brep_.surface( cmv.component_id.id ) .mesh() .point( cmv.vertex ) .string() diff --git a/src/geode/io/model/msh_input.cpp b/src/geode/io/model/msh_input.cpp index fb2e1fd9..1352dbde 100644 --- a/src/geode/io/model/msh_input.cpp +++ b/src/geode/io/model/msh_input.cpp @@ -438,9 +438,9 @@ namespace const std::string& line ) { const auto tokens = geode::string_split( line ); - return std::make_tuple( geode::string_to_index( tokens.at( 0 ) ), + return { geode::string_to_index( tokens.at( 0 ) ), read_node_coordinates( - tokens.at( 1 ), tokens.at( 2 ), tokens.at( 3 ) ) ); + tokens.at( 1 ), tokens.at( 2 ), tokens.at( 3 ) ) }; } void read_node_section_v4() @@ -603,7 +603,7 @@ namespace { for( const auto& c : brep_.corners() ) { - builder_.corner_mesh_builder( c.id() )->set_point( + builder_.corner_mesh_builder( c )->set_point( 0, nodes_[brep_.unique_vertex( { c.component_id(), 0 } )] ); } } @@ -613,7 +613,7 @@ namespace for( const auto& l : brep_.lines() ) { filter_duplicated_line_vertices( l, brep_ ); - auto line_builder = builder_.line_mesh_builder( l.id() ); + auto line_builder = builder_.line_mesh_builder( l ); for( const auto v : geode::Range{ l.mesh().nb_vertices() } ) { line_builder->set_point( @@ -628,8 +628,7 @@ namespace for( const auto& surface : brep_.surfaces() ) { filter_duplicated_surface_vertices( surface, brep_ ); - auto surface_builder = - builder_.surface_mesh_builder( surface.id() ); + auto surface_builder = builder_.surface_mesh_builder( surface ); const auto& mesh = surface.mesh(); for( const auto v : geode::Range{ mesh.nb_vertices() } ) { @@ -654,13 +653,13 @@ namespace { line.component_id(), e1 } ) ); for( const auto& cmv0 : cmvs0 ) { - if( cmv0.component_id.id() != surface.id() ) + if( cmv0.component_id.id != surface.id() ) { continue; } for( const auto& cmv1 : cmvs1 ) { - if( cmv1.component_id.id() != surface.id() ) + if( cmv1.component_id.id != surface.id() ) { continue; } @@ -692,7 +691,7 @@ namespace for( const auto& b : brep_.blocks() ) { filter_duplicated_block_vertices( b, brep_ ); - auto block_builder = builder_.block_mesh_builder( b.id() ); + auto block_builder = builder_.block_mesh_builder( b ); for( const auto v : geode::Range{ b.mesh().nb_vertices() } ) { block_builder->set_point( @@ -780,8 +779,7 @@ namespace void filter_duplicated_line_vertices( const geode::Line3D& line, geode::BRep& brep ) { - auto builder = - geode::BRepBuilder{ brep }.line_mesh_builder( line.id() ); + auto builder = geode::BRepBuilder{ brep }.line_mesh_builder( line ); filter_duplicated_vertices( line, brep, *builder ); } @@ -789,7 +787,7 @@ namespace const geode::Surface3D& surface, geode::BRep& brep ) { auto builder = - geode::BRepBuilder{ brep }.surface_mesh_builder( surface.id() ); + geode::BRepBuilder{ brep }.surface_mesh_builder( surface ); filter_duplicated_vertices( surface, brep, *builder ); } @@ -797,7 +795,7 @@ namespace const geode::Block3D& block, geode::BRep& brep ) { auto builder = - geode::BRepBuilder{ brep }.block_mesh_builder( block.id() ); + geode::BRepBuilder{ brep }.block_mesh_builder( block ); filter_duplicated_vertices( block, brep, *builder ); } @@ -812,8 +810,8 @@ namespace { for( const auto& incidence_vertex : incidence_type_vertices ) { - b2i_relations[boundary_vertex.component_id.id()].emplace( - incidence_vertex.component_id.id() ); + b2i_relations[boundary_vertex.component_id.id].emplace( + incidence_vertex.component_id.id ); } } } @@ -827,13 +825,13 @@ namespace { for( const auto& boundary_vertex : boundary_type_vertices ) { - if( b2i_relations.find( boundary_vertex.component_id.id() ) + if( b2i_relations.find( boundary_vertex.component_id.id ) == b2i_relations.end() ) { continue; } auto& incidences_in_relations = - b2i_relations.at( boundary_vertex.component_id.id() ); + b2i_relations.at( boundary_vertex.component_id.id ); auto it = incidences_in_relations.cbegin(); while( it != incidences_in_relations.cend() ) @@ -844,7 +842,7 @@ namespace incidence_type_vertices.end(), [&incidence_id]( const geode::ComponentMeshVertex& cmv ) { - return cmv.component_id.id() == incidence_id; + return cmv.component_id.id == incidence_id; } ) == incidence_type_vertices.end() ) { @@ -866,25 +864,25 @@ namespace std::vector< geode::ComponentMeshVertex > blocks_vertices; for( const auto& cmv : brep_.component_mesh_vertices( uv ) ) { - if( cmv.component_id.type() + if( cmv.component_id.type == geode::Corner3D::component_type_static() ) { corners_vertices.push_back( cmv ); continue; } - if( cmv.component_id.type() + if( cmv.component_id.type == geode::Line3D::component_type_static() ) { lines_vertices.push_back( cmv ); continue; } - if( cmv.component_id.type() + if( cmv.component_id.type == geode::Surface3D::component_type_static() ) { surfaces_vertices.push_back( cmv ); continue; } - if( cmv.component_id.type() + if( cmv.component_id.type == geode::Block3D::component_type_static() ) { blocks_vertices.push_back( cmv ); diff --git a/src/geode/io/model/svg_input.cpp b/src/geode/io/model/svg_input.cpp index b0b34bdf..26157c46 100644 --- a/src/geode/io/model/svg_input.cpp +++ b/src/geode/io/model/svg_input.cpp @@ -357,7 +357,8 @@ namespace return; } const auto& line_id = builder_.add_line(); - const auto line_builder = builder_.line_mesh_builder( line_id ); + const auto line_builder = + builder_.line_mesh_builder( section_.line( line_id ) ); line_builder->create_point( vertices.front() ); for( const auto v : geode::Range{ 1, vertices.size() } ) { @@ -377,7 +378,7 @@ namespace for( const auto& unique_point : colocated_info.unique_points ) { const auto corner_id = builder_.add_corner(); - builder_.corner_mesh_builder( corner_id ) + builder_.corner_mesh_builder( section_.corner( corner_id ) ) ->create_point( unique_point ); const auto uv_id = builder_.create_unique_vertex(); builder_.set_unique_vertex( @@ -398,8 +399,8 @@ namespace colocated_info.colocated_mapping[cmv]; const auto& corner = section_.corner( corner_ids[mapped_corner] ); - const auto& line = section_.line( - potential_corner_cmv_[cmv].component_id.id() ); + const auto& line = + section_.line( potential_corner_cmv_[cmv].component_id.id ); if( !boundary_relation_exist( corner, line ) ) { builder_.add_corner_line_boundary_relationship( 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" );