20 #if !defined(__MITSUBA_CORE_BSPHERE_H_)
21 #define __MITSUBA_CORE_BSPHERE_H_
37 inline BSphere() : center(0.0f), radius(0.0f) { }
41 center =
Point(stream);
47 : center(center), radius(radius) {
52 : center(boundingSphere.center), radius(boundingSphere.radius) {
57 return radius <= 0.0f;
62 radius = std::max(radius, (p-center).length());
67 return (p - center).length() <= radius;
72 return center == boundingSphere.
center && radius == boundingSphere.
radius;
77 return center != boundingSphere.
center || radius != boundingSphere.
radius;
90 Float A = ray.d.lengthSquared();
92 Float C = o.lengthSquared() - radius*radius;
99 center.serialize(stream);
105 std::ostringstream oss;
106 oss <<
"BSphere[center = " << center.toString()
107 <<
", radius = " << radius <<
"]";
std::string toString() const
Return a string representation of the bounding sphere.
Definition: bsphere.h:104
BSphere()
Construct a bounding sphere at the origin having radius zero.
Definition: bsphere.h:37
void serialize(Stream *stream) const
Serialize this bounding sphere to a binary data stream.
Definition: bsphere.h:98
void expandBy(const Point p)
Expand the bounding sphere radius to contain another point.
Definition: bsphere.h:61
Bounding sphere data structure in three dimensions.
Definition: bsphere.h:32
Float readFloat()
Write a floating point number (configured precision) to the stream.
Definition: stream.h:424
bool operator==(const BSphere &boundingSphere) const
Equality test.
Definition: bsphere.h:71
BSphere(const BSphere &boundingSphere)
Copy constructor.
Definition: bsphere.h:51
Float radius
Definition: bsphere.h:34
TPoint3< Float > Point
Definition: fwd.h:136
bool operator!=(const BSphere &boundingSphere) const
Inequality test.
Definition: bsphere.h:76
MTS_EXPORT_CORE bool solveQuadratic(Float a, Float b, Float c, Float &x0, Float &x1)
Solve a quadratic equation of the form a*x^2 + b*x + c = 0.
void writeFloat(Float value)
Write a floating point number (configured precision) to the stream.
Definition: stream.h:271
Abstract seekable stream class.
Definition: stream.h:58
BSphere(const Point ¢er, Float radius)
Create a bounding sphere from a given center point and radius.
Definition: bsphere.h:46
bool isEmpty() const
Return whether this bounding sphere has a radius of zero or less.
Definition: bsphere.h:56
BSphere(Stream *stream)
Unserialize a bounding sphere from a binary data stream.
Definition: bsphere.h:40
bool rayIntersect(const Ray &ray, Float &nearHit, Float &farHit) const
Calculate the intersection points with the given ray.
Definition: bsphere.h:88
T dot(const TQuaternion< T > &q1, const TQuaternion< T > &q2)
Definition: quat.h:348
Point center
Definition: bsphere.h:33
bool contains(const Point p) const
Check whether the specified point is inside or on the sphere.
Definition: bsphere.h:66