From 8d77ac39e3788456666d560b745ce3e7b44fa20c Mon Sep 17 00:00:00 2001 From: cignoni Date: Wed, 11 May 2011 10:07:27 +0000 Subject: [PATCH] updated the slicing/capping/edgemesh sample --- apps/sample/trimesh_edge/trimesh_edge.cpp | 62 +++++++++-------------- apps/sample/trimesh_edge/trimesh_edge.pro | 3 +- 2 files changed, 26 insertions(+), 39 deletions(-) diff --git a/apps/sample/trimesh_edge/trimesh_edge.cpp b/apps/sample/trimesh_edge/trimesh_edge.cpp index 21620343..9ba7ca44 100644 --- a/apps/sample/trimesh_edge/trimesh_edge.cpp +++ b/apps/sample/trimesh_edge/trimesh_edge.cpp @@ -20,6 +20,7 @@ * for more details. * * * ****************************************************************************/ +#include #include #include @@ -31,6 +32,7 @@ #include #include +#include // input output #include @@ -38,10 +40,12 @@ // topology computation #include +#include // normals #include #include +#include using namespace vcg; using namespace std; @@ -66,7 +70,7 @@ int main( int argc, char **argv ) return -1; } - MyMesh m,em; + MyMesh m,em,cm,full; if(tri::io::ImporterPLY::Open(m,argv[1])!=0) { @@ -76,53 +80,35 @@ int main( int argc, char **argv ) tri::UpdateFlags::FaceBorderFromFF(m); tri::UpdateNormals::PerVertexNormalized(m); + tri::UpdateBounding::Box(m); printf("Input mesh vn:%i fn:%i\n",m.vn,m.fn); printf( "Mesh has %i vert and %i faces\n", m.vn, m.fn ); - + srand(time(0)); Plane3f slicingPlane; Point3f planeCenter = m.bbox.Center(); - slicingPlane.Init(planeCenter,Point3f(0,0,1)); - vcg::IntersectionPlaneMesh(m, slicingPlane, em ); - tri::Clean::RemoveDuplicateVertex(em); - std::vector< std::vector > outlines; - std::vector outline; - vcg::tri::UpdateFlags::EdgeClearV(em); - int nv=0; - - tri::UpdateTopology::EdgeEdge(em); - - for(size_t i=0;iSetV(); - outline.push_back(curE->V(curI)->P()); - nextE=curE->EEp((curI+1)%2); - nextI=curE->EEi((curI+1)%2); - curE=nextE; - curI=nextI; - nv++; - } - while(curE != startE); + cm.Clear(); + em.Clear(); + Point3f planeDir = Point3f(-0.5f+float(rand())/RAND_MAX,-0.5f+float(rand())/RAND_MAX,-0.5f+float(rand())/RAND_MAX); + planeDir.Normalize(); + printf("slicing dir %5.2f %5.2f %5.2f\n",planeDir[0],planeDir[1],planeDir[2]); - outlines.push_back(outline); - printf("Found one outline of %i vertices\n\n",outline.size()); + slicingPlane.Init(planeCenter+planeDir*0.3f*m.bbox.Diag()*float(rand())/RAND_MAX,planeDir); - outline.clear(); - } + vcg::IntersectionPlaneMesh(m, slicingPlane, em ); + tri::Clean::RemoveDuplicateVertex(em); + vcg::tri::CapEdgeMesh(em,cm); + + printf(" edge mesh vn %5i en %5i fn %5i\n",em.vn,em.en,em.fn); + printf("sliced mesh vn %5i en %5i fn %5i\n",cm.vn,cm.en,cm.fn); + + tri::Append::Mesh(full,cm); } - printf("Found %i outlines for a total of %i vertices",outlines.size(),nv); + + tri::io::ExporterPLY::Save(full,"out.ply",false); return 0; } diff --git a/apps/sample/trimesh_edge/trimesh_edge.pro b/apps/sample/trimesh_edge/trimesh_edge.pro index 2c769917..f73fd735 100644 --- a/apps/sample/trimesh_edge/trimesh_edge.pro +++ b/apps/sample/trimesh_edge/trimesh_edge.pro @@ -5,9 +5,10 @@ TARGET = trimesh_edge DEPENDPATH += . INCLUDEPATH += . ../../.. -CONFIG += console stl +CONFIG += console stl opengl TEMPLATE = app SOURCES += trimesh_edge.cpp ../../../wrap/ply/plylib.cpp HEADERS += ../../../vcg/complex/algorithms/update/topology.h +HEADERS += ../../../wrap/gl/glu_tessellator_cap.h # Mac specific Config required to avoid to make application bundles CONFIG -= app_bundle