Reputation: 320
I am trying to make the intersection function work on custom defined polygons that inherit from CGAL's polygons. Here's an example that doesn't compile
#include <CGAL/Exact_predicates_exact_constructions_kernel.h>
#include <CGAL/Point_2.h>
#include <CGAL/Polygon_2.h>
#include <CGAL/Polygon_with_holes_2.h>
#include <CGAL/Boolean_set_operations_2.h>
#include <iostream>
#include <vector>
typedef CGAL::Exact_predicates_exact_constructions_kernel Kernel;
typedef CGAL::Polygon_2<Kernel> SimplePolygon;
typedef CGAL::Polygon_with_holes_2<Kernel> Polygon;
typedef CGAL::Point_2<Kernel> Point;
class MyPolygon : public SimplePolygon {
};
int main( ) {
MyPolygon polygon1, polygon2; // This doesn't work!
//SimplePolygon polygon1, polygon2; // This works!
// Populate the polygons...
std::vector<Polygon> intersections;
CGAL::intersection(polygon1, polygon2, std::back_inserter(intersections));
return 0;
}
With the SimplePolygon
line it works, obviously. But when I try to compile with the MyPolygon
line I get the following error
In file included from main.cpp:25:
/opt/local/include/CGAL/Boolean_set_operations_2.h:839:57: error: no type named 'value_type' in 'std::__1::iterator_traits<MyPolygon>'
typedef typename std::iterator_traits<InputIterator>::value_type InputPolygon;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~
/opt/local/include/CGAL/Boolean_set_operations_2.h:907:12: note: in instantiation of template class 'CGAL::map_iterator_to_traits<MyPolygon>' requested here
typename map_iterator_to_traits<InputIterator>::Traits tr;
^
main.cpp:62:9: note: in instantiation of function template specialization 'CGAL::intersection<MyPolygon, std::__1::back_insert_iterator<std::__1::vector<CGAL::Polygon_with_holes_2<CGAL::Epeck, std::__1::vector<CGAL::Point_2<CGAL::Epeck>, std::__1::allocator<CGAL::Point_2<CGAL::Epeck> > > >, std::__1::allocator<CGAL::Polygon_with_holes_2<CGAL::Epeck, std::__1::vector<CGAL::Point_2<CGAL::Epeck>, std::__1::allocator<CGAL::Point_2<CGAL::Epeck> > > > > > > >' requested here
CGAL::intersection(polygon1, polygon2, std::back_inserter(intersections));
^
In file included from main.cpp:25:
/opt/local/include/CGAL/Boolean_set_operations_2.h:840:54: error: no type named 'Traits' in 'CGAL::Gps_default_traits<int>'
typedef typename Gps_default_traits<InputPolygon>::Traits Traits;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~
What am I missing?
Upvotes: 1
Views: 280
Reputation: 6274
The following function overload matches your call, and that gives your the compilation errors, because that overload expects iterators:
template<class InputIterator , class OutputIterator >
OutputIterator CGAL::intersection (InputIterator begin,
InputIterator end,
OutputIterator oi );
You need to modify your call that way, with explicit casting to the base class:
CGAL::intersection((SimplePolygon&)polygon1,
(SimplePolygon&)polygon2,
std::back_inserter(intersections));
Upvotes: 1