move multipolygon to polygon package

This commit is contained in:
Ken Arroyo Ohori 2023-08-24 15:59:19 +02:00
parent 1e77a29003
commit 4613aa78a4
15 changed files with 247 additions and 39 deletions

View File

@ -1,4 +1,4 @@
/*! \ingroup PkgPolygonRepairConcepts
/*! \ingroup PkgPolygon2Concepts
* \cgalConcept
*
* \cgalRefines{CopyConstructible,Assignable,DefaultConstructible}

View File

@ -20,7 +20,13 @@
\endcode
*/
/// \defgroup PkgDrawPolygonWithHoles2 Draw a 2D Polygon with Holes
/// \ingroup PkgPolygon2Ref
/*!
\code
#include <CGAL/draw_multipolygon_with_holes_2.h>
\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<PolygonTraits_2, Container>`
- `CGAL::Polygon_with_holes_2<PolygonTraits_2,Container>`
- `CGAL::General_polygon_with_holes_2<Polygon>`
- `CGAL::Multipolygon_with_holes_2<Polygon>`
\cgalCRPSection{Global Functions}
- `CGAL::area_2()`
@ -71,4 +79,7 @@
\cgalCRPSection{Draw a Polygon_with_holes_2}
- \link PkgDrawPolygonWithHoles2 CGAL::draw<PH>() \endlink
\cgalCRPSection{Draw a Multipolygon_with_holes_2}
- \link PkgDrawMultipolygonWithHoles2 CGAL::draw<MPH>() \endlink
*/

View File

@ -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<P>() \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<PH>() \endlink).
A polygon can be visualized by calling the \link PkgDrawPolygon2 CGAL::draw<P>() \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<PH>() \endlink and \link PkgDrawMultipolygonWithHoles2
CGAL::draw<MPH>() \endlink.
\cgalExample{Polygon/draw_polygon.cpp}

View File

@ -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
*/

View File

@ -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()

View File

@ -2,7 +2,7 @@
#include <sstream>
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Polygon_repair/draw_multipolygon_with_holes_2.h>
#include <CGAL/draw_multipolygon_with_holes_2.h>
#include <CGAL/IO/WKT.h>
using Kernel = CGAL::Exact_predicates_inexact_constructions_kernel;

View File

@ -1,5 +1,5 @@
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Polygon_repair/Multipolygon_with_holes_2.h>
#include <CGAL/Multipolygon_with_holes_2.h>
using Kernel = CGAL::Exact_predicates_inexact_constructions_kernel;
using Point_2 = Kernel::Point_2;

View File

@ -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 <k.ohori@tudelft.nl>
#ifndef CGAL_MULTIPOLYGON_WITH_HOLES_2_H
#define CGAL_MULTIPOLYGON_WITH_HOLES_2_H
#include <CGAL/license/Polygon_repair.h>
#include <CGAL/Polygon_with_holes_2.h>
namespace CGAL {

View File

@ -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 <k.ohori@tudelft.nl>
// Guillaume Damiand <guillaume.damiand@liris.cnrs.fr>
#ifndef CGAL_DRAW_MULTIPOLYGON_WITH_HOLES_2_H
#define CGAL_DRAW_MULTIPOLYGON_WITH_HOLES_2_H
#include <CGAL/Qt/Basic_viewer_qt.h>
#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 <typename MPH>
void draw(const MPH& aph);
} /* namespace CGAL */
#endif
#ifdef CGAL_USE_BASIC_VIEWER
#include <CGAL/Qt/init_ogl_context.h>
#include <CGAL/Multipolygon_with_holes_2.h>
namespace CGAL {
// Viewer class for Multipolygon_with_holes_2
template <typename Multipolygon>
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<class T, class C>
void draw(const CGAL::Multipolygon_with_holes_2<T, C>& 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<T, C>;
using Viewer = Mpwh_2_basic_viewer_qt<Mpwh>;
CGAL::Qt::init_ogl_context(4,3);
int argc = 1;
const char* argv[2] = {"t2_viewer", nullptr};
QApplication app(argc, const_cast<char**>(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

View File

@ -8,14 +8,6 @@
/// \defgroup PkgPolygonRepairFunctions Functions
/// \ingroup PkgPolygonRepairRef
/*!
\code
#include <CGAL/draw_multipolygon_with_holes_2.h>
\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<Polygon>`
- `CGAL::Polygon_repair`
\cgalCRPSection{Functions}
- `CGAL::Polygon_repair::repair()`
\cgalCRPSection{Draw a Multipolygon_with_holes_2}
- \link PkgDrawMultipolygonWithHoles2 CGAL::draw<MPH>() \endlink
*/

View File

@ -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
*/

View File

@ -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()
endforeach()

View File

@ -18,9 +18,9 @@
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Polygon_2.h>
#include <CGAL/Polygon_with_holes_2.h>
#include <CGAL/Multipolygon_with_holes_2.h>
#include <CGAL/Constrained_Delaunay_triangulation_2.h>
#include <CGAL/Polygon_repair/Multipolygon_with_holes_2.h>
#include <CGAL/Polygon_repair/Triangulation_face_base_with_repair_info_2.h>
#include <CGAL/Polygon_repair/Triangulation_with_odd_even_constraints_2.h>

View File

@ -7,7 +7,7 @@
#include <CGAL/Polygon_repair/Polygon_repair.h>
#include <CGAL/draw_polygon_2.h>
#include <CGAL/draw_polygon_with_holes_2.h>
#include <CGAL/Polygon_repair/draw_multipolygon_with_holes_2.h>
#include <CGAL/draw_multipolygon_with_holes_2.h>
#include <CGAL/IO/WKT.h>
using Kernel = CGAL::Exact_predicates_inexact_constructions_kernel;

View File

@ -19,7 +19,7 @@
#include <CGAL/Point_3.h>
#include <CGAL/Polygon_2.h>
#include <CGAL/Polygon_with_holes_2.h>
#include <CGAL/Polygon_repair/Multipolygon_with_holes_2.h>
#include <CGAL/Multipolygon_with_holes_2.h>
#include <CGAL/IO/WKT/traits_point.h>
#include <CGAL/IO/WKT/traits_point_3.h>