diff --git a/apps/sample/polygonmesh_polycoord_collapse/main.cpp b/apps/sample/polygonmesh_polycoord_collapse/main.cpp new file mode 100644 index 00000000..4d8fd3b7 --- /dev/null +++ b/apps/sample/polygonmesh_polycoord_collapse/main.cpp @@ -0,0 +1,109 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace vcg; + +class PolyVertex; +class PolyFace; + +struct PolyUsedTypes : public vcg::UsedTypes< + vcg::Use::AsVertexType, + vcg::Use::AsFaceType + > {}; + +class PolyVertex : public vcg::Vertex< + PolyUsedTypes, + vcg::vertex::Coord3f, + vcg::vertex::Normal3f, + vcg::vertex::BitFlags + > {}; + +class PolyFace : public vcg::Face< + PolyUsedTypes, + vcg::face::PolyInfo, + vcg::face::Normal3f, + vcg::face::BitFlags, + vcg::face::PFVAdj, + vcg::face::PFFAdj + > {}; + +class PolyMesh : public vcg::tri::TriMesh< + std::vector, + std::vector + > { + +public: + /** + * @brief open Loads a polygonal mesh from file. + * @param mesh The mesh object into which to extract the mesh. + * @param filename The filename where the mesh is stored. + * @return An error code. + */ + static int openMesh (PolyMesh &mesh, const char *filename) + { + // try to load the mesh from the file + int err = vcg::tri::io::Importer::Open(mesh, filename); + + // check if successfully loaded + if (err == 0) + { + // update bounding box + vcg::tri::UpdateBounding::Box(mesh); + // update topology + vcg::tri::UpdateTopology::FaceFace(mesh); + // update normals TODO: compute average normal in the polygon + vcg::tri::UpdateNormal::PerFaceNormalized(mesh); + // update flags + vcg::tri::UpdateFlags::Clear(mesh); + } + + return err; + } + + /** + * @brief saveMesh Writes a polygonal mesh into a file. + * @param mesh The mesh to write. + * @param filename The filename where to store the mesh. + * @return + */ + static int saveMesh (PolyMesh &mesh, const char *filename) { + // try to write the mesh into the file + return vcg::tri::io::Exporter::Save(mesh, filename); + } +}; + +int main(int argc, char *argv[]) +{ + if (argc < 2) { + std::cout << "Error. Usage: " << argv[0] << " meshfilename" << std::endl; + return -1; + } + + PolyMesh mesh; + + // open mesh + int err = PolyMesh::openMesh(mesh, argv[1]); + if (err != 0) + return err; + + // collapse ********************************************************************************************** + vcg::tri::PolycoordCollapse::CollapseAllPolycoords(mesh, true); + + // these don't work with polygonal meshes: + vcg::tri::Allocator::CompactFaceVector(mesh); + vcg::tri::Allocator::CompactVertexVector(mesh); + + // save mesh + PolyMesh::saveMesh(mesh, "output.obj"); + + return 0; +} + diff --git a/apps/sample/polygonmesh_polycoord_collapse/polygonmesh_polycoord_collapse.pro b/apps/sample/polygonmesh_polycoord_collapse/polygonmesh_polycoord_collapse.pro new file mode 100644 index 00000000..c089e0ec --- /dev/null +++ b/apps/sample/polygonmesh_polycoord_collapse/polygonmesh_polycoord_collapse.pro @@ -0,0 +1,12 @@ +TEMPLATE = app +CONFIG += console +CONFIG -= app_bundle +CONFIG -= qt + +SOURCES += main.cpp + + +VCGLIBDIR = ../../../ +DEPENDPATH += $$VCGLIBDIR +INCLUDEPATH += $$VCGLIBDIR +SOURCES += $$VCGLIBDIR/wrap/ply/plylib.cpp