24 #ifndef __VCG_TRI_UPDATE_NORMALS 
   25 #define __VCG_TRI_UPDATE_NORMALS 
   27 #include <vcg/space/triangle3.h> 
   28 #include <vcg/complex/base.h> 
   30 #include <vcg/complex/algorithms/polygon_support.h> 
   49 template <
class ComputeMeshType>
 
   53 typedef ComputeMeshType MeshType;
 
   54 typedef typename MeshType::VertexType     VertexType;
 
   55 typedef typename MeshType::CoordType     CoordType;
 
   56 typedef typename VertexType::NormalType     NormalType;
 
   57 typedef typename VertexType::ScalarType ScalarType;
 
   58 typedef typename MeshType::VertexPointer  VertexPointer;
 
   59 typedef typename MeshType::VertexIterator VertexIterator;
 
   60 typedef typename MeshType::FaceType       FaceType;
 
   61 typedef typename MeshType::FacePointer    FacePointer;
 
   62 typedef typename MeshType::FaceIterator   FaceIterator;
 
   69 static void PerVertexClear(ComputeMeshType &m, 
bool ClearAllVertNormal=
false)
 
   71   RequirePerVertexNormal(m);
 
   72   if(ClearAllVertNormal)
 
   77     for(FaceIterator f=m.face.begin();f!=m.face.end();++f)
 
   79        for(
int i=0;i<3;++i) (*f).V(i)->ClearV();
 
   82   for(vi=m.vert.begin();vi!=m.vert.end();++vi)
 
   83      if( !(*vi).IsD() && (*vi).IsRW() && (!(*vi).IsV()) )
 
   84          (*vi).N() = NormalType((ScalarType)0,(ScalarType)0,(ScalarType)0);
 
   94  for(FaceIterator f=m.face.begin();f!=m.face.end();++f)
 
   95    if( !(*f).IsD() && (*f).IsR() )
 
   97     typename VertexType::NormalType t = vcg::TriangleNormal(*f);
 
   99     for(
int j=0; j<(*f).VN(); ++j)
 
  100      if( !(*f).V(j)->IsD() && (*f).V(j)->IsRW() )
 
  105 static void PerFacePolygonal(ComputeMeshType &m)
 
  107   RequirePerFaceNormal(m);  
 
  108   for(FaceIterator fi=m.face.begin();fi!=m.face.end();++fi)
 
  111       fi->N() = PolygonNormal(*fi).Normalize();
 
  128   for(f=m.face.begin();f!=m.face.end();++f)
 
  129    if( !(*f).IsD() && (*f).IsR() )
 
  131         NormalType t = TriangleNormal(*f).Normalize();
 
  132         NormalType e0 = ((*f).V1(0)->cP()-(*f).V0(0)->cP()).Normalize();
 
  133         NormalType e1 = ((*f).V1(1)->cP()-(*f).V0(1)->cP()).Normalize();
 
  134         NormalType e2 = ((*f).V1(2)->cP()-(*f).V0(2)->cP()).Normalize();
 
  136         (*f).V(0)->N() += t*AngleN(e0,-e2);
 
  137         (*f).V(1)->N() += t*AngleN(-e0,e1);
 
  138         (*f).V(2)->N() += t*AngleN(-e1,e2);
 
  154  for(f=m.face.begin();f!=m.face.end();++f)
 
  155    if( !(*f).IsD() && (*f).IsR() )
 
  157     typename FaceType::NormalType t = TriangleNormal(*f);
 
  158         ScalarType e0 = SquaredDistance((*f).V0(0)->cP(),(*f).V1(0)->cP());
 
  159         ScalarType e1 = SquaredDistance((*f).V0(1)->cP(),(*f).V1(1)->cP());
 
  160         ScalarType e2 = SquaredDistance((*f).V0(2)->cP(),(*f).V1(2)->cP());
 
  162         (*f).V(0)->N() += t/(e0*e2);
 
  163         (*f).V(1)->N() += t/(e0*e1);
 
  164         (*f).V(2)->N() += t/(e1*e2);
 
  173   RequirePerFaceNormal(m);
 
  174   for(FaceIterator f=m.face.begin();f!=m.face.end();++f)
 
  176               f->N() = TriangleNormal(*f);
 
  184   tri::RequirePerFaceNormal(m);
 
  185   tri::RequirePolygonalMesh(m);
 
  186   for(FaceIterator fi = m.face.begin(); fi != m.face.end(); fi++)
 
  189       for (
int i = 0; i < fi->VN(); i++)
 
  190         fi->N() += fi->V0(i)->P() ^ fi->V1(i)->P();
 
  201   tri::RequirePerVertexNormal(m);
 
  204  for(vi=m.vert.begin();vi!=m.vert.end();++vi)
 
  205    if( !(*vi).IsD() && (*vi).IsRW() )
 
  206      (*vi).N()=CoordType(0,0,0);
 
  209  for(fi=m.face.begin();fi!=m.face.end();++fi)
 
  212     for(
int j=0; j<(*fi).VN(); ++j)
 
  213             if( !(*fi).V(j)->IsD())
 
  214                     (*fi).V(j)->N() += (*fi).cN();
 
  224   tri::RequirePerVertexNormal(m);
 
  225   tri::RequirePerFaceNormal(m);
 
  226   for (FaceIterator fi=m.face.begin(); fi!=m.face.end(); ++fi)
 
  231         for(
int j=0; j<3; ++j)
 
  241   tri::RequirePerVertexNormal(m);
 
  242   for(VertexIterator vi=m.vert.begin();vi!=m.vert.end();++vi)
 
  243         if( !(*vi).IsD() && (*vi).IsRW() )
 
  244             (*vi).N().Normalize();
 
  250   tri::RequirePerFaceNormal(m);
 
  251   for(FaceIterator fi=m.face.begin();fi!=m.face.end();++fi)
 
  252       if( !(*fi).IsD() )    (*fi).N().Normalize();
 
  258   tri::RequirePerFaceNormal(m);
 
  260   for(fi=m.face.begin();fi!=m.face.end();++fi)
 
  263                 (*fi).N().Normalize();
 
  264                 (*fi).N() = (*fi).N() * DoubleArea(*fi);
 
  313     for(FaceIterator f=m.face.begin();f!=m.face.end();++f) {
 
  315         for (
int k=0; k<3; k++) 
if (f->IsF(k))
 
  316         if (&*f < f->FFp(k)) {
 
  317           f->N() = f->FFp(k)->N() = (f->FFp(k)->N() + f->N()).Normalize();
 
  328   tri::RequireCompactness(m);
 
  329   tri::RequireTriangularMesh(m);
 
  331   std::vector<VertexPointer> vertVec;
 
  332   std::vector<FacePointer> faceVec;
 
  333   for(
size_t i=0;i<m.face.size();++i)
 
  336       tri::PolygonSupport<MeshType,MeshType>::ExtractPolygon(&(m.face[i]),vertVec,faceVec);
 
  338       for(
size_t j=0;j<faceVec.size();++j)
 
  339         nf+=faceVec[j]->N().Normalize() * DoubleArea(*faceVec[j]);
 
  343       for(
size_t j=0;j<faceVec.size();++j)
 
  348 static void PerVertexMatrix(ComputeMeshType &m, 
const Matrix44<ScalarType> &mat, 
bool remove_scaling= 
true)
 
  350     tri::RequirePerVertexNormal(m);
 
  353     Matrix33<ScalarType> mat33(mat,3);
 
  357         scale = pow(mat33.Determinant(),(ScalarType)(1.0/3.0));
 
  359         Matrix33<ScalarType> S;
 
  360         S.SetDiagonal(scaleV.V());
 
  364     for(VertexIterator vi=m.vert.begin();vi!=m.vert.end();++vi)
 
  365         if( !(*vi).IsD() && (*vi).IsRW() )
 
  366             (*vi).N()  = mat33*(*vi).N();
 
  370 static void PerFaceMatrix(ComputeMeshType &m, 
const Matrix44<ScalarType> &mat, 
bool remove_scaling= 
true)
 
  372     tri::RequirePerFaceNormal(m);
 
  375     Matrix33<ScalarType> mat33(mat,3);
 
  377     if( !HasPerFaceNormal(m)) 
return;
 
  380         scale = pow(mat33.Determinant(),ScalarType(1.0/3.0));
 
  386     for(FaceIterator fi=m.face.begin();fi!=m.face.end();++fi)
 
  387         if( !(*fi).IsD() && (*fi).IsRW() )
 
  388             (*fi).N() = mat33* (*fi).N();
 
  397   tri::RequirePerFaceWedgeNormal(m);
 
  398   tri::RequireFFAdjacency(m);
 
  400   ScalarType cosangle=math::Cos(angleRad);
 
  403   for(FaceIterator fi=m.face.begin();fi!=m.face.end();++fi) 
if(!(*fi).IsD())
 
  405     (*fi).WN(0)=NormalType(0,0,0);
 
  406     (*fi).WN(1)=NormalType(0,0,0);
 
  407     (*fi).WN(2)=NormalType(0,0,0);
 
  410   for(FaceIterator fi=m.face.begin();fi!=m.face.end();++fi)      
if(!(*fi).IsD())
 
  412     NormalType nn= TriangleNormal(*fi);
 
  415       const NormalType &na=TriangleNormal(*(*fi).FFp(i));
 
  416       if(nn*na > cosangle )
 
  418         fi->WN((i+0)%3) +=na;
 
  419         fi->WN((i+1)%3) +=na;
 
  426 static void PerFaceRW(ComputeMeshType &m, 
bool normalize=
false)
 
  428   tri::RequirePerFaceNormal(m);
 
  434         for(f=m.m.face.begin();f!=m.m.face.end();++f)
 
  435         if( !(*f).IsD() && (*f).IsRW() )
 
  437             for(
int j=0; j<3; ++j)
 
  438                 if( !(*f).V(j)->IsR())  cn = 
false;
 
  439       if( cn )     f->N() = TriangleNormal(*f).Normalize();
 
  445         for(f=m.m.face.begin();f!=m.m.face.end();++f)
 
  446             if( !(*f).IsD() && (*f).IsRW() )
 
  448                 for(
int j=0; j<3; ++j)
 
  449                     if( !(*f).V(j)->IsR())  cn = 
false;
 
  452                   f->N() = TriangleNormal(*f).Normalize();
 
Management, updating and computation of per-vertex and per-face flags (like border flags).
Definition: flag.h:44
 
Management, updating and computation of per-vertex, per-face, and per-wedge normals.
Definition: normal.h:51
 
static void PerWedgeCrease(ComputeMeshType &m, ScalarType angleRad)
Compute per wedge normals taking into account the angle between adjacent faces.
Definition: normal.h:395
 
static void NormalizePerVertex(ComputeMeshType &m)
Normalize the length of the vertex normals.
Definition: normal.h:239
 
static void PerVertexAngleWeighted(ComputeMeshType &m)
Calculates the vertex normal as an angle weighted average. It does not need or exploit current face n...
Definition: normal.h:124
 
static void PerVertexMatrix(ComputeMeshType &m, const Matrix44< ScalarType > &mat, bool remove_scaling=true)
Multiply the vertex normals by the matrix passed. By default, the scale component is removed.
Definition: normal.h:348
 
static void PerBitQuadFaceNormalized(ComputeMeshType &m)
Exploit bitquads to compute a per-polygon face normal.
Definition: normal.h:310
 
static void PerVertexNelsonMaxWeighted(ComputeMeshType &m)
Calculates the vertex normal using the Max et al. weighting scheme. It does not need or exploit curre...
Definition: normal.h:150
 
static void PerFaceNormalized(ComputeMeshType &m)
Equivalent to PerFace() and NormalizePerFace()
Definition: normal.h:276
 
static void PerVertex(ComputeMeshType &m)
Calculates the vertex normal as the classic area weighted average. It does not need or exploit curren...
Definition: normal.h:91
 
static void PerVertexNormalized(ComputeMeshType &m)
Equivalent to PerVertex() and NormalizePerVertex()
Definition: normal.h:269
 
static void PerFaceFromCurrentVertexNormal(ComputeMeshType &m)
Calculates the face normal by averaging the current per-vertex normals.
Definition: normal.h:222
 
static void PerVertexClear(ComputeMeshType &m, bool ClearAllVertNormal=false)
Set to zero all the PerVertex normals.
Definition: normal.h:69
 
static void PerVertexFromCurrentFaceNormal(ComputeMeshType &m)
Calculates the vertex normal by averaging the current per-face normals.
Definition: normal.h:199
 
static void PerBitPolygonFaceNormalized(ComputeMeshType &m)
Exploit bitquads to compute a per-polygon face normal.
Definition: normal.h:325
 
static void PerPolygonalFaceNormalized(ComputeMeshType &m)
Equivalent to PerPolygonalFace() and NormalizePerFace()
Definition: normal.h:283
 
static void PerVertexPerFace(ComputeMeshType &m)
Equivalent to PerVertex() and PerFace().
Definition: normal.h:289
 
static void PerFace(ComputeMeshType &m)
Calculates the face normal.
Definition: normal.h:171
 
static void PerVertexNormalizedPerFaceNormalized(ComputeMeshType &m)
Equivalent to PerVertexNormalizedPerFace() and NormalizePerFace().
Definition: normal.h:303
 
static void PerPolygonalFace(ComputeMeshType &m)
computePerPolygonalFace computes the normal of each polygonal face.
Definition: normal.h:183
 
static void PerFaceMatrix(ComputeMeshType &m, const Matrix44< ScalarType > &mat, bool remove_scaling=true)
Multiply the face normals by the matrix passed. By default, the scale component is removed.
Definition: normal.h:370
 
static void PerVertexNormalizedPerFace(ComputeMeshType &m)
Equivalent to PerVertexNormalized() and PerFace().
Definition: normal.h:296
 
static void NormalizePerFace(ComputeMeshType &m)
Normalize the length of the face normals.
Definition: normal.h:248
 
static void NormalizePerFaceByArea(ComputeMeshType &m)
Set the length of the face normals to their area (without recomputing their directions).
Definition: normal.h:256
 
Definition: namespaces.dox:6