Skip to content

Commit efa282d

Browse files
committed
Fix clang-tidy warnings
1 parent 448b13f commit efa282d

10 files changed

+179
-57
lines changed

examples/SO2_adaptor_example.cpp

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@
3333

3434
#include "utils.h"
3535

36+
namespace
37+
{
38+
3639
template <typename num_t>
3740
void kdtree_demo(const size_t N)
3841
{
@@ -67,12 +70,21 @@ void kdtree_demo(const size_t N)
6770
std::cout << "ret_index=" << ret_index << " out_dist_sqr=" << out_dist_sqr << std::endl;
6871
}
6972
}
73+
} // namespace
7074

7175
int main()
7276
{
73-
// Randomize Seed
74-
srand(static_cast<unsigned int>(time(nullptr)));
75-
kdtree_demo<float>(1000000);
76-
kdtree_demo<double>(1000000);
77-
return 0;
77+
try
78+
{
79+
// Randomize Seed
80+
srand(static_cast<unsigned int>(time(nullptr)));
81+
kdtree_demo<float>(1000000);
82+
kdtree_demo<double>(1000000);
83+
return 0;
84+
}
85+
catch (const std::exception& e)
86+
{
87+
std::cerr << e.what() << "\n";
88+
return 1;
89+
}
7890
}

examples/SO3_adaptor_example.cpp

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@
3333

3434
#include "utils.h"
3535

36+
namespace
37+
{
38+
3639
template <typename num_t>
3740
void kdtree_demo(const size_t N)
3841
{
@@ -66,12 +69,21 @@ void kdtree_demo(const size_t N)
6669
std::cout << "ret_index=" << ret_index << " out_dist_sqr=" << out_dist_sqr << std::endl;
6770
}
6871
}
72+
} // namespace
6973

7074
int main()
7175
{
72-
// Randomize Seed
73-
srand(static_cast<unsigned int>(time(nullptr)));
74-
kdtree_demo<float>(1000000);
75-
kdtree_demo<double>(1000000);
76-
return 0;
76+
try
77+
{
78+
// Randomize Seed
79+
srand(static_cast<unsigned int>(time(nullptr)));
80+
kdtree_demo<float>(1000000);
81+
kdtree_demo<double>(1000000);
82+
return 0;
83+
}
84+
catch (const std::exception& e)
85+
{
86+
std::cerr << e.what() << "\n";
87+
return 1;
88+
}
7789
}

examples/dynamic_pointcloud_example.cpp

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@
3333

3434
#include "utils.h"
3535

36+
namespace
37+
{
38+
3639
template <typename num_t>
3740
void 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

128132
int 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
}

examples/pointcloud_adaptor_example.cpp

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@
3636

3737
void dump_mem_usage();
3838

39+
namespace
40+
{
41+
3942
// And this is the "dataset to kd-tree" adaptor class:
4043
template <typename Derived>
4144
struct PointCloudAdaptor
@@ -122,12 +125,21 @@ void kdtree_demo(const size_t N)
122125
do_knn_search(index1);
123126
do_knn_search(index2);
124127
}
128+
} // namespace
125129

126130
int main()
127131
{
128-
// Randomize Seed
129-
srand((unsigned int)time(NULL));
130-
kdtree_demo<float>(1000000);
131-
kdtree_demo<double>(1000000);
132-
return 0;
132+
try
133+
{
134+
// Randomize Seed
135+
srand((unsigned int)time(NULL));
136+
kdtree_demo<float>(1000000);
137+
kdtree_demo<double>(1000000);
138+
return 0;
139+
}
140+
catch (const std::exception& e)
141+
{
142+
std::cerr << e.what() << "\n";
143+
return 1;
144+
}
133145
}

examples/pointcloud_custom_metric.cpp

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ using namespace nanoflann;
4040
// the metric class My_Custom_Metric_Adaptor, whose constructor accepts
4141
// arbitrary parameters:
4242

43+
namespace
44+
{
45+
4346
template <class T, class DataSource, typename _DistanceType = T, typename IndexType = uint32_t>
4447
struct My_Custom_Metric_Adaptor
4548
{
@@ -122,11 +125,20 @@ static void kdtree_custom_metric_demo(const size_t N)
122125
cout << "Worst pair: idx=" << worst_pair.first << " dist=" << worst_pair.second << endl;
123126
}
124127
}
128+
} // namespace
125129

126130
int main()
127131
{
128-
// Randomize Seed
129-
srand(static_cast<unsigned int>(time(nullptr)));
130-
kdtree_custom_metric_demo(10000);
131-
return 0;
132+
try
133+
{
134+
// Randomize Seed
135+
srand(static_cast<unsigned int>(time(nullptr)));
136+
kdtree_custom_metric_demo(10000);
137+
return 0;
138+
}
139+
catch (const std::exception& e)
140+
{
141+
std::cerr << e.what() << "\n";
142+
return 1;
143+
}
132144
}

examples/pointcloud_custom_resultset.cpp

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,14 @@
3030
#include <ctime>
3131
#include <iostream>
3232
#include <nanoflann.hpp>
33-
#include <type_traits>
3433

3534
#include "utils.h"
3635

3736
using num_t = double;
3837

38+
namespace
39+
{
40+
3941
template <typename _DistanceType, typename _IndexType = size_t>
4042
class MyCustomResultSet
4143
{
@@ -113,11 +115,20 @@ void kdtree_demo(const size_t N)
113115
std::cout << "Found: " << indices_dists.size() << " NN points." << std::endl;
114116
}
115117
}
118+
} // namespace
116119

117120
int main()
118121
{
119-
// Randomize Seed
120-
srand(static_cast<unsigned int>(time(nullptr)));
121-
kdtree_demo(10000);
122-
return 0;
122+
try
123+
{
124+
// Randomize Seed
125+
srand(static_cast<unsigned int>(time(nullptr)));
126+
kdtree_demo(10000);
127+
return 0;
128+
}
129+
catch (const std::exception& e)
130+
{
131+
std::cerr << e.what() << "\n";
132+
return 1;
133+
}
123134
}

examples/pointcloud_example.cpp

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@
3434

3535
#include "utils.h"
3636

37+
namespace
38+
{
39+
3740
template <typename num_t>
3841
void kdtree_demo(const size_t N)
3942
{
@@ -85,12 +88,21 @@ void kdtree_demo(const size_t N)
8588
<< std::endl;
8689
}
8790
}
91+
} // namespace
8892

8993
int main()
9094
{
91-
// Randomize Seed
92-
srand(static_cast<unsigned int>(time(nullptr)));
93-
kdtree_demo<float>(1000000);
94-
kdtree_demo<double>(1000000);
95-
return 0;
95+
try
96+
{
97+
// Randomize Seed
98+
srand(static_cast<unsigned int>(time(nullptr)));
99+
kdtree_demo<float>(1000000);
100+
kdtree_demo<double>(1000000);
101+
return 0;
102+
}
103+
catch (const std::exception& e)
104+
{
105+
std::cerr << e.what() << "\n";
106+
return 1;
107+
}
96108
}

examples/pointcloud_kdd_radius.cpp

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@
3333

3434
#include "utils.h"
3535

36+
namespace
37+
{
38+
3639
template <typename num_t>
3740
void kdtree_demo(const size_t N)
3841
{
@@ -99,12 +102,21 @@ void kdtree_demo(const size_t N)
99102
cout << "\n";
100103
}
101104
}
105+
} // namespace
102106

103107
int main()
104108
{
105-
// Randomize Seed
106-
srand(static_cast<unsigned int>(time(nullptr)));
107-
kdtree_demo<float>(4);
108-
kdtree_demo<double>(100000);
109-
return 0;
109+
try
110+
{
111+
// Randomize Seed
112+
srand(static_cast<unsigned int>(time(nullptr)));
113+
kdtree_demo<float>(4);
114+
kdtree_demo<double>(100000);
115+
return 0;
116+
}
117+
catch (const std::exception& e)
118+
{
119+
std::cerr << e.what() << "\n";
120+
return 1;
121+
}
110122
}

0 commit comments

Comments
 (0)