1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
|
// Copyright (c) 2018-2022 GeometryFactory (France)
// All rights reserved.
//
// This file is part of CGAL (www.cgal.org).
//
// $URL: https://github.com/CGAL/cgal/blob/v6.1.1/BGL/include/CGAL/draw_face_graph.h $
// $Id: include/CGAL/draw_face_graph.h 08b27d3db14 $
// SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial
//
// Author(s) : Guillaume Damiand <guillaume.damiand@liris.cnrs.fr>
// Laurent Rineau <laurent.rineau@cgal.org>
// Mostafa Ashraf <mostaphaashraf1996@gmail.com>
#ifndef CGAL_DRAW_FACE_GRAPH_H
#define CGAL_DRAW_FACE_GRAPH_H
#include <CGAL/Graphics_scene.h>
#include <CGAL/Graphics_scene_options.h>
#include <CGAL/Dynamic_property_map.h>
#include <CGAL/Random.h>
#include <CGAL/boost/graph/helpers.h>
namespace CGAL {
namespace draw_function_for_FG {
template <typename FG, typename GSOptions>
void compute_elements(const FG &fg,
CGAL::Graphics_scene &graphics_scene,
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;
using Vector = typename Kernel::Vector_3;
auto vnormals = get(CGAL::dynamic_vertex_property_t<Vector>(), 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, fg), fg))
{
if (!is_border(h, fg))
{
Vector ni = CGAL::cross_product(
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;
}
}
}
put(vnormals, v, n / i);
}
if (gs_options.are_faces_enabled())
{
for (auto fh : faces(fg))
{
if (fh != boost::graph_traits<FG>::null_face() && // face exists
gs_options.draw_face(fg, fh)) // face is drawn
{
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
{
auto v = source(hd, fg);
graphics_scene.add_point_in_face(get(point_pmap, v), get(vnormals, v));
hd = next(hd, fg);
}
while (hd != first_hd);
graphics_scene.face_end();
}
}
}
if(gs_options.are_edges_enabled())
{
for (auto e : edges(fg))
{
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)),
gs_options.edge_color(fg, e));
}
else
{
graphics_scene.add_segment(get(point_pmap, source(halfedge(e, fg), fg)),
get(point_pmap, target(halfedge(e, fg), fg)));
}
}
}
if(gs_options.are_vertices_enabled())
{
for (auto v : vertices(fg))
{
if(gs_options.colored_vertex(fg, v)) // vertex is colored
{
graphics_scene.add_point(get(point_pmap, v),
gs_options.vertex_color(fg, v));
}
else
{
graphics_scene.add_point(get(point_pmap, v));
}
}
}
}
} // draw_function_for_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)
{
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)
{
Graphics_scene_options<FG,
typename boost::graph_traits<FG>::vertex_descriptor,
typename boost::graph_traits<FG>::edge_descriptor,
typename boost::graph_traits<FG>::face_descriptor>
gs_options;
gs_options.colored_face = [](const FG&,
typename boost::graph_traits<FG>::face_descriptor) -> bool
{ return true; };
gs_options.face_color = [] (const FG&,
typename boost::graph_traits<FG>::face_descriptor fh) -> CGAL::IO::Color
{
if (fh==boost::graph_traits<FG>::null_face())
{ return CGAL::IO::Color(100, 125, 200); }
return get_random_color(CGAL::get_default_random());
};
add_to_graphics_scene_for_fg(fg, graphics_scene, gs_options);
}
} // End namespace CGAL
#endif // CGAL_DRAW_SURFACE_MESH_H
|