point_2dh.inl
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
00040
00041
00042
00043 #ifndef LASS_GUARDIAN_OF_INCLUSION_PRIM_POINT_2DH_INL
00044 #define LASS_GUARDIAN_OF_INCLUSION_PRIM_POINT_2DH_INL
00045
00046 #include "point_2dh.h"
00047
00048 namespace lass
00049 {
00050 namespace prim
00051 {
00052
00053 template <typename T> inline
00054 Point2DH<T>::Point2DH():
00055 x(TNumTraits::zero),
00056 y(TNumTraits::zero),
00057 z(TNumTraits::zero)
00058 {
00059 LASS_ASSERT(isZero());
00060 }
00061
00062
00063
00064 template<typename T> inline
00065 Point2DH<T>::Point2DH(TParam iX, TParam iY, TParam iZ):
00066 x(iX),
00067 y(iY),
00068 z(iZ)
00069 {
00070 }
00071
00072
00073
00074 template<typename T> inline
00075 Point2DH<T>::Point2DH(const TPoint& iAffinePoint):
00076 x(iAffinePoint.x),
00077 y(iAffinePoint.y),
00078 z(TNumTraits::one)
00079 {
00080 }
00081
00082
00083
00084 template<typename T> inline
00085 Point2DH<T>::Point2DH(const TVector& iPositionVector):
00086 x(iPositionVector.x),
00087 y(iPositionVector.y),
00088 z(iPositionVector.z)
00089 {
00090 }
00091
00092
00093
00094 template <typename T> inline
00095 const typename Point2DH<T>::TVector
00096 Point2DH<T>::position() const
00097 {
00098 return TVector(x, y, z);
00099 }
00100
00101
00102
00103 template<typename T> inline
00104 typename Point2DH<T>::TConstReference
00105 Point2DH<T>::operator[](size_t iIndex) const
00106 {
00107 LASS_ASSERT(iIndex < dimension);
00108 return *(&x + iIndex);
00109 }
00110
00111
00112
00113 template<typename T> inline
00114 typename Point2DH<T>::TReference
00115 Point2DH<T>::operator[](size_t iIndex)
00116 {
00117 LASS_ASSERT(iIndex < dimension);
00118 return *(&x + iIndex);
00119 }
00120
00121
00122
00123
00124
00125 template<typename T> inline
00126 typename Point2DH<T>::TConstReference
00127 Point2DH<T>::at(signed iIndex) const
00128 {
00129 return *(&x + num::mod(iIndex, dimension));
00130 }
00131
00132
00133
00134
00135
00136 template<typename T> inline
00137 typename Point2DH<T>::TReference
00138 Point2DH<T>::at(signed iIndex)
00139 {
00140 return *(&x + num::mod(iIndex, dimension));
00141 }
00142
00143
00144
00145
00146
00147 template<typename T> inline
00148 const Point2DH<T>& Point2DH<T>::operator+() const
00149 {
00150 return *this;
00151 }
00152
00153
00154
00155 template<typename T>
00156 const Point2DH<T> Point2DH<T>::operator-() const
00157 {
00158 return Poin2DH(-x, -y, -z);
00159 }
00160
00161
00162
00163 template<typename T>
00164 Point2DH<T>& Point2DH<T>::operator+=(const Point2DH<T>& iB)
00165 {
00166 x += iB.x;
00167 y += iB.y;
00168 z += iB.z;
00169 return *this;
00170 }
00171
00172
00173
00174 template<typename T>
00175 Point2DH<T>& Point2DH<T>::operator-=(const Point2DH<T>& iB)
00176 {
00177 x -= iB.x;
00178 y -= iB.y;
00179 z -= iB.z;
00180 return *this;
00181 }
00182
00183
00184
00185 template<typename T>
00186 Point2DH<T>& Point2DH<T>::operator*=(TParam iB)
00187 {
00188 x *= iB;
00189 y *= iB;
00190 z *= iB;
00191 return *this;
00192 }
00193
00194
00195
00196 template<typename T>
00197 Point2DH<T>& Point2DH<T>::operator/=(TParam iB)
00198 {
00199 const TValue invB = TNumTraits::one / iB;
00200 x *= invB;
00201 y *= invB;
00202 z *= invB;
00203 return *this;
00204 }
00205
00206
00207
00208
00209
00210
00211 template<typename T>
00212 const bool Point2DH<T>::isZero() const
00213 {
00214 return x == TNumTraits::zero && y == TNumTraits::zero;
00215 }
00216
00217
00218
00219
00220
00221 template<typename T> inline
00222 const bool Point2DH<T>::isNaN() const
00223 {
00224 return num::isNaN(x) || num::isNaN(y) || num::isNaN(z);
00225 }
00226
00227
00228
00229
00230
00231 template<typename T>
00232 const bool Point2DH<T>::isInfinite() const
00233 {
00234 return z == TNumTraits::zero;
00235 }
00236
00237
00238
00239
00240
00241 template<typename T>
00242 const bool Point2DH<T>::isValid() const
00243 {
00244 return x != TNumTraits::zero || y != TNumTraits::zero || z != TNumTraits::zero;
00245 }
00246
00247
00248
00249
00250
00251 template<typename T> inline
00252 const typename Point2DH<T>::TValue Point2DH<T>::weight() const
00253 {
00254 return z;
00255 }
00256
00257
00258
00259
00260
00261
00262 template<typename T> inline
00263 const Point2D<T> Point2DH<T>::affine() const
00264 {
00265 Point2DH<T> result(*this);
00266 result.homogenize();
00267 return Point2D<T>(result.x, result.y);
00268 }
00269
00270
00271
00272
00273
00274 template<typename T>
00275 void Point2DH<T>::homogenize()
00276 {
00277 const TValue invZ = TNumTraits::one / z;
00278 x *= invZ;
00279 y *= invZ;
00280 z = TNumTraits::one;
00281 }
00282
00283
00284
00285
00286
00287
00288
00289 template<typename T>
00290 bool operator==(const Point2DH<T>& iA, const Point2DH<T>& iB)
00291 {
00292 return iA.x == iB.x && iA.y == iB.y && iA.z == iB.z;
00293 }
00294
00295
00296
00297
00298
00299 template<typename T> inline
00300 bool operator!=(const Point2DH<T>& iA, const Point2DH<T>& iB)
00301 {
00302 return !(iA == iB);
00303 }
00304
00305
00306
00307
00308
00309 template<typename T> inline
00310 Point2DH<T> operator+(const Point2DH<T>& iA, const Point2DH<T>& iB)
00311 {
00312 Point2DH<T> result(iA);
00313 result += iB;
00314 return result;
00315 }
00316
00317
00318
00319
00320
00321 template<typename T> inline
00322 Point2DH<T> operator+(const Point2DH<T>& iA, const Point2D<T>& iB)
00323 {
00324 Point2DH<T> result(iA);
00325 result += iB;
00326 return result;
00327 }
00328
00329
00330
00331
00332
00333 template<typename T> inline
00334 Point2DH<T> operator+(const Point2D<T>& iA, const Point2DH<T>& iB)
00335 {
00336 Point2DH<T> result(iA);
00337 result += iB;
00338 return result;
00339 }
00340
00341
00342
00343
00344
00345 template<typename T> inline
00346 Point2DH<T> operator+(const Point2D<T>& iA, const Point2D<T>& iB)
00347 {
00348 Point2DH<T> result(iA);
00349 result += iB;
00350 return result;
00351 }
00352
00353
00354
00355
00356
00357 template<typename T> inline
00358 Point2DH<T> operator-(const Point2DH<T>& iA, const Point2DH<T>& iB)
00359 {
00360 Point2DH<T> result(iA.position());
00361 result -= iB;
00362 return result;
00363 }
00364
00365
00366
00367
00368
00369 template<typename T> inline
00370 Point2DH<T> operator*(const Point2DH<T>& iA, typename Point2DH<T>::TParam iB)
00371 {
00372 Point2DH<T> result(iA);
00373 result *= iB;
00374 return result;
00375 }
00376
00377
00378
00379
00380
00381 template<typename T> inline
00382 Point2DH<T> operator/(const Point2DH<T>& iA, typename Point2DH<T>::TParam iB)
00383 {
00384 Point2DH<T> result(iA);
00385 result /= iB;
00386 return result;
00387 }
00388
00389
00390
00391
00392
00393 template<typename T> inline
00394 Point2DH<T> operator*(typename Point2DH<T>::TParam iA, const Point2DH<T>& iB)
00395 {
00396 Point2DH<T> result(iB);
00397 result *= iA;
00398 return result;
00399 }
00400
00401
00402
00403
00404
00405 template<typename T>
00406 std::ostream& operator<<(std::ostream& ioOStream, const Point2DH<T>& iB)
00407 {
00408 LASS_ENFORCE_STREAM(ioOStream) << iB.position();
00409 return ioOStream;
00410 }
00411
00412
00413
00414
00415
00416 template<typename T>
00417 io::XmlOStream& operator<<(io::XmlOStream& oOStream, const Point2DH<T>& iB)
00418 {
00419 LASS_ENFORCE_STREAM(oOStream)
00420 << "<Point2DH>" << iB.x << " " << iB.y << " " << iB.z << "</Point2DH>\n";
00421 return oOStream;
00422 }
00423
00424
00425
00426
00427
00428 template<typename T>
00429 std::istream& operator>>(std::istream& ioIStream, Point2DH<T>& oB)
00430 {
00431 Vector3D<T> temp;
00432 LASS_ENFORCE(ioIStream) >> temp;
00433 oB = Point2DH<T>(temp);
00434 return ioIStream;
00435 }
00436
00437
00438
00439 }
00440
00441 }
00442
00443 #endif
00444
00445