diff --git a/Tangential_complex/include/CGAL/Tangential_complex.h b/Tangential_complex/include/CGAL/Tangential_complex.h index 2cdb28ee3c4..00ade4c9b65 100644 --- a/Tangential_complex/include/CGAL/Tangential_complex.h +++ b/Tangential_complex/include/CGAL/Tangential_complex.h @@ -358,9 +358,8 @@ private: const int NUM_NEIGHBORS = 150; std::size_t nearest_nb[NUM_NEIGHBORS]; - FT squared_distance[NUM_NEIGHBORS]; m_points_ds.query_ANN( - center_pt, NUM_NEIGHBORS, nearest_nb, squared_distance); + center_pt, NUM_NEIGHBORS, nearest_nb); /*const int NUM_NEIGHBORS = 150; std::size_t nearest_nb[NUM_NEIGHBORS]; for (int ii = 0 ; ii < NUM_NEIGHBORS ; ++ii) @@ -509,9 +508,8 @@ private: Kernel::Difference_of_vectors_d diff_vec = m_k.difference_of_vectors_d_object(); std::size_t neighbor_indices[NUM_POINTS_FOR_PCA]; - FT squared_distance[NUM_POINTS_FOR_PCA]; m_points_ds.query_ANN( - p, NUM_POINTS_FOR_PCA, neighbor_indices, squared_distance); + p, NUM_POINTS_FOR_PCA, neighbor_indices); //******************************* PCA ************************************* diff --git a/Tangential_complex/include/CGAL/Tangential_complex/Point_cloud.h b/Tangential_complex/include/CGAL/Tangential_complex/Point_cloud.h index 6cd815f7e65..7452028d9c3 100644 --- a/Tangential_complex/include/CGAL/Tangential_complex/Point_cloud.h +++ b/Tangential_complex/include/CGAL/Tangential_complex/Point_cloud.h @@ -225,17 +225,16 @@ class Point_cloud_data_structure { public: typedef typename Point_container_::value_type Point; - typedef typename CGAL::Kernel_traits::type Kernel; - typedef typename Kernel::FT FT; + typedef typename CGAL::Kernel_traits::type Kernel; + typedef typename Kernel::FT FT; - typedef boost::tuple Point_and_idx; typedef CGAL::Search_traits< - FT, Point, + FT, Point, typename Kernel::Cartesian_const_iterator_d, typename Kernel::Construct_cartesian_const_iterator_d> Traits_base; - typedef CGAL::Search_traits_adapter, - Traits_base> STraits; + // using a pointer as a special property map type + typedef CGAL::Search_traits_adapter< + std::ptrdiff_t, Point*, Traits_base> STraits; typedef CGAL::Orthogonal_k_neighbor_search K_neighbor_search; typedef typename K_neighbor_search::Tree Tree; @@ -244,15 +243,13 @@ public: static const int AMB_DIM = Ambient_dimension::value; /// Constructor - Point_cloud_data_structure(Point_container_ &points, Kernel const& k) + Point_cloud_data_structure(Point_container_ const& points, Kernel const& k) : m_points(points), m_tree( - boost::make_zip_iterator(boost::make_tuple( - points.begin(), - boost::counting_iterator(0))), - boost::make_zip_iterator(boost::make_tuple( - points.end(), - boost::counting_iterator(points.size()))) ) + boost::counting_iterator(0), + boost::counting_iterator(points.size()), + Tree::Splitter(), + STraits((Point*)&(points[0])) ) { } @@ -265,22 +262,48 @@ public: { return m_points; }*/ - + + template void query_ANN(const Point &sp, unsigned int k, - size_t *neighbor_indices, - FT *squared_distance) const + IndexOutputIt indices_out) const { // Initialize the search structure, and search all N points - K_neighbor_search search(m_tree, sp, k); + // Note that we need to pass the Distance explicitly since it needs to + // know the property map + K_neighbor_search search(m_tree, sp, k, FT(0.1), true, + Distance_adapter >( + (Point*)&(m_points[0])) ); + // report the N nearest neighbors and their distance // This should sort all N points by increasing distance from origin - int i = 0; for(K_neighbor_search::iterator it = search.begin(); - it != search.end(); ++it, ++i) + it != search.end(); ++it) { - neighbor_indices[i] = boost::get<1>(it->first); - squared_distance[i] = it->second; + *indices_out++ = it->first; + } + } + + template + void query_ANN(const Point &sp, + unsigned int k, + IndexOutputIt indices_out, + DistanceOutputIt distances_out) const + { + // Initialize the search structure, and search all N points + // Note that we need to pass the Distance explicitly since it needs to + // know the property map + K_neighbor_search search(m_tree, sp, k, FT(0.1), true, + Distance_adapter >( + (Point*)&(m_points[0])) ); + + // report the N nearest neighbors and their distance + // This should sort all N points by increasing distance from origin + for(K_neighbor_search::iterator it = search.begin(); + it != search.end(); ++it) + { + *indices_out++ = it->first; + *distances_out++ = it->second; } }