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,74 +258,67 @@ 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) {
{ 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(auto vi=m.vert.begin();vi!=m.vert.end();++vi)
for(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() = ( (*vi).P() + TD[*vi].sum)/(TD[*vi].cnt+1);
(*vi).P() = ( (*vi).P() + TD[*vi].sum)/(TD[*vi].cnt+1); }
} }
}
} }
// 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; LaplacianInfo lpz(CoordType(0,0,0),0);
FaceIterator fi; SimpleTempData<typename MeshType::VertContainer,LaplacianInfo > TD(m.vert,lpz);
LaplacianInfo lpz(CoordType(0,0,0),0); for(int i=0;i<step;++i)
SimpleTempData<typename MeshType::VertContainer,LaplacianInfo > TD(m.vert,lpz); {
for(int i=0;i<step;++i) if(cb)cb(100*i/step, "Planar Laplacian Smoothing");
{ TD.Init(lpz);
if(cb)cb(100*i/step, "Planar Laplacian Smoothing"); AccumulateLaplacianInfo(m,TD);
TD.Init(lpz); // First normalize the AccumulateLaplacianInfo
AccumulateLaplacianInfo(m,TD); for(auto vi=m.vert.begin();vi!=m.vert.end();++vi)
for(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(auto fi=m.face.begin();fi!=m.face.end();++fi){
for(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) ), Normal( (*fi).P0(j) , (*fi).P1(j), (*fi).P2(j) ) ) > AngleThrRad )
Normal( (*fi).P0(j) , (*fi).P1(j), (*fi).P2(j) ) ) > AngleThrRad ) TD[(*fi).V0(j)].sum = (*fi).P0(j);
TD[(*fi).V0(j)].sum = (*fi).P0(j); }
} }
} }
} for(auto fi=m.face.begin();fi!=m.face.end();++fi){
for(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) ), Normal( (*fi).P0(j) , (*fi).P1(j), (*fi).P2(j) ) ) > AngleThrRad )
Normal( (*fi).P0(j) , (*fi).P1(j), (*fi).P2(j) ) ) > AngleThrRad ) {
{ TD[(*fi).V0(j)].sum = (*fi).P0(j);
TD[(*fi).V0(j)].sum = (*fi).P0(j); TD[(*fi).V1(j)].sum = (*fi).P1(j);
TD[(*fi).V1(j)].sum = (*fi).P1(j); }
} }
} }
} }
}
for(auto vi=m.vert.begin();vi!=m.vert.end();++vi)
for(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)