k-dimensional tree constructable both with 2D (lon,lat) points as with 3D (x,y,z) points
More...
|
| KDTree (const KDTree &handle) |
|
| KDTree () |
| Construct an empty kd-tree with default geometry (Earth)
|
|
| KDTree (const Geometry &geometry) |
| Construct an empty kd-tree with custom geometry.
|
|
template<typename Tree > |
| KDTree (const std::shared_ptr< Tree > &kdtree) |
| Construct a shared kd-tree with default geometry (Earth)
|
|
template<typename Tree > |
| KDTree (const std::shared_ptr< Tree > &kdtree, const Geometry &geometry) |
| Construct a shared kd-tree with custom geometry.
|
|
void | reserve (idx_t size) |
| Reserve memory for building the kd-tree in one shot (optional, at cost of extra memory)
|
|
template<typename Point > |
void | insert (const Point &p, const Payload &payload) |
| Insert spherical point (lon,lat) or 3D cartesian point (x,y,z) More...
|
|
void | insert (const Value &value) |
| Insert kd-tree value in tree. More...
|
|
void | build () |
| Build the kd-tree in one shot, if memory has been reserved. More...
|
|
template<typename Longitudes , typename Latitudes , typename Payloads > |
void | build (const Longitudes &longitudes, const Latitudes &latitudes, const Payloads &payloads) |
| Build with spherical points (lon,lat) where longitudes, latitudes, and payloads are separate containers. More...
|
|
template<typename LongitudesIterator , typename LatitudesIterator , typename PayloadsIterator > |
void | build (const LongitudesIterator &longitudes_begin, const LongitudesIterator &longitudes_end, const LatitudesIterator &latitudes_begin, const LatitudesIterator &latitudes_end, const PayloadsIterator &payloads_begin, const PayloadsIterator &payloads_end) |
| Build with spherical points (lon,lat) given separate iterator ranges for longitudes, latitudes, and payloads. More...
|
|
template<typename Points , typename Payloads > |
void | build (const Points &points, const Payloads &payloads) |
| Build with templated points. More...
|
|
template<typename PointIterator , typename PayloadsIterator > |
void | build (const PointIterator &points_begin, const PointIterator &points_end, const PayloadsIterator &payloads_begin, const PayloadsIterator &payloads_end) |
| Build with spherical points (lon,lat) given separate iterator ranges for longitudes, latitudes, and payloads. More...
|
|
void | build (const std::vector< Value > &values) |
| Build with vector of Value. More...
|
|
bool | empty () const |
|
size_t | size () const |
|
size_t | footprint () const |
|
template<typename Point > |
ValueList | closestPoints (const Point &p, size_t k) const |
| Find k closest points given a 3D cartesian point (x,y,z) or 2D lonlat point(lon,lat)
|
|
template<typename Point > |
Value | closestPoint (const Point &p) const |
| Find closest point given a 3D cartesian point (x,y,z) or 2D lonlat point(lon,lat)
|
|
template<typename Point > |
ValueList | closestPointsWithinRadius (const Point &p, double radius) const |
| Find all points within a distance of given radius from a given point 3D cartesian point (x,y,z) or a 2D (lon,lat) point.
|
|
const Geometry & | geometry () const |
| Return geometry used to convert (lon,lat) to (x,y,z) coordinates.
|
|
Public Member Functions inherited from atlas::util::ObjectHandle< detail::KDTreeBase< PayloadT, PointT > > |
| ObjectHandle (const detail::KDTreeBase< PayloadT, PointT > *object) |
|
| ObjectHandle (const ObjectHandle &handle) |
|
ObjectHandle & | operator= (const ObjectHandle &handle) |
|
ATLAS_ALWAYS_INLINE detail::KDTreeBase< PayloadT, PointT > * | get () |
|
ATLAS_ALWAYS_INLINE const detail::KDTreeBase< PayloadT, PointT > * | get () const |
|
ATLAS_ALWAYS_INLINE const detail::KDTreeBase< PayloadT, PointT > * | operator-> () const |
|
ATLAS_ALWAYS_INLINE detail::KDTreeBase< PayloadT, PointT > * | operator-> () |
|
ATLAS_ALWAYS_INLINE const detail::KDTreeBase< PayloadT, PointT > & | operator* () const |
|
ATLAS_ALWAYS_INLINE detail::KDTreeBase< PayloadT, PointT > & | operator* () |
|
ATLAS_ALWAYS_INLINE void | reset (const detail::KDTreeBase< PayloadT, PointT > *object) |
|
Public Member Functions inherited from atlas::util::ObjectHandleBase |
| ObjectHandleBase (const Object *object) |
|
const ObjectHandleBase & | operator= (const ObjectHandleBase &other) |
|
| operator bool () const |
|
void | reset (const Object *other) |
|
int | owners () const |
|
template<typename PayloadT, typename PointT = Point3>
class atlas::util::KDTree< PayloadT, PointT >
k-dimensional tree constructable both with 2D (lon,lat) points as with 3D (x,y,z) points
The implementation is based on eckit::KDTreeMemory with 3D (x,y,z) points. 2D points (lon,lat) are converted when needed to 3D during insertion, and during search, so that a search always happens with 3D cartesian points.
Example:
Construct a KDTree, given a list_of_lonlat_points
(e.g. std::vector<PointLonLat>
or other container) A payload given is the index in this list.
KDTree<idx_t> search;
search.reserve( list_of_lonlat_points.size() );
for ( auto& point : list_of_lonlat_points ) {
search.insert( point, n++ );
}
search.build();
We can now do e.g. a search for the nearest 4 neighbours (k=4) sorted by shortest distance
auto neighbours = search.closestPoints( PointLonLat{180., 45.}, k ).payloads();
The variable neighbours
is now a container of indices (the payloads) of the 4 nearest points