big cleaning in Point* and Matrix*, now they are very closed to be simple typedef of
Eigen's Matrix. Now the dilema is how to mimic those typedefs, using inheritence ? or using the classic workaround: typename Point3<float>::Type; with Point3<T>::Type defined to Eigen::Matrix<T,3,1>. Anyway currently I support both (and the inheritence scheme has to be preserved for compatibility). The advantage of the second approach is that when eigen has to evaluate an expression it uses an Eigen::Matrix<>, so it is probably better to only use Eigen::Matrix but I'm not 100% sure that makes a big difference especially if we add some automatic reinterpret_cast between Eigen::Matrix and vcg::Point*....
This commit is contained in:
parent
632f4842f1
commit
0361427bc0
|
@ -26,18 +26,19 @@
|
|||
|
||||
// TODO enable the vectorization
|
||||
#define EIGEN_DONT_VECTORIZE
|
||||
#define EIGEN_MATRIXBASE_PLUGIN <vcg/math/eigen_vcgaddons.h>
|
||||
#define EIGEN_MATRIXBASE_PLUGIN <vcg/math/eigen_matrixbase_addons.h>
|
||||
#define EIGEN_MATRIX_PLUGIN <vcg/math/eigen_matrix_addons.h>
|
||||
|
||||
// forward declarations
|
||||
namespace Eigen {
|
||||
template<typename Derived1, typename Derived2, int Size> struct ei_lexi_comparison;
|
||||
}
|
||||
|
||||
#include "base.h"
|
||||
#include "../Eigen/LU"
|
||||
#include "../Eigen/Geometry"
|
||||
#include "../Eigen/Array"
|
||||
#include "../Eigen/Core"
|
||||
#include "base.h"
|
||||
|
||||
// add support for unsigned char and short int
|
||||
namespace Eigen {
|
||||
|
@ -239,6 +240,18 @@ inline typename Eigen::ei_traits<Derived1>::Scalar
|
|||
SquaredDistance(const Eigen::MatrixBase<Derived1>& p1, const Eigen::MatrixBase<Derived2> & p2)
|
||||
{ return (p1-p2).norm2(); }
|
||||
|
||||
template<typename Derived>
|
||||
inline const Eigen::CwiseUnaryOp<Eigen::ei_scalar_abs_op<typename Eigen::ei_traits<Derived>::Scalar>, Derived>
|
||||
Abs(const Eigen::MatrixBase<Derived>& p)
|
||||
{ return p.cwise().abs(); }
|
||||
|
||||
template<typename Derived>
|
||||
inline const Eigen::CwiseBinaryOp<Eigen::ei_scalar_max_op<typename Eigen::ei_traits<Derived>::Scalar>,
|
||||
Derived,
|
||||
Eigen::NestByValue<typename Derived::ConstantReturnType> >
|
||||
LowClampToZero(const Eigen::MatrixBase<Derived>& p)
|
||||
{ return p.cwise().max(Derived::Zero().nestByValue()); }
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -0,0 +1,143 @@
|
|||
/****************************************************************************
|
||||
* 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. *
|
||||
* *
|
||||
****************************************************************************/
|
||||
|
||||
#warning You are including deprecated math stuff
|
||||
|
||||
enum {Dimension = SizeAtCompileTime};
|
||||
typedef vcg::VoidType ParamType;
|
||||
typedef Matrix PointType;
|
||||
using Base::V;
|
||||
|
||||
/// 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)
|
||||
{
|
||||
EIGEN_STATIC_ASSERT_VECTOR_ONLY(Matrix);
|
||||
EIGEN_STATIC_ASSERT_FIXED_SIZE(Matrix);
|
||||
EIGEN_STATIC_ASSERT_VECTOR_ONLY(OtherDerived);
|
||||
EIGEN_STATIC_ASSERT_FIXED_SIZE(OtherDerived);
|
||||
enum { OtherSize = OtherDerived::SizeAtCompileTime };
|
||||
assert(SizeAtCompileTime<=4 && OtherSize<=4);
|
||||
data()[0] = Scalar(b[0]);
|
||||
if (SizeAtCompileTime>1) { if (OtherSize>1) data()[1] = Scalar(b[1]); else data()[1] = 0; }
|
||||
if (SizeAtCompileTime>2) { if (OtherSize>2) data()[2] = Scalar(b[2]); else data()[2] = 0; }
|
||||
if (SizeAtCompileTime>3) { if (OtherSize>3) data()[3] = Scalar(b[3]); else data()[3] = 0; }
|
||||
}
|
||||
|
||||
/// 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 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;
|
||||
}
|
||||
|
||||
/// 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]; }
|
||||
inline const Scalar& W() const { return data()[SizeAtCompileTime-1]; }
|
||||
|
||||
Scalar* V() { return data(); }
|
||||
const Scalar* V() const { return data(); }
|
||||
|
||||
// overloaded to return a const reference
|
||||
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);
|
||||
}
|
|
@ -22,15 +22,15 @@
|
|||
****************************************************************************/
|
||||
|
||||
#warning You are including deprecated math stuff
|
||||
/*!
|
||||
* \deprecated use cols()
|
||||
*/
|
||||
|
||||
|
||||
typedef Scalar ScalarType;
|
||||
|
||||
/*! \deprecated use cols() */
|
||||
EIGEN_DEPRECATED inline unsigned int ColumnsNumber() const { return cols(); };
|
||||
|
||||
|
||||
/*!
|
||||
* \deprecated use rows()
|
||||
*/
|
||||
/*! \deprecated use rows() */
|
||||
EIGEN_DEPRECATED inline unsigned int RowsNumber() const { return rows(); };
|
||||
|
||||
/*!
|
||||
|
@ -83,9 +83,6 @@ EIGEN_DEPRECATED void SwapRows(const unsigned int i, const unsigned int j)
|
|||
row(i).swap(row(j));
|
||||
};
|
||||
|
||||
Scalar* V() { return derived().data(); }
|
||||
const Scalar* V() const { return derived().data(); }
|
||||
|
||||
/*!
|
||||
* \deprecated use *this.cwise() += k
|
||||
* (Modifier) Add to each element of this matrix the scalar constant <I>k</I>.
|
|
@ -79,19 +79,14 @@ public:
|
|||
template<typename OtherDerived>
|
||||
Matrix33(const Eigen::MatrixBase<OtherDerived>& other) : Base(other) {}
|
||||
|
||||
/*!
|
||||
* \deprecated use *this.row(i)
|
||||
*/
|
||||
/*! \deprecated use *this.row(i) */
|
||||
inline typename Base::RowXpr operator[](const unsigned int i)
|
||||
{ return Base::row(i); }
|
||||
|
||||
/*!
|
||||
* \deprecated use *this.row(i)
|
||||
*/
|
||||
/*! \deprecated use *this.row(i) */
|
||||
inline const typename Base::RowXpr operator[](const unsigned int i) const
|
||||
{ return Base::row(i); }
|
||||
|
||||
|
||||
/** \deprecated */
|
||||
Matrix33 & SetRotateRad(Scalar angle, const Point3<Scalar> & axis )
|
||||
{
|
||||
|
@ -129,7 +124,7 @@ public:
|
|||
*/
|
||||
Scalar Norm() { return Base::cwise().abs2().sum(); }
|
||||
// {
|
||||
// // FIXME looks like there is a bug: j is not used !!!
|
||||
// // FIXME looks like there was a bug: j is not used !!!
|
||||
// Scalar SQsum=0;
|
||||
// for(int i=0;i<3;++i)
|
||||
// for(int j=0;j<3;++j)
|
||||
|
@ -138,8 +133,7 @@ public:
|
|||
// }
|
||||
|
||||
|
||||
/**
|
||||
It computes the covariance matrix of a set of 3d points. Returns the barycenter
|
||||
/** Computes the covariance matrix of a set of 3d points. Returns the barycenter.
|
||||
*/
|
||||
// FIXME should be outside Matrix
|
||||
template <class STLPOINTCONTAINER >
|
||||
|
|
|
@ -80,7 +80,9 @@ for 'column' vectors.
|
|||
*/
|
||||
|
||||
|
||||
/** This class represents a 4x4 matrix. T is the kind of element in the matrix.
|
||||
/** \deprecated use Eigen::Matrix<Scalar,4,4> (or the typedef) you want a real 4x4 matrix, or use Eigen::Transform<Scalar,3> if you want a transformation matrix for a 3D space (a Eigen::Transform<Scalar,3> is internally a 4x4 col-major matrix)
|
||||
*
|
||||
* This class represents a 4x4 matrix. T is the kind of element in the matrix.
|
||||
*/
|
||||
template<typename _Scalar>
|
||||
class Matrix44 : public Eigen::Matrix<_Scalar,4,4,Eigen::RowMajor> // FIXME col or row major !
|
||||
|
@ -91,6 +93,7 @@ class Matrix44 : public Eigen::Matrix<_Scalar,4,4,Eigen::RowMajor> // FIXME col
|
|||
using _Base::coeffRef;
|
||||
using _Base::ElementAt;
|
||||
using _Base::setZero;
|
||||
using _Base::operator*;
|
||||
|
||||
public:
|
||||
|
||||
|
@ -103,7 +106,6 @@ public:
|
|||
~Matrix44() {}
|
||||
Matrix44(const Matrix44 &m) : Base(m) {}
|
||||
Matrix44(const Scalar * v ) : Base(Eigen::Map<Eigen::Matrix<Scalar,4,4,Eigen::RowMajor> >(v)) {}
|
||||
|
||||
template<typename OtherDerived>
|
||||
Matrix44(const Eigen::MatrixBase<OtherDerived>& other) : Base(other) {}
|
||||
|
||||
|
@ -149,6 +151,27 @@ public:
|
|||
return tmp;
|
||||
}
|
||||
|
||||
// template <class T> Point3<T> operator*(const Point3<T> &p) {
|
||||
// T w;
|
||||
// Point3<T> s;
|
||||
// s[0] = m.ElementAt(0, 0)*p[0] + m.ElementAt(0, 1)*p[1] + m.ElementAt(0, 2)*p[2] + m.ElementAt(0, 3);
|
||||
// s[1] = m.ElementAt(1, 0)*p[0] + m.ElementAt(1, 1)*p[1] + m.ElementAt(1, 2)*p[2] + m.ElementAt(1, 3);
|
||||
// s[2] = m.ElementAt(2, 0)*p[0] + m.ElementAt(2, 1)*p[1] + m.ElementAt(2, 2)*p[2] + m.ElementAt(2, 3);
|
||||
// w = m.ElementAt(3, 0)*p[0] + m.ElementAt(3, 1)*p[1] + m.ElementAt(3, 2)*p[2] + m.ElementAt(3, 3);
|
||||
// if(w!= 0) s /= w;
|
||||
// return s;
|
||||
// }
|
||||
|
||||
Eigen::Matrix<Scalar,3,1> operator * (const Eigen::Matrix<Scalar,3,1>& p) const {
|
||||
Scalar w;
|
||||
Eigen::Matrix<Scalar,3,1> s;
|
||||
s[0] = ElementAt(0, 0)*p[0] + ElementAt(0, 1)*p[1] + ElementAt(0, 2)*p[2] + ElementAt(0, 3);
|
||||
s[1] = ElementAt(1, 0)*p[0] + ElementAt(1, 1)*p[1] + ElementAt(1, 2)*p[2] + ElementAt(1, 3);
|
||||
s[2] = ElementAt(2, 0)*p[0] + ElementAt(2, 1)*p[1] + ElementAt(2, 2)*p[2] + ElementAt(2, 3);
|
||||
w = ElementAt(3, 0)*p[0] + ElementAt(3, 1)*p[1] + ElementAt(3, 2)*p[2] + ElementAt(3, 3);
|
||||
if(w!= 0) s /= w;
|
||||
return s;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
@ -172,7 +195,7 @@ protected:
|
|||
//template <class T> Point3<T> operator*(const Point3<T> &p, const Matrix44<T> &m);
|
||||
|
||||
///Premultiply
|
||||
template <class T> Point3<T> operator*(const Matrix44<T> &m, const Point3<T> &p);
|
||||
// template <class T> Point3<T> operator*(const Matrix44<T> &m, const Point3<T> &p);
|
||||
|
||||
//return NULL matrix if not invertible
|
||||
template <class T> Matrix44<T> &Invert(Matrix44<T> &m);
|
||||
|
@ -464,16 +487,7 @@ bool Decompose(Matrix44<T> &M, Point3<T> &ScaleV, Point3<T> &ShearV, Point3<T> &
|
|||
return true;
|
||||
}
|
||||
|
||||
template <class T> Point3<T> operator*(const Matrix44<T> &m, const Point3<T> &p) {
|
||||
T w;
|
||||
Point3<T> s;
|
||||
s[0] = m.ElementAt(0, 0)*p[0] + m.ElementAt(0, 1)*p[1] + m.ElementAt(0, 2)*p[2] + m.ElementAt(0, 3);
|
||||
s[1] = m.ElementAt(1, 0)*p[0] + m.ElementAt(1, 1)*p[1] + m.ElementAt(1, 2)*p[2] + m.ElementAt(1, 3);
|
||||
s[2] = m.ElementAt(2, 0)*p[0] + m.ElementAt(2, 1)*p[1] + m.ElementAt(2, 2)*p[2] + m.ElementAt(2, 3);
|
||||
w = m.ElementAt(3, 0)*p[0] + m.ElementAt(3, 1)*p[1] + m.ElementAt(3, 2)*p[2] + m.ElementAt(3, 3);
|
||||
if(w!= 0) s /= w;
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -33,18 +33,18 @@
|
|||
#include <vcg/space/space.h>
|
||||
|
||||
namespace vcg{
|
||||
template<class Scalar> class Point4;
|
||||
}
|
||||
template<typename Scalar> class Point2;
|
||||
template<typename Scalar> class Point3;
|
||||
template<typename Scalar> class Point4;
|
||||
|
||||
namespace Eigen{
|
||||
template<typename Scalar,int Size>
|
||||
struct ei_traits<vcg::Point<Scalar,Size> > : ei_traits<Eigen::Matrix<Scalar,Size,1> > {};
|
||||
namespace ndim{
|
||||
template <int Size, typename Scalar> class Point;
|
||||
}
|
||||
}
|
||||
|
||||
namespace vcg {
|
||||
namespace ndim{
|
||||
|
||||
|
||||
/** \addtogroup space */
|
||||
/*@{*/
|
||||
/**
|
||||
|
@ -55,7 +55,17 @@ namespace ndim{
|
|||
*/
|
||||
template <int N, class S> class Point : public Eigen::Matrix<S,N,1>
|
||||
{
|
||||
typedef Eigen::Matrix<T,N,1> _Base;
|
||||
//----------------------------------------
|
||||
// template typedef part
|
||||
// use it as follow: typename Point<N,S>::Type instead of simply Point<N,S>
|
||||
//----------------------------------------
|
||||
public:
|
||||
typedef Eigen::Matrix<S,N,1> Type;
|
||||
//----------------------------------------
|
||||
// inheritence part
|
||||
//----------------------------------------
|
||||
private:
|
||||
typedef Eigen::Matrix<S,N,1> _Base;
|
||||
using _Base::coeff;
|
||||
using _Base::coeffRef;
|
||||
using _Base::setZero;
|
||||
|
@ -65,212 +75,50 @@ template <int N, class S> class Point : public Eigen::Matrix<S,N,1>
|
|||
public:
|
||||
|
||||
_EIGEN_GENERIC_PUBLIC_INTERFACE(Point,_Base);
|
||||
|
||||
typedef S ScalarType;
|
||||
typedef VoidType ParamType;
|
||||
typedef Point<N,S> PointType;
|
||||
enum {Dimension = N};
|
||||
|
||||
VCG_EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Point)
|
||||
|
||||
//@{
|
||||
|
||||
/** @name Standard Constructors and Initializers
|
||||
No casting operators have been introduced to avoid automatic unattended (and costly) conversion between different PointType types
|
||||
**/
|
||||
inline Point() : Base() {}
|
||||
template<typename OtherDerived>
|
||||
inline Point(const Eigen::MatrixBase<OtherDerived>& other) : Base(other) {}
|
||||
|
||||
/// Padding function: give a default 0 value to all the elements that are not in the [0..2] range.
|
||||
/// Useful for managing in a consistent way object that could have point2 / point3 / point4
|
||||
inline S Ext( const int i ) const
|
||||
{
|
||||
if(i>=0 && i<=N) return data()[i];
|
||||
else return 0;
|
||||
}
|
||||
|
||||
/// importer for points with different scalar type and-or dimensionality
|
||||
template <int N2, class S2>
|
||||
inline void Import( const Point<N2,S2> & b )
|
||||
{
|
||||
data()[0] = ScalarType(b[0]);
|
||||
data()[1] = ScalarType(b[1]);
|
||||
if (N>2) { if (N2>2) data()[2] = ScalarType(b[2]); else data()[2] = 0;};
|
||||
if (N>3) { if (N2>3) data()[3] = ScalarType(b[3]); else data()[3] = 0;};
|
||||
}
|
||||
|
||||
/// constructor for points with different scalar type and-or dimensionality
|
||||
template <int N2, class S2>
|
||||
static inline PointType Construct( const Point<N2,S2> & b )
|
||||
{
|
||||
PointType p; p.Import(b);
|
||||
return p;
|
||||
}
|
||||
|
||||
/// importer for homogeneous points
|
||||
template <class S2>
|
||||
inline void ImportHomo( const Point<N-1,S2> & b )
|
||||
{
|
||||
data()[0] = ScalarType(b[0]);
|
||||
data()[1] = ScalarType(b[1]);
|
||||
if (N>2) { data()[2] = ScalarType(data()[2]); };
|
||||
data()[N-1] = 1.0;
|
||||
}
|
||||
|
||||
/// constructor for homogeneus point.
|
||||
template <int N2, class S2>
|
||||
static inline PointType Construct( const Point<N-1,S2> & b )
|
||||
{
|
||||
PointType p; p.ImportHomo(b);
|
||||
return p;
|
||||
}
|
||||
|
||||
//@}
|
||||
|
||||
//@{
|
||||
|
||||
/** @name Data Access.
|
||||
access to data is done by overloading of [] or explicit naming of coords (x,y,z)**/
|
||||
|
||||
inline const S &X() const { return data()[0]; }
|
||||
inline const S &Y() const { return data()[1]; }
|
||||
inline const S &Z() const { static_assert(N>2); return data()[2]; }
|
||||
/// W is in any case the last coordinate.
|
||||
/// (in a 2D point, W() == Y(). In a 3D point, W()==Z()
|
||||
/// in a 4D point, W() is a separate component)
|
||||
inline const S &W() const { return data()[N-1]; }
|
||||
inline S &X() { return data()[0]; }
|
||||
inline S &Y() { return data()[1]; }
|
||||
inline S &Z() { static_assert(N>2); return data()[2]; }
|
||||
inline S &W() { return data()[N-1]; }
|
||||
//@}
|
||||
|
||||
|
||||
//@{
|
||||
|
||||
/** @name Dot products (cross product "%" is defined olny for 3D points)
|
||||
**/
|
||||
|
||||
/// slower version, more stable (double precision only)
|
||||
inline S StableDot ( const PointType & p ) const;
|
||||
|
||||
//@}
|
||||
|
||||
//@{
|
||||
|
||||
/** @name Norms
|
||||
**/
|
||||
|
||||
/// Euclidean norm, static version
|
||||
template <class PT> static S Norm(const PT &p );
|
||||
/// Squared Euclidean norm, static version
|
||||
template <class PT> static S SquaredNorm(const PT &p );
|
||||
/// Normalization (division by norm), static version
|
||||
template <class PT> static PointType & Normalize(const PT &p);
|
||||
|
||||
//@}
|
||||
inline S StableDot (const Point& p) const;
|
||||
|
||||
/// Signed area operator
|
||||
/// a % b returns the signed area of the parallelogram inside a and b
|
||||
// inline S operator % ( PointType const & p ) const;
|
||||
|
||||
/// Convert to polar coordinates
|
||||
void ToPolar( S & ro, S & tetha, S & fi ) const
|
||||
{
|
||||
ro = Norm();
|
||||
tetha = (S)atan2( data()[1], data()[0] );
|
||||
fi = (S)acos( data()[2]/ro );
|
||||
}
|
||||
|
||||
//@{
|
||||
|
||||
/** @name Comparison Operators.
|
||||
Lexicographic order.
|
||||
**/
|
||||
|
||||
inline bool operator == ( PointType const & p ) const;
|
||||
inline bool operator != ( PointType const & p ) const;
|
||||
inline bool operator < ( PointType const & p ) const;
|
||||
inline bool operator > ( PointType const & p ) const;
|
||||
inline bool operator <= ( PointType const & p ) const;
|
||||
inline bool operator >= ( PointType const & p ) const;
|
||||
//@}
|
||||
|
||||
//@{
|
||||
|
||||
/** @name
|
||||
Glocal to Local and viceversa
|
||||
(provided for uniformity with other spatial classes. trivial for points)
|
||||
**/
|
||||
|
||||
inline PointType LocalToGlobal(ParamType p) const { return *this; }
|
||||
inline ParamType GlobalToLocal(PointType p) const { ParamType p(); return p; }
|
||||
//@}
|
||||
|
||||
}; // end class definition
|
||||
|
||||
|
||||
// workaround the lack of template typedef (the next c++ standard will support them :) )
|
||||
typedef Eigen::Matrix<short ,2,1> Point2s;
|
||||
typedef Eigen::Matrix<int ,2,1> Point2i;
|
||||
typedef Eigen::Matrix<float ,2,1> Point2f;
|
||||
typedef Eigen::Matrix<double,2,1> Point2d;
|
||||
typedef Eigen::Matrix<short ,2,1> Vector2s;
|
||||
typedef Eigen::Matrix<int ,2,1> Vector2i;
|
||||
typedef Eigen::Matrix<float ,2,1> Vector2f;
|
||||
typedef Eigen::Matrix<double,2,1> Vector2d;
|
||||
|
||||
template <typename S>
|
||||
struct Point2:public Point<2,S>{
|
||||
typedef Point<3,S> Base;
|
||||
inline Point2() : Base() {};
|
||||
inline Point2(const Point2& p):Base(p){};
|
||||
inline Point2(S a, S b):Base(a,b){};
|
||||
template<typename OtherDerived>
|
||||
inline Point2(const Eigen::MatrixBase<OtherDerived>& other) : Base(other) {}
|
||||
};
|
||||
|
||||
template <typename S>
|
||||
struct Point3:public Point<3,S> {
|
||||
typedef Point<3,S> Base;
|
||||
inline Point3() : Base() {};
|
||||
inline Point3(const Point3& p):Base(p){}
|
||||
inline Point3(S a, S b, S c):Base(a,b,c){};
|
||||
template<typename OtherDerived>
|
||||
inline Point3(const Eigen::MatrixBase<OtherDerived>& other) : Base(other) {}
|
||||
};
|
||||
typedef Eigen::Matrix<short ,3,1> Point3s;
|
||||
typedef Eigen::Matrix<int ,3,1> Point3i;
|
||||
typedef Eigen::Matrix<float ,3,1> Point3f;
|
||||
typedef Eigen::Matrix<double,3,1> Point3d;
|
||||
typedef Eigen::Matrix<short ,3,1> Vector3s;
|
||||
typedef Eigen::Matrix<int ,3,1> Vector3i;
|
||||
typedef Eigen::Matrix<float ,3,1> Vector3f;
|
||||
typedef Eigen::Matrix<double,3,1> Vector3d;
|
||||
|
||||
|
||||
template <typename S>
|
||||
struct Point4:public Point<4,S>{
|
||||
typedef Point<4,S> Base;
|
||||
inline Point4() : Base() {};
|
||||
inline Point4(const Point4& p):Base(p) {}
|
||||
inline Point4(S a, S b, S c, S d):Base(a,b,c,d){};
|
||||
template<typename OtherDerived>
|
||||
inline Point4(const Eigen::MatrixBase<OtherDerived>& other) : Base(other) {}
|
||||
};
|
||||
typedef Eigen::Matrix<short ,4,1> Point4s;
|
||||
typedef Eigen::Matrix<int ,4,1> Point4i;
|
||||
typedef Eigen::Matrix<float ,4,1> Point4f;
|
||||
typedef Eigen::Matrix<double,4,1> Point4d;
|
||||
typedef Eigen::Matrix<short ,4,1> Vector4s;
|
||||
typedef Eigen::Matrix<int ,4,1> Vector4i;
|
||||
typedef Eigen::Matrix<float ,4,1> Vector4f;
|
||||
typedef Eigen::Matrix<double,4,1> Vector4d;
|
||||
|
||||
typedef Point<2,short> Point2s;
|
||||
typedef Point<2,int> Point2i;
|
||||
typedef Point<2,float> Point2f;
|
||||
typedef Point<2,double> Point2d;
|
||||
typedef Point<2,short> Vector2s;
|
||||
typedef Point<2,int> Vector2i;
|
||||
typedef Point<2,float> Vector2f;
|
||||
typedef Point<2,double> Vector2d;
|
||||
|
||||
typedef Point<3,short> Point3s;
|
||||
typedef Point<3,int> Point3i;
|
||||
typedef Point<3,float> Point3f;
|
||||
typedef Point<3,double> Point3d;
|
||||
typedef Point<3,short> Vector3s;
|
||||
typedef Point<3,int> Vector3i;
|
||||
typedef Point<3,float> Vector3f;
|
||||
typedef Point<3,double> Vector3d;
|
||||
|
||||
|
||||
typedef Point<4,short> Point4s;
|
||||
typedef Point<4,int> Point4i;
|
||||
typedef Point<4,float> Point4f;
|
||||
typedef Point<4,double> Point4d;
|
||||
typedef Point<4,short> Vector4s;
|
||||
typedef Point<4,int> Vector4i;
|
||||
typedef Point<4,float> Vector4f;
|
||||
typedef Point<4,double> Vector4d;
|
||||
|
||||
/*@}*/
|
||||
|
||||
|
|
|
@ -29,15 +29,14 @@
|
|||
#define __VCGLIB_POINT2
|
||||
|
||||
#include "../math/eigen.h"
|
||||
#include <vcg/math/base.h>
|
||||
// #include "point.h"
|
||||
|
||||
namespace vcg{
|
||||
template<class Scalar> class Point2;
|
||||
template<typename Scalar> class Point2;
|
||||
}
|
||||
|
||||
namespace Eigen {
|
||||
template<typename Scalar>
|
||||
struct ei_traits<vcg::Point2<Scalar> > : ei_traits<Eigen::Matrix<Scalar,2,1> > {};
|
||||
template<typename Scalar> struct ei_traits<vcg::Point2<Scalar> > : ei_traits<Eigen::Matrix<Scalar,2,1> > {};
|
||||
}
|
||||
|
||||
namespace vcg {
|
||||
|
@ -51,6 +50,16 @@ namespace vcg {
|
|||
*/
|
||||
template <class _Scalar> class Point2 : public Eigen::Matrix<_Scalar,2,1>
|
||||
{
|
||||
//----------------------------------------
|
||||
// template typedef part
|
||||
// use it as follow: typename Point2<S>::Type instead of simply Point2<S>
|
||||
//----------------------------------------
|
||||
public:
|
||||
typedef Eigen::Matrix<_Scalar,2,1> Type;
|
||||
//----------------------------------------
|
||||
// inheritence part
|
||||
//----------------------------------------
|
||||
private:
|
||||
typedef Eigen::Matrix<_Scalar,2,1> _Base;
|
||||
using _Base::coeff;
|
||||
using _Base::coeffRef;
|
||||
|
@ -61,29 +70,8 @@ template <class _Scalar> class Point2 : public Eigen::Matrix<_Scalar,2,1>
|
|||
public:
|
||||
|
||||
_EIGEN_GENERIC_PUBLIC_INTERFACE(Point2,_Base);
|
||||
typedef Scalar ScalarType;
|
||||
|
||||
VCG_EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Point2)
|
||||
|
||||
enum {Dimension = 2};
|
||||
|
||||
//@{
|
||||
/** @name Access to Coords.
|
||||
access to coords is done by overloading of [] or explicit naming of coords (X,Y,)
|
||||
("p[0]" or "p.X()" are equivalent) **/
|
||||
inline const Scalar &X() const {return data()[0];}
|
||||
inline const Scalar &Y() const {return data()[1];}
|
||||
inline Scalar &X() {return data()[0];}
|
||||
inline Scalar &Y() {return data()[1];}
|
||||
|
||||
// overloaded to return a const reference
|
||||
inline const Scalar & V( const int i ) const
|
||||
{
|
||||
assert(i>=0 && i<2);
|
||||
return data()[i];
|
||||
}
|
||||
//@}
|
||||
|
||||
/// empty constructor (does nothing)
|
||||
inline Point2 () { }
|
||||
/// x,y constructor
|
||||
|
@ -133,19 +121,6 @@ public:
|
|||
|
||||
return *this;
|
||||
}
|
||||
|
||||
/// imports from 2D points of different types
|
||||
template <class T>
|
||||
inline void Import( const Point2<T> & b )
|
||||
{
|
||||
data()[0] = b.X(); data()[1] = b.Y();
|
||||
}
|
||||
/// constructs a 2D points from an existing one of different type
|
||||
template <class T>
|
||||
static Point2 Construct( const Point2<T> & b )
|
||||
{
|
||||
return Point2(b.X(),b.Y());
|
||||
}
|
||||
}; // end class definition
|
||||
|
||||
typedef Point2<short> Point2s;
|
||||
|
@ -153,6 +128,15 @@ typedef Point2<int> Point2i;
|
|||
typedef Point2<float> Point2f;
|
||||
typedef Point2<double> Point2d;
|
||||
|
||||
// typedef Eigen::Matrix<short ,2,1> Point2s;
|
||||
// typedef Eigen::Matrix<int ,2,1> Point2i;
|
||||
// typedef Eigen::Matrix<float ,2,1> Point2f;
|
||||
// typedef Eigen::Matrix<double,2,1> Point2d;
|
||||
// typedef Eigen::Matrix<short ,2,1> Vector2s;
|
||||
// typedef Eigen::Matrix<int ,2,1> Vector2i;
|
||||
// typedef Eigen::Matrix<float ,2,1> Vector2f;
|
||||
// typedef Eigen::Matrix<double,2,1> Vector2d;
|
||||
|
||||
/*@}*/
|
||||
} // end namespace
|
||||
#endif
|
||||
|
|
|
@ -29,15 +29,14 @@
|
|||
#define __VCGLIB_POINT3
|
||||
|
||||
#include "../math/eigen.h"
|
||||
#include <vcg/math/base.h>
|
||||
|
||||
namespace vcg{
|
||||
template<class Scalar> class Point3;
|
||||
template<typename Scalar> class Point3;
|
||||
}
|
||||
|
||||
namespace Eigen{
|
||||
template<typename Scalar>
|
||||
struct ei_traits<vcg::Point3<Scalar> > : ei_traits<Eigen::Matrix<Scalar,3,1> > {};
|
||||
|
||||
template<typename Scalar> struct ei_traits<vcg::Point3<Scalar> > : ei_traits<Eigen::Matrix<Scalar,3,1> > {};
|
||||
|
||||
template<typename Scalar>
|
||||
struct NumTraits<vcg::Point3<Scalar> > : NumTraits<Scalar>
|
||||
|
@ -53,6 +52,8 @@ struct NumTraits<vcg::Point3<Scalar> > : NumTraits<Scalar>
|
|||
|
||||
namespace vcg {
|
||||
|
||||
template<typename Scalar> class Box3;
|
||||
|
||||
/** \addtogroup space */
|
||||
/*@{*/
|
||||
/**
|
||||
|
@ -60,29 +61,24 @@ namespace vcg {
|
|||
The class is templated over the ScalarType class that is used to represent coordinates. All the usual
|
||||
operator overloading (* + - ...) is present.
|
||||
*/
|
||||
template <class T> class Box3;
|
||||
|
||||
template <class _Scalar> class Point3 : public Eigen::Matrix<_Scalar,3,1>
|
||||
{
|
||||
typedef Eigen::Matrix<_Scalar,3,1> _Base;
|
||||
using _Base::coeff;
|
||||
using _Base::coeffRef;
|
||||
using _Base::setZero;
|
||||
using _Base::data;
|
||||
using _Base::V;
|
||||
|
||||
//----------------------------------------
|
||||
// template typedef part
|
||||
// use it as follow: typename Point3<S>::Type instead of simply Point3<S>
|
||||
//----------------------------------------
|
||||
public:
|
||||
typedef Eigen::Matrix<_Scalar,3,1> Type;
|
||||
//----------------------------------------
|
||||
// inheritence part
|
||||
//----------------------------------------
|
||||
private:
|
||||
typedef Eigen::Matrix<_Scalar,3,1> _Base;
|
||||
using _Base::Construct;
|
||||
public:
|
||||
|
||||
_EIGEN_GENERIC_PUBLIC_INTERFACE(Point3,_Base);
|
||||
typedef Scalar ScalarType;
|
||||
|
||||
VCG_EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Point3)
|
||||
|
||||
enum {Dimension = 3};
|
||||
|
||||
|
||||
//@{
|
||||
|
||||
/** @name Standard Constructors and Initializers
|
||||
No casting operators have been introduced to avoid automatic unattended (and costly) conversion between different point types
|
||||
**/
|
||||
|
@ -95,133 +91,15 @@ public:
|
|||
inline Point3(const Eigen::MatrixBase<OtherDerived>& other) : Base(other) {}
|
||||
|
||||
|
||||
template<class OtherDerived>
|
||||
inline void Import( const Eigen::MatrixBase<OtherDerived>& b )
|
||||
{
|
||||
EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(OtherDerived,3);
|
||||
data()[0] = Scalar(b[0]);
|
||||
data()[1] = Scalar(b[1]);
|
||||
data()[2] = Scalar(b[2]);
|
||||
}
|
||||
|
||||
template <class Q>
|
||||
static inline Point3 Construct( const Point3<Q> & b )
|
||||
{
|
||||
return Point3(Scalar(b[0]),Scalar(b[1]),Scalar(b[2]));
|
||||
}
|
||||
|
||||
// this one is very useless
|
||||
template <class Q>
|
||||
static inline Point3 Construct( const Q & P0, const Q & P1, const Q & P2)
|
||||
{
|
||||
return Point3(Scalar(P0),Scalar(P1),Scalar(P2));
|
||||
}
|
||||
vcg::Box3<_Scalar> GetBBox(vcg::Box3<_Scalar> &bb) const;
|
||||
|
||||
static inline Point3 Construct( const Point3<ScalarType> & b )
|
||||
{
|
||||
return b;
|
||||
}
|
||||
|
||||
//@}
|
||||
|
||||
//@{
|
||||
|
||||
/** @name Data Access.
|
||||
access to data is done by overloading of [] or explicit naming of coords (x,y,z)**/
|
||||
|
||||
inline const Scalar &X() const { return data()[0]; }
|
||||
inline const Scalar &Y() const { return data()[1]; }
|
||||
inline const Scalar &Z() const { return data()[2]; }
|
||||
inline Scalar &X() { return data()[0]; }
|
||||
inline Scalar &Y() { return data()[1]; }
|
||||
inline Scalar &Z() { return data()[2]; }
|
||||
// overloaded to return a const reference
|
||||
inline const Scalar & V( const int i ) const
|
||||
{
|
||||
assert(i>=0 && i<3);
|
||||
return data()[i];
|
||||
}
|
||||
//@}
|
||||
//@{
|
||||
|
||||
/** @name Classical overloading of operators
|
||||
Note
|
||||
**/
|
||||
|
||||
// Scalatura differenziata
|
||||
inline Point3 & Scale( const Scalar sx, const Scalar sy, const Scalar sz )
|
||||
{
|
||||
data()[0] *= sx;
|
||||
data()[1] *= sy;
|
||||
data()[2] *= sz;
|
||||
return *this;
|
||||
}
|
||||
inline Point3 & Scale( const Point3 & p )
|
||||
{
|
||||
data()[0] *= p.data()[0];
|
||||
data()[1] *= p.data()[1];
|
||||
data()[2] *= p.data()[2];
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
{
|
||||
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)
|
||||
{
|
||||
data()[0]= ro*cos(theta)*cos(phi);
|
||||
data()[1]= ro*sin(phi);
|
||||
data()[2]= ro*sin(theta)*cos(phi);
|
||||
}
|
||||
|
||||
Box3<_Scalar> GetBBox(Box3<_Scalar> &bb) const;
|
||||
//@}
|
||||
|
||||
}; // end class definition
|
||||
|
||||
|
||||
// versione uguale alla precedente ma che assume che i due vettori sono unitari
|
||||
template <class Scalar>
|
||||
inline Scalar AngleN( Point3<Scalar> const & p1, Point3<Scalar> const & p2 )
|
||||
{
|
||||
Scalar w = p1*p2;
|
||||
if(w>1)
|
||||
w = 1;
|
||||
else if(w<-1)
|
||||
w=-1;
|
||||
return (Scalar) acos(w);
|
||||
}
|
||||
|
||||
|
||||
template <class Scalar>
|
||||
inline Point3<Scalar> & Normalize( Point3<Scalar> & p )
|
||||
{
|
||||
p.Normalize();
|
||||
return p;
|
||||
}
|
||||
}; // end class definition (Point3)
|
||||
|
||||
// Dot product preciso numericamente (solo double!!)
|
||||
// Implementazione: si sommano i prodotti per ordine di esponente
|
||||
|
@ -255,8 +133,6 @@ double stable_dot ( Point3<Scalar> const & p0, Point3<Scalar> const & p1 )
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// Point(p) Edge(v1-v2) dist, q is the point in v1-v2 with min dist
|
||||
template<class Scalar>
|
||||
Scalar PSDist( const Point3<Scalar> & p,
|
||||
|
@ -272,7 +148,6 @@ Scalar PSDist( const Point3<Scalar> & p,
|
|||
return Distance(p,q);
|
||||
}
|
||||
|
||||
|
||||
template <class Scalar>
|
||||
void GetUV( Point3<Scalar> &n,Point3<Scalar> &u, Point3<Scalar> &v, Point3<Scalar> up=(Point3<Scalar>(0,1,0)) )
|
||||
{
|
||||
|
@ -297,23 +172,21 @@ void GetUV( Point3<Scalar> &n,Point3<Scalar> &u, Point3<Scalar> &v, Point3<Scala
|
|||
Point3<Scalar> uv=u^v;
|
||||
}
|
||||
|
||||
|
||||
template <class SCALARTYPE>
|
||||
inline Point3<SCALARTYPE> Abs(const Point3<SCALARTYPE> & p) {
|
||||
return (Point3<SCALARTYPE>(math::Abs(p[0]), math::Abs(p[1]), math::Abs(p[2])));
|
||||
}
|
||||
// probably a more uniform naming should be defined...
|
||||
template <class SCALARTYPE>
|
||||
inline Point3<SCALARTYPE> LowClampToZero(const Point3<SCALARTYPE> & p) {
|
||||
return (Point3<SCALARTYPE>(math::Max(p[0], (SCALARTYPE)0), math::Max(p[1], (SCALARTYPE)0), math::Max(p[2], (SCALARTYPE)0)));
|
||||
}
|
||||
/*@}*/
|
||||
|
||||
typedef Point3<short> Point3s;
|
||||
typedef Point3<int> Point3i;
|
||||
typedef Point3<float> Point3f;
|
||||
typedef Point3<double> Point3d;
|
||||
|
||||
/*@}*/
|
||||
// typedef Eigen::Matrix<short ,3,1> Point3s;
|
||||
// typedef Eigen::Matrix<int ,3,1> Point3i;
|
||||
// typedef Eigen::Matrix<float ,3,1> Point3f;
|
||||
// typedef Eigen::Matrix<double,3,1> Point3d;
|
||||
// typedef Eigen::Matrix<short ,3,1> Vector3s;
|
||||
// typedef Eigen::Matrix<int ,3,1> Vector3i;
|
||||
// typedef Eigen::Matrix<float ,3,1> Vector3f;
|
||||
// typedef Eigen::Matrix<double,3,1> Vector3d;
|
||||
|
||||
} // end namespace
|
||||
|
||||
|
|
|
@ -31,15 +31,16 @@
|
|||
#include "../math/eigen.h"
|
||||
|
||||
namespace vcg{
|
||||
template<class Scalar> class Point4;
|
||||
template<typename Scalar> class Point4;
|
||||
}
|
||||
|
||||
namespace Eigen {
|
||||
template<typename Scalar>
|
||||
struct ei_traits<vcg::Point4<Scalar> > : ei_traits<Eigen::Matrix<Scalar,4,1> > {};
|
||||
template<typename Scalar> struct ei_traits<vcg::Point4<Scalar> > : ei_traits<Eigen::Matrix<Scalar,4,1> > {};
|
||||
}
|
||||
|
||||
namespace vcg {
|
||||
|
||||
|
||||
/** \addtogroup space */
|
||||
/*@{*/
|
||||
/**
|
||||
|
@ -47,9 +48,18 @@ namespace vcg {
|
|||
The class is templated over the ScalarType class that is used to represent coordinates.
|
||||
All the usual operator (* + - ...) are defined.
|
||||
*/
|
||||
|
||||
template <class T> class Point4 : public Eigen::Matrix<T,4,1>
|
||||
{
|
||||
//----------------------------------------
|
||||
// template typedef part
|
||||
// use it as follow: typename Point4<S>::Type instead of simply Point4<S>
|
||||
//----------------------------------------
|
||||
public:
|
||||
typedef Eigen::Matrix<T,4,1> Type;
|
||||
//----------------------------------------
|
||||
// inheritence part
|
||||
//----------------------------------------
|
||||
private:
|
||||
typedef Eigen::Matrix<T,4,1> _Base;
|
||||
using _Base::coeff;
|
||||
using _Base::coeffRef;
|
||||
|
@ -64,8 +74,6 @@ public:
|
|||
|
||||
VCG_EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Point4)
|
||||
|
||||
enum {Dimension = 4};
|
||||
|
||||
inline Point4() : Base() {}
|
||||
inline Point4( const T nx, const T ny, const T nz , const T nw ) : Base(nx,ny,nz,nw) {}
|
||||
inline Point4(const T p[4]) : Base(p) {}
|
||||
|
@ -74,30 +82,6 @@ public:
|
|||
inline Point4(const Eigen::MatrixBase<OtherDerived>& other) : Base(other) {}
|
||||
|
||||
|
||||
/// importer from different Point4 types
|
||||
template <class Q> inline void Import( const Point4<Q> & b ) { *this = b.template cast<T>(); }
|
||||
|
||||
/// constuctor that imports from different Point4 types
|
||||
template <class Q>
|
||||
static inline Point4 Construct( const Point4<Q> & b ) { return b.template cast<T>(); }
|
||||
|
||||
|
||||
//@{
|
||||
|
||||
inline T &X() {return Base::x();}
|
||||
inline T &Y() {return Base::y();}
|
||||
inline T &Z() {return Base::z();}
|
||||
inline T &W() {return Base::w();}
|
||||
|
||||
// overloaded to return a const reference
|
||||
inline const T & V (int i) const
|
||||
{
|
||||
assert(i>=0 && i<4);
|
||||
return data()[i];
|
||||
}
|
||||
|
||||
//@}
|
||||
|
||||
inline Point4 VectProd ( const Point4 &x, const Point4 &z ) const
|
||||
{
|
||||
Point4 res;
|
||||
|
@ -147,6 +131,20 @@ public:
|
|||
}; // end class definition
|
||||
|
||||
|
||||
typedef Point4<short> Point4s;
|
||||
typedef Point4<int> Point4i;
|
||||
typedef Point4<float> Point4f;
|
||||
typedef Point4<double> Point4d;
|
||||
|
||||
// typedef Eigen::Matrix<short ,4,1> Point4s;
|
||||
// typedef Eigen::Matrix<int ,4,1> Point4i;
|
||||
// typedef Eigen::Matrix<float ,4,1> Point4f;
|
||||
// typedef Eigen::Matrix<double,4,1> Point4d;
|
||||
// typedef Eigen::Matrix<short ,4,1> Vector4s;
|
||||
// typedef Eigen::Matrix<int ,4,1> Vector4i;
|
||||
// typedef Eigen::Matrix<float ,4,1> Vector4f;
|
||||
// typedef Eigen::Matrix<double,4,1> Vector4d;
|
||||
|
||||
/// slower version of dot product, more stable (double precision only)
|
||||
template<class T>
|
||||
double StableDot ( Point4<T> const & p0, Point4<T> const & p1 )
|
||||
|
@ -154,11 +152,6 @@ double StableDot ( Point4<T> const & p0, Point4<T> const & p1 )
|
|||
return p0.StableDot(p1);
|
||||
}
|
||||
|
||||
typedef Point4<short> Point4s;
|
||||
typedef Point4<int> Point4i;
|
||||
typedef Point4<float> Point4f;
|
||||
typedef Point4<double> Point4d;
|
||||
|
||||
/*@}*/
|
||||
} // end namespace
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue