Added method PerBitPolygonFaceNormalized for computing normals for polygonal meshes kept with fauxbit.

Added a few Require just for safety
This commit is contained in:
Paolo Cignoni 2014-05-20 22:30:59 +00:00
parent 44741d7f36
commit 8ba0e6d6aa
1 changed files with 109 additions and 89 deletions

View File

@ -25,6 +25,7 @@
#define __VCG_TRI_UPDATE_NORMALS
#include <vcg/complex/algorithms/update/flag.h>
#include <vcg/complex/algorithms/polygon_support.h>
#include <vcg/math/matrix44.h>
#include <vcg/complex/exception.h>
@ -170,15 +171,13 @@ static void PerFace(ComputeMeshType &m)
///
/// Not normalized. Use PerPolygonalFaceNormalized() or call NormalizePerFace() if you need unit length per face normals.
static void PerPolygonalFace(ComputeMeshType &m) {
// check input type mesh
if (!HasPerFaceNormal(m))
throw vcg::MissingComponentException("PerFaceNormal");
// for each face
for(FaceIterator f = m.face.begin(); f != m.face.end(); f++)
if (!f->IsD()) {
f->N().SetZero();
for (int v = 0; v < f->VN(); v++)
f->N() += f->V(v)->P() ^ f->V((v+1)%f->VN())->P();
tri::RequirePerFaceNormal(m);
tri::RequirePolygonalMesh(m);
for(FaceIterator fi = m.face.begin(); fi != m.face.end(); fi++)
if (!fi->IsD()) {
fi->N().SetZero();
for (int i = 0; i < fi->VN(); i++)
fi->N() += fi->V0(i)->P() ^ fi->V1(i)->P();
}
}
@ -272,9 +271,7 @@ static void PerFaceNormalized(ComputeMeshType &m)
/// \brief Equivalent to PerPolygonalFace() and NormalizePerFace()
static void PerPolygonalFaceNormalized(ComputeMeshType &m) {
// compute normals
PerPolygonalFace(m);
// normalize them
NormalizePerFace(m);
}
@ -303,8 +300,7 @@ static void PerVertexNormalizedPerFaceNormalized(ComputeMeshType &m)
static void PerBitQuadFaceNormalized(ComputeMeshType &m)
{
PerFace(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() ) {
for (int k=0; k<3; k++) if (f->IsF(k))
if (&*f < f->FFp(k)) {
@ -314,6 +310,30 @@ static void PerBitQuadFaceNormalized(ComputeMeshType &m)
}
}
/// \brief Exploit bitquads to compute a per-polygon face normal
static void PerBitPolygonFaceNormalized(ComputeMeshType &m)
{
PerFace(m);
tri::RequireCompactness(m);
tri::RequireTriangularMesh(m);
tri::UpdateFlags<ComputeMeshType>::FaceClearV(m);
std::vector<VertexPointer> vertVec;
std::vector<FacePointer> faceVec;
for(size_t i=0;i<m.face.size();++i)
if(!m.face[i].IsV())
{
tri::PolygonSupport<MeshType,MeshType>::ExtractPolygon(&(m.face[i]),vertVec,faceVec);
CoordType nf(0,0,0);
for(size_t j=0;j<faceVec.size();++j)
nf+=faceVec[j]->N().Normalize() * DoubleArea(*faceVec[j]);
nf.Normalize();
for(size_t j=0;j<faceVec.size();++j)
faceVec[j]->N()=nf;
}
}
/// \brief Multiply the vertex normals by the matrix passed. By default, the scale component is removed.
static void PerVertexMatrix(ComputeMeshType &m, const Matrix44<ScalarType> &mat, bool remove_scaling= true)
{