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,7 +831,9 @@ public:
class PDFaceInfo class PDFaceInfo
{ {
public: public:
CoordType m; PDFaceInfo(){}
PDFaceInfo(const CoordType &_m):m(_m){}
CoordType m;
}; };
/***************************************************************************/ /***************************************************************************/
// Paso Doble Step 1 compute the smoothed normals // Paso Doble Step 1 compute the smoothed normals
@ -896,59 +898,49 @@ 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; CoordType bc=Barycenter<FaceType>(*fi);
// 1) Clear all the visited flag of faces that are vertex-adjacent to fi
FaceIterator fi; for(int i=0;i<3;++i)
tri::UpdateNormal<MeshType>::AreaNormalizeFace(m);
for(fi=m.face.begin();fi!=m.face.end();++fi) if(!(*fi).IsD())
{ {
CoordType bc=Barycenter<FaceType>(*fi); VFLocalIterator ep(&*fi,i);
// 1) Clear all the visited flag of faces that are vertex-adjacent to fi for (;!ep.End();++ep)
for(i=0;i<3;++i) ep.f->ClearV();
{
VFLocalIterator ep(&*fi,i);
for (;!ep.End();++ep)
ep.f->ClearV();
}
// 2) Effectively average the normals
CoordType normalSum=(*fi).N();
for(i=0;i<3;++i)
{
VFLocalIterator ep(&*fi,i);
for (;!ep.End();++ep)
{
if(! (*ep.f).IsV() )
{
normalSum += ep.f->N();
(*ep.f).SetV();
}
}
}
normalSum.Normalize();
TDF[*fi].m=normalSum;
} }
for(fi=m.face.begin();fi!=m.face.end();++fi)
(*fi).N()=TDF[*fi].m;
tri::UpdateNormal<MeshType>::NormalizePerFace(m); // 2) Effectively average the normals
CoordType normalSum=(*fi).N();
TDF.Stop(); for(int i=0;i<3;++i)
{
VFLocalIterator ep(&*fi,i);
for (;!ep.End();++ep)
{
if(! (*ep.f).IsV() )
{
normalSum += ep.f->N();
(*ep.f).SetV();
}
}
}
normalSum.Normalize();
TDF[*fi].m=normalSum;
}
for(FaceIterator fi=m.face.begin();fi!=m.face.end();++fi)
(*fi).N()=TDF[*fi].m;
tri::UpdateNormal<MeshType>::NormalizePerFace(m);
} }
// 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);