ClassifierAdaptors.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/rp/ClassifierAdaptors.h
22  \brief Classifier Adaptors.
23  */
24 
25 #ifndef __TERRALIB_RP_INTERNAL_CLASSIFIERADAPTORS_H
26 #define __TERRALIB_RP_INTERNAL_CLASSIFIERADAPTORS_H
27 
28 #include "Matrix.h"
29 #include "Config.h"
30 #include "../classification/Adaptors.h"
31 #include "../raster/Raster.h"
32 
33 namespace te
34 {
35  namespace rp
36  {
37  namespace ca
38  {
39  /*!
40  \class RasterInputAdaptor
41  \brief Classifiers raster input data adaptor.
42 
43  */
44  template<typename DataType>
45  class RasterInputAdaptor : public te::cl::InputAdaptor< DataType >
46  {
47  public:
48 
50  : m_raster( raster ), m_nRows( raster.getNumberOfRows() ),
51  m_nCols( raster.getNumberOfColumns() )
52  {};
53 
55 
56  // overload
57  void getFeature(const unsigned int& elementIndex, const unsigned int& featureIndex,
58  DataType& featureValue ) const
59  {
60  m_raster.getValue( elementIndex % m_nCols, elementIndex / m_nCols, featureValue, featureIndex );
61  };
62 
63  // overload
64  unsigned int getElementsCount() const
65  {
66  return ( m_nRows * m_nCols );
67  };
68 
69  // overload
70  unsigned int getFeaturesCount() const
71  {
72  return static_cast<unsigned int>(m_raster.getNumberOfBands());
73  };
74 
75  protected :
76 
78  unsigned int m_nRows;
79  unsigned int m_nCols;
80  };
81 
82  /*!
83  \class RasterOutputAdaptor
84  \brief Classifiers raster output data adaptor.
85 
86  */
87  template<typename DataType>
88  class RasterOutputAdaptor : public te::cl::OutputAdaptor< DataType >
89  {
90  public:
91 
93  : m_raster( raster ), m_nRows( raster.getNumberOfRows() ),
94  m_nCols( raster.getNumberOfColumns() )
95  {};
96 
98 
99  // overload
100  void setFeature(const unsigned int& elementIndex,
101  const unsigned int& featureIndex, const DataType& value )
102  {
103  m_raster.setValue( elementIndex % m_nCols, elementIndex / m_nCols, (double)value,
104  featureIndex );
105  };
106 
107  // overload
108  unsigned int getElementsCount() const
109  {
110  return ( m_nRows * m_nCols );
111  };
112 
113  // overload
114  unsigned int getFeaturesCount() const
115  {
116  return static_cast<unsigned int>(m_raster.getNumberOfBands());
117  };
118 
119  protected :
120 
122  unsigned int m_nRows;
123  unsigned int m_nCols;
124  double m_value;
125  };
126 
127  /*!
128  \class MatrixOutputAdaptor
129  \brief Classifiers matrix output data adaptor.
130 
131  */
132  template<typename DataType>
133  class MatrixOutputAdaptor : public te::cl::OutputAdaptor< DataType >
134  {
135  public:
136 
138  : m_matrix( matrix ), m_nRows( matrix.getLinesNumber() ),
139  m_nCols( matrix.getColumnsNumber() )
140  {};
141 
143 
144  // overload
145  void setFeature(const unsigned int& elementIndex,
146  const unsigned int& featureIndex, const DataType& value )
147  {
148  assert( featureIndex == 0 );
149  m_matrix( elementIndex / m_nCols, elementIndex % m_nCols ) = value;
150  };
151 
152  // overload
153  unsigned int getElementsCount() const
154  {
155  return ( m_nRows * m_nCols );
156  };
157 
158  // overload
159  unsigned int getFeaturesCount() const
160  {
161  return ( m_nCols ? 1 : 0 ) ;
162  };
163 
164  protected :
165 
167  unsigned int m_nRows;
168  unsigned int m_nCols;
169  };
170 
171  /*!
172  \class RasterInputOutputAdaptor
173  \brief Classifiers raster input/output data adaptor.
174 
175  */
176  template<typename DataType>
178  {
179  public:
180 
182  : m_raster( raster ), m_nRows( raster.getNumberOfRows() ),
183  m_nCols( raster.getNumberOfColumns() )
184  {};
185 
187 
188  // overload
189  void getFeature(const unsigned int& elementIndex, const unsigned int& featureIndex,
190  DataType& featureValue ) const
191  {
192  assert( elementIndex < ( m_nCols * m_nRows ) );
193  assert( featureIndex < ( m_raster.getNumberOfBands() ) );
194  m_raster.getValue( elementIndex % m_nCols,
195  elementIndex / m_nCols, m_value, featureIndex );
196  featureValue = (DataType)m_value;
197  };
198 
199  // overload
200  void setFeature(const unsigned int& elementIndex,
201  const unsigned int& featureIndex, const DataType& value )
202  {
203  assert( elementIndex < ( m_nCols * m_nRows ) );
204  assert( featureIndex < ( m_raster.getNumberOfBands() ) );
205  m_raster.setValue( elementIndex % m_nCols, elementIndex / m_nCols, (double)value,
206  featureIndex );
207  };
208 
209  // overload
210  unsigned int getElementsCount() const
211  {
212  return ( m_nRows * m_nCols );
213  };
214 
215  // overload
216  unsigned int getFeaturesCount() const
217  {
218  return m_raster.getNumberOfBands();
219  };
220 
221  protected :
222 
224  unsigned int m_nRows;
225  unsigned int m_nCols;
226  mutable double m_value;
227  };
228 
229  } // end namespace ca
230  } // end namespace rp
231 } // end namespace te
232 
233 #endif // __TERRALIB_RP_INTERNAL_CLASSIFIERADAPTORS_H
234 
Generic template matrix.
Classifiers input data adaptor.
Definition: Adaptors.h:46
Classifiers input and output data adaptor.
Definition: Adaptors.h:113
Classifiers output data adaptor.
Definition: Adaptors.h:80
Classifiers matrix output data adaptor.
unsigned int getElementsCount() const
Returns the total elements number.
unsigned int getFeaturesCount() const
Returns the total features per element number.
MatrixOutputAdaptor(te::rp::Matrix< DataType > &matrix)
te::rp::Matrix< DataType > & m_matrix
void setFeature(const unsigned int &elementIndex, const unsigned int &featureIndex, const DataType &value)
Set one feature value.
Classifiers raster input data adaptor.
unsigned int getFeaturesCount() const
Returns the total features per element number.
const te::rst::Raster & m_raster
void getFeature(const unsigned int &elementIndex, const unsigned int &featureIndex, DataType &featureValue) const
Returns one feature value.
RasterInputAdaptor(const te::rst::Raster &raster)
unsigned int getElementsCount() const
Returns the total elements number.
Classifiers raster input/output data adaptor.
void getFeature(const unsigned int &elementIndex, const unsigned int &featureIndex, DataType &featureValue) const
Returns one feature value.
unsigned int getFeaturesCount() const
Returns the total features per element number.
void setFeature(const unsigned int &elementIndex, const unsigned int &featureIndex, const DataType &value)
Set one feature value.
unsigned int getElementsCount() const
Returns the total elements number.
RasterInputOutputAdaptor(te::rst::Raster &raster)
Classifiers raster output data adaptor.
unsigned int getElementsCount() const
Returns the total elements number.
void setFeature(const unsigned int &elementIndex, const unsigned int &featureIndex, const DataType &value)
Set one feature value.
RasterOutputAdaptor(te::rst::Raster &raster)
unsigned int getFeaturesCount() const
Returns the total features per element number.
An abstract class for raster data strucutures.
Definition: Raster.h:72
virtual void setValue(unsigned int c, unsigned int r, const double value, std::size_t b=0)
Sets the attribute value in a band of a cell.
virtual std::size_t getNumberOfBands() const =0
Returns the number of bands (dimension of cells attribute values) in the raster.
virtual void getValue(unsigned int c, unsigned int r, double &value, std::size_t b=0) const
Returns the attribute value of a band of a cell.
TerraLib.
Proxy configuration file for TerraView (see terraview_config.h).