MEPP2 Project
PointCloudNNSearchConceptCheck.h
Go to the documentation of this file.
1 // Copyright (c) 2012-2019 University of Lyon and CNRS (France).
2 // All rights reserved.
3 //
4 // This file is part of MEPP2; you can redistribute it and/or modify
5 // it under the terms of the GNU Lesser General Public License as
6 // published by the Free Software Foundation; either version 3 of
7 // the License, or (at your option) any later version.
8 //
9 // This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
10 // WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
11 #pragma once
12 
13 
15 #include <cassert>
16 #include <cmath>
17 
18 
19 namespace FEVV {
20 
21 // Needs Graph_traits, Geometry_traits and Graph_properties
22 template<typename PointCloudT>
23 void
25 {
26  // types
27  typedef boost::graph_traits< PointCloudT > GraphTraits;
28  //typedef typename GraphTraits::vertices_size_type vertices_size_type;
30  //typedef typename GraphTraits::vertex_iterator vertex_iterator;
31  typedef FEVV::Geometry_traits< PointCloudT > Geometry;
32  typedef typename Geometry::Point Point;
33 
34  // create point cloud
35  PointCloudT cloud;
36 
37  // create points
38  vertex_descriptor v0 = add_vertex(cloud);
39  vertex_descriptor v1 = add_vertex(cloud);
40  vertex_descriptor v2 = add_vertex(cloud);
41  vertex_descriptor v3 = add_vertex(cloud);
42  vertex_descriptor v4 = add_vertex(cloud);
43  vertex_descriptor v5 = add_vertex(cloud);
44 
45  // set points geometry
46  auto pm = get(boost::vertex_point, cloud);
47  put(pm, v0, Point(0, 0, 0));
48  put(pm, v1, Point(2, 2, 0));
49  put(pm, v2, Point(1, 2, 0));
50  put(pm, v3, Point(1, 1, 0));
51  put(pm, v4, Point(0, 3, 0));
52  put(pm, v5, Point(3, 0, 0));
53 
54  // init kd-tree
55  auto kd_tree_ptr = create_kd_tree(cloud);
56 
57  // test kNN-search
58  {
59  // do kNN-search
60  unsigned int k = 3;
61  auto result = kNN_search(*kd_tree_ptr, k, Point(0.6, 0.6, 0.), cloud);
62 
63  // check search result
64  auto nn_ids = result.first;
65  assert(nn_ids.size() == k);
66  assert(nn_ids[0] == static_cast< vertex_descriptor >(3));
67  assert(nn_ids[1] == static_cast< vertex_descriptor >(0));
68  assert(nn_ids[2] == static_cast< vertex_descriptor >(2));
69  auto nn_dists = result.second;
70  assert(nn_dists.size() == k);
71  assert(std::abs(nn_dists[0] - 0.565685) <= 0.0001);
72  assert(std::abs(nn_dists[1] - 0.848528) <= 0.0001);
73  assert(std::abs(nn_dists[2] - 1.45602) <= 0.0001);
74  }
75 
76  // test radius search
77  {
78  // do radius-search
79  double r = 2.0;
80  auto result = radius_search(*kd_tree_ptr, r, Point(0.6, 0.6, 0.), cloud);
81 
82  // check search result
83  auto nn_ids = result.first;
84  assert(nn_ids.size() == 4);
85  assert(nn_ids[0] == static_cast< vertex_descriptor >(3));
86  assert(nn_ids[1] == static_cast< vertex_descriptor >(0));
87  assert(nn_ids[2] == static_cast< vertex_descriptor >(2));
88  assert(nn_ids[3] == static_cast< vertex_descriptor >(1));
89  auto nn_dists = result.second;
90  assert(nn_dists.size() == 4);
91  assert(std::abs(nn_dists[0] - 0.565685) <= 0.0001);
92  assert(std::abs(nn_dists[1] - 0.848528) <= 0.0001);
93  assert(std::abs(nn_dists[2] - 1.456020) <= 0.0001);
94  assert(std::abs(nn_dists[3] - 1.979899) <= 0.0001);
95  }
96 }
97 
98 } // namespace FEVV
CGAL::kNN_search
std::pair< std::vector< CGALPointSetNNSearch::vertex_descriptor >, std::vector< double > > kNN_search(const CGALPointSetNNSearch::KdTree &kd_tree, unsigned int k, const FEVV::CGALPointSetPoint &query, const FEVV::CGALPointSet &pc)
Search the k nearest neighbors of a geometric point.
Definition: Graph_properties_cgal_point_set.h:113
FEVV::check_point_cloud_NN_search_concept
void check_point_cloud_NN_search_concept(void)
Definition: PointCloudNNSearchConceptCheck.h:24
CGAL::create_kd_tree
CGALPointSetNNSearch::KdTreePtr create_kd_tree(const FEVV::CGALPointSet &pc)
Initialize a k-d tree with all cloud points.
Definition: Graph_properties_cgal_point_set.h:83
FEVV::Geometry_traits
Refer to Geometry_traits_documentation_dummy for further documentation on provided types and algorith...
Definition: Geometry_traits.h:162
Point
AIFMesh::Point Point
Definition: Graph_properties_aif.h:21
FEVV::get
FEVV::PCLPointCloudPointMap::value_type get(const FEVV::PCLPointCloudPointMap &pm, FEVV::PCLPointCloudPointMap::key_type key)
Specialization of get(point_map, key) for PCLPointCloud.
Definition: Graph_properties_pcl_point_cloud.h:117
FEVV
Interfaces for plugins These interfaces will be used for different plugins.
Definition: Assert.h:16
Geometry_traits.h
FEVV::DataStructures::AIF::add_vertex
boost::graph_traits< FEVV::DataStructures::AIF::AIFMesh >::vertex_descriptor add_vertex(typename boost::graph_traits< FEVV::DataStructures::AIF::AIFMesh >::vertex_property_type vp, FEVV::DataStructures::AIF::AIFMesh &sm)
Definition: Graph_properties_aif.h:263
msdm2::vertex_descriptor
boost::graph_traits< MeshT >::vertex_descriptor vertex_descriptor
Definition: msdm2_surfacemesh.h:33
FEVV::put
void put(FEVV::PCLPointCloudPointMap &pm, FEVV::PCLPointCloudPointMap::key_type key, const FEVV::PCLPointCloudPointMap::value_type &value)
Specialization of put(point_map, key, value) for PCLPointCloud.
Definition: Graph_properties_pcl_point_cloud.h:126
CGAL::radius_search
std::pair< std::vector< CGALPointSetNNSearch::vertex_descriptor >, std::vector< double > > radius_search(const CGALPointSetNNSearch::KdTree &kd_tree, double radius, const FEVV::CGALPointSetPoint &query, const FEVV::CGALPointSet &pc)
Search for the nearest neighbors of a geometric point in the given radius.
Definition: Graph_properties_cgal_point_set.h:157