How to get the primitive from an AABB Tree from the first intersection?

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

How to get the primitive from an AABB Tree from the first intersection?

Rash
Hi guys,

for learning CGAL I wanted to write a small ray tracerIt works fine for
hit detection and but I am not able to get the primitive which the ray
has hit. So I can't compute the normal of the primitve.

#include <CGAL/AABB_tree.h>
#include <CGAL/Polyhedron_3.h>

     typedef CGAL::AABB_face_graph_triangle_primitive<Polyhedron> Primitive;


                 boost::optional<Primitive_id> hit =
tree.first_intersected_primitive(rays[this->transformCoordinates(y,x)]);

//okay we have a hit. Nice but how do we get the primitve?

std::cout << *hit << std::endl; //does not work, strange iterrator
std::cout << hit << std::endl; //does not work
std::cout << &hit << std::endl; //damn
std::cout << boost::get<Point>(&(hit)) << std::endl; //come one
std::cout << boost::get<Point>((hit)) << std::endl; //google doesnt help
std::cout << boost::get<Point>(*hit) << std::endl; //write an email

After using googled for two hours I gave up. Sorry, I am not too familar
with boost.

Kind regards
Rashid

--
You are currently subscribed to cgal-discuss.
To unsubscribe or access the archives, go to
https://sympa.inria.fr/sympa/info/cgal-discuss


Reply | Threaded
Open this post in threaded view
|

Re: How to get the primitive from an AABB Tree from the first intersection?

Sebastien Loriot (GeometryFactory)
The primitive in this case is a face descriptor that depend on the type
of mesh you are using.

In the case of Polyhedron_3, it is a Facet_handle
So you can access the vertices of the facet by using
Halfedge_handle h = (*hit)->halfedge();

then the 3 vertices of the triangle face are
h->vertex(), h->next()->vertex(), h->next()->next()->vertex().

This is somehow what is used here:
https://doc.cgal.org/latest/AABB_tree/index.html#title6

Sebastien.


On 07/03/2018 09:06 AM, Rash wrote:

> Hi guys,
>
> for learning CGAL I wanted to write a small ray tracerIt works fine for
> hit detection and but I am not able to get the primitive which the ray
> has hit. So I can't compute the normal of the primitve.
>
> #include <CGAL/AABB_tree.h>
> #include <CGAL/Polyhedron_3.h>
>
>      typedef CGAL::AABB_face_graph_triangle_primitive<Polyhedron>
> Primitive;
>
>
>                  boost::optional<Primitive_id> hit =
> tree.first_intersected_primitive(rays[this->transformCoordinates(y,x)]);
>
> //okay we have a hit. Nice but how do we get the primitve?
>
> std::cout << *hit << std::endl; //does not work, strange iterrator
> std::cout << hit << std::endl; //does not work
> std::cout << &hit << std::endl; //damn
> std::cout << boost::get<Point>(&(hit)) << std::endl; //come one
> std::cout << boost::get<Point>((hit)) << std::endl; //google doesnt help
> std::cout << boost::get<Point>(*hit) << std::endl; //write an email
>
> After using googled for two hours I gave up. Sorry, I am not too familar
> with boost.
>
> Kind regards
> Rashid
>

--
You are currently subscribed to cgal-discuss.
To unsubscribe or access the archives, go to
https://sympa.inria.fr/sympa/info/cgal-discuss