OpenVDB: LevelSetAdvect.h Source File

OpenVDB 3.1.0

- Main Page
- Related Pages
- Namespaces
- Classes
- Files

- File List
- File Members

LevelSetAdvect.h
Go to the documentation of this file.
1 //
3 // Copyright (c) 2012-2015 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
50 namespace openvdb {
51 OPENVDB_USE_VERSION_NAMESPACE
52 namespace OPENVDB_VERSION_NAME {
53 namespace tools {
54
94
95 template<typename GridT,
96 typename FieldT = EnrightField<typename GridT::ValueType>,
97 typename InterruptT = util::NullInterrupter>
98 class LevelSetAdvection
99 {
100 public:
101 typedef GridT GridType;
102 typedef LevelSetTracker<GridT, InterruptT> TrackerT;
103 typedef typename TrackerT::LeafRange LeafRange;
104 typedef typename TrackerT::LeafType LeafType;
105 typedef typename TrackerT::BufferType BufferType;
106 typedef typename TrackerT::ValueType ValueType;
107 typedef typename FieldT::VectorType VectorType;
108
110 LevelSetAdvection(GridT& grid, const FieldT& field, InterruptT* interrupt = NULL):
111 mTracker(grid, interrupt), mField(field),
112 mSpatialScheme(math::HJWENO5_BIAS),
113 mTemporalScheme(math::TVD_RK2) {}
114
115 virtual ~LevelSetAdvection() {}
116
118 math::BiasedGradientScheme getSpatialScheme() const { return mSpatialScheme; }
120 void setSpatialScheme(math::BiasedGradientScheme scheme) { mSpatialScheme = scheme; }
121
123 math::TemporalIntegrationScheme getTemporalScheme() const { return mTemporalScheme; }
125 void setTemporalScheme(math::TemporalIntegrationScheme scheme) { mTemporalScheme = scheme; }
126
128 math::BiasedGradientScheme getTrackerSpatialScheme() const { return mTracker.getSpatialScheme(); }
130 void setTrackerSpatialScheme(math::BiasedGradientScheme scheme) { mTracker.setSpatialScheme(scheme); }
131
133 math::TemporalIntegrationScheme getTrackerTemporalScheme() const { return mTracker.getTemporalScheme(); }
135 void setTrackerTemporalScheme(math::TemporalIntegrationScheme scheme) { mTracker.setTemporalScheme(scheme); }
136
139 int getNormCount() const { return mTracker.getNormCount(); }
142 void setNormCount(int n) { mTracker.setNormCount(n); }
143
145 int getGrainSize() const { return mTracker.getGrainSize(); }
148 void setGrainSize(int grainsize) { mTracker.setGrainSize(grainsize); }
149
154 size_t advect(ValueType time0, ValueType time1);
155
156 private:
157
158 // disallow copy construction and copy by assinment!
159 LevelSetAdvection(const LevelSetAdvection&);// not implemented
160 LevelSetAdvection& operator=(const LevelSetAdvection&);// not implemented
161
162 // This templated private struct implements all the level set magic.
163 template<typename MapT, math::BiasedGradientScheme SpatialScheme,
164 math::TemporalIntegrationScheme TemporalScheme>
165 struct Advect
166 {
168 Advect(LevelSetAdvection& parent);
170 Advect(const Advect& other);
172 Advect(Advect& other, tbb::split);
174 virtual ~Advect() { if (mIsMaster) this->clearField(); }
177 size_t advect(ValueType time0, ValueType time1);
179 void operator()(const LeafRange& r) const
180 {
181 if (mTask) mTask(const_cast<Advect*>(this), r);
182 else OPENVDB_THROW(ValueError, "task is undefined - don\'t call this method directly");
183 }
185 void operator()(const LeafRange& r)
186 {
187 if (mTask) mTask(this, r);
188 else OPENVDB_THROW(ValueError, "task is undefined - don\'t call this method directly");
189 }
191 void join(const Advect& other) { mMaxAbsV = math::Max(mMaxAbsV, other.mMaxAbsV); }
193 enum ThreadingMode { PARALLEL_FOR, PARALLEL_REDUCE }; // for internal use
194 // method calling tbb
195 void cook(ThreadingMode mode, size_t swapBuffer = 0);
197 typename GridT::ValueType sampleField(ValueType time0, ValueType time1);
198 void clearField();
199 void sampleXformedField(const LeafRange& r, ValueType time0, ValueType time1);
200 void sampleAlignedField(const LeafRange& r, ValueType time0, ValueType time1);
201
202 // Convex combination of Phi and a forward Euler advection steps:
203 // Phi(result) = alpha * Phi(phi) + (1-alpha) * (Phi(0) - dt * Speed(speed)*|Grad[Phi(0)]|);
204 template <int Nominator, int Denominator>
205 void euler(const LeafRange&, ValueType, Index, Index);
206 inline void euler01(const LeafRange& r, ValueType t) {this->euler<0,1>(r, t, 0, 1);}
207 inline void euler12(const LeafRange& r, ValueType t) {this->euler<1,2>(r, t, 1, 1);}
208 inline void euler34(const LeafRange& r, ValueType t) {this->euler<3,4>(r, t, 1, 2);}
209 inline void euler13(const LeafRange& r, ValueType t) {this->euler<1,3>(r, t, 1, 2);}
210
211 LevelSetAdvection& mParent;
212 VectorType** mVec;
213 const ValueType mMinAbsV;
214 ValueType mMaxAbsV;
215 const MapT* mMap;
216 typename boost::function<void (Advect*, const LeafRange&)> mTask;
217 const bool mIsMaster;
218 }; // end of private Advect struct
219
220 template<math::BiasedGradientScheme SpatialScheme>
221 size_t advect1(ValueType time0, ValueType time1);
222
223 template<math::BiasedGradientScheme SpatialScheme,
224 math::TemporalIntegrationScheme TemporalScheme>
225 size_t advect2(ValueType time0, ValueType time1);
226
227 template<math::BiasedGradientScheme SpatialScheme,
228 math::TemporalIntegrationScheme TemporalScheme,
229 typename MapType>
230 size_t advect3(ValueType time0, ValueType time1);
231
232 TrackerT mTracker;
233 //each thread needs a deep copy of the field since it might contain a ValueAccessor
234 const FieldT mField;
235 math::BiasedGradientScheme mSpatialScheme;
236 math::TemporalIntegrationScheme mTemporalScheme;
237
238 };//end of LevelSetAdvection
239
240 template<typename GridT, typename FieldT, typename InterruptT>
241 inline size_t
242 LevelSetAdvection<GridT, FieldT, InterruptT>::advect(ValueType time0, ValueType time1)
243 {
244 switch (mSpatialScheme) {
245 case math::FIRST_BIAS:
246 return this->advect1<math::FIRST_BIAS >(time0, time1);
247 case math::SECOND_BIAS:
248 return this->advect1<math::SECOND_BIAS >(time0, time1);
249 case math::THIRD_BIAS:
250 return this->advect1<math::THIRD_BIAS >(time0, time1);
251 case math::WENO5_BIAS:
252 return this->advect1<math::WENO5_BIAS >(time0, time1);
253 case math::HJWENO5_BIAS:
254 return this->advect1<math::HJWENO5_BIAS>(time0, time1);
255 default:
256 OPENVDB_THROW(ValueError, "Spatial difference scheme not supported!");
257 }
258 return 0;
259 }
260
261 template<typename GridT, typename FieldT, typename InterruptT>
262 template<math::BiasedGradientScheme SpatialScheme>
263 inline size_t
264 LevelSetAdvection<GridT, FieldT, InterruptT>::advect1(ValueType time0, ValueType time1)
265 {
266 switch (mTemporalScheme) {
267 case math::TVD_RK1:
268 return this->advect2<SpatialScheme, math::TVD_RK1>(time0, time1);
269 case math::TVD_RK2:
270 return this->advect2<SpatialScheme, math::TVD_RK2>(time0, time1);
271 case math::TVD_RK3:
272 return this->advect2<SpatialScheme, math::TVD_RK3>(time0, time1);
273 default:
274 OPENVDB_THROW(ValueError, "Temporal integration scheme not supported!");
275 }
276 return 0;
277 }
278
279 template<typename GridT, typename FieldT, typename InterruptT>
280 template<math::BiasedGradientScheme SpatialScheme,
281 math::TemporalIntegrationScheme TemporalScheme>
282 inline size_t
283 LevelSetAdvection<GridT, FieldT, InterruptT>::advect2(ValueType time0, ValueType time1)
284 {
285 const math::Transform& trans = mTracker.grid().transform();
286 if (trans.mapType() == math::UniformScaleMap::mapType()) {
287 return this->advect3<SpatialScheme, TemporalScheme, math::UniformScaleMap>(time0, time1);
288 } else if (trans.mapType() == math::UniformScaleTranslateMap::mapType()) {
289 return this->advect3<SpatialScheme, TemporalScheme, math::UniformScaleTranslateMap>(time0, time1);
290 } else if (trans.mapType() == math::UnitaryMap::mapType()) {
291 return this->advect3<SpatialScheme, TemporalScheme, math::UnitaryMap >(time0, time1);
292 } else if (trans.mapType() == math::TranslationMap::mapType()) {
293 return this->advect3<SpatialScheme, TemporalScheme, math::TranslationMap>(time0, time1);
294 } else {
295 OPENVDB_THROW(ValueError, "MapType not supported!");
296 }
297 return 0;
298 }
299
300 template<typename GridT, typename FieldT, typename InterruptT>
301 template<math::BiasedGradientScheme SpatialScheme,
302 math::TemporalIntegrationScheme TemporalScheme,
303 typename MapT>
304 inline size_t
305 LevelSetAdvection<GridT, FieldT, InterruptT>::advect3(ValueType time0, ValueType time1)
306 {
307 Advect<MapT, SpatialScheme, TemporalScheme> tmp(*this);
308 return tmp.advect(time0, time1);
309 }
310
311
313
314
315 template<typename GridT, typename FieldT, typename InterruptT>
316 template <typename MapT, math::BiasedGradientScheme SpatialScheme,
317 math::TemporalIntegrationScheme TemporalScheme>
318 inline
319 LevelSetAdvection<GridT, FieldT, InterruptT>::
320 Advect<MapT, SpatialScheme, TemporalScheme>::
321 Advect(LevelSetAdvection& parent):
322 mParent(parent),
323 mVec(NULL),
324 mMinAbsV(ValueType(1e-6)),
325 mMap(parent.mTracker.grid().transform().template constMap<MapT>().get()),
326 mTask(0),
327 mIsMaster(true)
328 {
329 }
330
331 template<typename GridT, typename FieldT, typename InterruptT>
332 template <typename MapT, math::BiasedGradientScheme SpatialScheme,
333 math::TemporalIntegrationScheme TemporalScheme>
334 inline
335 LevelSetAdvection<GridT, FieldT, InterruptT>::
336 Advect<MapT, SpatialScheme, TemporalScheme>::
337 Advect(const Advect& other):
338 mParent(other.mParent),
339 mVec(other.mVec),
340 mMinAbsV(other.mMinAbsV),
341 mMaxAbsV(other.mMaxAbsV),
342 mMap(other.mMap),
343 mTask(other.mTask),
344 mIsMaster(false)
345 {
346 }
347
348 template<typename GridT, typename FieldT, typename InterruptT>
349 template <typename MapT, math::BiasedGradientScheme SpatialScheme,
350 math::TemporalIntegrationScheme TemporalScheme>
351 inline
352 LevelSetAdvection<GridT, FieldT, InterruptT>::
353 Advect<MapT, SpatialScheme, TemporalScheme>::
354 Advect(Advect& other, tbb::split):
355 mParent(other.mParent),
356 mVec(other.mVec),
357 mMinAbsV(other.mMinAbsV),
358 mMaxAbsV(other.mMaxAbsV),
359 mMap(other.mMap),
360 mTask(other.mTask),
361 mIsMaster(false)
362 {
363 }
364
365 template<typename GridT, typename FieldT, typename InterruptT>
366 template <typename MapT, math::BiasedGradientScheme SpatialScheme,
367 math::TemporalIntegrationScheme TemporalScheme>
368 inline size_t
369 LevelSetAdvection<GridT, FieldT, InterruptT>::
370 Advect<MapT, SpatialScheme, TemporalScheme>::
371 advect(ValueType time0, ValueType time1)
372 {
373 size_t countCFL = 0;
374 if ( math::isZero(time0 - time1) ) return countCFL;
375 const bool isForward = time0 < time1;
376 while ((isForward ? time0<time1 : time0>time1) && mParent.mTracker.checkInterrupter()) {
378 mParent.mTracker.leafs().rebuildAuxBuffers(TemporalScheme == math::TVD_RK3 ? 2 : 1);
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(PARALLEL_FOR, 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(PARALLEL_FOR, 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(PARALLEL_FOR, 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(PARALLEL_FOR, 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(PARALLEL_FOR, 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(PARALLEL_FOR, 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 template<typename GridT, typename FieldT, typename InterruptT>
446 template<typename MapT, math::BiasedGradientScheme SpatialScheme,
447 math::TemporalIntegrationScheme TemporalScheme>
448 inline typename GridT::ValueType
449 LevelSetAdvection<GridT, FieldT, InterruptT>::
450 Advect<MapT, SpatialScheme, TemporalScheme>::
451 sampleField(ValueType time0, ValueType time1)
452 {
453 mMaxAbsV = mMinAbsV;
454 const size_t leafCount = mParent.mTracker.leafs().leafCount();
455 if (leafCount==0) return ValueType(0.0);
456 mVec = new VectorType*[leafCount];
457 if (mParent.mField.transform() == mParent.mTracker.grid().transform()) {
458 mTask = boost::bind(&Advect::sampleAlignedField, _1, _2, time0, time1);
459 } else {
460 mTask = boost::bind(&Advect::sampleXformedField, _1, _2, time0, time1);
461 }
462 this->cook(PARALLEL_REDUCE);
463 if (math::isExactlyEqual(mMinAbsV, mMaxAbsV)) return ValueType(0.0);//V is essentially zero
464 #ifndef _MSC_VER // Visual C++ doesn't guarantee thread-safe initialization of local statics
465 static
466 #endif
467 const ValueType CFL = (TemporalScheme == math::TVD_RK1 ? ValueType(0.3) :
468 TemporalScheme == math::TVD_RK2 ? ValueType(0.9) :
469 ValueType(1.0))/math::Sqrt(ValueType(3.0));
470 const ValueType dt = math::Abs(time1 - time0), dx = mParent.mTracker.voxelSize();
471 return math::Min(dt, ValueType(CFL*dx/math::Sqrt(mMaxAbsV)));
472 }
473
474 template<typename GridT, typename FieldT, typename InterruptT>
475 template <typename MapT, math::BiasedGradientScheme SpatialScheme,
476 math::TemporalIntegrationScheme TemporalScheme>
477 inline void
478 LevelSetAdvection<GridT, FieldT, InterruptT>::
479 Advect<MapT, SpatialScheme, TemporalScheme>::
480 sampleXformedField(const LeafRange& range, ValueType time0, ValueType time1)
481 {
482 const bool isForward = time0 < time1;
483 typedef typename LeafType::ValueOnCIter VoxelIterT;
484 const MapT& map = *mMap;
485 mParent.mTracker.checkInterrupter();
486 for (typename LeafRange::Iterator leafIter = range.begin(); leafIter; ++leafIter) {
487 VectorType* vec = new VectorType[leafIter->onVoxelCount()];
488 mVec[leafIter.pos()] = vec;
489 for (VoxelIterT iter = leafIter->cbeginValueOn(); iter; ++iter, ++vec) {
490 const VectorType v = mParent.mField(map.applyMap(iter.getCoord().asVec3d()), time0);
491 mMaxAbsV = math::Max(mMaxAbsV, ValueType(math::Pow2(v[0])+math::Pow2(v[1])+math::Pow2(v[2])));
492 *vec = isForward ? v : -v;
493 }
494 }
495 }
496
497 template<typename GridT, typename FieldT, typename InterruptT>
498 template <typename MapT, math::BiasedGradientScheme SpatialScheme,
499 math::TemporalIntegrationScheme TemporalScheme>
500 inline void
501 LevelSetAdvection<GridT, FieldT, InterruptT>::
502 Advect<MapT, SpatialScheme, TemporalScheme>::
503 sampleAlignedField(const LeafRange& range, ValueType time0, ValueType time1)
504 {
505 const bool isForward = time0 < time1;
506 typedef typename LeafType::ValueOnCIter VoxelIterT;
507 mParent.mTracker.checkInterrupter();
508 for (typename LeafRange::Iterator leafIter = range.begin(); leafIter; ++leafIter) {
509 VectorType* vec = new VectorType[leafIter->onVoxelCount()];
510 mVec[leafIter.pos()] = vec;
511 for (VoxelIterT iter = leafIter->cbeginValueOn(); iter; ++iter, ++vec) {
512 const VectorType v = mParent.mField(iter.getCoord(), time0);
513 mMaxAbsV = math::Max(mMaxAbsV, ValueType(math::Pow2(v[0])+math::Pow2(v[1])+math::Pow2(v[2])));
514 *vec = isForward ? v : -v;
515 }
516 }
517 }
518
519 template<typename GridT, typename FieldT, typename InterruptT>
520 template <typename MapT, math::BiasedGradientScheme SpatialScheme,
521 math::TemporalIntegrationScheme TemporalScheme>
522 inline void
523 LevelSetAdvection<GridT, FieldT, InterruptT>::
524 Advect<MapT, SpatialScheme, TemporalScheme>::
525 clearField()
526 {
527 if (mVec == NULL) return;
528 for (size_t n=0, e=mParent.mTracker.leafs().leafCount(); n<e; ++n) delete [] mVec[n];
529 delete [] mVec;
530 mVec = NULL;
531 }
532
533 template<typename GridT, typename FieldT, typename InterruptT>
534 template <typename MapT, math::BiasedGradientScheme SpatialScheme,
535 math::TemporalIntegrationScheme TemporalScheme>
536 inline void
537 LevelSetAdvection<GridT, FieldT, InterruptT>::
538 Advect<MapT, SpatialScheme, TemporalScheme>::
539 cook(ThreadingMode mode, size_t swapBuffer)
540 {
541 mParent.mTracker.startInterrupter("Advecting level set");
542
543 const int grainSize = mParent.mTracker.getGrainSize();
544 const LeafRange range = mParent.mTracker.leafs().leafRange(grainSize);
545
546 if (grainSize == 0) {
547 (*this)(range);
548 } else if (mode == PARALLEL_FOR) {
549 tbb::parallel_for(range, *this);
550 } else if (mode == PARALLEL_REDUCE) {
551 tbb::parallel_reduce(range, *this);
552 } else {
553 OPENVDB_THROW(ValueError,"Undefined threading mode");
554 }
555
556 mParent.mTracker.leafs().swapLeafBuffer(swapBuffer, grainSize == 0);
557
558 mParent.mTracker.endInterrupter();
559 }
560
561 // Convex combination of Phi and a forward Euler advection steps:
562 // Phi(result) = alpha * Phi(phi) + (1-alpha) * (Phi(0) - dt * V.Grad(0));
563 template<typename GridT, typename FieldT, typename InterruptT>
564 template<typename MapT, math::BiasedGradientScheme SpatialScheme,
565 math::TemporalIntegrationScheme TemporalScheme>
566 template <int Nominator, int Denominator>
567 inline void
568 LevelSetAdvection<GridT, FieldT, InterruptT>::
569 Advect<MapT, SpatialScheme, TemporalScheme>::
570 euler(const LeafRange& range, ValueType dt, Index phiBuffer, Index resultBuffer)
571 {
572 typedef math::BIAS_SCHEME<SpatialScheme> SchemeT;
573 typedef typename SchemeT::template ISStencil<GridType>::StencilType StencilT;
574 typedef typename LeafType::ValueOnCIter VoxelIterT;
575 typedef math::GradientBiased<MapT, SpatialScheme> GradT;
576
577 static const ValueType Alpha = ValueType(Nominator)/ValueType(Denominator);
578 static const ValueType Beta = ValueType(1) - Alpha;
579
580 mParent.mTracker.checkInterrupter();
581 const MapT& map = *mMap;
582 StencilT stencil(mParent.mTracker.grid());
583 for (typename LeafRange::Iterator leafIter = range.begin(); leafIter; ++leafIter) {
584 const VectorType* v = mVec[leafIter.pos()];
585 const ValueType* phi = leafIter.buffer(phiBuffer).data();
586 ValueType* result = leafIter.buffer(resultBuffer).data();
587 for (VoxelIterT voxelIter = leafIter->cbeginValueOn(); voxelIter; ++voxelIter, ++v) {
588 const Index i = voxelIter.pos();
589 stencil.moveTo(voxelIter);
590 const ValueType a = stencil.getValue() - dt * v->dot(GradT::result(map, stencil,*v));
591 result[i] = Nominator ? Alpha * phi[i] + Beta * a : a;
592 }//loop over active voxels in the leaf of the mask
593 }//loop over leafs of the level set
594 }
595
596 } // namespace tools
597 } // namespace OPENVDB_VERSION_NAME
598 } // namespace openvdb
599
600 #endif // OPENVDB_TOOLS_LEVEL_SET_ADVECT_HAS_BEEN_INCLUDED
601
602 // Copyright (c) 2012-2015 DreamWorks Animation LLC
603 // All rights reserved. This software is distributed under the
604 // Mozilla Public License 2.0 ( http://www.mozilla.org/MPL/2.0/ )
FiniteDifference.h
openvdb::v3_1_0::Index
Index32 Index
Definition: Types.h:58
openvdb::v3_1_0::tools::LevelSetAdvection::setTrackerSpatialScheme
void setTrackerSpatialScheme(math::BiasedGradientScheme scheme)
Set the spatial finite difference scheme.
Definition: LevelSetAdvect.h:130
openvdb::v3_1_0::math::HJWENO5_BIAS
Definition: FiniteDifference.h:198
LevelSetTracker.h
Performs multi-threaded interface tracking of narrow band level sets. This is the building-block for ...
openvdb::v3_1_0::tools::LevelSetAdvection::LevelSetAdvection
LevelSetAdvection(GridT &grid, const FieldT &field, InterruptT *interrupt=NULL)
Main constructor.
Definition: LevelSetAdvect.h:110
openvdb::v3_1_0::tools::LevelSetAdvection::getTemporalScheme
math::TemporalIntegrationScheme getTemporalScheme() const
Definition: LevelSetAdvect.h:123
openvdb::v3_1_0::tools::LevelSetAdvection::getSpatialScheme
math::BiasedGradientScheme getSpatialScheme() const
Definition: LevelSetAdvect.h:118
VelocityFields.h
Defines two simple wrapper classes for advection velocity fields as well as VelocitySampler and Veloc...
openvdb::v3_1_0::math::Abs
int32_t Abs(int32_t i)
Return the absolute value of the given quantity.
Definition: Math.h:293
openvdb::v3_1_0::math::TVD_RK1
Definition: FiniteDifference.h:263
openvdb::v3_1_0::ValueError
Definition: Exceptions.h:88
openvdb::v3_1_0::math::isExactlyEqual
bool isExactlyEqual(const T0 &a, const T1 &b)
Return true if a is exactly equal to b.
Definition: Math.h:407
openvdb::v3_1_0::tools::LevelSetTracker
Performs multi-threaded interface tracking of narrow band level sets.
Definition: LevelSetTracker.h:67
OPENVDB_THROW
#define OPENVDB_THROW(exception, message)
Definition: Exceptions.h:97
openvdb::v3_1_0::tools::LevelSetAdvection::GridType
GridT GridType
Definition: LevelSetAdvect.h:101
openvdb::v3_1_0::tools::LevelSetAdvection::LeafRange
TrackerT::LeafRange LeafRange
Definition: LevelSetAdvect.h:103
openvdb::v3_1_0::math::WENO5_BIAS
Definition: FiniteDifference.h:197
openvdb::v3_1_0::tools::LevelSetAdvection::setNormCount
void setNormCount(int n)
Set the number of normalizations performed per track or normalize call.
Definition: LevelSetAdvect.h:142
openvdb::v3_1_0::tools::LevelSetAdvection::getGrainSize
int getGrainSize() const
Definition: LevelSetAdvect.h:145
openvdb::v3_1_0::math::BIAS_SCHEME
Definition: Operators.h:152
openvdb::v3_1_0::tools::LevelSetAdvection::VectorType
FieldT::VectorType VectorType
Definition: LevelSetAdvect.h:107
openvdb::v3_1_0::tools::LevelSetTracker::BufferType
LeafManagerType::BufferType BufferType
Definition: LevelSetTracker.h:76
openvdb::v3_1_0::math::SECOND_BIAS
Definition: FiniteDifference.h:195
openvdb::v3_1_0::tree::LeafManager::LeafRange::begin
Iterator begin() const
Definition: LeafManager.h:181
openvdb::v3_1_0::tools::LevelSetTracker::ValueType
TreeType::ValueType ValueType
Definition: LevelSetTracker.h:73
openvdb::v3_1_0::tools::LevelSetTracker::leafs
LeafManagerType & leafs()
Definition: LevelSetTracker.h:185
OPENVDB_VERSION_NAME
#define OPENVDB_VERSION_NAME
Definition: version.h:43
openvdb::v3_1_0::tree::LeafManager::rebuildAuxBuffers
void rebuildAuxBuffers(size_t auxBuffersPerLeaf, bool serial=false)
Change the number of auxiliary buffers.
Definition: LeafManager.h:283
openvdb::v3_1_0::math::isZero
bool isZero(const Type &x)
Return true if x is exactly equal to zero.
Definition: Math.h:324
openvdb::v3_1_0::tools::LevelSetTracker::checkInterrupter
bool checkInterrupter()
Definition: LevelSetTracker.h:376
openvdb::v3_1_0::math::THIRD_BIAS
Definition: FiniteDifference.h:196
openvdb::v3_1_0::tools::LevelSetAdvection::BufferType
TrackerT::BufferType BufferType
Definition: LevelSetAdvect.h:105
openvdb
Definition: Exceptions.h:39
openvdb::v3_1_0::tools::LevelSetAdvection::getTrackerSpatialScheme
math::BiasedGradientScheme getTrackerSpatialScheme() const
Definition: LevelSetAdvect.h:128
OPENVDB_NO_UNREACHABLE_CODE_WARNING_BEGIN
#define OPENVDB_NO_UNREACHABLE_CODE_WARNING_BEGIN
Definition: Platform.h:129
openvdb::v3_1_0::tools::LevelSetAdvection::ValueType
TrackerT::ValueType ValueType
Definition: LevelSetAdvect.h:106
openvdb::v3_1_0::tree::LeafManager::leafCount
size_t leafCount() const
Return the number of leaf nodes.
Definition: LeafManager.h:304
openvdb::v3_1_0::tools::LevelSetAdvection::setSpatialScheme
void setSpatialScheme(math::BiasedGradientScheme scheme)
Set the spatial finite difference scheme.
Definition: LevelSetAdvect.h:120
openvdb::v3_1_0::math::Max
const Type & Max(const Type &a, const Type &b)
Return the maximum of two values.
Definition: Math.h:561
openvdb::v3_1_0::tools::LevelSetAdvection::TrackerT
LevelSetTracker< GridT, InterruptT > TrackerT
Definition: LevelSetAdvect.h:102
openvdb::v3_1_0::math::Pow2
Type Pow2(Type x)
Return .
Definition: Math.h:514
openvdb::v3_1_0::math::FIRST_BIAS
Definition: FiniteDifference.h:194
openvdb::v3_1_0::tools::LevelSetTracker::grid
const GridType & grid() const
Definition: LevelSetTracker.h:183
openvdb::v3_1_0::tools::LevelSetAdvection::LeafType
TrackerT::LeafType LeafType
Definition: LevelSetAdvect.h:104
openvdb::v3_1_0::math::Transform
Calculate an axis-aligned bounding box in index space from a bounding sphere in world space...
Definition: Transform.h:66
OPENVDB_NO_UNREACHABLE_CODE_WARNING_END
#define OPENVDB_NO_UNREACHABLE_CODE_WARNING_END
Definition: Platform.h:130
openvdb::v3_1_0::math::BiasedGradientScheme
BiasedGradientScheme
Biased Gradients are limited to non-centered differences.
Definition: FiniteDifference.h:192
openvdb::v3_1_0::math::Transform::mapType
Name mapType() const
Return the transformation map&#39;s type-name.
Definition: Transform.h:93
openvdb::v3_1_0::tools::LevelSetAdvection
Hyperbolic advection of narrow-band level sets in an external velocity field.
Definition: LevelSetAdvect.h:98
openvdb::v3_1_0::tools::LevelSetAdvection::~LevelSetAdvection
virtual ~LevelSetAdvection()
Definition: LevelSetAdvect.h:115
openvdb::v3_1_0::tools::LevelSetTracker::LeafType
TreeType::LeafNodeType LeafType
Definition: LevelSetTracker.h:72
openvdb::v3_1_0::math::GradientBiased
Biased gradient operators, defined with respect to the range-space of the map.
Definition: Operators.h:827
openvdb::v3_1_0::math::TVD_RK3
Definition: FiniteDifference.h:265
openvdb::v3_1_0::tree::LeafManager::LeafRange::Iterator
Definition: LeafManager.h:134
openvdb::v3_1_0::tools::LevelSetAdvection::setTemporalScheme
void setTemporalScheme(math::TemporalIntegrationScheme scheme)
Set the spatial finite difference scheme.
Definition: LevelSetAdvect.h:125
openvdb::v3_1_0::math::TVD_RK2
Definition: FiniteDifference.h:264
OPENVDB_USE_VERSION_NAMESPACE
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:71
openvdb::v3_1_0::math::Sqrt
float Sqrt(float x)
Return the square root of a floating-point value.
Definition: Math.h:709
openvdb::v3_1_0::tools::LevelSetTracker::startInterrupter
void startInterrupter(const char *msg)
Definition: LevelSetTracker.h:360
openvdb::v3_1_0::tools::LevelSetAdvection::setTrackerTemporalScheme
void setTrackerTemporalScheme(math::TemporalIntegrationScheme scheme)
Set the spatial finite difference scheme.
Definition: LevelSetAdvect.h:135
openvdb::v3_1_0::math::Min
const Type & Min(const Type &a, const Type &b)
Return the minimum of two values.
Definition: Math.h:622
openvdb::v3_1_0::tools::LevelSetAdvection::getNormCount
int getNormCount() const
Definition: LevelSetAdvect.h:139
openvdb::v3_1_0::math::TemporalIntegrationScheme
TemporalIntegrationScheme
Temporal integration schemes.
Definition: FiniteDifference.h:261
openvdb::v3_1_0::tools::LevelSetAdvection::getTrackerTemporalScheme
math::TemporalIntegrationScheme getTrackerTemporalScheme() const
Definition: LevelSetAdvect.h:133
openvdb::v3_1_0::tree::LeafManager::LeafRange
Definition: LeafManager.h:131
Platform.h
openvdb::v3_1_0::tools::LevelSetAdvection::setGrainSize
void setGrainSize(int grainsize)
Set the grain-size used for multi-threading.
Definition: LevelSetAdvect.h:148