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 #include "error.H"
00030 #include "treeBoundBox.H"
00031 #include "point.H"
00032 #include "Random.H"
00033
00034
00035
00036 namespace Foam
00037 {
00038
00039
00040
00041
00042 inline treeBoundBox::treeBoundBox()
00043 :
00044 boundBox()
00045 {}
00046
00047
00048
00049 inline treeBoundBox::treeBoundBox(const point& min, const point& max)
00050 :
00051 boundBox(min, max)
00052 {}
00053
00054
00055
00056 inline treeBoundBox::treeBoundBox(const boundBox& bb)
00057 :
00058 boundBox(bb)
00059 {}
00060
00061
00062
00063
00064
00065 inline direction treeBoundBox::subOctant(const point& sample) const
00066 {
00067 scalar midx = 0.5*(max().x() + min().x());
00068 scalar midy = 0.5*(max().y() + min().y());
00069 scalar midz = 0.5*(max().z() + min().z());
00070
00071 direction octant = 0;
00072
00073 if (sample.x() > midx)
00074 {
00075 octant |= treeBoundBox::RIGHTHALF;
00076 }
00077
00078 if (sample.y() > midy)
00079 {
00080 octant |= treeBoundBox::TOPHALF;
00081 }
00082
00083 if (sample.z() > midz)
00084 {
00085 octant |= treeBoundBox::FRONTHALF;
00086 }
00087
00088 return octant;
00089 }
00090
00091
00092
00093
00094 inline direction treeBoundBox::subOctant
00095 (
00096 const point& mid,
00097 const point& sample
00098 )
00099 {
00100 direction octant = 0;
00101
00102 if (sample.x() > mid.x())
00103 {
00104 octant |= treeBoundBox::RIGHTHALF;
00105 }
00106
00107 if (sample.y() > mid.y())
00108 {
00109 octant |= treeBoundBox::TOPHALF;
00110 }
00111
00112 if (sample.z() > mid.z())
00113 {
00114 octant |= treeBoundBox::FRONTHALF;
00115 }
00116
00117 return octant;
00118 }
00119
00120
00121
00122
00123 inline direction treeBoundBox::subOctant(const point& sample, bool& onEdge)
00124 const
00125 {
00126 point mid = 0.5*(max() + min());
00127
00128 direction octant = 0;
00129
00130 onEdge = false;
00131 if (sample.x() > mid.x())
00132 {
00133 octant |= treeBoundBox::RIGHTHALF;
00134 }
00135 else if (sample.x() == mid.x())
00136 {
00137 onEdge = true;
00138 }
00139
00140 if (sample.y() > mid.y())
00141 {
00142 octant |= treeBoundBox::TOPHALF;
00143 }
00144 else if (sample.y() == mid.y())
00145 {
00146 onEdge = true;
00147 }
00148
00149 if (sample.z() > mid.z())
00150 {
00151 octant |= treeBoundBox::FRONTHALF;
00152 }
00153 else if (sample.z() == mid.z())
00154 {
00155 onEdge = true;
00156 }
00157
00158 return octant;
00159 }
00160
00161
00162
00163
00164 inline direction treeBoundBox::subOctant
00165 (
00166 const point& mid,
00167 const point& sample,
00168 bool& onEdge
00169 )
00170 {
00171 direction octant = 0;
00172
00173 onEdge = false;
00174 if (sample.x() > mid.x())
00175 {
00176 octant |= treeBoundBox::RIGHTHALF;
00177 }
00178 else if (sample.x() == mid.x())
00179 {
00180 onEdge = true;
00181 }
00182
00183 if (sample.y() > mid.y())
00184 {
00185 octant |= treeBoundBox::TOPHALF;
00186 }
00187 else if (sample.y() == mid.y())
00188 {
00189 onEdge = true;
00190 }
00191
00192 if (sample.z() > mid.z())
00193 {
00194 octant |= treeBoundBox::FRONTHALF;
00195 }
00196 else if (sample.z() == mid.z())
00197 {
00198 onEdge = true;
00199 }
00200
00201 return octant;
00202 }
00203
00204
00205
00206
00207
00208
00209 inline direction treeBoundBox::subOctant
00210 (
00211 const point& mid,
00212 const vector& dir,
00213 const point& sample,
00214 bool& onEdge
00215 )
00216 {
00217 direction octant = 0;
00218
00219 onEdge = false;
00220
00221 if (sample.x() > mid.x())
00222 {
00223 octant |= treeBoundBox::RIGHTHALF;
00224 }
00225 else if (sample.x() == mid.x())
00226 {
00227 onEdge = true;
00228
00229 if (dir.x() > 0)
00230 {
00231 octant |= treeBoundBox::RIGHTHALF;
00232 }
00233 }
00234
00235 if (sample.y() > mid.y())
00236 {
00237 octant |= treeBoundBox::TOPHALF;
00238 }
00239 else if (sample.y() == mid.y())
00240 {
00241 onEdge = true;
00242
00243 if (dir.y() > 0)
00244 {
00245 octant |= treeBoundBox::TOPHALF;
00246 }
00247 }
00248
00249 if (sample.z() > mid.z())
00250 {
00251 octant |= treeBoundBox::FRONTHALF;
00252 }
00253 else if (sample.z() == mid.z())
00254 {
00255 onEdge = true;
00256
00257 if (dir.z() > 0)
00258 {
00259 octant |= treeBoundBox::FRONTHALF;
00260 }
00261 }
00262
00263 return octant;
00264 }
00265
00266
00267
00268
00269 inline bool treeBoundBox::intersects(const treeBoundBox& bb) const
00270 {
00271 return boundBox::intersects(bb);
00272 }
00273
00274
00275 inline bool treeBoundBox::contains(const point& sample) const
00276 {
00277 return
00278 (
00279 (sample.x() >= min().x()) &&
00280 (sample.y() >= min().y()) &&
00281 (sample.z() >= min().z()) &&
00282 (sample.x() <= max().x()) &&
00283 (sample.y() <= max().y()) &&
00284 (sample.z() <= max().z())
00285 );
00286 }
00287
00288
00289
00290 inline treeBoundBox treeBoundBox::extend(Random& rndGen, const scalar s) const
00291 {
00292 treeBoundBox bb(*this);
00293
00294 const vector span(bb.max() - bb.min());
00295
00296 bb.min() -= scale(s*rndGen.vector01(), span);
00297 bb.max() += scale(s*rndGen.vector01(), span);
00298
00299 return bb;
00300 }
00301
00302
00303
00304
00305 }
00306
00307
Copyright © 2000-2007 OpenCFD Ltd