OpenVDB 5.1.0

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