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