mirror of https://github.com/CGAL/cgal
Update lcc viewer with path to deal with Surface mesh and Polyhedron
This commit is contained in:
parent
260b3e54e3
commit
afa2417c16
|
|
@ -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<HEG>::vertex_descriptor vertex_descriptor;
|
||||
typedef typename boost::graph_traits<HEG>::edge_descriptor edge_descriptor;
|
||||
|
|
@ -826,6 +827,49 @@ protected:
|
|||
storage_type m_map;
|
||||
};
|
||||
|
||||
template<class Mesh_>
|
||||
struct Get_traits
|
||||
{
|
||||
typedef Mesh_ Mesh;
|
||||
typedef typename Mesh::Traits Kernel;
|
||||
typedef typename Mesh::Point Point;
|
||||
typedef typename Mesh::Vector Vector;
|
||||
|
||||
template<class Dart_handle>
|
||||
static const Point& get_point(const Mesh& m, Dart_handle dh)
|
||||
{ return m.point(dh); }
|
||||
};
|
||||
|
||||
template<class P>
|
||||
struct Get_traits<CGAL::Surface_mesh<P> >
|
||||
{
|
||||
typedef CGAL::Surface_mesh<P> Mesh;
|
||||
typedef typename CGAL::Kernel_traits<P>::Kernel Kernel;
|
||||
typedef typename Kernel::Point_3 Point;
|
||||
typedef typename Kernel::Vector_3 Vector;
|
||||
|
||||
template<class Dart_handle>
|
||||
static const Point& get_point(const Mesh& m, Dart_handle dh)
|
||||
{ return m.point(m.source(dh)); }
|
||||
};
|
||||
|
||||
template<class PolyhedronTraits_3,
|
||||
class PolyhedronItems_3,
|
||||
template<class T, class I, class A> class T_HDS,
|
||||
class Alloc>
|
||||
struct Get_traits<CGAL::Polyhedron_3<PolyhedronTraits_3,
|
||||
PolyhedronItems_3, T_HDS, Alloc> >
|
||||
{
|
||||
typedef CGAL::Polyhedron_3<PolyhedronTraits_3, PolyhedronItems_3, T_HDS, Alloc> Mesh;
|
||||
typedef PolyhedronTraits_3 Kernel;
|
||||
typedef typename Kernel::Point_3 Point;
|
||||
typedef typename Kernel::Vector_3 Vector;
|
||||
|
||||
template<class Dart_handle>
|
||||
static const Point& get_point(const Mesh& /*m*/, Dart_handle dh)
|
||||
{ return dh->vertex()->point(); }
|
||||
};
|
||||
|
||||
} // Namespace CGAL
|
||||
|
||||
#endif // CGAL_FACE_GRAPH_WRAPPER_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<class Mesh, class Kernel>
|
||||
struct LCC_geom_utils<CGAL::Face_graph_wrapper<Mesh>, Kernel, 3>
|
||||
{
|
||||
static typename Kernel::Vector_3
|
||||
get_vertex_normal(const CGAL::Face_graph_wrapper<Mesh>& mesh,
|
||||
typename CGAL::Face_graph_wrapper<Mesh>::Dart_const_handle dh)
|
||||
{
|
||||
typename Kernel::Vector_3 n; // TODO =
|
||||
// we can use mesh.get_fg() to retreine the initial mesh
|
||||
//internal::Geom_utils<typename LCC::Traits>::
|
||||
//get_local_vector(CGAL::compute_normal_of_cell_0<LCC>(lcc,dh));
|
||||
n = n/(CGAL::sqrt(n*n));
|
||||
return n;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
// Viewer class for LCC with paths.
|
||||
template<class Mesh, class DrawingFunctorLCC>
|
||||
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<Mesh, Mesh>::type LCC;
|
||||
typedef typename LCC::Dart_const_handle Dart_const_handle;
|
||||
typedef typename CGAL::Kernel_traits<typename LCC::Point_3>::Kernel Kernel;
|
||||
typedef typename Kernel::Point_3 Point;
|
||||
typedef typename Kernel::Vector_3 Vector;
|
||||
|
||||
typedef typename CGAL::Get_traits<Mesh>::Kernel Kernel;
|
||||
typedef typename CGAL::Get_traits<Mesh>::Point Point;
|
||||
typedef typename CGAL::Get_traits<Mesh>::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<Path_on_surface<LCC> >* paths=NULL,
|
||||
const std::vector<Path_on_surface<Mesh> >* 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<Mesh>::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<LCC, Local_kernel>::
|
||||
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<LCC, LCC>::storage_type lcc;
|
||||
const Mesh& mesh;
|
||||
const typename Get_map<Mesh, Mesh>::storage_type lcc;
|
||||
bool m_nofaces;
|
||||
const DrawingFunctorLCC& m_drawing_functor;
|
||||
const std::vector<Path_on_surface<LCC> >* m_paths;
|
||||
const std::vector<Path_on_surface<Mesh> >* 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<class LCC, class DrawingFunctor>
|
||||
void draw(const LCC& alcc,
|
||||
const std::vector<Path_on_surface<LCC> >& paths,
|
||||
const char* title="LCC Viewer",
|
||||
template<class Mesh, class DrawingFunctor>
|
||||
void draw(const Mesh& alcc,
|
||||
const std::vector<Path_on_surface<Mesh> >& 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<char**>(argv));
|
||||
LCC_with_path_viewer<LCC, DrawingFunctor> mainwindow(app.activeWindow(),
|
||||
alcc, &paths, amark,
|
||||
title, nofill,
|
||||
drawing_functor);
|
||||
LCC_with_path_viewer<Mesh, DrawingFunctor> mainwindow(app.activeWindow(),
|
||||
alcc, &paths, amark,
|
||||
title, nofill,
|
||||
drawing_functor);
|
||||
mainwindow.show();
|
||||
app.exec();
|
||||
}
|
||||
}
|
||||
|
||||
template<class LCC>
|
||||
void draw(const LCC& alcc,
|
||||
const std::vector<Path_on_surface<LCC> >& paths,
|
||||
template<class Mesh>
|
||||
void draw(const Mesh& alcc,
|
||||
const std::vector<Path_on_surface<Mesh> >& paths,
|
||||
const char* title="LCC Viewer",
|
||||
std::size_t amark=-1,
|
||||
bool nofill=false)
|
||||
{
|
||||
DefaultDrawingFunctorLCC f;
|
||||
return draw<LCC, DefaultDrawingFunctorLCC>(alcc, paths, title,
|
||||
amark, nofill, f);
|
||||
return draw<Mesh, DefaultDrawingFunctorLCC>(alcc, paths, title,
|
||||
amark, nofill, f);
|
||||
}
|
||||
|
||||
} // End namespace CGAL
|
||||
|
|
|
|||
Loading…
Reference in New Issue