eigen_matrix_addons.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 #ifdef __GNUC__
00025 #warning You are including deprecated math stuff
00026 #endif
00027 
00028 enum {Dimension = SizeAtCompileTime};
00029 typedef typename ei_to_vcgtype<Matrix>::type EquivVcgType;
00030 typedef vcg::VoidType   ParamType;
00031 typedef Matrix          PointType;
00032 using Base::V;
00033 
00034 // automatic conversion to similar vcg types
00035 // the otherway round is implicit because they inherits this Matrix tyoe
00036 operator EquivVcgType& () { return *reinterpret_cast<EquivVcgType*>(this); }
00037 operator const EquivVcgType& () const { return *reinterpret_cast<const EquivVcgType*>(this); }
00038 
00040 
00041 // FIXME the Point3/Point4 specialization were only for same sizes ??
00042 // while the Point version was generic like this one
00043 template<typename OtherDerived>
00044 inline void Import(const MatrixBase<OtherDerived>& b)
00045 {
00046         ei_import_selector<Matrix,OtherDerived>::run(*this,b.derived());
00047 }
00048 
00050 template<typename OtherDerived>
00051 static inline Matrix Construct(const MatrixBase<OtherDerived>& b)
00052 { Matrix p; p.Import(b); return p; }
00053 
00055 template<typename OtherDerived>
00056 inline void ImportHomo(const MatrixBase<OtherDerived>& b)
00057 {
00058         EIGEN_STATIC_ASSERT_VECTOR_ONLY(Matrix);
00059         EIGEN_STATIC_ASSERT_FIXED_SIZE(Matrix);
00060         EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(OtherDerived,SizeAtCompileTime-1);
00061 
00062         this->template start<SizeAtCompileTime-1> = b;
00063         data()[SizeAtCompileTime-1] = Scalar(1.0);
00064 }
00065 
00067 template<typename OtherDerived>
00068 static inline Matrix ConstructHomo(const MatrixBase<OtherDerived>& b)
00069 { Matrix p; p.ImportHomo(b); return p; }
00070 
00071 inline const Scalar &X() const { return data()[0]; }
00072 inline const Scalar &Y() const { return data()[1]; }
00073 inline const Scalar &Z() const { assert(SizeAtCompileTime>2); return data()[2]; }
00074 inline Scalar &X() { return data()[0]; }
00075 inline Scalar &Y() { return data()[1]; }
00076 inline Scalar &Z() { assert(SizeAtCompileTime>2); return data()[2]; }
00077 
00079 inline Scalar& W() { return data()[SizeAtCompileTime-1]; }
00081 inline const Scalar& W() const { return data()[SizeAtCompileTime-1]; }
00082 
00084 EIGEN_DEPRECATED Scalar* V() { return data(); }
00086 EIGEN_DEPRECATED const Scalar* V() const { return data(); }
00087 
00089 // overloaded to return a const reference
00090 EIGEN_DEPRECATED inline const Scalar& V( const int i ) const
00091 {
00092         assert(i>=0 && i<SizeAtCompileTime);
00093         return data()[i];
00094 }
00095 
00096 //--------------------------------------------------------------------------------
00097 // SPACE
00098 //--------------------------------------------------------------------------------
00099 
00102 inline Matrix LocalToGlobal(ParamType p) const { return *this; }
00105 inline ParamType GlobalToLocal(PointType /*p*/) const { return ParamType(); }
00106 
00117 void ToPolar(Scalar &ro, Scalar &theta, Scalar &phi) const
00118 {
00119         EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(Matrix,3);
00120         ro = this->norm();
00121         theta = (Scalar)atan2(data()[2], data()[0]);
00122         phi   = (Scalar)asin(data()[1]/ro);
00123 }
00124 
00135 void FromPolar(const Scalar &ro, const Scalar &theta, const Scalar &phi)
00136 {
00137         EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(Matrix,3);
00138         data()[0]= ro*ei_cos(theta)*ei_cos(phi);
00139         data()[1]= ro*ei_sin(phi);
00140         data()[2]= ro*ei_sin(theta)*ei_cos(phi);
00141 }


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