PointIndexHit.H
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
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 #ifndef PointIndexHit_H
00040 #define PointIndexHit_H
00041
00042 #include "bool.H"
00043 #include "point.H"
00044
00045
00046
00047 namespace Foam
00048 {
00049
00050
00051
00052
00053
00054 template<class Point>
00055 class PointIndexHit
00056 {
00057
00058
00059
00060 bool hit_;
00061
00062
00063 Point hitPoint_;
00064
00065
00066 label index_;
00067
00068
00069 public:
00070
00071
00072
00073
00074 PointIndexHit(const bool success, const Point& p, const label index)
00075 :
00076 hit_(success),
00077 hitPoint_(p),
00078 index_(index)
00079 {}
00080
00081
00082 PointIndexHit(const Point& p)
00083 :
00084 hit_(false),
00085 hitPoint_(p),
00086 index_(-1)
00087 {}
00088
00089
00090 PointIndexHit()
00091 :
00092 hit_(false),
00093 hitPoint_(vector::zero),
00094 index_(-1)
00095 {}
00096
00097
00098 PointIndexHit(Istream& is)
00099 {
00100 is >> *this;
00101 }
00102
00103
00104
00105
00106
00107 bool hit() const
00108 {
00109 return hit_;
00110 }
00111
00112
00113 label index() const
00114 {
00115 return index_;
00116 }
00117
00118
00119 const Point& hitPoint() const
00120 {
00121 if (!hit_)
00122 {
00123 FatalErrorIn("PointIndexHit::hitPoint() const")
00124 << "requested a hit point for a miss"
00125 << abort(FatalError);
00126 }
00127
00128 return hitPoint_;
00129 }
00130
00131
00132 const Point& missPoint() const
00133 {
00134 if (hit_)
00135 {
00136 FatalErrorIn("PointIndexHit::missPoint() const")
00137 << "requested a miss point for a hit"
00138 << abort(FatalError);
00139 }
00140
00141 return hitPoint_;
00142 }
00143
00144
00145 const Point& rawPoint() const
00146 {
00147 return hitPoint_;
00148 }
00149
00150 Point& rawPoint()
00151 {
00152 return hitPoint_;
00153 }
00154
00155 void setHit()
00156 {
00157 hit_ = true;
00158 }
00159
00160 void setMiss()
00161 {
00162 hit_ = false;
00163 }
00164
00165 void setPoint(const Point& p)
00166 {
00167 hitPoint_ = p;
00168 }
00169
00170 void setIndex(const label index)
00171 {
00172 index_ = index;
00173 }
00174
00175 bool operator==(const PointIndexHit& rhs) const
00176 {
00177 return
00178 hit_ == rhs.hit()
00179 && hitPoint_ == rhs.rawPoint()
00180 && index_ == rhs.index();
00181 }
00182
00183 bool operator!=(const PointIndexHit& rhs) const
00184 {
00185 return !operator==(rhs);
00186 }
00187
00188 void write(Ostream& os)
00189 {
00190 if (hit())
00191 {
00192 os << "hit:" << hitPoint() << " index:" << index();
00193 }
00194 else
00195 {
00196 os << "miss:" << missPoint() << " index:" << index();
00197 }
00198 }
00199
00200 friend Ostream& operator<< (Ostream& os, const PointIndexHit& pHit)
00201 {
00202 if (os.format() == IOstream::ASCII)
00203 {
00204 os << pHit.hit_ << token::SPACE << pHit.hitPoint_
00205 << token::SPACE << pHit.index_;
00206 }
00207 else
00208 {
00209 os.write
00210 (
00211 reinterpret_cast<const char*>(&pHit),
00212 sizeof(PointIndexHit)
00213 );
00214 }
00215
00216
00217 os.check("Ostream& operator<<(Ostream&, const PointIndexHit&)");
00218
00219 return os;
00220 }
00221
00222 friend Istream& operator>>(Istream& is, PointIndexHit& pHit)
00223 {
00224 if (is.format() == IOstream::ASCII)
00225 {
00226 return is >> pHit.hit_ >> pHit.hitPoint_ >> pHit.index_;
00227 }
00228 else
00229 {
00230 is.read
00231 (
00232 reinterpret_cast<char*>(&pHit),
00233 sizeof(PointIndexHit)
00234 );
00235 }
00236
00237
00238 is.check("Istream& operator>>(Istream&, PointIndexHit&)");
00239
00240 return is;
00241 }
00242
00243 };
00244
00245
00246
00247
00248 }
00249
00250
00251
00252 #endif
00253
00254
Copyright © 2000-2009 OpenCFD Ltd