Updated to reflect the Normal() -> TriangleNormal() change

And added function to compute normals per polygonal faces
This commit is contained in:
Paolo Cignoni 2014-11-12 00:09:58 +00:00
parent 884795203c
commit 18d91de047
1 changed files with 20 additions and 13 deletions

View File

@ -89,12 +89,10 @@ static void PerVertexClear(ComputeMeshType &m, bool ClearAllVertNormal=false)
static void PerVertex(ComputeMeshType &m)
{
PerVertexClear(m);
FaceIterator f;
for(f=m.face.begin();f!=m.face.end();++f)
for(FaceIterator f=m.face.begin();f!=m.face.end();++f)
if( !(*f).IsD() && (*f).IsR() )
{
//typename FaceType::NormalType t = (*f).Normal();
typename FaceType::NormalType t = vcg::Normal(*f);
typename FaceType::NormalType t = vcg::TriangleNormal(*f);
for(int j=0; j<(*f).VN(); ++j)
if( !(*f).V(j)->IsD() && (*f).V(j)->IsRW() )
@ -102,6 +100,15 @@ static void PerVertexClear(ComputeMeshType &m, bool ClearAllVertNormal=false)
}
}
static void PerFacePolygonal(ComputeMeshType &m)
{
for(FaceIterator fi=m.face.begin();fi!=m.face.end();++fi)
{
if( !(*fi).IsD() )
fi->N() = PolygonNormal(*fi).Normalize();
}
}
/// \brief Calculates the vertex normal as an angle weighted average. It does not need or exploit current face normals.
/**
The normal of a vertex v computed as a weighted sum f the incident face normals.
@ -118,7 +125,7 @@ Journal of Graphics Tools, 1998
for(f=m.face.begin();f!=m.face.end();++f)
if( !(*f).IsD() && (*f).IsR() )
{
NormalType t = vcg::NormalizedNormal(*f);
NormalType t = TriangleNormal(*f).Normalize();
NormalType e0 = ((*f).V1(0)->cP()-(*f).V0(0)->cP()).Normalize();
NormalType e1 = ((*f).V1(1)->cP()-(*f).V0(1)->cP()).Normalize();
NormalType e2 = ((*f).V1(2)->cP()-(*f).V0(2)->cP()).Normalize();
@ -144,7 +151,7 @@ static void PerVertexNelsonMaxWeighted(ComputeMeshType &m)
for(f=m.face.begin();f!=m.face.end();++f)
if( !(*f).IsD() && (*f).IsR() )
{
typename FaceType::NormalType t = vcg::Normal(*f);
typename FaceType::NormalType t = TriangleNormal(*f);
ScalarType e0 = SquaredDistance((*f).V0(0)->cP(),(*f).V1(0)->cP());
ScalarType e1 = SquaredDistance((*f).V0(1)->cP(),(*f).V1(1)->cP());
ScalarType e2 = SquaredDistance((*f).V0(2)->cP(),(*f).V1(2)->cP());
@ -163,7 +170,7 @@ static void PerFace(ComputeMeshType &m)
RequirePerFaceNormal(m);
for(FaceIterator f=m.face.begin();f!=m.face.end();++f)
if( !(*f).IsD() )
face::ComputeNormal(*f);
f->N() = TriangleNormal(*f).Normalize();
}
@ -398,10 +405,10 @@ static void PerWedgeCrease(ComputeMeshType &m, ScalarType angleRad)
for(FaceIterator fi=m.face.begin();fi!=m.face.end();++fi) if(!(*fi).IsD())
{
NormalType nn= vcg::Normal(*fi);
NormalType nn= TriangleNormal(*fi);
for(int i=0;i<3;++i)
{
const NormalType &na=vcg::Normal(*(*fi).FFp(i));
const NormalType &na=TriangleNormal(*(*fi).FFp(i));
if(nn*na > cosangle )
{
fi->WN((i+0)%3) +=na;
@ -425,7 +432,7 @@ static void PerFaceRW(ComputeMeshType &m, bool normalize=false)
{
for(int j=0; j<3; ++j)
if( !(*f).V(j)->IsR()) cn = false;
if( cn ) face::ComputeNormalizedNormal(*f);
if( cn ) f->N() = TriangleNormal(*f).Normalize();
cn = true;
}
}
@ -438,7 +445,7 @@ static void PerFaceRW(ComputeMeshType &m, bool normalize=false)
if( !(*f).V(j)->IsR()) cn = false;
if( cn )
(*f).ComputeNormal();
f->N() = TriangleNormal(*f).Normalize();
cn = true;
}
}