diff --git a/BGL/include/CGAL/draw_face_graph.h b/BGL/include/CGAL/draw_face_graph.h index e78016a56f1..f5784dc2a79 100644 --- a/BGL/include/CGAL/draw_face_graph.h +++ b/BGL/include/CGAL/draw_face_graph.h @@ -16,41 +16,40 @@ #include #include -#include - -#ifdef CGAL_USE_BASIC_VIEWER - #include #include #include namespace CGAL { -namespace draw_function_for_SM { +namespace draw_function_for_FG { -template -void compute_elements(const SM &sm, +template +void compute_elements(const FG &fg, CGAL::Graphic_buffer &graphic_buffer, - const DrawingFunctor &m_drawing_functor, bool anofaces = false) { - - using Point = - typename boost::property_map_value::type; + const DrawingFunctor &m_drawing_functor) +{ + using Point=typename boost::property_map_value::type; using Kernel = typename CGAL::Kernel_traits::Kernel; using Vector = typename Kernel::Vector_3; - auto vnormals = get(CGAL::dynamic_vertex_property_t(), sm); - auto point_pmap = get(CGAL::vertex_point, sm); - for (auto v : vertices(sm)) { + auto vnormals = get(CGAL::dynamic_vertex_property_t(), fg); + auto point_pmap = get(CGAL::vertex_point, fg); + for (auto v : vertices(fg)) + { Vector n(NULL_VECTOR); int i = 0; - for (auto h : halfedges_around_target(halfedge(v, sm), sm)) { - if (!is_border(h, sm)) { + for (auto h : halfedges_around_target(halfedge(v, fg), fg)) + { + if (!is_border(h, fg)) + { Vector ni = CGAL::cross_product( - Vector(get(point_pmap, source(h, sm)), - get(point_pmap, target(h, sm))), - Vector(get(point_pmap, target(h, sm)), - get(point_pmap, target(next(h, sm), sm)))); - if (ni != NULL_VECTOR) { + Vector(get(point_pmap, source(h, fg)), + get(point_pmap, target(h, fg))), + Vector(get(point_pmap, target(h, fg)), + get(point_pmap, target(next(h, fg), fg)))); + if (ni != NULL_VECTOR) + { n += ni; ++i; } @@ -59,70 +58,104 @@ void compute_elements(const SM &sm, put(vnormals, v, n / i); } - if (!anofaces) { - for (auto fh : faces(sm)) { - if (fh != boost::graph_traits::null_face() && m_drawing_functor.colored_face(sm, fh)) { - CGAL::IO::Color c = m_drawing_functor.face_color(sm, fh); - graphic_buffer.face_begin(c); - auto hd = halfedge(fh, sm); + if (m_drawing_functor.are_faces_enabled()) + { + for (auto fh : faces(fg)) + { + if (fh != boost::graph_traits::null_face() && // face exists + m_drawing_functor.colored_face && // std::function is not null + m_drawing_functor.colored_face(fg, fh)) // and face is colored + { + graphic_buffer.face_begin(m_drawing_functor.face_color(fg, fh)); + auto hd = halfedge(fh, fg); const auto first_hd = hd; - do { - auto v = source(hd, sm); + do + { + auto v = source(hd, fg); graphic_buffer.add_point_in_face(get(point_pmap, v), get(vnormals, v)); - hd = next(hd, sm); - } while (hd != first_hd); + hd = next(hd, fg); + } + while (hd != first_hd); graphic_buffer.face_end(); } } } - for (auto e : edges(sm)) { - graphic_buffer.add_segment(get(point_pmap, source(halfedge(e, sm), sm)), - get(point_pmap, target(halfedge(e, sm), sm))); + if(m_drawing_functor.are_edges_enabled()) + { + for (auto e : edges(fg)) + { + if(m_drawing_functor.colored_edge && // std::function is not null + m_drawing_functor.colored_edge(fg, e)) // and edge is colored + { + graphic_buffer.add_segment(get(point_pmap, source(halfedge(e, fg), fg)), + get(point_pmap, target(halfedge(e, fg), fg)), + m_drawing_functor.edge_color(fg, e)); + } + else + { + graphic_buffer.add_segment(get(point_pmap, source(halfedge(e, fg), fg)), + get(point_pmap, target(halfedge(e, fg), fg))); + } + } } - for (auto v : vertices(sm)) { - graphic_buffer.add_point(get(point_pmap, v)); + if(m_drawing_functor.are_vertices_enabled()) + { + for (auto v : vertices(fg)) + { + if(m_drawing_functor.colored_vertex && // std::function is not null + m_drawing_functor.colored_vertex(fg, v)) // and vertex is colored + { + graphic_buffer.add_point(get(point_pmap, v), + m_drawing_functor.vertex_color(fg, v)); + } + else + { + graphic_buffer.add_point(get(point_pmap, v)); + } + } } } -} // draw_function_for_SM +} // draw_function_for_FG -template -void add_in_graphic_buffer(const SM &sm, CGAL::Graphic_buffer &graphic_buffer, - const DrawingFunctor &m_drawing_functor) { - draw_function_for_SM::compute_elements(sm, graphic_buffer, m_drawing_functor); +template +void add_in_graphic_buffer_for_fg(const FG &fg, + CGAL::Graphic_buffer &graphic_buffer, + const DrawingFunctor &drawing_functor) +{ + draw_function_for_FG::compute_elements(fg, graphic_buffer, drawing_functor); } -template -void add_in_graphic_buffer(const SM &sm, CGAL::Graphic_buffer &graphic_buffer) { - - // Default functor; user can add his own functor. - Drawing_functor::face_descriptor, - typename boost::graph_traits::face_descriptor, - typename boost::graph_traits::face_descriptor> +template +void add_in_graphic_buffer_for_fg(const FG &fg, + CGAL::Graphic_buffer &graphic_buffer) +{ + Drawing_functor::vertex_descriptor, + typename boost::graph_traits::edge_descriptor, + typename boost::graph_traits::face_descriptor> drawing_functor; - drawing_functor.colored_face = [](const SM &, - typename boost::graph_traits::face_descriptor fh) -> bool + drawing_functor.colored_face = [](const FG&, + typename boost::graph_traits::face_descriptor) -> bool { return true; }; - drawing_functor.face_color = [] (const SM &, - typename boost::graph_traits::face_descriptor fh) -> CGAL::IO::Color + drawing_functor.face_color = [] (const FG&, + typename boost::graph_traits::face_descriptor fh) -> CGAL::IO::Color { - if (fh == - boost::graph_traits::null_face()) // use to get the mono color - return CGAL::IO::Color(100, 125, 200); // R G B between 0-255 + if (fh==boost::graph_traits::null_face()) + { return CGAL::IO::Color(100, 125, 200); } + // TODO (?) use a seed given fh (cannot directly cast because FG is either a polyhedron or a surface mesh) return get_random_color(CGAL::get_default_random()); }; - add_in_graphic_buffer(sm, graphic_buffer, drawing_functor); + add_in_graphic_buffer_for_fg(fg, graphic_buffer, drawing_functor); } } // End namespace CGAL -#endif // CGAL_USE_BASIC_VIEWER - #endif // CGAL_DRAW_SURFACE_MESH_H diff --git a/Polyhedron/include/CGAL/draw_polyhedron.h b/Polyhedron/include/CGAL/draw_polyhedron.h index b6d92c56b3a..826a2b7a6e3 100644 --- a/Polyhedron/include/CGAL/draw_polyhedron.h +++ b/Polyhedron/include/CGAL/draw_polyhedron.h @@ -13,57 +13,81 @@ #ifndef CGAL_DRAW_POLYHEDRON_H #define CGAL_DRAW_POLYHEDRON_H +#include #include #include -#include -#include - -#ifdef CGAL_USE_BASIC_VIEWER -#include #include #include -#include + +#ifdef CGAL_USE_BASIC_VIEWER +#include +#endif namespace CGAL { -// Specialization of draw function. #define CGAL_POLY_TYPE CGAL::Polyhedron_3 \ +// Specialization of add_in_graphic_buffer function. template class T_HDS, - class Alloc, typename BufferType = float> + class Alloc, + typename BufferType=float, + class DrawingFunctor> +void add_in_graphic_buffer(const CGAL_POLY_TYPE& apoly, + CGAL::Graphic_buffer &graphic_buffer, + const DrawingFunctor &drawing_functor) +{ add_in_graphic_buffer_for_fg(apoly, graphic_buffer, drawing_functor); } + +template + class T_HDS, + class Alloc, + typename BufferType=float> +void add_in_graphic_buffer(const CGAL_POLY_TYPE& apoly, + CGAL::Graphic_buffer &graphic_buffer) +{ add_in_graphic_buffer_for_fg(apoly, graphic_buffer); } + +// Specialization of draw function: require Qt and the CGAL basic viewer. +#ifdef CGAL_USE_BASIC_VIEWER + +template + class T_HDS, + class Alloc, + typename BufferType=float> void draw(const CGAL_POLY_TYPE& apoly, - const char* title="Polyhedron Basic Viewer", - bool nofill=false) + const char* title="Polyhedron Basic Viewer") { CGAL::Graphic_buffer buffer; - add_in_graphic_buffer(apoly, buffer); - draw_buffer(buffer); + add_in_graphic_buffer_for_fg(apoly, buffer); + draw_buffer(buffer, title); } template class T_HDS, - class Alloc, typename BufferType = float, class DrawingFunctor> + class Alloc, + typename BufferType=float, + class DrawingFunctor> void draw(const CGAL_POLY_TYPE& apoly, const DrawingFunctor &drawing_functor, - const char* title="Polyhedron Basic Viewer", - bool nofill=false) + const char* title="Polyhedron Basic Viewer") { CGAL::Graphic_buffer buffer; - add_in_graphic_buffer(apoly, buffer, drawing_functor); - draw_buffer(buffer); + add_in_graphic_buffer_for_fg(apoly, buffer, drawing_functor); + draw_buffer(buffer, title); } - +#endif // CGAL_USE_BASIC_VIEWER + #undef CGAL_POLY_TYPE } // End namespace CGAL -#endif // CGAL_USE_BASIC_VIEWER - #endif // CGAL_DRAW_POLYHEDRON_H diff --git a/Surface_mesh/include/CGAL/draw_surface_mesh.h b/Surface_mesh/include/CGAL/draw_surface_mesh.h index 184d80c5a83..c6a545a5bf8 100644 --- a/Surface_mesh/include/CGAL/draw_surface_mesh.h +++ b/Surface_mesh/include/CGAL/draw_surface_mesh.h @@ -29,46 +29,56 @@ void draw(const SM& asm); #else // DOXYGEN_RUNNING +#include #include #include -#include -#include - -#ifdef CGAL_USE_BASIC_VIEWER - -#include #include #include +#ifdef CGAL_USE_BASIC_VIEWER +#include +#endif + namespace CGAL { -// Specialization of draw function. -template +template +void add_in_graphic_buffer(const Surface_mesh& amesh, + CGAL::Graphic_buffer &graphic_buffer, + const DrawingFunctor &drawing_functor) +{ add_in_graphic_buffer_for_fg(amesh, graphic_buffer, drawing_functor); } + +template +void add_in_graphic_buffer(const Surface_mesh& amesh, + CGAL::Graphic_buffer &graphic_buffer) +{ add_in_graphic_buffer_for_fg(amesh, graphic_buffer); } + +#ifdef CGAL_USE_BASIC_VIEWER + + // Specialization of draw function. +template void draw(const Surface_mesh& amesh, - const char* title="Surface_mesh Basic Viewer", - bool nofill=false) + const char* title="Surface_mesh Basic Viewer") { CGAL::Graphic_buffer buffer; - add_in_graphic_buffer(amesh, buffer); - draw_buffer(buffer); + add_in_graphic_buffer_for_fg(amesh, buffer); + draw_buffer(buffer, title); } -template +template void draw(const Surface_mesh& amesh, const DrawingFunctor &drawing_functor, - const char* title="Surface_mesh Basic Viewer", - bool nofill=false) + const char* title="Surface_mesh Basic Viewer") { CGAL::Graphic_buffer buffer; - add_in_graphic_buffer(amesh, buffer, drawing_functor); - draw_buffer(buffer); + add_in_graphic_buffer_for_fg(amesh, buffer, drawing_functor); + draw_buffer(buffer, title); } -} // End namespace CGAL - #endif // CGAL_USE_BASIC_VIEWER +} // End namespace CGAL + #endif // DOXYGEN_RUNNING #endif // CGAL_DRAW_SURFACE_MESH_H