首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >高效Ransac的模板化内核问题

高效Ransac的模板化内核问题
EN

Stack Overflow用户
提问于 2022-05-17 07:39:57
回答 1查看 39关注 0票数 2

我试图在一个使用模板内核的函数中使用CGAL的高效Ransac算法,下面是一个可以复制的最小代码。

代码语言:javascript
复制
#include <CGAL/property_map.h>
#include <CGAL/Point_with_normal_3.h>
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Shape_detection/Efficient_RANSAC.h>
// Type declarations.
typedef CGAL::Exact_predicates_inexact_constructions_kernel  Kernel;


template < typename K > //comment for working version
void funcTest() {

//typedef   CGAL::Exact_predicates_inexact_constructions_kernel  K;       //uncomment for working version
  typedef   std::tuple<typename K::Point_3,typename K::Vector_3, size_t, bool>     Point_and_normals;
  typedef   CGAL::Nth_of_tuple_property_map<0, Point_and_normals>  Point_map;
  typedef   CGAL::Nth_of_tuple_property_map<1, Point_and_normals>  Normal_map;
  typedef   CGAL::Shape_detection::Efficient_RANSAC_traits
                <K, std::vector<Point_and_normals>, Point_map, Normal_map>             TraitsShape;
  typedef  CGAL::Shape_detection::Efficient_RANSAC<TraitsShape> Efficient_ransac;
  typedef  CGAL::Shape_detection::Plane<TraitsShape> PlaneRansac;

  std::vector<Point_and_normals>  points;
  Efficient_ransac ransac;
  ransac.set_input(points);
  ransac.add_shape_factory<PlaneRansac>();
  ransac.detect();
}

int main (int argc, char** argv) {

  funcTest<Kernel>();   //comment for working version
  //funcTest());        //uncomment for working version
  return 0;
}

在这段代码中,模板化版本没有生成,从而产生了这个错误

代码语言:javascript
复制
tester.cpp:24:39: error: expected primary-expression before ‘>’ token
    24 |   ransac.add_shape_factory<PlaneRansac>();
       |                                       ^
tester.cpp:24:41: error: expected primary-expression before ‘)’ token
    24 |   ransac.add_shape_factory<PlaneRansac>();

然而,这个问题并不存在于显式内核中,我猜想它可能来自于typename问题,但我不知道我在这个问题上做错了什么。如有任何建议,欢迎光临。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-05-17 07:44:46

问题是编译器不知道在add_shape_factory后面的令牌<是小于运算符还是模板参数列表的开始。

当调用.template成员函数模板时,我们可以使用构造来解决这个问题,如下所示:

代码语言:javascript
复制
ransac.template add_shape_factory<PlaneRansac>();
//-----^^^^^^^^------------------------------------->added template keyword here to indicate that it is a member function template

.template用于告诉编译器,<令牌是模板参数列表的开始,并且不少于操作符。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72269958

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档