library of assembled shared sources

http://lass.cocamware.com

aabb_3d.h

Go to the documentation of this file.
00001 /** @file
00002  *  @author Bram de Greve (bramz@users.sourceforge.net)
00003  *  @author Tom De Muer (tomdemuer@users.sourceforge.net)
00004  *
00005  *  *** BEGIN LICENSE INFORMATION ***
00006  *  
00007  *  The contents of this file are subject to the Common Public Attribution License 
00008  *  Version 1.0 (the "License"); you may not use this file except in compliance with 
00009  *  the License. You may obtain a copy of the License at 
00010  *  http://lass.sourceforge.net/cpal-license. The License is based on the 
00011  *  Mozilla Public License Version 1.1 but Sections 14 and 15 have been added to cover 
00012  *  use of software over a computer network and provide for limited attribution for 
00013  *  the Original Developer. In addition, Exhibit A has been modified to be consistent 
00014  *  with Exhibit B.
00015  *  
00016  *  Software distributed under the License is distributed on an "AS IS" basis, WITHOUT 
00017  *  WARRANTY OF ANY KIND, either express or implied. See the License for the specific 
00018  *  language governing rights and limitations under the License.
00019  *  
00020  *  The Original Code is LASS - Library of Assembled Shared Sources.
00021  *  
00022  *  The Initial Developer of the Original Code is Bram de Greve and Tom De Muer.
00023  *  The Original Developer is the Initial Developer.
00024  *  
00025  *  All portions of the code written by the Initial Developer are:
00026  *  Copyright (C) 2004-2007 the Initial Developer.
00027  *  All Rights Reserved.
00028  *  
00029  *  Contributor(s):
00030  *
00031  *  Alternatively, the contents of this file may be used under the terms of the 
00032  *  GNU General Public License Version 2 or later (the GPL), in which case the 
00033  *  provisions of GPL are applicable instead of those above.  If you wish to allow use
00034  *  of your version of this file only under the terms of the GPL and not to allow 
00035  *  others to use your version of this file under the CPAL, indicate your decision by 
00036  *  deleting the provisions above and replace them with the notice and other 
00037  *  provisions required by the GPL License. If you do not delete the provisions above,
00038  *  a recipient may use your version of this file under either the CPAL or the GPL.
00039  *  
00040  *  *** END LICENSE INFORMATION ***
00041  */
00042 
00043 
00044 
00045 /** @class lass::prim::Aabb3D
00046  *  @brief your momma's axis aligned bounding box.
00047  *  @author Bram de Greve [BdG]
00048  *  @date 2003
00049  *
00050  *  An AABB (Axis Aligned Bounding Box) is a rectangular box of a given dimension
00051  *  (in this case a 3D box), that is often used as a simple bounding volume of another
00052  *  primitive or data structure.
00053  *
00054  *  <i>"A form of a bounding box where the box is aligned to the axis therefore only
00055  *  two points in space are needed to define it. AABB's are much faster to use, and
00056  *  take up less memory, but are very limited in the sense that they can only be
00057  *  aligned to the axis."</i>, http://www.gamedev.net/dict/term.asp?TermID=525
00058  *
00059  *  The way an AABB handles its minima and maxima can be set by the @c MinMaxPolicy.
00060  *  On policy StrictPolicy will enforce you to use correct minima and maxima, and on
00061  *  any suspicious behaviour, it will throw an exception.  The other policy AutoPolicy
00062  *  will try to correct misbehaviour without your notice.  For more information on
00063  *  these policies, I refer to the documentation compagning these policies.
00064  */
00065 
00066 
00067 
00068 #ifndef LASS_GUARDIAN_OF_INCLUSION_PRIM_AABB_3D_H
00069 #define LASS_GUARDIAN_OF_INCLUSION_PRIM_AABB_3D_H
00070 
00071 
00072 
00073 #include "min_max_policy.h"
00074 #include "point_3dh.h"
00075 
00076 
00077 namespace lass
00078 {
00079 
00080 namespace prim
00081 {
00082 
00083 template
00084 <
00085     typename T,
00086     class MinMaxPolicy = StrictMinMax
00087 >
00088 class Aabb3D
00089 {
00090 public:
00091 
00092     typedef Aabb3D<T, MinMaxPolicy> TSelf;
00093     typedef MinMaxPolicy TMinMaxPolicy;
00094 
00095     typedef Point3D<T> TPoint;
00096     typedef Point3DH<T> TPointH;
00097     typedef typename TPoint::TVector TVector;
00098 
00099     typedef typename TPoint::TValue TValue;
00100     typedef typename TPoint::TParam TParam;
00101     typedef typename TPoint::TReference TReference;
00102     typedef typename TPoint::TConstReference TConstReference;
00103     typedef typename TPoint::TNumTraits TNumTraits;
00104 
00105     enum { dimension = TPoint::dimension }; /**< number of dimensions of vector */
00106 
00107     template <typename U> struct Rebind
00108     {
00109         typedef Aabb3D<U, MinMaxPolicy> Type;
00110     };
00111 
00112     Aabb3D();
00113     Aabb3D(const TPoint& min, const TPoint& max);
00114     explicit Aabb3D(const TPoint& point);
00115     template <class MMP2> Aabb3D(const Aabb3D<T, MMP2>& other);
00116 
00117     const TPoint& min() const;
00118     const TPoint& max() const;
00119     void setMin(const TPoint& min);
00120     void setMax(const TPoint& max);
00121 
00122     template <class MMP2> TSelf& operator=(const Aabb3D<T, MMP2>& other);
00123 
00124     TSelf& operator+=(const TPoint& point);
00125     template<class MMP2> TSelf& operator+=(const Aabb3D<T, MMP2>& other);
00126     void grow(TParam iDistance);
00127     void grow(TVector iDistance);
00128     void scale(TParam iScale);
00129 
00130     const TPointH center() const;
00131     const TVector size() const;
00132     const TValue area() const;
00133     const TValue volume() const;
00134 
00135     const Side classify(const TPoint& point) const;
00136     const bool contains(const TPoint& point) const;
00137     template <class MMP2> const bool contains(const Aabb3D<T, MMP2>& other) const;
00138     template <class MMP2> const bool intersects(const Aabb3D<T, MMP2>& other) const;
00139     template <class MMP2> const bool collides(const Aabb3D<T, MMP2>& other) const;
00140 
00141     template <class RandomGenerator> const TPoint random(RandomGenerator& random) const;
00142 
00143     void clear();
00144     const bool isEmpty() const;
00145     const bool isValid() const;
00146 
00147     template <typename MMP2> void swap(Aabb3D<T, MMP2>& other);
00148 
00149 private:
00150 
00151     TPoint min_;
00152     TPoint max_;
00153 };
00154 
00155 template <typename T, class MMPa, class MMPb>
00156 const Aabb3D<T, MMPa> operator+(const Aabb3D<T, MMPa>& a, const Aabb3D<T, MMPb>& b);
00157 
00158 template <typename T, class MMP>
00159 const Aabb3D<T, MMP> operator+(const Aabb3D<T, MMP>& a, const Point3D<T>& b);
00160 
00161 template <typename T, class MMP>
00162 const Aabb3D<T, MMP> operator+(const Point3D<T>& a, const Aabb3D<T, MMP>& b);
00163 
00164 template <typename T>
00165 const Aabb3D<T> aabb(const Point3D<T>& point);
00166 
00167 template <typename T, class MMP>
00168 T distance(const Aabb3D<T, MMP>& a, const Point3D<T>& b);
00169 
00170 template <typename T, class MMPa, class MMPb>
00171 T distance(const Aabb3D<T, MMPa>& a, const Aabb3D<T, MMPb>& b);
00172 
00173 template <typename T, class MMPa, class MMPb, class MMPr>
00174 Result intersect(const Aabb3D<T, MMPa>& a, const Aabb3D<T, MMPb>& b, Aabb3D<T, MMPr>& result);
00175 
00176 template <typename T, class MMPa, class MMPb>
00177 const bool intersects(const Aabb3D<T, MMPa>& a, const Aabb3D<T, MMPb>& b);
00178 
00179 template <typename T, class MMP>
00180 const bool intersects(const Aabb3D<T, MMP>& a, const Point3D<T>& b);
00181 
00182 template <typename T, class MMP>
00183 const bool intersects(const Point3D<T>& a, const Aabb3D<T, MMP>& b);
00184 
00185 template <typename T, class MMPa, class MMPb>
00186 const bool collides(const Aabb3D<T, MMPa>& a, const Aabb3D<T, MMPb>& b);
00187 
00188 template <typename T, class MMP>
00189 const bool collides(const Aabb3D<T, MMP>& a, const Point3D<T>& b);
00190 
00191 template <typename T, class MMP>
00192 const bool collides(const Point3D<T>& a, const Aabb3D<T, MMP>& b);
00193 
00194 template <typename T, class MMP>
00195 std::ostream& operator<<(std::ostream& stream, const Aabb3D<T, MMP>& aabb);
00196 
00197 template <typename T, class MMP>
00198 io::XmlOStream& operator<<(io::XmlOStream& stream, const Aabb3D<T, MMP>& aabb);
00199 
00200 }
00201 
00202 }
00203 
00204 #include "aabb_3d.inl"
00205 
00206 #define LASS_PRIM_HAVE_PY_EXPORT_TRAITS_AABB_3D
00207 #ifdef LASS_GUARDIAN_OF_INCLUSION_UTIL_PYOBJECT_PLUS_H
00208 #   include "pyobject_util.h"
00209 #endif
00210 
00211 #define LASS_PRIM_PYOBJECT_UTIL_AABB_3D
00212 #ifdef LASS_GUARDIAN_OF_INCLUSION_PRIM_PYOBJECT_UTIL_H
00213 #   include "pyobject_util.h"
00214 #endif
00215 
00216 #ifdef LASS_GUARDIAN_OF_INCLUSION_PRIM_PARALLELOGRAM_3D_H
00217 #   include "aabb_3d_parallelogram_3d.h"
00218 #endif
00219 
00220 #ifdef LASS_GUARDIAN_OF_INCLUSION_PRIM_RAY_3D_H
00221 #   include "aabb_3d_ray_3d.h"
00222 #endif
00223 
00224 #ifdef LASS_GUARDIAN_OF_INCLUSION_PRIM_SIMPLE_POLYGON_3D_H
00225 #   include "aabb_3d_simple_polygon_3d.h"
00226 #endif
00227 
00228 #ifdef LASS_GUARDIAN_OF_INCLUSION_PRIM_SPHERE_3D_H
00229 #   include "aabb_3d_sphere_3d.h"
00230 #endif
00231 
00232 #ifdef LASS_GUARDIAN_OF_INCLUSION_PRIM_TRIANGLE_3D_H
00233 #   include "aabb_3d_triangle_3d.h"
00234 #endif
00235 
00236 #ifdef LASS_GUARDIAN_OF_INCLUSION_PRIM_TRANSFORMATION_3D_H
00237 #   include "aabb_3d_transformation_3d.h"
00238 #endif
00239 
00240 #endif
00241 
00242 // EOF
00243 

Generated on Mon Nov 10 14:19:58 2008 for Library of Assembled Shared Sources by doxygen 1.5.7.1
SourceForge.net Logo