//=========================================================================== // GoTools Core - SINTEF Geometry Tools Core library, version 2.0.1 // // Copyright (C) 2000-2007, 2010 SINTEF ICT, Applied Mathematics, Norway. // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License // as published by the Free Software Foundation version 2 of the License. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., // 59 Temple Place - Suite 330, // Boston, MA 02111-1307, USA. // // Contact information: E-mail: tor.dokken@sintef.no // SINTEF ICT, Department of Applied Mathematics, // P.O. Box 124 Blindern, // 0314 Oslo, Norway. // // Other licenses are also available for this software, notably licenses // for: // - Building commercial software. // - Building software whose source code you wish to keep private. //=========================================================================== 00013 #ifndef _BOUNDINGBOX_H 00014 #define _BOUNDINGBOX_H 00015 00016 #include "GoTools/utils/Point.h" 00017 #include <vector> 00018 #include "GoTools/utils/config.h" 00019 00020 namespace Go 00021 { 00022 00023 00029 class GO_API BoundingBox 00030 { 00031 public: 00034 BoundingBox() : valid_(false) {} 00037 explicit BoundingBox(int dim) 00038 : low_(dim), high_(dim), valid_(false) {} 00042 BoundingBox(const Point& low, const Point& high) 00043 : low_(low), high_(high), valid_(false) { check(); } 00045 ~BoundingBox(); 00046 00049 void setFromPoints(const Point& low, const Point& high); 00050 00054 template <typename FloatType> 00055 void setFromArray(const FloatType* start, const FloatType* end, int dim) 00056 { 00057 low_ = Point(start, start+dim); 00058 high_ = Point(start, start+dim); 00059 start += dim; 00060 while (start != end) { 00061 for (int d = 0; d < dim; ++d) { 00062 if (start[d] < low_[d]) { 00063 low_[d] = start[d]; 00064 } else if (start[d] > high_[d]) { 00065 high_[d] = start[d]; 00066 } 00067 } 00068 start += dim; 00069 } 00070 00071 check(); 00072 } 00076 template <typename ForwardIterator> 00077 void setFromArray(ForwardIterator start, 00078 ForwardIterator end, int dim) 00079 { 00080 low_ = Point(start, start+dim); 00081 high_ = Point(start, start+dim); 00082 start += dim; 00083 while (start != end) { 00084 for (int d = 0; d < dim; ++d) { 00085 if (start[d] < low_[d]) { 00086 low_[d] = start[d]; 00087 } else if (start[d] > high_[d]) { 00088 high_[d] = start[d]; 00089 } 00090 } 00091 start += dim; 00092 } 00093 00094 check(); 00095 } 00098 void setFromPoints(const std::vector<Point>& points) 00099 { 00100 int dim = points[0].dimension(); 00101 low_ = points[0]; 00102 high_ = points[0]; 00103 for (size_t i = 1; i < points.size(); ++i) { 00104 for (int d = 0; d < dim; ++d) { 00105 if (points[i][d] < low_[d]) { 00106 low_[d] = points[i][d]; 00107 } else if (points[i][d] > high_[d]) { 00108 high_[d] = points[i][d]; 00109 } 00110 } 00111 } 00112 00113 check(); 00114 } 00115 00117 void read(std::istream& is); 00119 void write(std::ostream& os) const; 00120 00122 int dimension() const { return low_.size(); } 00123 00125 const Point& low() const { return low_; } 00127 const Point& high() const { return high_; } 00128 00131 bool containsPoint(const Point& pt, double tol = 0.0) const; 00132 00135 bool overlaps(const BoundingBox& box, double tol = 0.0) const; 00136 bool getOverlap(const BoundingBox& box, double& overlap, double tol = 0.0) const; 00139 bool containsBox(const BoundingBox& box, double tol = 0.0) const; 00140 00143 void addUnionWith(const Point& pt); 00146 void addUnionWith(const BoundingBox& box); 00147 00149 bool valid() const { return valid_; } 00150 00153 void check() const; 00154 00155 private: 00156 // Data members 00157 Point low_; 00158 Point high_; 00159 mutable bool valid_; 00160 }; 00161 00162 00163 } // namespace Go 00164 00165 00166 namespace std { 00167 00168 00170 inline std::istream& operator >> (std::istream& is, 00171 Go::BoundingBox& bbox) 00172 { 00173 bbox.read(is); 00174 return is; 00175 } 00176 00177 00179 inline std::ostream& operator << (std::ostream& os, 00180 const Go::BoundingBox& bbox) 00181 { 00182 bbox.write(os); 00183 return os; 00184 } 00185 00186 00187 } // namespace std 00188 00189 00190 #endif // _BOUNDINGBOX_H
Generated on Tue Sep 21 15:44:17 2010 for GoTools Core by  doxygen 1.6.3