File: eigen_matrix_addons.h

package info (click to toggle)
meshlab 1.3.0a%2Bdfsg1-3
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 23,416 kB
  • sloc: cpp: 214,034; ansic: 4,493; makefile: 72
file content (141 lines) | stat: -rw-r--r-- 6,233 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/****************************************************************************
* VCGLib                                                            o o     *
* Visual and Computer Graphics Library                            o     o   *
*                                                                _   O  _   *
* Copyright(C) 2004                                                \/)\/    *
* Visual Computing Lab                                            /\/|      *
* ISTI - Italian National Research Council                           |      *
*                                                                    \      *
* All rights reserved.                                                      *
*                                                                           *
* This program is free software; you can redistribute it and/or modify      *
* it under the terms of the GNU General Public License as published by      *
* the Free Software Foundation; either version 2 of the License, or         *
* (at your option) any later version.                                       *
*                                                                           *
* This program is distributed in the hope that it will be useful,           *
* but WITHOUT ANY WARRANTY; without even the implied warranty of            *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             *
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt)          *
* for more details.                                                         *
*                                                                           *
****************************************************************************/

#ifdef __GNUC__
#warning You are including deprecated math stuff
#endif

enum {Dimension = SizeAtCompileTime};
typedef typename ei_to_vcgtype<Matrix>::type EquivVcgType;
typedef vcg::VoidType   ParamType;
typedef Matrix          PointType;
using Base::V;

// automatic conversion to similar vcg types
// the otherway round is implicit because they inherits this Matrix tyoe
operator EquivVcgType& () { return *reinterpret_cast<EquivVcgType*>(this); }
operator const EquivVcgType& () const { return *reinterpret_cast<const EquivVcgType*>(this); }

/** \deprecated use m.cast<NewScalar>() */
/// importer for points with different scalar type and-or dimensionality
// FIXME the Point3/Point4 specialization were only for same sizes ??
// while the Point version was generic like this one
template<typename OtherDerived>
inline void Import(const MatrixBase<OtherDerived>& b)
{
	ei_import_selector<Matrix,OtherDerived>::run(*this,b.derived());
}

/// constructor for points with different scalar type and-or dimensionality
template<typename OtherDerived>
static inline Matrix Construct(const MatrixBase<OtherDerived>& b)
{ Matrix p; p.Import(b); return p; }

/// importer for homogeneous points
template<typename OtherDerived>
inline void ImportHomo(const MatrixBase<OtherDerived>& b)
{
	EIGEN_STATIC_ASSERT_VECTOR_ONLY(Matrix);
	EIGEN_STATIC_ASSERT_FIXED_SIZE(Matrix);
	EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(OtherDerived,SizeAtCompileTime-1);

	this->template start<SizeAtCompileTime-1> = b;
	data()[SizeAtCompileTime-1] = Scalar(1.0);
}

/// constructor for homogeneus point.
template<typename OtherDerived>
static inline Matrix ConstructHomo(const MatrixBase<OtherDerived>& b)
{ Matrix p; p.ImportHomo(b); return p; }

inline const Scalar &X() const { return data()[0]; }
inline const Scalar &Y() const { return data()[1]; }
inline const Scalar &Z() const { assert(SizeAtCompileTime>2); return data()[2]; }
inline Scalar &X() { return data()[0]; }
inline Scalar &Y() { return data()[1]; }
inline Scalar &Z() { assert(SizeAtCompileTime>2); return data()[2]; }

/** note, W always returns the last entry */
inline Scalar& W() { return data()[SizeAtCompileTime-1]; }
/** note, W always returns the last entry */
inline const Scalar& W() const { return data()[SizeAtCompileTime-1]; }

/** \deprecated use .data() */
EIGEN_DEPRECATED Scalar* V() { return data(); }
/** \deprecated use .data() */
EIGEN_DEPRECATED const Scalar* V() const { return data(); }

/** \deprecated use m.coeff(i) or m[i] or m(i) */
// overloaded to return a const reference
EIGEN_DEPRECATED inline const Scalar& V( const int i ) const
{
	assert(i>=0 && i<SizeAtCompileTime);
	return data()[i];
}

//--------------------------------------------------------------------------------
// SPACE
//--------------------------------------------------------------------------------

/** Local to Glocal
  * (provided for uniformity with other spatial classes. trivial for points) */
inline Matrix LocalToGlobal(ParamType p) const { return *this; }
/** Glocal to Local
  * (provided for uniformity with other spatial classes. trivial for points) */
inline ParamType GlobalToLocal(PointType /*p*/) const { return ParamType(); }

/**
	* Convert to polar coordinates from cartesian coordinates.
	*
	* Theta is the azimuth angle and ranges between [0, 360) degrees.
	* Phi is the elevation angle (not the polar angle) and ranges between [-90, 90] degrees.
	*
	* \note Note that instead of the classical polar angle, which ranges between
	*       0 and 180 degrees we opt for the elevation angle to obtain a more
	*       intuitive spherical coordinate system.
	*/
void ToPolar(Scalar &ro, Scalar &theta, Scalar &phi) const
{
	EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(Matrix,3);
	ro = this->norm();
	theta = (Scalar)atan2(data()[2], data()[0]);
	phi   = (Scalar)asin(data()[1]/ro);
}

/**
	* Convert from polar coordinates to cartesian coordinates.
	*
	* Theta is the azimuth angle and ranges between [0, 360) degrees.
	* Phi is the elevation angle (not the polar angle) and ranges between [-90, 90] degrees.
	*
	* \note Note that instead of the classical polar angle, which ranges between
	*       0 and 180 degrees, we opt for the elevation angle to obtain a more
	*       intuitive spherical coordinate system.
	*/
void FromPolar(const Scalar &ro, const Scalar &theta, const Scalar &phi)
{
	EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(Matrix,3);
	data()[0]= ro*ei_cos(theta)*ei_cos(phi);
	data()[1]= ro*ei_sin(phi);
	data()[2]= ro*ei_sin(theta)*ei_cos(phi);
}