BlockMatrixAgglomeration
[foam-extend-3.0.git] / src / foam / meshes / boundBox / boundBox.H
blobeae7efc43b5dac7f6a9b6d76f09aa50cb8e48df4
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | foam-extend: Open Source CFD
4    \\    /   O peration     |
5     \\  /    A nd           | For copyright notice see file Copyright
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
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/>.
24 Class
25     Foam::boundBox
27 Description
28     A bounding box defined in terms of the points at its extremities.
30 \*---------------------------------------------------------------------------*/
32 #ifndef boundBox_H
33 #define boundBox_H
35 #include "pointField.H"
37 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
39 namespace Foam
42 // Forward declaration of friend functions and operators
44 class boundBox;
45 template<class T> class tmp;
47 Ostream& operator<<(Ostream& os, const boundBox& b);
50 /*---------------------------------------------------------------------------*\
51                           Class boundBox Declaration
52 \*---------------------------------------------------------------------------*/
54 class boundBox
56     // Private data
58         //- Minimum and maximum describing the bounding box
59         point min_, max_;
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);
67 public:
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;
81     // Constructors
83         //- Construct null, setting points to zero
84         boundBox()
85         :
86             min_(point::zero),
87             max_(point::zero)
88         {}
90         //- Construct from components
91         boundBox(const point& min, const point& max)
92         :
93             min_(min),
94             max_(max)
95         {}
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
106         boundBox(Istream&);
109     // Member functions
111         // Access
113             //- Minimum describing the bounding box
114             const point& min() const
115             {
116                 return min_;
117             }
119             //- Maximum describing the bounding box
120             const point& max() const
121             {
122                 return max_;
123             }
125             //- Minimum describing the bounding box, non-const access
126             point& min()
127             {
128                 return min_;
129             }
131             //- Maximum describing the bounding box, non-const access
132             point& max()
133             {
134                 return max_;
135             }
137             //- The midpoint of the bounding box
138             point midpoint() const
139             {
140                 return 0.5 * (max_ + min_);
141             }
143             //- The bounding box span (from minimum to maximum)
144             vector span() const
145             {
146                 return (max_ - min_);
147             }
149             //- The magnitude of the bounding box span
150             scalar mag() const
151             {
152                 return ::Foam::mag(max_ - min_);
153             }
155             //- Smallest length/height/width dimension
156             scalar minDim() const
157             {
158                 return cmptMin(span());
159             }
161             //- Largest length/height/width dimension
162             scalar maxDim() const
163             {
164                 return cmptMax(span());
165             }
167             //- Average length/height/width dimension
168             scalar avgDim() const
169             {
170                 return cmptAv(span());
171             }
174         // Query
176             //- Overlaps/touches boundingBox?
177             bool overlaps(const boundBox& bb) const
178             {
179                 return
180                 (
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()
184                 );
185             }
187             //- Contains point? (inside or on edge)
188             bool contains(const point& pt) const
189             {
190                 return
191                 (
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()
195                 );
196             }
198             //- Contains point? (inside only)
199             bool containsInside(const point& pt) const
200             {
201                 return
202                 (
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()
206                 );
207             }
210     // Friend Operators
212         friend bool operator==(const boundBox& a, const boundBox& b)
213         {
214             return (a.min_ == b.min_) && (a.max_ == b.max_);
215         }
217         friend bool operator!=(const boundBox& a, const boundBox& b)
218         {
219             return !(a == b);
220         }
223     // IOstream operator
225         friend Istream& operator>>(Istream& is, boundBox&);
226         friend Ostream& operator<<(Ostream& os, const boundBox&);
230 //- Data associated with boundBox type are contiguous
231 template<>
232 inline bool contiguous<boundBox>() {return contiguous<point>();}
235 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
237 } // End namespace Foam
239 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
241 #endif
243 // ************************************************************************* //