From 7f04082cfcc58129cc1dac15c9af57b7aea6b3aa Mon Sep 17 00:00:00 2001 From: Dimitris Papavasiliou Date: Tue, 31 Aug 2021 13:32:29 +0300 Subject: [PATCH 1/4] Add polygon set drawing functionality. --- .../CGAL/draw_polygon_set_2.h | 14 +++ .../PackageDescription.txt | 11 +++ .../doc/Boolean_set_operations_2/examples.txt | 1 + .../draw_polygon_set.cpp | 47 ++++++++++ .../include/CGAL/draw_polygon_set_2.h | 94 +++++++++++++++++++ .../include/CGAL/draw_polygon_with_holes_2.h | 24 +++-- 6 files changed, 181 insertions(+), 10 deletions(-) create mode 100644 Boolean_set_operations_2/doc/Boolean_set_operations_2/CGAL/draw_polygon_set_2.h create mode 100644 Boolean_set_operations_2/examples/Boolean_set_operations_2/draw_polygon_set.cpp create mode 100644 Boolean_set_operations_2/include/CGAL/draw_polygon_set_2.h diff --git a/Boolean_set_operations_2/doc/Boolean_set_operations_2/CGAL/draw_polygon_set_2.h b/Boolean_set_operations_2/doc/Boolean_set_operations_2/CGAL/draw_polygon_set_2.h new file mode 100644 index 00000000000..0e8e3ed3ba3 --- /dev/null +++ b/Boolean_set_operations_2/doc/Boolean_set_operations_2/CGAL/draw_polygon_set_2.h @@ -0,0 +1,14 @@ +namespace CGAL { + +/*! +\ingroup PkgDrawPolygonSet2 + +opens a new window and draws `aps`, an instance of the `CGAL::Polygon_set_2` class. A call to this function is blocking, that is the program continues as soon as the user closes the window. This function requires CGAL_Qt5, and is only available if the flag CGAL_USE_BASIC_VIEWER is defined at compile time. +\tparam PS an instance of the `CGAL::Polygon_set_2` class. +\param aps the polygon set to draw. + +*/ +template +void draw(const PS& aps); + +} /* end namespace CGAL */ diff --git a/Boolean_set_operations_2/doc/Boolean_set_operations_2/PackageDescription.txt b/Boolean_set_operations_2/doc/Boolean_set_operations_2/PackageDescription.txt index 9e3884bed4b..7c3b7b13e71 100644 --- a/Boolean_set_operations_2/doc/Boolean_set_operations_2/PackageDescription.txt +++ b/Boolean_set_operations_2/doc/Boolean_set_operations_2/PackageDescription.txt @@ -6,6 +6,14 @@ /// The namespace containing concepts specific to 2D Boolean Set Operations. namespace ArrDirectionalTraits {} +/*! + \code + #include + \endcode +*/ +/// \defgroup PkgDrawPolygonSet2 Draw a 2D Polygon Set +/// \ingroup PkgBooleanSetOperations2Ref + /*! \addtogroup PkgBooleanSetOperations2Ref \todo check generated documentation @@ -62,4 +70,7 @@ containment predicates. - \link boolean_oriented_side `CGAL::oriented_side()` \endlink - \link boolean_connect_holes `CGAL::connect_holes()` \endlink +\cgalCRPSection{Draw a Polygon_set_2} +- \link PkgDrawPolygonSet2 CGAL::draw() \endlink + */ diff --git a/Boolean_set_operations_2/doc/Boolean_set_operations_2/examples.txt b/Boolean_set_operations_2/doc/Boolean_set_operations_2/examples.txt index 3ce0aadd4d0..46d981d80c8 100644 --- a/Boolean_set_operations_2/doc/Boolean_set_operations_2/examples.txt +++ b/Boolean_set_operations_2/doc/Boolean_set_operations_2/examples.txt @@ -5,6 +5,7 @@ \example Boolean_set_operations_2/conic_traits_adapter.cpp \example Boolean_set_operations_2/connect_polygon.cpp \example Boolean_set_operations_2/do_intersect.cpp +\example Boolean_set_operations_2/draw_polygon_set.cpp \example Boolean_set_operations_2/dxf_union.cpp \example Boolean_set_operations_2/sequence.cpp \example Boolean_set_operations_2/set_union.cpp diff --git a/Boolean_set_operations_2/examples/Boolean_set_operations_2/draw_polygon_set.cpp b/Boolean_set_operations_2/examples/Boolean_set_operations_2/draw_polygon_set.cpp new file mode 100644 index 00000000000..bfd44d57b02 --- /dev/null +++ b/Boolean_set_operations_2/examples/Boolean_set_operations_2/draw_polygon_set.cpp @@ -0,0 +1,47 @@ +/*! \file draw_polygon_set.cpp + * Drawing a polygon set. + */ + +#include +#include +#include +#include +#include + +typedef CGAL::Exact_predicates_exact_constructions_kernel K; +typedef CGAL::Polygon_2 Polygon_2; +typedef CGAL::Polygon_with_holes_2 Polygon_with_holes_2; +typedef CGAL::Polygon_set_2 Polygon_set_2; +typedef CGAL::Point_2 Point_2; + +Polygon_2 rectangle(int l) +{ + // Create a rectangle with given side length. + Polygon_2 P; + P.push_back(Point_2(-l,-l)); + P.push_back(Point_2(l,-l)); + P.push_back(Point_2(l,l)); + P.push_back(Point_2(-l,l)); + + return P; +} + +int main() +{ + // Create a large rectangle A, with a hole and a smaller rectangle + // B inside A's hole. + Polygon_with_holes_2 A(rectangle(3)); + Polygon_2 H(rectangle(2)); + H.reverse_orientation(); + A.add_hole(H); + Polygon_2 B(rectangle(1)); + + // Add them to a polygon set and draw it. + Polygon_set_2 S; + S.insert(A); + S.insert(B); + + CGAL::draw(S); + + return 0; +} diff --git a/Boolean_set_operations_2/include/CGAL/draw_polygon_set_2.h b/Boolean_set_operations_2/include/CGAL/draw_polygon_set_2.h new file mode 100644 index 00000000000..c4ae09c9b30 --- /dev/null +++ b/Boolean_set_operations_2/include/CGAL/draw_polygon_set_2.h @@ -0,0 +1,94 @@ +// Copyright (c) 1997 +// Utrecht University (The Netherlands), +// ETH Zurich (Switzerland), +// INRIA Sophia-Antipolis (France), +// Max-Planck-Institute Saarbruecken (Germany), +// and Tel-Aviv University (Israel). All rights reserved. +// +// This file is part of CGAL (www.cgal.org) +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial +// +// +// Author(s) : Guillaume Damiand + +#ifndef CGAL_DRAW_POLYGON_SET_2_H +#define CGAL_DRAW_POLYGON_SET_2_H + +#include + +#ifdef DOXYGEN_RUNNING +namespace CGAL { + +/*! +\ingroup PkgDrawPolygonSet2 + +opens a new window and draws `aps`, an instance of the `CGAL::Polygon_set_2` class. A call to this function is blocking, that is the program continues as soon as the user closes the window. This function requires CGAL_Qt5, and is only available if the flag CGAL_USE_BASIC_VIEWER is defined at compile time. +\tparam PS an instance of the `CGAL::Polygon_set_2` class. +\param aps the polygon set to draw. + +*/ +template +void draw(const PS& aps); + +} /* namespace CGAL */ +#endif + +#ifdef CGAL_USE_BASIC_VIEWER +#include + +namespace CGAL +{ + +template +class SimplePolygonSet2ViewerQt : + public SimplePolygonWithHoles2ViewerQt +{ + typedef SimplePolygonWithHoles2ViewerQt Base; + +public: + SimplePolygonSet2ViewerQt(QWidget* parent, const PS2& aps2, + const char* title="Basic Polygon_set_2 Viewer") : + Base(parent, title) + { + const int n = aps2.number_of_polygons_with_holes(); + typename PS2::Polygon_with_holes_2 polygons[n]; + aps2.polygons_with_holes(polygons); + + for (typename PS2::Polygon_with_holes_2& P: polygons) { + Base::compute_elements(P); + } + } +}; + +// Specialization of draw function. +template +void draw(const CGAL::Polygon_set_2& aps2, + const char* title="Polygon_set_2 Basic Viewer") +{ +#if defined(CGAL_TEST_SUITE) + bool cgal_test_suite=true; +#else + bool cgal_test_suite=qEnvironmentVariableIsSet("CGAL_TEST_SUITE"); +#endif + + if (!cgal_test_suite) + { + CGAL::Qt::init_ogl_context(4,3); + int argc=1; + const char* argv[2]={"t2_viewer","\0"}; + QApplication app(argc,const_cast(argv)); + SimplePolygonSet2ViewerQt > + mainwindow(app.activeWindow(), aps2, title); + mainwindow.show(); + app.exec(); + } +} + +} // End namespace CGAL + +#endif // CGAL_USE_BASIC_VIEWER + +#endif // CGAL_DRAW_POLYGON_SET_2_H diff --git a/Polygon/include/CGAL/draw_polygon_with_holes_2.h b/Polygon/include/CGAL/draw_polygon_with_holes_2.h index 7b420eea9b6..f3a38486b37 100644 --- a/Polygon/include/CGAL/draw_polygon_with_holes_2.h +++ b/Polygon/include/CGAL/draw_polygon_with_holes_2.h @@ -44,7 +44,7 @@ void draw(const PH& aph); namespace CGAL { -// Viewer class for Polygon_2 +// Viewer class for Polygon_with_holes_2 template class SimplePolygonWithHoles2ViewerQt : public Basic_viewer_qt { @@ -52,16 +52,25 @@ class SimplePolygonWithHoles2ViewerQt : public Basic_viewer_qt typedef typename P2::General_polygon_2::Point_2 Point; public: + /// Construct the viewer without drawing anything. + /// @param title the title of the window + SimplePolygonWithHoles2ViewerQt(QWidget* parent, + const char* title="Basic Polygon_with_holes_2 Viewer") : + Base(parent, title, true, true, true, false, false) + { + clear(); + } + /// Construct the viewer. /// @param ap2 the polygon to view /// @param title the title of the window SimplePolygonWithHoles2ViewerQt(QWidget* parent, const P2& ap2, const char* title="Basic Polygon_with_holes_2 Viewer") : // First draw: vertices; edges, faces; multi-color; no inverse normal - Base(parent, title, true, true, true, false, false), - p2(ap2) + Base(parent, title, true, true, true, false, false) { - compute_elements(); + clear(); + compute_elements(ap2); } protected: @@ -85,10 +94,8 @@ protected: add_segment(*prev, *(p.vertices_begin())); } - void compute_elements() + void compute_elements(const P2& p2) { - clear(); - if (p2.outer_boundary().is_empty()) return; CGAL::IO::Color c(75,160,255); @@ -120,9 +127,6 @@ protected: // Call the base method to process others/classicals key Base::keyPressEvent(e); } - -protected: - const P2& p2; }; // Specialization of draw function. From 3728852d473f28024eb5265b94b8414bbd20b1f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loriot?= Date: Thu, 23 Sep 2021 10:04:35 +0200 Subject: [PATCH 2/4] fix cmake --- .../Boolean_set_operations_2/CMakeLists.txt | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/Boolean_set_operations_2/examples/Boolean_set_operations_2/CMakeLists.txt b/Boolean_set_operations_2/examples/Boolean_set_operations_2/CMakeLists.txt index 4d170cfa0eb..515afd0ff30 100644 --- a/Boolean_set_operations_2/examples/Boolean_set_operations_2/CMakeLists.txt +++ b/Boolean_set_operations_2/examples/Boolean_set_operations_2/CMakeLists.txt @@ -4,9 +4,11 @@ cmake_minimum_required(VERSION 3.1...3.20) project(Boolean_set_operations_2_Examples) -find_package(CGAL REQUIRED COMPONENTS Core) +find_package(CGAL REQUIRED COMPONENTS Core OPTIONAL_COMPONENTS Qt5) -include(${CGAL_USE_FILE}) +if(CGAL_Qt5_FOUND) + add_definitions(-DCGAL_USE_BASIC_VIEWER -DQT_NO_KEYWORDS) +endif() # create a target per cppfile file( @@ -16,3 +18,12 @@ file( foreach(cppfile ${cppfiles}) create_single_source_cgal_program("${cppfile}") endforeach() + +if(CGAL_Qt5_FOUND) + target_link_libraries(draw_polygon_set PUBLIC CGAL::CGAL_Qt5) +else() + message( + STATUS + "NOTICE: The example draw_polygon_set requires Qt and drawing will be disabled." + ) +endif() From 280ae00a949082b623ef2d7fd09e48c4b07ca447 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loriot?= Date: Thu, 23 Sep 2021 12:05:20 +0200 Subject: [PATCH 3/4] add new dependancy --- .../package_info/Boolean_set_operations_2/dependencies | 1 + 1 file changed, 1 insertion(+) diff --git a/Boolean_set_operations_2/package_info/Boolean_set_operations_2/dependencies b/Boolean_set_operations_2/package_info/Boolean_set_operations_2/dependencies index df17bf59f12..a4d2b53c7b3 100644 --- a/Boolean_set_operations_2/package_info/Boolean_set_operations_2/dependencies +++ b/Boolean_set_operations_2/package_info/Boolean_set_operations_2/dependencies @@ -8,6 +8,7 @@ Circulator Distance_2 Distance_3 Filtered_kernel +GraphicsView HalfedgeDS Hash_map Homogeneous_kernel From 29464cb974b9faf8ac36b4af377438539a755aef Mon Sep 17 00:00:00 2001 From: Dimitris Papavasiliou Date: Fri, 24 Sep 2021 22:16:37 +0300 Subject: [PATCH 4/4] Fix polygon set drawing functionality. --- Boolean_set_operations_2/include/CGAL/draw_polygon_set_2.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Boolean_set_operations_2/include/CGAL/draw_polygon_set_2.h b/Boolean_set_operations_2/include/CGAL/draw_polygon_set_2.h index c4ae09c9b30..9e994a50922 100644 --- a/Boolean_set_operations_2/include/CGAL/draw_polygon_set_2.h +++ b/Boolean_set_operations_2/include/CGAL/draw_polygon_set_2.h @@ -53,9 +53,8 @@ public: const char* title="Basic Polygon_set_2 Viewer") : Base(parent, title) { - const int n = aps2.number_of_polygons_with_holes(); - typename PS2::Polygon_with_holes_2 polygons[n]; - aps2.polygons_with_holes(polygons); + std::vector polygons; + aps2.polygons_with_holes(std::back_inserter(polygons)); for (typename PS2::Polygon_with_holes_2& P: polygons) { Base::compute_elements(P);