59 #ifndef OPENVDB_TOOLS_RAYINTERSECTOR_HAS_BEEN_INCLUDED 60 #define OPENVDB_TOOLS_RAYINTERSECTOR_HAS_BEEN_INCLUDED 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)");
140 const ValueT&
getIsoValue()
const {
return mTester.getIsoValue(); }
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);
179 bool intersectsIS(
const RayType& iRay, Vec3Type& xyz, RealType &iTime)
const 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);
225 bool intersectsWS(
const RayType& wRay, Vec3Type& world, RealType &wTime)
const 227 if (!mTester.setWorldRay(wRay))
return false;
229 mTester.getWorldPos(world);
230 wTime = mTester.getWorldTime();
240 bool intersectsWS(
const RayType& wRay, Vec3Type& world, Vec3Type& normal)
const 242 if (!mTester.setWorldRay(wRay))
return false;
244 mTester.getWorldPosAndNml(world, normal);
256 bool intersectsWS(
const RayType& wRay, Vec3Type& world, Vec3Type& normal, RealType &wTime)
const 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);
436 inline bool march(RealType& t0, RealType& t1)
438 const typename RayT::TimeSpan t = this->march();
451 template <
typename ListType>
452 inline void hits(ListType& list)
454 mHDDA.hits(mRay, mAccessor, list);
467 return time*mGrid->transform().baseMap()->applyJacobian(mRay.dir()).length();
471 const GridT&
grid()
const {
return *mGrid; }
475 const TreeT&
tree()
const {
return *mTree; }
484 void print(std::ostream& os = std::cout,
int verboseLevel = 1)
486 if (verboseLevel>0) {
487 os <<
"BBox: " << mBBox << std::endl;
488 if (verboseLevel==2) {
490 }
else if (verboseLevel>2) {
500 const bool mIsMaster;
538 template<
typename Gr
idT,
int Iterations,
typename RealT>
544 typedef typename GridT::ValueType
ValueT;
554 mMinValue(isoValue - ValueT(2 * grid.voxelSize()[0])),
555 mMaxValue(isoValue + ValueT(2 * grid.voxelSize()[0]))
557 if ( grid.empty() ) {
560 if (mIsoValue<= -grid.background() ||
561 mIsoValue>= grid.background() ){
564 grid.tree().root().evalActiveBoundingBox(mBBox,
false);
576 return mRay.
clip(mBBox);
585 return mRay.
clip(mBBox);
594 inline void getWorldPos(VecT& xyz)
const { xyz = mStencil.grid().indexToWorld(mRay(mTime)); }
601 this->getIndexPos(xyz);
602 mStencil.moveTo(xyz);
603 nml = mStencil.gradient(xyz);
605 xyz = mStencil.grid().indexToWorld(xyz);
614 return mTime*mStencil.grid().transform().baseMap()->applyJacobian(mRay.dir()).length();
621 inline void init(RealT t0)
624 mV[0] =
static_cast<ValueT
>(this->interpValue(t0));
627 inline void setRange(RealT t0, RealT t1) { mRay.setTimes(t0, t1); }
630 inline const RayT& ray()
const {
return mRay; }
633 template <
typename NodeT>
634 inline bool hasNode(
const Coord& ijk)
636 return mStencil.accessor().template probeConstNode<NodeT>(ijk) != NULL;
644 inline bool operator()(
const Coord& ijk, RealT time)
647 if (mStencil.accessor().probeValue(ijk, V) &&
648 V>mMinValue && V<mMaxValue) {
650 mV[1] =
static_cast<ValueT
>(this->interpValue(time));
652 mTime = this->interpTime();
654 for (
int n=0; Iterations>0 && n<Iterations; ++n) {
655 V =
static_cast<ValueT
>(this->interpValue(mTime));
659 mTime = this->interpTime();
670 inline RealT interpTime()
673 return mT[0]+(mT[1]-mT[0])*mV[0]/(mV[0]-mV[1]);
676 inline RealT interpValue(RealT time)
678 const VecT pos = mRay(time);
679 mStencil.moveTo(pos);
680 return mStencil.interpolation(pos) - mIsoValue;
690 const ValueT mIsoValue, mMinValue, mMaxValue;
698 #endif // OPENVDB_TOOLS_RAYINTERSECTOR_HAS_BEEN_INCLUDED
General-purpose arithmetic and comparison routines, most of which accept arbitrary value types (or at...
Delta for small floating-point offsets.
Definition: Math.h:132
#define OPENVDB_THROW(exception, message)
Definition: Exceptions.h:97
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:398
Helper class that implements Hierarchical Digital Differential Analyzers and is specialized for ray i...
Definition: DDA.h:170
Signed (x, y, z) 32-bit integer coordinates.
Definition: Coord.h:47
Definition: ValueAccessor.h:219
#define OPENVDB_VERSION_NAME
Definition: version.h:43
bool clip(const Vec3T ¢er, RealT radius)
Return true if this ray intersects the specified sphere.
Definition: Ray.h:244
Definition: Exceptions.h:86
Implementation of morphological dilation and erosion.
Definition: Exceptions.h:39
bool normalize(T eps=T(1.0e-7))
this = normalized this
Definition: Vec3.h:348
Helper class that implements Hierarchical Digital Differential Analyzers for ray intersections agains...
Definition: DDA.h:213
Axis-aligned bounding box of signed integer coordinates.
Definition: Coord.h:259
Definition: Exceptions.h:88
Defines various finite difference stencils by means of the "curiously recurring template pattern" on ...
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:719
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:71
Digital Differential Analyzers specialized for VDB.
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