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