【问题标题】:CGAL::intersection errorCGAL::交叉点错误
【发布时间】:2014-08-04 17:05:52
【问题描述】:

我正在使用 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'

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

【问题讨论】:

  • t_3tLado1_3 是什么?
  • t_3 和 tLado1_3 都是 triangle3 指针 typedef CGAL::Cartesian tc; typedef tc::Triangle_3 Triangle3;
  • 我实际上更改了代码以使用旧版本的交集并将结果提供给对象:CGAL::Object resultL1 = CGAL::intersection(*t_3,*tLado1_3);现在我得到一个运行时错误:在抛出一个 'CGAL::Precondition_exception' what() 实例后调用终止:CGAL 错误:违反前提条件!表达式:! s1.is_degenerate () && ! s2.is_degenerate() 文件:/usr/include/CGAL/Intersections_3/intersection_3_1_impl.
  • 您使用的是哪个版本的 CGAL?
  • 我放弃了那个实现并使用旧的 CGAL 版本来获取交集结果作为 CGAL::Object。由于运行时错误,我还不得不将内核更改为exact_predicates_exact 结构。谢谢你们的时间!

标签: c++ boost intersection cgal apply-visitor


【解决方案1】:

根据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
  }

}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-04-09
    • 2013-07-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多