treeBoundBox.H
Go to the documentation of this file.
1/*---------------------------------------------------------------------------*\
2 ========= |
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4 \\ / O peration |
5 \\ / A nd | www.openfoam.com
6 \\/ M anipulation |
7-------------------------------------------------------------------------------
8 Copyright (C) 2011-2016 OpenFOAM Foundation
9 Copyright (C) 2017-2020 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
12 This file is part of OpenFOAM.
13
14 OpenFOAM is free software: you can redistribute it and/or modify it
15 under the terms of the GNU General Public License as published by
16 the Free Software Foundation, either version 3 of the License, or
17 (at your option) any later version.
18
19 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26
27Class
28 Foam::treeBoundBox
29
30Description
31 Standard boundBox with extra functionality for use in octree.
32
33 Numbering of corner points is according to octant numbering.
34
35 On the back plane (z=0):
36
37 \verbatim
38 Y
39 ^
40 |
41 +--------+
42 |2 3|
43 | |
44 | |
45 | |
46 |0 1|
47 +--------+->X
48 \endverbatim
49
50 For the front plane add 4 to the point labels.
51
52Note
53 When a bounding box is created without any points, it creates an inverted
54 bounding box. Points can be added later and the bounding box will grow to
55 include them.
56
57SourceFiles
58 treeBoundBoxI.H
59 treeBoundBox.C
60 treeBoundBoxTemplates.C
61
62\*---------------------------------------------------------------------------*/
63
64#ifndef treeBoundBox_H
65#define treeBoundBox_H
66
67#include "boundBox.H"
68#include "direction.H"
69#include "pointField.H"
70#include "faceList.H"
71
72// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
73
74namespace Foam
75{
76
77// Forward Declarations
78class Random;
79class treeBoundBox;
80Istream& operator>>(Istream& is, treeBoundBox& bb);
81Ostream& operator<<(Ostream& os, const treeBoundBox& bb);
82
83/*---------------------------------------------------------------------------*\
84 Class treeBoundBox Declaration
85\*---------------------------------------------------------------------------*/
87class treeBoundBox
88:
89 public boundBox
90{
91public:
92
93 // Enumerations
94
95 //- Bits used for octant/point encoding.
96 // Every octant/corner point is the combination of three directions.
97 enum octantBit : direction
98 {
99 RIGHTHALF = 0x1,
100 TOPHALF = 0x2,
102 };
103
104 //- Face codes. Identical order and meaning as per hex cellmodel
105 //- and boundBox, but have a different point ordering.
106 enum faceId
108 LEFT = 0,
109 RIGHT = 1,
110 BOTTOM = 2,
111 TOP = 3,
112 BACK = 4,
113 FRONT = 5
114 };
115
116 //- Bits used for face encoding
117 enum faceBit : direction
120 LEFTBIT = 0x1 << LEFT,
121 RIGHTBIT = 0x1 << RIGHT,
122 BOTTOMBIT = 0x1 << BOTTOM,
123 TOPBIT = 0x1 << TOP,
124 BACKBIT = 0x1 << BACK,
125 FRONTBIT = 0x1 << FRONT
126 };
127
128 //- Edges codes.
129 // E01 = edge between 0 and 1.
130 enum edgeId
132 E01 = 0,
133 E13 = 1,
134 E23 = 2,
135 E02 = 3,
137 E45 = 4,
138 E57 = 5,
139 E67 = 6,
140 E46 = 7,
142 E04 = 8,
143 E15 = 9,
144 E37 = 10,
145 E26 = 11
146 };
147
148
149 // Static Data Members
150
151 //- Face to point addressing
152 static const faceList faces;
153
154 //- Edge to point addressing
155 static const edgeList edges;
156
157
158 // Constructors
159
160 //- Construct without any points - an inverted bounding box
161 inline treeBoundBox();
162
163 //- Construct from a boundBox
164 inline explicit treeBoundBox(const boundBox& bb);
165
166 //- Construct a bounding box containing a single initial point
167 inline explicit treeBoundBox(const point& pt);
168
169 //- Construct from components
170 inline treeBoundBox(const point& min, const point& max);
171
172 //- Construct as the bounding box of the given pointField.
173 // Local processor domain only (no reduce as in boundBox)
174 explicit treeBoundBox(const UList<point>& points);
175
176 //- Construct as subset of points
177 // Local processor domain only (no reduce as in boundBox)
178 treeBoundBox(const UList<point>& points, const labelUList& indices);
179
180 //- Construct as subset of points
181 // The indices could be from edge/triFace etc.
182 // Local processor domain only (no reduce as in boundBox)
183 template<unsigned N>
185 (
186 const UList<point>& points,
187 const FixedList<label, N>& indices
188 );
189
190
191 //- Construct from Istream
192 inline treeBoundBox(Istream& is);
193
194
195 // Member functions
196
197 // Access
198
199 //- Typical dimension length,height,width
200 inline scalar typDim() const;
201
202 //- Vertex coordinates. In octant coding.
203 tmp<pointField> points() const;
204
205
206 // Check
207
208 //- Corner point of given octant
209 inline point corner(const direction octant) const;
210
211 //- Sub-box of given octant. Midpoint calculated.
212 treeBoundBox subBbox(const direction octant) const;
213
214 //- Sub-box given by octant number. Midpoint provided.
215 treeBoundBox subBbox(const point& mid, const direction) const;
216
217 //- Returns octant number given point and the calculated midpoint.
218 inline direction subOctant
219 (
220 const point& pt
221 ) const;
222
223 //- Returns octant number given point and midpoint.
224 static inline direction subOctant
225 (
226 const point& mid,
227 const point& pt
228 );
229
230 //- Returns octant number given point and the calculated midpoint.
231 // onEdge set if the point is on edge of subOctant
232 inline direction subOctant
233 (
234 const point& pt,
235 bool& onEdge
236 ) const;
237
238 //- Returns octant number given point and midpoint.
239 // onEdge set if the point is on edge of subOctant
240 static inline direction subOctant
241 (
242 const point& mid,
243 const point& pt,
244 bool& onEdge
245 );
246
247 //- Returns octant number given intersection and midpoint.
248 // onEdge set if the point is on edge of subOctant
249 // If onEdge, the direction vector determines which octant to use
250 // (acc. to which octant the point would be if it were moved
251 // along dir)
252 static inline direction subOctant
253 (
254 const point& mid,
255 const vector& dir,
256 const point& pt,
257 bool& onEdge
258 );
259
260 //- Calculates optimal order to look for nearest to point.
261 // First will be the octant containing the point,
262 // second the octant with boundary nearest to the point etc.
263 inline void searchOrder
264 (
265 const point& pt,
266 FixedList<direction, 8>& octantOrder
267 ) const;
268
269 //- Overlaps other bounding box?
270 using boundBox::overlaps;
271
272 //- Intersects segment; set point to intersection position and face,
273 // return true if intersection found.
274 // (pt argument used during calculation even if not intersecting).
275 // Calculates intersections from outside supplied vector
276 // (overallStart, overallVec). This is so when
277 // e.g. tracking through lots of consecutive boxes
278 // (typical octree) we're not accumulating truncation errors. Set
279 // to start, (end-start) if not used.
280 bool intersects
281 (
282 const point& overallStart,
283 const vector& overallVec,
284 const point& start,
285 const point& end,
286 point& pt,
287 direction& ptBits
288 ) const;
289
290 //- Like above but does not return faces point is on
291 bool intersects
292 (
293 const point& start,
294 const point& end,
295 point& pt
296 ) const;
297
298 //- Contains point or other bounding box?
299 using boundBox::contains;
300
301 //- Contains point (inside or on edge) and moving in direction
302 // dir would cause it to go inside.
303 bool contains(const vector& dir, const point&) const;
304
305 //- Code position of point on bounding box faces
306 direction faceBits(const point& pt) const;
307
308 //- Position of point relative to bounding box
309 direction posBits(const point& pt) const;
310
311 //- Calculate nearest and furthest (to point) vertex coords of
312 // bounding box
313 void calcExtremities
314 (
315 const point& pt,
316 point& nearest,
317 point& furthest
318 ) const;
319
320 //- Returns distance point to furthest away corner.
321 scalar maxDist(const point& pt) const;
322
323 //- Compare distance to point with other bounding box
324 // return:
325 // -1 : all vertices of my bounding box are nearer than any of
326 // other
327 // +1 : all vertices of my bounding box are further away than
328 // any of other
329 // 0 : none of the above.
330 label distanceCmp(const point& pt, const treeBoundBox& other) const;
331
332 //- Return slightly wider bounding box
333 // Extends all dimensions with s*span*Random::sample01<scalar>()
334 // and guarantees in any direction s*mag(span) minimum width
335 inline treeBoundBox extend(Random& rndGen, const scalar s) const;
336
337
338 // IOstream operator
341 friend Ostream& operator<<(Ostream& os, const treeBoundBox& bb);
342};
343
344
345// * * * * * * * * * * * * * * * * * Traits * * * * * * * * * * * * * * * * //
346
347//- Contiguous data for treeBoundBox
348template<> struct is_contiguous<treeBoundBox> : is_contiguous<boundBox> {};
349
350//- Contiguous scalar data for treeBoundBox
351template<> struct is_contiguous_scalar<treeBoundBox>
352:
353 is_contiguous_scalar<boundBox>
354{};
355
356
357// * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * //
358
359inline bool operator==(const treeBoundBox& a, const treeBoundBox& b);
360inline bool operator!=(const treeBoundBox& a, const treeBoundBox& b);
361
362
363// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
364
365} // End namespace Foam
366
367#include "treeBoundBoxI.H"
368
369#ifdef NoRepository
370 #include "treeBoundBoxTemplates.C"
371#endif
372
373// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
374
375#endif
376
377// ************************************************************************* //
A 1D vector of objects of type <T> with a fixed length <N>.
Definition: FixedList.H:81
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:64
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:62
int overlaps
Flag to control which overlap calculations are performed.
Definition: PDRparams.H:97
Random number generator.
Definition: Random.H:60
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: UList.H:94
A bounding box defined in terms of min/max extrema points.
Definition: boundBox.H:64
point nearest(const point &pt) const
Return the nearest point on the boundBox to the supplied point.
Definition: boundBox.C:268
const point & min() const
Minimum describing the bounding box.
Definition: boundBoxI.H:91
const point & max() const
Maximum describing the bounding box.
Definition: boundBoxI.H:97
bool contains(const point &pt) const
Contains point? (inside or on edge)
Definition: boundBoxI.H:271
A class for managing temporary objects.
Definition: tmp.H:65
Standard boundBox with extra functionality for use in octree.
Definition: treeBoundBox.H:89
void calcExtremities(const point &pt, point &nearest, point &furthest) const
Calculate nearest and furthest (to point) vertex coords of.
Definition: treeBoundBox.C:429
faceBit
Bits used for face encoding.
Definition: treeBoundBox.H:117
@ FRONTBIT
32: z-max, front
Definition: treeBoundBox.H:124
@ TOPBIT
8: y-max, top
Definition: treeBoundBox.H:122
@ LEFTBIT
1: x-min, left
Definition: treeBoundBox.H:119
@ BACKBIT
16: z-min, back
Definition: treeBoundBox.H:123
@ RIGHTBIT
2: x-max, right
Definition: treeBoundBox.H:120
@ BOTTOMBIT
4: y-min, bottom
Definition: treeBoundBox.H:121
label distanceCmp(const point &pt, const treeBoundBox &other) const
Compare distance to point with other bounding box.
Definition: treeBoundBox.C:465
treeBoundBox extend(Random &rndGen, const scalar s) const
Return slightly wider bounding box.
void searchOrder(const point &pt, FixedList< direction, 8 > &octantOrder) const
Calculates optimal order to look for nearest to point.
static const edgeList edges
Edge to point addressing.
Definition: treeBoundBox.H:154
treeBoundBox subBbox(const direction octant) const
Sub-box of given octant. Midpoint calculated.
Definition: treeBoundBox.C:106
friend Istream & operator>>(Istream &is, treeBoundBox &bb)
friend Ostream & operator<<(Ostream &os, const treeBoundBox &bb)
edgeId
Edges codes.
Definition: treeBoundBox.H:130
bool intersects(const point &overallStart, const vector &overallVec, const point &start, const point &end, point &pt, direction &ptBits) const
Intersects segment; set point to intersection position and face,.
Definition: treeBoundBox.C:162
point corner(const direction octant) const
Corner point of given octant.
Definition: treeBoundBoxI.H:72
direction faceBits(const point &pt) const
Code position of point on bounding box faces.
Definition: treeBoundBox.C:358
bool contains(const vector &dir, const point &) const
Contains point (inside or on edge) and moving in direction.
Definition: treeBoundBox.C:320
direction posBits(const point &pt) const
Position of point relative to bounding box.
Definition: treeBoundBox.C:393
direction subOctant(const point &pt) const
Returns octant number given point and the calculated midpoint.
Definition: treeBoundBoxI.H:84
octantBit
Bits used for octant/point encoding.
Definition: treeBoundBox.H:97
@ TOPHALF
2: positive y-direction
Definition: treeBoundBox.H:99
@ RIGHTHALF
1: positive x-direction
Definition: treeBoundBox.H:98
@ FRONTHALF
4: positive z-direction
Definition: treeBoundBox.H:100
@ TOP
3: y-max, top
Definition: treeBoundBox.H:110
@ FRONT
5: z-max, front
Definition: treeBoundBox.H:112
@ BOTTOM
2: y-min, bottom
Definition: treeBoundBox.H:109
@ BACK
4: z-min, back
Definition: treeBoundBox.H:111
@ LEFT
0: x-min, left
Definition: treeBoundBox.H:107
@ RIGHT
1: x-max, right
Definition: treeBoundBox.H:108
scalar typDim() const
Typical dimension length,height,width.
Definition: treeBoundBoxI.H:66
static const faceList faces
Face to point addressing.
Definition: treeBoundBox.H:151
treeBoundBox()
Construct without any points - an inverted bounding box.
Definition: treeBoundBoxI.H:34
scalar maxDist(const point &pt) const
Returns distance point to furthest away corner.
Definition: treeBoundBox.C:455
tmp< pointField > points() const
Vertex coordinates. In octant coding.
Definition: treeBoundBox.C:92
Direction is an 8-bit unsigned integer type used to represent Cartesian directions,...
OBJstream os(runTime.globalPath()/outputName)
gmvFile<< "tracers "<< particles.size()<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().x()<< " ";}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().y()<< " ";}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().z()<< " ";}gmvFile<< nl;forAll(lagrangianScalarNames, i){ word name=lagrangianScalarNames[i];IOField< scalar > s(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
Namespace for OpenFOAM.
bool operator!=(const eddy &a, const eddy &b)
Definition: eddy.H:239
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:83
tmp< faMatrix< Type > > operator==(const faMatrix< Type > &, const faMatrix< Type > &)
Istream & operator>>(Istream &, directionInfo &)
uint8_t direction
Definition: direction.H:56
volScalarField & b
Definition: createFields.H:27
A template class to specify if a data type is composed solely of Foam::scalar elements.
Definition: contiguous.H:94
A template class to specify that a data type can be considered as being contiguous in memory.
Definition: contiguous.H:78
Random rndGen
Definition: createFields.H:23