deprecated_point2.h
Go to the documentation of this file.
00001 /****************************************************************************
00002 * VCGLib                                                            o o     *
00003 * Visual and Computer Graphics Library                            o     o   *
00004 *                                                                _   O  _   *
00005 * Copyright(C) 2004                                                \/)\/    *
00006 * Visual Computing Lab                                            /\/|      *
00007 * ISTI - Italian National Research Council                           |      *
00008 *                                                                    \      *
00009 * All rights reserved.                                                      *
00010 *                                                                           *
00011 * This program is free software; you can redistribute it and/or modify      *
00012 * it under the terms of the GNU General Public License as published by      *
00013 * the Free Software Foundation; either version 2 of the License, or         *
00014 * (at your option) any later version.                                       *
00015 *                                                                           *
00016 * This program is distributed in the hope that it will be useful,           *
00017 * but WITHOUT ANY WARRANTY; without even the implied warranty of            *
00018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             *
00019 * GNU General Public License (http://www.gnu.org/licenses/gpl.txt)          *
00020 * for more details.                                                         *
00021 *                                                                           *
00022 ****************************************************************************/
00023 /****************************************************************************
00024   History
00025 
00026 $Log: not supported by cvs2svn $
00027 Revision 1.9  2006/10/07 16:51:43  m_di_benedetto
00028 Implemented Scale() method (was only declared).
00029 
00030 Revision 1.8  2006/01/19 13:53:19  m_di_benedetto
00031 Fixed product by scalar and SquaredNorm()
00032 
00033 Revision 1.7  2005/10/15 19:11:49  m_di_benedetto
00034 Corrected return type in Angle() and protected member access in unary operator -
00035 
00036 Revision 1.6  2005/03/18 16:34:42  fiorin
00037 minor changes to comply gcc compiler
00038 
00039 Revision 1.5  2004/05/10 13:22:25  cignoni
00040 small syntax error Math -> math in Angle
00041 
00042 Revision 1.4  2004/04/05 11:57:32  cignoni
00043 Add V() access function
00044 
00045 Revision 1.3  2004/03/10 17:42:40  tarini
00046 Added comments (Dox) !
00047 Added Import(). Costruct(), ScalarType...  Corrected cross prod (sign). Added Angle. Now using Math:: stuff for trigon. etc.
00048 
00049 Revision 1.2  2004/03/03 15:07:40  cignoni
00050 renamed protected member v -> _v
00051 
00052 Revision 1.1  2004/02/13 00:44:53  cignoni
00053 First commit...
00054 
00055 
00056 ****************************************************************************/
00057 
00058 #ifndef __VCGLIB_POINT2
00059 #define __VCGLIB_POINT2
00060 
00061 #include <assert.h>
00062 #include <vcg/math/base.h>
00063 
00064 namespace vcg {
00065 
00073 template <class P2ScalarType> class Point2
00074 {
00075 protected:
00077         P2ScalarType _v[2];
00078 public:
00080         typedef P2ScalarType ScalarType;
00081         enum {Dimension = 2};
00082 
00084 
00088         inline const ScalarType &X() const {return _v[0];}
00089         inline const ScalarType &Y() const {return _v[1];}
00090         inline ScalarType &X() {return _v[0];}
00091         inline ScalarType &Y() {return _v[1];}
00092         inline const ScalarType * V() const
00093         {
00094                 return _v;
00095         }
00096         inline ScalarType * V()
00097         {
00098                 return _v;
00099         }
00100         inline ScalarType & V( const int i )
00101         {
00102                 assert(i>=0 && i<2);
00103                 return _v[i];
00104         }
00105         inline const ScalarType & V( const int i ) const
00106         {
00107                 assert(i>=0 && i<2);
00108                 return _v[i];
00109         }
00110         inline const ScalarType & operator [] ( const int i ) const
00111         {
00112                 assert(i>=0 && i<2);
00113                 return _v[i];
00114         }
00115         inline ScalarType & operator [] ( const int i )
00116         {
00117                 assert(i>=0 && i<2);
00118                 return _v[i];
00119         }
00121 
00122         inline Point2 () { }
00124         inline Point2 ( const ScalarType nx, const ScalarType ny )
00125         {
00126                         _v[0] = nx; _v[1] = ny;
00127         }
00129         inline Point2 ( Point2 const & p)
00130         {
00131                         _v[0]= p._v[0];    _v[1]= p._v[1];
00132         }
00134         inline Point2 & operator =( Point2 const & p)
00135         {
00136                         _v[0]= p._v[0]; _v[1]= p._v[1];
00137                         return *this;
00138         }
00140         inline void SetZero()
00141         { _v[0] = 0;_v[1] = 0;}
00143         inline ScalarType operator * ( Point2 const & p ) const
00144         {
00145                         return ( _v[0]*p._v[0] + _v[1]*p._v[1] );
00146         }
00147         inline ScalarType dot( const Point2 & p ) const { return (*this) * p; }
00149         inline ScalarType operator ^ ( Point2 const & p ) const
00150         {
00151                         return _v[0]*p._v[1] - _v[1]*p._v[0];
00152         }
00154 
00155         inline Point2 operator + ( Point2 const & p) const
00156         {
00157                         return Point2<ScalarType>( _v[0]+p._v[0], _v[1]+p._v[1] );
00158         }
00159         inline Point2 operator - ( Point2 const & p) const
00160         {
00161                         return Point2<ScalarType>( _v[0]-p._v[0], _v[1]-p._v[1] );
00162         }
00163         inline Point2 operator * ( const ScalarType s ) const
00164         {
00165                         return Point2<ScalarType>( _v[0] * s, _v[1] * s );
00166         }
00167         inline Point2 operator / ( const ScalarType s ) const
00168         {
00169                         return Point2<ScalarType>( _v[0] / s, _v[1] / s );
00170         }
00171         inline Point2 & operator += ( Point2 const & p)
00172         {
00173                         _v[0] += p._v[0];    _v[1] += p._v[1];
00174                         return *this;
00175         }
00176         inline Point2 & operator -= ( Point2 const & p)
00177         {
00178                         _v[0] -= p._v[0];    _v[1] -= p._v[1];
00179                         return *this;
00180         }
00181         inline Point2 & operator *= ( const ScalarType s )
00182         {
00183                         _v[0] *= s;    _v[1] *= s;
00184                         return *this;
00185         }
00186         inline Point2 & operator /= ( const ScalarType s )
00187         {
00188                         _v[0] /= s;    _v[1] /= s;
00189                         return *this;
00190         }
00192 
00193         inline ScalarType Norm( void ) const
00194         {
00195                 return math::Sqrt( _v[0]*_v[0] + _v[1]*_v[1] );
00196         }
00198         inline ScalarType SquaredNorm( void ) const
00199         {
00200                         return ( _v[0]*_v[0] + _v[1]*_v[1] );
00201         }
00202         inline Point2 & Scale( const ScalarType sx, const ScalarType sy )
00203         {
00204                 _v[0] *= sx;
00205                 _v[1] *= sy;
00206                 return * this;
00207         }
00209         inline Point2 & Normalize( void )
00210         {
00211                         ScalarType n = math::Sqrt(_v[0]*_v[0] + _v[1]*_v[1]);
00212                         if(n>0.0) {     _v[0] /= n;     _v[1] /= n; }
00213                         return *this;
00214         }
00216         inline bool operator == ( Point2 const & p ) const
00217         {
00218                         return (_v[0]==p._v[0] && _v[1]==p._v[1]);
00219         }
00221         inline bool operator != ( Point2 const & p ) const
00222         {
00223                         return ( (_v[0]!=p._v[0]) || (_v[1]!=p._v[1]) );
00224         }
00226         inline bool operator <  ( Point2 const & p ) const
00227         {
00228                         return  (_v[1]!=p._v[1])?(_v[1]<p._v[1]):
00229                                                         (_v[0]<p._v[0]);
00230         }
00232         inline bool operator >  ( Point2 const & p ) const
00233         {
00234                         return  (_v[1]!=p._v[1])?(_v[1]>p._v[1]):
00235                                                         (_v[0]>p._v[0]);
00236         }
00238         inline bool operator <= ( Point2 const & p ) const
00239         {
00240                         return  (_v[1]!=p._v[1])?(_v[1]< p._v[1]):
00241                                                         (_v[0]<=p._v[0]);
00242         }
00244         inline bool operator >= ( Point2 const & p ) const
00245         {
00246                         return  (_v[1]!=p._v[1])?(_v[1]> p._v[1]):
00247                                                         (_v[0]>=p._v[0]);
00248         }
00250         inline ScalarType Distance( Point2 const & p ) const
00251         {
00252                         return Norm(*this-p);
00253         }
00255         inline ScalarType SquaredDistance( Point2 const & p ) const
00256         {
00257       return (*this-p).SquaredNorm();
00258         }
00260         inline ScalarType Angle() const {
00261                 return math::Atan2(_v[1],_v[0]);
00262         }
00264         inline Point2 & Cartesian2Polar()
00265         {
00266                 ScalarType t = Angle();
00267                 _v[0] = Norm();
00268                 _v[1] = t;
00269                 return *this;
00270         }
00272         inline Point2 & Polar2Cartesian()
00273         {
00274                 ScalarType l = _v[0];
00275                 _v[0] = (ScalarType)(l*math::Cos(_v[1]));
00276                 _v[1] = (ScalarType)(l*math::Sin(_v[1]));
00277                 return *this;
00278         }
00280         inline Point2 & Rotate( const ScalarType rad )
00281         {
00282                 ScalarType t = _v[0];
00283                 ScalarType s = math::Sin(rad);
00284                 ScalarType c = math::Cos(rad);
00285 
00286                 _v[0] = _v[0]*c - _v[1]*s;
00287                 _v[1] =   t *s + _v[1]*c;
00288 
00289                 return *this;
00290         }
00291 
00294         inline ScalarType Ext( const int i ) const
00295         {
00296                 if(i>=0 && i<2) return _v[i];
00297                 else            return 0;
00298         }
00300         template <class T>
00301         inline void Import( const Point2<T> & b )
00302         {
00303                 _v[0] = b.X(); _v[1] = b.Y();
00304         }
00306         template <class T>
00307         static Point2 Construct( const Point2<T> & b )
00308         {
00309     return Point2(b.X(),b.Y());
00310         }
00311 
00312 
00313 }; // end class definition
00314 
00315 
00316 template <class T>
00317 inline T Angle( Point2<T> const & p0, Point2<T> const & p1 )
00318 {
00319         return p1.Angle() - p0.Angle();
00320 }
00321 
00322 template <class T>
00323 inline Point2<T> operator - ( Point2<T> const & p ){
00324     return Point2<T>( -p[0], -p[1] );
00325 }
00326 
00327 template <class T>
00328 inline Point2<T> operator * ( const T s, Point2<T> const & p ){
00329     return Point2<T>( p[0] * s, p[1] * s  );
00330 }
00331 
00332 template <class T>
00333 inline T Norm( Point2<T> const & p ){
00334                 return p.Norm();
00335 }
00336 
00337 template <class T>
00338 inline T SquaredNorm( Point2<T> const & p ){
00339     return p.SquaredNorm();
00340 }
00341 
00342 template <class T>
00343 inline Point2<T> & Normalize( Point2<T> & p ){
00344     return p.Normalize();
00345 }
00346 
00347 template <class T>
00348 inline T Distance( Point2<T> const & p1,Point2<T> const & p2 ){
00349     return Norm(p1-p2);
00350 }
00351 
00352 template <class T>
00353 inline T SquaredDistance( Point2<T> const & p1,Point2<T> const & p2 ){
00354     return SquaredNorm(p1-p2);
00355 }
00356 
00357 template <class SCALARTYPE>
00358 inline Point2<SCALARTYPE> Abs(const Point2<SCALARTYPE> & p) {
00359   return (Point2<SCALARTYPE>(math::Abs(p[0]), math::Abs(p[1])));
00360 }
00361 
00362 typedef Point2<short>  Point2s;
00363 typedef Point2<int>        Point2i;
00364 typedef Point2<float>  Point2f;
00365 typedef Point2<double> Point2d;
00366 
00368 } // end namespace
00369 #endif


shape_reconstruction
Author(s): Roberto Martín-Martín
autogenerated on Sat Jun 8 2019 18:30:29