37 #ifndef OPENVDB_POINTS_POINT_ADVECT_HAS_BEEN_INCLUDED 38 #define OPENVDB_POINTS_POINT_ADVECT_HAS_BEEN_INCLUDED 68 template <
typename PointDataGridT,
typename VelGridT,
69 typename AdvectFilterT = NullFilter,
typename FilterT = NullFilter>
70 inline void advectPoints(PointDataGridT& points,
const VelGridT& velocity,
71 const Index integrationOrder,
const double dt,
const Index timeSteps,
72 const AdvectFilterT& advectFilter = NullFilter(),
73 const FilterT& filter = NullFilter(),
74 const bool cached =
true);
80 namespace point_advect_internal {
89 template <
typename VelGr
idT, Index IntegrationOrder,
bool Staggered,
typename FilterT>
93 using IntegratorT = openvdb::tools::VelocityIntegrator<VelGridT, Staggered>;
96 const FilterT& filter)
97 : mIntegrator(velocityGrid)
100 , mFilter(filter) { }
102 template <
typename LeafT>
103 void reset(
const LeafT& leaf,
size_t )
108 template <
typename IndexIterT>
111 if (mFilter.valid(iter)) {
112 for (
int n = 0; n < mSteps; ++n) {
113 mIntegrator.template rungeKutta<IntegrationOrder, openvdb::Vec3d>(
114 static_cast<typename IntegratorT::ElementType>(mTimeStep), position);
120 IntegratorT mIntegrator;
127 template <
typename Po
intDataGr
idT,
typename VelGr
idT,
typename AdvectFilterT,
typename FilterT>
133 const Index integrationOrder,
const double timeStep,
const Index steps,
134 const AdvectFilterT& advectFilter,
135 const FilterT& filter)
137 , mVelocity(velocity)
138 , mIntegrationOrder(integrationOrder)
139 , mTimeStep(timeStep)
141 , mAdvectFilter(advectFilter)
142 , mFilter(filter) { }
156 template <
int IntegrationOrder,
bool Staggered>
157 void resolveIntegrationOrder(
bool buildCache)
159 const auto leaf = mPoints.constTree().cbeginLeaf();
163 if (!buildCache && mCachedDeformer) {
164 movePoints(mPoints, *mCachedDeformer, mFilter);
174 AdvectionDeformer<VelGridT, IntegrationOrder, Staggered, NullFilter> deformer(
175 mVelocity, mTimeStep, mSteps, nullFilter);
177 mCachedDeformer->evaluate(mPoints, deformer, nullFilter);
179 BinaryFilter<AdvectFilterT, FilterT,
true> binaryFilter(
180 mAdvectFilter, mFilter);
181 mCachedDeformer->evaluate(mPoints, deformer, binaryFilter);
187 AdvectionDeformer<VelGridT, IntegrationOrder, Staggered, NullFilter> deformer(
188 mVelocity, mTimeStep, mSteps, nullFilter);
192 AdvectionDeformer<VelGridT, IntegrationOrder, Staggered, AdvectFilterT> deformer(
193 mVelocity, mTimeStep, mSteps, mAdvectFilter);
199 template <
bool Staggered>
200 void resolveStaggered(
bool buildCache)
203 resolveIntegrationOrder<1, Staggered>(buildCache);
205 resolveIntegrationOrder<2, Staggered>(buildCache);
207 resolveIntegrationOrder<3, Staggered>(buildCache);
209 resolveIntegrationOrder<4, Staggered>(buildCache);
213 void operator()(
bool buildCache)
216 if (mPoints.constTree().leafCount() == 0)
return;
219 resolveStaggered<true>(buildCache);
221 resolveStaggered<false>(buildCache);
225 PointDataGridT& mPoints;
226 const VelGridT& mVelocity;
227 const Index mIntegrationOrder;
228 const double mTimeStep;
230 const AdvectFilterT& mAdvectFilter;
231 const FilterT& mFilter;
232 CachedDeformerT::Cache mCache;
233 std::unique_ptr<CachedDeformerT> mCachedDeformer;
242 template <
typename Po
intDataGr
idT,
typename VelGr
idT,
typename AdvectFilterT,
typename FilterT>
243 inline void advectPoints(PointDataGridT& points,
const VelGridT& velocity,
244 const Index integrationOrder,
const double timeStep,
const Index steps,
245 const AdvectFilterT& advectFilter,
246 const FilterT& filter,
249 using namespace point_advect_internal;
251 if (steps == 0)
return;
253 if (integrationOrder > 4) {
254 throw ValueError{
"Unknown integration order for advecting points."};
257 AdvectionOp<PointDataGridT, VelGridT, AdvectFilterT, FilterT> op(
258 points, velocity, integrationOrder, timeStep, steps,
259 advectFilter, filter);
264 if (cached) op.cache();
274 #endif // OPENVDB_POINTS_POINT_ADVECT_HAS_BEEN_INCLUDED A no-op filter that can be used when iterating over all indices.
Definition: IndexIterator.h:77
Attribute Group access and filtering for iteration.
Index32 Index
Definition: Types.h:61
Definition: points/PointAdvect.h:86
Defines two simple wrapper classes for advection velocity fields as well as VelocitySampler and Veloc...
void advect()
Definition: points/PointAdvect.h:150
void cache()
Definition: points/PointAdvect.h:144
Vec3< double > Vec3d
Definition: Vec3.h:679
Defined various multi-threaded utility functions for trees.
Point group manipulation in a VDB Point Grid.
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:817
Definition: points/PointAdvect.h:85
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h:136
Definition: points/PointAdvect.h:84
Definition: points/PointAdvect.h:128
Definition: Exceptions.h:40
IntegrationOrder
Definition: points/PointAdvect.h:82
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:243
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:132
Ability to move VDB Points using a custom deformer.
Definition: IndexIterator.h:70
Attribute-owned data structure for points. Point attributes are stored in leaf nodes and ordered by v...
Definition: Exceptions.h:92
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:188
Definition: points/PointAdvect.h:83