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 <vcg/complex/complex.h>
00025
00026
00027 #include <vcg/complex/algorithms/update/topology.h>
00028 #include <vcg/complex/algorithms/update/bounding.h>
00029 #include <vcg/complex/algorithms/update/normal.h>
00030
00031 #include <vcg/complex/algorithms/clean.h>
00032 #include <vcg/complex/algorithms/create/platonic.h>
00033
00034 #include <wrap/io_trimesh/import.h>
00035 #include <wrap/io_trimesh/export_ply.h>
00036
00037
00038
00039
00040
00041 #include <vcg/complex/algorithms/update/halfedge_indexed.h>
00042
00043
00044 using namespace vcg;
00045 using namespace std;
00046
00047
00048 class TFace;
00049 class TVertex;
00050
00051 struct TUsedTypes: public vcg::UsedTypes< vcg::Use<TVertex>::AsVertexType, vcg::Use<TFace>::AsFaceType >{};
00052
00053
00054
00055
00056
00057 class TVertex : public Vertex< TUsedTypes,
00058 vertex::BitFlags,
00059 vertex::Coord3f,
00060 vertex::Normal3f,
00061 vertex::Mark >{};
00062
00063 class TFace : public Face< TUsedTypes,
00064 face::VertexRef,
00065 face::Normal3f,
00066 face::BitFlags,
00067 face::FFAdj
00068 > {};
00069
00070
00071 class TMesh : public vcg::tri::TriMesh< vector<TVertex>, vector<TFace> > {};
00072
00073
00074
00075
00076 class PFace;
00077 class PVertex;
00078 class PHEdge;
00079 class PEdge;
00080
00081 struct PUsedTypes: public vcg::UsedTypes<vcg::Use<PVertex> ::AsVertexType,
00082 vcg::Use<PEdge> ::AsEdgeType,
00083 vcg::Use<PHEdge>::AsHEdgeType,
00084 vcg::Use<PFace> ::AsFaceType
00085 >{};
00086
00087
00088 class PVertex:public vcg::Vertex< PUsedTypes,
00089 vcg::vertex::Coord3f,
00090 vcg::vertex::Normal3f,
00091 vcg::vertex::Mark,
00092 vcg::vertex::BitFlags,
00093 vcg::vertex::VHAdj>{} ;
00094
00095 class PEdge : public Edge<PUsedTypes>{};
00096 class PHEdge : public HEdge< PUsedTypes, hedge::BitFlags,
00097
00098
00099
00100
00101 hedge::HEdgeData
00102
00103 >{};
00104
00105 class PFace:public vcg::Face<
00106 PUsedTypes
00107 ,vcg::face::PolyInfo
00108
00109
00110 ,vcg::face::PFVAdj
00111 ,vcg::face::PFVAdj
00112 ,vcg::face::PFFAdj
00113 ,vcg::face::PFHAdj
00114 ,vcg::face::BitFlags
00115 ,vcg::face::Normal3f
00116 > {};
00117
00118 class PMesh: public
00119 vcg::tri::TriMesh<
00120 std::vector<PVertex>,
00121 std::vector<PFace >,
00122 std::vector<PHEdge> ,
00123 std::vector<PEdge>
00124 >{};
00125
00126 PMesh pm;
00127 TMesh tm0;
00128
00129 int main(int argc, char *argv[]) {
00130
00131 int loadmask;
00132
00133 if(true){
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143 vcg::tri::Hexahedron(tm0);
00144 vcg::tri::Clean<TMesh>::RemoveUnreferencedVertex(tm0);
00145 vcg::tri::Clean<TMesh>::RemoveZeroAreaFace(tm0);
00146 vcg::tri::UpdateTopology<TMesh>::FaceFace(tm0);
00147 vcg::tri::Clean<TMesh>::RemoveNonManifoldFace(tm0);
00148 vcg::tri::UpdateTopology<TMesh>::FaceFace(tm0);
00149 assert(vcg::tri::Clean<TMesh>::CountNonManifoldEdgeFF(tm0)==0);
00150 assert(vcg::tri::Clean<TMesh>::CountNonManifoldVertexFF(tm0)==0);
00151
00152
00153 vcg::tri::PolygonSupport<TMesh,PMesh>::ImportFromTriMesh(pm,tm0);
00154 }
00155 else
00156 {
00157
00158
00159
00160 vcg::tri::io::ImporterOBJ<PMesh>::Open(pm,argv[1],loadmask);
00161 vcg::tri::UpdateTopology<PMesh>::FaceFace(pm);
00162 vcg::tri::Clean<PMesh>::RemoveNonManifoldFace(pm);
00163 vcg::tri::UpdateTopology<PMesh>::FaceFace(pm);
00164 assert(vcg::tri::Clean<PMesh>::CountNonManifoldEdgeFF(pm));
00165 }
00166
00167
00168
00169 vcg::tri::UpdateHalfEdges<PMesh>::FromIndexed(pm);
00170
00171
00172
00173
00174 assert(vcg::tri::UpdateHalfEdges<PMesh>::CheckConsistency(pm));
00175
00176 int size = pm.face.size();
00177
00178
00179
00180 for(int i = 0; i < size; ++i)
00181 if(!(pm.face[i].IsD()))
00182 if(pm.face[i].VN()>3){
00183 PMesh::HEdgePointer ef = pm.face[i].FHp();
00184 PMesh::HEdgePointer ef1 = ef -> HNp();
00185 ef1 = ef1->HNp();
00186 vcg::tri::UpdateHalfEdges<PMesh>::AddHEdge(pm, ef, ef1 );
00187 }
00188 assert(vcg::tri::UpdateHalfEdges<PMesh>::CheckConsistency(pm));
00189 size = pm.face.size();
00190
00191
00192
00193 for(int i = 0; i < size; ++i)
00194 if(!(pm.face[i].IsD() ))
00195 {
00196 PMesh::HEdgePointer ef = pm.face[i].FHp();
00197 if( ef->HOp()->HFp() !=NULL){
00198 vcg::tri::UpdateHalfEdges<PMesh>::RemoveHEdge(pm,ef);
00199 }
00200 }
00201
00202
00203 assert(vcg::tri::UpdateHalfEdges<PMesh>::CheckConsistency(pm));
00204
00205
00206
00207
00208
00209 TMesh tm1;
00210 vcg::tri::PolygonSupport<TMesh,PMesh>::ImportFromPolyMesh(tm1,pm);
00211
00212 vcg::tri::io::PlyInfo pi;
00213 vcg::tri::io::ExporterPLY<TMesh>::Save(tm1,"converted_tri.ply",false,pi);
00214 vcg::tri::io::ExporterPLY<PMesh>::Save(pm,"converted_poly.ply",false,pi);
00215 }
00216
00217
00218