Cleaned up a bit naming and comments and some interfaces of some bitquad functions

This commit is contained in:
Paolo Cignoni 2013-10-10 16:02:27 +00:00
parent b8769bd3e6
commit a1471cea44
3 changed files with 464 additions and 492 deletions

View File

@ -5,6 +5,7 @@
#include <vcg/simplex/face/jumping_pos.h> #include <vcg/simplex/face/jumping_pos.h>
#include <vcg/simplex/face/topology.h> #include <vcg/simplex/face/topology.h>
#include <vcg/space/planar_polygon_tessellation.h> #include <vcg/space/planar_polygon_tessellation.h>
#include <vcg/complex/algorithms/update/quality.h>
/** BIT-QUAD creation support: /** BIT-QUAD creation support:
a few basic operations to work with bit-quads simplices a few basic operations to work with bit-quads simplices
@ -966,9 +967,7 @@ static void UpdateValencyInFlags(MeshType& m){
} }
static void UpdateValencyInQuality(MeshType& m){ static void UpdateValencyInQuality(MeshType& m){
for (VertexIterator vi = m.vert.begin(); vi!=m.vert.end(); vi++) if (!vi->IsD()) { tri::UpdateQuality<MeshType>::VertexConstant(m,0);
vi->Q() = 0;
}
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()) {
for (int w=0; w<3; w++) for (int w=0; w<3; w++)
@ -991,16 +990,15 @@ static bool HasConsistentValencyFlag(MeshType &m) {
// helper function: // helper function:
// returns quality of a given (potential) quad // returns quality of a given (potential) quad
static ScalarType quadQuality(FaceType *f, int edge){ static ScalarType quadQuality(FaceType *f, int edgeInd){
CoordType CoordType
a = f->V0(edge)->P(), a = f->V0(edgeInd)->P(),
b = f->FFp(edge)->V2( f->FFi(edge) )->P(), b = f->FFp(edgeInd)->V2( f->FFi(edgeInd) )->P(),
c = f->V1(edge)->P(), c = f->V1(edgeInd)->P(),
d = f->V2(edge)->P(); d = f->V2(edgeInd)->P();
return quadQuality(a,b,c,d); return quadQuality(a,b,c,d);
} }
/** /**

View File

@ -44,11 +44,11 @@
#include <vcg/complex/algorithms/update/topology.h> #include <vcg/complex/algorithms/update/topology.h>
#include <vcg/space/triangle3.h> #include <vcg/space/triangle3.h>
namespace vcg { namespace vcg {
namespace tri{ namespace tri{
template <class ConnectedMeshType> template <class ConnectedMeshType>
class ConnectedIterator class ConnectedComponentIterator
{ {
public: public:
typedef ConnectedMeshType MeshType; typedef ConnectedMeshType MeshType;
@ -62,7 +62,6 @@ class ConnectedIterator
typedef typename MeshType::ConstFaceIterator ConstFaceIterator; typedef typename MeshType::ConstFaceIterator ConstFaceIterator;
typedef typename MeshType::FaceContainer FaceContainer; typedef typename MeshType::FaceContainer FaceContainer;
public: public:
void operator ++() void operator ++()
{ {
@ -90,6 +89,7 @@ public:
tri::Mark(m,p); tri::Mark(m,p);
sf.push(p); sf.push(p);
} }
bool completed() { bool completed() {
return sf.empty(); return sf.empty();
} }
@ -132,12 +132,6 @@ private:
typedef GridStaticPtr<FaceType, ScalarType > TriMeshGrid; typedef GridStaticPtr<FaceType, ScalarType > TriMeshGrid;
typedef Point3<ScalarType> Point3x; typedef Point3<ScalarType> Point3x;
//TriMeshGrid gM;
//FaceIterator fi;
//FaceIterator gi;
//vcg::face::Pos<FaceType> he;
//vcg::face::Pos<FaceType> hei;
/* classe di confronto per l'algoritmo di eliminazione vertici duplicati*/ /* classe di confronto per l'algoritmo di eliminazione vertici duplicati*/
class RemoveDuplicateVert_Compare{ class RemoveDuplicateVert_Compare{
public: public:
@ -627,7 +621,7 @@ private:
static bool IsBitQuadOnly(const MeshType &m) static bool IsBitQuadOnly(const MeshType &m)
{ {
typedef typename MeshType::FaceType F; typedef typename MeshType::FaceType F;
if (!HasPerFaceFlags(m)) return false; tri::RequirePerFaceFlags(m);
for (ConstFaceIterator fi = m.face.begin(); fi != m.face.end(); ++fi) if (!fi->IsD()) { for (ConstFaceIterator fi = m.face.begin(); fi != m.face.end(); ++fi) if (!fi->IsD()) {
unsigned int tmp = fi->Flags()&(F::FAUX0|F::FAUX1|F::FAUX2); unsigned int tmp = fi->Flags()&(F::FAUX0|F::FAUX1|F::FAUX2);
if ( tmp != F::FAUX0 && tmp != F::FAUX1 && tmp != F::FAUX2) return false; if ( tmp != F::FAUX0 && tmp != F::FAUX1 && tmp != F::FAUX2) return false;
@ -641,11 +635,9 @@ private:
*/ */
static bool IsBitTriOnly(const MeshType &m) static bool IsBitTriOnly(const MeshType &m)
{ {
if (!HasPerFaceFlags(m)) return true; tri::RequirePerFaceFlags(m);
for (ConstFaceIterator fi = m.face.begin(); fi != m.face.end(); ++fi) { for (ConstFaceIterator fi = m.face.begin(); fi != m.face.end(); ++fi) {
if ( if ( !fi->IsD() && fi->IsAnyF() ) return false;
!fi->IsD() && fi->IsAnyF()
) return false;
} }
return true; return true;
} }
@ -656,11 +648,12 @@ private:
/** /**
* Is the mesh only composed by quadrilaterals and triangles? (no pentas, etc) * Is the mesh only composed by quadrilaterals and triangles? (no pentas, etc)
* It assumes that the bits are consistent. In that case there can be only a single faux edge.
*/ */
static bool IsBitTriQuadOnly(const MeshType &m) static bool IsBitTriQuadOnly(const MeshType &m)
{ {
tri::RequirePerFaceFlags(m);
typedef typename MeshType::FaceType F; typedef typename MeshType::FaceType F;
if (!HasPerFaceFlags(m)) return false;
for (ConstFaceIterator fi = m.face.begin(); fi != m.face.end(); ++fi) if (!fi->IsD()) { for (ConstFaceIterator fi = m.face.begin(); fi != m.face.end(); ++fi) if (!fi->IsD()) {
unsigned int tmp = fi->cFlags()&(F::FAUX0|F::FAUX1|F::FAUX2); unsigned int tmp = fi->cFlags()&(F::FAUX0|F::FAUX1|F::FAUX2);
if ( tmp!=F::FAUX0 && tmp!=F::FAUX1 && tmp!=F::FAUX2 && tmp!=0 ) return false; if ( tmp!=F::FAUX0 && tmp!=F::FAUX1 && tmp!=F::FAUX2 && tmp!=0 ) return false;
@ -670,10 +663,11 @@ private:
/** /**
* How many quadrilaterals? * How many quadrilaterals?
* It assumes that the bits are consistent. In that case we count the tris with a single faux edge and divide by two.
*/ */
static int CountBitQuads(const MeshType &m) static int CountBitQuads(const MeshType &m)
{ {
if (!HasPerFaceFlags(m)) return 0; tri::RequirePerFaceFlags(m);
typedef typename MeshType::FaceType F; typedef typename MeshType::FaceType F;
int count=0; int count=0;
for (ConstFaceIterator fi = m.face.begin(); fi != m.face.end(); ++fi) if (!fi->IsD()) { for (ConstFaceIterator fi = m.face.begin(); fi != m.face.end(); ++fi) if (!fi->IsD()) {
@ -688,7 +682,7 @@ private:
*/ */
static int CountBitTris(const MeshType &m) static int CountBitTris(const MeshType &m)
{ {
if (!HasPerFaceFlags(m)) return m.fn; tri::RequirePerFaceFlags(m);
int count=0; int count=0;
for (ConstFaceIterator fi = m.face.begin(); fi != m.face.end(); ++fi) if (!fi->IsD()) { for (ConstFaceIterator fi = m.face.begin(); fi != m.face.end(); ++fi) if (!fi->IsD()) {
if (!(fi->IsAnyF())) count++; if (!(fi->IsAnyF())) count++;
@ -698,11 +692,11 @@ private:
/** /**
* How many polygons of any kind? (including triangles) * How many polygons of any kind? (including triangles)
* it assumes that there are no faux vertexes (e.g vertices completely surrounded by faux edges)
*/ */
static int CountBitPolygons(const MeshType &m) static int CountBitPolygons(const MeshType &m)
{ {
if (!HasPerFaceFlags(m)) return m.fn; tri::RequirePerFaceFlags(m);
typedef typename MeshType::FaceType F;
int count = 0; int count = 0;
for (ConstFaceIterator fi = m.face.begin(); fi != m.face.end(); ++fi) if (!fi->IsD()) { for (ConstFaceIterator fi = m.face.begin(); fi != m.face.end(); ++fi) if (!fi->IsD()) {
if (fi->IsF(0)) count++; if (fi->IsF(0)) count++;
@ -725,7 +719,7 @@ private:
*/ */
static int CountBitLargePolygons(MeshType &m) static int CountBitLargePolygons(MeshType &m)
{ {
tri::RequirePerFaceFlags(m);
UpdateFlags<MeshType>::VertexSetV(m); UpdateFlags<MeshType>::VertexSetV(m);
// First loop Clear all referenced vertices // First loop Clear all referenced vertices
for (FaceIterator fi = m.face.begin(); fi != m.face.end(); ++fi) for (FaceIterator fi = m.face.begin(); fi != m.face.end(); ++fi)
@ -733,9 +727,8 @@ private:
for(int i=0;i<3;++i) fi->V(i)->ClearV(); for(int i=0;i<3;++i) fi->V(i)->ClearV();
// Second Loop, count (twice) faux edges and mark all vertices touched by non faux edges (e.g vertexes on the boundary of a polygon) // Second Loop, count (twice) faux edges and mark all vertices touched by non faux edges
if (!HasPerFaceFlags(m)) return m.fn; // (e.g vertexes on the boundary of a polygon)
typedef typename MeshType::FaceType F;
int countE = 0; int countE = 0;
for (FaceIterator fi = m.face.begin(); fi != m.face.end(); ++fi) for (FaceIterator fi = m.face.begin(); fi != m.face.end(); ++fi)
if (!fi->IsD()) { if (!fi->IsD()) {
@ -775,30 +768,11 @@ private:
for (ConstFaceIterator fi = m.face.begin(); fi != m.face.end(); ++fi) for (ConstFaceIterator fi = m.face.begin(); fi != m.face.end(); ++fi)
if(!(*fi).IsD()) if(!(*fi).IsD())
for (int k=0; k<3; k++) for (int k=0; k<3; k++)
if( fi->IsF(k) != fi->cFFp(k)->IsF(fi->cFFi(k)) ) { if( ( fi->IsF(k) != fi->cFFp(k)->IsF(fi->cFFi(k)) ) ||
( fi->IsF(k) && face::IsBorder(*fi,k)) )
{
return false; return false;
} }
// non-reciprocal faux edge!
// (OR: border faux edge, which is likewise inconsistent)
return true;
}
static bool HasConsistentEdges(const MeshType &m)
{
RequirePerFaceFlags(m);
for (ConstFaceIterator fi = m.face.begin(); fi != m.face.end(); ++fi)
if(!(*fi).IsD())
for (int k=0; k<3; k++)
{
VertexType *v0=(*fi).V(0);
VertexType *v1=(*fi).V(1);
VertexType *v2=(*fi).V(2);
if ((v0==v1)||(v0==v2)||(v1==v2))
return false;
}
return true; return true;
} }
@ -1572,7 +1546,7 @@ private:
*/ */
static bool HasConsistentPerWedgeTexCoord(MeshType &m) static bool HasConsistentPerWedgeTexCoord(MeshType &m)
{ {
if(!HasPerWedgeTexCoord(m)) return false; tri::RequirePerFaceWedgeTexCoord(m);
for (FaceIterator fi = m.face.begin(); fi != m.face.end(); ++fi) for (FaceIterator fi = m.face.begin(); fi != m.face.end(); ++fi)
if(!(*fi).IsD()) if(!(*fi).IsD())
@ -1590,7 +1564,7 @@ private:
*/ */
static bool HasZeroTexCoordFace(MeshType &m) static bool HasZeroTexCoordFace(MeshType &m)
{ {
if(!HasPerWedgeTexCoord(m)) return false; tri::RequirePerFaceWedgeTexCoord(m);
for (FaceIterator fi = m.face.begin(); fi != m.face.end(); ++fi) for (FaceIterator fi = m.face.begin(); fi != m.face.end(); ++fi)
if(!(*fi).IsD()) if(!(*fi).IsD())
@ -1695,7 +1669,7 @@ static std::pair<int,int> RemoveSmallConnectedComponentsSize(MeshType &m, int m
int TotalCC=ConnectedComponents(m, CCV); int TotalCC=ConnectedComponents(m, CCV);
int DeletedCC=0; int DeletedCC=0;
ConnectedIterator<MeshType> ci; ConnectedComponentIterator<MeshType> ci;
for(unsigned int i=0;i<CCV.size();++i) for(unsigned int i=0;i<CCV.size();++i)
{ {
std::vector<typename MeshType::FacePointer> FPV; std::vector<typename MeshType::FacePointer> FPV;
@ -1721,7 +1695,7 @@ static std::pair<int,int> RemoveSmallConnectedComponentsDiameter(MeshType &m, Sc
std::vector< std::pair<int, typename MeshType::FacePointer> > CCV; std::vector< std::pair<int, typename MeshType::FacePointer> > CCV;
int TotalCC=ConnectedComponents(m, CCV); int TotalCC=ConnectedComponents(m, CCV);
int DeletedCC=0; int DeletedCC=0;
tri::ConnectedIterator<MeshType> ci; tri::ConnectedComponentIterator<MeshType> ci;
for(unsigned int i=0;i<CCV.size();++i) for(unsigned int i=0;i<CCV.size();++i)
{ {
Box3f bb; Box3f bb;
@ -1751,7 +1725,7 @@ static std::pair<int,int> RemoveHugeConnectedComponentsDiameter(MeshType &m, Sca
std::vector< std::pair<int, typename MeshType::FacePointer> > CCV; std::vector< std::pair<int, typename MeshType::FacePointer> > CCV;
int TotalCC=ConnectedComponents(m, CCV); int TotalCC=ConnectedComponents(m, CCV);
int DeletedCC=0; int DeletedCC=0;
tri::ConnectedIterator<MeshType> ci; tri::ConnectedComponentIterator<MeshType> ci;
for(unsigned int i=0;i<CCV.size();++i) for(unsigned int i=0;i<CCV.size();++i)
{ {
Box3f bb; Box3f bb;

View File

@ -287,7 +287,7 @@ It require FaceFace Adjacency becouse it relies on the output of the ConnecteCom
std::vector< std::pair<int, typename MeshType::FacePointer> > CCV; std::vector< std::pair<int, typename MeshType::FacePointer> > CCV;
int ScatterSize= std::min (100,tri::Clean<MeshType>::ConnectedComponents(m, CCV)); // number of random color to be used. Never use too many. int ScatterSize= std::min (100,tri::Clean<MeshType>::ConnectedComponents(m, CCV)); // number of random color to be used. Never use too many.
ConnectedIterator<MeshType> ci; ConnectedComponentIterator<MeshType> ci;
for(unsigned int i=0;i<CCV.size();++i) for(unsigned int i=0;i<CCV.size();++i)
{ {
Color4b BaseColor = Color4b::Scatter(ScatterSize, i%ScatterSize,.4f,.7f); Color4b BaseColor = Color4b::Scatter(ScatterSize, i%ScatterSize,.4f,.7f);