1

我想知道两个多面体是否相交,为此我用生成边界立方体的 CGAL::AABB_tree 制作了它们的 AABB 树,我想用这个 AABB 树检查相交:

CGAL::box_intersection_d (RandomAccessIterator1 begin1, RandomAccessIterator1 end1, RandomAccessIterator2 begin2, RandomAccessIterator2 end2, 回调回调, ...)

但我不知道如何从树中获取 RandomAccessIterator1 begin1、RandomAccessIterator1 end1、RandomAccessIterator2 begin2、RandomAccessIterator2 end2,有人可以帮我吗?

#include <CGAL/Simple_cartesian.h>
#include <CGAL/Polyhedron_3.h>
#include <CGAL/IO/Polyhedron_iostream.h>
#include <iostream>
#include <fstream>
#include <algorithm>
#include <CGAL/AABB_tree.h>
#include <CGAL/AABB_traits.h>
#include <CGAL/AABB_face_graph_triangle_primitive.h>
#include <CGAL/box_intersection_d.h>
#include <CGAL/Bbox_2.h>    

typedef CGAL::Simple_cartesian<double> K;
typedef K::Point_3 Point;
typedef CGAL::Polyhedron_3<K> Polyhedron;
typedef CGAL::AABB_face_graph_triangle_primitive<Polyhedron> Primitive;
typedef CGAL::AABB_traits<K, Primitive> Traits;
typedef CGAL::AABB_tree<Traits> Tree;
typedef Tree::Primitive_id Primitive_id;
typedef CGAL::Box_intersection_d::Box_d<double,2> Box;
typedef CGAL::Bbox_3                              Bbox;


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

Point p(1.0, 0.0, 0.0);
Point q(0.0, 1.0, 0.0);
Point r(0.0, 0.0, 1.0);
Point s(0.0, 0.0, 0.0);
Polyhedron polyhedron;
polyhedron.make_tetrahedron(p, q, r, s);

Polyhedron P;
std::ifstream in1((argc>1)? 
argv[1]:"/home/domus/Programming_Projects/Cpp_projects/cube_1.off");
in1 >> P;

Tree P_tree(faces(P).first, faces(P).second, P);
std::cout << P_tree.size() << std::endl;

Tree tree(faces(polyhedron).first, faces(polyhedron).second, polyhedron);
std::cout << tree.size() << std::endl;

return 0;
}
4

1 回答 1

0

您可以使用以下CGAL::Polygon_mesh_processing::do_intersect()函数。

如果您可以使用 CGAL 的 master 分支,您甚至可以使用新引入的功能进行碰撞检测:请参阅当前文档页面

于 2019-01-23T15:50:19.897 回答