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-2019 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 /*---------------------------------------------------------------------------*\
85  Class treeBoundBox Declaration
86 \*---------------------------------------------------------------------------*/
87 
88 class treeBoundBox
89 :
90  public boundBox
91 {
92 
93 public:
94 
95  // Static Data Members
96 
97  //- Bits used for octant/point encoding.
98  // Every octant/corner point is the combination of three faces.
99  enum octantBit : direction
100  {
101  RIGHTHALF = 0x1,
102  TOPHALF = 0x2,
103  FRONTHALF = 0x4
104  };
105 
106  //- Face codes. Identical order and meaning as per hex cellmodel
107  //- and boundBox, but have a different point ordering.
108  enum faceId
109  {
110  LEFT = 0,
111  RIGHT = 1,
112  BOTTOM = 2,
113  TOP = 3,
114  BACK = 4,
115  FRONT = 5
116  };
117 
118  //- Bits used for face encoding
119  enum faceBit : direction
120  {
121  NOFACE = 0,
122  LEFTBIT = 0x1 << LEFT,
123  RIGHTBIT = 0x1 << RIGHT,
124  BOTTOMBIT = 0x1 << BOTTOM,
125  TOPBIT = 0x1 << TOP,
126  BACKBIT = 0x1 << BACK,
127  FRONTBIT = 0x1 << FRONT
128  };
129 
130  //- Edges codes.
131  // E01 = edge between 0 and 1.
132  enum edgeId
133  {
134  E01 = 0,
135  E13 = 1,
136  E23 = 2,
137  E02 = 3,
138 
139  E45 = 4,
140  E57 = 5,
141  E67 = 6,
142  E46 = 7,
143 
144  E04 = 8,
145  E15 = 9,
146  E37 = 10,
147  E26 = 11
148  };
149 
150  //- Face to point addressing
151  static const faceList faces;
152 
153  //- Edge to point addressing
154  static const edgeList edges;
155 
156 
157  // Constructors
158 
159  //- Construct without any points - an inverted bounding box
160  inline treeBoundBox();
161 
162  //- Construct from a boundBox
163  inline explicit treeBoundBox(const boundBox& bb);
164 
165  //- Construct a bounding box containing a single initial point
166  inline explicit treeBoundBox(const point& pt);
167 
168  //- Construct from components
169  inline treeBoundBox(const point& min, const point& max);
170 
171  //- Construct as the bounding box of the given pointField.
172  // Local processor domain only (no reduce as in boundBox)
173  explicit treeBoundBox(const UList<point>& points);
174 
175  //- Construct as subset of points
176  // Local processor domain only (no reduce as in boundBox)
177  treeBoundBox(const UList<point>& points, const labelUList& indices);
178 
179  //- Construct as subset of points
180  // The indices could be from edge/triFace etc.
181  // Local processor domain only (no reduce as in boundBox)
182  template<unsigned N>
184  (
185  const UList<point>& points,
186  const FixedList<label, N>& indices
187  );
188 
189 
190  //- Construct from Istream
191  inline treeBoundBox(Istream& is);
192 
193 
194  // Member functions
195 
196  // Access
197 
198  //- Typical dimension length,height,width
199  inline scalar typDim() const;
200 
201  //- Vertex coordinates. In octant coding.
202  tmp<pointField> points() const;
203 
204 
205  // Check
206 
207  //- Corner point of given octant
208  inline point corner(const direction octant) const;
209 
210  //- Sub-box of given octant. Midpoint calculated.
211  treeBoundBox subBbox(const direction octant) const;
212 
213  //- Sub-box given by octant number. Midpoint provided.
214  treeBoundBox subBbox(const point& mid, const direction) const;
215 
216  //- Returns octant number given point and the calculated midpoint.
217  inline direction subOctant
218  (
219  const point& pt
220  ) const;
221 
222  //- Returns octant number given point and midpoint.
223  static inline direction subOctant
224  (
225  const point& mid,
226  const point& pt
227  );
228 
229  //- Returns octant number given point and the calculated midpoint.
230  // onEdge set if the point is on edge of subOctant
231  inline direction subOctant
232  (
233  const point& pt,
234  bool& onEdge
235  ) const;
236 
237  //- Returns octant number given point and midpoint.
238  // onEdge set if the point is on edge of subOctant
239  static inline direction subOctant
240  (
241  const point& mid,
242  const point& pt,
243  bool& onEdge
244  );
245 
246  //- Returns octant number given intersection and midpoint.
247  // onEdge set if the point is on edge of subOctant
248  // If onEdge, the direction vector determines which octant to use
249  // (acc. to which octant the point would be if it were moved
250  // along dir)
251  static inline direction subOctant
252  (
253  const point& mid,
254  const vector& dir,
255  const point& pt,
256  bool& onEdge
257  );
258 
259  //- Calculates optimal order to look for nearest to point.
260  // First will be the octant containing the point,
261  // second the octant with boundary nearest to the point etc.
262  inline void searchOrder
263  (
264  const point& pt,
265  FixedList<direction, 8>& octantOrder
266  ) const;
267 
268  //- Overlaps other bounding box?
269  using boundBox::overlaps;
270 
271  //- Intersects segment; set point to intersection position and face,
272  // return true if intersection found.
273  // (pt argument used during calculation even if not intersecting).
274  // Calculates intersections from outside supplied vector
275  // (overallStart, overallVec). This is so when
276  // e.g. tracking through lots of consecutive boxes
277  // (typical octree) we're not accumulating truncation errors. Set
278  // to start, (end-start) if not used.
279  bool intersects
280  (
281  const point& overallStart,
282  const vector& overallVec,
283  const point& start,
284  const point& end,
285  point& pt,
286  direction& ptBits
287  ) const;
288 
289  //- Like above but does not return faces point is on
290  bool intersects
291  (
292  const point& start,
293  const point& end,
294  point& pt
295  ) const;
296 
297  //- Contains point or other bounding box?
298  using boundBox::contains;
299 
300  //- Contains point (inside or on edge) and moving in direction
301  // dir would cause it to go inside.
302  bool contains(const vector& dir, const point&) const;
303 
304  //- Code position of point on bounding box faces
305  direction faceBits(const point& pt) const;
306 
307  //- Position of point relative to bounding box
308  direction posBits(const point& pt) const;
309 
310  //- Calculate nearest and furthest (to point) vertex coords of
311  // bounding box
312  void calcExtremities
313  (
314  const point& pt,
315  point& nearest,
316  point& furthest
317  ) const;
318 
319  //- Returns distance point to furthest away corner.
320  scalar maxDist(const point& pt) const;
321 
322  //- Compare distance to point with other bounding box
323  // return:
324  // -1 : all vertices of my bounding box are nearer than any of
325  // other
326  // +1 : all vertices of my bounding box are further away than
327  // any of other
328  // 0 : none of the above.
329  label distanceCmp(const point& pt, const treeBoundBox& other) const;
330 
331  //- Return slightly wider bounding box
332  // Extends all dimensions with s*span*Random::sample01<scalar>()
333  // and guarantees in any direction s*mag(span) minimum width
334  inline treeBoundBox extend(Random& rndGen, const scalar s) const;
335 
336 
337  // IOstream operator
338 
339  friend Istream& operator>>(Istream& is, treeBoundBox& bb);
340  friend Ostream& operator<<(Ostream& os, const treeBoundBox& bb);
341 };
342 
343 
344 // * * * * * * * * * * * * * * * * * Traits * * * * * * * * * * * * * * * * //
345 
346 //- Contiguous data for treeBoundBox
347 template<> struct is_contiguous<treeBoundBox> : is_contiguous<boundBox> {};
348 
349 //- Contiguous scalar data for treeBoundBox
350 template<> struct is_contiguous_scalar<treeBoundBox>
351 :
352  is_contiguous_scalar<boundBox>
353 {};
354 
355 
356 // * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * //
357 
358 inline bool operator==(const treeBoundBox& a, const treeBoundBox& b);
359 inline bool operator!=(const treeBoundBox& a, const treeBoundBox& b);
360 
361 
362 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
363 
364 } // End namespace Foam
365 
366 #include "treeBoundBoxI.H"
367 
368 #ifdef NoRepository
369  #include "treeBoundBoxTemplates.C"
370 #endif
371 
372 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
373 
374 #endif
375 
376 // ************************************************************************* //
Foam::treeBoundBox::NOFACE
Definition: treeBoundBox.H:120
Foam::treeBoundBox::TOPHALF
Definition: treeBoundBox.H:101
Foam::treeBoundBox::faceBit
faceBit
Bits used for face encoding.
Definition: treeBoundBox.H:118
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:113
Foam::treeBoundBox::E46
Definition: treeBoundBox.H:141
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:139
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:59
Foam::treeBoundBox::BOTTOMBIT
4: y-min, bottom
Definition: treeBoundBox.H:123
Foam::treeBoundBox::E01
Definition: treeBoundBox.H:133
Foam::treeBoundBox
Standard boundBox with extra functionality for use in octree.
Definition: treeBoundBox.H:87
Foam::treeBoundBox::edgeId
edgeId
Edges codes.
Definition: treeBoundBox.H:131
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:426
Foam::treeBoundBox::TOPBIT
8: y-max, top
Definition: treeBoundBox.H:124
Foam::operator>>
Istream & operator>>(Istream &, directionInfo &)
Definition: directionInfo.C:230
Foam::treeBoundBox::edges
static const edgeList edges
Edge to point addressing.
Definition: treeBoundBox.H:153
Foam::treeBoundBox::E13
Definition: treeBoundBox.H:134
Foam::boundBox::max
const point & max() const
Maximum describing the bounding box.
Definition: boundBoxI.H:97
Foam::treeBoundBox::RIGHTHALF
Definition: treeBoundBox.H:100
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:125
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:235
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:110
Foam::treeBoundBox::posBits
direction posBits(const point &pt) const
Position of point relative to bounding box.
Definition: treeBoundBox.C:391
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:109
Foam::treeBoundBox::faces
static const faceList faces
Face to point addressing.
Definition: treeBoundBox.H:150
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:112
Foam::treeBoundBox::E37
Definition: treeBoundBox.H:145
Foam::treeBoundBox::E45
Definition: treeBoundBox.H:138
Foam::treeBoundBox::BOTTOM
2: y-min, bottom
Definition: treeBoundBox.H:111
Foam::treeBoundBox::LEFTBIT
1: x-min, left
Definition: treeBoundBox.H:121
treeBoundBoxTemplates.C
Foam::treeBoundBox::RIGHTBIT
2: x-max, right
Definition: treeBoundBox.H:122
Foam::treeBoundBox::E67
Definition: treeBoundBox.H:140
Foam::treeBoundBox::faceId
faceId
Definition: treeBoundBox.H:107
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 the Cartesian directions etc.
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:126
pointField.H
boundBox.H
Foam::treeBoundBox::E02
Definition: treeBoundBox.H:136
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:473
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
Definition: treeBoundBox.H:102
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: HashTable.H:102
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:47
Foam::treeBoundBox::E23
Definition: treeBoundBox.H:135
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:114
rndGen
Random rndGen
Definition: createFields.H:23
Foam::treeBoundBox::E26
Definition: treeBoundBox.H:146
Foam::treeBoundBox::distanceCmp
label distanceCmp(const point &pt, const treeBoundBox &other) const
Compare distance to point with other bounding box.
Definition: treeBoundBox.C:483
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:98
Foam::treeBoundBox::E04
Definition: treeBoundBox.H:143
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:144
Foam::treeBoundBox::operator>>
friend Istream & operator>>(Istream &is, treeBoundBox &bb)