Refactored Smooth::FaceNormalLaplacianVF

This commit is contained in:
Paolo Cignoni 2014-02-19 15:27:01 +00:00
parent 2e18e0650a
commit 7cfd407a2f
1 changed files with 40 additions and 51 deletions

View File

@ -831,6 +831,8 @@ public:
class PDFaceInfo class PDFaceInfo
{ {
public: public:
PDFaceInfo(){}
PDFaceInfo(const CoordType &_m):m(_m){}
CoordType m; CoordType m;
}; };
/***************************************************************************/ /***************************************************************************/
@ -896,29 +898,21 @@ void FaceNormalFuzzyVectorSB(MeshType &m,
// Replace the normal of the face with the average of normals of the vertex adijacent faces. // Replace the normal of the face with the average of normals of the vertex adijacent faces.
// Normals are weighted with face area. // Normals are weighted with face area.
// It assumes that: // It assumes that:
// Normals are normalized:
// VF adjacency is present. // VF adjacency is present.
static void FaceNormalLaplacianVF(MeshType &m) static void FaceNormalLaplacianVF(MeshType &m)
{ {
SimpleTempData<typename MeshType::FaceContainer, PDFaceInfo> TDF(m.face); tri::RequireVFAdjacency(m);
PDFaceInfo lpzf(CoordType(0,0,0));
SimpleTempData<typename MeshType::FaceContainer, PDFaceInfo> TDF(m.face,lpzf);
PDFaceInfo lpzf; tri::UpdateNormal<MeshType>::NormalizePerFaceByArea(m);
lpzf.m=CoordType(0,0,0);
assert(tri::HasPerVertexVFAdjacency(m) && tri::HasPerFaceVFAdjacency(m) ); for(FaceIterator fi=m.face.begin();fi!=m.face.end();++fi) if(!(*fi).IsD())
TDF.Start(lpzf);
int i;
FaceIterator fi;
tri::UpdateNormal<MeshType>::AreaNormalizeFace(m);
for(fi=m.face.begin();fi!=m.face.end();++fi) if(!(*fi).IsD())
{ {
CoordType bc=Barycenter<FaceType>(*fi); CoordType bc=Barycenter<FaceType>(*fi);
// 1) Clear all the visited flag of faces that are vertex-adjacent to fi // 1) Clear all the visited flag of faces that are vertex-adjacent to fi
for(i=0;i<3;++i) for(int i=0;i<3;++i)
{ {
VFLocalIterator ep(&*fi,i); VFLocalIterator ep(&*fi,i);
for (;!ep.End();++ep) for (;!ep.End();++ep)
@ -928,7 +922,7 @@ static void FaceNormalLaplacianVF(MeshType &m)
// 2) Effectively average the normals // 2) Effectively average the normals
CoordType normalSum=(*fi).N(); CoordType normalSum=(*fi).N();
for(i=0;i<3;++i) for(int i=0;i<3;++i)
{ {
VFLocalIterator ep(&*fi,i); VFLocalIterator ep(&*fi,i);
for (;!ep.End();++ep) for (;!ep.End();++ep)
@ -943,12 +937,10 @@ static void FaceNormalLaplacianVF(MeshType &m)
normalSum.Normalize(); normalSum.Normalize();
TDF[*fi].m=normalSum; TDF[*fi].m=normalSum;
} }
for(fi=m.face.begin();fi!=m.face.end();++fi) for(FaceIterator fi=m.face.begin();fi!=m.face.end();++fi)
(*fi).N()=TDF[*fi].m; (*fi).N()=TDF[*fi].m;
tri::UpdateNormal<MeshType>::NormalizePerFace(m); tri::UpdateNormal<MeshType>::NormalizePerFace(m);
TDF.Stop();
} }
// Replace the normal of the face with the average of normals of the face adijacent faces. // Replace the normal of the face with the average of normals of the face adijacent faces.
@ -960,10 +952,9 @@ static void FaceNormalLaplacianVF(MeshType &m)
static void FaceNormalLaplacianFF(MeshType &m, int step=1, bool SmoothSelected=false ) static void FaceNormalLaplacianFF(MeshType &m, int step=1, bool SmoothSelected=false )
{ {
PDFaceInfo lpzf; PDFaceInfo lpzf(CoordType(0,0,0));
lpzf.m=CoordType(0,0,0);
SimpleTempData<typename MeshType::FaceContainer, PDFaceInfo> TDF(m.face,lpzf); SimpleTempData<typename MeshType::FaceContainer, PDFaceInfo> TDF(m.face,lpzf);
assert(tri::HasFFAdjacency(m)); tri::RequireFFAdjacency(m);
FaceIterator fi; FaceIterator fi;
tri::UpdateNormal<MeshType>::NormalizePerFaceByArea(m); tri::UpdateNormal<MeshType>::NormalizePerFaceByArea(m);
@ -1188,8 +1179,7 @@ static void VertexCoordPasoDoble(MeshType &m, int step, typename MeshType::Scala
SimpleTempData< typename MeshType::FaceContainer, PDFaceInfo> TDF(m.face); SimpleTempData< typename MeshType::FaceContainer, PDFaceInfo> TDF(m.face);
PDVertInfo lpzv; PDVertInfo lpzv;
lpzv.np=CoordType(0,0,0); lpzv.np=CoordType(0,0,0);
PDFaceInfo lpzf; PDFaceInfo lpzf(CoordType(0,0,0));
lpzf.m=CoordType(0,0,0);
assert(m.HasVFTopology()); assert(m.HasVFTopology());
m.HasVFTopology(); m.HasVFTopology();
@ -1215,8 +1205,7 @@ static void VertexCoordPasoDobleFast(MeshType &m, int NormalSmoothStep, typename
{ {
PDVertInfo lpzv; PDVertInfo lpzv;
lpzv.np=CoordType(0,0,0); lpzv.np=CoordType(0,0,0);
PDFaceInfo lpzf; PDFaceInfo lpzf(CoordType(0,0,0));
lpzf.m=CoordType(0,0,0);
assert(HasPerVertexVFAdjacency(m) && HasPerFaceVFAdjacency(m)); assert(HasPerVertexVFAdjacency(m) && HasPerFaceVFAdjacency(m));
SimpleTempData< typename MeshType::VertContainer, PDVertInfo> TDV(m.vert,lpzv); SimpleTempData< typename MeshType::VertContainer, PDVertInfo> TDV(m.vert,lpzv);