25 #ifndef OPENVDB_TOOLS_VELOCITY_FIELDS_HAS_BEEN_INCLUDED 26 #define OPENVDB_TOOLS_VELOCITY_FIELDS_HAS_BEEN_INCLUDED 28 #include <tbb/parallel_reduce.h> 41 template <
typename VelGr
idT,
typename Interpolator = BoxSampler>
48 "DiscreteField requires a floating point grid.");
51 : mAccessor(vel.tree())
52 , mTransform(&vel.transform())
58 : mAccessor(other.mAccessor.tree())
59 , mTransform(other.mTransform)
72 inline VectorType operator() (
const Vec3d& xyz, ValueType)
const 74 return Interpolator::sample(mAccessor, mTransform->worldToIndex(xyz));
81 inline VectorType operator() (
const Coord& ijk, ValueType)
const 83 return mAccessor.getValue(ijk);
87 const typename VelGridT::ConstAccessor mAccessor;
100 template <
typename ScalarT =
float>
107 "EnrightField requires a floating point grid.");
118 inline VectorType operator() (
const Vec3d& xyz, ValueType time)
const;
121 inline VectorType operator() (
const Coord& ijk, ValueType time)
const 123 return (*
this)(ijk.asVec3d(), time);
127 template <
typename ScalarT>
131 const ScalarT
pi = math::pi<ScalarT>();
132 const ScalarT phase = pi / ScalarT(3);
133 const ScalarT Px = pi * ScalarT(xyz[0]), Py = pi * ScalarT(xyz[1]), Pz = pi * ScalarT(xyz[2]);
134 const ScalarT tr =
math::Cos(ScalarT(time) * phase);
135 const ScalarT a =
math::Sin(ScalarT(2)*Py);
136 const ScalarT b = -
math::Sin(ScalarT(2)*Px);
137 const ScalarT c =
math::Sin(ScalarT(2)*Pz);
151 bool Staggered =
false,
162 mAcc(grid.getAccessor())
168 mAcc(mGrid->getAccessor())
178 template <
typename LocationType>
179 inline bool sample(
const LocationType& world, ValueType& result)
const 181 const Vec3R xyz = mGrid->worldToIndex(
Vec3R(world[0], world[1], world[2]));
191 template <
typename LocationType>
192 inline ValueType
sample(
const LocationType& world)
const 194 const Vec3R xyz = mGrid->worldToIndex(
Vec3R(world[0], world[1], world[2]));
213 bool Staggered =
false,
214 size_t SampleOrder = 1>
229 template<
size_t OrderRK,
typename LocationType>
230 inline void rungeKutta(
const ElementType dt, LocationType& world)
const 232 BOOST_STATIC_ASSERT(OrderRK <= 4);
233 VecType P(static_cast<ElementType>(world[0]),
234 static_cast<ElementType>(world[1]),
235 static_cast<ElementType>(world[2]));
239 }
else if (OrderRK == 1) {
241 mVelSampler.sample(P, V0);
243 }
else if (OrderRK == 2) {
245 mVelSampler.sample(P, V0);
246 mVelSampler.sample(P + ElementType(0.5) * dt * V0, V1);
248 }
else if (OrderRK == 3) {
250 mVelSampler.sample(P, V0);
251 mVelSampler.sample(P + ElementType(0.5) * dt * V0, V1);
252 mVelSampler.sample(P + dt * (ElementType(2.0) * V1 - V0), V2);
253 P = dt * (V0 + ElementType(4.0) * V1 + V2) * ElementType(1.0 / 6.0);
254 }
else if (OrderRK == 4) {
255 VecType V0, V1, V2, V3;
256 mVelSampler.sample(P, V0);
257 mVelSampler.sample(P + ElementType(0.5) * dt * V0, V1);
258 mVelSampler.sample(P + ElementType(0.5) * dt * V1, V2);
259 mVelSampler.sample(P + dt * V2, V3);
260 P = dt * (V0 + ElementType(2.0) * (V1 + V2) + V3) * ElementType(1.0 / 6.0);
262 typedef typename LocationType::ValueType OutType;
263 world += LocationType(static_cast<OutType>(P[0]),
264 static_cast<OutType>(P[1]),
265 static_cast<OutType>(P[2]));
276 #endif // OPENVDB_TOOLS_VELOCITY_FIELDS_HAS_BEEN_INCLUDED
Vec3SGrid Vec3fGrid
Definition: openvdb.h:54
float Cos(const float &x)
Return cos x.
Definition: Math.h:728
math::Vec3< Real > Vec3R
Definition: Types.h:72
Definition: Exceptions.h:13
ValueT value
Definition: GridBuilder.h:1287
constexpr T pi()
Pi constant taken from Boost to match old behaviour.
Definition: Math.h:118
float Sin(const float &x)
Return sin x.
Definition: Math.h:719
Type Pow2(Type x)
Return x2.
Definition: Math.h:551
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h.in:116
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h.in:202