/**************************************************************************** * 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. * * * ****************************************************************************/ #ifndef VCG_USE_EIGEN #include "deprecated_point3.h" #else #ifndef __VCGLIB_POINT3 #define __VCGLIB_POINT3 #include "../math/eigen.h" namespace vcg{ template class Point3; } namespace Eigen{ template struct ei_traits > : ei_traits > {}; template struct NumTraits > : NumTraits { enum { ReadCost = 3, AddCost = 3, MulCost = 3 }; }; } namespace vcg { template class Box3; /** \addtogroup space */ /*@{*/ /** The templated class for representing a point in 3D space. The class is templated over the ScalarType class that is used to represent coordinates. All the usual operator overloading (* + - ...) is present. */ template class Point3 : public Eigen::Matrix<_Scalar,3,1> { //---------------------------------------- // template typedef part // use it as follow: typename Point3::Type instead of simply Point3 //---------------------------------------- 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); VCG_EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Point3) /** @name Standard Constructors and Initializers No casting operators have been introduced to avoid automatic unattended (and costly) conversion between different point types **/ inline Point3 () {} inline Point3 ( const Scalar nx, const Scalar ny, const Scalar nz ) : Base(nx,ny,nz) {} inline Point3 ( Point3 const & p ) : Base(p) {} inline Point3 ( const Scalar nv[3] ) : Base(nv) {} template inline Point3(const Eigen::MatrixBase& other) : Base(other) {} // this one is very useless template 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; }; // end class definition (Point3) // Dot product preciso numericamente (solo double!!) // Implementazione: si sommano i prodotti per ordine di esponente // (prima le piu' grandi) template double stable_dot ( Point3 const & p0, Point3 const & p1 ) { Scalar k0 = p0.data()[0]*p1.data()[0]; Scalar k1 = p0.data()[1]*p1.data()[1]; Scalar k2 = p0.data()[2]*p1.data()[2]; int exp0,exp1,exp2; frexp( double(k0), &exp0 ); frexp( double(k1), &exp1 ); frexp( double(k2), &exp2 ); if( exp0 Scalar PSDist( const Point3 & p, const Point3 & v1, const Point3 & v2, Point3 & q ) { Point3 e = v2-v1; Scalar t = ((p-v1).dot(e))/e.SquaredNorm(); if(t<0) t = 0; else if(t>1) t = 1; q = v1+e*t; return Distance(p,q); } template void GetUV( Point3 &n,Point3 &u, Point3 &v, Point3 up=(Point3(0,1,0)) ) { n.Normalize(); const double LocEps=double(1e-7); u=n^up; double len = u.Norm(); if(len < LocEps) { if(fabs(n[0])(1,0,0); // x is the min else up=Point3(0,0,1); // z is the min }else { if(fabs(n[1])(0,1,0); // y is the min else up=Point3(0,0,1); // z is the min } u=n^up; } u.Normalize(); v=n^u; v.Normalize(); Point3 uv=u^v; } /*@}*/ typedef Point3 Point3s; typedef Point3 Point3i; typedef Point3 Point3f; typedef Point3 Point3d; // typedef Eigen::Matrix Point3s; // typedef Eigen::Matrix Point3i; // typedef Eigen::Matrix Point3f; // typedef Eigen::Matrix Point3d; // typedef Eigen::Matrix Vector3s; // typedef Eigen::Matrix Vector3i; // typedef Eigen::Matrix Vector3f; // typedef Eigen::Matrix Vector3d; } // end namespace #endif #endif