trimesh_copy.cpp
Go to the documentation of this file.
00001 
00002 // stuff to define the mesh
00003 #include <vcg/complex/complex.h>
00004 #include <vcg/complex/append.h>
00005 // io
00006 #include <wrap/io_trimesh/import.h>
00007 #include <wrap/io_trimesh/export_ply.h>
00008 
00009 #include <cstdlib>
00010 
00011 #include <sys/timeb.h>
00012 #include <iostream>
00013 #include <string>
00014 
00015 
00016 class MyVertex;
00017 class MyEdge;
00018 class MyFace;
00019 
00020 struct MyUsedTypes: public vcg::UsedTypes<vcg::Use<MyVertex>::AsVertexType,vcg::Use<MyEdge>::AsEdgeType,vcg::Use<MyFace>::AsFaceType>{};
00021 
00022 class MyVertex  : public vcg::Vertex< MyUsedTypes,vcg::vertex::VFAdj,vcg::vertex::Coord3f,vcg::vertex::Normal3f,vcg::vertex::Mark,vcg::vertex::BitFlags  >
00023 {
00024 };
00025 
00026 class MyEdge : public vcg::Edge< MyUsedTypes> {};
00027 
00028 class MyFace    : public vcg::Face< MyUsedTypes,
00029     vcg::face::VFAdj,
00030     vcg::face::VertexRef,
00031     vcg::face::BitFlags > {};
00032 
00033 // the main mesh class
00034 class MyMesh    : public vcg::tri::TriMesh<std::vector<MyVertex>, std::vector<MyFace> > {};
00035 
00036 class OcfVertex;
00037 class OcfEdge;
00038 class OcfFace;
00039 
00040 // Declaration of the semantic of the used types
00041 class OcfUsedTypes: public vcg::UsedTypes < vcg::Use<OcfVertex>::AsVertexType,
00042     vcg::Use<OcfEdge   >::AsEdgeType,
00043     vcg::Use<OcfFace  >::AsFaceType >{};
00044 
00045 
00046 // The Main Vertex Class
00047 // Most of the attributes are optional and must be enabled before use.
00048 // Each vertex needs 40 byte, on 32bit arch. and 44 byte on 64bit arch.
00049 
00050 class OcfVertex  : public vcg::Vertex< OcfUsedTypes,vcg::vertex::InfoOcf,vcg::vertex::Coord3f,vcg::vertex::BitFlags,vcg::vertex::Normal3fOcf,vcg::vertex::VFAdjOcf,vcg::vertex::MarkOcf>
00051 {
00052 };
00053 
00054 
00055 // The Main Edge Class
00056 // Currently it does not contains anything.
00057 class OcfEdge : public vcg::Edge<OcfUsedTypes>
00058 {
00059 };
00060 
00061 // Each face needs 32 byte, on 32bit arch. and 48 byte on 64bit arch.
00062 class OcfFace    : public vcg::Face<  OcfUsedTypes,vcg::face::InfoOcf,vcg::face::VertexRef,vcg::face::BitFlags,vcg::face::VFAdjOcf> {};
00063 
00064 class OcfMesh    : public vcg::tri::TriMesh< vcg::vertex::vector_ocf<OcfVertex>, vcg::face::vector_ocf<OcfFace> >
00065 {
00066 };
00067 
00068 void Usage()
00069 {
00070     printf(
00071         "\nUsage:  "\
00072         "trimeshcopy fileIn -(n|o) [fileOut]\n"\
00073         "trimeshcopy test vcg::MeshCopy efficiency.\nIt imports a fileIn file into a user defined mesh and test how long vcg::MeshCopy needs to copy the imported mesh in a second one.The copy time is expressed in milliseconds.\nIf the -n flag is used a non-optional attributes mesh will be tested, defining -o, instead, the target mesh will be an ocf one.\nA fileOut file can be passed to the tool in order to check if the mesh was successfully copied.\nThe file will be exported in PLY file format.\n"
00074         );
00075     exit(-1);
00076 }
00077 
00078 template <class MeshType>
00079 bool UnitTest_Append(const char *filename1, const char *filename2)
00080 {
00081   MeshType mr;
00082   MeshType ml;
00083 
00084   int startOpen=clock();
00085   int err=vcg::tri::io::Importer<MeshType>::Open(mr,filename1);
00086   if(err)
00087   {
00088       std::cerr << "Unable to open mesh " << filename1 << " : " << vcg::tri::io::Importer<MyMesh>::ErrorMsg(err) << std::endl;
00089       exit(-1);
00090   }
00091   int endOpen = clock();
00092   std::cout << "mesh loaded in " << float(endOpen-startOpen)/CLOCKS_PER_SEC << " msecs. Verts: " << mr.VN() << " Faces: " << mr.FN() << "\n";
00093 
00094   int startCopy = clock();
00095   vcg::tri::Append<MeshType,MeshType>::Mesh(ml,mr,false,true);
00096   int endCopy = clock();
00097   std::cout << "mesh copied in " << float(endCopy-startCopy)/CLOCKS_PER_SEC << " msecs." << std::endl;
00098 
00099   assert(ml.VN()==mr.VN());
00100   assert(ml.en==mr.en);
00101   assert(ml.FN()==mr.FN());
00102 
00103   int startSave = clock();
00104   vcg::tri::io::ExporterPLY<MeshType>::Save(ml,filename2);
00105   int endSave = clock();
00106   std::cout << "mesh saved in " << float(endSave-startSave)/CLOCKS_PER_SEC << " msecs." << std::endl;
00107   return true;
00108 }
00109 
00110 int main(int /*argc*/ ,char**argv)
00111 {
00112     UnitTest_Append<MyMesh>(argv[1],"out.ply");
00113     UnitTest_Append<OcfMesh>(argv[1],"out.ply");
00114     return 0;
00115 }


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