mirror of https://github.com/CGAL/cgal
added rendering file
another attempt to simplify a polyhedron (the basic one this time) but it does not compile...
This commit is contained in:
parent
af6368c5db
commit
c31d6713bd
|
|
@ -5,23 +5,22 @@
|
|||
#include <CGAL/Surface_mesh_simplification/edge_collapse.h>
|
||||
#include <CGAL/Surface_mesh_simplification/Policies/Edge_collapse/Count_stop_predicate.h>
|
||||
|
||||
|
||||
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
|
||||
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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@
|
|||
|
||||
// surface
|
||||
#include <CGAL/Polyhedron_3.h>
|
||||
#include <CGAL/enriched_polyhedron.h>
|
||||
//#include <CGAL/enriched_polyhedron.h>
|
||||
|
||||
typedef CGAL::Exact_predicates_inexact_constructions_kernel Kernel;
|
||||
typedef Kernel::FT FT;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,72 @@
|
|||
#ifndef RENDER
|
||||
#define RENDER
|
||||
|
||||
#include <GL/glu.h>
|
||||
|
||||
template <class Polyhedron>
|
||||
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<Polyhedron::Facet,Kernel>(*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 <class Facet, class Kernel>
|
||||
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
|
||||
|
||||
|
||||
|
||||
|
||||
Loading…
Reference in New Issue