* change all remaining Transpose to transpose,
* update the gl/math wrappers to make them more Eigen friendly (and remove the useless, and not used, and somehow dangerous *Direct and *E functions) * add automatic reinterpret_casting from Eigen::Matrix to vcg specialized types
This commit is contained in:
parent
0361427bc0
commit
07f2e976ea
|
@ -464,7 +464,7 @@ int readmesh(FILE* fp)
|
|||
}
|
||||
}
|
||||
|
||||
Transpose(currtrasf);
|
||||
currtrasf = currtrasf.transpose().eval();
|
||||
|
||||
// apply tranformation
|
||||
if(hascolor && savecolor)
|
||||
|
|
|
@ -74,8 +74,7 @@ bool verify(Matrix33f &m) {
|
|||
cout << "Column norms: " << m.GetColumn(0).Norm() << " "
|
||||
<< m.GetColumn(1).Norm() << " "
|
||||
<< m.GetColumn(2).Norm() << endl;
|
||||
Matrix33f im = m;
|
||||
im.Transpose();
|
||||
Matrix33f im = m.transpose() * m;
|
||||
im = im*m;
|
||||
cout << "Check ortonormality: " << im << endl;
|
||||
Quaternionf q;
|
||||
|
|
|
@ -107,6 +107,7 @@ Revision 1.12 2004/03/25 14:57:49 ponchio
|
|||
#include <vcg/space/point3.h>
|
||||
#include <vcg/space/point4.h>
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
|
||||
|
||||
namespace vcg {
|
||||
|
@ -291,6 +292,18 @@ public:
|
|||
// for the transistion to eigen
|
||||
const Matrix44& eval() { return *this; }
|
||||
|
||||
void print() {
|
||||
unsigned int i, j, p;
|
||||
for (i=0, p=0; i<4; i++, p+=4)
|
||||
{
|
||||
std::cout << "[\t";
|
||||
for (j=0; j<4; j++)
|
||||
std::cout << _a[p+j] << "\t";
|
||||
|
||||
std::cout << "]\n";
|
||||
}
|
||||
std::cout << "\n";
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -31,7 +31,24 @@
|
|||
|
||||
// forward declarations
|
||||
namespace Eigen {
|
||||
|
||||
#include "../Eigen/src/Core/util/Meta.h"
|
||||
|
||||
template<typename Derived1, typename Derived2, int Size> struct ei_lexi_comparison;
|
||||
|
||||
template<typename Derived1, typename Derived2,
|
||||
bool SameType = ei_is_same_type<Derived1,Derived2>::ret,
|
||||
bool SameSize = Derived1::SizeAtCompileTime==Derived2::SizeAtCompileTime>
|
||||
struct ei_import_selector;
|
||||
|
||||
template<typename XprType,
|
||||
int Rows = XprType::RowsAtCompileTime,
|
||||
int Cols = XprType::ColsAtCompileTime,
|
||||
int StorageOrder = XprType::Flags&1,
|
||||
int MRows = XprType::MaxRowsAtCompileTime,
|
||||
int MCols = XprType::MaxColsAtCompileTime>
|
||||
struct ei_to_vcgtype;
|
||||
|
||||
}
|
||||
|
||||
#include "base.h"
|
||||
|
@ -156,6 +173,46 @@ template<typename Derived1, typename Derived2> struct ei_lexi_comparison<Derived
|
|||
}
|
||||
};
|
||||
|
||||
// implementation of Import
|
||||
template<typename Derived1, typename Derived2>
|
||||
struct ei_import_selector<Derived1,Derived2,true,true>
|
||||
{
|
||||
static void run(Derived1& a, const Derived2& b) { a = b; }
|
||||
};
|
||||
|
||||
template<typename Derived1, typename Derived2>
|
||||
struct ei_import_selector<Derived1,Derived2,false,true>
|
||||
{
|
||||
static void run(Derived1& a, const Derived2& b)
|
||||
{ a = b.template cast<typename Derived1::Scalar>(); }
|
||||
};
|
||||
|
||||
template<typename Derived1, typename Derived2>
|
||||
struct ei_import_selector<Derived1,Derived2,false,false>
|
||||
{
|
||||
static void run(Derived1& a, const Derived2& b)
|
||||
{
|
||||
EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived1);
|
||||
EIGEN_STATIC_ASSERT_FIXED_SIZE(Derived1);
|
||||
EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived2);
|
||||
EIGEN_STATIC_ASSERT_FIXED_SIZE(Derived2);
|
||||
enum {
|
||||
Size1 = Derived1::SizeAtCompileTime,
|
||||
Size2 = Derived2::SizeAtCompileTime
|
||||
};
|
||||
assert(Size1<=4 && Size2<=4);
|
||||
a.coeffRef(0) = Scalar(b.coeff(0));
|
||||
if (Size1>1) { if (Size2>1) a.coeffRef(1) = Scalar(b.coeff(1)); else a.coeffRef(1) = 0; }
|
||||
if (Size1>2) { if (Size2>2) a.coeffRef(2) = Scalar(b.coeff(2)); else a.coeffRef(2) = 0; }
|
||||
if (Size1>3) { if (Size2>3) a.coeffRef(3) = Scalar(b.coeff(3)); else a.coeffRef(3) = 0; }
|
||||
}
|
||||
};
|
||||
|
||||
// default implementation of ei_to_vcgtype
|
||||
// the specialization are with
|
||||
template<typename XprType,int Rows,int Cols,int StorageOrder,int MRows,int MCols>
|
||||
struct ei_to_vcgtype { typedef Matrix<typename XprType::Scalar,Rows,Cols,StorageOrder,MRows,MCols> type; };
|
||||
|
||||
}
|
||||
|
||||
#define VCG_EIGEN_INHERIT_ASSIGNMENT_OPERATOR(Derived, Op) \
|
||||
|
|
|
@ -24,28 +24,31 @@
|
|||
#warning You are including deprecated math stuff
|
||||
|
||||
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)
|
||||
{
|
||||
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; }
|
||||
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)
|
||||
|
@ -58,21 +61,10 @@ inline void ImportHomo(const MatrixBase<OtherDerived>& 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.
|
||||
/// constructor for homogeneus point.
|
||||
template<typename OtherDerived>
|
||||
static inline Matrix ConstructHomo(const MatrixBase<OtherDerived>& b)
|
||||
{
|
||||
Matrix p; p.ImportHomo(b);
|
||||
return p;
|
||||
}
|
||||
{ Matrix p; p.ImportHomo(b); return p; }
|
||||
|
||||
inline const Scalar &X() const { return data()[0]; }
|
||||
inline const Scalar &Y() const { return data()[1]; }
|
||||
|
@ -81,15 +73,19 @@ 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
|
||||
/** 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]; }
|
||||
|
||||
Scalar* V() { return data(); }
|
||||
const Scalar* V() const { return data(); }
|
||||
/** \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
|
||||
inline const Scalar& V( const int i ) const
|
||||
EIGEN_DEPRECATED inline const Scalar& V( const int i ) const
|
||||
{
|
||||
assert(i>=0 && i<SizeAtCompileTime);
|
||||
return data()[i];
|
||||
|
|
|
@ -41,6 +41,8 @@ template<class Scalar> class Matrix;
|
|||
namespace Eigen{
|
||||
template<typename Scalar>
|
||||
struct ei_traits<vcg::ndim::Matrix<Scalar> > : ei_traits<Eigen::Matrix<Scalar,Dynamic,Dynamic> > {};
|
||||
template<typename XprType> struct ei_to_vcgtype<XprType,Dynamic,Dynamic,RowMajor,Dynamic,Dynamic>
|
||||
{ typedef vcg::ndim::Matrix<typename XprType::Scalar> type; };
|
||||
}
|
||||
|
||||
namespace vcg{
|
||||
|
@ -50,7 +52,7 @@ namespace ndim{
|
|||
/* @{ */
|
||||
|
||||
/*!
|
||||
* \deprecated use Matrix<Scalar,Rows,Cols> or Matrix<Scalar,Dynamic,Dynamic>
|
||||
* \deprecated use Matrix<Scalar,Rows,Cols> or Matrix<Scalar,Dynamic,Dynamic> or any typedef
|
||||
* This class represent a generic <I>m</I><EFBFBD><I>n</I> matrix. The class is templated over the scalar type field.
|
||||
* @param Scalar (Templete Parameter) Specifies the ScalarType field.
|
||||
*/
|
||||
|
@ -63,7 +65,6 @@ public:
|
|||
|
||||
_EIGEN_GENERIC_PUBLIC_INTERFACE(Matrix,_Base);
|
||||
typedef _Scalar ScalarType;
|
||||
|
||||
VCG_EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Matrix)
|
||||
|
||||
/*!
|
||||
|
|
|
@ -38,12 +38,14 @@ template<class Scalar> class Matrix33;
|
|||
namespace Eigen{
|
||||
template<typename Scalar>
|
||||
struct ei_traits<vcg::Matrix33<Scalar> > : ei_traits<Eigen::Matrix<Scalar,3,3,RowMajor> > {};
|
||||
template<typename XprType> struct ei_to_vcgtype<XprType,3,3,RowMajor,3,3>
|
||||
{ typedef vcg::Matrix33<typename XprType::Scalar> type; };
|
||||
}
|
||||
|
||||
namespace vcg {
|
||||
|
||||
|
||||
/** @name Matrix33
|
||||
/** \deprecated use Matrix<Scalar,3,3>
|
||||
@name Matrix33
|
||||
Class Matrix33.
|
||||
This is the class for definition of a matrix 3x3.
|
||||
@param S (Templete Parameter) Specifies the ScalarType field.
|
||||
|
@ -98,7 +100,6 @@ public:
|
|||
return SetRotateRad(math::ToRad(angle),axis);
|
||||
}
|
||||
|
||||
|
||||
// Warning, this Inversion code can be HIGHLY NUMERICALLY UNSTABLE!
|
||||
// In most case you are advised to use the Invert() method based on SVD decomposition.
|
||||
/** \deprecated */
|
||||
|
@ -110,18 +111,13 @@ public:
|
|||
printf("| %g \t%g \t%g |\n",coeff(i,0),coeff(i,1),coeff(i,2));
|
||||
}
|
||||
|
||||
/*
|
||||
/** \deprecated use a * b.transpose()
|
||||
compute the matrix generated by the product of a * b^T
|
||||
*/
|
||||
void ExternalProduct(const Point3<Scalar> &a, const Point3<Scalar> &b)
|
||||
{
|
||||
for(int i=0;i<3;++i)
|
||||
for(int j=0;j<3;++j)
|
||||
(*this)[i][j] = a[i]*b[j];
|
||||
}
|
||||
// hm.... this is the outer product
|
||||
void ExternalProduct(const Point3<Scalar> &a, const Point3<Scalar> &b) { *this = a * b.transpose(); }
|
||||
|
||||
/* Compute the Frobenius Norm of the Matrix
|
||||
*/
|
||||
/** Compute the Frobenius Norm of the Matrix */
|
||||
Scalar Norm() { return Base::cwise().abs2().sum(); }
|
||||
// {
|
||||
// // FIXME looks like there was a bug: j is not used !!!
|
||||
|
|
|
@ -41,6 +41,8 @@ template<class Scalar> class Matrix44;
|
|||
namespace Eigen{
|
||||
template<typename Scalar>
|
||||
struct ei_traits<vcg::Matrix44<Scalar> > : ei_traits<Eigen::Matrix<Scalar,4,4,RowMajor> > {};
|
||||
template<typename XprType> struct ei_to_vcgtype<XprType,4,4,RowMajor,4,4>
|
||||
{ typedef vcg::Matrix44<typename XprType::Scalar> type; };
|
||||
}
|
||||
|
||||
namespace vcg {
|
||||
|
@ -140,17 +142,6 @@ public:
|
|||
Matrix44 &SetRotateDeg(Scalar AngleDeg, const Point3<Scalar> & axis);
|
||||
Matrix44 &SetRotateRad(Scalar AngleRad, const Point3<Scalar> & axis);
|
||||
|
||||
template <class Q> void Import(const Matrix44<Q> &m) {
|
||||
for(int i = 0; i < 16; i++)
|
||||
Base::data()[i] = (Scalar)(m.data()[i]);
|
||||
}
|
||||
template <class Q>
|
||||
static inline Matrix44 Construct( const Matrix44<Q> & b )
|
||||
{
|
||||
Matrix44 tmp; tmp.FromMatrix(b);
|
||||
return tmp;
|
||||
}
|
||||
|
||||
// template <class T> Point3<T> operator*(const Point3<T> &p) {
|
||||
// T w;
|
||||
// Point3<T> s;
|
||||
|
@ -173,30 +164,10 @@ public:
|
|||
return s;
|
||||
}
|
||||
|
||||
void print() {std::cout << *this << "\n\n";}
|
||||
|
||||
};
|
||||
|
||||
|
||||
/** Class for solving A * x = b. */
|
||||
template <class T> class LinearSolve: public Matrix44<T> {
|
||||
public:
|
||||
LinearSolve(const Matrix44<T> &m);
|
||||
Point4<T> Solve(const Point4<T> &b); // solve A <20> x = b
|
||||
///If you need to solve some equation you can use this function instead of Matrix44 one for speed.
|
||||
T Determinant() const;
|
||||
protected:
|
||||
///Holds row permutation.
|
||||
int index[4]; //hold permutation
|
||||
///Hold sign of row permutation (used for determinant sign)
|
||||
T d;
|
||||
bool Decompose();
|
||||
};
|
||||
|
||||
/*** Postmultiply */
|
||||
//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);
|
||||
|
||||
//return NULL matrix if not invertible
|
||||
template <class T> Matrix44<T> &Invert(Matrix44<T> &m);
|
||||
template <class T> Matrix44<T> Inverse(const Matrix44<T> &m);
|
||||
|
@ -206,18 +177,6 @@ typedef Matrix44<int> Matrix44i;
|
|||
typedef Matrix44<float> Matrix44f;
|
||||
typedef Matrix44<double> Matrix44d;
|
||||
|
||||
|
||||
//template <class T> T &Matrix44<T>::operator[](const int i) {
|
||||
// assert(i >= 0 && i < 16);
|
||||
// return ((T *)_a)[i];
|
||||
//}
|
||||
//
|
||||
//template <class T> const T &Matrix44<T>::operator[](const int i) const {
|
||||
// assert(i >= 0 && i < 16);
|
||||
// return ((T *)_a)[i];
|
||||
//}
|
||||
|
||||
|
||||
template < class PointType , class T > void operator*=( std::vector<PointType> &vert, const Matrix44<T> & m ) {
|
||||
typename std::vector<PointType>::iterator ii;
|
||||
for(ii=vert.begin();ii!=vert.end();++ii)
|
||||
|
@ -487,22 +446,6 @@ bool Decompose(Matrix44<T> &M, Point3<T> &ScaleV, Point3<T> &ShearV, Point3<T> &
|
|||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// template <class T> Point3<T> operator*(const Point3<T> &p, const Matrix44<T> &m) {
|
||||
// T w;
|
||||
// Point3<T> s;
|
||||
// s[0] = m.ElementAt(0, 0)*p[0] + m.ElementAt(1, 0)*p[1] + m.ElementAt(2, 0)*p[2] + m.ElementAt(3, 0);
|
||||
// s[1] = m.ElementAt(0, 1)*p[0] + m.ElementAt(1, 1)*p[1] + m.ElementAt(2, 1)*p[2] + m.ElementAt(3, 1);
|
||||
// s[2] = m.ElementAt(0, 2)*p[0] + m.ElementAt(1, 2)*p[1] + m.ElementAt(2, 2)*p[2] + m.ElementAt(3, 2);
|
||||
// w = m.ElementAt(0, 3)*p[0] + m.ElementAt(1, 3)*p[1] + m.ElementAt(2, 3)*p[2] + m.ElementAt(3, 3);
|
||||
// if(w != 0) s /= w;
|
||||
// return s;
|
||||
// }
|
||||
|
||||
|
||||
/*
|
||||
To invert a matrix you can
|
||||
either invert the matrix inplace calling
|
||||
|
|
|
@ -205,8 +205,7 @@ public:
|
|||
Matrix44<S> GetExtrinsicsToWorldMatrix() const {
|
||||
Matrix44<S> rotM ;
|
||||
Extrinsics.rot.ToMatrix(rotM);
|
||||
Transpose(rotM);
|
||||
return Matrix44<S>().SetTranslate(Extrinsics.tra) * rotM;
|
||||
return Matrix44<S>().SetTranslate(Extrinsics.tra) * rotM.transpose();
|
||||
}
|
||||
|
||||
/* Returns the matrix M such that
|
||||
|
@ -316,8 +315,7 @@ vcg::Point3<S> Shot<S,RotationType>::ConvertCameraToWorldCoordinates(const vcg::
|
|||
vcg::Point3<S> cp = p;
|
||||
cp[2]=-cp[2]; // note: World reference system is left handed
|
||||
Extrinsics.rot.ToMatrix(rotM);
|
||||
Transpose(rotM);
|
||||
cp = rotM * cp+ GetViewPoint();
|
||||
cp = rotM.transpose() * cp + GetViewPoint();
|
||||
return cp;
|
||||
}
|
||||
|
||||
|
|
|
@ -37,6 +37,8 @@ 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 XprType> struct ei_to_vcgtype<XprType,2,1,0,2,1>
|
||||
{ typedef vcg::Point2<typename XprType::Scalar> type; };
|
||||
}
|
||||
|
||||
namespace vcg {
|
||||
|
|
|
@ -38,6 +38,9 @@ namespace Eigen{
|
|||
|
||||
template<typename Scalar> struct ei_traits<vcg::Point3<Scalar> > : ei_traits<Eigen::Matrix<Scalar,3,1> > {};
|
||||
|
||||
template<typename XprType> struct ei_to_vcgtype<XprType,3,1,0,3,1>
|
||||
{ typedef vcg::Point3<typename XprType::Scalar> type; };
|
||||
|
||||
template<typename Scalar>
|
||||
struct NumTraits<vcg::Point3<Scalar> > : NumTraits<Scalar>
|
||||
{
|
||||
|
|
|
@ -36,6 +36,8 @@ 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 XprType> struct ei_to_vcgtype<XprType,4,1,0,4,1>
|
||||
{ typedef vcg::Point4<typename XprType::Scalar> type; };
|
||||
}
|
||||
|
||||
namespace vcg {
|
||||
|
|
|
@ -0,0 +1,144 @@
|
|||
/****************************************************************************
|
||||
* 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. *
|
||||
* *
|
||||
****************************************************************************/
|
||||
/****************************************************************************
|
||||
History
|
||||
|
||||
$Log: not supported by cvs2svn $
|
||||
Revision 1.10 2006/02/13 13:05:05 cignoni
|
||||
Removed glew inclusion
|
||||
|
||||
Revision 1.9 2004/09/30 00:48:07 ponchio
|
||||
<gl/glew.h> -> <GL/glew.h>
|
||||
|
||||
Revision 1.8 2004/09/28 14:04:36 ganovelli
|
||||
glGet added
|
||||
|
||||
Revision 1.7 2004/07/13 15:55:57 cignoni
|
||||
Added test on presence of glTranspose extension (for old hw support)
|
||||
|
||||
Revision 1.6 2004/05/26 15:12:39 cignoni
|
||||
Removed inclusion of gl extension stuff
|
||||
|
||||
Revision 1.5 2004/05/12 20:54:55 ponchio
|
||||
*** empty log message ***
|
||||
|
||||
Revision 1.4 2004/05/12 13:07:47 ponchio
|
||||
Added #include <glew.h>
|
||||
|
||||
Revision 1.3 2004/05/04 23:36:23 cignoni
|
||||
remove include of gl and added glextgension exploiting,
|
||||
|
||||
Revision 1.2 2004/04/07 10:47:03 cignoni
|
||||
inlined functions for avoid multiple linking errors
|
||||
|
||||
Revision 1.1 2004/03/31 15:27:17 ponchio
|
||||
*** empty log message ***
|
||||
|
||||
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef VCG_GL_MATH_H
|
||||
#define VCG_GL_MATH_H
|
||||
|
||||
// Please note that this file assume that you have already included your
|
||||
// gl-extension wrapping utility, and that therefore all the extension symbol are already defined.
|
||||
|
||||
#include <vcg/math/matrix44.h>
|
||||
#include <vcg/math/similarity.h>
|
||||
//#include <GL/glew.h> // please do not include it!
|
||||
|
||||
|
||||
namespace vcg {
|
||||
|
||||
inline void glMultMatrixE(const Matrix44f &matrix) {
|
||||
//glMultMatrixf((const GLfloat *)(matrix[0]));
|
||||
if(glMultTransposeMatrixf) glMultTransposeMatrixf((const GLfloat *)(matrix.V()));
|
||||
else {
|
||||
glMultMatrixf((const GLfloat *)(matrix.transpose().eval().V()));
|
||||
}
|
||||
}
|
||||
|
||||
inline void glMultMatrix(const Matrix44f &matrix) {
|
||||
glMultMatrixf((const GLfloat *)(matrix.transpose().eval().V()));
|
||||
}
|
||||
|
||||
inline void glMultMatrixE(const Matrix44d &matrix) {
|
||||
if(glMultTransposeMatrixd) glMultTransposeMatrixd((const GLdouble *)(matrix.V()));
|
||||
else {
|
||||
glMultMatrixd((const GLdouble *)(matrix.transpose().eval().V()));
|
||||
}
|
||||
}
|
||||
inline void glMultMatrix(const Matrix44d &matrix) {
|
||||
glMultMatrixd((const GLdouble *)(matrix.transpose().eval().V()));
|
||||
}
|
||||
|
||||
inline void glMultMatrixDirect(const Matrix44f &matrix) {
|
||||
glMultMatrixf((const GLfloat *)(matrix.V()));
|
||||
}
|
||||
|
||||
inline void glMultMatrixDirect(const Matrix44d &matrix) {
|
||||
glMultMatrixd((const GLdouble *)(matrix.V()));
|
||||
}
|
||||
|
||||
inline void glMultMatrix(const Similarityf &s) {
|
||||
glTranslatef(s.tra[0], s.tra[1], s.tra[2]);
|
||||
glScalef(s.sca, s.sca, s.sca);
|
||||
float alpha;
|
||||
Point3f axis;
|
||||
s.rot.ToAxis(alpha, axis);
|
||||
glRotatef(math::ToDeg(alpha), axis[0], axis[1], axis[2]);
|
||||
|
||||
}
|
||||
|
||||
inline void glMultMatrix(const Similarityd &s) {
|
||||
glTranslated(s.tra[0], s.tra[1], s.tra[2]);
|
||||
double alpha;
|
||||
Point3d axis;
|
||||
s.rot.ToAxis(alpha, axis);
|
||||
glRotated(math::ToDeg(alpha), axis[0], axis[1], axis[2]);
|
||||
glScaled(s.sca, s.sca, s.sca);
|
||||
}
|
||||
|
||||
inline void glGetv(const GLenum pname, Matrix44f & m){
|
||||
Matrix44f tmp;
|
||||
glGetFloatv(pname,tmp.V());
|
||||
m = tmp.transpose();
|
||||
}
|
||||
|
||||
inline void glGetv(const GLenum pname, Matrix44d & m){
|
||||
Matrix44d tmp;
|
||||
glGetDoublev(pname,tmp.V());
|
||||
m = tmp.transpose();
|
||||
}
|
||||
|
||||
inline void glGetDirectv(const GLenum pname, Matrix44f & m){
|
||||
glGetFloatv(pname,m.V());
|
||||
}
|
||||
|
||||
inline void glGetDirecv(const GLenum pname, Matrix44d & m){
|
||||
glGetDoublev(pname,m.V());
|
||||
}
|
||||
|
||||
|
||||
}//namespace
|
||||
#endif
|
|
@ -57,6 +57,10 @@ Revision 1.1 2004/03/31 15:27:17 ponchio
|
|||
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef VCG_USE_EIGEN
|
||||
#include "deprecated_math.h"
|
||||
#else
|
||||
|
||||
#ifndef VCG_GL_MATH_H
|
||||
#define VCG_GL_MATH_H
|
||||
|
||||
|
@ -70,35 +74,33 @@ Revision 1.1 2004/03/31 15:27:17 ponchio
|
|||
|
||||
namespace vcg {
|
||||
|
||||
inline void glMultMatrixE(const Matrix44f &matrix) {
|
||||
//glMultMatrixf((const GLfloat *)(matrix[0]));
|
||||
if(glMultTransposeMatrixf) glMultTransposeMatrixf((const GLfloat *)(matrix.V()));
|
||||
else {
|
||||
glMultMatrixf((const GLfloat *)(matrix.transpose().eval().V()));
|
||||
}
|
||||
inline void glLoadMatrix(const Eigen::Matrix<float,4,4>& matrix) { glLoadMatrixf(matrix.data()); }
|
||||
inline void glLoadMatrix(const Eigen::Matrix<float,4,4,Eigen::RowMajor>& matrix) {
|
||||
Eigen::Matrix4f tmp(matrix);
|
||||
glLoadMatrixf(tmp.data());
|
||||
}
|
||||
inline void glLoadMatrix(const Eigen::Matrix<double,4,4>& matrix) { glLoadMatrixd(matrix.data()); }
|
||||
inline void glLoadMatrix(const Eigen::Matrix<double,4,4,Eigen::RowMajor>& matrix) {
|
||||
Eigen::Matrix4d tmp(matrix);
|
||||
glLoadMatrixd(tmp.data());
|
||||
}
|
||||
template<typename Scalar>
|
||||
inline void glLoadMatrix(const Eigen::Transform<Scalar,3>& t) { glLoadMatrix(t.matrix()); }
|
||||
|
||||
inline void glMultMatrix(const Matrix44f &matrix) {
|
||||
glMultMatrixf((const GLfloat *)(matrix.transpose().eval().V()));
|
||||
}
|
||||
|
||||
inline void glMultMatrixE(const Matrix44d &matrix) {
|
||||
if(glMultTransposeMatrixd) glMultTransposeMatrixd((const GLdouble *)(matrix.V()));
|
||||
else {
|
||||
glMultMatrixd((const GLdouble *)(matrix.transpose().eval().V()));
|
||||
}
|
||||
inline void glMultMatrix(const Eigen::Matrix<float,4,4>& matrix) { glMultMatrixf(matrix.data()); }
|
||||
inline void glMultMatrix(const Eigen::Matrix<float,4,4,Eigen::RowMajor>& matrix) {
|
||||
Eigen::Matrix<float,4,4> tmp(matrix);
|
||||
glMultMatrixf(tmp.data());
|
||||
}
|
||||
inline void glMultMatrix(const Matrix44d &matrix) {
|
||||
glMultMatrixd((const GLdouble *)(matrix.transpose().eval().V()));
|
||||
inline void glMultMatrix(const Eigen::Matrix<double,4,4>& matrix) { glMultMatrixd(matrix.data()); }
|
||||
inline void glMultMatrix(const Eigen::Matrix<double,4,4,Eigen::RowMajor>& matrix) {
|
||||
Eigen::Matrix<double,4,4> tmp(matrix);
|
||||
glMultMatrixd(tmp.data());
|
||||
}
|
||||
template<typename Scalar>
|
||||
inline void glMultMatrix(const Eigen::Transform<Scalar,3>& t) { glMultMatrix(t.matrix()); }
|
||||
|
||||
inline void glMultMatrixDirect(const Matrix44f &matrix) {
|
||||
glMultMatrixf((const GLfloat *)(matrix.V()));
|
||||
}
|
||||
|
||||
inline void glMultMatrixDirect(const Matrix44d &matrix) {
|
||||
glMultMatrixd((const GLdouble *)(matrix.V()));
|
||||
}
|
||||
|
||||
inline void glMultMatrix(const Similarityf &s) {
|
||||
glTranslatef(s.tra[0], s.tra[1], s.tra[2]);
|
||||
|
@ -107,7 +109,6 @@ inline void glMultMatrix(const Similarityf &s) {
|
|||
Point3f axis;
|
||||
s.rot.ToAxis(alpha, axis);
|
||||
glRotatef(math::ToDeg(alpha), axis[0], axis[1], axis[2]);
|
||||
|
||||
}
|
||||
|
||||
inline void glMultMatrix(const Similarityd &s) {
|
||||
|
@ -119,26 +120,27 @@ inline void glMultMatrix(const Similarityd &s) {
|
|||
glScaled(s.sca, s.sca, s.sca);
|
||||
}
|
||||
|
||||
inline void glGetv(const GLenum pname, Matrix44f & m){
|
||||
Matrix44f tmp;
|
||||
glGetFloatv(pname,tmp.V());
|
||||
m = tmp.transpose();
|
||||
inline void glGetv(const GLenum pname, Eigen::Matrix<float,4,4>& matrix){
|
||||
glGetFloatv(pname,matrix.data());
|
||||
}
|
||||
|
||||
inline void glGetv(const GLenum pname, Matrix44d & m){
|
||||
Matrix44d tmp;
|
||||
glGetDoublev(pname,tmp.V());
|
||||
m = tmp.transpose();
|
||||
inline void glGetv(const GLenum pname, Eigen::Matrix<double,4,4>& matrix){
|
||||
glGetDoublev(pname,matrix.data());
|
||||
}
|
||||
|
||||
inline void glGetDirectv(const GLenum pname, Matrix44f & m){
|
||||
glGetFloatv(pname,m.V());
|
||||
inline void glGetv(const GLenum pname, Eigen::Matrix<float,4,4,Eigen::RowMajor>& matrix){
|
||||
Eigen::Matrix4f tmp;
|
||||
glGetFloatv(pname,tmp.data());
|
||||
matrix = tmp;
|
||||
}
|
||||
|
||||
inline void glGetDirecv(const GLenum pname, Matrix44d & m){
|
||||
glGetDoublev(pname,m.V());
|
||||
inline void glGetv(const GLenum pname, Eigen::Matrix<double,4,4,Eigen::RowMajor>& matrix){
|
||||
Eigen::Matrix4d tmp;
|
||||
glGetDoublev(pname,tmp.data());
|
||||
matrix = tmp;
|
||||
}
|
||||
|
||||
template<typename Scalar>
|
||||
inline void glGetv(const GLenum pname, const Eigen::Transform<Scalar,3>& t)
|
||||
{ glGetv(pname,t.matrix()); }
|
||||
|
||||
}//namespace
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
|
|
@ -177,7 +177,7 @@ void Trackball::DrawPostApply() {
|
|||
}
|
||||
|
||||
void Trackball::Apply () {
|
||||
glTranslate (center);
|
||||
glTranslate (center);track.Matrix().print();
|
||||
glMultMatrix (track.Matrix());
|
||||
glTranslate (-center);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue