From c31d6713bd1f7f1e9ec2493d60fd9f07dcde344c Mon Sep 17 00:00:00 2001 From: Pierre Alliez Date: Sat, 12 Jul 2008 09:48:23 +0000 Subject: [PATCH] added rendering file another attempt to simplify a polyhedron (the basic one this time) but it does not compile... --- .../demo/Polyhedron/MainWindow_simplify.cpp | 9 ++- Polyhedron/demo/Polyhedron/Scene.h | 2 +- .../demo/Polyhedron/include/CGAL/gl_render.h | 72 +++++++++++++++++++ 3 files changed, 77 insertions(+), 6 deletions(-) create mode 100644 Polyhedron/demo/Polyhedron/include/CGAL/gl_render.h diff --git a/Polyhedron/demo/Polyhedron/MainWindow_simplify.cpp b/Polyhedron/demo/Polyhedron/MainWindow_simplify.cpp index 903243aed68..926df4b784b 100644 --- a/Polyhedron/demo/Polyhedron/MainWindow_simplify.cpp +++ b/Polyhedron/demo/Polyhedron/MainWindow_simplify.cpp @@ -5,23 +5,22 @@ #include #include + void MainWindow::on_actionSimplify_triggered() { if(onePolygonIsSelected()) { int index = getSelectedPolygonIndex(); Polyhedron* pMesh = scene->polyhedron(index); + // simplify - //unsigned int nb_edges = 1000; // TODO: should be an option - //namespace SMS = CGAL::Surface_mesh_simplification ; + unsigned int nb_edges = 1000; // TODO: should be an option + //namespace SMS = CGAL::Surface_mesh_simplification; //SMS::Count_stop_predicate< Polyhedron > stop(nb_edges); // target # edges //SMS::edge_collapse( *pMesh, stop, // CGAL::vertex_index_map(boost::get(CGAL::vertex_external_index,*pMesh)) // .edge_index_map(boost::get(CGAL::edge_external_index,*pMesh))); - // recompute normals - //pMesh->compute_normals(); - // Tell the scene that polyhedron #index has been changed scene->polyhedronChanged(index); } diff --git a/Polyhedron/demo/Polyhedron/Scene.h b/Polyhedron/demo/Polyhedron/Scene.h index 45751547a2e..f85b6f9adc3 100644 --- a/Polyhedron/demo/Polyhedron/Scene.h +++ b/Polyhedron/demo/Polyhedron/Scene.h @@ -18,7 +18,7 @@ // surface #include -#include +//#include typedef CGAL::Exact_predicates_inexact_constructions_kernel Kernel; typedef Kernel::FT FT; diff --git a/Polyhedron/demo/Polyhedron/include/CGAL/gl_render.h b/Polyhedron/demo/Polyhedron/include/CGAL/gl_render.h new file mode 100644 index 00000000000..476aa2afa3e --- /dev/null +++ b/Polyhedron/demo/Polyhedron/include/CGAL/gl_render.h @@ -0,0 +1,72 @@ +#ifndef RENDER +#define RENDER + +#include + +template +void gl_render(Polyhedron& polyhedron) +{ + typedef typename Polyhedron::Traits Kernel; + typedef typename Kernel::Point_3 Point; + typedef typename Kernel::Vector_3 Vector; + + typedef typename Polyhedron::Halfedge_handle Halfedge_handle; + typedef typename Polyhedron::Facet_handle Facet_handle; + typedef typename Polyhedron::Vertex_handle Vertex_handle; + + typedef typename Polyhedron::Vertex_iterator Vertex_iterator; + typedef typename Polyhedron::Facet_iterator Facet_iterator; + typedef typename Polyhedron::Halfedge_iterator Halfedge_iterator; + typedef typename Polyhedron::Edge_iterator Edge_iterator; + + typedef typename Polyhedron::Halfedge_around_vertex_circulator HV_circulator; + typedef typename Polyhedron::Halfedge_around_facet_circulator HF_circulator; + + Facet_iterator f; + for(f = polyhedron.facets_begin(); + f != polyhedron.facets_end(); + f++) + { + ::glBegin(GL_POLYGON); + + // compute normal + Vector n = compute_normal(*f); + ::glNormal3d(n.x(),n.y(),n.z()); + + // revolve around current face to get vertices + HF_circulator he = f->facet_begin(); + do + { + const Point& p = he->vertex()->point(); + ::glVertex3d(p.x(),p.y(),p.z()); + } + while(++he != f->facet_begin()); + ::glEnd(); + } +} + +template +typename Kernel::Vector_3 compute_normal(Facet& f) +{ + typedef typename Kernel::Point_3 Point; + typedef typename Kernel::Vector_3 Vector; + typedef typename Facet::Halfedge_around_facet_circulator HF_circulator; + Vector normal = CGAL::NULL_VECTOR; + HF_circulator he = f.facet_begin(); + do + { + const Point& prev = he->prev()->vertex()->point(); + const Point& curr = he->vertex()->point(); + const Point& next = he->next()->vertex()->point(); + Vector n = CGAL::cross_product(next-curr,prev-curr); + normal = normal + (n / std::sqrt(n*n)); + } + while (++he != f.facet_begin()); + return normal / std::sqrt(normal * normal); +} + +#endif // RENDER + + + +