37 #ifndef OPENVDB_MATH_DDA_HAS_BEEN_INCLUDED 38 #define OPENVDB_MATH_DDA_HAS_BEEN_INCLUDED 46 #include <boost/mpl/at.hpp> 61 template<
typename RayT, Index Log2Dim = 0>
73 DDA(
const RayT& ray) { this->init(ray); }
75 DDA(
const RayT& ray,
RealT startTime) { this->init(ray, startTime); }
77 DDA(
const RayT& ray,
RealT startTime,
RealT maxTime) { this->init(ray, startTime, maxTime); }
81 assert(startTime <= maxTime);
82 static const int DIM = 1 << Log2Dim;
85 const Vec3T &pos = ray(mT0), &dir = ray.dir(), &inv = ray.invDir();
87 for (
int axis = 0; axis < 3; ++axis) {
92 }
else if (inv[axis] > 0) {
94 mNext[axis] = mT0 + (mVoxel[axis] + DIM - pos[axis]) * inv[axis];
95 mDelta[axis] = mStep[axis] * inv[axis];
98 mNext[axis] = mT0 + (mVoxel[axis] - pos[axis]) * inv[axis];
99 mDelta[axis] = mStep[axis] * inv[axis];
104 inline void init(
const RayT& ray) { this->
init(ray, ray.t0(), ray.t1()); }
106 inline void init(
const RayT& ray,
RealT startTime) { this->
init(ray, startTime, ray.t1()); }
113 mT0 = mNext[stepAxis];
114 mNext[stepAxis] += mDelta[stepAxis];
115 mVoxel[stepAxis] += mStep[stepAxis];
143 void print(std::ostream& os = std::cout)
const 145 os <<
"Dim=" << (1<<Log2Dim) <<
" time=" << mT0 <<
" next()=" 146 << this->next() <<
" voxel=" << mVoxel <<
" next=" << mNext
147 <<
" delta=" << mDelta <<
" step=" << mStep << std::endl;
158 template<
typename RayT, Index Log2Dim>
161 os <<
"Dim=" << (1<<Log2Dim) <<
" time=" << dda.
time()
162 <<
" next()=" << dda.
next() <<
" voxel=" << dda.
voxel();
171 template<
typename TreeT,
int NodeLevel>
174 typedef typename TreeT::RootNodeType::NodeChainType
ChainT;
175 typedef typename boost::mpl::at<ChainT, boost::mpl::int_<NodeLevel> >::type
NodeT;
177 template <
typename TesterT>
178 static bool test(TesterT& tester)
182 if (tester.template hasNode<NodeT>(dda.voxel())) {
183 tester.setRange(dda.time(), dda.next());
193 template<
typename TreeT>
196 template <
typename TesterT>
197 static bool test(TesterT& tester)
200 tester.
init(dda.time());
201 do {
if (tester(dda.voxel(), dda.next()))
return true; }
while(dda.step());
214 template <
typename TreeT,
typename RayT,
int ChildNodeLevel>
219 typedef typename TreeT::RootNodeType::NodeChainType
ChainT;
220 typedef typename boost::mpl::at<ChainT, boost::mpl::int_<ChildNodeLevel> >::type
NodeT;
225 template <
typename AccessorT>
229 if (ray.valid()) this->march(ray, acc, t);
237 template <
typename AccessorT,
typename ListT>
238 void hits(RayT& ray, AccessorT &acc, ListT& times)
242 this->hits(ray, acc, times, t);
243 if (t.valid()) times.push_back(t);
250 template <
typename AccessorT>
251 bool march(RayT& ray, AccessorT &acc,
TimeSpanT& t)
255 if (acc.template probeConstNode<NodeT>(mDDA.voxel()) != NULL) {
256 ray.setTimes(mDDA.time(), mDDA.next());
257 if (mHDDA.march(ray, acc, t))
return true;
258 }
else if (acc.isValueOn(mDDA.voxel())) {
259 if (t.t0<0) t.t0 = mDDA.time();
260 }
else if (t.t0>=0) {
262 if (t.valid())
return true;
265 }
while (mDDA.step());
266 if (t.t0>=0) t.t1 = mDDA.maxTime();
274 template <
typename AccessorT,
typename ListT>
275 void hits(RayT& ray, AccessorT &acc, ListT& times, TimeSpanT& t)
279 if (acc.template probeConstNode<NodeT>(mDDA.voxel()) != NULL) {
280 ray.setTimes(mDDA.time(), mDDA.next());
281 mHDDA.
hits(ray, acc, times, t);
282 }
else if (acc.isValueOn(mDDA.voxel())) {
283 if (t.t0<0) t.t0 = mDDA.time();
284 }
else if (t.t0>=0) {
286 if (t.valid()) times.push_back(t);
289 }
while (mDDA.step());
290 if (t.t0>=0) t.t1 = mDDA.maxTime();
293 math::DDA<RayT, NodeT::TOTAL> mDDA;
294 VolumeHDDA<TreeT, RayT, ChildNodeLevel-1> mHDDA;
299 template <
typename TreeT,
typename RayT>
304 typedef typename TreeT::LeafNodeType
LeafT;
309 template <
typename AccessorT>
313 if (ray.valid()) this->march(ray, acc, t);
317 template <
typename AccessorT,
typename ListT>
318 void hits(RayT& ray, AccessorT &acc, ListT& times)
322 this->hits(ray, acc, times, t);
323 if (t.valid()) times.push_back(t);
330 template <
typename AccessorT>
331 bool march(RayT& ray, AccessorT &acc,
TimeSpanT& t)
335 if (acc.template probeConstNode<LeafT>(mDDA.voxel()) ||
336 acc.isValueOn(mDDA.voxel())) {
337 if (t.t0<0) t.t0 = mDDA.time();
338 }
else if (t.t0>=0) {
340 if (t.valid())
return true;
343 }
while (mDDA.step());
344 if (t.t0>=0) t.t1 = mDDA.maxTime();
348 template <
typename AccessorT,
typename ListT>
349 void hits(RayT& ray, AccessorT &acc, ListT& times, TimeSpanT& t)
353 if (acc.template probeConstNode<LeafT>(mDDA.voxel()) ||
354 acc.isValueOn(mDDA.voxel())) {
355 if (t.t0<0) t.t0 = mDDA.time();
356 }
else if (t.t0>=0) {
358 if (t.valid()) times.push_back(t);
361 }
while (mDDA.step());
362 if (t.t0>=0) t.t1 = mDDA.maxTime();
364 math::DDA<RayT, LeafT::TOTAL> mDDA;
371 #endif // OPENVDB_MATH_DDA_HAS_BEEN_INCLUDED RealType next() const
Return the time (parameterized along the Ray) of the second (i.e. next) hit of a tree node of size 2^...
Definition: DDA.h:139
RealType RealT
Definition: DDA.h:66
boost::mpl::at< ChainT, boost::mpl::int_< NodeLevel > >::type NodeT
Definition: DDA.h:175
TreeT::RootNodeType::NodeChainType ChainT
Definition: DDA.h:219
General-purpose arithmetic and comparison routines, most of which accept arbitrary value types (or at...
TimeSpanT march(RayT &ray, AccessorT &acc)
Definition: DDA.h:226
VolumeHDDA()
Definition: DDA.h:223
static Coord floor(const Vec3< T > &xyz)
Return the largest integer coordinates that are not greater than xyz (node centered conversion).
Definition: Coord.h:83
DDA(const RayT &ray, RealT startTime)
Definition: DDA.h:75
const Type & Min(const Type &a, const Type &b)
Return the minimum of two values.
Definition: Math.h:610
RayT::RealType RealType
Definition: DDA.h:65
void init(const RayT &ray, RealT startTime, RealT maxTime)
Definition: DDA.h:79
TreeT::RootNodeType::NodeChainType ChainT
Definition: DDA.h:174
size_t MinIndex(const Vec3T &v)
Return the index [0,1,2] of the smallest value in a 3D vector.
Definition: Math.h:890
TreeT::LeafNodeType LeafT
Definition: DDA.h:304
VolumeHDDA()
Definition: DDA.h:307
Signed (x, y, z) 32-bit integer coordinates.
Definition: Coord.h:51
boost::mpl::at< ChainT, boost::mpl::int_< ChildNodeLevel > >::type NodeT
Definition: DDA.h:220
RayT::Vec3Type Vec3Type
Definition: DDA.h:67
static bool test(TesterT &tester)
Definition: DDA.h:178
A Digital Differential Analyzer specialized for OpenVDB grids.
Definition: DDA.h:62
DDA()
uninitialized constructor
Definition: DDA.h:71
RealType time() const
Return the time (parameterized along the Ray) of the first hit of a tree node of size 2^Log2Dim.
Definition: DDA.h:131
void hits(RayT &ray, AccessorT &acc, ListT ×)
Definition: DDA.h:318
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h:136
bool isZero(const Type &x)
Return true if x is exactly equal to zero.
Definition: Math.h:308
RealType maxTime() const
Return the maximum time (parameterized along the Ray).
Definition: DDA.h:134
const Coord & voxel() const
Return the index coordinates of the next node or voxel intersected by the ray. If Log2Dim = 0 the ret...
Definition: DDA.h:124
void print(std::ostream &os=std::cout) const
Print information about this DDA for debugging.
Definition: DDA.h:143
TimeSpanT march(RayT &ray, AccessorT &acc)
Definition: DDA.h:310
void init(const RayT &ray, RealT startTime)
Definition: DDA.h:106
Definition: Exceptions.h:40
DDA(const RayT &ray)
Definition: DDA.h:73
RayT::TimeSpan TimeSpanT
Definition: DDA.h:305
RayT::TimeSpan TimeSpanT
Definition: DDA.h:221
Helper class that implements Hierarchical Digital Differential Analyzers and is specialized for ray i...
Definition: DDA.h:172
static bool test(TesterT &tester)
Definition: DDA.h:197
std::ostream & operator<<(std::ostream &os, const DDA< RayT, Log2Dim > &dda)
Output streaming of the Ray class.
Definition: DDA.h:159
bool step()
Increment the voxel index to next intersected voxel or node and returns true if the step in time does...
Definition: DDA.h:110
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:188
Helper class that implements Hierarchical Digital Differential Analyzers for ray intersections agains...
Definition: DDA.h:215
void hits(RayT &ray, AccessorT &acc, ListT ×)
Definition: DDA.h:238
DDA(const RayT &ray, RealT startTime, RealT maxTime)
Definition: DDA.h:77
Vec3Type Vec3T
Definition: DDA.h:68
void init(const RayT &ray)
Definition: DDA.h:104