VCG Library
trimesh_copy.cpp
1 
2 #include <vcg/complex/complex.h>
3 #include <wrap/io_trimesh/import.h>
4 #include <wrap/io_trimesh/export_ply.h>
5 
6 class MyVertex;
7 class MyEdge;
8 class MyFace;
9 
10 struct MyUsedTypes: public vcg::UsedTypes<vcg::Use<MyVertex>::AsVertexType,vcg::Use<MyEdge>::AsEdgeType,vcg::Use<MyFace>::AsFaceType>{};
11 
12 class MyVertex : public vcg::Vertex< MyUsedTypes,vcg::vertex::VFAdj,vcg::vertex::Coord3f,vcg::vertex::Normal3f,vcg::vertex::Mark,vcg::vertex::BitFlags > {};
13 
14 class MyEdge : public vcg::Edge< MyUsedTypes> {};
15 
16 class MyFace : public vcg::Face< MyUsedTypes,
17  vcg::face::VFAdj,
18  vcg::face::VertexRef,
19  vcg::face::BitFlags > {};
20 
21 // the main mesh class
22 class MyMesh : public vcg::tri::TriMesh<std::vector<MyVertex>, std::vector<MyFace> > {};
23 
24 class OcfVertex;
25 class OcfEdge;
26 class OcfFace;
27 
28 // Declaration of the semantic of the used types
29 class OcfUsedTypes: public vcg::UsedTypes < vcg::Use<OcfVertex>::AsVertexType,
30  vcg::Use<OcfEdge >::AsEdgeType,
31  vcg::Use<OcfFace >::AsFaceType >{};
32 
33 
34 // The Main Vertex Class
35 // Most of the attributes are optional and must be enabled before use.
36 // Each vertex needs 40 byte, on 32bit arch. and 44 byte on 64bit arch.
37 
38 class OcfVertex : public vcg::Vertex< OcfUsedTypes,vcg::vertex::InfoOcf,vcg::vertex::Coord3f,vcg::vertex::BitFlags,vcg::vertex::Normal3fOcf,vcg::vertex::VFAdjOcf,vcg::vertex::MarkOcf>
39 {
40 };
41 
42 
43 // The Main Edge Class
44 // Currently it does not contains anything.
45 class OcfEdge : public vcg::Edge<OcfUsedTypes>
46 {
47 };
48 
49 // Each face needs 32 byte, on 32bit arch. and 48 byte on 64bit arch.
50 class OcfFace : public vcg::Face< OcfUsedTypes,vcg::face::InfoOcf,vcg::face::VertexRef,vcg::face::BitFlags,vcg::face::VFAdjOcf> {};
51 
52 class OcfMesh : public vcg::tri::TriMesh< vcg::vertex::vector_ocf<OcfVertex>, vcg::face::vector_ocf<OcfFace> >
53 {
54 };
55 
56 void Usage()
57 {
58  printf(
59  "\nUsage: "\
60  "trimeshcopy fileIn -(n|o) [fileOut]\n"\
61  "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"
62  );
63  exit(-1);
64 }
65 
66 template <class MeshType>
67 bool UnitTest_Append(const char *filename1, const char *filename2)
68 {
69  MeshType mr;
70  MeshType ml;
71 
72  int startOpen=clock();
73  int err=vcg::tri::io::Importer<MeshType>::Open(mr,filename1);
74  if(err)
75  {
76  std::cerr << "Unable to open mesh " << filename1 << " : " << vcg::tri::io::Importer<MyMesh>::ErrorMsg(err) << std::endl;
77  exit(-1);
78  }
79  int endOpen = clock();
80  std::cout << "mesh loaded in " << float(endOpen-startOpen)/CLOCKS_PER_SEC << " msecs. Verts: " << mr.VN() << " Faces: " << mr.FN() << "\n";
81 
82  int startCopy = clock();
84  int endCopy = clock();
85  std::cout << "mesh copied in " << float(endCopy-startCopy)/CLOCKS_PER_SEC << " msecs." << std::endl;
86 
87  assert(ml.VN()==mr.VN());
88  assert(ml.en==mr.en);
89  assert(ml.FN()==mr.FN());
90 
91  int startSave = clock();
92  vcg::tri::io::ExporterPLY<MeshType>::Save(ml,filename2);
93  int endSave = clock();
94  std::cout << "mesh saved in " << float(endSave-startSave)/CLOCKS_PER_SEC << " msecs." << std::endl;
95  return true;
96 }
97 
98 int main(int /*argc*/ ,char**argv)
99 {
100  UnitTest_Append<MyMesh>(argv[1],"out.ply");
101  UnitTest_Append<OcfMesh>(argv[1],"out.ply");
102  return 0;
103 }