OpenVDB  8.1.1
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>
19 #include <openvdb/math/Operators.h>
20 #include <openvdb/math/Stencils.h>
21 #include <openvdb/math/Transform.h>
22 #include <openvdb/Grid.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 {
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>
56 {
57 public:
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 {
75  int n = static_cast<int>(LEVEL_SET_HALF_WIDTH), int g = 1)
76  : spatialScheme(s), temporalScheme(t), normCount(n), grainSize(g) {}
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>
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() ) {
267  "The transform must have uniform scale for the LevelSetTracker to function");
268  }
269  if ( grid.getGridClass() != GRID_LEVEL_SET) {
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
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
304 {
305  // Dilate narrow-band (this also rebuilds the leaf array!)
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
318 dilate(int iterations)
319 {
320  if (this->getNormCount() == 0) {
321  for (int i=0; i < iterations; ++i) {
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());
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
340 erode(int iterations)
341 {
343  tools::pruneLevelSet(mLeafs->tree());
344  mLeafs->rebuildLeafArray();
345  const ValueType background = mGrid->background() - ValueType(iterations) * mDx;
346  tools::changeLevelSetBackground(this->leafs(), background);
347 }
348 
349 template<typename GridT, typename InterruptT>
350 inline bool
352 resize(Index halfWidth)
353 {
354  const int wOld = static_cast<int>(math::RoundDown(this->getHalfWidth()));
355  const int wNew = static_cast<int>(halfWidth);
356  if (wOld < wNew) {
357  this->dilate(wNew - wOld);
358  } else if (wOld > wNew) {
359  this->erode(wOld - wNew);
360  }
361  return wOld != wNew;
362 }
363 
364 template<typename GridT, typename InterruptT>
365 inline void
367 startInterrupter(const char* msg)
368 {
369  if (mInterrupter) mInterrupter->start(msg);
370 }
371 
372 template<typename GridT, typename InterruptT>
373 inline void
376 {
377  if (mInterrupter) mInterrupter->end();
378 }
379 
380 template<typename GridT, typename InterruptT>
381 inline bool
384 {
385  if (util::wasInterrupted(mInterrupter)) {
386  tbb::task::self().cancel_group_execution();
387  return false;
388  }
389  return true;
390 }
391 
392 template<typename GridT, typename InterruptT>
393 template<typename MaskT>
394 inline void
396 normalize(const MaskT* mask)
397 {
398  switch (this->getSpatialScheme()) {
399  case math::FIRST_BIAS:
400  this->normalize1<math::FIRST_BIAS , MaskT>(mask); break;
401  case math::SECOND_BIAS:
402  this->normalize1<math::SECOND_BIAS, MaskT>(mask); break;
403  case math::THIRD_BIAS:
404  this->normalize1<math::THIRD_BIAS, MaskT>(mask); break;
405  case math::WENO5_BIAS:
406  this->normalize1<math::WENO5_BIAS, MaskT>(mask); break;
407  case math::HJWENO5_BIAS:
408  this->normalize1<math::HJWENO5_BIAS, MaskT>(mask); break;
409  case math::UNKNOWN_BIAS:
410  default:
411  OPENVDB_THROW(ValueError, "Spatial difference scheme not supported!");
412  }
413 }
414 
415 template<typename GridT, typename InterruptT>
416 template<math::BiasedGradientScheme SpatialScheme, typename MaskT>
417 inline void
419 normalize1(const MaskT* mask)
420 {
421  switch (this->getTemporalScheme()) {
422  case math::TVD_RK1:
423  this->normalize2<SpatialScheme, math::TVD_RK1, MaskT>(mask); break;
424  case math::TVD_RK2:
425  this->normalize2<SpatialScheme, math::TVD_RK2, MaskT>(mask); break;
426  case math::TVD_RK3:
427  this->normalize2<SpatialScheme, math::TVD_RK3, MaskT>(mask); break;
428  case math::UNKNOWN_TIS:
429  default:
430  OPENVDB_THROW(ValueError, "Temporal integration scheme not supported!");
431  }
432 }
433 
434 template<typename GridT, typename InterruptT>
435 template<math::BiasedGradientScheme SpatialScheme,
436  math::TemporalIntegrationScheme TemporalScheme,
437  typename MaskT>
438 inline void
440 normalize2(const MaskT* mask)
441 {
442  Normalizer<SpatialScheme, TemporalScheme, MaskT> tmp(*this, mask);
443  tmp.normalize();
444 }
445 
446 
448 
449 
450 template<typename GridT, typename InterruptT>
451 template<lstrack::TrimMode Trimming>
452 inline void
454 {
456  if (Trimming != TrimMode::kNone) {
457  const int grainSize = mTracker.getGrainSize();
458  const LeafRange range = mTracker.leafs().leafRange(grainSize);
459 
460  if (grainSize>0) {
461  tbb::parallel_for(range, *this);
462  } else {
463  (*this)(range);
464  }
465  }
467 }
468 
469 
471 template<typename GridT, typename InterruptT>
472 template<lstrack::TrimMode Trimming>
473 inline void
475 {
476  mTracker.checkInterrupter();
477  const ValueType gamma = mTracker.mGrid->background();
478 
480  for (auto leafIter = range.begin(); leafIter; ++leafIter) {
481  auto& leaf = *leafIter;
482  for (auto iter = leaf.beginValueOn(); iter; ++iter) {
483  const auto val = *iter;
484  switch (Trimming) { // resolved at compile time
485  case TrimMode::kNone:
486  break;
487  case TrimMode::kInterior:
488  if (val <= -gamma) { leaf.setValueOff(iter.pos(), -gamma); }
489  break;
490  case TrimMode::kExterior:
491  if (val >= gamma) { leaf.setValueOff(iter.pos(), gamma); }
492  break;
493  case TrimMode::kAll:
494  if (val <= -gamma) {
495  leaf.setValueOff(iter.pos(), -gamma);
496  } else if (val >= gamma) {
497  leaf.setValueOff(iter.pos(), gamma);
498  }
499  break;
500  }
501  }
502  }
504 }
505 
506 
508 
509 template<typename GridT, typename InterruptT>
510 template<math::BiasedGradientScheme SpatialScheme,
511  math::TemporalIntegrationScheme TemporalScheme,
512  typename MaskT>
513 inline
516 Normalizer(LevelSetTracker& tracker, const MaskT* mask)
517  : mTracker(tracker)
518  , mMask(mask)
519  , mDt(tracker.voxelSize()*(TemporalScheme == math::TVD_RK1 ? 0.3f :
520  TemporalScheme == math::TVD_RK2 ? 0.9f : 1.0f))
521  , mInvDx(1.0f/tracker.voxelSize())
522  , mTask(nullptr)
523 {
524 }
525 
526 template<typename GridT, typename InterruptT>
527 template<math::BiasedGradientScheme SpatialScheme,
528  math::TemporalIntegrationScheme TemporalScheme,
529  typename MaskT>
530 inline void
533 normalize()
534 {
535  namespace ph = std::placeholders;
536 
538  mTracker.mLeafs->rebuildAuxBuffers(TemporalScheme == math::TVD_RK3 ? 2 : 1);
539 
540  for (int n=0, e=mTracker.getNormCount(); n < e; ++n) {
541 
543  switch(TemporalScheme) {//switch is resolved at compile-time
544  case math::TVD_RK1:
545  // Perform one explicit Euler step: t1 = t0 + dt
546  // Phi_t1(0) = Phi_t0(0) - dt * VdotG_t0(1)
547  mTask = std::bind(&Normalizer::euler01, ph::_1, ph::_2);
548 
549  // Cook and swap buffer 0 and 1 such that Phi_t1(0) and Phi_t0(1)
550  this->cook("Normalizing level set using TVD_RK1", 1);
551  break;
552  case math::TVD_RK2:
553  // Perform one explicit Euler step: t1 = t0 + dt
554  // Phi_t1(1) = Phi_t0(0) - dt * VdotG_t0(1)
555  mTask = std::bind(&Normalizer::euler01, ph::_1, ph::_2);
556 
557  // Cook and swap buffer 0 and 1 such that Phi_t1(0) and Phi_t0(1)
558  this->cook("Normalizing level set using TVD_RK1 (step 1 of 2)", 1);
559 
560  // Convex combine explicit Euler step: t2 = t0 + dt
561  // Phi_t2(1) = 1/2 * Phi_t0(1) + 1/2 * (Phi_t1(0) - dt * V.Grad_t1(0))
562  mTask = std::bind(&Normalizer::euler12, ph::_1, ph::_2);
563 
564  // Cook and swap buffer 0 and 1 such that Phi_t2(0) and Phi_t1(1)
565  this->cook("Normalizing level set using TVD_RK1 (step 2 of 2)", 1);
566  break;
567  case math::TVD_RK3:
568  // Perform one explicit Euler step: t1 = t0 + dt
569  // Phi_t1(1) = Phi_t0(0) - dt * VdotG_t0(1)
570  mTask = std::bind(&Normalizer::euler01, ph::_1, ph::_2);
571 
572  // Cook and swap buffer 0 and 1 such that Phi_t1(0) and Phi_t0(1)
573  this->cook("Normalizing level set using TVD_RK3 (step 1 of 3)", 1);
574 
575  // Convex combine explicit Euler step: t2 = t0 + dt/2
576  // Phi_t2(2) = 3/4 * Phi_t0(1) + 1/4 * (Phi_t1(0) - dt * V.Grad_t1(0))
577  mTask = std::bind(&Normalizer::euler34, ph::_1, ph::_2);
578 
579  // Cook and swap buffer 0 and 2 such that Phi_t2(0) and Phi_t1(2)
580  this->cook("Normalizing level set using TVD_RK3 (step 2 of 3)", 2);
581 
582  // Convex combine explicit Euler step: t3 = t0 + dt
583  // Phi_t3(2) = 1/3 * Phi_t0(1) + 2/3 * (Phi_t2(0) - dt * V.Grad_t2(0)
584  mTask = std::bind(&Normalizer::euler13, ph::_1, ph::_2);
585 
586  // Cook and swap buffer 0 and 2 such that Phi_t3(0) and Phi_t2(2)
587  this->cook("Normalizing level set using TVD_RK3 (step 3 of 3)", 2);
588  break;
589  case math::UNKNOWN_TIS:
590  default:
591  OPENVDB_THROW(ValueError, "Temporal integration scheme not supported!");
592  }
594  }
595  mTracker.mLeafs->removeAuxBuffers();
596 }
597 
600 template<typename GridT, typename InterruptT>
601 template<math::BiasedGradientScheme SpatialScheme,
602  math::TemporalIntegrationScheme TemporalScheme,
603  typename MaskT>
604 inline void
607 cook(const char* msg, int swapBuffer)
608 {
609  mTracker.startInterrupter( msg );
610 
611  const int grainSize = mTracker.getGrainSize();
612  const LeafRange range = mTracker.leafs().leafRange(grainSize);
613 
614  grainSize>0 ? tbb::parallel_for(range, *this) : (*this)(range);
615 
616  mTracker.leafs().swapLeafBuffer(swapBuffer, grainSize==0);
617 
618  mTracker.endInterrupter();
619 }
620 
621 template<typename GridT, typename InterruptT>
622 template<math::BiasedGradientScheme SpatialScheme,
623  math::TemporalIntegrationScheme TemporalScheme,
624  typename MaskT>
625 template <int Nominator, int Denominator>
626 inline void
629 eval(StencilT& stencil, const ValueType* phi, ValueType* result, Index n) const
630 {
631  using GradientT = typename math::ISGradientNormSqrd<SpatialScheme>;
632  static const ValueType alpha = ValueType(Nominator)/ValueType(Denominator);
633  static const ValueType beta = ValueType(1) - alpha;
634 
635  const ValueType normSqGradPhi = GradientT::result(stencil);
636  const ValueType phi0 = stencil.getValue();
637  ValueType v = phi0 / ( math::Sqrt(math::Pow2(phi0) + normSqGradPhi) +
639  v = phi0 - mDt * v * (math::Sqrt(normSqGradPhi) * mInvDx - 1.0f);
640  result[n] = Nominator ? alpha * phi[n] + beta * v : v;
641 }
642 
643 template<typename GridT, typename InterruptT>
644 template<math::BiasedGradientScheme SpatialScheme,
645  math::TemporalIntegrationScheme TemporalScheme,
646  typename MaskT>
647 template <int Nominator, int Denominator>
648 inline void
651 euler(const LeafRange& range, Index phiBuffer, Index resultBuffer)
652 {
653  mTracker.checkInterrupter();
654 
655  StencilT stencil(mTracker.grid());
656 
657  for (typename LeafRange::Iterator leafIter = range.begin(); leafIter; ++leafIter) {
658  const ValueType* phi = leafIter.buffer(phiBuffer).data();
659  ValueType* result = leafIter.buffer(resultBuffer).data();
660  if (mMask == nullptr) {
661  for (auto iter = leafIter->cbeginValueOn(); iter; ++iter) {
662  stencil.moveTo(iter);
663  this->eval<Nominator, Denominator>(stencil, phi, result, iter.pos());
664  }//loop over active voxels in the leaf of the level set
665  } else if (const MaskLeafT* mask = mMask->probeLeaf(leafIter->origin())) {
666  const ValueType* phi0 = leafIter->buffer().data();
667  for (MaskIterT iter = mask->cbeginValueOn(); iter; ++iter) {
668  const Index i = iter.pos();
669  stencil.moveTo(iter.getCoord(), phi0[i]);
670  this->eval<Nominator, Denominator>(stencil, phi, result, i);
671  }//loop over active voxels in the leaf of the mask
672  }
673  }//loop over leafs of the level set
674 }
675 
676 } // namespace tools
677 } // namespace OPENVDB_VERSION_NAME
678 } // namespace openvdb
679 
680 #endif // OPENVDB_TOOLS_LEVEL_SET_TRACKER_HAS_BEEN_INCLUDED
Definition: FiniteDifference.h:238
Set all out-of-band voxels to the background value.
virtual ~LevelSetTracker()
Definition: LevelSetTracker.h:87
const GridType & grid() const
Definition: LevelSetTracker.h:185
LeafManagerType & leafs()
Definition: LevelSetTracker.h:187
Definition: Morphology.h:56
#define OPENVDB_THROW(exception, message)
Definition: openvdb/Exceptions.h:74
typename tree::LeafManager< TreeType > LeafManagerType
Definition: LevelSetTracker.h:64
bool checkInterrupter()
Definition: LevelSetTracker.h:383
General-purpose arithmetic and comparison routines, most of which accept arbitrary value types (or at...
ValueType voxelSize() const
Definition: LevelSetTracker.h:176
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
void setState(const State &s)
Set the state of the tracker (see struct defined above)
Definition: LevelSetTracker.h:139
void prune()
Set voxels that are outside the narrow band to the background value (if trimming is enabled) and prun...
Definition: LevelSetTracker.h:280
float RoundDown(float x)
Return x rounded down to the nearest integer.
Definition: Math.h:806
TemporalIntegrationScheme
Temporal integration schemes.
Definition: FiniteDifference.h:234
math::BiasedGradientScheme getSpatialScheme() const
Definition: LevelSetTracker.h:142
Efficient multi-threaded replacement of the background values in tree.
int grainSize
Definition: LevelSetTracker.h:80
Definition: FiniteDifference.h:236
TrimMode
How to handle voxels that fall outside the narrow band.
Definition: LevelSetTracker.h:43
typename LeafManagerType::LeafRange LeafRange
Definition: LevelSetTracker.h:65
Definition: FiniteDifference.h:168
void normalize()
Iterative normalization, i.e. solving the Eikonal equation.
Definition: LevelSetTracker.h:95
Performs multi-threaded interface tracking of narrow band level sets.
Definition: LevelSetTracker.h:55
Leave out-of-band voxels intact.
typename TreeType::template ValueConverter< ValueMask >::Type MaskTreeType
Definition: LevelSetTracker.h:67
GridT GridType
Definition: LevelSetTracker.h:60
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
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
Defined various multi-threaded utility functions for trees.
GridType::Ptr normalize(const GridType &grid, bool threaded, InterruptT *interrupt)
Normalize the vectors of the given vector-valued grid.
Definition: GridOperators.h:1064
Index32 Index
Definition: openvdb/Types.h:50
TrimMode trimming() const
Return the trimming mode for voxels outside the narrow band.
Definition: LevelSetTracker.h:171
Definition: Operators.h:227
Definition: FiniteDifference.h:167
void dilateActiveValues(TreeOrLeafManagerT &tree, const int iterations=1, const NearestNeighbors nn=NN_FACE, const TilePolicy mode=PRESERVE_TILES, const bool threaded=true)
Topologically dilate all active values (i.e. both voxels and tiles) in a tree using one of three near...
Definition: Morphology.h:1049
Definition: FiniteDifference.h:237
typename GridT::TreeType TreeType
Definition: LevelSetTracker.h:61
math::BiasedGradientScheme spatialScheme
Definition: LevelSetTracker.h:77
bool wasInterrupted(T *i, int percent=-1)
Definition: NullInterrupter.h:49
Lightweight struct that stores the state of the LevelSetTracker.
Definition: LevelSetTracker.h:72
void setNormCount(int n)
Set the number of normalizations performed per track or normalize call.
Definition: LevelSetTracker.h:159
Definition: openvdb/Exceptions.h:63
Implementation of morphological dilation and erosion.
void erode(int iterations=1)
Erodes the width of the narrow-band and update the background values.
Definition: LevelSetTracker.h:340
Definition: openvdb/Exceptions.h:13
#define OPENVDB_NO_UNREACHABLE_CODE_WARNING_BEGIN
SIMD Intrinsic Headers.
Definition: Platform.h:115
ValueType getHalfWidth() const
Return the half width of the narrow band in floating-point voxel units.
Definition: LevelSetTracker.h:133
BiasedGradientScheme
Biased Gradients are limited to non-centered differences.
Definition: FiniteDifference.h:165
Definition: Morphology.h:78
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
Type Pow2(Type x)
Return x2.
Definition: Math.h:551
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
void setTrimming(TrimMode mode)
Specify whether to trim voxels outside the narrow band prior to pruning.
Definition: LevelSetTracker.h:174
int getGrainSize() const
Definition: LevelSetTracker.h:162
void startInterrupter(const char *msg)
Definition: LevelSetTracker.h:367
Tag dispatch class that distinguishes topology copy constructors from deep copy constructors.
Definition: openvdb/Types.h:560
void setSpatialScheme(math::BiasedGradientScheme s)
Set the spatial finite difference scheme.
Definition: LevelSetTracker.h:145
float Sqrt(float x)
Return the square root of a floating-point value.
Definition: Math.h:764
static const Real LEVEL_SET_HALF_WIDTH
Definition: openvdb/Types.h:339
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:352
typename LeafManagerType::BufferType BufferType
Definition: LevelSetTracker.h:66
Definition: openvdb/Types.h:333
#define OPENVDB_NO_UNREACHABLE_CODE_WARNING_END
Definition: Platform.h:116
Definition: openvdb/Exceptions.h:65
math::TemporalIntegrationScheme temporalScheme
Definition: LevelSetTracker.h:78
Definition: FiniteDifference.h:170
Definition: FiniteDifference.h:169
Definition: Operators.h:126
void setGrainSize(int grainsize)
Set the grain-size used for multi-threading.
Definition: LevelSetTracker.h:166
typename TreeType::LeafNodeType LeafType
Definition: LevelSetTracker.h:62
Definition: FiniteDifference.h:235
Set out-of-band exterior voxels to the background value.
typename TreeType::ValueType ValueType
Definition: LevelSetTracker.h:63
Defines various finite difference stencils by means of the "curiously recurring template pattern" on ...
void setTemporalScheme(math::TemporalIntegrationScheme s)
Set the spatial finite difference scheme.
Definition: LevelSetTracker.h:151
Definition: FiniteDifference.h:166
Definition: FiniteDifference.h:171
const LeafManagerType & leafs() const
Definition: LevelSetTracker.h:189
void erodeActiveValues(TreeOrLeafManagerT &tree, const int iterations=1, const NearestNeighbors nn=NN_FACE, const TilePolicy mode=PRESERVE_TILES, const bool threaded=true)
Topologically erode all active values (i.e. both voxels and tiles) in a tree using one of three neare...
Definition: Morphology.h:1126
void track()
Track the level set interface, i.e. rebuild and normalize the narrow band of the level set...
Definition: LevelSetTracker.h:303
A LeafManager manages a linear array of pointers to a given tree&#39;s leaf nodes, as well as optional au...
math::TemporalIntegrationScheme getTemporalScheme() const
Definition: LevelSetTracker.h:148
void endInterrupter()
Definition: LevelSetTracker.h:375
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h.in:116
static T value()
Definition: Math.h:147
int getNormCount() const
Definition: LevelSetTracker.h:155
Set out-of-band interior voxels to the background value.
State getState() const
Return the state of the tracker (see struct defined above)
Definition: LevelSetTracker.h:136
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h.in:178
int normCount
Definition: LevelSetTracker.h:79