Skip to content

Commit

Permalink
Merge pull request #7888 from afabri/Spatial_searching-add_example-GF
Browse files Browse the repository at this point in the history
Spatial Searching: Add example storing triangulation vertices
  • Loading branch information
lrineau committed Dec 11, 2023
2 parents e2a745f + f9e405f commit 3cd25f4
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 0 deletions.
1 change: 1 addition & 0 deletions Spatial_searching/doc/Spatial_searching/examples.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
\example Spatial_searching/searching_with_circular_query.cpp
\example Spatial_searching/searching_surface_mesh_vertices.cpp
\example Spatial_searching/searching_polyhedron_vertices.cpp
\example Spatial_searching/searching_triangulation_vertices.cpp
\example Spatial_searching/searching_with_point_with_info.cpp
\example Spatial_searching/searching_with_point_with_info_inplace.cpp
\example Spatial_searching/searching_with_point_with_info_pmap.cpp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ create_single_source_cgal_program("searching_with_point_with_info_inplace.cpp")
create_single_source_cgal_program("searching_with_point_with_info_pmap.cpp")
create_single_source_cgal_program("searching_surface_mesh_vertices.cpp")
create_single_source_cgal_program("searching_polyhedron_vertices.cpp")
create_single_source_cgal_program("searching_triangulation_vertices.cpp")
create_single_source_cgal_program("searching_polyhedron_vertices_with_fuzzy_sphere.cpp")
create_single_source_cgal_program("user_defined_point_and_distance.cpp")
create_single_source_cgal_program("using_fair_splitting_rule.cpp")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Search_traits_3.h>
#include <CGAL/Search_traits_adapter.h>
#include <CGAL/Orthogonal_k_neighbor_search.h>
#include <CGAL/Delaunay_triangulation_3.h>
#include <CGAL/function_objects.h>

#include <boost/property_map/function_property_map.hpp>

#include <fstream>

typedef CGAL::Exact_predicates_inexact_constructions_kernel Kernel;
typedef Kernel::Point_3 Point_3;
typedef CGAL::Delaunay_triangulation_3<Kernel> Delaunay;
typedef Delaunay::Vertex_handle Vertex_handle;


struct Project {
typedef Vertex_handle argument_type;
typedef const Point_3& Point;
typedef Point result_type;
Point operator()( Vertex_handle v) const { return v->point(); }
};


typedef boost::function_property_map<Project, Vertex_handle> Vertex_point_pmap;
typedef CGAL::Search_traits_3<Kernel> Traits_base;
typedef CGAL::Search_traits_adapter<Vertex_handle,Vertex_point_pmap,Traits_base> Traits;
typedef CGAL::Orthogonal_k_neighbor_search<Traits> K_neighbor_search;
typedef K_neighbor_search::Tree Tree;
typedef Tree::Splitter Splitter;
typedef K_neighbor_search::Distance Distance;

int main(int argc, char* argv[])
{
std::ifstream in((argc>1)?argv[1]:CGAL::data_file_path("points_3/kitten.xyz"));
std::vector<Point_3> points;
Point_3 p;
while(in >> p){
points.push_back(p);
}

Delaunay dt(points.begin(), points.end());

const unsigned int K = 5;

Project project;
Vertex_point_pmap vppmap(project);

// Insert number_of_data_points in the tree
Tree tree(dt.finite_vertex_handles().begin(), dt.finite_vertex_handles().end(), Splitter(), Traits(vppmap));

// search K nearest neighbors
Point_3 query(0.0, 0.0, 0.0);
Distance tr_dist(vppmap);

K_neighbor_search search(tree, query, K,0,true,tr_dist);
std::cout <<"The "<< K << " nearest vertices to the query point at (0,0,0) are:" << std::endl;
for(K_neighbor_search::iterator it = search.begin(); it != search.end(); it++){
std::cout << "vertex " << &*(it->first) << " : " << vppmap[it->first] << " at distance "
<< tr_dist.inverse_of_transformed_distance(it->second) << std::endl;
}

return 0;
}

0 comments on commit 3cd25f4

Please sign in to comment.