1 #include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
2 #include <CGAL/box_intersection_d.h>
3 #include <vector>
4 #include <fstream>
5 
6 typedef CGAL::Exact_predicates_inexact_constructions_kernel   Kernel;
7 typedef Kernel::Point_3                                       Point_3;
8 typedef Kernel::Triangle_3                                    Triangle_3;
9 typedef std::vector<Triangle_3>                               Triangles;
10 typedef Triangles::iterator                                   Iterator;
11 typedef CGAL::Box_intersection_d::Box_with_handle_d<double,3,Iterator> Box;
12 
13 struct Report {
14   Triangles* triangles;
15 
ReportReport16   Report(Triangles& triangles)
17     : triangles(&triangles)
18   {}
19 
20   // callback functor that reports all truly intersecting triangles
operator ()Report21   void operator()(const Box& a, const Box& b) const
22   {
23     std::cout << "Box " << (a.handle() - triangles->begin()) << " and "
24               << (b.handle() - triangles->begin()) << " intersect";
25     if ( ! a.handle()->is_degenerate() && ! b.handle()->is_degenerate()
26          && CGAL::do_intersect( *(a.handle()), *(b.handle()))) {
27     std::cout << ", and the triangles intersect also";
28     }
29     std::cout << '.' << std::endl;
30   }
31 };
32 
33 
main(int argc,char * argv[])34 int main(int argc, char*argv[])
35 {
36   std::ifstream in((argc>1)?argv[1]:"data/triangles.xyz");
37   Triangles triangles;
38   Triangle_3 t;
39   while(in >> t){
40     triangles.push_back(t);
41   }
42 
43   // Create the corresponding vector of bounding boxes
44   std::vector<Box> boxes;
45   for ( Iterator i = triangles.begin(); i != triangles.end(); ++i)
46     boxes.push_back( Box( i->bbox(), i));
47 
48   // Run the self intersection algorithm with all defaults
49   CGAL::box_self_intersection_d( boxes.begin(), boxes.end(), Report(triangles));
50   return 0;
51 }
52