OpenVDB  3.0.0
LevelSetTracker.h
Go to the documentation of this file.
1 //
3 // Copyright (c) 2012-2014 DreamWorks Animation LLC
4 //
5 // All rights reserved. This software is distributed under the
6 // Mozilla Public License 2.0 ( http://www.mozilla.org/MPL/2.0/ )
7 //
8 // Redistributions of source code must retain the above copyright
9 // and license notice and the following restrictions and disclaimer.
10 //
11 // * Neither the name of DreamWorks Animation nor the names of
12 // its contributors may be used to endorse or promote products derived
13 // from this software without specific prior written permission.
14 //
15 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
18 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY INDIRECT, INCIDENTAL,
20 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 // IN NO EVENT SHALL THE COPYRIGHT HOLDERS' AND CONTRIBUTORS' AGGREGATE
27 // LIABILITY FOR ALL CLAIMS REGARDLESS OF THEIR BASIS EXCEED US$250.00.
28 //
30 //
38 
39 #ifndef OPENVDB_TOOLS_LEVEL_SET_TRACKER_HAS_BEEN_INCLUDED
40 #define OPENVDB_TOOLS_LEVEL_SET_TRACKER_HAS_BEEN_INCLUDED
41 
42 #include <tbb/parallel_reduce.h>
43 #include <tbb/parallel_for.h>
44 #include <boost/bind.hpp>
45 #include <boost/function.hpp>
46 #include <boost/type_traits/is_floating_point.hpp>
47 #include <openvdb/Types.h>
48 #include <openvdb/math/Math.h>
49 #include <openvdb/math/FiniteDifference.h>
50 #include <openvdb/math/Operators.h>
51 #include <openvdb/math/Stencils.h>
52 #include <openvdb/math/Transform.h>
53 #include <openvdb/Grid.h>
54 #include <openvdb/util/NullInterrupter.h>
55 #include <openvdb/tree/ValueAccessor.h>
56 #include <openvdb/tree/LeafManager.h>
57 #include "ChangeBackground.h"// for changeLevelSetBackground
58 #include "Morphology.h"//for dilateVoxels
59 #include "Prune.h"// for pruneLevelSet
60 
61 namespace openvdb {
63 namespace OPENVDB_VERSION_NAME {
64 namespace tools {
65 
67 template<typename GridT, typename InterruptT = util::NullInterrupter>
69 {
70 public:
71  typedef GridT GridType;
72  typedef typename GridT::TreeType TreeType;
73  typedef typename TreeType::LeafNodeType LeafType;
74  typedef typename TreeType::ValueType ValueType;
75  typedef typename tree::LeafManager<TreeType> LeafManagerType; // leafs + buffers
79  typedef typename TreeType::template ValueConverter<bool>::Type BoolMaskType;
80  BOOST_STATIC_ASSERT(boost::is_floating_point<ValueType>::value);
81 
84  LevelSetTracker(GridT& grid, InterruptT* interrupt = NULL);
85 
87  LevelSetTracker(const LevelSetTracker& other);
88 
89  virtual ~LevelSetTracker() { if (mIsMaster) delete mLeafs; }
90 
93  template <typename MaskType>
94  void normalize(const MaskType* mask);
95 
97  void normalize() { this->normalize<BoolMaskType>(NULL); }
98 
101  void track();
102 
104  void prune();
105 
108  void dilate(int iterations = 1);
109 
112  void erode(int iterations = 1);
113 
115  math::BiasedGradientScheme getSpatialScheme() const { return mSpatialScheme; }
116 
118  void setSpatialScheme(math::BiasedGradientScheme scheme) { mSpatialScheme = scheme; }
119 
121  math::TemporalIntegrationScheme getTemporalScheme() const { return mTemporalScheme; }
122 
124  void setTemporalScheme(math::TemporalIntegrationScheme scheme) { mTemporalScheme = scheme; }
125 
128  int getNormCount() const { return mNormCount; }
129 
132  void setNormCount(int n) { mNormCount = n; }
133 
135  int getGrainSize() const { return mGrainSize; }
136 
139  void setGrainSize(int grainsize) { mGrainSize = grainsize; }
140 
141  ValueType voxelSize() const { return mDx; }
142 
143  void startInterrupter(const char* msg);
144 
145  void endInterrupter();
146 
148  bool checkInterrupter();
149 
150  const GridType& grid() const { return *mGrid; }
151 
152  LeafManagerType& leafs() { return *mLeafs; }
153 
154  const LeafManagerType& leafs() const { return *mLeafs; }
155 
156 private:
157 
158  // Private class to perform multi-threaded trimming of
159  // voxels that are too far away from the zero-crossing.
160  struct Trim
161  {
162  Trim(LevelSetTracker& tracker) : mTracker(tracker) {}
163  void trim();
164  void operator()(const RangeType& r) const;
165  LevelSetTracker& mTracker;
166  };// Trim
167 
168  // Private class to perform multi-threaded normalization
169  template<math::BiasedGradientScheme SpatialScheme,
170  math::TemporalIntegrationScheme TemporalScheme,
171  typename MaskT>
172  struct Normalizer
173  {
174  typedef math::BIAS_SCHEME<SpatialScheme> SchemeT;
175  typedef typename SchemeT::template ISStencil<GridType>::StencilType StencilT;
176  typedef typename MaskT::LeafNodeType MaskLeafT;
177  typedef typename MaskLeafT::ValueOnCIter MaskIterT;
178  typedef typename LeafType::ValueOnCIter VoxelIterT;
179  Normalizer(LevelSetTracker& tracker, const MaskT* mask);
180  void normalize();
181  void operator()(const RangeType& r) const {mTask(const_cast<Normalizer*>(this), r);}
182  void cook(int swapBuffer=0);
183  template <int Nominator, int Denominator>
184  void euler(const RangeType& range, Index phiBuffer, Index resultBuffer);
185  inline void euler01(const RangeType& r) {this->euler<0,1>(r, 0, 1);}
186  inline void euler12(const RangeType& r, Index n, Index m) {this->euler<1,2>(r, n, m);}
187  inline void euler34(const RangeType& r, Index n, Index m) {this->euler<3,4>(r, n, m);}
188  inline void euler13(const RangeType& r, Index n, Index m) {this->euler<1,3>(r, n, m);}
189  template <int Nominator, int Denominator>
190  void eval(StencilT& stencil, const BufferType& phi, BufferType& result, Index n) const;
191  typedef typename boost::function<void (Normalizer*, const RangeType&)> FuncType;
192  LevelSetTracker& mTracker;
193  const MaskT* mMask;
194  const ValueType mDt, mInvDx;
195  FuncType mTask;
196  }; // Normalizer
197 
198  template<math::BiasedGradientScheme SpatialScheme, typename MaskT>
199  void normalize1(const MaskT* mask);
200 
201  template<math::BiasedGradientScheme SpatialScheme,
202  math::TemporalIntegrationScheme TemporalScheme, typename MaskT>
203  void normalize2(const MaskT* mask);
204 
205  // Throughout the methods below mLeafs is always assumed to contain
206  // a list of the current LeafNodes! The auxiliary buffers on the
207  // other hand always have to be allocated locally, since some
208  // methods need them and others don't!
209  GridType* mGrid;
210  LeafManagerType* mLeafs;
211  InterruptT* mInterrupter;
212  const ValueType mDx;
213  math::BiasedGradientScheme mSpatialScheme;
214  math::TemporalIntegrationScheme mTemporalScheme;
215  int mNormCount;// Number of iteratations of normalization
216  int mGrainSize;
217  const bool mIsMaster;
218 
219  // disallow copy by assignment
220  void operator=(const LevelSetTracker& other) {}
221 
222 }; // end of LevelSetTracker class
223 
224 template<typename GridT, typename InterruptT>
225 LevelSetTracker<GridT, InterruptT>::
226 LevelSetTracker(GridT& grid, InterruptT* interrupt):
227  mGrid(&grid),
228  mLeafs(new LeafManagerType(grid.tree())),
229  mInterrupter(interrupt),
230  mDx(static_cast<ValueType>(grid.voxelSize()[0])),
231  mSpatialScheme(math::HJWENO5_BIAS),
232  mTemporalScheme(math::TVD_RK1),
233  mNormCount(static_cast<int>(LEVEL_SET_HALF_WIDTH)),
234  mGrainSize(1),
235  mIsMaster(true)// N.B.
236 {
237  if ( !grid.hasUniformVoxels() ) {
239  "The transform must have uniform scale for the LevelSetTracker to function");
240  }
241  if ( grid.getGridClass() != GRID_LEVEL_SET) {
243  "LevelSetTracker expected a level set, got a grid of class \""
244  + grid.gridClassToString(grid.getGridClass())
245  + "\" [hint: Grid::setGridClass(openvdb::GRID_LEVEL_SET)]");
246  }
247 }
248 
249 template<typename GridT, typename InterruptT>
252  mGrid(other.mGrid),
253  mLeafs(other.mLeafs),
254  mInterrupter(other.mInterrupter),
255  mDx(other.mDx),
256  mSpatialScheme(other.mSpatialScheme),
257  mTemporalScheme(other.mTemporalScheme),
258  mNormCount(other.mNormCount),
259  mGrainSize(other.mGrainSize),
260  mIsMaster(false)// N.B.
261 {
262 }
263 
264 template<typename GridT, typename InterruptT>
265 inline void
268 {
269  this->startInterrupter("Pruning Level Set");
270 
271  // Prune voxels that are too far away from the zero-crossing
272  Trim t(*this);
273  t.trim();
274 
275  // Remove inactive nodes from tree
276  tools::pruneLevelSet(mGrid->tree());
277 
278  // The tree topology has changes so rebuild the list of leafs
279  mLeafs->rebuildLeafArray();
280  this->endInterrupter();
281 }
282 
283 template<typename GridT, typename InterruptT>
284 inline void
287 {
288  // Dilate narrow-band (this also rebuilds the leaf array!)
289  tools::dilateVoxels(*mLeafs);
290 
291  // Compute signed distances in dilated narrow-band
292  this->normalize();
293 
294  // Remove voxels that are outside the narrow band
295  this->prune();
296 }
297 
298 template<typename GridT, typename InterruptT>
299 inline void
301 dilate(int iterations)
302 {
303  if (mNormCount == 0) {
304  for (int i=0; i < iterations; ++i) {
305  tools::dilateVoxels(*mLeafs);
306  mLeafs->rebuildLeafArray();
307  tools::changeLevelSetBackground(leafs(), mDx + mGrid->background());
308  }
309  } else {
310  for (int i=0; i < iterations; ++i) {
311  BoolMaskType mask0(mGrid->tree(), false, TopologyCopy());
312  tools::dilateVoxels(*mLeafs);
313  mLeafs->rebuildLeafArray();
314  tools::changeLevelSetBackground(leafs(), mDx + mGrid->background());
315  BoolMaskType mask(mGrid->tree(), false, TopologyCopy());
316  mask.topologyDifference(mask0);
317  this->normalize(&mask);
318  }
319  }
320 }
321 
322 template<typename GridT, typename InterruptT>
323 inline void
325 erode(int iterations)
326 {
327  tools::erodeVoxels(*mLeafs, iterations);
328  mLeafs->rebuildLeafArray();
329  const ValueType background = mGrid->background() - iterations*mDx;
330  tools::changeLevelSetBackground(leafs(), background);
331 }
332 
333 template<typename GridT, typename InterruptT>
334 inline void
336 startInterrupter(const char* msg)
337 {
338  if (mInterrupter) mInterrupter->start(msg);
339 }
340 
341 template<typename GridT, typename InterruptT>
342 inline void
345 {
346  if (mInterrupter) mInterrupter->end();
347 }
348 
349 template<typename GridT, typename InterruptT>
350 inline bool
353 {
354  if (util::wasInterrupted(mInterrupter)) {
355  tbb::task::self().cancel_group_execution();
356  return false;
357  }
358  return true;
359 }
360 
361 template<typename GridT, typename InterruptT>
362 template<typename MaskT>
363 inline void
365 normalize(const MaskT* mask)
366 {
367  switch (mSpatialScheme) {
368  case math::FIRST_BIAS:
369  this->normalize1<math::FIRST_BIAS , MaskT>(mask); break;
370  case math::SECOND_BIAS:
371  this->normalize1<math::SECOND_BIAS, MaskT>(mask); break;
372  case math::THIRD_BIAS:
373  this->normalize1<math::THIRD_BIAS, MaskT>(mask); break;
374  case math::WENO5_BIAS:
375  this->normalize1<math::WENO5_BIAS, MaskT>(mask); break;
376  case math::HJWENO5_BIAS:
377  this->normalize1<math::HJWENO5_BIAS, MaskT>(mask); break;
378  default:
379  OPENVDB_THROW(ValueError, "Spatial difference scheme not supported!");
380  }
381 }
382 
383 template<typename GridT, typename InterruptT>
384 template<math::BiasedGradientScheme SpatialScheme, typename MaskT>
385 inline void
387 normalize1(const MaskT* mask)
388 {
389  switch (mTemporalScheme) {
390  case math::TVD_RK1:
391  this->normalize2<SpatialScheme, math::TVD_RK1, MaskT>(mask); break;
392  case math::TVD_RK2:
393  this->normalize2<SpatialScheme, math::TVD_RK2, MaskT>(mask); break;
394  case math::TVD_RK3:
395  this->normalize2<SpatialScheme, math::TVD_RK3, MaskT>(mask); break;
396  default:
397  OPENVDB_THROW(ValueError, "Temporal integration scheme not supported!");
398  }
399 }
400 
401 template<typename GridT, typename InterruptT>
402 template<math::BiasedGradientScheme SpatialScheme,
403  math::TemporalIntegrationScheme TemporalScheme,
404  typename MaskT>
405 inline void
406 LevelSetTracker<GridT, InterruptT>::
407 normalize2(const MaskT* mask)
408 {
409  Normalizer<SpatialScheme, TemporalScheme, MaskT> tmp(*this, mask);
410  tmp.normalize();
411 }
412 
414 
415 template<typename GridT, typename InterruptT>
416 inline void
417 LevelSetTracker<GridT, InterruptT>::
418 Trim::trim()
419 {
420  const int grainSize = mTracker.getGrainSize();
421  if (grainSize>0) {
422  tbb::parallel_for(mTracker.mLeafs->getRange(grainSize), *this);
423  } else {
424  (*this)(mTracker.mLeafs->getRange());
425  }
426 }
427 
429 template<typename GridT, typename InterruptT>
430 inline void
431 LevelSetTracker<GridT, InterruptT>::
432 Trim::operator()(const RangeType& range) const
433 {
434  typedef typename LeafType::ValueOnIter VoxelIterT;
435  mTracker.checkInterrupter();
436  const ValueType gamma = mTracker.mGrid->background();
437  for (size_t n=range.begin(), e=range.end(); n != e; ++n) {
438  LeafType &leaf = mTracker.mLeafs->leaf(n);
439  for (VoxelIterT iter = leaf.beginValueOn(); iter; ++iter) {
440  const ValueType val = *iter;
441  if (val <= -gamma)
442  leaf.setValueOff(iter.pos(), -gamma);
443  else if (val >= gamma)
444  leaf.setValueOff(iter.pos(), gamma);
445  }
446  }
447 }
448 
450 
451 template<typename GridT, typename InterruptT>
452 template<math::BiasedGradientScheme SpatialScheme,
453  math::TemporalIntegrationScheme TemporalScheme,
454  typename MaskT>
455 inline
456 LevelSetTracker<GridT, InterruptT>::
457 Normalizer<SpatialScheme, TemporalScheme, MaskT>::
458 Normalizer(LevelSetTracker& tracker, const MaskT* mask)
459  : mTracker(tracker)
460  , mMask(mask)
461  , mDt(tracker.voxelSize()*(TemporalScheme == math::TVD_RK1 ? 0.3f :
462  TemporalScheme == math::TVD_RK2 ? 0.9f : 1.0f))
463  , mInvDx(1.0f/tracker.voxelSize())
464  , mTask(0)
465 {
466 }
467 
468 template<typename GridT, typename InterruptT>
469 template<math::BiasedGradientScheme SpatialScheme,
470  math::TemporalIntegrationScheme TemporalScheme,
471  typename MaskT>
472 inline void
475 normalize()
476 {
478  mTracker.mLeafs->rebuildAuxBuffers(TemporalScheme == math::TVD_RK3 ? 2 : 1);
479 
480  for (int n=0, e=mTracker.getNormCount(); n < e; ++n) {
481 
483  switch(TemporalScheme) {//switch is resolved at compile-time
484  case math::TVD_RK1:
485  // Perform one explicit Euler step: t1 = t0 + dt
486  // Phi_t1(0) = Phi_t0(0) - dt * VdotG_t0(1)
487  mTask = boost::bind(&Normalizer::euler01, _1, _2);
488 
489  // Cook and swap buffer 0 and 1 such that Phi_t1(0) and Phi_t0(1)
490  this->cook(1);
491  break;
492  case math::TVD_RK2:
493  // Perform one explicit Euler step: t1 = t0 + dt
494  // Phi_t1(1) = Phi_t0(0) - dt * VdotG_t0(1)
495  mTask = boost::bind(&Normalizer::euler01, _1, _2);
496 
497  // Cook and swap buffer 0 and 1 such that Phi_t1(0) and Phi_t0(1)
498  this->cook(1);
499 
500  // Convex combine explict Euler step: t2 = t0 + dt
501  // Phi_t2(1) = 1/2 * Phi_t0(1) + 1/2 * (Phi_t1(0) - dt * V.Grad_t1(0))
502  mTask = boost::bind(&Normalizer::euler12, _1, _2, /*phi=*/1, /*result=*/1);
503 
504  // Cook and swap buffer 0 and 1 such that Phi_t2(0) and Phi_t1(1)
505  this->cook(1);
506  break;
507  case math::TVD_RK3:
508  // Perform one explicit Euler step: t1 = t0 + dt
509  // Phi_t1(1) = Phi_t0(0) - dt * VdotG_t0(1)
510  mTask = boost::bind(&Normalizer::euler01, _1, _2);
511 
512  // Cook and swap buffer 0 and 1 such that Phi_t1(0) and Phi_t0(1)
513  this->cook(1);
514 
515  // Convex combine explict Euler step: t2 = t0 + dt/2
516  // Phi_t2(2) = 3/4 * Phi_t0(1) + 1/4 * (Phi_t1(0) - dt * V.Grad_t1(0))
517  mTask = boost::bind(&Normalizer::euler34, _1, _2, /*phi=*/1, /*result=*/2);
518 
519  // Cook and swap buffer 0 and 2 such that Phi_t2(0) and Phi_t1(2)
520  this->cook(2);
521 
522  // Convex combine explict Euler step: t3 = t0 + dt
523  // Phi_t3(2) = 1/3 * Phi_t0(1) + 2/3 * (Phi_t2(0) - dt * V.Grad_t2(0)
524  mTask = boost::bind(&Normalizer::euler13, _1, _2, /*phi=*/1, /*result=*/2);
525 
526  // Cook and swap buffer 0 and 2 such that Phi_t3(0) and Phi_t2(2)
527  this->cook(2);
528  break;
529  default:
530  OPENVDB_THROW(ValueError, "Temporal integration scheme not supported!");
531  }
533  }
534  mTracker.mLeafs->removeAuxBuffers();
535 }
536 
539 template<typename GridT, typename InterruptT>
540 template<math::BiasedGradientScheme SpatialScheme,
541  math::TemporalIntegrationScheme TemporalScheme,
542  typename MaskT>
543 inline void
544 LevelSetTracker<GridT, InterruptT>::
545 Normalizer<SpatialScheme, TemporalScheme, MaskT>::
546 cook(int swapBuffer)
547 {
548  mTracker.startInterrupter("Normalizing Level Set");
549 
550  if (mTracker.getGrainSize()>0) {
551  tbb::parallel_for(mTracker.mLeafs->getRange(mTracker.getGrainSize()), *this);
552  } else {
553  (*this)(mTracker.mLeafs->getRange());
554  }
555 
556  mTracker.mLeafs->swapLeafBuffer(swapBuffer, mTracker.getGrainSize()==0);
557 
558  mTracker.endInterrupter();
559 }
560 
561 template<typename GridT, typename InterruptT>
562 template<math::BiasedGradientScheme SpatialScheme,
563  math::TemporalIntegrationScheme TemporalScheme,
564  typename MaskT>
565 template <int Nominator, int Denominator>
566 inline void
567 LevelSetTracker<GridT, InterruptT>::
568 Normalizer<SpatialScheme, TemporalScheme, MaskT>::
569 eval(StencilT& stencil, const BufferType& phi, BufferType& result, Index n) const
570 {
571  typedef typename math::ISGradientNormSqrd<SpatialScheme> GradientT;
572  static const ValueType alpha = ValueType(Nominator)/ValueType(Denominator);
573  static const ValueType beta = ValueType(1) - alpha;
574 
575  const ValueType normSqGradPhi = GradientT::result(stencil);
576  const ValueType phi0 = stencil.getValue();
577  ValueType v = phi0 / (math::Sqrt(math::Pow2(phi0) + normSqGradPhi));
578  v = phi0 - mDt * v * (math::Sqrt(normSqGradPhi) * mInvDx - 1.0f);
579  result.setValue(n, Nominator ? alpha * phi[n] + beta * v : v);
580 }
581 
582 template<typename GridT, typename InterruptT>
583 template<math::BiasedGradientScheme SpatialScheme,
584  math::TemporalIntegrationScheme TemporalScheme,
585  typename MaskT>
586 template <int Nominator, int Denominator>
587 inline void
588 LevelSetTracker<GridT,InterruptT>::
589 Normalizer<SpatialScheme, TemporalScheme, MaskT>::
590 euler(const RangeType& range, Index phiBuffer, Index resultBuffer)
591 {
592  typedef typename LeafType::ValueOnCIter VoxelIterT;
593 
594  mTracker.checkInterrupter();
595 
596  StencilT stencil(mTracker.grid());
597 
598  for (size_t n=range.begin(), e=range.end(); n != e; ++n) {
599  const BufferType& phi = mTracker.mLeafs->getBuffer(n, phiBuffer);
600  BufferType& result = mTracker.mLeafs->getBuffer(n, resultBuffer);
601  const LeafType& leaf = mTracker.mLeafs->leaf(n);
602 
603  if (mMask == NULL) {
604  for (VoxelIterT iter = leaf.cbeginValueOn(); iter; ++iter) {
605  stencil.moveTo(iter);
606  this->eval<Nominator,Denominator>(stencil, phi, result, iter.pos());
607  }//loop over active voxels in the leaf of the level set
608  } else if (const MaskLeafT* mask = mMask->probeLeaf(leaf.origin())) {
609  for (MaskIterT iter = mask->cbeginValueOn(); iter; ++iter) {
610  const Index i = iter.pos();
611  stencil.moveTo(iter.getCoord(), leaf.getValue(i));
612  this->eval<Nominator,Denominator>(stencil, phi, result, i);
613  }//loop over active voxels in the leaf of the mask
614  }
615  }//loop over leafs of the level set
616 }
617 
618 } // namespace tools
619 } // namespace OPENVDB_VERSION_NAME
620 } // namespace openvdb
621 
622 #endif // OPENVDB_TOOLS_LEVEL_SET_TRACKER_HAS_BEEN_INCLUDED
623 
624 // Copyright (c) 2012-2014 DreamWorks Animation LLC
625 // All rights reserved. This software is distributed under the
626 // Mozilla Public License 2.0 ( http://www.mozilla.org/MPL/2.0/ )
Definition: FiniteDifference.h:197
Definition: Types.h:424
Definition: FiniteDifference.h:265
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:260
int getGrainSize() const
Definition: LevelSetTracker.h:135
OPENVDB_STATIC_SPECIALIZATION void dilateVoxels(TreeType &tree, int iterations=1, NearestNeighbors nn=NN_FACE)
Topologically dilate all leaf-level active voxels in a tree using one of three nearest neighbor conne...
Definition: Morphology.h:774
tbb::blocked_range< size_t > RangeType
Definition: LeafManager.h:121
const GridType & grid() const
Definition: LevelSetTracker.h:150
void setSpatialScheme(math::BiasedGradientScheme scheme)
Set the spatial finite difference scheme.
Definition: LevelSetTracker.h:118
#define OPENVDB_THROW(exception, message)
Definition: Exceptions.h:97
void setNormCount(int n)
Set the number of normalizations performed per track or normalize call.
Definition: LevelSetTracker.h:132
Efficient multi-threaded replacement of the background values in tree.
Type Pow2(Type x)
Return .
Definition: Math.h:498
Definition: Operators.h:152
TreeType::LeafNodeType LeafType
Definition: LevelSetTracker.h:73
This class manages a linear array of pointers to a given tree's leaf nodes, as well as optional auxil...
Definition: LeafManager.h:109
void prune()
Remove voxels that are outside the narrow band. (substep of track)
Definition: LevelSetTracker.h:267
const LeafManagerType & leafs() const
Definition: LevelSetTracker.h:154
Definition: FiniteDifference.h:196
void startInterrupter(const char *msg)
Definition: LevelSetTracker.h:336
void erode(int iterations=1)
Erodes the width of the narrow-band and update the background values.
Definition: LevelSetTracker.h:325
Defined various multi-threaded utility functions for trees.
bool wasInterrupted(T *i, int percent=-1)
Definition: NullInterrupter.h:76
Definition: Types.h:210
void normalize()
Iterative normalization, i.e. solving the Eikonal equation.
Definition: LevelSetTracker.h:97
Definition: Exceptions.h:86
float Sqrt(float x)
Return the square root of a floating-point value.
Definition: Math.h:693
#define OPENVDB_VERSION_NAME
Definition: version.h:43
Index32 Index
Definition: Types.h:59
static const Real LEVEL_SET_HALF_WIDTH
Definition: Types.h:216
Implementation of morphological dilation and erosion.
GridType::Ptr normalize(const GridType &grid, bool threaded, InterruptT *interrupt)
Normalize the vectors of the given vector-valued grid.
Definition: GridOperators.h:1067
math::BiasedGradientScheme getSpatialScheme() const
Definition: LevelSetTracker.h:115
Definition: Exceptions.h:39
void dilate(int iterations=1)
Fast but approximate dilation of the narrow band.
Definition: LevelSetTracker.h:301
Definition: FiniteDifference.h:195
#define OPENVDB_NO_UNREACHABLE_CODE_WARNING_BEGIN
Definition: Platform.h:121
int getNormCount() const
Definition: LevelSetTracker.h:128
ValueType voxelSize() const
Definition: LevelSetTracker.h:141
LeafManagerType::RangeType RangeType
Definition: LevelSetTracker.h:76
Definition: FiniteDifference.h:264
math::TemporalIntegrationScheme getTemporalScheme() const
Definition: LevelSetTracker.h:121
Definition: Exceptions.h:88
BiasedGradientScheme
Biased Gradients are limited to non-centered differences.
Definition: FiniteDifference.h:192
#define OPENVDB_NO_UNREACHABLE_CODE_WARNING_END
Definition: Platform.h:122
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:369
void endInterrupter()
Definition: LevelSetTracker.h:344
GridT::TreeType TreeType
Definition: LevelSetTracker.h:72
void setTemporalScheme(math::TemporalIntegrationScheme scheme)
Set the spatial finite difference scheme.
Definition: LevelSetTracker.h:124
Performs multi-threaded interface tracking of narrow band level sets.
Definition: LevelSetTracker.h:68
Definition: FiniteDifference.h:198
LeafManagerType & leafs()
Definition: LevelSetTracker.h:152
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:71
virtual ~LevelSetTracker()
Definition: LevelSetTracker.h:89
void track()
Track the level set interface, i.e. rebuild and normalize the narrow band of the level set...
Definition: LevelSetTracker.h:286
LeafManagerType::BufferType BufferType
Definition: LevelSetTracker.h:78
TreeType::template ValueConverter< bool >::Type BoolMaskType
Definition: LevelSetTracker.h:79
Definition: FiniteDifference.h:194
Definition: FiniteDifference.h:263
TreeType::ValueType ValueType
Definition: LevelSetTracker.h:74
GridT GridType
Definition: LevelSetTracker.h:71
LevelSetTracker(GridT &grid, InterruptT *interrupt=NULL)
Main constructor.
Definition: LevelSetTracker.h:226
OPENVDB_STATIC_SPECIALIZATION 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:794
CopyConstness< TreeType, NonConstBufferType >::Type BufferType
Definition: LeafManager.h:120
tree::LeafManager< TreeType > LeafManagerType
Definition: LevelSetTracker.h:75
LeafManagerType::LeafRange LeafRange
Definition: LevelSetTracker.h:77
void setGrainSize(int grainsize)
Set the grain-size used for multi-threading.
Definition: LevelSetTracker.h:139
bool checkInterrupter()
Definition: LevelSetTracker.h:352
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:314
TemporalIntegrationScheme
Temporal integration schemes.
Definition: FiniteDifference.h:261