Describes a bounding sphere region in 3D space.
#include <Mesh/Geometry/boundingsphere.h>
◆ BoundingSphere() [1/3]
Constructs a null bounding sphere.
◆ BoundingSphere() [2/3]
- Parameters
-
sphere | The bounding sphere to copy. |
◆ BoundingSphere() [3/3]
- Parameters
-
center | The center of the bounding sphere. |
radius | The radius of the bounding sphere. It must not be negative. |
◆ clone()
- Returns
- A clone of this object.
- Note
- Subclasses would normally return their own type rather than the Clonable type. The C++ language rules allow a more derived type to be returned from a virtual function and the compiler will still treat it as a valid override.
We redeclare this function only so that the more derived return type is available without casting.
Implements ObjectGroup.
◆ cloneRegion()
This function should be called clone() but the Visual Studio compilers do not handle covariant return types when multiple inheritance from a virtual base class is involved. Since Region is often combined with other Clonable classes such as ObjectGroup, we don't provide clone() but instead provide cloneRegion() which is effectively doing the same thing, albeit with the annoyance of a different function name.
Note that subclasses will need to tell DataExecution::TypedDataFactory about their cloneRegion() implementation explicitly if they do not also inherit from some other Clonable base class as well, since Region does not derive from Clonable (which means the template specializations for TypedDataFactory will not automatically detect cloneRegion()).
Implements Region.
◆ contains()
bool contains |
( |
const Vector3d & |
p | ) |
const |
|
overridevirtual |
- Parameters
-
- Returns
- True if the point p is contained within the region. If p falls on the boundary of the region, the result returned must also be true. If the region is a null region (ie isNull() returns true), this function must return false.
Implements Region.
◆ destroy()
Destroys the object. This function is usually implemented by calling operator delete on the object.
- See also
- clone()
Implements Region.
◆ expand()
- Parameters
-
p | The point to test against the bounding sphere. |
If p is not within the current bounding sphere, the sphere will be expanded to include it. If the bounding sphere is null at the time of the call, it will be made non-null and will have its center set to p and its radius to zero..
- Warning
- This function is vulnerable to accumulated roundoff error due to the way the sphere has to be recomputed based on the current center and radius. The class does not retain a list of points added but rather it only retains the last known center and radius. Thus, it is possible that a point that was once inside the sphere might eventually fall just outside it due to rounding inaccuracies. A more robust alternative is to call expandRadius() since it guarantees to always contain whatever it previously contained.
◆ expandRadius()
- Parameters
-
p | The point to test against the bounding sphere. |
If p is not within the current bounding sphere, the sphere's radius will be expanded to include it.
- Precondition
- The center of the sphere must have been set before calling this function. It is okay for the radius to not be set, since it will be assumed to be zero in that case and set to whatever the radius is to p.
- See also
- expand()
◆ getBoundingBox()
- Parameters
-
minimum | If the function returns true, then at exit this will hold the corner of the bounding box corresponding to the minimum values of X, Y and Z. |
maximum | If the function returns true, then at exit this will hold the corner of the bounding box corresponding to the maximum values of X, Y and Z. |
The bounding box is guaranteed to contain all the regions for which a point passed to contains() will return true. It can be useful as a way of short-circuiting a more expensive test for whether a point is contained in a complex region. How conservative the bounding box is will be determined entirely by the subclass. It is allowable for the subclass to return the entire 3D domain as the bounding box (and indeed some subclasses logically have to do this, such as RegionNegate).
- Returns
- True if the bounding box could be defined. A return value of false would normally indicate that the region is null.
- See also
- getBoundingSphere(), isNull()
Implements Region.
◆ getBoundingSphere()
bool getBoundingSphere |
( |
Vector3d & |
center, |
|
|
double & |
radius |
|
) |
| const |
|
overridevirtual |
- Parameters
-
center | This will hold the center of the bounding sphere if the function is successful. If not successful, the function leaves it unmodified from the passed in value. |
radius | This will hold the radius of the bounding sphere if the function is successful. If not successful, the function leaves it unmodified from the passed in value. |
If the bounding sphere is not null, this function always succeeds and will be very efficient since the center and radius are both already held internally by the object.
- Returns
- True if the bounding sphere is not null.
- See also
- getBoundingBox(), isNull()
Reimplemented from Region.
◆ getCenter()
- Returns
- The center of the bounding sphere.
- Precondition
- The bounding sphere must not be null.
- See also
- setCenter(), isNull()
◆ getRadius()
double getRadius |
( |
| ) |
const |
- Returns
- The radius of the bounding sphere.
- Precondition
- The bounding sphere must not be null.
- See also
- setRadius(), isNull()
◆ isNull()
- Returns
- True if the bounding sphere is null. Any call to expand() will make a bounding sphere object non-null, as will the constructors taking Vector3d parameters.
Implements Region.
◆ operator!=()
◆ operator==()
◆ setCenter()
- Parameters
-
c | The new center of the sphere. |
- Postcondition
- The radius is left unchanged from whatever it was before the call.
- See also
- getCenter(), setRadius()
◆ setRadius()
void setRadius |
( |
double |
r | ) |
|
- Parameters
-
r | The new radius of the sphere. |
- Postcondition
- The center is left unchanged from whatever it was before the call.
- See also
- getRadius(), setCenter()
◆ visit()
Visit the specified region processor, invoking the correct processing function. Subclasses will need to override this to invoke the correct function.
Implements Region.