"Fossies" - the Fresh Open Source Software Archive 
Member "CGAL-5.0/examples/AABB_tree/AABB_ray_shooting_example.cpp" (8 Nov 2019, 2168 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 #include <iostream>
2 #include <fstream>
3
4 #include <CGAL/Simple_cartesian.h>
5 #include <CGAL/AABB_tree.h>
6 #include <CGAL/AABB_traits.h>
7 #include <CGAL/Surface_mesh.h>
8 #include <CGAL/AABB_face_graph_triangle_primitive.h>
9 #include <CGAL/Polygon_mesh_processing/compute_normal.h>
10 #include <CGAL/Polygon_mesh_processing/orientation.h>
11
12 typedef CGAL::Simple_cartesian<double> K;
13 typedef K::FT FT;
14 typedef K::Point_3 Point;
15 typedef K::Vector_3 Vector;
16 typedef K::Ray_3 Ray;
17
18 typedef CGAL::Surface_mesh<Point> Mesh;
19 typedef boost::graph_traits<Mesh>::face_descriptor face_descriptor;
20 typedef boost::graph_traits<Mesh>::halfedge_descriptor halfedge_descriptor;
21
22 typedef CGAL::AABB_face_graph_triangle_primitive<Mesh> Primitive;
23 typedef CGAL::AABB_traits<K, Primitive> Traits;
24 typedef CGAL::AABB_tree<Traits> Tree;
25 typedef boost::optional<Tree::Intersection_and_primitive_id<Ray>::Type> Ray_intersection;
26
27
28 struct Skip {
29 face_descriptor fd;
30
31 Skip(const face_descriptor fd)
32 : fd(fd)
33 {}
34
35 bool operator()(const face_descriptor& t) const
36 { if(t == fd){
37 std::cerr << "ignore " << t <<std::endl;
38 };
39 return(t == fd);
40 }
41
42 };
43
44 int main(int argc, char* argv[])
45 {
46 const char* filename = (argc > 1) ? argv[1] : "data/tetrahedron.off";
47 std::ifstream input(filename);
48 Mesh mesh;
49 input >> mesh;
50 Tree tree(faces(mesh).first, faces(mesh).second, mesh);
51
52 double d = CGAL::Polygon_mesh_processing::is_outward_oriented(mesh)?-1:1;
53
54 for(face_descriptor fd : faces(mesh)){
55 halfedge_descriptor hd = halfedge(fd,mesh);
56 Point p = CGAL::centroid(mesh.point(source(hd,mesh)),
57 mesh.point(target(hd,mesh)),
58 mesh.point(target(next(hd,mesh),mesh)));
59 Vector v = CGAL::Polygon_mesh_processing::compute_face_normal(fd,mesh);
60
61 Ray ray(p,d * v);
62 Skip skip(fd);
63 Ray_intersection intersection = tree.first_intersection(ray, skip);
64 if(intersection){
65 if(boost::get<Point>(&(intersection->first))){
66 const Point* p = boost::get<Point>(&(intersection->first) );
67 std::cout << *p << std::endl;
68 }
69 }
70 }
71 std::cerr << "done" << std::endl;
72 return 0;
73 }