2006-01-11 12:13:43 +01:00
|
|
|
#include <vector>
|
|
|
|
|
2008-12-19 11:43:36 +01:00
|
|
|
#include<vcg/simplex/vertex/base.h>
|
|
|
|
#include<vcg/simplex/face/base.h>
|
2006-01-11 12:13:43 +01:00
|
|
|
#include<vcg/simplex/face/topology.h>
|
|
|
|
|
2011-04-01 19:07:57 +02:00
|
|
|
#include<vcg/complex/complex.h>
|
|
|
|
#include<vcg/complex/allocate.h>
|
|
|
|
#include<vcg/complex/append.h>
|
|
|
|
#include<vcg/complex/algorithms/clean.h>
|
|
|
|
#include<vcg/complex/algorithms/clip.h>
|
|
|
|
#include<vcg/complex/algorithms/update/bounding.h>
|
2006-01-22 18:13:17 +01:00
|
|
|
|
2006-01-11 12:13:43 +01:00
|
|
|
|
|
|
|
// input output
|
|
|
|
#include <wrap/io_trimesh/import_ply.h>
|
|
|
|
#include <wrap/io_trimesh/export_ply.h>
|
|
|
|
|
|
|
|
// std
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
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::BitFlags >{};
|
|
|
|
class MyFace : public Face < MyUsedTypes, face::VertexRef, face::BitFlags > {};
|
2006-01-11 12:13:43 +01:00
|
|
|
class MyMesh : public vcg::tri::TriMesh< vector<MyVertex>, vector<MyFace> > {};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int main(int argc,char **argv )
|
|
|
|
{
|
|
|
|
if(argc<2)
|
|
|
|
{
|
|
|
|
printf( "\n trimesh_join ("__DATE__")\n"
|
|
|
|
"Visual Computing Group I.S.T.I. C.N.R.\n"
|
2006-01-22 18:13:17 +01:00
|
|
|
"Usage: trimesh_join [opt] filename.ply [filename.ply | *] \n"
|
|
|
|
"where opt can be:\n"
|
|
|
|
" -b xmin ymin zmin xmax ymax zmax : \n"
|
|
|
|
" Returns only mesh composed by faces inside specified bbox\n"
|
|
|
|
" -t Just scan all the input files computing the total bbox\n"
|
2006-01-11 12:13:43 +01:00
|
|
|
);
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
MyMesh ml,mr;
|
2006-01-22 18:13:17 +01:00
|
|
|
Box3f ClipBB,TotBB;
|
|
|
|
bool ClipFlag=false,MergeFlag=true;
|
2006-01-11 12:13:43 +01:00
|
|
|
int i=1;
|
2006-01-22 18:13:17 +01:00
|
|
|
// Parsing option loop
|
|
|
|
while(argv[i][0]=='-')
|
|
|
|
{
|
|
|
|
switch(argv[i][1])
|
|
|
|
{
|
|
|
|
case 'b': {
|
|
|
|
if(argc<i+7) {
|
|
|
|
printf("Error in parsing bbox option");
|
|
|
|
exit(0);
|
|
|
|
}
|
2006-10-13 15:17:23 +02:00
|
|
|
ClipBB.min=Point3f::Construct(atof(argv[i+1]),atof(argv[i+2]),atof(argv[i+3]));
|
|
|
|
ClipBB.max=Point3f::Construct(atof(argv[i+4]),atof(argv[i+5]),atof(argv[i+6]));
|
2006-01-22 18:13:17 +01:00
|
|
|
i+=6;
|
|
|
|
printf("Clipping incoming meshes with box:\n (%7.4f %7.4f %7.4f) - (%7.4f %7.4f %7.4f)\n",
|
|
|
|
ClipBB.min[0],ClipBB.min[1],ClipBB.min[2],
|
|
|
|
ClipBB.max[0],ClipBB.max[1],ClipBB.max[2]);
|
|
|
|
ClipFlag=true;
|
|
|
|
} break;
|
|
|
|
case 't': MergeFlag=false; break;
|
|
|
|
default : printf("Unknown option '%s'\n",argv[i]);
|
|
|
|
}
|
|
|
|
++i;
|
|
|
|
}
|
2006-01-11 12:13:43 +01:00
|
|
|
while(i<argc)
|
|
|
|
{
|
|
|
|
if(vcg::tri::io::ImporterPLY<MyMesh>::Open(mr,argv[i])!=0)
|
|
|
|
{
|
|
|
|
printf("Error reading file %s\n",argv[1]);
|
|
|
|
exit(0);
|
|
|
|
}
|
2006-01-22 18:13:17 +01:00
|
|
|
printf("Input mesh %3i vn:%9i fn:%9i\n",i, mr.vn, mr.fn);
|
|
|
|
if(ClipFlag)
|
|
|
|
{
|
2010-07-05 12:27:38 +02:00
|
|
|
tri::GenericVertexInterpolator<MyMesh> interp(mr);
|
|
|
|
tri::TriMeshClipper<MyMesh>::Box(ClipBB,interp,mr);
|
2006-01-22 18:13:17 +01:00
|
|
|
printf(" clipped to vn:%9i fn:%9i\n", mr.vn, mr.fn);
|
|
|
|
}
|
|
|
|
tri::UpdateBounding<MyMesh>::Box(mr);
|
|
|
|
TotBB.Add(mr.bbox);
|
|
|
|
|
|
|
|
if(MergeFlag) tri::Append<MyMesh,MyMesh>::Mesh(ml,mr); // append mesh mr to ml
|
2006-01-11 12:13:43 +01:00
|
|
|
++i;
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("Output mesh vn:%i fn:%i\n",ml.vn,ml.fn);
|
|
|
|
|
|
|
|
tri::io::ExporterPLY<MyMesh>::Save(ml,"joined.ply");
|
2006-01-11 16:43:18 +01:00
|
|
|
int dv=tri::Clean<MyMesh>::RemoveDuplicateVertex(ml);
|
|
|
|
printf("Removed %i duplicated vertices\n",dv);
|
2006-01-11 12:13:43 +01:00
|
|
|
tri::io::ExporterPLY<MyMesh>::Save(ml,"joined_unif.ply");
|
2006-01-22 18:13:17 +01:00
|
|
|
printf("Final BBox of mesh :\n (%7.4f %7.4f %7.4f) - (%7.4f %7.4f %7.4f)\n",
|
|
|
|
TotBB.min[0],TotBB.min[1],TotBB.min[2],
|
|
|
|
TotBB.max[0],TotBB.max[1],TotBB.max[2]);
|
|
|
|
|
2006-01-11 12:13:43 +01:00
|
|
|
}
|
|
|
|
|