1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd.
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/>.
24 \*---------------------------------------------------------------------------*/
27 #include "PstreamReduceOps.H"
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32 const Foam::scalar Foam::boundBox::great(VGREAT);
34 const Foam::boundBox Foam::boundBox::greatBox
36 point(-VGREAT, -VGREAT, -VGREAT),
37 point(VGREAT, VGREAT, VGREAT)
41 const Foam::boundBox Foam::boundBox::invertedBox
43 point(VGREAT, VGREAT, VGREAT),
44 point(-VGREAT, -VGREAT, -VGREAT)
48 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
50 void Foam::boundBox::calculate(const UList<point>& points, const bool doReduce)
57 if (doReduce && Pstream::parRun())
59 // Use values that get overwritten by reduce minOp, maxOp below
60 min_ = point(VGREAT, VGREAT, VGREAT);
61 max_ = point(-VGREAT, -VGREAT, -VGREAT);
69 for (label i = 1; i < points.size(); i++)
71 min_ = ::Foam::min(min_, points[i]);
72 max_ = ::Foam::max(max_, points[i]);
76 // Reduce parallel information
79 reduce(min_, minOp<point>());
80 reduce(max_, maxOp<point>());
85 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
87 Foam::boundBox::boundBox(const UList<point>& points, const bool doReduce)
92 calculate(points, doReduce);
96 Foam::boundBox::boundBox(const tmp<pointField>& points, const bool doReduce)
101 calculate(points(), doReduce);
106 Foam::boundBox::boundBox
108 const UList<point>& points,
109 const labelUList& indices,
116 if (points.empty() || indices.empty())
118 if (doReduce && Pstream::parRun())
120 // Use values that get overwritten by reduce minOp, maxOp below
121 min_ = point(VGREAT, VGREAT, VGREAT);
122 max_ = point(-VGREAT, -VGREAT, -VGREAT);
127 min_ = points[indices[0]];
128 max_ = points[indices[0]];
130 for (label i=1; i < indices.size(); ++i)
132 min_ = ::Foam::min(min_, points[indices[i]]);
133 max_ = ::Foam::max(max_, points[indices[i]]);
137 // Reduce parallel information
140 reduce(min_, minOp<point>());
141 reduce(max_, maxOp<point>());
146 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
148 Foam::tmp<Foam::pointField> Foam::boundBox::points() const
150 tmp<pointField> tPts = tmp<pointField>(new pointField(8));
151 pointField& pt = tPts();
153 pt[0] = min_; // min-x, min-y, min-z
154 pt[1] = point(max_.x(), min_.y(), min_.z()); // max-x, min-y, min-z
155 pt[2] = point(max_.x(), max_.y(), min_.z()); // max-x, max-y, min-z
156 pt[3] = point(min_.x(), max_.y(), min_.z()); // min-x, max-y, min-z
157 pt[4] = point(min_.x(), min_.y(), max_.z()); // min-x, min-y, max-z
158 pt[5] = point(max_.x(), min_.y(), max_.z()); // max-x, min-y, max-z
159 pt[6] = max_; // max-x, max-y, max-z
160 pt[7] = point(min_.x(), max_.y(), max_.z()); // min-x, max-y, max-z
166 bool Foam::boundBox::contains(const UList<point>& points) const
175 if (!contains(points[i]))
185 bool Foam::boundBox::contains
187 const UList<point>& points,
188 const labelUList& indices
191 if (points.empty() || indices.empty())
198 if (!contains(points[indices[i]]))
208 bool Foam::boundBox::containsAny(const UList<point>& points) const
217 if (contains(points[i]))
227 bool Foam::boundBox::containsAny
229 const UList<point>& points,
230 const labelUList& indices
233 if (points.empty() || indices.empty())
240 if (contains(points[indices[i]]))
250 // * * * * * * * * * * * * * * * Ostream Operator * * * * * * * * * * * * * //
252 Foam::Ostream& Foam::operator<<(Ostream& os, const boundBox& bb)
254 if (os.format() == IOstream::ASCII)
256 os << bb.min_ << token::SPACE << bb.max_;
262 reinterpret_cast<const char*>(&bb.min_),
267 // Check state of Ostream
268 os.check("Ostream& operator<<(Ostream&, const boundBox&)");
273 Foam::Istream& Foam::operator>>(Istream& is, boundBox& bb)
275 if (is.format() == IOstream::ASCII)
277 is >> bb.min_ >> bb.max_;
283 reinterpret_cast<char*>(&bb.min_),
288 // Check state of Istream
289 is.check("Istream& operator>>(Istream&, boundBox&)");
294 // ************************************************************************* //