initial commit for version 1.5.x patch release
[OpenFOAM-1.5.x.git] / src / meshTools / octree / treeBoundBox.H
blob01d7a9a6bd6e432bee2a3fcff038f5622ac8d5c9
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2008 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
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
19     for more details.
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
25 Class
26     Foam::treeBoundBox
28 Description
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):
35     @verbatim
36         Y
37         ^
38         |
39         +--------+
40         |2      3|
41         |        |
42         |        |
43         |        |
44         |0      1|
45         +--------+->X
46     @endverbatim
48     For the front plane add 4 to the point labels.
51 SourceFiles
52     treeBoundBoxI.H
53     treeBoundBox.C
55 \*---------------------------------------------------------------------------*/
57 #ifndef treeBoundBox_H
58 #define treeBoundBox_H
60 #include "boundBox.H"
61 #include "direction.H"
62 #include "pointField.H"
63 #include "faceList.H"
65 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
67 namespace Foam
70 class Random;
72 /*---------------------------------------------------------------------------*\
73                            Class treeBoundBox Declaration
74 \*---------------------------------------------------------------------------*/
76 class treeBoundBox
78     public boundBox
81 private:
83         //- To initialise faceNormals.
84         static FixedList<vector, 6> calcFaceNormals();
86 public:
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.
94         enum octantBit
95         {
96             RIGHTHALF   = 0x1 << 0,
97             TOPHALF     = 0x1 << 1,
98             FRONTHALF   = 0x1 << 2
99         };
101         //- Face codes
102         enum faceId
103         {
104             LEFT   = 0,
105             RIGHT  = 1,
106             BOTTOM = 2,
107             TOP    = 3,
108             BACK   = 4,
109             FRONT  = 5
110         };
112         //- Bits used for face coding
113         enum faceBit
114         {
115             NOFACE    = 0,
116             LEFTBIT   = 0x1 << LEFT,
117             RIGHTBIT  = 0x1 << RIGHT,
118             BOTTOMBIT = 0x1 << BOTTOM,
119             TOPBIT    = 0x1 << TOP,
120             BACKBIT   = 0x1 << BACK,
121             FRONTBIT  = 0x1 << FRONT,
122         };
124         //- Edges codes.
125         //  E01 = edge between 0 and 1.
126         enum edgeId
127         {
128             E01 = 0,
129             E13 = 1,
130             E23 = 2,
131             E02 = 3,
133             E45 = 4,
134             E57 = 5,
135             E67 = 6,
136             E46 = 7,
138             E04 = 8,
139             E15 = 9,
140             E37 = 10,
141             E26 = 11
142         };
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&);
158     // Constructors
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&);
180     // Member functions
182         // Access
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;
200         // Check
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
216             (
217                 const point& sample
218             ) const;
220             //- Returns octant number given point. Midpoint provided.
221             static inline direction subOctant
222             (
223                 const point& mid,
224                 const point& sample
225             );
227             //- Returns octant number given point. Midpoint calculated.
228             //  onEdge set if sample on edge of subOctant
229             inline direction subOctant
230             (
231                 const point& mid,
232                 bool& onEdge
233             ) const;
235             //- Returns octant number given point. Midpoint provided.
236             //  onEdge set if sample on edge of subOctant
237             static inline direction subOctant
238             (
239                 const point& mid,
240                 const point& sample,
241                 bool& onEdge
242             );
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
248             //  along dir)
249             static inline direction subOctant
250             (
251                 const point& mid,
252                 const vector& dir,
253                 const point& sample,
254                 bool& onEdge
255             );
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
261             (
262                  const point& sample,
263                  FixedList<direction, 8>& octantOrder
264             ) const;
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
285             //  inside.
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
292             //  bounding box
293             void calcExtremities
294             (
295                 const point& sample,
296                 point& nearest,
297                 point& furthest
298             ) const;
300             //- Returns distance sample to furthest away corner.
301             scalar maxDist(const point& sample) const;
303             //- Compare distance to point with other bounding box
304             //  return:
305             //  -1 : all vertices of my bounding box are nearer than any of
306             //       other
307             //  +1 : all vertices of my bounding box are further away than
308             //       any of other
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;
316     // Friend Operators
318         friend bool operator==(const treeBoundBox&, const treeBoundBox&);
319         friend bool operator!=(const treeBoundBox&, const treeBoundBox&);
322     // IOstream operator
324         friend Istream& operator>>(Istream&, treeBoundBox&);
328 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
330 } // End namespace Foam
332 #include "treeBoundBoxI.H"
334 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
336 #endif
338 // ************************************************************************* //