Add color to faces. Code cleanup

This commit is contained in:
Jasmeet Singh 2019-06-29 19:12:43 -07:00
parent 625ab7583d
commit 16992e743e
2 changed files with 18 additions and 17 deletions

View File

@ -1,4 +1,5 @@
#include <CGAL/Exact_predicates_exact_constructions_kernel.h> #include <CGAL/Exact_predicates_exact_constructions_kernel.h>
//#include <CGAL/Exact_integer.h>
//#include <CGAL/Extended_homogeneous.h> //#include <CGAL/Extended_homogeneous.h>
#include <CGAL/Nef_polyhedron_3.h> #include <CGAL/Nef_polyhedron_3.h>
#include <CGAL/Polyhedron_3.h> #include <CGAL/Polyhedron_3.h>
@ -10,6 +11,7 @@
#include <iostream> #include <iostream>
typedef CGAL::Exact_predicates_exact_constructions_kernel Kernel; typedef CGAL::Exact_predicates_exact_constructions_kernel Kernel;
//typedef CGAL::Exact_integer NT;
//typedef CGAL::Extended_homogeneous<NT> Kernel; //typedef CGAL::Extended_homogeneous<NT> Kernel;
typedef CGAL::Surface_mesh<Kernel::Point_3> Surface_mesh; typedef CGAL::Surface_mesh<Kernel::Point_3> Surface_mesh;
typedef CGAL::Nef_polyhedron_3<Kernel> Nef_polyhedron; typedef CGAL::Nef_polyhedron_3<Kernel> Nef_polyhedron;

View File

@ -41,8 +41,8 @@ struct DefaultColorFunctorNefPolyhedron
static CGAL::Color run(const NefPolyhedron&, static CGAL::Color run(const NefPolyhedron&,
typename NefPolyhedron::Halffacet_const_handle fh) typename NefPolyhedron::Halffacet_const_handle fh)
{ {
if (fh==boost::graph_traits<NefPolyhedron>::null_face()) // use to get the mono color //if (fh==boost::graph_traits<NefPolyhedron>::null_face()) // use to get the mono color
return CGAL::Color(100, 125, 200); // R G B between 0-255 // return CGAL::Color(100, 125, 200); // R G B between 0-255
CGAL::Random random((unsigned int)(std::size_t)(&(*fh))); CGAL::Random random((unsigned int)(std::size_t)(&(*fh)));
return get_random_color(random); return get_random_color(random);
@ -55,12 +55,8 @@ class SimpleNefPolyhedronViewerQt : public Basic_viewer_qt
{ {
typedef Basic_viewer_qt Base; typedef Basic_viewer_qt Base;
typedef typename Nef_Polyhedron::Kernel Kernel; typedef typename Nef_Polyhedron::Kernel Kernel;
typedef typename Nef_Polyhedron::Vertex_const_iterator Vertex_const_iterator;
typedef typename Nef_Polyhedron::Vertex_const_handle Vertex_const_handle; typedef typename Nef_Polyhedron::Vertex_const_handle Vertex_const_handle;
typedef typename Nef_Polyhedron::SNC_const_decorator SNC_const_decorator;
typedef typename Nef_Polyhedron::SNC_structure SNC_structure; typedef typename Nef_Polyhedron::SNC_structure SNC_structure;
typedef typename SNC_structure::Infi_box Infi_box;
typedef typename SNC_structure::Halffacet_cycle_const_iterator typedef typename SNC_structure::Halffacet_cycle_const_iterator
Halffacet_cycle_const_iterator; Halffacet_cycle_const_iterator;
@ -75,8 +71,6 @@ class SimpleNefPolyhedronViewerQt : public Basic_viewer_qt
typedef typename Nef_Polyhedron::Halffacet_const_handle Halffacet_const_handle; typedef typename Nef_Polyhedron::Halffacet_const_handle Halffacet_const_handle;
typedef typename Nef_Polyhedron::SHalfedge_const_handle SHalfedge_const_handle; typedef typename Nef_Polyhedron::SHalfedge_const_handle SHalfedge_const_handle;
typedef typename Nef_Polyhedron::SHalfloop_const_handle SHalfloop_const_handle; typedef typename Nef_Polyhedron::SHalfloop_const_handle SHalfloop_const_handle;
typedef typename Kernel::Point_3 Point_3;
public: public:
/// Construct the viewer /// Construct the viewer
/// @param anef the nef polyhedron to view /// @param anef the nef polyhedron to view
@ -88,8 +82,8 @@ public:
const char* title="Basic Nef Polyhedron Viewer", const char* title="Basic Nef Polyhedron Viewer",
bool anofaces=false, bool anofaces=false,
const ColorFunctor& fcolor=ColorFunctor()) : const ColorFunctor& fcolor=ColorFunctor()) :
//First draw: no vertex; edges, faces; mon-color; inverse normal //First draw: vertex; edges, faces; mon-color; inverse normal
Base(parent, title, true, true, true, true, false), Base(parent, title, true, true, true, false, false),
nef(anef), nef(anef),
m_nofaces(anofaces), m_nofaces(anofaces),
m_fcolor(fcolor) m_fcolor(fcolor)
@ -97,6 +91,7 @@ public:
compute_elements(); compute_elements();
} }
protected: protected:
// Visitor class to iterate through shell objects
class Nef_Visitor { class Nef_Visitor {
public: public:
Nef_Visitor(SimpleNefPolyhedronViewerQt &v) Nef_Visitor(SimpleNefPolyhedronViewerQt &v)
@ -125,7 +120,8 @@ protected:
return; return;
} }
viewer.face_begin(CGAL::Color(yellow())); CGAL::Color c = viewer.run_color(f);
viewer.face_begin(c);
SHalfedge_around_facet_const_circulator hc_start(se); SHalfedge_around_facet_const_circulator hc_start(se);
SHalfedge_around_facet_const_circulator hc_end(hc_start); SHalfedge_around_facet_const_circulator hc_end(hc_start);
@ -176,11 +172,9 @@ protected:
Volume_const_iterator c; Volume_const_iterator c;
int ic = 0;
Nef_Visitor V(*this); Nef_Visitor V(*this);
CGAL_forall_volumes(c, nef) CGAL_forall_volumes(c, nef)
{ {
std::cout << "Volume " << ic++ << std::endl;
int is = 0; int is = 0;
Shell_entry_const_iterator it; Shell_entry_const_iterator it;
CGAL_forall_shells_of(it, c) CGAL_forall_shells_of(it, c)
@ -193,6 +187,11 @@ protected:
std::cout << "Total edges drawn: " << V.n_edges << std::endl; std::cout << "Total edges drawn: " << V.n_edges << std::endl;
} }
CGAL::Color run_color(Halffacet_const_handle fh)
{
return m_fcolor.run(nef, fh);
}
virtual void keyPressEvent(QKeyEvent *e) virtual void keyPressEvent(QKeyEvent *e)
{ {
// Test key pressed: // Test key pressed: