26 #ifndef __TERRALIB_SAM_RTREE_INTERNAL_INDEX_H    27 #define __TERRALIB_SAM_RTREE_INTERNAL_INDEX_H    56       template<
class DATATYPE, 
int MAXNODES = 8, 
int MINNODES = MAXNODES / 2> 
class Index    84           std::size_t 
size(
void) 
const;
   170                           const DATATYPE& data,
   180                       std::vector<DATATYPE>& report,
   181                       int& foundObjs) 
const;
   260       template<
class DATATYPE, 
int MAXNODES, 
int MINNODES> 
inline   262         : m_root(0), m_size(0)
   269       template<
class DATATYPE, 
int MAXNODES, 
int MINNODES> 
inline   271         : m_root(0), m_mbr(mbr), m_size(0)
   273         assert(m_mbr.isValid());
   279       template<
class DATATYPE, 
int MAXNODES, 
int MINNODES> 
inline   286       template<
class DATATYPE, 
int MAXNODES, 
int MINNODES> 
inline   292       template<
class DATATYPE, 
int MAXNODES, 
int MINNODES> 
inline   295         return (m_root->m_count == 0);
   298       template<
class DATATYPE, 
int MAXNODES, 
int MINNODES> 
inline   312       template<
class DATATYPE, 
int MAXNODES, 
int MINNODES> 
inline   315         insert(mbr, data, &m_root, 0);
   319       template<
class DATATYPE, 
int MAXNODES, 
int MINNODES> 
inline   322         return remove(mbr, data, &m_root);
   325       template<
class DATATYPE, 
int MAXNODES, 
int MINNODES> 
inline   331           search(mbr, m_root, report, foundObjs);
   336       template<
class DATATYPE, 
int MAXNODES, 
int MINNODES> 
inline   342       template<
class DATATYPE, 
int MAXNODES, 
int MINNODES> 
inline   348       template<
class DATATYPE, 
int MAXNODES, 
int MINNODES> 
inline   356         if(chooseLeaf(mbr, data, *root, &newNode, level))  
   364           newRoot->
m_level = (*root)->m_level + 1;
   367           branch.
m_mbr  = nodeCover(*root);
   369           addBranch(&branch, newRoot, 0);
   372           branch.
m_mbr = nodeCover(newNode);
   374           addBranch(&branch, newRoot, 0);
   384       template<
class DATATYPE, 
int MAXNODES, 
int MINNODES> 
inline   389         std::vector<NodeType*> reInsertList;
   391         if(remove2(mbr, data, *root, reInsertList))
   396           while(!reInsertList.empty())
   400             for(i = 0; i < t->
m_count; ++i)
   404             reInsertList.erase(reInsertList.begin());
   412           if(((*root)->m_count == 1) && ((*root)->isInternalNode()))
   428       template<
class DATATYPE, 
int MAXNODES, 
int MINNODES> 
inline   435           for(i = 0; i < n->
m_count; ++i)
   459           for(i = 0; i < n->
m_count; ++i)
   472       template<
class DATATYPE, 
int MAXNODES, 
int MINNODES>
   481       template<
class DATATYPE, 
int MAXNODES, 
int MINNODES>
   490           int i = pickBranch(mbr, node);    
   505             b.
m_mbr = nodeCover(n2);
   507             return addBranch(&b, node, newNode);
   510         else if (node->
m_level == level)
   519           return addBranch(&b, node, newNode);
   529       template<
class DATATYPE, 
int MAXNODES, 
int MINNODES>
   536               for(i = 0; i < node->
m_count; ++i)
   545               for(i = 0; i < node->
m_count; ++i)
   551               report.push_back(
id);
   561       template<
class DATATYPE, 
int MAXNODES, 
int MINNODES>
   568         for(
int i = 0; i < n->
m_count; ++i)
   582       template<
class DATATYPE, 
int MAXNODES, 
int MINNODES> 
inline   590       template<
class DATATYPE, 
int MAXNODES, 
int MINNODES> 
inline   601           splitNode(node, branch, newNode);
   606       template<
class DATATYPE, 
int MAXNODES, 
int MINNODES> 
inline   611         double bestIncr = -1.0;
   612         double bestArea = 0.;
   615         for(
int i = 0; i < node->
m_count; ++i)
   620           rr = combineRect(mbr, rr);
   622           double increase = rr.
getArea() - area;
   624           if((increase <  bestIncr) || flag)
   631           else if((increase == bestIncr) && (area < bestArea))
   642       template<
class DATATYPE, 
int MAXNODES, 
int MINNODES> 
inline   650         getBranches(node, branch, partitions);
   653         methodZero(partitions);
   659         (*newNode)->m_level = node->
m_level = level;
   661         loadNodes(node, *newNode, partitions);
   664       template<
class DATATYPE, 
int MAXNODES, 
int MINNODES> 
inline   668         for(
int i = 0; i < MAXNODES; ++i)
   678         for(
int i = 1; i <= MAXNODES; ++i)
   684       template<
class DATATYPE, 
int MAXNODES, 
int MINNODES> 
inline   692       template<
class DATATYPE, 
int MAXNODES, 
int MINNODES> 
inline   700         int greatestLower[2];
   706         greatestLower[0] = leastUpper[0] = 0;
   708         for(i = 1; i <= MAXNODES; ++i)
   713             greatestLower[0] = i;
   725         greatestLower[1] = leastUpper[1] = 0;
   727         for(i = 1; i <= MAXNODES; ++i)
   732             greatestLower[1] = i;
   757         seed0 = leastUpper[0];
   758         seed1 = greatestLower[0];
   774         if(separation > bestSep)
   776           seed0 = leastUpper[1];
   777           seed1 = greatestLower[1];
   779           bestSep = separation;
   784           classify(seed0, 0, p);
   785           classify(seed1, 1, p);
   789       template<
class DATATYPE, 
int MAXNODES, 
int MINNODES> 
inline   805       template<
class DATATYPE, 
int MAXNODES, 
int MINNODES> 
inline   813         for(
int i = 0; i <= MAXNODES; ++i)
   818             if(p.
m_count[0] >= (MAXNODES + 1 - MINNODES))
   823             else if(p.
m_count[1] >= (MAXNODES + 1 - MINNODES))
   830             for(
int group = 0; group < 2; ++group)
   841               newArea[group] = newCover[group].
getArea();
   842               increase[group] = newArea[group] - p.
m_area[group];
   846             if(increase[0] < increase[1])
   848             else if(increase[1] < increase[0])
   864       template<
class DATATYPE, 
int MAXNODES, 
int MINNODES> 
inline   867         for(
int i = 0; i <= MAXNODES; ++i)
   878       template<
class DATATYPE, 
int MAXNODES, 
int MINNODES> 
inline   887         for(
int i = 0u; i < node->
m_count; ++i)
   899 #endif  // __TERRALIB_SAM_RTREE_INTERNAL_INDEX_H int m_partition[MAXNODES+1]
Auxiliary partition vector. 
 
NodeType * m_root
Pointer to the root node. 
 
void getBranches(NodeType *n, BranchType *b, PartitionVarsType &p) const
 
bool isInternalNode() const
It returns true if this is a internal node. 
 
double getArea() const
It returns the area of this envelope as measured in the spatial reference system of it...
 
bool intersects(const Envelope &rhs) const
It returns true if the envelopes "spatially intersects". 
 
bool addBranch(BranchType *branch, NodeType *node, NodeType **newNode) const
Add a branch to a node. 
 
bool chooseLeaf(const te::gm::Envelope &mbr, const DATATYPE &data, NodeType *node, NodeType **newNode, int level)
It inserts a new data rectangle into the index structure. 
 
void disconBranch(NodeType *n, int i)
It disconnects a dependent node. 
 
A class that represents an R-tree. 
 
NodeType::BranchType BranchType
 
A class that represents an R-tree node. 
 
te::gm::Envelope m_coverSplit
Auxiliary box covering branchBuf. 
 
te::gm::Envelope m_mbr
Bounding box of the tree. 
 
void classify(int i, int group, PartitionVarsType &p) const
 
double m_urx
Upper right corner x-coordinate. 
 
void init()
Initializes partition vars. 
 
DATATYPE m_data
An object-identifier (oid). 
 
void init()
This method is used during split when a node retained and used again (beeing re-filled). 
 
void pickSeeds(PartitionVarsType &p) const
 
const te::gm::Envelope & getMBR(void) const
It returns the bounding box of all elements in the tree. 
 
int m_level
Leaf is zero, others positive. 
 
bool isEmpty(void) const
It returns true if the tree is empty. 
 
void Union(const Envelope &rhs)
It updates the envelop with coordinates of another envelope. 
 
double m_area[2]
Auxiliary area of each new page. 
 
int m_count
The number of elements in the node (count). 
 
NodeType
The type of node read by XML reader. 
 
bool remove2(const te::gm::Envelope &mbr, const DATATYPE &data, NodeType *n, std::vector< NodeType *> &ee)
It deletes a rectangle from non-root part of an index structure. 
 
int search(const te::gm::Envelope &mbr, std::vector< DATATYPE > &report) const
Range search query. 
 
void pigeonhole(PartitionVarsType &p) const
 
double m_llx
Lower left corner x-coordinate. 
 
An Envelope defines a 2D rectangular region. 
 
void setMBR(const te::gm::Envelope &mbr)
It sets the bounding box of all elements in the tree. 
 
mydialect insert("+", new te::da::BinaryOpEncoder("+"))
 
void methodZero(PartitionVarsType &p) const
 
BRANCH m_branchBuf[MAXNODES+1]
Auxiliary branch buffer. 
 
te::sam::rtree::PartitionVars< BranchType, MAXNODES > PartitionVarsType
 
BranchType m_branch[MAXNODES]
Branches. 
 
bool isLeaf() const
It returns true if this is a leaf node. 
 
std::size_t m_size
The size of R-Tree (number of nodes). 
 
te::gm::Envelope m_mbr
Bounding box containing all the objects under the branch or an object bounding box. 
 
Index & operator=(const Index &rhs)
No assignment operator allowed. 
 
double m_lly
Lower left corner y-coordinate. 
 
void loadNodes(NodeType *n, NodeType *q, PartitionVarsType &p) const
 
void erase(NodeType *node)
Erases a node from the tree and all nodes below it. 
 
void insert(const te::gm::Envelope &mbr, const DATATYPE &data)
It inserts an item into the tree. 
 
double m_ury
Upper right corner y-coordinate. 
 
te::gm::Envelope nodeCover(NodeType *n) const
Find the smallest rectangle that includes all rectangles in branches of a node. 
 
int m_count[2]
Number of entries in each new page. 
 
void splitNode(NodeType *node, BranchType *branch, NodeType **newNode) const
Split a node. 
 
te::gm::Envelope combineRect(const te::gm::Envelope &mbrA, const te::gm::Envelope &mbrB) const
Combine two rectangles into larger one containing both. 
 
te::gm::Envelope m_cover[2]
Auxiliary box of each new page. 
 
int m_taken[MAXNODES+1]
Flag to indicate that entry is ok. 
 
std::size_t size(void) const
It returns the number of elements in the tree. 
 
NODE * m_child
A pointer to the child node. 
 
int pickBranch(const te::gm::Envelope &mbr, NodeType *node) const
Pick a branch. 
 
Auxiliary structure when searching for a split partition. 
 
Node< DATATYPE, MAXNODES, MINNODES > NodeType