1 /****************************************************************************
2 * VCGLib                                                            o o     *
3 * Visual and Computer Graphics Library                            o     o   *
4 *                                                                _   O  _   *
5 * Copyright(C) 2004-2016                                           \/)\/    *
6 * Visual Computing Lab                                            /\/|      *
7 * ISTI - Italian National Research Council                           |      *
8 *                                                                    \      *
9 * All rights reserved.                                                      *
10 *                                                                           *
11 * This program is free software; you can redistribute it and/or modify      *
12 * it under the terms of the GNU General Public License as published by      *
13 * the Free Software Foundation; either version 2 of the License, or         *
14 * (at your option) any later version.                                       *
15 *                                                                           *
16 * This program is distributed in the hope that it will be useful,           *
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of            *
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             *
19 * GNU General Public License (http://www.gnu.org/licenses/gpl.txt)          *
20 * for more details.                                                         *
21 *                                                                           *
22 ****************************************************************************/
23 
24 #ifndef VCGADDONS_H
25 #define VCGADDONS_H
26 
27 
28 namespace vcg {
29 
30 template <typename Scalar>
MaxCoeff(Point3<Scalar> const & p)31 inline Scalar MaxCoeff(Point3<Scalar> const & p)
32 {
33 	return std::max(std::max(p.X(), p.Y()), p.Z());
34 }
35 
36 //template <typename Scalar>
37 //inline Scalar MinCoeff(Point3<Scalar> const & p)
38 //{
39 //	return std::min(std::min(p.X(), p.Y()), p.Z());
40 //}
41 
42 template <typename Scalar>
Dot(Point3<Scalar> const & p1,Point3<Scalar> const & p2)43 inline Scalar Dot(Point3<Scalar> const & p1, Point3<Scalar> const & p2)
44 {
45 	return p1.X() * p2.X() + p1.Y() * p2.Y() + p1.Z() * p2.Z();
46 }
47 
48 //template <typename Scalar>
49 //inline Point3<Scalar> Cross(Point3<Scalar> const & p1, Point3<Scalar> const & p2)
50 //{
51 //	return p1 ^ p2;
52 //}
53 
54 //template <typename Scalar>
55 //inline Point3<Scalar> CwiseAdd(Point3<Scalar> const & p1, Scalar s)
56 //{
57 //	return Point3<Scalar>(p1.X() + s, p1.Y() + s, p1.Z() + s);
58 //}
59 
60 template <typename Scalar>
MaxCoeffId(Point3<Scalar> const & p)61 inline int MaxCoeffId(Point3<Scalar> const & p)
62 {
63 	if (p.X()>p.Y())
64 		return p.X()>p.Z() ? 0 : 2;
65 	else
66 		return p.Y()>p.Z() ? 1 : 2;
67 }
68 
69 //template <typename Scalar>
70 //inline int MinCoeffId(Point3<Scalar> const & p)
71 //{
72 //	if (p.X()<p.Y())
73 //		return p.X()<p.Z() ? 0 : 2;
74 //	else
75 //		return p.Y()<p.Z() ? 1 : 2;
76 //}
77 
78 //template <typename ToType, typename Scalar>
79 //inline Point3<ToType> Point3Cast(const Point3<Scalar>& p)
80 //{
81 //	return Point3<ToType>(p.X(), p.Y(), p.Z());
82 //}
83 
84 //template<class Scalar>
85 //Scalar Distance(const Point3<Scalar> &p, const Box3<Scalar> &bbox)
86 //{
87 //	Scalar dist2 = 0.;
88 //	Scalar aux;
89 //	for (int k=0 ; k<3 ; ++k)
90 //	{
91 //		if ( (aux = (p[k]-bbox.min[k]))<0. )
92 //			dist2 += aux*aux;
93 //		else if ( (aux = (bbox.max[k]-p[k]))<0. )
94 //			dist2 += aux*aux;
95 //	}
96 //	return sqrt(dist2);
97 //}
98 
99 }
100 
101 #endif
102