From 7b85798562f00abef44a457a10aa689a5e8f5581 Mon Sep 17 00:00:00 2001 From: cignoni Date: Tue, 29 May 2007 14:01:24 +0000 Subject: [PATCH] added bestmachting normal --- vcg/math/gen_normal.h | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/vcg/math/gen_normal.h b/vcg/math/gen_normal.h index caa08d58..7fb7bddf 100644 --- a/vcg/math/gen_normal.h +++ b/vcg/math/gen_normal.h @@ -110,6 +110,29 @@ static void Perturb(std::vector > &NN) } +/* +Trova la normale piu vicina a quella data. +Assume che tutte normale in ingresso sia normalizzata; +*/ +static int BestMatchingNormal(const Point3x &n, std::vector &nv) +{ + int ret=-1; + ScalarType bestang=-1; + ScalarType cosang; + typename std::vector::iterator ni; + for(ni=nv.begin();ni!=nv.end();++ni) + { + cosang=(*ni)*n; + if(cosang>bestang) { + bestang=cosang; + ret=ni-nv.begin(); + } + } + assert(ret>=0 && ret =0 && i=0 && j