Small refactoring

This commit is contained in:
Paolo Cignoni 2017-03-22 07:33:34 +01:00
parent aef47c18de
commit da8b1825c6
1 changed files with 56 additions and 63 deletions

View File

@ -258,7 +258,6 @@ static void AccumulateLaplacianInfo(MeshType &m, SimpleTempData<typename MeshTyp
static void VertexCoordLaplacian(MeshType &m, int step, bool SmoothSelected=false, bool cotangentWeight=false, vcg::CallBackPos * cb=0) static void VertexCoordLaplacian(MeshType &m, int step, bool SmoothSelected=false, bool cotangentWeight=false, vcg::CallBackPos * cb=0)
{ {
VertexIterator vi;
LaplacianInfo lpz(CoordType(0,0,0),0); LaplacianInfo lpz(CoordType(0,0,0),0);
SimpleTempData<typename MeshType::VertContainer,LaplacianInfo > TD(m.vert,lpz); SimpleTempData<typename MeshType::VertContainer,LaplacianInfo > TD(m.vert,lpz);
for(int i=0;i<step;++i) for(int i=0;i<step;++i)
@ -266,7 +265,7 @@ static void VertexCoordLaplacian(MeshType &m, int step, bool SmoothSelected=fals
if(cb)cb(100*i/step, "Classic Laplacian Smoothing"); if(cb)cb(100*i/step, "Classic Laplacian Smoothing");
TD.Init(lpz); TD.Init(lpz);
AccumulateLaplacianInfo(m,TD,cotangentWeight); AccumulateLaplacianInfo(m,TD,cotangentWeight);
for(vi=m.vert.begin();vi!=m.vert.end();++vi) for(auto vi=m.vert.begin();vi!=m.vert.end();++vi)
if(!(*vi).IsD() && TD[*vi].cnt>0 ) if(!(*vi).IsD() && TD[*vi].cnt>0 )
{ {
if(!SmoothSelected || (*vi).IsS()) if(!SmoothSelected || (*vi).IsS())
@ -278,8 +277,6 @@ static void VertexCoordLaplacian(MeshType &m, int step, bool SmoothSelected=fals
// Same of above but moves only the vertices that do not change FaceOrientation more that the given threshold // Same of above but moves only the vertices that do not change FaceOrientation more that the given threshold
static void VertexCoordPlanarLaplacian(MeshType &m, int step, float AngleThrRad = math::ToRad(1.0), bool SmoothSelected=false, vcg::CallBackPos * cb=0) static void VertexCoordPlanarLaplacian(MeshType &m, int step, float AngleThrRad = math::ToRad(1.0), bool SmoothSelected=false, vcg::CallBackPos * cb=0)
{ {
VertexIterator vi;
FaceIterator fi;
LaplacianInfo lpz(CoordType(0,0,0),0); LaplacianInfo lpz(CoordType(0,0,0),0);
SimpleTempData<typename MeshType::VertContainer,LaplacianInfo > TD(m.vert,lpz); SimpleTempData<typename MeshType::VertContainer,LaplacianInfo > TD(m.vert,lpz);
for(int i=0;i<step;++i) for(int i=0;i<step;++i)
@ -287,14 +284,15 @@ static void VertexCoordPlanarLaplacian(MeshType &m, int step, float AngleThrRad
if(cb)cb(100*i/step, "Planar Laplacian Smoothing"); if(cb)cb(100*i/step, "Planar Laplacian Smoothing");
TD.Init(lpz); TD.Init(lpz);
AccumulateLaplacianInfo(m,TD); AccumulateLaplacianInfo(m,TD);
for(vi=m.vert.begin();vi!=m.vert.end();++vi) // First normalize the AccumulateLaplacianInfo
for(auto vi=m.vert.begin();vi!=m.vert.end();++vi)
if(!(*vi).IsD() && TD[*vi].cnt>0 ) if(!(*vi).IsD() && TD[*vi].cnt>0 )
{ {
if(!SmoothSelected || (*vi).IsS()) if(!SmoothSelected || (*vi).IsS())
TD[*vi].sum = ( (*vi).P() + TD[*vi].sum)/(TD[*vi].cnt+1); TD[*vi].sum = ( (*vi).P() + TD[*vi].sum)/(TD[*vi].cnt+1);
} }
for(fi=m.face.begin();fi!=m.face.end();++fi){ for(auto fi=m.face.begin();fi!=m.face.end();++fi){
if(!(*fi).IsD()){ if(!(*fi).IsD()){
for (int j = 0; j < 3; ++j) { for (int j = 0; j < 3; ++j) {
if(Angle( Normal(TD[(*fi).V0(j)].sum, (*fi).P1(j), (*fi).P2(j) ), if(Angle( Normal(TD[(*fi).V0(j)].sum, (*fi).P1(j), (*fi).P2(j) ),
@ -303,7 +301,7 @@ static void VertexCoordPlanarLaplacian(MeshType &m, int step, float AngleThrRad
} }
} }
} }
for(fi=m.face.begin();fi!=m.face.end();++fi){ for(auto fi=m.face.begin();fi!=m.face.end();++fi){
if(!(*fi).IsD()){ if(!(*fi).IsD()){
for (int j = 0; j < 3; ++j) { for (int j = 0; j < 3; ++j) {
if(Angle( Normal(TD[(*fi).V0(j)].sum, TD[(*fi).V1(j)].sum, (*fi).P2(j) ), if(Angle( Normal(TD[(*fi).V0(j)].sum, TD[(*fi).V1(j)].sum, (*fi).P2(j) ),
@ -316,16 +314,11 @@ static void VertexCoordPlanarLaplacian(MeshType &m, int step, float AngleThrRad
} }
} }
for(vi=m.vert.begin();vi!=m.vert.end();++vi) for(auto vi=m.vert.begin();vi!=m.vert.end();++vi)
if(!(*vi).IsD() && TD[*vi].cnt>0 ) if(!(*vi).IsD() && TD[*vi].cnt>0 )
if(!SmoothSelected || (*vi).IsS()) if(!SmoothSelected || (*vi).IsS())
(*vi).P()= TD[*vi].sum; (*vi).P()= TD[*vi].sum;
} // end step } // end step
} }
static void VertexCoordLaplacianBlend(MeshType &m, int step, float alpha, bool SmoothSelected=false) static void VertexCoordLaplacianBlend(MeshType &m, int step, float alpha, bool SmoothSelected=false)