Cleaned up the UpdateFlags class. Assert into throw...

This commit is contained in:
Paolo Cignoni 2012-11-10 16:33:38 +00:00
parent aca80c215b
commit 9cea19e537
1 changed files with 311 additions and 376 deletions

View File

@ -19,72 +19,6 @@
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt) * * GNU General Public License (http://www.gnu.org/licenses/gpl.txt) *
* for more details. * * for more details. *
* * * *
****************************************************************************/
/****************************************************************************
History
$Log: not supported by cvs2svn $
Revision 1.20 2007/05/31 15:24:50 ponchio
FIxed off-by-one error on FaceBorderFromNone.
Revision 1.19 2007/05/22 15:19:42 cignoni
Added VertexClear
Revision 1.18 2007/01/30 18:49:23 tarini
aggiunta la VertexBorderFromNone (flag bordo per vertici senza richiedere nulla)
Revision 1.17 2006/08/31 13:11:12 marfr960
corrected bounds of a vector scan
Revision 1.16 2006/08/30 12:59:49 marfr960
Added missing std:: to swap
Revision 1.15 2006/08/30 06:50:07 cignoni
Reverted to version 1.13. Version 1.14 was done on outdated version.
Revision 1.13 2006/06/18 20:49:30 cignoni
Added missing IsD tests
Revision 1.12 2006/05/03 21:23:25 cignoni
Corrected IsDeleted -> isD
Revision 1.11 2005/12/02 00:09:12 cignoni
Added assert(HasFlags) everywhere..
Revision 1.10 2005/07/06 08:16:34 ganovelli
set VertexBorderFromFace as static
Revision 1.9 2005/06/10 15:07:23 cignoni
Completed FaceBorderFromNone (and added a missing helper class)
Revision 1.8 2005/04/01 13:04:55 fiorin
Minor changes
Revision 1.7 2004/09/14 19:49:43 ganovelli
first compilation version
Revision 1.6 2004/07/15 00:13:39 cignoni
Better doxigen documentation
Revision 1.5 2004/07/06 06:27:02 cignoni
Added FaceBorderFromVF
Revision 1.4 2004/05/13 15:58:55 ganovelli
function Clear added
Revision 1.3 2004/03/12 15:22:19 cignoni
Written some documentation and added to the trimes doxygen module
Revision 1.2 2004/03/10 00:46:10 cignoni
changed to the face::IsBorder() style
Revision 1.1 2004/03/05 10:59:24 cignoni
Changed name from plural to singular (normals->normal)
Revision 1.1 2004/03/04 00:37:56 cignoni
First working version!
****************************************************************************/ ****************************************************************************/
#ifndef __VCG_TRI_UPDATE_FLAGS #ifndef __VCG_TRI_UPDATE_FLAGS
#define __VCG_TRI_UPDATE_FLAGS #define __VCG_TRI_UPDATE_FLAGS
@ -108,111 +42,111 @@ class UpdateFlags
{ {
public: public:
typedef UpdateMeshType MeshType; typedef UpdateMeshType MeshType;
typedef vcg::face::Pos<typename UpdateMeshType::FaceType> PosType; typedef vcg::face::Pos<typename UpdateMeshType::FaceType> PosType;
typedef typename MeshType::ScalarType ScalarType; typedef typename MeshType::ScalarType ScalarType;
typedef typename MeshType::VertexType VertexType; typedef typename MeshType::VertexType VertexType;
typedef typename MeshType::VertexPointer VertexPointer; typedef typename MeshType::VertexPointer VertexPointer;
typedef typename MeshType::VertexIterator VertexIterator; typedef typename MeshType::VertexIterator VertexIterator;
typedef typename MeshType::EdgeType EdgeType; typedef typename MeshType::EdgeType EdgeType;
typedef typename MeshType::EdgePointer EdgePointer; typedef typename MeshType::EdgePointer EdgePointer;
typedef typename MeshType::EdgeIterator EdgeIterator; typedef typename MeshType::EdgeIterator EdgeIterator;
typedef typename MeshType::FaceType FaceType; typedef typename MeshType::FaceType FaceType;
typedef typename MeshType::FacePointer FacePointer; typedef typename MeshType::FacePointer FacePointer;
typedef typename MeshType::FaceIterator FaceIterator; typedef typename MeshType::FaceIterator FaceIterator;
/// \brief Reset all the mesh flags (both vertexes and faces) setting everithing to zero (the default value for flags) /// \brief Reset all the mesh flags (vertexes edge faces) setting everithing to zero (the default value for flags)
static void Clear(MeshType &m) static void Clear(MeshType &m)
{ {
assert(HasPerFaceFlags(m)); if(HasPerVertexFlags(m) )
FaceIterator fi; for(VertexIterator vi=m.vert.begin(); vi!=m.vert.end(); ++vi)
VertexIterator vi;
for(fi=m.face.begin(); fi!=m.face.end(); ++fi)
(*fi).Flags() = 0;
for(vi=m.vert.begin(); vi!=m.vert.end(); ++vi)
(*vi).Flags() = 0; (*vi).Flags() = 0;
} if(HasPerEdgeFlags(m) )
for(EdgeIterator ei=m.edge.begin(); ei!=m.edge.end(); ++ei)
(*ei).Flags() = 0;
if(HasPerFaceFlags(m) )
for(FaceIterator fi=m.face.begin(); fi!=m.face.end(); ++fi)
(*fi).Flags() = 0;
}
static void VertexClear(MeshType &m, unsigned int FlagMask = 0xffffffff) static void VertexClear(MeshType &m, unsigned int FlagMask = 0xffffffff)
{ {
VertexIterator vi; if(!HasPerVertexFlags(m)) throw vcg::MissingComponentException("VertexFlags");
int andMask = ~FlagMask; int andMask = ~FlagMask;
for(vi=m.vert.begin(); vi!=m.vert.end(); ++vi) for(VertexIterator vi=m.vert.begin(); vi!=m.vert.end(); ++vi)
if(!(*vi).IsD()) (*vi).Flags() &= andMask ; if(!(*vi).IsD()) (*vi).Flags() &= andMask ;
} }
static void EdgeClear(MeshType &m, unsigned int FlagMask = 0xffffffff)
{ static void EdgeClear(MeshType &m, unsigned int FlagMask = 0xffffffff)
EdgeIterator ei; {
if(!HasPerEdgeFlags(m)) throw vcg::MissingComponentException("EdgeFlags");
int andMask = ~FlagMask; int andMask = ~FlagMask;
for(ei=m.edge.begin(); ei!=m.edge.end(); ++ei) for(EdgeIterator ei=m.edge.begin(); ei!=m.edge.end(); ++ei)
if(!(*ei).IsD()) (*ei).Flags() &= andMask ; if(!(*ei).IsD()) (*ei).Flags() &= andMask ;
} }
static void FaceClear(MeshType &m, unsigned int FlagMask = 0xffffffff)
{ static void FaceClear(MeshType &m, unsigned int FlagMask = 0xffffffff)
FaceIterator fi; {
if(!HasPerFaceFlags(m)) throw vcg::MissingComponentException("FaceFlags");
int andMask = ~FlagMask; int andMask = ~FlagMask;
for(fi=m.face.begin(); fi!=m.face.end(); ++fi) for(FaceIterator fi=m.face.begin(); fi!=m.face.end(); ++fi)
if(!(*fi).IsD()) (*fi).Flags() &= andMask ; if(!(*fi).IsD()) (*fi).Flags() &= andMask ;
} }
static void VertexSet(MeshType &m, unsigned int FlagMask) static void VertexSet(MeshType &m, unsigned int FlagMask)
{ {
VertexIterator vi; if(!HasPerVertexFlags(m)) throw vcg::MissingComponentException("VertexFlags");
for(vi=m.vert.begin(); vi!=m.vert.end(); ++vi) for(VertexIterator vi=m.vert.begin(); vi!=m.vert.end(); ++vi)
if(!(*vi).IsD()) (*vi).Flags() |= FlagMask ; if(!(*vi).IsD()) (*vi).Flags() |= FlagMask ;
} }
static void FaceSet(MeshType &m, unsigned int FlagMask) static void FaceSet(MeshType &m, unsigned int FlagMask)
{ {
FaceIterator fi; if(!HasPerFaceFlags(m)) throw vcg::MissingComponentException("FaceFlags");
for(fi=m.face.begin(); fi!=m.face.end(); ++fi) for(FaceIterator fi=m.face.begin(); fi!=m.face.end(); ++fi)
if(!(*fi).IsD()) (*fi).Flags() |= FlagMask ; if(!(*fi).IsD()) (*fi).Flags() |= FlagMask ;
} }
static void VertexClearV(MeshType &m) { VertexClear(m,VertexType::VISITED);} static void VertexClearV(MeshType &m) { VertexClear(m,VertexType::VISITED);}
static void VertexClearS(MeshType &m) { VertexClear(m,VertexType::SELECTED);} static void VertexClearS(MeshType &m) { VertexClear(m,VertexType::SELECTED);}
static void VertexClearB(MeshType &m) { VertexClear(m,VertexType::BORDER);} static void VertexClearB(MeshType &m) { VertexClear(m,VertexType::BORDER);}
static void EdgeClearV(MeshType &m) { EdgeClear(m,EdgeType::VISITED);} static void EdgeClearV(MeshType &m) { EdgeClear(m,EdgeType::VISITED);}
static void FaceClearV(MeshType &m) { FaceClear(m,FaceType::VISITED);} static void FaceClearV(MeshType &m) { FaceClear(m,FaceType::VISITED);}
static void FaceClearB(MeshType &m) { FaceClear(m,FaceType::BORDER012);} static void FaceClearB(MeshType &m) { FaceClear(m,FaceType::BORDER012);}
static void FaceClearS(MeshType &m) {FaceClear(m,FaceType::SELECTED);} static void FaceClearS(MeshType &m) {FaceClear(m,FaceType::SELECTED);}
static void FaceClearF(MeshType &m) { FaceClear(m,FaceType::FAUX012);} static void FaceClearF(MeshType &m) { FaceClear(m,FaceType::FAUX012);}
static void VertexSetV(MeshType &m) { VertexSet(m,VertexType::VISITED);} static void VertexSetV(MeshType &m) { VertexSet(m,VertexType::VISITED);}
static void VertexSetB(MeshType &m) { VertexSet(m,VertexType::BORDER);} static void VertexSetB(MeshType &m) { VertexSet(m,VertexType::BORDER);}
static void FaceSetV(MeshType &m) { FaceSet(m,FaceType::VISITED);} static void FaceSetV(MeshType &m) { FaceSet(m,FaceType::VISITED);}
static void FaceSetB(MeshType &m) { FaceSet(m,FaceType::BORDER);} static void FaceSetB(MeshType &m) { FaceSet(m,FaceType::BORDER);}
static void FaceSetF(MeshType &m) { FaceSet(m,FaceType::FAUX012);} static void FaceSetF(MeshType &m) { FaceSet(m,FaceType::FAUX012);}
/// \brief Compute the border flags for the faces using the Face-Face Topology. /// \brief Compute the border flags for the faces using the Face-Face Topology.
/** /**
\warning Obviously it assumes that the topology has been correctly computed (see: UpdateTopology::FaceFace ) \warning Obviously it assumes that the topology has been correctly computed (see: UpdateTopology::FaceFace )
*/ */
static void FaceBorderFromFF(MeshType &m) static void FaceBorderFromFF(MeshType &m)
{ {
assert(HasPerFaceFlags(m)); if(!HasPerFaceFlags(m)) throw vcg::MissingComponentException("FaceFlags");
// const int BORDERFLAG[3]={FaceType::BORDER0,FaceType::BORDER1,FaceType::BORDER2}; if(!HasFFAdjacency(m)) throw vcg::MissingComponentException("FFAdj");
FaceIterator fi; for(FaceIterator fi=m.face.begin();fi!=m.face.end();++fi)if(!(*fi).IsD())
for(fi=m.face.begin();fi!=m.face.end();++fi)if(!(*fi).IsD())
for(int j=0;j<3;++j) for(int j=0;j<3;++j)
{ {
//if(!(*fi).IsManifold(j)) (*fi).SetCF(j);
//else
if(face::IsBorder(*fi,j)) (*fi).SetB(j); if(face::IsBorder(*fi,j)) (*fi).SetB(j);
else (*fi).ClearB(j); else (*fi).ClearB(j);
} }
} }
static void FaceBorderFromVF(MeshType &m) static void FaceBorderFromVF(MeshType &m)
{ {
assert(HasPerFaceFlags(m)); if(!HasPerFaceFlags(m)) throw vcg::MissingComponentException("FaceFlags");
assert(HasPerVertexVFAdjacency(m)); if(!HasVFAdjacency(m)) throw vcg::MissingComponentException("VFAdj");
assert(HasPerFaceVFAdjacency(m));
FaceClearB(m); FaceClearB(m);
int visitedBit=VertexType::NewBitFlag(); int visitedBit=VertexType::NewBitFlag();
@ -247,12 +181,12 @@ static void FaceBorderFromVF(MeshType &m)
} }
} }
VertexType::DeleteBitFlag(visitedBit); VertexType::DeleteBitFlag(visitedBit);
} }
class EdgeSorter class EdgeSorter
{ {
public: public:
VertexPointer v[2]; // Puntatore ai due vertici (Ordinati) VertexPointer v[2]; // Puntatore ai due vertici (Ordinati)
FacePointer f; // Puntatore alla faccia generatrice FacePointer f; // Puntatore alla faccia generatrice
@ -261,8 +195,8 @@ public:
EdgeSorter() {} // Nothing to do EdgeSorter() {} // Nothing to do
void Set( const FacePointer pf, const int nz ) void Set( const FacePointer pf, const int nz )
{ {
assert(pf!=0); assert(pf!=0);
assert(nz>=0); assert(nz>=0);
assert(nz<3); assert(nz<3);
@ -274,30 +208,31 @@ void Set( const FacePointer pf, const int nz )
if( v[0] > v[1] ) std::swap(v[0],v[1]); if( v[0] > v[1] ) std::swap(v[0],v[1]);
f = pf; f = pf;
z = nz; z = nz;
} }
inline bool operator < ( const EdgeSorter & pe ) const { inline bool operator < ( const EdgeSorter & pe ) const {
if( v[0]<pe.v[0] ) return true; if( v[0]<pe.v[0] ) return true;
else if( v[0]>pe.v[0] ) return false; else if( v[0]>pe.v[0] ) return false;
else return v[1] < pe.v[1]; else return v[1] < pe.v[1];
} }
inline bool operator == ( const EdgeSorter & pe ) const inline bool operator == ( const EdgeSorter & pe ) const
{ {
return v[0]==pe.v[0] && v[1]==pe.v[1]; return v[0]==pe.v[0] && v[1]==pe.v[1];
} }
inline bool operator != ( const EdgeSorter & pe ) const inline bool operator != ( const EdgeSorter & pe ) const
{ {
return v[0]!=pe.v[0] || v[1]!=pe.v[1]; return v[0]!=pe.v[0] || v[1]!=pe.v[1];
} }
}; };
// versione minimale che non calcola i complex flag. // versione minimale che non calcola i complex flag.
static void VertexBorderFromNone(MeshType &m) static void VertexBorderFromNone(MeshType &m)
{ {
assert(HasPerVertexFlags(m)); if(!HasPerVertexFlags(m)) throw vcg::MissingComponentException("VertexFlags");
std::vector<EdgeSorter> e; std::vector<EdgeSorter> e;
typename UpdateMeshType::FaceIterator pf; typename UpdateMeshType::FaceIterator pf;
typename std::vector<EdgeSorter>::iterator p; typename std::vector<EdgeSorter>::iterator p;
@ -336,13 +271,14 @@ static void VertexBorderFromNone(MeshType &m)
ps = pe; ps = pe;
} }
} }
} }
/// Computes per-face border flags without requiring any kind of topology
/// It has a O(fn log fn) complexity.
static void FaceBorderFromNone(MeshType &m)
{
if(!HasPerFaceFlags(m)) throw vcg::MissingComponentException("FaceFlags");
/// Computes per-face border flags without requiring any kind of topology
/// It has a O(fn log fn) complexity.
static void FaceBorderFromNone(MeshType &m)
{
assert(HasPerFaceFlags(m));
std::vector<EdgeSorter> e; std::vector<EdgeSorter> e;
typename UpdateMeshType::FaceIterator pf; typename UpdateMeshType::FaceIterator pf;
typename std::vector<EdgeSorter>::iterator p; typename std::vector<EdgeSorter>::iterator p;
@ -388,56 +324,55 @@ static void FaceBorderFromNone(MeshType &m)
if(pe==e.end()) break; if(pe==e.end()) break;
++pe; ++pe;
} while(true); } while(true);
// TRACE("found %i border (%i complex) on %i edges\n",nborder,ncomplex,ne); // TRACE("found %i border (%i complex) on %i edges\n",nborder,ncomplex,ne);
} }
/// Compute the PerVertex Border flag deriving it from the faces /// Compute the PerVertex Border flag deriving it from the border flag of faces
static void VertexBorderFromFace(MeshType &m) static void VertexBorderFromFace(MeshType &m)
{
assert(HasPerFaceFlags(m));
typename MeshType::VertexIterator v;
typename MeshType::FaceIterator f;
for(v=m.vert.begin();v!=m.vert.end();++v)
(*v).ClearB();
for(f=m.face.begin();f!=m.face.end();++f)
if(!(*f).IsD())
{ {
for(int z=0;z<(*f).VN();++z) if(!HasPerFaceFlags(m)) throw vcg::MissingComponentException("FaceFlags");
if( (*f).IsB(z) ) if(!HasPerVertexFlags(m)) throw vcg::MissingComponentException("VertexFlags");
for(VertexIterator vi=m.vert.begin();vi!=m.vert.end();++vi)
(*vi).ClearB();
for(FaceIterator fi=m.face.begin();fi!=m.face.end();++fi)
if(!(*fi).IsD())
{ {
(*f).V(z)->SetB(); for(int z=0;z<(*fi).VN();++z)
(*f).V((*f).Next(z))->SetB(); if( (*fi).IsB(z) )
{
(*fi).V(z)->SetB();
(*fi).V((*fi).Next(z))->SetB();
} }
} }
} }
// //
static void FaceFauxCrease(MeshType &m,float AngleRad) static void FaceFauxCrease(MeshType &m,float AngleRad)
{ {
assert(HasPerFaceFlags(m)); if(!HasPerFaceFlags(m)) throw vcg::MissingComponentException("FaceFlags");
assert(HasFFAdjacency(m)); if(!HasFFAdjacency(m)) throw vcg::MissingComponentException("FFAdj");
typename MeshType::FaceIterator f; typename MeshType::FaceIterator f;
//initially everything is faux (e.g all internal) //initially everything is faux (e.g all internal)
FaceSetF(m); FaceSetF(m);
for(f=m.face.begin();f!=m.face.end();++f) for(FaceIterator fi=m.face.begin();fi!=m.face.end();++fi)
{ {
if(!(*f).IsD()) if(!(*fi).IsD())
{ {
for(int z=0;z<(*f).VN();++z) for(int z=0;z<(*fi).VN();++z)
{ {
if( face::IsBorder(*f,z) ) (*f).ClearF(z); if( face::IsBorder(*fi,z) ) (*fi).ClearF(z);
else else
{ {
if(Angle((*f).N(), (*f).FFp(z)->N()) > AngleRad) if(Angle((*fi).N(), (*fi).FFp(z)->N()) > AngleRad)
(*f).ClearF(z); (*fi).ClearF(z);
}
} }
} }
} }
} }
}
}; // end class }; // end class