library of assembled shared sources

http://lass.cocamware.com

point_2dh.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 #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 /** Wrap index around range.
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 /** Wrap index around range.
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 /** A weird way to get back the same object
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 /** Return true if point is origin (0, 0, z).
00209  *  z may be 0 but doesn't has to be.
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 /** Return true if at least one of the components is NaN
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 /** Return true if point is at infinite distance of origin.  test if z == 0.
00230  */
00231 template<typename T>
00232 const bool Point2DH<T>::isInfinite() const
00233 {
00234     return z == TNumTraits::zero;
00235 }
00236 
00237 
00238 
00239 /** Return true if point is valid.  test if point != (0, 0, 0)
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 /** Return weight of point.  weight = z.
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 /** Return rescaled version of point with weight = 1.
00260  *  Does not influence original poitn.
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 /** Rescale point so that weight is 1.
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 // --- FREE FUNCTIONS ---------------------------------------------------------------------------
00286 
00287 /** @relates lass::prim::Point2DH
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 /** @relates lass::prim::Point2DH
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 /** @relates lass::prim::Point2DH
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 /** @relates lass::prim::Point2DH
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 /** @relates lass::prim::Point2DH
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 /** @relates lass::prim::Point2DH
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 /** @relates lass::prim::Point2DH
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 /** @relates lass::prim::Point2DH
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 /** @relates lass::prim::Point2DH
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 /** @relates lass::prim::Point2DH
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 /** @relates lass::prim::Point2DH
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 /** @relates lass::prim::Point2DH
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 /** @relates lass::prim::Point2DH
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 // --- END OF FILE ------------------------------------------------------------------------------

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