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 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322
|
// Copyright (c) 2018 CNRS and LIRIS' Establishments (France).
// All rights reserved.
//
// This file is part of CGAL (www.cgal.org)
//
// $URL: https://github.com/CGAL/cgal/blob/v6.1/Linear_cell_complex/include/CGAL/draw_linear_cell_complex.h $
// $Id: include/CGAL/draw_linear_cell_complex.h b26b07a1242 $
// SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial
//
// Author(s) : Guillaume Damiand <guillaume.damiand@liris.cnrs.fr>
// Mostafa Ashraf <mostaphaashraf1996@gmail.com>
#ifndef CGAL_DRAW_LCC_H
#define CGAL_DRAW_LCC_H
#include <CGAL/Basic_viewer.h>
#include <CGAL/Graphics_scene.h>
#include <CGAL/Graphics_scene_options.h>
#include <CGAL/Linear_cell_complex_base.h>
#include <CGAL/Linear_cell_complex_operations.h>
#include <CGAL/Random.h>
namespace CGAL {
namespace draw_function_for_lcc
{
typedef CGAL::Exact_predicates_inexact_constructions_kernel Local_kernel;
typedef Local_kernel::Point_3 Local_point;
typedef Local_kernel::Vector_3 Local_vector;
template <class LCC, class Local_kernel, int dim = LCC::ambient_dimension>
struct LCC_geom_utils;
template <class LCC, class Local_kernel>
struct LCC_geom_utils<LCC, Local_kernel, 3>
{
static typename Local_kernel::Vector_3
get_vertex_normal(const LCC& lcc, typename LCC::Dart_const_descriptor dh)
{
typename Local_kernel::Vector_3 n =
internal::Geom_utils<typename LCC::Traits, Local_kernel>::
get_local_vector(CGAL::compute_normal_of_cell_0<LCC>(lcc, dh));
n = n / (CGAL::sqrt(n * n));
return n;
}
};
template <class LCC, class Local_kernel>
struct LCC_geom_utils<LCC, Local_kernel, 2>
{
static typename Local_kernel::Vector_3
get_vertex_normal(const LCC&, typename LCC::Dart_const_descriptor)
{
typename Local_kernel::Vector_3 n=CGAL::NULL_VECTOR;
return n;
}
};
template <class LCC, class GSOptionsLCC>
void compute_face(const LCC& lcc,
typename LCC::Dart_const_handle dh,
typename LCC::Dart_const_handle voldh,
CGAL::Graphics_scene& graphics_scene,
const GSOptionsLCC& gso)
{
if(!gso.are_faces_enabled() || !gso.draw_face(lcc, dh))
{ return; }
// We fill only closed faces.
typename LCC::Dart_const_handle cur=dh;
do
{
if (!lcc.is_next_exist(cur))
{ return; } // open face=>not filled
cur = lcc.next(cur);
}
while (cur!=dh);
if (gso.colored_volume(lcc, voldh))
{ graphics_scene.face_begin(gso.volume_color(lcc, voldh)); }
else if (gso.colored_face(lcc, dh))
{ graphics_scene.face_begin(gso.face_color(lcc, dh)); }
else
{ graphics_scene.face_begin(); }
cur=dh;
do
{
graphics_scene.add_point_in_face
(lcc.point(cur),
LCC_geom_utils<LCC, Local_kernel>::get_vertex_normal(lcc, cur));
cur=lcc.next(cur);
}
while (cur!=dh);
graphics_scene.face_end();
}
template <class LCC, class GSOptions>
void compute_edge(const LCC& lcc,
typename LCC::Dart_const_handle dh,
CGAL::Graphics_scene& graphics_scene,
const GSOptions& gso)
{
if(!gso.are_edges_enabled() || !gso.draw_edge(lcc, dh))
{ return; }
const typename LCC::Point& p1=lcc.point(dh);
typename LCC::Dart_const_handle d2=lcc.other_extremity(dh);
if (d2!=LCC::null_descriptor)
{
if (gso.colored_edge(lcc, dh))
{
graphics_scene.add_segment(p1, lcc.point(d2),
gso.edge_color(lcc, dh));
}
else
{ graphics_scene.add_segment(p1, lcc.point(d2)); }
}
}
template <class LCC, class GSOptionsLCC>
void compute_vertex(const LCC& lcc,
typename LCC::Dart_const_handle dh,
CGAL::Graphics_scene& graphics_scene,
const GSOptionsLCC& gso)
{
if (!gso.are_vertices_enabled() || !gso.draw_vertex(lcc, dh))
{ return; }
if (gso.colored_vertex(lcc, dh))
{
graphics_scene.add_point(lcc.point(dh),
gso.vertex_color(lcc, dh));
}
else
{ graphics_scene.add_point(lcc.point(dh)); }
}
template<class LCC, unsigned int d=LCC::dimension>
struct Test_opposite_draw_lcc
{
template<class GSOptions>
static bool run(const LCC& lcc, const GSOptions& gso,
typename LCC::Dart_const_descriptor dh)
{ return (!lcc.template is_free<3>(dh) &&
!gso.volume_wireframe(lcc, lcc.template opposite<3>(dh))); }
};
template<class LCC>
struct Test_opposite_draw_lcc<LCC, 2>
{
template<class GSOptions>
static bool run(const LCC&, const GSOptions&,
typename LCC::Dart_const_descriptor)
{ return true; }
};
template <class LCC, class GSOptions>
void compute_elements(const LCC& lcc,
CGAL::Graphics_scene& graphics_scene,
const GSOptions& gso)
{
typename LCC::size_type markvolumes = lcc.get_new_mark();
typename LCC::size_type markfaces = lcc.get_new_mark();
typename LCC::size_type markedges = lcc.get_new_mark();
typename LCC::size_type markvertices = lcc.get_new_mark();
typename LCC::size_type oriented_mark = lcc.get_new_mark();
lcc.orient(oriented_mark);
for(typename LCC::Dart_range::const_iterator it=lcc.darts().begin(),
itend=lcc.darts().end(); it!=itend; ++it)
{
if (!lcc.is_marked(it, markvolumes) &&
gso.draw_volume(lcc, it))
{
for(typename LCC::template Dart_of_cell_basic_range<3>::const_iterator
itv=lcc.template darts_of_cell_basic<3>(it, markvolumes).begin(),
itvend=lcc.template darts_of_cell_basic<3>(it, markvolumes).end();
itv!=itvend; ++itv)
{
lcc.mark(itv, markvolumes);
if (!lcc.is_marked(itv, markfaces) &&
lcc.is_marked(itv, oriented_mark) &&
gso.draw_face(lcc, itv))
{
if ((!gso.volume_wireframe(lcc, itv) ||
Test_opposite_draw_lcc<LCC>::run(lcc, gso, itv)) &&
!gso.face_wireframe(lcc, itv))
{ compute_face(lcc, itv, it, graphics_scene, gso); }
for(typename LCC::template Dart_of_cell_basic_range<2>::const_iterator
itf=lcc.template darts_of_cell_basic<2>(itv, markfaces).begin(),
itfend=lcc.template darts_of_cell_basic<2>(itv, markfaces).end();
itf!=itfend; ++itf)
{
lcc.mark(itf, markfaces);
if (!lcc.is_marked(itf, markedges) &&
gso.draw_edge(lcc, itf))
{
compute_edge(lcc, itf, graphics_scene, gso);
for(typename LCC::template Dart_of_cell_basic_range<1>::const_iterator
ite=lcc.template darts_of_cell_basic<1>(itf, markedges).begin(),
iteend=lcc.template darts_of_cell_basic<1>(itf, markedges).end();
ite!=iteend; ++ite)
{
lcc.mark(ite, markedges);
if (!lcc.is_marked(ite, markvertices) &&
gso.draw_vertex(lcc, ite))
{
compute_vertex(lcc, ite, graphics_scene, gso);
CGAL::mark_cell<LCC, 0>(lcc, ite, markvertices);
}
}
}
}
}
}
}
}
for (typename LCC::Dart_range::const_iterator it = lcc.darts().begin(),
itend = lcc.darts().end(); it != itend; ++it)
{
lcc.unmark(it, markvertices);
lcc.unmark(it, markedges);
lcc.unmark(it, markfaces);
lcc.unmark(it, markvolumes);
lcc.unmark(it, oriented_mark);
}
lcc.free_mark(markvolumes);
lcc.free_mark(markfaces);
lcc.free_mark(markedges);
lcc.free_mark(markvertices);
lcc.free_mark(oriented_mark);
}
} // namespace draw_function_for_lcc
#define CGAL_LCC_TYPE \
CGAL::Linear_cell_complex_base<d_, ambient_dim, Traits_, Items_, Alloc_, \
Map, Refs, Storage_>
// add_to_graphics_scene: to add a LCC in the given graphic buffer, with a
// graphics scene options.
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_,
class GSOptions>
void add_to_graphics_scene(const CGAL_LCC_TYPE& alcc,
CGAL::Graphics_scene& graphics_scene,
const GSOptions& gso)
{
draw_function_for_lcc::compute_elements(static_cast<const Refs&>(alcc),
graphics_scene, gso);
}
// add_to_graphics_scene: to add a LCC in the given graphic buffer, without a
// graphics scene options. 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_>
void add_to_graphics_scene(const CGAL_LCC_TYPE& alcc,
CGAL::Graphics_scene& graphics_scene)
{
CGAL::Graphics_scene_options<CGAL_LCC_TYPE,
typename CGAL_LCC_TYPE::Dart_const_handle,
typename CGAL_LCC_TYPE::Dart_const_handle,
typename CGAL_LCC_TYPE::Dart_const_handle,
typename CGAL_LCC_TYPE::Dart_const_handle>
gso;
gso.colored_volume = [](const CGAL_LCC_TYPE&,
typename CGAL_LCC_TYPE::Dart_const_handle) -> bool
{ return true; };
gso.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);
};
add_to_graphics_scene(alcc, graphics_scene, gso);
}
// Specialization of draw function for a LCC, with a drawing graphics scene options.
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_,
class GSOptions>
void draw(const CGAL_LCC_TYPE& alcc, const GSOptions& gso,
const char *title="LCC Basic Viewer")
{
CGAL::Graphics_scene buffer;
add_to_graphics_scene(alcc, buffer, gso);
draw_graphics_scene(buffer, title);
}
// Specialization of draw function for a LCC, without a graphics scene options.
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_>
void draw(const CGAL_LCC_TYPE& alcc, const char *title="LCC Basic Viewer")
{
CGAL::Graphics_scene buffer;
add_to_graphics_scene(alcc, buffer);
draw_graphics_scene(buffer, title);
}
#undef CGAL_LCC_TYPE
} // End namespace CGAL
#endif // CGAL_DRAW_LCC_H
|