diff --git a/Polygon_repair/doc/Polygon_repair/Concepts/MultiPolygonWithHoles_2.h b/Polygon/doc/Polygon/Concepts/MultiPolygonWithHoles_2.h similarity index 97% rename from Polygon_repair/doc/Polygon_repair/Concepts/MultiPolygonWithHoles_2.h rename to Polygon/doc/Polygon/Concepts/MultiPolygonWithHoles_2.h index d7f037be4d6..1c315df5a6b 100644 --- a/Polygon_repair/doc/Polygon_repair/Concepts/MultiPolygonWithHoles_2.h +++ b/Polygon/doc/Polygon/Concepts/MultiPolygonWithHoles_2.h @@ -1,4 +1,4 @@ -/*! \ingroup PkgPolygonRepairConcepts +/*! \ingroup PkgPolygon2Concepts * \cgalConcept * * \cgalRefines{CopyConstructible,Assignable,DefaultConstructible} diff --git a/Polygon/doc/Polygon/PackageDescription.txt b/Polygon/doc/Polygon/PackageDescription.txt index 1d48e74493c..7748ee535ee 100644 --- a/Polygon/doc/Polygon/PackageDescription.txt +++ b/Polygon/doc/Polygon/PackageDescription.txt @@ -20,7 +20,13 @@ \endcode */ /// \defgroup PkgDrawPolygonWithHoles2 Draw a 2D Polygon with Holes -/// \ingroup PkgPolygon2Ref + +/*! + \code + #include + \endcode +*/ +/// \defgroup PkgDrawMultipolygonWithHoles2 Draw a 2D Multipolygon with Holes /*! \addtogroup PkgPolygon2Ref @@ -46,11 +52,13 @@ \cgalCRPSection{Concepts} - `PolygonTraits_2` - `GeneralPolygonWithHoles_2` +- `MultipolygonWithHoles_2` \cgalCRPSection{Classes} - `CGAL::Polygon_2` - `CGAL::Polygon_with_holes_2` - `CGAL::General_polygon_with_holes_2` +- `CGAL::Multipolygon_with_holes_2` \cgalCRPSection{Global Functions} - `CGAL::area_2()` @@ -71,4 +79,7 @@ \cgalCRPSection{Draw a Polygon_with_holes_2} - \link PkgDrawPolygonWithHoles2 CGAL::draw() \endlink +\cgalCRPSection{Draw a Multipolygon_with_holes_2} +- \link PkgDrawMultipolygonWithHoles2 CGAL::draw() \endlink + */ diff --git a/Polygon/doc/Polygon/Polygon.txt b/Polygon/doc/Polygon/Polygon.txt index b21d57325e7..9e50406194b 100644 --- a/Polygon/doc/Polygon/Polygon.txt +++ b/Polygon/doc/Polygon/Polygon.txt @@ -82,7 +82,8 @@ vertices. It additionally provides a member function `Polygon_2::vertices()` tha \subsection subsecPolygonDraw Draw a Polygon -A polygon can be visualized by calling the \link PkgDrawPolygon2 CGAL::draw

() \endlink function as shown in the following example. This function opens a new window showing the given polygon. A call to this function is blocking, that is the program continues as soon as the user closes the window (a version exists for polygon with holes, cf. \link PkgDrawPolygonWithHoles2 CGAL::draw() \endlink). +A polygon can be visualized by calling the \link PkgDrawPolygon2 CGAL::draw

() \endlink function as shown in the following example. This function opens a new window showing the given polygon. A call to this function is blocking, that is the program continues as soon as the user closes the window. Versions for polygons with holes and multipolygons with holes also exist, cf. \link PkgDrawPolygonWithHoles2 CGAL::draw() \endlink and \link PkgDrawMultipolygonWithHoles2 +CGAL::draw() \endlink. \cgalExample{Polygon/draw_polygon.cpp} diff --git a/Polygon/doc/Polygon/examples.txt b/Polygon/doc/Polygon/examples.txt index 3a608da09f4..2341aa5721d 100644 --- a/Polygon/doc/Polygon/examples.txt +++ b/Polygon/doc/Polygon/examples.txt @@ -7,4 +7,6 @@ \example Stream_support/Polygon_WKT.cpp \example Polygon/draw_polygon.cpp \example Polygon/draw_polygon_with_holes.cpp +\example Polygon/multipolygon.cpp +\example Polygon/draw_multipolygon_with_holes.cpp */ diff --git a/Polygon/examples/Polygon/CMakeLists.txt b/Polygon/examples/Polygon/CMakeLists.txt index c9fdf0aa007..e774514708e 100644 --- a/Polygon/examples/Polygon/CMakeLists.txt +++ b/Polygon/examples/Polygon/CMakeLists.txt @@ -18,4 +18,5 @@ endforeach() if(CGAL_Qt5_FOUND) target_link_libraries(draw_polygon PUBLIC CGAL::CGAL_Basic_viewer) target_link_libraries(draw_polygon_with_holes PUBLIC CGAL::CGAL_Basic_viewer) + target_link_libraries(draw_multipolygon_with_holes PUBLIC CGAL::CGAL_Basic_viewer) endif() diff --git a/Polygon_repair/examples/Polygon_repair/draw_multipolygon.cpp b/Polygon/examples/Polygon/draw_multipolygon_with_holes.cpp similarity index 90% rename from Polygon_repair/examples/Polygon_repair/draw_multipolygon.cpp rename to Polygon/examples/Polygon/draw_multipolygon_with_holes.cpp index 3451b98de51..5db6ececb9e 100644 --- a/Polygon_repair/examples/Polygon_repair/draw_multipolygon.cpp +++ b/Polygon/examples/Polygon/draw_multipolygon_with_holes.cpp @@ -2,7 +2,7 @@ #include #include -#include +#include #include using Kernel = CGAL::Exact_predicates_inexact_constructions_kernel; diff --git a/Polygon_repair/examples/Polygon_repair/multipolygon.cpp b/Polygon/examples/Polygon/multipolygon.cpp similarity index 94% rename from Polygon_repair/examples/Polygon_repair/multipolygon.cpp rename to Polygon/examples/Polygon/multipolygon.cpp index ce0cdf27f41..b98a6fda3cf 100644 --- a/Polygon_repair/examples/Polygon_repair/multipolygon.cpp +++ b/Polygon/examples/Polygon/multipolygon.cpp @@ -1,5 +1,5 @@ #include -#include +#include using Kernel = CGAL::Exact_predicates_inexact_constructions_kernel; using Point_2 = Kernel::Point_2; diff --git a/Polygon_repair/include/CGAL/Polygon_repair/Multipolygon_with_holes_2.h b/Polygon/include/CGAL/Multipolygon_with_holes_2.h similarity index 91% rename from Polygon_repair/include/CGAL/Polygon_repair/Multipolygon_with_holes_2.h rename to Polygon/include/CGAL/Multipolygon_with_holes_2.h index 2035b8fb84c..d2744339c7e 100644 --- a/Polygon_repair/include/CGAL/Polygon_repair/Multipolygon_with_holes_2.h +++ b/Polygon/include/CGAL/Multipolygon_with_holes_2.h @@ -1,19 +1,22 @@ -// Copyright (c) 2023 GeometryFactory. -// All rights reserved. +// Copyright (c) 2005 +// 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). +// This file is part of CGAL (www.cgal.org) // // $URL$ // $Id$ -// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-Commercial +// SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial // -// Author(s) : Ken Arroyo Ohori +// +// Author(s): Ken Arroyo Ohori #ifndef CGAL_MULTIPOLYGON_WITH_HOLES_2_H #define CGAL_MULTIPOLYGON_WITH_HOLES_2_H -#include - #include namespace CGAL { diff --git a/Polygon/include/CGAL/draw_multipolygon_with_holes_2.h b/Polygon/include/CGAL/draw_multipolygon_with_holes_2.h new file mode 100644 index 00000000000..814723411c7 --- /dev/null +++ b/Polygon/include/CGAL/draw_multipolygon_with_holes_2.h @@ -0,0 +1,211 @@ +// 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) : Ken Arroyo Ohori +// Guillaume Damiand + +#ifndef CGAL_DRAW_MULTIPOLYGON_WITH_HOLES_2_H +#define CGAL_DRAW_MULTIPOLYGON_WITH_HOLES_2_H + +#include + +#ifdef DOXYGEN_RUNNING +namespace CGAL { + +/*! + * \ingroup PkgDrawMultipolygonWithHoles2 + * + * opens a new window and draws `aph`, an instance of the + * `CGAL::Multipolygon_with_holes_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 macro + * `CGAL_USE_BASIC_VIEWER` is defined. Linking with the cmake target + * `CGAL::CGAL_Basic_viewer` will link with `CGAL_Qt5` and add the definition + * `CGAL_USE_BASIC_VIEWER`. + * \tparam PH an instance of the `CGAL::Multipolygon_with_holes_2` class. + * \param aph the multipolygon with holes to draw. + */ + +template +void draw(const MPH& aph); + +} /* namespace CGAL */ + +#endif + +#ifdef CGAL_USE_BASIC_VIEWER + +#include +#include + +namespace CGAL { + +// Viewer class for Multipolygon_with_holes_2 +template +class Mpwh_2_basic_viewer_qt : public Basic_viewer_qt { + using Base = Basic_viewer_qt; + using Mpwh = Multipolygon; + using Pwh = typename Mpwh::Polygon_with_holes_2; + using Pgn = typename Mpwh::Polygon_2; + using Pnt = typename Pgn::Point_2; + +public: + /// Construct the viewer. + /// @param parent the active window to draw + /// @param mpwh the multipolygon to view + /// @param title the title of the window + Mpwh_2_basic_viewer_qt(QWidget* parent, const Mpwh& mpwh, + const char* title = "Basic Multipolygon_with_holes_2 Viewer") : + Base(parent, title, true, true, true, false, false), + m_mpwh(mpwh) { + if (mpwh.number_of_polygons() == 0) return; + + // mimic the computation of Camera::pixelGLRatio() + auto bbox = bounding_box(); + CGAL::qglviewer::Vec minv(bbox.xmin(), bbox.ymin(), 0); + CGAL::qglviewer::Vec maxv(bbox.xmax(), bbox.ymax(), 0); + auto diameter = (maxv - minv).norm(); + m_pixel_ratio = diameter / m_height; + } + + /*! Intercept the resizing of the window. + */ + virtual void resizeGL(int width, int height) { + CGAL::QGLViewer::resizeGL(width, height); + m_width = width; + m_height = height; + CGAL::qglviewer::Vec p; + auto ratio = camera()->pixelGLRatio(p); + m_pixel_ratio = ratio; + add_elements(); + } + + /*! Obtain the pixel ratio. + */ + double pixel_ratio() const { return m_pixel_ratio; } + + /*! Compute the bounding box. + */ + CGAL::Bbox_2 bounding_box() { + Bbox_2 bbox; + if (m_mpwh.number_of_polygons() > 0) bbox = m_mpwh.polygons().front().outer_boundary().bbox(); + for (auto const& pwh: m_mpwh.polygons()) { + bbox += pwh.outer_boundary().bbox(); + } + return bbox; + } + + /*! Compute the elements of a multipolygon with holes. + */ + void add_elements() { + clear(); + + for (auto const& p: m_mpwh.polygons()) { + CGAL::IO::Color c(rand()%255,rand()%255,rand()%255); + face_begin(c); + + const Pnt* point_in_face; + const auto& outer_boundary = p.outer_boundary(); + compute_loop(outer_boundary, false); + point_in_face = &(outer_boundary.vertex(outer_boundary.size()-1)); + + for (auto it = p.holes_begin(); it != p.holes_end(); ++it) { + compute_loop(*it, true); + add_point_in_face(*point_in_face); + } + + face_end(); + } + } + +protected: + /*! Compute the face + */ + void compute_loop(const Pgn& p, bool hole) { + if (hole) add_point_in_face(p.vertex(p.size()-1)); + + auto prev = p.vertices_begin(); + auto it = prev; + add_point(*it); + add_point_in_face(*it); + for (++it; it != p.vertices_end(); ++it) { + add_segment(*prev, *it); // add segment with previous point + add_point(*it); + add_point_in_face(*it); // add point in face + prev = it; + } + + // Add the last segment between the last point and the first one + add_segment(*prev, *(p.vertices_begin())); + } + + virtual void keyPressEvent(QKeyEvent* e) { + // Test key pressed: + // const ::Qt::KeyboardModifiers modifiers = e->modifiers(); + // if ((e->key()==Qt::Key_PageUp) && (modifiers==Qt::NoButton)) { ... } + + // Call: * add_elements() if the model changed, followed by + // * redraw() if some viewing parameters changed that implies some + // modifications of the buffers + // (eg. type of normal, color/mono) + // * update() just to update the drawing + + // Call the base method to process others/classicals key + Base::keyPressEvent(e); + } + +private: + //! The window width in pixels. + int m_width = CGAL_BASIC_VIEWER_INIT_SIZE_X; + + //! The window height in pixels. + int m_height = CGAL_BASIC_VIEWER_INIT_SIZE_Y; + + //! The ratio between pixel and opengl units (in world coordinate system). + double m_pixel_ratio = 1; + + //! The polygon with holes to draw. + const Mpwh& m_mpwh; +}; + +// Specialization of draw function. +template +void draw(const CGAL::Multipolygon_with_holes_2& mpwh, + const char* title = "Multipolygon_with_holes_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) { + using Mpwh = CGAL::Multipolygon_with_holes_2; + using Viewer = Mpwh_2_basic_viewer_qt; + CGAL::Qt::init_ogl_context(4,3); + int argc = 1; + const char* argv[2] = {"t2_viewer", nullptr}; + QApplication app(argc, const_cast(argv)); + Viewer mainwindow(app.activeWindow(), mpwh, title); + mainwindow.add_elements(); + mainwindow.show(); + app.exec(); + } +} + +} // End namespace CGAL + +#endif // CGAL_USE_BASIC_VIEWER + +#endif // CGAL_DRAW_MULTIPOLYGON_WITH_HOLES_2_H diff --git a/Polygon_repair/doc/Polygon_repair/PackageDescription.txt b/Polygon_repair/doc/Polygon_repair/PackageDescription.txt index 4259a9f0808..0f63f0844b7 100644 --- a/Polygon_repair/doc/Polygon_repair/PackageDescription.txt +++ b/Polygon_repair/doc/Polygon_repair/PackageDescription.txt @@ -8,14 +8,6 @@ /// \defgroup PkgPolygonRepairFunctions Functions /// \ingroup PkgPolygonRepairRef -/*! - \code - #include - \endcode -*/ -/// \defgroup PkgDrawMultipolygonWithHoles2 Draw a 2D Multipolygon with holes -/// \ingroup PkgPolygonRepairRef - /*! \addtogroup PkgPolygonRepairRef \todo check generated documentation @@ -25,7 +17,7 @@ \cgalPkgSummaryBegin \cgalPkgAuthors{Ken Arroyo Ohori} -\cgalPkgDesc{The package provides a 2D multipolygon class and algorithms to repair 2D (multi)polygons. } +\cgalPkgDesc{The package provides algorithms to repair 2D (multi)polygons. } \cgalPkgManuals{Chapter_2D_Polygon_repair,PkgPolygonRepairRef} \cgalPkgSummaryEnd @@ -41,17 +33,10 @@ \cgalClassifedRefPages -\cgalCRPSection{Concepts} -- `MultipolygonWithHoles_2` - \cgalCRPSection{Classes} -- `CGAL::Multipolygon_with_holes_2` - `CGAL::Polygon_repair` \cgalCRPSection{Functions} - `CGAL::Polygon_repair::repair()` -\cgalCRPSection{Draw a Multipolygon_with_holes_2} -- \link PkgDrawMultipolygonWithHoles2 CGAL::draw() \endlink - */ diff --git a/Polygon_repair/doc/Polygon_repair/examples.txt b/Polygon_repair/doc/Polygon_repair/examples.txt index c0a82797236..1797f716577 100644 --- a/Polygon_repair/doc/Polygon_repair/examples.txt +++ b/Polygon_repair/doc/Polygon_repair/examples.txt @@ -1,6 +1,4 @@ /*! -\example Polygon_repair/multipolygon.cpp -\example Polygon_repair/draw_multipolygon.cpp \example Polygon_repair/repair_polygon_2.cpp \example Polygon_repair/write_labeled_triangulation.cpp */ diff --git a/Polygon_repair/examples/Polygon_repair/CMakeLists.txt b/Polygon_repair/examples/Polygon_repair/CMakeLists.txt index 930b4dc2567..4350cb89227 100644 --- a/Polygon_repair/examples/Polygon_repair/CMakeLists.txt +++ b/Polygon_repair/examples/Polygon_repair/CMakeLists.txt @@ -4,7 +4,7 @@ cmake_minimum_required(VERSION 3.1...3.23) project(Polygon_repair_Examples) -find_package(CGAL REQUIRED OPTIONAL_COMPONENTS Qt5) +find_package(CGAL REQUIRED) # create a target per cppfile file( @@ -13,8 +13,4 @@ file( ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp) foreach(cppfile ${cppfiles}) create_single_source_cgal_program("${cppfile}") -endforeach() - -if(CGAL_Qt5_FOUND) - target_link_libraries(draw_multipolygon PUBLIC CGAL::CGAL_Basic_viewer) -endif() \ No newline at end of file +endforeach() \ No newline at end of file diff --git a/Polygon_repair/include/CGAL/Polygon_repair/Polygon_repair.h b/Polygon_repair/include/CGAL/Polygon_repair/Polygon_repair.h index 6a06b95ac28..ac08e4ad0ef 100644 --- a/Polygon_repair/include/CGAL/Polygon_repair/Polygon_repair.h +++ b/Polygon_repair/include/CGAL/Polygon_repair/Polygon_repair.h @@ -18,9 +18,9 @@ #include #include #include +#include #include -#include #include #include diff --git a/Polygon_repair/test/Polygon_repair/draw_test_polygons.cpp b/Polygon_repair/test/Polygon_repair/draw_test_polygons.cpp index c20f298f847..db22777f457 100644 --- a/Polygon_repair/test/Polygon_repair/draw_test_polygons.cpp +++ b/Polygon_repair/test/Polygon_repair/draw_test_polygons.cpp @@ -7,7 +7,7 @@ #include #include #include -#include +#include #include using Kernel = CGAL::Exact_predicates_inexact_constructions_kernel; diff --git a/Stream_support/include/CGAL/IO/WKT.h b/Stream_support/include/CGAL/IO/WKT.h index 51cf67aea6c..ef8c7dee1f0 100644 --- a/Stream_support/include/CGAL/IO/WKT.h +++ b/Stream_support/include/CGAL/IO/WKT.h @@ -19,7 +19,7 @@ #include #include #include -#include +#include #include #include