From b2e2bfe2df2b391a5760ddd65a55009f76721069 Mon Sep 17 00:00:00 2001 From: cignoni Date: Wed, 4 Jul 2012 15:23:59 +0000 Subject: [PATCH] added Cotangent weighting to the basic laplacian smoothing. --- vcg/complex/algorithms/smooth.h | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/vcg/complex/algorithms/smooth.h b/vcg/complex/algorithms/smooth.h index 646ff166..b3515c7d 100644 --- a/vcg/complex/algorithms/smooth.h +++ b/vcg/complex/algorithms/smooth.h @@ -208,8 +208,9 @@ public: // // This function simply accumulate over a TempData all the positions of the ajacent vertices // -static void AccumulateLaplacianInfo(MeshType &m, SimpleTempData &TD) +static void AccumulateLaplacianInfo(MeshType &m, SimpleTempData &TD, bool cotangentFlag=false) { + float weight =1.0f; FaceIterator fi; for(fi=m.face.begin();fi!=m.face.end();++fi) { @@ -217,10 +218,15 @@ static void AccumulateLaplacianInfo(MeshType &m, SimpleTempDataP(); - TD[(*fi).V1(j)].sum+=(*fi).V(j)->P(); - ++TD[(*fi).V(j)].cnt; - ++TD[(*fi).V1(j)].cnt; + if(cotangentFlag) { + float angle = Angle(fi->P1(j)-fi->P2(j),fi->P0(j)-fi->P2(j)); + weight = tan(M_PI_2 - angle); + } + + TD[(*fi).V0(j)].sum+=(*fi).P1(j)*weight; + TD[(*fi).V1(j)].sum+=(*fi).P0(j)*weight; + TD[(*fi).V0(j)].cnt+=weight; + TD[(*fi).V1(j)].cnt+=weight; } } // si azzaera i dati per i vertici di bordo @@ -252,7 +258,7 @@ static void AccumulateLaplacianInfo(MeshType &m, SimpleTempData0 ) {