1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | foam-extend: Open Source CFD
5 \\ / A nd | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
9 This file is part of foam-extend.
11 foam-extend is free software: you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by the
13 Free Software Foundation, either version 3 of the License, or (at your
14 option) any later version.
16 foam-extend is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with foam-extend. 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 Ostream& operator<<(Ostream& os, const boundBox& b);
50 /*---------------------------------------------------------------------------*\
51 Class boundBox Declaration
52 \*---------------------------------------------------------------------------*/
58 //- Minimum and maximum describing the bounding box
61 // Private Member Functions
63 //- Calculate the bounding box from the given pointField.
64 // Does parallel communication (doReduce = true)
65 void calculate(const pointField&, const bool doReduce = true);
69 // Static data members
71 //- The great value used for greatBox and invertedBox
72 static const scalar great;
74 //- A very large boundBox: min/max == -/+ VGREAT
75 static const boundBox greatBox;
77 //- A very large inverted boundBox: min/max == +/- VGREAT
78 static const boundBox invertedBox;
83 //- Construct null, setting points to zero
90 //- Construct from components
91 boundBox(const point& min, const point& max)
97 //- Construct as the bounding box of the given pointField.
98 // Does parallel communication (doReduce = true)
99 boundBox(const pointField&, const bool doReduce = true);
101 //- Construct as the bounding box of the given temporary pointField.
102 // Does parallel communication (doReduce = true)
103 boundBox(const tmp<pointField>&, const bool doReduce = true);
105 //- Construct from Istream
113 //- Minimum describing the bounding box
114 const point& min() const
119 //- Maximum describing the bounding box
120 const point& max() const
125 //- Minimum describing the bounding box, non-const access
131 //- Maximum describing the bounding box, non-const access
137 //- The midpoint of the bounding box
138 point midpoint() const
140 return 0.5 * (max_ + min_);
143 //- The bounding box span (from minimum to maximum)
146 return (max_ - min_);
149 //- The magnitude of the bounding box span
152 return ::Foam::mag(max_ - min_);
155 //- Smallest length/height/width dimension
156 scalar minDim() const
158 return cmptMin(span());
161 //- Largest length/height/width dimension
162 scalar maxDim() const
164 return cmptMax(span());
167 //- Average length/height/width dimension
168 scalar avgDim() const
170 return cmptAv(span());
176 //- Overlaps/touches boundingBox?
177 bool overlaps(const boundBox& bb) const
181 bb.max_.x() >= min_.x() && bb.min_.x() <= max_.x()
182 && bb.max_.y() >= min_.y() && bb.min_.y() <= max_.y()
183 && bb.max_.z() >= min_.z() && bb.min_.z() <= max_.z()
187 //- Contains point? (inside or on edge)
188 bool contains(const point& pt) const
192 pt.x() >= min_.x() && pt.x() <= max_.x()
193 && pt.y() >= min_.y() && pt.y() <= max_.y()
194 && pt.z() >= min_.z() && pt.z() <= max_.z()
198 //- Contains point? (inside only)
199 bool containsInside(const point& pt) const
203 pt.x() > min_.x() && pt.x() < max_.x()
204 && pt.y() > min_.y() && pt.y() < max_.y()
205 && pt.z() > min_.z() && pt.z() < max_.z()
212 friend bool operator==(const boundBox& a, const boundBox& b)
214 return (a.min_ == b.min_) && (a.max_ == b.max_);
217 friend bool operator!=(const boundBox& a, const boundBox& b)
225 friend Istream& operator>>(Istream& is, boundBox&);
226 friend Ostream& operator<<(Ostream& os, const boundBox&);
230 //- Data associated with boundBox type are contiguous
232 inline bool contiguous<boundBox>() {return contiguous<point>();}
235 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
237 } // End namespace Foam
239 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
243 // ************************************************************************* //