OpenVDB: LevelSetAdvect.h Source File

OpenVDB 4.0.2

LevelSetAdvect.h
Go to the documentation of this file.
1 //
3 // Copyright (c) 2012-2017 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 //
32 //
38
39 #ifndef OPENVDB_TOOLS_LEVEL_SET_ADVECT_HAS_BEEN_INCLUDED
40 #define OPENVDB_TOOLS_LEVEL_SET_ADVECT_HAS_BEEN_INCLUDED
41
42 #include <tbb/parallel_for.h>
43 #include <tbb/parallel_reduce.h>
44 #include <openvdb/Platform.h>
45 #include "LevelSetTracker.h"
46 #include "VelocityFields.h" // for EnrightField
47 #include <openvdb/math/FiniteDifference.h>
48 #include <boost/math/constants/constants.hpp>
49 //#include <openvdb/util/CpuTimer.h>
50
51 namespace openvdb {
52 OPENVDB_USE_VERSION_NAMESPACE
53 namespace OPENVDB_VERSION_NAME {
54 namespace tools {
55
97
98 template<typename GridT,
99 typename FieldT = EnrightField<typename GridT::ValueType>,
100 typename InterruptT = util::NullInterrupter>
101 class LevelSetAdvection
102 {
103 public:
104 typedef GridT GridType;
105 typedef LevelSetTracker<GridT, InterruptT> TrackerT;
106 typedef typename TrackerT::LeafRange LeafRange;
107 typedef typename TrackerT::LeafType LeafType;
108 typedef typename TrackerT::BufferType BufferType;
109 typedef typename TrackerT::ValueType ValueType;
110 typedef typename FieldT::VectorType VectorType;
111
113 LevelSetAdvection(GridT& grid, const FieldT& field, InterruptT* interrupt = NULL):
114 mTracker(grid, interrupt), mField(field),
115 mSpatialScheme(math::HJWENO5_BIAS),
116 mTemporalScheme(math::TVD_RK2) {}
117
118 virtual ~LevelSetAdvection() {}
119
121 math::BiasedGradientScheme getSpatialScheme() const { return mSpatialScheme; }
123 void setSpatialScheme(math::BiasedGradientScheme scheme) { mSpatialScheme = scheme; }
124
126 math::TemporalIntegrationScheme getTemporalScheme() const { return mTemporalScheme; }
128 void setTemporalScheme(math::TemporalIntegrationScheme scheme) { mTemporalScheme = scheme; }
129
131 math::BiasedGradientScheme getTrackerSpatialScheme() const {
132 return mTracker.getSpatialScheme();
133 }
135 void setTrackerSpatialScheme(math::BiasedGradientScheme scheme) {
136 mTracker.setSpatialScheme(scheme);
137 }
139 math::TemporalIntegrationScheme getTrackerTemporalScheme() const {
140 return mTracker.getTemporalScheme();
141 }
143 void setTrackerTemporalScheme(math::TemporalIntegrationScheme scheme) {
144 mTracker.setTemporalScheme(scheme);
145 }
146
149 int getNormCount() const { return mTracker.getNormCount(); }
152 void setNormCount(int n) { mTracker.setNormCount(n); }
153
155 int getGrainSize() const { return mTracker.getGrainSize(); }
158 void setGrainSize(int grainsize) { mTracker.setGrainSize(grainsize); }
159
164 size_t advect(ValueType time0, ValueType time1);
165
166 private:
167 // disallow copy construction and copy by assinment!
168 LevelSetAdvection(const LevelSetAdvection&);// not implemented
169 LevelSetAdvection& operator=(const LevelSetAdvection&);// not implemented
170
171 // This templated private struct implements all the level set magic.
172 template<typename MapT, math::BiasedGradientScheme SpatialScheme,
173 math::TemporalIntegrationScheme TemporalScheme>
174 struct Advect
175 {
177 Advect(LevelSetAdvection& parent);
179 Advect(const Advect& other);
181 virtual ~Advect() { if (mIsMaster) this->clearField(); }
184 size_t advect(ValueType time0, ValueType time1);
186 void operator()(const LeafRange& r) const
187 {
188 if (mTask) mTask(const_cast<Advect*>(this), r);
189 else OPENVDB_THROW(ValueError, "task is undefined - don\'t call this method directly");
190 }
192 void cook(const char* msg, size_t swapBuffer = 0);
194 typename GridT::ValueType sampleField(ValueType time0, ValueType time1);
195 template <bool Aligned> void sample(const LeafRange& r, ValueType t0, ValueType t1);
196 inline void sampleXformed(const LeafRange& r, ValueType t0, ValueType t1)
197 {
198 this->sample<false>(r, t0, t1);
199 }
200 inline void sampleAligned(const LeafRange& r, ValueType t0, ValueType t1)
201 {
202 this->sample<true>(r, t0, t1);
203 }
204 void clearField();
205 // Convex combination of Phi and a forward Euler advection steps:
206 // Phi(result) = alpha * Phi(phi) + (1-alpha) * (Phi(0) - dt * Speed(speed)*|Grad[Phi(0)]|);
207 template <int Nominator, int Denominator>
208 void euler(const LeafRange&, ValueType, Index, Index);
209 inline void euler01(const LeafRange& r, ValueType t) {this->euler<0,1>(r, t, 0, 1);}
210 inline void euler12(const LeafRange& r, ValueType t) {this->euler<1,2>(r, t, 1, 1);}
211 inline void euler34(const LeafRange& r, ValueType t) {this->euler<3,4>(r, t, 1, 2);}
212 inline void euler13(const LeafRange& r, ValueType t) {this->euler<1,3>(r, t, 1, 2);}
213
214 LevelSetAdvection& mParent;
215 VectorType* mVelocity;
216 size_t* mOffsets;
217 const MapT* mMap;
218 typename boost::function<void (Advect*, const LeafRange&)> mTask;
219 const bool mIsMaster;
220 }; // end of private Advect struct
221
222 template<math::BiasedGradientScheme SpatialScheme>
223 size_t advect1(ValueType time0, ValueType time1);
224
225 template<math::BiasedGradientScheme SpatialScheme,
226 math::TemporalIntegrationScheme TemporalScheme>
227 size_t advect2(ValueType time0, ValueType time1);
228
229 template<math::BiasedGradientScheme SpatialScheme,
230 math::TemporalIntegrationScheme TemporalScheme,
231 typename MapType>
232 size_t advect3(ValueType time0, ValueType time1);
233
234 TrackerT mTracker;
235 //each thread needs a deep copy of the field since it might contain a ValueAccessor
236 const FieldT mField;
237 math::BiasedGradientScheme mSpatialScheme;
238 math::TemporalIntegrationScheme mTemporalScheme;
239
240 };//end of LevelSetAdvection
241
242
243 template<typename GridT, typename FieldT, typename InterruptT>
244 inline size_t
245 LevelSetAdvection<GridT, FieldT, InterruptT>::advect(ValueType time0, ValueType time1)
246 {
247 switch (mSpatialScheme) {
248 case math::FIRST_BIAS:
249 return this->advect1<math::FIRST_BIAS >(time0, time1);
250 case math::SECOND_BIAS:
251 return this->advect1<math::SECOND_BIAS >(time0, time1);
252 case math::THIRD_BIAS:
253 return this->advect1<math::THIRD_BIAS >(time0, time1);
254 case math::WENO5_BIAS:
255 return this->advect1<math::WENO5_BIAS >(time0, time1);
256 case math::HJWENO5_BIAS:
257 return this->advect1<math::HJWENO5_BIAS>(time0, time1);
258 default:
259 OPENVDB_THROW(ValueError, "Spatial difference scheme not supported!");
260 }
261 return 0;
262 }
263
264
265 template<typename GridT, typename FieldT, typename InterruptT>
266 template<math::BiasedGradientScheme SpatialScheme>
267 inline size_t
268 LevelSetAdvection<GridT, FieldT, InterruptT>::advect1(ValueType time0, ValueType time1)
269 {
270 switch (mTemporalScheme) {
271 case math::TVD_RK1:
272 return this->advect2<SpatialScheme, math::TVD_RK1>(time0, time1);
273 case math::TVD_RK2:
274 return this->advect2<SpatialScheme, math::TVD_RK2>(time0, time1);
275 case math::TVD_RK3:
276 return this->advect2<SpatialScheme, math::TVD_RK3>(time0, time1);
277 default:
278 OPENVDB_THROW(ValueError, "Temporal integration scheme not supported!");
279 }
280 return 0;
281 }
282
283
284 template<typename GridT, typename FieldT, typename InterruptT>
285 template<math::BiasedGradientScheme SpatialScheme, math::TemporalIntegrationScheme TemporalScheme>
286 inline size_t
287 LevelSetAdvection<GridT, FieldT, InterruptT>::advect2(ValueType time0, ValueType time1)
288 {
289 const math::Transform& trans = mTracker.grid().transform();
290 if (trans.mapType() == math::UniformScaleMap::mapType()) {
291 return this->advect3<SpatialScheme, TemporalScheme, math::UniformScaleMap>(time0, time1);
292 } else if (trans.mapType() == math::UniformScaleTranslateMap::mapType()) {
293 return this->advect3<SpatialScheme, TemporalScheme, math::UniformScaleTranslateMap>(
294 time0, time1);
295 } else if (trans.mapType() == math::UnitaryMap::mapType()) {
296 return this->advect3<SpatialScheme, TemporalScheme, math::UnitaryMap >(time0, time1);
297 } else if (trans.mapType() == math::TranslationMap::mapType()) {
298 return this->advect3<SpatialScheme, TemporalScheme, math::TranslationMap>(time0, time1);
299 } else {
300 OPENVDB_THROW(ValueError, "MapType not supported!");
301 }
302 return 0;
303 }
304
305
306 template<typename GridT, typename FieldT, typename InterruptT>
307 template<
308 math::BiasedGradientScheme SpatialScheme,
309 math::TemporalIntegrationScheme TemporalScheme,
310 typename MapT>
311 inline size_t
312 LevelSetAdvection<GridT, FieldT, InterruptT>::advect3(ValueType time0, ValueType time1)
313 {
314 Advect<MapT, SpatialScheme, TemporalScheme> tmp(*this);
315 return tmp.advect(time0, time1);
316 }
317
318
320
321
322 template<typename GridT, typename FieldT, typename InterruptT>
323 template<
324 typename MapT,
325 math::BiasedGradientScheme SpatialScheme,
326 math::TemporalIntegrationScheme TemporalScheme>
327 inline
328 LevelSetAdvection<GridT, FieldT, InterruptT>::
329 Advect<MapT, SpatialScheme, TemporalScheme>::
330 Advect(LevelSetAdvection& parent)
331 : mParent(parent)
332 , mVelocity(NULL)
333 , mOffsets(NULL)
334 , mMap(parent.mTracker.grid().transform().template constMap<MapT>().get())
335 , mTask(0)
336 , mIsMaster(true)
337 {
338 }
339
340
341 template<typename GridT, typename FieldT, typename InterruptT>
342 template<
343 typename MapT,
344 math::BiasedGradientScheme SpatialScheme,
345 math::TemporalIntegrationScheme TemporalScheme>
346 inline
347 LevelSetAdvection<GridT, FieldT, InterruptT>::
348 Advect<MapT, SpatialScheme, TemporalScheme>::
349 Advect(const Advect& other)
350 : mParent(other.mParent)
351 , mVelocity(other.mVelocity)
352 , mOffsets(other.mOffsets)
353 , mMap(other.mMap)
354 , mTask(other.mTask)
355 , mIsMaster(false)
356 {
357 }
358
359
360 template<typename GridT, typename FieldT, typename InterruptT>
361 template<
362 typename MapT,
363 math::BiasedGradientScheme SpatialScheme,
364 math::TemporalIntegrationScheme TemporalScheme>
365 inline size_t
366 LevelSetAdvection<GridT, FieldT, InterruptT>::
367 Advect<MapT, SpatialScheme, TemporalScheme>::
368 advect(ValueType time0, ValueType time1)
369 {
370 //util::CpuTimer timer;
371 size_t countCFL = 0;
372 if ( math::isZero(time0 - time1) ) return countCFL;
373 const bool isForward = time0 < time1;
374 while ((isForward ? time0<time1 : time0>time1) && mParent.mTracker.checkInterrupter()) {
376 //timer.start( "\nallocate buffers" );
377 mParent.mTracker.leafs().rebuildAuxBuffers(TemporalScheme == math::TVD_RK3 ? 2 : 1);
378 //timer.stop();
379
380 const ValueType dt = this->sampleField(time0, time1);
381 if ( math::isZero(dt) ) break;//V is essentially zero so terminate
382
383 OPENVDB_NO_UNREACHABLE_CODE_WARNING_BEGIN //switch is resolved at compile-time
384 switch(TemporalScheme) {
385 case math::TVD_RK1:
386 // Perform one explicit Euler step: t1 = t0 + dt
387 // Phi_t1(1) = Phi_t0(0) - dt * VdotG_t0(0)
388 mTask = boost::bind(&Advect::euler01, _1, _2, dt);
389
390 // Cook and swap buffer 0 and 1 such that Phi_t1(0) and Phi_t0(1)
391 this->cook("Advecting level set using TVD_RK1", 1);
392 break;
393 case math::TVD_RK2:
394 // Perform one explicit Euler step: t1 = t0 + dt
395 // Phi_t1(1) = Phi_t0(0) - dt * VdotG_t0(0)
396 mTask = boost::bind(&Advect::euler01, _1, _2, dt);
397
398 // Cook and swap buffer 0 and 1 such that Phi_t1(0) and Phi_t0(1)
399 this->cook("Advecting level set using TVD_RK1 (step 1 of 2)", 1);
400
401 // Convex combine explict Euler step: t2 = t0 + dt
402 // Phi_t2(1) = 1/2 * Phi_t0(1) + 1/2 * (Phi_t1(0) - dt * V.Grad_t1(0))
403 mTask = boost::bind(&Advect::euler12, _1, _2, dt);
404
405 // Cook and swap buffer 0 and 1 such that Phi_t2(0) and Phi_t1(1)
406 this->cook("Advecting level set using TVD_RK1 (step 2 of 2)", 1);
407 break;
408 case math::TVD_RK3:
409 // Perform one explicit Euler step: t1 = t0 + dt
410 // Phi_t1(1) = Phi_t0(0) - dt * VdotG_t0(0)
411 mTask = boost::bind(&Advect::euler01, _1, _2, dt);
412
413 // Cook and swap buffer 0 and 1 such that Phi_t1(0) and Phi_t0(1)
414 this->cook("Advecting level set using TVD_RK3 (step 1 of 3)", 1);
415
416 // Convex combine explict Euler step: t2 = t0 + dt/2
417 // Phi_t2(2) = 3/4 * Phi_t0(1) + 1/4 * (Phi_t1(0) - dt * V.Grad_t1(0))
418 mTask = boost::bind(&Advect::euler34, _1, _2, dt);
419
420 // Cook and swap buffer 0 and 2 such that Phi_t2(0) and Phi_t1(2)
421 this->cook("Advecting level set using TVD_RK3 (step 2 of 3)", 2);
422
423 // Convex combine explict Euler step: t3 = t0 + dt
424 // Phi_t3(2) = 1/3 * Phi_t0(1) + 2/3 * (Phi_t2(0) - dt * V.Grad_t2(0)
425 mTask = boost::bind(&Advect::euler13, _1, _2, dt);
426
427 // Cook and swap buffer 0 and 2 such that Phi_t3(0) and Phi_t2(2)
428 this->cook("Advecting level set using TVD_RK3 (step 3 of 3)", 2);
429 break;
430 default:
431 OPENVDB_THROW(ValueError, "Temporal integration scheme not supported!");
432 }//end of compile-time resolved switch
433 OPENVDB_NO_UNREACHABLE_CODE_WARNING_END
434
435 time0 += isForward ? dt : -dt;
436 ++countCFL;
437 mParent.mTracker.leafs().removeAuxBuffers();
438 this->clearField();
440 mParent.mTracker.track();
441 }//end wile-loop over time
442 return countCFL;//number of CLF propagation steps
443 }
444
445
446 template<typename GridT, typename FieldT, typename InterruptT>
447 template<
448 typename MapT,
449 math::BiasedGradientScheme SpatialScheme,
450 math::TemporalIntegrationScheme TemporalScheme>
451 inline typename GridT::ValueType
452 LevelSetAdvection<GridT, FieldT, InterruptT>::
453 Advect<MapT, SpatialScheme, TemporalScheme>::
454 sampleField(ValueType time0, ValueType time1)
455 {
456 const int grainSize = mParent.mTracker.getGrainSize();
457 const size_t leafCount = mParent.mTracker.leafs().leafCount();
458 if (leafCount==0) return ValueType(0.0);
459
460 // Compute the prefix sum of offsets to active voxels
461 size_t size=0, voxelCount=mParent.mTracker.leafs().getPrefixSum(mOffsets, size, grainSize);
462
463 // Sample the velocity field
464 if (mParent.mField.transform() == mParent.mTracker.grid().transform()) {
465 mTask = boost::bind(&Advect::sampleAligned, _1, _2, time0, time1);
466 } else {
467 mTask = boost::bind(&Advect::sampleXformed, _1, _2, time0, time1);
468 }
469 assert(voxelCount == mParent.mTracker.grid().activeVoxelCount());
470 mVelocity = new VectorType[ voxelCount ];
471 this->cook("Sampling advection field");
472
473 // Find the extrema of the magnitude of the velocities
474 ValueType maxAbsV = 0;
475 VectorType* v = mVelocity;
476 for (size_t i = 0; i < voxelCount; ++i, ++v) {
477 maxAbsV = math::Max(maxAbsV, ValueType(v->lengthSqr()));
478 }
479
480 // Compute the CFL number
481 if (math::isApproxZero(maxAbsV, math::Delta<ValueType>::value())) return ValueType(0);
482 #ifndef _MSC_VER // Visual C++ doesn't guarantee thread-safe initialization of local statics
483 static
484 #endif
485 const ValueType CFL = (TemporalScheme == math::TVD_RK1 ? ValueType(0.3) :
486 TemporalScheme == math::TVD_RK2 ? ValueType(0.9) :
487 ValueType(1.0))/math::Sqrt(ValueType(3.0));
488 const ValueType dt = math::Abs(time1 - time0), dx = mParent.mTracker.voxelSize();
489 return math::Min(dt, ValueType(CFL*dx/math::Sqrt(maxAbsV)));
490 }
491
492
493 template<typename GridT, typename FieldT, typename InterruptT>
494 template<
495 typename MapT,
496 math::BiasedGradientScheme SpatialScheme,
497 math::TemporalIntegrationScheme TemporalScheme>
498 template<bool Aligned>
499 inline void
500 LevelSetAdvection<GridT, FieldT, InterruptT>::
501 Advect<MapT, SpatialScheme, TemporalScheme>::
502 sample(const LeafRange& range, ValueType time0, ValueType time1)
503 {
504 const bool isForward = time0 < time1;
505 typedef typename LeafType::ValueOnCIter VoxelIterT;
506 const MapT& map = *mMap;
507 const FieldT field( mParent.mField );
508 mParent.mTracker.checkInterrupter();
509 for (typename LeafRange::Iterator leafIter = range.begin(); leafIter; ++leafIter) {
510 VectorType* vel = mVelocity + mOffsets[ leafIter.pos() ];
511 for (VoxelIterT iter = leafIter->cbeginValueOn(); iter; ++iter, ++vel) {
512 const VectorType v = Aligned ? field(iter.getCoord(), time0) ://resolved at compile time
513 field(map.applyMap(iter.getCoord().asVec3d()), time0);
514 *vel = isForward ? v : -v;
515 }
516 }
517 }
518
519
520 template<typename GridT, typename FieldT, typename InterruptT>
521 template<
522 typename MapT,
523 math::BiasedGradientScheme SpatialScheme,
524 math::TemporalIntegrationScheme TemporalScheme>
525 inline void
526 LevelSetAdvection<GridT, FieldT, InterruptT>::
527 Advect<MapT, SpatialScheme, TemporalScheme>::
528 clearField()
529 {
530 delete [] mOffsets;
531 delete [] mVelocity;
532 mOffsets = NULL;
533 mVelocity = NULL;
534 }
535
536
537 template<typename GridT, typename FieldT, typename InterruptT>
538 template<
539 typename MapT,
540 math::BiasedGradientScheme SpatialScheme,
541 math::TemporalIntegrationScheme TemporalScheme>
542 inline void
543 LevelSetAdvection<GridT, FieldT, InterruptT>::
544 Advect<MapT, SpatialScheme, TemporalScheme>::
545 cook(const char* msg, size_t swapBuffer)
546 {
547 mParent.mTracker.startInterrupter( msg );
548
549 const int grainSize = mParent.mTracker.getGrainSize();
550 const LeafRange range = mParent.mTracker.leafs().leafRange(grainSize);
551
552 grainSize == 0 ? (*this)(range) : tbb::parallel_for(range, *this);
553
554 mParent.mTracker.leafs().swapLeafBuffer(swapBuffer, grainSize == 0);
555
556 mParent.mTracker.endInterrupter();
557 }
558
559
560 // Convex combination of Phi and a forward Euler advection steps:
561 // Phi(result) = alpha * Phi(phi) + (1-alpha) * (Phi(0) - dt * V.Grad(0));
562 template<typename GridT, typename FieldT, typename InterruptT>
563 template<
564 typename MapT,
565 math::BiasedGradientScheme SpatialScheme,
566 math::TemporalIntegrationScheme TemporalScheme>
567 template <int Nominator, int Denominator>
568 inline void
569 LevelSetAdvection<GridT, FieldT, InterruptT>::
570 Advect<MapT, SpatialScheme, TemporalScheme>::
571 euler(const LeafRange& range, ValueType dt, Index phiBuffer, Index resultBuffer)
572 {
573 typedef math::BIAS_SCHEME<SpatialScheme> SchemeT;
574 typedef typename SchemeT::template ISStencil<GridType>::StencilType StencilT;
575 typedef typename LeafType::ValueOnCIter VoxelIterT;
576 typedef math::GradientBiased<MapT, SpatialScheme> GradT;
577
578 static const ValueType Alpha = ValueType(Nominator)/ValueType(Denominator);
579 static const ValueType Beta = ValueType(1) - Alpha;
580
581 mParent.mTracker.checkInterrupter();
582 const MapT& map = *mMap;
583 StencilT stencil(mParent.mTracker.grid());
584 for (typename LeafRange::Iterator leafIter = range.begin(); leafIter; ++leafIter) {
585 const VectorType* vel = mVelocity + mOffsets[ leafIter.pos() ];
586 const ValueType* phi = leafIter.buffer(phiBuffer).data();
587 ValueType* result = leafIter.buffer(resultBuffer).data();
588 for (VoxelIterT voxelIter = leafIter->cbeginValueOn(); voxelIter; ++voxelIter, ++vel) {
589 const Index i = voxelIter.pos();
590 stencil.moveTo(voxelIter);
591 const ValueType a =
592 stencil.getValue() - dt * vel->dot(GradT::result(map, stencil, *vel));
593 result[i] = Nominator ? Alpha * phi[i] + Beta * a : a;
594 }//loop over active voxels in the leaf of the mask
595 }//loop over leafs of the level set
596 }
597
598 } // namespace tools
599 } // namespace OPENVDB_VERSION_NAME
600 } // namespace openvdb
601
602 #endif // OPENVDB_TOOLS_LEVEL_SET_ADVECT_HAS_BEEN_INCLUDED
603
604 // Copyright (c) 2012-2017 DreamWorks Animation LLC
605 // All rights reserved. This software is distributed under the
606 // Mozilla Public License 2.0 ( http://www.mozilla.org/MPL/2.0/ )
openvdb::v4_0_2::math::TVD_RK2
Definition: FiniteDifference.h:264
FiniteDifference.h
openvdb::v4_0_2::math::TVD_RK1
Definition: FiniteDifference.h:263
openvdb::v4_0_2::math::SECOND_BIAS
Definition: FiniteDifference.h:195
openvdb::v4_0_2::tools::LevelSetAdvection::getGrainSize
int getGrainSize() const
Return the grain-size used for multi-threading.
Definition: LevelSetAdvect.h:155
openvdb::v4_0_2::tools::LevelSetAdvection::BufferType
TrackerT::BufferType BufferType
Definition: LevelSetAdvect.h:108
LevelSetTracker.h
Performs multi-threaded interface tracking of narrow band level sets. This is the building-block for ...
openvdb::v4_0_2::math::Max
const Type & Max(const Type &a, const Type &b)
Return the maximum of two values.
Definition: Math.h:545
openvdb::v4_0_2::tools::LevelSetAdvection::advect
size_t advect(ValueType time0, ValueType time1)
Definition: LevelSetAdvect.h:245
openvdb::v4_0_2::math::TemporalIntegrationScheme
TemporalIntegrationScheme
Temporal integration schemes.
Definition: FiniteDifference.h:261
VelocityFields.h
Defines two simple wrapper classes for advection velocity fields as well as VelocitySampler and Veloc...
openvdb::v4_0_2::math::HJWENO5_BIAS
Definition: FiniteDifference.h:198
openvdb::v4_0_2::math::Min
const Type & Min(const Type &a, const Type &b)
Return the minimum of two values.
Definition: Math.h:606
OPENVDB_THROW
#define OPENVDB_THROW(exception, message)
Definition: Exceptions.h:101
openvdb::v4_0_2::math::FIRST_BIAS
Definition: FiniteDifference.h:194
i
tbb::atomic< Index32 > i
Definition: LeafBuffer.h:71
openvdb::v4_0_2::tools::LevelSetTracker::LeafType
TreeType::LeafNodeType LeafType
Definition: LevelSetTracker.h:72
openvdb::v4_0_2::math::Delta::value
static T value()
Definition: Math.h:124
openvdb::v4_0_2::Index
Index32 Index
Definition: Types.h:57
openvdb::v4_0_2::tree::LeafManager::LeafRange
Definition: LeafManager.h:127
openvdb::v4_0_2::math::TVD_RK3
Definition: FiniteDifference.h:265
openvdb::v4_0_2::tools::LevelSetAdvection::getTrackerTemporalScheme
math::TemporalIntegrationScheme getTrackerTemporalScheme() const
Return the temporal integration scheme.
Definition: LevelSetAdvect.h:139
openvdb::v4_0_2::math::Transform
Calculate an axis-aligned bounding box in index space from a bounding sphere in world space...
Definition: Transform.h:66
OPENVDB_VERSION_NAME
#define OPENVDB_VERSION_NAME
Definition: version.h:43
openvdb::v4_0_2::tools::LevelSetAdvection::setNormCount
void setNormCount(int n)
Set the number of normalizations performed per track or normalize call.
Definition: LevelSetAdvect.h:152
openvdb::v4_0_2::math::isZero
bool isZero(const Type &x)
Return true if x is exactly equal to zero.
Definition: Math.h:308
openvdb::v4_0_2::tools::LevelSetAdvection::setGrainSize
void setGrainSize(int grainsize)
Set the grain-size used for multi-threading.
Definition: LevelSetAdvect.h:158
openvdb::v4_0_2::math::Abs
Coord Abs(const Coord &xyz)
Definition: Coord.h:509
openvdb::v4_0_2::tools::LevelSetAdvection::LeafRange
TrackerT::LeafRange LeafRange
Definition: LevelSetAdvect.h:106
openvdb::v4_0_2::tools::LevelSetAdvection::getTemporalScheme
math::TemporalIntegrationScheme getTemporalScheme() const
Return the temporal integration scheme.
Definition: LevelSetAdvect.h:126
openvdb
Definition: Exceptions.h:39
OPENVDB_NO_UNREACHABLE_CODE_WARNING_BEGIN
#define OPENVDB_NO_UNREACHABLE_CODE_WARNING_BEGIN
Definition: Platform.h:129
openvdb::v4_0_2::math::Transform::mapType
Name mapType() const
Return the transformation map&#39;s type-name.
Definition: Transform.h:93
openvdb::v4_0_2::tools::LevelSetAdvection::TrackerT
LevelSetTracker< GridT, InterruptT > TrackerT
Definition: LevelSetAdvect.h:105
openvdb::v4_0_2::tools::LevelSetAdvection::LeafType
TrackerT::LeafType LeafType
Definition: LevelSetAdvect.h:107
openvdb::v4_0_2::tools::LevelSetAdvection::VectorType
FieldT::VectorType VectorType
Definition: LevelSetAdvect.h:110
openvdb::v4_0_2::ValueError
Definition: Exceptions.h:92
openvdb::v4_0_2::tools::LevelSetAdvection::~LevelSetAdvection
virtual ~LevelSetAdvection()
Definition: LevelSetAdvect.h:118
openvdb::v4_0_2::tools::LevelSetAdvection::setTrackerSpatialScheme
void setTrackerSpatialScheme(math::BiasedGradientScheme scheme)
Set the spatial finite difference scheme.
Definition: LevelSetAdvect.h:135
openvdb::v4_0_2::tools::LevelSetAdvection::getSpatialScheme
math::BiasedGradientScheme getSpatialScheme() const
Return the spatial finite difference scheme.
Definition: LevelSetAdvect.h:121
OPENVDB_NO_UNREACHABLE_CODE_WARNING_END
#define OPENVDB_NO_UNREACHABLE_CODE_WARNING_END
Definition: Platform.h:130
openvdb::v4_0_2::math::isApproxZero
bool isApproxZero(const Type &x)
Return true if x is equal to zero to within the default floating-point comparison tolerance...
Definition: Math.h:320
openvdb::v4_0_2::math::WENO5_BIAS
Definition: FiniteDifference.h:197
openvdb::v4_0_2::tools::LevelSetAdvection::setTrackerTemporalScheme
void setTrackerTemporalScheme(math::TemporalIntegrationScheme scheme)
Set the spatial finite difference scheme.
Definition: LevelSetAdvect.h:143
openvdb::v4_0_2::math::BiasedGradientScheme
BiasedGradientScheme
Biased Gradients are limited to non-centered differences.
Definition: FiniteDifference.h:192
openvdb::v4_0_2::math::Sqrt
float Sqrt(float x)
Return the square root of a floating-point value.
Definition: Math.h:711
openvdb::v4_0_2::math::THIRD_BIAS
Definition: FiniteDifference.h:196
openvdb::v4_0_2::tools::LevelSetAdvection
Hyperbolic advection of narrow-band level sets in an external velocity field.
Definition: LevelSetAdvect.h:101
OPENVDB_USE_VERSION_NAMESPACE
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:71
openvdb::v4_0_2::tools::LevelSetTracker
Performs multi-threaded interface tracking of narrow band level sets.
Definition: LevelSetTracker.h:67
openvdb::v4_0_2::tools::LevelSetTracker::BufferType
LeafManagerType::BufferType BufferType
Definition: LevelSetTracker.h:76
openvdb::v4_0_2::tools::LevelSetAdvection::setSpatialScheme
void setSpatialScheme(math::BiasedGradientScheme scheme)
Set the spatial finite difference scheme.
Definition: LevelSetAdvect.h:123
openvdb::v4_0_2::tools::LevelSetTracker::ValueType
TreeType::ValueType ValueType
Definition: LevelSetTracker.h:73
openvdb::v4_0_2::tools::LevelSetAdvection::LevelSetAdvection
LevelSetAdvection(GridT &grid, const FieldT &field, InterruptT *interrupt=NULL)
Main constructor.
Definition: LevelSetAdvect.h:113
size
static constexpr size_t size
The size of a LeafBuffer when LeafBuffer::mOutOfCore is atomic.
Definition: LeafBuffer.h:85
openvdb::v4_0_2::tools::LevelSetAdvection::getTrackerSpatialScheme
math::BiasedGradientScheme getTrackerSpatialScheme() const
Return the spatial finite difference scheme.
Definition: LevelSetAdvect.h:131
openvdb::v4_0_2::tools::LevelSetAdvection::ValueType
TrackerT::ValueType ValueType
Definition: LevelSetAdvect.h:109
openvdb::v4_0_2::tools::LevelSetAdvection::GridType
GridT GridType
Definition: LevelSetAdvect.h:104
Platform.h
openvdb::v4_0_2::tools::LevelSetAdvection::setTemporalScheme
void setTemporalScheme(math::TemporalIntegrationScheme scheme)
Set the spatial finite difference scheme.
Definition: LevelSetAdvect.h:128
openvdb::v4_0_2::tools::LevelSetAdvection::getNormCount
int getNormCount() const
Return The number of normalizations performed per track or normalize call.
Definition: LevelSetAdvect.h:149