00001 /**************************************************************************** 00002 * MeshLab o o * 00003 * A versatile mesh processing toolbox o o * 00004 * _ O _ * 00005 * Copyright(C) 2005 \/)\/ * 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 VCGADDONS_H 00025 #define VCGADDONS_H 00026 00027 00028 namespace vcg { 00029 00030 template <typename Scalar> 00031 inline Scalar MaxCoeff(Point3<Scalar> const & p) 00032 { 00033 return std::max(std::max(p.X(), p.Y()), p.Z()); 00034 } 00035 00036 //template <typename Scalar> 00037 //inline Scalar MinCoeff(Point3<Scalar> const & p) 00038 //{ 00039 // return std::min(std::min(p.X(), p.Y()), p.Z()); 00040 //} 00041 00042 template <typename Scalar> 00043 inline Scalar Dot(Point3<Scalar> const & p1, Point3<Scalar> const & p2) 00044 { 00045 return p1.X() * p2.X() + p1.Y() * p2.Y() + p1.Z() * p2.Z(); 00046 } 00047 00048 //template <typename Scalar> 00049 //inline Point3<Scalar> Cross(Point3<Scalar> const & p1, Point3<Scalar> const & p2) 00050 //{ 00051 // return p1 ^ p2; 00052 //} 00053 00054 //template <typename Scalar> 00055 //inline Point3<Scalar> CwiseAdd(Point3<Scalar> const & p1, Scalar s) 00056 //{ 00057 // return Point3<Scalar>(p1.X() + s, p1.Y() + s, p1.Z() + s); 00058 //} 00059 00060 template <typename Scalar> 00061 inline int MaxCoeffId(Point3<Scalar> const & p) 00062 { 00063 if (p.X()>p.Y()) 00064 return p.X()>p.Z() ? 0 : 2; 00065 else 00066 return p.Y()>p.Z() ? 1 : 2; 00067 } 00068 00069 //template <typename Scalar> 00070 //inline int MinCoeffId(Point3<Scalar> const & p) 00071 //{ 00072 // if (p.X()<p.Y()) 00073 // return p.X()<p.Z() ? 0 : 2; 00074 // else 00075 // return p.Y()<p.Z() ? 1 : 2; 00076 //} 00077 00078 //template <typename ToType, typename Scalar> 00079 //inline Point3<ToType> Point3Cast(const Point3<Scalar>& p) 00080 //{ 00081 // return Point3<ToType>(p.X(), p.Y(), p.Z()); 00082 //} 00083 00084 //template<class Scalar> 00085 //Scalar Distance(const Point3<Scalar> &p, const Box3<Scalar> &bbox) 00086 //{ 00087 // Scalar dist2 = 0.; 00088 // Scalar aux; 00089 // for (int k=0 ; k<3 ; ++k) 00090 // { 00091 // if ( (aux = (p[k]-bbox.min[k]))<0. ) 00092 // dist2 += aux*aux; 00093 // else if ( (aux = (bbox.max[k]-p[k]))<0. ) 00094 // dist2 += aux*aux; 00095 // } 00096 // return sqrt(dist2); 00097 //} 00098 00099 } 00100 00101 #endif