10 #ifndef NANOVDB_RAY_H_HAS_BEEN_INCLUDED    11 #define NANOVDB_RAY_H_HAS_BEEN_INCLUDED    17 template<
typename RealT>
    69         , mInvDir(1 / mDir[0], 1 / mDir[1], 1 / mDir[2])
    71         , mSign{mInvDir[0] < 0, mInvDir[1] < 0, mInvDir[2] < 0}
    92         mInvDir[0] = 1.0 / mDir[0];
    93         mInvDir[1] = 1.0 / mDir[1];
    94         mInvDir[2] = 1.0 / mDir[2];
    95         mSign[0] = mInvDir[0] < 0;
    96         mSign[1] = mInvDir[1] < 0;
    97         mSign[2] = mInvDir[2] < 0;
   117         assert(t0 > 0 && t1 > 0);
   118         mTimeSpan.set(t0, t1);
   124         mTimeSpan.scale(scale);
   156         return Vec3T(fmaf(time, mDir[0], mEye[0]),
   157                      fmaf(time, mDir[1], mEye[1]),
   158                      fmaf(time, mDir[2], mEye[2]));
   160         return mEye + mDir * time;
   188     template<
typename MapType>
   191         const Vec3T eye = map.applyMap(mEye);
   192         const Vec3T dir = map.applyJacobian(mDir);
   193         const RealT length = dir.
length(), invLength = RealT(1) / length;
   194         RealT       t1 = mTimeSpan.t1;
   198         return Ray(eye, dir * invLength, length * mTimeSpan.t0, t1);
   200     template<
typename MapType>
   203         const Vec3T eye = map.applyMapF(mEye);
   204         const Vec3T dir = map.applyJacobianF(mDir);
   205         const RealT length = dir.
length(), invLength = RealT(1) / length;
   206         RealT       t1 = mTimeSpan.t1;
   210         return Ray(eye, dir * invLength, length * mTimeSpan.t0, t1);
   222     template<
typename MapType>
   225         const Vec3T eye = map.applyInverseMap(mEye);
   226         const Vec3T dir = map.applyInverseJacobian(mDir);
   227         const RealT length = dir.
length(), invLength = RealT(1) / length;
   228         return Ray(eye, dir * invLength, length * mTimeSpan.t0, length * mTimeSpan.t1);
   230     template<
typename MapType>
   233         const Vec3T eye = map.applyInverseMapF(mEye);
   234         const Vec3T dir = map.applyInverseJacobianF(mDir);
   235         const RealT length = dir.
length(), invLength = RealT(1) / length;
   236         return Ray(eye, dir * invLength, length * mTimeSpan.t0, length * mTimeSpan.t1);
   241     template<
typename Gr
idType>
   244         const Vec3T eye = grid.indexToWorldF(mEye);
   245         const Vec3T dir = grid.indexToWorldDirF(mDir);
   246         const RealT length = dir.
length(), invLength = RealT(1) / length;
   247         RealT       t1 = mTimeSpan.t1;
   251         return Ray(eye, dir * invLength, length * mTimeSpan.t0, t1);
   256     template<
typename Gr
idType>
   259         const Vec3T eye = grid.worldToIndexF(mEye);
   260         const Vec3T dir = grid.worldToIndexDirF(mDir);
   261         const RealT length = dir.
length(), invLength = RealT(1) / length;
   262         RealT       t1 = mTimeSpan.t1;
   266         return Ray(eye, dir * invLength, length * mTimeSpan.t0, t1);
   280         const Vec3T origin = mEye - center;
   282         const RealT B = 2 * mDir.dot(origin);
   283         const RealT C = origin.
lengthSqr() - radius * radius;
   284         const RealT D = B * B - 4 * A * C;
   289         const RealT Q = RealT(-0.5) * (B < 0 ? (B + 
Sqrt(D)) : (B - 
Sqrt(D)));
   299         if (t0 < mTimeSpan.t0) {
   302         if (t1 > mTimeSpan.t1) {
   315         return this->
intersects(center, radius, t0, t1) > 0;
   327         const bool hit = this->
intersects(center, radius, t0, t1);
   329             mTimeSpan.set(t0, t1);
   342     template<
typename BBoxT>
   345         t0       = (bbox[  mSign[0]][0] - mEye[0]) * mInvDir[0];
   346         RealT t2 = (bbox[1-mSign[1]][1] - mEye[1]) * mInvDir[1];
   347         if (t0 > t2) 
return false;
   348         t1       = (bbox[1-mSign[0]][0] - mEye[0]) * mInvDir[0];
   349         RealT t3 = (bbox[  mSign[1]][1] - mEye[1]) * mInvDir[1];
   350         if (t3 > t1) 
return false;
   351         if (t3 > t0) t0 = t3;
   352         if (t2 < t1) t1 = t2;
   353         t3 = (bbox[  mSign[2]][2] - mEye[2]) * mInvDir[2];
   354         if (t3 > t1) 
return false;
   355         t2 = (bbox[1-mSign[2]][2] - mEye[2]) * mInvDir[2];
   356         if (t0 > t2) 
return false;
   357         if (t3 > t0) t0 = t3;
   358         if (mTimeSpan.t1 < t0) 
return false;
   359         if (t2 < t1) t1 = t2;
   360         if (mTimeSpan.t0 > t1) 
return false;
   361         if (mTimeSpan.t0 > t0) t0 = mTimeSpan.t0;
   362         if (mTimeSpan.t1 < t1) t1 = mTimeSpan.t1;
   399         mTimeSpan.get(t0, t1);
   400         for (
int i = 0; i < 3; ++i) {
   401             RealT a = RealT(bbox.min()[i]), b = RealT(bbox.max()[i] + 1);
   405             a = (a - mEye[i]) * mInvDir[i];
   406             b = (b - mEye[i]) * mInvDir[i];
   427     template<
typename OtherVec3T>
   431         mTimeSpan.get(t0, t1);
   432         for (
int i = 0; i < 3; ++i) {
   433             RealT a = RealT(bbox.min()[i]), b = RealT(bbox.max()[i]);
   437             a = (a - mEye[i]) * mInvDir[i];
   438             b = (b - mEye[i]) * mInvDir[i];
   466     template<
typename BBoxT>
   475         RealT t0 = (bbox[mSign[0]][0] - mEye[0]) * mInvDir[0];
   476         RealT t2 = (bbox[1 - mSign[1]][1] - mEye[1]) * mInvDir[1];
   479         RealT t1 = (bbox[1 - mSign[0]][0] - mEye[0]) * mInvDir[0];
   480         RealT t3 = (bbox[mSign[1]][1] - mEye[1]) * mInvDir[1];
   487         t3 = (bbox[mSign[2]][2] - mEye[2]) * mInvDir[2];
   490         t2 = (bbox[1 - mSign[2]][2] - mEye[2]) * mInvDir[2];
   511     template<
typename BBoxT>
   515         const bool hit = this->
intersects(bbox, t0, t1);
   517             mTimeSpan.set(t0, t1);
   530         const RealT cosAngle = mDir.dot(normal);
   534         t = (distance - mEye.dot(normal)) / cosAngle;
   535         return this->
test(t);
   550     Vec3T    mEye, mDir, mInvDir;
   557 #endif // NANOVDB_RAY_HAS_BEEN_INCLUDED __hostdev__ Vec3T start() const 
Return the starting point of the ray. 
Definition: Ray.h:165
 
RealT t0
Definition: Ray.h:27
 
T lengthSqr() const 
Definition: NanoVDB.h:1089
 
__hostdev__ bool intersects(const Vec3T ¢er, RealT radius) const 
Return true if this ray intersects the specified sphere. 
Definition: Ray.h:312
 
Vec3Type Vec3T
Definition: Ray.h:23
 
__hostdev__ const Vec3T & dir() const 
Definition: Ray.h:142
 
__hostdev__ bool intersects(const Vec3T &normal, RealT distance, RealT &t) const 
Return true if the Ray intersects the plane specified by a normal and distance from the origin...
Definition: Ray.h:528
 
__hostdev__ RealT t0() const 
Definition: Ray.h:146
 
__hostdev__ Ray applyMapF(const MapType &map) const 
Definition: Ray.h:201
 
__hostdev__ bool intersects(const Vec3T ¢er, RealT radius, RealT &t0, RealT &t1) const 
Return true if this ray intersects the specified sphere. 
Definition: Ray.h:278
 
__hostdev__ Ray applyInverseMapF(const MapType &map) const 
Definition: Ray.h:231
 
__hostdev__ Ray & setMaxTime(RealT t1)
Definition: Ray.h:107
 
__hostdev__ Ray & setEye(const Vec3Type &eye)
Definition: Ray.h:83
 
__hostdev__ bool test(RealT time) const 
Return true if time is within t0 and t1, both inclusive. 
Definition: Ray.h:177
 
__hostdev__ Vec3T mid() const 
Return the midpoint of the ray. 
Definition: Ray.h:171
 
__hostdev__ bool test(RealT t) const 
Return true if time is inclusive. 
Definition: Ray.h:60
 
__hostdev__ Vec3T end() const 
Return the endpoint of the ray. 
Definition: Ray.h:168
 
RealT RealType
Definition: Ray.h:21
 
__hostdev__ const Vec3T & eye() const 
Definition: Ray.h:140
 
Implements a light-weight self-contained VDB data-structure in a single file! In other words...
 
Definition: NanoVDB.h:184
 
__hostdev__ Ray(const Vec3Type &eye=Vec3Type(0, 0, 0), const Vec3Type &direction=Vec3Type(1, 0, 0), RealT t0=Delta< RealT >::value(), RealT t1=Maximum< RealT >::value())
Definition: Ray.h:63
 
__hostdev__ Ray applyMap(const MapType &map) const 
Return a new Ray that is transformed with the specified map. 
Definition: Ray.h:189
 
__hostdev__ const Vec3T & invDir() const 
Definition: Ray.h:144
 
A simple vector class with three double components, similar to openvdb::math::Vec3. 
Definition: NanoVDB.h:856
 
__hostdev__ RealT t1() const 
Definition: Ray.h:148
 
__hostdev__ bool intersects(const BBox< OtherVec3T > &bbox, RealT &t0, RealT &t1) const 
Returns true if this ray intersects a floating-point bounding box. If the return value is true t0 and...
Definition: Ray.h:428
 
T length() const 
Definition: NanoVDB.h:1093
 
__hostdev__ Ray worldToIndexF(const GridType &grid) const 
Return a new ray in index space, assuming the existing ray is represented in the world space of the s...
Definition: Ray.h:257
 
Delta for small floating-point offsets. 
Definition: NanoVDB.h:597
 
__hostdev__ Vec3T operator()(RealT time) const 
Return the position along the ray at the specified time. 
Definition: Ray.h:153
 
Vec3< RealT > Vec3Type
Definition: Ray.h:22
 
bool isApproxZero(const Type &x)
Definition: NanoVDB.h:645
 
__hostdev__ RealT mid() const 
Return the midpoint of the ray. 
Definition: Ray.h:51
 
__hostdev__ TimeSpan()
Default constructor. 
Definition: Ray.h:29
 
__hostdev__ Ray & setDir(const Vec3Type &dir)
Definition: Ray.h:89
 
__hostdev__ bool intersects(const Vec3T &normal, const Vec3T &point, RealT &t) const 
Return true if the Ray intersects the plane specified by a normal and point. 
Definition: Ray.h:544
 
__hostdev__ bool clip(const BBoxT &bbox)
Return true if this ray intersects the specified bounding box. 
Definition: Ray.h:512
 
__hostdev__ int sign(int i) const 
Definition: Ray.h:150
 
__hostdev__ bool valid(RealT eps=Delta< float >::value()) const 
Return true if t1 is larger than t0 by at least eps. 
Definition: Ray.h:174
 
__hostdev__ Ray & offsetEye(RealT offset)
Definition: Ray.h:75
 
__hostdev__ bool intersects(const BBoxT &bbox) const 
Return true if this ray intersects the specified bounding box. 
Definition: Ray.h:467
 
__hostdev__ Ray & reset(const Vec3Type &eye, const Vec3Type &direction, RealT t0=Delta< RealT >::value(), RealT t1=Maximum< RealT >::value())
Definition: Ray.h:128
 
Maximum floating-point values. 
Definition: NanoVDB.h:613
 
T dot(const Vec3T &v) const 
Definition: NanoVDB.h:1081
 
GridType
List of types that are currently supported by NanoVDB. 
Definition: NanoVDB.h:216
 
__hostdev__ Ray indexToWorldF(const GridType &grid) const 
Return a new ray in world space, assuming the existing ray is represented in the index space of the s...
Definition: Ray.h:242
 
RealT t1
Definition: Ray.h:27
 
float Sqrt(float x)
Return the square root of a floating-point value. 
Definition: NanoVDB.h:795
 
__hostdev__ bool valid(RealT eps=Delta< RealT >::value()) const 
Return true if t1 is larger than t0 by at least eps. 
Definition: Ray.h:49
 
__hostdev__ Ray & setTimes(RealT t0=Delta< RealT >::value(), RealT t1=Maximum< RealT >::value())
Definition: Ray.h:113
 
__hostdev__ void scale(RealT s)
Multiplies both times. 
Definition: Ray.h:53
 
__hostdev__ Ray & scaleTimes(RealT scale)
Definition: Ray.h:122
 
__hostdev__ Ray applyInverseMap(const MapType &map) const 
Return a new Ray that is transformed with the inverse of the specified map. 
Definition: Ray.h:223
 
__hostdev__ Ray & setMinTime(RealT t0)
Definition: Ray.h:101
 
#define __hostdev__
Definition: NanoVDB.h:168
 
__hostdev__ TimeSpan(RealT _t0, RealT _t1)
Constructor. 
Definition: Ray.h:31
 
C++11 implementation of std::is_floating_point. 
Definition: NanoVDB.h:355
 
__hostdev__ bool intersects(const CoordBBox &bbox, RealT &t0, RealT &t1) const 
Returns true if this ray intersects an index bounding box. If the return value is true t0 and t1 are ...
Definition: Ray.h:397
 
__hostdev__ bool clip(const Vec3T ¢er, RealT radius)
Return true if this ray intersects the specified sphere. 
Definition: Ray.h:324