DirectionCone.h

00001 //===========================================================================
00002 // GoTools - SINTEF Geometry Tools version 1.1
00003 //
00004 // GoTools module: CORE
00005 //
00006 // Copyright (C) 2000-2007 SINTEF ICT, Applied Mathematics, Norway.
00007 //
00008 // This program is free software; you can redistribute it and/or          
00009 // modify it under the terms of the GNU General Public License            
00010 // as published by the Free Software Foundation version 2 of the License. 
00011 //
00012 // This program is distributed in the hope that it will be useful,        
00013 // but WITHOUT ANY WARRANTY; without even the implied warranty of         
00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          
00015 // GNU General Public License for more details.                           
00016 //
00017 // You should have received a copy of the GNU General Public License      
00018 // along with this program; if not, write to the Free Software            
00019 // Foundation, Inc.,                                                      
00020 // 59 Temple Place - Suite 330,                                           
00021 // Boston, MA  02111-1307, USA.                                           
00022 //
00023 // Contact information: E-mail: tor.dokken@sintef.no                      
00024 // SINTEF ICT, Department of Applied Mathematics,                         
00025 // P.O. Box 124 Blindern,                                                 
00026 // 0314 Oslo, Norway.                                                     
00027 //
00028 // Other licenses are also available for this software, notably licenses
00029 // for:
00030 // - Building commercial software.                                        
00031 // - Building software whose source code you wish to keep private.        
00032 //===========================================================================
00033 #ifndef _DIRECTIONCONE_H
00034 #define _DIRECTIONCONE_H
00035 
00036 #include "Point.h"
00037 
00038 namespace Go {
00041 
00042 
00052 class DirectionCone {
00053 public:
00055     DirectionCone() : greater_than_pi_(-1), zero_tol_(0.0) {}
00056 
00061     DirectionCone(const Point& pt)
00062         : centre_(pt), angle_(0.0), greater_than_pi_(0), zero_tol_(0.0)
00063     {
00064         if (pt.length() > 0.0)
00065             centre_.normalize();
00066     }
00067 
00072     DirectionCone(const Point& centre, double angle)
00073         : centre_(centre), angle_(angle), zero_tol_(0.0)
00074     {
00075         if (centre_.length() > 0.0)
00076             centre_.normalize();
00077         check_angle();
00078     }
00079     
00081     ~DirectionCone() { }
00082 
00090     void setFromArray(const double* start, const double* end, int dim);
00091 
00094     int dimension() const { return centre_.size(); }
00095 
00097     const Point& centre() const { return centre_; }
00098 
00100     double angle() const { return angle_; }
00101 
00105     int greaterThanPi() const { return greater_than_pi_; }
00106 
00109     bool overlaps(const DirectionCone& cone) const;
00110 
00113     bool perpendicularOverlaps(const DirectionCone& cone) const;
00114 
00117     bool containsDirection(const Point& pt, double tol = 0.0) const;
00118 
00121     void addUnionWith(const Point& pt);
00122 
00125     void addUnionWith(const DirectionCone& cone);
00126 
00128     void read(std::istream& is);
00129 
00131     void write(std::ostream& os) const;
00132 
00133 //     void setZeroTol(double zero_tol)
00134 //     {
00135 //      zero_tol_ = zero_tol;
00136 //     }
00137 
00138 private:
00139 
00140     void check_angle() const;
00141 
00142     Point centre_;
00143     double angle_;
00144     mutable int greater_than_pi_;
00145 
00146     double zero_tol_; // By default the zero-tol is 0.0. Used in greaterThanPi().
00147 
00148 };
00149 
00150 
00152 } // namespace Go
00153 
00154 
00155 #endif // _DIRECTIONCONE_H
00156 
00157 

Generated on Mon Jun 11 14:48:18 2007 for GoTools Core Library by  doxygen 1.5.1