From afa2417c16b2ca0eaf884b245e32d5b38c99c9dc Mon Sep 17 00:00:00 2001 From: Guillaume Damiand Date: Thu, 4 Apr 2019 18:47:49 +0200 Subject: [PATCH] Update lcc viewer with path to deal with Surface mesh and Polyhedron --- .../include/CGAL/Face_graph_wrapper.h | 44 ++++++++++ .../include/CGAL/draw_lcc_with_paths.h | 85 ++++++++++++------- 2 files changed, 98 insertions(+), 31 deletions(-) diff --git a/Combinatorial_map/include/CGAL/Face_graph_wrapper.h b/Combinatorial_map/include/CGAL/Face_graph_wrapper.h index 0d92254d153..48d016376b3 100644 --- a/Combinatorial_map/include/CGAL/Face_graph_wrapper.h +++ b/Combinatorial_map/include/CGAL/Face_graph_wrapper.h @@ -68,6 +68,7 @@ public: /// The dimension of the combinatorial map. static const unsigned int dimension=2; + static const unsigned int ambient_dimension=3; typedef typename boost::graph_traits::vertex_descriptor vertex_descriptor; typedef typename boost::graph_traits::edge_descriptor edge_descriptor; @@ -826,6 +827,49 @@ protected: storage_type m_map; }; + template + struct Get_traits + { + typedef Mesh_ Mesh; + typedef typename Mesh::Traits Kernel; + typedef typename Mesh::Point Point; + typedef typename Mesh::Vector Vector; + + template + static const Point& get_point(const Mesh& m, Dart_handle dh) + { return m.point(dh); } + }; + + template + struct Get_traits > + { + typedef CGAL::Surface_mesh

Mesh; + typedef typename CGAL::Kernel_traits

::Kernel Kernel; + typedef typename Kernel::Point_3 Point; + typedef typename Kernel::Vector_3 Vector; + + template + static const Point& get_point(const Mesh& m, Dart_handle dh) + { return m.point(m.source(dh)); } + }; + + template class T_HDS, + class Alloc> + struct Get_traits > + { + typedef CGAL::Polyhedron_3 Mesh; + typedef PolyhedronTraits_3 Kernel; + typedef typename Kernel::Point_3 Point; + typedef typename Kernel::Vector_3 Vector; + + template + static const Point& get_point(const Mesh& /*m*/, Dart_handle dh) + { return dh->vertex()->point(); } + }; + } // Namespace CGAL #endif // CGAL_FACE_GRAPH_WRAPPER_H // diff --git a/Surface_mesh_topology/include/CGAL/draw_lcc_with_paths.h b/Surface_mesh_topology/include/CGAL/draw_lcc_with_paths.h index b3b85510d7f..fba83670446 100644 --- a/Surface_mesh_topology/include/CGAL/draw_lcc_with_paths.h +++ b/Surface_mesh_topology/include/CGAL/draw_lcc_with_paths.h @@ -1,4 +1,4 @@ -// Copyright (c) 2017 CNRS and LIRIS' Establishments (France). +// Copyright (c) 2017 CNRS and LIRIS' Establishments (France). // All rights reserved. // // This file is part of CGAL (www.cgal.org); you can redistribute it and/or @@ -30,6 +30,24 @@ namespace CGAL { +template +struct LCC_geom_utils, Kernel, 3> +{ + static typename Kernel::Vector_3 + get_vertex_normal(const CGAL::Face_graph_wrapper& mesh, + typename CGAL::Face_graph_wrapper::Dart_const_handle dh) + { + typename Kernel::Vector_3 n; // TODO = + // we can use mesh.get_fg() to retreine the initial mesh + //internal::Geom_utils:: + //get_local_vector(CGAL::compute_normal_of_cell_0(lcc,dh)); + n = n/(CGAL::sqrt(n*n)); + return n; + } +}; + + + // Viewer class for LCC with paths. template class LCC_with_path_viewer : public Basic_viewer_qt @@ -37,10 +55,10 @@ class LCC_with_path_viewer : public Basic_viewer_qt typedef Basic_viewer_qt Base; typedef typename Get_map::type LCC; typedef typename LCC::Dart_const_handle Dart_const_handle; - typedef typename CGAL::Kernel_traits::Kernel Kernel; - typedef typename Kernel::Point_3 Point; - typedef typename Kernel::Vector_3 Vector; - + typedef typename CGAL::Get_traits::Kernel Kernel; + typedef typename CGAL::Get_traits::Point Point; + typedef typename CGAL::Get_traits::Vector Vector; + public: /// Construct the viewer. /// @param alcc the lcc to view @@ -49,11 +67,12 @@ public: /// usefull for very big object where this time could be long) LCC_with_path_viewer(QWidget* parent, const Mesh& amesh, - const std::vector >* paths=NULL, + const std::vector >* paths=NULL, std::size_t amark=LCC::INVALID_MARK, const char* title="", bool anofaces=false, const DrawingFunctorLCC& drawing_functor=DrawingFunctorLCC()) : Base(parent, title, true, true, true, false, true), + mesh(amesh), lcc(amesh), m_nofaces(anofaces), m_drawing_functor(drawing_functor), @@ -68,6 +87,9 @@ public: protected: + const Point& get_point(Dart_const_handle dh) const + { return CGAL::Get_traits::get_point(mesh, dh); } + void compute_elements() { clear(); @@ -78,9 +100,9 @@ protected: if (m_current_dart!=lcc.number_of_darts()) { // We want to draw only one dart - Dart_const_handle selected_dart=lcc.darts().iterator_to(lcc.darts()[m_current_dart]); - if (lcc.is_dart_used(selected_dart)) + if (lcc.darts().is_used(m_current_dart)) { + Dart_const_handle selected_dart=lcc.dart_handle(m_current_dart); compute_edge(selected_dart, CGAL::Color(255,0,0)); lcc.template mark_cell<1>(selected_dart, markedges); compute_vertex(selected_dart); @@ -156,7 +178,7 @@ protected: cur=dh; do { - add_point_in_face(lcc.point(cur), + add_point_in_face(get_point(cur), LCC_geom_utils:: get_vertex_normal(lcc, cur)); cur=lcc.next(cur); @@ -168,28 +190,28 @@ protected: void compute_edge(Dart_const_handle dh) { - Point p1 = lcc.point(dh); + Point p1 = get_point(dh); Dart_const_handle d2 = lcc.other_extremity(dh); if (d2!=NULL) { if (m_draw_marked_darts && m_amark!=LCC::INVALID_MARK && (lcc.is_marked(dh, m_amark) || lcc.is_marked(lcc.beta(dh, 2), m_amark))) - { add_segment(p1, lcc.point(d2), CGAL::Color(0, 0, 255)); } + { add_segment(p1, get_point(d2), CGAL::Color(0, 0, 255)); } else - { add_segment(p1, lcc.point(d2)); } + { add_segment(p1, get_point(d2)); } } } void compute_edge(Dart_const_handle dh, const CGAL::Color& color) { - Point p1 = lcc.point(dh); + Point p1 = get_point(dh); Dart_const_handle d2 = lcc.other_extremity(dh); if (d2!=NULL) - { add_segment(p1, lcc.point(d2), color); } + { add_segment(p1, get_point(d2), color); } } void compute_vertex(Dart_const_handle dh) - { add_point(lcc.point(dh)); } + { add_point(get_point(dh)); } virtual void keyPressEvent(QKeyEvent *e) { @@ -262,7 +284,7 @@ protected: CGAL::Random random(i); CGAL::Color color=get_random_color(random); - add_point(lcc.point((*m_paths)[i].get_ith_dart(0)), color); + add_point(get_point((*m_paths)[i].get_ith_dart(0)), color); for (unsigned int j=0; j<(*m_paths)[i].length(); ++j) { if ( !lcc.is_marked( (*m_paths)[i].get_ith_dart(j), amark) ) @@ -274,20 +296,21 @@ protected: } protected: - const typename Get_map::storage_type lcc; + const Mesh& mesh; + const typename Get_map::storage_type lcc; bool m_nofaces; const DrawingFunctorLCC& m_drawing_functor; - const std::vector >* m_paths; + const std::vector >* m_paths; unsigned int m_current_path; unsigned int m_current_dart; bool m_draw_marked_darts; std::size_t m_amark; // If !=INVALID_MARK, show darts marked with this mark }; -template -void draw(const LCC& alcc, - const std::vector >& paths, - const char* title="LCC Viewer", +template +void draw(const Mesh& alcc, + const std::vector >& paths, + const char* title="Mesh Viewer", std::size_t amark=-1, bool nofill=false, const DrawingFunctor& drawing_functor=DrawingFunctor()) @@ -303,25 +326,25 @@ void draw(const LCC& alcc, int argc=1; const char* argv[2]={"lccviewer","\0"}; QApplication app(argc,const_cast(argv)); - LCC_with_path_viewer mainwindow(app.activeWindow(), - alcc, &paths, amark, - title, nofill, - drawing_functor); + LCC_with_path_viewer mainwindow(app.activeWindow(), + alcc, &paths, amark, + title, nofill, + drawing_functor); mainwindow.show(); app.exec(); } } -template -void draw(const LCC& alcc, - const std::vector >& paths, +template +void draw(const Mesh& alcc, + const std::vector >& paths, const char* title="LCC Viewer", std::size_t amark=-1, bool nofill=false) { DefaultDrawingFunctorLCC f; - return draw(alcc, paths, title, - amark, nofill, f); + return draw(alcc, paths, title, + amark, nofill, f); } } // End namespace CGAL