Add examples to search the closest vertices of a polygonal mesh

This commit is contained in:
Andreas Fabri 2015-01-27 10:51:48 +01:00
parent 90543eefab
commit c0286ce026
6 changed files with 127 additions and 4 deletions

View File

@ -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<Key,PointPropertyMap,BaseTraits>` and
The following four example programs illustrate how to use the classes `Search_traits_adapter<Key,PointPropertyMap,BaseTraits>` and
`Distance_adapter<Key,PointPropertyMap,Base_distance>` to store in the kd-tree objects of an arbitrary key type. Points are
accessed through a point <A HREF="http://www.boost.org/doc/libs/release/libs/property_map/index.html">property map</A>.
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<Mesh>::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

View File

@ -5,3 +5,5 @@ Algebraic_foundations
Circulator
Stream_support
Kernel_d
Surface_mesh
Polyhedron

View File

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

View File

@ -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" )

View File

@ -0,0 +1,53 @@
#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/Polyhedron_3.h>
#include <CGAL/IO/Polyhedron_iostream.h>
#include <CGAL/boost/graph/graph_traits_Polyhedron_3.h>
#include <fstream>
typedef CGAL::Exact_predicates_inexact_constructions_kernel Kernel;
typedef Kernel::Point_3 Point_3;
typedef CGAL::Polyhedron_3<Kernel> Mesh;
typedef boost::graph_traits<Mesh>::vertex_descriptor Point;
typedef boost::property_map<Mesh,CGAL::vertex_point_t>::type Vertex_point_pmap;
typedef CGAL::Search_traits_3<Kernel> Traits_base;
typedef CGAL::Search_traits_adapter<Point,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[]) {
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;
}

View File

@ -0,0 +1,52 @@
#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/Surface_mesh.h>
#include <fstream>
typedef CGAL::Exact_predicates_inexact_constructions_kernel Kernel;
typedef Kernel::Point_3 Point_3;
typedef CGAL::Surface_mesh<Point_3> Mesh;
typedef boost::graph_traits<Mesh>::vertex_descriptor Point;
typedef boost::graph_traits<Mesh>::vertices_size_type size_type;
typedef boost::property_map<Mesh,CGAL::vertex_point_t>::type Vertex_point_pmap;
typedef CGAL::Search_traits_3<Kernel> Traits_base;
typedef CGAL::Search_traits_adapter<Point,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[]) {
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;
}