00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include <vector>
00025
00026
00027 #include <vcg/simplex/vertex/base.h>
00028
00029
00030 #include <vcg/simplex/face/base.h>
00031
00032
00033 #include <vcg/connectors/hedge.h>
00034
00035
00036 #include <vcg/complex/trimesh/base.h>
00037
00038
00039 #include <vcg/complex/trimesh/update/topology.h>
00040 #include <vcg/complex/trimesh/update/bounding.h>
00041 #include <vcg/complex/trimesh/update/normal.h>
00042
00043
00044 #include <vcg/complex/trimesh/clean.h>
00045
00046
00047 #include <wrap/io_trimesh/import.h>
00048
00049
00050 #include <wrap/io_trimesh/export_ply.h>
00051
00052
00053 #include <vcg/complex/trimesh/polygon_support.h>
00054
00055
00056 #include <vcg/simplex/face/component_polygon.h>
00057
00058
00059 #include <vcg/complex/trimesh/update/halfedge_indexed.h>
00060
00061
00062 using namespace vcg;
00063 using namespace std;
00064
00065
00066 class CFace;
00067 class CVertex;
00068 class CHEdge;
00069 class CEdge;
00070 class MyPolyVertex;
00071
00072 struct CUsedTypes: public vcg::UsedTypes< vcg::Use<CVertex>::AsVertexType, vcg::Use<CFace>::AsFaceType >{};
00073
00074
00075
00076
00077
00078 class CVertex : public Vertex< CUsedTypes,
00079 vertex::BitFlags,
00080 vertex::Coord3f,
00081 vertex::Normal3f,
00082 vertex::Mark >{};
00083
00084 class CFace : public Face< CUsedTypes,
00085 face::VertexRef,
00086 face::Normal3f,
00087 face::BitFlags,
00088 face::FFAdj
00089 > {};
00090
00091
00092 class CMesh : public vcg::tri::TriMesh< vector<CVertex>, vector<CFace> > {};
00093
00094
00095
00096
00097 class MyPolyFace;
00098 class MyPolyVertex;
00099 struct PolyUsedTypes: public vcg::UsedTypes<vcg::Use<MyPolyVertex> ::AsVertexType,
00100 vcg::Use<CEdge> ::AsEdgeType,
00101 vcg::Use<CHEdge> ::AsHEdgeType,
00102 vcg::Use<MyPolyFace> ::AsFaceType
00103 >{};
00104
00105
00106 class MyPolyVertex:public vcg::Vertex< PolyUsedTypes,
00107 vcg::vertex::Coord3f,
00108 vcg::vertex::Normal3f,
00109 vcg::vertex::Mark,
00110 vcg::vertex::BitFlags,
00111 vcg::vertex::VHAdj>{} ;
00112
00113 class CEdge : public Edge<PolyUsedTypes>{};
00114 class CHEdge : public HEdge< PolyUsedTypes, hedge::BitFlags,
00115
00116
00117
00118
00119 hedge::HEdgeData
00120
00121 >{};
00122
00123 class MyPolyFace:public vcg::Face<
00124 PolyUsedTypes
00125 ,vcg::face::PolyInfo
00126
00127
00128 ,vcg::face::PFVAdj
00129 ,vcg::face::PFVAdj
00130 ,vcg::face::PFFAdj
00131 ,vcg::face::PFHAdj
00132 ,vcg::face::BitFlags
00133 ,vcg::face::Normal3f
00134 > {};
00135
00136 class MyPolyMesh: public
00137 vcg::tri::TriMesh<
00138 std::vector<MyPolyVertex>,
00139 std::vector<MyPolyFace >,
00140 std::vector<CHEdge> ,
00141 std::vector<CEdge>
00142 >{};
00143
00144 MyPolyMesh pm;
00145
00146
00148
00149 CMesh mesh,mesh1;
00150
00151 int main(int argc, char *argv[]) {
00152
00153 int loadmask;
00154
00155 vcg::tri::io::PlyInfo pi;
00156
00157
00158 if(false){
00159
00160
00161
00162
00163
00164
00165
00166 vcg::tri::io::ImporterOBJ<CMesh>::Open(mesh,argv[1],loadmask);
00167
00168 vcg::tri::Clean<CMesh>::RemoveUnreferencedVertex(mesh);
00169 vcg::tri::Clean<CMesh>::RemoveZeroAreaFace(mesh);
00170 vcg::tri::UpdateTopology<CMesh>::FaceFace(mesh);
00171 vcg::tri::Clean<CMesh>::RemoveNonManifoldFace(mesh);
00172 vcg::tri::UpdateTopology<CMesh>::FaceFace(mesh);
00173 assert(vcg::tri::Clean<CMesh>::CountNonManifoldEdgeFF(mesh)==0);
00174 assert(vcg::tri::Clean<CMesh>::CountNonManifoldVertexFF(mesh)==0);
00175
00176
00177 vcg::tri::PolygonSupport<CMesh,MyPolyMesh>::ImportFromTriMesh(pm,mesh);
00178 }
00179 else
00180 {
00181
00182
00183
00184 vcg::tri::io::ImporterOBJ<MyPolyMesh>::Open(pm,argv[1],loadmask);
00185 vcg::tri::UpdateTopology<MyPolyMesh>::FaceFace(pm);
00186 vcg::tri::Clean<MyPolyMesh>::RemoveNonManifoldFace(pm);
00187 vcg::tri::UpdateTopology<MyPolyMesh>::FaceFace(pm);
00188 assert(vcg::tri::Clean<MyPolyMesh>::CountNonManifoldEdgeFF(pm));
00189
00190 }
00191
00192
00193
00194 vcg::tri::UpdateHalfEdges<MyPolyMesh>::FromIndexed(pm);
00195
00196
00197
00198
00199 assert(vcg::tri::UpdateHalfEdges<MyPolyMesh>::CheckConsistency(pm));
00200
00201 int size = pm.face.size();
00202
00203
00204
00205 for(int i = 0; i < size; ++i)
00206 if(!(pm.face[i].IsD()))
00207 if(pm.face[i].VN()>3){
00208 MyPolyMesh::HEdgePointer ef = pm.face[i].FHp();
00209 MyPolyMesh::HEdgePointer ef1 = ef -> HNp();
00210 ef1 = ef1->HNp();
00211 vcg::tri::UpdateHalfEdges<MyPolyMesh>::AddHEdge(pm, ef, ef1 );
00212 }
00213 assert(vcg::tri::UpdateHalfEdges<MyPolyMesh>::CheckConsistency(pm));
00214 size = pm.face.size();
00215
00216
00217
00218 for(int i = 0; i < size; ++i)
00219 if(!(pm.face[i].IsD() ))
00220 {
00221 MyPolyMesh::HEdgePointer ef = pm.face[i].FHp();
00222 if( ef->HOp()->HFp() !=NULL){
00223 vcg::tri::UpdateHalfEdges<MyPolyMesh>::RemoveHEdge(pm,ef);
00224 }
00225 }
00226
00227
00228 assert(vcg::tri::UpdateHalfEdges<MyPolyMesh>::CheckConsistency(pm));
00229
00230
00231 vcg::tri::UpdateIndexed<MyPolyMesh>::FromHalfEdges(pm );
00232
00233
00234 vcg::tri::PolygonSupport<CMesh,MyPolyMesh>::ImportFromPolyMesh(mesh1,pm);
00235
00236
00237 vcg::tri::io::ExporterPLY<CMesh>::Save(mesh1,"converted_out.ply",true,pi);
00238 }
00239
00240
00241