"Fossies" - the Fresh Open Source Software Archive

Member "CGAL-5.0/examples/AABB_tree/AABB_face_graph_triangle_example.cpp" (8 Nov 2019, 1659 Bytes) of package /linux/misc/CGAL-5.0.tar.xz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 // Author(s) : Pierre Alliez
    2 
    3 #include <iostream>
    4 
    5 #include <CGAL/Simple_cartesian.h>
    6 #include <CGAL/AABB_tree.h>
    7 #include <CGAL/AABB_traits.h>
    8 #include <CGAL/Polyhedron_3.h>
    9 #include <CGAL/AABB_face_graph_triangle_primitive.h>
   10 
   11 typedef CGAL::Simple_cartesian<double> K;
   12 typedef K::FT FT;
   13 typedef K::Point_3 Point;
   14 typedef K::Segment_3 Segment;
   15 typedef CGAL::Polyhedron_3<K> Polyhedron;
   16 typedef CGAL::AABB_face_graph_triangle_primitive<Polyhedron> Primitive;
   17 typedef CGAL::AABB_traits<K, Primitive> Traits;
   18 typedef CGAL::AABB_tree<Traits> Tree;
   19 
   20 template <class Kernel, class FaceGraph>
   21 void run(const FaceGraph& graph){
   22   typename Kernel::Point_3 p(0.2, 0.2, 0.2);
   23   typename Kernel::Point_3 q(1.0, 1.0, 1.0);
   24 
   25   // constructs the AABB tree and the internal search tree for
   26   // efficient distance queries.
   27   Tree tree( faces(graph).first, faces(graph).second, graph);
   28   tree.accelerate_distance_queries();
   29 
   30   // counts #intersections with a triangle query
   31   Segment segment_query(p,q);
   32   std::cout << tree.number_of_intersected_primitives(segment_query)
   33       << " intersections(s) with triangle" << std::endl;
   34 
   35   assert( tree.number_of_intersected_primitives(segment_query)== 1 );
   36 
   37   // computes the closest point from a query point
   38   typename Kernel::Point_3 point_query(2.0, 2.0, 2.0);
   39   typename Kernel::Point_3 closest = tree.closest_point(point_query);
   40 
   41   std::cerr << "closest point is: " << closest << std::endl;
   42 }
   43 
   44 int main()
   45 {
   46   Point p(1.0, 0.0, 0.0);
   47   Point q(0.0, 1.0, 0.0);
   48   Point r(0.0, 0.0, 1.0);
   49   Point s(0.0, 0.0, 0.0);
   50   Polyhedron polyhedron;
   51   polyhedron.make_tetrahedron(p, q, r, s);
   52 
   53   run<K>(polyhedron);
   54   return EXIT_SUCCESS;
   55 }