How to insert a subset of Halfedges of a CGAL:Polyhedron_3 into a CGAL:AABB_tree?

56 Views Asked by At

I managed to insert all Edges of a CGAL:Polyhedron_3 into a CGAL:AABB_tree using an example from CGAL manual. But when tring to insert a subset of Halfedges, the code does not compile (using clang 13.0.1 on MacOS). I tried a few CGAL versions. 5.6 is the latest one.

// Adapted from CGAL Manual
#include <iostream>
#include <vector>
//#include <CGAL/Simple_cartesian.h>
#include <CGAL/Exact_predicates_exact_constructions_kernel.h>
#include <CGAL/AABB_tree.h>
#include <CGAL/AABB_traits.h>
#include <CGAL/Polyhedron_3.h>
#include <CGAL/AABB_halfedge_graph_segment_primitive.h>

//typedef CGAL::Simple_cartesian<double> K;
typedef CGAL::Exact_predicates_exact_constructions_kernel    K;
typedef K::FT FT;
typedef K::Point_3 Point;
typedef K::Triangle_3 Triangle;

typedef CGAL::Polyhedron_3<K> Polyhedron;

typedef CGAL::AABB_halfedge_graph_segment_primitive<Polyhedron> Primitive;
typedef CGAL::AABB_traits<K, Primitive> Traits;
typedef CGAL::AABB_tree<Traits> Tree;

template <class Kernel, class HalfedgeGraph>
void run(const HalfedgeGraph& graph){
  typename Kernel::Point_3 p(1.0, 0.0, 0.0);
  typename Kernel::Point_3 q(0.0, 1.0, 0.0);
  typename Kernel::Point_3 r(0.0, 0.0, 1.0);

  // constructs the AABB tree  
  Tree tree;

#define INSERT_MODE 2

#if INSERT_MODE==0
  // This compiles, but I don't want to insert all edges in the aabb tree
  std::cout << "\nInserting all edges using CGAL::edges" << std::endl;
  tree.insert( CGAL::edges(graph).first,
               CGAL::edges(graph).second, graph);

#elif INSERT_MODE==2
  std::cout << "\nInserting subset of edges using vector iterators" << std::endl;

  // How to insert a subset of Halfedges of a CGAL:Polyhedron_3 into a CGAL:AABB_tree?

#if 1
  // This does not compile: 
  std::vector<const Polyhedron::Halfedge_handle> half_edges;
  Polyhedron::Halfedge_const_iterator edge_pos = graph.halfedges_begin();

#else
  // This compiles with with CGAL 4.13.2, 4.14.3, and 5.6
  // but I would like to store Polyhedron::Halfedge_handle instead of iterators
  std::vector<Polyhedron::Halfedge_const_iterator> half_edges;
  Polyhedron::Halfedge_const_iterator edge_pos = graph.halfedges_begin();
#endif
  
  half_edges.push_back( &(*edge_pos) );
  ++edge_pos;
  half_edges.push_back( &(*edge_pos) );

  // This does NOT compile with with CGAL 4.13.2, 4.14.3 or 5.6
  // tree.insert( half_edges.begin(), half_edges.end(),
  //             graph);
#endif

  tree.accelerate_distance_queries();
  
  // counts #intersections with a triangle query
  Triangle triangle_query(p,q,r);
  std::cout << tree.number_of_intersected_primitives(triangle_query)
      << " intersections(s) with triangle" << std::endl;
  assert( tree.number_of_intersected_primitives(triangle_query )== 6);
  // computes the closest point from a query point
  typename Kernel::Point_3 point_query(2.0, 2.0, 2.0);
  typename Kernel::Point_3 closest = tree.closest_point(point_query);
  std::cerr << "closest point is: " << closest << std::endl;  
}
int main()
{
  Point p(1.0, 0.0, 0.0);
  Point q(0.0, 1.0, 0.0);
  Point r(0.0, 0.0, 1.0);
  Point s(0.0, 0.0, 0.0);
  Polyhedron polyhedron;
  polyhedron.make_tetrahedron(p, q, r, s);
  
  run<K>(polyhedron);
  return EXIT_SUCCESS;
}

I have tried several variations of this example code. Some are shown via pre-processor variables.

This is the error message from clang. I have checked it many time but could not figure out what is the problem.

[ 0%] Building CXX object projects/helperprograms/test_AABB_tree/CMakeFiles/test_AABB_tree.dir/test_AABB_tree.C.o In file included from /Users/armando/SetSolver_git/SetSolver/projects/helperprograms/test_AABB_tree/test_AABB_tree.C:9: /Users/armando/SetSolver_hg/CGAL-5.6/include/CGAL/AABB_halfedge_graph_segment_primitive.h:178:17: error: no matching member function for call to 'make_id' : Base( Id_(make_id(*it, graph, OneHalfedgeGraphPerTree())), ^~~~~~~

/Users/armando/SetSolver_hg/CGAL-5.6/include/CGAL/AABB_tree.h:741:30: note: in instantiation of function template specialization 'CGAL::AABB_halfedge_graph_segment_primitiveCGAL::Polyhedron_3<CGAL::Epeck>::AABB_halfedge_graph_segment_primitive<std::__wrap_iter<CGAL::internal::In_place_list_const_iterator<CGAL::HalfedgeDS_in_place_list_halfedge<CGAL::I_Polyhedron_halfedge<CGAL::HalfedgeDS_halfedge_base<CGAL::HalfedgeDS_list_types<CGAL::Epeck, CGAL::I_Polyhedron_derived_items_3CGAL::Polyhedron_items_3, std::allocator>>>>, std::allocator<CGAL::HalfedgeDS_in_place_list_halfedge<CGAL::I_Polyhedron_halfedge<CGAL::HalfedgeDS_halfedge_base<CGAL::HalfedgeDS_list_types<CGAL::Epeck, CGAL::I_Polyhedron_derived_items_3CGAL::Polyhedron_items_3, std::allocator>>>>>> *>>' requested here m_primitives.push_back(Primitive(first,std::forward(t)...)); ^

/Users/armando/SetSolver_git/SetSolver/projects/helperprograms/test_AABB_tree/test_AABB_tree.C:62:8: note: in instantiation of function template specialization 'CGAL::AABB_tree<CGAL::AABB_traits<CGAL::Epeck, CGAL::AABB_halfedge_graph_segment_primitiveCGAL::Polyhedron_3<CGAL::Epeck>>>::insert<std::__wrap_iter<CGAL::internal::In_place_list_const_iterator<CGAL::HalfedgeDS_in_place_list_halfedge<CGAL::I_Polyhedron_halfedge<CGAL::HalfedgeDS_halfedge_base<CGAL::HalfedgeDS_list_types<CGAL::Epeck, CGAL::I_Polyhedron_derived_items_3CGAL::Polyhedron_items_3, std::allocator>>>>, std::allocator<CGAL::HalfedgeDS_in_place_list_halfedge<CGAL::I_Polyhedron_halfedge<CGAL::HalfedgeDS_halfedge_base<CGAL::HalfedgeDS_list_types<CGAL::Epeck, CGAL::I_Polyhedron_derived_items_3CGAL::Polyhedron_items_3, std::allocator>>>>>> *>, const CGAL::Polyhedron_3CGAL::Epeck &>' requested here tree.insert( half_edges.begin(), half_edges.end(), ^

/Users/armando/SetSolver_git/SetSolver/projects/helperprograms/test_AABB_tree/test_AABB_tree.C:87:3: note: in instantiation of function template specialization 'run<CGAL::Epeck, CGAL::Polyhedron_3CGAL::Epeck>' requested here run(polyhedron); ^

/Users/armando/SetSolver_hg/CGAL-5.6/include/CGAL/AABB_halfedge_graph_segment_primitive.h:102:6: note: candidate function not viable: no known conversion from 'CGAL::internal::In_place_list_const_iterator<CGAL::HalfedgeDS_in_place_list_halfedge<CGAL::I_Polyhedron_halfedge<CGAL::HalfedgeDS_halfedge_base<CGAL::HalfedgeDS_list_types<CGAL::Epeck, CGAL::I_Polyhedron_derived_items_3CGAL::Polyhedron_items_3, std::allocator>>>>, std::allocator<CGAL::HalfedgeDS_in_place_list_halfedge<CGAL::I_Polyhedron_halfedge<CGAL::HalfedgeDS_halfedge_base<CGAL::HalfedgeDS_list_types<CGAL::Epeck, CGAL::I_Polyhedron_derived_items_3CGAL::Polyhedron_items_3, std::allocator>>>>>>' to 'CGAL::AABB_halfedge_graph_segment_primitiveCGAL::Polyhedron_3<CGAL::Epeck>::ED' (aka 'HDS_edge<In_place_list_iterator<CGAL::HalfedgeDS_in_place_list_halfedge<CGAL::I_Polyhedron_halfedge<CGAL::HalfedgeDS_halfedge_base<CGAL::HalfedgeDS_list_types<CGAL::Epeck, CGAL::I_Polyhedron_derived_items_3CGAL::Polyhedron_items_3, std::allocator>>>>, std::allocator<CGAL::HalfedgeDS_in_place_list_halfedge<CGAL::I_Polyhedron_halfedge<CGAL::HalfedgeDS_halfedge_base<CGAL::HalfedgeDS_list_types<CGAL::Epeck, CGAL::I_Polyhedron_derived_items_3CGAL::Polyhedron_items_3, std::allocator>>>>>>>') for 1st argument ED make_id(ED ed, const HalfedgeGraph&, Tag_true) ^

/Users/armando/SetSolver_hg/CGAL-5.6/include/CGAL/AABB_halfedge_graph_segment_primitive.h:107:39: note: candidate function not viable: no known conversion from 'CGAL::internal::In_place_list_const_iterator<CGAL::HalfedgeDS_in_place_list_halfedge<CGAL::I_Polyhedron_halfedge<CGAL::HalfedgeDS_halfedge_base<CGAL::HalfedgeDS_list_types<CGAL::Epeck, CGAL::I_Polyhedron_derived_items_3CGAL::Polyhedron_items_3, std::allocator>>>>, std::allocator<CGAL::HalfedgeDS_in_place_list_halfedge<CGAL::I_Polyhedron_halfedge<CGAL::HalfedgeDS_halfedge_base<CGAL::HalfedgeDS_list_types<CGAL::Epeck, CGAL::I_Polyhedron_derived_items_3CGAL::Polyhedron_items_3, std::allocator>>>>>>' to 'CGAL::AABB_halfedge_graph_segment_primitiveCGAL::Polyhedron_3<CGAL::Epeck>::ED' (aka 'HDS_edge<In_place_list_iterator<CGAL::HalfedgeDS_in_place_list_halfedge<CGAL::I_Polyhedron_halfedge<CGAL::HalfedgeDS_halfedge_base<CGAL::HalfedgeDS_list_types<CGAL::Epeck, CGAL::I_Polyhedron_derived_items_3CGAL::Polyhedron_items_3, std::allocator>>>>, std::allocator<CGAL::HalfedgeDS_in_place_list_halfedge<CGAL::I_Polyhedron_halfedge<CGAL::HalfedgeDS_halfedge_base<CGAL::HalfedgeDS_list_types<CGAL::Epeck, CGAL::I_Polyhedron_derived_items_3CGAL::Polyhedron_items_3, std::allocator>>>>>>>') for 1st argument std::pair<ED, const HalfedgeGraph*> make_id(ED ed, const HalfedgeGraph& fg, Tag_false) ^ 1 error generated. make[2]: *** [projects/helperprograms/test_AABB_tree/CMakeFiles/test_AABB_tree.dir/test_AABB_tree.C.o] Error 1 make[1]: *** [projects/helperprograms/test_AABB_tree/CMakeFiles/test_AABB_tree.dir/all] Error 2 make: *** [all] Error 2

1

There are 1 best solutions below

0
Duarte On

I could accomplish what I wanted using a vector of boost::graph_traits< HalfedgeGraph >::edge_descriptor The code is below for those interested.

#include <iostream>
#include <vector>
#include <boost/graph/graph_traits.hpp>

//#include <CGAL/Simple_cartesian.h>
#include <CGAL/Exact_predicates_exact_constructions_kernel.h>
#include <CGAL/AABB_tree.h>
#include <CGAL/AABB_traits.h>
#include <CGAL/Polyhedron_3.h>
#include <CGAL/AABB_halfedge_graph_segment_primitive.h>

//typedef CGAL::Simple_cartesian<double> K;
typedef CGAL::Exact_predicates_exact_constructions_kernel    K;
typedef K::FT FT;
typedef K::Point_3 Point;
typedef K::Triangle_3 Triangle;

typedef CGAL::Polyhedron_3<K> Polyhedron;

typedef CGAL::AABB_halfedge_graph_segment_primitive<Polyhedron, /*VertexPointPMap*/ CGAL::Default,
/* OneHalfedgeGraphPerTree*/ CGAL::Tag_true > Primitive;
typedef CGAL::AABB_traits<K, Primitive> Traits;
typedef CGAL::AABB_tree<Traits> Tree;

template <class Kernel, class HalfedgeGraph>
void run(HalfedgeGraph& graph){
  typename Kernel::Point_3 p(1.0, 0.0, 0.0);
  typename Kernel::Point_3 q(0.0, 1.0, 0.0);
  typename Kernel::Point_3 r(0.0, 0.0, 1.0);

  // Construct an AABB tree with edges of a Polyhedron_3
  Tree tree;

  std::cout << "\nInserting subset of edges using vector iterators" << std::endl;

  // This compiles with CGAL 4.13.2, 4.14, 5.6 and likely others
  
  // vector to store in AABB tree the edges we want to use.
  // Type used comes from CGAL header AABB_halfedge_graph_segment_primitive.h
  std::vector< typename boost::graph_traits< HalfedgeGraph >::edge_descriptor > my_edges;

  // Use this to pick edges from HalfedgeGraph graph
  typename boost::graph_traits< HalfedgeGraph >::edge_iterator epos_start =
 CGAL::edges(graph).first;

  typename boost::graph_traits< HalfedgeGraph >::edge_descriptor edge = 
*epos_start;
  my_edges.push_back( edge );

  epos_start++;
  edge = *epos_start;
  my_edges.push_back( edge );
  
  // Type of first two arguments to this method are iterators
  // boost::graph_traits< EdgeListGraph >::edge_iterator
  // Their value is boost::graph_traits< HalfedgeGraph >::edge_descriptor
  // Rebuild aabb tree with boost::graph_traits< HalfedgeGraph >::edge_descriptor stored in vector
  tree.rebuild( my_edges.begin(), my_edges.end(),
                graph);
   
  // counts #intersections with a triangle query
  Triangle triangle_query(p,q,r);
  std::cout << tree.number_of_intersected_primitives(triangle_query)
      << " intersections(s) with triangle" << std::endl;
  //  assert( tree.number_of_intersected_primitives(triangle_query )== 6);
  // computes the closest point from a query point
  typename Kernel::Point_3 point_query(2.0, 2.0, 2.0);
  typename Kernel::Point_3 closest = tree.closest_point(point_query);
  std::cerr << "closest point is: " << closest << std::endl;  
}
int main()
{
  Point p(1.0, 0.0, 0.0);
  Point q(0.0, 1.0, 0.0);
  Point r(0.0, 0.0, 1.0);
  Point s(0.0, 0.0, 0.0);
  Polyhedron polyhedron;
  polyhedron.make_tetrahedron(p, q, r, s);
  
  run<K>(polyhedron);
  return EXIT_SUCCESS;
}