3333
3434#include " utils.h"
3535
36+ namespace
37+ {
38+
3639template <typename num_t >
3740void kdtree_demo (const size_t N)
3841{
@@ -50,10 +53,10 @@ void kdtree_demo(const size_t N)
5053 // Generate points:
5154 generateRandomPointCloud (cloud, N);
5255
53- num_t query_pt[3 ] = {0.5 , 0.5 , 0.5 };
56+ const num_t query_pt[3 ] = {0.5 , 0.5 , 0.5 };
5457
5558 // add points in chunks at a time
56- size_t chunk_size = 100 ;
59+ const size_t chunk_size = 100 ;
5760 for (size_t i = 0 ; i < N; i = i + chunk_size)
5861 {
5962 size_t end = std::min<size_t >(i + chunk_size, N - 1 );
@@ -62,7 +65,7 @@ void kdtree_demo(const size_t N)
6265 }
6366
6467 // remove a point
65- size_t removePointIndex = N - 1 ;
68+ const size_t removePointIndex = N - 1 ;
6669 index.removePoint (removePointIndex);
6770
6871 dump_mem_usage ();
@@ -115,7 +118,7 @@ void kdtree_demo(const size_t N)
115118
116119 index.findNeighbors (resultSet, query_pt);
117120
118- nanoflann::ResultItem<size_t , num_t > worst_pair = resultSet.worst_item ();
121+ const nanoflann::ResultItem<size_t , num_t > worst_pair = resultSet.worst_item ();
119122 std::cout << " Worst pair: idx=" << worst_pair.first << " dist=" << worst_pair.second
120123 << std::endl;
121124 std::cout << " point: (" << cloud.pts [worst_pair.first ].x << " , "
@@ -124,12 +127,21 @@ void kdtree_demo(const size_t N)
124127 std::cout << std::endl;
125128 }
126129}
130+ } // namespace
127131
128132int main ()
129133{
130- // Randomize Seed
131- srand (static_cast <unsigned int >(time (nullptr )));
132- kdtree_demo<float >(1000000 );
133- kdtree_demo<double >(1000000 );
134- return 0 ;
134+ try
135+ {
136+ // Randomize Seed
137+ srand (static_cast <unsigned int >(time (nullptr )));
138+ kdtree_demo<float >(1000000 );
139+ kdtree_demo<double >(1000000 );
140+ return 0 ;
141+ }
142+ catch (const std::exception& e)
143+ {
144+ std::cerr << e.what () << " \n " ;
145+ return 1 ;
146+ }
135147}
0 commit comments