From 0c30df5854cf47faa5bb0765d04cf0d1d2df60dd Mon Sep 17 00:00:00 2001 From: MelchiorSchuh Date: Tue, 21 Oct 2025 14:28:44 +0200 Subject: [PATCH 1/2] fix(Exceptions): Passed some exceptions to DATA exceptions, and allowed helper to create HorizonsStack with only a Stratigrpahic Unit. --- .../geographic_coordinate_system_helper.cpp | 4 +-- .../builder/horizons_stack_builder.cpp | 5 +-- .../representation/core/detail/helpers.cpp | 32 ++++++++++++------- .../representation/core/horizons_stack.cpp | 8 ++--- .../core/implicit_cross_section.cpp | 16 +++++----- .../core/implicit_structural_model.cpp | 22 +++++++------ .../core/stratigraphic_model.cpp | 4 +-- .../core/stratigraphic_section.cpp | 2 +- 8 files changed, 52 insertions(+), 41 deletions(-) diff --git a/src/geode/geosciences/explicit/geometry/geographic_coordinate_system_helper.cpp b/src/geode/geosciences/explicit/geometry/geographic_coordinate_system_helper.cpp index b1bec67..a7003d3 100644 --- a/src/geode/geosciences/explicit/geometry/geographic_coordinate_system_helper.cpp +++ b/src/geode/geosciences/explicit/geometry/geographic_coordinate_system_helper.cpp @@ -57,7 +57,7 @@ namespace using GeoCRS = typename geode::GeographicCoordinateSystem< Mesh::dim >; const auto& crs_manager = mesh.main_coordinate_reference_system_manager(); - OPENGEODE_EXCEPTION( + OPENGEODE_DATA_EXCEPTION( !crs_manager.coordinate_reference_system_exists( crs_name ), "[convert_components_coordinate_reference_system] New CRS name " "already exists" ); @@ -67,7 +67,7 @@ namespace std::make_shared< GeoCRS >( mesh.vertex_attribute_manager(), info ); if( mesh.nb_vertices() != 0 ) { - OPENGEODE_EXCEPTION( + OPENGEODE_DATA_EXCEPTION( crs_manager.active_coordinate_reference_system().type_name() == GeoCRS::type_name_static(), "[convert_components_coordinate_reference_system] Only " diff --git a/src/geode/geosciences/implicit/representation/builder/horizons_stack_builder.cpp b/src/geode/geosciences/implicit/representation/builder/horizons_stack_builder.cpp index 153024a..1936fde 100644 --- a/src/geode/geosciences/implicit/representation/builder/horizons_stack_builder.cpp +++ b/src/geode/geosciences/implicit/representation/builder/horizons_stack_builder.cpp @@ -148,11 +148,12 @@ namespace geode HorizonsStackBuilder< dimension >::add_horizon_in_stratigraphic_unit( const StratigraphicUnit< dimension >& strati_unit ) { - OPENGEODE_EXCEPTION( + OPENGEODE_DATA_EXCEPTION( horizons_stack_.has_stratigraphic_unit( strati_unit.id() ), "[HorizonsStackBuilder::add_horizon_in_stratigraphic_" "unit] Cannot add horizon: statigraphic unit ", - strati_unit.component_id().string() ); + strati_unit.component_id().string(), + " does not exist in the HorizonsStack" ); InsertedHorizonInfo info; info.new_horizon_id = this->create_horizon(); info.strati_unit_above_id = this->create_stratigraphic_unit(); diff --git a/src/geode/geosciences/implicit/representation/core/detail/helpers.cpp b/src/geode/geosciences/implicit/representation/core/detail/helpers.cpp index ec2368b..ee87979 100644 --- a/src/geode/geosciences/implicit/representation/core/detail/helpers.cpp +++ b/src/geode/geosciences/implicit/representation/core/detail/helpers.cpp @@ -58,12 +58,14 @@ namespace void check_number_of_horizons_and_stratigraphic_units( geode::index_t nb_horizons, geode::index_t nb_units ) { - OPENGEODE_EXCEPTION( nb_horizons <= nb_units + 1, - "[repair_horizon_stack_if_possible] Too many horizons compared " + OPENGEODE_DATA_EXCEPTION( nb_horizons <= nb_units + 1, + "[check_number_of_horizons_and_stratigraphic_units] Too many " + "horizons compared " "to stratigraphic units (", nb_horizons, ", should be less than ", nb_units, ")" ); - OPENGEODE_EXCEPTION( nb_units <= nb_horizons + 1, - "[repair_horizon_stack_if_possible] Too many stratigraphic " + OPENGEODE_DATA_EXCEPTION( nb_units <= nb_horizons + 1, + "[check_number_of_horizons_and_stratigraphic_units] Too many " + "stratigraphic " "units compared to horizons (", nb_units, ", should be less than ", nb_horizons, ")" ); } @@ -251,7 +253,7 @@ namespace geode ImplicitStructuralModel&& implicit_model, local_index_t implicit_axis ) { - OPENGEODE_EXCEPTION( implicit_axis < 3, + OPENGEODE_DATA_EXCEPTION( implicit_axis < 3, "[create_stratigraphic_model_from_brep_attribute_and_coords] " "Give a valid axis (0, 1, or 2)." ); @@ -283,15 +285,18 @@ namespace geode absl::Span< const std::string > horizons_names, absl::Span< const std::string > units_names ) { - OPENGEODE_EXCEPTION( !horizons_names.empty(), - "[horizons_stack_from_names] Cannot create HorizonsStack: " - "horizons_names list is empty." ); const auto nb_horizons = horizons_names.size(); const auto nb_units = units_names.size(); check_number_of_horizons_and_stratigraphic_units( nb_horizons, nb_units ); HorizonsStack< dimension > stack; HorizonsStackBuilder< dimension > builder{ stack }; + if( nb_horizons == 0 ) + { + const auto& only_su = builder.add_stratigraphic_unit(); + builder.set_stratigraphic_unit_name( su_above, units_names[0] ); + return stack; + } auto current_horizon = builder.add_horizon(); builder.set_horizon_name( current_horizon, horizons_names[0] ); const auto& su_above = builder.add_stratigraphic_unit(); @@ -333,15 +338,18 @@ namespace geode absl::Span< const std::string > horizons_names, absl::Span< const std::string > units_names ) { - OPENGEODE_EXCEPTION( !horizons_names.empty(), - "[horizons_stack_from_names] Cannot create HorizonsStack: " - "horizons_names list is empty." ); const auto nb_horizons = horizons_names.size(); const auto nb_units = units_names.size(); check_number_of_horizons_and_stratigraphic_units( nb_horizons, nb_units ); HorizonsStack< dimension > stack; HorizonsStackBuilder< dimension > builder{ stack }; + if( nb_horizons == 0 ) + { + const auto& only_su = builder.add_stratigraphic_unit(); + builder.set_stratigraphic_unit_name( su_above, units_names[0] ); + return stack; + } auto current_horizon = builder.add_horizon(); builder.set_horizon_name( current_horizon, horizons_names[0] ); const auto& su_under = builder.add_stratigraphic_unit(); @@ -408,7 +416,7 @@ namespace geode su_above = horizon_stack.above( current_horizon.value() ); horizon_counter++; } - OPENGEODE_EXCEPTION( horizon_counter == nb_horizons, + OPENGEODE_DATA_EXCEPTION( horizon_counter == nb_horizons, "[repair_horizon_stack_if_possible] Missing or wrong " "above/under relations between horizons and stratigraphic " "units." ); diff --git a/src/geode/geosciences/implicit/representation/core/horizons_stack.cpp b/src/geode/geosciences/implicit/representation/core/horizons_stack.cpp index 3d363aa..640ae6d 100644 --- a/src/geode/geosciences/implicit/representation/core/horizons_stack.cpp +++ b/src/geode/geosciences/implicit/representation/core/horizons_stack.cpp @@ -179,8 +179,8 @@ namespace geode auto component_is_a_horizon = this->has_horizon( component ); OPENGEODE_EXCEPTION( component_is_a_horizon || this->has_stratigraphic_unit( component ), - "[HorizonsStack::is_conformal_above] Component does not exist in " - "the stack." ); + "[HorizonsStack::is_conformal_above] Given component with uuid ", + component.string(), " does not exist in the stack." ); if( component_is_a_horizon ) { const auto contact_type = this->horizon( component ).contact_type(); @@ -210,8 +210,8 @@ namespace geode auto component_is_a_horizon = this->has_horizon( component ); OPENGEODE_EXCEPTION( component_is_a_horizon || this->has_stratigraphic_unit( component ), - "[HorizonsStack::is_conformal_above] Component does not exist in " - "the stack." ); + "[HorizonsStack::is_conformal_above] Given component with uuid ", + component.string(), " does not exist in the stack." ); if( component_is_a_horizon ) { const auto contact_type = this->horizon( component ).contact_type(); diff --git a/src/geode/geosciences/implicit/representation/core/implicit_cross_section.cpp b/src/geode/geosciences/implicit/representation/core/implicit_cross_section.cpp index 8d8d7b2..6e2969e 100644 --- a/src/geode/geosciences/implicit/representation/core/implicit_cross_section.cpp +++ b/src/geode/geosciences/implicit/representation/core/implicit_cross_section.cpp @@ -127,12 +127,12 @@ namespace geode std::optional< double > horizon_implicit_value( const Horizon2D& horizon ) const { - OPENGEODE_EXCEPTION( horizons_stack_.has_horizon( horizon.id() ), + OPENGEODE_DATA_EXCEPTION( + horizons_stack_.has_horizon( horizon.id() ), "[horizon_implicit_value] You cannot access the isovalue of " "Horizon ", horizon.id().string(), - " because the horizon is not defined in the " - "HorizonsStack." ); + " because the horizon is not defined in the HorizonsStack." ); const auto value = horizon_isovalues_.find( horizon.id() ); if( value == horizon_isovalues_.end() ) { @@ -145,10 +145,10 @@ namespace geode double implicit_function_value, const Horizon2D& horizon ) const { const auto increasing = increasing_stack_isovalues(); - OPENGEODE_EXCEPTION( increasing.has_value(), - "[implicit_value_is_above_horizon] Could not define if " - "implicit values were " - "increasing or decreasing in the horizon stack." ); + OPENGEODE_DATA_EXCEPTION( increasing.has_value(), + "[implicit_value_is_above_horizon] Could not find if " + "implicit values were increasing or decreasing in the horizon " + "stack." ); const auto it = horizon_isovalues_.find( horizon.id() ); OPENGEODE_EXCEPTION( it != horizon_isovalues_.end(), "[implicit_value_is_above_horizon] Cannot find horizon " @@ -218,7 +218,7 @@ namespace geode implicit_attributes_.reserve( model.nb_surfaces() ); for( const auto& surface : model.surfaces() ) { - OPENGEODE_EXCEPTION( + OPENGEODE_DATA_EXCEPTION( ( surface.mesh().type_name() == TriangulatedSurface2D::type_name_static() ), "[ImplicitCrossSection::instantiate_implicit_" diff --git a/src/geode/geosciences/implicit/representation/core/implicit_structural_model.cpp b/src/geode/geosciences/implicit/representation/core/implicit_structural_model.cpp index 59670a4..3678dd7 100644 --- a/src/geode/geosciences/implicit/representation/core/implicit_structural_model.cpp +++ b/src/geode/geosciences/implicit/representation/core/implicit_structural_model.cpp @@ -126,7 +126,8 @@ namespace geode std::optional< double > horizon_implicit_value( const Horizon3D& horizon ) const { - OPENGEODE_EXCEPTION( horizons_stack_.has_horizon( horizon.id() ), + OPENGEODE_DATA_EXCEPTION( + horizons_stack_.has_horizon( horizon.id() ), "[horizon_implicit_value] You cannot access the isovalue of " "Horizon ", horizon.id().string(), @@ -144,9 +145,9 @@ namespace geode { const auto increasing = increasing_stack_isovalues(); OPENGEODE_EXCEPTION( increasing.has_value(), - "[implicit_value_is_above_horizon] Could not define if " - "implicit values were " - "increasing or decreasing in the horizon stack." ); + "[implicit_value_is_above_horizon] Could not find if " + "implicit values were increasing or decreasing in the horizon " + "stack." ); const auto it = horizon_isovalues_.find( horizon.id() ); OPENGEODE_EXCEPTION( it != horizon_isovalues_.end(), "[implicit_value_is_above_horizon] Cannot find horizon " @@ -220,7 +221,7 @@ namespace geode { continue; } - OPENGEODE_EXCEPTION( + OPENGEODE_DATA_EXCEPTION( ( block.mesh().type_name() == TetrahedralSolid3D::type_name_static() ), "[ImplicitStructuralModel::instantiate_implicit_attribute_" @@ -248,8 +249,8 @@ namespace geode void set_implicit_value( const Block3D& block, index_t vertex_id, double value ) { - OPENGEODE_EXCEPTION( implicit_attributes_.find( block.id() ) - != implicit_attributes_.end(), + OPENGEODE_DATA_EXCEPTION( implicit_attributes_.find( block.id() ) + != implicit_attributes_.end(), "[ImplicitStructuralModel::set_implicit_value] Couldn't find " "block uuid in the attributes registered - Try instantiating " "your attribute first." ); @@ -264,10 +265,11 @@ namespace geode void set_horizon_implicit_value( const Horizon3D& horizon, double isovalue ) { - OPENGEODE_EXCEPTION( horizons_stack_.has_horizon( horizon.id() ), + OPENGEODE_DATA_EXCEPTION( + horizons_stack_.has_horizon( horizon.id() ), "[horizon_implicit_value] You cannot access the isovalue of " - "Horizon ", - horizon.id().string(), + "Horizon '", + horizon.name(), "' with uuid", horizon.id().string(), " because the horizon is not defined in the HorizonsStack." ); horizon_isovalues_[horizon.id()] = isovalue; } diff --git a/src/geode/geosciences/implicit/representation/core/stratigraphic_model.cpp b/src/geode/geosciences/implicit/representation/core/stratigraphic_model.cpp index 6a7ae3f..a4de77f 100644 --- a/src/geode/geosciences/implicit/representation/core/stratigraphic_model.cpp +++ b/src/geode/geosciences/implicit/representation/core/stratigraphic_model.cpp @@ -195,7 +195,7 @@ namespace geode { for( const auto& block : model.blocks() ) { - OPENGEODE_EXCEPTION( + OPENGEODE_DATA_EXCEPTION( ( block.mesh().type_name() == TetrahedralSolid3D::type_name_static() ), "[StratigraphicModel::instantiate_stratigraphic_" @@ -240,7 +240,7 @@ namespace geode void set_stratigraphic_location( const Block3D& block, index_t vertex_id, Point2D value ) { - OPENGEODE_EXCEPTION( + OPENGEODE_DATA_EXCEPTION( stratigraphic_location_attributes_.find( block.id() ) != stratigraphic_location_attributes_.end(), "[StratigraphicModel::set_stratigraphic_location] " diff --git a/src/geode/geosciences/implicit/representation/core/stratigraphic_section.cpp b/src/geode/geosciences/implicit/representation/core/stratigraphic_section.cpp index 80a4bca..faadb95 100644 --- a/src/geode/geosciences/implicit/representation/core/stratigraphic_section.cpp +++ b/src/geode/geosciences/implicit/representation/core/stratigraphic_section.cpp @@ -209,7 +209,7 @@ namespace geode { for( const auto& surface : model.surfaces() ) { - OPENGEODE_EXCEPTION( + OPENGEODE_DATA_EXCEPTION( ( surface.mesh().type_name() == TriangulatedSurface2D::type_name_static() ), "[StratigraphicSection::instantiate_stratigraphic_" From 6c4871e922b77841aaa876a905a4ecd1c4cceff1 Mon Sep 17 00:00:00 2001 From: MelchiorSchuh Date: Tue, 21 Oct 2025 14:47:01 +0200 Subject: [PATCH 2/2] fix compil --- .../implicit/representation/core/detail/helpers.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/geode/geosciences/implicit/representation/core/detail/helpers.cpp b/src/geode/geosciences/implicit/representation/core/detail/helpers.cpp index ee87979..60cdb47 100644 --- a/src/geode/geosciences/implicit/representation/core/detail/helpers.cpp +++ b/src/geode/geosciences/implicit/representation/core/detail/helpers.cpp @@ -294,7 +294,7 @@ namespace geode if( nb_horizons == 0 ) { const auto& only_su = builder.add_stratigraphic_unit(); - builder.set_stratigraphic_unit_name( su_above, units_names[0] ); + builder.set_stratigraphic_unit_name( only_su, units_names[0] ); return stack; } auto current_horizon = builder.add_horizon(); @@ -347,7 +347,7 @@ namespace geode if( nb_horizons == 0 ) { const auto& only_su = builder.add_stratigraphic_unit(); - builder.set_stratigraphic_unit_name( su_above, units_names[0] ); + builder.set_stratigraphic_unit_name( only_su, units_names[0] ); return stack; } auto current_horizon = builder.add_horizon();