37 #ifndef OPENVDB_TOOLS_POINT_ADVECT_HAS_BEEN_INCLUDED 38 #define OPENVDB_TOOLS_POINT_ADVECT_HAS_BEEN_INCLUDED 47 #include <tbb/blocked_range.h> 48 #include <tbb/parallel_for.h> 61 template<
typename CptGr
idT = Vec3fGr
id>
75 mCptAccessor(cptGrid.getAccessor()),
80 mCptGrid(other.mCptGrid),
81 mCptAccessor(mCptGrid->getAccessor()),
82 mCptIterations(other.mCptIterations)
89 template <
typename LocationType>
97 for (
unsigned int i = 0; i < mCptIterations; ++i) {
98 const Vec3R location = mCptGrid->worldToIndex(
Vec3R(result[0], result[1], result[2]));
99 BoxSampler::sample<CptAccessor>(mCptAccessor, location, result);
107 const CptGridType* mCptGrid;
108 CptAccessor mCptAccessor;
109 unsigned int mCptIterations;
137 typename PointListT = std::vector<typename GridT::ValueType>,
138 bool StaggeredVelocity =
false,
148 PointAdvect(
const GridT& velGrid, InterrupterType* interrupter =
nullptr):
151 mIntegrationOrder(1),
153 mInterrupter(interrupter)
157 mVelGrid(other.mVelGrid),
158 mPoints(other.mPoints),
160 mAdvIterations(other.mAdvIterations),
161 mIntegrationOrder(other.mIntegrationOrder),
162 mThreaded(other.mThreaded),
163 mInterrupter(other.mInterrupter)
170 bool earlyOut()
const {
return (mIntegrationOrder==0);}
177 void advect(PointListT& points,
float dt,
unsigned int advIterations = 1)
179 if (this->earlyOut())
return;
182 mAdvIterations = advIterations;
184 if (mInterrupter) mInterrupter->start(
"Advecting points by OpenVDB velocity field: ");
186 tbb::parallel_for(tbb::blocked_range<size_t>(0, mPoints->size()), *
this);
188 (*this)(tbb::blocked_range<size_t>(0, mPoints->size()));
190 if (mInterrupter) mInterrupter->end();
194 void operator() (
const tbb::blocked_range<size_t> &range)
const 196 if (mInterrupter && mInterrupter->wasInterrupted()) {
197 tbb::task::self().cancel_group_execution();
201 switch (mIntegrationOrder) {
204 for (
size_t n = range.begin(); n != range.end(); ++n) {
207 for (
unsigned int i = 0; i < mAdvIterations; ++i) {
208 velField.template rungeKutta<1>(mDt, X0);
215 for (
size_t n = range.begin(); n != range.end(); ++n) {
218 for (
unsigned int i = 0; i < mAdvIterations; ++i) {
219 velField.template rungeKutta<2>(mDt, X0);
226 for (
size_t n = range.begin(); n != range.end(); ++n) {
229 for (
unsigned int i = 0; i < mAdvIterations; ++i) {
230 velField.template rungeKutta<3>(mDt, X0);
237 for (
size_t n = range.begin(); n != range.end(); ++n) {
240 for (
unsigned int i = 0; i < mAdvIterations; ++i) {
241 velField.template rungeKutta<4>(mDt, X0);
251 const GridType* mVelGrid;
258 unsigned int mAdvIterations;
259 unsigned int mIntegrationOrder;
263 InterrupterType* mInterrupter;
269 typename PointListT = std::vector<typename GridT::ValueType>,
270 bool StaggeredVelocity =
false,
271 typename CptGridType = GridT,
283 const GridType& cptGrid,
int cptn, InterrupterType* interrupter =
nullptr):
287 mInterrupter(interrupter)
291 mVelGrid(other.mVelGrid),
292 mCptGrid(other.mCptGrid),
293 mCptIter(other.mCptIter),
294 mPoints(other.mPoints),
296 mAdvIterations(other.mAdvIterations),
297 mIntegrationOrder(other.mIntegrationOrder),
298 mThreaded(other.mThreaded),
299 mInterrupter(other.mInterrupter)
311 void advect(PointListT& points,
float dt,
unsigned int advIterations = 1)
316 if (mIntegrationOrder==0 && mCptIter == 0) {
319 (mIntegrationOrder>0) ? mAdvIterations = advIterations : mAdvIterations = 1;
321 if (mInterrupter) mInterrupter->start(
"Advecting points by OpenVDB velocity field: ");
322 const size_t N = mPoints->size();
325 tbb::parallel_for(tbb::blocked_range<size_t>(0, N), *
this);
327 (*this)(tbb::blocked_range<size_t>(0, N));
329 if (mInterrupter) mInterrupter->end();
334 void operator() (
const tbb::blocked_range<size_t> &range)
const 336 if (mInterrupter && mInterrupter->wasInterrupted()) {
337 tbb::task::self().cancel_group_execution();
342 switch (mIntegrationOrder) {
345 for (
size_t n = range.begin(); n != range.end(); ++n) {
347 for (
unsigned int i = 0; i < mAdvIterations; ++i) {
355 for (
size_t n = range.begin(); n != range.end(); ++n) {
357 for (
unsigned int i = 0; i < mAdvIterations; ++i) {
358 velField.template rungeKutta<1>(mDt, X0);
366 for (
size_t n = range.begin(); n != range.end(); ++n) {
368 for (
unsigned int i = 0; i < mAdvIterations; ++i) {
369 velField.template rungeKutta<2>(mDt, X0);
378 for (
size_t n = range.begin(); n != range.end(); ++n) {
380 for (
unsigned int i = 0; i < mAdvIterations; ++i) {
381 velField.template rungeKutta<3>(mDt, X0);
389 for (
size_t n = range.begin(); n != range.end(); ++n) {
391 for (
unsigned int i = 0; i < mAdvIterations; ++i) {
392 velField.template rungeKutta<4>(mDt, X0);
402 const GridType* mVelGrid;
403 const GridType* mCptGrid;
409 unsigned int mAdvIterations;
410 unsigned int mIntegrationOrder;
413 InterrupterType* mInterrupter;
420 #endif // OPENVDB_TOOLS_POINT_ADVECT_HAS_BEEN_INCLUDED math::Vec3< Real > Vec3R
Definition: Types.h:79
General-purpose arithmetic and comparison routines, most of which accept arbitrary value types (or at...
Defines two simple wrapper classes for advection velocity fields as well as VelocitySampler and Veloc...
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h:136
Definition: Exceptions.h:40
Dummy NOOP interrupter class defining interface.
Definition: NullInterrupter.h:52
Vec3SGrid Vec3fGrid
Definition: openvdb.h:83
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:188