1
votes

I'm trying to use CGAL's AABB_tree with multiple Surface_mesh and fail an odd assertion which makes me think it's trying to use the first surface mesh's vertices with the second mesh's indices or something similarly weird.

Before I file a bug, I'd like to validate that I'm not misunderstanding something.

Here's a minimally modified example. I'm using cube.off from: https://github.com/libigl/libigl/blob/master/tutorial/shared/cube.off and the Tetrahedron from CGAL's examples, but it seems to reproduce every time the second surface mesh I add has less vertices than the first mesh no matter what it is.

The assertion I'm failing is /usr/local/include/CGAL/Surface_mesh/Properties.h:178 - CGAL_assertion( idx < data.size() );

Using: CGAL_VERSION 4.12

CGAL_VERSION_NR 1041201000

CGAL_SVN_REVISION 99999

CGAL_GIT_HASH f7c3c8212b56c0d6dae63787efc99093f4383415

#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>

typedef CGAL::Simple_cartesian<double> K;
typedef K::Point_3 Point;
typedef K::Ray_3 Ray;
typedef CGAL::Surface_mesh<Point> Mesh;
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;

int main(int argc, char* argv[])
{
    const char* filename1 = "cube.off";
    const char* filename2 = "tetrahedron.off";

    std::ifstream input1(filename1);
    Mesh mesh1;
    input1 >> mesh1;

    std::ifstream input2(filename2);
    Mesh mesh2;
    input2 >> mesh2;

    Tree tree;
    tree.insert(faces(mesh1).first, faces(mesh1).second, mesh1);
    tree.insert(faces(mesh2).first, faces(mesh2).second, mesh2);
    tree.build(); // CGAL_assertion( idx < data.size() ) fails

    return 0;
}
1
I didn't really look at the code, but you are using a quad cube and a triangle tetrahedron with the same primitive type, based on triangles. That can't be good. Furthermore, you cannot use tbat Primitive type with a Tree built from several Surface_meshes, because it uses the id of the face as id, IIRC. Which means you will have several primitives with the same ID, or something like that. You will probably have to define your own AABB_primitive and choose a different way to set your Ids. Id could also triangulate faces to work with any type of face. - mgimeno
Actually you can use this primitive but you need to set the template tag OneFaceGraphPerTree to CGAL::Tag_false. And still, it won't work on not triangle meshes. - mgimeno
My bad, the quad mesh was part of my effort to build a toy example. The real problem was indeed with OneFaceGraphPerTree. Interesting that this defaults to true. Thanks to both of you. - jfclavette

1 Answers

1
votes

I repost my comment as an answer:

From my comment: Actually you can use this primitive but you need to set the template tag OneFaceGraphPerTree to CGAL::Tag_false. See here