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   354         if(chooseLeaf(mbr, data, *root, &newNode, level))  
   362           newRoot->
m_level = (*root)->m_level + 1;
   366           branch.
m_mbr  = nodeCover(*root);
   368           addBranch(&branch, newRoot, 0);
   371           branch.
m_mbr = nodeCover(newNode);
   373           addBranch(&branch, newRoot, 0);
   383       template<
class DATATYPE, 
int MAXNODES, 
int MINNODES> 
inline   387         std::vector<NodeType*> reInsertList;
   389         if(remove2(mbr, data, *root, reInsertList))
   394           while(!reInsertList.empty())
   398             for(
int i = 0; i < t->
m_count; ++i)
   402             reInsertList.erase(reInsertList.begin());
   410           if(((*root)->m_count == 1) && ((*root)->isInternalNode()))
   426       template<
class DATATYPE, 
int MAXNODES, 
int MINNODES> 
inline   433           for(i = 0; i < n->
m_count; ++i)
   457           for(i = 0; i < n->
m_count; ++i)
   470       template<
class DATATYPE, 
int MAXNODES, 
int MINNODES>
   479       template<
class DATATYPE, 
int MAXNODES, 
int MINNODES>
   485           int i = pickBranch(mbr, node);    
   502             b.
m_mbr = nodeCover(n2);
   504             return addBranch(&b, node, newNode);
   507         else if (node->
m_level == level)
   516           return addBranch(&b, node, newNode);
   526       template<
class DATATYPE, 
int MAXNODES, 
int MINNODES>
   533           for(i = 0; i < node->
m_count; ++i)
   542           for(i = 0; i < node->
m_count; ++i)
   547               report.push_back(
id);
   557       template<
class DATATYPE, 
int MAXNODES, 
int MINNODES>
   564         for(
int i = 0; i < n->
m_count; ++i)
   578       template<
class DATATYPE, 
int MAXNODES, 
int MINNODES> 
inline   586       template<
class DATATYPE, 
int MAXNODES, 
int MINNODES> 
inline   597           splitNode(node, branch, newNode);
   602       template<
class DATATYPE, 
int MAXNODES, 
int MINNODES> 
inline   607         double bestIncr = -1.0;
   608         double bestArea = 0.;
   611         for(
int i = 0; i < node->
m_count; ++i)
   616           rr = combineRect(mbr, rr);
   618           double increase = rr.
getArea() - area;
   620           if((increase <  bestIncr) || flag)
   627           else if((increase == bestIncr) && (area < bestArea))
   638       template<
class DATATYPE, 
int MAXNODES, 
int MINNODES> 
inline   646         getBranches(node, branch, partitions);
   649         methodZero(partitions);
   655         (*newNode)->m_level = node->
m_level = level;
   657         loadNodes(node, *newNode, partitions);
   660       template<
class DATATYPE, 
int MAXNODES, 
int MINNODES> 
inline   664         for(
int i = 0; i < MAXNODES; ++i)
   674         for(
int i = 1; i <= MAXNODES; ++i)
   680       template<
class DATATYPE, 
int MAXNODES, 
int MINNODES> 
inline   688       template<
class DATATYPE, 
int MAXNODES, 
int MINNODES> 
inline   696         int greatestLower[2];
   702         greatestLower[0] = leastUpper[0] = 0;
   704         for(i = 1; i <= MAXNODES; ++i)
   709             greatestLower[0] = i;
   721         greatestLower[1] = leastUpper[1] = 0;
   723         for(i = 1; i <= MAXNODES; ++i)
   728             greatestLower[1] = i;
   753         seed0 = leastUpper[0];
   754         seed1 = greatestLower[0];
   770         if(separation > bestSep)
   772           seed0 = leastUpper[1];
   773           seed1 = greatestLower[1];
   775           bestSep = separation;
   780           classify(seed0, 0, p);
   781           classify(seed1, 1, p);
   785       template<
class DATATYPE, 
int MAXNODES, 
int MINNODES> 
inline   801       template<
class DATATYPE, 
int MAXNODES, 
int MINNODES> 
inline   809         for(
int i = 0; i <= MAXNODES; ++i)
   814             if(p.
m_count[0] >= (MAXNODES + 1 - MINNODES))
   819             else if(p.
m_count[1] >= (MAXNODES + 1 - MINNODES))
   826             for(
int group = 0; group < 2; ++group)
   837               newArea[group] = newCover[group].
getArea();
   838               increase[group] = newArea[group] - p.
m_area[group];
   842             if(increase[0] < increase[1])
   844             else if(increase[1] < increase[0])
   860       template<
class DATATYPE, 
int MAXNODES, 
int MINNODES> 
inline   863         for(
int i = 0; i <= MAXNODES; ++i)
   874       template<
class DATATYPE, 
int MAXNODES, 
int MINNODES> 
inline   883         for(
int i = 0u; i < node->
m_count; ++i)
   895 #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