OpenVDB 3.2.0

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