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>
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);
54 namespace point_advect_internal {
56 enum IntegrationOrder {
57 INTEGRATION_ORDER_FWD_EULER = 1,
58 INTEGRATION_ORDER_RK_2ND,
59 INTEGRATION_ORDER_RK_3RD,
60 INTEGRATION_ORDER_RK_4TH
63 template <
typename VelGr
idT, Index IntegrationOrder,
bool Staggered,
typename FilterT>
64 class AdvectionDeformer
67 using IntegratorT = openvdb::tools::VelocityIntegrator<VelGridT, Staggered>;
69 AdvectionDeformer(
const VelGridT& velocityGrid,
const double timeStep,
const int steps,
71 : mIntegrator(velocityGrid)
76 template <
typename LeafT>
77 void reset(
const LeafT& leaf,
size_t )
82 template <
typename IndexIterT>
83 void apply(Vec3d&
position,
const IndexIterT& iter)
const
85 if (mFilter.valid(iter)) {
86 for (
int n = 0;
n < mSteps; ++
n) {
87 mIntegrator.template rungeKutta<IntegrationOrder, openvdb::Vec3d>(
88 static_cast<typename IntegratorT::ElementType
>(mTimeStep), position);
94 IntegratorT mIntegrator;
101 template <
typename Po
intDataGr
idT,
typename VelGr
idT,
typename AdvectFilterT,
typename FilterT>
104 using CachedDeformerT = CachedDeformer<double>;
106 AdvectionOp(PointDataGridT& points,
const VelGridT& velocity,
107 const Index integrationOrder,
const double timeStep,
const Index steps,
108 const AdvectFilterT& advectFilter,
111 , mVelocity(velocity)
112 , mIntegrationOrder(integrationOrder)
113 , mTimeStep(timeStep)
115 , mAdvectFilter(advectFilter)
116 , mFilter(filter) { }
120 mCachedDeformer.reset(
new CachedDeformerT(mCache));
130 template <
int IntegrationOrder,
bool Staggered>
131 void resolveIntegrationOrder(
bool buildCache)
133 const auto leaf = mPoints.constTree().cbeginLeaf();
137 if (!buildCache && mCachedDeformer) {
138 movePoints(mPoints, *mCachedDeformer, mFilter);
142 NullFilter nullFilter;
148 AdvectionDeformer<VelGridT, IntegrationOrder, Staggered, NullFilter> deformer(
149 mVelocity, mTimeStep, mSteps, nullFilter);
151 mCachedDeformer->evaluate(mPoints, deformer, nullFilter);
153 BinaryFilter<AdvectFilterT, FilterT,
true> binaryFilter(
154 mAdvectFilter, mFilter);
155 mCachedDeformer->evaluate(mPoints, deformer, binaryFilter);
161 AdvectionDeformer<VelGridT, IntegrationOrder, Staggered, NullFilter> deformer(
162 mVelocity, mTimeStep, mSteps, nullFilter);
166 AdvectionDeformer<VelGridT, IntegrationOrder, Staggered, AdvectFilterT> deformer(
167 mVelocity, mTimeStep, mSteps, mAdvectFilter);
173 template <
bool Staggered>
174 void resolveStaggered(
bool buildCache)
176 if (mIntegrationOrder == INTEGRATION_ORDER_FWD_EULER) {
177 resolveIntegrationOrder<1, Staggered>(buildCache);
178 }
else if (mIntegrationOrder == INTEGRATION_ORDER_RK_2ND) {
179 resolveIntegrationOrder<2, Staggered>(buildCache);
180 }
else if (mIntegrationOrder == INTEGRATION_ORDER_RK_3RD) {
181 resolveIntegrationOrder<3, Staggered>(buildCache);
182 }
else if (mIntegrationOrder == INTEGRATION_ORDER_RK_4TH) {
183 resolveIntegrationOrder<4, Staggered>(buildCache);
187 void operator()(
bool buildCache)
190 if (mPoints.constTree().leafCount() == 0)
return;
193 resolveStaggered<true>(buildCache);
195 resolveStaggered<false>(buildCache);
199 PointDataGridT& mPoints;
200 const VelGridT& mVelocity;
201 const Index mIntegrationOrder;
202 const double mTimeStep;
204 const AdvectFilterT& mAdvectFilter;
205 const FilterT& mFilter;
206 CachedDeformerT::Cache mCache;
207 std::unique_ptr<CachedDeformerT> mCachedDeformer;
217 template <
typename Po
intDataGr
idT,
typename VelGr
idT,
typename AdvectFilterT,
typename FilterT>
218 inline void advectPoints(PointDataGridT& points,
const VelGridT& velocity,
219 const Index integrationOrder,
const double timeStep,
const Index steps,
220 const AdvectFilterT& advectFilter,
224 using namespace point_advect_internal;
226 if (steps == 0)
return;
228 if (integrationOrder > 4) {
229 throw ValueError{
"Unknown integration order for advecting points."};
232 AdvectionOp<PointDataGridT, VelGridT, AdvectFilterT, FilterT> op(
233 points, velocity, integrationOrder, timeStep, steps,
234 advectFilter, filter);
239 if (cached) op.cache();
249 #endif // OPENVDB_POINTS_POINT_ADVECT_HAS_BEEN_INCLUDED
GLdouble GLdouble GLint GLint const GLdouble * points
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.
Point group manipulation in a VDB Point Grid.
#define OPENVDB_USE_VERSION_NAMESPACE
Defined various multi-threaded utility functions for trees.
void movePoints(PointDataGridT &points, const math::Transform &transform, DeformerT &deformer, const FilterT &filter, future::Advect *objectNotInUse, bool threaded)
Move points in a PointDataGrid using a custom deformer and a new transform.
Ability to move VDB Points using a custom deformer.
Defines two simple wrapper classes for advection velocity fields as well as VelocitySampler and Veloc...
Attribute Group access and filtering for iteration.
SIM_API const UT_StringHolder position
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Attribute-owned data structure for points. Point attributes are stored in leaf nodes and ordered by v...
GLint GLint GLint GLint GLint GLint GLint GLbitfield GLenum filter