Updated to reflect the Normal() -> TriangleNormal() change
And added function to compute normals per polygonal faces
This commit is contained in:
parent
884795203c
commit
18d91de047
|
@ -89,12 +89,10 @@ static void PerVertexClear(ComputeMeshType &m, bool ClearAllVertNormal=false)
|
||||||
static void PerVertex(ComputeMeshType &m)
|
static void PerVertex(ComputeMeshType &m)
|
||||||
{
|
{
|
||||||
PerVertexClear(m);
|
PerVertexClear(m);
|
||||||
FaceIterator f;
|
for(FaceIterator f=m.face.begin();f!=m.face.end();++f)
|
||||||
for(f=m.face.begin();f!=m.face.end();++f)
|
|
||||||
if( !(*f).IsD() && (*f).IsR() )
|
if( !(*f).IsD() && (*f).IsR() )
|
||||||
{
|
{
|
||||||
//typename FaceType::NormalType t = (*f).Normal();
|
typename FaceType::NormalType t = vcg::TriangleNormal(*f);
|
||||||
typename FaceType::NormalType t = vcg::Normal(*f);
|
|
||||||
|
|
||||||
for(int j=0; j<(*f).VN(); ++j)
|
for(int j=0; j<(*f).VN(); ++j)
|
||||||
if( !(*f).V(j)->IsD() && (*f).V(j)->IsRW() )
|
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.
|
/// \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.
|
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)
|
for(f=m.face.begin();f!=m.face.end();++f)
|
||||||
if( !(*f).IsD() && (*f).IsR() )
|
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 e0 = ((*f).V1(0)->cP()-(*f).V0(0)->cP()).Normalize();
|
||||||
NormalType e1 = ((*f).V1(1)->cP()-(*f).V0(1)->cP()).Normalize();
|
NormalType e1 = ((*f).V1(1)->cP()-(*f).V0(1)->cP()).Normalize();
|
||||||
NormalType e2 = ((*f).V1(2)->cP()-(*f).V0(2)->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)
|
for(f=m.face.begin();f!=m.face.end();++f)
|
||||||
if( !(*f).IsD() && (*f).IsR() )
|
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 e0 = SquaredDistance((*f).V0(0)->cP(),(*f).V1(0)->cP());
|
||||||
ScalarType e1 = SquaredDistance((*f).V0(1)->cP(),(*f).V1(1)->cP());
|
ScalarType e1 = SquaredDistance((*f).V0(1)->cP(),(*f).V1(1)->cP());
|
||||||
ScalarType e2 = SquaredDistance((*f).V0(2)->cP(),(*f).V1(2)->cP());
|
ScalarType e2 = SquaredDistance((*f).V0(2)->cP(),(*f).V1(2)->cP());
|
||||||
|
@ -163,7 +170,7 @@ static void PerFace(ComputeMeshType &m)
|
||||||
RequirePerFaceNormal(m);
|
RequirePerFaceNormal(m);
|
||||||
for(FaceIterator f=m.face.begin();f!=m.face.end();++f)
|
for(FaceIterator f=m.face.begin();f!=m.face.end();++f)
|
||||||
if( !(*f).IsD() )
|
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())
|
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)
|
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 )
|
if(nn*na > cosangle )
|
||||||
{
|
{
|
||||||
fi->WN((i+0)%3) +=na;
|
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)
|
for(int j=0; j<3; ++j)
|
||||||
if( !(*f).V(j)->IsR()) cn = false;
|
if( !(*f).V(j)->IsR()) cn = false;
|
||||||
if( cn ) face::ComputeNormalizedNormal(*f);
|
if( cn ) f->N() = TriangleNormal(*f).Normalize();
|
||||||
cn = true;
|
cn = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -438,7 +445,7 @@ static void PerFaceRW(ComputeMeshType &m, bool normalize=false)
|
||||||
if( !(*f).V(j)->IsR()) cn = false;
|
if( !(*f).V(j)->IsR()) cn = false;
|
||||||
|
|
||||||
if( cn )
|
if( cn )
|
||||||
(*f).ComputeNormal();
|
f->N() = TriangleNormal(*f).Normalize();
|
||||||
cn = true;
|
cn = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue