From 77a846fe90fa28ae79704c0e42ed1e46e8dbab00 Mon Sep 17 00:00:00 2001
From: cignoni <paolo.cignoni@isti.cnr.it>
Date: Fri, 30 Apr 2010 09:42:10 +0000
Subject: [PATCH] added a wrapper to the robust InterpolationParameters that
 uses a normal to choose the interpolation orientation

---
 vcg/space/triangle3.h | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/vcg/space/triangle3.h b/vcg/space/triangle3.h
index d8e14504..07f88d2b 100644
--- a/vcg/space/triangle3.h
+++ b/vcg/space/triangle3.h
@@ -184,6 +184,26 @@ bool InterpolationParameters(const TriangleType t, const int Axis, const Point3<
 	if(Axis==2) return InterpolationParameters2( P2(t.P(0)[0],t.P(0)[1]), P2(t.P(1)[0],t.P(1)[1]), P2(t.P(2)[0],t.P(2)[1]), P2(P[0],P[1]), L);
 	return false; 
 }
+/// Handy Wrapper of the above one that uses the passed normal N to choose the right orientation
+template<class TriangleType, class ScalarType>
+bool InterpolationParameters(const TriangleType t, const Point3<ScalarType> & N, const Point3<ScalarType> & P,  Point3<ScalarType> & L)
+{
+	if(N[0]>N[1])
+	{
+		if(N[0]>N[2])
+			return InterpolationParameters(t,0,P,L); /* 0 > 1 ? 2 */
+		else 
+			return InterpolationParameters(t,2,P,L); /* 2 > 1 ? 2 */
+		}
+	else 
+	{
+		if(N[1]>N[2])
+			return InterpolationParameters(t,1,P,L); /* 1 > 0 ? 2 */
+		else 
+			return InterpolationParameters(t,2,P,L); /* 2 > 1 ? 2 */
+	}
+}
+		
 
 
 // Function that computes the barycentric coords of a 2D triangle. Used by the above function.