21#ifndef GF_SPATIAL_R_STAR_TREE_H
22#define GF_SPATIAL_R_STAR_TREE_H
27#include <boost/container/static_vector.hpp>
29#include "BlockAllocator.h"
33#include "SpatialTypes.h"
36#ifndef DOXYGEN_SHOULD_SKIP_THIS
51 static constexpr std::size_t MaxSize = 16;
52 static constexpr std::size_t MinSize = 4;
106 std::size_t allocateEntry();
107 void disposeEntry(std::size_t index);
109 std::size_t allocateNode();
110 void disposeNode(std::size_t index);
112 RectF computeBounds(std::size_t nodeIndex);
113 void updateBoundsForChild(std::size_t parentIndex,
const RectF& bounds, std::size_t childIndex);
115 void doInsert(std::size_t entryIndex,
const RectF& bounds);
117 std::size_t chooseSubtree(std::size_t nodeIndex,
const RectF& bounds);
118 std::size_t chooseNode(std::size_t nodeIndex,
const RectF& bounds);
119 std::size_t searchForCoveringNode(std::size_t nodeIndex,
const RectF& bounds);
120 bool existsEmptyVolumeExtension(std::size_t nodeIndex,
const RectF& bounds);
128 template<
typename OverlapEnlargement>
129 std::size_t findCandidates(std::size_t nodeIndex, std::size_t t, std::size_t p,
const RectF& bounds, std::vector<Candidate>& candidates);
131 std::size_t doInsertInLeaf(std::size_t nodeIndex, std::size_t entryIndex,
const RectF& entryBounds);
132 std::size_t doInsertInBranch(std::size_t nodeIndex, std::size_t childIndex,
const RectF& childBounds);
136 void getEntriesAndDispose(std::size_t nodeIndex, std::vector<std::size_t>& eliminated);
137 void doRemove(std::size_t entryIndex);
139 void validate()
const;
140 std::size_t validateNode(std::size_t nodeIndex)
const;
143 static constexpr std::size_t Size = MaxSize + 1;
151 BlockAllocator<Entry> m_entries;
167 boost::container::static_vector<Member, Size> members;
170 BlockAllocator<Node> m_nodes;
174#ifndef DOXYGEN_SHOULD_SKIP_THIS
A handle to an object or an id.
Definition: Handle.h:40
An implemntation of a R* tree.
Definition: Spatial_RStarTree.h:49
SpatialId insert(Handle handle, const RectF &bounds)
Insert an object in the tree.
void remove(SpatialId id)
Remove an object from the tree.
Handle operator[](SpatialId id)
Get the handle associated to a spatial id.
std::size_t query(const RectF &bounds, SpatialQueryCallback callback, SpatialQuery kind=SpatialQuery::Intersect)
Query objects in the tree.
void clear()
Remove all the objects from the tree.
void modify(SpatialId id, RectF bounds)
Modify the bounds of an object.
Rect< float > RectF
A float rectangle.
Definition: Rect.h:493
SpatialQuery
A kind of spatial query.
Definition: SpatialTypes.h:73
std::function< void(Handle)> SpatialQueryCallback
A callback for spatial query.
Definition: SpatialTypes.h:82
SpatialId
A spatial id.
Definition: SpatialTypes.h:42
@ Node
The structure represents an internal node.
@ Intersect
Search for all objects that intersect the given bounds.
The namespace for gf classes.