59 #ifndef OPENVDB_TOOLS_RAYINTERSECTOR_HAS_BEEN_INCLUDED
60 #define OPENVDB_TOOLS_RAYINTERSECTOR_HAS_BEEN_INCLUDED
62 #include <openvdb/math/DDA.h>
63 #include <openvdb/math/Math.h>
64 #include <openvdb/math/Ray.h>
65 #include <openvdb/math/Stencils.h>
66 #include <openvdb/Grid.h>
67 #include <openvdb/Types.h>
69 #include <boost/utility.hpp>
70 #include <boost/type_traits/is_floating_point.hpp>
81 template<
typename Gr
idT,
int Iterations = 0,
typename RealT =
double>
105 template<
typename GridT,
107 int NodeLevel = GridT::TreeType::RootNodeType::ChildNodeType::LEVEL,
116 typedef typename GridT::ValueType
ValueT;
117 typedef typename GridT::TreeType
TreeT;
119 BOOST_STATIC_ASSERT( NodeLevel >= -1 && NodeLevel <
int(TreeT::DEPTH)-1);
120 BOOST_STATIC_ASSERT(boost::is_floating_point<ValueT>::value);
126 : mTester(grid, isoValue)
128 if (!grid.hasUniformVoxels() ) {
130 "LevelSetRayIntersector only supports uniform voxels!");
134 "LevelSetRayIntersector only supports level sets!"
135 "\nUse Grid::setGridClass(openvdb::GRID_LEVEL_SET)");
146 if (!mTester.setIndexRay(iRay))
return false;
156 if (!mTester.setIndexRay(iRay))
return false;
157 iTime = mTester.getIndexTime();
167 if (!mTester.setIndexRay(iRay))
return false;
169 mTester.getIndexPos(xyz);
181 if (!mTester.setIndexRay(iRay))
return false;
183 mTester.getIndexPos(xyz);
184 iTime = mTester.getIndexTime();
192 if (!mTester.setWorldRay(wRay))
return false;
202 if (!mTester.setWorldRay(wRay))
return false;
203 wTime = mTester.getWorldTime();
213 if (!mTester.setWorldRay(wRay))
return false;
215 mTester.getWorldPos(world);
227 if (!mTester.setWorldRay(wRay))
return false;
229 mTester.getWorldPos(world);
230 wTime = mTester.getWorldTime();
242 if (!mTester.setWorldRay(wRay))
return false;
244 mTester.getWorldPosAndNml(world, normal);
258 if (!mTester.setWorldRay(wRay))
return false;
260 mTester.getWorldPosAndNml(world, normal);
261 wTime = mTester.getWorldTime();
267 mutable SearchImplT mTester;
300 template<
typename GridT,
301 int NodeLevel = GridT::TreeType::RootNodeType::ChildNodeType::LEVEL,
309 typedef typename GridT::TreeType::RootNodeType
RootType;
312 BOOST_STATIC_ASSERT( NodeLevel >= 0 && NodeLevel <
int(TreeT::DEPTH)-1);
328 if (!grid.hasUniformVoxels() ) {
330 "VolumeRayIntersector only supports uniform voxels!");
332 if ( grid.empty() ) {
339 mTree->root().evalActiveBoundingBox(mBBox,
false);
341 mBBox.max().offset(1);
358 if (!grid.hasUniformVoxels() ) {
360 "VolumeRayIntersector only supports uniform voxels!");
362 if ( grid.empty() ) {
394 const bool hit = mRay.clip(mBBox);
395 if (hit) mTmax = mRay.t1();
412 return this->setIndexRay(wRay.worldToIndex(*mGrid));
415 inline typename RayT::TimeSpan
march()
417 const typename RayT::TimeSpan t = mHDDA.march(mRay, mAccessor);
435 const typename RayT::TimeSpan t = this->march();
440 inline void hits(std::vector<typename RayT::TimeSpan>& list)
442 mHDDA.hits(mRay, mAccessor, list);
455 return time*mGrid->transform().baseMap()->applyJacobian(mRay.dir()).length();
459 const GridT&
grid()
const {
return *mGrid; }
472 void print(std::ostream& os = std::cout,
int verboseLevel = 1)
474 if (verboseLevel>0) {
475 os <<
"BBox: " << mBBox << std::endl;
476 if (verboseLevel==2) {
478 }
else if (verboseLevel>2) {
488 const bool mIsMaster;
526 template<
typename Gr
idT,
int Iterations,
typename RealT>
527 class LinearSearchImpl
531 typedef typename GridT::ValueType
ValueT;
542 mMinValue(isoValue-2*grid.voxelSize()[0]),
543 mMaxValue(isoValue+2*grid.voxelSize()[0])
545 if ( grid.empty() ) {
548 if (mIsoValue<= -grid.background() ||
549 mIsoValue>= grid.background() ){
552 grid.tree().root().evalActiveBoundingBox(mBBox,
false);
564 return mRay.
clip(mBBox);
573 return mRay.
clip(mBBox);
582 inline void getWorldPos(
Vec3d& xyz)
const { xyz = mStencil.grid().indexToWorld(mRay(mTime)); }
589 this->getIndexPos(xyz);
590 mStencil.moveTo(xyz);
591 nml = mStencil.gradient(xyz);
593 xyz = mStencil.grid().indexToWorld(xyz);
602 return mTime*mStencil.grid().transform().baseMap()->applyJacobian(mRay.dir()).length();
609 inline void init(RealT t0)
612 mV[0] = this->interpValue(t0);
615 inline void setRange(RealT t0, RealT t1) { mRay.setTimes(t0, t1); }
618 inline const RayT& ray()
const {
return mRay; }
621 template <
typename NodeT>
622 inline bool hasNode(
const Coord& ijk)
624 return mStencil.accessor().template probeConstNode<NodeT>(ijk) != NULL;
632 inline bool operator()(
const Coord& ijk, RealT time)
635 if (mStencil.accessor().probeValue(ijk, V) &&
636 V>mMinValue && V<mMaxValue) {
638 mV[1] = this->interpValue(time);
640 mTime = this->interpTime();
642 for (
int n=0; Iterations>0 && n<Iterations; ++n) {
643 V = this->interpValue(mTime);
647 mTime = this->interpTime();
658 inline RealT interpTime()
661 return mT[0]+(mT[1]-mT[0])*mV[0]/(mV[0]-mV[1]);
664 inline RealT interpValue(RealT time)
666 const Vec3R pos = mRay(time);
667 mStencil.moveTo(pos);
668 return mStencil.interpolation(pos) - mIsoValue;
678 const ValueT mIsoValue, mMinValue, mMaxValue;
686 #endif // OPENVDB_TOOLS_RAYINTERSECTOR_HAS_BEEN_INCLUDED
Axis-aligned bounding box of signed integer coordinates.
Definition: Coord.h:229
bool isApproxLarger(const Type &a, const Type &b, const Type &tolerance)
Return true if a is larger than b to within the given tolerance, i.e., if b - a < tolerance...
Definition: Math.h:342
math::Vec3< Real > Vec3R
Definition: Types.h:75
bool ZeroCrossing(const Type &a, const Type &b)
Return true if the interval [a, b] includes zero, i.e., if either a or b is zero or if they have diff...
Definition: Math.h:645
bool clip(const Vec3T ¢er, RealT radius)
Return true if this ray intersects the specified sphere.
Definition: Ray.h:244
#define OPENVDB_THROW(exception, message)
Definition: Exceptions.h:97
Ray worldToIndex(const GridType &grid) const
Return a new ray in the index space of the specified grid, assuming the existing ray is represented i...
Definition: Ray.h:198
Delta for small floating-point offsets.
Definition: Math.h:123
Definition: Exceptions.h:88
Helper class that implements Hierarchical Digital Differential Analyzers and is specialized for ray i...
Definition: DDA.h:170
#define OPENVDB_VERSION_NAME
Definition: version.h:45
Vec3< double > Vec3d
Definition: Vec3.h:625
Definition: Exceptions.h:86
double Real
Definition: Types.h:63
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:67
Helper class that implements Hierarchical Digital Differential Analyzers for ray intersections agains...
Definition: DDA.h:209