1

I want to know if two polyhedra are intersecting, for that I made an AABB Tree of both of them with CGAL::AABB_tree which generates the bounding cubes, with this AABB Tree I want to check the intersection with:

CGAL::box_intersection_d (RandomAccessIterator1 begin1, RandomAccessIterator1 end1, RandomAccessIterator2 begin2, RandomAccessIterator2 end2, Callback callback, ...)

But I don't know how to obtain RandomAccessIterator1 begin1, RandomAccessIterator1 end1, RandomAccessIterator2 begin2, RandomAccessIterator2 end2 from the tree, can anyone help me?

#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;
}
Rodrigo
  • 11
  • 1
  • [This link](http://cgal-discuss.949826.n4.nabble.com/Is-it-possible-to-intersect-polyhedrons-with-AABB-tree-td4661361.html) mentiones a function which does what you want. I couldn't find that function. Perhaps you might find and show us how to do it. – Shibli Jan 23 '19 at 12:35

1 Answers1

0

You can use the following CGAL::Polygon_mesh_processing::do_intersect() function.

If you can work with the master branch of CGAL you can even use the newly introduced function for collision detection: See the current doc page.

sloriot
  • 6,070
  • 18
  • 27