1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
11 OpenFOAM is free software; you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by the
13 Free Software Foundation; either version 2 of the License, or (at your
14 option) any later version.
16 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM; if not, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
29 Standard boundBox + extra functionality for use in octree.
31 Numbering of corner points is according to octant numbering.
33 On the back plane (z=0):
48 For the front plane add 4 to the point labels.
55 \*---------------------------------------------------------------------------*/
57 #ifndef treeBoundBox_H
58 #define treeBoundBox_H
61 #include "direction.H"
62 #include "pointField.H"
65 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
72 /*---------------------------------------------------------------------------*\
73 Class treeBoundBox Declaration
74 \*---------------------------------------------------------------------------*/
83 //- To initialise faceNormals.
84 static FixedList<vector, 6> calcFaceNormals();
88 // Static data members
90 //- The great value used for greatBox and invertedBox
91 static const scalar great;
93 //- As per boundBox::greatBox, but with GREAT instead of VGREAT
94 static const treeBoundBox greatBox;
96 //- As per boundBox::invertedBox, but with GREAT instead of VGREAT
97 static const treeBoundBox invertedBox;
99 //- Bits used for octant/point coding.
100 // Every octant/corner point is the combination of three faces.
103 RIGHTHALF = 0x1 << 0,
119 //- Bits used for face coding
123 LEFTBIT = 0x1 << LEFT, //1
124 RIGHTBIT = 0x1 << RIGHT, //2
125 BOTTOMBIT = 0x1 << BOTTOM, //4
126 TOPBIT = 0x1 << TOP, //8
127 BACKBIT = 0x1 << BACK, //16
128 FRONTBIT = 0x1 << FRONT, //32
132 // E01 = edge between 0 and 1.
151 //- Face to point addressing
152 static const faceList faces;
154 //- Edge to point addressing
155 static const edgeList edges;
157 //- Per face the unit normal
158 static const FixedList<vector, 6> faceNormals;
161 //- Face on which neighbour is
162 static direction neighbourFaceBits(const label&);
167 //- Construct null setting points to zero
168 inline treeBoundBox();
170 //- Construct from components
171 inline treeBoundBox(const point& min, const point& max);
173 //- Construct from components
174 inline treeBoundBox(const boundBox& bb);
176 //- Construct as the bounding box of the given pointField.
177 // Local processor domain only (no reduce as in boundBox)
178 treeBoundBox(const UList<point>&);
180 //- Construct as subset of points
181 // Local processor domain only (no reduce as in boundBox)
182 treeBoundBox(const UList<point>&, const UList<label>& meshPoints);
184 //- Construct from Istream
185 treeBoundBox(Istream&);
192 //- Typical dimension length,height,width
193 inline scalar typDim() const;
195 //- vertex coordinates. In octant coding.
196 pointField points() const;
201 //- Corner point given octant
202 inline point corner(const direction) const;
204 //- Sub box given by octant number. Midpoint calculated.
205 treeBoundBox subBbox(const direction) const;
207 //- Sub box given by octant number. Midpoint provided.
208 treeBoundBox subBbox(const point& mid, const direction) const;
210 //- Returns octant number given point and the calculated midpoint.
211 inline direction subOctant
216 //- Returns octant number given point and midpoint.
217 static inline direction subOctant
223 //- Returns octant number given point and the calculated midpoint.
224 // onEdge set if the point is on edge of subOctant
225 inline direction subOctant
231 //- Returns octant number given point and midpoint.
232 // onEdge set if the point is on edge of subOctant
233 static inline direction subOctant
240 //- Returns octant number given intersection and midpoint.
241 // onEdge set if the point is on edge of subOctant
242 // If onEdge, the direction vector determines which octant to use
243 // (acc. to which octant the point would be if it were moved
245 static inline direction subOctant
253 //- Calculates optimal order to look for nearest to point.
254 // First will be the octant containing the point,
255 // second the octant with boundary nearest to the point etc.
256 inline void searchOrder
259 FixedList<direction, 8>& octantOrder
262 //- Overlaps other boundingbox?
263 inline bool overlaps(const treeBoundBox&) const;
265 //- Overlaps boundingSphere (centre + sqr(radius))?
266 bool overlaps(const point&, const scalar radiusSqr) const;
268 //- Intersects segment; set point to intersection position and face,
269 // return true if intersection found.
270 // (pt argument used during calculation even if not intersecting).
271 // Calculates intersections from outside supplied vector
272 // (overallStart, overallVec). This is so when
273 // e.g. tracking through lots of consecutive boxes
274 // (typical octree) we're not accumulating truncation errors. Set
275 // to start, (end-start) if not used.
278 const point& overallStart,
279 const vector& overallVec,
286 //- Like above but does not return faces point is on
294 //- fully contains other boundingBox?
295 inline bool contains(const treeBoundBox&) const;
297 //- Contains point? (inside or on edge)
298 inline bool contains(const point&) const;
300 //- Contains point (inside or on edge) and moving in direction
301 // dir would cause it to go inside.
302 bool contains(const vector& dir, const point&) const;
304 //- Code position of pt on bounding box faces
305 direction faceBits(const point& pt) const;
307 //- Position of point relative to bounding box
308 direction posBits(const point&) const;
310 //- Calculate nearest and furthest (to point) vertex coords of
319 //- Returns distance point to furthest away corner.
320 scalar maxDist(const point&) const;
322 //- Compare distance to point with other bounding box
324 // -1 : all vertices of my bounding box are nearer than any of
326 // +1 : all vertices of my bounding box are further away than
328 // 0 : none of the above.
329 label distanceCmp(const point&, const treeBoundBox& other) const;
331 //- Return slightly wider bounding box
332 // Extends all dimensions with s*span*Random::scalar01()
333 // and guarantees in any direction s*mag(span) minimum width
334 inline treeBoundBox extend(Random&, const scalar s) const;
338 friend bool operator==(const treeBoundBox&, const treeBoundBox&);
339 friend bool operator!=(const treeBoundBox&, const treeBoundBox&);
343 friend Istream& operator>>(Istream& is, treeBoundBox&);
344 friend Ostream& operator<<(Ostream& os, const treeBoundBox&);
349 //- Data associated with treeBoundBox type are contiguous
351 inline bool contiguous<treeBoundBox>() {return contiguous<boundBox>();}
354 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
356 } // End namespace Foam
358 #include "treeBoundBoxI.H"
360 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
364 // ************************************************************************* //