【问题标题】:CGAL intersecting inherited polygonsCGAL 与继承的多边形相交
【发布时间】:2014-05-15 12:03:34
【问题描述】:

我正在尝试使交叉函数在继承自 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;
          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~

我错过了什么?

【问题讨论】:

    标签: intersection cgal


    【解决方案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));
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-01-09
      • 2017-06-19
      • 1970-01-01
      • 1970-01-01
      • 2020-02-23
      • 2011-09-26
      • 2015-09-21
      • 2011-12-10
      相关资源
      最近更新 更多