PeriDEM 0.2.0
PeriDEM -- Peridynamics-based high-fidelity model for granular media
Loading...
Searching...
No Matches
nsearch::NFlannSearchKd< dim > Class Template Reference

A class for nearest neighbor search using nanoflann library. More...

#include <nsearch.h>

Inheritance diagram for nsearch::NFlannSearchKd< dim >:
Collaboration diagram for nsearch::NFlannSearchKd< dim >:

Public Member Functions

 NFlannSearchKd (const PointCloud &x, size_t debug=0, size_t max_leafs=10)
 Constructor.
 
double setInputCloud () override
 Set input cloud.
 
double updatePointCloud (const std::vector< util::Point > &x, bool parallel=true) override
 Function to implement point cloud update.
 
size_t radiusSearch (const util::Point &searchPoint, const double &search_r, std::vector< size_t > &neighs, std::vector< double > &sqr_dist) override
 Perform radius search to find points in a point cloud within specified distance from a given point. = 0 = 0 = 0
 
size_t radiusSearch (const util::Point &searchPoint, const double &search_r, std::vector< int > &neighs, std::vector< float > &sqr_dist) override
 Perform radius search to find points in a point cloud within specified distance from a given point. = 0
 
size_t radiusSearchExcludeTag (const util::Point &searchPoint, const double &search_r, std::vector< size_t > &neighs, std::vector< double > &sqr_dist, const size_t &searchPointTag, const std::vector< size_t > &dataTags) override
 = 0
 
size_t radiusSearchExcludeTag (const util::Point &searchPoint, const double &search_r, std::vector< int > &neighs, std::vector< float > &sqr_dist, const size_t &searchPointTag, const std::vector< size_t > &dataTags) override
 = 0
 
size_t radiusSearchIncludeTag (const util::Point &searchPoint, const double &search_r, std::vector< size_t > &neighs, std::vector< double > &sqr_dist, const size_t &searchPointTag, const std::vector< size_t > &dataTags) override
 = 0
 
size_t radiusSearchIncludeTag (const util::Point &searchPoint, const double &search_r, std::vector< int > &neighs, std::vector< float > &sqr_dist, const size_t &searchPointTag, const std::vector< size_t > &dataTags) override
 = 0
 
void closestPoint (const util::Point &searchPoint, size_t &neigh, double &sqrDistNeigh) override
 = 0
 
- Public Member Functions inherited from nsearch::BaseNSearch
 BaseNSearch (std::string name, size_t debug=0)
 Constructor.
 

Data Fields

PointCloudAdaptor d_cloud
 coordinates of the points
 
nanoflann::KDTreeSingleIndexAdaptor< nanoflann::L2_Simple_Adaptor< double, PointCloudAdaptor >, PointCloudAdaptor, dim > d_tree
 Tree.
 
nanoflann::SearchParameters d_params
 Tree search parameters.
 
- Data Fields inherited from nsearch::BaseNSearch
size_t d_debug
 control the verbosity
 
std::string d_treeType
 name of tree: nflann_kdtree
 

Detailed Description

template<int dim = 3>
class nsearch::NFlannSearchKd< dim >

A class for nearest neighbor search using nanoflann library.

Definition at line 178 of file nsearch.h.

Constructor & Destructor Documentation

◆ NFlannSearchKd()

template<int dim = 3>
nsearch::NFlannSearchKd< dim >::NFlannSearchKd ( const PointCloud x,
size_t  debug = 0,
size_t  max_leafs = 10 
)
inlineexplicit

Constructor.

Parameters
xPoint cloud
debugDebug level to print information
max_leafMaximum number of leafs

Definition at line 188 of file nsearch.h.

189 : BaseNSearch("nflann_kdtree", debug),
190 d_cloud(x),
191 d_tree(dim, d_cloud,
192 nanoflann::KDTreeSingleIndexAdaptorParams(max_leafs /* max leaf */)) {
193 d_params.sorted = false;
194 };
BaseNSearch(std::string name, size_t debug=0)
Constructor.
Definition nsearch.h:36
nanoflann::SearchParameters d_params
Tree search parameters.
Definition nsearch.h:422
PointCloudAdaptor d_cloud
coordinates of the points
Definition nsearch.h:413
nanoflann::KDTreeSingleIndexAdaptor< nanoflann::L2_Simple_Adaptor< double, PointCloudAdaptor >, PointCloudAdaptor, dim > d_tree
Tree.
Definition nsearch.h:419

References nsearch::NFlannSearchKd< dim >::d_params.

Member Function Documentation

◆ closestPoint()

template<int dim = 3>
void nsearch::NFlannSearchKd< dim >::closestPoint ( const util::Point searchPoint,
size_t &  neigh,
double &  sqrDistNeigh 
)
inlineoverridevirtual

= 0

= 0

Implements nsearch::BaseNSearch.

Definition at line 400 of file nsearch.h.

403 {
404
405 double query_pt[3] = {searchPoint[0], searchPoint[1], searchPoint[2]};
406 unsigned int neigh_temp = 0;
407 d_tree.knnSearch(&query_pt[0], 1, &neigh_temp, &sqrDistNeigh);
408 neigh = neigh_temp;
409 };

References nsearch::NFlannSearchKd< dim >::d_tree.

◆ radiusSearch() [1/2]

template<int dim = 3>
size_t nsearch::NFlannSearchKd< dim >::radiusSearch ( const util::Point searchPoint,
const double &  search_r,
std::vector< int > &  neighs,
std::vector< float > &  sqr_dist 
)
inlineoverridevirtual

Perform radius search to find points in a point cloud within specified distance from a given point. = 0

Parameters
searchPointPoint near which we want neighbors
search_rSearch radius
neighsIndices of points in neighborhood
sqr_distSquared distance of neighboring points from search point
Returns
number Number of points in neighborhood = 0

Implements nsearch::BaseNSearch.

Definition at line 244 of file nsearch.h.

247 {
248
249 // ugly but quick fix
250 // first, get results using int and float and then convert
251 std::vector<size_t> neighs_temp;
252 std::vector<double> sqr_dist_temp;
253 auto N =
254 this->radiusSearch(searchPoint, search_r, neighs_temp, sqr_dist_temp);
255
256 if (N > 0) {
257 neighs.resize(N);
258 sqr_dist.resize(N);
259 for (size_t i=0; i<N; i++) {
260 neighs.push_back(int(neighs_temp[i]));
261 sqr_dist.push_back(float(sqr_dist_temp[i]));
262 }
263 }
264
265 return N;
266 };
size_t radiusSearch(const util::Point &searchPoint, const double &search_r, std::vector< size_t > &neighs, std::vector< double > &sqr_dist) override
Perform radius search to find points in a point cloud within specified distance from a given point....
Definition nsearch.h:227

References nsearch::NFlannSearchKd< dim >::radiusSearch().

Here is the call graph for this function:

◆ radiusSearch() [2/2]

template<int dim = 3>
size_t nsearch::NFlannSearchKd< dim >::radiusSearch ( const util::Point searchPoint,
const double &  search_r,
std::vector< size_t > &  neighs,
std::vector< double > &  sqr_dist 
)
inlineoverridevirtual

Perform radius search to find points in a point cloud within specified distance from a given point. = 0 = 0 = 0

Parameters
searchPointPoint near which we want neighbors
search_rSearch radius
neighsIndices of points in neighborhood
sqr_distSquared distance of neighboring points from search point
Returns
number Number of points in neighborhood = 0 = 0 = 0

Implements nsearch::BaseNSearch.

Definition at line 227 of file nsearch.h.

230 {
231
232 double query_pt[3] = {searchPoint[0], searchPoint[1], searchPoint[2]};
233
234 TreeSearchRes resultSet(search_r * search_r, neighs, sqr_dist);
235 return d_tree.radiusSearchCustomCallback(&query_pt[0], resultSet, d_params);
236 };
TreeSearchResult< double, size_t > TreeSearchRes
Define result attributes.

References nsearch::NFlannSearchKd< dim >::d_params, and nsearch::NFlannSearchKd< dim >::d_tree.

Referenced by nsearch::NFlannSearchKd< dim >::radiusSearch().

Here is the caller graph for this function:

◆ radiusSearchExcludeTag() [1/2]

template<int dim = 3>
size_t nsearch::NFlannSearchKd< dim >::radiusSearchExcludeTag ( const util::Point searchPoint,
const double &  search_r,
std::vector< int > &  neighs,
std::vector< float > &  sqr_dist,
const size_t &  searchPointTag,
const std::vector< size_t > &  dataTags 
)
inlineoverridevirtual

= 0

= 0

Implements nsearch::BaseNSearch.

Definition at line 303 of file nsearch.h.

309 {
310
311 // first, get results using int and float and then convert
312 std::vector<size_t> neighs_temp;
313 std::vector<double> sqr_dist_temp;
314 auto N =
315 this->radiusSearchExcludeTag(searchPoint, search_r,
316 neighs_temp, sqr_dist_temp,
317 searchPointTag, dataTags);
318
319 if (N > 0) {
320 neighs.resize(N);
321 sqr_dist.resize(N);
322 for (size_t i=0; i<N; i++) {
323 neighs.push_back(int(neighs_temp[i]));
324 sqr_dist.push_back(float(sqr_dist_temp[i]));
325 }
326 }
327
328 return N;
329 };
size_t radiusSearchExcludeTag(const util::Point &searchPoint, const double &search_r, std::vector< size_t > &neighs, std::vector< double > &sqr_dist, const size_t &searchPointTag, const std::vector< size_t > &dataTags) override
= 0
Definition nsearch.h:278

References nsearch::NFlannSearchKd< dim >::radiusSearchExcludeTag().

Here is the call graph for this function:

◆ radiusSearchExcludeTag() [2/2]

template<int dim = 3>
size_t nsearch::NFlannSearchKd< dim >::radiusSearchExcludeTag ( const util::Point searchPoint,
const double &  search_r,
std::vector< size_t > &  neighs,
std::vector< double > &  sqr_dist,
const size_t &  searchPointTag,
const std::vector< size_t > &  dataTags 
)
inlineoverridevirtual

= 0

= 0

Implements nsearch::BaseNSearch.

Definition at line 278 of file nsearch.h.

284 {
285
286 double query_pt[3] = {searchPoint[0], searchPoint[1], searchPoint[2]};
287
288 TreeSearchCheckIDExcludeRes resultSet(search_r * search_r,
289 neighs, sqr_dist, searchPointTag, dataTags);
290
291 return d_tree.radiusSearchCustomCallback(&query_pt[0], resultSet, d_params);
292 };
TreeSearchCheckIDExcludeResult< double, size_t > TreeSearchCheckIDExcludeRes

References nsearch::NFlannSearchKd< dim >::d_params, and nsearch::NFlannSearchKd< dim >::d_tree.

Referenced by nsearch::NFlannSearchKd< dim >::radiusSearchExcludeTag().

Here is the caller graph for this function:

◆ radiusSearchIncludeTag() [1/2]

template<int dim = 3>
size_t nsearch::NFlannSearchKd< dim >::radiusSearchIncludeTag ( const util::Point searchPoint,
const double &  search_r,
std::vector< int > &  neighs,
std::vector< float > &  sqr_dist,
const size_t &  searchPointTag,
const std::vector< size_t > &  dataTags 
)
inlineoverridevirtual

= 0

= 0

Implements nsearch::BaseNSearch.

Definition at line 366 of file nsearch.h.

372 {
373
374 // first, get results using int and float and then convert
375 std::vector<size_t> neighs_temp;
376 std::vector<double> sqr_dist_temp;
377 auto N =
378 this->radiusSearchIncludeTag(searchPoint, search_r,
379 neighs_temp, sqr_dist_temp,
380 searchPointTag, dataTags);
381
382 if (N > 0) {
383 neighs.resize(N);
384 sqr_dist.resize(N);
385 for (size_t i=0; i<N; i++) {
386 neighs.push_back(int(neighs_temp[i]));
387 sqr_dist.push_back(float(sqr_dist_temp[i]));
388 }
389 }
390
391 return N;
392 };
size_t radiusSearchIncludeTag(const util::Point &searchPoint, const double &search_r, std::vector< size_t > &neighs, std::vector< double > &sqr_dist, const size_t &searchPointTag, const std::vector< size_t > &dataTags) override
= 0
Definition nsearch.h:340

References nsearch::NFlannSearchKd< dim >::radiusSearchIncludeTag().

Here is the call graph for this function:

◆ radiusSearchIncludeTag() [2/2]

template<int dim = 3>
size_t nsearch::NFlannSearchKd< dim >::radiusSearchIncludeTag ( const util::Point searchPoint,
const double &  search_r,
std::vector< size_t > &  neighs,
std::vector< double > &  sqr_dist,
const size_t &  searchPointTag,
const std::vector< size_t > &  dataTags 
)
inlineoverridevirtual

= 0

= 0

Implements nsearch::BaseNSearch.

Definition at line 340 of file nsearch.h.

346 {
347
348 double query_pt[3] = {searchPoint[0], searchPoint[1], searchPoint[2]};
349
350 TreeSearchCheckIDIncludeRes resultSet(search_r * search_r,
351 neighs, sqr_dist,
352 searchPointTag, dataTags);
353
354 return d_tree.radiusSearchCustomCallback(&query_pt[0], resultSet, d_params);
355 };
TreeSearchCheckIDIncludeResult< double, size_t > TreeSearchCheckIDIncludeRes

References nsearch::NFlannSearchKd< dim >::d_params, and nsearch::NFlannSearchKd< dim >::d_tree.

Referenced by nsearch::NFlannSearchKd< dim >::radiusSearchIncludeTag().

Here is the caller graph for this function:

◆ setInputCloud()

template<int dim = 3>
double nsearch::NFlannSearchKd< dim >::setInputCloud ( )
inlineoverridevirtual

Set input cloud.

Returns
double Time taken to update the point cloud

Implements nsearch::BaseNSearch.

Definition at line 200 of file nsearch.h.

200 {
201 auto t1 = steady_clock::now();
202 d_tree.buildIndex();
203 auto t2 = steady_clock::now();
204 return util::methods::timeDiff(t1, t2);
205 };
float timeDiff(std::chrono::steady_clock::time_point begin, std::chrono::steady_clock::time_point end, std::string unit="microseconds")
Returns difference between two times.
Definition methods.h:304

References nsearch::NFlannSearchKd< dim >::d_tree, and util::methods::timeDiff().

Here is the call graph for this function:

◆ updatePointCloud()

template<int dim = 3>
double nsearch::NFlannSearchKd< dim >::updatePointCloud ( const std::vector< util::Point > &  x,
bool  parallel = true 
)
inlineoverridevirtual

Function to implement point cloud update.

TODO Implement this function

Parameters
xVector of positions of points
parallelSpecify if this is done in parallel
Returns
double Time taken to update the point cloud

Implements nsearch::BaseNSearch.

Definition at line 216 of file nsearch.h.

217 {
218 return 0;
219 };

Field Documentation

◆ d_cloud

template<int dim = 3>
PointCloudAdaptor nsearch::NFlannSearchKd< dim >::d_cloud

coordinates of the points

Definition at line 413 of file nsearch.h.

◆ d_params

◆ d_tree


The documentation for this class was generated from the following file: