FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

boundBox.C

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2010 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software: you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by
00013     the Free Software Foundation, either version 3 of the License, or
00014     (at your option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.
00023 
00024 \*---------------------------------------------------------------------------*/
00025 
00026 #include "boundBox.H"
00027 #include <OpenFOAM/PstreamReduceOps.H>
00028 #include <OpenFOAM/tmp.H>
00029 
00030 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
00031 
00032 const Foam::scalar Foam::boundBox::great(VGREAT);
00033 
00034 const Foam::boundBox Foam::boundBox::greatBox
00035 (
00036     point(-VGREAT, -VGREAT, -VGREAT),
00037     point(VGREAT, VGREAT, VGREAT)
00038 );
00039 
00040 
00041 const Foam::boundBox Foam::boundBox::invertedBox
00042 (
00043     point(VGREAT, VGREAT, VGREAT),
00044     point(-VGREAT, -VGREAT, -VGREAT)
00045 );
00046 
00047 
00048 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
00049 
00050 void Foam::boundBox::calculate(const pointField& points, const bool doReduce)
00051 {
00052     if (points.empty())
00053     {
00054         min_ = point::zero;
00055         max_ = point::zero;
00056 
00057         if (doReduce && Pstream::parRun())
00058         {
00059             // Use values that get overwritten by reduce minOp, maxOp below
00060             min_ = point(VGREAT, VGREAT, VGREAT);
00061             max_ = point(-VGREAT, -VGREAT, -VGREAT);
00062         }
00063     }
00064     else
00065     {
00066         min_ = points[0];
00067         max_ = points[0];
00068 
00069         for (label i = 1; i < points.size(); i++)
00070         {
00071             min_ = ::Foam::min(min_, points[i]);
00072             max_ = ::Foam::max(max_, points[i]);
00073         }
00074     }
00075 
00076     // Reduce parallel information
00077     if (doReduce)
00078     {
00079         reduce(min_, minOp<point>());
00080         reduce(max_, maxOp<point>());
00081     }
00082 }
00083 
00084 
00085 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00086 
00087 Foam::boundBox::boundBox(const pointField& points, const bool doReduce)
00088 :
00089     min_(point::zero),
00090     max_(point::zero)
00091 {
00092     calculate(points, doReduce);
00093 }
00094 
00095 
00096 Foam::boundBox::boundBox(const tmp<pointField>& points, const bool doReduce)
00097 :
00098     min_(point::zero),
00099     max_(point::zero)
00100 {
00101     calculate(points(), doReduce);
00102     points.clear();
00103 }
00104 
00105 
00106 Foam::boundBox::boundBox(Istream& is)
00107 {
00108     operator>>(is, *this);
00109 }
00110 
00111 
00112 // * * * * * * * * * * * * * * * Ostream Operator  * * * * * * * * * * * * * //
00113 
00114 Foam::Ostream& Foam::operator<<(Ostream& os, const boundBox& bb)
00115 {
00116     if (os.format() == IOstream::ASCII)
00117     {
00118         os << bb.min_ << token::SPACE << bb.max_;
00119     }
00120     else
00121     {
00122         os.write
00123         (
00124             reinterpret_cast<const char*>(&bb.min_),
00125             sizeof(boundBox)
00126         );
00127     }
00128 
00129     // Check state of Ostream
00130     os.check("Ostream& operator<<(Ostream&, const boundBox&)");
00131     return os;
00132 }
00133 
00134 
00135 Foam::Istream& Foam::operator>>(Istream& is, boundBox& bb)
00136 {
00137     if (is.format() == IOstream::ASCII)
00138     {
00139         return is >> bb.min_ >> bb.max_;
00140     }
00141     else
00142     {
00143         is.read
00144         (
00145             reinterpret_cast<char*>(&bb.min_),
00146             sizeof(boundBox)
00147         );
00148     }
00149 
00150     // Check state of Istream
00151     is.check("Istream& operator>>(Istream&, boundBox&)");
00152     return is;
00153 }
00154 
00155 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines