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 -------------------------------------------------------------------------------
11 License
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 
27 Class
28  Foam::treeBoundBox
29 
30 Description
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 
52 Note
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 
57 SourceFiles
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 
74 namespace Foam
75 {
76 
77 // Forward Declarations
78 class Random;
79 class treeBoundBox;
80 Istream& operator>>(Istream& is, treeBoundBox& bb);
81 Ostream& operator<<(Ostream& os, const treeBoundBox& bb);
82 
83 /*---------------------------------------------------------------------------*\
84  Class treeBoundBox Declaration
85 \*---------------------------------------------------------------------------*/
86 
87 class treeBoundBox
88 :
89  public boundBox
90 {
91 public:
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,
101  FRONTHALF = 0x4
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
107  {
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
118  {
119  NOFACE = 0,
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
131  {
132  E01 = 0,
133  E13 = 1,
134  E23 = 2,
135  E02 = 3,
136 
137  E45 = 4,
138  E57 = 5,
139  E67 = 6,
140  E46 = 7,
141 
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
339 
340  friend Istream& operator>>(Istream& is, treeBoundBox& bb);
341  friend Ostream& operator<<(Ostream& os, const treeBoundBox& bb);
342 };
343 
344 
345 // * * * * * * * * * * * * * * * * * Traits * * * * * * * * * * * * * * * * //
346 
347 //- Contiguous data for treeBoundBox
348 template<> struct is_contiguous<treeBoundBox> : is_contiguous<boundBox> {};
349 
350 //- Contiguous scalar data for treeBoundBox
351 template<> struct is_contiguous_scalar<treeBoundBox>
352 :
353  is_contiguous_scalar<boundBox>
354 {};
355 
356 
357 // * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * //
358 
359 inline bool operator==(const treeBoundBox& a, const treeBoundBox& b);
360 inline 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 // ************************************************************************* //
Foam::treeBoundBox::NOFACE
Definition: treeBoundBox.H:118
Foam::treeBoundBox::TOPHALF
2: positive y-direction
Definition: treeBoundBox.H:99
Foam::treeBoundBox::faceBit
faceBit
Bits used for face encoding.
Definition: treeBoundBox.H:116
Foam::Random
Random number generator.
Definition: Random.H:59
Foam::treeBoundBox::extend
treeBoundBox extend(Random &rndGen, const scalar s) const
Return slightly wider bounding box.
Definition: treeBoundBoxI.H:325
Foam::treeBoundBox::BACK
4: z-min, back
Definition: treeBoundBox.H:111
Foam::treeBoundBox::E46
Definition: treeBoundBox.H:139
s
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))
Definition: gmvOutputSpray.H:25
Foam::treeBoundBox::E57
Definition: treeBoundBox.H:137
Foam::treeBoundBox::points
tmp< pointField > points() const
Vertex coordinates. In octant coding.
Definition: treeBoundBox.C:92
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:61
Foam::treeBoundBox::BOTTOMBIT
4: y-min, bottom
Definition: treeBoundBox.H:121
Foam::treeBoundBox::E01
Definition: treeBoundBox.H:131
Foam::treeBoundBox
Standard boundBox with extra functionality for use in octree.
Definition: treeBoundBox.H:86
Foam::treeBoundBox::edgeId
edgeId
Edges codes.
Definition: treeBoundBox.H:129
Foam::treeBoundBox::calcExtremities
void calcExtremities(const point &pt, point &nearest, point &furthest) const
Calculate nearest and furthest (to point) vertex coords of.
Definition: treeBoundBox.C:429
Foam::treeBoundBox::TOPBIT
8: y-max, top
Definition: treeBoundBox.H:122
Foam::operator>>
Istream & operator>>(Istream &, directionInfo &)
Definition: directionInfo.C:230
Foam::treeBoundBox::edges
static const edgeList edges
Edge to point addressing.
Definition: treeBoundBox.H:154
Foam::treeBoundBox::E13
Definition: treeBoundBox.H:132
Foam::boundBox::max
const point & max() const
Maximum describing the bounding box.
Definition: boundBoxI.H:97
Foam::treeBoundBox::RIGHTHALF
1: positive x-direction
Definition: treeBoundBox.H:98
Foam::treeBoundBox::treeBoundBox
treeBoundBox()
Construct without any points - an inverted bounding box.
Definition: treeBoundBoxI.H:34
faceList.H
Foam::treeBoundBox::faceBits
direction faceBits(const point &pt) const
Code position of point on bounding box faces.
Definition: treeBoundBox.C:358
Foam::boundBox::min
const point & min() const
Minimum describing the bounding box.
Definition: boundBoxI.H:91
Foam::treeBoundBox::subBbox
treeBoundBox subBbox(const direction octant) const
Sub-box of given octant. Midpoint calculated.
Definition: treeBoundBox.C:106
Foam::treeBoundBox::BACKBIT
16: z-min, back
Definition: treeBoundBox.H:123
Foam::boundBox::overlaps
bool overlaps(const boundBox &bb) const
Overlaps/touches boundingBox?
Definition: boundBoxI.H:221
Foam::operator!=
bool operator!=(const eddy &a, const eddy &b)
Definition: eddy.H:239
Foam::operator<<
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:83
Foam::treeBoundBox::corner
point corner(const direction octant) const
Corner point of given octant.
Definition: treeBoundBoxI.H:72
Foam::treeBoundBox::RIGHT
1: x-max, right
Definition: treeBoundBox.H:108
Foam::treeBoundBox::posBits
direction posBits(const point &pt) const
Position of point relative to bounding box.
Definition: treeBoundBox.C:393
Foam::constant::physicoChemical::b
const dimensionedScalar b
Wien displacement law constant: default SI units: [m.K].
Definition: createFields.H:27
Foam::operator==
tmp< faMatrix< Type > > operator==(const faMatrix< Type > &, const faMatrix< Type > &)
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:61
Foam::treeBoundBox::operator<<
friend Ostream & operator<<(Ostream &os, const treeBoundBox &bb)
Foam::treeBoundBox::intersects
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
Foam::treeBoundBox::typDim
scalar typDim() const
Typical dimension length,height,width.
Definition: treeBoundBoxI.H:66
Foam::treeBoundBox::LEFT
0: x-min, left
Definition: treeBoundBox.H:107
Foam::treeBoundBox::faces
static const faceList faces
Face to point addressing.
Definition: treeBoundBox.H:151
Foam::treeBoundBox::searchOrder
void searchOrder(const point &pt, FixedList< direction, 8 > &octantOrder) const
Calculates optimal order to look for nearest to point.
Definition: treeBoundBoxI.H:235
Foam::treeBoundBox::TOP
3: y-max, top
Definition: treeBoundBox.H:110
Foam::treeBoundBox::E37
Definition: treeBoundBox.H:143
Foam::treeBoundBox::E45
Definition: treeBoundBox.H:136
Foam::treeBoundBox::BOTTOM
2: y-min, bottom
Definition: treeBoundBox.H:109
Foam::treeBoundBox::LEFTBIT
1: x-min, left
Definition: treeBoundBox.H:119
treeBoundBoxTemplates.C
Foam::treeBoundBox::RIGHTBIT
2: x-max, right
Definition: treeBoundBox.H:120
Foam::treeBoundBox::E67
Definition: treeBoundBox.H:138
Foam::treeBoundBox::faceId
faceId
Definition: treeBoundBox.H:105
os
OBJstream os(runTime.globalPath()/outputName)
stdFoam::end
constexpr auto end(C &c) -> decltype(c.end())
Return iterator to the end of the container c.
Definition: stdFoam.H:121
Foam::boundBox::nearest
point nearest(const point &pt) const
Return the nearest point on the boundBox to the supplied point.
Definition: boundBox.C:268
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::is_contiguous_scalar
A template class to specify if a data type is composed solely of Foam::scalar elements.
Definition: contiguous.H:91
direction.H
Direction is an 8-bit unsigned integer type used to represent Cartesian directions,...
Foam::boundBox::contains
bool contains(const point &pt) const
Contains point? (inside or on edge)
Definition: boundBoxI.H:271
Foam::treeBoundBox::FRONTBIT
32: z-max, front
Definition: treeBoundBox.H:124
pointField.H
boundBox.H
Foam::treeBoundBox::E02
Definition: treeBoundBox.H:134
Foam::treeBoundBox::contains
bool contains(const vector &dir, const point &) const
Contains point (inside or on edge) and moving in direction.
Definition: treeBoundBox.C:320
Foam::treeBoundBox::maxDist
scalar maxDist(const point &pt) const
Returns distance point to furthest away corner.
Definition: treeBoundBox.C:455
Foam::treeBoundBox::subOctant
direction subOctant(const point &pt) const
Returns octant number given point and the calculated midpoint.
Definition: treeBoundBoxI.H:84
Foam::treeBoundBox::FRONTHALF
4: positive z-direction
Definition: treeBoundBox.H:100
Foam::Vector< scalar >
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: BitOps.H:63
Foam::FixedList
A 1D vector of objects of type <T> with a fixed length <N>.
Definition: HashTable.H:104
Foam::UList
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: HashTable.H:103
treeBoundBoxI.H
Foam::direction
uint8_t direction
Definition: direction.H:52
Foam::treeBoundBox::E23
Definition: treeBoundBox.H:133
Foam::boundBox
A bounding box defined in terms of min/max extrema points.
Definition: boundBox.H:63
Foam::treeBoundBox::FRONT
5: z-max, front
Definition: treeBoundBox.H:112
rndGen
Random rndGen
Definition: createFields.H:23
Foam::treeBoundBox::E26
Definition: treeBoundBox.H:144
Foam::treeBoundBox::distanceCmp
label distanceCmp(const point &pt, const treeBoundBox &other) const
Compare distance to point with other bounding box.
Definition: treeBoundBox.C:465
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::treeBoundBox::octantBit
octantBit
Bits used for octant/point encoding.
Definition: treeBoundBox.H:96
Foam::treeBoundBox::E04
Definition: treeBoundBox.H:141
Foam::is_contiguous
A template class to specify that a data type can be considered as being contiguous in memory.
Definition: contiguous.H:75
Foam::treeBoundBox::E15
Definition: treeBoundBox.H:142
Foam::treeBoundBox::operator>>
friend Istream & operator>>(Istream &is, treeBoundBox &bb)