Correct template specialisation for add_in_graphic_buffer functions, lcc and voronoi 2

This commit is contained in:
Guillaume Damiand 2022-10-13 11:18:32 +02:00
parent 91016007cd
commit 09ce35d9ba
3 changed files with 136 additions and 130 deletions

View File

@ -13,13 +13,12 @@
#ifndef CGAL_DRAW_LCC_H #ifndef CGAL_DRAW_LCC_H
#define CGAL_DRAW_LCC_H #define CGAL_DRAW_LCC_H
#include <CGAL/Graphic_buffer.h>
#include <CGAL/Drawing_functor.h>
#include <CGAL/Qt/Basic_viewer_qt.h> #include <CGAL/Qt/Basic_viewer_qt.h>
#include <functional>
#ifdef CGAL_USE_BASIC_VIEWER #ifdef CGAL_USE_BASIC_VIEWER
#include <CGAL/Graphic_buffer.h>
#include <CGAL/Drawing_functor.h>
#include <CGAL/Linear_cell_complex_operations.h> #include <CGAL/Linear_cell_complex_operations.h>
#include <CGAL/Random.h> #include <CGAL/Random.h>
@ -228,37 +227,48 @@ void compute_elements(const LCC *lcc, CGAL::Graphic_buffer<BufferType> &graphic_
lcc->free_mark(oriented_mark); lcc->free_mark(oriented_mark);
} }
} // namespace draw_function } // namespace draw_function_for_lcc
/** #define CGAL_LCC_TYPE \
* @brief This function is responsible for filling the buffer to allow CGAL::Linear_cell_complex_base<d_, ambient_dim, Traits_, Items_, Alloc_, \
* visualization. Map, Refs, Storage_>
*
* @param graphic_buffer // add_in_graphic_buffer: to add a LCC in the given graphic buffer, with a
* @param m_drawing_functor // drawing functor.
* @param alcc template<unsigned int d_, unsigned int ambient_dim, class Traits_,
*/ class Items_, class Alloc_,
template <typename BufferType = float, class LCC, class DrawingFunctor> template <unsigned int, class, class, class, class> class Map,
void add_in_graphic_buffer(const LCC &alcc, CGAL::Graphic_buffer<BufferType> &graphic_buffer, class Refs, class Storage_,
typename BufferType=float, class DrawingFunctor>
void add_in_graphic_buffer(const CGAL_LCC_TYPE &alcc,
CGAL::Graphic_buffer<BufferType> &graphic_buffer,
const DrawingFunctor &m_drawing_functor) const DrawingFunctor &m_drawing_functor)
{ {
draw_function_for_lcc::compute_elements(&alcc, graphic_buffer, m_drawing_functor); draw_function_for_lcc::compute_elements(&alcc, graphic_buffer, m_drawing_functor);
} }
template <typename BufferType = float, class LCC> // add_in_graphic_buffer: to add a LCC in the given graphic buffer, without a
void add_in_graphic_buffer(const LCC &alcc, CGAL::Graphic_buffer<BufferType> &graphic_buffer) // drawing functor. Use default drawing values.
template<unsigned int d_, unsigned int ambient_dim, class Traits_,
class Items_, class Alloc_,
template <unsigned int, class, class, class, class> class Map,
class Refs, class Storage_, typename BufferType=float>
void add_in_graphic_buffer(const CGAL_LCC_TYPE &alcc,
CGAL::Graphic_buffer<BufferType> &graphic_buffer)
{ {
Drawing_functor_with_volume<LCC,typename LCC::Dart_const_handle, CGAL::Drawing_functor_with_volume<CGAL_LCC_TYPE,
typename LCC::Dart_const_handle, typename CGAL_LCC_TYPE::Dart_const_handle,
typename LCC::Dart_const_handle, typename CGAL_LCC_TYPE::Dart_const_handle,
typename LCC::Dart_const_handle> drawing_functor_with_volume; typename CGAL_LCC_TYPE::Dart_const_handle,
typename CGAL_LCC_TYPE::Dart_const_handle>
drawing_functor_with_volume;
drawing_functor_with_volume.colored_volume = [](const LCC&, drawing_functor_with_volume.colored_volume = [](const CGAL_LCC_TYPE&,
typename LCC::Dart_const_handle) -> bool typename CGAL_LCC_TYPE::Dart_const_handle) -> bool
{ return true; }; { return true; };
drawing_functor_with_volume.volume_color = [] (const LCC& alcc, drawing_functor_with_volume.volume_color = [] (const CGAL_LCC_TYPE& alcc,
typename LCC::Dart_const_handle dh) -> CGAL::IO::Color typename CGAL_LCC_TYPE::Dart_const_handle dh) -> CGAL::IO::Color
{ {
CGAL::Random random((unsigned int)(alcc.darts().index(dh))); CGAL::Random random((unsigned int)(alcc.darts().index(dh)));
return get_random_color(random); return get_random_color(random);
@ -267,33 +277,30 @@ void add_in_graphic_buffer(const LCC &alcc, CGAL::Graphic_buffer<BufferType> &gr
add_in_graphic_buffer(alcc, graphic_buffer, drawing_functor_with_volume); add_in_graphic_buffer(alcc, graphic_buffer, drawing_functor_with_volume);
} }
// Specialization of draw function. // Specialization of draw function for a LCC, with a drawing functor.
#define CGAL_LCC_TYPE \
CGAL::Linear_cell_complex_base<d_, ambient_dim, Traits_, Items_, Alloc_, \
Map, Refs, Storage_>
template<unsigned int d_, unsigned int ambient_dim, class Traits_, template<unsigned int d_, unsigned int ambient_dim, class Traits_,
class Items_, class Alloc_, class Items_, class Alloc_,
template <unsigned int, class, class, class, class> class Map, template <unsigned int, class, class, class, class> class Map,
class Refs, class Storage_, class Refs, class Storage_,
class DrawingFunctor> class DrawingFunctor>
void draw(const CGAL_LCC_TYPE &alcc, const DrawingFunctor &drawing_functor, void draw(const CGAL_LCC_TYPE &alcc, const DrawingFunctor &drawing_functor,
const char *title = "LCC for CMap Basic Viewer") const char *title="LCC Basic Viewer")
{ {
CGAL::Graphic_buffer<float> buffer; CGAL::Graphic_buffer<float> buffer;
add_in_graphic_buffer(alcc, buffer, drawing_functor); 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<unsigned int d_, unsigned int ambient_dim, class Traits_, template<unsigned int d_, unsigned int ambient_dim, class Traits_,
class Items_, class Alloc_, class Items_, class Alloc_,
template <unsigned int, class, class, class, class> class Map, template <unsigned int, class, class, class, class> class Map,
class Refs, class Storage_> 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<float> buffer; CGAL::Graphic_buffer<float> buffer;
add_in_graphic_buffer(alcc, buffer); add_in_graphic_buffer(alcc, buffer);
draw_buffer(buffer); draw_buffer(buffer, title);
} }
#undef CGAL_LCC_TYPE #undef CGAL_LCC_TYPE

View File

@ -57,7 +57,6 @@ struct Drawing_functor_voronoi :
std::function<bool(const DS&, vertex_handle)> draw_dual_vertices; std::function<bool(const DS&, vertex_handle)> draw_dual_vertices;
std::function<bool(const DS&, vertex_handle)> draw_rays; std::function<bool(const DS&, vertex_handle)> draw_rays;
void disable_voronoi_vertices() { m_draw_voronoi_vertices=false; } void disable_voronoi_vertices() { m_draw_voronoi_vertices=false; }
void enable_voronoi_vertices() { m_draw_voronoi_vertices=true; } void enable_voronoi_vertices() { m_draw_voronoi_vertices=true; }
bool are_voronoi_vertices_enabled() const { return m_draw_voronoi_vertices; } 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; } void enable_rays() { m_draw_rays=true; }
bool are_rays_enabled() const { return m_draw_rays; } bool are_rays_enabled() const { return m_draw_rays; }
void disable_nofaces() { m_nofaces=false; } void disable_nofaces() { m_nofaces=false; }
void enable_nofaces() { m_nofaces=true; } void enable_nofaces() { m_nofaces=true; }
bool are_nofaces_enabled() const { return m_nofaces; } bool are_nofaces_enabled() const { return m_nofaces; }
@ -88,15 +86,13 @@ typedef Local_kernel::Vector_3 Local_vector;
template <typename BufferType = float, class V2> template <typename BufferType = float, class V2>
void compute_vertex(typename V2::Vertex_iterator vh, void compute_vertex(typename V2::Vertex_iterator vh,
CGAL::Graphic_buffer<BufferType> &graphic_buffer) { CGAL::Graphic_buffer<BufferType> &graphic_buffer)
graphic_buffer.add_point(vh->point()); { graphic_buffer.add_point(vh->point()); }
}
template <typename BufferType = float, class V2> template <typename BufferType = float, class V2>
void compute_dual_vertex(typename V2::Delaunay_graph::Finite_vertices_iterator vi, void compute_dual_vertex(typename V2::Delaunay_graph::Finite_vertices_iterator vi,
CGAL::Graphic_buffer<BufferType> &graphic_buffer) { CGAL::Graphic_buffer<BufferType> &graphic_buffer)
graphic_buffer.add_point(vi->point(), CGAL::IO::Color(50, 100, 180)); { graphic_buffer.add_point(vi->point(), CGAL::IO::Color(50, 100, 180)); }
}
template <typename BufferType = float, class V2> template <typename BufferType = float, class V2>
void add_segments_and_update_bounding_box(typename V2::Halfedge_handle he, void add_segments_and_update_bounding_box(typename V2::Halfedge_handle he,
@ -105,17 +101,20 @@ void add_segments_and_update_bounding_box(typename V2::Halfedge_handle he,
typedef CGAL::Exact_predicates_inexact_constructions_kernel Kernel; typedef CGAL::Exact_predicates_inexact_constructions_kernel Kernel;
typedef typename V2::Delaunay_vertex_handle Delaunay_vertex_const_handle; typedef typename V2::Delaunay_vertex_handle Delaunay_vertex_const_handle;
if (he->is_segment()) { if (he->is_segment())
graphic_buffer.add_segment(he->source()->point(), he->target()->point()); { graphic_buffer.add_segment(he->source()->point(), he->target()->point()); }
} else { else
{
Delaunay_vertex_const_handle v1 = he->up(); Delaunay_vertex_const_handle v1 = he->up();
Delaunay_vertex_const_handle v2 = he->down(); Delaunay_vertex_const_handle v2 = he->down();
Kernel::Vector_2 direction(v1->point().y() - v2->point().y(), 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->is_ray())
{
Kernel::Point_2 end_point; Kernel::Point_2 end_point;
if (he->has_source()) { if (he->has_source())
{
end_point = he->source()->point(); end_point = he->source()->point();
// update_bounding_box_for_ray(end_point, direction); // update_bounding_box_for_ray(end_point, direction);
@ -125,10 +124,10 @@ void add_segments_and_update_bounding_box(typename V2::Halfedge_handle he,
Local_vector lv = Basic_viewer_qt<>::get_local_vector(direction); Local_vector lv = Basic_viewer_qt<>::get_local_vector(direction);
CGAL::Bbox_3 b = (lp + lv).bbox(); CGAL::Bbox_3 b = (lp + lv).bbox();
graphic_buffer.update_bounding_box(b); 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, Kernel::Point_2 pointOnLine((v1->point().x() + v2->point().x()) / 2,
(v1->point().y() + v2->point().y()) / 2); (v1->point().y() + v2->point().y()) / 2);
Kernel::Vector_2 perpendicularDirection( 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(); CGAL::Bbox_3 b = lp.bbox() + (lp + lv).bbox() + (lp + lpv).bbox();
graphic_buffer.update_bounding_box(b); graphic_buffer.update_bounding_box(b);
} }
} }
} }
@ -167,11 +165,10 @@ Local_kernel::Point_2 get_second_point(typename V2::Halfedge_handle ray,
// origin of the ray // origin of the ray
Kernel::Point_2 p; Kernel::Point_2 p;
if (ray->has_source()) { if (ray->has_source())
p = ray->source()->point(); { p = ray->source()->point(); }
} else { else
p = ray->target()->point(); { p = ray->target()->point(); }
}
// get the bounding box of the viewer // get the bounding box of the viewer
Local_kernel::Vector_2 boundsMin(m_bounding_box.xmin(), Local_kernel::Vector_2 boundsMin(m_bounding_box.xmin(),
@ -181,18 +178,24 @@ Local_kernel::Point_2 get_second_point(typename V2::Halfedge_handle ray,
// calculate intersection // calculate intersection
double txmax, txmin, tymax, tymin; double txmax, txmin, tymax, tymin;
if (inv.x() >= 0) { if (inv.x() >= 0)
{
txmax = (boundsMax.x() - p.x()) * inv.x(); txmax = (boundsMax.x() - p.x()) * inv.x();
txmin = (boundsMin.x() - p.x()) * inv.x(); txmin = (boundsMin.x() - p.x()) * inv.x();
} else { }
else
{
txmax = (boundsMin.x() - p.x()) * inv.x(); txmax = (boundsMin.x() - p.x()) * inv.x();
txmin = (boundsMax.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(); tymax = (boundsMax.y() - p.y()) * inv.y();
tymin = (boundsMin.y() - p.y()) * inv.y(); tymin = (boundsMin.y() - p.y()) * inv.y();
} else { }
else
{
tymax = (boundsMin.y() - p.y()) * inv.y(); tymax = (boundsMin.y() - p.y()) * inv.y();
tymin = (boundsMax.y() - p.y()) * inv.y(); tymin = (boundsMax.y() - p.y()) * inv.y();
} }
@ -203,13 +206,12 @@ Local_kernel::Point_2 get_second_point(typename V2::Halfedge_handle ray,
txmax = tymax; txmax = tymax;
Local_kernel::Point_2 p1; Local_kernel::Point_2 p1;
if (v.x() == 0) { if (v.x() == 0)
p1 = Local_kernel::Point_2(p.x(), p.y() + tymax * v.y()); { p1 = Local_kernel::Point_2(p.x(), p.y() + tymax * v.y()); }
} else if (v.y() == 0) { else if (v.y() == 0)
p1 = Local_kernel::Point_2(p.x() + txmax * v.x(), p.y()); { p1 = Local_kernel::Point_2(p.x() + txmax * v.x(), p.y()); }
} else { else
p1 = Local_kernel::Point_2(p.x() + txmax * v.x(), p.y() + tymax * v.y()); { p1 = Local_kernel::Point_2(p.x() + txmax * v.x(), p.y() + tymax * v.y()); }
}
return p1; return p1;
} }
@ -290,61 +292,65 @@ void compute_elements(const V2& v2, CGAL::Graphic_buffer<BufferType> &graphic_bu
} }
// Draw the dual vertices // 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(); for (Dual_vertices_iterator it = v2.dual().finite_vertices_begin();
it != v2.dual().finite_vertices_end(); ++it) { it != v2.dual().finite_vertices_end(); ++it)
compute_dual_vertex<BufferType, V2>(it, graphic_buffer); { compute_dual_vertex<BufferType, V2>(it, graphic_buffer); }
}
} }
// Add segments and update bounding box // Add segments and update bounding box
for (typename V2::Halfedge_iterator it = v2.halfedges_begin(); for (typename V2::Halfedge_iterator it = v2.halfedges_begin();
it != v2.halfedges_end(); ++it) { it != v2.halfedges_end(); ++it)
add_segments_and_update_bounding_box<BufferType, V2>(it, graphic_buffer); { add_segments_and_update_bounding_box<BufferType, V2>(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(); for (typename V2::Halfedge_iterator it = v2.halfedges_begin();
it != v2.halfedges_end(); ++it) { it != v2.halfedges_end(); ++it)
compute_rays_and_bisectors<BufferType, V2>(it, graphic_buffer); { compute_rays_and_bisectors<BufferType, V2>(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(); for (typename V2::Face_iterator it = v2.faces_begin();
it != v2.faces_end(); ++it) { it != v2.faces_end(); ++it)
compute_face(it, v2, graphic_buffer, m_drawing_functor); { compute_face(it, v2, graphic_buffer, m_drawing_functor); }
}
} }
} }
} // namespace draw_function_for_v2 } // namespace draw_function_for_v2
template <typename BufferType = float, class V2, class DrawingFunctor> #define CGAL_VORONOI_TYPE CGAL::Voronoi_diagram_2 <DG, AT, AP>
void add_in_graphic_buffer(const V2 &v2, CGAL::Graphic_buffer<BufferType> &graphic_buffer,
template <class DG, class AT, class AP,
typename BufferType=float, class DrawingFunctor>
void add_in_graphic_buffer(const CGAL_VORONOI_TYPE &v2,
CGAL::Graphic_buffer<BufferType> &graphic_buffer,
const DrawingFunctor &m_drawing_functor) const DrawingFunctor &m_drawing_functor)
{ {
draw_function_for_v2::compute_elements(v2, graphic_buffer, m_drawing_functor); draw_function_for_v2::compute_elements(v2, graphic_buffer, m_drawing_functor);
} }
template <typename BufferType = float, class V2> template <class DG, class AT, class AP, typename BufferType=float>
void add_in_graphic_buffer(const V2 &v2, CGAL::Graphic_buffer<BufferType> &graphic_buffer, void add_in_graphic_buffer(const CGAL_VORONOI_TYPE &v2,
CGAL::Graphic_buffer<BufferType> &graphic_buffer,
bool m_nofaces = false, bool m_draw_voronoi_vertices = true, 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. // Default functor; user can add his own functor.
CGAL::draw_function_for_v2::Drawing_functor_voronoi<V2, typename V2::Vertex_iterator, CGAL::draw_function_for_v2::Drawing_functor_voronoi<CGAL_VORONOI_TYPE,
typename V2::Halfedge_iterator, typename CGAL_VORONOI_TYPE::Vertex_iterator,
typename V2::Face_iterator> typename CGAL_VORONOI_TYPE::Halfedge_iterator,
typename CGAL_VORONOI_TYPE::Face_iterator>
drawing_functor; drawing_functor;
drawing_functor.colored_face = [](const V2&, drawing_functor.colored_face = [](const CGAL_VORONOI_TYPE&,
typename V2::Face_iterator fh) -> bool typename CGAL_VORONOI_TYPE::Face_iterator fh) -> bool
{ return true; }; { return true; };
drawing_functor.face_color = [] (const CGAL_VORONOI_TYPE& alcc,
drawing_functor.face_color = [] (const V2& alcc, typename CGAL_VORONOI_TYPE::Face_iterator fh) -> CGAL::IO::Color
typename V2::Face_iterator fh) -> CGAL::IO::Color
{ {
return CGAL::IO::Color(73, 250, 117); return CGAL::IO::Color(73, 250, 117);
}; };
@ -358,26 +364,19 @@ void add_in_graphic_buffer(const V2 &v2, CGAL::Graphic_buffer<BufferType> &graph
// setKeyDescription(::Qt::Key_D, "Toggles dual vertices display"); // setKeyDescription(::Qt::Key_D, "Toggles dual vertices display");
// setKeyDescription(::Qt::Key_V, "Toggles voronoi vertices display"); // setKeyDescription(::Qt::Key_V, "Toggles voronoi vertices display");
// Specialization of draw function. // Specialization of draw function.
#define CGAL_VORONOI_TYPE CGAL::Voronoi_diagram_2 <DG, AT, AP> template<class DG, class AT, class AP,
typename BufferType=float, class DrawingFunctor>
template<class DG,
class AT,
class AP, typename BufferType = float, class DrawingFunctor>
void draw(const CGAL_VORONOI_TYPE &av2, 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<BufferType> buffer; CGAL::Graphic_buffer<BufferType> buffer;
add_in_graphic_buffer(av2, buffer, drawing_functor); add_in_graphic_buffer(av2, buffer, drawing_functor);
draw_buffer(buffer); draw_buffer(buffer, title);
} }
template<class DG, template<class DG, class AT, class AP, typename BufferType=float>
class AT,
class AP, typename BufferType = float>
void draw(const CGAL_VORONOI_TYPE &av2, void draw(const CGAL_VORONOI_TYPE &av2,
const char *title="2D Voronoi Diagram Basic Viewer") const char *title="2D Voronoi Diagram Basic Viewer")
{ {
@ -469,7 +468,7 @@ void draw(const CGAL_VORONOI_TYPE &av2,
/// [Keypress] /// [Keypress]
return true; return true;
}; };
draw_buffer(buffer, VoronoiKeyPressEvent); draw_buffer(buffer, VoronoiKeyPressEvent, title);
} }