Skip to Content.
Sympa Menu

cgal-discuss - Re: [cgal-discuss] Identifying Intersected Triangles in AABB Tree

Subject: CGAL users discussion list

List archive

Re: [cgal-discuss] Identifying Intersected Triangles in AABB Tree


Chronological Thread 
  • From: "Sebastien Loriot (GeometryFactory)" <>
  • To:
  • Subject: Re: [cgal-discuss] Identifying Intersected Triangles in AABB Tree
  • Date: Mon, 22 Oct 2012 09:14:57 +0200
  • Organization: GeometryFactory

The type of id is

std::vector<Triangle>::iterator

so to get the index you can do something like:

std::vector<Triangle> triangles;
....
std::size_t index_in_vector = std::distance(triangles.begin(),id);
assert( triangles[index_in_vector == *id );

Sebastien.

On 10/20/2012 08:51 PM, gg++ wrote:
Hi,

I've built an AABB tree from a vector of Triangle_3's (named
triangles_vector) that represent a triangular mesh. For a given Ray_3 query,
I'd like to find the intersected triangle in the tree/mesh that is closest
to the source point of the ray, and then I need to find the location/index
of that triangle in the vector of triangles I originally used to build the
AABB tree.

Basically, each triangle in the mesh has a corresponding number identifier
that I use for bookkeeping, and for now I'm using the index location of the
triangle in the original triangle vector as that number, i.e., Triangle 724
can be found at triangles_vector[724].

Since I know the AABB tree doesn't provide any functions for finding the
first intersected triangle with respect to the query source point as I need,
I was going to use:


std::vector<Primitive_id> primitives;
tree.all_intersected_primitives( Ray_3, std::back_inserter(primitives));


This would give me a vector of primitive ID's, but I really don't know what
a Primitive_id is or how to use it to find the corresponding triangles in
the original triangles_vector that I used to build the tree. If I could find
the original triangles, I could run distance queries to find the closest to
the ray source and then keep track of what triangles got hit by the ray.

My tree has the following setup:

typedef CGAL::Simple_cartesian<double> K;
typedef std::vector<Triangle>::iterator Iterator;
typedef CGAL::AABB_triangle_primitive<K, Iterator> Primitive;
typedef CGAL::AABB_traits<K, Primitive> AABB_triangle_traits;
typedef CGAL::AABB_tree<AABB_triangle_traits> Tree;
typedef Tree::Primitive_id Primitive_id;

Can someone please point me in the right direction? As you probably already
figured out, I have very limited experience with C++ and even less posting
to technical forums, so please explain it to me like I'm a two year-old

Thank you,

Grant





--
View this message in context:
http://cgal-discuss.949826.n4.nabble.com/Identifying-Intersected-Triangles-in-AABB-Tree-tp4656054.html
Sent from the cgal-discuss mailing list archive at Nabble.com.







Archive powered by MHonArc 2.6.18.

Top of Page