25 #ifndef WBOUNDINGBOX_H
26 #define WBOUNDINGBOX_H
32 #include <osg/BoundingBox>
34 #include "exceptions/WInvalidBoundingBox.h"
53 typedef typename osg::BoundingBoxImpl< VT >::vec_type
vec_type;
58 typedef typename osg::BoundingBoxImpl< VT >::value_type
value_type;
104 using osg::BoundingBoxImpl< VT >::valid;
105 using osg::BoundingBoxImpl< VT >::set;
106 using osg::BoundingBoxImpl< VT >::xMin;
107 using osg::BoundingBoxImpl< VT >::yMin;
108 using osg::BoundingBoxImpl< VT >::zMin;
109 using osg::BoundingBoxImpl< VT >::xMax;
110 using osg::BoundingBoxImpl< VT >::yMax;
111 using osg::BoundingBoxImpl< VT >::zMax;
112 using osg::BoundingBoxImpl< VT >::center;
113 using osg::BoundingBoxImpl< VT >::radius;
124 using osg::BoundingBoxImpl< VT >::corner;
133 using osg::BoundingBoxImpl< VT >::expandBy;
160 using osg::BoundingBoxImpl< VT >::contains;
193 : osg::BoundingBoxImpl< VT >()
199 : osg::BoundingBoxImpl< VT >( xmin, ymin, zmin, xmax, ymax, zmax )
205 : osg::BoundingBoxImpl< VT >( min, max )
211 : osg::BoundingBoxImpl< VT >( bs.center() - VT( bs.radius(), bs.radius(), bs.radius() ) ,
212 bs.center() + VT( bs.radius(), bs.radius(), bs.radius() ) )
230 return this->radius2();
236 return osg::BoundingBox( osg::BoundingBoxImpl< VT >::_min, osg::BoundingBoxImpl< VT >::_max );
242 osg::BoundingBoxImpl< VT >::expandBy( bb );
248 return osg::BoundingBoxImpl< VT >::intersects( bb );
269 if( !valid() || !bb.valid() )
271 throw WInvalidBoundingBox(
"One of the both bounding boxes inside minDistance computation is not valid." );
274 double dx = intervalDistance( xMin(), xMax(), bb.xMin(), bb.xMax() );
275 double dy = intervalDistance( yMin(), yMax(), bb.yMin(), bb.yMax() );
276 double dz = intervalDistance( zMin(), zMax(), bb.zMin(), bb.zMax() );
277 if( dx == 0.0 && dy == 0.0 && dz == 0.0 )
281 return std::sqrt( dx * dx + dy * dy + dz * dz );
295 out << std::scientific << std::setprecision( 16 );
296 out <<
"AABB( min: " << bb.xMin() <<
", " << bb.yMin() <<
", " << bb.zMin();
297 out <<
" max: " << bb.xMax() <<
", " << bb.yMax() <<
", " << bb.zMax() <<
" )";
304 return osg::BoundingBoxImpl< VT >::_min;
310 return osg::BoundingBoxImpl< VT >::_max;
Represents a axis parallel bounding box and provides some useful operations with them.
WBoundingBoxImpl()
Default constructor.
osg::BoundingBoxImpl< VT >::value_type value_type
Value type of the vertex type for example double, float, etc.
virtual ~WBoundingBoxImpl()
Destructs this instance.
bool intersects(const WBoundingBoxImpl< VT > &bb) const
Checks for intersection of this bounding box with the specified bounding box.
value_type radiusSquare() const
Calculates and returns the squared length of the bounding box radius.
const vec_type & getMax() const
Gives the back upper right aka maximum corner.
value_type minDistance(const WBoundingBoxImpl< VT > &bb) const
Computes the minimal distance of tow axis parallel bounding boxes.
double intervalDistance(double a0, double a1, double b0, double b1) const
Checks if the two given intervals intersect and computes the distance between them.
const vec_type & getMin() const
Gives the front lower left aka minimum corner.
void expandBy(const WBoundingBoxImpl< VT > &bb)
Expands this bounding box to include the given bounding box.
osg::BoundingBoxImpl< VT >::vec_type vec_type
Vertex type for min and max positions of this box.
WBoundingBoxImpl(const vec_type &min, const vec_type &max)
Constructs a bounding box by min and max positions.
WBoundingBoxImpl(value_type xmin, value_type ymin, value_type zmin, value_type xmax, value_type ymax, value_type zmax)
Wrapps the component wise bounding box constructor from osg::BoundingBox.
osg::BoundingBox toOSGBB() const
Explicit type conversion function to use a WBoundingBox as osg::BoundingBox.
void reset()
Resets this box to an initial state where max is FLT_MIN and min FLT_MAX.
WBoundingBoxImpl(const osg::BoundingSphereImpl< VT > &bs)
Create BoundinmgBox using a given sphere.
Indicates that a bounding box is not valid, meaning its valid() member function delivers false.