2012-10-09 10:43:35 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* VCGLib o o *
|
|
|
|
* Visual and Computer Graphics Library o o *
|
|
|
|
* _ O _ *
|
2016-06-13 07:29:25 +02:00
|
|
|
* Copyright(C) 2004-2016 \/)\/ *
|
2012-10-09 10:43:35 +02:00
|
|
|
* Visual Computing Lab /\/| *
|
|
|
|
* ISTI - Italian National Research Council | *
|
|
|
|
* \ *
|
|
|
|
* All rights reserved. *
|
|
|
|
* *
|
|
|
|
* This program is free software; you can redistribute it and/or modify *
|
|
|
|
* it under the terms of the GNU General Public License as published by *
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or *
|
|
|
|
* (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
* This program is distributed in the hope that it will be useful, *
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt) *
|
|
|
|
* for more details. *
|
|
|
|
* *
|
|
|
|
****************************************************************************/
|
2011-04-01 19:07:57 +02:00
|
|
|
#include<vcg/complex/complex.h>
|
|
|
|
#include <vcg/complex/algorithms/create/ball_pivoting.h>
|
2006-10-13 15:16:46 +02:00
|
|
|
|
|
|
|
// input output
|
|
|
|
#include <wrap/io_trimesh/import_ply.h>
|
|
|
|
#include <wrap/io_trimesh/export_ply.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,
|
2016-01-25 15:47:06 +01:00
|
|
|
Use<MyFace> ::AsFaceType>{};
|
[ 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
|
|
|
|
|
|
|
class MyVertex : public Vertex< MyUsedTypes, vertex::Coord3f, vertex::Normal3f, vertex::BitFlags, vertex::Mark>{};
|
|
|
|
class MyFace : public Face < MyUsedTypes, face::VertexRef, face::Normal3f, face::BitFlags > {};
|
2006-10-13 15:16:46 +02:00
|
|
|
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)
|
2016-01-25 15:47:06 +01:00
|
|
|
{
|
|
|
|
printf(
|
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"
|
2016-01-25 15:47:06 +01:00
|
|
|
);
|
|
|
|
exit(0);
|
|
|
|
}
|
2006-10-13 15:16:46 +02:00
|
|
|
|
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;
|
2016-01-25 15:47:06 +01: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 '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;
|
|
|
|
|
|
|
|
default : {printf("Error unable to parse option '%s'\n",argv[i]); exit(0);}
|
|
|
|
}
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
if(radius == 0)
|
2006-10-14 14:04:42 +02:00
|
|
|
printf("Autodetecting ball radius...\n");
|
2006-10-13 15:16:46 +02:00
|
|
|
|
2016-01-25 15:47:06 +01:00
|
|
|
MyMesh m;
|
|
|
|
|
|
|
|
if(vcg::tri::io::ImporterPLY<MyMesh>::Open(m,argv[1])!=0)
|
|
|
|
{
|
2006-10-13 15:16:46 +02:00
|
|
|
printf("Error reading file %s\n",argv[1]);
|
2016-01-25 15:47:06 +01:00
|
|
|
exit(0);
|
|
|
|
}
|
2006-10-13 15:16:46 +02:00
|
|
|
vcg::tri::UpdateBounding<MyMesh>::Box(m);
|
2012-10-09 09:12:31 +02:00
|
|
|
vcg::tri::UpdateNormal<MyMesh>::PerFace(m);
|
2012-10-15 09:52:40 +02:00
|
|
|
printf("Input mesh vn:%i fn:%i\n",m.VN(),m.FN());
|
2006-10-13 15:16:46 +02:00
|
|
|
|
|
|
|
int t0=clock();
|
|
|
|
// Initialization
|
2016-01-25 15:47:06 +01:00
|
|
|
tri::BallPivoting<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
|
2008-09-30 12:09:45 +02:00
|
|
|
pivot.BuildMesh(callback);
|
2006-10-13 15:16:46 +02:00
|
|
|
|
|
|
|
int t2=clock();
|
|
|
|
|
2012-10-15 09:52:40 +02:00
|
|
|
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);
|
2016-01-25 15:47:06 +01:00
|
|
|
|
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
|
|
|
|
|
|
|
}
|