From d3243585c5e47f0bdb748f27964cf9f87cf26734 Mon Sep 17 00:00:00 2001 From: dibenedetto Date: Fri, 23 Oct 2009 20:26:38 +0000 Subject: [PATCH] first commit. --- .../trimesh_split_vertex.cpp | 113 ++++++++++++++++++ .../trimesh_split_vertex.pro | 7 ++ 2 files changed, 120 insertions(+) create mode 100644 apps/sample/trimesh_split_vertex/trimesh_split_vertex.cpp create mode 100644 apps/sample/trimesh_split_vertex/trimesh_split_vertex.pro diff --git a/apps/sample/trimesh_split_vertex/trimesh_split_vertex.cpp b/apps/sample/trimesh_split_vertex/trimesh_split_vertex.cpp new file mode 100644 index 00000000..4c14bd84 --- /dev/null +++ b/apps/sample/trimesh_split_vertex/trimesh_split_vertex.cpp @@ -0,0 +1,113 @@ +#include + +#include +#include +#include +#include + +#include +#include + +/* + this sample shows how to transfer per wedge attributes from wedges to vertices. + during the process new vertices could be created. +*/ + +// source mesh type: per-wedge texture coordinates +class SrcVertex; +class SrcEdge; +class SrcFace; + +class SrcVertex : public vcg::VertexSimp2 { }; +class SrcFace : public vcg::FaceSimp2 { }; +class SrcMesh : public vcg::tri::TriMesh , std::vector > { }; + + +// destination mesh type: per-vertex texture coordinates +class DstVertex; +class DstEdge; +class DstFace; + +class DstVertex : public vcg::VertexSimp2 { }; +class DstFace : public vcg::FaceSimp2 { }; +class DstMesh : public vcg::tri::TriMesh , std::vector > { }; + +// extract wedge attributes functor. +// given a source face and a wedge index, this functor extracts all the relevant attributes from the wedge +// and transfer them to the destination vertex. +// source and destination meshes are provided to allow for attribute presence checking (.Is*Enabled()). +inline void ExtractVertex(const SrcMesh & srcMesh, const SrcFace & f, int whichWedge, const DstMesh & dstMesh, DstVertex & v) +{ + (void)srcMesh; + (void)dstMesh; + + v.P() = f.cP(whichWedge); + v.T() = f.cWT(whichWedge); +} + +// sample compare functor. +// given two destination vertices, this functor tells if they are identical in all relevan attributes. +// source and destination meshes are provided to allow for attribute presence checking (.Is*Enabled()). +inline bool CompareVertex(const DstMesh & m, const DstVertex & vA, const DstVertex & vB) +{ + (void)m; + + return (vA.cT() == vB.cT()); +} + +// sample copy functor. +// given two destination vertices, this functor is asked to copy all relevan attributes. +// source and destination meshes are provided to allow for attribute presence checking (.Is*Enabled()). +inline void CopyVertex(const DstMesh & m, const DstVertex & vSrc, DstVertex & vDst) +{ + (void)m; + + vDst.P() = vSrc.cP(); + vDst.T() = vSrc.cT(); +} + +void usage(void) +{ + printf("usage : trimesh_split_vertex \n"); + printf("where : : source PLY trimesh file name with texture coordinates per wedge\n"); + printf(" : destination PLY trimesh file name with texture coordinates per vertex\n"); + printf("exit.\n"); +} + +int main(int argc, char ** argv) +{ + if (argc != 3) + { + usage(); + return -1; + } + + SrcMesh srcMesh; + vcg::tri::io::ImporterPLY::Open(srcMesh, argv[1]); + if ((srcMesh.vn <= 0) || (srcMesh.fn <= 0)) + { + printf("invalid source mesh file.\n"); + return -1; + } + printf("source mesh succesfully loaded.\n"); + + DstMesh dstMesh; + vcg::tri::AttributeSeam::SplitVertex(srcMesh, dstMesh, ExtractVertex, CompareVertex, CopyVertex); + dstMesh.textures = srcMesh.textures; + if (vcg::tri::io::ExporterPLY::Save(dstMesh, argv[2], vcg::tri::io::Mask::IOM_VERTCOORD | vcg::tri::io::Mask::IOM_VERTTEXCOORD) != 0) + { + printf("cannot save destination mesh file.\n"); + return -1; + } + printf("destination mesh succesfully saved.\n"); + + printf("\n"); + printf("statistics:\n"); + printf(" input mesh vertices count : %d\n", srcMesh.vn); + printf(" input mesh faces count : %d\n", srcMesh.fn); + printf(" splitted mesh vertices count : %d\n", dstMesh.vn); + printf(" splitted mesh faces count : %d\n", dstMesh.fn); + printf("\n"); + + return 0; +} diff --git a/apps/sample/trimesh_split_vertex/trimesh_split_vertex.pro b/apps/sample/trimesh_split_vertex/trimesh_split_vertex.pro new file mode 100644 index 00000000..6fe90d43 --- /dev/null +++ b/apps/sample/trimesh_split_vertex/trimesh_split_vertex.pro @@ -0,0 +1,7 @@ +TARGET = trimesh_split_vertex +LIBPATH += +DEPENDPATH += . +INCLUDEPATH += . ../../.. +CONFIG += console stl +TEMPLATE = app +SOURCES += trimesh_split_vertex.cpp ../../../wrap/ply/plylib.cpp