能否在CGAL Quadtree自定义分割函数中调用quadtree.bbox(n)?
CGAL四叉树自定义分割函数访问节点包围盒问题解答
不能直接在split_if_true的operator()里调用quadtree.bbox(n),因为该函数对象内部没有持有对应四叉树实例的引用。你可以通过以下两种方式解决:
给函数对象添加四叉树引用成员
修改split_if_true结构体,让它持有Quadtree的const引用,这样就能在operator()里调用bbox方法:struct split_if_true { int flag; const Quadtree& quadtree; // 添加四叉树引用成员 // 构造函数初始化引用与flag split_if_true(int flag, const Quadtree& qt) : flag(flag), quadtree(qt) {} template<class Node> bool operator()(const Node& n) const { // 现在可以访问节点的包围盒 auto bbox = quadtree.bbox(n); // 此处编写你的分割判断逻辑 return true; } }; bool create_quad_tree(Point_vector points){ Quadtree quadtree(points); int flag = 0; // 构造函数传入四叉树实例 quadtree.refine(split_if_true(flag, quadtree)); return true; };利用Node类内置方法直接获取包围盒
CGAL的Orthtree节点本身提供了获取包围盒的方法,无需通过树实例调用。直接调用n.bbox()即可获取当前节点的包围盒,这种方式更简洁:struct split_if_true { int flag; split_if_true(int flag) : flag(flag) {} template<class Node> bool operator()(const Node& n) const { // 直接通过节点对象获取包围盒 auto bbox = n.bbox(); // 实现你的分割判断逻辑 return true; } }; bool create_quad_tree(Point_vector points){ Quadtree quadtree(points); int flag = 0; quadtree.refine(split_if_true(flag)); return true; };
推荐使用第二种方式,它不需要额外维护树实例的引用,代码更简洁,也符合CGAL Orthtree的设计规范。
内容的提问来源于stack exchange,提问作者Tunity
相关产品推荐
相关产品推荐

