Fixed some printout not alligned

This commit is contained in:
Paolo Cignoni 2005-09-28 13:57:09 +00:00
parent f37ac2dd1b
commit 895fa1dd37
1 changed files with 196 additions and 172 deletions

View File

@ -24,6 +24,9 @@
History History
$Log: not supported by cvs2svn $ $Log: not supported by cvs2svn $
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, Changed file name to uniform with other solution projects,
before was main.cpp before was main.cpp
@ -92,6 +95,13 @@ 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::VertexIterator VertexIterator;
typedef Point3<MyMesh::ScalarType> Point3x;
typedef vector<Point3x> Hole;
string ans; string ans;
void OpenMesh(const char *filename, MyMesh &m) void OpenMesh(const char *filename, MyMesh &m)
@ -187,7 +197,7 @@ void main(int argc,char ** argv){
MyMesh m; MyMesh m;
bool DEBUG = true; bool DEBUG = false;
/*------------XML file part ------------------*/ /*------------XML file part ------------------*/
@ -313,26 +323,27 @@ void main(int argc,char ** argv){
vcg::tri::UpdateTopology<MyMesh>::FaceFace(m); vcg::tri::UpdateTopology<MyMesh>::FaceFace(m);
// IS MANIFOLD // IS MANIFOLD
MyMesh::FaceIterator fi;
MyMesh::FaceIterator f; MyMesh::FaceIterator gi;
MyMesh::FaceIterator g;
vcg::face::Pos<MyMesh::FaceType> he; vcg::face::Pos<MyMesh::FaceType> he;
vcg::face::Pos<MyMesh::FaceType> hei; vcg::face::Pos<MyMesh::FaceType> hei;
int j; int j;
for(fi=m.face.begin();fi!=m.face.end();++fi)
(*fi).ClearS();
int man=0; int man=0;
bool Manifold = true; bool Manifold = true;
MyMesh::FaceIterator prova;
prova = m.face.end(); for(fi=m.face.begin();fi!=m.face.end();++fi)
for(f=m.face.begin();f!=m.face.end();++f)
{ {
for (j=0;j<3;++j) for (j=0;j<3;++j)
{ {
if(!IsManifold(*f,j)) if(!IsManifold(*fi,j))
{ {
Manifold = false; Manifold = false;
f= m.face.end(); fi= m.face.end();
--f; --fi;
j=3; j=3;
} }
} }
@ -374,33 +385,32 @@ void main(int argc,char ** argv){
ng->addNode(osn); ng->addNode(osn);
} }
// COUNT EDGES // COUNT EDGES
MyMesh::FaceIterator fi;
int count_e = 0; int count_e = 0;
int boundary_e = 0;
bool counted =false; bool counted =false;
for(fi=m.face.begin();fi!=m.face.end();++fi) for(fi=m.face.begin();fi!=m.face.end();fi++)
(*fi).ClearS();
for(fi=m.face.begin();fi!=m.face.end();++fi)
{ {
(*fi).SetS(); (*fi).SetS();
count_e +=3; count_e +=3; //assume that we have to increase the number of edges with three
for(int i=0; i<3; ++i) for(int j=0; j<3; j++)
{ {
if (IsManifold(*fi,i)) 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(i)->IsS()) if((*fi).FFp(j)->IsS()) //If the face on the other side of the edge is already selected
count_e--; count_e--; // we counted one edge twice
} }
else else //We have a non-manifold edge
{ {
hei.Set(&(*fi), i , fi->V(i)); hei.Set(&(*fi), j , fi->V(j));
he=hei; he=hei;
he.NextF(); he.NextF();
while (he.f!=hei.f) while (he.f!=hei.f) // so we have to iterated all faces that are connected to this edge
{ {
if (he.f->IsS()) 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;
@ -419,7 +429,11 @@ void main(int argc,char ** argv){
} }
} }
fprintf(index, "<p>Number of edges: %d </p>\n", count_e); fprintf(index, "<p>Number of edges: %d </p>\n", count_e);
fprintf(index, "<p>Number of internal edges: %d </p>\n", count_e-boundary_e);
fprintf(index, "<p>Number of boundary edges: %i </p>\n", boundary_e);
printf("\t Number of edges: %d \n", count_e); printf("\t Number of edges: %d \n", count_e);
printf("\t Number of internal edges: %d \n", count_e-boundary_e);
printf("\t Number of boundary edges: %i \n", boundary_e);
s = new(char[25]); s = new(char[25]);
vn = new ValueNode; vn = new ValueNode;
@ -469,9 +483,9 @@ void main(int argc,char ** argv){
for(v=m.vert.begin();v!=m.vert.end();++v) for(v=m.vert.begin();v!=m.vert.end();++v)
(*v).ClearV(); (*v).ClearV();
for(f=m.face.begin();f!=m.face.end();++f) for(fi=m.face.begin();fi!=m.face.end();++fi)
for(j=0;j<3;++j) for(j=0;j<3;++j)
(*f).V(j)->SetV(); (*fi).V(j)->SetV();
for(v=m.vert.begin();v!=m.vert.end();++v) for(v=m.vert.begin();v!=m.vert.end();++v)
if( !(*v).IsV() ) if( !(*v).IsV() )
@ -495,63 +509,61 @@ void main(int argc,char ** argv){
// HOLES COUNT // HOLES COUNT
for(f=m.face.begin();f!=m.face.end();++f) int numholes=0;
(*f).ClearS(); int numholev=0;
g=m.face.begin(); f=g; int BEdges=0;
vector<vector<Point3x> > holes; //indices of vertices
int BEdges=0; int numholes=0; for(fi=m.face.begin();fi!=m.face.end();++fi)
(*fi).ClearS();
gi=m.face.begin(); fi=gi;
if (Manifold) if (Manifold)
{ {
for(f=g;f!=m.face.end();++f) for(fi=m.face.begin();fi!=m.face.end();fi++) //for all faces do
{ {
if(!(*f).IsS()) for(j=0;j<3;j++) //for all edges
{ {
for(j=0;j<3;j++) if(fi->V(j)->IsS()) continue;
{
if ((*f).IsBorder(j))
{
BEdges++;
if(!(IsManifold(*f,j))) if((*fi).IsBorder(j)) //found an unvisited border edge
{ {
(*f).SetS(); he.Set(&(*fi),j,fi->V(j)); //set the face-face iterator to the current face, edge and vertex
hei.Set(&(*f),j,f->V(j)); vector<Point3x> hole; //start of a new hole
he=hei; hole.push_back(fi->P(j)); // including the first vertex
do numholev++;
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.
{ {
he.NextB(); Point3x newpoint = he.v->P(); //select its vertex.
he.f->SetS(); if(he.v->IsS()) //check if this vertex was selected already, because then we have an additional hole.
// BEdges++;
}
while (he.f!=hei.f);
//BEdges--;
numholes++;
}
}
}
}
}
}
else
{ {
for(f=g;f!=m.face.end();++f) //cut and paste the additional hole.
{ vector<Point3x> hole2;
for(j=0;j<3;j++) int index = find(hole.begin(),hole.end(),newpoint) - hole.begin();
{ for(int i=index; i<hole.size(); i++)
if ((*f).IsBorder(j)) hole2.push_back(hole[i]);
{
BEdges++; hole.resize(index);
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
}
holes.push_back(hole);
} }
} }
} }
} numholes = holes.size();
if (Manifold) fprintf(index,"<p>Number of holes/boundaries: %d </p>\n", numholes);
{ printf("\t Number of holes/boundaries: %d \n", numholes);
fprintf(index, "<p> Number of holes: %d </p> \n <p> Number of border edges: %d </p>", numholes, BEdges);
printf("\t Number of holes: %d \n", numholes);
printf("\t Number of border edges: %d\n", BEdges);
s = new(char[25]); s = new(char[25]);
vn = new ValueNode; vn = new ValueNode;
en = new EntryNode; en = new EntryNode;
@ -566,6 +578,17 @@ void main(int argc,char ** argv){
sn->addOwnSlot(osn); sn->addOwnSlot(osn);
ng->addNode(osn); ng->addNode(osn);
if(numholes>0)
{
int BEdges = 0;
printf("\t Edges per hole/boundary:\n\t (");
for(int i=0; i<numholes; i++)
{
if(i==numholes-1){ printf("%i)\n",holes[i].size()); BEdges++;}
else{ printf("%i, ",holes[i].size()); BEdges++;}
}
s = new(char[25]); s = new(char[25]);
vn = new ValueNode; vn = new ValueNode;
en = new EntryNode; en = new EntryNode;
@ -574,30 +597,15 @@ void main(int argc,char ** argv){
vn->setValue(s); vn->setValue(s);
en->addValue(*vn); en->addValue(*vn);
en->type = "Integer"; en->type = "Integer";
osn->setName("Number of Border Edges"); osn->setName("Number of Border Edges");
osn->addEntry(*en); osn->addEntry(*en);
sn->addOwnSlot(osn); sn->addOwnSlot(osn);
ng->addNode(osn); ng->addNode(osn);
} }
}
else else
{ printf( "\t Number of holes: UNDEFINED, mesh is non-manifold \n");
fprintf(index, "<p> Number of border edges: %d </p>", BEdges);
printf("\t Number of border edges: %d\n", BEdges);
s = new(char[25]);
vn = new ValueNode;
en = new EntryNode;
osn = new OwnSlotNode;
sprintf(s,"%d",BEdges);
vn->setValue(s);
en->addValue(*vn);
en->type = "Integer";
osn->setName("Number of Border Edges");
osn->addEntry(*en);
sn->addOwnSlot(osn);
ng->addNode(osn);
}
// Mesh Volume // Mesh Volume
float vol = m.Volume(); float vol = m.Volume();
@ -620,30 +628,38 @@ void main(int argc,char ** argv){
sn->addOwnSlot(osn); sn->addOwnSlot(osn);
ng->addNode(osn); ng->addNode(osn);
} }
else
{
printf("\t Volume: UNDEFINED, mesh is either non-manifold or has holes \n");
fprintf(index,"Volume: UNDEFINED, mesh is either non-manifold or has holes \n");
}
// CONNECTED COMPONENTS // CONNECTED COMPONENTS
vector<int> nrfaces;
for(f=m.face.begin();f!=m.face.end();++f) for(fi=m.face.begin();fi!=m.face.end();++fi)
(*f).ClearS(); (*fi).ClearS();
g=m.face.begin(); f=g; gi=m.face.begin(); fi=gi;
int CountComp=0; int CountOrient=0; int Compindex=0;
stack<MyMesh::FaceIterator> sf; stack<MyMesh::FaceIterator> sf;
MyMesh::FaceType *l; MyMesh::FaceType *l;
for(f=m.face.begin();f!=m.face.end();++f) for(fi=m.face.begin();fi!=m.face.end();++fi)
{ {
if (!(*f).IsS()) if (!(*fi).IsS())
{ {
(*f).SetS(); (*fi).SetS();
sf.push(f); (*fi).Q()=Compindex;
nrfaces.push_back(1);
sf.push(fi);
while (!sf.empty()) while (!sf.empty())
{ {
g=sf.top(); gi=sf.top();
he.Set(&(*g),0,g->V(0)); he.Set(&(*gi),0,gi->V(0));
sf.pop(); sf.pop();
for(j=0;j<3;++j) for(j=0;j<3;++j)
if( !(*g).IsBorder(j) ) {
if( !(*gi).IsBorder(j) )
{ {
l=he.f->FFp(j); l=he.f->FFp(j);
if( !(*l).IsS() ) if( !(*l).IsS() )
@ -653,16 +669,18 @@ void main(int argc,char ** argv){
} }
} }
} }
CountComp++; }
Compindex++;
} }
} }
fprintf(index, "<p> Number of connected components: %d </p>", CountComp); int numcomponents = nrfaces.size();
printf("\t Number of connected components: %d\n", CountComp); fprintf(index, "<p> Number of connected components: %d </p>", numcomponents);
printf("\t Number of connected components: %d\n", numcomponents);
s = new(char[25]); s = new(char[25]);
vn = new ValueNode; vn = new ValueNode;
en = new EntryNode; en = new EntryNode;
osn = new OwnSlotNode; osn = new OwnSlotNode;
sprintf(s,"%d",CountComp); sprintf(s,"%d",numcomponents);
vn->setValue(s); vn->setValue(s);
en->addValue(*vn); en->addValue(*vn);
en->type = "Integer"; en->type = "Integer";
@ -671,13 +689,14 @@ void main(int argc,char ** argv){
osn->addEntry(*en); osn->addEntry(*en);
sn->addOwnSlot(osn); sn->addOwnSlot(osn);
ng->addNode(osn); ng->addNode(osn);
if(CountComp ==1)
{ //GENUS --> 2( #components - genus ) = #vertices + #faces - #edge - #boundary_loops = eulernumber - #holes
int eulero; //v-e+f //eulero = (mesh.vn-count_uv) - (count_e)+mesh.fn;
eulero = (m.vn-count_uv)- (count_e+BEdges)+m.fn;
int eulernumber = (m.vn-count_uv) + m.fn - count_e;
if(Manifold) if(Manifold)
{ {
int genus = (2-eulero)>>1; int genus = -( 0.5 * (eulernumber - numholes) - numcomponents );
fprintf(index, "<p> Genus: %d </p> \n ", genus); fprintf(index, "<p> Genus: %d </p> \n ", genus);
printf( "\t Genus: %d \n", genus); printf( "\t Genus: %d \n", genus);
s = new(char[25]); s = new(char[25]);
@ -694,6 +713,10 @@ void main(int argc,char ** argv){
sn->addOwnSlot(osn); sn->addOwnSlot(osn);
ng->addNode(osn); ng->addNode(osn);
} }
else //(!Manifold)
{
fprintf( index,"<p>Genus: UNDEFINED, mesh is non-manifold </p>\n");
printf( "Genus: UNDEFINED, mesh is non-manifold \n");
} }
// REGULARITY // REGULARITY
@ -702,12 +725,12 @@ void main(int argc,char ** argv){
int inc=0; int inc=0;
for(v=m.vert.begin();v!=m.vert.end();++v) for(v=m.vert.begin();v!=m.vert.end();++v)
(*v).ClearS(); (*v).ClearS();
for(f=m.face.begin();f!=m.face.end();++f) for(fi=m.face.begin();fi!=m.face.end();++fi)
{ {
for (j=0; j<3; j++) for (j=0; j<3; j++)
{ {
he.Set(&(*f),j,f->V(j)); he.Set(&(*fi),j,fi->V(j));
if (!(*f).IsBorder(j) && !(*f).IsBorder((j+2)%3) && !f->V(j)->IsS()) if (!(*fi).IsBorder(j) && !(*fi).IsBorder((j+2)%3) && !fi->V(j)->IsS())
{ {
hei=he; hei=he;
inc=1; inc=1;
@ -728,11 +751,11 @@ void main(int argc,char ** argv){
Regular=false; Regular=false;
if (inc!=6 && inc!=5) if (inc!=6 && inc!=5)
Semiregular=false; Semiregular=false;
f->V(j)->SetS(); fi->V(j)->SetS();
} }
else else
f->V(j)->SetS(); fi->V(j)->SetS();
} }
if (Semiregular==false) if (Semiregular==false)
break; break;
@ -817,32 +840,32 @@ void main(int argc,char ** argv){
} }
else else
{ {
for(f=m.face.begin();f!=m.face.end();++f) for(fi=m.face.begin();fi!=m.face.end();++fi)
{ {
(*f).ClearS(); (*fi).ClearS();
(*f).ClearUserBit(0); (*fi).ClearUserBit(0);
} }
g=m.face.begin(); f=g; gi=m.face.begin(); fi=gi;
for(f=m.face.begin();f!=m.face.end();++f) for(fi=m.face.begin();fi!=m.face.end();++fi)
{ {
if (!(*f).IsS()) if (!(*fi).IsS())
{ {
(*f).SetS(); (*fi).SetS();
sf.push(f); sf.push(fi);
while (!sf.empty()) while (!sf.empty())
{ {
g=sf.top(); gi=sf.top();
sf.pop(); sf.pop();
for(j=0;j<3;++j) for(j=0;j<3;++j)
{ {
if( !(*g).IsBorder(j) ) if( !(*gi).IsBorder(j) )
{ {
he.Set(&(*g),0,g->V(0)); he.Set(&(*gi),0,gi->V(0));
l=he.f->FFp(j); l=he.f->FFp(j);
he.Set(&(*g),j,g->V(j)); he.Set(&(*gi),j,gi->V(j));
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( !(*g).IsUserBit(0) ) if( !(*gi).IsUserBit(0) )
{ {
if (he.v!=hei.v) // bene if (he.v!=hei.v) // bene
{ {
@ -1017,16 +1040,16 @@ void main(int argc,char ** argv){
if (m.fn<300000) if (m.fn<300000)
{ {
bool SelfInt=false; bool SelfInt=false;
for(f=m.face.begin();f!=m.face.end();++f) for(fi=m.face.begin();fi!=m.face.end();++fi)
{ {
for(g=++f , f--;g!=m.face.end();++g) for(gi=++fi , fi--;gi!=m.face.end();++gi)
{ {
if ((*f).FFp(0)!=&(*g) && (*f).FFp(1)!=&(*g) && (*f).FFp(2)!=&(*g) && if ((*fi).FFp(0)!=&(*gi) && (*fi).FFp(1)!=&(*gi) && (*fi).FFp(2)!=&(*gi) &&
f->V(0)!=g->V(0) && f->V(0)!=g->V(1) && f->V(0)!=g->V(2) && fi->V(0)!=gi->V(0) && fi->V(0)!=gi->V(1) && fi->V(0)!=gi->V(2) &&
f->V(1)!=g->V(0) && f->V(1)!=g->V(1) && f->V(1)!=g->V(2) && fi->V(1)!=gi->V(0) && fi->V(1)!=gi->V(1) && fi->V(1)!=gi->V(2) &&
f->V(2)!=g->V(0) && f->V(2)!=g->V(1) && f->V(2)!=g->V(2)) fi->V(2)!=gi->V(0) && fi->V(2)!=gi->V(1) && fi->V(2)!=gi->V(2))
{ {
if (NoDivTriTriIsect(f->V(0)->P(), f->V(1)->P(), f->V(2)->P(),g->V(0)->P(), g->V(1)->P(), g->V(2)->P()) ) if (NoDivTriTriIsect(fi->V(0)->P(), fi->V(1)->P(), fi->V(2)->P(),gi->V(0)->P(), gi->V(1)->P(), gi->V(2)->P()) )
SelfInt=true; SelfInt=true;
} }
} }
@ -1080,6 +1103,7 @@ void main(int argc,char ** argv){
if((ans == "S")||(ans == "s")) if((ans == "S")||(ans == "s"))
{
cout<< "\t available formats: [ply, off, stl] "<<endl; cout<< "\t available formats: [ply, off, stl] "<<endl;
cout<< "\t enter format"<<endl; cout<< "\t enter format"<<endl;
cin>>ans; cin>>ans;
@ -1095,7 +1119,7 @@ void main(int argc,char ** argv){
else if(ans == "off") else if(ans == "off")
tri::io::ExporterOFF<MyMesh>::Save(m,filesave); tri::io::ExporterOFF<MyMesh>::Save(m,filesave);
}
doc.addSlots(sn); doc.addSlots(sn);
OwnSlotsNode* ossn = new OwnSlotsNode; OwnSlotsNode* ossn = new OwnSlotsNode;