mirror of https://github.com/CGAL/cgal
Add polygon set drawing functionality.
This commit is contained in:
parent
ebb719c8a4
commit
7f04082cfc
|
|
@ -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<class PS>
|
||||||
|
void draw(const PS& aps);
|
||||||
|
|
||||||
|
} /* end namespace CGAL */
|
||||||
|
|
@ -6,6 +6,14 @@
|
||||||
/// The namespace containing concepts specific to 2D Boolean Set Operations.
|
/// The namespace containing concepts specific to 2D Boolean Set Operations.
|
||||||
namespace ArrDirectionalTraits {}
|
namespace ArrDirectionalTraits {}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\code
|
||||||
|
#include <CGAL/draw_polygon_set_2.h>
|
||||||
|
\endcode
|
||||||
|
*/
|
||||||
|
/// \defgroup PkgDrawPolygonSet2 Draw a 2D Polygon Set
|
||||||
|
/// \ingroup PkgBooleanSetOperations2Ref
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\addtogroup PkgBooleanSetOperations2Ref
|
\addtogroup PkgBooleanSetOperations2Ref
|
||||||
\todo check generated documentation
|
\todo check generated documentation
|
||||||
|
|
@ -62,4 +70,7 @@ containment predicates.
|
||||||
- \link boolean_oriented_side `CGAL::oriented_side()` \endlink
|
- \link boolean_oriented_side `CGAL::oriented_side()` \endlink
|
||||||
- \link boolean_connect_holes `CGAL::connect_holes()` \endlink
|
- \link boolean_connect_holes `CGAL::connect_holes()` \endlink
|
||||||
|
|
||||||
|
\cgalCRPSection{Draw a Polygon_set_2}
|
||||||
|
- \link PkgDrawPolygonSet2 CGAL::draw<PS>() \endlink
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@
|
||||||
\example Boolean_set_operations_2/conic_traits_adapter.cpp
|
\example Boolean_set_operations_2/conic_traits_adapter.cpp
|
||||||
\example Boolean_set_operations_2/connect_polygon.cpp
|
\example Boolean_set_operations_2/connect_polygon.cpp
|
||||||
\example Boolean_set_operations_2/do_intersect.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/dxf_union.cpp
|
||||||
\example Boolean_set_operations_2/sequence.cpp
|
\example Boolean_set_operations_2/sequence.cpp
|
||||||
\example Boolean_set_operations_2/set_union.cpp
|
\example Boolean_set_operations_2/set_union.cpp
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,47 @@
|
||||||
|
/*! \file draw_polygon_set.cpp
|
||||||
|
* Drawing a polygon set.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
|
||||||
|
#include <CGAL/Polygon_2.h>
|
||||||
|
#include <CGAL/Polygon_with_holes_2.h>
|
||||||
|
#include <CGAL/Polygon_set_2.h>
|
||||||
|
#include <CGAL/draw_polygon_set_2.h>
|
||||||
|
|
||||||
|
typedef CGAL::Exact_predicates_exact_constructions_kernel K;
|
||||||
|
typedef CGAL::Polygon_2<K> Polygon_2;
|
||||||
|
typedef CGAL::Polygon_with_holes_2<K> Polygon_with_holes_2;
|
||||||
|
typedef CGAL::Polygon_set_2<K> Polygon_set_2;
|
||||||
|
typedef CGAL::Point_2<K> 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;
|
||||||
|
}
|
||||||
|
|
@ -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 <guillaume.damiand@liris.cnrs.fr>
|
||||||
|
|
||||||
|
#ifndef CGAL_DRAW_POLYGON_SET_2_H
|
||||||
|
#define CGAL_DRAW_POLYGON_SET_2_H
|
||||||
|
|
||||||
|
#include <CGAL/draw_polygon_with_holes_2.h>
|
||||||
|
|
||||||
|
#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<class PS>
|
||||||
|
void draw(const PS& aps);
|
||||||
|
|
||||||
|
} /* namespace CGAL */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef CGAL_USE_BASIC_VIEWER
|
||||||
|
#include <CGAL/Polygon_set_2.h>
|
||||||
|
|
||||||
|
namespace CGAL
|
||||||
|
{
|
||||||
|
|
||||||
|
template<class PS2>
|
||||||
|
class SimplePolygonSet2ViewerQt :
|
||||||
|
public SimplePolygonWithHoles2ViewerQt<typename PS2::Polygon_with_holes_2>
|
||||||
|
{
|
||||||
|
typedef SimplePolygonWithHoles2ViewerQt<typename PS2::Polygon_with_holes_2> 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<class T, class C>
|
||||||
|
void draw(const CGAL::Polygon_set_2<T, C>& 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<char**>(argv));
|
||||||
|
SimplePolygonSet2ViewerQt<CGAL::Polygon_set_2<T, C> >
|
||||||
|
mainwindow(app.activeWindow(), aps2, title);
|
||||||
|
mainwindow.show();
|
||||||
|
app.exec();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} // End namespace CGAL
|
||||||
|
|
||||||
|
#endif // CGAL_USE_BASIC_VIEWER
|
||||||
|
|
||||||
|
#endif // CGAL_DRAW_POLYGON_SET_2_H
|
||||||
|
|
@ -44,7 +44,7 @@ void draw(const PH& aph);
|
||||||
namespace CGAL
|
namespace CGAL
|
||||||
{
|
{
|
||||||
|
|
||||||
// Viewer class for Polygon_2
|
// Viewer class for Polygon_with_holes_2
|
||||||
template<class P2>
|
template<class P2>
|
||||||
class SimplePolygonWithHoles2ViewerQt : public Basic_viewer_qt
|
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;
|
typedef typename P2::General_polygon_2::Point_2 Point;
|
||||||
|
|
||||||
public:
|
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.
|
/// Construct the viewer.
|
||||||
/// @param ap2 the polygon to view
|
/// @param ap2 the polygon to view
|
||||||
/// @param title the title of the window
|
/// @param title the title of the window
|
||||||
SimplePolygonWithHoles2ViewerQt(QWidget* parent, const P2& ap2,
|
SimplePolygonWithHoles2ViewerQt(QWidget* parent, const P2& ap2,
|
||||||
const char* title="Basic Polygon_with_holes_2 Viewer") :
|
const char* title="Basic Polygon_with_holes_2 Viewer") :
|
||||||
// First draw: vertices; edges, faces; multi-color; no inverse normal
|
// First draw: vertices; edges, faces; multi-color; no inverse normal
|
||||||
Base(parent, title, true, true, true, false, false),
|
Base(parent, title, true, true, true, false, false)
|
||||||
p2(ap2)
|
|
||||||
{
|
{
|
||||||
compute_elements();
|
clear();
|
||||||
|
compute_elements(ap2);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
@ -85,10 +94,8 @@ protected:
|
||||||
add_segment(*prev, *(p.vertices_begin()));
|
add_segment(*prev, *(p.vertices_begin()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void compute_elements()
|
void compute_elements(const P2& p2)
|
||||||
{
|
{
|
||||||
clear();
|
|
||||||
|
|
||||||
if (p2.outer_boundary().is_empty()) return;
|
if (p2.outer_boundary().is_empty()) return;
|
||||||
|
|
||||||
CGAL::IO::Color c(75,160,255);
|
CGAL::IO::Color c(75,160,255);
|
||||||
|
|
@ -120,9 +127,6 @@ protected:
|
||||||
// Call the base method to process others/classicals key
|
// Call the base method to process others/classicals key
|
||||||
Base::keyPressEvent(e);
|
Base::keyPressEvent(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
|
||||||
const P2& p2;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Specialization of draw function.
|
// Specialization of draw function.
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue