1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
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
13 the Free Software Foundation, either version 3 of the License, or
14 (at your 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, see <http://www.gnu.org/licenses/>.
28 Standard boundBox + extra functionality for use in octree.
30 Numbering of corner points is according to octant numbering.
32 On the back plane (z=0):
47 For the front plane add 4 to the point labels.
53 treeBoundBoxTemplates.C
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 edges.
84 static edgeList calcEdges(const label[12][2]);
86 //- To initialise faceNormals.
87 static FixedList<vector, 6> calcFaceNormals();
91 // Static data members
93 //- The great value used for greatBox and invertedBox
94 static const scalar great;
96 //- As per boundBox::greatBox, but with GREAT instead of VGREAT
97 static const treeBoundBox greatBox;
99 //- As per boundBox::invertedBox, but with GREAT instead of VGREAT
100 static const treeBoundBox invertedBox;
102 //- Bits used for octant/point coding.
103 // Every octant/corner point is the combination of three faces.
106 RIGHTHALF = 0x1 << 0,
122 //- Bits used for face coding
126 LEFTBIT = 0x1 << LEFT, //1
127 RIGHTBIT = 0x1 << RIGHT, //2
128 BOTTOMBIT = 0x1 << BOTTOM, //4
129 TOPBIT = 0x1 << TOP, //8
130 BACKBIT = 0x1 << BACK, //16
131 FRONTBIT = 0x1 << FRONT, //32
135 // E01 = edge between 0 and 1.
154 //- Face to point addressing
155 static const faceList faces;
157 //- Edge to point addressing
158 static const edgeList edges;
160 //- Per face the unit normal
161 static const FixedList<vector, 6> faceNormals;
166 //- Construct null setting points to zero
167 inline treeBoundBox();
169 //- Construct from a boundBox
170 explicit inline treeBoundBox(const boundBox& bb);
172 //- Construct from components
173 inline treeBoundBox(const point& min, const point& max);
175 //- Construct as the bounding box of the given pointField.
176 // Local processor domain only (no reduce as in boundBox)
177 explicit treeBoundBox(const UList<point>&);
179 //- Construct as subset of points
180 // Local processor domain only (no reduce as in boundBox)
181 treeBoundBox(const UList<point>&, const labelUList& indices);
183 //- Construct as subset of points
184 // The indices could be from edge/triFace etc.
185 // Local processor domain only (no reduce as in boundBox)
186 template<unsigned Size>
190 const FixedList<label, Size>& indices
194 //- Construct from Istream
195 inline treeBoundBox(Istream&);
202 //- Typical dimension length,height,width
203 inline scalar typDim() const;
205 //- vertex coordinates. In octant coding.
206 tmp<pointField> points() const;
211 //- Corner point given octant
212 inline point corner(const direction) const;
214 //- Sub box given by octant number. Midpoint calculated.
215 treeBoundBox subBbox(const direction) const;
217 //- Sub box given by octant number. Midpoint provided.
218 treeBoundBox subBbox(const point& mid, const direction) const;
220 //- Returns octant number given point and the calculated midpoint.
221 inline direction subOctant
226 //- Returns octant number given point and midpoint.
227 static inline direction subOctant
233 //- Returns octant number given point and the calculated midpoint.
234 // onEdge set if the point is on edge of subOctant
235 inline direction subOctant
241 //- Returns octant number given point and midpoint.
242 // onEdge set if the point is on edge of subOctant
243 static inline direction subOctant
250 //- Returns octant number given intersection and midpoint.
251 // onEdge set if the point is on edge of subOctant
252 // If onEdge, the direction vector determines which octant to use
253 // (acc. to which octant the point would be if it were moved
255 static inline direction subOctant
263 //- Calculates optimal order to look for nearest to point.
264 // First will be the octant containing the point,
265 // second the octant with boundary nearest to the point etc.
266 inline void searchOrder
269 FixedList<direction, 8>& octantOrder
272 //- Overlaps other bounding box?
273 using boundBox::overlaps;
275 //- Overlaps boundingSphere (centre + sqr(radius))?
276 bool overlaps(const point&, const scalar radiusSqr) const;
278 //- Intersects segment; set point to intersection position and face,
279 // return true if intersection found.
280 // (pt argument used during calculation even if not intersecting).
281 // Calculates intersections from outside supplied vector
282 // (overallStart, overallVec). This is so when
283 // e.g. tracking through lots of consecutive boxes
284 // (typical octree) we're not accumulating truncation errors. Set
285 // to start, (end-start) if not used.
288 const point& overallStart,
289 const vector& overallVec,
296 //- Like above but does not return faces point is on
304 //- Contains point or other bounding box?
305 using boundBox::contains;
307 //- Contains point (inside or on edge) and moving in direction
308 // dir would cause it to go inside.
309 bool contains(const vector& dir, const point&) const;
311 //- Code position of point on bounding box faces
312 direction faceBits(const point&) const;
314 //- Position of point relative to bounding box
315 direction posBits(const point&) const;
317 //- Calculate nearest and furthest (to point) vertex coords of
326 //- Returns distance point to furthest away corner.
327 scalar maxDist(const point&) const;
329 //- Compare distance to point with other bounding box
331 // -1 : all vertices of my bounding box are nearer than any of
333 // +1 : all vertices of my bounding box are further away than
335 // 0 : none of the above.
336 label distanceCmp(const point&, const treeBoundBox& other) const;
338 //- Return slightly wider bounding box
339 // Extends all dimensions with s*span*Random::scalar01()
340 // and guarantees in any direction s*mag(span) minimum width
341 inline treeBoundBox extend(Random&, const scalar s) const;
345 friend bool operator==(const treeBoundBox&, const treeBoundBox&);
346 friend bool operator!=(const treeBoundBox&, const treeBoundBox&);
350 friend Istream& operator>>(Istream& is, treeBoundBox&);
351 friend Ostream& operator<<(Ostream& os, const treeBoundBox&);
356 //- Data associated with treeBoundBox type are contiguous
358 inline bool contiguous<treeBoundBox>() {return contiguous<boundBox>();}
361 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
363 } // End namespace Foam
365 #include "treeBoundBoxI.H"
368 # include "treeBoundBoxTemplates.C"
371 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
375 // ************************************************************************* //