SpiecsEngine
 
Loading...
Searching...
No Matches

◆ TEST_F() [10/72]

SpicesTest::TEST_F ( kd_tree_test ,
NearestNeighbourSearch  )

Testing if NearestNeighbourSearch successfully.

Search for specific points.

Definition at line 104 of file KDTree_test.h.

104 {
105
107
111 scl::kd_tree<2>::item val = { 2, 2 };
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;
117 scl::kd_tree<3> modelKDTree;
118 std::vector<scl::kd_tree<3>::item> points;
119 const scl::kd_tree<3>::item findVal = { 50.2f, 87.3f, 12.6f };
120
121 {
122 SPICESTEST_PROFILE_SCOPE("Create Points Collection.");
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 {
134 SPICESTEST_PROFILE_SCOPE("Insert to KDTree");
135
136 Spices::ThreadPool threadPool;
138 threadPool.Start(10);
139 modelKDTree.insert_async(points, &threadPool);
140 EXPECT_EQ(modelKDTree.size(), nPoints);
141 }
142
143 {
144 SPICESTEST_PROFILE_SCOPE("Search in KDTree");
145
146 for (int i = 0; i < nSearchs; i++)
147 {
148 auto rval = modelKDTree.nearest_neighbour_search(findVal, { 10.0f, 10.0f, 10.0f });
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 {
157 SPICESTEST_PROFILE_SCOPE("Search in Loop");
158
159 for (int i = 0; i < nSearchs; i++)
160 {
161 scl::kd_tree<3>::item nearVal = { 1E11, 1E11, 1E11 };
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.
Definition KDTree.h:237
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...
Definition KDTree.h:608
std::array< float, K > item
using item instead of point in k d.
Definition KDTree.h:33
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...
Definition KDTree.h:629
The kd_tree with K dimensions container Class. K the number of dimensions. Every node in the tree is ...
Definition KDTree.h:27