boundBox.H
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #ifndef boundBox_H
00034 #define boundBox_H
00035
00036 #include "pointField.H"
00037
00038
00039
00040 namespace Foam
00041 {
00042
00043
00044
00045 class boundBox;
00046 template<class T> class tmp;
00047
00048 Ostream& operator<<(Ostream& os, const boundBox& b);
00049
00050
00051
00052
00053
00054
00055 class boundBox
00056 {
00057
00058
00059
00060 point min_, max_;
00061
00062
00063
00064
00065
00066 void calculate(const pointField&, const bool doReduce = true);
00067
00068 public:
00069
00070
00071
00072
00073 static const scalar great;
00074
00075
00076 static const boundBox greatBox;
00077
00078
00079 static const boundBox invertedBox;
00080
00081
00082
00083
00084
00085 boundBox()
00086 :
00087 min_(point::zero),
00088 max_(point::zero)
00089 {}
00090
00091
00092 boundBox(const point& min, const point& max)
00093 :
00094 min_(min),
00095 max_(max)
00096 {}
00097
00098
00099
00100 boundBox(const pointField&, const bool doReduce = true);
00101
00102
00103
00104 boundBox(const tmp<pointField>&, const bool doReduce = true);
00105
00106
00107 boundBox(Istream&);
00108
00109
00110
00111
00112
00113
00114
00115 const point& min() const
00116 {
00117 return min_;
00118 }
00119
00120
00121 const point& max() const
00122 {
00123 return max_;
00124 }
00125
00126
00127 point& min()
00128 {
00129 return min_;
00130 }
00131
00132
00133 point& max()
00134 {
00135 return max_;
00136 }
00137
00138
00139 point midpoint() const
00140 {
00141 return 0.5 * (max_ + min_);
00142 }
00143
00144
00145 vector span() const
00146 {
00147 return (max_ - min_);
00148 }
00149
00150
00151 scalar mag() const
00152 {
00153 return ::Foam::mag(max_ - min_);
00154 }
00155
00156
00157 scalar minDim() const
00158 {
00159 return cmptMin(span());
00160 }
00161
00162
00163 scalar maxDim() const
00164 {
00165 return cmptMax(span());
00166 }
00167
00168
00169 scalar avgDim() const
00170 {
00171 return cmptAv(span());
00172 }
00173
00174
00175
00176
00177
00178 bool overlaps(const boundBox& bb) const
00179 {
00180 return
00181 (
00182 bb.max_.x() >= min_.x() && bb.min_.x() <= max_.x()
00183 && bb.max_.y() >= min_.y() && bb.min_.y() <= max_.y()
00184 && bb.max_.z() >= min_.z() && bb.min_.z() <= max_.z()
00185 );
00186 }
00187
00188
00189 bool contains(const point& pt) const
00190 {
00191 return
00192 (
00193 pt.x() >= min_.x() && pt.x() <= max_.x()
00194 && pt.y() >= min_.y() && pt.y() <= max_.y()
00195 && pt.z() >= min_.z() && pt.z() <= max_.z()
00196 );
00197 }
00198
00199
00200 bool containsInside(const point& pt) const
00201 {
00202 return
00203 (
00204 pt.x() > min_.x() && pt.x() < max_.x()
00205 && pt.y() > min_.y() && pt.y() < max_.y()
00206 && pt.z() > min_.z() && pt.z() < max_.z()
00207 );
00208 }
00209
00210
00211
00212
00213 friend bool operator==(const boundBox& a, const boundBox& b)
00214 {
00215 return (a.min_ == b.min_) && (a.max_ == b.max_);
00216 }
00217
00218 friend bool operator!=(const boundBox& a, const boundBox& b)
00219 {
00220 return !(a == b);
00221 }
00222
00223
00224
00225
00226 friend Istream& operator>>(Istream& is, boundBox&);
00227 friend Ostream& operator<<(Ostream& os, const boundBox&);
00228 };
00229
00230
00231
00232 template<>
00233 inline bool contiguous<boundBox>() {return contiguous<point>();}
00234
00235
00236
00237
00238 }
00239
00240
00241
00242
00243
00244 #endif
00245
00246
Copyright © 2000-2009 OpenCFD Ltd