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 #ifndef VCG_USE_EIGEN
00025 #include "deprecated_point2.h"
00026 #else
00027 
00028 #ifndef __VCGLIB_POINT2
00029 #define __VCGLIB_POINT2
00030 
00031 #include "../math/eigen.h"
00032 // #include "point.h"
00033 
00034 namespace vcg{
00035 template<typename Scalar> class Point2;
00036 }
00037 
00038 namespace Eigen {
00039 template<typename Scalar> struct ei_traits<vcg::Point2<Scalar> > : ei_traits<Eigen::Matrix<Scalar,2,1> > {};
00040 template<typename XprType> struct ei_to_vcgtype<XprType,2,1,0,2,1>
00041 { typedef vcg::Point2<typename XprType::Scalar> type; };
00042 }
00043 
00044 namespace vcg {
00045 
00053 template <class _Scalar> class Point2 : public Eigen::Matrix<_Scalar,2,1>
00054 {
00055 //----------------------------------------
00056 // template typedef part
00057 // use it as follow: typename Point2<S>::Type instead of simply Point2<S>
00058 //----------------------------------------
00059 public:
00060         typedef Eigen::Matrix<_Scalar,2,1> Type;
00061 //----------------------------------------
00062 // inheritence part
00063 //----------------------------------------
00064 private:
00065         typedef Eigen::Matrix<_Scalar,2,1> _Base;
00066 public:
00067         using _Base::coeff;
00068         using _Base::coeffRef;
00069         using _Base::setZero;
00070         using _Base::data;
00071         using _Base::V;
00072 
00073         _EIGEN_GENERIC_PUBLIC_INTERFACE(Point2,_Base);
00074         VCG_EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Point2)
00075 
00076         
00077         inline Point2 () { }
00079         inline Point2 ( const Scalar nx, const Scalar ny ) : Base(nx,ny) {}
00081         inline Point2(Point2 const & p) : Base(p) {}
00082         template<typename OtherDerived>
00083         inline Point2(const Eigen::MatrixBase<OtherDerived>& other) : Base(other) {}
00084 
00086         // hm.. this is not really a cross product
00087         inline Scalar operator ^ ( Point2 const & p ) const
00088         {
00089                 return data()[0]*p.data()[1] - data()[1]*p.data()[0];
00090         }
00091 
00093         inline Scalar Angle() const
00094         {
00095                 return math::Atan2(data()[1],data()[0]);
00096         }
00098         inline Point2 & Cartesian2Polar()
00099         {
00100                 Scalar t = Angle();
00101                 data()[0] = this->norm();
00102                 data()[1] = t;
00103                 return *this;
00104         }
00106         inline Point2 & Polar2Cartesian()
00107         {
00108                 Scalar l = data()[0];
00109                 data()[0] = (Scalar)(l*math::Cos(data()[1]));
00110                 data()[1] = (Scalar)(l*math::Sin(data()[1]));
00111                 return *this;
00112         }
00114         inline Point2 & Rotate( const Scalar rad )
00115         {
00116                 Scalar t = data()[0];
00117                 Scalar s = math::Sin(rad);
00118                 Scalar c = math::Cos(rad);
00119 
00120                 data()[0] = data()[0]*c - data()[1]*s;
00121                 data()[1] =   t *s + data()[1]*c;
00122 
00123                 return *this;
00124         }
00125 }; // end class definition
00126 
00127 typedef Point2<short>  Point2s;
00128 typedef Point2<int>        Point2i;
00129 typedef Point2<float>  Point2f;
00130 typedef Point2<double> Point2d;
00131 
00132 // typedef Eigen::Matrix<short ,2,1> Point2s;
00133 // typedef Eigen::Matrix<int   ,2,1> Point2i;
00134 // typedef Eigen::Matrix<float ,2,1> Point2f;
00135 // typedef Eigen::Matrix<double,2,1> Point2d;
00136 // typedef Eigen::Matrix<short ,2,1> Vector2s;
00137 // typedef Eigen::Matrix<int   ,2,1> Vector2i;
00138 // typedef Eigen::Matrix<float ,2,1> Vector2f;
00139 // typedef Eigen::Matrix<double,2,1> Vector2d;
00140 
00142 } // end namespace
00143 #endif
00144 
00145 #endif


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