From 993a9a2c5bd6907790f58ad3853d6481bf17ad48 Mon Sep 17 00:00:00 2001 From: cignoni Date: Thu, 28 Nov 2013 23:29:06 +0000 Subject: [PATCH] Tricky Change to the refine interface. Now the edge and midpoint predicate are passed as reference so if you need you can make predicate with state. This is useful when the edge and midpoint predicate share a lot of common information and you want exploit the computation done in the edge predicate (e.g. sometimes when you decide if an edge has to be split you already know where the vertex should be placed). --- vcg/complex/algorithms/refine.h | 1120 +++++++++++++++---------------- 1 file changed, 560 insertions(+), 560 deletions(-) diff --git a/vcg/complex/algorithms/refine.h b/vcg/complex/algorithms/refine.h index 7943591a..0138b7c6 100644 --- a/vcg/complex/algorithms/refine.h +++ b/vcg/complex/algorithms/refine.h @@ -8,7 +8,7 @@ * \ * * All rights reserved. * * * -* This program is free software; you can redistribute it and/or modify * +* This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * @@ -37,44 +37,44 @@ namespace vcg{ namespace tri{ - + /* A very short intro about the generic refinement framework, - the main fuction is the - + the main fuction is the + template bool RefineE(MESH_TYPE &m, MIDPOINT mid, EDGEPRED ep,bool RefineSelected=false, CallBackPos *cb = 0) - + You have to provide two functor objects to this, one for deciding what edge has to be spltted and one to decide position and new values for the attributes of the new point. - + for example the minimal EDGEPRED is - + template class EdgeLen { - public: - FLT thr2; - bool operator()(face::Pos ep) const - { - return SquaredDistance(ep.f->V(ep.z)->P(), ep.f->V1(ep.z)->P())>thr2; - } + public: + FLT thr2; + bool operator()(face::Pos ep) const + { + return SquaredDistance(ep.f->V(ep.z)->P(), ep.f->V1(ep.z)->P())>thr2; + } }; - - With a bit of patience you can customize to make also slicing operation. - -*/ - -/* The table which encodes how to subdivide a triangle depending + With a bit of patience you can customize to make also slicing operation. + +*/ + + +/* The table which encodes how to subdivide a triangle depending on the splitted edges is organized as such: TriNum (the first number): encodes the number of triangles TV (the following 4 triples): encodes the resulting triangles where - 0, 1, 2 are the original vertices of the triangles and 3, 4, 5 + 0, 1, 2 are the original vertices of the triangles and 3, 4, 5 (mp01, mp12, mp20) are the midpoints of the three edges. In the case two edges are splitted the triangle has 2 possible splittings: we need to choose a diagonal of the resulting trapezoid. 'swap' encodes the two diagonals to test: if diag1 < diag2 we swap the diagonal -like this (140, 504 -> 150, 514) (the second vertex of each triangles is replaced +like this (140, 504 -> 150, 514) (the second vertex of each triangles is replaced by the first vertex of the other one). 2 / \ @@ -86,13 +86,13 @@ like this (140, 504 -> 150, 514) (the second vertex of each triangles is replace class Split { public: - int TriNum; // number of triangles - int TV[4][3]; // The triangles coded as the following convention - // 0..2 vertici originali del triangolo - // 3..5 mp01, mp12, mp20 midpoints of the three edges - int swap[2][2]; // the two diagonals to test for swapping - int TE[4][3]; // the edge-edge correspondence between refined triangles and the old one - // (3) means the edge of the new triangle is internal; + int TriNum; // number of triangles + int TV[4][3]; // The triangles coded as the following convention + // 0..2 vertici originali del triangolo + // 3..5 mp01, mp12, mp20 midpoints of the three edges + int swap[2][2]; // the two diagonals to test for swapping + int TE[4][3]; // the edge-edge correspondence between refined triangles and the old one + // (3) means the edge of the new triangle is internal; }; const Split SplitTab[8]={ @@ -115,42 +115,42 @@ const Split SplitTab[8]={ template struct MidPoint : public std::unary_function , typename MESH_TYPE::CoordType > { - MidPoint(MESH_TYPE *_mp) { mp=_mp; } - - MESH_TYPE *mp; - - void operator()(typename MESH_TYPE::VertexType &nv, face::Pos ep){ - assert(mp); - nv.P()= (ep.f->V(ep.z)->P()+ep.f->V1(ep.z)->P())/2.0; + MidPoint(MESH_TYPE *_mp) { mp=_mp; } - if( tri::HasPerVertexNormal(*mp)) - nv.N()= (ep.f->V(ep.z)->N()+ep.f->V1(ep.z)->N()).normalized(); + MESH_TYPE *mp; - if( tri::HasPerVertexColor(*mp)) - nv.C().lerp(ep.f->V(ep.z)->C(),ep.f->V1(ep.z)->C(),.5f); - - if( tri::HasPerVertexQuality(*mp)) - nv.Q() = ((ep.f->V(ep.z)->Q()+ep.f->V1(ep.z)->Q())) / 2.0; + void operator()(typename MESH_TYPE::VertexType &nv, face::Pos ep){ + assert(mp); + nv.P()= (ep.f->V(ep.z)->P()+ep.f->V1(ep.z)->P())/2.0; - if( tri::HasPerVertexTexCoord(*mp)) - nv.T().P() = ((ep.f->V(ep.z)->T().P()+ep.f->V1(ep.z)->T().P())) / 2.0; - } + if( tri::HasPerVertexNormal(*mp)) + nv.N()= (ep.f->V(ep.z)->N()+ep.f->V1(ep.z)->N()).normalized(); - Color4 WedgeInterp(Color4 &c0, Color4 &c1) - { - Color4 cc; - return cc.lerp(c0,c1,0.5f); - } + if( tri::HasPerVertexColor(*mp)) + nv.C().lerp(ep.f->V(ep.z)->C(),ep.f->V1(ep.z)->C(),.5f); - template - TexCoord2 WedgeInterp(TexCoord2 &t0, TexCoord2 &t1) - { - TexCoord2 tmp; - assert(t0.n()== t1.n()); - tmp.n()=t0.n(); - tmp.t()=(t0.t()+t1.t())/2.0; - return tmp; - } + if( tri::HasPerVertexQuality(*mp)) + nv.Q() = ((ep.f->V(ep.z)->Q()+ep.f->V1(ep.z)->Q())) / 2.0; + + if( tri::HasPerVertexTexCoord(*mp)) + nv.T().P() = ((ep.f->V(ep.z)->T().P()+ep.f->V1(ep.z)->T().P())) / 2.0; + } + + Color4 WedgeInterp(Color4 &c0, Color4 &c1) + { + Color4 cc; + return cc.lerp(c0,c1,0.5f); + } + + template + TexCoord2 WedgeInterp(TexCoord2 &t0, TexCoord2 &t1) + { + TexCoord2 tmp; + assert(t0.n()== t1.n()); + tmp.n()=t0.n(); + tmp.t()=(t0.t()+t1.t())/2.0; + return tmp; + } }; @@ -158,59 +158,59 @@ struct MidPoint : public std::unary_function struct MidPointArc : public std::unary_function , typename MESH_TYPE::CoordType> { - void operator()(typename MESH_TYPE::VertexType &nv, face::Pos ep) - { - const typename MESH_TYPE::ScalarType EPS =1e-10; - typename MESH_TYPE::CoordType vp = (ep.f->V(ep.z)->P()+ep.f->V1(ep.z)->P())/2.0; - typename MESH_TYPE::CoordType n = (ep.f->V(ep.z)->N()+ep.f->V1(ep.z)->N())/2.0; - typename MESH_TYPE::ScalarType w =n.Norm(); - if(wV(ep.z)->P()+ep.f->V1(ep.z)->P())/2.0; return;} - n/=w; - typename MESH_TYPE::CoordType d0 = ep.f->V(ep.z)->P() - vp; - typename MESH_TYPE::CoordType d1 = ep.f->V1(ep.z)->P()- vp; - typename MESH_TYPE::ScalarType d=Distance(ep.f->V(ep.z)->P(),ep.f->V1(ep.z)->P())/2.0; + void operator()(typename MESH_TYPE::VertexType &nv, face::Pos ep) + { + const typename MESH_TYPE::ScalarType EPS =1e-10; + typename MESH_TYPE::CoordType vp = (ep.f->V(ep.z)->P()+ep.f->V1(ep.z)->P())/2.0; + typename MESH_TYPE::CoordType n = (ep.f->V(ep.z)->N()+ep.f->V1(ep.z)->N())/2.0; + typename MESH_TYPE::ScalarType w =n.Norm(); + if(wV(ep.z)->P()+ep.f->V1(ep.z)->P())/2.0; return;} + n/=w; + typename MESH_TYPE::CoordType d0 = ep.f->V(ep.z)->P() - vp; + typename MESH_TYPE::CoordType d1 = ep.f->V1(ep.z)->P()- vp; + typename MESH_TYPE::ScalarType d=Distance(ep.f->V(ep.z)->P(),ep.f->V1(ep.z)->P())/2.0; - typename MESH_TYPE::CoordType nn = ep.f->V1(ep.z)->N() ^ ep.f->V(ep.z)->N(); - typename MESH_TYPE::CoordType np = n ^ d0; //vector perpendicular to the edge plane, normal is interpolated - np.Normalize(); - double sign=1; - if(np*nn<0) sign=-1; // se le normali non divergono sposta il punto nella direzione opposta - - typename MESH_TYPE::CoordType n0=ep.f->V(ep.z)->N() -np*(ep.f->V(ep.z)->N()*np); - n0.Normalize(); - typename MESH_TYPE::CoordType n1=ep.f->V1(ep.z)->N()-np*(ep.f->V1(ep.z)->N()*np); - assert(n1.Norm()>EPS); - n1.Normalize(); - typename MESH_TYPE::ScalarType cosa0=n0*n; - typename MESH_TYPE::ScalarType cosa1=n1*n; - if(2-cosa0-cosa1V(ep.z)->P()+ep.f->V1(ep.z)->P())/2.0;return;} - typename MESH_TYPE::ScalarType cosb0=(d0*n)/d; - typename MESH_TYPE::ScalarType cosb1=(d1*n)/d; - assert(1+cosa0>EPS); - assert(1+cosa1>EPS); - typename MESH_TYPE::ScalarType delta0=d*(cosb0 +sqrt( ((1-cosb0*cosb0)*(1-cosa0))/(1+cosa0)) ); - typename MESH_TYPE::ScalarType delta1=d*(cosb1 +sqrt( ((1-cosb1*cosb1)*(1-cosa1))/(1+cosa1)) ); - assert(delta0+delta1<2*d); - nv.P()=vp+n*sign*(delta0+delta1)/2.0; - return ; - } + typename MESH_TYPE::CoordType nn = ep.f->V1(ep.z)->N() ^ ep.f->V(ep.z)->N(); + typename MESH_TYPE::CoordType np = n ^ d0; //vector perpendicular to the edge plane, normal is interpolated + np.Normalize(); + double sign=1; + if(np*nn<0) sign=-1; // se le normali non divergono sposta il punto nella direzione opposta - // Aggiunte in modo grezzo le due wedgeinterp - Color4 WedgeInterp(Color4 &c0, Color4 &c1) - { - Color4 cc; - return cc.lerp(c0,c1,0.5f); - } + typename MESH_TYPE::CoordType n0=ep.f->V(ep.z)->N() -np*(ep.f->V(ep.z)->N()*np); + n0.Normalize(); + typename MESH_TYPE::CoordType n1=ep.f->V1(ep.z)->N()-np*(ep.f->V1(ep.z)->N()*np); + assert(n1.Norm()>EPS); + n1.Normalize(); + typename MESH_TYPE::ScalarType cosa0=n0*n; + typename MESH_TYPE::ScalarType cosa1=n1*n; + if(2-cosa0-cosa1V(ep.z)->P()+ep.f->V1(ep.z)->P())/2.0;return;} + typename MESH_TYPE::ScalarType cosb0=(d0*n)/d; + typename MESH_TYPE::ScalarType cosb1=(d1*n)/d; + assert(1+cosa0>EPS); + assert(1+cosa1>EPS); + typename MESH_TYPE::ScalarType delta0=d*(cosb0 +sqrt( ((1-cosb0*cosb0)*(1-cosa0))/(1+cosa0)) ); + typename MESH_TYPE::ScalarType delta1=d*(cosb1 +sqrt( ((1-cosb1*cosb1)*(1-cosa1))/(1+cosa1)) ); + assert(delta0+delta1<2*d); + nv.P()=vp+n*sign*(delta0+delta1)/2.0; + return ; + } - template - TexCoord2 WedgeInterp(TexCoord2 &t0, TexCoord2 &t1) - { - TexCoord2 tmp; - assert(t0.n()== t1.n()); - tmp.n()=t0.n(); - tmp.t()=(t0.t()+t1.t())/2.0; - return tmp; - } + // Aggiunte in modo grezzo le due wedgeinterp + Color4 WedgeInterp(Color4 &c0, Color4 &c1) + { + Color4 cc; + return cc.lerp(c0,c1,0.5f); + } + + template + TexCoord2 WedgeInterp(TexCoord2 &t0, TexCoord2 &t1) + { + TexCoord2 tmp; + assert(t0.n()== t1.n()); + tmp.n()=t0.n(); + tmp.t()=(t0.t()+t1.t())/2.0; + return tmp; + } }; @@ -219,42 +219,42 @@ Versione Della Midpoint basata sul paper: S. Karbacher, S. Seeger, G. Hausler A non linear subdivision scheme for triangle meshes - Non funziona! - Almeno due problemi: - 1) il verso delle normali influenza il risultato (e.g. si funziona solo se le normali divergono) - Risolvibile controllando se le normali divergono + Non funziona! + Almeno due problemi: + 1) il verso delle normali influenza il risultato (e.g. si funziona solo se le normali divergono) + Risolvibile controllando se le normali divergono 2) gli archi vanno calcolati sul piano definito dalla normale interpolata e l'edge. - funziona molto meglio nelle zone di sella e non semplici. + funziona molto meglio nelle zone di sella e non semplici. */ template struct MidPointArcNaive : public std::unary_function< face::Pos , typename MESH_TYPE::CoordType> { - typename MESH_TYPE::CoordType operator()(face::Pos ep) - { + typename MESH_TYPE::CoordType operator()(face::Pos ep) + { - typename MESH_TYPE::CoordType vp = (ep.f->V(ep.z)->P()+ep.f->V1(ep.z)->P())/2.0; - typename MESH_TYPE::CoordType n = (ep.f->V(ep.z)->N()+ep.f->V1(ep.z)->N())/2.0; - n.Normalize(); - typename MESH_TYPE::CoordType d0 = ep.f->V(ep.z)->P() - vp; - typename MESH_TYPE::CoordType d1 = ep.f->V1(ep.z)->P()- vp; - typename MESH_TYPE::ScalarType d=Distance(ep.f->V(ep.z)->P(),ep.f->V1(ep.z)->P())/2.0; + typename MESH_TYPE::CoordType vp = (ep.f->V(ep.z)->P()+ep.f->V1(ep.z)->P())/2.0; + typename MESH_TYPE::CoordType n = (ep.f->V(ep.z)->N()+ep.f->V1(ep.z)->N())/2.0; + n.Normalize(); + typename MESH_TYPE::CoordType d0 = ep.f->V(ep.z)->P() - vp; + typename MESH_TYPE::CoordType d1 = ep.f->V1(ep.z)->P()- vp; + typename MESH_TYPE::ScalarType d=Distance(ep.f->V(ep.z)->P(),ep.f->V1(ep.z)->P())/2.0; - typename MESH_TYPE::ScalarType cosa0=ep.f->V(ep.z)->N()*n; - typename MESH_TYPE::ScalarType cosa1=ep.f->V1(ep.z)->N()*n; - typename MESH_TYPE::ScalarType cosb0=(d0*n)/d; - typename MESH_TYPE::ScalarType cosb1=(d1*n)/d; + typename MESH_TYPE::ScalarType cosa0=ep.f->V(ep.z)->N()*n; + typename MESH_TYPE::ScalarType cosa1=ep.f->V1(ep.z)->N()*n; + typename MESH_TYPE::ScalarType cosb0=(d0*n)/d; + typename MESH_TYPE::ScalarType cosb1=(d1*n)/d; - typename MESH_TYPE::ScalarType delta0=d*(cosb0 +sqrt( ((1-cosb0*cosb0)*(1-cosa0))/(1+cosa0)) ); - typename MESH_TYPE::ScalarType delta1=d*(cosb1 +sqrt( ((1-cosb1*cosb1)*(1-cosa1))/(1+cosa1)) ); - - return vp+n*(delta0+delta1)/2.0; - } + typename MESH_TYPE::ScalarType delta0=d*(cosb0 +sqrt( ((1-cosb0*cosb0)*(1-cosa0))/(1+cosa0)) ); + typename MESH_TYPE::ScalarType delta1=d*(cosb1 +sqrt( ((1-cosb1*cosb1)*(1-cosa1))/(1+cosa1)) ); + + return vp+n*(delta0+delta1)/2.0; + } }; // Basic Predicate that tells if a given edge must be splitted. -// the constructure requires the threshold. +// the constructure requires the threshold. // VERY IMPORTANT REQUIREMENT: this function must be symmetric // e.g. it must return the same value if the Pos is VFlipped. // If this function is not symmetric the Refine can crash. @@ -264,13 +264,13 @@ class EdgeLen { FLT squaredThr; public: - EdgeLen(){}; - EdgeLen(FLT threshold) {setThr(threshold);} - void setThr(FLT threshold) {squaredThr = threshold*threshold; } - bool operator()(face::Pos ep) const - { - return SquaredDistance(ep.V()->P(), ep.VFlip()->P())>squaredThr; - } + EdgeLen(){}; + EdgeLen(FLT threshold) {setThr(threshold);} + void setThr(FLT threshold) {squaredThr = threshold*threshold; } + bool operator()(face::Pos ep) const + { + return SquaredDistance(ep.V()->P(), ep.VFlip()->P())>squaredThr; + } }; /*********************************************************/ @@ -288,115 +288,115 @@ Requirement: FF Adjacency and Manifoldness **********************************************************/ /*********************************************************/ -template -class RefinedFaceData - { - public: - RefinedFaceData(){ - ep[0]=0;ep[1]=0;ep[2]=0; - vp[0]=0;vp[1]=0;vp[2]=0; - } - bool ep[3]; - VertexPointer vp[3]; - }; +template +class RefinedFaceData + { + public: + RefinedFaceData(){ + ep[0]=0;ep[1]=0;ep[2]=0; + vp[0]=0;vp[1]=0;vp[2]=0; + } + bool ep[3]; + VertexPointer vp[3]; + }; template -bool RefineE(MESH_TYPE &m, MIDPOINT mid, EDGEPRED ep,bool RefineSelected=false, CallBackPos *cb = 0) +bool RefineE(MESH_TYPE &m, MIDPOINT &mid, EDGEPRED &ep,bool RefineSelected=false, CallBackPos *cb = 0) { - // common typenames - typedef typename MESH_TYPE::VertexIterator VertexIterator; - typedef typename MESH_TYPE::FaceIterator FaceIterator; - typedef typename MESH_TYPE::VertexPointer VertexPointer; - typedef typename MESH_TYPE::FacePointer FacePointer; - typedef typename MESH_TYPE::FaceType FaceType; - typedef typename MESH_TYPE::FaceType::TexCoordType TexCoordType; - assert(tri::HasFFAdjacency(m)); - tri::UpdateFlags::FaceBorderFromFF(m); - typedef face::Pos PosType; + // common typenames + typedef typename MESH_TYPE::VertexIterator VertexIterator; + typedef typename MESH_TYPE::FaceIterator FaceIterator; + typedef typename MESH_TYPE::VertexPointer VertexPointer; + typedef typename MESH_TYPE::FacePointer FacePointer; + typedef typename MESH_TYPE::FaceType FaceType; + typedef typename MESH_TYPE::FaceType::TexCoordType TexCoordType; + assert(tri::HasFFAdjacency(m)); + tri::UpdateFlags::FaceBorderFromFF(m); + typedef face::Pos PosType; - int j,NewVertNum=0,NewFaceNum=0; + int j,NewVertNum=0,NewFaceNum=0; - typedef RefinedFaceData RFD; - typedef typename MESH_TYPE :: template PerFaceAttributeHandle HandleType; - HandleType RD = tri::Allocator:: template AddPerFaceAttribute (m,std::string("RefineData")); + typedef RefinedFaceData RFD; + typedef typename MESH_TYPE :: template PerFaceAttributeHandle HandleType; + HandleType RD = tri::Allocator:: template AddPerFaceAttribute (m,std::string("RefineData")); - // Callback stuff - int step=0; - int PercStep=std::max(1,m.fn/33); - - // First Loop: We analyze the mesh to compute the number of the new faces and new vertices - FaceIterator fi; + // Callback stuff + int step=0; + int PercStep=std::max(1,m.fn/33); + + // First Loop: We analyze the mesh to compute the number of the new faces and new vertices + FaceIterator fi; for(fi=m.face.begin(),j=0;fi!=m.face.end();++fi) if(!(*fi).IsD()) - { - if(cb && (++step%PercStep)==0) (*cb)(step/PercStep,"Refining..."); - // skip unselected faces if necessary - if(RefineSelected && !(*fi).IsS()) continue; - - for(j=0;j<3;j++) - { - if(RD[fi].ep[j]) continue; - - PosType edgeCur(&*fi,j); - if(RefineSelected && ! edgeCur.FFlip()->IsS()) continue; - if(!ep(edgeCur)) continue; - - RD[edgeCur.F()].ep[edgeCur.E()]=true; - ++NewFaceNum; - ++NewVertNum; - assert(edgeCur.IsManifold()); - if(!edgeCur.IsBorder()) - { - edgeCur.FlipF(); - edgeCur.F()->SetV(); - RD[edgeCur.F()].ep[edgeCur.E()]=true; - ++NewFaceNum; - } - } - + { + if(cb && (++step%PercStep)==0) (*cb)(step/PercStep,"Refining..."); + // skip unselected faces if necessary + if(RefineSelected && !(*fi).IsS()) continue; + + for(j=0;j<3;j++) + { + if(RD[fi].ep[j]) continue; + + PosType edgeCur(&*fi,j); + if(RefineSelected && ! edgeCur.FFlip()->IsS()) continue; + if(!ep(edgeCur)) continue; + + RD[edgeCur.F()].ep[edgeCur.E()]=true; + ++NewFaceNum; + ++NewVertNum; + assert(edgeCur.IsManifold()); + if(!edgeCur.IsBorder()) + { + edgeCur.FlipF(); + edgeCur.F()->SetV(); + RD[edgeCur.F()].ep[edgeCur.E()]=true; + ++NewFaceNum; + } + } + } // end face loop - - if(NewVertNum ==0 ) - { - tri::Allocator :: template DeletePerFaceAttribute > (m,RD); - return false; - } - VertexIterator lastv = tri::Allocator::AddVertices(m,NewVertNum); - - // Secondo loop: We initialize a edge->vertex map - - for(fi=m.face.begin();fi!=m.face.end();++fi) if(!(*fi).IsD()) + + if(NewVertNum ==0 ) + { + tri::Allocator :: template DeletePerFaceAttribute > (m,RD); + return false; + } + VertexIterator lastv = tri::Allocator::AddVertices(m,NewVertNum); + + // Secondo loop: We initialize a edge->vertex map + + for(fi=m.face.begin();fi!=m.face.end();++fi) if(!(*fi).IsD()) { - if(cb && (++step%PercStep)==0)(*cb)(step/PercStep,"Refining..."); + if(cb && (++step%PercStep)==0)(*cb)(step/PercStep,"Refining..."); for(j=0;j<3;j++) - { - // skip unselected faces if necessary - if(RefineSelected && !(*fi).IsS()) continue; - for(j=0;j<3;j++) - { - PosType edgeCur(&*fi,j); - if(RefineSelected && ! edgeCur.FFlip()->IsS()) continue; - - if( RD[edgeCur.F()].ep[edgeCur.E()] && RD[edgeCur.F()].vp[edgeCur.E()] ==0 ) - { - RD[edgeCur.F()].vp[edgeCur.E()] = &*lastv; - mid(*lastv,edgeCur); - if(!edgeCur.IsBorder()) - { - edgeCur.FlipF(); - assert(RD[edgeCur.F()].ep[edgeCur.E()]); - RD[edgeCur.F()].vp[edgeCur.E()] = &*lastv; - } - ++lastv; - } - } - } + { + // skip unselected faces if necessary + if(RefineSelected && !(*fi).IsS()) continue; + for(j=0;j<3;j++) + { + PosType edgeCur(&*fi,j); + if(RefineSelected && ! edgeCur.FFlip()->IsS()) continue; + + if( RD[edgeCur.F()].ep[edgeCur.E()] && RD[edgeCur.F()].vp[edgeCur.E()] ==0 ) + { + RD[edgeCur.F()].vp[edgeCur.E()] = &*lastv; + mid(*lastv,edgeCur); + if(!edgeCur.IsBorder()) + { + edgeCur.FlipF(); + assert(RD[edgeCur.F()].ep[edgeCur.E()]); + RD[edgeCur.F()].vp[edgeCur.E()] = &*lastv; + } + ++lastv; + } + } + } } - - assert(lastv==m.vert.end()); // critical assert: we MUST have used all the vertex that we forecasted we need - - FaceIterator lastf = tri::Allocator::AddFaces(m,NewFaceNum); - FaceIterator oldendf = lastf; - + + assert(lastv==m.vert.end()); // critical assert: we MUST have used all the vertex that we forecasted we need + + FaceIterator lastf = tri::Allocator::AddFaces(m,NewFaceNum); + FaceIterator oldendf = lastf; + /* * v0 * @@ -412,93 +412,93 @@ bool RefineE(MESH_TYPE &m, MIDPOINT mid, EDGEPRED ep,bool RefineSelected=false, * */ - VertexPointer vv[6]; // The six vertices that arise in the single triangle splitting - // 0..2 Original triangle vertices - // 3..5 mp01, mp12, mp20 midpoints of the three edges - FacePointer nf[4]; // The (up to) four faces that are created. + VertexPointer vv[6]; // The six vertices that arise in the single triangle splitting + // 0..2 Original triangle vertices + // 3..5 mp01, mp12, mp20 midpoints of the three edges + FacePointer nf[4]; // The (up to) four faces that are created. - TexCoordType wtt[6]; // per ogni faccia sono al piu' tre i nuovi valori - // di texture per wedge (uno per ogni edge) + TexCoordType wtt[6]; // per ogni faccia sono al piu' tre i nuovi valori + // di texture per wedge (uno per ogni edge) - int fca=0,fcn =0; - for(fi=m.face.begin();fi!=oldendf;++fi) if(!(*fi).IsD()) - { - if(cb && (++step%PercStep)==0)(*cb)(step/PercStep,"Refining..."); - fcn++; - vv[0]=(*fi).V(0); - vv[1]=(*fi).V(1); - vv[2]=(*fi).V(2); - vv[3] = RD[fi].vp[0]; - vv[4] = RD[fi].vp[1]; - vv[5] = RD[fi].vp[2]; + int fca=0,fcn =0; + for(fi=m.face.begin();fi!=oldendf;++fi) if(!(*fi).IsD()) + { + if(cb && (++step%PercStep)==0)(*cb)(step/PercStep,"Refining..."); + fcn++; + vv[0]=(*fi).V(0); + vv[1]=(*fi).V(1); + vv[2]=(*fi).V(2); + vv[3] = RD[fi].vp[0]; + vv[4] = RD[fi].vp[1]; + vv[5] = RD[fi].vp[2]; - int ind=((&*vv[3])?1:0)+((&*vv[4])?2:0)+((&*vv[5])?4:0); + int ind=((&*vv[3])?1:0)+((&*vv[4])?2:0)+((&*vv[5])?4:0); - nf[0]=&*fi; - int i; - for(i=1;iImportData(*fi); + nf[0]=&*fi; + int i; + for(i=1;iImportData(*fi); // if(tri::HasPerFaceColor(m)) // nf[i]->C()=(*fi).cC(); - } + } - if(tri::HasPerWedgeTexCoord(m)) - for(i=0;i<3;++i) { - wtt[i]=(*fi).WT(i); - wtt[3+i]=mid.WedgeInterp((*fi).WT(i),(*fi).WT((i+1)%3)); - } + if(tri::HasPerWedgeTexCoord(m)) + for(i=0;i<3;++i) { + wtt[i]=(*fi).WT(i); + wtt[3+i]=mid.WedgeInterp((*fi).WT(i),(*fi).WT((i+1)%3)); + } - int orgflag= (*fi).Flags(); - for(i=0;iP(),vv[SplitTab[ind].swap[0][1]]->P()) < - SquaredDistance(vv[SplitTab[ind].swap[1][0]]->P(),vv[SplitTab[ind].swap[1][1]]->P()) ) - { // swap the last two triangles - (*nf[2]).V(1)=(*nf[1]).V(0); - (*nf[1]).V(1)=(*nf[2]).V(0); - if(tri::HasPerWedgeTexCoord(m)){ //swap also textures coordinates - (*nf[2]).WT(1)=(*nf[1]).WT(0); - (*nf[1]).WT(1)=(*nf[2]).WT(0); - } + if(SplitTab[ind].TriNum==3 && + SquaredDistance(vv[SplitTab[ind].swap[0][0]]->P(),vv[SplitTab[ind].swap[0][1]]->P()) < + SquaredDistance(vv[SplitTab[ind].swap[1][0]]->P(),vv[SplitTab[ind].swap[1][1]]->P()) ) + { // swap the last two triangles + (*nf[2]).V(1)=(*nf[1]).V(0); + (*nf[1]).V(1)=(*nf[2]).V(0); + if(tri::HasPerWedgeTexCoord(m)){ //swap also textures coordinates + (*nf[2]).WT(1)=(*nf[1]).WT(0); + (*nf[1]).WT(1)=(*nf[2]).WT(0); + } - if((*nf[1]).IsB(0)) (*nf[2]).SetB(1); else (*nf[2]).ClearB(1); - if((*nf[2]).IsB(0)) (*nf[1]).SetB(1); else (*nf[1]).ClearB(1); - (*nf[1]).ClearB(0); - (*nf[2]).ClearB(0); - } - } - - assert(lastf==m.face.end()); // critical assert: we MUST have used all the faces that we forecasted we need and that we previously allocated. - assert(!m.vert.empty()); - for(fi=m.face.begin();fi!=m.face.end();++fi) if(!(*fi).IsD()){ - assert((*fi).V(0)>=&*m.vert.begin() && (*fi).V(0)<=&m.vert.back() ); - assert((*fi).V(1)>=&*m.vert.begin() && (*fi).V(1)<=&m.vert.back() ); - assert((*fi).V(2)>=&*m.vert.begin() && (*fi).V(2)<=&m.vert.back() ); - } - tri::UpdateTopology::FaceFace(m); - - tri::Allocator :: template DeletePerFaceAttribute > (m,RD); + if((*nf[1]).IsB(0)) (*nf[2]).SetB(1); else (*nf[2]).ClearB(1); + if((*nf[2]).IsB(0)) (*nf[1]).SetB(1); else (*nf[1]).ClearB(1); + (*nf[1]).ClearB(0); + (*nf[2]).ClearB(0); + } + } - return true; + assert(lastf==m.face.end()); // critical assert: we MUST have used all the faces that we forecasted we need and that we previously allocated. + assert(!m.vert.empty()); + for(fi=m.face.begin();fi!=m.face.end();++fi) if(!(*fi).IsD()){ + assert((*fi).V(0)>=&*m.vert.begin() && (*fi).V(0)<=&m.vert.back() ); + assert((*fi).V(1)>=&*m.vert.begin() && (*fi).V(1)<=&m.vert.back() ); + assert((*fi).V(2)>=&*m.vert.begin() && (*fi).V(2)<=&m.vert.back() ); + } + tri::UpdateTopology::FaceFace(m); + + tri::Allocator :: template DeletePerFaceAttribute > (m,RD); + + return true; } /*************************************************************************/ @@ -507,14 +507,14 @@ bool RefineE(MESH_TYPE &m, MIDPOINT mid, EDGEPRED ep,bool RefineSelected=false, template bool Refine(MESH_TYPE &m, MIDPOINT mid, typename MESH_TYPE::ScalarType thr=0,bool RefineSelected=false, CallBackPos *cb = 0) { - EdgeLen ep(thr); + EdgeLen ep(thr); return RefineE(m,mid,ep,RefineSelected,cb); } /*************************************************************************/ /* -Modified Butterfly interpolation scheme, -as presented in +Modified Butterfly interpolation scheme, +as presented in Zorin, Schroeder Subdivision for modeling and animation Siggraph 2000 Course Notes @@ -540,103 +540,103 @@ struct MidPointButterfly : public std::unary_function ep) - { - face::Pos he(ep.f,ep.z,ep.f->V(ep.z)); - typename MESH_TYPE::CoordType *vl,*vr; - typename MESH_TYPE::CoordType *vl0,*vr0; - typename MESH_TYPE::CoordType *vu,*vd,*vul,*vur,*vdl,*vdr; - vl=&he.v->P(); - he.FlipV(); - vr=&he.v->P(); - - if( tri::HasPerVertexColor(m)) - nv.C().lerp(ep.f->V(ep.z)->C(),ep.f->V1(ep.z)->C(),.5f); + void operator()(typename MESH_TYPE::VertexType &nv, face::Pos ep) + { + face::Pos he(ep.f,ep.z,ep.f->V(ep.z)); + typename MESH_TYPE::CoordType *vl,*vr; + typename MESH_TYPE::CoordType *vl0,*vr0; + typename MESH_TYPE::CoordType *vu,*vd,*vul,*vur,*vdl,*vdr; + vl=&he.v->P(); + he.FlipV(); + vr=&he.v->P(); - if(he.IsBorder()) - { - he.NextB(); - vr0=&he.v->P(); - he.FlipV(); - he.NextB(); - assert(&he.v->P()==vl); - he.NextB(); - vl0=&he.v->P(); - nv.P()=((*vl)+(*vr))*(9.0/16.0)-((*vl0)+(*vr0))/16.0 ; - } - else - { - he.FlipE();he.FlipV(); - vu=&he.v->P(); - he.FlipF();he.FlipE();he.FlipV(); - vur=&he.v->P(); - he.FlipV();he.FlipE();he.FlipF(); assert(&he.v->P()==vu); // back to vu (on the right) - he.FlipE(); - he.FlipF();he.FlipE();he.FlipV(); - vul=&he.v->P(); - he.FlipV();he.FlipE();he.FlipF(); assert(&he.v->P()==vu); // back to vu (on the left) - he.FlipV();he.FlipE();he.FlipF(); assert(&he.v->P()==vl);// again on vl (but under the edge) - he.FlipE();he.FlipV(); - vd=&he.v->P(); - he.FlipF();he.FlipE();he.FlipV(); - vdl=&he.v->P(); - he.FlipV();he.FlipE();he.FlipF(); assert(&he.v->P()==vd);// back to vd (on the right) - he.FlipE(); - he.FlipF();he.FlipE();he.FlipV(); - vdr=&he.v->P(); + if( tri::HasPerVertexColor(m)) + nv.C().lerp(ep.f->V(ep.z)->C(),ep.f->V1(ep.z)->C(),.5f); - nv.P()=((*vl)+(*vr))/2.0+((*vu)+(*vd))/8.0 - ((*vul)+(*vur)+(*vdl)+(*vdr))/16.0; - } - } + if(he.IsBorder()) + { + he.NextB(); + vr0=&he.v->P(); + he.FlipV(); + he.NextB(); + assert(&he.v->P()==vl); + he.NextB(); + vl0=&he.v->P(); + nv.P()=((*vl)+(*vr))*(9.0/16.0)-((*vl0)+(*vr0))/16.0 ; + } + else + { + he.FlipE();he.FlipV(); + vu=&he.v->P(); + he.FlipF();he.FlipE();he.FlipV(); + vur=&he.v->P(); + he.FlipV();he.FlipE();he.FlipF(); assert(&he.v->P()==vu); // back to vu (on the right) + he.FlipE(); + he.FlipF();he.FlipE();he.FlipV(); + vul=&he.v->P(); + he.FlipV();he.FlipE();he.FlipF(); assert(&he.v->P()==vu); // back to vu (on the left) + he.FlipV();he.FlipE();he.FlipF(); assert(&he.v->P()==vl);// again on vl (but under the edge) + he.FlipE();he.FlipV(); + vd=&he.v->P(); + he.FlipF();he.FlipE();he.FlipV(); + vdl=&he.v->P(); + he.FlipV();he.FlipE();he.FlipF(); assert(&he.v->P()==vd);// back to vd (on the right) + he.FlipE(); + he.FlipF();he.FlipE();he.FlipV(); + vdr=&he.v->P(); - /// Aggiunte in modo grezzo le due wedge interp - Color4 WedgeInterp(Color4 &c0, Color4 &c1) - { - Color4 cc; - return cc.lerp(c0,c1,0.5f); - } + nv.P()=((*vl)+(*vr))/2.0+((*vu)+(*vd))/8.0 - ((*vul)+(*vur)+(*vdl)+(*vdr))/16.0; + } + } - template - TexCoord2 WedgeInterp(TexCoord2 &t0, TexCoord2 &t1) - { - TexCoord2 tmp; - assert(t0.n()== t1.n()); - tmp.n()=t0.n(); - tmp.t()=(t0.t()+t1.t())/2.0; - return tmp; - } + /// Aggiunte in modo grezzo le due wedge interp + Color4 WedgeInterp(Color4 &c0, Color4 &c1) + { + Color4 cc; + return cc.lerp(c0,c1,0.5f); + } + + template + TexCoord2 WedgeInterp(TexCoord2 &t0, TexCoord2 &t1) + { + TexCoord2 tmp; + assert(t0.n()== t1.n()); + tmp.n()=t0.n(); + tmp.t()=(t0.t()+t1.t())/2.0; + return tmp; + } }; #if 0 - int rule=0; - if(vr==vul) rule+=1; - if(vl==vur) rule+=2; - if(vl==vdr) rule+=4; - if(vr==vdl) rule+=8; - switch(rule){ + int rule=0; + if(vr==vul) rule+=1; + if(vl==vur) rule+=2; + if(vl==vdr) rule+=4; + if(vr==vdl) rule+=8; + switch(rule){ /* */ /* */ case 0 : return ((*vl)+(*vr))/2.0+((*vu)+(*vd))/8.0 - ((*vul)+(*vur)+(*vdl)+(*vdr))/16.0; -/* ul */ case 1 : return (*vl*6 + *vr*10 + *vu + *vd*3 - *vur - *vdl -*vdr*2 )/16.0; -/* ur */ case 2 : return (*vr*6 + *vl*10 + *vu + *vd*3 - *vul - *vdr -*vdl*2 )/16.0; -/* dr */ case 4 : return (*vr*6 + *vl*10 + *vd + *vu*3 - *vdl - *vur -*vul*2 )/16.0; -/* dl */ case 8 : return (*vl*6 + *vr*10 + *vd + *vu*3 - *vdr - *vul -*vur*2 )/16.0; -/* ul,ur */ case 3 : return (*vl*4 + *vr*4 + *vd*2 + - *vdr - *vdl )/8.0; -/* dl,dr */ case 12 : return (*vl*4 + *vr*4 + *vu*2 + - *vur - *vul )/8.0; +/* ul */ case 1 : return (*vl*6 + *vr*10 + *vu + *vd*3 - *vur - *vdl -*vdr*2 )/16.0; +/* ur */ case 2 : return (*vr*6 + *vl*10 + *vu + *vd*3 - *vul - *vdr -*vdl*2 )/16.0; +/* dr */ case 4 : return (*vr*6 + *vl*10 + *vd + *vu*3 - *vdl - *vur -*vul*2 )/16.0; +/* dl */ case 8 : return (*vl*6 + *vr*10 + *vd + *vu*3 - *vdr - *vul -*vur*2 )/16.0; +/* ul,ur */ case 3 : return (*vl*4 + *vr*4 + *vd*2 + - *vdr - *vdl )/8.0; +/* dl,dr */ case 12 : return (*vl*4 + *vr*4 + *vu*2 + - *vur - *vul )/8.0; /* ul,dr */ case 5 : -/* ur,dl */ case 10 : - default: - return (*vl+ *vr)/2.0; - } +/* ur,dl */ case 10 : + default: + return (*vl+ *vr)/2.0; + } #endif /* vul-------vu--------vur - \ / \ / - \ / \ / + \ / \ / + \ / \ / \ / fu \ / vl--------vr / \ fd / \ @@ -651,78 +651,78 @@ struct MidPointButterfly : public std::unary_function struct MidPointButterfly2 : public std::unary_function , typename MESH_TYPE::CoordType> { - typename MESH_TYPE::CoordType operator()(face::Pos ep) - { -double Rules[11][10] = + typename MESH_TYPE::CoordType operator()(face::Pos ep) + { +double Rules[11][10] = { - {.0}, // valenza 0 - {.0}, // valenza 1 - {.0}, // valenza 2 - { .4166666667, -.08333333333 , -.08333333333 }, // valenza 3 - { .375 , .0 , -0.125 , .0 }, // valenza 4 - { .35 , .03090169945 , -.08090169945 , -.08090169945, .03090169945 }, // valenza 5 - { .5 , .125 , -0.0625 , .0 , -0.0625 , 0.125 }, // valenza 6 - { .25 , .1088899050 , -.06042933822 , -.04846056675, -.04846056675, -.06042933822, .1088899050 }, // valenza 7 - { .21875 , .1196383476 , -.03125 , -.05713834763, -.03125 , -.05713834763, -.03125 ,.1196383476 }, // valenza 8 - { .1944444444, .1225409480 , -.00513312590 , -.05555555556, -.03407448880, -.03407448880, -.05555555556, -.00513312590, .1225409480 }, // valenza 9 - { .175 , .1213525492 , .01545084973 , -.04635254918, -.04045084973, -.025 , -.04045084973, -.04635254918, .01545084973, .1213525492 } // valenza 10 + {.0}, // valenza 0 + {.0}, // valenza 1 + {.0}, // valenza 2 + { .4166666667, -.08333333333 , -.08333333333 }, // valenza 3 + { .375 , .0 , -0.125 , .0 }, // valenza 4 + { .35 , .03090169945 , -.08090169945 , -.08090169945, .03090169945 }, // valenza 5 + { .5 , .125 , -0.0625 , .0 , -0.0625 , 0.125 }, // valenza 6 + { .25 , .1088899050 , -.06042933822 , -.04846056675, -.04846056675, -.06042933822, .1088899050 }, // valenza 7 + { .21875 , .1196383476 , -.03125 , -.05713834763, -.03125 , -.05713834763, -.03125 ,.1196383476 }, // valenza 8 + { .1944444444, .1225409480 , -.00513312590 , -.05555555556, -.03407448880, -.03407448880, -.05555555556, -.00513312590, .1225409480 }, // valenza 9 + { .175 , .1213525492 , .01545084973 , -.04635254918, -.04045084973, -.025 , -.04045084973, -.04635254918, .01545084973, .1213525492 } // valenza 10 }; face::Pos he(ep.f,ep.z,ep.f->V(ep.z)); - typename MESH_TYPE::CoordType *vl,*vr; - vl=&he.v->P(); - vr=&he.VFlip()->P(); - if(he.IsBorder()) - {he.FlipV(); - typename MESH_TYPE::CoordType *vl0,*vr0; - he.NextB(); - vr0=&he.v->P(); - he.FlipV(); - he.NextB(); - assert(&he.v->P()==vl); - he.NextB(); - vl0=&he.v->P(); - return ((*vl)+(*vr))*(9.0/16.0)-((*vl0)+(*vr0))/16.0 ; - } + typename MESH_TYPE::CoordType *vl,*vr; + vl=&he.v->P(); + vr=&he.VFlip()->P(); + if(he.IsBorder()) + {he.FlipV(); + typename MESH_TYPE::CoordType *vl0,*vr0; + he.NextB(); + vr0=&he.v->P(); + he.FlipV(); + he.NextB(); + assert(&he.v->P()==vl); + he.NextB(); + vl0=&he.v->P(); + return ((*vl)+(*vr))*(9.0/16.0)-((*vl0)+(*vr0))/16.0 ; + } - int kl=0,kr=0; // valence of left and right vertices - bool bl=false,br=false; // if left and right vertices are of border + int kl=0,kr=0; // valence of left and right vertices + bool bl=false,br=false; // if left and right vertices are of border face::Pos heStart=he;assert(he.v->P()==*vl); - do { // compute valence of left vertex - he.FlipE();he.FlipF(); - if(he.IsBorder()) bl=true; - ++kl; - } while(he!=heStart); - - he.FlipV();heStart=he;assert(he.v->P()==*vr); - do { // compute valence of right vertex - he.FlipE();he.FlipF(); - if(he.IsBorder()) br=true; - ++kr; - } while(he!=heStart); + do { // compute valence of left vertex + he.FlipE();he.FlipF(); + if(he.IsBorder()) bl=true; + ++kl; + } while(he!=heStart); + + he.FlipV();heStart=he;assert(he.v->P()==*vr); + do { // compute valence of right vertex + he.FlipE();he.FlipF(); + if(he.IsBorder()) br=true; + ++kr; + } while(he!=heStart); if(br||bl) return MidPointButterfly()( ep ); - if(kr==6 && kl==6) return MidPointButterfly()( ep ); - // TRACE("odd vertex among valences of %i %i\n",kl,kr); - typename MESH_TYPE::CoordType newposl=*vl*.75, newposr=*vr*.75; - he.FlipV();heStart=he; assert(he.v->P()==*vl); - int i=0; - if(kl!=6) - do { // compute position of left vertex - newposl+= he.VFlip()->P() * Rules[kl][i]; - he.FlipE();he.FlipF(); - ++i; - } while(he!=heStart); - i=0;he.FlipV();heStart=he;assert(he.v->P()==*vr); - if(kr!=6) - do { // compute position of right vertex - newposr+=he.VFlip()->P()* Rules[kr][i]; - he.FlipE();he.FlipF(); - ++i; - } while(he!=heStart); - if(kr==6) return newposl; - if(kl==6) return newposr; - return newposl+newposr; - } + if(kr==6 && kl==6) return MidPointButterfly()( ep ); + // TRACE("odd vertex among valences of %i %i\n",kl,kr); + typename MESH_TYPE::CoordType newposl=*vl*.75, newposr=*vr*.75; + he.FlipV();heStart=he; assert(he.v->P()==*vl); + int i=0; + if(kl!=6) + do { // compute position of left vertex + newposl+= he.VFlip()->P() * Rules[kl][i]; + he.FlipE();he.FlipF(); + ++i; + } while(he!=heStart); + i=0;he.FlipV();heStart=he;assert(he.v->P()==*vr); + if(kr!=6) + do { // compute position of right vertex + newposr+=he.VFlip()->P()* Rules[kr][i]; + he.FlipE();he.FlipF(); + ++i; + } while(he!=heStart); + if(kr==6) return newposl; + if(kl==6) return newposr; + return newposl+newposr; + } }; /* The two following classes are the functor and the predicate that you need for using the refine framework to cut a mesh along a linear interpolation of the quality. @@ -750,7 +750,7 @@ public: QualityMidPointFunctor(ScalarType _thr):thr(_thr){} - + void operator()(typename MESH_TYPE::VertexType &nv, const face::Pos &ep){ Point3x p0=ep.f->V0(ep.z)->P(); Point3x p1=ep.f->V1(ep.z)->P(); @@ -759,23 +759,23 @@ public: double pp= q0/(q0-q1); nv.P()=p1*pp + p0*(1.0-pp); nv.Q()=thr; - } + } - Color4 WedgeInterp(Color4 &c0, Color4 &c1) - { - Color4 cc; - return cc.lerp(c0,c1,0.5f); - } + Color4 WedgeInterp(Color4 &c0, Color4 &c1) + { + Color4 cc; + return cc.lerp(c0,c1,0.5f); + } - template - TexCoord2 WedgeInterp(TexCoord2 &t0, TexCoord2 &t1) - { - TexCoord2 tmp; - assert(t0.n()== t1.n()); - tmp.n()=t0.n(); - tmp.t()=(t0.t()+t1.t())/2.0; - return tmp; - } + template + TexCoord2 WedgeInterp(TexCoord2 &t0, TexCoord2 &t1) + { + TexCoord2 tmp; + assert(t0.n()== t1.n()); + tmp.n()=t0.n(); + tmp.t()=(t0.t()+t1.t())/2.0; + return tmp; + } }; @@ -804,47 +804,47 @@ class QualityEdgePredicate template struct MidPointSphere : public std::unary_function , typename MESH_TYPE::CoordType> { - Sphere3 sph; - typedef Point3 Point3x; - - void operator()(typename MESH_TYPE::VertexType &nv, face::Pos ep){ - Point3x &p0=ep.f->V0(ep.z)->P(); - Point3x &p1=ep.f->V1(ep.z)->P(); + Sphere3 sph; + typedef Point3 Point3x; + + void operator()(typename MESH_TYPE::VertexType &nv, face::Pos ep){ + Point3x &p0=ep.f->V0(ep.z)->P(); + Point3x &p1=ep.f->V1(ep.z)->P(); nv.P()= sph.c+((p0+p1)/2.0 - sph.c ).Normalize(); - } + } - Color4 WedgeInterp(Color4 &c0, Color4 &c1) - { - Color4 cc; - return cc.lerp(c0,c1,0.5f); - } + Color4 WedgeInterp(Color4 &c0, Color4 &c1) + { + Color4 cc; + return cc.lerp(c0,c1,0.5f); + } - template - TexCoord2 WedgeInterp(TexCoord2 &t0, TexCoord2 &t1) - { - TexCoord2 tmp; - assert(t0.n()== t1.n()); - tmp.n()=t0.n(); - tmp.t()=(t0.t()+t1.t())/2.0; - return tmp; - } + template + TexCoord2 WedgeInterp(TexCoord2 &t0, TexCoord2 &t1) + { + TexCoord2 tmp; + assert(t0.n()== t1.n()); + tmp.n()=t0.n(); + tmp.t()=(t0.t()+t1.t())/2.0; + return tmp; + } }; template class EdgeSplSphere { - public: + public: Sphere3 sph; - bool operator()(const Point3 &p0, const Point3 &p1) const - { - if(Distance(sph,p0)>0) { - if(Distance(sph,p1)>0) return false; - else return true; - } - else if(Distance(sph,p1)<=0) return false; - return true; - } + bool operator()(const Point3 &p0, const Point3 &p1) const + { + if(Distance(sph,p0)>0) { + if(Distance(sph,p1)>0) return false; + else return true; + } + else if(Distance(sph,p1)<=0) return false; + return true; + } }; /*! @@ -854,79 +854,79 @@ class EdgeSplSphere template struct CenterPoint : public std::unary_function { - typename TRIMESH_TYPE::CoordType operator()(typename TRIMESH_TYPE::FacePointer f){ - return vcg::Barycenter(*f); - } + typename TRIMESH_TYPE::CoordType operator()(typename TRIMESH_TYPE::FacePointer f){ + return vcg::Barycenter(*f); + } }; template void TriSplit(typename TRIMESH_TYPE::FacePointer f, - typename TRIMESH_TYPE::FacePointer f1,typename TRIMESH_TYPE::FacePointer f2, - typename TRIMESH_TYPE::VertexPointer vB, CenterPoint Center) + typename TRIMESH_TYPE::FacePointer f1,typename TRIMESH_TYPE::FacePointer f2, + typename TRIMESH_TYPE::VertexPointer vB, CenterPoint Center) { - vB->P() = Center(f); + vB->P() = Center(f); - //i tre vertici della faccia da dividere - typename TRIMESH_TYPE::VertexType* V0,*V1,*V2; - V0 = f->V(0); - V1 = f->V(1); - V2 = f->V(2); + //i tre vertici della faccia da dividere + typename TRIMESH_TYPE::VertexType* V0,*V1,*V2; + V0 = f->V(0); + V1 = f->V(1); + V2 = f->V(2); - //risistemo la faccia di partenza - (*f).V(2) = &(*vB); - //Faccia nuova #1 - (*f1).V(0) = &(*vB); - (*f1).V(1) = V1; - (*f1).V(2) = V2; - //Faccia nuova #2 - (*f2).V(0) = V0; - (*f2).V(1) = &(*vB); - (*f2).V(2) = V2; + //risistemo la faccia di partenza + (*f).V(2) = &(*vB); + //Faccia nuova #1 + (*f1).V(0) = &(*vB); + (*f1).V(1) = V1; + (*f1).V(2) = V2; + //Faccia nuova #2 + (*f2).V(0) = V0; + (*f2).V(1) = &(*vB); + (*f2).V(2) = V2; - if(f->HasFFAdjacency()) - { - //adiacenza delle facce adiacenti a quelle aggiunte - f->FFp(1)->FFp(f->FFi(1)) = f1; - f->FFp(2)->FFp(f->FFi(2)) = f2; + if(f->HasFFAdjacency()) + { + //adiacenza delle facce adiacenti a quelle aggiunte + f->FFp(1)->FFp(f->FFi(1)) = f1; + f->FFp(2)->FFp(f->FFi(2)) = f2; - //adiacenza ff - typename TRIMESH_TYPE::FacePointer FF0,FF1,FF2; - FF0 = f->FFp(0); - FF1 = f->FFp(1); - FF2 = f->FFp(2); + //adiacenza ff + typename TRIMESH_TYPE::FacePointer FF0,FF1,FF2; + FF0 = f->FFp(0); + FF1 = f->FFp(1); + FF2 = f->FFp(2); - //Indici di adiacenza ff - char FFi0,FFi1,FFi2; - FFi0 = f->FFi(0); - FFi1 = f->FFi(1); - FFi2 = f->FFi(2); + //Indici di adiacenza ff + char FFi0,FFi1,FFi2; + FFi0 = f->FFi(0); + FFi1 = f->FFi(1); + FFi2 = f->FFi(2); - //adiacenza della faccia di partenza - (*f).FFp(1) = &(*f1); - (*f).FFi(1) = 0; - (*f).FFp(2) = &(*f2); - (*f).FFi(2) = 0; + //adiacenza della faccia di partenza + (*f).FFp(1) = &(*f1); + (*f).FFi(1) = 0; + (*f).FFp(2) = &(*f2); + (*f).FFi(2) = 0; - //adiacenza della faccia #1 - (*f1).FFp(0) = f; - (*f1).FFi(0) = 1; + //adiacenza della faccia #1 + (*f1).FFp(0) = f; + (*f1).FFi(0) = 1; - (*f1).FFp(1) = FF1; - (*f1).FFi(1) = FFi1; + (*f1).FFp(1) = FF1; + (*f1).FFi(1) = FFi1; - (*f1).FFp(2) = &(*f2); - (*f1).FFi(2) = 1; + (*f1).FFp(2) = &(*f2); + (*f1).FFi(2) = 1; - //adiacenza della faccia #2 - (*f2).FFp(0) = f; - (*f2).FFi(0) = 2; + //adiacenza della faccia #2 + (*f2).FFp(0) = f; + (*f2).FFi(0) = 2; - (*f2).FFp(1) = &(*f1); - (*f2).FFi(1) = 2; + (*f2).FFp(1) = &(*f1); + (*f2).FFi(1) = 2; - (*f2).FFp(2) = FF2; - (*f2).FFi(2) = FFi2; - } + (*f2).FFp(2) = FF2; + (*f2).FFi(2) = FFi2; + } }