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-2026 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 #include "scalable.H"
38 
39 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
40 
41 namespace Foam
42 {
43 
44 // Forward declaration of friend functions and operators
45 
46 class boundBox;
47 template<class T> class tmp;
48 
49 bool operator==(const boundBox&, const boundBox&);
50 bool operator!=(const boundBox&, const boundBox&);
51 
52 Istream& operator>>(Istream&, boundBox&);
53 Ostream& operator<<(Ostream&, const boundBox&);
54 
55 
56 /*---------------------------------------------------------------------------*\
57  Class boundBox Declaration
58 \*---------------------------------------------------------------------------*/
59 
60 class boundBox
61 {
62  // Private Data
63 
64  //- Minimum and maximum describing the bounding box
65  point min_, max_;
66 
67  // Private Member Functions
68 
69  //- Calculate the bounding box from the given points.
70  // Does parallel communication (doReduce = true)
71  void calculate(const UList<point>&, const bool doReduce = true);
72 
73 public:
74 
75  // Static Data Members
76 
77  //- A very large boundBox: min/max == -/+ vGreat
78  static const boundBox greatBox;
79 
80  //- A very large inverted boundBox: min/max == +/- vGreat
81  static const boundBox invertedBox;
82 
83 
84  // Static Member Functions
85 
86  //- Does the dictionary have a bound box specified in it?
87  inline static bool found(const dictionary& dict);
88 
89 
90  // Constructors
91 
92  //- Construct null, setting points to zero
93  inline boundBox();
94 
95  //- Construct from components
96  inline boundBox(const point& min, const point& max);
97 
98  //- Construct as the bounding box of the given points
99  // Does parallel communication (doReduce = true)
100  boundBox(const UList<point>&, const bool doReduce = true);
101 
102  //- Construct as the bounding box of the given temporary pointField.
103  // Does parallel communication (doReduce = true)
104  boundBox(const tmp<pointField>&, const bool doReduce = true);
105 
106  //- Construct bounding box as subset of the pointField.
107  // The indices could be from cell/face etc.
108  // Does parallel communication (doReduce = true)
109  boundBox
110  (
111  const UList<point>&,
112  const labelUList& indices,
113  const bool doReduce = true
114  );
115 
116  //- Construct bounding box as subset of the pointField.
117  // The indices could be from edge/triFace etc.
118  // Does parallel communication (doReduce = true)
119  template<unsigned Size>
120  boundBox
121  (
122  const UList<point>&,
123  const FixedList<label, Size>& indices,
124  const bool doReduce = true
125  );
126 
127  //- Construct from Istream
128  inline boundBox(Istream&);
129 
130  //- Construct from dictionary
131  inline boundBox(const dictionary&);
132 
133 
134  // Member Functions
135 
136  // Access
137 
138  //- Minimum point defining the bounding box
139  inline const point& min() const;
140 
141  //- Maximum point defining the bounding box
142  inline const point& max() const;
143 
144  //- Minimum point defining the bounding box, non-const access
145  inline point& min();
146 
147  //- Maximum point defining the bounding box, non-const access
148  inline point& max();
149 
150  //- The midpoint of the bounding box
151  inline point midpoint() const;
152 
153  //- The bounding box span (from minimum to maximum)
154  inline vector span() const;
155 
156  //- The magnitude of the bounding box span
157  inline scalar mag() const;
158 
159  //- The volume of the bound box
160  inline scalar volume() const;
161 
162  //- Smallest length/height/width dimension
163  inline scalar minDim() const;
164 
165  //- Largest length/height/width dimension
166  inline scalar maxDim() const;
167 
168  //- Average length/height/width dimension
169  inline scalar avgDim() const;
170 
171  //- Return corner points in an order corresponding to a 'hex' cell
172  tmp<pointField> points() const;
173 
174  //- Return faces with correct point order
175  static faceList faces();
176 
177 
178  // Manipulate
179 
180  //- Inflate box by factor*mag(span) in all dimensions
181  void inflate(const scalar s);
182 
183 
184  // Query
185 
186  //- Overlaps/touches boundingBox?
187  inline bool overlaps(const boundBox&) const;
188 
189  //- Overlaps boundingSphere (centre + sqr(radius))?
190  inline bool overlaps(const point&, const scalar radiusSqr) const;
191 
192  //- Contains point? (inside or on edge)
193  inline bool contains(const point&) const;
194 
195  //- Fully contains other boundingBox?
196  inline bool contains(const boundBox&) const;
197 
198  //- Contains point? (inside only)
199  inline bool containsInside(const point&) const;
200 
201  //- Contains all of the points? (inside or on edge)
202  bool contains(const UList<point>&) const;
203 
204  //- Contains all of the points? (inside or on edge)
205  bool contains
206  (
207  const UList<point>&,
208  const labelUList& indices
209  ) const;
210 
211  //- Contains all of the points? (inside or on edge)
212  template<unsigned Size>
213  bool contains
214  (
215  const UList<point>&,
216  const FixedList<label, Size>& indices
217  ) const;
218 
219 
220  //- Contains any of the points? (inside or on edge)
221  bool containsAny(const UList<point>&) const;
222 
223  //- Contains any of the points? (inside or on edge)
224  bool containsAny
225  (
226  const UList<point>&,
227  const labelUList& indices
228  ) const;
229 
230  //- Contains any of the points? (inside or on edge)
231  template<unsigned Size>
232  bool containsAny
233  (
234  const UList<point>&,
235  const FixedList<label, Size>& indices
236  ) const;
237 
238  //- Return the nearest point on the boundBox to the supplied point.
239  // If point is inside the boundBox then the point is returned
240  // unchanged.
241  point nearest(const point&) const;
242 
243 
244  // Friend Operators
245 
246  inline friend bool operator==(const boundBox&, const boundBox&);
247  inline friend bool operator!=(const boundBox&, const boundBox&);
248 
249 
250  // IOstream operator
251 
253  friend Ostream& operator<<(Ostream&, const boundBox&);
254 };
255 
256 
257 //- Data associated with boundBox type are contiguous
258 template<>
259 inline bool contiguous<boundBox>() {return contiguous<point>();}
260 
261 
262 //- A boundBox is scalable
263 template<>
264 struct scalable<boundBox> : public std::true_type {};
265 
266 //- Apply a conversion to a boundBox by applying separately to min and max
267 template<class ... Args>
268 void convert(boundBox& bb, const Args& ... args)
269 {
270  convert(bb.min(), args ...);
271  convert(bb.max(), args ...);
272 }
273 
274 
275 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
276 
277 } // End namespace Foam
278 
279 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
280 
281 #include "boundBoxI.H"
282 
283 #ifdef NoRepository
284  #include "boundBoxTemplates.C"
285 #endif
286 
287 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
288 
289 #endif
290 
291 // ************************************************************************* //
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:60
static bool found(const dictionary &dict)
Does the dictionary have a bound box specified in it?
Definition: boundBoxI.H:31
point nearest(const point &) const
Return the nearest point on the boundBox to the supplied point.
Definition: boundBox.C:300
const point & min() const
Minimum point defining the bounding box.
Definition: boundBoxI.H:88
const point & max() const
Maximum point defining the bounding box.
Definition: boundBoxI.H:94
static const boundBox invertedBox
A very large inverted boundBox: min/max == +/- vGreat.
Definition: boundBox.H:80
scalar volume() const
The volume of the bound box.
Definition: boundBoxI.H:130
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:154
static const boundBox greatBox
A very large boundBox: min/max == -/+ vGreat.
Definition: boundBox.H:77
static faceList faces()
Return faces with correct point order.
Definition: boundBox.C:164
void inflate(const scalar s)
Inflate box by factor*mag(span) in all dimensions.
Definition: boundBox.C:207
bool contains(const point &) const
Contains point? (inside or on edge)
Definition: boundBoxI.H:204
friend Ostream & operator<<(Ostream &, const boundBox &)
scalar minDim() const
Smallest length/height/width dimension.
Definition: boundBoxI.H:136
scalar mag() const
The magnitude of the bounding box span.
Definition: boundBoxI.H:124
scalar avgDim() const
Average length/height/width dimension.
Definition: boundBoxI.H:148
bool containsAny(const UList< point > &) const
Contains any of the points? (inside or on edge)
Definition: boundBox.C:258
boundBox()
Construct null, setting points to zero.
Definition: boundBoxI.H:39
friend Istream & operator>>(Istream &, boundBox &)
point midpoint() const
The midpoint of the bounding box.
Definition: boundBoxI.H:112
vector span() const
The bounding box span (from minimum to maximum)
Definition: boundBoxI.H:118
scalar maxDim() const
Largest length/height/width dimension.
Definition: boundBoxI.H:142
bool containsInside(const point &) const
Contains point? (inside only)
Definition: boundBoxI.H:222
tmp< pointField > points() const
Return corner points in an order corresponding to a 'hex' cell.
Definition: boundBox.C:146
A list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Definition: dictionary.H:162
A class for managing temporary objects.
Definition: tmp.H:55
gmvFile<< "tracers "<< particles.size()<< nl;forAllConstIter(lagrangian::Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().x()<< " ";}gmvFile<< nl;forAllConstIter(lagrangian::Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().y()<< " ";}gmvFile<< nl;forAllConstIter(lagrangian::Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().z()<< " ";}gmvFile<< nl;forAll(lagrangianScalarNames, i){ word name=lagrangianScalarNames[i];IOField< scalar > s(IOobject(name, runTime.name(), lagrangian::cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
Namespace for OpenFOAM.
bool operator!=(const particle &, const particle &)
Definition: particle.C:445
Istream & operator>>(Istream &, pointEdgeDist &)
Definition: pointEdgeDist.C:41
tmp< fvMatrix< Type > > operator==(const fvMatrix< Type > &, const fvMatrix< Type > &)
bool contiguous< boundBox >()
Data associated with boundBox type are contiguous.
Definition: boundBox.H:258
Ostream & operator<<(Ostream &os, const fvConstraints &constraints)
void convert(UList< Type > &l, const Args &... args)
Apply a conversion to a UList by applying to each element individually.
Definition: UList.H:421
Trait to identify types which are "scalable"; i.e., that can be multiply-equals-d with a scalar....
dictionary dict
Foam::argList args(argc, argv)