Restructuring code
This commit is contained in:
parent
4d691096e2
commit
a2bdeea8f6
apps/trimeshinfo
|
@ -24,6 +24,9 @@
|
||||||
History
|
History
|
||||||
|
|
||||||
$Log: not supported by cvs2svn $
|
$Log: not supported by cvs2svn $
|
||||||
|
Revision 1.16 2005/12/12 12:09:08 cignoni
|
||||||
|
Changed names of clean function and tested inertia.h
|
||||||
|
|
||||||
Revision 1.15 2005/12/12 11:29:21 corsini
|
Revision 1.15 2005/12/12 11:29:21 corsini
|
||||||
Minor changes
|
Minor changes
|
||||||
|
|
||||||
|
@ -92,12 +95,16 @@ Revision 1.2 2005/01/03 16:13:09 rita_borgo
|
||||||
Added Standard comments
|
Added Standard comments
|
||||||
|
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
|
// Standard headers
|
||||||
|
#include <fstream>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <stack>
|
#include <stack>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
// VCG headers
|
||||||
#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>
|
||||||
|
@ -123,7 +130,6 @@ using namespace std;
|
||||||
#include <vcg/space/index/grid_static_ptr.h>
|
#include <vcg/space/index/grid_static_ptr.h>
|
||||||
#include "defs.h"
|
#include "defs.h"
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
using namespace vcg;
|
using namespace vcg;
|
||||||
|
|
||||||
|
|
||||||
|
@ -138,18 +144,6 @@ typedef CMesh::VertexIterator VertexIterator;
|
||||||
typedef Point3<CMesh::ScalarType> Point3x;
|
typedef Point3<CMesh::ScalarType> Point3x;
|
||||||
typedef vector<Point3x> Hole;
|
typedef vector<Point3x> Hole;
|
||||||
|
|
||||||
void OpenMesh(const char *filename, CMesh &m)
|
|
||||||
{
|
|
||||||
int err = tri::io::Importer<CMesh>::Open(m,filename);
|
|
||||||
if(err)
|
|
||||||
{
|
|
||||||
printf("Error in reading %s: '%s'\n",filename,
|
|
||||||
tri::io::Importer<CMesh>::ErrorMsg(err));
|
|
||||||
exit(-1);
|
|
||||||
}
|
|
||||||
printf("\t read mesh `%s'\n", filename);
|
|
||||||
}
|
|
||||||
|
|
||||||
typedef CMesh::VertexPointer VertexPointer;
|
typedef CMesh::VertexPointer VertexPointer;
|
||||||
typedef CMesh::VertexIterator VertexIterator;
|
typedef CMesh::VertexIterator VertexIterator;
|
||||||
typedef CMesh::FaceContainer FaceContainer;
|
typedef CMesh::FaceContainer FaceContainer;
|
||||||
|
@ -170,6 +164,22 @@ struct MeshInfo
|
||||||
bool SelfIntersect;
|
bool SelfIntersect;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void OpenMesh(const char *filename, CMesh &m)
|
||||||
|
{
|
||||||
|
printf(" Mesh loading...");
|
||||||
|
|
||||||
|
int err = tri::io::Importer<CMesh>::Open(m,filename);
|
||||||
|
|
||||||
|
if (err)
|
||||||
|
{
|
||||||
|
printf("\n Error during loading %s: '%s'\n",filename,
|
||||||
|
tri::io::Importer<CMesh>::ErrorMsg(err));
|
||||||
|
exit(-1);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
printf(" done.\n\n");
|
||||||
|
}
|
||||||
|
|
||||||
void initMeshInfo(MeshInfo &mi)
|
void initMeshInfo(MeshInfo &mi)
|
||||||
{
|
{
|
||||||
memset(&mi, 0, sizeof(mi));
|
memset(&mi, 0, sizeof(mi));
|
||||||
|
@ -177,52 +187,66 @@ void initMeshInfo(MeshInfo &mi)
|
||||||
|
|
||||||
void PrintMeshInfo(MeshInfo &mi)
|
void PrintMeshInfo(MeshInfo &mi)
|
||||||
{
|
{
|
||||||
printf("\t Mesh info:\n");
|
printf(" *** Mesh information ***\n\n");
|
||||||
printf("\t M: '%s'\n\t Number of vertices: %d \n", mi.FileName.c_str(), mi.vn);
|
printf(" Mesh: '%s' \n", mi.FileName.c_str());
|
||||||
printf("\t Number of faces: %d \n", mi.fn);
|
printf(" Number of vertices: %d \n", mi.vn);
|
||||||
|
printf(" Number of faces: %d \n", mi.fn);
|
||||||
|
printf(" Number of edges: %d \n", mi.count_e);
|
||||||
|
printf(" Number of internal edges: %d \n", mi.count_e-mi.boundary_e);
|
||||||
|
printf(" Number of boundary edges: %i \n", mi.boundary_e);
|
||||||
|
printf(" Number of degenerated faces: %d\n", mi.count_fd);
|
||||||
|
printf(" Number of unreferenced vertices: %d\n",mi.count_uv);
|
||||||
|
printf(" Number of holes/boundaries: %d \n", mi.numholes);
|
||||||
|
|
||||||
if (!mi.Manifold)
|
if ((mi.Manifold)&&(mi.Oriented)&&(!mi.numholes))
|
||||||
printf("\t Manifold: NO\n");
|
printf(" Volume: %f \n", mi.Volume);
|
||||||
else
|
|
||||||
printf("\t Manifold: YES\n");
|
|
||||||
|
|
||||||
printf("\t Number of edges: %d \n", mi.count_e);
|
|
||||||
printf("\t Number of internal edges: %d \n", mi.count_e-mi.boundary_e);
|
|
||||||
printf("\t Number of boundary edges: %i \n", mi.boundary_e);
|
|
||||||
printf("\t Number of degenerated faces: %d\n", mi.count_fd);
|
|
||||||
printf("\t Number of unreferenced vertices: %d\n",mi.count_uv);
|
|
||||||
printf("\t Number of holes/boundaries: %d \n", mi.numholes);
|
|
||||||
if (mi.Volume)
|
|
||||||
printf("\t Volume: %f \n", mi.Volume);
|
|
||||||
else
|
else
|
||||||
printf("\t Volume: UNDEFINED, mesh is either non-manifold or has holes \n");
|
printf(" Volume: UNDEFINED (a closed oriented manifold is requested)\n");
|
||||||
|
|
||||||
printf("\t Number of connected components: %d\n", mi.numcomponents);
|
printf(" Number of connected components: %d\n", mi.numcomponents);
|
||||||
if (mi.Manifold)
|
|
||||||
printf("\t Genus: %d \n", mi.Genus);
|
|
||||||
else
|
|
||||||
printf("\t Genus (n/a)\n");
|
|
||||||
|
|
||||||
if (mi.Regular)
|
|
||||||
printf("\t Type of Mesh: REGULAR\n");
|
|
||||||
else if (mi.Semiregular)
|
|
||||||
printf("\t Type of Mesh: SEMIREGULAR\n");
|
|
||||||
else
|
|
||||||
printf("\t Type of Mesh: IRREGULAR\n");
|
|
||||||
|
|
||||||
|
// Orientation
|
||||||
if (!mi.Manifold)
|
if (!mi.Manifold)
|
||||||
{
|
{
|
||||||
printf("\t Orientable Mesh: NO\n");
|
printf(" Orientable Mesh: NO\n");
|
||||||
printf("\t Oriented Mesh: NO\n");
|
printf(" Oriented Mesh: NO\n");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
printf("\t Orientable Mesh: %s\n",mi.Orientable?"Yes":"No");
|
if (mi.Orientable)
|
||||||
printf("\t Oriented Mesh: %s\n",mi.Oriented?"Yes":"No");
|
printf(" Orientable Mesh: YES\n");
|
||||||
|
else
|
||||||
|
printf(" Orientable Mesh: NO\n");
|
||||||
|
|
||||||
|
if (mi.Oriented)
|
||||||
|
printf(" Oriented Mesh: YES\n");
|
||||||
|
else
|
||||||
|
printf(" Oriented Mesh: NO\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("\t Number of duplicated vertices found: %d\n",mi.dv);
|
// Manifold
|
||||||
printf("\t Self Intersection: %s\n",mi.SelfIntersect?"Yes":"No");
|
if (!mi.Manifold)
|
||||||
|
printf(" Manifold: NO\n");
|
||||||
|
else
|
||||||
|
printf(" Manifold: YES\n");
|
||||||
|
|
||||||
|
// Genus
|
||||||
|
if (mi.Manifold)
|
||||||
|
printf(" Genus: %d \n", mi.Genus);
|
||||||
|
else
|
||||||
|
printf(" Genus (n/a)\n");
|
||||||
|
|
||||||
|
// Mesh Type
|
||||||
|
if (mi.Regular)
|
||||||
|
printf(" Mesh Type: REGULAR\n");
|
||||||
|
else if (mi.Semiregular)
|
||||||
|
printf(" Mesh Type: SEMIREGULAR\n");
|
||||||
|
else
|
||||||
|
printf(" Mesh Type: IRREGULAR\n");
|
||||||
|
|
||||||
|
// Further details
|
||||||
|
printf(" Number of duplicated vertices found: %d\n", mi.dv);
|
||||||
|
printf(" Self Intersection: %s\n", mi.SelfIntersect?"Yes":"No");
|
||||||
}
|
}
|
||||||
|
|
||||||
void SaveXMLInfo(MeshInfo &mi)
|
void SaveXMLInfo(MeshInfo &mi)
|
||||||
|
@ -274,12 +298,12 @@ void SaveXMLInfo(MeshInfo &mi)
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
doc.addNode(mi.Orientable?"Yes":"No", VALUE_STRING,"Orientable Mesh");
|
doc.addNode(mi.Orientable?"Yes":"No", VALUE_STRING,"Orientable Mesh");
|
||||||
doc.addNode( mi.Oriented?"Yes":"No", VALUE_STRING,"Oriented Mesh");
|
doc.addNode(mi.Oriented?"Yes":"No", VALUE_STRING,"Oriented Mesh");
|
||||||
}
|
}
|
||||||
|
|
||||||
sprintf(s,"%d",mi.dv);
|
sprintf(s,"%d",mi.dv);
|
||||||
doc.addNode(s, VALUE_INTEGER,"Duplicated Vertices");
|
doc.addNode(s, VALUE_INTEGER,"Duplicated Vertices");
|
||||||
doc.addNode( mi.SelfIntersect?"Yes":"No", VALUE_STRING,"Self Intersection");
|
doc.addNode(mi.SelfIntersect?"Yes":"No", VALUE_STRING,"Self Intersection");
|
||||||
|
|
||||||
doc.finalizeMain();
|
doc.finalizeMain();
|
||||||
doc.printXMLTree();
|
doc.printXMLTree();
|
||||||
|
@ -287,71 +311,75 @@ void SaveXMLInfo(MeshInfo &mi)
|
||||||
|
|
||||||
void SaveHtmlInfo(MeshInfo &mi)
|
void SaveHtmlInfo(MeshInfo &mi)
|
||||||
{
|
{
|
||||||
//...TODO...
|
ofstream fout;
|
||||||
|
|
||||||
|
fout.open("result.txt", ios::out);
|
||||||
|
|
||||||
|
if (!fout)
|
||||||
|
{
|
||||||
|
printf("\n Impossible to create the HTML output file.\n");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
char dquotes = 32; // double quotes
|
||||||
|
|
||||||
|
fout << "<table>" << endl;
|
||||||
|
fout << "...todo..." << endl;
|
||||||
|
fout << "<\table>";
|
||||||
|
|
||||||
|
fout.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char ** argv)
|
int main(int argc, char ** argv)
|
||||||
{
|
{
|
||||||
CMesh m;
|
CMesh m;
|
||||||
bool saveFlag = false;
|
bool verboseFlag = true; // Verbose mode on/off
|
||||||
bool verboseFlag = true;
|
bool XmlFlag= false; // XML output enabled/disabled
|
||||||
bool XmlFlag= false;
|
bool HtmlFlag = false; // HTML output enabled/disabled
|
||||||
bool HtmlFlag = false;
|
|
||||||
|
|
||||||
string SaveName;
|
string SaveName;
|
||||||
|
|
||||||
MeshInfo mi;
|
MeshInfo mi;
|
||||||
initMeshInfo(mi);
|
initMeshInfo(mi);
|
||||||
printf("-------------------------------\n"
|
|
||||||
" TriMeshInfo V.1.2 \n"
|
printf("\n -------------------------------\n"
|
||||||
" http://vcg.isti.cnr.it\n"
|
" TriMeshInfo V.1.2 \n"
|
||||||
" release date: "__DATE__"\n"
|
" http://vcg.isti.cnr.it\n"
|
||||||
"-------------------------------\n\n");
|
" release date: "__DATE__"\n"
|
||||||
|
" -------------------------------\n\n\n");
|
||||||
|
|
||||||
|
|
||||||
// load input meshes.
|
// Parsing arguments
|
||||||
|
///////////////////////////////////////////////
|
||||||
|
|
||||||
if (argc <= 1)
|
if (argc <= 1)
|
||||||
{
|
{
|
||||||
printf(MSG_ERR_N_ARGS);
|
printf(MSG_ERR_N_ARGS);
|
||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
mi.FileName=argv[1];
|
|
||||||
|
|
||||||
for(int i=3; i < argc; i++)
|
mi.FileName = argv[1];
|
||||||
|
|
||||||
|
for(int i = 2; i < argc; i++)
|
||||||
{
|
{
|
||||||
if(argv[i][0] == '-')
|
if (argv[i][0] == '-')
|
||||||
{
|
{
|
||||||
switch(argv[i][1])
|
switch(argv[i][1])
|
||||||
{
|
{
|
||||||
case 's' :
|
case 'q' :
|
||||||
saveFlag = true;
|
// Quiet mode, disable verbose mode
|
||||||
SaveName = argv[i][2];
|
verboseFlag = false;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'x' :
|
case 'x' :
|
||||||
if(argv[i][2]=='y')
|
// Enable XML output
|
||||||
{
|
XmlFlag = true;
|
||||||
XmlFlag = true;
|
|
||||||
printf("Enable XML output\n");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
XmlFlag = false;
|
|
||||||
printf("Disable XML output\n");
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'v' :
|
case 'h' :
|
||||||
if(argv[i][2]=='y')
|
// Enable HTML output
|
||||||
{
|
HtmlFlag = true;
|
||||||
verboseFlag = true;
|
|
||||||
printf("Enable Ascii Printing\n");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
verboseFlag = false;
|
|
||||||
printf("Disable Ascii Printing\n");
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
@ -362,18 +390,33 @@ int main(int argc, char ** argv)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Mesh loading
|
||||||
|
//////////////////////////////////////////
|
||||||
|
|
||||||
OpenMesh(mi.FileName.c_str(),m);
|
OpenMesh(mi.FileName.c_str(),m);
|
||||||
mi.vn=m.vn;
|
|
||||||
mi.fn=m.fn;
|
|
||||||
|
|
||||||
// DEGENERATED FACES
|
|
||||||
|
// Mesh processing
|
||||||
|
//////////////////////////////////////////
|
||||||
|
|
||||||
|
printf(" Mesh processing...\n\n");
|
||||||
|
|
||||||
|
// Number of vertices
|
||||||
|
mi.vn = m.vn;
|
||||||
|
|
||||||
|
// Number of faces
|
||||||
|
mi.fn = m.fn;
|
||||||
|
|
||||||
|
// DEGENERATED FACES => (faces with area zero)
|
||||||
mi.count_fd = tri::Clean<CMesh>::RemoveZeroAreaFace(m);
|
mi.count_fd = tri::Clean<CMesh>::RemoveZeroAreaFace(m);
|
||||||
|
|
||||||
vcg::tri::UpdateTopology<CMesh>::FaceFace(m);
|
// Update topology (face-to-face)
|
||||||
|
tri::UpdateTopology<CMesh>::FaceFace(m);
|
||||||
|
|
||||||
// UNREFERENCED VERTEX
|
// UNREFERENCED VERTEX
|
||||||
mi.count_uv = tri::Clean<CMesh>::RemoveUnreferencedVertex(m);
|
mi.count_uv = tri::Clean<CMesh>::RemoveUnreferencedVertex(m);
|
||||||
|
|
||||||
|
// Update flags
|
||||||
tri::UpdateFlags<CMesh>::Clear(m);
|
tri::UpdateFlags<CMesh>::Clear(m);
|
||||||
|
|
||||||
// IS MANIFOLD
|
// IS MANIFOLD
|
||||||
|
@ -389,35 +432,41 @@ int main(int argc, char ** argv)
|
||||||
mi.BEdges = tri::Clean<CMesh>::BorderEdges(m, mi.numholes);
|
mi.BEdges = tri::Clean<CMesh>::BorderEdges(m, mi.numholes);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mesh Volume
|
|
||||||
if (mi.numholes==0) mi.Volume = m.Volume();
|
|
||||||
|
|
||||||
// CONNECTED COMPONENTS
|
// CONNECTED COMPONENTS
|
||||||
mi.numcomponents = tri::Clean<CMesh>::ConnectedComponents(m);
|
mi.numcomponents = tri::Clean<CMesh>::ConnectedComponents(m);
|
||||||
|
|
||||||
|
// ORIENTATION
|
||||||
|
if (mi.Manifold)
|
||||||
|
tri::Clean<CMesh>::IsOrientedMesh(m, mi.Oriented, mi.Orientable);
|
||||||
|
|
||||||
|
// VOLUME (require a closed oriented manifold)
|
||||||
|
if ((mi.Manifold)&&(mi.Oriented)&&(!mi.numholes))
|
||||||
|
mi.Volume = m.Volume();
|
||||||
|
|
||||||
|
// GENUS
|
||||||
if(mi.Manifold)
|
if(mi.Manifold)
|
||||||
mi.Genus = tri::Clean<CMesh>::MeshGenus(m,mi.count_uv, mi.numholes,
|
mi.Genus = tri::Clean<CMesh>::MeshGenus(m,mi.count_uv, mi.numholes,
|
||||||
mi.numcomponents, mi.count_e);
|
mi.numcomponents, mi.count_e);
|
||||||
|
|
||||||
// REGULARITY
|
// REGULARITY
|
||||||
tri::Clean<CMesh>::IsRegularMesh(m, mi.Regular, mi.Semiregular);
|
tri::Clean<CMesh>::IsRegularMesh(m, mi.Regular, mi.Semiregular);
|
||||||
|
|
||||||
// ORIENTABLE E ORIENTED MESH
|
|
||||||
if (mi.Manifold)
|
|
||||||
tri::Clean<CMesh>::IsOrientedMesh(m, mi.Oriented, mi.Orientable);
|
|
||||||
|
|
||||||
|
// DUPLICATED VERTICES
|
||||||
mi.dv = tri::Clean<CMesh>::RemoveDuplicateVertex(m);
|
mi.dv = tri::Clean<CMesh>::RemoveDuplicateVertex(m);
|
||||||
|
|
||||||
// SELF INTERSECTION
|
// SELF INTERSECTION
|
||||||
mi.SelfIntersect = tri::Clean<CMesh>::SelfIntersections(m);
|
mi.SelfIntersect = tri::Clean<CMesh>::SelfIntersections(m);
|
||||||
|
|
||||||
|
|
||||||
tri::Inertia<CMesh> mm;
|
tri::Inertia<CMesh> mm;
|
||||||
mm.Compute(m);
|
mm.Compute(m);
|
||||||
|
|
||||||
printf("Volume of mesh %f\n",mm.Mass());
|
/* Save the clean mesh
|
||||||
if (saveFlag)
|
if (saveFlag)
|
||||||
tri::io::Exporter<CMesh>::Save(m, SaveName.c_str());
|
tri::io::Exporter<CMesh>::Save(m, SaveName.c_str());
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Mesh Information Output
|
||||||
|
//////////////////////////////////////////
|
||||||
|
|
||||||
// Print mesh information
|
// Print mesh information
|
||||||
if(verboseFlag)
|
if(verboseFlag)
|
||||||
|
|
Loading…
Reference in New Issue