point4.h
Go to the documentation of this file.
00001 /****************************************************************************
00002 * VCGLib                                                            o o     *
00003 * Visual and Computer Graphics Library                            o     o   *
00004 *                                                                _   O  _   *
00005 * Copyright(C) 2004                                                \/)\/    *
00006 * Visual Computing Lab                                            /\/|      *
00007 * ISTI - Italian National Research Council                           |      *
00008 *                                                                    \      *
00009 * All rights reserved.                                                      *
00010 *                                                                           *
00011 * This program is free software; you can redistribute it and/or modify      *
00012 * it under the terms of the GNU General Public License as published by      *
00013 * the Free Software Foundation; either version 2 of the License, or         *
00014 * (at your option) any later version.                                       *
00015 *                                                                           *
00016 * This program is distributed in the hope that it will be useful,           *
00017 * but WITHOUT ANY WARRANTY; without even the implied warranty of            *
00018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             *
00019 * GNU General Public License (http://www.gnu.org/licenses/gpl.txt)          *
00020 * for more details.                                                         *
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 // template typedef part
00057 // use it as follow: typename Point4<S>::Type instead of simply Point4<S>
00058 //----------------------------------------
00059 public:
00060         typedef Eigen::Matrix<T,4,1> Type;
00061 //----------------------------------------
00062 // inheritence part
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) { std::swap(k0,k1); std::swap(exp0,exp1); }
00121                 if (exp2>exp3) { std::swap(k2,k3); std::swap(exp2,exp3); }
00122                 if (exp0>exp2) { std::swap(k0,k2); std::swap(exp0,exp2); }
00123                 if (exp1>exp3) { std::swap(k1,k3); std::swap(exp1,exp3); }
00124                 if (exp2>exp3) { std::swap(k2,k3); std::swap(exp2,exp3); }
00125 
00126                 return ( (k0 + k1) + k2 ) +k3;
00127         }
00129 
00130 
00131 }; // end class definition
00132 
00133 
00134 typedef Point4<short>  Point4s;
00135 typedef Point4<int>        Point4i;
00136 typedef Point4<float>  Point4f;
00137 typedef Point4<double> Point4d;
00138 
00139 // typedef Eigen::Matrix<short ,4,1> Point4s;
00140 // typedef Eigen::Matrix<int   ,4,1> Point4i;
00141 // typedef Eigen::Matrix<float ,4,1> Point4f;
00142 // typedef Eigen::Matrix<double,4,1> Point4d;
00143 // typedef Eigen::Matrix<short ,4,1> Vector4s;
00144 // typedef Eigen::Matrix<int   ,4,1> Vector4i;
00145 // typedef Eigen::Matrix<float ,4,1> Vector4f;
00146 // typedef Eigen::Matrix<double,4,1> Vector4d;
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 } // end namespace
00157 #endif
00158 
00159 #endif


shape_reconstruction
Author(s): Roberto Martín-Martín
autogenerated on Sat Jun 8 2019 18:34:12