2006-05-16 23:54:50 +02:00
|
|
|
|
|
|
|
// mesh definition
|
|
|
|
//#include <vcg/simplex/vertex/with/vn.h>
|
|
|
|
//#include <vcg/simplex/face/with/af.h>
|
2011-04-01 19:07:57 +02:00
|
|
|
//#include <vcg/complex/complex.h>
|
2006-05-16 23:54:50 +02:00
|
|
|
|
2008-12-19 11:43:36 +01:00
|
|
|
#include<vcg/simplex/vertex/base.h>
|
|
|
|
#include<vcg/simplex/face/base.h>
|
2006-05-16 23:54:50 +02:00
|
|
|
#include<vcg/simplex/face/topology.h>
|
|
|
|
|
2011-04-01 19:07:57 +02:00
|
|
|
#include<vcg/complex/complex.h>
|
2006-05-16 23:54:50 +02:00
|
|
|
|
2011-04-01 19:07:57 +02:00
|
|
|
#include <vcg/complex/algorithms/update/bounding.h>
|
|
|
|
#include <vcg/complex/algorithms/update/topology.h>
|
|
|
|
#include <vcg/complex/algorithms/update/normal.h>
|
|
|
|
#include <vcg/complex/algorithms/update/flag.h>
|
|
|
|
#include <vcg/complex/algorithms/clustering.h>
|
2006-05-16 23:54:50 +02:00
|
|
|
|
|
|
|
// input output
|
|
|
|
#include <wrap/io_trimesh/import_ply.h>
|
|
|
|
#include <wrap/io_trimesh/export_ply.h>
|
|
|
|
|
|
|
|
// std
|
|
|
|
#include <vector>
|
|
|
|
#include <time.h>
|
|
|
|
|
|
|
|
using namespace vcg;
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
class MyFace;
|
|
|
|
class MyVertex;
|
|
|
|
|
[ Changes in definition of TriMesh: PART I ]
Note for the developers: the change to make to existing projects is very little
but strictly necessary to compile. This change IS NOT backward compliant.
==== OLD ==== way to define a TriMesh:
// forward declarations
class MyVertex;
class MyEdge;
class MyFace;
class MyVertex: public VertexSimp2 < MyVertex, MyEdge, MyFace, vertex::Coord3f,...other components>{};
class MyFace: public FaceSimp2 < MyVertex, MyEdge, MyFace, face::VertexRef,...other components>{};
class MyMesh: public TriMesh<vector<MyVertex>,vector<MyFace> >{};
==== NEW ==== way to define a TriMesh:
// forward declarations
class MyVertex;
class MyEdge;
class MyFace;
// declaration of which types is used as VertexType, which type is used as FaceType and so on...
class MyUsedTypes: public vcg::UsedType < vcg::Use<MyVertex>::AsVertexType,
vcg::Use<MyFace>::AsFaceType>{};
class MyVertex: public Vertex < MyUsedTypes, vertex::Coord3f,...other components>{};
class MyFace: public Face < MyUsedTypes, face::VertexRef,...other components>{};
class MyMesh: public TriMesh<vector<MyVertex>,vector<MyFace> >{};
===== classes introduced
[vcg::UsedType] : it is a class containing all the types that must be passed to the definition of Vertex, Face, Edge... This
class replaces the list of typenames to pass as first templates and the need to specify the maximal simplicial. So
<MyVertex, MyEdge, MyFace becomes <MyUsedTypes<
and
VertexSimp2 becomes Vertex
[vcg::Use] : an auxiliary class to give a simple way to specify the role of a type
Note 2: the order of templates parameters to vcg::UsedTypes is unimportant, e.g:
class MyUsedTypes: public vcg::UsedType <vcg::Use<MyVertex>::AsVertexType,
vcg::Use<MyEdge>::AsEdgeType,
vcg::Use<MyFace>::AsFaceType>{};
is the same as:
class MyUsedTypes: public vcg::UsedType <vcg::Use<MyFace>::AsFaceType,
vcg::Use<MyEdge>::AsEdgeType,
vcg::Use<MyVertex>::AsVertexType>{};
Note 3: you only need to specify the type you use. If you do not have edges you do not need
to include vcg::Use<MyEdge>::AsEdgeType in the template list of UsedTypes.
==== the Part II will be a tiny change to the class TriMesh it self.
2010-03-15 11:44:40 +01:00
|
|
|
struct MyUsedTypes : public UsedTypes< Use<MyVertex> ::AsVertexType,
|
|
|
|
Use<MyFace> ::AsFaceType>{};
|
|
|
|
|
|
|
|
class MyVertex : public Vertex< MyUsedTypes, vertex::Coord3f, vertex::Normal3f, vertex::BitFlags >{};
|
|
|
|
class MyFace : public Face < MyUsedTypes, face::VertexRef, face::Normal3f, face::BitFlags > {};
|
2006-05-16 23:54:50 +02:00
|
|
|
class MyMesh : public vcg::tri::TriMesh< vector<MyVertex>, vector<MyFace> > {};
|
|
|
|
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
if(argc<3)
|
|
|
|
{
|
|
|
|
printf(
|
|
|
|
"\n trimesh_clustering ("__DATE__")\n"
|
|
|
|
" Visual Computing Group I.S.T.I. C.N.R.\n"
|
|
|
|
"Usage: PlyRefine filein.ply fileout.ply [opt] \n"
|
|
|
|
"options: \n"
|
|
|
|
"-k cellnum approx number of cluster that should be defined; (default 10e5)\n"
|
2010-04-30 11:56:37 +02:00
|
|
|
"-s size in absolute units the size of the clustering cell (override the previous param)\n"
|
2006-05-21 08:40:31 +02:00
|
|
|
"-d enable the duplication of faces for double surfaces\n"
|
2006-05-16 23:54:50 +02:00
|
|
|
);
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
2006-05-21 08:40:31 +02:00
|
|
|
int i=3;
|
|
|
|
int CellNum=100000;
|
|
|
|
float CellSize=0;
|
|
|
|
bool DupFace=false;
|
2006-05-16 23:54:50 +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])
|
|
|
|
{
|
|
|
|
case 'k' : CellNum=atoi(argv[i+1]); ++i; printf("Using %i clustering cells\n",CellNum); break;
|
|
|
|
case 's' : CellSize=atof(argv[i+1]); ++i; printf("Using %5f as clustering cell size\n",CellSize); break;
|
2006-05-21 08:40:31 +02:00
|
|
|
case 'd' : DupFace=true; printf("Enabling the duplication of faces for double surfaces\n"); break;
|
|
|
|
|
2006-05-16 23:54:50 +02:00
|
|
|
default : {printf("Error unable to parse option '%s'\n",argv[i]); exit(0);}
|
|
|
|
}
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2006-05-18 15:58:11 +02:00
|
|
|
vcg::tri::UpdateNormals<MyMesh>::PerFace(m);
|
2006-05-16 23:54:50 +02:00
|
|
|
printf("Input mesh vn:%i fn:%i\n",m.vn,m.fn);
|
2010-04-30 11:56:37 +02:00
|
|
|
vcg::tri::Clustering<MyMesh, vcg::tri::AverageColorCell<MyMesh> > Grid;
|
2006-05-21 08:40:31 +02:00
|
|
|
Grid.DuplicateFaceParam=DupFace;
|
2006-05-16 23:54:50 +02:00
|
|
|
Grid.Init(m.bbox,CellNum,CellSize);
|
|
|
|
|
|
|
|
printf("Clustering to %i cells\n",Grid.Grid.siz[0]*Grid.Grid.siz[1]*Grid.Grid.siz[2] );
|
|
|
|
printf("Grid of %i x %i x %i cells\n",Grid.Grid.siz[0],Grid.Grid.siz[1],Grid.Grid.siz[2]);
|
|
|
|
printf("with cells size of %.2f x %.2f x %.2f units\n",Grid.Grid.voxel[0],Grid.Grid.voxel[1],Grid.Grid.voxel[2]);
|
|
|
|
|
|
|
|
int t0=clock();
|
2010-04-30 11:56:37 +02:00
|
|
|
Grid.AddMesh(m);
|
2006-05-16 23:54:50 +02:00
|
|
|
int t1=clock();
|
2010-04-30 11:56:37 +02:00
|
|
|
Grid.ExtractMesh(m);
|
2006-05-16 23:54:50 +02:00
|
|
|
int t2=clock();
|
|
|
|
printf("Output mesh vn:%i fn:%i\n",m.vn,m.fn);
|
|
|
|
printf("Simplified in :%i msec (%i+%i)\n",t2-t0,t1-t0,t2-t1);
|
|
|
|
|
|
|
|
vcg::tri::io::PlyInfo pi;
|
|
|
|
vcg::tri::io::ExporterPLY<MyMesh>::Save(m,argv[2],pi.mask);
|
|
|
|
return 0;
|
|
|
|
}
|