CGAL交叉继承多边形

时间:2014-05-15 12:03:35

标签: intersection cgal

我正在尝试使交集函数适用于从CGAL的多边形继承的自定义多边形。这是一个不编译的例子

#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;
}

显然,SimplePolygon行有效。但是当我尝试使用MyPolygon行进行编译时,我收到以下错误

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;
          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~

我错过了什么?

1 个答案:

答案 0 :(得分:1)

following function overload匹配您的调用,这会产生编译错误,因为该重载需要迭代器:

template<class InputIterator , class OutputIterator >
OutputIterator CGAL::intersection (InputIterator begin,
                                   InputIterator end,
                                   OutputIterator oi );

您需要以这种方式修改您的调用,并显式转换为基类:

CGAL::intersection((SimplePolygon&)polygon1,
                   (SimplePolygon&)polygon2,
                   std::back_inserter(intersections));