From 4eeb1fa37f4543ad1ff09240f4eed33bc01a39a7 Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Tue, 2 Apr 2019 15:31:59 +0200 Subject: [PATCH] WIP towards making all partition methods work --- .../y_monotone_partition_with_info_2.cpp | 71 ++++++ .../include/CGAL/Pair_partition_traits_2.h | 222 ++++++++++++++++++ .../CGAL/Partition_2/Rotation_tree_2.h | 7 +- 3 files changed, 297 insertions(+), 3 deletions(-) create mode 100644 Partition_2/examples/Partition_2/y_monotone_partition_with_info_2.cpp create mode 100644 Partition_2/include/CGAL/Pair_partition_traits_2.h diff --git a/Partition_2/examples/Partition_2/y_monotone_partition_with_info_2.cpp b/Partition_2/examples/Partition_2/y_monotone_partition_with_info_2.cpp new file mode 100644 index 00000000000..77f34f2f464 --- /dev/null +++ b/Partition_2/examples/Partition_2/y_monotone_partition_with_info_2.cpp @@ -0,0 +1,71 @@ +#include +#include +#include +#include +#include +#include + + +typedef CGAL::Exact_predicates_inexact_constructions_kernel K; +typedef CGAL::Surface_mesh Surface_mesh; +typedef CGAL::Pair_partition_traits_2 Traits; +typedef Traits::Point_2 Point_2; + +typedef Traits::Polygon_2 Polygon_2; +typedef std::list Polygon_list; + +/* + + v4 v2 + | \ /| + | \ / | + | v3 | + | | + v0-----v1 + + */ + +int main( ) +{ + + Surface_mesh sm; + + Traits traits; + + Polygon_2 polygon(traits); + + polygon.push_back(std::make_pair(K::Point_2(0,0), sm.add_vertex(K::Point_2(0,0)))); + polygon.push_back(std::make_pair(K::Point_2(2,0), sm.add_vertex(K::Point_2(2,0)))); + polygon.push_back(std::make_pair(K::Point_2(2,2), sm.add_vertex(K::Point_2(2,2)))); + polygon.push_back(std::make_pair(K::Point_2(1,1), sm.add_vertex(K::Point_2(1,1)))); + polygon.push_back(std::make_pair(K::Point_2(0,2), sm.add_vertex(K::Point_2(0,2)))); + + Polygon_list partition_polys; + + + + //CGAL::y_monotone_partition_2 + CGAL::optimal_convex_partition_2 + (polygon.vertices_begin(), + polygon.vertices_end(), + std::back_inserter(partition_polys), + traits); + + std::list::const_iterator poly_it; + for (poly_it = partition_polys.begin(); poly_it != partition_polys.end(); + poly_it++) + { + for(Point_2 p : poly_it->container()){ + std::cout << "[" << p.first << "| " << p.second << "] "; + } + std::cout << std::endl; + } +#if 1 + assert(CGAL::convex_partition_is_valid_2(polygon.vertices_begin(), + polygon.vertices_end(), + partition_polys.begin(), + partition_polys.end(), + traits)); +#endif + return 0; +} diff --git a/Partition_2/include/CGAL/Pair_partition_traits_2.h b/Partition_2/include/CGAL/Pair_partition_traits_2.h new file mode 100644 index 00000000000..7151e1000a1 --- /dev/null +++ b/Partition_2/include/CGAL/Pair_partition_traits_2.h @@ -0,0 +1,222 @@ +// Copyright (c) 2000 Max-Planck-Institute Saarbruecken (Germany). +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org). +// You can redistribute it and/or modify it under the terms of the GNU +// General Public License as published by the Free Software Foundation, +// either version 3 of the License, or (at your option) any later version. +// +// Licensees holding a valid commercial license may use this file in +// accordance with the commercial license agreement provided with the software. +// +// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: GPL-3.0+ +// +// +// Author(s) : Susan Hert + +#ifndef CGAL_PAIR_PARTITION_TRAITS_2_H +#define CGAL_PAIR_PARTITION_TRAITS_2_H + +#include + +#include +#include +#include + +namespace CGAL { + + + template + struct Pair_functor { + Functor fct; + + Pair_functor() + : fct() + {} + + Pair_functor(const Functor fct) + : fct(fct) + {} + + typename Functor::result_type + operator()(const Pair& p, const Pair& q)const + { + return fct(p.first,q.first); + } + + typename Functor::result_type + operator()(const Pair& p, const Pair& q, const Pair& r)const + { + return fct(p.first,q.first,r.first); + } + }; + + template + struct Pair_compare_x_at_y_2 { + + typename K::Compare_x_at_y_2 fct; + + Pair_compare_x_at_y_2(typename K::Compare_x_at_y_2 fct) + : fct(fct) + {} + + typename K::Compare_x_at_y_2::result_type + operator()(const Pair& p, const typename K::Line_2& line) const + { + return fct(p.first,line); + } + }; + + +template +class Pair_partition_traits_2 +{ +private: + typedef Kernel_ Kernel; + typedef Pair_partition_traits_2 Self; + typedef Surface_mesh Surface_mesh; + +public: + + Pair_partition_traits_2() + {} + + + typedef typename boost::graph_traits::vertex_descriptor vertex_descriptor; + + typedef typename Kernel::FT FT; + typedef typename boost::graph_traits::vertex_descriptor vertex_descriptor; + typedef std::pair Point_2; + typedef ::std::list Container; + typedef CGAL::Polygon_2 Polygon_2; + + + typedef Pair_functor Equal_2; + + typedef Pair_functor Less_yx_2; + typedef Pair_functor Less_xy_2; + typedef Pair_functor Left_turn_2; + typedef Pair_functor Orientation_2; + typedef Pair_functor Compare_y_2; + typedef Pair_functor Compare_x_2; + typedef CGAL::Is_convex_2 Is_convex_2; + typedef CGAL::Is_y_monotone_2 Is_y_monotone_2; + + // needed by Indirect_edge_compare, used in y_monotone and greene_approx + typedef typename Kernel::Line_2 Line_2; + typedef Pair_functor Construct_line_2; + typedef Pair_compare_x_at_y_2 Compare_x_at_y_2; + typedef typename Kernel::Is_horizontal_2 Is_horizontal_2; + +#if 1 + // needed by visibility graph and thus by optimal convex + typedef typename Kernel::Ray_2 Ray_2; + typedef Pair_functor + Collinear_are_ordered_along_line_2; + typedef Pair_functor + Are_strictly_ordered_along_line_2; + typedef typename Kernel::Intersect_2 Intersect_2; + typedef typename Kernel::Assign_2 Assign_2; + typedef typename Kernel::Object_2 Object_2; + + // needed by approx_convex (for constrained triangulation) + // and optimal convex (for vis. graph) +#endif + typedef typename Kernel::Segment_2 Segment_2; +#if 1 + // needed by optimal convex (for vis. graph) + typedef Pair_functor Construct_segment_2; + typedef Pair_functor Construct_ray_2; +#endif + Equal_2 + equal_2_object() const + { return Equal_2(Kernel().equal_2_object()); } + + Orientation_2 + orientation_2_object() const + { return Orientation_2(Kernel().orientation_2_object()); } + + + + Less_yx_2 + less_yx_2_object() const + { return Less_yx_2(Kernel().less_yx_2_object()); } + + Less_xy_2 + less_xy_2_object() const + { return Less_xy_2(Kernel().less_xy_2_object()); } + + Left_turn_2 + left_turn_2_object() const + { return Left_turn_2(Kernel().left_turn_2_object()); } + + Compare_y_2 + compare_y_2_object() const + { return Compare_y_2(Kernel().compare_y_2_object()); } + + Compare_x_2 + compare_x_2_object() const + { return Compare_x_2(Kernel().compare_x_2_object()); } + + + + Construct_line_2 + construct_line_2_object() const + { return Construct_line_2(Kernel().construct_line_2_object()); } + + Compare_x_at_y_2 + compare_x_at_y_2_object() const + { return Compare_x_at_y_2(Kernel().compare_x_at_y_2_object()); } + + +#if 1 + + Construct_segment_2 + construct_segment_2_object() const + { return Construct_segment_2(); } + + Construct_ray_2 + construct_ray_2_object() const + { return Construct_ray_2(); } + + Collinear_are_ordered_along_line_2 + collinear_are_ordered_along_line_2_object() const + { return Collinear_are_ordered_along_line_2(); } + + Are_strictly_ordered_along_line_2 + are_strictly_ordered_along_line_2_object() const + { return Are_strictly_ordered_along_line_2(); } + +#endif + + Is_horizontal_2 + is_horizontal_2_object() const + { return Is_horizontal_2(); } + + Is_convex_2 + is_convex_2_object(const Self& traits) const + { return Is_convex_2(traits); } + + Is_y_monotone_2 + is_y_monotone_2_object(const Self& traits) const + { return Is_y_monotone_2(traits); } + +#if 1 + Intersect_2 + intersect_2_object() const + { return Intersect_2(); } + + Assign_2 + assign_2_object() const + { return Assign_2(); } +#endif +}; + +} + +#endif // CGAL_PAIR_PARTITION_TRAITS_2_H diff --git a/Partition_2/include/CGAL/Partition_2/Rotation_tree_2.h b/Partition_2/include/CGAL/Partition_2/Rotation_tree_2.h index a149a137f06..d47a398a13b 100644 --- a/Partition_2/include/CGAL/Partition_2/Rotation_tree_2.h +++ b/Partition_2/include/CGAL/Partition_2/Rotation_tree_2.h @@ -82,12 +82,13 @@ public: std::unique(this->begin(), this->end()); // front() is the point with the largest x coordinate - + + Point_2 p; // push the point p_minus_infinity; the coordinates should never be used - push_back(Point_2( 1, -1)); + push_back(p); // push the point p_infinity; the coordinates should never be used - push_back(Point_2(1, 1)); + push_back(p); _p_inf = this->end(); // record the iterators to these extreme points _p_inf--;