Loading...
Searching...
No Matches
KDTreeMultiIndex.h
Go to the documentation of this file.
1/* Copyright (C) 2008 National Institute For Space Research (INPE) - Brazil.
2
3 This file is part of the TerraLib - a Framework for building GIS enabled applications.
4
5 TerraLib is free software: you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 TerraLib is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public License
16 along with TerraLib. See COPYING. If not, write to
17 TerraLib Team at <terralib-team@terralib.org>.
18 */
19
20/*!
21 \file KDTreeIndex.h
22
23 \brief This class makes easier and more generic the use of the te::sam::rtree::Index
24
25 \ingroup vp
26 */
27
28#ifndef __TERRALIB_VP_INTERNAL_KDTREEMULTIINDEX_H
29#define __TERRALIB_VP_INTERNAL_KDTREEMULTIINDEX_H
30
31// Terralib
32#include "Config.h"
33
34#include "../common/STLUtils.h"
35#include "../sam/kdtree/Index.h"
37
38//STL
39#include <memory>
40#include <vector>
41
42namespace te
43{
44 namespace vp
45 {
46 /*!
47 \class KDTreeIndex
48
49 \brief This class makes easier and more generic the use of the te::sam::kdtree::Index
50
51 \ingroup vp
52 */
53 template<class T>
55 {
57
58 public:
59
60 //!< Constructor
62
63 //!< Destructor
65
66 //!< Clears the index
67 void clear();
68
69 //!< Inserts the given data considering the given envelope as key
70 void insert(const te::gm::Coord2D& coord, const T& data);
71
72 //!< Removes the given data considering the given envelope as key
73 void remove(const te::gm::Coord2D& coord, std::size_t dataIndex);
74
75 //!< Gets all data from the KDTreeIndex
76 std::unique_ptr<te::vp::IndexReport<T>> getData() const;
77
78 //!< Searches from all data consdering the given mbr
79 std::unique_ptr<te::vp::IndexReport<T>> search(const te::gm::Envelope& mbr) const;
80
81 private:
82 te::sam::kdtree::Index<KD_NODE> m_index; //!< The internal rtree to store the data indexes
83 IndexContainer<T> m_indexContainer; //!< The indexed data container
84 };
85 }
86}
87
88//Implementation
89template<class T>
91 : m_index(te::gm::Envelope())
92{
93
94}
95template<class T>
97{
98 clear();
99}
100
101template<class T>
103{
104 m_index.clear();
105 m_indexContainer.clear();
106}
107
108
109template<class T>
111{
112 std::size_t newDataIndex = m_indexContainer.insert(data);
113 m_index.insert(coord, newDataIndex);
114}
115
116template<class T>
117void te::vp::KDTreeMultiIndex<T>::remove(const te::gm::Coord2D& coord, std::size_t dataIndex)
118{
119 m_indexContainer.remove(dataIndex);
120}
121
122template<class T>
123std::unique_ptr<te::vp::IndexReport<T>> te::vp::KDTreeMultiIndex<T>::getData() const
124{
125 std::vector<std::size_t> vecValidIndexes = m_indexContainer.getValidIndexes();
126
127 std::unique_ptr<te::vp::IndexReport<T>> indexReport(new te::vp::IndexReport<T>(&m_indexContainer, vecValidIndexes));
128 return indexReport;
129}
130
131template<class T>
132std::unique_ptr<te::vp::IndexReport<T>> te::vp::KDTreeMultiIndex<T>::search(const te::gm::Envelope& mbr) const
133{
134 std::vector<KD_NODE*> vecNodesReport;
135 m_index.search(mbr, vecNodesReport);
136
137 std::vector<std::size_t> vecFullIndexesReport;
138 for (std::size_t i = 0; i < vecNodesReport.size(); ++i)
139 {
140 const std::vector<std::size_t>& vecNodeIndexes = vecNodesReport.at(i)->getData();
141 vecFullIndexesReport.insert(vecFullIndexesReport.end(), vecNodeIndexes.begin(), vecNodeIndexes.end());
142 }
143
144 std::vector<std::size_t> vecNetIndexesReport = m_indexContainer.getValidIndexes(vecFullIndexesReport);
145
146 std::unique_ptr<te::vp::IndexReport<T>> indexReport(new te::vp::IndexReport<T>(&m_indexContainer, vecNetIndexesReport));
147 return indexReport;
148}
149
150#endif // __TERRALIB_VP_INTERNAL_KDTREEINDEX_H
mydialect insert("=", new te::da::BinaryOpEncoder("="))
An Envelope defines a 2D rectangular region.
Definition: Envelope.h:52
A class that represents a two dimensional K-d Tree (2-d Tree).
Definition: Index.h:68
A class that represents an Kd-tree node.
Definition: Node.h:62
std::unique_ptr< te::vp::IndexReport< T > > getData() const
Searches from all data consdering the given mbr.
te::sam::kdtree::Index< KD_NODE > m_index
The internal rtree to store the data indexes.
void remove(const te::gm::Coord2D &coord, std::size_t dataIndex)
Gets all data from the KDTreeIndex.
IndexContainer< T > m_indexContainer
The indexed data container.
std::unique_ptr< te::vp::IndexReport< T > > search(const te::gm::Envelope &mbr) const
KDTreeMultiIndex()
< Constructor
void clear()
Inserts the given data considering the given envelope as key.
~KDTreeMultiIndex()
Clears the index.
void insert(const te::gm::Coord2D &coord, const T &data)
Removes the given data considering the given envelope as key.
TerraLib.
An utility struct for representing 2D coordinates.
Definition: Coord2D.h:41
Kd-Tree node type for nodes with multuple elements (used by template instantiation).
Definition: Node.h:39
Proxy configuration file for TerraView (see terraview_config.h).
Utility classes, structures and definitions for Vector Processing.