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