Testing if NearestNeighbourSearch successfully.
Search for specific points.
104 {
105
107
112
113 EXPECT_EQ(m_KDTree.nearest_neighbour_search({ 2.0, 0.0 }, { 3.0, 3.0 }), val);
114
115 constexpr int nPoints = 1000;
116 constexpr int nSearchs = 1000;
118 std::vector<scl::kd_tree<3>::item> points;
120
121 {
123
124 points.resize(nPoints);
125 for (int i = 0; i < nPoints; i++)
126 {
127 points[i][0] = std::rand() / float(RAND_MAX) * 100.0f;
128 points[i][1] = std::rand() / float(RAND_MAX) * 100.0f;
129 points[i][2] = std::rand() / float(RAND_MAX) * 100.0f;
130 }
131 }
132
133 {
135
138 threadPool.
Start(10);
140 EXPECT_EQ(modelKDTree.
size(), nPoints);
141 }
142
143 {
145
146 for (int i = 0; i < nSearchs; i++)
147 {
149 bool check = 10.0f - std::abs(rval[0] - findVal[0]) > 0.0f;
150 EXPECT_EQ(check, true);
151 }
152 }
153
154#if 1
155
156 {
158
159 for (int i = 0; i < nSearchs; i++)
160 {
162
163 for (int j = 0; j < nPoints; j++)
164 {
165 if (std::abs(points[j][0] - findVal[0]) < nearVal[0] &&
166 std::abs(points[j][1] - findVal[1]) < nearVal[1] &&
167 std::abs(points[j][2] - findVal[2]) < nearVal[2])
168 {
169 nearVal = points[j];
170 }
171 }
172
173 bool check = 10.0f - nearVal[0] > 0.0f;
174 EXPECT_EQ(check, true);
175 }
176 }
177
178#endif
179
180 }
#define SPICESTEST_PROFILE_SCOPE(name)
#define SPICESTEST_PROFILE_FUNCTION()
void SetMode(PoolMode mode)
Set Pool Run Mode.
void Start(int initThreadSize=0.5 *std::thread::hardware_concurrency())
Start Run this thread pool.
Thread Pool Basic Class. Instance inherited from it and use multithreading feature.
size_t size() const
Get KD Tree size.
void insert_async(const std::vector< item > &points, Spices::ThreadPool *threadPool)
Insert a point into the kd_tree async. Start at the root, comparing the new point’s first dimension w...
std::array< float, K > item
using item instead of point in k d.
auto nearest_neighbour_search(const item &point, const item &condition) const -> item
Search for a nearest point in the kd_tree. Traverse the tree as in a normal search to find the leaf n...
The kd_tree with K dimensions container Class. K the number of dimensions. Every node in the tree is ...