Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Polygon repair using union and intersection #8510

Open
wants to merge 50 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
a41cd1c
import @afabri files for Boolean using CDT
sloriot Oct 1, 2024
69d56c5
const
afabri Oct 2, 2024
8af54f7
rename function
afabri Oct 3, 2024
ace1e7f
Add repair() with Non_zero_rule
afabri Oct 3, 2024
3076c16
Start changing the documentation
afabri Oct 3, 2024
80ffeac
labeled
afabri Oct 3, 2024
f6da27d
No need to include a kernel
afabri Oct 3, 2024
d03325b
Move Boolean.h
afabri Oct 4, 2024
e0ef774
Add code for repairing with a union or intersection rule
afabri Nov 5, 2024
8910d58
Fix CMakeLists
afabri Nov 5, 2024
a99dcc9
Use repair() with two new rules
afabri Nov 5, 2024
c835d10
Cleanup
afabri Nov 5, 2024
c6e6307
Cleanup
afabri Nov 5, 2024
0de379d
Fix example file name
afabri Nov 5, 2024
37e5922
Fix anchor
afabri Nov 5, 2024
4020165
cleanup
afabri Nov 6, 2024
a39d3cc
Fix example file name
afabri Nov 6, 2024
a494094
fix dependencies
afabri Nov 6, 2024
e4ce60c
Add winding.wkt
afabri Nov 6, 2024
b24f19c
fix warnings
sloriot Nov 6, 2024
78c8b44
Add free functions join() and intersection() for any combination of P…
afabri Nov 6, 2024
db684c7
make draw conditional
sloriot Nov 6, 2024
2385e58
fix warning + use verb for function name
sloriot Nov 6, 2024
c8aa6e4
Move demo in the Polygon_repair directory
afabri Nov 6, 2024
17af065
Document functions
afabri Nov 6, 2024
ead629c
User Manual
afabri Nov 7, 2024
bdb93ff
Documention
afabri Nov 7, 2024
4ff92c1
Documention
afabri Nov 7, 2024
64bc98d
add missing dependency
sloriot Nov 8, 2024
eddf0b6
fix compilation errors
sloriot Nov 8, 2024
53c9987
use polygonal domain as MPWH can be more than one poly
sloriot Nov 8, 2024
0639b48
Merge remote-tracking branch 'cgal/master'
sloriot Nov 8, 2024
b2b7de8
remove deps
sloriot Nov 12, 2024
b074e32
Fix demo
afabri Nov 14, 2024
ce3fe4f
Fix example
afabri Nov 14, 2024
f65b7f7
Adress warnings and errors in the testsuite
afabri Nov 15, 2024
fdf5150
Add ipe and svg figures
afabri Dec 10, 2024
215feb7
Add ipe and svg figures
afabri Dec 10, 2024
b050344
Add ipe and svg figures
afabri Dec 10, 2024
0f06b0a
Add ipe and svg figures
afabri Dec 10, 2024
42014bd
Reorganize User Manual
afabri Dec 10, 2024
98e4e5e
Reorganize User Manual
afabri Dec 10, 2024
aa004be
fix figures
afabri Dec 10, 2024
60a3343
Combine in a single paragraph
afabri Dec 10, 2024
e77a873
typo
afabri Dec 10, 2024
355315f
Merge remote-tracking branch 'cgal/master' into Polygon_repair-union_…
afabri Dec 12, 2024
927d52e
Add to changes.md
afabri Dec 12, 2024
ec1c645
Update Polygon_repair/include/CGAL/Polygon_repair/repair.h
afabri Jan 2, 2025
aabf975
Remove link
afabri Jan 2, 2025
9e9c710
Remove demo that compiles but needs major improvements to be of any use
afabri Jan 2, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ typedef CGAL::Polygon_with_holes_2<K> Polygon_with_holes;

template <typename K>
GraphicsViewPolygonWithHolesInput<K>::GraphicsViewPolygonWithHolesInput(QObject *parent, QGraphicsScene* s)
: GraphicsViewInput(parent), scene_(s), polygon_input(false)
: GraphicsViewInput(parent), polygon_input(false), scene_(s)
{
pwhItem = new CGAL::Qt::PolygonWithHolesGraphicsItem<Polygon_with_holes>(&pwh);
pwhItem->setBrush(::Qt::yellow);
Expand Down Expand Up @@ -151,7 +151,7 @@ GraphicsViewPolygonWithHolesInput<K>::processInput(CGAL::Object o)

template <typename K>
void
GraphicsViewPolygonWithHolesInput<K>::keyPressEvent ( QKeyEvent * event )
GraphicsViewPolygonWithHolesInput<K>::keyPressEvent ( QKeyEvent * /* event */ )
{
}

Expand Down
4 changes: 4 additions & 0 deletions Installation/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@

- Introduces two traits decorators, namely `Arr_tracing_traits_2` and `Arr_counting_traits_2`, which can be used to extract debugging and informative metadata about the traits in use while a program is being executed.

### [Polygon Repair](https://doc.cgal.org/6.1/Manual/packages.html#PkgPolygonRepair)

- Add a the non-zero rule, as well as functions to compute the conservative inner and outer hull of similar polygons.

## [Release 6.0.1](https://github.com/CGAL/cgal/releases/tag/v6.0.1)

### [Poisson Surface Reconstruction](https://doc.cgal.org/6.0.1/Manual/packages.html#PkgPoissonSurfaceReconstruction3)
Expand Down
25 changes: 13 additions & 12 deletions Polygon/include/CGAL/Multipolygon_with_holes_2.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,29 +24,30 @@ namespace CGAL {
/*! \ingroup PkgPolygon2Ref
*
* The class `Multipolygon_with_holes_2` models the concept `MultipolygonWithHoles_2`.
* It is parameterized with two types (`Kernel` and `Container`) that are used to instantiate
* the types `Polygon_2<Kernel,Container>` and `Polygon_with_holes_2<Kernel,Container>`.
* It is parameterized with two types (`Kernel` and `Container_`) that are used to instantiate
* the types `Polygon_2<Kernel,Container_>` and `Polygon_with_holes_2<Kernel,Container_>`.
* The latter is used to represent each polygon with holes. The former is converted to the latter.
*
* \cgalModels{MultipolygonWithHoles_2}
*/
template <class Kernel,
class Container = std::vector<typename Kernel::Point_2>>
class Container_ = std::vector<typename Kernel::Point_2>>
class Multipolygon_with_holes_2 {
public:
/// \name Definition

/// @{

/// polygon type
using Polygon_2 = CGAL::Polygon_2<Kernel, Container>;
using Polygon_2 = CGAL::Polygon_2<Kernel, Container_>;

/// polygon with holes type
using Polygon_with_holes_2 = CGAL::Polygon_with_holes_2<Kernel, Container>;
using Polygon_with_holes_2 = CGAL::Polygon_with_holes_2<Kernel, Container_>;

/// @}

using Traits = Kernel;
using Container = Container_;
using value_type = Polygon_with_holes_2;
using Polygon_with_holes_container = std::deque<Polygon_with_holes_2>;

Expand Down Expand Up @@ -183,10 +184,10 @@ order.

\relates Multipolygon_with_holes_2
*/
template <class Kernel, class Container>
template <class Kernel, class Container_>
std::ostream& operator<<(std::ostream& os,
const Multipolygon_with_holes_2<Kernel, Container>& mp) {
typename Multipolygon_with_holes_2<Kernel, Container>::Polygon_with_holes_const_iterator i;
const Multipolygon_with_holes_2<Kernel, Container_>& mp) {
typename Multipolygon_with_holes_2<Kernel, Container_>::Polygon_with_holes_const_iterator i;

switch(IO::get_mode(os)) {
case IO::ASCII :
Expand Down Expand Up @@ -214,11 +215,11 @@ std::ostream& operator<<(std::ostream& os,
}
}

template <class Transformation, class Kernel, class Container>
Multipolygon_with_holes_2<Kernel, Container> transform(const Transformation& t,
const Multipolygon_with_holes_2<Kernel, Container>& mp)
template <class Transformation, class Kernel, class Container_>
Multipolygon_with_holes_2<Kernel, Container_> transform(const Transformation& t,
const Multipolygon_with_holes_2<Kernel, Container_>& mp)
{
Multipolygon_with_holes_2<Kernel, Container> result;
Multipolygon_with_holes_2<Kernel, Container_> result;
for(const auto& pwh : mp.polygons_with_holes()){
result.add_polygon_with_holes(transform(t, pwh));
}
Expand Down
94 changes: 47 additions & 47 deletions Polygon/include/CGAL/Polygon_2.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ namespace CGAL {
/// algorithms were used and what complexity they have.
///

template <class Traits_P, class Container_P
= std::vector<typename Traits_P::Point_2> >
template <class Traits_, class Container_
= std::vector<typename Traits_::Point_2> >
class Polygon_2 {

public:
Expand All @@ -70,33 +70,33 @@ class Polygon_2 {
/// @{

/// The traits type.
typedef Traits_P Traits;
typedef Traits_ Traits;
/// The container type.
typedef Container_P Container;
typedef Container_ Container;

/// The number type of the coordinates of the points of the polygon.
typedef typename Traits_P::FT FT;
typedef typename Traits_::FT FT;
/// The point type of the polygon.
typedef typename Traits_P::Point_2 Point_2;
typedef typename Traits_::Point_2 Point_2;
/// The type of a segment between two points of the polygon.
typedef typename Traits_P::Segment_2 Segment_2;
typedef typename Traits_::Segment_2 Segment_2;

/// @}

typedef typename Container_P::difference_type difference_type;
typedef typename Container_P::value_type value_type;
typedef typename Container_P::pointer pointer;
typedef typename Container_P::reference reference;
typedef typename Container_P::const_reference const_reference;
typedef typename Container_::difference_type difference_type;
typedef typename Container_::value_type value_type;
typedef typename Container_::pointer pointer;
typedef typename Container_::reference reference;
typedef typename Container_::const_reference const_reference;


//-------------------------------------------------------//
// this intermediary step is required by Sun C++ 4.1
typedef typename Container_P::iterator iterator;
typedef typename Container_P::const_iterator const_iterator;
typedef typename Container_::iterator iterator;
typedef typename Container_::const_iterator const_iterator;
//-------------------------------------------------------//
typedef typename Container::iterator Vertex_const_iterator;
typedef Polygon_circulator<Container_P> Vertex_const_circulator;
typedef Polygon_circulator<Container_> Vertex_const_circulator;

/// \name Iterators
///
Expand Down Expand Up @@ -141,11 +141,11 @@ class Polygon_2 {
//
#else
typedef Vertex_const_circulator Vertex_circulator;
typedef Polygon_2_edge_iterator<Traits_P,Container_P> Edge_const_iterator;
typedef Polygon_2_const_edge_circulator<Traits_P,
Container_P> Edge_const_circulator;
typedef Polygon_2_edge_iterator<Traits_,Container_> Edge_const_iterator;
typedef Polygon_2_const_edge_circulator<Traits_,
Container_> Edge_const_circulator;

typedef Polygon_2_edge_iterator<Traits_P,Container_P,
typedef Polygon_2_edge_iterator<Traits_,Container_,
Tag_false> Vertex_pair_iterator;

typedef Iterator_range<Edge_const_iterator> Edges;
Expand All @@ -162,7 +162,7 @@ class Polygon_2 {
Polygon_2(const Traits & p_traits) : traits(p_traits) {}

// Move constructor
// Polygon_2(Polygon_2<Traits_P,Container_P>&& polygon) = default;
// Polygon_2(Polygon_2<Traits_,Container_>&& polygon) = default;

/// Creates a polygon with vertices from the sequence
/// defined by the range \c [first,last).
Expand Down Expand Up @@ -260,7 +260,7 @@ class Polygon_2 {
{
if (size() <= 1)
return;
typename Container_P::iterator i = d_container.begin();
typename Container_::iterator i = d_container.begin();
std::reverse(++i, d_container.end());
}

Expand Down Expand Up @@ -500,32 +500,32 @@ class Polygon_2 {
{ return d_container.empty(); }

/// Returns a const reference to the sequence of vertices of the polygon.
const Container_P& container() const
const Container_& container() const
{ return d_container; }

/// Returns a reference to the sequence of vertices of the polygon.
Container_P& container()
Container_& container()
{ return d_container; }

/// Returns an iterator to the first vertex of the polygon.
typename Container_P::iterator begin()
typename Container_::iterator begin()
{
return container().begin();
}
/// Returns an iterator to the element after the last vertex of the polygon.
typename Container_P::iterator end()
typename Container_::iterator end()
{
return container().end();
}

/// Returns a const iterator to the first vertex of the polygon.
const typename Container_P::const_iterator begin() const
const typename Container_::const_iterator begin() const
{
return container().begin();
}

/// Returns a const iterator to the element after the last vertex of the polygon.
const typename Container_P::const_iterator end() const
const typename Container_::const_iterator end() const
{
return container().end();
}
Expand All @@ -544,14 +544,14 @@ class Polygon_2 {

/// @}

bool identical(const Polygon_2<Traits_P,Container_P> &q) const
bool identical(const Polygon_2<Traits_,Container_> &q) const
{ return this == &q; }

Traits_P const &traits_member() const { return traits;}
Traits_ const &traits_member() const { return traits;}

private:
Container_P d_container;
Traits_P traits;
Container_ d_container;
Traits_ traits;
};


Expand All @@ -563,23 +563,23 @@ class Polygon_2 {
/// equal to the vertices of `p1`. Note that the template argument
/// `%Container` of `p1` and `p2` may be different.
/// \memberof Polygon_2
template <class Traits_P, class Container1_P, class Container2_P>
bool operator==( const Polygon_2<Traits_P,Container1_P> &p1,
const Polygon_2<Traits_P,Container2_P> &p2 );
template <class Traits_, class Container1_P, class Container2_P>
bool operator==( const Polygon_2<Traits_,Container1_P> &p1,
const Polygon_2<Traits_,Container2_P> &p2 );

/// Test for inequality.
/// \memberof Polygon_2
template <class Traits_P, class Container1_P, class Container2_P>
template <class Traits_, class Container1_P, class Container2_P>
inline
bool
operator!=(const Polygon_2<Traits_P,Container1_P> &p1,
const Polygon_2<Traits_P,Container2_P> &p2);
operator!=(const Polygon_2<Traits_,Container1_P> &p1,
const Polygon_2<Traits_,Container2_P> &p2);

/// Returns the image of the polygon \c p under the transformation \c t.
/// \relates Polygon_2
template <class Transformation, class Traits_P, class Container_P>
Polygon_2<Traits_P,Container_P>
transform(const Transformation& t, const Polygon_2<Traits_P,Container_P>& p);
template <class Transformation, class Traits_, class Container_>
Polygon_2<Traits_,Container_>
transform(const Transformation& t, const Polygon_2<Traits_,Container_>& p);

/// @} // global operators

Expand All @@ -591,14 +591,14 @@ transform(const Transformation& t, const Polygon_2<Traits_P,Container_P>& p);
/// Reads a polygon from stream `is` and assigns it to `p`.
/// \pre The extract operator must be defined for `Point_2`.
/// \relates Polygon_2
template <class Traits_P, class Container_P>
std::istream &operator>>(std::istream &is, Polygon_2<Traits_P,Container_P>& p);
template <class Traits_, class Container_>
std::istream &operator>>(std::istream &is, Polygon_2<Traits_,Container_>& p);

/// Inserts the polygon `p` into the stream `os`.
/// \pre The insert operator must be defined for `Point_2`.
/// \relates Polygon_2
template <class Traits_P, class Container_P>
std::ostream &operator<<(std::ostream &os, const Polygon_2<Traits_P,Container_P>& p);
template <class Traits_, class Container_>
std::ostream &operator<<(std::ostream &os, const Polygon_2<Traits_,Container_>& p);

/// @} // IO

Expand All @@ -612,11 +612,11 @@ std::ostream &operator<<(std::ostream &os, const Polygon_2<Traits_P,Container_P>

namespace CGAL {

template <class Traits_P, class Container1_P, class Container2_P>
template <class Traits_, class Container1_P, class Container2_P>
inline
bool
operator!=(const Polygon_2<Traits_P,Container1_P> &x,
const Polygon_2<Traits_P,Container2_P> &y)
operator!=(const Polygon_2<Traits_,Container1_P> &x,
const Polygon_2<Traits_,Container2_P> &y)
{
return !(x==y);
}
Expand Down
21 changes: 11 additions & 10 deletions Polygon/include/CGAL/Polygon_with_holes_2.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,22 @@ namespace CGAL {

The class `Polygon_with_holes_2` models the concept `GeneralPolygonWithHoles_2`.
It represents a linear polygon with holes. It is parameterized with two
types (`Kernel` and `Container`) that are used to instantiate
the type `Polygon_2<Kernel,Container>`. This poygon type is used to
types (`Kernel` and `Container_`) that are used to instantiate
the type `Polygon_2<Kernel,Container_>`. This polygon type is used to
represent the outer boundary and the boundary of the holes (if any exist).

\cgalModels{GeneralPolygonWithHoles_2}

*/
template <class Kernel,
class Containter = std::vector<typename Kernel::Point_2> >
class Container_ = std::vector<typename Kernel::Point_2> >
class Polygon_with_holes_2 :
public General_polygon_with_holes_2<CGAL::Polygon_2<Kernel, Containter> >
public General_polygon_with_holes_2<CGAL::Polygon_2<Kernel, Container_> >
{
public:

typedef CGAL::Polygon_2<Kernel, Containter> Polygon_2;
typedef Kernel Traits;
typedef Container_ Container;
typedef CGAL::Polygon_2<Kernel, Container> Polygon_2;
typedef General_polygon_with_holes_2<Polygon_2> Base;
typedef typename Base::Hole_const_iterator Hole_const_iterator;
typedef typename Base::Size Size;
Expand Down Expand Up @@ -90,11 +91,11 @@ class Polygon_with_holes_2 :

};

template <class Transformation, class Kernel, class Container>
Polygon_with_holes_2<Kernel,Container> transform(const Transformation& t,
const Polygon_with_holes_2<Kernel,Container>& pwh)
template <class Transformation, class Kernel, class Container_>
Polygon_with_holes_2<Kernel,Container_> transform(const Transformation& t,
const Polygon_with_holes_2<Kernel,Container_>& pwh)
{
Polygon_with_holes_2<Kernel,Container> result(transform(t, pwh.outer_boundary()));
Polygon_with_holes_2<Kernel,Container_> result(transform(t, pwh.outer_boundary()));
for(const auto& hole : pwh.holes()){
result.add_hole(transform(t, hole));
}
Expand Down
10 changes: 8 additions & 2 deletions Polygon_repair/doc/Polygon_repair/PackageDescription.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
\cgalPkgAuthors{Ken Arroyo Ohori}
\cgalPkgDesc{This package provides algorithms to repair 2D polygons, polygons with holes,
and multipolygons with holes, by selecting faces of the arrangement of the input based on a selection rule.
Currently, only the even-odd rule is provided. }
The even-odd rule and the non-zero rule are provided for dealing with self intersections.
The %union and the %intersection rule enable to combine similar polygons. }
\cgalPkgManuals{Chapter_2D_Polygon_repair,PkgPolygonRepairRef}
\cgalPkgSummaryEnd

Expand All @@ -32,7 +33,12 @@ Currently, only the even-odd rule is provided. }

\cgalCRPSection{Functions}
- `CGAL::Polygon_repair::repair()`
- `CGAL::Polygon_repair::join()`
- `CGAL::Polygon_repair::intersect()`

\cgalCRPSection{Simplification Rules}
\cgalCRPSection{Repair Rules}
- `CGAL::Polygon_repair::Even_odd_rule`
- `CGAL::Polygon_repair::Non_zero_rule`
- `CGAL::Polygon_repair::Union_rule`
- `CGAL::Polygon_repair::Intersection_rule`
*/
Loading
Loading