libspatialindex API Reference  (git-trunk)
LeafQuery.cc
Go to the documentation of this file.
1 /******************************************************************************
2  * Project: libsidx - A C API wrapper around libspatialindex
3  * Purpose: C++ objects to implement a query of the index's leaves.
4  * Author: Howard Butler, hobu.inc@gmail.com
5  ******************************************************************************
6  * Copyright (c) 2009, Howard Butler
7  *
8  * All rights reserved.
9  *
10  * Permission is hereby granted, free of charge, to any person obtaining a
11  * copy of this software and associated documentation files (the "Software"),
12  * to deal in the Software without restriction, including without limitation
13  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
14  * and/or sell copies of the Software, and to permit persons to whom the
15  * Software is furnished to do so, subject to the following conditions:
16  *
17  * The above copyright notice and this permission notice shall be included
18  * in all copies or substantial portions of the Software.
19  *
20  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
26  * DEALINGS IN THE SOFTWARE.
27 ******************************************************************************/
28 
30 
32 {
33 
34 }
35 
37 {
38  LeafQueryResult result (n->getIdentifier());
39 
41  n->getShape(&ps);
42  SpatialIndex::Region* pr = dynamic_cast<SpatialIndex::Region*>(ps);
43  std::vector<SpatialIndex::id_type> ids;
44  for (uint32_t cChild = 0; cChild < n->getChildrenCount(); cChild++)
45  {
46  ids.push_back(n->getChildIdentifier(cChild));
47  }
48 
49  result.SetIDs(ids);
50  result.SetBounds(pr);
51  delete ps;
52 
53  return result;
54 }
56  SpatialIndex::id_type& nextEntry,
57  bool& hasNext)
58 {
59 
60  const SpatialIndex::INode* n = dynamic_cast<const SpatialIndex::INode*>(&entry);
61 
62  if (n != 0)
63  {
64  // traverse only index nodes at levels 2 and higher.
65  if (n->getLevel() > 0)
66  {
67  for (uint32_t cChild = 0; cChild < n->getChildrenCount(); cChild++)
68  {
69  m_ids.push(n->getChildIdentifier(cChild));
70  }
71  }
72 
73  if (n->isLeaf())
74  {
75  m_results.push_back(get_results(n));
76  }
77  }
78 
79  if (! m_ids.empty())
80  {
81  nextEntry = m_ids.front(); m_ids.pop();
82  hasNext = true;
83  }
84  else
85  {
86  hasNext = false;
87  }
88 }
89 
90 
91 std::vector<SpatialIndex::id_type> const& LeafQueryResult::GetIDs() const
92 {
93  return ids;
94 }
95 
96 void LeafQueryResult::SetIDs(std::vector<SpatialIndex::id_type>& v)
97 {
98  ids.resize(v.size());
99  std::copy(v.begin(), v.end(), ids.begin());
100 }
102 {
103  return bounds;
104 }
105 
107 {
108  bounds = new SpatialIndex::Region(*b);
109 }
110 
111 LeafQueryResult::LeafQueryResult(LeafQueryResult const& other)
112 {
113  ids.resize(other.ids.size());
114  std::copy(other.ids.begin(), other.ids.end(), ids.begin());
115  m_id = other.m_id;
116 
117  bounds = other.bounds->clone();
118 }
119 
121 {
122  if (&rhs != this)
123  {
124  ids.resize(rhs.ids.size());
125  std::copy(rhs.ids.begin(), rhs.ids.end(), ids.begin());
126  m_id = rhs.m_id;
127  bounds = rhs.bounds->clone();
128  }
129  return *this;
130 }
131 
LeafQueryResult get_results(const SpatialIndex::INode *n)
Definition: LeafQuery.cc:36
LeafQueryResult & operator=(LeafQueryResult const &rhs)
Assignment operator.
Definition: LeafQuery.cc:120
void SetBounds(const SpatialIndex::Region *b)
Definition: LeafQuery.cc:106
const SpatialIndex::Region * GetBounds() const
Definition: LeafQuery.cc:101
std::vector< SpatialIndex::id_type > const & GetIDs() const
Definition: LeafQuery.cc:91
void SetIDs(std::vector< SpatialIndex::id_type > &v)
Definition: LeafQuery.cc:96
void getNextEntry(const SpatialIndex::IEntry &entry, SpatialIndex::id_type &nextEntry, bool &hasNext)
Definition: LeafQuery.cc:55
virtual void getShape(IShape **out) const =0
virtual id_type getIdentifier() const =0
virtual uint32_t getChildrenCount() const =0
virtual uint32_t getLevel() const =0
virtual id_type getChildIdentifier(uint32_t index) const =0
virtual bool isLeaf() const =0
Region * clone() override
Definition: Region.cc:114
int64_t id_type
Definition: SpatialIndex.h:41