RStarVisitor.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008 Dustin Spicuzza <dustin@virtualroadside.com>
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of version 2 of the GNU General Public License
6  * as published by the Free Software Foundation.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
16  */
17 
18  #ifndef RSTARVISITOR_H
19  #define RSTARVISITOR_H
20 
21 //#include "RStarBoundingBox.h"
23 
24  /**
25  \file
26 
27  I'm not convinced that these are really the best way to implement
28  this, but it works so I'll stick with it for the moment
29 
30  It should be noted that all of these items are typedef'ed inside
31  of the RStarTree class, so you shouldn't generally need to
32  directly use them.
33  */
34 
35 
36 /********************************************************************
37  * These are all 'acceptor' functors used for queries and removals,
38  * which will have the following characteristics:
39  *
40  * template<typename Node, typename Leaf>
41  *
42  * bool operator()(const Node * node)
43  * -- returns true if this branch should be visited
44  *
45  * bool operator()(const Leaf * leaf)
46  * -- returns true if this leaf should be visited
47  *
48  * This class of functions should be easy to copy, and are expected
49  * to be const. They are only used to determine whether something
50  * should be visited, and not do the actual visiting.
51  *
52  ********************************************************************/
53 
54 // returns true if the node overlaps the specified bound
55 template <typename Node, typename Leaf>
57 {
58  const typename Node::BoundingBox &m_bound;
59  explicit RStarAcceptOverlapping(const typename Node::BoundingBox &bound) : m_bound(bound) {}
60 
61  bool operator()(const Node * const node) const
62  {
63  return m_bound.overlaps(node->bound);
64  }
65 
66  bool operator()(const Leaf * const leaf) const
67  {
68  return m_bound.overlaps(leaf->bound);
69  }
70 
72 };
73 
74 
75 // returns true if the compared boundary is within the specified bound
76 template <typename Node, typename Leaf>
78 {
79  const typename Node::BoundingBox &m_bound;
80  explicit RStarAcceptEnclosing(const typename Node::BoundingBox &bound) : m_bound(bound) {}
81 
82  bool operator()(const Node * const node) const
83  {
84  return m_bound.overlaps(node->bound);
85  }
86 
87  bool operator()(const Leaf * const leaf) const
88  {
89  return m_bound.encloses(leaf->bound);
90  }
91 
92  private: RStarAcceptEnclosing(){}
93 };
94 
95 
96 // will always return true, no matter what
97 template <typename Node, typename Leaf>
99 {
100  bool operator()(const Node * const /*node*/) const { return true; }
101  bool operator()(const Leaf * const /*leaf*/) const { return true; }
102 };
103 
104 
105 /********************************************************************
106  * These are all 'visitor' styled functions -- even though these are
107  * specifically targeted for removal tasks, visitor classes are
108  * specified exactly the same way.
109  *
110  * bool operator()(RStarLeaf<LeafType, dimensions> * leaf)
111  * -- Removal: if returns true, then remove the node
112  * -- Visitor: return can actually be void, not used
113  *
114  * bool ContinueVisiting; (not a function)
115  * -- if false, then the query will end as soon as possible. It
116  * is not guaranteed that the operator() will not be called, so
117  * items may be removed/visited after this is set to false
118  *
119  * You may modify the items that the leaf points to, but under no
120  * circumstance should the bounds of the item be modified (since
121  * that would screw up the tree).
122  *
123  ********************************************************************/
124 
125 
126 /*
127  Default functor used to delete nodes from the R* tree. You can specify
128  a different functor to use, as long as it has the same signature as this.
129 */
130 template <typename Leaf>
132 
133  const bool ContinueVisiting;
134  RStarRemoveLeaf() : ContinueVisiting(true) {}
135 
136  bool operator()(const Leaf * const /*leaf*/) const
137  {
138  return true;
139  }
140 };
141 
142 
143 // returns true if the specific leaf is matched. If remove duplicates is true,
144 // then it searches for all possible instances of the item
145 template <typename Leaf>
147 {
148  mutable bool ContinueVisiting;
150  const typename Leaf::leaf_type &m_leaf;
151 
152  explicit RStarRemoveSpecificLeaf(const typename Leaf::leaf_type &leaf, bool remove_duplicates = false) :
153  ContinueVisiting(true), m_remove_duplicates(remove_duplicates), m_leaf(leaf) {}
154 
155  bool operator()(const Leaf * const leaf) const
156  {
157  if (ContinueVisiting && m_leaf == leaf->leaf)
158  {
159  if (!m_remove_duplicates)
160  ContinueVisiting = false;
161  return true;
162  }
163  return false;
164  }
165 
167 };
168 
169 
170 #endif
bool operator()(const Leaf *const leaf) const
Definition: RStarVisitor.h:87
bool operator()(const Leaf *const ) const
Definition: RStarVisitor.h:101
const bool ContinueVisiting
Definition: RStarVisitor.h:133
bool operator()(const Node *const ) const
Definition: RStarVisitor.h:100
bool operator()(const Leaf *const ) const
Definition: RStarVisitor.h:136
RStarRemoveSpecificLeaf(const typename Leaf::leaf_type &leaf, bool remove_duplicates=false)
Definition: RStarVisitor.h:152
const Node::BoundingBox & m_bound
Definition: RStarVisitor.h:79
const Leaf::leaf_type & m_leaf
Definition: RStarVisitor.h:150
bool operator()(const Leaf *const leaf) const
Definition: RStarVisitor.h:155
bool operator()(const Node *const node) const
Definition: RStarVisitor.h:61
RTree::BoundingBox BoundingBox
Definition: main.cpp:34
RStarAcceptOverlapping(const typename Node::BoundingBox &bound)
Definition: RStarVisitor.h:59
const Node::BoundingBox & m_bound
Definition: RStarVisitor.h:58
RStarAcceptEnclosing(const typename Node::BoundingBox &bound)
Definition: RStarVisitor.h:80
bool operator()(const Node *const node) const
Definition: RStarVisitor.h:82
bool operator()(const Leaf *const leaf) const
Definition: RStarVisitor.h:66