PeriDEM 0.2.0
PeriDEM -- Peridynamics-based high-fidelity model for granular media
Loading...
Searching...
No Matches
nflannSetup.h
Go to the documentation of this file.
1/*
2 * -------------------------------------------
3 * Copyright (c) 2021 - 2024 Prashant K. Jha
4 * -------------------------------------------
5 * PeriDEM https://github.com/prashjha/PeriDEM
6 *
7 * Distributed under the Boost Software License, Version 1.0. (See accompanying
8 * file LICENSE)
9 */
10
11#ifndef NSEARCH_NFLANNSETUP_H
12#define NSEARCH_NFLANNSETUP_H
13
14#include "util/point.h" // definition of Point
15#include "nanoflann/include/nanoflann.hpp"
16
17namespace nsearch {
18
20typedef std::vector<util::Point> PointCloud;
21
28 typedef double coord_t;
29
32
38 PointCloudAdaptor(const PointCloud &obj) : d_obj(obj) {}
39
45 inline const PointCloud &pointCloud() const { return d_obj; }
46
52 inline size_t kdtree_get_point_count() const { return pointCloud().size(); }
53
54
62 inline coord_t kdtree_get_pt(const size_t idx, const size_t dim) const {
63 return pointCloud()[idx][dim];
64 }
65
75 template <class BBOX> bool kdtree_get_bbox(BBOX & /*bb*/) const {
76 return false;
77 }
78};
79
85template <typename _DistanceType, typename _IndexType = size_t>
87public:
89 typedef _DistanceType DistanceType;
90
92 typedef _IndexType IndexType;
93
94public:
98
100 std::vector<IndexType> &d_indices;
101
103 std::vector<DistanceType> &d_dists;
104
113 std::vector<IndexType> &indices,
114 std::vector<DistanceType> &dists)
115 : d_r(radius_), d_indices(indices), d_dists(dists) {
116 init();
117 }
118
122 inline void init() { clear(); }
123
127 inline void clear() {
128 d_indices.clear();
129 d_dists.clear();
130 }
131
137 inline size_t size() const { return d_indices.size(); }
138
143 inline bool full() const { return true; }
144
152 inline bool addPoint(DistanceType dist, IndexType index) {
153 if (dist < d_r) {
154 d_indices.push_back(index);
155 d_dists.push_back(dist);
156 }
157 return true;
158 }
159
164 inline DistanceType worstDist() const { return d_r; }
165
174 std::pair<IndexType, DistanceType> worst_item() const {
175 if (d_indices.empty())
176 throw std::runtime_error("Cannot invoke RadiusResultSet::worst_item() on "
177 "an empty list of results.");
178 return std::make_pair(0, 0.);
179 }
180};
181
191template <typename _DistanceType, typename _IndexType = size_t>
193public:
195 typedef _DistanceType DistanceType;
196
198 typedef _IndexType IndexType;
199
200public:
204
207
209 std::vector<IndexType> &d_indices;
210
212 std::vector<DistanceType> &d_dists;
213
215 const std::vector<IndexType> &d_dataTags;
216
227 std::vector<IndexType> &indices,
228 std::vector<DistanceType> &dists,
229 const IndexType &searchPointTag,
230 const std::vector<IndexType> &dataTags)
231 : d_r(radius_),
232 d_tag(searchPointTag),
233 d_indices(indices),
234 d_dists(dists),
235 d_dataTags(dataTags) {
236 init();
237 }
238
242 inline void init() { clear(); }
243
247 inline void clear() {
248 d_indices.clear();
249 d_dists.clear();
250 }
251
257 inline size_t size() const { return d_indices.size(); }
258
263 inline bool full() const { return true; }
264
272 inline bool addPoint(DistanceType dist, IndexType index) {
273 if (dist < d_r) {
274 if (d_dataTags[index] != d_tag) {
275 d_indices.push_back(index);
276 d_dists.push_back(dist);
277 }
278 }
279 return true;
280 }
281
286 inline DistanceType worstDist() const { return d_r; }
287
296 std::pair<IndexType, DistanceType> worst_item() const {
297 if (d_indices.empty())
298 throw std::runtime_error("Cannot invoke RadiusResultSet::worst_item() on "
299 "an empty list of results.");
300 return std::make_pair(0, 0.);
301 }
302};
303
313template <typename _DistanceType, typename _IndexType = size_t>
315public:
317 typedef _DistanceType DistanceType;
318
320 typedef _IndexType IndexType;
321
322public:
326
329
331 std::vector<IndexType> &d_indices;
332
334 std::vector<DistanceType> &d_dists;
335
337 const std::vector<IndexType> &d_dataTags;
338
349 std::vector<IndexType> &indices,
350 std::vector<DistanceType> &dists,
351 const IndexType &searchPointTag,
352 const std::vector<IndexType> &dataTags)
353 : d_r(radius_),
354 d_tag(searchPointTag),
355 d_indices(indices),
356 d_dists(dists),
357 d_dataTags(dataTags) {
358 init();
359 }
360
364 inline void init() { clear(); }
365
369 inline void clear() {
370 d_indices.clear();
371 d_dists.clear();
372 }
373
379 inline size_t size() const { return d_indices.size(); }
380
385 inline bool full() const { return true; }
386
394 inline bool addPoint(DistanceType dist, IndexType index) {
395 if (dist < d_r) {
396 if (d_dataTags[index] == d_tag) {
397 d_indices.push_back(index);
398 d_dists.push_back(dist);
399 }
400 }
401 return true;
402 }
403
408 inline DistanceType worstDist() const { return d_r; }
409
418 std::pair<IndexType, DistanceType> worst_item() const {
419 if (d_indices.empty())
420 throw std::runtime_error("Cannot invoke RadiusResultSet::worst_item() on "
421 "an empty list of results.");
422 return std::make_pair(0, 0.);
423 }
424};
425
426
431
432
434typedef nanoflann::KDTreeSingleIndexAdaptor<
435 nanoflann::L2_Simple_Adaptor<double, PointCloudAdaptor>, PointCloudAdaptor,
436 3 /* dim */
437>
439
441typedef nanoflann::KDTreeSingleIndexAdaptor<
442 nanoflann::L2_Simple_Adaptor<double, PointCloudAdaptor>, PointCloudAdaptor,
443 3 /* dim */
444>
446
448typedef nanoflann::KDTreeSingleIndexAdaptor<
449 nanoflann::L2_Simple_Adaptor<double, PointCloudAdaptor>, PointCloudAdaptor,
450 2 /* dim */
451>
453
454} // namespace nsearch
455
456#endif // NSEARCH_NFLANNSETUP_H
To collect results of nanoflann tree search. In this class, we check the tag of a potential point and...
_IndexType IndexType
Index type (int, size_t, etc)
void init()
Initialize the data (clear)
const std::vector< IndexType > & d_dataTags
Tag of point data that we want to check with given point to be added to the search result.
_DistanceType DistanceType
Distance type (double, float, etc)
bool full() const
Check (not implemented)
std::vector< DistanceType > & d_dists
Distance of points found within the search radius.
TreeSearchCheckIDExcludeResult(DistanceType radius_, std::vector< IndexType > &indices, std::vector< DistanceType > &dists, const IndexType &searchPointTag, const std::vector< IndexType > &dataTags)
Constructor.
const DistanceType d_r
Define search radius. Note this should be square of radius, where radius is a distance within which w...
bool addPoint(DistanceType dist, IndexType index)
Called during search to add an element matching the criteria.
std::vector< IndexType > & d_indices
Indices within the search radius.
std::pair< IndexType, DistanceType > worst_item() const
Find the worst result (furtherest neighbor) without copying or sorting Pre-conditions: size() > 0.
DistanceType worstDist() const
Return maximum distance for search.
const IndexType & d_tag
Tag of the point we are searching for neighboring points.
size_t size() const
Get the size of currently stored (found so far) indices.
To collect results of nanoflann tree search. In this class, we check the tag of a potential point and...
const IndexType & d_tag
Tag of the point we are searching for neighboring points.
const DistanceType d_r
Define search radius. Note this should be square of radius, where radius is a distance within which w...
_IndexType IndexType
Index type (int, size_t, etc)
std::pair< IndexType, DistanceType > worst_item() const
Find the worst result (furtherest neighbor) without copying or sorting Pre-conditions: size() > 0.
size_t size() const
Get the size of currently stored (found so far) indices.
bool full() const
Check (not implemented)
const std::vector< IndexType > & d_dataTags
Tag of point data that we want to check with given point to be added to the search result.
bool addPoint(DistanceType dist, IndexType index)
Called during search to add an element matching the criteria.
std::vector< IndexType > & d_indices
Indices within the search radius.
std::vector< DistanceType > & d_dists
Distance of points found within the search radius.
_DistanceType DistanceType
Distance type (double, float, etc)
DistanceType worstDist() const
Return maximum distance for search.
void init()
Initialize the data (clear)
TreeSearchCheckIDIncludeResult(DistanceType radius_, std::vector< IndexType > &indices, std::vector< DistanceType > &dists, const IndexType &searchPointTag, const std::vector< IndexType > &dataTags)
Constructor.
To collect results of nanoflann tree search. Default result output of nanoflann search uses std::vect...
Definition nflannSetup.h:86
_DistanceType DistanceType
Distance type (double, float, etc)
Definition nflannSetup.h:89
void clear()
Clear the data.
const DistanceType d_r
Define search radius. Note this should be square of radius, where radius is a distance within which w...
Definition nflannSetup.h:97
DistanceType worstDist() const
Return maximum distance for search.
TreeSearchResult(DistanceType radius_, std::vector< IndexType > &indices, std::vector< DistanceType > &dists)
Constructor.
std::vector< IndexType > & d_indices
Indices within the search radius.
size_t size() const
Get the size of currently stored (found so far) indices.
_IndexType IndexType
Index type (int, size_t, etc)
Definition nflannSetup.h:92
void init()
Initialize the data (clear)
std::pair< IndexType, DistanceType > worst_item() const
Find the worst result (furtherest neighbor) without copying or sorting Pre-conditions: size() > 0.
bool full() const
Check (not implemented)
bool addPoint(DistanceType dist, IndexType index)
Called during search to add an element matching the criteria.
std::vector< DistanceType > & d_dists
Distance of points found within the search radius.
Methods for performing efficient search of neighboring points.
Definition nflannSetup.h:17
TreeSearchResult< double, size_t > TreeSearchRes
Define result attributes.
TreeSearchCheckIDIncludeResult< double, size_t > TreeSearchCheckIDIncludeRes
std::vector< util::Point > PointCloud
Define list of points for tree search using nanoflann lib.
Definition nflannSetup.h:20
nanoflann::KDTreeSingleIndexAdaptor< nanoflann::L2_Simple_Adaptor< double, PointCloudAdaptor >, PointCloudAdaptor, 3 > NFlannKdTree
Define tree data type for nanoflann.
nanoflann::KDTreeSingleIndexAdaptor< nanoflann::L2_Simple_Adaptor< double, PointCloudAdaptor >, PointCloudAdaptor, 3 > NFlannKdTree3D
Define tree data type for nanoflann (3D)
nanoflann::KDTreeSingleIndexAdaptor< nanoflann::L2_Simple_Adaptor< double, PointCloudAdaptor >, PointCloudAdaptor, 2 > NFlannKdTree2D
Define tree data type for nanoflann (2D)
TreeSearchCheckIDExcludeResult< double, size_t > TreeSearchCheckIDExcludeRes
Allows custom point cloud data structure to interface with nanoflann. See https://github....
Definition nflannSetup.h:26
bool kdtree_get_bbox(BBOX &) const
Optional bounding-box computation: return false to default to a standard bbox computation loop....
Definition nflannSetup.h:75
coord_t kdtree_get_pt(const size_t idx, const size_t dim) const
Get specific coordinate of a point.
Definition nflannSetup.h:62
const PointCloud & d_obj
Const reference to list of points.
Definition nflannSetup.h:31
const PointCloud & pointCloud() const
Get vector of points.
Definition nflannSetup.h:45
double coord_t
Define coordinate type.
Definition nflannSetup.h:28
size_t kdtree_get_point_count() const
Get number of points in point cloud.
Definition nflannSetup.h:52
PointCloudAdaptor(const PointCloud &obj)
Constructor.
Definition nflannSetup.h:38