52 #ifndef OPENVDB_TOOLS_VELOCITY_FIELDS_HAS_BEEN_INCLUDED 53 #define OPENVDB_TOOLS_VELOCITY_FIELDS_HAS_BEEN_INCLUDED 55 #include <tbb/parallel_reduce.h> 56 #include <openvdb/Platform.h> 58 #include <openvdb/math/FiniteDifference.h> 59 #include <boost/math/constants/constants.hpp> 68 template <
typename VelGr
idT,
typename Interpolator = BoxSampler>
74 BOOST_STATIC_ASSERT(boost::is_floating_point<ValueType>::value);
77 : mAccessor(vel.tree())
78 , mTransform(&vel.transform())
84 : mAccessor(other.mAccessor.tree())
85 , mTransform(other.mTransform)
98 inline VectorType operator() (
const Vec3d& xyz, ValueType)
const 100 return Interpolator::sample(mAccessor, mTransform->worldToIndex(xyz));
107 inline VectorType operator() (
const Coord& ijk, ValueType)
const 109 return mAccessor.getValue(ijk);
113 const typename VelGridT::ConstAccessor mAccessor;
126 template <
typename ScalarT =
float>
132 BOOST_STATIC_ASSERT(boost::is_floating_point<ScalarT>::value);
143 inline VectorType operator() (
const Vec3d& xyz, ValueType time)
const;
146 inline VectorType operator() (
const Coord& ijk, ValueType time)
const 148 return (*
this)(ijk.asVec3d(), time);
152 template <
typename ScalarT>
156 const ScalarT pi = boost::math::constants::pi<ScalarT>();
157 const ScalarT phase = pi / ScalarT(3);
158 const ScalarT Px = pi * ScalarT(xyz[0]), Py = pi * ScalarT(xyz[1]), Pz = pi * ScalarT(xyz[2]);
159 const ScalarT tr =
math::Cos(ScalarT(time) * phase);
160 const ScalarT a =
math::Sin(ScalarT(2)*Py);
161 const ScalarT b = -
math::Sin(ScalarT(2)*Px);
162 const ScalarT c =
math::Sin(ScalarT(2)*Pz);
176 bool Staggered =
false,
187 mAcc(grid.getAccessor())
193 mAcc(mGrid->getAccessor())
203 template <
typename LocationType>
204 inline bool sample(
const LocationType& world, ValueType& result)
const 206 const Vec3R xyz = mGrid->worldToIndex(
Vec3R(world[0], world[1], world[2]));
216 template <
typename LocationType>
217 inline ValueType
sample(
const LocationType& world)
const 219 const Vec3R xyz = mGrid->worldToIndex(
Vec3R(world[0], world[1], world[2]));
238 bool Staggered =
false,
239 size_t SampleOrder = 1>
254 template<
size_t OrderRK,
typename LocationType>
255 inline void rungeKutta(
const ElementType dt, LocationType& world)
const 257 BOOST_STATIC_ASSERT(OrderRK <= 4);
258 VecType P(static_cast<ElementType>(world[0]),
259 static_cast<ElementType>(world[1]),
260 static_cast<ElementType>(world[2]));
264 }
else if (OrderRK == 1) {
266 mVelSampler.sample(P, V0);
268 }
else if (OrderRK == 2) {
270 mVelSampler.sample(P, V0);
271 mVelSampler.sample(P + ElementType(0.5) * dt * V0, V1);
273 }
else if (OrderRK == 3) {
275 mVelSampler.sample(P, V0);
276 mVelSampler.sample(P + ElementType(0.5) * dt * V0, V1);
277 mVelSampler.sample(P + dt * (ElementType(2.0) * V1 - V0), V2);
278 P = dt * (V0 + ElementType(4.0) * V1 + V2) * ElementType(1.0 / 6.0);
279 }
else if (OrderRK == 4) {
280 VecType V0, V1, V2, V3;
281 mVelSampler.sample(P, V0);
282 mVelSampler.sample(P + ElementType(0.5) * dt * V0, V1);
283 mVelSampler.sample(P + ElementType(0.5) * dt * V1, V2);
284 mVelSampler.sample(P + dt * V2, V3);
285 P = dt * (V0 + ElementType(2.0) * (V1 + V2) + V3) * ElementType(1.0 / 6.0);
287 typedef typename LocationType::ValueType OutType;
288 world += LocationType(static_cast<OutType>(P[0]),
289 static_cast<OutType>(P[1]),
290 static_cast<OutType>(P[2]));
301 #endif // OPENVDB_TOOLS_VELOCITY_FIELDS_HAS_BEEN_INCLUDED
float Sin(const float &x)
Return .
Definition: Math.h:682
Type Pow2(Type x)
Return .
Definition: Math.h:514
#define OPENVDB_VERSION_NAME
Definition: version.h:43
Vec3< double > Vec3d
Definition: Vec3.h:651
float Cos(const float &x)
Return .
Definition: Math.h:691
Definition: Exceptions.h:39
Vec3SGrid Vec3fGrid
Definition: openvdb.h:80
math::Vec3< Real > Vec3R
Definition: Types.h:76
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:71