Skip to content

Commit

Permalink
T2 and CDT2 draw
Browse files Browse the repository at this point in the history
  • Loading branch information
gdamiand committed Dec 1, 2023
1 parent 9abee07 commit 9ea4e75
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 89 deletions.
3 changes: 2 additions & 1 deletion Triangulation_2/examples/Triangulation_2/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ foreach(cppfile ${cppfiles})
endforeach()

if(CGAL_Qt6_FOUND)
target_link_libraries(polygon_triangulation PUBLIC CGAL::CGAL_Basic_viewer)
target_link_libraries(constrained PUBLIC CGAL::CGAL_Basic_viewer)
target_link_libraries(draw_triangulation_2 PUBLIC CGAL::CGAL_Basic_viewer)
target_link_libraries(polygon_triangulation PUBLIC CGAL::CGAL_Basic_viewer)
target_link_libraries(star_conflict_zone PUBLIC CGAL::CGAL_Basic_viewer)
else()
message(STATUS "NOTICE: Several examples require Qt6 and will not be compiled.")
Expand Down
4 changes: 4 additions & 0 deletions Triangulation_2/examples/Triangulation_2/constrained.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Constrained_Delaunay_triangulation_2.h>
#include <CGAL/draw_constrained_triangulation_2.h>

#include <cassert>
#include <iostream>
Expand Down Expand Up @@ -27,5 +28,8 @@ main( )
++count;
std::cout << "The number of resulting constrained edges is ";
std::cout << count << std::endl;

CGAL::draw(cdt);

return 0;
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ int main( )
assert(count > 0);
assert(count < cdt.number_of_faces());

CGAL::Polygon_triangulation_gs_options<CDT> myfunctor(in_domain);
CGAL::draw(cdt, myfunctor);
Polygon_triangulation_gs_options<CDT> gso(in_domain);
CGAL::draw(cdt, gso);
return 0;
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,42 +12,37 @@
#ifndef CGAL_POLYGON_TRIANGULATION_GRAPHICS_SCENE_OPTIONS_H
#define CGAL_POLYGON_TRIANGULATION_GRAPHICS_SCENE_OPTIONS_H

#include <CGAL/license/Triangulation_2.h>
#include <CGAL/Graphics_scene_options.h>
#include <CGAL/Random.h>
#include <CGAL/draw_triangulation_2.h>
#include <CGAL/Constrained_Delaunay_triangulation_2.h>

namespace CGAL
{

template<class PT>
struct Polygon_triangulation_gs_options :
public CGAL::Graphics_scene_options<PT,
public CGAL::Graphics_scene_options<typename PT::Triangulation,
typename PT::Vertex_handle,
typename PT::Finite_edges_iterator,
typename PT::Finite_faces_iterator>
{
using T2=typename PT::Triangulation;
template<class IPM>
Polygon_triangulation_gs_options(IPM ipm)
{
this->colored_face =
[](const PT&, const typename PT::Finite_faces_iterator) -> bool
[](const T2&, const typename PT::Finite_faces_iterator) -> bool
{ return true; };

this->face_color =
[](const PT&, const typename PT::Finite_faces_iterator fh) -> CGAL::IO::Color
[](const T2&, const typename PT::Finite_faces_iterator fh) -> CGAL::IO::Color
{
CGAL::Random random((unsigned int)(std::size_t)(&*fh));
return get_random_color(random);
};

this->draw_face=
[ipm](const PT&, const typename PT::Finite_faces_iterator fh) -> bool
[ipm](const T2&, const typename PT::Finite_faces_iterator fh) -> bool
{ return get(ipm, fh); };

this->draw_edge=
[ipm](const PT& pt, const typename PT::Finite_edges_iterator eh) -> bool
[ipm](const T2& pt, const typename PT::Finite_edges_iterator eh) -> bool
{
typename PT::Face_handle fh1=eh->first;
typename PT::Face_handle fh2=pt.mirror_edge(*eh).first;
Expand All @@ -56,33 +51,4 @@ struct Polygon_triangulation_gs_options :
}
};

#define CGAL_CT2_TYPE CGAL::Constrained_Delaunay_triangulation_2<K, TDS, Itag>

template <class K, class TDS, typename Itag,
typename BufferType=float, class GSOptions>
void add_in_graphics_scene(const CGAL_CT2_TYPE& ct2,
CGAL::Graphics_scene<BufferType>& graphic_buffer,
const GSOptions& gs_options)
{
draw_function_for_t2::compute_elements(ct2, graphic_buffer, gs_options);
}

#ifdef CGAL_USE_BASIC_VIEWER

// Specialization of draw function.
template <class K, class TDS, typename Itag, class GSOptions>
void draw(const CGAL_CT2_TYPE &ct2, const GSOptions &gs_options,
const char *title="Constrained Triangulation_2 Basic Viewer")
{
CGAL::Graphics_scene<float> buffer;
add_in_graphics_scene(ct2, buffer, gs_options);
draw_graphics_scene(buffer, title);
}

#endif // CGAL_USE_BASIC_VIEWER

#undef CGAL_CT2_TYPE

}; // end namespace CGAL

#endif // CGAL_POLYGON_TRIANGULATION_GRAPHICS_SCENE_OPTIONS_H
92 changes: 55 additions & 37 deletions Triangulation_2/include/CGAL/draw_constrained_triangulation_2.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,55 +16,73 @@

#include <CGAL/Constrained_triangulation_2.h>
#include <CGAL/Triangulation_2/internal/In_domain.h>

#ifdef CGAL_USE_BASIC_VIEWER

#include <CGAL/draw_triangulation_2.h>

namespace CGAL
{

template<class CDT>
struct Graphics_scene_options_constrained_triangulation_2:
public CGAL::Graphics_scene_options<typename CDT::Triangulation,
typename CDT::Vertex_handle,
typename CDT::Finite_edges_iterator,
typename CDT::Finite_faces_iterator>
{
using BASET2=typename CDT::Triangulation;

Graphics_scene_options_constrained_triangulation_2(const CDT& cdt)
{
this->colored_edge =
[&cdt](const BASET2&, typename CDT::Finite_edges_iterator eh) -> bool
{ return cdt.is_constrained(*eh); };

this->edge_color =
[&cdt](const BASET2&, typename CDT::Finite_edges_iterator eh) -> CGAL::IO::Color
{ return cdt.is_constrained(*eh)? CGAL::IO::green() : CGAL::IO::black(); };
};

template<class InDomainPmap>
Graphics_scene_options_constrained_triangulation_2(const CDT& cdt, InDomainPmap ipm)
{
this->colored_edge =
[&cdt](const BASET2&, typename CDT::Finite_edges_iterator eh) -> bool
{ return cdt.is_constrained(*eh); };

this->edge_color =
[&cdt](const BASET2&, typename CDT::Finite_edges_iterator eh) -> CGAL::IO::Color
{ return cdt.is_constrained(*eh)? CGAL::IO::green() : CGAL::IO::black(); };

this->colored_face =
[](const BASET2&, typename CDT::Finite_faces_iterator) -> bool
{ return true; };

this->face_color =
[ipm](const BASET2&, typename CDT::Finite_faces_iterator fh) -> CGAL::IO::Color
{ return get(ipm, fh)? CGAL::IO::blue() : CGAL::IO::white(); };
};
};

// Specialization of draw function.
#define CGAL_T2_TYPE CGAL::Constrained_triangulation_2<Gt, Tds, Itag>

template <class Gt, class Tds, class Itag, class InDomainPmap>
void add_to_graphics_scene(const CGAL_T2_TYPE& at2, InDomainPmap ipm,
CGAL::Graphics_scene& graphics_scene)
CGAL::Graphics_scene& graphics_scene)
{
using BASET2=CGAL::Triangulation_2<Gt, Tds>;

Graphics_scene_options<BASET2, //CGAL_T2_TYPE,
typename CGAL_T2_TYPE::Vertex_handle,
typename CGAL_T2_TYPE::Finite_edges_iterator,
typename CGAL_T2_TYPE::Finite_faces_iterator>
drawingFunctor;

drawingFunctor.colored_edge =
[](const BASET2& t2, typename CGAL_T2_TYPE::Finite_edges_iterator eh) -> bool
{ return static_cast<const CGAL_T2_TYPE&>(t2).is_constrained(*eh); };

drawingFunctor.edge_color =
[](const BASET2& t2, typename CGAL_T2_TYPE::Finite_edges_iterator eh) -> CGAL::IO::Color
{ return static_cast<const CGAL_T2_TYPE&>(t2).is_constrained(*eh)? CGAL::IO::green() : CGAL::IO::black(); };

drawingFunctor.colored_face =
[](const BASET2&, typename CGAL_T2_TYPE::Finite_faces_iterator) -> bool
{ return true; };

drawingFunctor.face_color =
[&ipm](const BASET2&, typename CGAL_T2_TYPE::Finite_faces_iterator fh) -> CGAL::IO::Color
{ return get(ipm, fh)? CGAL::IO::yellow() : CGAL::IO::white(); };

add_to_graphics_scene(at2, graphics_scene, drawingFunctor);
Graphics_scene_options_constrained_triangulation_2<CGAL_T2_TYPE> gso(at2, ipm);
draw_function_for_t2::compute_elements(at2, graphics_scene, gso);
}

template <class Gt, class Tds, class Itag>
void add_to_graphics_scene(const CGAL_T2_TYPE& at2,
CGAL::Graphics_scene& graphics_scene)
CGAL::Graphics_scene& graphics_scene)
{
internal::In_domain<CGAL_T2_TYPE> in_domain;
add_to_graphics_scene(at2, in_domain, graphics_scene);
Graphics_scene_options_constrained_triangulation_2<CGAL_T2_TYPE> gso(at2);
draw_function_for_t2::compute_elements(at2, graphics_scene, gso);
}

#ifdef CGAL_USE_BASIC_VIEWER

template<class Gt, class Tds, class Itag, class InDomainPmap>
void draw(const CGAL_T2_TYPE& at2, InDomainPmap ipm,
const char *title="Constrained Triangulation_2 Basic Viewer")
Expand All @@ -74,19 +92,19 @@ void draw(const CGAL_T2_TYPE& at2, InDomainPmap ipm,
draw_graphics_scene(buffer, title);
}


template<class Gt, class Tds, class Itag>
void draw(const CGAL_T2_TYPE& at2,
const char *title="Constrained Triangulation_2 Basic Viewer")
{
internal::In_domain<CGAL_T2_TYPE> in_domain;
draw(at2, in_domain, title);
CGAL::Graphics_scene buffer;
add_to_graphics_scene(at2, buffer);
draw_graphics_scene(buffer, title);
}

#endif // CGAL_USE_BASIC_VIEWER

#undef CGAL_T2_TYPE

} // End namespace CGAL

#endif // CGAL_USE_BASIC_VIEWER

#endif // CGAL_DRAW_CT2_H
14 changes: 5 additions & 9 deletions Triangulation_2/include/CGAL/draw_triangulation_2.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,9 @@ void compute_vertex(const T2& t2, typename T2::Vertex_handle vh,
{ return; }

if (gs_options.colored_vertex(t2, vh))
{
graphics_scene.add_point(vh->point(), gs_options.vertex_color(t2, vh));
}
{ graphics_scene.add_point(vh->point(), gs_options.vertex_color(t2, vh)); }
else
{
graphics_scene.add_point(vh->point());
}
{ graphics_scene.add_point(vh->point()); }
}

template <class T2, class GSOptions>
Expand Down Expand Up @@ -117,17 +113,17 @@ void compute_elements(const T2& t2,

#define CGAL_T2_TYPE CGAL::Triangulation_2<Gt, Tds>

template<class Gt, class Tds, class GSOptions>
template<class Gt, class Tds, class GSOptions>
void add_to_graphics_scene(const CGAL_T2_TYPE& at2,
CGAL::Graphics_scene& graphics_scene,
const GSOptions& gs_options)
{
draw_function_for_t2::compute_elements(at2, graphics_scene, gs_options);
}

template <class Gt, class Tds>
template <class Gt, class Tds>
void add_to_graphics_scene(const CGAL_T2_TYPE& at2,
CGAL::Graphics_scene& graphics_scene)
CGAL::Graphics_scene& graphics_scene)
{
Graphics_scene_options<CGAL_T2_TYPE,
typename CGAL_T2_TYPE::Vertex_handle,
Expand Down

0 comments on commit 9ea4e75

Please sign in to comment.