Skip to content

Commit

Permalink
A (last) verification step for all draw functions (nyf).
Browse files Browse the repository at this point in the history
  • Loading branch information
gdamiand committed Nov 30, 2023
1 parent 906f51d commit 90f3a7c
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 33 deletions.
30 changes: 16 additions & 14 deletions BGL/include/CGAL/draw_face_graph.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace draw_function_for_FG {
template <typename FG, typename GSOptions>
void compute_elements(const FG &fg,
CGAL::Graphics_scene &graphics_scene,
const GSOptions &m_gs_options)
const GSOptions &gs_options)
{
using Point=typename boost::property_map_value<FG, CGAL::vertex_point_t>::type;
using Kernel = typename CGAL::Kernel_traits<Point>::Kernel;
Expand Down Expand Up @@ -58,15 +58,17 @@ void compute_elements(const FG &fg,
put(vnormals, v, n / i);
}

if (m_gs_options.are_faces_enabled())
if (gs_options.are_faces_enabled())
{
for (auto fh : faces(fg))
{
if (fh != boost::graph_traits<FG>::null_face() && // face exists
!m_gs_options.face_wireframe(fg, fh) && // face is not wireframe
m_gs_options.colored_face(fg, fh)) // and face is colored
gs_options.draw_face(fg, fh)) // face is drawn
{
graphics_scene.face_begin(m_gs_options.face_color(fg, fh));
if(gs_options.colored_face(fg, fh)) // face is colored
{ graphics_scene.face_begin(gs_options.face_color(fg, fh)); }
else
{ graphics_scene.face_begin(); }
auto hd = halfedge(fh, fg);
const auto first_hd = hd;
do
Expand All @@ -81,15 +83,15 @@ void compute_elements(const FG &fg,
}
}

if(m_gs_options.are_edges_enabled())
if(gs_options.are_edges_enabled())
{
for (auto e : edges(fg))
{
if(m_gs_options.colored_edge(fg, e)) // edge is colored
if(gs_options.colored_edge(fg, e)) // edge is colored
{
graphics_scene.add_segment(get(point_pmap, source(halfedge(e, fg), fg)),
get(point_pmap, target(halfedge(e, fg), fg)),
m_gs_options.edge_color(fg, e));
gs_options.edge_color(fg, e));
}
else
{
Expand All @@ -99,14 +101,14 @@ void compute_elements(const FG &fg,
}
}

if(m_gs_options.are_vertices_enabled())
if(gs_options.are_vertices_enabled())
{
for (auto v : vertices(fg))
{
if(m_gs_options.colored_vertex(fg, v)) // vertex is colored
if(gs_options.colored_vertex(fg, v)) // vertex is colored
{
graphics_scene.add_point(get(point_pmap, v),
m_gs_options.vertex_color(fg, v));
gs_options.vertex_color(fg, v));
}
else
{
Expand All @@ -120,15 +122,15 @@ void compute_elements(const FG &fg,

template <class FG, class GSOptions>
void add_to_graphics_scene_for_fg(const FG &fg,
CGAL::Graphics_scene &graphics_scene,
const GSOptions &gs_options)
CGAL::Graphics_scene &graphics_scene,
const GSOptions &gs_options)
{
draw_function_for_FG::compute_elements(fg, graphics_scene, gs_options);
}

template <class FG>
void add_to_graphics_scene_for_fg(const FG &fg,
CGAL::Graphics_scene &graphics_scene)
CGAL::Graphics_scene &graphics_scene)
{
Graphics_scene_options<FG,
typename boost::graph_traits<FG>::vertex_descriptor,
Expand Down
6 changes: 3 additions & 3 deletions Point_set_3/include/CGAL/draw_point_set_3.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ void compute_elements(const PointSet& pointset,

template <class P, class V, class GSOptions>
void add_to_graphics_scene(const Point_set_3<P, V>& apointset,
Graphics_scene& graphics_scene,
const GSOptions& gs_options)
Graphics_scene& graphics_scene,
const GSOptions& gs_options)
{
draw_function_for_PointSet::compute_elements(apointset,
graphics_scene,
Expand All @@ -80,7 +80,7 @@ void add_to_graphics_scene(const Point_set_3<P, V>& apointset,

template <class P, class V>
void add_to_graphics_scene(const Point_set_3<P, V>& apointset,
Graphics_scene& graphics_scene)
Graphics_scene& graphics_scene)
{
CGAL::Graphics_scene_options<Point_set_3<P, V>,
typename Point_set_3<P, V>::const_iterator,
Expand Down
15 changes: 8 additions & 7 deletions Polygon/include/CGAL/draw_polygon_2.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ void compute_elements(const P2& p2,
if (p2.is_empty())
return;

typename P2::Point_2 prev=p2.vertex(p2.size()-1);

if (gso.are_faces_enabled())
{
if(gso.colored_face(p2, nullptr))
Expand All @@ -64,6 +62,7 @@ void compute_elements(const P2& p2,
{ graphics_scene.face_begin(); }
}

typename P2::Vertex_const_iterator prev=p2.vertices_end(); --prev;
for (typename P2::Vertex_const_iterator i=p2.vertices_begin();
i!=p2.vertices_end(); ++i)
{
Expand All @@ -77,18 +76,18 @@ void compute_elements(const P2& p2,
}

if(gso.are_edges_enabled() &&
gso.draw_edge(p2, i))
gso.draw_edge(p2, prev))
{ // Add edge with previous point
if(gso.colored_edge(p2, i))
{ graphics_scene.add_segment(prev, *i, gso.edge_color(p2, i)); }
if(gso.colored_edge(p2, prev))
{ graphics_scene.add_segment(*prev, *i, gso.edge_color(p2, prev)); }
else
{ graphics_scene.add_segment(prev, *i); }
{ graphics_scene.add_segment(*prev, *i); }
}

if(gso.are_faces_enabled())
{ graphics_scene.add_point_in_face(*i); } // Add point in face

prev = *i;
prev=i;
}

if (gso.are_faces_enabled())
Expand Down Expand Up @@ -141,6 +140,8 @@ void draw(const CGAL_P2_TYPE &ap2,

#endif // CGAL_USE_BASIC_VIEWER

#undef CGAL_P2_TYPE

} // End namespace CGAL

#endif // CGAL_DRAW_POLYGON_2_H
23 changes: 15 additions & 8 deletions Polygon/include/CGAL/draw_polygon_with_holes_2.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,19 +68,18 @@ void compute_one_loop_elements(const P2& ap2,
{
if(gs_options.are_vertices_enabled() &&
gs_options.draw_vertex(ap2, i))
{ // Add vertex
if(gs_options.colored_vertex(ap2, i))
{ // Add vertex
if(gs_options.colored_vertex(ap2, i))
{ graphics_scene.add_point(*i, gs_options.vertex_color(ap2, i)); }
else
{ graphics_scene.add_point(*i); }
}
}

if(i!=aloop.vertices_begin() &&
gs_options.are_edges_enabled() &&
gs_options.draw_edge(ap2, i))
gs_options.are_edges_enabled() && gs_options.draw_edge(ap2, prev))
{ // Add segment with previous point
if(gs_options.colored_vertex(ap2, i))
{ graphics_scene.add_segment(*prev, *i, gs_options.edge_color(ap2, i)); }
if(gs_options.colored_edge(ap2, prev))
{ graphics_scene.add_segment(*prev, *i, gs_options.edge_color(ap2, prev)); }
else
{ graphics_scene.add_segment(*prev, *i); }
}
Expand All @@ -94,7 +93,13 @@ void compute_one_loop_elements(const P2& ap2,
// Add the last segment between the last point and the first one
if(gs_options.are_edges_enabled() &&
gs_options.draw_edge(ap2, aloop.vertices_begin()))
{ graphics_scene.add_segment(*prev, *(aloop.vertices_begin())); }
{
if(gs_options.colored_edge(ap2, prev))
{ graphics_scene.add_segment(*prev, *(aloop.vertices_begin()),
gs_options.edge_color(ap2, prev)); }
else
{ graphics_scene.add_segment(*prev, *(aloop.vertices_begin())); }
}
}

template <class P2, class GSOptions>
Expand Down Expand Up @@ -176,6 +181,8 @@ void draw(const CGAL_P2_WITH_HOLES_TYPE& ap2,

#endif // CGAL_USE_BASIC_VIEWER

#undef CGAL_P2_WITH_HOLES_TYPE

} // End namespace CGAL

#endif // CGAL_DRAW_POLYGON_WITH_HOLES_2_H
2 changes: 1 addition & 1 deletion Surface_mesh/include/CGAL/draw_surface_mesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ template<class K>
void add_to_graphics_scene(const Surface_mesh<K>& amesh,
CGAL::Graphics_scene &graphics_scene)
{ add_to_graphics_scene_for_fg(amesh, graphics_scene,
Graphics_scene_options_surface_mesh<K>(amesh)); }
Graphics_scene_options_surface_mesh<K>(amesh)); }

#ifdef CGAL_USE_BASIC_VIEWER

Expand Down

0 comments on commit 90f3a7c

Please sign in to comment.