Skip to content

Commit

Permalink
Merge pull request #135 from Geode-solutions/feat/helper_to_get_horiz…
Browse files Browse the repository at this point in the history
…on_from_name

feat(helper): Added function to get horizon id from HorizonsStack and…
  • Loading branch information
MelchiorSchuh authored Oct 2, 2024
2 parents 3551a07 + 833c7db commit 376b98b
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 4 deletions.
4 changes: 2 additions & 2 deletions bindings/python/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# This file is autogenerated by pip-compile with Python 3.10
# by the following command:
#
# pip-compile bindings/python/requirements.in
# pip-compile --pre bindings/python/requirements.in
#
opengeode-core==15.*,>=15.4.7
opengeode-core==15.*,>=15.4.8
# via -r bindings/python/requirements.in
4 changes: 4 additions & 0 deletions bindings/python/src/implicit/representation/core/helpers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@

#include <geode/geosciences/implicit/representation/core/detail/helpers.hpp>

#include <geode/basic/uuid.hpp>

#include <geode/model/representation/core/brep.hpp>

#include <geode/geosciences/implicit/representation/core/stratigraphic_model.hpp>
Expand Down Expand Up @@ -58,6 +60,8 @@ namespace geode
&repair_horizon_stack_if_possible< 2 > )
.def( "repair_horizon_stack_if_possible_3d",
&repair_horizon_stack_if_possible< 3 > )
.def( "horizon_id_from_name_2d", &horizon_id_from_name< 2 > )
.def( "horizon_id_from_name_3d", &horizon_id_from_name< 3 > )
.def( "implicit_section_from_cross_section_scalar_field",
[]( CrossSection& model, std::string_view attribute_name ) {
return implicit_section_from_cross_section_scalar_field(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@

#pragma once

#include <optional>
#include <string_view>

#include <absl/types/span.h>

#include <geode/geosciences/implicit/common.hpp>
Expand All @@ -40,6 +43,7 @@ namespace geode
class StratigraphicSection;
class StratigraphicModel;
struct MeshElement;
struct uuid;
} // namespace geode

namespace geode
Expand Down Expand Up @@ -96,6 +100,11 @@ namespace geode
const HorizonsStack< dimension >& horizon_stack,
HorizonsStackBuilder< dimension >& builder );

template < index_t dimension >
[[nodiscard]] std::optional< uuid > horizon_id_from_name(
const HorizonsStack< dimension >& horizon_stack,
std::string_view horizon_name );

[[nodiscard]] std::vector< MeshElement >
opengeode_geosciences_implicit_api invalid_stratigraphic_tetrahedra(
const StratigraphicModel& model );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,7 @@ namespace geode
}

void save_stratigraphic_blocks(
const geode::StratigraphicModel& implicit_model,
std::string_view prefix )
const StratigraphicModel& implicit_model, std::string_view prefix )
{
index_t counter{ 0 };
for( const auto& block : implicit_model.blocks() )
Expand Down Expand Up @@ -369,6 +368,21 @@ namespace geode
}
}

template < index_t dimension >
std::optional< uuid > horizon_id_from_name(
const HorizonsStack< dimension >& horizon_stack,
absl::string_view horizon_name )
{
for( const auto& horizon : horizon_stack.horizons() )
{
if( horizon.name() == horizon_name )
{
return horizon.id();
}
}
return std::nullopt;
}

std::vector< MeshElement > invalid_stratigraphic_tetrahedra(
const StratigraphicModel& implicit_model )
{
Expand Down Expand Up @@ -425,5 +439,12 @@ namespace geode
template void opengeode_geosciences_implicit_api
repair_horizon_stack_if_possible< 3 >(
const HorizonsStack< 3 >&, HorizonsStackBuilder< 3 >& );

template std::optional< uuid >
opengeode_geosciences_implicit_api horizon_id_from_name< 2 >(
const HorizonsStack< 2 >&, absl::string_view );
template std::optional< uuid >
opengeode_geosciences_implicit_api horizon_id_from_name< 3 >(
const HorizonsStack< 3 >&, absl::string_view );
} // namespace detail
} // namespace geode
11 changes: 11 additions & 0 deletions tests/implicit/test-horizons-stack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,17 @@ void test_create_horizons_stack()
.name()
== units_list[0],
"[Test] Wrong name for unit above bottom horizon." );
const auto bot_horizon_id =
geode::detail::horizon_id_from_name( horizons_stack, horizons_list[0] );
OPENGEODE_EXCEPTION(
bot_horizon_id && bot_horizon_id.value() == bot_horizon,
"[Test] Should have found bottom horizon from first horizon name" );
const auto top_horizon_id =
geode::detail::horizon_id_from_name( horizons_stack, horizons_list[3] );
OPENGEODE_EXCEPTION(
top_horizon_id
&& top_horizon_id.value() == horizons_stack.top_horizon(),
"[Test] Should have found top horizon from last horizon name" );
}

int main()
Expand Down

0 comments on commit 376b98b

Please sign in to comment.