Skip to content

Commit fda60b0

Browse files
Merge pull request #147 from Geode-solutions/fix/add_top_to_bottom_range_in_horizonstack
fix(HorizonsStack): Added functions to loop on horizons/units from to…
2 parents 769b554 + 3c2169b commit fda60b0

File tree

3 files changed

+134
-24
lines changed

3 files changed

+134
-24
lines changed

include/geode/geosciences/implicit/representation/core/horizons_stack.hpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,16 @@ namespace geode
5757
PASSKEY( HorizonsStackBuilder< dimension >, HorizonsStackBuilderKey );
5858

5959
public:
60+
enum struct RANGEORDER
61+
{
62+
bottom_to_top,
63+
top_to_bottom
64+
};
6065
class opengeode_geosciences_implicit_api HorizonOrderedRange
6166
{
6267
public:
63-
HorizonOrderedRange( const HorizonsStack& horizons_stack );
68+
HorizonOrderedRange(
69+
const HorizonsStack& horizons_stack, RANGEORDER range_order );
6470
HorizonOrderedRange( HorizonOrderedRange&& other ) noexcept;
6571
HorizonOrderedRange( const HorizonOrderedRange& other );
6672
~HorizonOrderedRange();
@@ -90,7 +96,7 @@ namespace geode
9096
{
9197
public:
9298
StratigraphicUnitOrderedRange(
93-
const HorizonsStack& horizons_stack );
99+
const HorizonsStack& horizons_stack, RANGEORDER range_order );
94100
StratigraphicUnitOrderedRange(
95101
StratigraphicUnitOrderedRange&& other ) noexcept;
96102
StratigraphicUnitOrderedRange(
@@ -152,6 +158,10 @@ namespace geode
152158

153159
[[nodiscard]] StratigraphicUnitOrderedRange bottom_to_top_units() const;
154160

161+
[[nodiscard]] HorizonOrderedRange top_to_bottom_horizons() const;
162+
163+
[[nodiscard]] StratigraphicUnitOrderedRange top_to_bottom_units() const;
164+
155165
[[nodiscard]] bool is_eroded_by(
156166
const StratigraphicUnit< dimension >& eroded,
157167
const Horizon< dimension >& erosion ) const;

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

Lines changed: 96 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ namespace geode
118118
"on HorizonsStack will be empty: top and bottom "
119119
"horizons have not been computed, or stack is empty." );
120120
}
121-
return { *this };
121+
return { *this, RANGEORDER::bottom_to_top };
122122
}
123123

124124
template < index_t dimension >
@@ -128,11 +128,39 @@ namespace geode
128128
if( !impl_->top_horizon() || !impl_->bottom_horizon() )
129129
{
130130
Logger::warn(
131-
"[HorizonsStack::bottom_to_top_horizons] Iteration "
131+
"[HorizonsStack::bottom_to_top_units] Iteration "
132+
"on HorizonsStack will be empty: top and bottom "
133+
"horizons have not been computed, or stack is empty" );
134+
}
135+
return { *this, RANGEORDER::bottom_to_top };
136+
}
137+
138+
template < index_t dimension >
139+
auto HorizonsStack< dimension >::top_to_bottom_horizons() const
140+
-> HorizonOrderedRange
141+
{
142+
if( !impl_->top_horizon() || !impl_->bottom_horizon() )
143+
{
144+
Logger::warn(
145+
"[HorizonsStack::top_to_bottom_horizons] Iteration "
146+
"on HorizonsStack will be empty: top and bottom "
147+
"horizons have not been computed, or stack is empty." );
148+
}
149+
return { *this, RANGEORDER::top_to_bottom };
150+
}
151+
152+
template < index_t dimension >
153+
auto HorizonsStack< dimension >::top_to_bottom_units() const
154+
-> StratigraphicUnitOrderedRange
155+
{
156+
if( !impl_->top_horizon() || !impl_->bottom_horizon() )
157+
{
158+
Logger::warn(
159+
"[HorizonsStack::top_to_bottom_units] Iteration "
132160
"on HorizonsStack will be empty: top and bottom "
133161
"horizons have not been computed, or stack is empty" );
134162
}
135-
return { *this };
163+
return { *this, RANGEORDER::top_to_bottom };
136164
}
137165

138166
template < index_t dimension >
@@ -206,12 +234,21 @@ namespace geode
206234
class HorizonsStack< dimension >::HorizonOrderedRange::Impl
207235
{
208236
public:
209-
Impl( const HorizonsStack< dimension >& stack ) : stack_( stack )
237+
Impl( const HorizonsStack< dimension >& stack, RANGEORDER range_order )
238+
: stack_( stack ), range_order_( range_order )
210239
{
211240
auto bot_horizon = stack.bottom_horizon();
212-
if( bot_horizon && stack.top_horizon() )
241+
auto top_horizon = stack.top_horizon();
242+
if( bot_horizon && top_horizon )
213243
{
214-
iter_ = bot_horizon.value();
244+
if( range_order_ == RANGEORDER::bottom_to_top )
245+
{
246+
iter_ = bot_horizon.value();
247+
}
248+
else if( range_order_ == RANGEORDER::top_to_bottom )
249+
{
250+
iter_ = top_horizon.value();
251+
}
215252
}
216253
}
217254

@@ -222,10 +259,23 @@ namespace geode
222259

223260
void operator++()
224261
{
225-
if( iter_ != stack_.top_horizon().value() )
262+
if( range_order_ == RANGEORDER::bottom_to_top )
263+
{
264+
if( iter_ != stack_.top_horizon().value() )
265+
{
266+
iter_ =
267+
stack_.above( stack_.above( iter_ ).value() ).value();
268+
return;
269+
}
270+
}
271+
else if( range_order_ == RANGEORDER::top_to_bottom )
226272
{
227-
iter_ = stack_.above( stack_.above( iter_ ).value() ).value();
228-
return;
273+
if( iter_ != stack_.bottom_horizon().value() )
274+
{
275+
iter_ =
276+
stack_.under( stack_.under( iter_ ).value() ).value();
277+
return;
278+
}
229279
}
230280
iter_ = uuid{};
231281
}
@@ -237,13 +287,14 @@ namespace geode
237287

238288
private:
239289
const HorizonsStack< dimension >& stack_;
290+
RANGEORDER range_order_;
240291
uuid iter_{};
241292
};
242293

243294
template < index_t dimension >
244295
HorizonsStack< dimension >::HorizonOrderedRange::HorizonOrderedRange(
245-
const HorizonsStack& horizons_stack )
246-
: impl_( horizons_stack )
296+
const HorizonsStack& horizons_stack, RANGEORDER bottom_to_top )
297+
: impl_( horizons_stack, bottom_to_top )
247298
{
248299
}
249300

@@ -286,12 +337,21 @@ namespace geode
286337
class HorizonsStack< dimension >::StratigraphicUnitOrderedRange::Impl
287338
{
288339
public:
289-
Impl( const HorizonsStack< dimension >& stack ) : stack_( stack )
340+
Impl( const HorizonsStack< dimension >& stack, RANGEORDER range_order )
341+
: stack_( stack ), range_order_( range_order )
290342
{
291343
auto bot_horizon = stack.bottom_horizon();
292-
if( bot_horizon && stack.top_horizon() )
344+
auto top_horizon = stack.top_horizon();
345+
if( bot_horizon && top_horizon )
293346
{
294-
iter_ = stack.under( bot_horizon.value() ).value();
347+
if( range_order_ == RANGEORDER::bottom_to_top )
348+
{
349+
iter_ = stack.under( bot_horizon.value() ).value();
350+
}
351+
else if( range_order_ == RANGEORDER::top_to_bottom )
352+
{
353+
iter_ = stack.above( top_horizon.value() ).value();
354+
}
295355
}
296356
}
297357

@@ -302,10 +362,25 @@ namespace geode
302362

303363
void operator++()
304364
{
305-
if( iter_ != stack_.above( stack_.top_horizon().value() ).value() )
365+
if( range_order_ == RANGEORDER::bottom_to_top )
306366
{
307-
iter_ = stack_.above( stack_.above( iter_ ).value() ).value();
308-
return;
367+
if( iter_
368+
!= stack_.above( stack_.top_horizon().value() ).value() )
369+
{
370+
iter_ =
371+
stack_.above( stack_.above( iter_ ).value() ).value();
372+
return;
373+
}
374+
}
375+
else if( range_order_ == RANGEORDER::top_to_bottom )
376+
{
377+
if( iter_
378+
!= stack_.under( stack_.bottom_horizon().value() ).value() )
379+
{
380+
iter_ =
381+
stack_.under( stack_.under( iter_ ).value() ).value();
382+
return;
383+
}
309384
}
310385
iter_ = uuid{};
311386
}
@@ -317,13 +392,15 @@ namespace geode
317392

318393
private:
319394
const HorizonsStack< dimension >& stack_;
395+
RANGEORDER range_order_;
320396
uuid iter_{};
321397
};
322398

323399
template < index_t dimension >
324400
HorizonsStack< dimension >::StratigraphicUnitOrderedRange::
325-
StratigraphicUnitOrderedRange( const HorizonsStack& horizons_stack )
326-
: impl_( horizons_stack )
401+
StratigraphicUnitOrderedRange(
402+
const HorizonsStack& horizons_stack, RANGEORDER bottom_to_top )
403+
: impl_( horizons_stack, bottom_to_top )
327404
{
328405
}
329406

tests/implicit/test-horizons-stack.cpp

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ void test_horizons_stack()
3838
geode::HorizonsStackBuilder3D stack_builder{ horizons_stack };
3939

4040
geode::index_t counter{ 0 };
41+
geode::Logger::info(
42+
"There should be a warning on empty iteration after this" );
4143
for( const auto& horizon : horizons_stack.bottom_to_top_horizons() )
4244
{
4345
geode::Logger::debug( "[Test] Found horizon ", horizon.id().string() );
@@ -151,9 +153,17 @@ void test_create_horizons_stack()
151153
" as horizon number ", counter, ", not ", horizon.name() );
152154
counter++;
153155
}
154-
OPENGEODE_EXCEPTION(
155-
counter == 4, "[Test] Range did not pass through all horizons" );
156-
counter = 0;
156+
OPENGEODE_EXCEPTION( counter == 4,
157+
"[Test] Bottom to top Range did not pass through all horizons" );
158+
for( const auto& horizon : horizons_stack.top_to_bottom_horizons() )
159+
{
160+
counter--;
161+
OPENGEODE_EXCEPTION( horizon.name() == horizons_list[counter],
162+
"[Test] Should have found horizon ", horizons_list[counter],
163+
" as horizon number ", counter, ", not ", horizon.name() );
164+
}
165+
OPENGEODE_EXCEPTION( counter == 0,
166+
"[Test] Top to bottom Range did not pass through all horizons" );
157167
for( const auto& s_unit : horizons_stack.bottom_to_top_units() )
158168
{
159169
if( counter != 0 && counter < 4 )
@@ -167,6 +177,19 @@ void test_create_horizons_stack()
167177
}
168178
OPENGEODE_EXCEPTION( counter == 5,
169179
"[Test] Range did not pass through all stratigraphic units" );
180+
for( const auto& s_unit : horizons_stack.top_to_bottom_units() )
181+
{
182+
counter--;
183+
if( counter != 0 && counter < 4 )
184+
{
185+
OPENGEODE_EXCEPTION( s_unit.name() == units_list[counter - 1],
186+
"[Test] Should have found stratigraphic unit ",
187+
units_list[counter - 1], " as unit number ", counter, ", not ",
188+
s_unit.name() );
189+
}
190+
}
191+
OPENGEODE_EXCEPTION( counter == 0, "[Test] Top to bottom Range did not "
192+
"pass through all stratigraphic units" );
170193
}
171194

172195
int main()

0 commit comments

Comments
 (0)