Fixed manifold Test

This commit is contained in:
Paolo Cignoni 2005-09-30 15:48:46 +00:00
parent eb14792ee4
commit 1610300e86
1 changed files with 239 additions and 259 deletions

View File

@ -1,62 +1,65 @@
/****************************************************************************
* VCGLib o o *
* Visual and Computer Graphics Library o o *
* _ O _ *
* Copyright(C) 2004 \/)\/ *
* Visual Computing Lab /\/| *
* ISTI - Italian National Research Council | *
* \ *
* All rights reserved. *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt) *
* for more details. *
* *
* VCGLib o o *
* Visual and Computer Graphics Library o o *
* _ O _ *
* Copyright(C) 2004 \/)\/ *
* Visual Computing Lab /\/| *
* ISTI - Italian National Research Council | *
* \ *
* All rights reserved. *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt) *
* for more details. *
* *
****************************************************************************/
/****************************************************************************
History
$Log: not supported by cvs2svn $
Revision 1.5 2005/09/30 13:29:40 rita_borgo
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
Revision 1.4 2005/09/29 14:48:15 rita_borgo
Revision 1.4 2005/09/29 14:48:15 rita_borgo
Fixed code related to creation of the XML file
Revision 1.3 2005/09/28 13:57:09 rita_borgo
Revision 1.3 2005/09/28 13:57:09 rita_borgo
Fixed some printout not alligned
Revision 1.2 2005/09/28 10:46:04 rita_borgo
Revision 1.2 2005/09/28 10:46:04 rita_borgo
Added possibility of saving File in OFF format
Revision 1.1 2005/09/20 10:15:27 rita_borgo
Revision 1.1 2005/09/20 10:15:27 rita_borgo
Changed file name to uniform with other solution projects,
before was main.cpp
Revision 1.8 2005/02/15 12:26:06 rita_borgo
Revision 1.8 2005/02/15 12:26:06 rita_borgo
Minor changes to self-intersection
Revision 1.7 2005/02/07 15:44:31 rita_borgo
Revision 1.7 2005/02/07 15:44:31 rita_borgo
Fixed Color and Volume
Revision 1.6 2005/02/01 17:37:53 rita_borgo
Revision 1.6 2005/02/01 17:37:53 rita_borgo
Fixed Volume and Color
Revision 1.5 2005/01/18 16:33:12 rita_borgo
Revision 1.5 2005/01/18 16:33:12 rita_borgo
Added OFF file Option
Revision 1.4 2005/01/17 18:19:00 rita_borgo
Revision 1.4 2005/01/17 18:19:00 rita_borgo
Added new routines.
Self-intersection first release
Revision 1.2 2005/01/03 16:13:09 rita_borgo
Revision 1.2 2005/01/03 16:13:09 rita_borgo
Added Standard comments
@ -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/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 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;
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,80 +135,69 @@ 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() )
{
if( (! (*perm[i]).IsD()) &&
(! (*perm[j]).IsD()) &&
(*perm[i]).P() == (*perm[j]).cP() )
if(deleted ==0)
{
if(deleted ==0)
{
cout<< "\t Found Duplicated Vertices"<< endl;
cout<< "\t do you want to remove them? [y/Y| n/N]\n";
cin>>ans;
}
if((ans == "s") ||(ans=="S"))
{
VertexPointer t = perm[i];
mp[perm[i]] = perm[j];
(*t).SetD();
m.vn--;
}
++i;
deleted++;// per evitare che su risposta no rifaccia la domanda ad ogni vertice che incontra;
cout<< "\t Found Duplicated Vertices"<< endl;
cout<< "\t do you want to remove them? [y/Y| n/N]\n";
cin>>ans;
}
else
if((ans == "s") ||(ans=="S"))
{
j = i;
++i;
VertexPointer t = perm[i];
mp[perm[i]] = perm[j];
(*t).SetD();
m.vn--;
}
++i;
deleted++;// per evitare che su risposta no rifaccia la domanda ad ogni vertice che incontra;
}
ans.clear();
return deleted;
else
{
j = i;
++i;
}
}
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";
XMLTree doc;
/*------------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";
@ -230,12 +206,12 @@ cout<<"Punto 2"<<endl;
// print program info
printf("-------------------------------\n"
" TriMeshInfo V.1.01 \n"
" http://vcg.isti.cnr.it\n"
" release date: "__DATE__"\n"
" TriMeshInfo V.1.01 \n"
" http://vcg.isti.cnr.it\n"
" 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 ------------------*/
@ -277,11 +254,10 @@ cout<<"Punto 5"<<endl;
fprintf(index,"<p>Number of vertices: %d </p>\n", m.vn);
fprintf(index,"<p>Number of faces: %d </p>\n", m.fn);
printf("Mesh info:\n");
printf(" M: '%s'\n\t Number of vertices: %d \n", argv[1], m.vn);
printf(" M: '%s'\n\t Number of vertices: %d \n", argv[1], m.vn);
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()))
{
Manifold = false;
fi= m.face.end();
--fi;
j=3;
}
}
if((BorderCount(*fi)>0))
{
Manifold = false;
fi= m.face.end();
--fi;
}
}
@ -430,24 +409,24 @@ cout<<"Punto 7"<<endl;
for(fi=m.face.begin();fi!=m.face.end();fi++)
{
(*fi).SetS();
count_e +=3; //assume that we have to increase the number of edges with three
count_e +=3; //assume that we have to increase the number of edges with three
for(j=0; j<3; j++)
{
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
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
{
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));
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,26 +545,26 @@ 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
hole.push_back(fi->P(j)); // including the first 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
hole.push_back(fi->P(j)); // including the first vertex
numholev++;
he.v->SetS(); //set the current vertex as selected
he.NextB(); //go to the next boundary edge
he.v->SetS(); //set the current vertex as selected
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.
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.
{
//cut and paste the additional hole.
vector<Point3x> hole2;
@ -594,13 +573,13 @@ cout<<"Punto 7"<<endl;
hole2.push_back(hole[i]);
hole.resize(index);
if(hole2.size()!=0) //annoying in degenerate cases
if(hole2.size()!=0) //annoying in degenerate cases
holes.push_back(hole2);
}
hole.push_back(newpoint);
numholev++;
he.v->SetS(); //set the current vertex as selected
he.NextB(); //go to the next boundary edge
he.v->SetS(); //set the current vertex as selected
he.NextB(); //go to the next boundary edge
}
holes.push_back(hole);
}
@ -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())
@ -747,7 +727,7 @@ cout<<"Punto 7"<<endl;
ng->addNode(osn);
/*--------------------------------------------*/
//GENUS --> 2( #components - genus ) = #vertices + #faces - #edge - #boundary_loops = eulernumber - #holes
//GENUS --> 2( #components - genus ) = #vertices + #faces - #edge - #boundary_loops = eulernumber - #holes
//eulero = (mesh.vn-count_uv) - (count_e)+mesh.fn;
int eulernumber = (m.vn-count_uv) + m.fn - count_e;
@ -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))
{
@ -1217,19 +1197,19 @@ cout<<"Punto 7"<<endl;
cin>>ans;
if((ans=="Y")||(ans=="y"))
{
/*------------XML file part ------------------*/
doc.addSlots(sn);
OwnSlotsNode* ossn = new OwnSlotsNode;
ossn->addOwnSlot(ng);
ClassNode* cn = new ClassNode;
cn->addOwnSlots(ossn);
doc.addClasses(cn);
/*------------XML file part ------------------*/
doc.addSlots(sn);
OwnSlotsNode* ossn = new OwnSlotsNode;
ossn->addOwnSlot(ng);
ClassNode* cn = new ClassNode;
cn->addOwnSlots(ossn);
doc.addClasses(cn);
InstanceNode* in = new InstanceNode;
in->addOwnSlots(ossn);
doc.addInstances(in);
doc.finalizeMain("/",XML_SCHEMA_NAME);
doc.printXMLTree();
InstanceNode* in = new InstanceNode;
in->addOwnSlots(ossn);
doc.addInstances(in);
doc.finalizeMain("/",XML_SCHEMA_NAME);
doc.printXMLTree();
}
/*--------------------------------------------*/
fclose(index);