10 #ifndef OPENVDB_TOOLS_POINT_ADVECT_HAS_BEEN_INCLUDED 11 #define OPENVDB_TOOLS_POINT_ADVECT_HAS_BEEN_INCLUDED 18 #include <openvdb/thread/Threading.h> 22 #include <tbb/blocked_range.h> 23 #include <tbb/parallel_for.h> 36 template<
typename CptGr
idT = Vec3fGr
id>
50 mCptAccessor(cptGrid.getAccessor()),
55 mCptGrid(other.mCptGrid),
56 mCptAccessor(mCptGrid->getAccessor()),
57 mCptIterations(other.mCptIterations)
64 template <
typename LocationType>
72 for (
unsigned int i = 0; i < mCptIterations; ++i) {
73 const Vec3R location = mCptGrid->worldToIndex(
Vec3R(result[0], result[1], result[2]));
74 BoxSampler::sample<CptAccessor>(mCptAccessor, location, result);
84 unsigned int mCptIterations;
112 typename PointListT = std::vector<typename GridT::ValueType>,
113 bool StaggeredVelocity =
false,
123 PointAdvect(
const GridT& velGrid, InterrupterType* interrupter =
nullptr):
126 mIntegrationOrder(1),
128 mInterrupter(interrupter)
132 mVelGrid(other.mVelGrid),
133 mPoints(other.mPoints),
135 mAdvIterations(other.mAdvIterations),
136 mIntegrationOrder(other.mIntegrationOrder),
137 mThreaded(other.mThreaded),
138 mInterrupter(other.mInterrupter)
145 bool earlyOut()
const {
return (mIntegrationOrder==0);}
152 void advect(PointListT& points,
float dt,
unsigned int advIterations = 1)
154 if (this->earlyOut())
return;
157 mAdvIterations = advIterations;
159 if (mInterrupter) mInterrupter->start(
"Advecting points by OpenVDB velocity field: ");
161 tbb::parallel_for(tbb::blocked_range<size_t>(0, mPoints->size()), *
this);
163 (*this)(tbb::blocked_range<size_t>(0, mPoints->size()));
165 if (mInterrupter) mInterrupter->end();
169 void operator() (
const tbb::blocked_range<size_t> &range)
const 171 if (mInterrupter && mInterrupter->wasInterrupted()) {
172 thread::cancelGroupExecution();
176 switch (mIntegrationOrder) {
179 for (
size_t n = range.begin(); n != range.end(); ++n) {
182 for (
unsigned int i = 0; i < mAdvIterations; ++i) {
183 velField.template rungeKutta<1>(mDt, X0);
190 for (
size_t n = range.begin(); n != range.end(); ++n) {
193 for (
unsigned int i = 0; i < mAdvIterations; ++i) {
194 velField.template rungeKutta<2>(mDt, X0);
201 for (
size_t n = range.begin(); n != range.end(); ++n) {
204 for (
unsigned int i = 0; i < mAdvIterations; ++i) {
205 velField.template rungeKutta<3>(mDt, X0);
212 for (
size_t n = range.begin(); n != range.end(); ++n) {
215 for (
unsigned int i = 0; i < mAdvIterations; ++i) {
216 velField.template rungeKutta<4>(mDt, X0);
233 unsigned int mAdvIterations;
234 unsigned int mIntegrationOrder;
238 InterrupterType* mInterrupter;
244 typename PointListT = std::vector<typename GridT::ValueType>,
245 bool StaggeredVelocity =
false,
246 typename CptGridType = GridT,
258 const GridType& cptGrid,
int cptn, InterrupterType* interrupter =
nullptr):
262 mInterrupter(interrupter)
266 mVelGrid(other.mVelGrid),
267 mCptGrid(other.mCptGrid),
268 mCptIter(other.mCptIter),
269 mPoints(other.mPoints),
271 mAdvIterations(other.mAdvIterations),
272 mIntegrationOrder(other.mIntegrationOrder),
273 mThreaded(other.mThreaded),
274 mInterrupter(other.mInterrupter)
286 void advect(PointListT& points,
float dt,
unsigned int advIterations = 1)
291 if (mIntegrationOrder==0 && mCptIter == 0) {
294 (mIntegrationOrder>0) ? mAdvIterations = advIterations : mAdvIterations = 1;
296 if (mInterrupter) mInterrupter->start(
"Advecting points by OpenVDB velocity field: ");
297 const size_t N = mPoints->size();
300 tbb::parallel_for(tbb::blocked_range<size_t>(0, N), *
this);
302 (*this)(tbb::blocked_range<size_t>(0, N));
304 if (mInterrupter) mInterrupter->end();
309 void operator() (
const tbb::blocked_range<size_t> &range)
const 311 if (mInterrupter && mInterrupter->wasInterrupted()) {
312 thread::cancelGroupExecution();
317 switch (mIntegrationOrder) {
320 for (
size_t n = range.begin(); n != range.end(); ++n) {
322 for (
unsigned int i = 0; i < mAdvIterations; ++i) {
330 for (
size_t n = range.begin(); n != range.end(); ++n) {
332 for (
unsigned int i = 0; i < mAdvIterations; ++i) {
333 velField.template rungeKutta<1>(mDt, X0);
341 for (
size_t n = range.begin(); n != range.end(); ++n) {
343 for (
unsigned int i = 0; i < mAdvIterations; ++i) {
344 velField.template rungeKutta<2>(mDt, X0);
353 for (
size_t n = range.begin(); n != range.end(); ++n) {
355 for (
unsigned int i = 0; i < mAdvIterations; ++i) {
356 velField.template rungeKutta<3>(mDt, X0);
364 for (
size_t n = range.begin(); n != range.end(); ++n) {
366 for (
unsigned int i = 0; i < mAdvIterations; ++i) {
367 velField.template rungeKutta<4>(mDt, X0);
384 unsigned int mAdvIterations;
385 unsigned int mIntegrationOrder;
388 InterrupterType* mInterrupter;
395 #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...
Base class for interrupters.
Definition: NullInterrupter.h:25
Definition: Exceptions.h:13
Vec3SGrid Vec3fGrid
Definition: openvdb.h:85
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h.in:121
math::Vec3< Real > Vec3R
Definition: Types.h:72
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h.in:218