10 #ifndef OPENVDB_POINTS_POINT_ADVECT_HAS_BEEN_INCLUDED 11 #define OPENVDB_POINTS_POINT_ADVECT_HAS_BEEN_INCLUDED 41 template <
typename PointDataGridT,
typename VelGridT,
42 typename AdvectFilterT = NullFilter,
typename FilterT = NullFilter>
43 inline void advectPoints(PointDataGridT& points,
const VelGridT& velocity,
44 const Index integrationOrder,
const double dt,
const Index timeSteps,
45 const AdvectFilterT& advectFilter = NullFilter(),
46 const FilterT& filter = NullFilter(),
47 const bool cached =
true);
53 namespace point_advect_internal {
62 template <
typename VelGr
idT, Index IntegrationOrder,
bool Staggered,
typename FilterT>
66 using IntegratorT = openvdb::tools::VelocityIntegrator<VelGridT, Staggered>;
69 const FilterT& filter)
70 : mIntegrator(velocityGrid)
75 template <
typename LeafT>
76 void reset(
const LeafT& leaf,
size_t )
81 template <
typename IndexIterT>
82 void apply(
Vec3d& position,
const IndexIterT& iter)
const 84 if (mFilter.valid(iter)) {
85 for (
int n = 0; n < mSteps; ++n) {
86 mIntegrator.template rungeKutta<IntegrationOrder, openvdb::Vec3d>(
87 static_cast<typename IntegratorT::ElementType
>(mTimeStep), position);
93 IntegratorT mIntegrator;
100 template <
typename Po
intDataGr
idT,
typename VelGr
idT,
typename AdvectFilterT,
typename FilterT>
106 const Index integrationOrder,
const double timeStep,
const Index steps,
107 const AdvectFilterT& advectFilter,
108 const FilterT& filter)
110 , mVelocity(velocity)
111 , mIntegrationOrder(integrationOrder)
112 , mTimeStep(timeStep)
114 , mAdvectFilter(advectFilter)
115 , mFilter(filter) { }
129 template <
int IntegrationOrder,
bool Staggered>
130 void resolveIntegrationOrder(
bool buildCache)
132 const auto leaf = mPoints.constTree().cbeginLeaf();
136 if (!buildCache && mCachedDeformer) {
137 movePoints(mPoints, *mCachedDeformer, mFilter);
147 AdvectionDeformer<VelGridT, IntegrationOrder, Staggered, NullFilter> deformer(
148 mVelocity, mTimeStep, mSteps, nullFilter);
150 mCachedDeformer->evaluate(mPoints, deformer, nullFilter);
152 BinaryFilter<AdvectFilterT, FilterT,
true> binaryFilter(
153 mAdvectFilter, mFilter);
154 mCachedDeformer->evaluate(mPoints, deformer, binaryFilter);
160 AdvectionDeformer<VelGridT, IntegrationOrder, Staggered, NullFilter> deformer(
161 mVelocity, mTimeStep, mSteps, nullFilter);
165 AdvectionDeformer<VelGridT, IntegrationOrder, Staggered, AdvectFilterT> deformer(
166 mVelocity, mTimeStep, mSteps, mAdvectFilter);
172 template <
bool Staggered>
173 void resolveStaggered(
bool buildCache)
176 resolveIntegrationOrder<1, Staggered>(buildCache);
178 resolveIntegrationOrder<2, Staggered>(buildCache);
180 resolveIntegrationOrder<3, Staggered>(buildCache);
182 resolveIntegrationOrder<4, Staggered>(buildCache);
186 void operator()(
bool buildCache)
189 if (mPoints.constTree().leafCount() == 0)
return;
192 resolveStaggered<true>(buildCache);
194 resolveStaggered<false>(buildCache);
198 PointDataGridT& mPoints;
199 const VelGridT& mVelocity;
200 const Index mIntegrationOrder;
201 const double mTimeStep;
203 const AdvectFilterT& mAdvectFilter;
204 const FilterT& mFilter;
205 CachedDeformerT::Cache mCache;
206 std::unique_ptr<CachedDeformerT> mCachedDeformer;
215 template <
typename Po
intDataGr
idT,
typename VelGr
idT,
typename AdvectFilterT,
typename FilterT>
216 inline void advectPoints(PointDataGridT& points,
const VelGridT& velocity,
217 const Index integrationOrder,
const double timeStep,
const Index steps,
218 const AdvectFilterT& advectFilter,
219 const FilterT& filter,
222 using namespace point_advect_internal;
224 if (steps == 0)
return;
226 if (integrationOrder > 4) {
227 throw ValueError{
"Unknown integration order for advecting points."};
230 AdvectionOp<PointDataGridT, VelGridT, AdvectFilterT, FilterT> op(
231 points, velocity, integrationOrder, timeStep, steps,
232 advectFilter, filter);
237 if (cached) op.cache();
247 #endif // OPENVDB_POINTS_POINT_ADVECT_HAS_BEEN_INCLUDED A no-op filter that can be used when iterating over all indices.
Definition: IndexIterator.h:50
AdvectionOp(PointDataGridT &points, const VelGridT &velocity, const Index integrationOrder, const double timeStep, const Index steps, const AdvectFilterT &advectFilter, const FilterT &filter)
Definition: points/PointAdvect.h:105
Attribute Group access and filtering for iteration.
Defines two simple wrapper classes for advection velocity fields as well as VelocitySampler and Veloc...
Vec3< double > Vec3d
Definition: Vec3.h:662
void advectPoints(PointDataGridT &points, const VelGridT &velocity, const Index integrationOrder, const double dt, const Index timeSteps, const AdvectFilterT &advectFilter=NullFilter(), const FilterT &filter=NullFilter(), const bool cached=true)
Advect points in a PointDataGrid through a velocity grid.
Definition: points/PointAdvect.h:216
Definition: IndexIterator.h:43
Defined various multi-threaded utility functions for trees.
Point group manipulation in a VDB Point Grid.
Definition: Exceptions.h:65
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h:102
void advect()
Definition: points/PointAdvect.h:123
void cache()
Definition: points/PointAdvect.h:117
Definition: points/PointAdvect.h:101
Definition: Exceptions.h:13
IntegrationOrder
Definition: points/PointAdvect.h:55
Definition: points/PointAdvect.h:56
Index32 Index
Definition: Types.h:31
Ability to move VDB Points using a custom deformer.
Attribute-owned data structure for points. Point attributes are stored in leaf nodes and ordered by v...
Definition: points/PointAdvect.h:58
Definition: points/PointAdvect.h:59
Definition: points/PointAdvect.h:57
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:154
void movePoints(PointDataGridT &points, DeformerT &deformer, const FilterT &filter=NullFilter(), future::Advect *objectNotInUse=nullptr, bool threaded=true)
Move points in a PointDataGrid using a custom deformer.
Definition: PointMove.h:1090