OpenVDB 13.0.0

Loading...
Searching...
No Matches
LevelSetAdvect.h
Go to the documentation of this file.
1// Copyright Contributors to the OpenVDB Project
2// SPDX-License-Identifier: Apache-2.0
3
4/// @author Ken Museth
5///
6/// @file tools/LevelSetAdvect.h
7///
8/// @brief Hyperbolic advection of narrow-band level sets
9
10#ifndef OPENVDB_TOOLS_LEVEL_SET_ADVECT_HAS_BEEN_INCLUDED
11#define OPENVDB_TOOLS_LEVEL_SET_ADVECT_HAS_BEEN_INCLUDED
12
13#include <tbb/parallel_for.h>
14#include <tbb/parallel_reduce.h>
15#include "LevelSetTracker.h"
16#include "VelocityFields.h" // for EnrightField
17#include <openvdb/Platform.h>
18#include <openvdb/math/FiniteDifference.h>
19#include <openvdb/util/Assert.h>
20//#include <openvdb/util/CpuTimer.h>
21#include <functional>
22
23
24 namespace openvdb {
25 OPENVDB_USE_VERSION_NAMESPACE
26 namespace OPENVDB_VERSION_NAME {
27 namespace tools {
28
29/// @brief Hyperbolic advection of narrow-band level sets in an
30/// external velocity field
31///
32/// The @c FieldType template argument below refers to any functor
33/// with the following interface (see tools/VelocityFields.h
34/// for examples):
35///
36/// @code
37/// class VelocityField {
38/// ...
39/// public:
40/// openvdb::VectorType operator() (const openvdb::Coord& xyz, ValueType time) const;
41/// ...
42/// };
43/// @endcode
44///
45/// @note The functor method returns the velocity field at coordinate
46/// position xyz of the advection grid, and for the specified
47/// time. Note that since the velocity is returned in the local
48/// coordinate space of the grid that is being advected, the functor
49/// typically depends on the transformation of that grid. This design
50/// is chosen for performance reasons. Finally we will assume that the
51/// functor method is NOT threadsafe (typically uses a ValueAccessor)
52/// and that its lightweight enough that we can copy it per thread.
53///
54/// The @c InterruptType template argument below refers to any class
55/// with the following interface:
56/// @code
57/// class Interrupter {
58/// ...
59/// public:
60/// void start(const char* name = nullptr) // called when computations begin
61/// void end() // called when computations end
62/// bool wasInterrupted(int percent=-1) // return true to break computation
63///};
64/// @endcode
65///
66/// @note If no template argument is provided for this InterruptType
67/// the util::NullInterrupter is used which implies that all
68/// interrupter calls are no-ops (i.e. incurs no computational overhead).
69///
70
71 template<typename GridT,
72 typename FieldT = EnrightField<typename GridT::ValueType>,
73 typename InterruptT = util::NullInterrupter>
74 class LevelSetAdvection
75{
76 public:
77 using GridType = GridT;
78 using TrackerT = LevelSetTracker<GridT, InterruptT>;
79 using LeafRange = typename TrackerT::LeafRange;
80 using LeafType = typename TrackerT::LeafType;
81 using BufferType = typename TrackerT::BufferType;
82 using ValueType = typename TrackerT::ValueType;
83 using VectorType = typename FieldT::VectorType;
84
85 /// Main constructor
86 LevelSetAdvection(GridT& grid, const FieldT& field, InterruptT* interrupt = nullptr):
87 mTracker(grid, interrupt), mField(field),
88 mSpatialScheme(math::HJWENO5_BIAS),
89 mTemporalScheme(math::TVD_RK2) {}
90
91 virtual ~LevelSetAdvection() {}
92
93 /// @brief Return the spatial finite difference scheme
94 math::BiasedGradientScheme getSpatialScheme() const { return mSpatialScheme; }
95 /// @brief Set the spatial finite difference scheme
96 void setSpatialScheme(math::BiasedGradientScheme scheme) { mSpatialScheme = scheme; }
97
98 /// @brief Return the temporal integration scheme
99 math::TemporalIntegrationScheme getTemporalScheme() const { return mTemporalScheme; }
100 /// @brief Set the spatial finite difference scheme
101 void setTemporalScheme(math::TemporalIntegrationScheme scheme) { mTemporalScheme = scheme; }
102
103 /// @brief Return the spatial finite difference scheme
104 math::BiasedGradientScheme getTrackerSpatialScheme() const {
105 return mTracker.getSpatialScheme();
106 }
107 /// @brief Set the spatial finite difference scheme
108 void setTrackerSpatialScheme(math::BiasedGradientScheme scheme) {
109 mTracker.setSpatialScheme(scheme);
110 }
111 /// @brief Return the temporal integration scheme
112 math::TemporalIntegrationScheme getTrackerTemporalScheme() const {
113 return mTracker.getTemporalScheme();
114 }
115 /// @brief Set the spatial finite difference scheme
116 void setTrackerTemporalScheme(math::TemporalIntegrationScheme scheme) {
117 mTracker.setTemporalScheme(scheme);
118 }
119
120 /// @brief Return The number of normalizations performed per track or
121 /// normalize call.
122 int getNormCount() const { return mTracker.getNormCount(); }
123 /// @brief Set the number of normalizations performed per track or
124 /// normalize call.
125 void setNormCount(int n) { mTracker.setNormCount(n); }
126
127 /// @brief Return the grain-size used for multi-threading
128 int getGrainSize() const { return mTracker.getGrainSize(); }
129 /// @brief Set the grain-size used for multi-threading.
130 /// @note A grain size of 0 or less disables multi-threading!
131 void setGrainSize(int grainsize) { mTracker.setGrainSize(grainsize); }
132
133 /// Advect the level set from its current time, time0, to its
134 /// final time, time1. If time0>time1 backward advection is performed.
135 ///
136 /// @return number of CFL iterations used to advect from time0 to time1
137 size_t advect(ValueType time0, ValueType time1);
138
139 private:
140 // disallow copy construction and copy by assignment!
141 LevelSetAdvection(const LevelSetAdvection&);// not implemented
142 LevelSetAdvection& operator=(const LevelSetAdvection&);// not implemented
143
144 // This templated private struct implements all the level set magic.
145 template<typename MapT, math::BiasedGradientScheme SpatialScheme,
146 math::TemporalIntegrationScheme TemporalScheme>
147 struct Advect
148 {
149 /// Main constructor
150 Advect(LevelSetAdvection& parent);
151 /// Shallow copy constructor called by tbb::parallel_for() threads
152 Advect(const Advect& other);
153 /// Destructor
154 virtual ~Advect() { if (mIsMaster) this->clearField(); }
155 /// Advect the level set from its current time, time0, to its final time, time1.
156 /// @return number of CFL iterations
157 size_t advect(ValueType time0, ValueType time1);
158 /// Used internally by tbb::parallel_for()
159 void operator()(const LeafRange& r) const
160 {
161 if (mTask) mTask(const_cast<Advect*>(this), r);
162 else OPENVDB_THROW(ValueError, "task is undefined - don\'t call this method directly");
163 }
164 /// method calling tbb
165 void cook(const char* msg, size_t swapBuffer = 0);
166 /// Sample field and return the CFL time step
167 typename GridT::ValueType sampleField(ValueType time0, ValueType time1);
168 template <bool Aligned> void sample(const LeafRange& r, ValueType t0, ValueType t1);
169 inline void sampleXformed(const LeafRange& r, ValueType t0, ValueType t1)
170 {
171 this->sample<false>(r, t0, t1);
172 }
173 inline void sampleAligned(const LeafRange& r, ValueType t0, ValueType t1)
174 {
175 this->sample<true>(r, t0, t1);
176 }
177 void clearField();
178 // Convex combination of Phi and a forward Euler advection steps:
179 // Phi(result) = alpha * Phi(phi) + (1-alpha) * (Phi(0) - dt * Speed(speed)*|Grad[Phi(0)]|);
180 template <int Nominator, int Denominator>
181 void euler(const LeafRange&, ValueType, Index, Index);
182 inline void euler01(const LeafRange& r, ValueType t) {this->euler<0,1>(r, t, 0, 1);}
183 inline void euler12(const LeafRange& r, ValueType t) {this->euler<1,2>(r, t, 1, 1);}
184 inline void euler34(const LeafRange& r, ValueType t) {this->euler<3,4>(r, t, 1, 2);}
185 inline void euler13(const LeafRange& r, ValueType t) {this->euler<1,3>(r, t, 1, 2);}
186
187 LevelSetAdvection& mParent;
188 VectorType* mVelocity;
189 size_t* mOffsets;
190 const MapT* mMap;
191 typename std::function<void (Advect*, const LeafRange&)> mTask;
192 const bool mIsMaster;
193 }; // end of private Advect struct
194
195 template<math::BiasedGradientScheme SpatialScheme>
196 size_t advect1(ValueType time0, ValueType time1);
197
198 template<math::BiasedGradientScheme SpatialScheme,
199 math::TemporalIntegrationScheme TemporalScheme>
200 size_t advect2(ValueType time0, ValueType time1);
201
202 template<math::BiasedGradientScheme SpatialScheme,
203 math::TemporalIntegrationScheme TemporalScheme,
204 typename MapType>
205 size_t advect3(ValueType time0, ValueType time1);
206
207 TrackerT mTracker;
208 //each thread needs a deep copy of the field since it might contain a ValueAccessor
209 const FieldT mField;
210 math::BiasedGradientScheme mSpatialScheme;
211 math::TemporalIntegrationScheme mTemporalScheme;
212
213};//end of LevelSetAdvection
214
215
216 template<typename GridT, typename FieldT, typename InterruptT>
217 size_t
218 LevelSetAdvection<GridT, FieldT, InterruptT>::advect(ValueType time0, ValueType time1)
219{
220 switch (mSpatialScheme) {
221 case math::FIRST_BIAS:
222 return this->advect1<math::FIRST_BIAS >(time0, time1);
223 case math::SECOND_BIAS:
224 return this->advect1<math::SECOND_BIAS >(time0, time1);
225 case math::THIRD_BIAS:
226 return this->advect1<math::THIRD_BIAS >(time0, time1);
227 case math::WENO5_BIAS:
228 return this->advect1<math::WENO5_BIAS >(time0, time1);
229 case math::HJWENO5_BIAS:
230 return this->advect1<math::HJWENO5_BIAS>(time0, time1);
231 default:
232 OPENVDB_THROW(ValueError, "Spatial difference scheme not supported!");
233 }
234 return 0;
235}
236
237
238 template<typename GridT, typename FieldT, typename InterruptT>
239 template<math::BiasedGradientScheme SpatialScheme>
240 size_t
241LevelSetAdvection<GridT, FieldT, InterruptT>::advect1(ValueType time0, ValueType time1)
242{
243 switch (mTemporalScheme) {
244 case math::TVD_RK1:
245 return this->advect2<SpatialScheme, math::TVD_RK1>(time0, time1);
246 case math::TVD_RK2:
247 return this->advect2<SpatialScheme, math::TVD_RK2>(time0, time1);
248 case math::TVD_RK3:
249 return this->advect2<SpatialScheme, math::TVD_RK3>(time0, time1);
250 default:
251 OPENVDB_THROW(ValueError, "Temporal integration scheme not supported!");
252 }
253 return 0;
254}
255
256
257 template<typename GridT, typename FieldT, typename InterruptT>
258 template<math::BiasedGradientScheme SpatialScheme, math::TemporalIntegrationScheme TemporalScheme>
259 size_t
260LevelSetAdvection<GridT, FieldT, InterruptT>::advect2(ValueType time0, ValueType time1)
261{
262 const math::Transform& trans = mTracker.grid().transform();
263 if (trans.mapType() == math::UniformScaleMap::mapType()) {
264 return this->advect3<SpatialScheme, TemporalScheme, math::UniformScaleMap>(time0, time1);
265 } else if (trans.mapType() == math::UniformScaleTranslateMap::mapType()) {
266 return this->advect3<SpatialScheme, TemporalScheme, math::UniformScaleTranslateMap>(
267 time0, time1);
268 } else if (trans.mapType() == math::UnitaryMap::mapType()) {
269 return this->advect3<SpatialScheme, TemporalScheme, math::UnitaryMap >(time0, time1);
270 } else if (trans.mapType() == math::TranslationMap::mapType()) {
271 return this->advect3<SpatialScheme, TemporalScheme, math::TranslationMap>(time0, time1);
272 } else {
273 OPENVDB_THROW(ValueError, "MapType not supported!");
274 }
275 return 0;
276}
277
278
279 template<typename GridT, typename FieldT, typename InterruptT>
280 template<
281 math::BiasedGradientScheme SpatialScheme,
282 math::TemporalIntegrationScheme TemporalScheme,
283 typename MapT>
284 size_t
285LevelSetAdvection<GridT, FieldT, InterruptT>::advect3(ValueType time0, ValueType time1)
286{
287 Advect<MapT, SpatialScheme, TemporalScheme> tmp(*this);
288 return tmp.advect(time0, time1);
289}
290
291
292///////////////////////////////////////////////////////////////////////
293
294
295 template<typename GridT, typename FieldT, typename InterruptT>
296 template<
297 typename MapT,
298 math::BiasedGradientScheme SpatialScheme,
299 math::TemporalIntegrationScheme TemporalScheme>
300 inline
301LevelSetAdvection<GridT, FieldT, InterruptT>::
302Advect<MapT, SpatialScheme, TemporalScheme>::
303Advect(LevelSetAdvection& parent)
304 : mParent(parent)
305 , mVelocity(nullptr)
306 , mOffsets(nullptr)
307 , mMap(parent.mTracker.grid().transform().template constMap<MapT>().get())
308 , mTask(0)
309 , mIsMaster(true)
310{
311}
312
313
314 template<typename GridT, typename FieldT, typename InterruptT>
315 template<
316 typename MapT,
317 math::BiasedGradientScheme SpatialScheme,
318 math::TemporalIntegrationScheme TemporalScheme>
319 inline
320 LevelSetAdvection<GridT, FieldT, InterruptT>::
321 Advect<MapT, SpatialScheme, TemporalScheme>::
322 Advect(const Advect& other)
323 : mParent(other.mParent)
324 , mVelocity(other.mVelocity)
325 , mOffsets(other.mOffsets)
326 , mMap(other.mMap)
327 , mTask(other.mTask)
328 , mIsMaster(false)
329{
330}
331
332
333 template<typename GridT, typename FieldT, typename InterruptT>
334 template<
335 typename MapT,
336 math::BiasedGradientScheme SpatialScheme,
337 math::TemporalIntegrationScheme TemporalScheme>
338 inline size_t
339 LevelSetAdvection<GridT, FieldT, InterruptT>::
340 Advect<MapT, SpatialScheme, TemporalScheme>::
341 advect(ValueType time0, ValueType time1)
342{
343 namespace ph = std::placeholders;
344
345 //util::CpuTimer timer;
346 size_t countCFL = 0;
347 if ( math::isZero(time0 - time1) ) return countCFL;
348 const bool isForward = time0 < time1;
349 while ((isForward ? time0<time1 : time0>time1) && mParent.mTracker.checkInterrupter()) {
350 /// Make sure we have enough temporal auxiliary buffers
351 //timer.start( "\nallocate buffers" );
352 mParent.mTracker.leafs().rebuildAuxBuffers(TemporalScheme == math::TVD_RK3 ? 2 : 1);
353 //timer.stop();
354
355 const ValueType dt = this->sampleField(time0, time1);
356 if ( math::isZero(dt) ) break;//V is essentially zero so terminate
357
358 OPENVDB_NO_UNREACHABLE_CODE_WARNING_BEGIN //switch is resolved at compile-time
359 switch(TemporalScheme) {
360 case math::TVD_RK1:
361 // Perform one explicit Euler step: t1 = t0 + dt
362 // Phi_t1(1) = Phi_t0(0) - dt * VdotG_t0(0)
363 mTask = std::bind(&Advect::euler01, ph::_1, ph::_2, dt);
364
365 // Cook and swap buffer 0 and 1 such that Phi_t1(0) and Phi_t0(1)
366 this->cook("Advecting level set using TVD_RK1", 1);
367 break;
368 case math::TVD_RK2:
369 // Perform one explicit Euler step: t1 = t0 + dt
370 // Phi_t1(1) = Phi_t0(0) - dt * VdotG_t0(0)
371 mTask = std::bind(&Advect::euler01, ph::_1, ph::_2, dt);
372
373 // Cook and swap buffer 0 and 1 such that Phi_t1(0) and Phi_t0(1)
374 this->cook("Advecting level set using TVD_RK1 (step 1 of 2)", 1);
375
376 // Convex combine explict Euler step: t2 = t0 + dt
377 // Phi_t2(1) = 1/2 * Phi_t0(1) + 1/2 * (Phi_t1(0) - dt * V.Grad_t1(0))
378 mTask = std::bind(&Advect::euler12, ph::_1, ph::_2, dt);
379
380 // Cook and swap buffer 0 and 1 such that Phi_t2(0) and Phi_t1(1)
381 this->cook("Advecting level set using TVD_RK1 (step 2 of 2)", 1);
382 break;
383 case math::TVD_RK3:
384 // Perform one explicit Euler step: t1 = t0 + dt
385 // Phi_t1(1) = Phi_t0(0) - dt * VdotG_t0(0)
386 mTask = std::bind(&Advect::euler01, ph::_1, ph::_2, dt);
387
388 // Cook and swap buffer 0 and 1 such that Phi_t1(0) and Phi_t0(1)
389 this->cook("Advecting level set using TVD_RK3 (step 1 of 3)", 1);
390
391 // Convex combine explict Euler step: t2 = t0 + dt/2
392 // Phi_t2(2) = 3/4 * Phi_t0(1) + 1/4 * (Phi_t1(0) - dt * V.Grad_t1(0))
393 mTask = std::bind(&Advect::euler34, ph::_1, ph::_2, dt);
394
395 // Cook and swap buffer 0 and 2 such that Phi_t2(0) and Phi_t1(2)
396 this->cook("Advecting level set using TVD_RK3 (step 2 of 3)", 2);
397
398 // Convex combine explict Euler step: t3 = t0 + dt
399 // Phi_t3(2) = 1/3 * Phi_t0(1) + 2/3 * (Phi_t2(0) - dt * V.Grad_t2(0)
400 mTask = std::bind(&Advect::euler13, ph::_1, ph::_2, dt);
401
402 // Cook and swap buffer 0 and 2 such that Phi_t3(0) and Phi_t2(2)
403 this->cook("Advecting level set using TVD_RK3 (step 3 of 3)", 2);
404 break;
405 default:
406 OPENVDB_THROW(ValueError, "Temporal integration scheme not supported!");
407 }//end of compile-time resolved switch
408 OPENVDB_NO_UNREACHABLE_CODE_WARNING_END
409
410 time0 += isForward ? dt : -dt;
411 ++countCFL;
412 mParent.mTracker.leafs().removeAuxBuffers();
413 this->clearField();
414 /// Track the narrow band
415 mParent.mTracker.track();
416 }//end wile-loop over time
417 return countCFL;//number of CLF propagation steps
418}
419
420
421 template<typename GridT, typename FieldT, typename InterruptT>
422 template<
423 typename MapT,
424 math::BiasedGradientScheme SpatialScheme,
425 math::TemporalIntegrationScheme TemporalScheme>
426 inline typename GridT::ValueType
427 LevelSetAdvection<GridT, FieldT, InterruptT>::
428 Advect<MapT, SpatialScheme, TemporalScheme>::
429 sampleField(ValueType time0, ValueType time1)
430{
431 namespace ph = std::placeholders;
432
433 const int grainSize = mParent.mTracker.getGrainSize();
434 const size_t leafCount = mParent.mTracker.leafs().leafCount();
435 if (leafCount==0) return ValueType(0.0);
436
437 // Compute the prefix sum of offsets to active voxels
438 size_t size=0, voxelCount=mParent.mTracker.leafs().getPrefixSum(mOffsets, size, grainSize);
439
440 // Sample the velocity field
441 if (mParent.mField.transform() == mParent.mTracker.grid().transform()) {
442 mTask = std::bind(&Advect::sampleAligned, ph::_1, ph::_2, time0, time1);
443 } else {
444 mTask = std::bind(&Advect::sampleXformed, ph::_1, ph::_2, time0, time1);
445 }
446 OPENVDB_ASSERT(voxelCount == mParent.mTracker.grid().activeVoxelCount());
447 mVelocity = new VectorType[ voxelCount ];
448 this->cook("Sampling advection field");
449
450 // Find the extrema of the magnitude of the velocities
451 ValueType maxAbsV = 0;
452 VectorType* v = mVelocity;
453 for (size_t i = 0; i < voxelCount; ++i, ++v) {
454 maxAbsV = math::Max(maxAbsV, ValueType(v->lengthSqr()));
455 }
456
457 // Compute the CFL number
458 if (math::isApproxZero(maxAbsV, math::Delta<ValueType>::value())) return ValueType(0);
459 static const ValueType CFL = (TemporalScheme == math::TVD_RK1 ? ValueType(0.3) :
460 TemporalScheme == math::TVD_RK2 ? ValueType(0.9) :
461 ValueType(1.0))/math::Sqrt(ValueType(3.0));
462 const ValueType dt = math::Abs(time1 - time0), dx = mParent.mTracker.voxelSize();
463 return math::Min(dt, ValueType(CFL*dx/math::Sqrt(maxAbsV)));
464}
465
466
467 template<typename GridT, typename FieldT, typename InterruptT>
468 template<
469 typename MapT,
470 math::BiasedGradientScheme SpatialScheme,
471 math::TemporalIntegrationScheme TemporalScheme>
472 template<bool Aligned>
473 inline void
474 LevelSetAdvection<GridT, FieldT, InterruptT>::
475 Advect<MapT, SpatialScheme, TemporalScheme>::
476 sample(const LeafRange& range, ValueType time0, ValueType time1)
477{
478 const bool isForward = time0 < time1;
479 using VoxelIterT = typename LeafType::ValueOnCIter;
480 const MapT& map = *mMap;
481 const FieldT field( mParent.mField );
482 mParent.mTracker.checkInterrupter();
483 for (typename LeafRange::Iterator leafIter = range.begin(); leafIter; ++leafIter) {
484 VectorType* vel = mVelocity + mOffsets[ leafIter.pos() ];
485 for (VoxelIterT iter = leafIter->cbeginValueOn(); iter; ++iter, ++vel) {
486 OPENVDB_NO_TYPE_CONVERSION_WARNING_BEGIN
487 const VectorType v = Aligned ? field(iter.getCoord(), time0) ://resolved at compile time
488 field(map.applyMap(iter.getCoord().asVec3d()), time0);
489 *vel = isForward ? v : -v;
490 OPENVDB_NO_TYPE_CONVERSION_WARNING_END
491 }
492 }
493}
494
495
496 template<typename GridT, typename FieldT, typename InterruptT>
497 template<
498 typename MapT,
499 math::BiasedGradientScheme SpatialScheme,
500 math::TemporalIntegrationScheme TemporalScheme>
501 inline void
502 LevelSetAdvection<GridT, FieldT, InterruptT>::
503 Advect<MapT, SpatialScheme, TemporalScheme>::
504 clearField()
505{
506 delete [] mOffsets;
507 delete [] mVelocity;
508 mOffsets = nullptr;
509 mVelocity = nullptr;
510}
511
512
513 template<typename GridT, typename FieldT, typename InterruptT>
514 template<
515 typename MapT,
516 math::BiasedGradientScheme SpatialScheme,
517 math::TemporalIntegrationScheme TemporalScheme>
518 inline void
519 LevelSetAdvection<GridT, FieldT, InterruptT>::
520 Advect<MapT, SpatialScheme, TemporalScheme>::
521 cook(const char* msg, size_t swapBuffer)
522{
523 mParent.mTracker.startInterrupter( msg );
524
525 const int grainSize = mParent.mTracker.getGrainSize();
526 const LeafRange range = mParent.mTracker.leafs().leafRange(grainSize);
527
528 grainSize == 0 ? (*this)(range) : tbb::parallel_for(range, *this);
529
530 mParent.mTracker.leafs().swapLeafBuffer(swapBuffer, grainSize == 0);
531
532 mParent.mTracker.endInterrupter();
533}
534
535
536// Convex combination of Phi and a forward Euler advection steps:
537// Phi(result) = alpha * Phi(phi) + (1-alpha) * (Phi(0) - dt * V.Grad(0));
538 template<typename GridT, typename FieldT, typename InterruptT>
539 template<
540 typename MapT,
541 math::BiasedGradientScheme SpatialScheme,
542 math::TemporalIntegrationScheme TemporalScheme>
543 template <int Nominator, int Denominator>
544 inline void
545 LevelSetAdvection<GridT, FieldT, InterruptT>::
546 Advect<MapT, SpatialScheme, TemporalScheme>::
547 euler(const LeafRange& range, ValueType dt, Index phiBuffer, Index resultBuffer)
548{
549 using SchemeT = math::BIAS_SCHEME<SpatialScheme>;
550 using StencilT = typename SchemeT::template ISStencil<GridType>::StencilType;
551 using VoxelIterT = typename LeafType::ValueOnCIter;
552 using GradT = math::GradientBiased<MapT, SpatialScheme>;
553
554 static const ValueType Alpha = ValueType(Nominator)/ValueType(Denominator);
555 static const ValueType Beta = ValueType(1) - Alpha;
556
557 mParent.mTracker.checkInterrupter();
558 const MapT& map = *mMap;
559 StencilT stencil(mParent.mTracker.grid());
560 for (typename LeafRange::Iterator leafIter = range.begin(); leafIter; ++leafIter) {
561 const VectorType* vel = mVelocity + mOffsets[ leafIter.pos() ];
562 const ValueType* phi = leafIter.buffer(phiBuffer).data();
563 ValueType* result = leafIter.buffer(resultBuffer).data();
564 for (VoxelIterT voxelIter = leafIter->cbeginValueOn(); voxelIter; ++voxelIter, ++vel) {
565 const Index i = voxelIter.pos();
566 stencil.moveTo(voxelIter);
567 const ValueType a =
568 stencil.getValue() - dt * vel->dot(GradT::result(map, stencil, *vel));
569 result[i] = Nominator ? Alpha * phi[i] + Beta * a : a;
570 }//loop over active voxels in the leaf of the mask
571 }//loop over leafs of the level set
572}
573
574
575////////////////////////////////////////
576
577
578// Explicit Template Instantiation
579
580#ifdef OPENVDB_USE_EXPLICIT_INSTANTIATION
581
582#ifdef OPENVDB_INSTANTIATE_LEVELSETADVECT
583#include <openvdb/util/ExplicitInstantiation.h>
584#endif
585
586 OPENVDB_INSTANTIATE_CLASS LevelSetAdvection<FloatGrid, DiscreteField<Vec3SGrid, BoxSampler>, util::NullInterrupter>;
587 OPENVDB_INSTANTIATE_CLASS LevelSetAdvection<DoubleGrid, DiscreteField<Vec3SGrid, BoxSampler>, util::NullInterrupter>;
588
589#endif // OPENVDB_USE_EXPLICIT_INSTANTIATION
590
591
592} // namespace tools
593} // namespace OPENVDB_VERSION_NAME
594} // namespace openvdb
595
596#endif // OPENVDB_TOOLS_LEVEL_SET_ADVECT_HAS_BEEN_INCLUDED
Assert.h
OPENVDB_ASSERT
#define OPENVDB_ASSERT(X)
Definition Assert.h:41
ExplicitInstantiation.h
FiniteDifference.h
LevelSetTracker.h
Performs multi-threaded interface tracking of narrow band level sets. This is the building-block for ...
Platform.h
OPENVDB_NO_TYPE_CONVERSION_WARNING_BEGIN
#define OPENVDB_NO_TYPE_CONVERSION_WARNING_BEGIN
Bracket code with OPENVDB_NO_TYPE_CONVERSION_WARNING_BEGIN/_END, to inhibit warnings about type conve...
Definition Platform.h:244
OPENVDB_NO_UNREACHABLE_CODE_WARNING_END
#define OPENVDB_NO_UNREACHABLE_CODE_WARNING_END
Definition Platform.h:164
OPENVDB_NO_TYPE_CONVERSION_WARNING_END
#define OPENVDB_NO_TYPE_CONVERSION_WARNING_END
Definition Platform.h:245
OPENVDB_NO_UNREACHABLE_CODE_WARNING_BEGIN
#define OPENVDB_NO_UNREACHABLE_CODE_WARNING_BEGIN
Definition Platform.h:163
VelocityFields.h
Defines two simple wrapper classes for advection velocity fields as well as VelocitySampler and Veloc...
openvdb::v13_0::ValueError
Definition Exceptions.h:65
openvdb::v13_0::math::Transform
Definition Transform.h:40
openvdb::v13_0::math::Transform::mapType
Name mapType() const
Return the transformation map's type-name.
Definition Transform.h:66
openvdb::v13_0::math::UniformScaleMap::mapType
static Name mapType()
Definition Maps.h:936
openvdb::v13_0::tools::LevelSetAdvection
Hyperbolic advection of narrow-band level sets in an external velocity field.
Definition LevelSetAdvect.h:75
openvdb::v13_0::tools::LevelSetAdvection::LeafRange
typename TrackerT::LeafRange LeafRange
Definition LevelSetAdvect.h:79
openvdb::v13_0::tools::LevelSetAdvection::setTrackerSpatialScheme
void setTrackerSpatialScheme(math::BiasedGradientScheme scheme)
Set the spatial finite difference scheme.
Definition LevelSetAdvect.h:108
openvdb::v13_0::tools::LevelSetAdvection::getTrackerSpatialScheme
math::BiasedGradientScheme getTrackerSpatialScheme() const
Return the spatial finite difference scheme.
Definition LevelSetAdvect.h:104
openvdb::v13_0::tools::LevelSetAdvection::setTrackerTemporalScheme
void setTrackerTemporalScheme(math::TemporalIntegrationScheme scheme)
Set the spatial finite difference scheme.
Definition LevelSetAdvect.h:116
openvdb::v13_0::tools::LevelSetAdvection::ValueType
typename TrackerT::ValueType ValueType
Definition LevelSetAdvect.h:82
openvdb::v13_0::tools::LevelSetAdvection::getTemporalScheme
math::TemporalIntegrationScheme getTemporalScheme() const
Return the temporal integration scheme.
Definition LevelSetAdvect.h:99
openvdb::v13_0::tools::LevelSetAdvection::BufferType
typename TrackerT::BufferType BufferType
Definition LevelSetAdvect.h:81
openvdb::v13_0::tools::LevelSetAdvection::setTemporalScheme
void setTemporalScheme(math::TemporalIntegrationScheme scheme)
Set the spatial finite difference scheme.
Definition LevelSetAdvect.h:101
openvdb::v13_0::tools::LevelSetAdvection::setSpatialScheme
void setSpatialScheme(math::BiasedGradientScheme scheme)
Set the spatial finite difference scheme.
Definition LevelSetAdvect.h:96
openvdb::v13_0::tools::LevelSetAdvection::getSpatialScheme
math::BiasedGradientScheme getSpatialScheme() const
Return the spatial finite difference scheme.
Definition LevelSetAdvect.h:94
openvdb::v13_0::tools::LevelSetAdvection::setGrainSize
void setGrainSize(int grainsize)
Set the grain-size used for multi-threading.
Definition LevelSetAdvect.h:131
openvdb::v13_0::tools::LevelSetAdvection::LevelSetAdvection
LevelSetAdvection(GridT &grid, const FieldT &field, InterruptT *interrupt=nullptr)
Main constructor.
Definition LevelSetAdvect.h:86
openvdb::v13_0::tools::LevelSetAdvection::VectorType
typename FieldT::VectorType VectorType
Definition LevelSetAdvect.h:83
openvdb::v13_0::tools::LevelSetAdvection::getGrainSize
int getGrainSize() const
Return the grain-size used for multi-threading.
Definition LevelSetAdvect.h:128
openvdb::v13_0::tools::LevelSetAdvection::setNormCount
void setNormCount(int n)
Set the number of normalizations performed per track or normalize call.
Definition LevelSetAdvect.h:125
openvdb::v13_0::tools::LevelSetAdvection::LeafType
typename TrackerT::LeafType LeafType
Definition LevelSetAdvect.h:80
openvdb::v13_0::tools::LevelSetAdvection::TrackerT
LevelSetTracker< GridT, InterruptT > TrackerT
Definition LevelSetAdvect.h:78
openvdb::v13_0::tools::LevelSetAdvection::getTrackerTemporalScheme
math::TemporalIntegrationScheme getTrackerTemporalScheme() const
Return the temporal integration scheme.
Definition LevelSetAdvect.h:112
openvdb::v13_0::tools::LevelSetAdvection::~LevelSetAdvection
virtual ~LevelSetAdvection()
Definition LevelSetAdvect.h:91
openvdb::v13_0::tools::LevelSetAdvection::advect
size_t advect(ValueType time0, ValueType time1)
Definition LevelSetAdvect.h:218
openvdb::v13_0::tools::LevelSetAdvection::GridType
GridT GridType
Definition LevelSetAdvect.h:77
openvdb::v13_0::tools::LevelSetAdvection::getNormCount
int getNormCount() const
Return The number of normalizations performed per track or normalize call.
Definition LevelSetAdvect.h:122
openvdb::v13_0::tools::LevelSetTracker
Performs multi-threaded interface tracking of narrow band level sets.
Definition LevelSetTracker.h:58
openvdb::v13_0::tools::LevelSetTracker< GridT, InterruptT >::ValueType
typename TreeType::ValueType ValueType
Definition LevelSetTracker.h:65
openvdb::v13_0::tools::LevelSetTracker::getGrainSize
int getGrainSize() const
Definition LevelSetTracker.h:164
openvdb::v13_0::tools::LevelSetTracker::startInterrupter
void startInterrupter(const char *msg)
Definition LevelSetTracker.h:369
openvdb::v13_0::tools::LevelSetTracker< GridT, InterruptT >::LeafRange
typename LeafManagerType::LeafRange LeafRange
Definition LevelSetTracker.h:67
openvdb::v13_0::tools::LevelSetTracker< GridT, InterruptT >::BufferType
typename LeafManagerType::BufferType BufferType
Definition LevelSetTracker.h:68
openvdb::v13_0::tools::LevelSetTracker< GridT, InterruptT >::LeafType
typename TreeType::LeafNodeType LeafType
Definition LevelSetTracker.h:64
openvdb::v13_0::math
Definition Types.h:759
openvdb::v13_0::math::TemporalIntegrationScheme
TemporalIntegrationScheme
Temporal integration schemes.
Definition FiniteDifference.h:233
openvdb::v13_0::math::TVD_RK1
@ TVD_RK1
Definition FiniteDifference.h:235
openvdb::v13_0::math::TVD_RK2
@ TVD_RK2
Definition FiniteDifference.h:236
openvdb::v13_0::math::TVD_RK3
@ TVD_RK3
Definition FiniteDifference.h:237
openvdb::v13_0::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:362
openvdb::v13_0::math::Sqrt
float Sqrt(float x)
Return the square root of a floating-point value.
Definition Math.h:832
openvdb::v13_0::math::Max
const Type & Max(const Type &a, const Type &b)
Return the maximum of two values.
Definition Math.h:646
openvdb::v13_0::math::BiasedGradientScheme
BiasedGradientScheme
Biased Gradients are limited to non-centered differences.
Definition FiniteDifference.h:164
openvdb::v13_0::math::FIRST_BIAS
@ FIRST_BIAS
Definition FiniteDifference.h:166
openvdb::v13_0::math::THIRD_BIAS
@ THIRD_BIAS
Definition FiniteDifference.h:168
openvdb::v13_0::math::WENO5_BIAS
@ WENO5_BIAS
Definition FiniteDifference.h:169
openvdb::v13_0::math::SECOND_BIAS
@ SECOND_BIAS
Definition FiniteDifference.h:167
openvdb::v13_0::math::HJWENO5_BIAS
@ HJWENO5_BIAS
Definition FiniteDifference.h:170
openvdb::v13_0::math::Min
const Type & Min(const Type &a, const Type &b)
Return the minimum of two values.
Definition Math.h:724
openvdb::v13_0::math::Abs
Coord Abs(const Coord &xyz)
Definition Coord.h:518
openvdb::v13_0::math::isZero
bool isZero(const Type &x)
Return true if x is exactly equal to zero.
Definition Math.h:350
openvdb::v13_0::Index
Index32 Index
Definition Types.h:34
openvdb
Definition Exceptions.h:13
OPENVDB_THROW
#define OPENVDB_THROW(exception, message)
Definition Exceptions.h:74
openvdb::v13_0::math::Delta::value
static T value()
Definition Math.h:167
OPENVDB_VERSION_NAME
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition version.h.in:121
OPENVDB_USE_VERSION_NAMESPACE
#define OPENVDB_USE_VERSION_NAMESPACE
Definition version.h.in:218
OPENVDB_INSTANTIATE_CLASS
#define OPENVDB_INSTANTIATE_CLASS
Definition version.h.in:158