From 92d6da43d532b85dfb73f392224550923cf84cbc Mon Sep 17 00:00:00 2001 From: cignoni Date: Tue, 4 Mar 2014 00:35:44 +0000 Subject: [PATCH] Added the possibility for the plain midpoint class to allow also the correct interpolation of userdefined data by providing, in the constructor, an interpolator functor that will be called for each new vertex to be created. --- vcg/complex/algorithms/refine.h | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/vcg/complex/algorithms/refine.h b/vcg/complex/algorithms/refine.h index 60df3004..ef41a29e 100644 --- a/vcg/complex/algorithms/refine.h +++ b/vcg/complex/algorithms/refine.h @@ -107,18 +107,38 @@ const Split SplitTab[8]={ /* 1 1 1 */ {4, {{3,4,5},{0,3,5},{3,1,4},{5,4,2}}, {{0,0},{0,0}}, {{3,3,3},{0,3,2},{0,1,3},{3,1,2}} }, }; + +template +struct BaseInterpolator +{ + typedef typename face::Pos PosType; + typedef typename MeshType::VertexType VertexType; + void operator()(VertexType &, PosType ){} +}; + // Basic subdivision class // This class must provide methods for finding the position of the newly created vertices // In this implemenation we simply put the new vertex in the MidPoint position. // Color and TexCoords are interpolated accordingly. -template +// This subdivision class allow also the correct interpolation of userdefined data by +// providing, in the constructor, an interpolator functor that will be called for each new vertex to be created. + +template > struct MidPoint : public std::unary_function , typename MESH_TYPE::CoordType > { - MidPoint(MESH_TYPE *_mp) { mp=_mp; } + typedef typename face::Pos PosType; + typedef typename MESH_TYPE::VertexType VertexType; + + MidPoint(MESH_TYPE *_mp, + InterpolatorFunctorType *_intFunc=0) { + mp=_mp; + intFunc =_intFunc; + } MESH_TYPE *mp; + InterpolatorFunctorType *intFunc; /// This callback is called to fill up - void operator()(typename MESH_TYPE::VertexType &nv, face::Pos ep){ + void operator()(VertexType &nv, PosType ep){ assert(mp); nv.P()= (ep.f->V(ep.z)->P()+ep.f->V1(ep.z)->P())/2.0; @@ -133,6 +153,8 @@ struct MidPoint : public std::unary_functionV(ep.z)->T().P()+ep.f->V1(ep.z)->T().P())) / 2.0; + if(intFunc) + (*intFunc)(nv,ep); } Color4 WedgeInterp(Color4 &c0, Color4 &c1)