Click here to Skip to main content
15,867,686 members
Articles / Programming Languages / VC++
Tip/Trick

R-tree:Space Search Algorithm

Rate me:
Please Sign up or sign in to vote.
3.22/5 (3 votes)
2 Dec 2014CPOL 22.2K   495   8   4
This tip will show you an example for using R-tree.

Introduction

We want to find out what controls are in Rectangle1 and Rectangle2 .

Here are some buttons and two rectangles. "Rectangle1" contains "Button1","Button2","Button5". "Rectangle2" contains "Button3","Button4","Button5".

Image 1

If we want find out what controls are contained by Rectangle1 , then

Click "Test Rectangle1" can show or hide the controls in "Rectangle1".

If we want find out what controls are contained by Rectangle2 , then

Click "Test Rectangle2" can show or hide the controls in "Rectangle2".

Image 2

Image 3

Using the Code

The class description is as follows:

C++
// R-tree class define
template <class DATATYPE,class KEYTYPE,int NUMDIMS,
class KEYTYPEREAL=ELEMTYPE,int TMAXNODES=8,int TMINNODES=TMAXNODES/2> class RTreeEx;

// template argument description
//     DATATYPE - data type
//     KEYTYPE - key type
//     NUMDIMS - Dimension
//     KEYTYPEREAL - The type who can contain KEYTYPE<sup>3
//     TMAXNODES - 3~20
//     TMINNODES - TMAXNODES/2

The usage is as follows:

C++
// Create R-tree object
RT::RTreeEx<CWnd *, LONG, 2> m_rt;

// Insert data
LONG lMin[2], lMax[2];
CRect rc;
pCtrl->GetWindowRect(&rc);
ScreenToClient(&rc);
lMin[0] = rc.left;
lMin[1] = rc.top;
lMax[0] = rc.right;
lMax[1] = rc.bottom;
m_rt.Insert(lMin, lMax, pCtrl);

// Search 
LONG lMin[2], lMax[2];
CRect rc;
lMin[0] = ...;
lMin[1] = ...;
lMax[0] = ...;
lMax[1] = ...;//Particular see source
std::set<CWnd *> setCtrl;
m_rt.Search(lMin, lMax, setCtrl);

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer China Telecom Guangdong
China China
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralMy vote of 1 Pin
Ajay Vijayvargiya7-Dec-14 20:00
Ajay Vijayvargiya7-Dec-14 20:00 
GeneralMy vote of 5 Pin
Volynsky Alex6-Dec-14 10:06
professionalVolynsky Alex6-Dec-14 10:06 
Questionleaves out a lot Pin
chandanadhikari3-Dec-14 19:38
chandanadhikari3-Dec-14 19:38 
AnswerRe: leaves out a lot Pin
EmoBemo3-Dec-14 23:21
EmoBemo3-Dec-14 23:21 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.