Fixed manifold Test
This commit is contained in:
parent
eb14792ee4
commit
1610300e86
|
@ -24,6 +24,9 @@
|
|||
History
|
||||
|
||||
$Log: not supported by cvs2svn $
|
||||
Revision 1.6 2005/09/30 14:13:01 rita_borgo
|
||||
Problem: Text not aligned
|
||||
|
||||
Revision 1.5 2005/09/30 13:29:40 rita_borgo
|
||||
Fixed Manifold Test
|
||||
|
||||
|
@ -66,13 +69,10 @@ Added Standard comments
|
|||
#include <string>
|
||||
#include <stack>
|
||||
using namespace std;
|
||||
|
||||
#include<vcg/simplex/vertex/vertex.h>
|
||||
#include<vcg/simplex/face/with/afav.h>
|
||||
#include<vcg/simplex/face/topology.h>
|
||||
#include<vcg/simplex/face/pos.h> // mi sembra di averlo aggiunto!
|
||||
|
||||
|
||||
#include<vcg/complex/trimesh/base.h>
|
||||
#include<vcg/complex/trimesh/update/topology.h>
|
||||
#include <vcg/complex/trimesh/update/edges.h>
|
||||
|
@ -84,46 +84,36 @@ using namespace std;
|
|||
#include <wrap/io_trimesh/export_ply.h>
|
||||
#include <wrap/io_trimesh/export_stl.h>
|
||||
#include <wrap/io_trimesh/export_dxf.h>
|
||||
|
||||
#include "XMLTree.h"
|
||||
#include <wrap/io_trimesh/export_off.h>
|
||||
|
||||
|
||||
// loader
|
||||
#include<wrap/io_trimesh/import_ply.h>
|
||||
|
||||
#include "defs.h"
|
||||
|
||||
string ans;
|
||||
using namespace vcg;
|
||||
using namespace tri;
|
||||
using namespace face;
|
||||
int prova1;
|
||||
|
||||
class MyFace;
|
||||
class MyEdge;
|
||||
class MyVertex:public Vertex<float,MyEdge,MyFace>{};
|
||||
class MyVertex : public Vertex<float,MyEdge,MyFace>{};
|
||||
class MyFace :public FaceAFAV<MyVertex,MyEdge,MyFace>{};
|
||||
class MyMesh: public tri::TriMesh< std::vector<MyVertex>, std::vector<MyFace > >{};
|
||||
|
||||
|
||||
typedef MyMesh::VertexPointer VertexPointer;
|
||||
typedef MyMesh::VertexIterator VertexIterator;
|
||||
|
||||
typedef Point3<MyMesh::ScalarType> Point3x;
|
||||
typedef vector<Point3x> Hole;
|
||||
|
||||
string ans;
|
||||
|
||||
void OpenMesh(const char *filename, MyMesh &m)
|
||||
{
|
||||
int err = tri::io::Importer<MyMesh>::Open(m,filename);
|
||||
if(err) {
|
||||
if(err){
|
||||
printf("Error in reading %s: '%s'\n",filename,tri::io::Importer<MyMesh>::ErrorMsg(err));
|
||||
exit(-1);
|
||||
}
|
||||
printf("read mesh `%s'\n", filename);
|
||||
}
|
||||
|
||||
|
||||
inline char* GetExtension(char* filename)
|
||||
{
|
||||
for(int i=strlen(filename)-1; i >= 0; i--)
|
||||
|
@ -134,11 +124,8 @@ inline char* GetExtension(char* filename)
|
|||
else
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
typedef MyMesh::VertexPointer VertexPointer;
|
||||
typedef MyMesh::VertexIterator VertexIterator;
|
||||
|
||||
/* classe di confronto per l'algoritmo di individuazione vertici duplicati*/
|
||||
template <class VertexIterator>
|
||||
class DuplicateVert_Compare{
|
||||
|
@ -148,31 +135,26 @@ public:
|
|||
return *a < *b;
|
||||
}
|
||||
};
|
||||
|
||||
static int DuplicateVertex( MyMesh & m ) // V1.0
|
||||
static int DuplicateVertex( MyMesh & m )// V1.0
|
||||
{if(m.vert.size()==0 || m.vn==0)
|
||||
return 0;
|
||||
std::map<VertexPointer, VertexPointer> mp;
|
||||
int i,j;
|
||||
VertexIterator vi;
|
||||
int deleted=0;
|
||||
int k=0;
|
||||
int num_vert = m.vert.size();
|
||||
vector<VertexPointer> perm(num_vert);
|
||||
for(vi=m.vert.begin(); vi!=m.vert.end(); ++vi, ++k)
|
||||
perm[k] = &(*vi);
|
||||
DuplicateVert_Compare<VertexPointer> c_obj;
|
||||
std::sort(perm.begin(),perm.end(),c_obj);
|
||||
j = 0;
|
||||
i = j;
|
||||
mp[perm[i]] = perm[j];
|
||||
++i;
|
||||
for(;i!=num_vert;)
|
||||
{
|
||||
|
||||
if(m.vert.size()==0 || m.vn==0)
|
||||
return 0;
|
||||
std::map<VertexPointer, VertexPointer> mp;
|
||||
int i,j;
|
||||
VertexIterator vi;
|
||||
int deleted=0;
|
||||
int k=0;
|
||||
int num_vert = m.vert.size();
|
||||
vector<VertexPointer> perm(num_vert);
|
||||
for(vi=m.vert.begin(); vi!=m.vert.end(); ++vi, ++k)
|
||||
perm[k] = &(*vi);
|
||||
|
||||
DuplicateVert_Compare<VertexPointer> c_obj;
|
||||
|
||||
std::sort(perm.begin(),perm.end(),c_obj);
|
||||
j = 0;
|
||||
i = j;
|
||||
mp[perm[i]] = perm[j];
|
||||
++i;
|
||||
for(;i!=num_vert;)
|
||||
{
|
||||
if( (! (*perm[i]).IsD()) &&
|
||||
(! (*perm[j]).IsD()) &&
|
||||
(*perm[i]).P() == (*perm[j]).cP() )
|
||||
|
@ -198,30 +180,24 @@ static int DuplicateVertex( MyMesh & m ) // V1.0
|
|||
j = i;
|
||||
++i;
|
||||
}
|
||||
}
|
||||
ans.clear();
|
||||
return deleted;
|
||||
}
|
||||
ans.clear();
|
||||
return deleted;
|
||||
}
|
||||
|
||||
|
||||
void main(int argc,char ** argv){
|
||||
|
||||
|
||||
MyMesh m;
|
||||
bool DEBUG = true;
|
||||
int k;
|
||||
k=3;
|
||||
bool DEBUG=false;
|
||||
|
||||
int j;
|
||||
j=0;
|
||||
cout<<"Punto 1"<<endl;
|
||||
/*------------XML file part ------------------*/
|
||||
|
||||
static char* XML_SCHEMA_NAME = "protegekb";
|
||||
/*------------XML file part ------------------*/static char* XML_SCHEMA_NAME = "protegekb";
|
||||
XMLTree doc;
|
||||
MainNode* mn = new MainNode;
|
||||
|
||||
/*--------------------------------------------*/
|
||||
cout<<"Punto 2"<<endl;
|
||||
|
||||
|
||||
//load the mesh
|
||||
//argv[1]=(char*)"c:\\checkup\\debug\\column1m.ply";
|
||||
|
@ -235,7 +211,7 @@ cout<<"Punto 2"<<endl;
|
|||
" release date: "__DATE__"\n"
|
||||
"-------------------------------\n\n");
|
||||
|
||||
cout<<"Punto 3"<<endl;
|
||||
|
||||
|
||||
if(DEBUG)
|
||||
argv[1] = "C:\\sf\\apps\\msvc\\trimeshinfo\\Release\\tests\\kite_hole3.ply";
|
||||
|
@ -249,12 +225,13 @@ cout<<"Punto 3"<<endl;
|
|||
exit(-1);
|
||||
}
|
||||
}
|
||||
cout<<"Punto 4"<<endl;
|
||||
|
||||
|
||||
|
||||
OpenMesh(argv[1],m);
|
||||
|
||||
cout<<"Punto 5"<<endl;
|
||||
|
||||
|
||||
|
||||
|
||||
/*------------XML file part ------------------*/
|
||||
|
@ -281,7 +258,6 @@ cout<<"Punto 5"<<endl;
|
|||
printf("\t Number of faces: %d \n", m.fn);
|
||||
|
||||
|
||||
cout<<"Punto 6"<<endl;
|
||||
|
||||
/*------------XML file part ------------------*/
|
||||
NodeGroup* ng = new NodeGroup;
|
||||
|
@ -315,7 +291,6 @@ cout<<"Punto 6"<<endl;
|
|||
ng->addNode(osn);
|
||||
/*--------------------------------------------*/
|
||||
|
||||
cout<<"Punto 7"<<endl;
|
||||
|
||||
|
||||
if(m.HasPerFaceColor()||m.HasPerVertexColor())
|
||||
|
@ -341,7 +316,7 @@ cout<<"Punto 7"<<endl;
|
|||
/*--------------------------------------------*/
|
||||
}
|
||||
|
||||
cout<<"Punto 8"<<endl;
|
||||
|
||||
vcg::tri::UpdateTopology<MyMesh>::FaceFace(m);
|
||||
|
||||
// IS MANIFOLD
|
||||
|
@ -350,8 +325,13 @@ cout<<"Punto 7"<<endl;
|
|||
vcg::face::Pos<MyMesh::FaceType> he;
|
||||
vcg::face::Pos<MyMesh::FaceType> hei;
|
||||
|
||||
for(fi=m.face.begin();fi!=m.face.end();++fi)
|
||||
for(fi=m.face.begin();fi!=m.face.end();fi++)
|
||||
{
|
||||
(*fi).ClearB(0);
|
||||
(*fi).ClearB(1);
|
||||
(*fi).ClearB(2);
|
||||
(*fi).ClearS();
|
||||
}
|
||||
int cf=0;
|
||||
bool Manifold=true;
|
||||
|
||||
|
@ -368,13 +348,12 @@ cout<<"Punto 7"<<endl;
|
|||
--fi;
|
||||
j=3;
|
||||
}
|
||||
else if((!fi->HasFFAdjacency())&&(fi!=m.face.begin()))
|
||||
}
|
||||
if((BorderCount(*fi)>0))
|
||||
{
|
||||
Manifold = false;
|
||||
fi= m.face.end();
|
||||
--fi;
|
||||
j=3;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -435,19 +414,19 @@ cout<<"Punto 7"<<endl;
|
|||
{
|
||||
if (fi->IsBorder(j)) //If this edge is a border edge
|
||||
boundary_e++; // then increase the number of boundary edges
|
||||
else if (IsManifold(*fi,j)) //If this edge is manifold
|
||||
else if (IsManifold(*fi,j))//If this edge is manifold
|
||||
{
|
||||
if((*fi).FFp(j)->IsS()) //If the face on the other side of the edge is already selected
|
||||
count_e--; // we counted one edge twice
|
||||
}
|
||||
else //We have a non-manifold edge
|
||||
else//We have a non-manifold edge
|
||||
{
|
||||
hei.Set(&(*fi), j , fi->V(j));
|
||||
he=hei;
|
||||
he.NextF();
|
||||
while (he.f!=hei.f) // so we have to iterate all faces that are connected to this edge
|
||||
while (he.f!=hei.f)// so we have to iterate all faces that are connected to this edge
|
||||
{
|
||||
if (he.f->IsS()) // if one of the other faces was already visited than this edge was counted already.
|
||||
if (he.f->IsS())// if one of the other faces was already visited than this edge was counted already.
|
||||
{
|
||||
counted=true;
|
||||
break;
|
||||
|
@ -566,13 +545,13 @@ cout<<"Punto 7"<<endl;
|
|||
|
||||
if (Manifold)
|
||||
{
|
||||
for(fi=m.face.begin();fi!=m.face.end();fi++) //for all faces do
|
||||
for(fi=m.face.begin();fi!=m.face.end();fi++)//for all faces do
|
||||
{
|
||||
for(j=0;j<3;j++) //for all edges
|
||||
for(j=0;j<3;j++)//for all edges
|
||||
{
|
||||
if(fi->V(j)->IsS()) continue;
|
||||
|
||||
if((*fi).IsBorder(j)) //found an unvisited border edge
|
||||
if((*fi).IsBorder(j))//found an unvisited border edge
|
||||
{
|
||||
he.Set(&(*fi),j,fi->V(j)); //set the face-face iterator to the current face, edge and vertex
|
||||
vector<Point3x> hole; //start of a new hole
|
||||
|
@ -582,10 +561,10 @@ cout<<"Punto 7"<<endl;
|
|||
he.NextB(); //go to the next boundary edge
|
||||
|
||||
|
||||
while(fi->V(j) != he.v) //will we do not encounter the first boundary edge.
|
||||
while(fi->V(j) != he.v)//will we do not encounter the first boundary edge.
|
||||
{
|
||||
Point3x newpoint = he.v->P(); //select its vertex.
|
||||
if(he.v->IsS()) //check if this vertex was selected already, because then we have an additional hole.
|
||||
if(he.v->IsS())//check if this vertex was selected already, because then we have an additional hole.
|
||||
{
|
||||
//cut and paste the additional hole.
|
||||
vector<Point3x> hole2;
|
||||
|
@ -692,6 +671,7 @@ cout<<"Punto 7"<<endl;
|
|||
// CONNECTED COMPONENTS
|
||||
|
||||
vector<int> nrfaces;
|
||||
nrfaces.reserve(1);
|
||||
for(fi=m.face.begin();fi!=m.face.end();++fi)
|
||||
(*fi).ClearS();
|
||||
gi=m.face.begin(); fi=gi;
|
||||
|
@ -703,7 +683,7 @@ cout<<"Punto 7"<<endl;
|
|||
if (!(*fi).IsS())
|
||||
{
|
||||
(*fi).SetS();
|
||||
(*fi).Q()=Compindex;
|
||||
//(*fi).Q()=Compindex;
|
||||
nrfaces.push_back(1);
|
||||
sf.push(fi);
|
||||
while (!sf.empty())
|
||||
|
@ -773,10 +753,10 @@ cout<<"Punto 7"<<endl;
|
|||
ng->addNode(osn);
|
||||
/*--------------------------------------------*/
|
||||
}
|
||||
else //(!Manifold)
|
||||
else//(!Manifold)
|
||||
{
|
||||
fprintf( index,"<p>Genus: UNDEFINED, mesh is non-manifold </p>\n");
|
||||
printf( "Genus: UNDEFINED, mesh is non-manifold \n");
|
||||
printf( "\t Genus: UNDEFINED, mesh is non-manifold \n");
|
||||
}
|
||||
// REGULARITY
|
||||
|
||||
|
@ -936,7 +916,7 @@ cout<<"Punto 7"<<endl;
|
|||
hei.Set(he.f->FFp(j),he.f->FFi(j), (he.f->FFp(j))->V(he.f->FFi(j)));
|
||||
if( !(*gi).IsUserBit(0) )
|
||||
{
|
||||
if (he.v!=hei.v) // bene
|
||||
if (he.v!=hei.v)// bene
|
||||
{
|
||||
if ((*l).IsS() && (*l).IsUserBit(0))
|
||||
{
|
||||
|
@ -962,7 +942,7 @@ cout<<"Punto 7"<<endl;
|
|||
break;
|
||||
}
|
||||
}
|
||||
else if (he.v==hei.v) // bene
|
||||
else if (he.v==hei.v)// bene
|
||||
{
|
||||
if ((*l).IsS() && (*l).IsUserBit(0))
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue