00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef VCG_USE_EIGEN
00025 #include "deprecated_point4.h"
00026 #else
00027
00028 #ifndef __VCGLIB_POINT4
00029 #define __VCGLIB_POINT4
00030
00031 #include "../math/eigen.h"
00032
00033 namespace vcg{
00034 template<typename Scalar> class Point4;
00035 }
00036
00037 namespace Eigen {
00038 template<typename Scalar> struct ei_traits<vcg::Point4<Scalar> > : ei_traits<Eigen::Matrix<Scalar,4,1> > {};
00039 template<typename XprType> struct ei_to_vcgtype<XprType,4,1,0,4,1>
00040 { typedef vcg::Point4<typename XprType::Scalar> type; };
00041 }
00042
00043 namespace vcg {
00044
00045
00053 template <class T> class Point4 : public Eigen::Matrix<T,4,1>
00054 {
00055
00056
00057
00058
00059 public:
00060 typedef Eigen::Matrix<T,4,1> Type;
00061
00062
00063
00064 private:
00065 typedef Eigen::Matrix<T,4,1> _Base;
00066 public:
00067 using _Base::coeff;
00068 using _Base::coeffRef;
00069 using _Base::setZero;
00070 using _Base::data;
00071
00072 _EIGEN_GENERIC_PUBLIC_INTERFACE(Point4,_Base);
00073 typedef Scalar ScalarType;
00074
00075 VCG_EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Point4)
00076
00077 inline Point4() : Base() {}
00078 inline Point4( const T nx, const T ny, const T nz , const T nw ) : Base(nx,ny,nz,nw) {}
00079 inline Point4(const T p[4]) : Base(p) {}
00080 inline Point4(const Point4& p) : Base(p) {}
00081 template<typename OtherDerived>
00082 inline Point4(const Eigen::MatrixBase<OtherDerived>& other) : Base(other) {}
00083
00084
00085 inline Point4 VectProd ( const Point4 &x, const Point4 &z ) const
00086 {
00087 Point4 res;
00088 const Point4 &y = *this;
00089
00090 res[0] = y[1]*x[2]*z[3]-y[1]*x[3]*z[2]-x[1]*y[2]*z[3]+
00091 x[1]*y[3]*z[2]+z[1]*y[2]*x[3]-z[1]*y[3]*x[2];
00092 res[1] = y[0]*x[3]*z[2]-z[0]*y[2]*x[3]-y[0]*x[2]*
00093 z[3]+z[0]*y[3]*x[2]+x[0]*y[2]*z[3]-x[0]*y[3]*z[2];
00094 res[2] = -y[0]*z[1]*x[3]+x[0]*z[1]*y[3]+y[0]*x[1]*
00095 z[3]-x[0]*y[1]*z[3]-z[0]*x[1]*y[3]+z[0]*y[1]*x[3];
00096 res[3] = -z[0]*y[1]*x[2]-y[0]*x[1]*z[2]+x[0]*y[1]*
00097 z[2]+y[0]*z[1]*x[2]-x[0]*z[1]*y[2]+z[0]*x[1]*y[2];
00098 return res;
00099 }
00100
00102
00105 inline Point4 operator ^ ( const Point4& p ) const
00106 {
00107 assert(0 && "not defined by two vectors (only put for metaprogramming)");
00108 return Point4();
00109 }
00110
00112 T StableDot ( const Point4<T> & p ) const
00113 {
00114 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];
00115 int exp0,exp1,exp2,exp3;
00116
00117 frexp( double(k0), &exp0 );frexp( double(k1), &exp1 );
00118 frexp( double(k2), &exp2 );frexp( double(k3), &exp3 );
00119
00120 if (exp0>exp1) { math::Swap(k0,k1); math::Swap(exp0,exp1); }
00121 if (exp2>exp3) { math::Swap(k2,k3); math::Swap(exp2,exp3); }
00122 if (exp0>exp2) { math::Swap(k0,k2); math::Swap(exp0,exp2); }
00123 if (exp1>exp3) { math::Swap(k1,k3); math::Swap(exp1,exp3); }
00124 if (exp2>exp3) { math::Swap(k2,k3); math::Swap(exp2,exp3); }
00125
00126 return ( (k0 + k1) + k2 ) +k3;
00127 }
00129
00130
00131 };
00132
00133
00134 typedef Point4<short> Point4s;
00135 typedef Point4<int> Point4i;
00136 typedef Point4<float> Point4f;
00137 typedef Point4<double> Point4d;
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00149 template<class T>
00150 double StableDot ( Point4<T> const & p0, Point4<T> const & p1 )
00151 {
00152 return p0.StableDot(p1);
00153 }
00154
00156 }
00157 #endif
00158
00159 #endif