draw voronoi 2

This commit is contained in:
Guillaume Damiand 2023-12-04 08:40:28 +01:00
parent 1760fcf3f2
commit 91ecafd004
2 changed files with 58 additions and 46 deletions

View File

@ -23,15 +23,15 @@ int main(int argc, char* argv[])
{ {
VD vd; VD vd;
std::ifstream ifs((argc>1)?argv[1]:"data/data4.dt.cin"); std::ifstream ifs((argc>1)?argv[1]:"data/data4.dt.cin");
assert(ifs); if(ifs)
{
Site_2 t; Site_2 t;
while ( ifs >> t ) { vd.insert(t); } while ( ifs >> t ) { vd.insert(t); }
ifs.close(); ifs.close();
assert( vd.is_valid() ); assert( vd.is_valid() );
CGAL::draw(vd); CGAL::draw(vd);
}
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }

View File

@ -33,16 +33,30 @@ template <typename DS,
typename vertex_handle, typename vertex_handle,
typename edge_handle, typename edge_handle,
typename face_handle> typename face_handle>
struct Graphics_scene_options_voronoi : struct Graphics_scene_options_voronoi_2 :
public CGAL::Graphics_scene_options<DS, vertex_handle, edge_handle, face_handle> public CGAL::Graphics_scene_options<DS, vertex_handle, edge_handle, face_handle>
{ {
Graphics_scene_options_voronoi() : m_draw_voronoi_vertices(true), Graphics_scene_options_voronoi_2() : m_dual_vertex_color(50, 100, 180),
m_draw_dual_vertices(true), m_ray_color(100, 0, 0),
dual_vertex_color(CGAL::IO::Color(50, 100, 180)), m_bisector_color(0, 100, 0),
ray_color(CGAL::IO::Color(100, 0, 0)), m_draw_voronoi_vertices(true),
bisector_color(CGAL::IO::Color(0, 100, 0)) m_draw_dual_vertices(true)
{} {}
const CGAL::IO::Color& dual_vertex_color() const
{ return m_dual_vertex_color; }
const CGAL::IO::Color& ray_color() const
{ return m_ray_color; }
const CGAL::IO::Color& bisector_color() const
{ return m_bisector_color; }
void dual_vertex_color(const CGAL::IO::Color& c)
{ m_dual_vertex_color=c; }
void ray_color(const CGAL::IO::Color& c)
{ m_ray_color=c; }
void bisector_color(const CGAL::IO::Color& c)
{ m_bisector_color=c; }
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; }
@ -53,11 +67,10 @@ struct Graphics_scene_options_voronoi :
bool are_dual_vertices_enabled() const { return m_draw_dual_vertices; } bool are_dual_vertices_enabled() const { return m_draw_dual_vertices; }
void toggle_draw_dual_vertices() { m_draw_dual_vertices=!m_draw_dual_vertices; } void toggle_draw_dual_vertices() { m_draw_dual_vertices=!m_draw_dual_vertices; }
CGAL::IO::Color dual_vertex_color;
CGAL::IO::Color ray_color;
CGAL::IO::Color bisector_color;
protected: protected:
CGAL::IO::Color m_dual_vertex_color;
CGAL::IO::Color m_ray_color;
CGAL::IO::Color m_bisector_color;
bool m_draw_voronoi_vertices; bool m_draw_voronoi_vertices;
bool m_draw_dual_vertices; bool m_draw_dual_vertices;
}; };
@ -89,7 +102,7 @@ void compute_dual_vertex(const V2& /*v2*/,
typename V2::Delaunay_graph::Finite_vertices_iterator vi, typename V2::Delaunay_graph::Finite_vertices_iterator vi,
CGAL::Graphics_scene &graphics_scene, CGAL::Graphics_scene &graphics_scene,
const GSOptions& gs_options) const GSOptions& gs_options)
{ graphics_scene.add_point(vi->point(), gs_options.dual_vertex_color); } { graphics_scene.add_point(vi->point(), gs_options.dual_vertex_color()); }
template <class V2, class GSOptions> template <class V2, class GSOptions>
void add_segments_and_update_bounding_box(const V2& v2, void add_segments_and_update_bounding_box(const V2& v2,
@ -101,6 +114,8 @@ void add_segments_and_update_bounding_box(const V2& v2,
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())
{
if(gs_options.draw_edge(v2, he))
{ {
if(gs_options.colored_edge(v2, he)) if(gs_options.colored_edge(v2, he))
{ {
@ -112,6 +127,7 @@ void add_segments_and_update_bounding_box(const V2& v2,
graphics_scene.add_segment(he->source()->point(), he->target()->point()); graphics_scene.add_segment(he->source()->point(), he->target()->point());
} }
} }
}
else else
{ {
Delaunay_vertex_const_handle v1 = he->up(); Delaunay_vertex_const_handle v1 = he->up();
@ -240,14 +256,14 @@ void compute_rays_and_bisectors(const V2&,
if (he->has_source()) if (he->has_source())
{ {
// add_ray_segment(he->source()->point(), get_second_point(he, graphics_scene.get_bounding_box())); // add_ray_segment(he->source()->point(), get_second_point(he, graphics_scene.get_bounding_box()));
graphics_scene.add_ray(he->source()->point(), direction, gs_options.ray_color); graphics_scene.add_ray(he->source()->point(), direction, gs_options.ray_color());
} }
} }
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);
graphics_scene.add_line(pointOnLine, direction, gs_options.bisector_color); graphics_scene.add_line(pointOnLine, direction, gs_options.bisector_color());
} }
} }
@ -348,7 +364,7 @@ void add_to_graphics_scene(const CGAL_VORONOI_TYPE& v2,
CGAL::Graphics_scene& graphics_scene) CGAL::Graphics_scene& graphics_scene)
{ {
// Default graphics view options. // Default graphics view options.
CGAL::Graphics_scene_options_voronoi<CGAL_VORONOI_TYPE, CGAL::Graphics_scene_options_voronoi_2<CGAL_VORONOI_TYPE,
typename CGAL_VORONOI_TYPE::Vertex_iterator, typename CGAL_VORONOI_TYPE::Vertex_iterator,
typename CGAL_VORONOI_TYPE::Halfedge_iterator, typename CGAL_VORONOI_TYPE::Halfedge_iterator,
typename CGAL_VORONOI_TYPE::Face_iterator> typename CGAL_VORONOI_TYPE::Face_iterator>
@ -362,27 +378,11 @@ void add_to_graphics_scene(const CGAL_VORONOI_TYPE& v2,
// Specialization of draw function. // Specialization of draw function.
template<class DG, class AT, class AP, class GSOptions> template<class DG, class AT, class AP, class GSOptions>
void draw(const CGAL_VORONOI_TYPE& av2, void draw(const CGAL_VORONOI_TYPE& av2,
const GSOptions& gs_options, GSOptions& gs_options,
const char *title="2D Voronoi Diagram Basic Viewer") const char *title="2D Voronoi Diagram Basic Viewer")
{ {
CGAL::Graphics_scene buffer; CGAL::Graphics_scene buffer;
add_to_graphics_scene(av2, buffer, gs_options); add_to_graphics_scene(av2, buffer, gs_options);
draw_graphics_scene(buffer, title);
}
template<class DG, class AT, class AP>
void draw(const CGAL_VORONOI_TYPE& av2,
const char *title="2D Voronoi Diagram Basic Viewer")
{
CGAL::Graphics_scene buffer;
CGAL::Graphics_scene_options_voronoi<CGAL_VORONOI_TYPE,
typename CGAL_VORONOI_TYPE::Vertex_iterator,
typename CGAL_VORONOI_TYPE::Halfedge_iterator,
typename CGAL_VORONOI_TYPE::Face_iterator>
gs_options;
add_to_graphics_scene(av2, buffer, gs_options);
CGAL::Qt::QApplication_and_basic_viewer app(buffer, title); CGAL::Qt::QApplication_and_basic_viewer app(buffer, title);
if(app) if(app)
@ -445,6 +445,18 @@ void draw(const CGAL_VORONOI_TYPE& av2,
} }
} }
template<class DG, class AT, class AP>
void draw(const CGAL_VORONOI_TYPE& av2,
const char *title="2D Voronoi Diagram Basic Viewer")
{
CGAL::Graphics_scene_options_voronoi_2<CGAL_VORONOI_TYPE,
typename CGAL_VORONOI_TYPE::Vertex_iterator,
typename CGAL_VORONOI_TYPE::Halfedge_iterator,
typename CGAL_VORONOI_TYPE::Face_iterator>
gs_options;
draw(av2, gs_options, title);
}
#endif // CGAL_USE_BASIC_VIEWER #endif // CGAL_USE_BASIC_VIEWER
#undef CGAL_VORONOI_TYPE #undef CGAL_VORONOI_TYPE