From 6aa09931c4dfc6bb7c8bfba9b7791cf2a8916cc7 Mon Sep 17 00:00:00 2001 From: ganovelli Date: Thu, 25 Mar 2010 16:47:03 +0000 Subject: [PATCH] updated to comply with: [introduction of half edges as alternative representation] No modification should be necessary for the existing code. most relevant changes: creation of folder: vcg/connectors vcg/connectors/hedge.h vcg/connectors/hedge_component.h addition to the container of half edges to the trimesh: HEdgeContainer hedge; // container int hn; // number of half edges addition of vcg/trimesh/update/halfedge_indexed.h which contains: - the functions to compute the half edge representation from the indexed and vivecersa - the functions to add or remove an half edge --- apps/sample/polygonmesh_base/polygonmesh.cpp | 76 ++++++++++---------- 1 file changed, 39 insertions(+), 37 deletions(-) diff --git a/apps/sample/polygonmesh_base/polygonmesh.cpp b/apps/sample/polygonmesh_base/polygonmesh.cpp index 05377866..c3b62859 100644 --- a/apps/sample/polygonmesh_base/polygonmesh.cpp +++ b/apps/sample/polygonmesh_base/polygonmesh.cpp @@ -30,7 +30,7 @@ #include /*include the base definition for the edge */ -#include +#include /*include the base definition for the trimesh*/ #include @@ -56,7 +56,7 @@ #include /* include the support for half edges */ -#include +#include using namespace vcg; @@ -65,7 +65,7 @@ using namespace std; // forward declarations class CFace; class CVertex; -class CEdge; +class CHEdge; class DummyEdge; class MyPolyVertex; @@ -96,25 +96,26 @@ class CMesh : public vcg::tri::TriMesh< vector, vector > {}; */ class MyPolyFace; class MyPolyVertex; -struct PolyUsedTypes: public vcg::UsedTypes< vcg::Use::AsVertexType, - vcg::Use::AsEdgeType, - vcg::Use::AsFaceType >{}; +struct PolyUsedTypes: public vcg::UsedTypes ::AsVertexType, + vcg::Use ::AsHEdgeType, + vcg::Use ::AsFaceType + >{}; -class MyPolyVertex:public vcg::Vertex{} ; +class MyPolyVertex:public vcg::Vertex< PolyUsedTypes, + vcg::vertex::Coord3f, + vcg::vertex::Normal3f, + vcg::vertex::Mark, + vcg::vertex::BitFlags, + vcg::vertex::VHAdj>{} ; -class CEdge : public Edge< PolyUsedTypes, edge::BitFlags, - //edge::EFAdj, // pointer to the face - //edge::HEOppAdj, // pointer to the opposite edge - //edge::HEVAdj, // pointer to the vertex - //edge::HENextAdj, // pointer to the next halfedge - edge::HEdgeData // the previous 4 components (just more handy, you can comment this and uncomment the previous four lines) - //,edge::HEPrevAdj // pointer to the previous halfedge +class CHEdge : public HEdge< PolyUsedTypes, hedge::BitFlags, + //hedge::HFAdj, // pointer to the face + //hedge::HOppAdj, // pointer to the opposite edge + //hedge::HVAdj, // pointer to the vertex + //hedge::HNextAdj, // pointer to the next halfedge + hedge::HEdgeData // the previous 4 components (just more handy, you can comment this and uncomment the previous four lines) + //,hedge::HPrevAdj // pointer to the previous halfedge >{}; class MyPolyFace:public vcg::Face< @@ -123,8 +124,9 @@ class MyPolyFace:public vcg::Face< // It says "this class is a polygon and the memory for its components (e.g. pointer to its vertices // will be allocated dynamically") ,vcg::face::PFVAdj // Pointer to the vertices (just like FVAdj ) + ,vcg::face::PFVAdj ,vcg::face::PFFAdj // Pointer to edge-adjacent face (just like FFAdj ) - ,vcg::face::PFHEAdj // Pointer its half -edges ( you may need this if you use half edges) + ,vcg::face::PFHAdj // Pointer its half -edges ( you may need this if you use half edges) ,vcg::face::BitFlags // bit flags ,vcg::face::Normal3f // normal > {}; @@ -132,7 +134,7 @@ class MyPolyFace:public vcg::Face< class MyPolyMesh: public vcg::tri::TriMesh< std::vector, // the vector of vertices std::vector, // the vector of faces - std::vector // the vector of edges + std::vector // the vector of edges >{}; MyPolyMesh pm; @@ -142,15 +144,13 @@ MyPolyMesh pm; // Globals: the mesh, the OpenGL wrapper to draw the mesh and the trackball. CMesh mesh,mesh1; - - - int main(int argc, char *argv[]) { int loadmask; vcg::tri::io::PlyInfo pi; +// pm.hedge.reserve(100000); if(false){ /* first way: @@ -186,45 +186,47 @@ else // compute the half edges because I'm a half-edge programmer - vcg::tri::EdgeSupport::ComputeHalfEdgeFromIndexed(pm); + vcg::tri::UpdateHalfEdges::FromIndexed(pm); // .... my half edge based code ...... // check for consistency - assert(vcg::tri::EdgeSupport::CheckConsistency(pm)); + assert(vcg::tri::UpdateHalfEdges::CheckConsistency(pm)); int size = pm.face.size(); // add a face to each face with more than 3 vertices ( just one pass) + for(int i = 0; i < size; ++i) if(!(pm.face[i].IsD())) if(pm.face[i].VN()>3){ - MyPolyMesh::EdgePointer ef = pm.face[i].FHEp(); - MyPolyMesh::EdgePointer ef1 = ef -> HENp(); - ef1 = ef1->HENp(); - vcg::tri::EdgeSupport::AddEdge(pm, ef, ef1 ); + MyPolyMesh::HEdgePointer ef = pm.face[i].FHp(); + MyPolyMesh::HEdgePointer ef1 = ef -> HNp(); + ef1 = ef1->HNp(); + vcg::tri::UpdateHalfEdges::AddHEdge(pm, ef, ef1 ); } - assert(vcg::tri::EdgeSupport::CheckConsistency(pm)); + assert(vcg::tri::UpdateHalfEdges::CheckConsistency(pm)); size = pm.face.size(); // remove an edge for each face + for(int i = 0; i < size; ++i) if(!(pm.face[i].IsD() )) { - MyPolyMesh::EdgePointer ef = pm.face[i].FHEp(); - if( ef->HEOp()->EFp() !=NULL){ - vcg::tri::EdgeSupport::RemoveEdge(pm,ef); + MyPolyMesh::HEdgePointer ef = pm.face[i].FHp(); + if( ef->HOp()->HFp() !=NULL){ + vcg::tri::UpdateHalfEdges::RemoveHEdge(pm,ef); } } // check for consistency - assert(vcg::tri::EdgeSupport::CheckConsistency(pm)); + assert(vcg::tri::UpdateHalfEdges::CheckConsistency(pm)); // recompute indexed data structure from the half edge data structure - vcg::tri::EdgeSupport::ComputeIndexedFromHalfEdge(pm ); + vcg::tri::UpdateIndexed::FromHalfEdges(pm ); // create a triangle mesh from a polygon mesh - vcg::tri::PolygonSupport::ImportFromPolyMesh(mesh1,pm); + vcg::tri::PolygonSupport::ImportFromPolyMesh(mesh1,pm); // write out the triangle mesh vcg::tri::io::ExporterPLY::Save(mesh1,"converted_out.ply",true,pi);