diff --git a/Spatial_searching/doc/Spatial_searching/Spatial_searching.txt b/Spatial_searching/doc/Spatial_searching/Spatial_searching.txt index ccb21533849..ca61d5d8445 100644 --- a/Spatial_searching/doc/Spatial_searching/Spatial_searching.txt +++ b/Spatial_searching/doc/Spatial_searching/Spatial_searching.txt @@ -346,32 +346,42 @@ wrapper for all our defined types. The searching itself works exactly as for \cg \subsection Spatial_searchingExamplesforUsinganArbitrary Examples for Using an Arbitrary Point Type with Point Property Maps -The following three example programs illustrate how to use the classes `Search_traits_adapter` and +The following four example programs illustrate how to use the classes `Search_traits_adapter` and `Distance_adapter` to store in the kd-tree objects of an arbitrary key type. Points are accessed through a point property map. This enables to associate information to a point or to reduce the size of the search structure. -\subsection Spatial_searchingUsingaPointandanInteger Using a Point and an Integer as Key Type +\subsubsection Spatial_searchingUsingaPointandanInteger Using a Point and an Integer as Key Type In this example program, the search tree stores tuples of point and integer. The value type of the iterator of the neighbor searching algorithm is this tuple type. \cgalExample{Spatial_searching/searching_with_point_with_info.cpp} -\subsection Spatial_searchingUsinganIntegerasKeyType Using an Integer as Key Type +\subsubsection Spatial_searchingUsinganIntegerasKeyType Using an Integer as Key Type In this example program, the search tree stores only integers that refer to points stored within a user vector. The point type of the search traits is `std::size_t`. \cgalExample{Spatial_searching/searching_with_point_with_info_inplace.cpp} -\subsection Spatial_searchingUsingaModelofLvalueProperty Using a Model of L-value Property Map Concept +\subsubsection Spatial_searchingUsingaModelofLvalueProperty Using a Model of L-value Property Map Concept This example programs uses a model of `LvaluePropertyMap`. Points are read from a `std::map`. The search tree stores integers of type `std::size_t`. The value type of the iterator of the neighbor searching algorithm is `std::size_t`. \cgalExample{Spatial_searching/searching_with_point_with_info_pmap.cpp} +\subsubsection Spatial_searchingUsingSurfaceMesh Using a Point Property Map of a Polygonal Mesh + +This example programs shows how to search the closest vertices of a `Surface_mesh` or, quite similar, of a +`Polyhedron_3`. +Points are stored in the polygonal mesh. The search tree stores vertex descriptors. The value type of the iterator of the neighbor searching algorithm is `boost::graph_traits::vertex_descriptor`. + +\cgalExample{Spatial_searching/searching_surface_mesh_vertices.cpp} + + + \subsection Spatial_searchingExampleforSelectingaSplitting Example for Selecting a Splitting Rule and Setting the Bucket Size This example program illustrates selecting a splitting rule and diff --git a/Spatial_searching/doc/Spatial_searching/dependencies b/Spatial_searching/doc/Spatial_searching/dependencies index d7cee2d67e5..81b09a3d80e 100644 --- a/Spatial_searching/doc/Spatial_searching/dependencies +++ b/Spatial_searching/doc/Spatial_searching/dependencies @@ -5,3 +5,5 @@ Algebraic_foundations Circulator Stream_support Kernel_d +Surface_mesh +Polyhedron diff --git a/Spatial_searching/doc/Spatial_searching/examples.txt b/Spatial_searching/doc/Spatial_searching/examples.txt index 86a12530d02..bf31eef0ad3 100644 --- a/Spatial_searching/doc/Spatial_searching/examples.txt +++ b/Spatial_searching/doc/Spatial_searching/examples.txt @@ -8,6 +8,8 @@ \example Spatial_searching/iso_rectangle_2_query.cpp \example Spatial_searching/nearest_neighbor_searching.cpp \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_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 diff --git a/Spatial_searching/examples/Spatial_searching/CMakeLists.txt b/Spatial_searching/examples/Spatial_searching/CMakeLists.txt index 4329110eb95..83cd7ce25c4 100644 --- a/Spatial_searching/examples/Spatial_searching/CMakeLists.txt +++ b/Spatial_searching/examples/Spatial_searching/CMakeLists.txt @@ -81,6 +81,10 @@ 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( "user_defined_point_and_distance.cpp" ) create_single_source_cgal_program( "using_fair_splitting_rule.cpp" ) diff --git a/Spatial_searching/examples/Spatial_searching/searching_polyhedron_vertices.cpp b/Spatial_searching/examples/Spatial_searching/searching_polyhedron_vertices.cpp new file mode 100644 index 00000000000..42d564ebaa5 --- /dev/null +++ b/Spatial_searching/examples/Spatial_searching/searching_polyhedron_vertices.cpp @@ -0,0 +1,53 @@ +#include +#include +#include +#include +#include +#include +#include +#include + +typedef CGAL::Exact_predicates_inexact_constructions_kernel Kernel; +typedef Kernel::Point_3 Point_3; + +typedef CGAL::Polyhedron_3 Mesh; +typedef boost::graph_traits::vertex_descriptor Point; + +typedef boost::property_map::type Vertex_point_pmap; + +typedef CGAL::Search_traits_3 Traits_base; +typedef CGAL::Search_traits_adapter Traits; + + +typedef CGAL::Orthogonal_k_neighbor_search 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[]) { + Mesh mesh; + std::ifstream in(argv[1]); + in >> mesh; + const unsigned int K = 5; + + Vertex_point_pmap vppmap = get(CGAL::vertex_point,mesh); + + // Insert number_of_data_points in the tree + Tree tree( + vertices(mesh).begin(), + vertices(mesh).end(), + Splitter(), + Traits(vppmap) + ); + Point_3 query(0.0, 0.0, 0.0); + Distance tr_dist(vppmap); + + // search K nearest neighbours + 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; +} diff --git a/Spatial_searching/examples/Spatial_searching/searching_surface_mesh_vertices.cpp b/Spatial_searching/examples/Spatial_searching/searching_surface_mesh_vertices.cpp new file mode 100644 index 00000000000..3db4d7b3747 --- /dev/null +++ b/Spatial_searching/examples/Spatial_searching/searching_surface_mesh_vertices.cpp @@ -0,0 +1,52 @@ +#include +#include +#include +#include +#include +#include + +typedef CGAL::Exact_predicates_inexact_constructions_kernel Kernel; +typedef Kernel::Point_3 Point_3; + +typedef CGAL::Surface_mesh Mesh; +typedef boost::graph_traits::vertex_descriptor Point; +typedef boost::graph_traits::vertices_size_type size_type; + +typedef boost::property_map::type Vertex_point_pmap; + +typedef CGAL::Search_traits_3 Traits_base; +typedef CGAL::Search_traits_adapter Traits; + + +typedef CGAL::Orthogonal_k_neighbor_search 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[]) { + Mesh mesh; + std::ifstream in(argv[1]); + in >> mesh; + const unsigned int K = 5; + + Vertex_point_pmap vppmap = get(CGAL::vertex_point,mesh); + + // Insert number_of_data_points in the tree + Tree tree( + vertices(mesh).begin(), + vertices(mesh).end(), + Splitter(), + Traits(vppmap) + ); + Point_3 query(0.0, 0.0, 0.0); + Distance tr_dist(vppmap); + + // search K nearest neighbours + 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; +}