#include <dl_rtree.h>
Public Member Functions | |
| DlRTree (const DlRect rects[], int N, const int ids[]=nullptr, bool predicate(int id)=[](int) { return true;}, int invalid_id=-1) | |
| void | search (const DlRect &query, std::vector< int > *results) const |
| int | id (int result_index) const |
| const DlRect & | bounds () const |
| const DlRect & | bounds (int result_index) const |
| size_t | bytes_used () const |
| Returns the bytes used by the object and all of its node data. | |
| int | leaf_count () const |
| int | node_count () const |
| std::list< DlRect > | searchAndConsolidateRects (const DlRect &query, bool deband=true) const |
| const DlRegion & | region () const |
| DlRegion | region (const DlRect &query) const |
An R-Tree that stores a list of bounding rectangles with optional associated IDs.
The R-Tree can be searched in one of two ways:
Definition at line 27 of file dl_rtree.h.
| flutter::DlRTree::DlRTree | ( | const DlRect | rects[], |
| int | N, | ||
| const int | ids[] = nullptr, |
||
| bool | predicateint id = [](int) { return true; }, |
||
| int | invalid_id = -1 |
||
| ) |
Construct an R-Tree from the list of rectangles respecting the order in which they appear in the list. An optional array of IDs can be provided to tag each rectangle with information needed by the caller as well as an optional predicate that can filter out rectangles with IDs that should not be stored in the R-Tree.
If an array of IDs is not specified then all leaf nodes will be represented by the |invalid_id| (which defaults to -1).
Invalid rects that are empty or contain a NaN value will not be stored in the R-Tree. And, if a |predicate| function is provided, that function will be called to query if the rectangle associated with the ID should be included.
Duplicate rectangles and IDs are allowed and not processed in any way except to eliminate invalid rectangles and IDs that are rejected by the optional predicate function.
Definition at line 12 of file dl_rtree.cc.
References bounds(), FML_DCHECK, i, id, and leaf_count().
| const DlRect & flutter::DlRTree::bounds | ( | ) | const |
Returns maximum and minimum axis values of rectangles in this R-Tree. If R-Tree is empty returns an empty DlRect.
Definition at line 215 of file dl_rtree.cc.
Referenced by DlRTree(), region(), searchAndConsolidateRects(), flutter::testing::TEST(), flutter::testing::TEST(), and flutter::testing::TEST().
|
inline |
Return the rectangle bounds for the indicated result of a query or an empty rect if the index is not a valid leaf node index.
Definition at line 95 of file dl_rtree.h.
|
inline |
Returns the bytes used by the object and all of its node data.
Definition at line 102 of file dl_rtree.h.
|
inline |
Return the ID for the indicated result of a query or invalid_id if the index is not a valid leaf node index.
Definition at line 83 of file dl_rtree.h.
Referenced by flutter::testing::TEST(), flutter::testing::TEST(), and flutter::testing::TEST().
|
inline |
Returns the number of leaf nodes corresponding to non-empty rectangles that were passed in the constructor and not filtered out by the predicate.
Definition at line 109 of file dl_rtree.h.
Referenced by DlRTree(), flutter::testing::TEST(), flutter::testing::TEST(), flutter::testing::TEST(), and flutter::testing::TEST().
|
inline |
Return the total number of nodes used in the R-Tree, both leaf and internal consolidation nodes.
Definition at line 113 of file dl_rtree.h.
Referenced by flutter::testing::TEST(), flutter::testing::TEST(), flutter::testing::TEST(), and flutter::testing::TEST().
| const DlRegion & flutter::DlRTree::region | ( | ) | const |
Returns DlRegion that represents the union of all rectangles in the R-Tree.
Definition at line 203 of file dl_rtree.cc.
References bounds(), i, and impeller::TRect< T >::RoundOut().
Referenced by region(), searchAndConsolidateRects(), and flutter::testing::TEST().
Returns DlRegion that represents the union of all rectangles in the R-Tree intersected with the query rect.
Definition at line 133 of file dl_rtree.h.
References flutter::DlRegion::MakeIntersection(), region(), and impeller::TRect< T >::RoundOut().
| void flutter::DlRTree::search | ( | const DlRect & | query, |
| std::vector< int > * | results | ||
| ) | const |
Search the rectangles and return a vector of leaf node indices for rectangles that intersect the query.
Note that the indices are internal indices of the stored data and not the index of the rectangles or ids in the constructor. The returned indices may not themselves be in numerical order, but they will represent the rectangles and IDs in the order in which they were passed into the constructor. The actual rectangle and ID associated with each index can be retrieved using the |DlRTreeid| and |DlRTreebounds| methods.
Definition at line 142 of file dl_rtree.cc.
References FML_DCHECK, impeller::TRect< T >::IsEmpty(), and search().
Referenced by search(), searchAndConsolidateRects(), flutter::testing::TEST(), flutter::testing::TEST(), flutter::testing::TEST(), flutter::testing::TEST(), and flutter::testing::TEST().
| std::list< DlRect > flutter::DlRTree::searchAndConsolidateRects | ( | const DlRect & | query, |
| bool | deband = true |
||
| ) | const |
Finds the rects in the tree that intersect with the query rect.
The returned list of rectangles will be non-overlapping. In other words, the bounds of each rect in the result list are mutually exclusive.
If |deband| is true, then matching rectangles from adjacent DlRegion spanlines will be joined together. This reduces the number of rectangles returned, but requires some extra computation.
Definition at line 163 of file dl_rtree.cc.
References bounds(), flutter::DlRegion::getRects(), impeller::TRect< Scalar >::Make(), region(), impeller::TRect< T >::RoundOut(), and search().
Referenced by flutter::testing::TEST(), flutter::testing::TEST(), flutter::testing::TEST(), and flutter::testing::TEST().