Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages

Box.h

Go to the documentation of this file.
00001 /** Routines for handling vectors of intervals.
00002  * @file Box.h 
00003  * @author John Hart
00004  * @author Terry Fleury
00005  * @date 3 July 2001
00006  */
00007 
00008 #ifndef BOX_H
00009 #define BOX_H
00010 
00011 #include "Interval.h"
00012 #include "RandomStream.h"
00013 
00014 /** 
00015  * @class Box 
00016  * An interval vector class.
00017  * A box is an axis aligned region of space represented by a vector of
00018  * intervals.  A generalized Box can be of any dimension.  Specialized
00019  * classes exist for 3D and 4D regions.
00020  */
00021 template <class Float>
00022 class Box : public TNT::Vector< Interval<Float> > // Note space between >'s
00023 {
00024   private:
00025     RandomStream rs;   ///< A stream of random numbers
00026 
00027   public:
00028     /// Constructors
00029     Box();
00030     Box(int n);
00031     Box(int n, Float x);
00032     Box(TNT::Vector<Float> x);
00033 
00034     /// Math operators
00035     Box<Float>& operator *=(const Interval<Float> &c);
00036     Box<Float>& operator /=(const Interval<Float> &c);
00037     Box<Float>& operator +=(const Interval<Float> &c);
00038 
00039     /// Size operators
00040     Float width(int &dim);  ///< Also returns which side was longest
00041     Float width();
00042     Interval<Float> length();
00043     Interval<Float> lengthSquared();
00044     Box<Float> normalize();
00045 
00046     /// Parts of Boxes
00047     Box<Float> unionWith(Box<Float> &b);
00048     void subdivide(Box<Float> &IX1, Box<Float> &IX2);
00049     TNT::Vector<Float> center();
00050 
00051     /// Basic output
00052     void print();
00053 };  // End of class definition
00054 
00055 
00056 
00057 
00058 /// Explicit instantiation of Box<double>
00059 template class Box<double>;
00060 
00061 /// Multiply a box and an interval.
00062 template <class Float>
00063 Box<Float> operator *(const Box<Float> &x, const Interval<Float> &y)
00064 {
00065   Box<Float> z = x;
00066   return (z *= y);
00067 }
00068 
00069 /// Multiply an interval and a box.
00070 template <class Float>
00071 Box<Float> operator *(const Interval<Float> &x, const Box<Float> &y)
00072 {
00073   Box<Float> z = y;
00074   return (z *= x);
00075 }
00076 
00077 /// Divide a box and an interval.
00078 template <class Float>
00079 Box<Float> operator /(const Box<Float> &x, const Interval<Float> &y)
00080 {
00081   Box<Float> z = x;
00082   return (z /= y);
00083 }
00084 
00085 /// Add a box and an interval.
00086 template <class Float>
00087 Box<Float> operator +(const Box<Float> &x, const Interval<Float> &y)
00088 {
00089   Box<Float> z = x;
00090   return (z += y);
00091 }
00092 
00093 /// Add an interval and a box.
00094 template <class Float>
00095 Box<Float> operator +(const Interval<Float> &x, const Box<Float> &y)
00096 {
00097   Box<Float> z = y;
00098   return (z += x);
00099 }
00100 
00101 /// 'Dot' product of two boxes - loose definition of dot product here.
00102 template <class Float>
00103 Interval<Float> dot(const Box<Float> &x, const Box<Float> &y)
00104 {
00105   Interval<Float> sum = 0.0;
00106   for (int i = 0; i < x.size(); i++)
00107     sum += x[i] * y[i];
00108 
00109   return sum;
00110 }
00111 
00112 /// Standard output stream to print out the coords of the box.
00113 template<class Float>
00114 std::ostream& operator<<(std::ostream& os, const Box<Float>& x)
00115 {
00116   os << "[ ";
00117   for (int i = 0; i < x.size(); i++)
00118     {
00119       os << x[i];
00120       if (i < (x.size()-1))
00121         os << ", ";
00122     }
00123   return os << " ]";
00124 }
00125 
00126 
00127 
00128 
00129 /**
00130  * This is the 3D / double specific version of a Box.  Use this most often
00131  * so you don't have to declare the size of your Boxes all the time.
00132  */
00133 class Box3d : public Box<double>
00134 {
00135   public:
00136     /// Constructors
00137     Box3d();
00138     Box3d(TNT::Vector< Interval<double> > A);
00139     Box3d(gmVector3 mincorner, gmVector3 maxcorner);
00140     Box3d(gmVector3 x);
00141     Box3d(Interval<double> x, Interval<double> y, Interval<double> z);
00142     Box3d(Interval<double> v);
00143     Box3d(double d);
00144     Box3d(Box<double> x);
00145 
00146     /// 'Corner' operators
00147     gmVector3 low();
00148     gmVector3 high();
00149 };
00150 
00151 
00152 
00153 
00154 /**
00155  * This is the 4D / double specific version of a Box.  Use this when you
00156  * need a 4D box (ie, x,y,z,t) for finding 4D critical points (through time).
00157  */
00158 class Box4d : public Box<double>
00159 {
00160   public:
00161     /// Constructors
00162     Box4d();
00163     Box4d(TNT::Vector< Interval<double> >);
00164     Box4d(gmVector4 mincorner, gmVector4 maxcorner);
00165     Box4d(gmVector4 x);
00166     Box4d(Interval<double>,Interval<double>,Interval<double>,Interval<double>);
00167     Box4d(Interval<double>);
00168     Box4d(double d);
00169     Box4d(Box<double>);
00170    
00171     /// 'Corner' operators
00172     gmVector4 low();
00173     gmVector4 high();
00174 };
00175 
00176 #endif
00177 

Generated on Mon Jun 28 14:58:13 2004 for Advanced Surface Library by doxygen 1.3.4