(CGAL)获取AABB树生成的边界立方体以进行碰撞检测

时间:2019-01-23 09:31:22

标签: c++ collision-detection cgal aabb

我想知道两个多面体是否相交,为此,我用CGAL :: AABB_tree制作了两个都为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;
}

1 个答案:

答案 0 :(得分:0)

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

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