From 09ce35d9baa637943752bb85129cce5a11cf6aa9 Mon Sep 17 00:00:00 2001 From: Guillaume Damiand Date: Thu, 13 Oct 2022 11:18:32 +0200 Subject: [PATCH] Correct template specialisation for add_in_graphic_buffer functions, lcc and voronoi 2 --- .../include/CGAL/Qt/Basic_viewer_qt.h | 4 +- .../include/CGAL/draw_linear_cell_complex.h | 81 ++++---- .../include/CGAL/draw_voronoi_diagram_2.h | 181 +++++++++--------- 3 files changed, 136 insertions(+), 130 deletions(-) diff --git a/GraphicsView/include/CGAL/Qt/Basic_viewer_qt.h b/GraphicsView/include/CGAL/Qt/Basic_viewer_qt.h index 2f702781ddb..aca0bfc1c14 100644 --- a/GraphicsView/include/CGAL/Qt/Basic_viewer_qt.h +++ b/GraphicsView/include/CGAL/Qt/Basic_viewer_qt.h @@ -1305,7 +1305,7 @@ protected: { setManipulatedFrame(nullptr); } else { setManipulatedFrame(m_frame_plane); } - + switch(m_use_clipping_plane) { case CLIPPING_PLANE_OFF: displayMessage(QString("Draw clipping = false")); break; @@ -1510,7 +1510,7 @@ protected: { CGAL::QGLViewer::keyPressEvent(e); } // By default call QGLViewer key press } } - + virtual QString helpString() const { return helpString("CGAL Basic Viewer"); } diff --git a/Linear_cell_complex/include/CGAL/draw_linear_cell_complex.h b/Linear_cell_complex/include/CGAL/draw_linear_cell_complex.h index daa202cf962..280d9e7cd08 100644 --- a/Linear_cell_complex/include/CGAL/draw_linear_cell_complex.h +++ b/Linear_cell_complex/include/CGAL/draw_linear_cell_complex.h @@ -13,13 +13,12 @@ #ifndef CGAL_DRAW_LCC_H #define CGAL_DRAW_LCC_H -#include -#include #include -#include #ifdef CGAL_USE_BASIC_VIEWER +#include +#include #include #include @@ -90,7 +89,7 @@ void compute_face(typename LCC::Dart_const_handle dh, CGAL::IO::Color c=m_drawing_functor.face_color(*lcc, dh); graphic_buffer.face_begin(c); } - else + else { graphic_buffer.face_begin(); } cur=dh; @@ -148,7 +147,7 @@ void compute_vertex(typename LCC::Dart_const_handle dh, const LCC *lcc, } template -void compute_elements(const LCC *lcc, CGAL::Graphic_buffer &graphic_buffer, +void compute_elements(const LCC *lcc, CGAL::Graphic_buffer &graphic_buffer, const DrawingFunctor &m_drawing_functor) { if (lcc==nullptr) @@ -228,37 +227,48 @@ void compute_elements(const LCC *lcc, CGAL::Graphic_buffer &graphic_ lcc->free_mark(oriented_mark); } -} // namespace draw_function +} // namespace draw_function_for_lcc -/** - * @brief This function is responsible for filling the buffer to allow - * visualization. - * - * @param graphic_buffer - * @param m_drawing_functor - * @param alcc - */ -template -void add_in_graphic_buffer(const LCC &alcc, CGAL::Graphic_buffer &graphic_buffer, - const DrawingFunctor &m_drawing_functor) +#define CGAL_LCC_TYPE \ + CGAL::Linear_cell_complex_base + +// add_in_graphic_buffer: to add a LCC in the given graphic buffer, with a +// drawing functor. +template class Map, + class Refs, class Storage_, + typename BufferType=float, class DrawingFunctor> +void add_in_graphic_buffer(const CGAL_LCC_TYPE &alcc, + CGAL::Graphic_buffer &graphic_buffer, + const DrawingFunctor &m_drawing_functor) { draw_function_for_lcc::compute_elements(&alcc, graphic_buffer, m_drawing_functor); } -template -void add_in_graphic_buffer(const LCC &alcc, CGAL::Graphic_buffer &graphic_buffer) +// add_in_graphic_buffer: to add a LCC in the given graphic buffer, without a +// drawing functor. Use default drawing values. +template class Map, + class Refs, class Storage_, typename BufferType=float> +void add_in_graphic_buffer(const CGAL_LCC_TYPE &alcc, + CGAL::Graphic_buffer &graphic_buffer) { - Drawing_functor_with_volume drawing_functor_with_volume; + CGAL::Drawing_functor_with_volume + drawing_functor_with_volume; - drawing_functor_with_volume.colored_volume = [](const LCC&, - typename LCC::Dart_const_handle) -> bool + drawing_functor_with_volume.colored_volume = [](const CGAL_LCC_TYPE&, + typename CGAL_LCC_TYPE::Dart_const_handle) -> bool { return true; }; - drawing_functor_with_volume.volume_color = [] (const LCC& alcc, - typename LCC::Dart_const_handle dh) -> CGAL::IO::Color + drawing_functor_with_volume.volume_color = [] (const CGAL_LCC_TYPE& alcc, + typename CGAL_LCC_TYPE::Dart_const_handle dh) -> CGAL::IO::Color { CGAL::Random random((unsigned int)(alcc.darts().index(dh))); return get_random_color(random); @@ -267,33 +277,30 @@ void add_in_graphic_buffer(const LCC &alcc, CGAL::Graphic_buffer &gr add_in_graphic_buffer(alcc, graphic_buffer, drawing_functor_with_volume); } -// Specialization of draw function. -#define CGAL_LCC_TYPE \ - CGAL::Linear_cell_complex_base - +// Specialization of draw function for a LCC, with a drawing functor. template class Map, class Refs, class Storage_, class DrawingFunctor> -void draw(const CGAL_LCC_TYPE &alcc, const DrawingFunctor &drawing_functor, - const char *title = "LCC for CMap Basic Viewer") +void draw(const CGAL_LCC_TYPE &alcc, const DrawingFunctor &drawing_functor, + const char *title="LCC Basic Viewer") { CGAL::Graphic_buffer buffer; add_in_graphic_buffer(alcc, buffer, drawing_functor); - draw_buffer(buffer); + draw_buffer(buffer, title); } +// Specialization of draw function for a LCC, without a drawing functor. template class Map, class Refs, class Storage_> -void draw(const CGAL_LCC_TYPE &alcc, const char *title = "LCC for CMap Basic Viewer") +void draw(const CGAL_LCC_TYPE &alcc, const char *title="LCC Basic Viewer") { CGAL::Graphic_buffer buffer; add_in_graphic_buffer(alcc, buffer); - draw_buffer(buffer); + draw_buffer(buffer, title); } #undef CGAL_LCC_TYPE diff --git a/Voronoi_diagram_2/include/CGAL/draw_voronoi_diagram_2.h b/Voronoi_diagram_2/include/CGAL/draw_voronoi_diagram_2.h index 640a75b86c3..662a261b27b 100644 --- a/Voronoi_diagram_2/include/CGAL/draw_voronoi_diagram_2.h +++ b/Voronoi_diagram_2/include/CGAL/draw_voronoi_diagram_2.h @@ -57,7 +57,6 @@ struct Drawing_functor_voronoi : std::function draw_dual_vertices; std::function draw_rays; - void disable_voronoi_vertices() { m_draw_voronoi_vertices=false; } void enable_voronoi_vertices() { m_draw_voronoi_vertices=true; } bool are_voronoi_vertices_enabled() const { return m_draw_voronoi_vertices; } @@ -70,7 +69,6 @@ struct Drawing_functor_voronoi : void enable_rays() { m_draw_rays=true; } bool are_rays_enabled() const { return m_draw_rays; } - void disable_nofaces() { m_nofaces=false; } void enable_nofaces() { m_nofaces=true; } bool are_nofaces_enabled() const { return m_nofaces; } @@ -88,15 +86,13 @@ typedef Local_kernel::Vector_3 Local_vector; template void compute_vertex(typename V2::Vertex_iterator vh, - CGAL::Graphic_buffer &graphic_buffer) { - graphic_buffer.add_point(vh->point()); -} + CGAL::Graphic_buffer &graphic_buffer) +{ graphic_buffer.add_point(vh->point()); } template void compute_dual_vertex(typename V2::Delaunay_graph::Finite_vertices_iterator vi, - CGAL::Graphic_buffer &graphic_buffer) { - graphic_buffer.add_point(vi->point(), CGAL::IO::Color(50, 100, 180)); -} + CGAL::Graphic_buffer &graphic_buffer) +{ graphic_buffer.add_point(vi->point(), CGAL::IO::Color(50, 100, 180)); } template void add_segments_and_update_bounding_box(typename V2::Halfedge_handle he, @@ -105,30 +101,33 @@ void add_segments_and_update_bounding_box(typename V2::Halfedge_handle he, typedef CGAL::Exact_predicates_inexact_constructions_kernel Kernel; typedef typename V2::Delaunay_vertex_handle Delaunay_vertex_const_handle; - if (he->is_segment()) { - graphic_buffer.add_segment(he->source()->point(), he->target()->point()); - } else { + if (he->is_segment()) + { graphic_buffer.add_segment(he->source()->point(), he->target()->point()); } + else + { Delaunay_vertex_const_handle v1 = he->up(); Delaunay_vertex_const_handle v2 = he->down(); Kernel::Vector_2 direction(v1->point().y() - v2->point().y(), - v2->point().x() - v1->point().x()); - if (he->is_ray()) { + v2->point().x() - v1->point().x()); + if (he->is_ray()) + { Kernel::Point_2 end_point; - if (he->has_source()) { + if (he->has_source()) + { end_point = he->source()->point(); - // update_bounding_box_for_ray(end_point, direction); - - // update_bounding_box_for_ray - Local_point lp = Basic_viewer_qt<>::get_local_point(end_point); - Local_vector lv = Basic_viewer_qt<>::get_local_vector(direction); - CGAL::Bbox_3 b = (lp + lv).bbox(); - graphic_buffer.update_bounding_box(b); - + // update_bounding_box_for_ray(end_point, direction); + // update_bounding_box_for_ray + Local_point lp = Basic_viewer_qt<>::get_local_point(end_point); + Local_vector lv = Basic_viewer_qt<>::get_local_vector(direction); + CGAL::Bbox_3 b = (lp + lv).bbox(); + graphic_buffer.update_bounding_box(b); } - } else if (he->is_bisector()) { + } + else if (he->is_bisector()) + { Kernel::Point_2 pointOnLine((v1->point().x() + v2->point().x()) / 2, (v1->point().y() + v2->point().y()) / 2); Kernel::Vector_2 perpendicularDirection( @@ -145,7 +144,6 @@ void add_segments_and_update_bounding_box(typename V2::Halfedge_handle he, CGAL::Bbox_3 b = lp.bbox() + (lp + lv).bbox() + (lp + lpv).bbox(); graphic_buffer.update_bounding_box(b); - } } } @@ -167,32 +165,37 @@ Local_kernel::Point_2 get_second_point(typename V2::Halfedge_handle ray, // origin of the ray Kernel::Point_2 p; - if (ray->has_source()) { - p = ray->source()->point(); - } else { - p = ray->target()->point(); - } + if (ray->has_source()) + { p = ray->source()->point(); } + else + { p = ray->target()->point(); } // get the bounding box of the viewer Local_kernel::Vector_2 boundsMin(m_bounding_box.xmin(), - m_bounding_box.zmin()); + m_bounding_box.zmin()); Local_kernel::Vector_2 boundsMax(m_bounding_box.xmax(), - m_bounding_box.zmax()); + m_bounding_box.zmax()); // calculate intersection double txmax, txmin, tymax, tymin; - if (inv.x() >= 0) { + if (inv.x() >= 0) + { txmax = (boundsMax.x() - p.x()) * inv.x(); txmin = (boundsMin.x() - p.x()) * inv.x(); - } else { + } + else + { txmax = (boundsMin.x() - p.x()) * inv.x(); txmin = (boundsMax.x() - p.x()) * inv.x(); } - if (inv.y() >= 0) { + if (inv.y() >= 0) + { tymax = (boundsMax.y() - p.y()) * inv.y(); tymin = (boundsMin.y() - p.y()) * inv.y(); - } else { + } + else + { tymax = (boundsMin.y() - p.y()) * inv.y(); tymin = (boundsMax.y() - p.y()) * inv.y(); } @@ -203,20 +206,19 @@ Local_kernel::Point_2 get_second_point(typename V2::Halfedge_handle ray, txmax = tymax; Local_kernel::Point_2 p1; - if (v.x() == 0) { - p1 = Local_kernel::Point_2(p.x(), p.y() + tymax * v.y()); - } else if (v.y() == 0) { - p1 = Local_kernel::Point_2(p.x() + txmax * v.x(), p.y()); - } else { - p1 = Local_kernel::Point_2(p.x() + txmax * v.x(), p.y() + tymax * v.y()); - } + if (v.x() == 0) + { p1 = Local_kernel::Point_2(p.x(), p.y() + tymax * v.y()); } + else if (v.y() == 0) + { p1 = Local_kernel::Point_2(p.x() + txmax * v.x(), p.y()); } + else + { p1 = Local_kernel::Point_2(p.x() + txmax * v.x(), p.y() + tymax * v.y()); } return p1; } // Halfedge_const_handle template void compute_rays_and_bisectors(typename V2::Halfedge_iterator he, - CGAL::Graphic_buffer &graphic_buffer) + CGAL::Graphic_buffer &graphic_buffer) { typedef CGAL::Exact_predicates_inexact_constructions_kernel Kernel; typedef typename V2::Delaunay_vertex_handle Delaunay_vertex_const_handle; @@ -225,7 +227,7 @@ void compute_rays_and_bisectors(typename V2::Halfedge_iterator he, Delaunay_vertex_const_handle v2 = he->down(); Kernel::Vector_2 direction(v1->point().y() - v2->point().y(), - v2->point().x() - v1->point().x()); + v2->point().x() - v1->point().x()); if (he->is_ray()) { if (he->has_source()) { // add_ray_segment(he->source()->point(), get_second_point(he, graphic_buffer.get_bounding_box())); @@ -276,7 +278,7 @@ void compute_face(typename V2::Face_iterator fh, } template -void compute_elements(const V2& v2, CGAL::Graphic_buffer &graphic_buffer, +void compute_elements(const V2& v2, CGAL::Graphic_buffer &graphic_buffer, const DrawingFunctor &m_drawing_functor) { typedef typename V2::Delaunay_graph::Finite_vertices_iterator Dual_vertices_iterator; @@ -290,61 +292,65 @@ void compute_elements(const V2& v2, CGAL::Graphic_buffer &graphic_bu } // Draw the dual vertices - if (m_drawing_functor.are_dual_vertices_enabled()) { + if (m_drawing_functor.are_dual_vertices_enabled()) + { for (Dual_vertices_iterator it = v2.dual().finite_vertices_begin(); - it != v2.dual().finite_vertices_end(); ++it) { - compute_dual_vertex(it, graphic_buffer); - } + it != v2.dual().finite_vertices_end(); ++it) + { compute_dual_vertex(it, graphic_buffer); } } // Add segments and update bounding box for (typename V2::Halfedge_iterator it = v2.halfedges_begin(); - it != v2.halfedges_end(); ++it) { - add_segments_and_update_bounding_box(it, graphic_buffer); - } + it != v2.halfedges_end(); ++it) + { add_segments_and_update_bounding_box(it, graphic_buffer); } - if(m_drawing_functor.are_rays_enabled()) { + if(m_drawing_functor.are_rays_enabled()) + { for (typename V2::Halfedge_iterator it = v2.halfedges_begin(); - it != v2.halfedges_end(); ++it) { - compute_rays_and_bisectors(it, graphic_buffer); - } + it != v2.halfedges_end(); ++it) + { compute_rays_and_bisectors(it, graphic_buffer); } } - if (!m_drawing_functor.are_nofaces_enabled()) { + if (!m_drawing_functor.are_nofaces_enabled()) + { for (typename V2::Face_iterator it = v2.faces_begin(); - it != v2.faces_end(); ++it) { - compute_face(it, v2, graphic_buffer, m_drawing_functor); - } + it != v2.faces_end(); ++it) + { compute_face(it, v2, graphic_buffer, m_drawing_functor); } } } } // namespace draw_function_for_v2 -template -void add_in_graphic_buffer(const V2 &v2, CGAL::Graphic_buffer &graphic_buffer, - const DrawingFunctor &m_drawing_functor) +#define CGAL_VORONOI_TYPE CGAL::Voronoi_diagram_2 + +template +void add_in_graphic_buffer(const CGAL_VORONOI_TYPE &v2, + CGAL::Graphic_buffer &graphic_buffer, + const DrawingFunctor &m_drawing_functor) { draw_function_for_v2::compute_elements(v2, graphic_buffer, m_drawing_functor); } -template -void add_in_graphic_buffer(const V2 &v2, CGAL::Graphic_buffer &graphic_buffer, +template +void add_in_graphic_buffer(const CGAL_VORONOI_TYPE &v2, + CGAL::Graphic_buffer &graphic_buffer, bool m_nofaces = false, bool m_draw_voronoi_vertices = true, - bool m_draw_dual_vertices = true ) { - + bool m_draw_dual_vertices = true ) +{ // Default functor; user can add his own functor. - CGAL::draw_function_for_v2::Drawing_functor_voronoi + CGAL::draw_function_for_v2::Drawing_functor_voronoi drawing_functor; - drawing_functor.colored_face = [](const V2&, - typename V2::Face_iterator fh) -> bool + drawing_functor.colored_face = [](const CGAL_VORONOI_TYPE&, + typename CGAL_VORONOI_TYPE::Face_iterator fh) -> bool { return true; }; - - drawing_functor.face_color = [] (const V2& alcc, - typename V2::Face_iterator fh) -> CGAL::IO::Color + drawing_functor.face_color = [] (const CGAL_VORONOI_TYPE& alcc, + typename CGAL_VORONOI_TYPE::Face_iterator fh) -> CGAL::IO::Color { return CGAL::IO::Color(73, 250, 117); }; @@ -358,32 +364,25 @@ void add_in_graphic_buffer(const V2 &v2, CGAL::Graphic_buffer &graph // setKeyDescription(::Qt::Key_D, "Toggles dual vertices display"); // setKeyDescription(::Qt::Key_V, "Toggles voronoi vertices display"); - - - // Specialization of draw function. -#define CGAL_VORONOI_TYPE CGAL::Voronoi_diagram_2 - -template +template void draw(const CGAL_VORONOI_TYPE &av2, - const DrawingFunctor &drawing_functor) + const DrawingFunctor &drawing_functor, + const char *title="2D Voronoi Diagram Basic Viewer") { CGAL::Graphic_buffer buffer; add_in_graphic_buffer(av2, buffer, drawing_functor); - draw_buffer(buffer); + draw_buffer(buffer, title); } -template +template void draw(const CGAL_VORONOI_TYPE &av2, const char *title="2D Voronoi Diagram Basic Viewer") { CGAL::Graphic_buffer buffer; - CGAL::draw_function_for_v2::Drawing_functor_voronoi @@ -402,7 +401,7 @@ void draw(const CGAL_VORONOI_TYPE &av2, add_in_graphic_buffer(av2, buffer, drawing_functor); - std::function *)> VoronoiKeyPressEvent = + std::function *)> VoronoiKeyPressEvent = [&av2, &drawing_functor] (QKeyEvent *e, CGAL::Basic_viewer_qt *_this) -> bool { /// [Keypress] @@ -469,7 +468,7 @@ void draw(const CGAL_VORONOI_TYPE &av2, /// [Keypress] return true; }; - draw_buffer(buffer, VoronoiKeyPressEvent); + draw_buffer(buffer, VoronoiKeyPressEvent, title); }