boundBox.C
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include "boundBox.H"
00028 #include "PstreamReduceOps.H"
00029 #include "tmp.H"
00030
00031
00032
00033 const Foam::scalar Foam::boundBox::great(VGREAT);
00034
00035 const Foam::boundBox Foam::boundBox::greatBox
00036 (
00037 point(-VGREAT, -VGREAT, -VGREAT),
00038 point(VGREAT, VGREAT, VGREAT)
00039 );
00040
00041
00042 const Foam::boundBox Foam::boundBox::invertedBox
00043 (
00044 point(VGREAT, VGREAT, VGREAT),
00045 point(-VGREAT, -VGREAT, -VGREAT)
00046 );
00047
00048
00049
00050
00051 void Foam::boundBox::calculate(const pointField& points, const bool doReduce)
00052 {
00053 if (points.empty())
00054 {
00055 min_ = point::zero;
00056 max_ = point::zero;
00057
00058 if (doReduce && Pstream::parRun())
00059 {
00060
00061 min_ = point(VGREAT, VGREAT, VGREAT);
00062 max_ = point(-VGREAT, -VGREAT, -VGREAT);
00063 }
00064 }
00065 else
00066 {
00067 min_ = points[0];
00068 max_ = points[0];
00069
00070 for (label i = 1; i < points.size(); i++)
00071 {
00072 min_ = ::Foam::min(min_, points[i]);
00073 max_ = ::Foam::max(max_, points[i]);
00074 }
00075 }
00076
00077
00078 if (doReduce)
00079 {
00080 reduce(min_, minOp<point>());
00081 reduce(max_, maxOp<point>());
00082 }
00083 }
00084
00085
00086
00087
00088 Foam::boundBox::boundBox(const pointField& points, const bool doReduce)
00089 :
00090 min_(point::zero),
00091 max_(point::zero)
00092 {
00093 calculate(points, doReduce);
00094 }
00095
00096
00097 Foam::boundBox::boundBox(const tmp<pointField>& points, const bool doReduce)
00098 :
00099 min_(point::zero),
00100 max_(point::zero)
00101 {
00102 calculate(points(), doReduce);
00103 points.clear();
00104 }
00105
00106
00107 Foam::boundBox::boundBox(Istream& is)
00108 {
00109 operator>>(is, *this);
00110 }
00111
00112
00113
00114
00115 Foam::Ostream& Foam::operator<<(Ostream& os, const boundBox& bb)
00116 {
00117 if (os.format() == IOstream::ASCII)
00118 {
00119 os << bb.min_ << token::SPACE << bb.max_;
00120 }
00121 else
00122 {
00123 os.write
00124 (
00125 reinterpret_cast<const char*>(&bb.min_),
00126 sizeof(boundBox)
00127 );
00128 }
00129
00130
00131 os.check("Ostream& operator<<(Ostream&, const boundBox&)");
00132 return os;
00133 }
00134
00135
00136 Foam::Istream& Foam::operator>>(Istream& is, boundBox& bb)
00137 {
00138 if (is.format() == IOstream::ASCII)
00139 {
00140 return is >> bb.min_ >> bb.max_;
00141 }
00142 else
00143 {
00144 is.read
00145 (
00146 reinterpret_cast<char*>(&bb.min_),
00147 sizeof(boundBox)
00148 );
00149 }
00150
00151
00152 is.check("Istream& operator>>(Istream&, boundBox&)");
00153 return is;
00154 }
00155
00156
Copyright © 2000-2009 OpenCFD Ltd