Update drawing functor and lcc demo

This commit is contained in:
Guillaume Damiand 2022-09-12 15:42:07 +02:00
parent 6076849ea5
commit 974a4accf1
4 changed files with 238 additions and 423 deletions

View File

@ -17,26 +17,37 @@
Viewer::Viewer(QWidget *parent) Viewer::Viewer(QWidget *parent)
: Base(parent, m_graphic_buffer, ""), : Base(parent, m_graphic_buffer, ""),
m_nofaces_(false), m_random_face_color_(false), m_previous_scene_empty(true)
m_previous_scene_empty(true) {} {
m_drawing_functor.volume_color=[](const LCC & alcc,
Dart_const_handle dh)->CGAL::IO::Color
{ return alcc.template info<3>(dh).color(); };
void Viewer::setScene(Scene *scene_, bool doredraw) { m_drawing_functor.colored_volume=[](const LCC &, Dart_const_handle)->bool
scene = scene_; { return true; };
if (scene->lcc != nullptr) { m_drawing_functor.draw_volume=[](const LCC & alcc, Dart_const_handle dh)->bool
CGAL::add_in_graphic_buffer_lcc(gBuffer, m_drawing_functor_, scene->lcc, m_nofaces_, { return alcc.template info<3>(dh).is_visible(); };
m_random_face_color_);
}
if (doredraw) { m_drawing_functor.volume_wireframe=[](const LCC& alcc, Dart_const_handle dh)->bool
Base::redraw(); { return !(alcc.template info<3>(dh).is_filled()); };
}
} }
void Viewer::sceneChanged() { void Viewer::setScene(Scene *scene_, bool doredraw)
{
scene = scene_;
if (scene->lcc!=nullptr)
{ CGAL::add_in_graphic_buffer_lcc(gBuffer, m_drawing_functor, scene->lcc); }
if (doredraw)
{ Base::redraw(); }
}
void Viewer::sceneChanged()
{
gBuffer.clear(); gBuffer.clear();
CGAL::add_in_graphic_buffer_lcc(gBuffer, m_drawing_functor_, scene->lcc, CGAL::add_in_graphic_buffer_lcc(gBuffer, m_drawing_functor, scene->lcc);
m_nofaces_, m_random_face_color_);
this->camera()->setSceneBoundingBox( this->camera()->setSceneBoundingBox(
CGAL::qglviewer::Vec(gBuffer.get_bounding_box().xmin(), CGAL::qglviewer::Vec(gBuffer.get_bounding_box().xmin(),
@ -46,15 +57,14 @@ void Viewer::sceneChanged() {
gBuffer.get_bounding_box().ymax(), gBuffer.get_bounding_box().ymax(),
gBuffer.get_bounding_box().zmax())); gBuffer.get_bounding_box().zmax()));
Base::redraw(); Base::redraw();
if (m_previous_scene_empty) { if (m_previous_scene_empty)
this->showEntireScene(); { this->showEntireScene(); }
}
m_previous_scene_empty = m_previous_scene_empty=scene->lcc->is_empty(); // for the next call to sceneChanged
scene->lcc->is_empty(); // for the next call to sceneChanged
} }
void Viewer::keyPressEvent(QKeyEvent *e) { void Viewer::keyPressEvent(QKeyEvent *e)
{
// const Qt::KeyboardModifiers modifiers = e->modifiers(); // const Qt::KeyboardModifiers modifiers = e->modifiers();
Base::keyPressEvent(e); Base::keyPressEvent(e);
} }

View File

@ -21,93 +21,6 @@
#include <CGAL/draw_linear_cell_complex.h> #include <CGAL/draw_linear_cell_complex.h>
#include <CGAL/Qt/Basic_viewer_qt.h> #include <CGAL/Qt/Basic_viewer_qt.h>
// Functor used by SimpleLCCViewerQt to colorize of not elements.
struct MyDrawingFunctorLCC
{
/// @return true iff the volume containing dh is drawn.
template<typename LCC>
bool draw_volume(const LCC& alcc,
typename LCC::Dart_const_handle dh) const
{ return alcc.template info<3>(dh).is_visible(); }
/// @return true iff the face containing dh is drawn.
template<typename LCC>
bool draw_face(const LCC&,
typename LCC::Dart_const_handle) const
{ return true; }
/// @return true iff the edge containing dh is drawn.
template<typename LCC>
bool draw_edge(const LCC&,
typename LCC::Dart_const_handle) const
{ return true; }
/// @return true iff the vertex containing dh is drawn.
template<typename LCC>
bool draw_vertex(const LCC&,
typename LCC::Dart_const_handle) const
{ return true; }
/// @return true iff the volume containing dh is drawn in wireframe.
template<typename LCC>
bool volume_wireframe(const LCC& alcc,
typename LCC::Dart_const_handle dh) const
{ return !(alcc.template info<3>(dh).is_filled()); }
/// @return true iff the face containing dh is drawn in wireframe.
template<typename LCC>
bool face_wireframe(const LCC&,
typename LCC::Dart_const_handle) const
{ return false; }
/// @return true iff the volume containing dh is colored.
template<typename LCC>
bool colored_volume(const LCC&,
typename LCC::Dart_const_handle) const
{ return true; }
/// @return true iff the face containing dh is colored.
/// if we have also colored_volume(alcc, dh), the volume color is
/// ignored and only the face color is considered.
template<typename LCC>
bool colored_face(const LCC&,
typename LCC::Dart_const_handle) const
{ return false; }
/// @return true iff the edge containing dh is colored.
template<typename LCC>
bool colored_edge(const LCC&,
typename LCC::Dart_const_handle) const
{ return false; }
/// @return true iff the vertex containing dh is colored.
template<typename LCC>
bool colored_vertex(const LCC&,
typename LCC::Dart_const_handle) const
{ return false; }
/// @return the color of the volume containing dh
/// used only if colored_volume(alcc, dh) and !colored_face(alcc, dh)
template<typename LCC>
CGAL::IO::Color volume_color(const LCC& alcc,
typename LCC::Dart_const_handle dh) const
{ return alcc.template info<3>(dh).color(); }
/// @return the color of the face containing dh
/// used only if colored_face(alcc, dh)
template<typename LCC>
CGAL::IO::Color face_color(const LCC& alcc,
typename LCC::Dart_const_handle dh) const
{
CGAL::Random random((unsigned int)(alcc.darts().index(dh)));
return get_random_color(random);
}
/// @return the color of the edge containing dh
/// used only if colored_edge(alcc, dh)
template<typename LCC>
CGAL::IO::Color edge_color(const LCC&,
typename LCC::Dart_const_handle) const
{ return CGAL::IO::Color(0, 0, 0); }
/// @return the color of the vertex containing dh
/// used only if colored_vertex(alcc, dh)
template<typename LCC>
CGAL::IO::Color vertex_color(const LCC&,
typename LCC::Dart_const_handle) const
{ return CGAL::IO::Color(0, 0, 0); }
};
class Viewer : public CGAL::Basic_viewer_qt<float> class Viewer : public CGAL::Basic_viewer_qt<float>
{ {
Q_OBJECT Q_OBJECT
@ -124,9 +37,12 @@ public Q_SLOTS:
void sceneChanged(); void sceneChanged();
private: private:
MyDrawingFunctorLCC m_drawing_functor_; CGAL::DefaultDrawingFunctorXWithVolume<LCC,
Dart_const_handle,
Dart_const_handle,
Dart_const_handle,
Dart_const_handle> m_drawing_functor;
CGAL::GraphicBuffer<float> m_graphic_buffer; CGAL::GraphicBuffer<float> m_graphic_buffer;
bool m_nofaces_, m_random_face_color_;
Scene* scene; Scene* scene;
bool m_previous_scene_empty; bool m_previous_scene_empty;
}; };

View File

@ -159,6 +159,7 @@ typedef CGAL::Linear_cell_complex_traits
typedef CGAL::Linear_cell_complex_for_combinatorial_map<3,3,Mytraits,Myitems> LCC; typedef CGAL::Linear_cell_complex_for_combinatorial_map<3,3,Mytraits,Myitems> LCC;
typedef LCC::Dart_handle Dart_handle; typedef LCC::Dart_handle Dart_handle;
typedef LCC::Dart_const_handle Dart_const_handle;
typedef LCC::Vertex_attribute Vertex; typedef LCC::Vertex_attribute Vertex;
typedef LCC::Point Point_3; typedef LCC::Point Point_3;

View File

@ -15,6 +15,7 @@
#include <CGAL/GraphicBuffer.h> #include <CGAL/GraphicBuffer.h>
#include <CGAL/Qt/Basic_viewer_qt.h> #include <CGAL/Qt/Basic_viewer_qt.h>
#include <functional>
#ifdef CGAL_USE_BASIC_VIEWER #ifdef CGAL_USE_BASIC_VIEWER
@ -23,195 +24,94 @@
namespace CGAL { namespace CGAL {
// This functor draws all faces, edges, and vertices.
// Default color functor; user can change it to have its own face color // CGAL::IO::Color face_color(const DS &aVal, face_handle dh) const {
struct DefaultDrawingFunctorLCC { // CGAL::Random random((unsigned int)(aVal.darts().index(dh)));
/// @return true iff the volume containing dh is drawn. // return get_random_color(random);
template <typename LCC> // }
bool draw_volume(const LCC &, typename LCC::Dart_const_handle) const {
return true;
} template <typename DS,
/// @return true iff the face containing dh is drawn. typename vertex_handle,
template <typename LCC> typename edge_handle,
bool draw_face(const LCC &, typename LCC::Dart_const_handle) const { typename face_handle>
return true; struct DefaultDrawingFunctorX
} {
/// @return true iff the edge containing dh is drawn. DefaultDrawingFunctorX(): m_enabled_vertices(true),
template <typename LCC> m_enabled_edges(true),
bool draw_edge(const LCC &, typename LCC::Dart_const_handle) const { m_enabled_faces(true)
return true; {
} draw_vertex=[](const DS &, vertex_handle)->bool { return true; };
/// @return true iff the vertex containing dh is drawn. draw_edge=[](const DS &, edge_handle)->bool { return true; };
template <typename LCC> draw_face=[](const DS &, face_handle)->bool { return true; };
bool draw_vertex(const LCC &, typename LCC::Dart_const_handle) const {
return true; colored_vertex=[](const DS &, vertex_handle)->bool { return false; };
colored_edge=[](const DS &, edge_handle)->bool { return false; };
colored_face=[](const DS &, face_handle)->bool { return false; };
face_wireframe=[](const DS &, face_handle)->bool { return false; };
} }
/// @return true iff the volume containing dh is drawn in wireframe. std::function<bool(const DS &, vertex_handle)> draw_vertex;
template <typename LCC> std::function<bool(const DS &, edge_handle)> draw_edge;
bool volume_wireframe(const LCC &, typename LCC::Dart_const_handle) const { std::function<bool(const DS &, face_handle)> draw_face;
return false;
}
/// @return true iff the face containing dh is drawn in wireframe.
template <typename LCC>
bool face_wireframe(const LCC &, typename LCC::Dart_const_handle) const {
return false;
}
/// @return true iff the volume containing dh is colored. std::function<bool(const DS &, vertex_handle)> colored_vertex;
template <typename LCC> std::function<bool(const DS &, edge_handle)> colored_edge;
bool colored_volume(const LCC &, typename LCC::Dart_const_handle) const { std::function<bool(const DS &, face_handle)> colored_face;
return true;
}
/// @return true iff the face containing dh is colored.
/// if we have also colored_volume(alcc, dh), the volume color is
/// ignored and only the face color is considered.
template <typename LCC>
bool colored_face(const LCC &, typename LCC::Dart_const_handle) const {
return false;
}
/// @return true iff the edge containing dh is colored.
template <typename LCC>
bool colored_edge(const LCC &, typename LCC::Dart_const_handle) const {
return false;
}
/// @return true iff the vertex containing dh is colored.
template <typename LCC>
bool colored_vertex(const LCC &, typename LCC::Dart_const_handle) const {
return false;
}
/// @return the color of the volume containing dh std::function<bool(const DS &, face_handle)> face_wireframe;
/// used only if colored_volume(alcc, dh) and !colored_face(alcc, dh)
template <typename LCC> std::function<CGAL::IO::Color(const DS &, vertex_handle)> vertex_color;
CGAL::IO::Color volume_color(const LCC &alcc, std::function<CGAL::IO::Color(const DS &, edge_handle)> edge_color;
typename LCC::Dart_const_handle dh) const { std::function<CGAL::IO::Color(const DS &, face_handle)> face_color;
CGAL::Random random((unsigned int)(alcc.darts().index(dh)));
return get_random_color(random); void disable_vertices() { m_enabled_vertices=false; }
} void enable_vertices() { m_enabled_vertices=true; }
/// @return the color of the face containing dh bool are_vertices_enabled() const { return m_enabled_vertices; }
/// used only if colored_face(alcc, dh)
template <typename LCC> void disable_edges() { m_enabled_edges=false; }
CGAL::IO::Color face_color(const LCC &alcc, void enable_edges() { m_enabled_edges=true; }
typename LCC::Dart_const_handle dh) const { bool are_edges_enabled() const { return m_enabled_edges; }
CGAL::Random random((unsigned int)(alcc.darts().index(dh)));
return get_random_color(random); void disable_faces() { m_enabled_faces=false; }
} void enable_faces() { m_enabled_faces=true; }
/// @return the color of the edge containing dh bool are_faces_enabled() const { return m_enabled_faces; }
/// used only if colored_edge(alcc, dh)
template <typename LCC> protected:
CGAL::IO::Color edge_color(const LCC &alcc, bool m_enabled_vertices, m_enabled_edges, m_enabled_faces;
typename LCC::Dart_const_handle dh) const {
CGAL::Random random((unsigned int)(alcc.darts().index(dh)));
return get_random_color(random);
}
/// @return the color of the vertex containing dh
/// used only if colored_vertex(alcc, dh)
template <typename LCC>
CGAL::IO::Color vertex_color(const LCC &alcc,
typename LCC::Dart_const_handle dh) const {
CGAL::Random random((unsigned int)(alcc.darts().index(dh)));
return get_random_color(random);
}
}; };
// TODO: these functors will modify a specific face, edge, and vertex. template <typename DS,
struct DefaultDrawingFunctorX { typename vertex_handle,
typename edge_handle,
template <typename DS, typename face_handle, typename edge_handle, typename face_handle,
typename vertex_handle> typename volume_handle>
bool draw_face(const DS &, face_handle handle) const { struct DefaultDrawingFunctorXWithVolume :
return true; public DefaultDrawingFunctorX<DS, vertex_handle, edge_handle, face_handle>
{
DefaultDrawingFunctorXWithVolume() : m_enabled_volumes(true)
{
draw_volume=[](const DS &, volume_handle)->bool { return true; };
colored_volume=[](const DS &, volume_handle)->bool { return false; };
volume_wireframe=[](const DS &, volume_handle)->bool { return false; };
} }
template <typename DS, typename face_handle, typename edge_handle, std::function<bool(const DS &, volume_handle)> draw_volume;
typename vertex_handle> std::function<bool(const DS &, volume_handle)> colored_volume;
bool draw_edge(const DS &, edge_handle handle) const { std::function<bool(const DS &, volume_handle)> volume_wireframe;
return true; std::function<CGAL::IO::Color(const DS &, volume_handle)> volume_color;
}
template <typename DS, typename face_handle, typename edge_handle, void disable_volumes() { m_enabled_volumes=false; }
typename vertex_handle> void enable_volumes() { m_enabled_volumes=true; }
bool draw_vertex(const DS &, vertex_handle handle) const { bool are_volumes_enabled() const { return m_enabled_volumes; }
return true;
}
template <typename DS, typename face_handle, typename edge_handle, protected:
typename vertex_handle> bool m_enabled_volumes;
bool face_wireframe(const DS &, typename DS::Dart_const_handle) const {
return false;
}
template <typename DS, typename face_handle, typename edge_handle,
typename vertex_handle>
bool colored_face(const DS &, face_handle handle) const {
return false;
}
template <typename DS, typename face_handle, typename edge_handle,
typename vertex_handle>
bool colored_edge(const DS &, edge_handle handle) const {
return false;
}
template <typename DS, typename face_handle, typename edge_handle,
typename vertex_handle>
bool colored_vertex(const DS &, vertex_handle handle) const {
return false;
}
template <typename DS, typename face_handle, typename edge_handle,
typename vertex_handle>
CGAL::IO::Color face_color(const DS &aVal, face_handle dh) const {
CGAL::Random random((unsigned int)(aVal.darts().index(dh)));
return get_random_color(random);
}
template <typename DS, typename face_handle, typename edge_handle,
typename vertex_handle>
CGAL::IO::Color edge_color(const DS &aVal, edge_handle dh) const {
CGAL::Random random((unsigned int)(aVal.darts().index(dh)));
return get_random_color(random);
}
template <typename DS, typename face_handle, typename edge_handle,
typename vertex_handle>
CGAL::IO::Color vertex_color(const DS &aVal, vertex_handle dh) const {
CGAL::Random random((unsigned int)(aVal.darts().index(dh)));
return get_random_color(random);
}
}; };
struct DefaultDrawingFunctorXWithVoulume : public DefaultDrawingFunctorX { namespace draw_function_for_lcc
{
template <typename DS, typename face_handle, typename edge_handle,
typename vertex_handle, typename volume_handle>
bool draw_volume(const DS &, volume_handle) const {
return true;
}
template <typename DS, typename face_handle, typename edge_handle,
typename vertex_handle, typename volume_handle>
CGAL::IO::Color volume_color(const DS &aVal,
volume_handle dh) const {
CGAL::Random random((unsigned int)(aVal.darts().index(dh)));
return get_random_color(random);
}
template <typename DS, typename face_handle, typename edge_handle,
typename vertex_handle, typename volume_handle>
bool volume_wireframe(const DS &, volume_handle) const {
return false;
}
template <typename DS, typename face_handle, typename edge_handle,
typename vertex_handle, typename volume_handle>
bool colored_volume(const DS &, volume_handle) const {
return true;
}
};
namespace draw_function {
typedef CGAL::Exact_predicates_inexact_constructions_kernel Local_kernel; typedef CGAL::Exact_predicates_inexact_constructions_kernel Local_kernel;
typedef Local_kernel::Point_3 Local_point; typedef Local_kernel::Point_3 Local_point;
@ -221,9 +121,11 @@ template <class LCC, class Local_kernel, int dim = LCC::ambient_dimension>
struct LCC_geom_utils; struct LCC_geom_utils;
template <class LCC, class Local_kernel> template <class LCC, class Local_kernel>
struct LCC_geom_utils<LCC, Local_kernel, 3> { struct LCC_geom_utils<LCC, Local_kernel, 3>
{
static typename Local_kernel::Vector_3 static typename Local_kernel::Vector_3
get_vertex_normal(const LCC &lcc, typename LCC::Dart_const_handle dh) { get_vertex_normal(const LCC &lcc, typename LCC::Dart_const_handle dh)
{
typename Local_kernel::Vector_3 n = typename Local_kernel::Vector_3 n =
internal::Geom_utils<typename LCC::Traits, Local_kernel>:: internal::Geom_utils<typename LCC::Traits, Local_kernel>::
get_local_vector(CGAL::compute_normal_of_cell_0<LCC>(lcc, dh)); get_local_vector(CGAL::compute_normal_of_cell_0<LCC>(lcc, dh));
@ -233,110 +135,109 @@ struct LCC_geom_utils<LCC, Local_kernel, 3> {
}; };
template <class LCC, class Local_kernel> template <class LCC, class Local_kernel>
struct LCC_geom_utils<LCC, Local_kernel, 2> { struct LCC_geom_utils<LCC, Local_kernel, 2>
{
static typename Local_kernel::Vector_3 static typename Local_kernel::Vector_3
get_vertex_normal(const LCC &, typename LCC::Dart_const_handle) { get_vertex_normal(const LCC &, typename LCC::Dart_const_handle)
typename Local_kernel::Vector_3 n = CGAL::NULL_VECTOR; {
typename Local_kernel::Vector_3 n=CGAL::NULL_VECTOR;
return n; return n;
} }
}; };
template <typename BufferType = float, class LCC, class DrawingFunctorLCC> template <typename BufferType=float, class LCC, class DrawingFunctorLCC>
void compute_face(typename LCC::Dart_const_handle dh, void compute_face(typename LCC::Dart_const_handle dh,
typename LCC::Dart_const_handle voldh, const LCC *lcc, typename LCC::Dart_const_handle voldh, const LCC *lcc,
bool m_nofaces, bool m_random_face_color,
const DrawingFunctorLCC &m_drawing_functor, const DrawingFunctorLCC &m_drawing_functor,
GraphicBuffer<BufferType> &graphic_buffer) { GraphicBuffer<BufferType> &graphic_buffer)
{
typedef typename LCC::Dart_const_handle Dart_const_handle; if (!m_drawing_functor.are_faces_enabled() ||
typedef typename LCC::Traits Kernel; !m_drawing_functor.draw_face(*lcc, dh))
typedef typename Kernel::Point Point; { return; }
typedef typename Kernel::Vector Vector;
if (m_nofaces || !m_drawing_functor.draw_face(*lcc, dh))
return;
// We fill only closed faces. // We fill only closed faces.
Dart_const_handle cur = dh; typename LCC::Dart_const_handle cur=dh;
Dart_const_handle min = dh; do
do { {
if (!lcc->is_next_exist(cur)) if (!lcc->is_next_exist(cur))
return; // open face=>not filled { return; } // open face=>not filled
if (cur < min)
min = cur;
cur = lcc->next(cur); cur = lcc->next(cur);
} while (cur != dh);
if (m_random_face_color) {
CGAL::Random random((unsigned int)(lcc->darts().index(dh)));
CGAL::IO::Color c = get_random_color(random);
graphic_buffer.face_begin(c);
} else if (m_drawing_functor.colored_face(*lcc, dh)) {
CGAL::IO::Color c = m_drawing_functor.face_color(*lcc, dh);
graphic_buffer.face_begin(c);
} else if (m_drawing_functor.colored_volume(*lcc, voldh)) {
CGAL::IO::Color c = m_drawing_functor.volume_color(*lcc, voldh);
graphic_buffer.face_begin(c);
} else {
graphic_buffer.face_begin();
} }
while (cur!=dh);
cur = dh; if (m_drawing_functor.colored_volume(*lcc, voldh))
do { {
graphic_buffer.add_point_in_face( CGAL::IO::Color c=m_drawing_functor.volume_color(*lcc, voldh);
lcc->point(cur), graphic_buffer.face_begin(c);
}
else if (m_drawing_functor.colored_face(*lcc, dh))
{
CGAL::IO::Color c=m_drawing_functor.face_color(*lcc, dh);
graphic_buffer.face_begin(c);
}
else
{ graphic_buffer.face_begin(); }
cur=dh;
do
{
graphic_buffer.add_point_in_face
(lcc->point(cur),
LCC_geom_utils<LCC, Local_kernel>::get_vertex_normal(*lcc, cur)); LCC_geom_utils<LCC, Local_kernel>::get_vertex_normal(*lcc, cur));
cur = lcc->next(cur); cur=lcc->next(cur);
} while (cur != dh); }
while (cur!=dh);
graphic_buffer.face_end(); graphic_buffer.face_end();
} }
template <typename BufferType = float, class LCC, class DrawingFunctorLCC> template <typename BufferType=float, class LCC, class DrawingFunctor>
void compute_edge(typename LCC::Dart_const_handle dh, const LCC *lcc, void compute_edge(typename LCC::Dart_const_handle dh, const LCC *lcc,
const DrawingFunctorLCC &m_drawing_functor, const DrawingFunctor &m_drawing_functor,
GraphicBuffer<BufferType> &graphic_buffer) { GraphicBuffer<BufferType> &graphic_buffer)
typedef typename LCC::Dart_const_handle Dart_const_handle; {
typedef typename LCC::Traits Kernel; if (!m_drawing_functor.are_edges_enabled() ||
typedef typename Kernel::Point Point; !m_drawing_functor.draw_edge(*lcc, dh))
{ return; }
if (!m_drawing_functor.draw_edge(*lcc, dh)) const typename LCC::Point& p1=lcc->point(dh);
return; typename LCC::Dart_const_handle d2=lcc->other_extremity(dh);
if (d2!=nullptr)
Point p1 = lcc->point(dh); {
Dart_const_handle d2 = lcc->other_extremity(dh); if (m_drawing_functor.colored_edge(*lcc, dh))
if (d2 != nullptr) { {
if (m_drawing_functor.colored_edge(*lcc, dh)) {
graphic_buffer.add_segment(p1, lcc->point(d2), graphic_buffer.add_segment(p1, lcc->point(d2),
m_drawing_functor.edge_color(*lcc, dh)); m_drawing_functor.edge_color(*lcc, dh));
} else {
graphic_buffer.add_segment(p1, lcc->point(d2));
} }
else
{ graphic_buffer.add_segment(p1, lcc->point(d2)); }
} }
} }
template <typename BufferType = float, class LCC, class DrawingFunctorLCC> template <typename BufferType = float, class LCC, class DrawingFunctorLCC>
void compute_vertex(typename LCC::Dart_const_handle dh, const LCC *lcc, void compute_vertex(typename LCC::Dart_const_handle dh, const LCC *lcc,
const DrawingFunctorLCC &m_drawing_functor, const DrawingFunctorLCC &m_drawing_functor,
GraphicBuffer<BufferType> &graphic_buffer) { GraphicBuffer<BufferType> &graphic_buffer)
if (!m_drawing_functor.draw_vertex(*lcc, dh)) {
return; if (!m_drawing_functor.are_vertices_enabled() ||
!m_drawing_functor.draw_vertex(*lcc, dh))
{ return; }
if (m_drawing_functor.colored_vertex(*lcc, dh)) { if (m_drawing_functor.colored_vertex(*lcc, dh))
{
graphic_buffer.add_point(lcc->point(dh), graphic_buffer.add_point(lcc->point(dh),
m_drawing_functor.vertex_color(*lcc, dh)); m_drawing_functor.vertex_color(*lcc, dh));
} else {
graphic_buffer.add_point(lcc->point(dh));
} }
else
{ graphic_buffer.add_point(lcc->point(dh)); }
} }
template <typename BufferType = float, class LCC, class DrawingFunctorLCC> template <typename BufferType = float, class LCC, class DrawingFunctor>
void compute_elements(GraphicBuffer<BufferType> &graphic_buffer, const LCC *lcc, void compute_elements(GraphicBuffer<BufferType> &graphic_buffer, const LCC *lcc,
const DrawingFunctorLCC &m_drawing_functor, const DrawingFunctor &m_drawing_functor)
bool m_nofaces, bool m_random_face_color) { {
if (lcc==nullptr)
if (lcc == nullptr) { return; }
return;
typename LCC::size_type markvolumes = lcc->get_new_mark(); typename LCC::size_type markvolumes = lcc->get_new_mark();
typename LCC::size_type markfaces = lcc->get_new_mark(); typename LCC::size_type markfaces = lcc->get_new_mark();
@ -346,54 +247,44 @@ void compute_elements(GraphicBuffer<BufferType> &graphic_buffer, const LCC *lcc,
lcc->orient(oriented_mark); lcc->orient(oriented_mark);
for (typename LCC::Dart_range::const_iterator it = lcc->darts().begin(), for(typename LCC::Dart_range::const_iterator it=lcc->darts().begin(),
itend = lcc->darts().end(); itend=lcc->darts().end(); it!=itend; ++it)
it != itend; ++it) { {
if (!lcc->is_marked(it, markvolumes) && if (!lcc->is_marked(it, markvolumes) &&
m_drawing_functor.draw_volume(*lcc, it)) { m_drawing_functor.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) for(typename LCC::template Dart_of_cell_basic_range<3>::const_iterator
.begin(), itv=lcc->template darts_of_cell_basic<3>(it, markvolumes).begin(),
itvend = itvend=lcc->template darts_of_cell_basic<3>(it, markvolumes).end();
lcc->template darts_of_cell_basic<3>(it, markvolumes).end(); itv!=itvend; ++itv)
itv != itvend; ++itv) { {
lcc->mark(itv, markvolumes); // To be sure that all darts of the basic lcc->mark(itv, markvolumes);
// iterator will be marked
if (!lcc->is_marked(itv, markfaces) && if (!lcc->is_marked(itv, markfaces) &&
lcc->is_marked(itv, oriented_mark) && lcc->is_marked(itv, oriented_mark) &&
m_drawing_functor.draw_face(*lcc, itv)) { m_drawing_functor.draw_face(*lcc, itv))
{
if (!m_drawing_functor.volume_wireframe(*lcc, itv) && if (!m_drawing_functor.volume_wireframe(*lcc, itv) &&
!m_drawing_functor.face_wireframe(*lcc, itv)) { !m_drawing_functor.face_wireframe(*lcc, itv))
compute_face(itv, it, lcc, m_nofaces, m_random_face_color, { compute_face(itv, it, lcc, m_drawing_functor, graphic_buffer); }
m_drawing_functor, graphic_buffer); for(typename LCC::template Dart_of_cell_basic_range<2>::const_iterator
} itf=lcc->template darts_of_cell_basic<2>(itv, markfaces).begin(),
for (typename LCC::template Dart_of_cell_basic_range< itfend=lcc->template darts_of_cell_basic<2>(itv, markfaces).end();
2>::const_iterator itf!=itfend; ++itf)
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) {
if (!m_drawing_functor.volume_wireframe(*lcc, itv) &&
!m_drawing_functor.face_wireframe(*lcc, itv)) {
lcc->mark(itf, markfaces); lcc->mark(itf, markfaces);
} // To be sure that all darts of the basic iterator will be marked
if (!lcc->is_marked(itf, markedges) && if (!lcc->is_marked(itf, markedges) &&
m_drawing_functor.draw_edge(*lcc, itf)) { m_drawing_functor.draw_edge(*lcc, itf))
{
compute_edge(itf, lcc, m_drawing_functor, graphic_buffer); compute_edge(itf, lcc, m_drawing_functor, graphic_buffer);
for (typename LCC::template Dart_of_cell_basic_range< for(typename LCC::template Dart_of_cell_basic_range<1>::const_iterator
1>::const_iterator ite=lcc->template darts_of_cell_basic<1>(itf, markedges).begin(),
ite = iteend=lcc->template darts_of_cell_basic<1>(itf, markedges).end();
lcc->template darts_of_cell_basic<1>(itf, markedges) ite!=iteend; ++ite)
.begin(), {
iteend = lcc->mark(ite, markedges);
lcc->template darts_of_cell_basic<1>(itf, markedges)
.end();
ite != iteend; ++ite) {
lcc->mark(ite, markedges); // To be sure that all darts of the
// basic iterator will be marked
if (!lcc->is_marked(ite, markvertices) && if (!lcc->is_marked(ite, markvertices) &&
m_drawing_functor.draw_vertex(*lcc, ite)) { m_drawing_functor.draw_vertex(*lcc, ite))
{
compute_vertex(ite, lcc, m_drawing_functor, graphic_buffer); compute_vertex(ite, lcc, m_drawing_functor, graphic_buffer);
CGAL::mark_cell<LCC, 0>(*lcc, ite, markvertices); CGAL::mark_cell<LCC, 0>(*lcc, ite, markvertices);
} }
@ -406,8 +297,8 @@ void compute_elements(GraphicBuffer<BufferType> &graphic_buffer, const LCC *lcc,
} }
for (typename LCC::Dart_range::const_iterator it = lcc->darts().begin(), for (typename LCC::Dart_range::const_iterator it = lcc->darts().begin(),
itend = lcc->darts().end(); itend = lcc->darts().end(); it != itend; ++it)
it != itend; ++it) { {
lcc->unmark(it, markvertices); lcc->unmark(it, markvertices);
lcc->unmark(it, markedges); lcc->unmark(it, markedges);
lcc->unmark(it, markfaces); lcc->unmark(it, markfaces);
@ -431,17 +322,15 @@ void compute_elements(GraphicBuffer<BufferType> &graphic_buffer, const LCC *lcc,
* @param graphic_buffer * @param graphic_buffer
* @param m_drawing_functor * @param m_drawing_functor
* @param alcc * @param alcc
* @param anofaces if true, do not draw faces.
*/ */
template <typename BufferType = float, class LCC, class DrawingFunctorLCC> template <typename BufferType = float, class LCC, class DrawingFunctor>
void add_in_graphic_buffer_lcc(GraphicBuffer<BufferType> &graphic_buffer, void add_in_graphic_buffer_lcc(GraphicBuffer<BufferType> &graphic_buffer,
const DrawingFunctorLCC &m_drawing_functor, const DrawingFunctor &m_drawing_functor,
const LCC *alcc = nullptr, bool nofaces = false, const LCC *alcc = nullptr)
bool m_random_face_color = false) { {
if (alcc!=nullptr)
if (alcc != nullptr) { {
draw_function::compute_elements(graphic_buffer, alcc, m_drawing_functor, draw_function_for_lcc::compute_elements(graphic_buffer, alcc, m_drawing_functor);
nofaces, m_random_face_color);
} }
} }
@ -450,25 +339,24 @@ void add_in_graphic_buffer_lcc(GraphicBuffer<BufferType> &graphic_buffer,
CGAL::Linear_cell_complex_base<d_, ambient_dim, Traits_, Items_, Alloc_, \ CGAL::Linear_cell_complex_base<d_, ambient_dim, Traits_, Items_, Alloc_, \
Map, Refs, Storage_> Map, Refs, Storage_>
template <unsigned int d_, unsigned int ambient_dim, class Traits_, template<unsigned int d_, unsigned int ambient_dim, class Traits_,
class Items_, class Alloc_, class Items_, class Alloc_,
template <unsigned int, class, class, class, class> class Map, template <unsigned int, class, class, class, class> class Map,
class Refs, class Storage_, class Refs, class Storage_,
class DrawingFunctorLCC = DefaultDrawingFunctorLCC> class DrawingFunctor=DefaultDrawingFunctorXWithVolume<CGAL_LCC_TYPE,
// TODO: I'll add it again after done LCC demo. typename CGAL_LCC_TYPE::Dart_const_handle,
// class DrawingFunctorLCC = DefaultDrawingFunctorXWithVoulume> typename CGAL_LCC_TYPE::Dart_const_handle,
typename CGAL_LCC_TYPE::Dart_const_handle,
typename CGAL_LCC_TYPE::Dart_const_handle>>
void draw(const CGAL_LCC_TYPE &alcc, void draw(const CGAL_LCC_TYPE &alcc,
const char *title = "LCC for CMap Basic Viewer", const char *title = "LCC for CMap Basic Viewer",
const DrawingFunctorLCC &drawing_functor = DrawingFunctorLCC()) { const DrawingFunctor &drawing_functor=DrawingFunctor())
// TODO: I'll add it again after done LCC demo. {
// const DrawingFunctorLCC &drawing_functor = DefaultDrawingFunctorXWithVoulume()) {
GraphicBuffer<float> buffer; GraphicBuffer<float> buffer;
add_in_graphic_buffer_lcc(buffer, drawing_functor, &alcc, false); add_in_graphic_buffer_lcc(buffer, drawing_functor, &alcc);
draw_buffer(buffer); draw_buffer(buffer);
} }
// Todo a function taking a const DrawingFunctorLCC& drawing_functor as
// parameter
#undef CGAL_LCC_TYPE #undef CGAL_LCC_TYPE
} // End namespace CGAL } // End namespace CGAL