OpenVDB 7.0.0

LevelSetTracker.h
Go to the documentation of this file.
1 // Copyright Contributors to the OpenVDB Project
2 // SPDX-License-Identifier: MPL-2.0
3
11
12 #ifndef OPENVDB_TOOLS_LEVEL_SET_TRACKER_HAS_BEEN_INCLUDED
13 #define OPENVDB_TOOLS_LEVEL_SET_TRACKER_HAS_BEEN_INCLUDED
14
15 #include <tbb/parallel_for.h>
16 #include <openvdb/Types.h>
17 #include <openvdb/math/Math.h>
18 #include <openvdb/math/FiniteDifference.h>
19 #include <openvdb/math/Operators.h>
20 #include <openvdb/math/Stencils.h>
21 #include <openvdb/math/Transform.h>
22 #include <openvdb/Grid.h>
23 #include <openvdb/util/NullInterrupter.h>
24 #include <openvdb/tree/ValueAccessor.h>
25 #include <openvdb/tree/LeafManager.h>
26 #include "ChangeBackground.h"// for changeLevelSetBackground
27 #include "Morphology.h"//for dilateActiveValues
28 #include "Prune.h"// for pruneLevelSet
29 #include <functional>
30 #include <type_traits>
31
32
33 namespace openvdb {
34 OPENVDB_USE_VERSION_NAMESPACE
35 namespace OPENVDB_VERSION_NAME {
36 namespace tools {
37
38 namespace lstrack {
39
43 enum class TrimMode {
44 kNone,
45 kInterior,
46 kExterior,
47 kAll
48 };
49
50 } // namespace lstrack
51
52
54 template<typename GridT, typename InterruptT = util::NullInterrupter>
55 class LevelSetTracker
56 {
57 public:
58 using TrimMode = lstrack::TrimMode;
59
60 using GridType = GridT;
61 using TreeType = typename GridT::TreeType;
62 using LeafType = typename TreeType::LeafNodeType;
63 using ValueType = typename TreeType::ValueType;
64 using LeafManagerType = typename tree::LeafManager<TreeType>; // leafs + buffers
65 using LeafRange = typename LeafManagerType::LeafRange;
66 using BufferType = typename LeafManagerType::BufferType;
67 using MaskTreeType = typename TreeType::template ValueConverter<ValueMask>::Type;
68 static_assert(std::is_floating_point<ValueType>::value,
69 "LevelSetTracker requires a level set grid with floating-point values");
70
72 struct State {
73 State(math::BiasedGradientScheme s = math::HJWENO5_BIAS,
74 math::TemporalIntegrationScheme t = math::TVD_RK1,
75 int n = static_cast<int>(LEVEL_SET_HALF_WIDTH), int g = 1)
76 : spatialScheme(s), temporalScheme(t), normCount(n), grainSize(g) {}
77 math::BiasedGradientScheme spatialScheme;
78 math::TemporalIntegrationScheme temporalScheme;
79 int normCount;// Number of iterations of normalization
80 int grainSize;
81 };
82
85 LevelSetTracker(GridT& grid, InterruptT* interrupt = nullptr);
86
87 virtual ~LevelSetTracker() { delete mLeafs; }
88
91 template <typename MaskType>
92 void normalize(const MaskType* mask);
93
95 void normalize() { this->normalize<MaskTreeType>(nullptr); }
96
99 void track();
100
105 void prune();
106
122 void dilate(int iterations = 1);
123
126 void erode(int iterations = 1);
127
130 bool resize(Index halfWidth = static_cast<Index>(LEVEL_SET_HALF_WIDTH));
131
133 ValueType getHalfWidth() const { return mGrid->background()/mDx; }
134
136 State getState() const { return mState; }
137
139 void setState(const State& s) { mState = s; }
140
142 math::BiasedGradientScheme getSpatialScheme() const { return mState.spatialScheme; }
143
145 void setSpatialScheme(math::BiasedGradientScheme s) { mState.spatialScheme = s; }
146
148 math::TemporalIntegrationScheme getTemporalScheme() const { return mState.temporalScheme; }
149
151 void setTemporalScheme(math::TemporalIntegrationScheme s) { mState.temporalScheme = s;}
152
155 int getNormCount() const { return mState.normCount; }
156
159 void setNormCount(int n) { mState.normCount = n; }
160
162 int getGrainSize() const { return mState.grainSize; }
163
166 void setGrainSize(int grainsize) { mState.grainSize = grainsize; }
167
171 TrimMode trimming() const { return mTrimMode; }
174 void setTrimming(TrimMode mode) { mTrimMode = mode; }
175
176 ValueType voxelSize() const { return mDx; }
177
178 void startInterrupter(const char* msg);
179
180 void endInterrupter();
181
183 bool checkInterrupter();
184
185 const GridType& grid() const { return *mGrid; }
186
187 LeafManagerType& leafs() { return *mLeafs; }
188
189 const LeafManagerType& leafs() const { return *mLeafs; }
190
191 private:
192 // disallow copy construction and copy by assignment!
193 LevelSetTracker(const LevelSetTracker&);// not implemented
194 LevelSetTracker& operator=(const LevelSetTracker&);// not implemented
195
196 // Private class to perform multi-threaded trimming of
197 // voxels that are too far away from the zero-crossing.
198 template<TrimMode Trimming>
199 struct Trim
200 {
201 Trim(LevelSetTracker& tracker) : mTracker(tracker) {}
202 void trim();
203 void operator()(const LeafRange& r) const;
204 LevelSetTracker& mTracker;
205 };// Trim
206
207 // Private struct to perform multi-threaded normalization
208 template<math::BiasedGradientScheme SpatialScheme,
209 math::TemporalIntegrationScheme TemporalScheme,
210 typename MaskT>
211 struct Normalizer
212 {
213 using SchemeT = math::BIAS_SCHEME<SpatialScheme>;
214 using StencilT = typename SchemeT::template ISStencil<GridType>::StencilType;
215 using MaskLeafT = typename MaskT::LeafNodeType;
216 using MaskIterT = typename MaskLeafT::ValueOnCIter;
217 using VoxelIterT = typename LeafType::ValueOnCIter;
218
219 Normalizer(LevelSetTracker& tracker, const MaskT* mask);
220 void normalize();
221 void operator()(const LeafRange& r) const {mTask(const_cast<Normalizer*>(this), r);}
222 void cook(const char* msg, int swapBuffer=0);
223 template <int Nominator, int Denominator>
224 void euler(const LeafRange& range, Index phiBuffer, Index resultBuffer);
225 inline void euler01(const LeafRange& r) {this->euler<0,1>(r, 0, 1);}
226 inline void euler12(const LeafRange& r) {this->euler<1,2>(r, 1, 1);}
227 inline void euler34(const LeafRange& r) {this->euler<3,4>(r, 1, 2);}
228 inline void euler13(const LeafRange& r) {this->euler<1,3>(r, 1, 2);}
229 template <int Nominator, int Denominator>
230 void eval(StencilT& stencil, const ValueType* phi, ValueType* result, Index n) const;
231 LevelSetTracker& mTracker;
232 const MaskT* mMask;
233 const ValueType mDt, mInvDx;
234 typename std::function<void (Normalizer*, const LeafRange&)> mTask;
235 }; // Normalizer struct
236
237 template<math::BiasedGradientScheme SpatialScheme, typename MaskT>
238 void normalize1(const MaskT* mask);
239
240 template<math::BiasedGradientScheme SpatialScheme,
241 math::TemporalIntegrationScheme TemporalScheme, typename MaskT>
242 void normalize2(const MaskT* mask);
243
244 // Throughout the methods below mLeafs is always assumed to contain
245 // a list of the current LeafNodes! The auxiliary buffers on the
246 // other hand always have to be allocated locally, since some
247 // methods need them and others don't!
248 GridType* mGrid;
249 LeafManagerType* mLeafs;
250 InterruptT* mInterrupter;
251 const ValueType mDx;
252 State mState;
253 TrimMode mTrimMode = TrimMode::kAll;
254 }; // end of LevelSetTracker class
255
256 template<typename GridT, typename InterruptT>
257 LevelSetTracker<GridT, InterruptT>::
258 LevelSetTracker(GridT& grid, InterruptT* interrupt):
259 mGrid(&grid),
260 mLeafs(new LeafManagerType(grid.tree())),
261 mInterrupter(interrupt),
262 mDx(static_cast<ValueType>(grid.voxelSize()[0])),
263 mState()
264 {
265 if ( !grid.hasUniformVoxels() ) {
266 OPENVDB_THROW(RuntimeError,
267 "The transform must have uniform scale for the LevelSetTracker to function");
268 }
269 if ( grid.getGridClass() != GRID_LEVEL_SET) {
270 OPENVDB_THROW(RuntimeError,
271 "LevelSetTracker expected a level set, got a grid of class \""
272 + grid.gridClassToString(grid.getGridClass())
273 + "\" [hint: Grid::setGridClass(openvdb::GRID_LEVEL_SET)]");
274 }
275 }
276
277 template<typename GridT, typename InterruptT>
278 inline void
279 LevelSetTracker<GridT, InterruptT>::
280 prune()
281 {
282 this->startInterrupter("Pruning Level Set");
283
284 // Set voxels that are too far away from the zero crossing to the background value.
285 switch (mTrimMode) {
286 case TrimMode::kNone: break;
287 case TrimMode::kInterior: Trim<TrimMode::kInterior>(*this).trim(); break;
288 case TrimMode::kExterior: Trim<TrimMode::kExterior>(*this).trim(); break;
289 case TrimMode::kAll: Trim<TrimMode::kAll>(*this).trim(); break;
290 }
291
292 // Remove inactive nodes from tree
293 tools::pruneLevelSet(mGrid->tree());
294
295 // The tree topology has changes so rebuild the list of leafs
296 mLeafs->rebuildLeafArray();
297 this->endInterrupter();
298 }
299
300 template<typename GridT, typename InterruptT>
301 inline void
302 LevelSetTracker<GridT, InterruptT>::
303 track()
304 {
305 // Dilate narrow-band (this also rebuilds the leaf array!)
306 tools::dilateActiveValues( *mLeafs, 1, tools::NN_FACE, tools::IGNORE_TILES);
307
308 // Compute signed distances in dilated narrow-band
309 this->normalize();
310
311 // Remove voxels that are outside the narrow band
312 this->prune();
313 }
314
315 template<typename GridT, typename InterruptT>
316 inline void
317 LevelSetTracker<GridT, InterruptT>::
318 dilate(int iterations)
319 {
320 if (this->getNormCount() == 0) {
321 for (int i=0; i < iterations; ++i) {
322 tools::dilateActiveValues( *mLeafs, 1, tools::NN_FACE, tools::IGNORE_TILES);
323 tools::changeLevelSetBackground(this->leafs(), mDx + mGrid->background());
324 }
325 } else {
326 for (int i=0; i < iterations; ++i) {
327 MaskTreeType mask0(mGrid->tree(), false, TopologyCopy());
328 tools::dilateActiveValues( *mLeafs, 1, tools::NN_FACE, tools::IGNORE_TILES);
329 tools::changeLevelSetBackground(this->leafs(), mDx + mGrid->background());
330 MaskTreeType mask(mGrid->tree(), false, TopologyCopy());
331 mask.topologyDifference(mask0);
332 this->normalize(&mask);
333 }
334 }
335 }
336
337 template<typename GridT, typename InterruptT>
338 inline void
339 LevelSetTracker<GridT, InterruptT>::
340 erode(int iterations)
341 {
342 tools::erodeVoxels(*mLeafs, iterations);
343 mLeafs->rebuildLeafArray();
344 const ValueType background = mGrid->background() - ValueType(iterations) * mDx;
345 tools::changeLevelSetBackground(this->leafs(), background);
346 }
347
348 template<typename GridT, typename InterruptT>
349 inline bool
350 LevelSetTracker<GridT, InterruptT>::
351 resize(Index halfWidth)
352 {
353 const int wOld = static_cast<int>(math::RoundDown(this->getHalfWidth()));
354 const int wNew = static_cast<int>(halfWidth);
355 if (wOld < wNew) {
356 this->dilate(wNew - wOld);
357 } else if (wOld > wNew) {
358 this->erode(wOld - wNew);
359 }
360 return wOld != wNew;
361 }
362
363 template<typename GridT, typename InterruptT>
364 inline void
365 LevelSetTracker<GridT, InterruptT>::
366 startInterrupter(const char* msg)
367 {
368 if (mInterrupter) mInterrupter->start(msg);
369 }
370
371 template<typename GridT, typename InterruptT>
372 inline void
373 LevelSetTracker<GridT, InterruptT>::
374 endInterrupter()
375 {
376 if (mInterrupter) mInterrupter->end();
377 }
378
379 template<typename GridT, typename InterruptT>
380 inline bool
381 LevelSetTracker<GridT, InterruptT>::
382 checkInterrupter()
383 {
384 if (util::wasInterrupted(mInterrupter)) {
385 tbb::task::self().cancel_group_execution();
386 return false;
387 }
388 return true;
389 }
390
391 template<typename GridT, typename InterruptT>
392 template<typename MaskT>
393 inline void
394 LevelSetTracker<GridT, InterruptT>::
395 normalize(const MaskT* mask)
396 {
397 switch (this->getSpatialScheme()) {
398 case math::FIRST_BIAS:
399 this->normalize1<math::FIRST_BIAS , MaskT>(mask); break;
400 case math::SECOND_BIAS:
401 this->normalize1<math::SECOND_BIAS, MaskT>(mask); break;
402 case math::THIRD_BIAS:
403 this->normalize1<math::THIRD_BIAS, MaskT>(mask); break;
404 case math::WENO5_BIAS:
405 this->normalize1<math::WENO5_BIAS, MaskT>(mask); break;
406 case math::HJWENO5_BIAS:
407 this->normalize1<math::HJWENO5_BIAS, MaskT>(mask); break;
408 case math::UNKNOWN_BIAS:
409 default:
410 OPENVDB_THROW(ValueError, "Spatial difference scheme not supported!");
411 }
412 }
413
414 template<typename GridT, typename InterruptT>
415 template<math::BiasedGradientScheme SpatialScheme, typename MaskT>
416 inline void
417 LevelSetTracker<GridT, InterruptT>::
418 normalize1(const MaskT* mask)
419 {
420 switch (this->getTemporalScheme()) {
421 case math::TVD_RK1:
422 this->normalize2<SpatialScheme, math::TVD_RK1, MaskT>(mask); break;
423 case math::TVD_RK2:
424 this->normalize2<SpatialScheme, math::TVD_RK2, MaskT>(mask); break;
425 case math::TVD_RK3:
426 this->normalize2<SpatialScheme, math::TVD_RK3, MaskT>(mask); break;
427 case math::UNKNOWN_TIS:
428 default:
429 OPENVDB_THROW(ValueError, "Temporal integration scheme not supported!");
430 }
431 }
432
433 template<typename GridT, typename InterruptT>
434 template<math::BiasedGradientScheme SpatialScheme,
435 math::TemporalIntegrationScheme TemporalScheme,
436 typename MaskT>
437 inline void
438 LevelSetTracker<GridT, InterruptT>::
439 normalize2(const MaskT* mask)
440 {
441 Normalizer<SpatialScheme, TemporalScheme, MaskT> tmp(*this, mask);
442 tmp.normalize();
443 }
444
445
447
448
449 template<typename GridT, typename InterruptT>
450 template<lstrack::TrimMode Trimming>
451 inline void
452 LevelSetTracker<GridT, InterruptT>::Trim<Trimming>::trim()
453 {
454 OPENVDB_NO_UNREACHABLE_CODE_WARNING_BEGIN
455 if (Trimming != TrimMode::kNone) {
456 const int grainSize = mTracker.getGrainSize();
457 const LeafRange range = mTracker.leafs().leafRange(grainSize);
458
459 if (grainSize>0) {
460 tbb::parallel_for(range, *this);
461 } else {
462 (*this)(range);
463 }
464 }
465 OPENVDB_NO_UNREACHABLE_CODE_WARNING_END
466 }
467
468
470 template<typename GridT, typename InterruptT>
471 template<lstrack::TrimMode Trimming>
472 inline void
473 LevelSetTracker<GridT, InterruptT>::Trim<Trimming>::operator()(const LeafRange& range) const
474 {
475 mTracker.checkInterrupter();
476 const ValueType gamma = mTracker.mGrid->background();
477
478 OPENVDB_NO_UNREACHABLE_CODE_WARNING_BEGIN
479 for (auto leafIter = range.begin(); leafIter; ++leafIter) {
480 auto& leaf = *leafIter;
481 for (auto iter = leaf.beginValueOn(); iter; ++iter) {
482 const auto val = *iter;
483 switch (Trimming) { // resolved at compile time
484 case TrimMode::kNone:
485 break;
486 case TrimMode::kInterior:
487 if (val <= -gamma) { leaf.setValueOff(iter.pos(), -gamma); }
488 break;
489 case TrimMode::kExterior:
490 if (val >= gamma) { leaf.setValueOff(iter.pos(), gamma); }
491 break;
492 case TrimMode::kAll:
493 if (val <= -gamma) {
494 leaf.setValueOff(iter.pos(), -gamma);
495 } else if (val >= gamma) {
496 leaf.setValueOff(iter.pos(), gamma);
497 }
498 break;
499 }
500 }
501 }
502 OPENVDB_NO_UNREACHABLE_CODE_WARNING_END
503 }
504
505
507
508 template<typename GridT, typename InterruptT>
509 template<math::BiasedGradientScheme SpatialScheme,
510 math::TemporalIntegrationScheme TemporalScheme,
511 typename MaskT>
512 inline
513 LevelSetTracker<GridT, InterruptT>::
514 Normalizer<SpatialScheme, TemporalScheme, MaskT>::
515 Normalizer(LevelSetTracker& tracker, const MaskT* mask)
516 : mTracker(tracker)
517 , mMask(mask)
518 , mDt(tracker.voxelSize()*(TemporalScheme == math::TVD_RK1 ? 0.3f :
519 TemporalScheme == math::TVD_RK2 ? 0.9f : 1.0f))
520 , mInvDx(1.0f/tracker.voxelSize())
521 , mTask(nullptr)
522 {
523 }
524
525 template<typename GridT, typename InterruptT>
526 template<math::BiasedGradientScheme SpatialScheme,
527 math::TemporalIntegrationScheme TemporalScheme,
528 typename MaskT>
529 inline void
530 LevelSetTracker<GridT, InterruptT>::
531 Normalizer<SpatialScheme, TemporalScheme, MaskT>::
532 normalize()
533 {
534 namespace ph = std::placeholders;
535
537 mTracker.mLeafs->rebuildAuxBuffers(TemporalScheme == math::TVD_RK3 ? 2 : 1);
538
539 for (int n=0, e=mTracker.getNormCount(); n < e; ++n) {
540
541 OPENVDB_NO_UNREACHABLE_CODE_WARNING_BEGIN
542 switch(TemporalScheme) {//switch is resolved at compile-time
543 case math::TVD_RK1:
544 // Perform one explicit Euler step: t1 = t0 + dt
545 // Phi_t1(0) = Phi_t0(0) - dt * VdotG_t0(1)
546 mTask = std::bind(&Normalizer::euler01, ph::_1, ph::_2);
547
548 // Cook and swap buffer 0 and 1 such that Phi_t1(0) and Phi_t0(1)
549 this->cook("Normalizing level set using TVD_RK1", 1);
550 break;
551 case math::TVD_RK2:
552 // Perform one explicit Euler step: t1 = t0 + dt
553 // Phi_t1(1) = Phi_t0(0) - dt * VdotG_t0(1)
554 mTask = std::bind(&Normalizer::euler01, ph::_1, ph::_2);
555
556 // Cook and swap buffer 0 and 1 such that Phi_t1(0) and Phi_t0(1)
557 this->cook("Normalizing level set using TVD_RK1 (step 1 of 2)", 1);
558
559 // Convex combine explicit Euler step: t2 = t0 + dt
560 // Phi_t2(1) = 1/2 * Phi_t0(1) + 1/2 * (Phi_t1(0) - dt * V.Grad_t1(0))
561 mTask = std::bind(&Normalizer::euler12, ph::_1, ph::_2);
562
563 // Cook and swap buffer 0 and 1 such that Phi_t2(0) and Phi_t1(1)
564 this->cook("Normalizing level set using TVD_RK1 (step 2 of 2)", 1);
565 break;
566 case math::TVD_RK3:
567 // Perform one explicit Euler step: t1 = t0 + dt
568 // Phi_t1(1) = Phi_t0(0) - dt * VdotG_t0(1)
569 mTask = std::bind(&Normalizer::euler01, ph::_1, ph::_2);
570
571 // Cook and swap buffer 0 and 1 such that Phi_t1(0) and Phi_t0(1)
572 this->cook("Normalizing level set using TVD_RK3 (step 1 of 3)", 1);
573
574 // Convex combine explicit Euler step: t2 = t0 + dt/2
575 // Phi_t2(2) = 3/4 * Phi_t0(1) + 1/4 * (Phi_t1(0) - dt * V.Grad_t1(0))
576 mTask = std::bind(&Normalizer::euler34, ph::_1, ph::_2);
577
578 // Cook and swap buffer 0 and 2 such that Phi_t2(0) and Phi_t1(2)
579 this->cook("Normalizing level set using TVD_RK3 (step 2 of 3)", 2);
580
581 // Convex combine explicit Euler step: t3 = t0 + dt
582 // Phi_t3(2) = 1/3 * Phi_t0(1) + 2/3 * (Phi_t2(0) - dt * V.Grad_t2(0)
583 mTask = std::bind(&Normalizer::euler13, ph::_1, ph::_2);
584
585 // Cook and swap buffer 0 and 2 such that Phi_t3(0) and Phi_t2(2)
586 this->cook("Normalizing level set using TVD_RK3 (step 3 of 3)", 2);
587 break;
588 case math::UNKNOWN_TIS:
589 default:
590 OPENVDB_THROW(ValueError, "Temporal integration scheme not supported!");
591 }
592 OPENVDB_NO_UNREACHABLE_CODE_WARNING_END
593 }
594 mTracker.mLeafs->removeAuxBuffers();
595 }
596
599 template<typename GridT, typename InterruptT>
600 template<math::BiasedGradientScheme SpatialScheme,
601 math::TemporalIntegrationScheme TemporalScheme,
602 typename MaskT>
603 inline void
604 LevelSetTracker<GridT, InterruptT>::
605 Normalizer<SpatialScheme, TemporalScheme, MaskT>::
606 cook(const char* msg, int swapBuffer)
607 {
608 mTracker.startInterrupter( msg );
609
610 const int grainSize = mTracker.getGrainSize();
611 const LeafRange range = mTracker.leafs().leafRange(grainSize);
612
613 grainSize>0 ? tbb::parallel_for(range, *this) : (*this)(range);
614
615 mTracker.leafs().swapLeafBuffer(swapBuffer, grainSize==0);
616
617 mTracker.endInterrupter();
618 }
619
620 template<typename GridT, typename InterruptT>
621 template<math::BiasedGradientScheme SpatialScheme,
622 math::TemporalIntegrationScheme TemporalScheme,
623 typename MaskT>
624 template <int Nominator, int Denominator>
625 inline void
626 LevelSetTracker<GridT, InterruptT>::
627 Normalizer<SpatialScheme, TemporalScheme, MaskT>::
628 eval(StencilT& stencil, const ValueType* phi, ValueType* result, Index n) const
629 {
630 using GradientT = typename math::ISGradientNormSqrd<SpatialScheme>;
631 static const ValueType alpha = ValueType(Nominator)/ValueType(Denominator);
632 static const ValueType beta = ValueType(1) - alpha;
633
634 const ValueType normSqGradPhi = GradientT::result(stencil);
635 const ValueType phi0 = stencil.getValue();
636 ValueType v = phi0 / ( math::Sqrt(math::Pow2(phi0) + normSqGradPhi) +
637 math::Tolerance<ValueType>::value() );
638 v = phi0 - mDt * v * (math::Sqrt(normSqGradPhi) * mInvDx - 1.0f);
639 result[n] = Nominator ? alpha * phi[n] + beta * v : v;
640 }
641
642 template<typename GridT, typename InterruptT>
643 template<math::BiasedGradientScheme SpatialScheme,
644 math::TemporalIntegrationScheme TemporalScheme,
645 typename MaskT>
646 template <int Nominator, int Denominator>
647 inline void
648 LevelSetTracker<GridT,InterruptT>::
649 Normalizer<SpatialScheme, TemporalScheme, MaskT>::
650 euler(const LeafRange& range, Index phiBuffer, Index resultBuffer)
651 {
652 mTracker.checkInterrupter();
653
654 StencilT stencil(mTracker.grid());
655
656 for (typename LeafRange::Iterator leafIter = range.begin(); leafIter; ++leafIter) {
657 const ValueType* phi = leafIter.buffer(phiBuffer).data();
658 ValueType* result = leafIter.buffer(resultBuffer).data();
659 if (mMask == nullptr) {
660 for (auto iter = leafIter->cbeginValueOn(); iter; ++iter) {
661 stencil.moveTo(iter);
662 this->eval<Nominator, Denominator>(stencil, phi, result, iter.pos());
663 }//loop over active voxels in the leaf of the level set
664 } else if (const MaskLeafT* mask = mMask->probeLeaf(leafIter->origin())) {
665 const ValueType* phi0 = leafIter->buffer().data();
666 for (MaskIterT iter = mask->cbeginValueOn(); iter; ++iter) {
667 const Index i = iter.pos();
668 stencil.moveTo(iter.getCoord(), phi0[i]);
669 this->eval<Nominator, Denominator>(stencil, phi, result, i);
670 }//loop over active voxels in the leaf of the mask
671 }
672 }//loop over leafs of the level set
673 }
674
675 } // namespace tools
676 } // namespace OPENVDB_VERSION_NAME
677 } // namespace openvdb
678
679 #endif // OPENVDB_TOOLS_LEVEL_SET_TRACKER_HAS_BEEN_INCLUDED
openvdb::v7_0::tools::LevelSetTracker::getSpatialScheme
math::BiasedGradientScheme getSpatialScheme() const
Definition: LevelSetTracker.h:142
openvdb::v7_0::math::FIRST_BIAS
Definition: FiniteDifference.h:167
openvdb::v7_0::tools::LevelSetTracker::getHalfWidth
ValueType getHalfWidth() const
Return the half width of the narrow band in floating-point voxel units.
Definition: LevelSetTracker.h:133
openvdb::v7_0::tools::LevelSetTracker::setGrainSize
void setGrainSize(int grainsize)
Set the grain-size used for multi-threading.
Definition: LevelSetTracker.h:166
openvdb::v7_0::tools::NN_FACE
Definition: Morphology.h:60
openvdb::v7_0::tools::LevelSetTracker::setState
void setState(const State &s)
Set the state of the tracker (see struct defined above)
Definition: LevelSetTracker.h:139
Types.h
openvdb::v7_0::math::WENO5_BIAS
Definition: FiniteDifference.h:170
openvdb::v7_0::tools::LevelSetTracker::prune
void prune()
Set voxels that are outside the narrow band to the background value (if trimming is enabled) and prun...
Definition: LevelSetTracker.h:280
openvdb::v7_0::tools::LevelSetTracker::grid
const GridType & grid() const
Definition: LevelSetTracker.h:185
openvdb::v7_0::tools::LevelSetTracker::leafs
const LeafManagerType & leafs() const
Definition: LevelSetTracker.h:189
openvdb::v7_0::tools::erodeVoxels
void erodeVoxels(TreeType &tree, int iterations=1, NearestNeighbors nn=NN_FACE)
Topologically erode all leaf-level active voxels in the given tree.
Definition: Morphology.h:846
openvdb::v7_0::tools::LevelSetTracker::dilate
void dilate(int iterations=1)
Fast but approximate dilation of the narrow band - one layer at a time. Normally we recommend using t...
Definition: LevelSetTracker.h:318
openvdb::v7_0::tools::LevelSetTracker::MaskTreeType
typename TreeType::template ValueConverter< ValueMask >::Type MaskTreeType
Definition: LevelSetTracker.h:67
openvdb::v7_0::math::TVD_RK1
Definition: FiniteDifference.h:236
Transform.h
openvdb::v7_0::tools::changeLevelSetBackground
void changeLevelSetBackground(TreeOrLeafManagerT &tree, const typename TreeOrLeafManagerT::ValueType &halfWidth, bool threaded=true, size_t grainSize=32)
Replace the background value in all the nodes of a floating-point tree containing a symmetric narrow-...
Definition: ChangeBackground.h:233
openvdb::v7_0::tools::LevelSetTracker::getGrainSize
int getGrainSize() const
Definition: LevelSetTracker.h:162
openvdb::v7_0::tools::IGNORE_TILES
Definition: Morphology.h:75
openvdb::v7_0::tools::LevelSetTracker::track
void track()
Track the level set interface, i.e. rebuild and normalize the narrow band of the level set.
Definition: LevelSetTracker.h:303
openvdb::v7_0::tools::LevelSetTracker::startInterrupter
void startInterrupter(const char *msg)
Definition: LevelSetTracker.h:366
openvdb::v7_0::tools::LevelSetTracker::State::temporalScheme
math::TemporalIntegrationScheme temporalScheme
Definition: LevelSetTracker.h:78
openvdb::v7_0::tools::normalize
GridType::Ptr normalize(const GridType &grid, bool threaded, InterruptT *interrupt)
Normalize the vectors of the given vector-valued grid.
Definition: GridOperators.h:1064
openvdb::v7_0::tools::LevelSetTracker
Performs multi-threaded interface tracking of narrow band level sets.
Definition: LevelSetTracker.h:55
openvdb::v7_0::tools::lstrack::TrimMode::kExterior
Set out-of-band exterior voxels to the background value.
openvdb::v7_0::math::TVD_RK3
Definition: FiniteDifference.h:238
openvdb::v7_0::math::UNKNOWN_TIS
Definition: FiniteDifference.h:235
Grid.h
openvdb::v7_0::math::BiasedGradientScheme
BiasedGradientScheme
Biased Gradients are limited to non-centered differences.
Definition: FiniteDifference.h:165
openvdb::v7_0::tools::LevelSetTracker::erode
void erode(int iterations=1)
Erodes the width of the narrow-band and update the background values.
Definition: LevelSetTracker.h:340
openvdb::v7_0::tools::LevelSetTracker::GridType
GridT GridType
Definition: LevelSetTracker.h:60
openvdb::v7_0::tools::LevelSetTracker::normalize
void normalize()
Iterative normalization, i.e. solving the Eikonal equation.
Definition: LevelSetTracker.h:95
ValueAccessor.h
openvdb::v7_0::tools::LevelSetTracker::State::grainSize
int grainSize
Definition: LevelSetTracker.h:80
openvdb::v7_0::tools::LevelSetTracker::LeafType
typename TreeType::LeafNodeType LeafType
Definition: LevelSetTracker.h:62
openvdb::v7_0::math::Pow2
Type Pow2(Type x)
Return x2.
Definition: Math.h:495
openvdb::v7_0::math::THIRD_BIAS
Definition: FiniteDifference.h:169
openvdb::v7_0::tools::LevelSetTracker::TreeType
typename GridT::TreeType TreeType
Definition: LevelSetTracker.h:61
openvdb::v7_0::tools::LevelSetTracker::State::State
State(math::BiasedGradientScheme s=math::HJWENO5_BIAS, math::TemporalIntegrationScheme t=math::TVD_RK1, int n=static_cast< int >(LEVEL_SET_HALF_WIDTH), int g=1)
Definition: LevelSetTracker.h:73
openvdb::v7_0::tools::LevelSetTracker::setNormCount
void setNormCount(int n)
Set the number of normalizations performed per track or normalize call.
Definition: LevelSetTracker.h:159
openvdb::v7_0::math::HJWENO5_BIAS
Definition: FiniteDifference.h:171
FiniteDifference.h
openvdb::v7_0::tools::LevelSetTracker::getNormCount
int getNormCount() const
Definition: LevelSetTracker.h:155
openvdb::v7_0::tools::LevelSetTracker::LeafRange
typename LeafManagerType::LeafRange LeafRange
Definition: LevelSetTracker.h:65
Math.h
General-purpose arithmetic and comparison routines, most of which accept arbitrary value types (or at...
openvdb::v7_0::math::BIAS_SCHEME
Definition: Operators.h:126
openvdb::v7_0::tools::LevelSetTracker::resize
bool resize(Index halfWidth=static_cast< Index >(LEVEL_SET_HALF_WIDTH))
Resize the width of the narrow band, i.e. perform dilation and renormalization or erosion as required...
Definition: LevelSetTracker.h:351
openvdb::v7_0::LEVEL_SET_HALF_WIDTH
static const Real LEVEL_SET_HALF_WIDTH
Definition: Types.h:460
openvdb::v7_0::tools::pruneLevelSet
void pruneLevelSet(TreeT &tree, bool threaded=true, size_t grainSize=1)
Reduce the memory footprint of a tree by replacing nodes whose values are all inactive with inactive ...
Definition: Prune.h:389
Prune.h
Defined various multi-threaded utility functions for trees.
openvdb::v7_0::tools::lstrack::TrimMode::kInterior
Set out-of-band interior voxels to the background value.
openvdb::v7_0::tree::LeafManager
This class manages a linear array of pointers to a given tree's leaf nodes, as well as optional auxil...
Definition: LeafManager.h:82
openvdb::v7_0::tools::lstrack::TrimMode::kNone
Leave out-of-band voxels intact.
openvdb::v7_0::tools::LevelSetTracker::LeafManagerType
typename tree::LeafManager< TreeType > LeafManagerType
Definition: LevelSetTracker.h:64
openvdb::v7_0::math::RoundDown
float RoundDown(float x)
Return x rounded down to the nearest integer.
Definition: Math.h:750
openvdb::v7_0::TopologyCopy
Tag dispatch class that distinguishes topology copy constructors from deep copy constructors.
Definition: Types.h:681
NullInterrupter.h
OPENVDB_NO_UNREACHABLE_CODE_WARNING_BEGIN
#define OPENVDB_NO_UNREACHABLE_CODE_WARNING_BEGIN
SIMD Intrinsic Headers.
Definition: Platform.h:114
openvdb::v7_0::tools::LevelSetTracker::BufferType
typename LeafManagerType::BufferType BufferType
Definition: LevelSetTracker.h:66
openvdb::v7_0::tools::lstrack::TrimMode::kAll
Set all out-of-band voxels to the background value.
openvdb::v7_0::tools::LevelSetTracker::trimming
TrimMode trimming() const
Return the trimming mode for voxels outside the narrow band.
Definition: LevelSetTracker.h:171
openvdb::v7_0::RuntimeError
Definition: Exceptions.h:63
openvdb::v7_0::tools::LevelSetTracker::leafs
LeafManagerType & leafs()
Definition: LevelSetTracker.h:187
openvdb::v7_0::tools::dilateActiveValues
void dilateActiveValues(TreeType &tree, int iterations=1, NearestNeighbors nn=NN_FACE, TilePolicy mode=PRESERVE_TILES)
Topologically dilate all active values (i.e. both voxels and tiles) in a tree using one of three near...
Definition: Morphology.h:1047
OPENVDB_USE_VERSION_NAMESPACE
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:154
openvdb::v7_0::tools::LevelSetTracker::endInterrupter
void endInterrupter()
Definition: LevelSetTracker.h:374
openvdb::v7_0::tools::lstrack::TrimMode
TrimMode
How to handle voxels that fall outside the narrow band.
Definition: LevelSetTracker.h:43
openvdb::v7_0::math::Sqrt
float Sqrt(float x)
Return the square root of a floating-point value.
Definition: Math.h:708
openvdb::v7_0::tools::LevelSetTracker::setTrimming
void setTrimming(TrimMode mode)
Specify whether to trim voxels outside the narrow band prior to pruning.
Definition: LevelSetTracker.h:174
openvdb::v7_0::tools::prune
void prune(TreeT &tree, typename TreeT::ValueType tolerance=zeroVal< typename TreeT::ValueType >(), bool threaded=true, size_t grainSize=1)
Reduce the memory footprint of a tree by replacing with tiles any nodes whose values are all the same...
Definition: Prune.h:334
LeafManager.h
A LeafManager manages a linear array of pointers to a given tree's leaf nodes, as well as optional au...
openvdb::v7_0::tools::LevelSetTracker::~LevelSetTracker
virtual ~LevelSetTracker()
Definition: LevelSetTracker.h:87
openvdb::v7_0::math::Tolerance::value
static T value()
Definition: Math.h:90
openvdb::v7_0::Index
Index32 Index
Definition: Types.h:31
openvdb::v7_0::tools::LevelSetTracker::State::normCount
int normCount
Definition: LevelSetTracker.h:79
openvdb::v7_0::math::SECOND_BIAS
Definition: FiniteDifference.h:168
openvdb::v7_0::tools::LevelSetTracker::getState
State getState() const
Return the state of the tracker (see struct defined above)
Definition: LevelSetTracker.h:136
openvdb::v7_0::tools::LevelSetTracker::getTemporalScheme
math::TemporalIntegrationScheme getTemporalScheme() const
Definition: LevelSetTracker.h:148
openvdb::v7_0::tools::LevelSetTracker::ValueType
typename TreeType::ValueType ValueType
Definition: LevelSetTracker.h:63
Morphology.h
Implementation of morphological dilation and erosion.
Stencils.h
Defines various finite difference stencils by means of the "curiously recurring template pattern" on ...
OPENVDB_VERSION_NAME
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h:102
openvdb::v7_0::math::UNKNOWN_BIAS
Definition: FiniteDifference.h:166
OPENVDB_NO_UNREACHABLE_CODE_WARNING_END
#define OPENVDB_NO_UNREACHABLE_CODE_WARNING_END
Definition: Platform.h:115
openvdb::v7_0::tools::LevelSetTracker::voxelSize
ValueType voxelSize() const
Definition: LevelSetTracker.h:176
ChangeBackground.h
Efficient multi-threaded replacement of the background values in tree.
openvdb::v7_0::tools::LevelSetTracker::setSpatialScheme
void setSpatialScheme(math::BiasedGradientScheme s)
Set the spatial finite difference scheme.
Definition: LevelSetTracker.h:145
openvdb::v7_0::tools::LevelSetTracker::State
Lightweight struct that stores the state of the LevelSetTracker.
Definition: LevelSetTracker.h:72
openvdb::v7_0::ValueError
Definition: Exceptions.h:65
openvdb::v7_0::util::wasInterrupted
bool wasInterrupted(T *i, int percent=-1)
Definition: NullInterrupter.h:49
openvdb::v7_0::GRID_LEVEL_SET
Definition: Types.h:454
openvdb::v7_0::tools::LevelSetTracker::checkInterrupter
bool checkInterrupter()
Definition: LevelSetTracker.h:382
openvdb
Definition: Exceptions.h:13
openvdb::v7_0::points::index::State
State
Definition: IndexIterator.h:39
openvdb::v7_0::tools::LevelSetTracker::setTemporalScheme
void setTemporalScheme(math::TemporalIntegrationScheme s)
Set the spatial finite difference scheme.
Definition: LevelSetTracker.h:151
openvdb::v7_0::math::TVD_RK2
Definition: FiniteDifference.h:237
Operators.h
openvdb::v7_0::math::TemporalIntegrationScheme
TemporalIntegrationScheme
Temporal integration schemes.
Definition: FiniteDifference.h:234
OPENVDB_THROW
#define OPENVDB_THROW(exception, message)
Definition: Exceptions.h:82
openvdb::v7_0::tools::LevelSetTracker::State::spatialScheme
math::BiasedGradientScheme spatialScheme
Definition: LevelSetTracker.h:77