trimesh_join.cpp
Go to the documentation of this file.
00001 /****************************************************************************
00002 * VCGLib                                                            o o     *
00003 * Visual and Computer Graphics Library                            o     o   *
00004 *                                                                _   O  _   *
00005 * Copyright(C) 2004-2012                                           \/)\/    *
00006 * Visual Computing Lab                                            /\/|      *
00007 * ISTI - Italian National Research Council                           |      *
00008 *                                                                    \      *
00009 * All rights reserved.                                                      *
00010 *                                                                           *
00011 * This program is free software; you can redistribute it and/or modify      *
00012 * it under the terms of the GNU General Public License as published by      *
00013 * the Free Software Foundation; either version 2 of the License, or         *
00014 * (at your option) any later version.                                       *
00015 *                                                                           *
00016 * This program is distributed in the hope that it will be useful,           *
00017 * but WITHOUT ANY WARRANTY; without even the implied warranty of            *
00018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             *
00019 * GNU General Public License (http://www.gnu.org/licenses/gpl.txt)          *
00020 * for more details.                                                         *
00021 *                                                                           *
00022 ****************************************************************************/
00023 #include<vcg/complex/complex.h>
00024 #include<vcg/complex/append.h>
00025 #include<vcg/complex/algorithms/clean.h>
00026 #include<vcg/complex/algorithms/clip.h>
00027 #include<vcg/complex/algorithms/update/bounding.h>
00028 
00029 // input output
00030 #include <wrap/io_trimesh/import_ply.h>
00031 #include <wrap/io_trimesh/export_ply.h>
00032 
00033 // std
00034 #include <vector>
00035 
00036 using namespace vcg;
00037 using namespace std;
00038 
00039 class MyFace;
00040 class MyVertex;
00041 
00042 struct MyUsedTypes : public UsedTypes<  Use<MyVertex>           ::AsVertexType,
00043                                                                                 Use<MyFace>                     ::AsFaceType>{};
00044 
00045 class MyVertex  : public Vertex <MyUsedTypes, vertex::Coord3f, vertex::BitFlags  >{};
00046 class MyFace    : public Face   < MyUsedTypes, face::VertexRef, face::BitFlags > {};
00047 class MyMesh    : public vcg::tri::TriMesh< vector<MyVertex>, vector<MyFace> > {};
00048 
00049 
00050 
00051 int main(int argc,char **argv )
00052 {
00053  if(argc<2)
00054     {
00055         printf( "Usage: trimesh_join [opt] filename.ply [filename.ply | *] \n"
00056                 "where opt can be:\n"
00057                 "   -b xmin ymin zmin xmax ymax zmax  : \n"
00058                 "      Returns only mesh composed by faces inside specified bbox\n"
00059                 "   -t Just scan all the input files computing the total bbox\n"
00060             );
00061         exit(0);
00062     }
00063 
00064   MyMesh ml,mr;
00065   Box3f ClipBB,TotBB;
00066   bool ClipFlag=false,MergeFlag=true;
00067     int i=1;
00068   // Parsing option loop
00069   while(argv[i][0]=='-')
00070   {
00071     switch(argv[i][1])
00072     {
00073       case 'b': {
00074               if(argc<i+7) {
00075                 printf("Error in parsing bbox option");
00076                   exit(0);
00077               }
00078               ClipBB.min=Point3f::Construct(atof(argv[i+1]),atof(argv[i+2]),atof(argv[i+3]));
00079               ClipBB.max=Point3f::Construct(atof(argv[i+4]),atof(argv[i+5]),atof(argv[i+6]));
00080               i+=6;
00081               printf("Clipping incoming meshes with box:\n (%7.4f %7.4f %7.4f) - (%7.4f %7.4f %7.4f)\n",
00082                     ClipBB.min[0],ClipBB.min[1],ClipBB.min[2],
00083                     ClipBB.max[0],ClipBB.max[1],ClipBB.max[2]);
00084               ClipFlag=true;
00085           } break;
00086     case 't': MergeFlag=false; break;
00087     default : printf("Unknown option '%s'\n",argv[i]);
00088     }
00089   ++i;
00090   }
00091     while(i<argc)
00092         {
00093           if(vcg::tri::io::ImporterPLY<MyMesh>::Open(mr,argv[i])!=0)
00094           {
00095         printf("Error reading file  %s\n",argv[1]);
00096               exit(0);
00097           }
00098       printf("Input mesh %3i           vn:%9i fn:%9i\n",i, mr.VN(), mr.FN());
00099       if(ClipFlag)
00100       {
00101         tri::GenericVertexInterpolator<MyMesh> interp(mr);
00102         tri::TriMeshClipper<MyMesh>::Box(ClipBB,interp,mr);
00103         printf("              clipped to vn:%9i fn:%9i\n", mr.VN(), mr.FN());
00104       }
00105       tri::UpdateBounding<MyMesh>::Box(mr);
00106       TotBB.Add(mr.bbox);
00107 
00108       if(MergeFlag) tri::Append<MyMesh,MyMesh>::Mesh(ml,mr); // append mesh mr to ml
00109         ++i;
00110         }
00111 
00112   printf("Output mesh vn:%i fn:%i\n",ml.VN(),ml.FN());
00113 
00114   tri::io::ExporterPLY<MyMesh>::Save(ml,"joined.ply");
00115   int dv=tri::Clean<MyMesh>::RemoveDuplicateVertex(ml);
00116   printf("Removed %i duplicated vertices\n",dv);
00117   tri::io::ExporterPLY<MyMesh>::Save(ml,"joined_unif.ply");
00118   printf("Final BBox of mesh :\n (%7.4f %7.4f %7.4f) - (%7.4f %7.4f %7.4f)\n",
00119                     TotBB.min[0],TotBB.min[1],TotBB.min[2],
00120                     TotBB.max[0],TotBB.max[1],TotBB.max[2]);
00121 
00122 }
00123 


shape_reconstruction
Author(s): Roberto Martín-Martín
autogenerated on Sat Jun 8 2019 18:38:20