2006-10-13 15:16:46 +02:00
|
|
|
|
|
|
|
// mesh definition
|
|
|
|
//#include <vcg/simplex/vertex/with/vn.h>
|
|
|
|
//#include <vcg/simplex/face/with/af.h>
|
|
|
|
//#include <vcg/complex/trimesh/base.h>
|
|
|
|
|
|
|
|
#include<vcg/simplex/vertexplus/base.h>
|
|
|
|
#include<vcg/simplex/faceplus/base.h>
|
|
|
|
#include<vcg/simplex/face/topology.h>
|
|
|
|
|
|
|
|
#include<vcg/complex/trimesh/base.h>
|
|
|
|
|
|
|
|
#include <vcg/complex/trimesh/update/bounding.h>
|
|
|
|
#include <vcg/complex/trimesh/update/topology.h>
|
|
|
|
#include <vcg/complex/trimesh/update/normal.h>
|
|
|
|
#include <vcg/complex/trimesh/update/flag.h>
|
|
|
|
#include <vcg/complex/trimesh/create/ball_pivoting.h>
|
|
|
|
|
|
|
|
// input output
|
|
|
|
#include <wrap/io_trimesh/import_ply.h>
|
|
|
|
#include <wrap/io_trimesh/export_ply.h>
|
|
|
|
|
|
|
|
// std
|
2006-10-16 16:28:07 +02:00
|
|
|
#include <iostream>
|
2006-10-13 15:16:46 +02:00
|
|
|
#include <vector>
|
|
|
|
#include <time.h>
|
|
|
|
|
|
|
|
using namespace vcg;
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
class MyEdge; // dummy prototype never used
|
|
|
|
class MyFace;
|
|
|
|
class MyVertex;
|
|
|
|
|
2006-10-13 16:06:58 +02:00
|
|
|
class MyVertex : public VertexSimp2< MyVertex, MyEdge, MyFace, vert::Coord3f, vert::Normal3f, vert::BitFlags, vert::Mark>{};
|
2006-10-13 15:16:46 +02:00
|
|
|
class MyFace : public FaceSimp2 < MyVertex, MyEdge, MyFace, face::VertexRef, face::Normal3f, face::BitFlags > {};
|
|
|
|
class MyMesh : public vcg::tri::TriMesh< vector<MyVertex>, vector<MyFace> > {};
|
|
|
|
|
2006-10-16 16:28:07 +02:00
|
|
|
bool callback(int percent, const char *str) {
|
|
|
|
cout << "str: " << str << " " << percent << "%\n";
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2006-10-13 15:16:46 +02:00
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
if(argc<3)
|
|
|
|
{
|
|
|
|
printf(
|
|
|
|
"\n trimesh_ball_pivoting ("__DATE__")\n"
|
|
|
|
" Visual Computing Group I.S.T.I. C.N.R.\n"
|
2006-10-16 10:50:11 +02:00
|
|
|
"Usage: trimesh_ball_pivoting filein.ply fileout.ply [opt]\n"
|
2006-10-13 15:16:46 +02:00
|
|
|
"options: \n"
|
|
|
|
"-r <val> radius of the rolling ball\n"
|
2006-10-13 15:35:39 +02:00
|
|
|
"-c <val> clustering radius (as fraction of radius) default: 0.05\n"
|
2006-10-13 15:16:46 +02:00
|
|
|
);
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
2006-10-14 14:04:42 +02:00
|
|
|
float radius = 0.0f;
|
2006-10-13 15:35:39 +02:00
|
|
|
float clustering = 0.05;
|
2006-10-13 16:06:58 +02:00
|
|
|
int i = 3;
|
2006-10-13 15:16:46 +02:00
|
|
|
while(i<argc)
|
|
|
|
{
|
|
|
|
if(argv[i][0]!='-')
|
|
|
|
{printf("Error unable to parse option '%s'\n",argv[i]); exit(0);}
|
|
|
|
switch(argv[i][1])
|
|
|
|
{
|
2006-10-13 16:06:58 +02:00
|
|
|
case 'r' : radius = atof(argv[++i]); printf("Using %f sphere radius\n",radius); break;
|
|
|
|
case 'c' : clustering = atof(argv[++i]); printf("Using %f clustering radius\n",clustering); break;
|
2006-10-13 15:35:39 +02:00
|
|
|
|
2006-10-13 15:16:46 +02:00
|
|
|
default : {printf("Error unable to parse option '%s'\n",argv[i]); exit(0);}
|
|
|
|
}
|
|
|
|
++i;
|
|
|
|
}
|
2006-10-14 14:04:42 +02:00
|
|
|
if(radius == 0)
|
|
|
|
printf("Autodetecting ball radius...\n");
|
|
|
|
|
2006-10-13 15:16:46 +02:00
|
|
|
MyMesh m;
|
|
|
|
|
|
|
|
if(vcg::tri::io::ImporterPLY<MyMesh>::Open(m,argv[1])!=0)
|
|
|
|
{
|
|
|
|
printf("Error reading file %s\n",argv[1]);
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
vcg::tri::UpdateBounding<MyMesh>::Box(m);
|
|
|
|
vcg::tri::UpdateNormals<MyMesh>::PerFace(m);
|
|
|
|
printf("Input mesh vn:%i fn:%i\n",m.vn,m.fn);
|
|
|
|
|
|
|
|
int t0=clock();
|
|
|
|
// Initialization
|
2006-10-13 16:06:58 +02:00
|
|
|
tri::Pivot<MyMesh> pivot(m, radius, clustering);
|
2006-10-14 14:04:42 +02:00
|
|
|
printf("Ball radius: %f\nClustering points withing %f radii\n", pivot.radius, clustering);
|
2006-10-13 15:16:46 +02:00
|
|
|
|
|
|
|
int t1=clock();
|
|
|
|
// the main processing
|
2006-10-16 16:28:07 +02:00
|
|
|
pivot.buildMesh(callback);
|
2006-10-13 15:16:46 +02:00
|
|
|
|
|
|
|
int t2=clock();
|
|
|
|
|
|
|
|
printf("Output mesh vn:%i fn:%i\n",m.vn,m.fn);
|
2006-10-13 15:35:39 +02:00
|
|
|
printf("Created in :%i msec (%i+%i)\n",t2-t0,t1-t0,t2-t1);
|
2006-10-13 15:16:46 +02:00
|
|
|
|
|
|
|
vcg::tri::io::PlyInfo pi;
|
2006-10-13 15:35:39 +02:00
|
|
|
vcg::tri::io::ExporterPLY<MyMesh>::Save(m,argv[2],pi.mask);
|
|
|
|
return 0;
|
2006-10-13 15:16:46 +02:00
|
|
|
|
|
|
|
}
|