Skip to content

Commit

Permalink
draw fg with paths (nyf)
Browse files Browse the repository at this point in the history
  • Loading branch information
gdamiand committed Nov 21, 2023
1 parent 0602fd4 commit 1ecfa50
Showing 1 changed file with 53 additions and 60 deletions.
113 changes: 53 additions & 60 deletions Surface_mesh_topology/include/CGAL/draw_face_graph_with_paths.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

#include <CGAL/license/Surface_mesh_topology.h>

#include <CGAL/Qt/Basic_viewer.h>
#include <CGAL/Graphics_scene.h>
#include <CGAL/Graphics_scene_options.h>

Expand All @@ -38,7 +37,7 @@ template <typename DS,
struct Graphics_scene_options_face_graph_with_paths :
public CGAL::Graphics_scene_options<DS, vertex_handle, edge_handle, face_handle>
{
Graphics_scene_options_face_graph_with_paths(std::size_t nbpaths): m_nbpaths(nbpaths)
Graphics_scene_options_face_graph_with_paths()
{
color_of_path=[](std::size_t i)->CGAL::IO::Color
{
Expand All @@ -47,14 +46,11 @@ struct Graphics_scene_options_face_graph_with_paths :
};

draw_path=[](std::size_t)->bool
{ return true; }
{ return true; };
}

std::function<CGAL::IO::Color(std::size_t)> color_of_path;
std::function<bool(std::size_t)> draw_path;

protected:
std::size_t m_nbpaths;
};

namespace draw_function_for_lcc
Expand Down Expand Up @@ -146,9 +142,9 @@ void compute_face(const Mesh& mesh,
const typename Get_map<Mesh, Mesh>::storage_type& lcc,
typename Get_map<Mesh, Mesh>::type::Dart_const_descriptor dh,
CGAL::Graphics_scene& graphics_scene,
GSOptions& gs_options)
GSOptions& gso)
{
if(!gs_options.draw_face(lcc, dh))
if(!gso.draw_face(lcc, dh))
{ return; }

typedef typename Get_map<Mesh, Mesh>::type LCC;
Expand All @@ -170,8 +166,8 @@ void compute_face(const Mesh& mesh,
}
while(cur!=dh);

if(gs_options.colored_face(lcc, dh))
{ graphics_scene.face_begin(gs_options.face_color(lcc, dh)); }
if(gso.colored_face(lcc, dh))
{ graphics_scene.face_begin(gso.face_color(lcc, dh)); }
else
{ graphics_scene.face_begin(); }

Expand All @@ -192,12 +188,12 @@ template <typename Mesh, class GSOptions>
void compute_edge(const Mesh &mesh,
const typename Get_map<Mesh, Mesh>::storage_type& lcc,
typename Get_map<Mesh, Mesh>::type::Dart_const_descriptor dh,
typename Get_map<Mesh, Mesh>::type::size_type aamark,
typename Get_map<Mesh, Mesh>::type::size_type amark,
CGAL::Graphics_scene& graphics_scene,
GSOptions& gs_options,
GSOptions& gso,
bool draw_marked_darts=true)
{
if(!gs_options.draw_edge(lcc, dh))
if(!gso.draw_edge(lcc, dh))
{ return; }

typedef typename Get_map<Mesh, Mesh>::type LCC;
Expand Down Expand Up @@ -242,19 +238,18 @@ template <typename Mesh, class GSOptions>
void compute_vertex(const Mesh &mesh,
typename Get_map<Mesh, Mesh>::type::Dart_const_descriptor dh,
CGAL::Graphics_scene& graphics_scene,
GSOptions& gs_options)
GSOptions& gso)
{
typedef typename CGAL::Get_traits<Mesh>::Kernel Kernel;
typedef typename CGAL::Get_traits<Mesh>::Point Point;
typedef typename CGAL::Get_traits<Mesh>::Vector Vector;
graphics_scene.add_point(get_point(mesh, dh));
if(gso.draw_vertex(mesh, dh))
{ graphics_scene.add_point(get_point(mesh, dh)); }
}

template <typename Mesh>
template <typename Mesh, class GSOptions>
void compute_path(const Mesh &mesh,
const typename Get_map<Mesh, Mesh>::storage_type& lcc,
CGAL::Graphics_scene &graphics_scene,
const std::vector<Surface_mesh_topology::Path_on_surface<Mesh>>* m_paths,
const GSOptions &gso,
const std::vector<Surface_mesh_topology::Path_on_surface<Mesh>>* paths,
std::size_t i,
typename Get_map<Mesh, Mesh>::type::size_type amark)
{
Expand All @@ -263,29 +258,29 @@ void compute_path(const Mesh &mesh,
typedef typename CGAL::Get_traits<Mesh>::Point Point;
typedef typename CGAL::Get_traits<Mesh>::Vector Vector;

if ((*m_paths)[i].is_empty() || !gs_options.draw_path(i))
if ((*paths)[i].is_empty() || !gso.draw_path(i))
{ return; }

CGAL::Random random(static_cast<unsigned int>(i));
CGAL::IO::Color color = get_random_color(random);

graphics_scene.add_point(get_point(mesh, (*m_paths)[i].get_ith_dart(0)), color);
for (std::size_t j=0; j<(*m_paths)[i].length(); ++j)
graphics_scene.add_point(get_point(mesh, (*paths)[i].get_ith_dart(0)), color);
for (std::size_t j=0; j<(*paths)[i].length(); ++j)
{
if ( !lcc.is_marked( (*m_paths)[i].get_ith_dart(j), amark) )
if ( !lcc.is_marked( (*paths)[i].get_ith_dart(j), amark) )
{
compute_edge(mesh, lcc, (*m_paths)[i].get_ith_dart(j), color, mesh, graphics_scene, lcc);
lcc.template mark_cell<1>((*m_paths)[i].get_ith_dart(j), amark);
compute_edge(mesh, lcc, (*paths)[i].get_ith_dart(j), color, graphics_scene);
lcc.template mark_cell<1>((*paths)[i].get_ith_dart(j), amark);
}
}
}

template <class Mesh, class GSOptions>
void compute_elements(const Mesh &mesh,
CGAL::Graphics_scene &graphics_scene,
const GSOptions &m_gs_options,
const std::vector<Surface_mesh_topology::Path_on_surface<Mesh>>* m_paths,
typename Get_map<Mesh, Mesh>::type::size_type amark)
const GSOptions &gso,
const std::vector<Surface_mesh_topology::Path_on_surface<Mesh>>* paths,
typename Get_map<Mesh, Mesh>::type::size_type mark)
{
typedef typename Get_map<Mesh, Mesh>::type LCC;
typedef typename LCC::size_type size_type;
Expand All @@ -295,27 +290,27 @@ void compute_elements(const Mesh &mesh,
typedef typename CGAL::Get_traits<Mesh>::Vector Vector;
typedef typename LCC::Dart_const_descriptor Dart_const_descriptor;

typename Get_map<Mesh, Mesh>::storage_type alcc(mesh);
typename LCC::Dart_range::const_iterator m_current_dart = lcc.darts().end();
typename LCC::size_type m_oriented_mark = lcc.get_new_mark();
std::size_t m_current_path = m_paths->size();
typename LCC::size_type amark=amark==(std::numeric_limits<size_type>::max)()?
LCC::INVALID_MARK:amark; // If !=INVALID_MARK, show darts marked with this mark
typename Get_map<Mesh, Mesh>::storage_type lcc(mesh);
typename LCC::Dart_range::const_iterator current_dart = lcc.darts().end();
typename LCC::size_type oriented_mark = lcc.get_new_mark();
std::size_t current_path = paths->size();
typename LCC::size_type amark=mark==(std::numeric_limits<size_type>::max)()?
LCC::INVALID_MARK:mark; // If !=INVALID_MARK, show darts marked with this mark

lcc.orient(m_oriented_mark);
lcc.orient(oriented_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();

if (m_current_dart!=lcc.darts().end())
/* if (current_dart!=lcc.darts().end())
{ // We want to draw only one dart
Dart_const_descriptor selected_dart=m_current_dart; //lcc.dart_handle(m_current_dart);
Dart_const_descriptor selected_dart=current_dart; //lcc.dart_handle(current_dart);
compute_edge<Mesh>(selected_dart, CGAL::IO::Color(255,0,0), mesh, graphics_scene, lcc);
lcc.template mark_cell<1>(selected_dart, markedges);
compute_vertex<Mesh>(selected_dart, mesh, graphics_scene);
if ( !m_nofaces )
if (gso.are_faces_enabled())
{ compute_face<Mesh>(selected_dart, mesh, graphics_scene, lcc); }
for (typename LCC::Dart_range::const_iterator it=lcc.darts().begin(),
Expand All @@ -328,35 +323,35 @@ void compute_elements(const Mesh &mesh,
}
}
}
else
else */
{
if (m_current_path==m_paths->size())
if (current_path==paths->size())
{
for (std::size_t i=0; i<m_paths->size(); ++i)
{ compute_path<Mesh>(i, markedges, mesh, graphics_scene, m_paths, lcc); }
for (std::size_t i=0; i<paths->size(); ++i)
{ compute_path(mesh, lcc, graphics_scene, gso, paths, i, markedges); }
}
else if (m_current_path!=m_paths->size()+1)
{ compute_path<Mesh>(m_current_path, markedges, mesh, graphics_scene, m_paths, lcc); }
else if (current_path!=paths->size()+1)
{ compute_path(mesh, lcc, graphics_scene, gso, paths, current_path, markedges); }

for (typename LCC::Dart_range::const_iterator it=lcc.darts().begin(),
itend=lcc.darts().end(); it!=itend; ++it )
{
if (!m_nofaces && !lcc.is_marked(it, markfaces) &&
!lcc.is_perforated(it) && lcc.is_marked(it, m_oriented_mark))
if (gso.are_faces_enabled() && !lcc.is_marked(it, markfaces) &&
!lcc.is_perforated(it) && lcc.is_marked(it, oriented_mark))
{
compute_face<Mesh>(it, mesh, graphics_scene, lcc);
compute_face(mesh, lcc, it, graphics_scene, gso);
lcc.template mark_cell<2>(it, markfaces);
}

if ( !lcc.is_marked(it, markedges) )
{
compute_edge<Mesh>(it, mesh, graphics_scene, lcc, amark, draw_marked_darts);
compute_edge(mesh, lcc, it, amark, graphics_scene, gso, draw_marked_darts);
lcc.template mark_cell<1>(it, markedges);
}

if ( !lcc.is_marked(it, markvertices) )
{
compute_vertex<Mesh>(it, mesh, graphics_scene);
compute_vertex(mesh, it, graphics_scene, gso);
lcc.template mark_cell<0>(it, markvertices);
}
}
Expand All @@ -372,15 +367,13 @@ void compute_elements(const Mesh &mesh,
template <class Mesh, class GSOptions>
void add_to_graphics_scene(const Mesh& mesh,
CGAL::Graphics_scene& graphics_scene,
const GSOptions& gso,
const std::vector<Surface_mesh_topology::Path_on_surface<Mesh>>* paths,
const GSOptions& gs_options,
typename Get_map<Mesh, Mesh>::type::size_type amark=
typename Get_map<Mesh, Mesh>::type::INVALID_MARK)
{
draw_function_for_face_graph_with_paths::compute_elements(mesh,
graphics_scene,
gs_options,
paths, amark);
draw_function_for_face_graph_with_paths::compute_elements(mesh, graphics_scene,
gso, paths, amark);
}

template <class Mesh>
Expand All @@ -391,13 +384,13 @@ void add_to_graphics_scene(const Mesh& mesh,
typename Get_map<Mesh, Mesh>::type::INVALID_MARK)
{
// Default graphics view options.
Graphics_scene_options<Mesh,
Graphics_scene_options_face_graph_with_paths<Mesh,
typename Get_map<Mesh, Mesh>::type::Dart_const_descriptor /*vh*/,
typename Get_map<Mesh, Mesh>::type::Dart_const_descriptor /*eh*/,
typename Get_map<Mesh, Mesh>::type::Dart_const_descriptor /*fh*/>
gs_options;
gso;

add_to_graphics_scene(mesh, graphics_scene, gs_options, paths, amark);
add_to_graphics_scene(mesh, graphics_scene, gso, paths, amark);
}

#ifdef CGAL_USE_BASIC_VIEWER
Expand All @@ -417,13 +410,13 @@ void draw(const Mesh& mesh,
template<typename Mesh, typename GSOptions>
void draw(const Mesh& mesh,
const std::vector<Surface_mesh_topology::Path_on_surface<Mesh> >& paths,
const GSOptions& gs_options,
const GSOptions& gso,
typename Get_map<Mesh, Mesh>::type::size_type amark=
(std::numeric_limits<typename Get_map<Mesh, Mesh>::type::size_type>::max)(),
const char* title="Mesh Viewer With Path")
{
CGAL::Graphics_scene buffer;
add_to_graphics_scene(mesh, buffer, gs_options, &paths, amark);
add_to_graphics_scene(mesh, buffer, gso, &paths, amark);
draw_graphics_scene(buffer, title);
}

Expand Down

0 comments on commit 1ecfa50

Please sign in to comment.