10 #ifndef OPENVDB_MATH_RAY_HAS_BEEN_INCLUDED
11 #define OPENVDB_MATH_RAY_HAS_BEEN_INCLUDED
26 template<
typename RealT =
double>
31 "math::Ray requires a floating-point value type");
44 inline void set(RealT _t0, RealT _t1) {
t0=_t0;
t1=_t1; }
46 inline void get(RealT& _t0, RealT& _t1)
const { _t0=
t0; _t1=
t1; }
50 inline RealT
mid()
const {
return 0.5*(
t0 +
t1); }
54 inline bool test(RealT
t)
const {
return (t>=
t0 && t<=
t1); }
104 inline RealT
t0()
const {
return mTimeSpan.
t0;}
106 inline RealT
t1()
const {
return mTimeSpan.
t1;}
132 template<
typename MapType>
138 const Vec3T eye = map.applyMap(mEye);
139 const Vec3T dir = map.applyJacobian(mDir);
141 return Ray(eye, dir/length, length*mTimeSpan.
t0, length*mTimeSpan.
t1);
150 template<
typename MapType>
155 const Vec3T eye = map.applyInverseMap(mEye);
156 const Vec3T dir = map.applyInverseJacobian(mDir);
158 return Ray(eye, dir/length, length*mTimeSpan.
t0, length*mTimeSpan.
t1);
163 template<
typename Gr
idType>
166 return this->
applyMap(*(grid.transform().baseMap()));
171 template<
typename Gr
idType>
186 const Vec3T origin = mEye - center;
188 const RealT
B = 2 * mDir.
dot(origin);
189 const RealT C = origin.
lengthSqr() - radius * radius;
190 const RealT D = B * B - 4 * A * C;
192 if (D < 0)
return false;
194 const RealT Q = RealT(-0.5)*(B<0 ? (B +
Sqrt(D)) : (B -
Sqrt(D)));
200 if (t0 < mTimeSpan.
t0) t0 = mTimeSpan.
t0;
201 if (t1 > mTimeSpan.
t1) t1 = mTimeSpan.
t1;
211 return this->
intersects(center, radius, t0, t1)>0;
221 const bool hit = this->
intersects(center, radius, t0, t1);
222 if (hit) mTimeSpan.
set(t0, t1);
233 template<
typename BBoxT>
236 mTimeSpan.
get(t0, t1);
237 for (
int i = 0; i < 3; ++i) {
238 RealT
a = (bbox.min()[i] - mEye[i]) * mInvDir[i];
239 RealT
b = (bbox.max()[i] - mEye[i]) * mInvDir[i];
243 if (t0 > t1)
return false;
250 template<
typename BBoxT>
260 template<
typename BBoxT>
261 inline bool clip(
const BBoxT& bbox)
264 const bool hit = this->
intersects(bbox, t0, t1);
265 if (hit) mTimeSpan.
set(t0, t1);
276 const RealT cosAngle = mDir.
dot(normal);
278 t = (distance - mEye.
dot(normal))/cosAngle;
279 return this->
test(t);
293 Vec3T mEye, mDir, mInvDir;
300 template<
typename RealT>
301 inline std::ostream& operator<<(std::ostream& os, const Ray<RealT>&
r)
303 os <<
"eye=" <<
r.eye() <<
" dir=" <<
r.dir() <<
" 1/dir="<<
r.invDir()
304 <<
" t0=" <<
r.t0() <<
" t1=" <<
r.t1();
312 #endif // OPENVDB_MATH_RAY_HAS_BEEN_INCLUDED
RealT mid() const
Return the midpoint of the ray.
void setTimes(RealT t0=math::Delta< RealT >::value(), RealT t1=std::numeric_limits< RealT >::max())
bool clip(const Vec3T ¢er, RealT radius)
Return true if this ray intersects the specified sphere.
GridType
List of types that are currently supported by NanoVDB.
void swap(UT::ArraySet< Key, MULTI, MAX_LOAD_FACTOR_256, Clearer, Hash, KeyEqual > &a, UT::ArraySet< Key, MULTI, MAX_LOAD_FACTOR_256, Clearer, Hash, KeyEqual > &b)
GT_API const UT_StringHolder time
void setEye(const Vec3Type &eye)
Vec3R end() const
Return the endpoint of the ray.
IMF_EXPORT IMATH_NAMESPACE::V3f direction(const IMATH_NAMESPACE::Box2i &dataWindow, const IMATH_NAMESPACE::V2f &pixelPosition)
GLsizei const GLfloat * value
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...
const Vec3T & eye() const
bool intersects(const Vec3T ¢er, RealT radius) const
Return true if this ray intersects the specified sphere.
void setDir(const Vec3Type &dir)
GLboolean GLboolean GLboolean GLboolean a
GLuint GLsizei GLsizei * length
#define OPENVDB_USE_VERSION_NAMESPACE
T dot(const Vec3< T > &v) const
Dot product.
bool test(RealT time) const
Return true if time is within t0 and t1, both inclusive.
#define OPENVDB_ASSERT(X)
void set(RealT _t0, RealT _t1)
Set both times.
void get(RealT &_t0, RealT &_t1) const
Get both times.
Ray applyMap(const MapType &map) const
Return a new Ray that is transformed with the specified map.
const Vec3T & invDir() const
Vec3R operator()(RealT time) const
Return the position along the ray at the specified time.
Ray applyInverseMap(const MapType &map) const
Return a new Ray that is transformed with the inverse of the specified map.
TimeSpan()
Default constructor.
Vec3R start() const
Return the starting point of the ray.
General-purpose arithmetic and comparison routines, most of which accept arbitrary value types (or at...
Delta for small floating-point offsets.
float Sqrt(float x)
Return the square root of a floating-point value.
bool intersects(const BBoxT &bbox, RealT &t0, RealT &t1) const
Return true if the Ray intersects the specified axisaligned bounding box.
bool isRelOrApproxEqual(const Type &a, const Type &b, const Type &absTol, const Type &relTol)
void setMinTime(RealT t0)
void scale(RealT s)
Multiplies both times.
bool isApproxZero(const Type &x)
Return true if x is equal to zero to within the default floating-point comparison tolerance...
GLboolean GLboolean GLboolean b
Ray(const Vec3Type &eye=Vec3Type(0, 0, 0), const Vec3Type &direction=Vec3Type(1, 0, 0), RealT t0=math::Delta< RealT >::value(), RealT t1=std::numeric_limits< RealT >::max())
bool clip(const BBoxT &bbox)
Return true if this ray intersects the specified bounding box.
bool valid(RealT eps=math::Delta< float >::value()) const
Return true if t1 is larger than t0 by at least eps.
MatType scale(const Vec3< typename MatType::value_type > &s)
Return a matrix that scales by s.
bool intersects(const Vec3T ¢er, RealT radius, RealT &t0, RealT &t1) const
Return true if this ray intersects the specified sphere.
void setMaxTime(RealT t1)
const Vec3T & dir() const
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.
ImageBuf OIIO_API max(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
Vec3R mid() const
Return the midpoint of the ray.
TimeSpan(RealT _t0, RealT _t1)
Constructor.
bool valid(RealT eps=math::Delta< RealT >::value()) const
Return true if t1 is larger than t0 by at least eps.
Ray indexToWorld(const GridType &grid) const
Return a new ray in world space, assuming the existing ray is represented in the index space of the s...
void reset(const Vec3Type &eye, const Vec3Type &direction, RealT t0=math::Delta< RealT >::value(), RealT t1=std::numeric_limits< RealT >::max())
SIM_API const UT_StringHolder distance
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
void scaleTimes(RealT scale)
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...
bool test(RealT t) const
Return true if time is inclusive.
bool intersects(const BBoxT &bbox) const
Return true if this ray intersects the specified bounding box.
T length() const
Length of the vector.