boundBox.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2024 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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.
15 
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.
20 
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/>.
23 
24 Class
25  Foam::boundBox
26 
27 Description
28  A bounding box defined in terms of the points at its extremities.
29 
30 \*---------------------------------------------------------------------------*/
31 
32 #ifndef boundBox_H
33 #define boundBox_H
34 
35 #include "pointField.H"
36 #include "faceList.H"
37 
38 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
39 
40 namespace Foam
41 {
42 
43 // Forward declaration of friend functions and operators
44 
45 class boundBox;
46 template<class T> class tmp;
47 
48 bool operator==(const boundBox&, const boundBox&);
49 bool operator!=(const boundBox&, const boundBox&);
50 
51 Istream& operator>>(Istream&, boundBox&);
52 Ostream& operator<<(Ostream&, const boundBox&);
53 
54 
55 /*---------------------------------------------------------------------------*\
56  Class boundBox Declaration
57 \*---------------------------------------------------------------------------*/
58 
59 class boundBox
60 {
61  // Private Data
62 
63  //- Minimum and maximum describing the bounding box
64  point min_, max_;
65 
66  // Private Member Functions
67 
68  //- Calculate the bounding box from the given points.
69  // Does parallel communication (doReduce = true)
70  void calculate(const UList<point>&, const bool doReduce = true);
71 
72 public:
73 
74  // Static Data Members
75 
76  //- The great value used for greatBox and invertedBox
77  static const scalar great;
78 
79  //- A very large boundBox: min/max == -/+ vGreat
80  static const boundBox greatBox;
81 
82  //- A very large inverted boundBox: min/max == +/- vGreat
83  static const boundBox invertedBox;
84 
85 
86  // Constructors
87 
88  //- Construct null, setting points to zero
89  inline boundBox();
90 
91  //- Construct from components
92  inline boundBox(const point& min, const point& max);
93 
94  //- Construct as the bounding box of the given points
95  // Does parallel communication (doReduce = true)
96  boundBox(const UList<point>&, const bool doReduce = true);
97 
98  //- Construct as the bounding box of the given temporary pointField.
99  // Does parallel communication (doReduce = true)
100  boundBox(const tmp<pointField>&, const bool doReduce = true);
101 
102  //- Construct bounding box as subset of the pointField.
103  // The indices could be from cell/face etc.
104  // Does parallel communication (doReduce = true)
105  boundBox
106  (
107  const UList<point>&,
108  const labelUList& indices,
109  const bool doReduce = true
110  );
111 
112  //- Construct bounding box as subset of the pointField.
113  // The indices could be from edge/triFace etc.
114  // Does parallel communication (doReduce = true)
115  template<unsigned Size>
116  boundBox
117  (
118  const UList<point>&,
119  const FixedList<label, Size>& indices,
120  const bool doReduce = true
121  );
122 
123  //- Construct from dictionary
124  inline boundBox(const dictionary&);
125 
126  //- Construct from Istream
127  inline boundBox(Istream&);
128 
129 
130  // Member Functions
131 
132  // Access
133 
134  //- Minimum point defining the bounding box
135  inline const point& min() const;
136 
137  //- Maximum point defining the bounding box
138  inline const point& max() const;
139 
140  //- Minimum point defining the bounding box, non-const access
141  inline point& min();
142 
143  //- Maximum point defining the bounding box, non-const access
144  inline point& max();
145 
146  //- The midpoint of the bounding box
147  inline point midpoint() const;
148 
149  //- The bounding box span (from minimum to maximum)
150  inline vector span() const;
151 
152  //- The magnitude of the bounding box span
153  inline scalar mag() const;
154 
155  //- The volume of the bound box
156  inline scalar volume() const;
157 
158  //- Smallest length/height/width dimension
159  inline scalar minDim() const;
160 
161  //- Largest length/height/width dimension
162  inline scalar maxDim() const;
163 
164  //- Average length/height/width dimension
165  inline scalar avgDim() const;
166 
167  //- Return corner points in an order corresponding to a 'hex' cell
168  tmp<pointField> points() const;
169 
170  //- Return faces with correct point order
171  static faceList faces();
172 
173 
174  // Manipulate
175 
176  //- Inflate box by factor*mag(span) in all dimensions
177  void inflate(const scalar s);
178 
179 
180  // Query
181 
182  //- Overlaps/touches boundingBox?
183  inline bool overlaps(const boundBox&) const;
184 
185  //- Overlaps boundingSphere (centre + sqr(radius))?
186  inline bool overlaps(const point&, const scalar radiusSqr) const;
187 
188  //- Contains point? (inside or on edge)
189  inline bool contains(const point&) const;
190 
191  //- Fully contains other boundingBox?
192  inline bool contains(const boundBox&) const;
193 
194  //- Contains point? (inside only)
195  inline bool containsInside(const point&) const;
196 
197  //- Contains all of the points? (inside or on edge)
198  bool contains(const UList<point>&) const;
199 
200  //- Contains all of the points? (inside or on edge)
201  bool contains
202  (
203  const UList<point>&,
204  const labelUList& indices
205  ) const;
206 
207  //- Contains all of the points? (inside or on edge)
208  template<unsigned Size>
209  bool contains
210  (
211  const UList<point>&,
212  const FixedList<label, Size>& indices
213  ) const;
214 
215 
216  //- Contains any of the points? (inside or on edge)
217  bool containsAny(const UList<point>&) const;
218 
219  //- Contains any of the points? (inside or on edge)
220  bool containsAny
221  (
222  const UList<point>&,
223  const labelUList& indices
224  ) const;
225 
226  //- Contains any of the points? (inside or on edge)
227  template<unsigned Size>
228  bool containsAny
229  (
230  const UList<point>&,
231  const FixedList<label, Size>& indices
232  ) const;
233 
234  //- Return the nearest point on the boundBox to the supplied point.
235  // If point is inside the boundBox then the point is returned
236  // unchanged.
237  point nearest(const point&) const;
238 
239 
240  // Friend Operators
241 
242  inline friend bool operator==(const boundBox&, const boundBox&);
243  inline friend bool operator!=(const boundBox&, const boundBox&);
244 
245 
246  // IOstream operator
247 
249  friend Ostream& operator<<(Ostream&, const boundBox&);
250 };
251 
252 
253 //- Data associated with boundBox type are contiguous
254 template<>
255 inline bool contiguous<boundBox>() {return contiguous<point>();}
256 
257 
258 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
259 
260 } // End namespace Foam
261 
262 #include "boundBoxI.H"
263 
264 #ifdef NoRepository
265  #include "boundBoxTemplates.C"
266 #endif
267 
268 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
269 
270 #endif
271 
272 // ************************************************************************* //
A 1D vector of objects of type <T> with a fixed size <Size>.
Definition: FixedList.H:78
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:60
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
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:74
A bounding box defined in terms of the points at its extremities.
Definition: boundBox.H:59
point nearest(const point &) const
Return the nearest point on the boundBox to the supplied point.
Definition: boundBox.C:292
const point & min() const
Minimum point defining the bounding box.
Definition: boundBoxI.H:60
const point & max() const
Maximum point defining the bounding box.
Definition: boundBoxI.H:66
static const boundBox invertedBox
A very large inverted boundBox: min/max == +/- vGreat.
Definition: boundBox.H:82
static const scalar great
The great value used for greatBox and invertedBox.
Definition: boundBox.H:76
scalar volume() const
The volume of the bound box.
Definition: boundBoxI.H:102
friend bool operator==(const boundBox &, const boundBox &)
friend bool operator!=(const boundBox &, const boundBox &)
bool overlaps(const boundBox &) const
Overlaps/touches boundingBox?
Definition: boundBoxI.H:126
static const boundBox greatBox
A very large boundBox: min/max == -/+ vGreat.
Definition: boundBox.H:79
static faceList faces()
Return faces with correct point order.
Definition: boundBox.C:156
void inflate(const scalar s)
Inflate box by factor*mag(span) in all dimensions.
Definition: boundBox.C:199
bool contains(const point &) const
Contains point? (inside or on edge)
Definition: boundBoxI.H:176
friend Ostream & operator<<(Ostream &, const boundBox &)
scalar minDim() const
Smallest length/height/width dimension.
Definition: boundBoxI.H:108
scalar mag() const
The magnitude of the bounding box span.
Definition: boundBoxI.H:96
scalar avgDim() const
Average length/height/width dimension.
Definition: boundBoxI.H:120
bool containsAny(const UList< point > &) const
Contains any of the points? (inside or on edge)
Definition: boundBox.C:250
boundBox()
Construct null, setting points to zero.
Definition: boundBoxI.H:31
friend Istream & operator>>(Istream &, boundBox &)
point midpoint() const
The midpoint of the bounding box.
Definition: boundBoxI.H:84
vector span() const
The bounding box span (from minimum to maximum)
Definition: boundBoxI.H:90
scalar maxDim() const
Largest length/height/width dimension.
Definition: boundBoxI.H:114
bool containsInside(const point &) const
Contains point? (inside only)
Definition: boundBoxI.H:194
tmp< pointField > points() const
Return corner points in an order corresponding to a 'hex' cell.
Definition: boundBox.C:138
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:162
A class for managing temporary objects.
Definition: tmp.H:55
gmvFile<< "tracers "<< particles.size()<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().x()<< " ";}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().y()<< " ";}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().z()<< " ";}gmvFile<< nl;forAll(lagrangianScalarNames, i){ word name=lagrangianScalarNames[i];IOField< scalar > s(IOobject(name, runTime.name(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
Namespace for OpenFOAM.
bool operator!=(const particle &, const particle &)
Definition: particle.C:1210
tmp< fvMatrix< Type > > operator==(const fvMatrix< Type > &, const fvMatrix< Type > &)
bool contiguous< boundBox >()
Data associated with boundBox type are contiguous.
Definition: boundBox.H:254
Istream & operator>>(Istream &, pistonPointEdgeData &)
Ostream & operator<<(Ostream &os, const fvConstraints &constraints)