Fix clang-tidy warnings

This commit is contained in:
Jose Luis Blanco-Claraco
2025-12-22 17:25:11 +01:00
parent 448b13faee
commit efa282de28
10 changed files with 179 additions and 57 deletions

View File

@@ -33,6 +33,9 @@
#include "utils.h"
namespace
{
template <typename num_t>
void kdtree_demo(const size_t N)
{
@@ -67,12 +70,21 @@ void kdtree_demo(const size_t N)
std::cout << "ret_index=" << ret_index << " out_dist_sqr=" << out_dist_sqr << std::endl;
}
}
} // namespace
int main()
{
// Randomize Seed
srand(static_cast<unsigned int>(time(nullptr)));
kdtree_demo<float>(1000000);
kdtree_demo<double>(1000000);
return 0;
try
{
// Randomize Seed
srand(static_cast<unsigned int>(time(nullptr)));
kdtree_demo<float>(1000000);
kdtree_demo<double>(1000000);
return 0;
}
catch (const std::exception& e)
{
std::cerr << e.what() << "\n";
return 1;
}
}

View File

@@ -33,6 +33,9 @@
#include "utils.h"
namespace
{
template <typename num_t>
void kdtree_demo(const size_t N)
{
@@ -66,12 +69,21 @@ void kdtree_demo(const size_t N)
std::cout << "ret_index=" << ret_index << " out_dist_sqr=" << out_dist_sqr << std::endl;
}
}
} // namespace
int main()
{
// Randomize Seed
srand(static_cast<unsigned int>(time(nullptr)));
kdtree_demo<float>(1000000);
kdtree_demo<double>(1000000);
return 0;
try
{
// Randomize Seed
srand(static_cast<unsigned int>(time(nullptr)));
kdtree_demo<float>(1000000);
kdtree_demo<double>(1000000);
return 0;
}
catch (const std::exception& e)
{
std::cerr << e.what() << "\n";
return 1;
}
}

View File

@@ -33,6 +33,9 @@
#include "utils.h"
namespace
{
template <typename num_t>
void kdtree_demo(const size_t N)
{
@@ -50,10 +53,10 @@ void kdtree_demo(const size_t N)
// Generate points:
generateRandomPointCloud(cloud, N);
num_t query_pt[3] = {0.5, 0.5, 0.5};
const num_t query_pt[3] = {0.5, 0.5, 0.5};
// add points in chunks at a time
size_t chunk_size = 100;
const size_t chunk_size = 100;
for (size_t i = 0; i < N; i = i + chunk_size)
{
size_t end = std::min<size_t>(i + chunk_size, N - 1);
@@ -62,7 +65,7 @@ void kdtree_demo(const size_t N)
}
// remove a point
size_t removePointIndex = N - 1;
const size_t removePointIndex = N - 1;
index.removePoint(removePointIndex);
dump_mem_usage();
@@ -115,7 +118,7 @@ void kdtree_demo(const size_t N)
index.findNeighbors(resultSet, query_pt);
nanoflann::ResultItem<size_t, num_t> worst_pair = resultSet.worst_item();
const nanoflann::ResultItem<size_t, num_t> worst_pair = resultSet.worst_item();
std::cout << "Worst pair: idx=" << worst_pair.first << " dist=" << worst_pair.second
<< std::endl;
std::cout << "point: (" << cloud.pts[worst_pair.first].x << ", "
@@ -124,12 +127,21 @@ void kdtree_demo(const size_t N)
std::cout << std::endl;
}
}
} // namespace
int main()
{
// Randomize Seed
srand(static_cast<unsigned int>(time(nullptr)));
kdtree_demo<float>(1000000);
kdtree_demo<double>(1000000);
return 0;
try
{
// Randomize Seed
srand(static_cast<unsigned int>(time(nullptr)));
kdtree_demo<float>(1000000);
kdtree_demo<double>(1000000);
return 0;
}
catch (const std::exception& e)
{
std::cerr << e.what() << "\n";
return 1;
}
}

View File

@@ -36,6 +36,9 @@
void dump_mem_usage();
namespace
{
// And this is the "dataset to kd-tree" adaptor class:
template <typename Derived>
struct PointCloudAdaptor
@@ -122,12 +125,21 @@ void kdtree_demo(const size_t N)
do_knn_search(index1);
do_knn_search(index2);
}
} // namespace
int main()
{
// Randomize Seed
srand((unsigned int)time(NULL));
kdtree_demo<float>(1000000);
kdtree_demo<double>(1000000);
return 0;
try
{
// Randomize Seed
srand((unsigned int)time(NULL));
kdtree_demo<float>(1000000);
kdtree_demo<double>(1000000);
return 0;
}
catch (const std::exception& e)
{
std::cerr << e.what() << "\n";
return 1;
}
}

View File

@@ -40,6 +40,9 @@ using namespace nanoflann;
// the metric class My_Custom_Metric_Adaptor, whose constructor accepts
// arbitrary parameters:
namespace
{
template <class T, class DataSource, typename _DistanceType = T, typename IndexType = uint32_t>
struct My_Custom_Metric_Adaptor
{
@@ -122,11 +125,20 @@ static void kdtree_custom_metric_demo(const size_t N)
cout << "Worst pair: idx=" << worst_pair.first << " dist=" << worst_pair.second << endl;
}
}
} // namespace
int main()
{
// Randomize Seed
srand(static_cast<unsigned int>(time(nullptr)));
kdtree_custom_metric_demo(10000);
return 0;
try
{
// Randomize Seed
srand(static_cast<unsigned int>(time(nullptr)));
kdtree_custom_metric_demo(10000);
return 0;
}
catch (const std::exception& e)
{
std::cerr << e.what() << "\n";
return 1;
}
}

View File

@@ -30,12 +30,14 @@
#include <ctime>
#include <iostream>
#include <nanoflann.hpp>
#include <type_traits>
#include "utils.h"
using num_t = double;
namespace
{
template <typename _DistanceType, typename _IndexType = size_t>
class MyCustomResultSet
{
@@ -113,11 +115,20 @@ void kdtree_demo(const size_t N)
std::cout << "Found: " << indices_dists.size() << " NN points." << std::endl;
}
}
} // namespace
int main()
{
// Randomize Seed
srand(static_cast<unsigned int>(time(nullptr)));
kdtree_demo(10000);
return 0;
try
{
// Randomize Seed
srand(static_cast<unsigned int>(time(nullptr)));
kdtree_demo(10000);
return 0;
}
catch (const std::exception& e)
{
std::cerr << e.what() << "\n";
return 1;
}
}

View File

@@ -34,6 +34,9 @@
#include "utils.h"
namespace
{
template <typename num_t>
void kdtree_demo(const size_t N)
{
@@ -85,12 +88,21 @@ void kdtree_demo(const size_t N)
<< std::endl;
}
}
} // namespace
int main()
{
// Randomize Seed
srand(static_cast<unsigned int>(time(nullptr)));
kdtree_demo<float>(1000000);
kdtree_demo<double>(1000000);
return 0;
try
{
// Randomize Seed
srand(static_cast<unsigned int>(time(nullptr)));
kdtree_demo<float>(1000000);
kdtree_demo<double>(1000000);
return 0;
}
catch (const std::exception& e)
{
std::cerr << e.what() << "\n";
return 1;
}
}

View File

@@ -33,6 +33,9 @@
#include "utils.h"
namespace
{
template <typename num_t>
void kdtree_demo(const size_t N)
{
@@ -99,12 +102,21 @@ void kdtree_demo(const size_t N)
cout << "\n";
}
}
} // namespace
int main()
{
// Randomize Seed
srand(static_cast<unsigned int>(time(nullptr)));
kdtree_demo<float>(4);
kdtree_demo<double>(100000);
return 0;
try
{
// Randomize Seed
srand(static_cast<unsigned int>(time(nullptr)));
kdtree_demo<float>(4);
kdtree_demo<double>(100000);
return 0;
}
catch (const std::exception& e)
{
std::cerr << e.what() << "\n";
return 1;
}
}

View File

@@ -34,6 +34,8 @@
#include "utils.h"
namespace
{
void kdtree_save_load_demo(const size_t N)
{
PointCloud<double> cloud;
@@ -41,7 +43,7 @@ void kdtree_save_load_demo(const size_t N)
// Generate points:
generateRandomPointCloud(cloud, N);
double query_pt[3] = {0.5, 0.5, 0.5};
const double query_pt[3] = {0.5, 0.5, 0.5};
// construct a kd-tree index:
using my_kd_tree_t = nanoflann::KDTreeSingleIndexAdaptor<
@@ -51,12 +53,15 @@ void kdtree_save_load_demo(const size_t N)
// Construct the index and save it:
// --------------------------------------------
{
my_kd_tree_t index(
const my_kd_tree_t index(
3 /*dim*/, cloud, nanoflann::KDTreeSingleIndexAdaptorParams(10 /* max leaf */));
std::ofstream f("index.bin", std::ofstream::binary);
if (f.bad()) throw std::runtime_error("Error writing index file!");
if (f.bad())
{
throw std::runtime_error("Error writing index file!");
}
index.saveIndex(f);
f.close();
@@ -91,24 +96,33 @@ void kdtree_save_load_demo(const size_t N)
index.findNeighbors(resultSet, &query_pt[0]);
std::cout << "knnSearch(nn=" << num_results << "): \n";
std::cout << "ret_index=" << ret_index << " out_dist_sqr=" << out_dist_sqr << std::endl;
std::cout << "ret_index=" << ret_index << " out_dist_sqr=" << out_dist_sqr << "\n";
}
// Stress test: try to save an empty index
{
PointCloud<double> emptyCloud;
my_kd_tree_t index(3 /*dim*/, emptyCloud);
std::ofstream f("index2.bin", std::ofstream::binary);
const PointCloud<double> emptyCloud;
const my_kd_tree_t index(3 /*dim*/, emptyCloud);
std::ofstream f("index2.bin", std::ofstream::binary);
if (f.bad()) throw std::runtime_error("Error writing index file!");
index.saveIndex(f);
f.close();
}
}
} // namespace
int main()
{
// Randomize Seed
srand(static_cast<unsigned int>(time(nullptr)));
kdtree_save_load_demo(100000);
return 0;
try
{
// Randomize Seed
srand(static_cast<unsigned int>(time(nullptr)));
kdtree_save_load_demo(100000);
return 0;
}
catch (const std::exception& e)
{
std::cerr << e.what() << "\n";
return 1;
}
}

View File

@@ -35,6 +35,9 @@ using namespace nanoflann;
#include "KDTreeVectorOfVectorsAdaptor.h"
namespace
{
const int SAMPLES_DIM = 15;
typedef std::vector<std::vector<double>> my_vector_of_vectors_t;
@@ -88,10 +91,20 @@ void kdtree_demo(const size_t nSamples, const size_t dim)
std::cout << "ret_index[" << i << "]=" << ret_indexes[i]
<< " out_dist_sqr=" << out_dists_sqr[i] << std::endl;
}
} // namespace
int main()
{
// Randomize Seed
srand(static_cast<unsigned int>(time(nullptr)));
kdtree_demo(1000 /* samples */, SAMPLES_DIM /* dim */);
try
{
// Randomize Seed
srand(static_cast<unsigned int>(time(nullptr)));
kdtree_demo(1000 /* samples */, SAMPLES_DIM /* dim */);
return 0;
}
catch (const std::exception& e)
{
std::cerr << e.what() << "\n";
return 1;
}
}