Skip to content

Commit 75f67a5

Browse files
committed
fix(clone): Fixed issue where implicit information was not cloned correctly (wrong uuid at the end).
1 parent 91c3188 commit 75f67a5

File tree

6 files changed

+75
-42
lines changed

6 files changed

+75
-42
lines changed

include/geode/geosciences/explicit/representation/builder/detail/copy.hpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,12 @@ namespace geode
7272
}
7373
else
7474
{
75-
const auto& horizon_id = builder_to.add_horizon();
76-
mapping.map( horizon.id(), horizon_id );
77-
builder_to.set_horizon_name( horizon_id, horizon.name() );
78-
builder_to.set_horizon_type( horizon_id, horizon.type() );
75+
const auto& new_horizon_id = builder_to.add_horizon();
76+
mapping.map( horizon.id(), new_horizon_id );
77+
builder_to.set_horizon_name(
78+
new_horizon_id, horizon.name() );
79+
builder_to.set_horizon_type(
80+
new_horizon_id, horizon.type() );
7981
}
8082
}
8183
}

include/geode/geosciences/explicit/representation/core/detail/clone.hpp

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,28 +42,32 @@ namespace geode
4242
ModelCopyMapping& mapping, const Model& model );
4343

4444
template < typename Model >
45-
[[nodiscard]] BijectiveMapping< uuid > clone_horizon_mapping(
46-
const Model& model )
45+
[[nodiscard]] void add_horizons_clone_mapping(
46+
const Model& model, BijectiveMapping< uuid >& horizons_mapping )
4747
{
48-
BijectiveMapping< uuid > horizon_clone_mapping;
4948
for( const auto& horizon : model.horizons() )
5049
{
51-
horizon_clone_mapping.map( horizon.id(), horizon.id() );
50+
if( !horizons_mapping.has_mapping_input( horizon.id() ) )
51+
{
52+
horizons_mapping.map( horizon.id(), horizon.id() );
53+
}
5254
}
53-
return horizon_clone_mapping;
5455
}
5556

5657
template < typename Model >
57-
[[nodiscard]] BijectiveMapping< uuid > clone_stratigraphic_unit_mapping(
58-
const Model& model )
58+
[[nodiscard]] void add_stratigraphic_units_clone_mapping(
59+
const Model& model,
60+
BijectiveMapping< uuid >& stratigraphic_units_mapping )
5961
{
60-
BijectiveMapping< uuid > stratigraphic_unit_clone_mapping;
6162
for( const auto& stratigraphic_unit : model.stratigraphic_units() )
6263
{
63-
stratigraphic_unit_clone_mapping.map(
64-
stratigraphic_unit.id(), stratigraphic_unit.id() );
64+
if( !stratigraphic_units_mapping.has_mapping_input(
65+
stratigraphic_unit.id() ) )
66+
{
67+
stratigraphic_units_mapping.map(
68+
stratigraphic_unit.id(), stratigraphic_unit.id() );
69+
}
6570
}
66-
return stratigraphic_unit_clone_mapping;
6771
}
6872
} // namespace detail
6973
} // namespace geode

src/geode/geosciences/explicit/representation/core/detail/clone.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,12 @@ namespace
6060
void add_stack_geology_clone_mapping(
6161
geode::ModelCopyMapping& clone_mapping, const Model& model )
6262
{
63-
clone_mapping.emplace(
64-
geode::Horizon< Model::dim >::component_type_static(),
65-
geode::detail::clone_horizon_mapping( model ) );
66-
clone_mapping.emplace(
67-
geode::StratigraphicUnit< Model::dim >::component_type_static(),
68-
geode::detail::clone_stratigraphic_unit_mapping( model ) );
63+
geode::detail::add_horizons_clone_mapping( model,
64+
clone_mapping
65+
[geode::Horizon< Model::dim >::component_type_static()] );
66+
geode::detail::add_stratigraphic_units_clone_mapping(
67+
model, clone_mapping[geode::StratigraphicUnit<
68+
Model::dim >::component_type_static()] );
6969
}
7070

7171
template < typename Model >

src/geode/geosciences/implicit/representation/core/horizons_stack.cpp

Lines changed: 34 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,12 @@ namespace geode
8181
HorizonsStackBuilder< dimension > clone_builder{ stack_clone };
8282
clone_builder.copy_identifier( *this );
8383
ModelCopyMapping clone_mapping;
84-
clone_mapping.emplace(
85-
geode::Horizon< dimension >::component_type_static(),
86-
detail::clone_horizon_mapping( *this ) );
87-
clone_mapping.emplace(
88-
geode::StratigraphicUnit< dimension >::component_type_static(),
89-
detail::clone_stratigraphic_unit_mapping( *this ) );
84+
detail::add_horizons_clone_mapping( *this,
85+
clone_mapping
86+
[geode::Horizon< dimension >::component_type_static()] );
87+
detail::add_stratigraphic_units_clone_mapping(
88+
*this, clone_mapping[geode::StratigraphicUnit<
89+
dimension >::component_type_static()] );
9090
clone_builder.copy( clone_mapping, *this );
9191
if( impl_->top_horizon() && impl_->bottom_horizon() )
9292
{
@@ -111,19 +111,27 @@ namespace geode
111111
auto HorizonsStack< dimension >::bottom_to_top_horizons() const
112112
-> HorizonOrderedRange
113113
{
114-
OPENGEODE_EXCEPTION( impl_->top_horizon() && impl_->bottom_horizon(),
115-
"[HorizonsStack::bottom_to_top_horizons] Cannot iterate on "
116-
"HorizonsStack: top and bottom horizons have not been computed." );
114+
if( !impl_->top_horizon() || !impl_->bottom_horizon() )
115+
{
116+
Logger::warn(
117+
"[HorizonsStack::bottom_to_top_horizons] Iteration "
118+
"on HorizonsStack will be empty: top and bottom "
119+
"horizons have not been computed, or stack is empty." );
120+
}
117121
return { *this };
118122
}
119123

120124
template < index_t dimension >
121125
auto HorizonsStack< dimension >::bottom_to_top_units() const
122126
-> StratigraphicUnitOrderedRange
123127
{
124-
OPENGEODE_EXCEPTION( impl_->top_horizon() && impl_->bottom_horizon(),
125-
"[HorizonsStack::bottom_to_top_units] Cannot iterate on "
126-
"HorizonsStack: top and bottom horizons have not been computed." );
128+
if( !impl_->top_horizon() || !impl_->bottom_horizon() )
129+
{
130+
Logger::warn(
131+
"[HorizonsStack::bottom_to_top_horizons] Iteration "
132+
"on HorizonsStack will be empty: top and bottom "
133+
"horizons have not been computed, or stack is empty" );
134+
}
127135
return { *this };
128136
}
129137

@@ -198,9 +206,13 @@ namespace geode
198206
class HorizonsStack< dimension >::HorizonOrderedRange::Impl
199207
{
200208
public:
201-
Impl( const HorizonsStack< dimension >& stack )
202-
: stack_( stack ), iter_( stack.bottom_horizon().value() )
209+
Impl( const HorizonsStack< dimension >& stack ) : stack_( stack )
203210
{
211+
auto bot_horizon = stack.bottom_horizon();
212+
if( bot_horizon && stack.top_horizon() )
213+
{
214+
iter_ = bot_horizon.value();
215+
}
204216
}
205217

206218
constexpr bool operator!=( const Impl& /*unused*/ ) const
@@ -225,7 +237,7 @@ namespace geode
225237

226238
private:
227239
const HorizonsStack< dimension >& stack_;
228-
uuid iter_;
240+
uuid iter_{};
229241
};
230242

231243
template < index_t dimension >
@@ -274,10 +286,13 @@ namespace geode
274286
class HorizonsStack< dimension >::StratigraphicUnitOrderedRange::Impl
275287
{
276288
public:
277-
Impl( const HorizonsStack< dimension >& stack )
278-
: stack_( stack ),
279-
iter_( stack.under( stack.bottom_horizon().value() ).value() )
289+
Impl( const HorizonsStack< dimension >& stack ) : stack_( stack )
280290
{
291+
auto bot_horizon = stack.bottom_horizon();
292+
if( bot_horizon && stack.top_horizon() )
293+
{
294+
iter_ = stack.under( bot_horizon.value() ).value();
295+
}
281296
}
282297

283298
constexpr bool operator!=( const Impl& /*unused*/ ) const
@@ -302,7 +317,7 @@ namespace geode
302317

303318
private:
304319
const HorizonsStack< dimension >& stack_;
305-
uuid iter_;
320+
uuid iter_{};
306321
};
307322

308323
template < index_t dimension >

src/geode/geosciences/implicit/representation/core/implicit_structural_model.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,7 @@ namespace geode
9797
std::optional< index_t > containing_polyhedron(
9898
const Block3D& block, const Point3D& point ) const
9999
{
100-
auto closest_tetrahedron = std::get< 0 >(
101-
block_mesh_aabb_trees_
100+
auto closest_tetrahedron = std::get< 0 >( block_mesh_aabb_trees_
102101
.at( block.id() )( create_aabb_tree, block.mesh() )
103102
.closest_element_box(
104103
point, block_distance_to_tetras_.at( block.id() ) ) );
@@ -366,6 +365,10 @@ namespace geode
366365
ModelCopyMapping clone_mappings;
367366
detail::add_geology_clone_mapping< StructuralModel >(
368367
clone_mappings, *this );
368+
detail::add_horizons_clone_mapping( this->horizons_stack(),
369+
clone_mappings[Horizon3D::component_type_static()] );
370+
detail::add_stratigraphic_units_clone_mapping( this->horizons_stack(),
371+
clone_mappings[StratigraphicUnit3D::component_type_static()] );
369372
clone_builder.copy_implicit_information( clone_mappings, *this );
370373
return model_clone;
371374
}

tests/implicit/test-horizons-stack.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,15 @@ void test_horizons_stack()
3737
geode::HorizonsStack3D horizons_stack;
3838
geode::HorizonsStackBuilder3D stack_builder{ horizons_stack };
3939

40+
geode::index_t counter{ 0 };
41+
for( const auto& horizon : horizons_stack.bottom_to_top_horizons() )
42+
{
43+
geode::Logger::debug( "[Test] Found horizon ", horizon.id().string() );
44+
counter++;
45+
}
46+
OPENGEODE_EXCEPTION(
47+
counter == 0, "[Test] Range should not have iterated on any horizon." );
48+
4049
const auto& hor0 = stack_builder.add_horizon();
4150
const auto& hor1 = stack_builder.add_horizon();
4251
const geode::uuid hor2{};

0 commit comments

Comments
 (0)