Cleaned up

This commit is contained in:
Efi Fogel 2025-07-17 13:12:59 +03:00
parent e70cf9fa17
commit 616931594a
3 changed files with 185 additions and 222 deletions

View File

@ -16,7 +16,8 @@
#ifndef ARR_VIEWER_H
#define ARR_VIEWER_H
#include "CGAL/Draw_aos/type_utils.h"
#include <CGAL/license/Arrangement_on_surface_2.h>
#include <array>
#include <cstddef>
#include <limits>
@ -31,22 +32,22 @@
#include <QtGui/QMouseEvent>
#include <QtGui/QKeyEvent>
#include <CGAL/Qt/camera.h>
#include <CGAL/Arr_linear_traits_2.h>
#include <CGAL/Arr_segment_traits_2.h>
#include <CGAL/Basic_viewer.h>
#include <CGAL/Bbox_2.h>
#include <CGAL/Graphics_scene.h>
#include <CGAL/Graphics_scene_options.h>
#include "CGAL/Draw_aos/type_utils.h"
#include <CGAL/Draw_aos/Arr_bounded_renderer.h>
#include <CGAL/Draw_aos/Arr_render_context.h>
#include <CGAL/Graphics_scene.h>
#include <CGAL/Graphics_scene_options.h>
#include <CGAL/Qt/camera.h>
namespace CGAL {
namespace draw_aos {
template <typename Arrangement, typename GSOptions>
class Arr_viewer : public Qt::Basic_viewer
{
class Arr_viewer : public Qt::Basic_viewer {
using Basic_viewer = Qt::Basic_viewer;
using Vertex_const_handle = typename Arrangement::Vertex_const_handle;
using Halfedge_const_handle = typename Arrangement::Halfedge_const_handle;
@ -64,9 +65,7 @@ private:
this->camera_->computeModelViewMatrix();
this->camera_->getProjectionMatrix(proj_mat.data());
this->camera_->getModelViewMatrix(mv_mat.data());
if(proj_mat == m_last_proj_matrix && mv_mat == m_last_modelview_matrix) {
return false;
}
if (proj_mat == m_last_proj_matrix && mv_mat == m_last_modelview_matrix) return false;
m_last_proj_matrix = proj_mat;
m_last_modelview_matrix = mv_mat;
return true;
@ -85,18 +84,19 @@ private:
QMatrix4x4 inverse_mvp = (projection_matrix * modelview_matrix).inverted();
// Define 4 corners of the near plane in NDC (-1 to 1 in x and y)
QVector4D clip_space_corners[] = {QVector4D(-1.0, -1.0, 0.0, 1.0), QVector4D(-1.0, 1.0, 0.0, 1.0),
QVector4D(1.0, -1.0, 0.0, 1.0), QVector4D(1.0, 1.0, 0.0, 1.0)};
QVector4D clip_space_corners[] = {
QVector4D(-1.0, -1.0, 0.0, 1.0), QVector4D(-1.0, 1.0, 0.0, 1.0),
QVector4D(1.0, -1.0, 0.0, 1.0), QVector4D(1.0, 1.0, 0.0, 1.0)
};
double xmin = std::numeric_limits<double>::max();
double xmax = std::numeric_limits<double>::lowest();
double ymin = std::numeric_limits<double>::max();
double ymax = std::numeric_limits<double>::lowest();
for(const QVector4D& corner : clip_space_corners) {
for (const QVector4D& corner : clip_space_corners) {
QVector4D world = inverse_mvp * corner;
if(world.w() != 0.0)
world /= world.w();
if (world.w() != 0.0) world /= world.w();
double x = world.x();
double y = world.y();
@ -109,10 +109,11 @@ private:
return Bbox_2(xmin, ymin, xmax, ymax);
}
/*!
*/
double get_approx_error(const Bbox_2& bbox) const {
if constexpr(Traits_adaptor<Geom_traits>::Approximation_sizing_factor == 0.0) {
if constexpr(Traits_adaptor<Geom_traits>::Approximation_sizing_factor == 0.0)
return std::numeric_limits<double>::max();
}
std::array<GLint, 4> viewport;
camera_->getViewport(viewport.data());
double viewport_width = static_cast<double>(viewport[2]);
@ -121,16 +122,21 @@ private:
}
public:
/*!
*/
Arr_viewer(QWidget* parent,
const Arrangement& arr,
Graphics_scene_options options,
const char* title = "Arrangement Viewer")
: Basic_viewer(parent, m_scene, title)
, m_scene_options(options)
, m_arr(arr)
, m_feature_portals(Arr_portals<Arrangement>(*arr.geometry_traits()).create(arr))
, m_pl(arr) {}
const char* title = "Arrangement Viewer") :
Basic_viewer(parent, m_scene, title),
m_scene_options(options),
m_arr(arr),
m_feature_portals(Arr_portals<Arrangement>(*arr.geometry_traits()).create(arr)),
m_pl(arr)
{}
/*!
*/
void render_arr(const Bbox_2& bbox) {
Arr_render_context<Arrangement> ctx(m_arr, m_pl, m_feature_portals, get_approx_error(bbox));
Arr_bounded_renderer<Arrangement> renderer(ctx, bbox);
@ -143,60 +149,47 @@ public:
#endif
// add faces
for(const auto& [fh, face_tris] : cache.face_cache()) {
for (const auto& [fh, face_tris] : cache.face_cache()) {
const auto& points = face_tris.points;
const auto& tris = face_tris.triangles;
bool draw_face = m_scene_options.colored_face(m_arr, fh);
for(const auto& t : tris) {
if(draw_face) {
m_scene.face_begin(m_scene_options.face_color(m_arr, fh));
} else {
m_scene.face_begin();
}
for(const auto idx : t) {
m_scene.add_point_in_face(points[idx]);
}
for (const auto& t : tris) {
if (draw_face) m_scene.face_begin(m_scene_options.face_color(m_arr, fh));
else m_scene.face_begin();
for (const auto idx : t) m_scene.add_point_in_face(points[idx]);
m_scene.face_end();
}
}
// add edges
for(const auto& [he, polyline] : cache.halfedge_cache()) {
if(polyline.size() < 2) {
continue;
}
for (const auto& [he, polyline] : cache.halfedge_cache()) {
if (polyline.size() < 2) continue;
bool draw_colored_edge = m_scene_options.colored_edge(m_arr, he);
auto color = draw_colored_edge ? m_scene_options.edge_color(m_arr, he) : CGAL::IO::Color();
for(size_t i = 0; i < polyline.size() - 1; ++i) {
for (size_t i = 0; i < polyline.size() - 1; ++i) {
const auto& cur_pt = polyline[i];
const auto& next_pt = polyline[i + 1];
auto mid_pt = CGAL::midpoint(cur_pt, next_pt);
if(mid_pt.x() <= bbox.xmin() || mid_pt.x() > bbox.xmax() || mid_pt.y() <= bbox.ymin() ||
mid_pt.y() > bbox.ymax())
if (mid_pt.x() <= bbox.xmin() || mid_pt.x() > bbox.xmax() || mid_pt.y() <= bbox.ymin() ||
mid_pt.y() > bbox.ymax())
{
continue;
}
if(draw_colored_edge) {
m_scene.add_segment(cur_pt, next_pt, color);
} else {
m_scene.add_segment(cur_pt, next_pt);
}
if (draw_colored_edge) m_scene.add_segment(cur_pt, next_pt, color);
else m_scene.add_segment(cur_pt, next_pt);
}
}
// add vertices
for(const auto& [vh, pt] : cache.vertex_cache()) {
if(m_scene_options.colored_vertex(m_arr, vh)) {
m_scene.add_point(pt, m_scene_options.vertex_color(m_arr, vh));
} else {
m_scene.add_point(pt);
}
for (const auto& [vh, pt] : cache.vertex_cache()) {
if (m_scene_options.colored_vertex(m_arr, vh)) m_scene.add_point(pt, m_scene_options.vertex_color(m_arr, vh));
else m_scene.add_point(pt);
}
// If there's nothing to render, we fill the bbox with background color.
// This is to keep the Basic_viewer working in 2D mode.
if(m_scene.empty()) {
if (m_scene.empty()) {
m_scene.face_begin(CGAL::IO::Color(255, 255, 255)); // White, by now
using Approx_point = typename Arr_approximation_geometry_traits<Geom_traits>::Approx_point;
m_scene.add_point_in_face(Approx_point(bbox.xmin(), bbox.ymin()));
@ -207,14 +200,18 @@ public:
}
}
/*!
*/
void rerender(Bbox_2 bbox) {
m_scene.clear();
render_arr(bbox);
Basic_viewer::redraw();
}
/*!
*/
virtual void draw() override {
if(is_camera_changed()) {
if (is_camera_changed()) {
Bbox_2 bbox = view_bbox_from_camera();
#if defined(CGAL_DRAW_AOS_DEBUG)
double dx = (bbox.xmax() - bbox.xmin()) * 0.1;
@ -227,6 +224,8 @@ public:
Basic_viewer::draw();
}
/*!
*/
virtual ~Arr_viewer() {}
private:

View File

@ -26,21 +26,17 @@ enum class Side_of_boundary {
};
template <typename, typename = std::void_t<>>
struct has_construct_x_monotone_curve_2 : std::false_type
{};
struct has_construct_x_monotone_curve_2 : std::false_type {};
template <typename T>
struct has_construct_x_monotone_curve_2<T, std::void_t<typename T::Construct_x_monotone_curve_2>> : std::true_type
{};
struct has_construct_x_monotone_curve_2<T, std::void_t<typename T::Construct_x_monotone_curve_2>> : std::true_type {};
template <typename, typename = std::void_t<>>
struct has_approximate_2_object : std::false_type
{};
struct has_approximate_2_object : std::false_type {};
// Specialization: detection succeeds if decltype(T::approximate_2_object()) is valid
template <typename T>
struct has_approximate_2_object<T, std::void_t<decltype(std::declval<T>().approximate_2_object())>> : std::true_type
{};
struct has_approximate_2_object<T, std::void_t<decltype(std::declval<T>().approximate_2_object())>> : std::true_type {};
// Convenience variable
template <typename T>
@ -49,13 +45,12 @@ inline constexpr bool has_approximate_2_object_v = has_approximate_2_object<T>::
// Primary templates: detection fails by default
// Does a class have operator()(const Point&)?
template <typename, typename, typename = std::void_t<>>
struct has_operator_point : std::false_type
{};
struct has_operator_point : std::false_type {};
// Specialization: detection succeeds if decltype works out
template <typename T, typename A>
struct has_operator_point<T, A, std::void_t<decltype(std::declval<A>()(std::declval<const typename T::Point_2&>()))>>
: std::true_type
struct has_operator_point<T, A, std::void_t<decltype(std::declval<A>()(std::declval<const typename T::Point_2&>()))>> :
std::true_type
{};
// Convenience variable
@ -65,9 +60,10 @@ inline constexpr bool has_operator_point_v = has_operator_point<T, A>::value;
// Primary templates: detection fails by default
// Does a class have operator()(const X_monotone_curve&)?
template <typename, typename, typename, typename = std::void_t<>>
struct has_operator_xcv : std::false_type
{};
struct has_operator_xcv : std::false_type {};
/*!
*/
template <typename T, typename A, typename O>
struct has_operator_xcv<T,
A,
@ -82,9 +78,10 @@ struct has_operator_xcv<T,
template <typename T, typename A>
constexpr bool has_operator_xcv_v = has_operator_xcv<T, A, void*>::value;
/*!
*/
template <typename GeomTraits>
struct Traits_adaptor_base
{
struct Traits_adaptor_base {
public:
using Geom_traits = GeomTraits;
using Point_2 = typename Geom_traits::Point_2;
@ -94,12 +91,15 @@ public:
using Compare_xy_2 = typename Geom_traits::Compare_xy_2;
};
/*!
*/
template <typename GeomTraits>
struct Traits_adaptor;
/*!
*/
template <typename Kernel>
struct Traits_adaptor<Arr_segment_traits_2<Kernel>> : public Traits_adaptor_base<Arr_segment_traits_2<Kernel>>
{
struct Traits_adaptor<Arr_segment_traits_2<Kernel>> : public Traits_adaptor_base<Arr_segment_traits_2<Kernel>> {
private:
using Geom_traits = Arr_segment_traits_2<Kernel>;
@ -113,10 +113,11 @@ public:
using Approximate_point_2 = typename Geom_traits::Approximate_point_2;
};
/*!
*/
template <typename Kernel>
struct Traits_adaptor<Arr_non_caching_segment_traits_2<Kernel>>
: public Traits_adaptor_base<Arr_non_caching_segment_traits_2<Kernel>>
{
struct Traits_adaptor<Arr_non_caching_segment_traits_2<Kernel>> :
public Traits_adaptor_base<Arr_non_caching_segment_traits_2<Kernel>> {
private:
using Geom_traits = Arr_non_caching_segment_traits_2<Kernel>;
@ -130,10 +131,11 @@ public:
using Approximate_point_2 = typename Geom_traits::Approximate_point_2;
};
/*!
*/
template <typename SegmentTraits>
struct Traits_adaptor<Arr_polyline_traits_2<SegmentTraits>>
: public Traits_adaptor_base<Arr_polyline_traits_2<SegmentTraits>>
{
struct Traits_adaptor<Arr_polyline_traits_2<SegmentTraits>> :
public Traits_adaptor_base<Arr_polyline_traits_2<SegmentTraits>> {
private:
using Geom_traits = Arr_polyline_traits_2<SegmentTraits>;
using Sub_traits = SegmentTraits;
@ -149,10 +151,11 @@ public:
using Approximate_point_2 = typename Adapted_sub_traits::Approximate_point_2;
};
/*!
*/
template <typename SubcurveTraits>
struct Traits_adaptor<Arr_polycurve_traits_2<SubcurveTraits>>
: public Traits_adaptor_base<Arr_polycurve_traits_2<SubcurveTraits>>
{
struct Traits_adaptor<Arr_polycurve_traits_2<SubcurveTraits>> :
public Traits_adaptor_base<Arr_polycurve_traits_2<SubcurveTraits>> {
private:
using Sub_traits = SubcurveTraits;
using Geom_traits = Arr_polycurve_traits_2<Sub_traits>;
@ -168,9 +171,10 @@ public:
using Approximate_point_2 = typename Adapted_sub_traits::Approximate_point_2;
};
/*!
*/
template <typename Kernel>
struct Traits_adaptor<Arr_linear_traits_2<Kernel>> : public Traits_adaptor_base<Arr_linear_traits_2<Kernel>>
{
struct Traits_adaptor<Arr_linear_traits_2<Kernel>> : public Traits_adaptor_base<Arr_linear_traits_2<Kernel>> {
private:
using Geom_traits = Arr_segment_traits_2<Kernel>;
@ -184,10 +188,11 @@ public:
using Approximate_point_2 = typename Geom_traits::Approximate_point_2;
};
/*!
*/
template <typename RatKernel, typename AlgKernel, typename NtTraits>
struct Traits_adaptor<Arr_conic_traits_2<RatKernel, AlgKernel, NtTraits>>
: public Traits_adaptor_base<Arr_conic_traits_2<RatKernel, AlgKernel, NtTraits>>
{
struct Traits_adaptor<Arr_conic_traits_2<RatKernel, AlgKernel, NtTraits>> :
public Traits_adaptor_base<Arr_conic_traits_2<RatKernel, AlgKernel, NtTraits>> {
private:
using Geom_traits = Arr_conic_traits_2<RatKernel, AlgKernel, NtTraits>;
@ -201,10 +206,11 @@ public:
using Approximate_point_2 = typename Geom_traits::Approximate_point_2;
};
/*!
*/
template <typename Kernel>
struct Traits_adaptor<Arr_circle_segment_traits_2<Kernel>>
: public Traits_adaptor_base<Arr_circle_segment_traits_2<Kernel>>
{
struct Traits_adaptor<Arr_circle_segment_traits_2<Kernel>> :
public Traits_adaptor_base<Arr_circle_segment_traits_2<Kernel>> {
private:
using Geom_traits = Arr_circle_segment_traits_2<Kernel>;
using Base = Traits_adaptor_base<Geom_traits>;
@ -219,10 +225,11 @@ public:
using Approximate_point_2 = typename Geom_traits::Approximate_point_2;
};
/*!
*/
template <typename Kernel>
struct Traits_adaptor<Arr_rational_function_traits_2<Kernel>>
: public Traits_adaptor_base<Arr_rational_function_traits_2<Kernel>>
{
struct Traits_adaptor<Arr_rational_function_traits_2<Kernel>> :
public Traits_adaptor_base<Arr_rational_function_traits_2<Kernel>> {
private:
using Geom_traits = Arr_rational_function_traits_2<Kernel>;
@ -238,18 +245,20 @@ public:
using Approximate_point_2 = typename Approximate_kernel::Point_2;
};
/*!
*/
template <typename GeomTraits>
class Construct_coordinate
{
class Construct_coordinate {
using FT = typename Traits_adaptor<GeomTraits>::FT;
public:
FT operator()(double val) const { return FT(val); }
};
/*!
*/
template <typename Kernel>
class Construct_coordinate<Arr_rational_function_traits_2<Kernel>>
{
class Construct_coordinate<Arr_rational_function_traits_2<Kernel>> {
using FT = typename Traits_adaptor<Arr_rational_function_traits_2<Kernel>>::FT;
using Bound = typename Kernel::Bound;
@ -257,9 +266,10 @@ public:
FT operator()(double val) const { return FT(Bound(val)); }
};
/*!
*/
template <typename GeomTraits>
class Arr_approximation_geometry_traits
{
class Arr_approximation_geometry_traits {
using Adapted_traits = Traits_adaptor<GeomTraits>;
public:
@ -271,8 +281,7 @@ public:
using Polyline_geom = Apporx_point_vec;
using Triangle = std::array<std::size_t, 3>;
using Triangle_vec = std::vector<Triangle>;
struct Triangulated_face
{
struct Triangulated_face {
Apporx_point_vec points;
Triangle_vec triangles;
};
@ -281,4 +290,4 @@ public:
} // namespace draw_aos
} // namespace CGAL
#endif // CGAL_DRAW_AOS_TYPE_UTILS_H
#endif // CGAL_DRAW_AOS_TYPE_UTILS_H

View File

@ -16,6 +16,8 @@
#ifndef CGAL_DRAW_ARRANGEMENT_2_H
#define CGAL_DRAW_ARRANGEMENT_2_H
#include <CGAL/license/Arrangement_on_surface_2.h>
#include <cstdlib>
#include <type_traits>
#include <unordered_map>
@ -27,7 +29,6 @@
#include <CGAL/Graphics_scene.h>
#include <CGAL/Graphics_scene_options.h>
#include <CGAL/Random.h>
#include <CGAL/license/Arrangement_on_surface_2.h>
#include <CGAL/config.h>
#include <CGAL/Draw_aos/Arr_viewer.h>
@ -44,13 +45,11 @@ namespace draw_function_for_arrangement_2 {
// Primary templates: detection fails by default
// Does the traits have approximate_2_object()?
template <typename, typename = std::void_t<>>
struct has_approximate_2_object : std::false_type
{};
struct has_approximate_2_object : std::false_type {};
// Specialization: detection succeeds if decltype(T::approximate_2_object()) is valid
template <typename T>
struct has_approximate_2_object<T, std::void_t<decltype(std::declval<T>().approximate_2_object())>> : std::true_type
{};
struct has_approximate_2_object<T, std::void_t<decltype(std::declval<T>().approximate_2_object())>> : std::true_type {};
// Convenience variable
template <typename T>
@ -61,8 +60,7 @@ inline constexpr bool has_approximate_2_object_v = has_approximate_2_object<T>::
// Primary templates: detection fails by default
// Does a class have operator()(const Point&)?
template <typename, typename, typename = std::void_t<>>
struct has_operator_point : std::false_type
{};
struct has_operator_point : std::false_type {};
// Specialization: detection succeeds if decltype works out
template <typename T, typename A>
@ -79,8 +77,7 @@ inline constexpr bool has_operator_point_v = has_operator_point<T, A>::value;
// Primary templates: detection fails by default
// Does a class have operator()(const X_monotone_curve&)?
template <typename, typename, typename = std::void_t<>>
struct has_operator_xcv : std::false_type
{};
struct has_operator_xcv : std::false_type {};
// Specialization: detection succeeds if decltype works out
struct Dummy_output
@ -104,8 +101,7 @@ inline constexpr bool has_operator_xcv_v = has_operator_xcv<T, A>::value;
// Helper: detect whether T is or derives from Arr_geodesic_arc_on_sphere_traits_2<*, *, *>
template <typename T>
struct is_or_derived_from_agas
{
struct is_or_derived_from_agas {
private:
template <typename Kernel_, int AtanX, int AtanY>
static std::true_type test(const Arr_geodesic_arc_on_sphere_traits_2<Kernel_, AtanX, AtanY>*);
@ -123,8 +119,7 @@ inline constexpr bool is_or_derived_from_agas_v = is_or_derived_from_agas<T>::va
///
template <typename Arr, typename GSOptions>
class Draw_arr_tool
{
class Draw_arr_tool {
public:
using Halfedge_const_handle = typename Arr::Halfedge_const_handle;
using Vertex_const_handle = typename Arr::Vertex_const_handle;
@ -138,18 +133,18 @@ public:
/*! Construct
*/
Draw_arr_tool(Arr& a_aos, CGAL::Graphics_scene& a_gs, const GSOptions& a_gso)
: m_aos(a_aos)
, m_gs(a_gs)
, m_gso(a_gso) {}
Draw_arr_tool(Arr& a_aos, CGAL::Graphics_scene& a_gs, const GSOptions& a_gso) :
m_aos(a_aos),
m_gs(a_gs),
m_gso(a_gso)
{}
/// Add a face.
void add_face(Face_const_handle face) {
// std::cout << "add_face()\n";
for(Inner_ccb_const_iterator it = face->inner_ccbs_begin(); it != face->inner_ccbs_end(); ++it)
add_ccb(*it);
for (Inner_ccb_const_iterator it = face->inner_ccbs_begin(); it != face->inner_ccbs_end(); ++it) add_ccb(*it);
for(Outer_ccb_const_iterator it = face->outer_ccbs_begin(); it != face->outer_ccbs_end(); ++it) {
for (Outer_ccb_const_iterator it = face->outer_ccbs_begin(); it != face->outer_ccbs_end(); ++it) {
add_ccb(*it);
draw_region(*it);
}
@ -161,8 +156,7 @@ public:
auto curr = circ;
do {
auto new_face = curr->twin()->face();
if(m_visited.find(new_face) != m_visited.end())
continue;
if (m_visited.find(new_face) != m_visited.end()) continue;
m_visited[new_face] = true;
add_face(new_face);
} while(++curr != circ);
@ -186,10 +180,8 @@ public:
*
* For now we use C++14 features.
*/
if(m_gso.colored_face(m_aos, circ->face()))
m_gs.face_begin(m_gso.face_color(m_aos, circ->face()));
else
m_gs.face_begin();
if (m_gso.colored_face(m_aos, circ->face())) m_gs.face_begin(m_gso.face_color(m_aos, circ->face()));
else m_gs.face_begin();
const auto* traits = this->m_aos.geometry_traits();
auto ext = find_smallest(circ, *traits);
@ -197,8 +189,7 @@ public:
do {
// Skip halfedges that are "antenas":
while(curr->face() == curr->twin()->face())
curr = curr->twin()->next();
while(curr->face() == curr->twin()->face()) curr = curr->twin()->next();
draw_region_impl1(*traits, curr);
curr = curr->next();
} while(curr != ext);
@ -210,22 +201,19 @@ public:
///
template <typename T, typename A, std::enable_if_t<!has_operator_point_v<T, A>, int> = 0>
void draw_region_impl2(const T& /* traits */, const A& /* approximate */, Halfedge_const_handle curr) {
draw_exact_region(curr);
}
void draw_region_impl2(const T& /* traits */, const A& /* approximate */, Halfedge_const_handle curr)
{ draw_exact_region(curr); }
///
template <typename T, typename A, std::enable_if_t<has_operator_point_v<T, A>, int> = 0>
auto draw_region_impl2(const T& /* traits */, const A& approx, Halfedge_const_handle curr) {
draw_approximate_region(curr, approx);
}
auto draw_region_impl2(const T& /* traits */, const A& approx, Halfedge_const_handle curr)
{ draw_approximate_region(curr, approx); }
/*! Draw a region, where the traits does not has approximate_2_object.
*/
template <typename T, std::enable_if_t<!has_approximate_2_object_v<T> && !is_or_derived_from_agas_v<T>, int> = 0>
void draw_region_impl1(const T& /* traits */, Halfedge_const_handle curr) {
draw_exact_region(curr);
}
void draw_region_impl1(const T& /* traits */, Halfedge_const_handle curr)
{ draw_exact_region(curr); }
///
template <typename T, std::enable_if_t<has_approximate_2_object_v<T> && !is_or_derived_from_agas_v<T>, int> = 0>
@ -255,12 +243,10 @@ public:
double error(0.01); // TODO? (this->pixel_ratio());
bool l2r = curr->direction() == ARR_LEFT_TO_RIGHT;
approx(curr->curve(), error, std::back_inserter(polyline), l2r);
if(polyline.empty())
return;
if (polyline.empty()) return;
auto it = polyline.begin();
auto prev = it++;
for(; it != polyline.end(); prev = it++)
m_gs.add_point_in_face(*prev);
for (; it != polyline.end(); prev = it++) m_gs.add_point_in_face(*prev);
}
/*! Draw an exact curve.
@ -271,10 +257,8 @@ public:
auto ctr_min = traits->construct_min_vertex_2_object();
auto ctr_max = traits->construct_max_vertex_2_object();
m_gs.add_segment(ctr_min(curve), ctr_max(curve));
if(colored)
m_gs.add_segment(ctr_min(curve), ctr_max(curve), c);
else
m_gs.add_segment(ctr_min(curve), ctr_max(curve));
if (colored) m_gs.add_segment(ctr_min(curve), ctr_max(curve), c);
else m_gs.add_segment(ctr_min(curve), ctr_max(curve));
}
/*! Draw a region in an exact manner.
@ -284,10 +268,8 @@ public:
/// Add all faces.
template <typename Traits>
void add_faces(const Traits&) {
for(auto it = m_aos.unbounded_faces_begin(); it != m_aos.unbounded_faces_end(); ++it)
add_face(it);
}
void add_faces(const Traits&)
{ for (auto it = m_aos.unbounded_faces_begin(); it != m_aos.unbounded_faces_end(); ++it) add_face(it); }
/// Compile time dispatching
@ -295,47 +277,39 @@ public:
*/
template <typename Approximate>
void draw_approximate_point(const Point& p, const Approximate& approx, bool colored, const CGAL::IO::Color& color) {
if(colored)
m_gs.add_point(approx(p), color);
else
m_gs.add_point(approx(p));
if (colored) m_gs.add_point(approx(p), color);
else m_gs.add_point(approx(p));
}
///
void draw_exact_point(const Point& p, bool colored, const CGAL::IO::Color& color) {
if(colored)
m_gs.add_point(p, color);
else
m_gs.add_point(p);
if (colored) m_gs.add_point(p, color);
else m_gs.add_point(p);
}
///
template <typename T, typename A, std::enable_if_t<!has_operator_point_v<T, A>, int> = 0>
void draw_point_impl2(
const T& /* traits */, const A& /* approximate */, const Point& p, bool colored, const CGAL::IO::Color& c) {
draw_exact_point(p, colored, c);
}
void draw_point_impl2(const T& /* traits */, const A& /* approximate */, const Point& p, bool colored,
const CGAL::IO::Color& c)
{ draw_exact_point(p, colored, c); }
///
template <typename T, typename A, std::enable_if_t<has_operator_point_v<T, A>, int> = 0>
auto
draw_point_impl2(const T& /* traits */, const A& approx, const Point& p, bool colored, const CGAL::IO::Color& c) {
draw_approximate_point(p, approx, colored, c);
}
draw_point_impl2(const T& /* traits */, const A& approx, const Point& p, bool colored, const CGAL::IO::Color& c)
{ draw_approximate_point(p, approx, colored, c); }
/*! Draw a point, where the traits does not has approximate_2_object.
*/
template <typename T, std::enable_if_t<!has_approximate_2_object_v<T> && !is_or_derived_from_agas_v<T>, int> = 0>
void draw_point_impl1(const T& /* traits */, const Point& p, bool colored, const CGAL::IO::Color& c) {
draw_exact_point(p, colored, c);
}
void draw_point_impl1(const T& /* traits */, const Point& p, bool colored, const CGAL::IO::Color& c)
{ draw_exact_point(p, colored, c); }
/*! Draw a point, where the traits does have approximate_2_object.
*/
template <typename T, std::enable_if_t<has_approximate_2_object_v<T> && !is_or_derived_from_agas_v<T>, int> = 0>
auto draw_point_impl1(const T& traits, const Point& p, bool colored, const CGAL::IO::Color& c) {
draw_point_impl2(traits, traits.approximate_2_object(), p, colored, c);
}
auto draw_point_impl1(const T& traits, const Point& p, bool colored, const CGAL::IO::Color& c)
{ draw_point_impl2(traits, traits.approximate_2_object(), p, colored, c); }
/*! Draw a geodesic point.
*/
@ -352,10 +326,8 @@ public:
auto z = ap.dz();
auto l = std::sqrt(x * x + y * y + z * z);
Approx_point_3 p3(x / l, y / l, z / l);
if(colored)
m_gs.add_point(p3, color);
else
m_gs.add_point(p3);
if (colored) m_gs.add_point(p3, color);
else m_gs.add_point(p3);
}
/// Draw a point.
@ -367,9 +339,8 @@ public:
///
template <typename Kernel, int AtanX, int AtanY>
Halfedge_const_handle find_smallest(Ccb_halfedge_const_circulator circ,
Arr_geodesic_arc_on_sphere_traits_2<Kernel, AtanX, AtanY> const&) {
return circ;
}
Arr_geodesic_arc_on_sphere_traits_2<Kernel, AtanX, AtanY> const&)
{ return circ; }
/*! Find the halfedge incident to the lexicographically smallest vertex
* along the CCB, such that there is no other halfedge underneath.
@ -383,9 +354,7 @@ public:
// Find the first halfedge directed from left to right
auto curr = circ;
do
if(curr->direction() == CGAL::ARR_LEFT_TO_RIGHT)
break;
do if (curr->direction() == CGAL::ARR_LEFT_TO_RIGHT) break;
while(++curr != circ);
Halfedge_const_handle ext = curr;
@ -393,25 +362,22 @@ public:
// such that there is no other halfedge underneath.
do {
// Discard edges not directed from left to right:
if(curr->direction() != CGAL::ARR_LEFT_TO_RIGHT)
continue;
if (curr->direction() != CGAL::ARR_LEFT_TO_RIGHT) continue;
auto res = cmp_xy(curr->source()->point(), ext->source()->point());
// Discard the edges inciden to a point strictly larger than the point
// incident to the stored extreme halfedge:
if(res == LARGER)
continue;
if (res == LARGER) continue;
// Store the edge inciden to a point strictly smaller:
if(res == SMALLER) {
if (res == SMALLER) {
ext = curr;
continue;
}
// The incident points are equal; compare the halfedges themselves:
if(cmp_y(curr->curve(), ext->curve(), curr->source()->point()) == SMALLER)
ext = curr;
if (cmp_y(curr->curve(), ext->curve(), curr->source()->point()) == SMALLER) ext = curr;
} while(++curr != circ);
return ext;
@ -423,33 +389,28 @@ public:
// std::cout << "ratio: " << this->pixel_ratio() << std::endl;
m_visited.clear();
if(m_aos.is_empty())
return;
if (m_aos.is_empty()) return;
if(m_gso.are_faces_enabled())
if (m_gso.are_faces_enabled())
add_faces(*(this->m_aos.geometry_traits()));
// Add edges that do not separate faces.
if(m_gso.are_edges_enabled()) {
for(auto it = m_aos.edges_begin(); it != m_aos.edges_end(); ++it) {
if(it->face() != it->twin()->face()) {
if(m_gso.draw_edge(m_aos, it)) {
if(m_gso.colored_edge(m_aos, it))
draw_curve(it->curve(), true, m_gso.edge_color(m_aos, it));
else
draw_curve(it->curve(), false, CGAL::IO::Color());
if (m_gso.are_edges_enabled()) {
for (auto it = m_aos.edges_begin(); it != m_aos.edges_end(); ++it) {
if (it->face() != it->twin()->face()) {
if (m_gso.draw_edge(m_aos, it)) {
if (m_gso.colored_edge(m_aos, it)) draw_curve(it->curve(), true, m_gso.edge_color(m_aos, it));
else draw_curve(it->curve(), false, CGAL::IO::Color());
}
}
}
}
// Add all points
if(m_gso.are_vertices_enabled()) {
for(auto it = m_aos.vertices_begin(); it != m_aos.vertices_end(); ++it) {
if(m_gso.colored_vertex(m_aos, it))
draw_point(it->point(), true, m_gso.vertex_color(m_aos, it));
else
draw_point(it->point(), false, CGAL::IO::Color());
if (m_gso.are_vertices_enabled()) {
for (auto it = m_aos.vertices_begin(); it != m_aos.vertices_end(); ++it) {
if (m_gso.colored_vertex(m_aos, it)) draw_point(it->point(), true, m_gso.vertex_color(m_aos, it));
else draw_point(it->point(), false, CGAL::IO::Color());
}
}
@ -471,15 +432,12 @@ public:
std::vector<typename Gt::Approximate_point_2> polyline;
double error(0.01); // TODO? (this->pixel_ratio());
approx(curve, error, std::back_inserter(polyline));
if(polyline.empty())
return;
if (polyline.empty()) return;
auto it = polyline.begin();
auto prev = it++;
for(; it != polyline.end(); prev = it++) {
if(colored)
m_gs.add_segment(*prev, *it, c);
else
m_gs.add_segment(*prev, *it);
for (; it != polyline.end(); prev = it++) {
if (colored) m_gs.add_segment(*prev, *it, c);
else m_gs.add_segment(*prev, *it);
}
}
@ -489,23 +447,20 @@ public:
const A& /* approximate */,
const X_monotone_curve& xcv,
bool colored,
const CGAL::IO::Color& c) {
draw_exact_curve(xcv, colored, c);
}
const CGAL::IO::Color& c)
{ draw_exact_curve(xcv, colored, c); }
///
template <typename T, typename A, std::enable_if_t<has_operator_point_v<T, A>, int> = 0>
auto draw_curve_impl2(
const T& /* traits */, const A& approx, const X_monotone_curve& xcv, bool colored, const CGAL::IO::Color& c) {
draw_approximate_curve(xcv, approx, colored, c);
}
auto draw_curve_impl2(const T& /* traits */, const A& approx, const X_monotone_curve& xcv, bool colored,
const CGAL::IO::Color& c)
{ draw_approximate_curve(xcv, approx, colored, c); }
/*! Draw a curve, where the traits does not has approximate_2_object.
*/
template <typename T, std::enable_if_t<!has_approximate_2_object_v<T> && !is_or_derived_from_agas_v<T>, int> = 0>
void draw_curve_impl1(const T& /* traits */, const X_monotone_curve& xcv, bool colored, const CGAL::IO::Color& c) {
draw_exact_curve(xcv, colored, c);
}
void draw_curve_impl1(const T& /* traits */, const X_monotone_curve& xcv, bool colored, const CGAL::IO::Color& c)
{ draw_exact_curve(xcv, colored, c); }
/*! Draw a curve, where the traits does have approximate_2_object.
*/
@ -536,13 +491,13 @@ public:
auto z = it->dz();
auto l = std::sqrt(x * x + y * y + z * z);
Approx_point_3 prev(x / l, y / l, z / l);
for(++it; it != apoints.end(); ++it) {
for (++it; it != apoints.end(); ++it) {
auto x = it->dx();
auto y = it->dy();
auto z = it->dz();
auto l = std::sqrt(x * x + y * y + z * z);
Approx_point_3 next(x / l, y / l, z / l);
if(colored)
if (colored)
m_gs.add_segment(prev, next, c);
else
m_gs.add_segment(prev, next);