polygon_boolean_operations.h
Go to the documentation of this file.
1 /**************************************************************************************************
2  Software License Agreement (BSD License)
3 
4  Copyright (c) 2011-2013, LAR toolkit developers - University of Aveiro - http://lars.mec.ua.pt
5  All rights reserved.
6 
7  Redistribution and use in source and binary forms, with or without modification, are permitted
8  provided that the following conditions are met:
9 
10  *Redistributions of source code must retain the above copyright notice, this list of
11  conditions and the following disclaimer.
12  *Redistributions in binary form must reproduce the above copyright notice, this list of
13  conditions and the following disclaimer in the documentation and/or other materials provided
14  with the distribution.
15  *Neither the name of the University of Aveiro nor the names of its contributors may be used to
16  endorse or promote products derived from this software without specific prior written permission.
17 
18  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
19  IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
20  FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
21  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
24  IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
25  OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 ***************************************************************************************************/
34 #ifndef _polygon_boolean_operations_H_
35 #define _polygon_boolean_operations_H_
36 
45 #define PFLN {printf("DEBUG PRINT FILE %s LINE %d\n",__FILE__,__LINE__);}
46 
47 //####################################################################
50 #include <ros/ros.h>
51 
52 #include <pcl/point_cloud.h>
53 #include <pcl/point_types.h>
54 #include <pcl_ros/transforms.h>
55 #include <tf/tf.h>
56 
57 //CGAL
58 #include <CGAL/basic.h>
59 #include <CGAL/Polygon_2.h>
60 #include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
61 #include <CGAL/Partition_traits_2.h>
62 #include <CGAL/Partition_is_valid_traits_2.h>
63 #include <CGAL/polygon_function_objects.h>
64 #include <CGAL/partition_2.h>
65 #include <CGAL/point_generators_2.h>
66 #include <CGAL/Polygon_set_2.h>
67 
68 #include <CGAL/random_polygon_2.h>
69 
70 #include <CGAL/Cartesian.h>
71 #include <CGAL/Boolean_set_operations_2.h>
72 
73 #include "polygon_simplification.h"
74 #include "transform_wrapper.h"
75 
76 typedef CGAL::Exact_predicates_exact_constructions_kernel PBO_Kernel;
77 typedef PBO_Kernel::Point_2 PBO_Point_2;
78 typedef CGAL::Polygon_2<PBO_Kernel> PBO_Polygon_2;
79 typedef CGAL::Polygon_with_holes_2<PBO_Kernel> PBO_Polygon_with_holes_2;
80 typedef std::list<PBO_Polygon_with_holes_2> PBO_Pwh_list_2;
81 typedef CGAL::Polygon_set_2<PBO_Kernel> PBO_Polygon_set_2;
82 
84 {
85  public:
88 
89  int insert(pcl::PointCloud<pcl::PointXYZ>::Ptr p_pc);
90  int insert(pcl::PointCloud<pcl::PointXYZ>* pc);
91 
92 
93  int intersection(pcl::PointCloud<pcl::PointXYZ>* pc);
94  int join(pcl::PointCloud<pcl::PointXYZ>* pc);
95  int complement(void);
96 
97 
98  int get_largest_pcl(pcl::PointCloud<pcl::PointXYZ>* pc_out);
99  int get_first_pcl(pcl::PointCloud<pcl::PointXYZ>* pc_out);
100  int get_all_pcls(std::vector<pcl::PointCloud<pcl::PointXYZ> >* pc_out_vector);
101 
102  int print(void);
103 
104  protected:
106  PBO_Polygon_2 from_pcl_to_cgalpolygon(pcl::PointCloud<pcl::PointXYZ>* pc);
107 
108 
109  template<class Kernel, class Container>
110  void print_polygon (const CGAL::Polygon_2<Kernel, Container>& P)
111  {
112  typename CGAL::Polygon_2<Kernel, Container>::Vertex_const_iterator vit;
113 
114  std::cout << "[ " << P.size() << " vertices:" << std::endl;
115  int k=1;
116  for (vit = P.vertices_begin(); vit != P.vertices_end(); ++vit)
117  {
118  std::cout << "x(" << k << ")=" << (*vit).x() << "; y(" << k << ")=" << (*vit).y()<< "; ";
119  k++;
120  }
121  std::cout << std::endl;
122  }
123 
124  template<class Kernel, class Container>
125  void print_polygon_with_holes(const CGAL::Polygon_with_holes_2<Kernel, Container> & pwh)
126  {
127  if (! pwh.is_unbounded()) {
128  std::cout << "{ is_simple=" << pwh.outer_boundary().is_simple() << "Outer boundary = ";
129  print_polygon (pwh.outer_boundary());
130  }
131  else
132  std::cout << "{ Unbounded polygon." << std::endl;
133 
134  typename CGAL::Polygon_with_holes_2<Kernel,Container>::Hole_const_iterator hit;
135  unsigned int k = 1;
136 
137  std::cout << " " << pwh.number_of_holes() << " holes:" << std::endl;
138  for (hit = pwh.holes_begin(); hit != pwh.holes_end(); ++hit, ++k) {
139  std::cout << "is_simple=" << (*hit).is_simple() <<" Hole #" << k << " = ";
140  print_polygon (*hit);
141  }
142  std::cout << " }" << std::endl;
143  }
144 };
145 
146 
147 #endif
148 
Defines the class polygon simplification.
int get_all_pcls(std::vector< pcl::PointCloud< pcl::PointXYZ > > *pc_out_vector)
CGAL::Polygon_with_holes_2< PBO_Kernel > PBO_Polygon_with_holes_2
Defines the class transform_wrapper *.
int insert(pcl::PointCloud< pcl::PointXYZ >::Ptr p_pc)
PBO_Kernel::Point_2 PBO_Point_2
PBO_Polygon_2 from_pcl_to_cgalpolygon(pcl::PointCloud< pcl::PointXYZ > *pc)
int get_largest_pcl(pcl::PointCloud< pcl::PointXYZ > *pc_out)
int join(pcl::PointCloud< pcl::PointXYZ > *pc)
CGAL::Polygon_set_2< PBO_Kernel > PBO_Polygon_set_2
int intersection(pcl::PointCloud< pcl::PointXYZ > *pc)
int get_first_pcl(pcl::PointCloud< pcl::PointXYZ > *pc_out)
CGAL::Polygon_2< PBO_Kernel > PBO_Polygon_2
std::list< PBO_Polygon_with_holes_2 > PBO_Pwh_list_2
void print_polygon_with_holes(const CGAL::Polygon_with_holes_2< Kernel, Container > &pwh)
CGAL::Exact_predicates_exact_constructions_kernel PBO_Kernel
void print_polygon(const CGAL::Polygon_2< Kernel, Container > &P)


bo_polygon2d
Author(s): Miguel Oliveira
autogenerated on Mon Mar 2 2015 01:31:29