00001 /*---------------------------------------------------------------------------*\ 00002 ========= | 00003 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox 00004 \\ / O peration | 00005 \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd. 00006 \\/ M anipulation | 00007 ------------------------------------------------------------------------------- 00008 License 00009 This file is part of OpenFOAM. 00010 00011 OpenFOAM is free software: you can redistribute it and/or modify it 00012 under the terms of the GNU General Public License as published by 00013 the Free Software Foundation, either version 3 of the License, or 00014 (at your option) any later version. 00015 00016 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT 00017 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00018 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 00019 for more details. 00020 00021 You should have received a copy of the GNU General Public License 00022 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. 00023 00024 Class 00025 Foam::treeBoundBox 00026 00027 Description 00028 Standard boundBox + extra functionality for use in octree. 00029 00030 Numbering of corner points is according to octant numbering. 00031 00032 On the back plane (z=0): 00033 00034 @verbatim 00035 Y 00036 ^ 00037 | 00038 +--------+ 00039 |2 3| 00040 | | 00041 | | 00042 | | 00043 |0 1| 00044 +--------+->X 00045 @endverbatim 00046 00047 For the front plane add 4 to the point labels. 00048 00049 00050 SourceFiles 00051 treeBoundBoxI.H 00052 treeBoundBox.C 00053 00054 \*---------------------------------------------------------------------------*/ 00055 00056 #ifndef treeBoundBox_H 00057 #define treeBoundBox_H 00058 00059 #include <OpenFOAM/boundBox.H> 00060 #include <OpenFOAM/direction.H> 00061 #include <OpenFOAM/pointField.H> 00062 #include <OpenFOAM/faceList.H> 00063 00064 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00065 00066 namespace Foam 00067 { 00068 00069 class Random; 00070 00071 /*---------------------------------------------------------------------------*\ 00072 Class treeBoundBox Declaration 00073 \*---------------------------------------------------------------------------*/ 00074 00075 class treeBoundBox 00076 : 00077 public boundBox 00078 { 00079 00080 private: 00081 00082 //- To initialise faceNormals. 00083 static FixedList<vector, 6> calcFaceNormals(); 00084 00085 public: 00086 00087 // Static data members 00088 00089 //- The great value used for greatBox and invertedBox 00090 static const scalar great; 00091 00092 //- As per boundBox::greatBox, but with GREAT instead of VGREAT 00093 static const treeBoundBox greatBox; 00094 00095 //- As per boundBox::invertedBox, but with GREAT instead of VGREAT 00096 static const treeBoundBox invertedBox; 00097 00098 //- Bits used for octant/point coding. 00099 // Every octant/corner point is the combination of three faces. 00100 enum octantBit 00101 { 00102 RIGHTHALF = 0x1 << 0, 00103 TOPHALF = 0x1 << 1, 00104 FRONTHALF = 0x1 << 2 00105 }; 00106 00107 //- Face codes 00108 enum faceId 00109 { 00110 LEFT = 0, 00111 RIGHT = 1, 00112 BOTTOM = 2, 00113 TOP = 3, 00114 BACK = 4, 00115 FRONT = 5 00116 }; 00117 00118 //- Bits used for face coding 00119 enum faceBit 00120 { 00121 NOFACE = 0, 00122 LEFTBIT = 0x1 << LEFT, //1 00123 RIGHTBIT = 0x1 << RIGHT, //2 00124 BOTTOMBIT = 0x1 << BOTTOM, //4 00125 TOPBIT = 0x1 << TOP, //8 00126 BACKBIT = 0x1 << BACK, //16 00127 FRONTBIT = 0x1 << FRONT, //32 00128 }; 00129 00130 //- Edges codes. 00131 // E01 = edge between 0 and 1. 00132 enum edgeId 00133 { 00134 E01 = 0, 00135 E13 = 1, 00136 E23 = 2, 00137 E02 = 3, 00138 00139 E45 = 4, 00140 E57 = 5, 00141 E67 = 6, 00142 E46 = 7, 00143 00144 E04 = 8, 00145 E15 = 9, 00146 E37 = 10, 00147 E26 = 11 00148 }; 00149 00150 //- Face to point addressing 00151 static const faceList faces; 00152 00153 //- Edge to point addressing 00154 static const edgeList edges; 00155 00156 //- Per face the unit normal 00157 static const FixedList<vector, 6> faceNormals; 00158 00159 00160 //- Face on which neighbour is 00161 static direction neighbourFaceBits(const label&); 00162 00163 00164 // Constructors 00165 00166 //- Construct null setting points to zero 00167 inline treeBoundBox(); 00168 00169 //- Construct from components 00170 inline treeBoundBox(const point& min, const point& max); 00171 00172 //- Construct from components 00173 explicit inline treeBoundBox(const boundBox& bb); 00174 00175 //- Construct as the bounding box of the given pointField. 00176 // Local processor domain only (no reduce as in boundBox) 00177 explicit treeBoundBox(const UList<point>&); 00178 00179 //- Construct as subset of points 00180 // Local processor domain only (no reduce as in boundBox) 00181 treeBoundBox(const UList<point>&, const UList<label>& meshPoints); 00182 00183 //- Construct from Istream 00184 treeBoundBox(Istream&); 00185 00186 00187 // Member functions 00188 00189 // Access 00190 00191 //- Typical dimension length,height,width 00192 inline scalar typDim() const; 00193 00194 //- vertex coordinates. In octant coding. 00195 pointField points() const; 00196 00197 00198 // Check 00199 00200 //- Corner point given octant 00201 inline point corner(const direction) const; 00202 00203 //- Sub box given by octant number. Midpoint calculated. 00204 treeBoundBox subBbox(const direction) const; 00205 00206 //- Sub box given by octant number. Midpoint provided. 00207 treeBoundBox subBbox(const point& mid, const direction) const; 00208 00209 //- Returns octant number given point and the calculated midpoint. 00210 inline direction subOctant 00211 ( 00212 const point& pt 00213 ) const; 00214 00215 //- Returns octant number given point and midpoint. 00216 static inline direction subOctant 00217 ( 00218 const point& mid, 00219 const point& pt 00220 ); 00221 00222 //- Returns octant number given point and the calculated midpoint. 00223 // onEdge set if the point is on edge of subOctant 00224 inline direction subOctant 00225 ( 00226 const point& pt, 00227 bool& onEdge 00228 ) const; 00229 00230 //- Returns octant number given point and midpoint. 00231 // onEdge set if the point is on edge of subOctant 00232 static inline direction subOctant 00233 ( 00234 const point& mid, 00235 const point& pt, 00236 bool& onEdge 00237 ); 00238 00239 //- Returns octant number given intersection and midpoint. 00240 // onEdge set if the point is on edge of subOctant 00241 // If onEdge, the direction vector determines which octant to use 00242 // (acc. to which octant the point would be if it were moved 00243 // along dir) 00244 static inline direction subOctant 00245 ( 00246 const point& mid, 00247 const vector& dir, 00248 const point& pt, 00249 bool& onEdge 00250 ); 00251 00252 //- Calculates optimal order to look for nearest to point. 00253 // First will be the octant containing the point, 00254 // second the octant with boundary nearest to the point etc. 00255 inline void searchOrder 00256 ( 00257 const point& pt, 00258 FixedList<direction, 8>& octantOrder 00259 ) const; 00260 00261 //- Overlaps other boundingbox? 00262 inline bool overlaps(const treeBoundBox&) const; 00263 00264 //- Overlaps boundingSphere (centre + sqr(radius))? 00265 bool overlaps(const point&, const scalar radiusSqr) const; 00266 00267 //- Intersects segment; set point to intersection position and face, 00268 // return true if intersection found. 00269 // (pt argument used during calculation even if not intersecting). 00270 // Calculates intersections from outside supplied vector 00271 // (overallStart, overallVec). This is so when 00272 // e.g. tracking through lots of consecutive boxes 00273 // (typical octree) we're not accumulating truncation errors. Set 00274 // to start, (end-start) if not used. 00275 bool intersects 00276 ( 00277 const point& overallStart, 00278 const vector& overallVec, 00279 const point& start, 00280 const point& end, 00281 point& pt, 00282 direction& ptBits 00283 ) const; 00284 00285 //- Like above but does not return faces point is on 00286 bool intersects 00287 ( 00288 const point& start, 00289 const point& end, 00290 point& pt 00291 ) const; 00292 00293 //- fully contains other boundingBox? 00294 inline bool contains(const treeBoundBox&) const; 00295 00296 //- Contains point? (inside or on edge) 00297 inline bool contains(const point&) const; 00298 00299 //- Contains point (inside or on edge) and moving in direction 00300 // dir would cause it to go inside. 00301 bool contains(const vector& dir, const point&) const; 00302 00303 //- Code position of pt on bounding box faces 00304 direction faceBits(const point& pt) const; 00305 00306 //- Position of point relative to bounding box 00307 direction posBits(const point&) const; 00308 00309 //- Calculate nearest and furthest (to point) vertex coords of 00310 // bounding box 00311 void calcExtremities 00312 ( 00313 const point& pt, 00314 point& nearest, 00315 point& furthest 00316 ) const; 00317 00318 //- Returns distance point to furthest away corner. 00319 scalar maxDist(const point&) const; 00320 00321 //- Compare distance to point with other bounding box 00322 // return: 00323 // -1 : all vertices of my bounding box are nearer than any of 00324 // other 00325 // +1 : all vertices of my bounding box are further away than 00326 // any of other 00327 // 0 : none of the above. 00328 label distanceCmp(const point&, const treeBoundBox& other) const; 00329 00330 //- Return slightly wider bounding box 00331 // Extends all dimensions with s*span*Random::scalar01() 00332 // and guarantees in any direction s*mag(span) minimum width 00333 inline treeBoundBox extend(Random&, const scalar s) const; 00334 00335 // Friend Operators 00336 00337 friend bool operator==(const treeBoundBox&, const treeBoundBox&); 00338 friend bool operator!=(const treeBoundBox&, const treeBoundBox&); 00339 00340 // IOstream operator 00341 00342 friend Istream& operator>>(Istream& is, treeBoundBox&); 00343 friend Ostream& operator<<(Ostream& os, const treeBoundBox&); 00344 00345 }; 00346 00347 00348 //- Data associated with treeBoundBox type are contiguous 00349 template<> 00350 inline bool contiguous<treeBoundBox>() {return contiguous<boundBox>();} 00351 00352 00353 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00354 00355 } // End namespace Foam 00356 00357 #include <meshTools/treeBoundBoxI.H> 00358 00359 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00360 00361 #endif 00362 00363 // ************************ vim: set sw=4 sts=4 et: ************************ //