34 #ifndef OPENVDB_MATH_RAY_HAS_BEEN_INCLUDED
35 #define OPENVDB_MATH_RAY_HAS_BEEN_INCLUDED
45 #include <openvdb/math/Transform.h>
53 template<
typename _Real>
66 Real time = std::numeric_limits<Real>::epsilon(),
68 : mOrigin(origin), mDirection(direction),
69 mInvDirection(1/direction[0],1/direction[1],1/direction[2]),
70 mTime(time), mMinTime(start), mMaxTime(end)
95 void setDirection(
const Vec3R &dir)
98 this->setInvDirection();
106 this->setInvDirection();
129 Vec3R start()
const {
return mOrigin + mDirection * mMinTime; }
130 Vec3R end()
const {
return mOrigin + mDirection * mMaxTime; }
131 bool isValid()
const {
return (mTime>mMinTime && mTime<mMaxTime); }
138 mOrigin = xform->worldToIndex(mOrigin);
140 mDirection = xform->worldToIndex(mDirection);
141 mDirection -= xform->indexToWorld(
Vec3R(0,0,0));
142 this->setInvDirection();
149 mOrigin = xform->indexToWorld( mOrigin );
151 mDirection += xform->indexToWorld(
Vec3R( 0,0,0 ) );
152 mDirection = xform->indexToWorld( mDirection );
153 this->setInvDirection();
157 void setInvDirection()
159 mInvDirection[0] = 1/mDirection[0];
160 mInvDirection[1] = 1/mDirection[1];
161 mInvDirection[2] = 1/mDirection[2];
168 Real mMinTime, mMaxTime;
172 template<
typename Real>
173 inline std::ostream &operator<<(std::ostream &os, const Ray<Real> &r) {
174 os <<
"org=" << r.getOrigin() <<
" dir=" << r.getDirection() <<
" tmin=" <<
175 r.getMinTime() <<
" tmax=" << r.getMaxTime() <<
" t=" << r.getTime();
180 template<
typename Real,
typename ValueType>
187 enum Tag {EMPTY=0, CONSTANT, VARIABLE};
195 : t0(std::numeric_limits<
Real>::epsilon()),
196 t1(std::numeric_limits<
Real>::
max()), tag(EMPTY)
201 : t0(_t0), t1(_t1), tag(EMPTY)
207 : t0(_t0), t1(_t1), tag(VARIABLE)
213 : t0(_t0), t1(_t1), tag(CONSTANT), value(_value)
232 tag = empty ? EMPTY : VARIABLE;
236 void set(
Real _t0,
Real _t1,
const ValueType &_value)
259 if (this->tag != other.
tag
263 }
else if (std::abs(this->t0-other.
t1)<
tolerance) {
266 }
else if (std::abs(this->t1-other.
t0)<
tolerance) {
275 std::cerr <<
"t0=" << t0 <<
"\tt1=" << t1 <<
"\ttag="
276 << (tag==0 ?
"EMPTY" : tag==1 ?
"CONSTANT" :
"VARIABLE");
277 if (tag==1) std::cerr <<
"\tvalue=" << value;
278 std::cerr << std::endl;
283 template<
typename Real,
typename ValueType>
301 if (this->size()==0)
return false;
303 typename std::set<IntervalType>::const_iterator iter=this->begin(), iend=this->end();
307 for ( ++iter; iter != iend; ++iter ) {
320 bool isEmpty()
const {
return this->size()==0;}
323 void print(
const std::string &str=std::string(
""))
const
325 if (str!=std::string(
""))
326 std::cerr <<
"RayIntervalSet for \"" << str <<
"\"" << std::endl;
327 if (this->isEmpty()) {
328 std::cerr <<
"Empty RayIntervalSet!" << std::endl;
331 typename std::set<IntervalType>::const_iterator iter=this->begin();
332 for (; iter!=this->end(); ++iter) iter->print();
340 #endif // OPENVDB_MATH_RAY_HAS_BEEN_INCLUDED