36 #ifndef OPENVDB_TOOLS_POINT_ADVECT_HAS_BEEN_INCLUDED 37 #define OPENVDB_TOOLS_POINT_ADVECT_HAS_BEEN_INCLUDED 46 #include <tbb/blocked_range.h> 47 #include <tbb/parallel_for.h> 60 template<
typename CptGr
idT = Vec3fGr
id>
74 mCptAccessor(cptGrid.getAccessor()),
79 mCptGrid(other.mCptGrid),
80 mCptAccessor(mCptGrid->getAccessor()),
81 mCptIterations(other.mCptIterations)
88 template <
typename LocationType>
96 for (
unsigned int i = 0; i < mCptIterations; ++i) {
97 const Vec3R location = mCptGrid->worldToIndex(
Vec3R(result[0], result[1], result[2]));
98 BoxSampler::sample<CptAccessor>(mCptAccessor, location, result);
108 unsigned int mCptIterations;
136 typename PointListT = std::vector<typename GridT::ValueType>,
137 bool StaggeredVelocity =
false,
147 PointAdvect(
const GridT& velGrid, InterrupterType* interrupter =
nullptr):
150 mIntegrationOrder(1),
152 mInterrupter(interrupter)
156 mVelGrid(other.mVelGrid),
157 mPoints(other.mPoints),
159 mAdvIterations(other.mAdvIterations),
160 mIntegrationOrder(other.mIntegrationOrder),
161 mThreaded(other.mThreaded),
162 mInterrupter(other.mInterrupter)
169 bool earlyOut()
const {
return (mIntegrationOrder==0);}
176 void advect(PointListT& points,
float dt,
unsigned int advIterations = 1)
178 if (this->earlyOut())
return;
181 mAdvIterations = advIterations;
183 if (mInterrupter) mInterrupter->start(
"Advecting points by OpenVDB velocity field: ");
185 tbb::parallel_for(tbb::blocked_range<size_t>(0, mPoints->size()), *
this);
187 (*this)(tbb::blocked_range<size_t>(0, mPoints->size()));
189 if (mInterrupter) mInterrupter->end();
193 void operator() (
const tbb::blocked_range<size_t> &range)
const 195 if (mInterrupter && mInterrupter->wasInterrupted()) {
196 tbb::task::self().cancel_group_execution();
200 switch (mIntegrationOrder) {
203 for (
size_t n = range.begin(); n != range.end(); ++n) {
206 for (
unsigned int i = 0; i < mAdvIterations; ++i) {
207 velField.template rungeKutta<1>(mDt, X0);
214 for (
size_t n = range.begin(); n != range.end(); ++n) {
217 for (
unsigned int i = 0; i < mAdvIterations; ++i) {
218 velField.template rungeKutta<2>(mDt, X0);
225 for (
size_t n = range.begin(); n != range.end(); ++n) {
228 for (
unsigned int i = 0; i < mAdvIterations; ++i) {
229 velField.template rungeKutta<3>(mDt, X0);
236 for (
size_t n = range.begin(); n != range.end(); ++n) {
239 for (
unsigned int i = 0; i < mAdvIterations; ++i) {
240 velField.template rungeKutta<4>(mDt, X0);
257 unsigned int mAdvIterations;
258 unsigned int mIntegrationOrder;
262 InterrupterType* mInterrupter;
268 typename PointListT = std::vector<typename GridT::ValueType>,
269 bool StaggeredVelocity =
false,
270 typename CptGridType = GridT,
282 const GridType& cptGrid,
int cptn, InterrupterType* interrupter =
nullptr):
286 mInterrupter(interrupter)
290 mVelGrid(other.mVelGrid),
291 mCptGrid(other.mCptGrid),
292 mCptIter(other.mCptIter),
293 mPoints(other.mPoints),
295 mAdvIterations(other.mAdvIterations),
296 mIntegrationOrder(other.mIntegrationOrder),
297 mThreaded(other.mThreaded),
298 mInterrupter(other.mInterrupter)
310 void advect(PointListT& points,
float dt,
unsigned int advIterations = 1)
315 if (mIntegrationOrder==0 && mCptIter == 0) {
318 (mIntegrationOrder>0) ? mAdvIterations = advIterations : mAdvIterations = 1;
320 if (mInterrupter) mInterrupter->start(
"Advecting points by OpenVDB velocity field: ");
321 const size_t N = mPoints->size();
324 tbb::parallel_for(tbb::blocked_range<size_t>(0, N), *
this);
326 (*this)(tbb::blocked_range<size_t>(0, N));
328 if (mInterrupter) mInterrupter->end();
333 void operator() (
const tbb::blocked_range<size_t> &range)
const 335 if (mInterrupter && mInterrupter->wasInterrupted()) {
336 tbb::task::self().cancel_group_execution();
341 switch (mIntegrationOrder) {
344 for (
size_t n = range.begin(); n != range.end(); ++n) {
346 for (
unsigned int i = 0; i < mAdvIterations; ++i) {
354 for (
size_t n = range.begin(); n != range.end(); ++n) {
356 for (
unsigned int i = 0; i < mAdvIterations; ++i) {
357 velField.template rungeKutta<1>(mDt, X0);
365 for (
size_t n = range.begin(); n != range.end(); ++n) {
367 for (
unsigned int i = 0; i < mAdvIterations; ++i) {
368 velField.template rungeKutta<2>(mDt, X0);
377 for (
size_t n = range.begin(); n != range.end(); ++n) {
379 for (
unsigned int i = 0; i < mAdvIterations; ++i) {
380 velField.template rungeKutta<3>(mDt, X0);
388 for (
size_t n = range.begin(); n != range.end(); ++n) {
390 for (
unsigned int i = 0; i < mAdvIterations; ++i) {
391 velField.template rungeKutta<4>(mDt, X0);
408 unsigned int mAdvIterations;
409 unsigned int mIntegrationOrder;
412 InterrupterType* mInterrupter;
419 #endif // OPENVDB_TOOLS_POINT_ADVECT_HAS_BEEN_INCLUDED
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
Vec3SGrid Vec3fGrid
Definition: openvdb.h:83
Definition: Exceptions.h:40
math::Vec3< Real > Vec3R
Definition: Types.h:79
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:188
Dummy NOOP interrupter class defining interface.
Definition: NullInterrupter.h:52