Class NearestNeighborsCapable

Inheritance Relationships

Derived Types

Class Documentation

class NearestNeighborsCapable

Virtual interface for maps having the capability of searching the closest neighbor(s) of a given query 2D or 3D point.

Note this is more generic than mrpt::math::KDTreeCapable since it does not assume the use of KD-trees, and it is also non templatized, so users can use dynamic casting to interact with maps in a generic way.

Note

New in MRPT 2.11.3

Subclassed by mrpt::maps::CVoxelMapOccupancyBase< VoxelNodeOccupancy >, mrpt::maps::CVoxelMapOccupancyBase< VoxelNodeOccRGB >, mrpt::maps::COccupancyGridMap2D, mrpt::maps::COccupancyGridMap3D, mrpt::maps::CPointsMap, mrpt::maps::CVoxelMapOccupancyBase< voxel_node_t, occupancy_t >

API of the NearestNeighborsCapable virtual interface

virtual bool nn_has_indices_or_ids() const = 0

Returns true if the rest of nn_* methods will populate the output indices values with 0-based contiguous indices. Returns false if indices are actually sparse ID numbers without any expectation of they be contiguous or start near zero.

inline virtual void nn_prepare_for_2d_queries() const

Must be called before calls to nn_*_search() to ensure the required data structures are ready for queries (e.g. KD-trees). Useful in multithreading applications.

inline virtual void nn_prepare_for_3d_queries() const

Must be called before calls to nn_*_search() to ensure the required data structures are ready for queries (e.g. KD-trees). Useful in multithreading applications.

virtual size_t nn_index_count() const = 0

If nn_has_indices_or_ids() returns true, this must return the number of “points” (or whatever entity) the indices correspond to. Otherwise, the return value should be ignored.

virtual bool nn_single_search(const mrpt::math::TPoint3Df &query, mrpt::math::TPoint3Df &result, float &out_dist_sqr, uint64_t &resultIndexOrIDOrID) const = 0

Search for the closest 3D point to a given one.

Parameters:
  • query[in] The query input point.

  • result[out] The found closest point.

  • out_dist_sqr[out] The square Euclidean distance between the query and the returned point.

  • resultIndexOrID[out] The index or ID of the result point in the map.

Returns:

True if successful, false if no point was found.

virtual bool nn_single_search(const mrpt::math::TPoint2Df &query, mrpt::math::TPoint2Df &result, float &out_dist_sqr, uint64_t &resultIndexOrIDOrID) const = 0
virtual void nn_multiple_search(const mrpt::math::TPoint3Df &query, size_t N, std::vector<mrpt::math::TPoint3Df> &results, std::vector<float> &out_dists_sqr, std::vector<uint64_t> &resultIndicesOrIDs) const = 0

Search for the N closest 3D points to a given one.

Parameters:
  • query[in] The query input point.

  • results[out] The found closest points.

  • out_dists_sqr[out] The square Euclidean distances between the query and the returned point.

  • resultIndicesOrIDs[out] The indices or IDs of the result points.

virtual void nn_multiple_search(const mrpt::math::TPoint2Df &query, size_t N, std::vector<mrpt::math::TPoint2Df> &results, std::vector<float> &out_dists_sqr, std::vector<uint64_t> &resultIndicesOrIDs) const = 0
virtual void nn_radius_search(const mrpt::math::TPoint3Df &query, float search_radius_sqr, std::vector<mrpt::math::TPoint3Df> &results, std::vector<float> &out_dists_sqr, std::vector<uint64_t> &resultIndicesOrIDs, size_t maxPoints = 0) const = 0

Radius search for closest 3D points to a given one.

Parameters:
  • query[in] The query input point.

  • search_radius_sqr[in] The search radius, squared.

  • results[out] The found closest points.

  • out_dists_sqr[out] The square Euclidean distances between the query and the returned point.

  • resultIndicesOrIDs[out] The indices or IDs of the result points.

  • maxPoints[in] If !=0, the maximum number of neigbors to return.

virtual void nn_radius_search(const mrpt::math::TPoint2Df &query, float search_radius_sqr, std::vector<mrpt::math::TPoint2Df> &results, std::vector<float> &out_dists_sqr, std::vector<uint64_t> &resultIndicesOrIDs, size_t maxPoints = 0) const = 0

Public Functions

NearestNeighborsCapable() = default
virtual ~NearestNeighborsCapable() = default
NearestNeighborsCapable(const NearestNeighborsCapable&) = default
NearestNeighborsCapable(NearestNeighborsCapable&&) = default
NearestNeighborsCapable &operator=(const NearestNeighborsCapable&) = default
NearestNeighborsCapable &operator=(NearestNeighborsCapable&&) = default