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