polygonmesh_polychord_collapse.cpp
Go to the documentation of this file.
00001 #include <iostream>
00002 #include <vcg/complex/complex.h>
00003 #include <vcg/complex/algorithms/clean.h>
00004 #include <wrap/io_trimesh/import.h>
00005 #include <wrap/io_trimesh/export.h>
00006 #include <vcg/complex/algorithms/polygon_support.h>
00007 #include <vcg/complex/algorithms/polygon_polychord_collapse.h>
00008 
00009 using namespace vcg;
00010 
00011 class PolyVertex;
00012 class PolyFace;
00013 
00014 struct PolyUsedTypes : public vcg::UsedTypes<
00015         vcg::Use<PolyVertex>::AsVertexType,
00016         vcg::Use<PolyFace>::AsFaceType
00017         > {};
00018 
00019 class PolyVertex : public vcg::Vertex<
00020         PolyUsedTypes,
00021         vcg::vertex::Coord3f,
00022         vcg::vertex::Normal3f,
00023         vcg::vertex::BitFlags
00024         > {};
00025 
00026 class PolyFace : public vcg::Face<
00027         PolyUsedTypes,
00028         vcg::face::PolyInfo,
00029         vcg::face::Normal3f,
00030         vcg::face::BitFlags,
00031         vcg::face::PFVAdj,
00032         vcg::face::PFFAdj
00033         > {};
00034 
00035 class PolyMesh : public vcg::tri::TriMesh<
00036         std::vector<PolyVertex>,
00037         std::vector<PolyFace>
00038         > {
00039 
00040 public:
00047     static int openMesh (PolyMesh &mesh, const char *filename)
00048     {
00049         // try to load the mesh from the file
00050         int err = vcg::tri::io::Importer<PolyMesh>::Open(mesh, filename);
00051 
00052         // check if successfully loaded
00053         if (err == 0)
00054         {
00055             // update bounding box
00056             vcg::tri::UpdateBounding<PolyMesh>::Box(mesh);
00057             // update topology
00058             vcg::tri::UpdateTopology<PolyMesh>::FaceFace(mesh);
00059             // update normals TODO: compute average normal in the polygon
00060             vcg::tri::UpdateNormal<PolyMesh>::PerFaceNormalized(mesh);
00061             // update flags
00062             vcg::tri::UpdateFlags<PolyMesh>::Clear(mesh);
00063         }
00064 
00065         return err;
00066     }
00067 
00074     static int saveMesh (PolyMesh &mesh, const char *filename) {
00075         // try to write the mesh into the file
00076         return vcg::tri::io::Exporter<PolyMesh>::Save(mesh, filename);
00077     }
00078 };
00079 
00080 int main(int argc, char *argv[])
00081 {
00082   if (argc < 2) {
00083     std::cout << "Error. Usage: " << argv[0] << " meshfilename" << std::endl;
00084     return -1;
00085   }
00086 
00087   PolyMesh mesh;
00088 
00089   // open mesh
00090   int err = PolyMesh::openMesh(mesh, argv[1]);
00091   if (err != 0)
00092     return err;
00093 
00094   // collapse **********************************************************************************************
00095   vcg::tri::PolychordCollapse<PolyMesh>::CollapseAllPolychords(mesh, true);
00096 
00097   // these don't work with polygonal meshes:
00098   vcg::tri::Allocator<PolyMesh>::CompactFaceVector(mesh);
00099   vcg::tri::Allocator<PolyMesh>::CompactVertexVector(mesh);
00100 
00101   // save mesh
00102   PolyMesh::saveMesh(mesh, "output.obj");
00103 
00104   return 0;
00105 }
00106 


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