2004-02-10 02:11:28 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* VCGLib o o *
|
|
|
|
* Visual and Computer Graphics Library o o *
|
|
|
|
* _ O _ *
|
2016-06-13 07:29:25 +02:00
|
|
|
* Copyright(C) 2004-2016 \/)\/ *
|
2004-02-10 02:11:28 +01:00
|
|
|
* Visual Computing Lab /\/| *
|
|
|
|
* ISTI - Italian National Research Council | *
|
|
|
|
* \ *
|
|
|
|
* All rights reserved. *
|
|
|
|
* *
|
2008-10-29 01:05:44 +01:00
|
|
|
* This program is free software; you can redistribute it and/or modify *
|
2004-02-10 02:11:28 +01:00
|
|
|
* 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. *
|
|
|
|
* *
|
|
|
|
****************************************************************************/
|
2005-01-12 12:25:02 +01:00
|
|
|
|
2008-10-27 20:35:17 +01:00
|
|
|
#ifndef VCG_USE_EIGEN
|
|
|
|
#include "deprecated_point4.h"
|
|
|
|
#else
|
2004-02-10 02:11:28 +01:00
|
|
|
|
|
|
|
#ifndef __VCGLIB_POINT4
|
|
|
|
#define __VCGLIB_POINT4
|
|
|
|
|
2008-10-27 20:35:17 +01:00
|
|
|
#include "../math/eigen.h"
|
|
|
|
|
|
|
|
namespace vcg{
|
2008-10-28 21:06:17 +01:00
|
|
|
template<typename Scalar> class Point4;
|
2008-10-27 20:35:17 +01:00
|
|
|
}
|
|
|
|
|
2008-10-28 21:06:17 +01:00
|
|
|
namespace Eigen {
|
|
|
|
template<typename Scalar> struct ei_traits<vcg::Point4<Scalar> > : ei_traits<Eigen::Matrix<Scalar,4,1> > {};
|
2008-10-29 01:05:44 +01:00
|
|
|
template<typename XprType> struct ei_to_vcgtype<XprType,4,1,0,4,1>
|
|
|
|
{ typedef vcg::Point4<typename XprType::Scalar> type; };
|
2008-10-27 20:35:17 +01:00
|
|
|
}
|
2005-04-13 11:40:30 +02:00
|
|
|
|
2004-02-10 02:11:28 +01:00
|
|
|
namespace vcg {
|
2008-10-28 21:06:17 +01:00
|
|
|
|
|
|
|
|
2004-03-10 22:38:40 +01:00
|
|
|
/** \addtogroup space */
|
|
|
|
/*@{*/
|
2008-10-28 21:06:17 +01:00
|
|
|
/**
|
|
|
|
The templated class for representing a point in 4D space.
|
|
|
|
The class is templated over the ScalarType class that is used to represent coordinates.
|
|
|
|
All the usual operator (* + - ...) are defined.
|
|
|
|
*/
|
2008-10-27 20:35:17 +01:00
|
|
|
template <class T> class Point4 : public Eigen::Matrix<T,4,1>
|
2004-02-10 02:11:28 +01:00
|
|
|
{
|
2008-10-28 21:06:17 +01:00
|
|
|
//----------------------------------------
|
|
|
|
// 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:
|
2008-10-27 20:35:17 +01:00
|
|
|
typedef Eigen::Matrix<T,4,1> _Base;
|
2008-10-29 12:28:51 +01:00
|
|
|
public:
|
2008-10-27 20:35:17 +01:00
|
|
|
using _Base::coeff;
|
|
|
|
using _Base::coeffRef;
|
|
|
|
using _Base::setZero;
|
|
|
|
using _Base::data;
|
2004-03-11 18:17:49 +01:00
|
|
|
|
2008-10-27 20:35:17 +01:00
|
|
|
_EIGEN_GENERIC_PUBLIC_INTERFACE(Point4,_Base);
|
|
|
|
typedef Scalar ScalarType;
|
2004-02-10 02:11:28 +01:00
|
|
|
|
2008-10-27 20:35:17 +01:00
|
|
|
VCG_EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Point4)
|
|
|
|
|
|
|
|
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) {}
|
|
|
|
inline Point4(const Point4& p) : Base(p) {}
|
|
|
|
template<typename OtherDerived>
|
|
|
|
inline Point4(const Eigen::MatrixBase<OtherDerived>& other) : Base(other) {}
|
2004-02-10 02:11:28 +01:00
|
|
|
|
2004-03-11 18:17:49 +01:00
|
|
|
|
2005-01-21 19:02:11 +01:00
|
|
|
inline Point4 VectProd ( const Point4 &x, const Point4 &z ) const
|
2008-10-28 21:06:17 +01:00
|
|
|
{
|
2005-01-12 12:25:02 +01:00
|
|
|
Point4 res;
|
2005-01-21 19:02:11 +01:00
|
|
|
const Point4 &y = *this;
|
|
|
|
|
2008-10-27 20:35:17 +01:00
|
|
|
res[0] = y[1]*x[2]*z[3]-y[1]*x[3]*z[2]-x[1]*y[2]*z[3]+
|
2013-07-26 09:01:21 +02:00
|
|
|
x[1]*y[3]*z[2]+z[1]*y[2]*x[3]-z[1]*y[3]*x[2];
|
2008-10-27 20:35:17 +01:00
|
|
|
res[1] = y[0]*x[3]*z[2]-z[0]*y[2]*x[3]-y[0]*x[2]*
|
2013-07-26 09:01:21 +02:00
|
|
|
z[3]+z[0]*y[3]*x[2]+x[0]*y[2]*z[3]-x[0]*y[3]*z[2];
|
2005-01-21 19:02:11 +01:00
|
|
|
res[2] = -y[0]*z[1]*x[3]+x[0]*z[1]*y[3]+y[0]*x[1]*
|
2013-07-26 09:01:21 +02:00
|
|
|
z[3]-x[0]*y[1]*z[3]-z[0]*x[1]*y[3]+z[0]*y[1]*x[3];
|
2005-01-21 19:02:11 +01:00
|
|
|
res[3] = -z[0]*y[1]*x[2]-y[0]*x[1]*z[2]+x[0]*y[1]*
|
2013-07-26 09:01:21 +02:00
|
|
|
z[2]+y[0]*z[1]*x[2]-x[0]*z[1]*y[2]+z[0]*x[1]*y[2];
|
2005-01-21 19:02:11 +01:00
|
|
|
return res;
|
2004-10-11 19:46:11 +02:00
|
|
|
}
|
2008-10-28 21:06:17 +01:00
|
|
|
|
2004-03-11 18:17:49 +01:00
|
|
|
//@{
|
|
|
|
/** @name Dot products
|
|
|
|
**/
|
2004-02-10 02:11:28 +01:00
|
|
|
|
2005-01-12 12:25:02 +01:00
|
|
|
inline Point4 operator ^ ( const Point4& p ) const
|
|
|
|
{
|
2008-10-27 20:35:17 +01:00
|
|
|
assert(0 && "not defined by two vectors (only put for metaprogramming)");
|
2005-01-12 12:25:02 +01:00
|
|
|
return Point4();
|
|
|
|
}
|
|
|
|
|
2004-03-11 18:17:49 +01:00
|
|
|
/// slower version, more stable (double precision only)
|
|
|
|
T StableDot ( const Point4<T> & p ) const
|
2004-02-10 02:11:28 +01:00
|
|
|
{
|
2008-10-27 20:35:17 +01:00
|
|
|
T k0=data()[0]*p.data()[0], k1=data()[1]*p.data()[1], k2=data()[2]*p.data()[2], k3=data()[3]*p.data()[3];
|
2004-03-11 18:17:49 +01:00
|
|
|
int exp0,exp1,exp2,exp3;
|
|
|
|
|
|
|
|
frexp( double(k0), &exp0 );frexp( double(k1), &exp1 );
|
|
|
|
frexp( double(k2), &exp2 );frexp( double(k3), &exp3 );
|
|
|
|
|
2013-07-26 09:01:21 +02:00
|
|
|
if (exp0>exp1) { std::swap(k0,k1); std::swap(exp0,exp1); }
|
|
|
|
if (exp2>exp3) { std::swap(k2,k3); std::swap(exp2,exp3); }
|
|
|
|
if (exp0>exp2) { std::swap(k0,k2); std::swap(exp0,exp2); }
|
|
|
|
if (exp1>exp3) { std::swap(k1,k3); std::swap(exp1,exp3); }
|
|
|
|
if (exp2>exp3) { std::swap(k2,k3); std::swap(exp2,exp3); }
|
2004-03-11 18:17:49 +01:00
|
|
|
|
|
|
|
return ( (k0 + k1) + k2 ) +k3;
|
2008-10-28 21:06:17 +01:00
|
|
|
}
|
2004-03-11 18:17:49 +01:00
|
|
|
//@}
|
2004-02-10 02:11:28 +01:00
|
|
|
|
|
|
|
|
|
|
|
}; // end class definition
|
|
|
|
|
|
|
|
|
2008-10-28 21:06:17 +01:00
|
|
|
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)
|
2004-03-11 18:17:49 +01:00
|
|
|
template<class T>
|
|
|
|
double StableDot ( Point4<T> const & p0, Point4<T> const & p1 )
|
|
|
|
{
|
|
|
|
return p0.StableDot(p1);
|
2008-10-28 21:06:17 +01:00
|
|
|
}
|
2004-02-10 02:11:28 +01:00
|
|
|
|
2004-03-10 22:38:40 +01:00
|
|
|
/*@}*/
|
2004-02-10 02:11:28 +01:00
|
|
|
} // end namespace
|
|
|
|
#endif
|
2008-10-27 20:35:17 +01:00
|
|
|
|
|
|
|
#endif
|