Loading...
Searching...
No Matches
Adaptors.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 terralib/classification/Adaptors.h
22
23 \brief Classifiers adaptors.
24*/
25
26#ifndef __TERRALIB_CLASSIFICATION_INTERNAL_ADAPTORS_H
27#define __TERRALIB_CLASSIFICATION_INTERNAL_ADAPTORS_H
28
29#include "Config.h"
30#include "Exception.h"
31
32#include <cstddef>
33#include <vector>
34
35namespace te
36{
37 namespace cl
38 {
39 /*!
40 \class InputAdaptor
41 \brief Classifiers input data adaptor.
42
43 */
44 template<typename DataType>
46 {
47 public:
48
50
52
53 /*!
54 \brief Returns one feature value.
55 \param elementIndex Element index..
56 \param featureIndex Feature index.
57 \param featureValue The returned feature value.
58 */
59 virtual void getFeature(const unsigned int& elementIndex,
60 const unsigned int& featureIndex, DataType& featureValue ) const = 0;
61
62 /*!
63 \brief Returns the total elements number.
64 */
65 virtual unsigned int getElementsCount() const = 0;
66
67 /*!
68 \brief Returns the total features per element number.
69 */
70 virtual unsigned int getFeaturesCount() const = 0;
71 };
72
73 /*!
74 \class OutputAdaptor
75 \brief Classifiers output data adaptor.
76
77 */
78 template<typename DataType>
80 {
81 public:
82
84
86
87 /*!
88 \brief Set one feature value.
89 \param elementIndex Element index..
90 \param featureIndex Feature index.
91 */
92 virtual void setFeature(const unsigned int& elementIndex,
93 const unsigned int& featureIndex, const DataType& value ) = 0;
94
95 /*!
96 \brief Returns the total elements number.
97 */
98 virtual unsigned int getElementsCount() const = 0;
99
100 /*!
101 \brief Returns the total features per element number.
102 */
103 virtual unsigned int getFeaturesCount() const = 0;
104 };
105
106 /*!
107 \class InputOutputAdaptor
108 \brief Classifiers input and output data adaptor.
109
110 */
111 template<typename DataType>
113 {
114 public:
115
117
119
120 /*!
121 \brief Returns one feature value.
122 \param elementIndex Element index..
123 \param featureIndex Feature index.
124 \param featureValue The returned feature value.
125 */
126 virtual void getFeature(const unsigned int& elementIndex,
127 const unsigned int& featureIndex, DataType& featureValue ) const = 0;
128
129 /*!
130 \brief Set one feature value.
131 \param elementIndex Element index..
132 \param featureIndex Feature index.
133 */
134 virtual void setFeature(const unsigned int& elementIndex,
135 const unsigned int& featureIndex, const DataType& value ) = 0;
136
137 /*!
138 \brief Returns the total elements number.
139 */
140 virtual unsigned int getElementsCount() const = 0;
141
142 /*!
143 \brief Returns the total features per element number.
144 */
145 virtual unsigned int getFeaturesCount() const = 0;
146 };
147
148
149 /*!
150 \class ContainerInputAdaptor
151 \brief Classifiers container input data adaptor.
152
153 */
154 template<typename DataType>
155 class VectorOfVectorsInputAdaptor : public InputAdaptor< DataType >
156 {
157 public:
158
159 VectorOfVectorsInputAdaptor( const std::vector< std::vector< DataType > >& container )
160 : m_container( container )
161 {
162 // Checking consistency
163
164 if( !container.empty() )
165 {
166 typename std::vector< std::vector< DataType > >::const_iterator it = container.begin();
167 const typename std::vector< std::vector< DataType > >::const_iterator itEnd = container.end();
168 const std::size_t baseFeaturesCount = container[ 0 ].size();
169
170 while( it != itEnd )
171 {
172 if( it->size() != baseFeaturesCount )
173 {
174 throw Exception( "Features count inconsistency" );
175 }
176
177 ++it;
178 }
179 }
180 };
181
183
184 // overload
185 void getFeature(const unsigned int& elementIndex, const unsigned int& featureIndex,
186 DataType& featureValue ) const
187 {
188 featureValue = m_container[ elementIndex ][ featureIndex ];
189 };
190
191 // overload
192 unsigned int getElementsCount() const
193 {
194 return static_cast<unsigned int>(m_container.size());
195 };
196
197 // overload
198 unsigned int getFeaturesCount() const
199 {
200 if( m_container.empty() )
201 {
202 return 0;
203 }
204 else
205 {
206 return static_cast<unsigned int>(m_container[0].size());
207 }
208 };
209
210 protected :
211
212 /*!
213 \brief Internal container reference.
214 */
215 const std::vector< std::vector< DataType > >& m_container;
216 };
217
218 /*!
219 \class VectorOutputAdaptor
220 \brief Classifiers vector container output data adaptor.
221
222 */
223 template< typename DataType >
225 {
226 public:
227 explicit VectorOutputAdaptor( std::vector< DataType >& container )
228 : m_container( container )
229 {
230 };
231
233
234 // overload
235 void setFeature(const unsigned int& elementIndex,
236 const unsigned int&, const DataType& value )
237 {
238 m_container[ elementIndex ] = value;
239 }
240
241 // overload
242 unsigned int getElementsCount() const
243 {
244 return m_container.size();
245 }
246
247 // overload
248 unsigned int getFeaturesCount() const
249 {
250 return 1;
251 }
252
253 protected :
254
255 /*!
256 \brief Internal container reference.
257 */
258 std::vector< DataType >& m_container;
259 };
260
261 } // end namespace cl
262} // end namespace te
263
264#endif // __TERRALIB_CLASSIFICATION_INTERNAL_MAP_H
Classifiers input data adaptor.
Definition: Adaptors.h:46
virtual void getFeature(const unsigned int &elementIndex, const unsigned int &featureIndex, DataType &featureValue) const =0
Returns one feature value.
virtual unsigned int getFeaturesCount() const =0
Returns the total features per element number.
virtual unsigned int getElementsCount() const =0
Returns the total elements number.
Classifiers input and output data adaptor.
Definition: Adaptors.h:113
virtual unsigned int getElementsCount() const =0
Returns the total elements number.
virtual unsigned int getFeaturesCount() const =0
Returns the total features per element number.
virtual void setFeature(const unsigned int &elementIndex, const unsigned int &featureIndex, const DataType &value)=0
Set one feature value.
virtual void getFeature(const unsigned int &elementIndex, const unsigned int &featureIndex, DataType &featureValue) const =0
Returns one feature value.
Classifiers output data adaptor.
Definition: Adaptors.h:80
virtual unsigned int getElementsCount() const =0
Returns the total elements number.
virtual unsigned int getFeaturesCount() const =0
Returns the total features per element number.
virtual void setFeature(const unsigned int &elementIndex, const unsigned int &featureIndex, const DataType &value)=0
Set one feature value.
void getFeature(const unsigned int &elementIndex, const unsigned int &featureIndex, DataType &featureValue) const
Returns one feature value.
Definition: Adaptors.h:185
VectorOfVectorsInputAdaptor(const std::vector< std::vector< DataType > > &container)
Definition: Adaptors.h:159
unsigned int getElementsCount() const
Returns the total elements number.
Definition: Adaptors.h:192
const std::vector< std::vector< DataType > > & m_container
Internal container reference.
Definition: Adaptors.h:215
unsigned int getFeaturesCount() const
Returns the total features per element number.
Definition: Adaptors.h:198
Classifiers vector container output data adaptor.
Definition: Adaptors.h:225
std::vector< DataType > & m_container
Internal container reference.
Definition: Adaptors.h:258
unsigned int getFeaturesCount() const
Returns the total features per element number.
Definition: Adaptors.h:248
VectorOutputAdaptor(std::vector< DataType > &container)
Definition: Adaptors.h:227
unsigned int getElementsCount() const
Returns the total elements number.
Definition: Adaptors.h:242
void setFeature(const unsigned int &elementIndex, const unsigned int &, const DataType &value)
Set one feature value.
Definition: Adaptors.h:235
TerraLib.
Base exception class for plugin module.
Definition: Exception.h:42
Proxy configuration file for TerraView (see terraview_config.h).
An exception class for the XML module.