1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
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.
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
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/>.
28 A bounding box defined in terms of the points at its extremities.
30 \*---------------------------------------------------------------------------*/
35 #include "pointField.H"
37 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
42 // Forward declaration of friend functions and operators
45 template<class T> class tmp;
47 Istream& operator>>(Istream&, boundBox&);
48 Ostream& operator<<(Ostream&, const boundBox&);
51 /*---------------------------------------------------------------------------*\
52 Class boundBox Declaration
53 \*---------------------------------------------------------------------------*/
59 //- Minimum and maximum describing the bounding box
62 // Private Member Functions
64 //- Calculate the bounding box from the given points.
65 // Does parallel communication (doReduce = true)
66 void calculate(const UList<point>&, const bool doReduce = true);
70 // Static data members
72 //- The great value used for greatBox and invertedBox
73 static const scalar great;
75 //- A very large boundBox: min/max == -/+ VGREAT
76 static const boundBox greatBox;
78 //- A very large inverted boundBox: min/max == +/- VGREAT
79 static const boundBox invertedBox;
84 //- Construct null, setting points to zero
87 //- Construct from components
88 inline boundBox(const point& min, const point& max);
90 //- Construct as the bounding box of the given points
91 // Does parallel communication (doReduce = true)
92 boundBox(const UList<point>&, const bool doReduce = true);
94 //- Construct as the bounding box of the given temporary pointField.
95 // Does parallel communication (doReduce = true)
96 boundBox(const tmp<pointField>&, const bool doReduce = true);
98 //- Construct bounding box as subset of the pointField.
99 // The indices could be from cell/face etc.
100 // Does parallel communication (doReduce = true)
104 const labelUList& indices,
105 const bool doReduce = true
108 //- Construct bounding box as subset of the pointField.
109 // The indices could be from edge/triFace etc.
110 // Does parallel communication (doReduce = true)
111 template<unsigned Size>
115 const FixedList<label, Size>& indices,
116 const bool doReduce = true
119 //- Construct from Istream
120 inline boundBox(Istream&);
127 //- Minimum describing the bounding box
128 inline const point& min() const;
130 //- Maximum describing the bounding box
131 inline const point& max() const;
133 //- Minimum describing the bounding box, non-const access
136 //- Maximum describing the bounding box, non-const access
139 //- The midpoint of the bounding box
140 inline point midpoint() const;
142 //- The bounding box span (from minimum to maximum)
143 inline vector span() const;
145 //- The magnitude of the bounding box span
146 inline scalar mag() const;
148 //- The volume of the bound box
149 inline scalar volume() const;
151 //- Smallest length/height/width dimension
152 inline scalar minDim() const;
154 //- Largest length/height/width dimension
155 inline scalar maxDim() const;
157 //- Average length/height/width dimension
158 inline scalar avgDim() const;
160 //- Return corner points in an order corresponding to a 'hex' cell
161 tmp<pointField> points() const;
166 //- Inflate box by factor*mag(span) in all dimensions
167 void inflate(const scalar s);
172 //- Overlaps/touches boundingBox?
173 inline bool overlaps(const boundBox&) const;
175 //- Contains point? (inside or on edge)
176 inline bool contains(const point&) const;
178 //- Fully contains other boundingBox?
179 inline bool contains(const boundBox&) const;
181 //- Contains point? (inside only)
182 inline bool containsInside(const point&) const;
184 //- Contains all of the points? (inside or on edge)
185 bool contains(const UList<point>&) const;
187 //- Contains all of the points? (inside or on edge)
191 const labelUList& indices
194 //- Contains all of the points? (inside or on edge)
195 template<unsigned Size>
199 const FixedList<label, Size>& indices
203 //- Contains any of the points? (inside or on edge)
204 bool containsAny(const UList<point>&) const;
206 //- Contains any of the points? (inside or on edge)
210 const labelUList& indices
213 //- Contains any of the points? (inside or on edge)
214 template<unsigned Size>
218 const FixedList<label, Size>& indices
224 inline friend bool operator==(const boundBox&, const boundBox&);
225 inline friend bool operator!=(const boundBox&, const boundBox&);
230 friend Istream& operator>>(Istream&, boundBox&);
231 friend Ostream& operator<<(Ostream&, const boundBox&);
235 //- Data associated with boundBox type are contiguous
237 inline bool contiguous<boundBox>() {return contiguous<point>();}
240 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
242 } // End namespace Foam
244 #include "boundBoxI.H"
247 # include "boundBoxTemplates.C"
250 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
254 // ************************************************************************* //