mirror of https://github.com/CGAL/cgal
Add an example for ray shooting
This commit is contained in:
parent
03f9c56c76
commit
145ab7e3db
|
|
@ -137,6 +137,19 @@ a segment. We finally compute the first intersection along a ray.
|
||||||
|
|
||||||
\cgalExample{AABB_tree/AABB_polyhedron_facet_intersection_example.cpp}
|
\cgalExample{AABB_tree/AABB_polyhedron_facet_intersection_example.cpp}
|
||||||
|
|
||||||
|
|
||||||
|
\subsection aabb_tree_examples_2 Ray Shooting
|
||||||
|
|
||||||
|
In the following example we load a closed polyhedral surface and perform a
|
||||||
|
ray shooting query from the centroid of each face, orthogonally to the face
|
||||||
|
towards the interior. As the centroid is computed with floating point
|
||||||
|
arithmetic the first face hit by the ray may be the face of the centroid.
|
||||||
|
The skip functor takes care of ignoring the face.
|
||||||
|
|
||||||
|
\cgalExample{AABB_tree/AABB_ray_shooting_example.cpp}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
\subsection aabb_tree_examples_3 Tree of Polyhedron Triangle Facets for Distance Queries
|
\subsection aabb_tree_examples_3 Tree of Polyhedron Triangle Facets for Distance Queries
|
||||||
|
|
||||||
In the following example the AABB primitive wraps a facet handle of a
|
In the following example the AABB primitive wraps a facet handle of a
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@
|
||||||
\example AABB_tree/AABB_polyhedron_facet_distance_example.cpp
|
\example AABB_tree/AABB_polyhedron_facet_distance_example.cpp
|
||||||
\example AABB_tree/AABB_polyhedron_facet_intersection_example.cpp
|
\example AABB_tree/AABB_polyhedron_facet_intersection_example.cpp
|
||||||
\example AABB_tree/AABB_segment_3_example.cpp
|
\example AABB_tree/AABB_segment_3_example.cpp
|
||||||
|
\example AABB_tree/AABB_ray_shooting_example.cpp
|
||||||
\example AABB_tree/AABB_triangle_3_example.cpp
|
\example AABB_tree/AABB_triangle_3_example.cpp
|
||||||
\example AABB_tree/AABB_halfedge_graph_edge_example.cpp
|
\example AABB_tree/AABB_halfedge_graph_edge_example.cpp
|
||||||
\example AABB_tree/AABB_face_graph_triangle_example.cpp
|
\example AABB_tree/AABB_face_graph_triangle_example.cpp
|
||||||
|
|
|
||||||
|
|
@ -58,8 +58,10 @@ int main()
|
||||||
if(intersection)
|
if(intersection)
|
||||||
{
|
{
|
||||||
// gets intersection object
|
// gets intersection object
|
||||||
if(boost::get<Point>(&(intersection->first)))
|
const Point* p = boost::get<Point>(&(intersection->first))
|
||||||
std::cout << "intersection object is a point" << std::endl;
|
if(p)
|
||||||
|
std::cout << "intersection object is a point " << *p << std::endl;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// computes all intersections with segment query (as pairs object - primitive_id)
|
// computes all intersections with segment query (as pairs object - primitive_id)
|
||||||
|
|
@ -83,10 +85,6 @@ int main()
|
||||||
if(boost::get<Segment>(&(plane_intersection->first)))
|
if(boost::get<Segment>(&(plane_intersection->first)))
|
||||||
std::cout << "intersection object is a segment" << std::endl;
|
std::cout << "intersection object is a segment" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
Point inside(0.1, 0.1, 0.1);
|
|
||||||
Ray ray(inside,r);
|
|
||||||
tree.first_intersection(ray);
|
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,72 @@
|
||||||
|
#include <iostream>
|
||||||
|
#include <fstream>
|
||||||
|
|
||||||
|
#include <CGAL/Simple_cartesian.h>
|
||||||
|
#include <CGAL/AABB_tree.h>
|
||||||
|
#include <CGAL/AABB_traits.h>
|
||||||
|
#include <CGAL/Surface_mesh.h>
|
||||||
|
#include <CGAL/AABB_face_graph_triangle_primitive.h>
|
||||||
|
#include <CGAL/Polygon_mesh_processing/compute_normal.h>
|
||||||
|
#include <CGAL/Polygon_mesh_processing/orientation.h>
|
||||||
|
|
||||||
|
typedef CGAL::Simple_cartesian<double> K;
|
||||||
|
typedef K::FT FT;
|
||||||
|
typedef K::Point_3 Point;
|
||||||
|
typedef K::Vector_3 Vector;
|
||||||
|
typedef K::Ray_3 Ray;
|
||||||
|
|
||||||
|
typedef CGAL::Surface_mesh<Point> Mesh;
|
||||||
|
typedef boost::graph_traits<Mesh>::face_descriptor face_descriptor;
|
||||||
|
typedef boost::graph_traits<Mesh>::halfedge_descriptor halfedge_descriptor;
|
||||||
|
|
||||||
|
typedef CGAL::AABB_face_graph_triangle_primitive<Mesh> Primitive;
|
||||||
|
typedef CGAL::AABB_traits<K, Primitive> Traits;
|
||||||
|
typedef CGAL::AABB_tree<Traits> Tree;
|
||||||
|
typedef boost::optional<Tree::Intersection_and_primitive_id<Ray>::Type> Ray_intersection;
|
||||||
|
|
||||||
|
|
||||||
|
struct Skip {
|
||||||
|
face_descriptor fd;
|
||||||
|
|
||||||
|
Skip(const face_descriptor fd)
|
||||||
|
: fd(fd)
|
||||||
|
{}
|
||||||
|
|
||||||
|
bool operator()(const face_descriptor& t) const
|
||||||
|
{ if(t == fd){
|
||||||
|
std::cerr << "ignore" << t <<std::endl;
|
||||||
|
};
|
||||||
|
return(t == fd);
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
int main(int argc, char* argv[])
|
||||||
|
{
|
||||||
|
const char* filename = (argc > 1) ? argv[1] : "data/tetrahedron.off";
|
||||||
|
std::ifstream input(filename);
|
||||||
|
Mesh mesh;
|
||||||
|
input >> mesh;
|
||||||
|
Tree tree(faces(mesh).first, faces(mesh).second, mesh);
|
||||||
|
|
||||||
|
double d = CGAL::Polygon_mesh_processing::is_outward_oriented(mesh)?-1:1;
|
||||||
|
|
||||||
|
BOOST_FOREACH(face_descriptor fd, faces(mesh)){
|
||||||
|
halfedge_descriptor hd = halfedge(fd,mesh);
|
||||||
|
Point p = CGAL::centroid(mesh.point(source(hd,mesh)),
|
||||||
|
mesh.point(target(hd,mesh)),
|
||||||
|
mesh.point(target(next(hd,mesh),mesh)));
|
||||||
|
Vector v = CGAL::Polygon_mesh_processing::compute_face_normal(fd,mesh);
|
||||||
|
|
||||||
|
Ray ray(p,d * v);
|
||||||
|
Ray_intersection intersection = tree.first_intersection(ray, Skip(fd));
|
||||||
|
if(intersection){
|
||||||
|
if(boost::get<Point>(&(intersection->first))){
|
||||||
|
const Point* p = boost::get<Point>(&(intersection->first) );
|
||||||
|
std::cout << *p << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
std::cerr << "done" << std::endl;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,11 @@
|
||||||
|
OFF
|
||||||
|
4 4 0
|
||||||
|
0.0 0.0 0.0
|
||||||
|
1.0 0.0 0.0
|
||||||
|
0.0 1.0 0.0
|
||||||
|
0.0 0.0 1.0
|
||||||
|
3 0 1 2
|
||||||
|
3 0 3 1
|
||||||
|
3 0 2 3
|
||||||
|
3 1 3 2
|
||||||
|
|
||||||
Loading…
Reference in New Issue