Go to the documentation of this file.00001 #include <vcg/complex/complex.h>
00002 #include <vcg/complex/algorithms/attribute_seam.h>
00003
00004 #include <wrap/io_trimesh/import_ply.h>
00005 #include <wrap/io_trimesh/export_ply.h>
00006
00007
00008
00009
00010
00011 using namespace vcg;
00012
00013 #define TEST_IN_PLACE_SPLIT
00014
00015 #ifdef TEST_IN_PLACE_SPLIT
00016
00017 class SrcVertex;
00018 class SrcFace;
00019
00020 struct ScrUsedTypes : public UsedTypes< Use<SrcVertex>::AsVertexType,
00021 Use<SrcFace>::AsFaceType>{};
00022
00023 class SrcVertex : public vcg::Vertex
00024 < ScrUsedTypes,
00025 vcg::vertex::InfoOcf,
00026 vcg::vertex::Coord3f,
00027 vcg::vertex::TexCoordfOcf,
00028 vcg::vertex::BitFlags
00029 > { };
00030
00031 class SrcFace : public vcg::Face
00032 < ScrUsedTypes,
00033 vcg::face::InfoOcf,
00034 vcg::face::VertexRef,
00035 vcg::face::WedgeTexCoordfOcf
00036 > { };
00037
00038 class SrcMesh : public vcg::tri::TriMesh <vcg::vertex::vector_ocf<SrcVertex>, vcg::face::vector_ocf<SrcFace> > { };
00039
00040 typedef SrcVertex DstVertex;
00041 typedef SrcFace DstFace;
00042 typedef SrcMesh DstMesh;
00043
00044 #else
00045
00046
00047 class SrcVertex;
00048 class SrcFace;
00049
00050
00051 struct SrcUsedTypes : public UsedTypes< Use<SrcVertex>::AsVertexType,
00052 Use<SrcFace>::AsFaceType>{};
00053
00054 class SrcVertex : public vcg::Vertex <SrcUsedTypes, vcg::vertex::Coord3f, vcg::vertex::TexCoord2f, vcg::vertex::BitFlags> { };
00055 class SrcFace : public vcg::Face <SrcUsedTypes, vcg::face::VertexRef, vcg::face::WedgeTexCoord2f> { };
00056 class SrcMesh : public vcg::tri::TriMesh <std::vector<SrcVertex>, std::vector<SrcFace> > { };
00057
00058
00059
00060 class DstVertex;
00061 class DstFace;
00062
00063 struct DstUsedTypes : public UsedTypes< Use<SrcVertex>::AsVertexType,
00064 Use<SrcFace>::AsFaceType>{};
00065
00066 class DstVertex : public vcg::Vertex <DstUsedTypes, vcg::vertex::Coord3f, vcg::vertex::TexCoord2f, vcg::vertex::BitFlags> { };
00067 class DstFace : public vcg::Face <DstUsedTypes, vcg::face::VertexRef> { };
00068 class DstMesh : public vcg::tri::TriMesh <std::vector<DstVertex>, std::vector<DstFace> > { };
00069
00070 #endif
00071
00072
00073
00074
00075
00076 inline void ExtractVertex(const SrcMesh & srcMesh, const SrcFace & f, int whichWedge, const DstMesh & dstMesh, DstVertex & v)
00077 {
00078 (void)srcMesh;
00079 (void)dstMesh;
00080
00081 v.P() = f.cP(whichWedge);
00082 v.T() = f.cWT(whichWedge);
00083 }
00084
00085
00086
00087
00088 inline bool CompareVertex(const DstMesh & m, const DstVertex & vA, const DstVertex & vB)
00089 {
00090 (void)m;
00091
00092 return (vA.cT() == vB.cT());
00093 }
00094
00095
00096
00097
00098 inline void CopyVertex(const DstMesh & m, const DstVertex & vSrc, DstVertex & vDst)
00099 {
00100 (void)m;
00101
00102 vDst.P() = vSrc.cP();
00103 vDst.T() = vSrc.cT();
00104 }
00105
00106 void usage(void)
00107 {
00108 printf("usage : trimesh_split_vertex <src_ply_file_name> <dst_ply_file_name>\n");
00109 printf("where : <src_ply_file_name> : source PLY trimesh file name with texture coordinates per wedge\n");
00110 printf(" <dst_ply_file_name> : destination PLY trimesh file name with texture coordinates per vertex\n");
00111 printf("exit.\n");
00112 }
00113
00114 int main(int argc, char ** argv)
00115 {
00116 if (argc != 3)
00117 {
00118 usage();
00119 return -1;
00120 }
00121
00122 SrcMesh srcMesh;
00123 #ifdef TEST_IN_PLACE_SPLIT
00124 srcMesh.face.EnableWedgeTexCoord();
00125 #endif
00126 vcg::tri::io::ImporterPLY<SrcMesh>::Open(srcMesh, argv[1]);
00127 if ((srcMesh.VN() <= 0) || (srcMesh.FN() <= 0))
00128 {
00129 printf("invalid source mesh file.\n");
00130 return -1;
00131 }
00132 const int srcVN = srcMesh.VN();
00133 const int srcFN = srcMesh.FN();
00134 printf("source mesh succesfully loaded.\n");
00135
00136 #ifdef TEST_IN_PLACE_SPLIT
00137 DstMesh & dstMesh = srcMesh;
00138 dstMesh.vert.EnableTexCoord();
00139 vcg::tri::AttributeSeam::SplitVertex(dstMesh, ExtractVertex, CompareVertex);
00140 #else
00141 DstMesh dstMesh;
00142 vcg::tri::AttributeSeam::SplitVertex(srcMesh, dstMesh, ExtractVertex, CompareVertex, CopyVertex);
00143 dstMesh.textures = srcMesh.textures;
00144 #endif
00145 if (vcg::tri::io::ExporterPLY<DstMesh>::Save(dstMesh, argv[2], vcg::tri::io::Mask::IOM_VERTCOORD | vcg::tri::io::Mask::IOM_VERTTEXCOORD) != 0)
00146 {
00147 printf("cannot save destination mesh file.\n");
00148 return -1;
00149 }
00150 printf("destination mesh succesfully saved.\n");
00151 const int dstVN = dstMesh.VN();
00152 const int dstFN = dstMesh.FN();
00153
00154 printf("\n");
00155 printf("statistics:\n");
00156 printf(" input mesh vertices count : %d\n", srcVN);
00157 printf(" input mesh faces count : %d\n", srcFN);
00158 printf(" splitted mesh vertices count : %d\n", dstVN);
00159 printf(" splitted mesh faces count : %d\n", dstFN);
00160 printf("\n");
00161
00162 return 0;
00163 }