00001 #include <vector>
00002
00003 #include<vcg/simplex/vertex/base.h>
00004 #include<vcg/simplex/face/base.h>
00005 #include<vcg/simplex/face/topology.h>
00006
00007 #include<vcg/complex/trimesh/base.h>
00008 #include<vcg/complex/trimesh/allocate.h>
00009 #include<vcg/complex/trimesh/append.h>
00010 #include<vcg/complex/trimesh/clean.h>
00011 #include<vcg/complex/trimesh/clip.h>
00012 #include<vcg/complex/trimesh/update/bounding.h>
00013
00014
00015
00016 #include <wrap/io_trimesh/import_ply.h>
00017 #include <wrap/io_trimesh/export_ply.h>
00018
00019
00020 #include <vector>
00021
00022 using namespace vcg;
00023 using namespace std;
00024
00025 class MyFace;
00026 class MyVertex;
00027
00028 struct MyUsedTypes : public UsedTypes< Use<MyVertex> ::AsVertexType,
00029 Use<MyFace> ::AsFaceType>{};
00030
00031 class MyVertex : public Vertex <MyUsedTypes, vertex::Coord3f, vertex::BitFlags >{};
00032 class MyFace : public Face < MyUsedTypes, face::VertexRef, face::BitFlags > {};
00033 class MyMesh : public vcg::tri::TriMesh< vector<MyVertex>, vector<MyFace> > {};
00034
00035
00036
00037 int main(int argc,char **argv )
00038 {
00039 if(argc<2)
00040 {
00041 printf( "\n trimesh_join ("__DATE__")\n"
00042 "Visual Computing Group I.S.T.I. C.N.R.\n"
00043 "Usage: trimesh_join [opt] filename.ply [filename.ply | *] \n"
00044 "where opt can be:\n"
00045 " -b xmin ymin zmin xmax ymax zmax : \n"
00046 " Returns only mesh composed by faces inside specified bbox\n"
00047 " -t Just scan all the input files computing the total bbox\n"
00048 );
00049 exit(0);
00050 }
00051
00052 MyMesh ml,mr;
00053 Box3f ClipBB,TotBB;
00054 bool ClipFlag=false,MergeFlag=true;
00055 int i=1;
00056
00057 while(argv[i][0]=='-')
00058 {
00059 switch(argv[i][1])
00060 {
00061 case 'b': {
00062 if(argc<i+7) {
00063 printf("Error in parsing bbox option");
00064 exit(0);
00065 }
00066 ClipBB.min=Point3f::Construct(atof(argv[i+1]),atof(argv[i+2]),atof(argv[i+3]));
00067 ClipBB.max=Point3f::Construct(atof(argv[i+4]),atof(argv[i+5]),atof(argv[i+6]));
00068 i+=6;
00069 printf("Clipping incoming meshes with box:\n (%7.4f %7.4f %7.4f) - (%7.4f %7.4f %7.4f)\n",
00070 ClipBB.min[0],ClipBB.min[1],ClipBB.min[2],
00071 ClipBB.max[0],ClipBB.max[1],ClipBB.max[2]);
00072 ClipFlag=true;
00073 } break;
00074 case 't': MergeFlag=false; break;
00075 default : printf("Unknown option '%s'\n",argv[i]);
00076 }
00077 ++i;
00078 }
00079 while(i<argc)
00080 {
00081 if(vcg::tri::io::ImporterPLY<MyMesh>::Open(mr,argv[i])!=0)
00082 {
00083 printf("Error reading file %s\n",argv[1]);
00084 exit(0);
00085 }
00086 printf("Input mesh %3i vn:%9i fn:%9i\n",i, mr.vn, mr.fn);
00087 if(ClipFlag)
00088 {
00089 tri::GenericVertexInterpolator<MyMesh> interp(mr);
00090 tri::TriMeshClipper<MyMesh>::Box(ClipBB,interp,mr);
00091 printf(" clipped to vn:%9i fn:%9i\n", mr.vn, mr.fn);
00092 }
00093 tri::UpdateBounding<MyMesh>::Box(mr);
00094 TotBB.Add(mr.bbox);
00095
00096 if(MergeFlag) tri::Append<MyMesh,MyMesh>::Mesh(ml,mr);
00097 ++i;
00098 }
00099
00100 printf("Output mesh vn:%i fn:%i\n",ml.vn,ml.fn);
00101
00102 tri::io::ExporterPLY<MyMesh>::Save(ml,"joined.ply");
00103 int dv=tri::Clean<MyMesh>::RemoveDuplicateVertex(ml);
00104 printf("Removed %i duplicated vertices\n",dv);
00105 tri::io::ExporterPLY<MyMesh>::Save(ml,"joined_unif.ply");
00106 printf("Final BBox of mesh :\n (%7.4f %7.4f %7.4f) - (%7.4f %7.4f %7.4f)\n",
00107 TotBB.min[0],TotBB.min[1],TotBB.min[2],
00108 TotBB.max[0],TotBB.max[1],TotBB.max[2]);
00109
00110 }
00111