Go to Overview over all GrAL packages.
Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

Geometry/box.h

Go to the documentation of this file.
00001 #ifndef NMWR_GB_GEOMETRY_BOX_H
00002 #define NMWR_GB_GEOMETRY_BOX_H
00003 
00004 // $LICENSE
00005 
00006 
00007 #include <algorithm>
00008 #include "Geometry/point-traits.h"
00009 
00025 template<class coord>
00026 class box {
00027   typedef box<coord>          self;
00028   typedef point_traits<coord> pt;
00029 private:
00030   coord minc, maxc;
00031 public:
00032   // box() // empty box: minc[] = + \infty, maxc[i] = -\infty
00033     // => |= works correctly
00034   box(const coord& cmin) : minc(cmin), maxc(cmin) {}
00035   box(const coord& cmin, const coord& cmax) : minc(cmin), maxc(cmin) 
00036     { *this |= cmax; }
00037 
00038   const coord& the_min() const { return minc;}
00039   const coord& the_max() const { return maxc;}
00040   coord        center()  const { return 0.5*(minc+maxc);}
00041 
00042   // dangerous - cannot check consistency
00043   coord& the_min()  { return minc;}
00044   coord& the_max()  { return maxc;}
00045 
00046   // (0,..,0) -> minc , (1,...,1) -> max
00047   coord global_coords(const coord& local) const {
00048     coord res = minc;
00049     for(int i = pt::LowerIndex(res); i <= pt::UpperIndex(res); ++i) {
00050       res[i] = (1-local[i]) * minc[i] + local[i] * maxc[i];
00051     }
00052     return res;
00053   }
00054   // function interface
00055   typedef coord argument_type;
00056   typedef coord result_type;
00057   coord operator()(const coord& local) const
00058     { return global_coords(local); }
00059 
00060   bool contains(coord const& p) const {
00061     bool res = true;
00062     for(int i = pt::LowerIndex(p); i <= pt::UpperIndex(p); ++i) {
00063       res = res && (p[i] >= minc[i]) && (p[i] <= maxc[i]);
00064     }
00065     return res;
00066   }
00067   
00068   // bool element(const coord& p) const;
00069   // bool empty() const;
00070 
00071   // intersection
00072   // self& operator &=(self const&);
00073   //  self operator & (const self& ls, const self& rs)
00074   // closure of union
00075   self & operator |= (self const& rs)
00076     {
00077       for(int i = pt::LowerIndex(minc); i <= pt::UpperIndex(minc); ++i) {
00078           minc[i] = std::min(minc[i],rs.minc[i]);
00079           maxc[i] = std::max(maxc[i],rs.maxc[i]);
00080       }
00081       return *this;
00082     }
00083   friend self operator | (const self& ls, const self& rs)
00084     { 
00085       self res(ls);
00086       return res |= rs;
00087     }
00088   /*
00089       coord new_min(ls.minc), new_max(ls.maxc);
00090       for(int i = pt::LowerIndex(new_min); i <= pt::UpperIndex(new_min); ++i) {
00091           new_min[i] = min(new_min[i],rs.minc[i]);
00092           new_max[i] = max(new_max[i],rs.maxc[i]);
00093       }
00094       return self(new_min,new_max);
00095     }
00096   */
00097 };
00098 
00099 #endif
00100 
00101 

Copyright (c) Guntram Berti 1997-2002. See the GrAL Homepage for up-to-date information.

Generated at Tue Feb 26 15:57:26 2002 for Geometry by doxygen 1.2.11-20011104 written by Dimitri van Heesch, © 1997-2000