BWAPI
SPAR/AIModule/BWTA/vendors/CGAL/CGAL/Bbox_3.h
Go to the documentation of this file.
00001 // Copyright (c) 1999,2004  Utrecht University (The Netherlands),
00002 // ETH Zurich (Switzerland), Freie Universitaet Berlin (Germany),
00003 // INRIA Sophia-Antipolis (France), Martin-Luther-University Halle-Wittenberg
00004 // (Germany), Max-Planck-Institute Saarbruecken (Germany), RISC Linz (Austria),
00005 // and Tel-Aviv University (Israel).  All rights reserved.
00006 //
00007 // This file is part of CGAL (www.cgal.org); you can redistribute it and/or
00008 // modify it under the terms of the GNU Lesser General Public License as
00009 // published by the Free Software Foundation; version 2.1 of the License.
00010 // See the file LICENSE.LGPL distributed with CGAL.
00011 //
00012 // Licensees holding a valid commercial license may use this file in
00013 // accordance with the commercial license agreement provided with the software.
00014 //
00015 // This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00016 // WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00017 //
00018 // $URL: svn+ssh://scm.gforge.inria.fr/svn/cgal/branches/CGAL-3.5-branch/Kernel_23/include/CGAL/Bbox_3.h $
00019 // $Id: Bbox_3.h 49057 2009-04-30 14:03:52Z spion $
00020 //
00021 // Author(s)     : Andreas Fabri
00022 
00023 #ifndef CGAL_BBOX_3_H
00024 #define CGAL_BBOX_3_H
00025 
00026 #include <CGAL/basic.h>
00027 #include <CGAL/IO/io.h>
00028 #include <CGAL/Dimension.h>
00029 #include <CGAL/array.h>
00030 
00031 CGAL_BEGIN_NAMESPACE
00032 
00033 template < typename T >
00034 struct Simple_cartesian;
00035 
00036 class Bbox_3
00037 {
00038   cpp0x::array<double, 6>   rep;
00039 
00040 public:
00041 
00042   typedef Dimension_tag<3>  Ambient_dimension;
00043   typedef Dimension_tag<3>  Feature_dimension;
00044 
00045   typedef Simple_cartesian<double>  R;
00046 
00047         Bbox_3() {}
00048 
00049         Bbox_3(double x_min, double y_min, double z_min,
00050                double x_max, double y_max, double z_max)
00051           : rep(CGAL::make_array(x_min, y_min, z_min, x_max, y_max, z_max)) {}
00052 
00053   inline bool operator==(const Bbox_3 &b) const;
00054   inline bool operator!=(const Bbox_3 &b) const;
00055 
00056   inline int dimension() const;
00057   double  xmin() const;
00058   double  ymin() const;
00059   double  zmin() const;
00060   double  xmax() const;
00061   double  ymax() const;
00062   double  zmax() const;
00063 
00064   inline double min BOOST_PREVENT_MACRO_SUBSTITUTION (int i) const;
00065   inline double max BOOST_PREVENT_MACRO_SUBSTITUTION (int i) const;
00066 
00067   Bbox_3  operator+(const Bbox_3& b) const;
00068 };
00069 
00070 inline
00071 double
00072 Bbox_3::xmin() const
00073 { return rep[0]; }
00074 
00075 inline
00076 double
00077 Bbox_3::ymin() const
00078 { return rep[1]; }
00079 
00080 inline
00081 double
00082 Bbox_3::zmin() const
00083 { return rep[2]; }
00084 
00085 inline
00086 double
00087 Bbox_3::xmax() const
00088 { return rep[3]; }
00089 
00090 inline
00091 double
00092 Bbox_3::ymax() const
00093 { return rep[4]; }
00094 
00095 inline
00096 double
00097 Bbox_3::zmax() const
00098 { return rep[5]; }
00099 
00100 inline
00101 bool
00102 Bbox_3::operator==(const Bbox_3 &b) const
00103 {
00104   return xmin() == b.xmin() && xmax() == b.xmax()
00105       && ymin() == b.ymin() && ymax() == b.ymax()
00106       && zmin() == b.zmin() && zmax() == b.zmax();
00107 }
00108 
00109 inline
00110 bool
00111 Bbox_3::operator!=(const Bbox_3 &b) const
00112 {
00113   return ! (b == *this);
00114 }
00115 
00116 inline
00117 int
00118 Bbox_3::dimension() const
00119 { return 3; }
00120 
00121 inline
00122 double
00123 Bbox_3::min BOOST_PREVENT_MACRO_SUBSTITUTION (int i) const
00124 {
00125   CGAL_kernel_precondition( (i == 0 ) || ( i == 1 ) || ( i == 2) );
00126   if (i == 0) { return xmin(); }
00127   if (i == 1) { return ymin(); }
00128   return zmin();
00129 }
00130 
00131 inline
00132 double
00133 Bbox_3::max BOOST_PREVENT_MACRO_SUBSTITUTION (int i) const
00134 {
00135   CGAL_kernel_precondition( (i == 0 ) || ( i == 1 ) || ( i == 2 ) );
00136   if (i == 0) { return xmax(); }
00137   if (i == 1) { return ymax(); }
00138   return zmax();
00139 }
00140 
00141 inline
00142 Bbox_3
00143 Bbox_3::operator+(const Bbox_3& b) const
00144 {
00145   return Bbox_3((std::min)(xmin(), b.xmin()),
00146                 (std::min)(ymin(), b.ymin()),
00147                 (std::min)(zmin(), b.zmin()),
00148                 (std::max)(xmax(), b.xmax()),
00149                 (std::max)(ymax(), b.ymax()),
00150                 (std::max)(zmax(), b.zmax()));
00151 }
00152 
00153 inline
00154 bool
00155 do_overlap(const Bbox_3& bb1, const Bbox_3& bb2)
00156 {
00157     // check for emptiness ??
00158     if (bb1.xmax() < bb2.xmin() || bb2.xmax() < bb1.xmin())
00159         return false;
00160     if (bb1.ymax() < bb2.ymin() || bb2.ymax() < bb1.ymin())
00161         return false;
00162     if (bb1.zmax() < bb2.zmin() || bb2.zmax() < bb1.zmin())
00163         return false;
00164     return true;
00165 }
00166 
00167 
00168 inline
00169 std::ostream&
00170 operator<<(std::ostream &os, const Bbox_3& b)
00171 {
00172   switch(os.iword(IO::mode))
00173   {
00174     case IO::ASCII :
00175         return os << b.xmin() << ' ' << b.ymin() << ' ' << b.zmin()
00176                   << ' ' << b.xmax() << ' ' << b.ymax() << ' ' << b.zmax();
00177     case IO::BINARY :
00178         write(os, b.xmin());
00179         write(os, b.ymin());
00180         write(os, b.zmin());
00181         write(os, b.xmax());
00182         write(os, b.ymax());
00183         write(os, b.zmax());
00184         return os;
00185     default:
00186         os << "Bbox_3((" << b.xmin()
00187            << ", "       << b.ymin()
00188            << ", "       << b.zmin() << "), (";
00189         os <<               b.xmax()
00190            << ", "       << b.ymax()
00191            << ", "       << b.zmax() << "))";
00192         return os;
00193   }
00194 }
00195 
00196 inline
00197 std::istream&
00198 operator>>(std::istream &is, Bbox_3& b)
00199 {
00200   double xmin, ymin, zmin, xmax, ymax, zmax;
00201 
00202   switch(is.iword(IO::mode))
00203   {
00204     case IO::ASCII :
00205       is >> xmin >> ymin >> zmin >> xmax >> ymax >> zmax;
00206         break;
00207     case IO::BINARY :
00208         read(is, xmin);
00209         read(is, ymin);
00210         read(is, zmin);
00211         read(is, xmax);
00212         read(is, ymax);
00213         read(is, zmax);
00214         break;
00215   }
00216   if (is)
00217     b = Bbox_3(xmin, ymin, zmin, xmax, ymax, zmax);
00218   return is;
00219 }
00220 
00221 CGAL_END_NAMESPACE
00222 
00223 #endif // CGAL_BBOX_3_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines