Skip to content
Draft

V18 #199

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions include/geode/io/image/detail/vtk_output.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@

#include <geode/basic/attribute_manager.hpp>

namespace geode

Check warning on line 34 in include/geode/io/image/detail/vtk_output.hpp

View workflow job for this annotation

GitHub Actions / test / tidy

include/geode/io/image/detail/vtk_output.hpp:34:1 [modernize-concat-nested-namespaces]

nested namespaces can be concatenated
{
namespace detail
{
template < typename Mesh >
class VTKOutputImpl

Check warning on line 39 in include/geode/io/image/detail/vtk_output.hpp

View workflow job for this annotation

GitHub Actions / test / tidy

include/geode/io/image/detail/vtk_output.hpp:39:15 [cppcoreguidelines-special-member-functions]

class 'VTKOutputImpl' defines a non-default destructor but does not define a copy constructor, a copy assignment operator, a move constructor or a move assignment operator
{
public:
void write_file()
Expand All @@ -59,7 +59,7 @@
"[VTKOutput] Error while writing file: ", filename );
}

virtual ~VTKOutputImpl() {}

Check warning on line 62 in include/geode/io/image/detail/vtk_output.hpp

View workflow job for this annotation

GitHub Actions / test / tidy

include/geode/io/image/detail/vtk_output.hpp:62:21 [hicpp-use-equals-default]

use '= default' to define a trivial destructor

const Mesh& mesh() const
{
Expand All @@ -79,27 +79,32 @@
write_attributes( attribute_node, manager, elements );
}

void write_attributes( pugi::xml_node& attribute_node,

Check warning on line 82 in include/geode/io/image/detail/vtk_output.hpp

View workflow job for this annotation

GitHub Actions / test / tidy

include/geode/io/image/detail/vtk_output.hpp:82:18 [readability-function-cognitive-complexity]

function 'write_attributes' has cognitive complexity of 13 (threshold 10)
const AttributeManager& manager,
absl::Span< const index_t > elements ) const
{
for( const auto& name : manager.attribute_names() )
for( const auto& id : manager.attribute_ids() )

Check warning on line 86 in include/geode/io/image/detail/vtk_output.hpp

View workflow job for this annotation

GitHub Actions / test / tidy

include/geode/io/image/detail/vtk_output.hpp:86:34 [readability-identifier-length]

variable name 'id' is too short, expected at least 3 characters
{
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;
for( const auto e : elements )
{
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, " " );
Expand Down
33 changes: 24 additions & 9 deletions include/geode/io/mesh/detail/vtk_input.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@

#include <geode/geometry/point.hpp>

namespace geode

Check warning on line 42 in include/geode/io/mesh/detail/vtk_input.hpp

View workflow job for this annotation

GitHub Actions / test / tidy

include/geode/io/mesh/detail/vtk_input.hpp:42:1 [modernize-concat-nested-namespaces]

nested namespaces can be concatenated
{
namespace detail
{
template < typename Mesh >
class VTKInputImpl

Check warning on line 47 in include/geode/io/mesh/detail/vtk_input.hpp

View workflow job for this annotation

GitHub Actions / test / tidy

include/geode/io/mesh/detail/vtk_input.hpp:47:15 [cppcoreguidelines-special-member-functions]

class 'VTKInputImpl' defines a default destructor but does not define a copy constructor, a copy assignment operator, a move constructor or a move assignment operator
{
public:
virtual ~VTKInputImpl() = default;
Expand All @@ -59,17 +59,17 @@
return std::move( mesh_ );
}

Percentage is_loadable()

Check failure on line 62 in include/geode/io/mesh/detail/vtk_input.hpp

View workflow job for this annotation

GitHub Actions / test / tidy

include/geode/io/mesh/detail/vtk_input.hpp:62:13 [clang-diagnostic-error]

unknown type name 'Percentage'
{
read_common_data();
std::vector< Percentage > percentages;

Check failure on line 65 in include/geode/io/mesh/detail/vtk_input.hpp

View workflow job for this annotation

GitHub Actions / test / tidy

include/geode/io/mesh/detail/vtk_input.hpp:65:30 [clang-diagnostic-error]

use of undeclared identifier 'Percentage'
for( const auto& vtk_object : root_.children( type_ ) )
{
is_vtk_object_loadable( vtk_object, percentages );
}
if( percentages.empty() )
{
return Percentage{ 0 };

Check failure on line 72 in include/geode/io/mesh/detail/vtk_input.hpp

View workflow job for this annotation

GitHub Actions / test / tidy

include/geode/io/mesh/detail/vtk_input.hpp:72:38 [clang-diagnostic-error]

expected ';' after return statement

Check failure on line 72 in include/geode/io/mesh/detail/vtk_input.hpp

View workflow job for this annotation

GitHub Actions / test / tidy

include/geode/io/mesh/detail/vtk_input.hpp:72:28 [clang-diagnostic-error]

use of undeclared identifier 'Percentage'
}
const auto nb_percentages = percentages.size();
double value{ 0 };
Expand All @@ -77,7 +77,7 @@
{
value += percentage.value();
}
return Percentage{ value / nb_percentages };

Check failure on line 80 in include/geode/io/mesh/detail/vtk_input.hpp

View workflow job for this annotation

GitHub Actions / test / tidy

include/geode/io/mesh/detail/vtk_input.hpp:80:34 [clang-diagnostic-error]

expected ';' after return statement

Check failure on line 80 in include/geode/io/mesh/detail/vtk_input.hpp

View workflow job for this annotation

GitHub Actions / test / tidy

include/geode/io/mesh/detail/vtk_input.hpp:80:24 [clang-diagnostic-error]

use of undeclared identifier 'Percentage'
}

protected:
Expand All @@ -97,7 +97,7 @@

virtual void is_vtk_object_loadable(
const pugi::xml_node& vtk_object,
std::vector< Percentage >& percentages ) const = 0;

Check failure on line 100 in include/geode/io/mesh/detail/vtk_input.hpp

View workflow job for this annotation

GitHub Actions / test / tidy

include/geode/io/mesh/detail/vtk_input.hpp:100:30 [clang-diagnostic-error]

use of undeclared identifier 'Percentage'

void read_common_data()
{
Expand All @@ -124,20 +124,20 @@
index_t read_attribute(
const pugi::xml_node& piece, std::string_view attribute ) const
{
return string_to_index(

Check failure on line 127 in include/geode/io/mesh/detail/vtk_input.hpp

View workflow job for this annotation

GitHub Actions / test / tidy

include/geode/io/mesh/detail/vtk_input.hpp:127:24 [clang-diagnostic-error]

use of undeclared identifier 'string_to_index'
piece.attribute( attribute.data() ).value() );

Check warning on line 128 in include/geode/io/mesh/detail/vtk_input.hpp

View workflow job for this annotation

GitHub Actions / test / tidy

include/geode/io/mesh/detail/vtk_input.hpp:128:48 [bugprone-suspicious-stringview-data-usage]

result of a `data()` call may not be null terminated, provide size information to the callee to prevent potential issues
}

template < typename T >
std::vector< T > read_integer_data_array(
const pugi::xml_node& data ) const
{
const auto format = data.attribute( "format" ).value();

Check warning on line 135 in include/geode/io/mesh/detail/vtk_input.hpp

View workflow job for this annotation

GitHub Actions / test / tidy

include/geode/io/mesh/detail/vtk_input.hpp:135:17 [llvm-qualified-auto]

'const auto format' can be declared as 'const auto *const format'
if( match( format, "appended" ) )
{
return decode< T >( read_appended_data( data ) );
}
else

Check warning on line 140 in include/geode/io/mesh/detail/vtk_input.hpp

View workflow job for this annotation

GitHub Actions / test / tidy

include/geode/io/mesh/detail/vtk_input.hpp:140:17 [llvm-else-after-return]

do not use 'else' after 'return'
{
const auto data_string =
absl::StripAsciiWhitespace( data.child_value() );
Expand Down Expand Up @@ -220,16 +220,21 @@
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] );
Expand Down Expand Up @@ -374,9 +379,19 @@
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 } )
Expand Down
6 changes: 3 additions & 3 deletions include/geode/io/model/detail/vtm_output.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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() );
Expand Down Expand Up @@ -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(
Expand Down
22 changes: 11 additions & 11 deletions include/geode/io/model/internal/msh_common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@
{
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
Expand All @@ -131,7 +131,7 @@
nb_vertices_( nb_vertices ),
vertex_ids_str_( vertex_ids )
{
OpenGeodeIOModelException::check_exception(

Check failure on line 134 in include/geode/io/model/internal/msh_common.hpp

View workflow job for this annotation

GitHub Actions / test / tidy

include/geode/io/model/internal/msh_common.hpp:134:17 [clang-diagnostic-error]

use of undeclared identifier 'OpenGeodeIOModelException'; did you mean 'OpenGeodeModelException'?
elementary_entity_id > 0, nullptr,
OpenGeodeException::TYPE::data,
"[GMSHElement] GMSH tag for elementary entity "
Expand Down Expand Up @@ -215,7 +215,7 @@
};
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 )
{
Expand Down Expand Up @@ -255,7 +255,7 @@
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 );
Expand Down Expand Up @@ -303,7 +303,7 @@
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 );
Expand Down Expand Up @@ -372,7 +372,7 @@

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
Expand All @@ -383,7 +383,7 @@
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 );
Expand Down Expand Up @@ -427,7 +427,7 @@
}

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 >,
Expand All @@ -451,7 +451,7 @@
}

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 >,
Expand All @@ -476,7 +476,7 @@
}

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 >,
Expand All @@ -500,7 +500,7 @@
}

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 >,
Expand Down
2 changes: 1 addition & 1 deletion src/geode/io/mesh/assimp_input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ namespace geode
}
catch( const OpenGeodeException& e )
{
Logger::warn( e.what() );
Logger::warning( e.what() );
}
}
}
Expand Down
16 changes: 14 additions & 2 deletions src/geode/io/mesh/csv_input_helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() } )
Expand Down
28 changes: 20 additions & 8 deletions src/geode/io/model/gid_output.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}

Expand Down
2 changes: 1 addition & 1 deletion src/geode/io/model/vtm_brep_output.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() );
Expand Down
24 changes: 18 additions & 6 deletions tests/image/test-raster-image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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(
Expand All @@ -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(
Expand Down
26 changes: 21 additions & 5 deletions tests/mesh/test-vti.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
Loading
Loading