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