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>
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 {
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
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
366 startInterrupter(const char* msg)
367 {
368  if (mInterrupter) mInterrupter->start(msg);
369 }
370 
371 template<typename GridT, typename InterruptT>
372 inline void
375 {
376  if (mInterrupter) mInterrupter->end();
377 }
378 
379 template<typename GridT, typename InterruptT>
380 inline bool
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
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
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
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
453 {
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  }
466 }
467 
468 
470 template<typename GridT, typename InterruptT>
471 template<lstrack::TrimMode Trimming>
472 inline void
474 {
475  mTracker.checkInterrupter();
476  const ValueType gamma = mTracker.mGrid->background();
477 
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  }
503 }
504 
505 
507 
508 template<typename GridT, typename InterruptT>
509 template<math::BiasedGradientScheme SpatialScheme,
510  math::TemporalIntegrationScheme TemporalScheme,
511  typename MaskT>
512 inline
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
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 
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  }
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
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
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) +
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
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
void track()
Track the level set interface, i.e. rebuild and normalize the narrow band of the level set...
Definition: LevelSetTracker.h:303
int getGrainSize() const
Definition: LevelSetTracker.h:162
void setNormCount(int n)
Set the number of normalizations performed per track or normalize call.
Definition: LevelSetTracker.h:159
static const Real LEVEL_SET_HALF_WIDTH
Definition: Types.h:460
Definition: FiniteDifference.h:236
int normCount
Definition: LevelSetTracker.h:79
void erode(int iterations=1)
Erodes the width of the narrow-band and update the background values.
Definition: LevelSetTracker.h:340
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
General-purpose arithmetic and comparison routines, most of which accept arbitrary value types (or at...
virtual ~LevelSetTracker()
Definition: LevelSetTracker.h:87
int grainSize
Definition: LevelSetTracker.h:80
const GridType & grid() const
Definition: LevelSetTracker.h:185
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
bool checkInterrupter()
Definition: LevelSetTracker.h:382
const LeafManagerType & leafs() const
Definition: LevelSetTracker.h:189
#define OPENVDB_THROW(exception, message)
Definition: Exceptions.h:82
Set out-of-band exterior voxels to the background value.
Definition: FiniteDifference.h:238
Efficient multi-threaded replacement of the background values in tree.
float RoundDown(float x)
Return x rounded down to the nearest integer.
Definition: Math.h:750
TrimMode
How to handle voxels that fall outside the narrow band.
Definition: LevelSetTracker.h:43
TemporalIntegrationScheme
Temporal integration schemes.
Definition: FiniteDifference.h:234
static T value()
Definition: Math.h:90
math::TemporalIntegrationScheme getTemporalScheme() const
Definition: LevelSetTracker.h:148
void endInterrupter()
Definition: LevelSetTracker.h:374
GridType::Ptr normalize(const GridType &grid, bool threaded, InterruptT *interrupt)
Normalize the vectors of the given vector-valued grid.
Definition: GridOperators.h:1064
Type Pow2(Type x)
Return x2.
Definition: Math.h:495
math::BiasedGradientScheme spatialScheme
Definition: LevelSetTracker.h:77
typename tree::LeafManager< TreeType > LeafManagerType
Definition: LevelSetTracker.h:64
Definition: FiniteDifference.h:237
Defined various multi-threaded utility functions for trees.
Definition: FiniteDifference.h:168
Definition: Exceptions.h:65
Definition: FiniteDifference.h:235
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
void prune()
Set voxels that are outside the narrow band to the background value (if trimming is enabled) and prun...
Definition: LevelSetTracker.h:280
Lightweight struct that stores the state of the LevelSetTracker.
Definition: LevelSetTracker.h:72
Definition: FiniteDifference.h:166
Leave out-of-band voxels intact.
int getNormCount() const
Definition: LevelSetTracker.h:155
void setSpatialScheme(math::BiasedGradientScheme s)
Set the spatial finite difference scheme.
Definition: LevelSetTracker.h:145
Definition: FiniteDifference.h:169
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
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h:102
Set out-of-band interior voxels to the background value.
typename TreeType::ValueType ValueType
Definition: LevelSetTracker.h:63
void setTemporalScheme(math::TemporalIntegrationScheme s)
Set the spatial finite difference scheme.
Definition: LevelSetTracker.h:151
Definition: Operators.h:126
Implementation of morphological dilation and erosion.
void startInterrupter(const char *msg)
Definition: LevelSetTracker.h:366
Definition: Exceptions.h:13
math::BiasedGradientScheme getSpatialScheme() const
Definition: LevelSetTracker.h:142
#define OPENVDB_NO_UNREACHABLE_CODE_WARNING_BEGIN
SIMD Intrinsic Headers.
Definition: Platform.h:114
Performs multi-threaded interface tracking of narrow band level sets.
Definition: LevelSetTracker.h:55
This class manages a linear array of pointers to a given tree&#39;s leaf nodes, as well as optional auxil...
Definition: LeafManager.h:82
bool wasInterrupted(T *i, int percent=-1)
Definition: NullInterrupter.h:49
float Sqrt(float x)
Return the square root of a floating-point value.
Definition: Math.h:708
Definition: FiniteDifference.h:170
Tag dispatch class that distinguishes topology copy constructors from deep copy constructors.
Definition: Types.h:681
Definition: FiniteDifference.h:171
typename TreeType::template ValueConverter< ValueMask >::Type MaskTreeType
Definition: LevelSetTracker.h:67
Definition: Exceptions.h:63
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 setGrainSize(int grainsize)
Set the grain-size used for multi-threading.
Definition: LevelSetTracker.h:166
void setState(const State &s)
Set the state of the tracker (see struct defined above)
Definition: LevelSetTracker.h:139
Index32 Index
Definition: Types.h:31
#define OPENVDB_NO_UNREACHABLE_CODE_WARNING_END
Definition: Platform.h:115
math::TemporalIntegrationScheme temporalScheme
Definition: LevelSetTracker.h:78
TrimMode trimming() const
Return the trimming mode for voxels outside the narrow band.
Definition: LevelSetTracker.h:171
Set all out-of-band voxels to the background value.
Definition: Operators.h:227
ValueType voxelSize() const
Definition: LevelSetTracker.h:176
State getState() const
Return the state of the tracker (see struct defined above)
Definition: LevelSetTracker.h:136
typename TreeType::LeafNodeType LeafType
Definition: LevelSetTracker.h:62
ValueType getHalfWidth() const
Return the half width of the narrow band in floating-point voxel units.
Definition: LevelSetTracker.h:133
Definition: Morphology.h:75
Defines various finite difference stencils by means of the "curiously recurring template pattern" on ...
typename GridT::TreeType TreeType
Definition: LevelSetTracker.h:61
Definition: FiniteDifference.h:167
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
typename LeafManagerType::LeafRange LeafRange
Definition: LevelSetTracker.h:65
GridT GridType
Definition: LevelSetTracker.h:60
void normalize()
Iterative normalization, i.e. solving the Eikonal equation.
Definition: LevelSetTracker.h:95
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:154
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
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
A LeafManager manages a linear array of pointers to a given tree&#39;s leaf nodes, as well as optional au...
typename LeafManagerType::BufferType BufferType
Definition: LevelSetTracker.h:66
Definition: Morphology.h:60
LeafManagerType & leafs()
Definition: LevelSetTracker.h:187
Definition: Types.h:454
BiasedGradientScheme
Biased Gradients are limited to non-centered differences.
Definition: FiniteDifference.h:165
void setTrimming(TrimMode mode)
Specify whether to trim voxels outside the narrow band prior to pruning.
Definition: LevelSetTracker.h:174