CGAL 6.1 - 2D Polygon Repair
Loading...
Searching...
No Matches
Polygon_repair/repair_union_intersect_2.cpp
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Polygon_with_holes_2.h>
#include <CGAL/Multipolygon_with_holes_2.h>
#ifdef CGAL_USE_BASIC_VIEWER
#include <CGAL/draw_multipolygon_with_holes_2.h>
#endif
#include <CGAL/Polygon_repair/repair.h>
#include <CGAL/IO/WKT.h>
#include <iostream>
#include <sstream>
using Point_2 = K::Point_2;
using Polygon_2 = CGAL::Polygon_2<K>;
using Polygon_with_holes_2 = CGAL::Polygon_with_holes_2<K>;
using Multipolygon_with_holes_2 = CGAL::Multipolygon_with_holes_2<K>;
int
main(int argc, char* argv[])
{
Multipolygon_with_holes_2 pA;
if (argc == 2) {
{
std::ifstream in(argv[1]);
}
} else {
std::istringstream is("MULTIPOLYGON( ((0 0, 20 0, 20 20, 0 20), (1 1, 1 19, 19 19, 19 1) ) , (( 10 -2, 12 -2, 12 22, 10 22)) )");
//std::istringstream is("MULTIPOLYGON( ((0 0, 2 0, 2 3, 0 3) ) )"); // (0.1 0.1, 0.1 0.4, 0.4 0.1)
}
Multipolygon_with_holes_2 mpwh = CGAL::Polygon_repair::repair(pA, CGAL::Polygon_repair::Union_rule());
{
std::ofstream out("union.wkt");
#ifdef CGAL_USE_BASIC_VIEWER
CGAL::draw(mpwh);
#endif
}
{
std::ofstream out("intersection.wkt");
#ifdef CGAL_USE_BASIC_VIEWER
CGAL::draw(mpwh);
#endif
}
{
Polygon_2 pB;
pB.push_back(Point_2(-1,-1));
pB.push_back(Point_2(1,-1));
pB.push_back(Point_2(1,1));
pB.push_back(Point_2(-1,1));
mpwh = CGAL::Polygon_repair::join(mpwh, pB);
CGAL::draw(mpwh);
}
return 0;
}
void draw(const P &p, const GSOptions &gso)
Multipolygon_with_holes_2< Kernel, Container > repair(const Polygon_2< Kernel, Container > &p, Rule=Rule())
repairs polygon p using the given rule
Definition: repair.h:51
Multipolygon_with_holes_2< Kernel, Container > join(const Multipolygon_with_holes_2< Kernel, Container > &pa)
computes the union of all polygons with holes in p
Definition: repair.h:797
std::ostream & write_multi_polygon_WKT(std::ostream &out, MultiPolygon &polygons)
bool read_multi_polygon_WKT(std::istream &in, MultiPolygon &polygons)
Tag class to select the intersection rule when calling CGAL::Polygon_repair::repair().
Definition: Intersection_rule.h:27
Tag class to select the union rule when calling CGAL::Polygon_repair::repair().
Definition: Union_rule.h:27