10 #ifndef OPENVDB_TOOLS_POINT_ADVECT_HAS_BEEN_INCLUDED
11 #define OPENVDB_TOOLS_POINT_ADVECT_HAS_BEEN_INCLUDED
20 #include <tbb/blocked_range.h>
21 #include <tbb/parallel_for.h>
34 template<
typename CptGr
idT = Vec3fGr
id>
48 mCptAccessor(cptGrid.getAccessor()),
53 mCptGrid(other.mCptGrid),
54 mCptAccessor(mCptGrid->getAccessor()),
55 mCptIterations(other.mCptIterations)
62 template <
typename LocationType>
70 for (
unsigned int i = 0; i < mCptIterations; ++i) {
71 const Vec3R location = mCptGrid->worldToIndex(
Vec3R(result[0], result[1], result[2]));
72 BoxSampler::sample<CptAccessor>(mCptAccessor, location, result);
80 const CptGridType* mCptGrid;
81 CptAccessor mCptAccessor;
82 unsigned int mCptIterations;
110 typename PointListT = std::vector<typename GridT::ValueType>,
111 bool StaggeredVelocity =
false,
121 PointAdvect(
const GridT& velGrid, InterrupterType* interrupter =
nullptr):
124 mIntegrationOrder(1),
126 mInterrupter(interrupter)
130 mVelGrid(other.mVelGrid),
131 mPoints(other.mPoints),
133 mAdvIterations(other.mAdvIterations),
134 mIntegrationOrder(other.mIntegrationOrder),
135 mThreaded(other.mThreaded),
136 mInterrupter(other.mInterrupter)
143 bool earlyOut()
const {
return (mIntegrationOrder==0);}
150 void advect(PointListT& points,
float dt,
unsigned int advIterations = 1)
152 if (this->earlyOut())
return;
155 mAdvIterations = advIterations;
157 if (mInterrupter) mInterrupter->start(
"Advecting points by OpenVDB velocity field: ");
159 tbb::parallel_for(tbb::blocked_range<size_t>(0, mPoints->size()), *
this);
161 (*this)(tbb::blocked_range<size_t>(0, mPoints->size()));
163 if (mInterrupter) mInterrupter->end();
167 void operator() (
const tbb::blocked_range<size_t> &range)
const
169 if (mInterrupter && mInterrupter->wasInterrupted()) {
170 tbb::task::self().cancel_group_execution();
174 switch (mIntegrationOrder) {
177 for (
size_t n = range.begin(); n != range.end(); ++n) {
180 for (
unsigned int i = 0; i < mAdvIterations; ++i) {
181 velField.template rungeKutta<1>(mDt, X0);
188 for (
size_t n = range.begin(); n != range.end(); ++n) {
191 for (
unsigned int i = 0; i < mAdvIterations; ++i) {
192 velField.template rungeKutta<2>(mDt, X0);
199 for (
size_t n = range.begin(); n != range.end(); ++n) {
202 for (
unsigned int i = 0; i < mAdvIterations; ++i) {
203 velField.template rungeKutta<3>(mDt, X0);
210 for (
size_t n = range.begin(); n != range.end(); ++n) {
213 for (
unsigned int i = 0; i < mAdvIterations; ++i) {
214 velField.template rungeKutta<4>(mDt, X0);
224 const GridType* mVelGrid;
231 unsigned int mAdvIterations;
232 unsigned int mIntegrationOrder;
236 InterrupterType* mInterrupter;
242 typename PointListT = std::vector<typename GridT::ValueType>,
243 bool StaggeredVelocity =
false,
244 typename CptGridType = GridT,
256 const GridType& cptGrid,
int cptn, InterrupterType* interrupter =
nullptr):
260 mInterrupter(interrupter)
264 mVelGrid(other.mVelGrid),
265 mCptGrid(other.mCptGrid),
266 mCptIter(other.mCptIter),
267 mPoints(other.mPoints),
269 mAdvIterations(other.mAdvIterations),
270 mIntegrationOrder(other.mIntegrationOrder),
271 mThreaded(other.mThreaded),
272 mInterrupter(other.mInterrupter)
284 void advect(PointListT& points,
float dt,
unsigned int advIterations = 1)
289 if (mIntegrationOrder==0 && mCptIter == 0) {
292 (mIntegrationOrder>0) ? mAdvIterations = advIterations : mAdvIterations = 1;
294 if (mInterrupter) mInterrupter->start(
"Advecting points by OpenVDB velocity field: ");
295 const size_t N = mPoints->size();
298 tbb::parallel_for(tbb::blocked_range<size_t>(0, N), *
this);
300 (*this)(tbb::blocked_range<size_t>(0, N));
302 if (mInterrupter) mInterrupter->end();
307 void operator() (
const tbb::blocked_range<size_t> &range)
const
309 if (mInterrupter && mInterrupter->wasInterrupted()) {
310 tbb::task::self().cancel_group_execution();
315 switch (mIntegrationOrder) {
318 for (
size_t n = range.begin(); n != range.end(); ++n) {
320 for (
unsigned int i = 0; i < mAdvIterations; ++i) {
328 for (
size_t n = range.begin(); n != range.end(); ++n) {
330 for (
unsigned int i = 0; i < mAdvIterations; ++i) {
331 velField.template rungeKutta<1>(mDt, X0);
339 for (
size_t n = range.begin(); n != range.end(); ++n) {
341 for (
unsigned int i = 0; i < mAdvIterations; ++i) {
342 velField.template rungeKutta<2>(mDt, X0);
351 for (
size_t n = range.begin(); n != range.end(); ++n) {
353 for (
unsigned int i = 0; i < mAdvIterations; ++i) {
354 velField.template rungeKutta<3>(mDt, X0);
362 for (
size_t n = range.begin(); n != range.end(); ++n) {
364 for (
unsigned int i = 0; i < mAdvIterations; ++i) {
365 velField.template rungeKutta<4>(mDt, X0);
375 const GridType* mVelGrid;
376 const GridType* mCptGrid;
382 unsigned int mAdvIterations;
383 unsigned int mIntegrationOrder;
386 InterrupterType* mInterrupter;
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...
Vec3SGrid Vec3fGrid
Definition: openvdb.h:56
math::Vec3< Real > Vec3R
Definition: openvdb/Types.h:68
Definition: openvdb/Exceptions.h:13
Dummy NOOP interrupter class defining interface.
Definition: NullInterrupter.h:26
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h.in:116
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h.in:178