library of assembled shared sources

http://lass.cocamware.com

point_3dh.inl

Go to the documentation of this file.
00001 /** @file
00002  *  @author Bram de Greve (bramz@users.sourceforge.net)
00003  *  @author Tom De Muer (tomdemuer@users.sourceforge.net)
00004  *
00005  *  *** BEGIN LICENSE INFORMATION ***
00006  *  
00007  *  The contents of this file are subject to the Common Public Attribution License 
00008  *  Version 1.0 (the "License"); you may not use this file except in compliance with 
00009  *  the License. You may obtain a copy of the License at 
00010  *  http://lass.sourceforge.net/cpal-license. The License is based on the 
00011  *  Mozilla Public License Version 1.1 but Sections 14 and 15 have been added to cover 
00012  *  use of software over a computer network and provide for limited attribution for 
00013  *  the Original Developer. In addition, Exhibit A has been modified to be consistent 
00014  *  with Exhibit B.
00015  *  
00016  *  Software distributed under the License is distributed on an "AS IS" basis, WITHOUT 
00017  *  WARRANTY OF ANY KIND, either express or implied. See the License for the specific 
00018  *  language governing rights and limitations under the License.
00019  *  
00020  *  The Original Code is LASS - Library of Assembled Shared Sources.
00021  *  
00022  *  The Initial Developer of the Original Code is Bram de Greve and Tom De Muer.
00023  *  The Original Developer is the Initial Developer.
00024  *  
00025  *  All portions of the code written by the Initial Developer are:
00026  *  Copyright (C) 2004-2007 the Initial Developer.
00027  *  All Rights Reserved.
00028  *  
00029  *  Contributor(s):
00030  *
00031  *  Alternatively, the contents of this file may be used under the terms of the 
00032  *  GNU General Public License Version 2 or later (the GPL), in which case the 
00033  *  provisions of GPL are applicable instead of those above.  If you wish to allow use
00034  *  of your version of this file only under the terms of the GPL and not to allow 
00035  *  others to use your version of this file under the CPAL, indicate your decision by 
00036  *  deleting the provisions above and replace them with the notice and other 
00037  *  provisions required by the GPL License. If you do not delete the provisions above,
00038  *  a recipient may use your version of this file under either the CPAL or the GPL.
00039  *  
00040  *  *** END LICENSE INFORMATION ***
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 /** Wrap index around range.
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 /** Wrap index around range.
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 /** A weird way to get back the same object
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 /** Return true if point is origin (0, 0, 0, w).
00226  *  w may be 0 but doesn't has to be.
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 /** Return true if at least one of the components is NaN
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 /** Return true if point is at infinite distance of origin.  test if w == 0.
00247  */
00248 template<typename T> inline
00249 const bool Point3DH<T>::isInfinite() const
00250 {
00251     return w == TNumTraits::zero;
00252 }
00253 
00254 
00255 
00256 /** Return true if point is valid.  test if point != (0, 0, 0, 0)
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 /** Return weight of point.  weight = w.
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 /** Return rescaled version of point with weight = 1.
00279  *  Does not influence original poitn.
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 /** Rescale point so that weight is 1.
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 // --- FREE FUNCTIONS ---------------------------------------------------------------------------
00306 
00307 /** @relates lass::prim::Point3DH
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 /** @relates lass::prim::Point3DH
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 /** @relates lass::prim::Point3DH
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 /** @relates lass::prim::Point3DH
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 /** @relates lass::prim::Point3DH
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 /** @relates lass::prim::Point3DH
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 /** @relates lass::prim::Point3DH
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 /** @relates lass::prim::Point3DH
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 /** @relates lass::prim::Point3DH
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 /** @relates lass::prim::Point3DH
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 // --- END OF FILE ------------------------------------------------------------------------------

Generated on Mon Nov 10 14:21:04 2008 for Library of Assembled Shared Sources by doxygen 1.5.7.1
SourceForge.net Logo