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;
75 WBoundingBoxImpl( value_type xmin, value_type ymin, value_type zmin, value_type xmax, value_type ymax, value_type zmax );
111 using osg::BoundingBoxImpl< VT >::valid;
112 using osg::BoundingBoxImpl< VT >::set;
113 using osg::BoundingBoxImpl< VT >::xMin;
114 using osg::BoundingBoxImpl< VT >::yMin;
115 using osg::BoundingBoxImpl< VT >::zMin;
116 using osg::BoundingBoxImpl< VT >::xMax;
117 using osg::BoundingBoxImpl< VT >::yMax;
118 using osg::BoundingBoxImpl< VT >::zMax;
119 using osg::BoundingBoxImpl< VT >::center;
120 using osg::BoundingBoxImpl< VT >::radius;
131 using osg::BoundingBoxImpl< VT >::corner;
138 osg::BoundingBox
toOSGBB()
const;
140 using osg::BoundingBoxImpl< VT >::expandBy;
167 using osg::BoundingBoxImpl< VT >::contains;
174 const vec_type&
getMin()
const;
181 const vec_type&
getMax()
const;
195 double intervalDistance(
double a0,
double a1,
double b0,
double b1 )
const;
200 : osg::BoundingBoxImpl< VT >()
206 : osg::BoundingBoxImpl< VT >( xmin, ymin, zmin, xmax, ymax, zmax )
212 : osg::BoundingBoxImpl< VT >( min, max )
218 : osg::BoundingBoxImpl< VT >( bs.center() - VT( bs.radius(), bs.radius(), bs.radius() ) ,
219 bs.center() + VT( bs.radius(), bs.radius(), bs.radius() ) )
225 : osg::BoundingBoxImpl< VT >( bb )
243 return this->radius2();
249 return osg::BoundingBox( osg::BoundingBoxImpl< VT >::_min, osg::BoundingBoxImpl< VT >::_max );
255 osg::BoundingBoxImpl< VT >::expandBy( bb );
261 return osg::BoundingBoxImpl< VT >::intersects( bb );
282 if( !valid() || !bb.valid() )
284 throw WInvalidBoundingBox(
"One of the both bounding boxes inside minDistance computation is not valid." );
287 double dx = intervalDistance( xMin(), xMax(), bb.xMin(), bb.xMax() );
288 double dy = intervalDistance( yMin(), yMax(), bb.yMin(), bb.yMax() );
289 double dz = intervalDistance( zMin(), zMax(), bb.zMin(), bb.zMax() );
290 if( dx == 0.0 && dy == 0.0 && dz == 0.0 )
294 return std::sqrt( dx * dx + dy * dy + dz * dz );
306 inline std::ostream& operator<<( std::ostream& out, const WBoundingBoxImpl< VT >& bb )
308 out << std::scientific << std::setprecision( 16 );
309 out <<
"AABB( min: " << bb.xMin() <<
", " << bb.yMin() <<
", " << bb.zMin();
310 out <<
" max: " << bb.xMax() <<
", " << bb.yMax() <<
", " << bb.zMax() <<
" )";
317 return osg::BoundingBoxImpl< VT >::_min;
323 return osg::BoundingBoxImpl< VT >::_max;
328 #endif // WBOUNDINGBOX_H
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.
double intervalDistance(double a0, double a1, double b0, double b1) const
Checks if the two given intervals intersect and computes the distance between them.
void expandBy(const WBoundingBoxImpl< VT > &bb)
Expands this bounding box to include the given bounding box.
Represents a axis parallel bounding box and provides some useful operations with them.
osg::BoundingBoxImpl< VT >::vec_type vec_type
Vertex type for min and max positions of this box.
osg::BoundingBoxImpl< VT >::value_type value_type
Value type of the vertex type for example double, float, etc.
bool intersects(const WBoundingBoxImpl< VT > &bb) const
Checks for intersection of this bounding box with the specified bounding box.
value_type minDistance(const WBoundingBoxImpl< VT > &bb) const
Computes the minimal distance of tow axis parallel bounding boxes.
const vec_type & getMin() const
Gives the front lower left aka minimum corner.
WBoundingBoxImpl()
Default constructor.
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.
Indicates that a bounding box is not valid, meaning its valid() member function delivers false...
virtual ~WBoundingBoxImpl()
Destructs this instance.