1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2008 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 static const treeBoundBox greatBox;
92 //- Bits used for octant/point coding. Every octant/corner point
93 // is the combination of three faces.
112 //- Bits used for face coding
116 LEFTBIT = 0x1 << LEFT,
117 RIGHTBIT = 0x1 << RIGHT,
118 BOTTOMBIT = 0x1 << BOTTOM,
120 BACKBIT = 0x1 << BACK,
121 FRONTBIT = 0x1 << FRONT,
125 // E01 = edge between 0 and 1.
144 //- Face to point addressing
145 static const faceList faces;
147 //- Edge to point addressing
148 static const edgeList edges;
150 //- Per face the unit normal
151 static const FixedList<vector, 6> faceNormals;
154 //- Face on which neighbour is
155 static direction neighbourFaceBits(const label&);
160 //- Construct null setting points to zero
161 inline treeBoundBox();
163 //- Construct from components
164 inline treeBoundBox(const point& min, const point& max);
166 //- Construct from components
167 inline treeBoundBox(const boundBox& bb);
169 //- Construct as the bounding box of the given pointField. Local
170 // processor domain only (no reduce as in boundBox)
171 treeBoundBox(const UList<point>& points);
173 //- Construct as subset of points
174 treeBoundBox(const UList<point>&, const labelList& meshPoints);
176 //- Construct from Istream
177 treeBoundBox(Istream&);
184 //- Smallest of length,height,width
185 inline scalar minDim() const;
187 //- Largest of length,height,width
188 inline scalar maxDim() const;
190 //- Average of length,height,width
191 inline scalar avgDim() const;
193 //- Typical dimension length,height,width
194 inline scalar typDim() const;
196 //- vertex coordinates. In octant coding.
197 pointField points() const;
202 //- Corner point given octant
203 inline point corner(const direction) const;
205 //- Calculates midpoint
206 inline point mid() const;
208 //- Sub box given by octant number. Midpoint calculated.
209 treeBoundBox subBbox(const direction) const;
211 //- Sub box given by octant number. Midpoint provided.
212 treeBoundBox subBbox(const point& mid, const direction) const;
214 //- Returns octant number given point. Midpoint calculated.
215 inline direction subOctant
220 //- Returns octant number given point. Midpoint provided.
221 static inline direction subOctant
227 //- Returns octant number given point. Midpoint calculated.
228 // onEdge set if sample on edge of subOctant
229 inline direction subOctant
235 //- Returns octant number given point. Midpoint provided.
236 // onEdge set if sample on edge of subOctant
237 static inline direction subOctant
244 //- Returns octant number given intersection. Midpoint provided.
245 // onEdge set if sample on edge of subOctant. If onEdge
246 // the direction vector determines which octant to use
247 // (acc. to which octant the sample would be if it were moved
249 static inline direction subOctant
257 //- Calculates optimal order to look for nearest to sample. First
258 // will be the octant containing the sample, second the octant
259 // with boundary nearest to the sample etc.
260 inline void searchOrder
263 FixedList<direction, 8>& octantOrder
266 //- Intersects other boundingbox?
267 inline bool intersects(const treeBoundBox&) const;
269 //- Intersects segment; set point to intersection position,
270 // return true if intersection found.
271 // (intPt argument used during calculation even if not intersecting)
272 bool intersects(const point&, const point&, point& intPt) const;
274 //- fully contains bb
275 bool contains(const treeBoundBox& bb) const;
277 //- Contains point? (inside or on edge)
278 inline bool contains(const point&) const;
280 //- Contains point? (only inside)
281 bool containsNarrow(const point&) const;
283 //- Contains point inside or
284 // on edge and moving in direction dir would cause it to go
286 bool contains(const vector& dir, const point&) const;
288 //- Position of point relative to bb
289 direction posBits(const point&) const;
291 //- Calculate nearest and furthest (to sample) vertex coords of
300 //- Returns distance sample to furthest away corner.
301 scalar maxDist(const point& sample) const;
303 //- Compare distance to point with other bounding box
305 // -1 : all vertices of my bounding box are nearer than any of
307 // +1 : all vertices of my bounding box are further away than
309 // 0 : none of the above.
310 label distanceCmp(const point&, const treeBoundBox& other) const;
312 //- Return slightly wider bounding box
313 // Extends all dimensions with s*span*Random::scalar01()
314 inline treeBoundBox extend(Random&, const scalar s) const;
318 friend bool operator==(const treeBoundBox&, const treeBoundBox&);
319 friend bool operator!=(const treeBoundBox&, const treeBoundBox&);
324 friend Istream& operator>>(Istream&, treeBoundBox&);
328 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
330 } // End namespace Foam
332 #include "treeBoundBoxI.H"
334 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
338 // ************************************************************************* //