boundBox.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 | Copyright (C) 2011-2012 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 Istream& operator>>(Istream&, boundBox&);
49 Ostream& operator<<(Ostream&, const boundBox&);
50 
51 
52 /*---------------------------------------------------------------------------*\
53  Class boundBox Declaration
54 \*---------------------------------------------------------------------------*/
55 
56 class boundBox
57 {
58  // Private data
59 
60  //- Minimum and maximum describing the bounding box
61  point min_, max_;
62 
63  // Private Member Functions
64 
65  //- Calculate the bounding box from the given points.
66  // Does parallel communication (doReduce = true)
67  void calculate(const UList<point>&, const bool doReduce = true);
68 
69 public:
70 
71  // Static data members
72 
73  //- The great value used for greatBox and invertedBox
74  static const scalar great;
75 
76  //- A very large boundBox: min/max == -/+ VGREAT
77  static const boundBox greatBox;
78 
79  //- A very large inverted boundBox: min/max == +/- VGREAT
80  static const boundBox invertedBox;
81 
82 
83  // Constructors
84 
85  //- Construct null, setting points to zero
86  inline boundBox();
87 
88  //- Construct from components
89  inline boundBox(const point& min, const point& max);
90 
91  //- Construct as the bounding box of the given points
92  // Does parallel communication (doReduce = true)
93  boundBox(const UList<point>&, const bool doReduce = true);
94 
95  //- Construct as the bounding box of the given temporary pointField.
96  // Does parallel communication (doReduce = true)
97  boundBox(const tmp<pointField>&, const bool doReduce = true);
98 
99  //- Construct bounding box as subset of the pointField.
100  // The indices could be from cell/face etc.
101  // Does parallel communication (doReduce = true)
102  boundBox
103  (
104  const UList<point>&,
105  const labelUList& indices,
106  const bool doReduce = true
107  );
108 
109  //- Construct bounding box as subset of the pointField.
110  // The indices could be from edge/triFace etc.
111  // Does parallel communication (doReduce = true)
112  template<unsigned Size>
113  boundBox
114  (
115  const UList<point>&,
116  const FixedList<label, Size>& indices,
117  const bool doReduce = true
118  );
119 
120  //- Construct from Istream
121  inline boundBox(Istream&);
122 
123 
124  // Member functions
125 
126  // Access
127 
128  //- Minimum describing the bounding box
129  inline const point& min() const;
130 
131  //- Maximum describing the bounding box
132  inline const point& max() const;
133 
134  //- Minimum describing the bounding box, non-const access
135  inline point& min();
136 
137  //- Maximum describing the bounding box, non-const access
138  inline point& max();
139 
140  //- The midpoint of the bounding box
141  inline point midpoint() const;
142 
143  //- The bounding box span (from minimum to maximum)
144  inline vector span() const;
145 
146  //- The magnitude of the bounding box span
147  inline scalar mag() const;
148 
149  //- The volume of the bound box
150  inline scalar volume() const;
151 
152  //- Smallest length/height/width dimension
153  inline scalar minDim() const;
154 
155  //- Largest length/height/width dimension
156  inline scalar maxDim() const;
157 
158  //- Average length/height/width dimension
159  inline scalar avgDim() const;
160 
161  //- Return corner points in an order corresponding to a 'hex' cell
162  tmp<pointField> points() const;
163 
164  //- Return faces with correct point order
165  static faceList faces();
166 
167 
168  // Manipulate
169 
170  //- Inflate box by factor*mag(span) in all dimensions
171  void inflate(const scalar s);
172 
173 
174  // Query
175 
176  //- Overlaps/touches boundingBox?
177  inline bool overlaps(const boundBox&) const;
178 
179  //- Overlaps boundingSphere (centre + sqr(radius))?
180  inline bool overlaps(const point&, const scalar radiusSqr) const;
181 
182  //- Contains point? (inside or on edge)
183  inline bool contains(const point&) const;
184 
185  //- Fully contains other boundingBox?
186  inline bool contains(const boundBox&) const;
187 
188  //- Contains point? (inside only)
189  inline bool containsInside(const point&) const;
190 
191  //- Contains all of the points? (inside or on edge)
192  bool contains(const UList<point>&) const;
193 
194  //- Contains all of the points? (inside or on edge)
195  bool contains
196  (
197  const UList<point>&,
198  const labelUList& indices
199  ) const;
200 
201  //- Contains all of the points? (inside or on edge)
202  template<unsigned Size>
203  bool contains
204  (
205  const UList<point>&,
206  const FixedList<label, Size>& indices
207  ) const;
208 
209 
210  //- Contains any of the points? (inside or on edge)
211  bool containsAny(const UList<point>&) const;
212 
213  //- Contains any of the points? (inside or on edge)
214  bool containsAny
215  (
216  const UList<point>&,
217  const labelUList& indices
218  ) const;
219 
220  //- Contains any of the points? (inside or on edge)
221  template<unsigned Size>
222  bool containsAny
223  (
224  const UList<point>&,
225  const FixedList<label, Size>& indices
226  ) const;
227 
228  //- Return the nearest point on the boundBox to the supplied point.
229  // If point is inside the boundBox then the point is returned
230  // unchanged.
231  point nearest(const point&) const;
232 
233 
234  // Friend Operators
235 
236  inline friend bool operator==(const boundBox&, const boundBox&);
237  inline friend bool operator!=(const boundBox&, const boundBox&);
238 
239 
240  // IOstream operator
241 
242  friend Istream& operator>>(Istream&, boundBox&);
243  friend Ostream& operator<<(Ostream&, const boundBox&);
244 };
245 
246 
247 //- Data associated with boundBox type are contiguous
248 template<>
249 inline bool contiguous<boundBox>() {return contiguous<point>();}
250 
251 
252 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
253 
254 } // End namespace Foam
255 
256 #include "boundBoxI.H"
257 
258 #ifdef NoRepository
259 # include "boundBoxTemplates.C"
260 #endif
261 
262 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
263 
264 #endif
265 
266 // ************************************************************************* //
const point & min() const
Minimum describing the bounding box.
Definition: boundBoxI.H:54
boundBox()
Construct null, setting points to zero.
Definition: boundBoxI.H:32
scalar avgDim() const
Average length/height/width dimension.
Definition: boundBoxI.H:114
scalar minDim() const
Smallest length/height/width dimension.
Definition: boundBoxI.H:102
static const boundBox invertedBox
A very large inverted boundBox: min/max == +/- VGREAT.
Definition: boundBox.H:79
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.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE ))
scalar mag() const
The magnitude of the bounding box span.
Definition: boundBoxI.H:90
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
vector span() const
The bounding box span (from minimum to maximum)
Definition: boundBoxI.H:84
bool containsAny(const UList< point > &) const
Contains any of the points? (inside or on edge)
Definition: boundBox.C:261
point nearest(const point &) const
Return the nearest point on the boundBox to the supplied point.
Definition: boundBox.C:303
friend Ostream & operator<<(Ostream &, const boundBox &)
A 1D vector of objects of type <T> with a fixed size <Size>.
Definition: FixedList.H:53
Ostream & operator<<(Ostream &, const edgeMesh &)
Definition: edgeMeshIO.C:133
tmp< pointField > points() const
Return corner points in an order corresponding to a &#39;hex&#39; cell.
Definition: boundBox.C:149
Namespace for OpenFOAM.
friend bool operator==(const boundBox &, const boundBox &)
static faceList faces()
Return faces with correct point order.
Definition: boundBox.C:167
friend Istream & operator>>(Istream &, boundBox &)
static const scalar great
The great value used for greatBox and invertedBox.
Definition: boundBox.H:73
static const boundBox greatBox
A very large boundBox: min/max == -/+ VGREAT.
Definition: boundBox.H:76
const point & max() const
Maximum describing the bounding box.
Definition: boundBoxI.H:60
A bounding box defined in terms of the points at its extremities.
Definition: boundBox.H:55
point midpoint() const
The midpoint of the bounding box.
Definition: boundBoxI.H:78
bool contains(const point &) const
Contains point? (inside or on edge)
Definition: boundBoxI.H:170
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:60
Istream & operator>>(Istream &, edgeMesh &)
Definition: edgeMeshIO.C:144
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
scalar maxDim() const
Largest length/height/width dimension.
Definition: boundBoxI.H:108
bool contiguous< boundBox >()
Data associated with boundBox type are contiguous.
Definition: boundBox.H:248
bool containsInside(const point &) const
Contains point? (inside only)
Definition: boundBoxI.H:188
scalar volume() const
The volume of the bound box.
Definition: boundBoxI.H:96
void inflate(const scalar s)
Inflate box by factor*mag(span) in all dimensions.
Definition: boundBox.C:210
friend bool operator!=(const boundBox &, const boundBox &)
bool overlaps(const boundBox &) const
Overlaps/touches boundingBox?
Definition: boundBoxI.H:120
A class for managing temporary objects.
Definition: PtrList.H:118