c++ - CGAL::交集错误

标签 c++ boost intersection cgal apply-visitor

我正在使用 CGAL 计算 3d 三角形之间的交点。我需要验证交叉点是否返回点、线或三角形。

typedef CGAL::Cartesian<double> tc;
typedef tc::Triangle_3       Triangle3;

CGAL::cpp11::result_of<tc::Intersect_3(Triangle3,Triangle3)>::type
                resultL1 = CGAL::intersection(*t_3,*tLado1_3);

if (resultL1){                                              // LINE 110
   boost::apply_visitor(Intersection_visitor(), *resultL1); // LINE 111
}

路口访客:

template<typename R>
struct Intersection_visitor {
    typedef void result_type;
    void operator()(const Point3<R>& p) const{
        // handle point
    }
    void operator()(const Segment_3<R>& s) const{
    // handle segment
    }
    void operator()(const Triangle3<R>& t) const{
    // handle triangle
    }
};

这给了我两个错误:

TextureManager.cpp:110: error: invalid type argument of unary '*' (have 'bool')

TextureManager.cpp:111: error: could not convert 'resultL1' from 'CGAL::cpp11::result_of<CGAL::CommonKernelFunctors::Intersect_3<CGAL::Cartesian<double> >(CGAL::Triangle_3<CGAL::Cartesian<double> >, CGAL::Triangle_3<CGAL::Cartesian<double> >)>::type {aka CGAL::Object}' to 'bool'

有人知道如何解决这些问题吗?

最佳答案

根据manual page您缺少访问者中 operator() 的可能类型。以下示例可以正常编译。

#include <CGAL/Cartesian.h>

typedef CGAL::Cartesian<double> tc;
typedef tc::Triangle_3       Triangle3;

template<typename R>
struct Intersection_visitor {
    typedef void result_type;
    void operator()(const CGAL::Point_3<R>& /* p */) const{
        // handle point
    }
    void operator()(const CGAL::Segment_3<R>& /* s */) const{
    // handle segment
    }
    void operator()(const CGAL::Triangle_3<R>& /* t */) const{
    // handle triangle
    }
    void operator()(const std::vector< CGAL::Point_3<R> >& /* t */) const{
    // handle triangle
    }
};

int main()
{
  Triangle3 t1, t2;
  CGAL::cpp11::result_of<tc::Intersect_3(Triangle3,Triangle3)>::type
                  resultL1 = CGAL::intersection(t1, t2);


  if (resultL1){                                              // LINE 110
     boost::apply_visitor(Intersection_visitor<tc>(), *resultL1); // LINE 111
  }

}

关于c++ - CGAL::交集错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25123939/

相关文章:

c++ - 为什么在这段代码中隐式类型转换的结果不正确?

c++ - 如何在 Symbian Qt 上的单个 QMainWindow、多个嵌套 QWidgets 应用程序中拥有动态变化的菜单?

c++ - 像普通方法一样调用构造函数和析构函数的注意事项和风险?

c++ - boost::filesystem:path检测到两个路径共享同一物理驱动器

python - 如何将 python 列表与共享项合并到新列表中

python - 可变数量列表的交集

c++ - 按文本搜索行并将其删除到文本文件中(从 C# 到 C++/CLI)

c++ - 工作队列的这种变体是某种模式还是通用结构?

math - 判断两条线是否相交

c++ - 如何在 boost::multi_index::multi_index_container 中存储元素?