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 #include "boundBox.H"
00027 #include <OpenFOAM/PstreamReduceOps.H>
00028 #include <OpenFOAM/tmp.H>
00029
00030
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
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
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
00077 if (doReduce)
00078 {
00079 reduce(min_, minOp<point>());
00080 reduce(max_, maxOp<point>());
00081 }
00082 }
00083
00084
00085
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
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
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
00151 is.check("Istream& operator>>(Istream&, boundBox&)");
00152 return is;
00153 }
00154
00155