cgma
CubitBox.hpp
Go to the documentation of this file.
00001 //- Class: CubitBox
00002 //-
00003 //- Description: This file defines the CubitBox class which represents
00004 //- an axis-aligned rectangular box which can be uses as a bounding box.
00005 //-
00006 //- Owner: Greg Sjaardema
00007 //- Checked by: 
00008 //- Version: $Id: 
00009 
00010 #ifndef CUBITBOX_HPP
00011 #define CUBITBOX_HPP
00012 
00013 #include "CubitVector.hpp"
00014 #include "CubitBoxStruct.h"
00015 #include "CGMUtilConfigure.h"
00016 #include <vector>
00017 
00018 class CUBIT_UTIL_EXPORT CubitBox
00019 {
00020 public:
00021     //- Heading: Constructors and Destructor
00022   CubitBox(); 
00023     //- Default constructor.
00024   
00025   CubitBox(const CubitVector &min, const CubitVector &max);
00026     //- Constructor: create box from two CubitVectors
00027   
00028   CubitBox(const double min[3], const double max[3] );
00029     //- Constructor: create box from two coordinates
00030   
00031   CubitBox(const CubitVector &min_max);
00032     //- Constructor: create box from one CubitVector
00033   
00034   CubitBox(const CubitBox& copy_from);  //- Copy Constructor
00035   
00036   CubitBox(const CubitBoxStruct& from);
00037 
00038   CubitBox(const std::vector<CubitVector> & pts);
00039   
00040   ~CubitBox(); 
00041     //- destructor
00042     
00043   CubitBox& bounding_box();
00044   
00045   
00046   void reset(const CubitVector &vector);
00047   void reset(const CubitVector &min, const CubitVector &max);
00048   void reset(const CubitBox &box);
00049   void reset(const double min[3], const double max[3]);
00050     //- reset ranges
00051 
00052   double max_x() const;
00053   double max_y() const;
00054   double max_z() const;
00055 
00056   double min_x() const;
00057   double min_y() const;
00058   double min_z() const;
00059 
00060   CubitVector minimum()  const;
00061   CubitVector maximum()  const;
00062   CubitVector center()   const;
00063   CubitVector diagonal() const;
00064     //- Return Box minimum/maximum/center
00065   
00066   void get_corners ( CubitVector corners[8] ) const;
00067     //- Fills 'corners' with the corners of this box.
00068     //- The order is:
00069     //-   0) minimum()
00070     //-   1-3) Front face (Constant minimum z-plane), normal out of box
00071     //-        using right hand rule, including corner[0].
00072     //-   4-7) Same as 0-3, but offset to back face
00073     //-        (constant maximum z-plane).  Normal of these last 4 points
00074     //-        is into box relative to back plane (same direction as
00075     //-        normal w/ first 4 points).  Maximum ends up at index 6.
00076   
00077   double x_range() const;
00078   double y_range() const;
00079   double z_range() const;
00080     //- x, y, and z range of the box (max - min)
00081   
00082   double minimum_range( void);
00083   double maximum_range( void);
00084   //- returns the maimum and maximum range 
00085 
00086   bool overlap( double tolerance, const CubitBox& other_box ) const;
00087     //- Check if boxes are within passed tolerance of each other.
00088     //- If tolerance is 0, use && or || operator.
00089   
00090   bool intersect(const CubitVector& ray_origin, const CubitVector& ray_direction,
00091       CubitVector& intersection_pt);
00092     //- Check if ray intersects box and returns an intersection point
00093 
00094 
00095   bool intersect(const CubitVector& ray_origin, const CubitVector& ray_direction);
00096     //- Check if ray intersects box but doesn't calculate an intersection point.
00097 
00098 
00099 
00100 
00101     //- Heading: Operators
00102 
00103     // Operators that modify {this}
00104   CubitBox& operator=(const CubitBox &box);
00105   CubitBox& operator|=(const CubitBox& box);
00106   CubitBox& operator|=(const CubitVector& vector);
00107   CubitBox& operator&=(const CubitBox& box);
00108   CubitBox& operator*=(double scale);
00109   CubitBox& operator/=(double scale);
00110   CubitBox& operator+=(const CubitVector& offset);
00111   CubitBox& operator-=(const CubitVector& offset);
00112     //- {=}  - Assignment
00113     //- {|=} - Union of {this} and {box}
00114     //- {&=} - Intersection (overlap) of {this} and {box}
00115     //- {*=} - Scale {this} about box center
00116     //- {/=} - Scale {this} about box center
00117     //- {+=} - Move {this} by {offset}  CubitVector
00118     //- {-=} - Move {this} by {-offset} CubitVector
00119   
00120     // Operators that check for containment
00121   int operator< (const CubitBox& box) const;
00122   int operator<=(const CubitBox& box) const;
00123   int operator> (const CubitBox& box) const;
00124   int operator>=(const CubitBox& box) const;
00125   int operator> (const CubitVector& vect) const;
00126   int operator>=(const CubitVector& vect) const;
00127   int operator<=(const CubitVector& vect) const;
00128   int operator&&(const CubitBox& box) const;
00129   int operator||(const CubitBox& box) const;
00130     //- {<}  - Is {this} completely surrounded by {box}?
00131     //- {>}  - Does {this} completely surround {box}?
00132     //- {<=,>=} - As above, but inner box may touch
00133     //-           boundary of outer box.
00134     //- {>}  - Is {vect} contained within {this}, but not on boundary?
00135     //- {>=} - Is {vect} contained within or on the boundary of {this}?
00136     //- {<=} - Is {vect} outside or on boundary of {this}?
00137     //- {&&} - Do {this} and {box} intersect?  Just butting against each
00138     //-        other also counts as an intersection. See {||}.
00139     //- {||} - Do {this} and {box} intersect?  Just butting against each
00140     //-        other does NOT count as an intersection.  See {&&}.
00141   
00142   CubitBox &operator=(const CubitBoxStruct &from);
00143 
00144   operator CubitBoxStruct() 
00145     {
00146       CubitBoxStruct to;
00147       to.minimum_ = minimum_;
00148       to.maximum_ = maximum_;
00149       return to;
00150     }
00151 
00152     // Operators that return a modification of {this}.
00153     // {this} itself is not modified.
00154   friend CUBIT_UTIL_EXPORT CubitBox operator|(const CubitBox& lhs, const CubitBox& rhs);
00155   friend CUBIT_UTIL_EXPORT CubitBox operator|(const CubitBox& lhs, const CubitVector& rhs);
00156   friend CUBIT_UTIL_EXPORT CubitBox operator&(const CubitBox& lhs, const CubitBox& rhs);
00157   friend CUBIT_UTIL_EXPORT CubitBox operator*(const CubitBox& lhs, double rhs);
00158   friend CUBIT_UTIL_EXPORT CubitBox operator*(double rhs, const CubitBox& lhs);
00159   friend CUBIT_UTIL_EXPORT CubitBox operator/(const CubitBox& lhs, double rhs);
00160   friend CUBIT_UTIL_EXPORT CubitBox operator+(const CubitBox& lhs, const CubitVector& rhs);
00161   friend CUBIT_UTIL_EXPORT CubitBox operator-(const CubitBox& lhs, const CubitVector& rhs);
00162   
00163     double distance_squared( const CubitVector& position ) const;
00164   
00165   CubitVector closest_point( const CubitVector& position ) const;
00166     //R CubitVector
00167     //R- The closest point on the box to the passed position.
00168     //R- The passed position will be returned if it is within
00169     //R- the box.
00170     //I- A position from which to evaluate the closest point
00171     //I- on the box.
00172   
00173 private:
00174   
00175   CubitVector minimum_; //- X, Y, and Z position of minimum corner
00176   CubitVector maximum_; //- X, Y, and Z position of maximum corner
00177 };
00178 
00179 inline CubitBox& CubitBox::operator=(const CubitBoxStruct &from)  
00180 {
00181   minimum_ = from.minimum_;
00182   maximum_ = from.maximum_;
00183   return *this;
00184 }
00185 
00186 inline CubitBox::CubitBox(const CubitBoxStruct &from)  
00187 {
00188   minimum_ = from.minimum_;
00189   maximum_ = from.maximum_;
00190 }
00191 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines