Flutter Engine
The Flutter Engine
Classes | Public Member Functions | Static Public Attributes | List of all members
SkRTree Class Reference

#include <SkRTree.h>

Inheritance diagram for SkRTree:
SkBBoxHierarchy SkRefCnt SkRefCntBase

Public Member Functions

 SkRTree ()
 
void insert (const SkRect[], int N) override
 
void search (const SkRect &query, std::vector< int > *results) const override
 
size_t bytesUsed () const override
 
int getDepth () const
 
int getCount () const
 
- Public Member Functions inherited from SkBBoxHierarchy
virtual void insert (const SkRect[], int N)=0
 
virtual void insert (const SkRect[], const Metadata[], int N)
 
virtual void search (const SkRect &query, std::vector< int > *results) const =0
 
virtual size_t bytesUsed () const =0
 
- Public Member Functions inherited from SkRefCntBase
 SkRefCntBase ()
 
virtual ~SkRefCntBase ()
 
bool unique () const
 
void ref () const
 
void unref () const
 

Static Public Attributes

static const int kMinChildren = 6
 
static const int kMaxChildren = 11
 

Additional Inherited Members

- Protected Member Functions inherited from SkBBoxHierarchy
 SkBBoxHierarchy ()=default
 
 SkBBoxHierarchy (const SkBBoxHierarchy &)=delete
 
SkBBoxHierarchyoperator= (const SkBBoxHierarchy &)=delete
 

Detailed Description

An R-Tree implementation. In short, it is a balanced n-ary tree containing a hierarchy of bounding rectangles.

It only supports bulk-loading, i.e. creation from a batch of bounding rectangles. This performs a bottom-up bulk load using the STR (sort-tile-recursive) algorithm.

TODO: Experiment with other bulk-load algorithms (in particular the Hilbert pack variant, which groups rects by position on the Hilbert curve, is probably worth a look). There also exist top-down bulk load variants (VAMSplit, TopDownGreedy, etc).

For more details see:

Beckmann, N.; Kriegel, H. P.; Schneider, R.; Seeger, B. (1990). "The R*-tree: an efficient and robust access method for points and rectangles"

Definition at line 34 of file SkRTree.h.

Constructor & Destructor Documentation

◆ SkRTree()

SkRTree::SkRTree ( )

Definition at line 13 of file SkRTree.cpp.

13: fCount(0) {}

Member Function Documentation

◆ bytesUsed()

size_t SkRTree::bytesUsed ( ) const
overridevirtual

Return approximate size in memory of *this.

Implements SkBBoxHierarchy.

Definition at line 165 of file SkRTree.cpp.

165 {
166 size_t byteCount = sizeof(SkRTree);
167
168 byteCount += fNodes.capacity() * sizeof(Node);
169
170 return byteCount;
171}
SkRTree()
Definition: SkRTree.cpp:13
Definition: dart.idl:29

◆ getCount()

int SkRTree::getCount ( ) const
inline

Definition at line 47 of file SkRTree.h.

47{ return fCount; }

◆ getDepth()

int SkRTree::getDepth ( ) const
inline

Definition at line 45 of file SkRTree.h.

45{ return fCount ? fRoot.fSubtree->fLevel + 1 : 0; }

◆ insert()

void SkRTree::insert ( const  SkRect[],
int  N 
)
overridevirtual

Insert N bounding boxes into the hierarchy.

Implements SkBBoxHierarchy.

Definition at line 15 of file SkRTree.cpp.

15 {
16 SkASSERT(0 == fCount);
17
18 std::vector<Branch> branches;
19 branches.reserve(N);
20
21 for (int i = 0; i < N; i++) {
22 const SkRect& bounds = boundsArray[i];
23 if (bounds.isEmpty()) {
24 continue;
25 }
26
27 Branch b;
28 b.fBounds = bounds;
29 b.fOpIndex = i;
30 branches.push_back(b);
31 }
32
33 fCount = (int)branches.size();
34 if (fCount) {
35 if (1 == fCount) {
36 fNodes.reserve(1);
37 Node* n = this->allocateNodeAtLevel(0);
38 n->fNumChildren = 1;
39 n->fChildren[0] = branches[0];
40 fRoot.fSubtree = n;
41 fRoot.fBounds = branches[0].fBounds;
42 } else {
43 fNodes.reserve(CountNodes(fCount));
44 fRoot = this->bulkLoad(&branches);
45 }
46 }
47}
#define SkASSERT(cond)
Definition: SkAssert.h:116
#define N
Definition: beziers.cpp:19
static bool b
Optional< SkRect > bounds
Definition: SkRecords.h:189

◆ search()

void SkRTree::search ( const SkRect query,
std::vector< int > *  results 
) const
overridevirtual

Populate results with the indices of bounding boxes intersecting that query.

Implements SkBBoxHierarchy.

Definition at line 147 of file SkRTree.cpp.

147 {
148 if (fCount > 0 && SkRect::Intersects(fRoot.fBounds, query)) {
149 this->search(fRoot.fSubtree, query, results);
150 }
151}
void search(const SkRect &query, std::vector< int > *results) const override
Definition: SkRTree.cpp:147

Member Data Documentation

◆ kMaxChildren

const int SkRTree::kMaxChildren = 11
static

Definition at line 51 of file SkRTree.h.

◆ kMinChildren

const int SkRTree::kMinChildren = 6
static

Definition at line 50 of file SkRTree.h.


The documentation for this class was generated from the following files: