diff --git a/apps/trimeshinfo/main.cpp b/apps/trimeshinfo/main.cpp index 39360914..ca69f56e 100644 --- a/apps/trimeshinfo/main.cpp +++ b/apps/trimeshinfo/main.cpp @@ -24,6 +24,9 @@ History $Log: not supported by cvs2svn $ +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 Added new routines. Self-intersection first release @@ -62,6 +65,7 @@ using namespace std; #include "defs.h" using namespace vcg; +using namespace tri; using namespace face; class MyFace; @@ -92,52 +96,114 @@ inline char* GetExtension(char* filename) return NULL; } + +typedef MyMesh::VertexPointer VertexPointer; +typedef MyMesh::VertexIterator VertexIterator; + +/* classe di confronto per l'algoritmo di individuazione vertici duplicati*/ +template +class DuplicateVert_Compare{ +public: + inline bool operator() (VertexIterator a, VertexIterator b) + { + return *a < *b; + } +}; + +static int DuplicateVertex( MyMesh & m ) // V1.0 +{ + if(m.vert.size()==0 || m.vn==0) + return 0; + std::map mp; + int i,j; + VertexIterator vi; + int deleted=0; + int k=0; + int num_vert = m.vert.size(); + vector perm(num_vert); + for(vi=m.vert.begin(); vi!=m.vert.end(); ++vi, ++k) + perm[k] = &(*vi); + + DuplicateVert_Compare 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() ) + { + VertexPointer t = perm[i]; + mp[perm[i]] = perm[j]; + ++i; + (*t).SetD(); + deleted++; + } + else + { + j = i; + ++i; + } + } + return deleted; +} void main(int argc,char ** argv){ char *fmt; MyMesh m; + bool DEBUG = false; //load the mesh //argv[1]=(char*)"c:\\checkup\\debug\\column1m.ply"; - //argv[1] = "C:\\Documents and Settings\\Rita\\Desktop\\MeshReader\\trimeshinfo\\Debug\\prova0.ply"; + //argv[1] = "C:\\sf\\apps\\msvc\\trimeshinfo\\Release\\prism.off"; +//argv[1] = "C:\\sf\\apps\\msvc\\trimeshinfo\\Release\\prova1.ply"; + + // print program info + printf("-------------------------------\n" + " TriMeshInfo V.1.01 \n" + " http://vcg.isti.cnr.it\n" + " release date: "__DATE__"\n" + "-------------------------------\n\n"); - // print program info - printf("-------------------------------\n" - " TriMeshInfo\n" - " release date: "__DATE__"\n" - "-------------------------------\n\n"); - + if(DEBUG) + argv[1] = "C:\\sf\\apps\\msvc\\trimeshinfo\\Release\\twirl.off"; + + else + { // load input meshes. if(argc <= 1) { - printf(MSG_ERR_N_ARGS); - exit(-1); + printf(MSG_ERR_N_ARGS); + exit(-1); } + } - printf("reading the mesh `%s'...", argv[1]); OpenMesh(argv[1],m); FILE * index; index = fopen((string(argv[1])+string("2.html")).c_str(),"w"); - fprintf(index,"

TriMeshInfo: This is the result for %s

\n\n\n", argv[1]); + fprintf(index,"

Mesh info: %s

\n\n\n", argv[1]); fprintf(index,"

GENERAL INFO

\n\n"); fprintf(index,"

Number of vertices: %d

\n", m.vn); fprintf(index,"

Number of faces: %d

\n", m.fn); - printf("Number of vertices: %d \n", m.vn); - printf("Number of faces: %d \n", m.fn); - if (m.Volume()!=0) - { - fprintf(index,"

Volume: %d

\n", m.Volume()); - printf("Volume: %d \n", m.Volume()); - } - Color4b Color=m.C(); - fprintf(index, "

Object color(4b): %f %f %f

\n\n", Color[0], Color[1], Color[2]); - printf( "Object color(4b): %f %f %f \n\n", Color[0], Color[1], Color[2]); + printf("Mesh info:\n"); + printf(" M: '%s'\n\t Number of vertices: %d \n", argv[1], m.vn); + printf("\t Number of faces: %d \n", m.fn); + if(m.HasPerFaceColor()||m.HasPerVertexColor()) + { + Color4b Color=m.C(); + fprintf(index, "

Object color(4b): %f %f %f

\n\n", Color[0], Color[1], Color[2]); + printf( "\t Object color(4b): %f %f %f \n", Color[0], Color[1], Color[2]); + } vcg::tri::UpdateTopology::FaceFace(m); @@ -169,13 +235,13 @@ void main(int argc,char ** argv){ } if (!Manifold) { - fprintf(index, "

Manifold from lib gives: NO

"); - printf( "Manifold from lib gives: NO\n"); + fprintf(index, "

Manifold: NO

"); + printf( "\t Manifold: NO\n"); } else { - fprintf(index, "

Manifold from lib gives: YES

"); - printf( "Manifold from lib gives: YES\n "); + fprintf(index, "

Manifold: YES

"); + printf( "\t Manifold: YES\n "); } // COUNT EDGES @@ -223,7 +289,7 @@ void main(int argc,char ** argv){ } } fprintf(index, "

Number of edges: %d

\n", count_e); - printf("Number of edges: %d \n", count_e); + printf("\t Number of edges: %d \n", count_e); // DA QUI IN POI!!! @@ -235,14 +301,14 @@ void main(int argc,char ** argv){ if((*fi).Area() == 0) count_fd++; fprintf(index, "

Number of degenerated faces: %d

\n", count_fd); - printf("Number of degenerated faces: %d \n", count_fd); + printf("\t Number of degenerated faces: %d \n", count_fd); // UNREFERENCED VERTEX int count_uv = 0; MyMesh::VertexIterator v; - int deleted = 0; + for(v=m.vert.begin();v!=m.vert.end();++v) (*v).ClearV(); @@ -255,7 +321,7 @@ void main(int argc,char ** argv){ if( !(*v).IsV() ) ++count_uv; fprintf(index,"

Number of unreferenced vertices: %d

\n",count_uv); - printf("Number of unreferenced vertices: %d\n",count_uv); + printf("\t Number of unreferenced vertices: %d\n",count_uv); // HOLES COUNT @@ -315,15 +381,24 @@ void main(int argc,char ** argv){ if (Manifold) { fprintf(index, "

Number of holes: %d

\n

Number of border edges: %d

", numholes, BEdges); - printf("Number of holes: %d \n", numholes, BEdges); - printf("Number of border edges: %d\n", numholes, BEdges); + printf("\t Number of holes: %d \n", numholes, BEdges); + printf("\t Number of border edges: %d\n", numholes, BEdges); } else { fprintf(index, "

Number of border edges: %d

", BEdges); - printf("Number of border edges: %d\n", BEdges); + printf("\t Number of border edges: %d\n", BEdges); } - + + // Mesh Volume + float vol = m.Volume(); + int nuh = numholes; + if((m.Volume()>0.)&&(Manifold)&&(numholes==0)) + { + fprintf(index,"

Volume: %d

\n", m.Volume()); + printf("\t Volume: %f \n", m.Volume()); + } + // CONNECTED COMPONENTS @@ -360,7 +435,7 @@ void main(int argc,char ** argv){ } } fprintf(index, "

Number of connected components: %d

", CountComp); - printf("Number of connected components: %d\n", CountComp); + printf("\t Number of connected components: %d\n", CountComp); if(CountComp ==1) { @@ -370,7 +445,7 @@ void main(int argc,char ** argv){ { int genus = (2-eulero)>>1; fprintf(index, "

Genus: %d

\n ", genus); - printf( "Genus: %d \n", genus); + printf( "\t Genus: %d \n", genus); } } // REGULARITY @@ -420,17 +495,17 @@ void main(int argc,char ** argv){ if (Regular) { fprintf(index, "

Type of Mesh: REGULAR

"); - printf("Type of Mesh: REGULAR\n"); + printf("\t Type of Mesh: REGULAR\n"); } else if (Semiregular) { fprintf(index, "

Type of Mesh: SEMIREGULAR

"); - printf("Type of Mesh: SEMIREGULAR\n"); + printf("\t Type of Mesh: SEMIREGULAR\n"); } else { fprintf(index, "

Type of Mesh: IRREGULAR

"); - printf("Type of Mesh: IRREGULAR\n"); + printf("\t Type of Mesh: IRREGULAR\n"); } // ORIENTABLE E ORIENTED MESH @@ -439,7 +514,7 @@ void main(int argc,char ** argv){ if (!Manifold) { fprintf(index, "

Orientable Mesh: NO

"); - printf( "Orientable Mesh: NO\n"); + printf( "\t Orientable Mesh: NO\n"); } else { @@ -531,23 +606,23 @@ void main(int argc,char ** argv){ if (Orientable) { fprintf(index, "

Orientable Mesh: YES

"); - printf( "Orientable Mesh: YES\n"); + printf( "\t Orientable Mesh: YES\n"); } else { fprintf(index, "

Orientable Mesh: NO

"); - printf( "Orientable Mesh: NO\n"); + printf( "\t Orientable Mesh: NO\n"); } } if (Oriented && Manifold) { fprintf(index, "

Oriented Mesh: YES

"); - printf( "Oriented Mesh: YES\n"); + printf( "\t Oriented Mesh: YES\n"); } else { fprintf(index, "

Oriented Mesh: NO

"); - printf( "Oriented Mesh: NO\n"); + printf( "\t Oriented Mesh: NO\n"); } // SELF INTERSECTION @@ -572,15 +647,27 @@ void main(int argc,char ** argv){ } if (SelfInt) { - fprintf(index, "

Self Intersection: YES

"); - printf( "Self Intersection: YES\n"); + fprintf(index, "

Self Intersection: YES

"); + printf( "\t Self Intersection: YES\n"); } else { fprintf(index, "

Self Intersection: NO

"); - printf( "Self Intersection: NO\n"); + printf( "\t Self Intersection: NO\n"); } } + int dv = DuplicateVertex(m); + if(dv>0) + { + fprintf(index, "

Duplicated vertices: %d

", dv); + printf( "\t Duplicated vertices: %d\n",dv); + } + else + { + fprintf(index, "

Duplicated vertices: NO

"); + printf( "\t Duplicated vertices: NO\n"); + } fclose(index); } +