Windows 2008 R2Windows 2008Win8Windows VistaWindows 7Windows 2003VC++Visual Studio 2010Windows XPVisual StudioWindowsC++
R-tree:Space Search Algorithm






3.22/5 (3 votes)
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
".
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
".
Using the Code
The class description is as follows:
// 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:
// 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);