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 
te::rp::ca::RasterInputOutputAdaptor
Classifiers raster input/output data adaptor.
Definition: ClassifierAdaptors.h:178
te::rp::ca::RasterInputAdaptor::m_raster
const te::rst::Raster & m_raster
Definition: ClassifierAdaptors.h:73
te::rp::ca::RasterInputAdaptor::~RasterInputAdaptor
~RasterInputAdaptor()
Definition: ClassifierAdaptors.h:54
te::rp::Matrix< DataType >
te::rp::ca::RasterInputOutputAdaptor::m_nCols
unsigned int m_nCols
Definition: ClassifierAdaptors.h:225
te
TerraLib.
Definition: AddressGeocodingOp.h:52
te::rp::ca::MatrixOutputAdaptor::~MatrixOutputAdaptor
~MatrixOutputAdaptor()
Definition: ClassifierAdaptors.h:142
te::rp::ca::RasterInputAdaptor::getFeature
void getFeature(const unsigned int &elementIndex, const unsigned int &featureIndex, DataType &featureValue) const
Returns one feature value.
Definition: ClassifierAdaptors.h:57
te::rp::ca::MatrixOutputAdaptor::MatrixOutputAdaptor
MatrixOutputAdaptor(te::rp::Matrix< DataType > &matrix)
Definition: ClassifierAdaptors.h:137
te::rst::Raster
An abstract class for raster data strucutures.
Definition: Raster.h:72
te::rp::ca::RasterOutputAdaptor::m_nRows
unsigned int m_nRows
Definition: ClassifierAdaptors.h:122
te::rst::Raster::setValue
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.
te::rp::ca::RasterInputAdaptor::m_nRows
unsigned int m_nRows
Definition: ClassifierAdaptors.h:78
Matrix.h
Generic template matrix.
te::rp::ca::MatrixOutputAdaptor::m_nCols
unsigned int m_nCols
Definition: ClassifierAdaptors.h:168
te::rp::ca::RasterInputOutputAdaptor::setFeature
void setFeature(const unsigned int &elementIndex, const unsigned int &featureIndex, const DataType &value)
Set one feature value.
Definition: ClassifierAdaptors.h:200
te::rp::ca::RasterInputOutputAdaptor::~RasterInputOutputAdaptor
~RasterInputOutputAdaptor()
Definition: ClassifierAdaptors.h:186
te::cl::InputOutputAdaptor
Classifiers input and output data adaptor.
Definition: Adaptors.h:113
te::rp::ca::RasterOutputAdaptor::RasterOutputAdaptor
RasterOutputAdaptor(te::rst::Raster &raster)
Definition: ClassifierAdaptors.h:92
te::rp::ca::RasterInputOutputAdaptor::getFeaturesCount
unsigned int getFeaturesCount() const
Returns the total features per element number.
Definition: ClassifierAdaptors.h:216
te::rp::ca::RasterOutputAdaptor::~RasterOutputAdaptor
~RasterOutputAdaptor()
Definition: ClassifierAdaptors.h:97
te::rp::ca::RasterInputAdaptor::RasterInputAdaptor
RasterInputAdaptor(const te::rst::Raster &raster)
Definition: ClassifierAdaptors.h:49
te::rp::ca::RasterOutputAdaptor::m_nCols
unsigned int m_nCols
Definition: ClassifierAdaptors.h:123
te::rp::ca::MatrixOutputAdaptor::getFeaturesCount
unsigned int getFeaturesCount() const
Returns the total features per element number.
Definition: ClassifierAdaptors.h:159
te::rp::ca::RasterInputOutputAdaptor::getElementsCount
unsigned int getElementsCount() const
Returns the total elements number.
Definition: ClassifierAdaptors.h:210
te::rp::ca::RasterOutputAdaptor::m_raster
te::rst::Raster & m_raster
Definition: ClassifierAdaptors.h:117
te::rp::ca::RasterInputOutputAdaptor::getFeature
void getFeature(const unsigned int &elementIndex, const unsigned int &featureIndex, DataType &featureValue) const
Returns one feature value.
Definition: ClassifierAdaptors.h:189
te::cl::OutputAdaptor
Classifiers output data adaptor.
Definition: Adaptors.h:80
te::rp::ca::MatrixOutputAdaptor::setFeature
void setFeature(const unsigned int &elementIndex, const unsigned int &featureIndex, const DataType &value)
Set one feature value.
Definition: ClassifierAdaptors.h:145
te::rp::ca::MatrixOutputAdaptor::m_matrix
te::rp::Matrix< DataType > & m_matrix
Definition: ClassifierAdaptors.h:162
te::rp::ca::RasterInputOutputAdaptor::m_nRows
unsigned int m_nRows
Definition: ClassifierAdaptors.h:224
te::rp::ca::RasterInputAdaptor
Classifiers raster input data adaptor.
Definition: ClassifierAdaptors.h:46
te::rp::ca::RasterOutputAdaptor::getFeaturesCount
unsigned int getFeaturesCount() const
Returns the total features per element number.
Definition: ClassifierAdaptors.h:114
te::rst::Raster::getValue
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.
te::rp::ca::MatrixOutputAdaptor
Classifiers matrix output data adaptor.
Definition: ClassifierAdaptors.h:134
te::cl::InputAdaptor
Classifiers input data adaptor.
Definition: Adaptors.h:46
te::rst::Raster::getNumberOfBands
virtual std::size_t getNumberOfBands() const =0
Returns the number of bands (dimension of cells attribute values) in the raster.
te::rp::ca::RasterInputAdaptor::getElementsCount
unsigned int getElementsCount() const
Returns the total elements number.
Definition: ClassifierAdaptors.h:64
te::rp::ca::RasterOutputAdaptor
Classifiers raster output data adaptor.
Definition: ClassifierAdaptors.h:89
te::rp::ca::RasterOutputAdaptor::m_value
double m_value
Definition: ClassifierAdaptors.h:124
te::rp::ca::RasterOutputAdaptor::setFeature
void setFeature(const unsigned int &elementIndex, const unsigned int &featureIndex, const DataType &value)
Set one feature value.
Definition: ClassifierAdaptors.h:100
te::rp::ca::RasterInputOutputAdaptor::RasterInputOutputAdaptor
RasterInputOutputAdaptor(te::rst::Raster &raster)
Definition: ClassifierAdaptors.h:181
te::rp::ca::RasterOutputAdaptor::getElementsCount
unsigned int getElementsCount() const
Returns the total elements number.
Definition: ClassifierAdaptors.h:108
te::rp::ca::MatrixOutputAdaptor::getElementsCount
unsigned int getElementsCount() const
Returns the total elements number.
Definition: ClassifierAdaptors.h:153
te::rp::ca::RasterInputAdaptor::m_nCols
unsigned int m_nCols
Definition: ClassifierAdaptors.h:79
te::rp::ca::RasterInputOutputAdaptor::m_raster
te::rst::Raster & m_raster
Definition: ClassifierAdaptors.h:219
Config.h
Proxy configuration file for TerraView (see terraview_config.h).
te::rp::ca::MatrixOutputAdaptor::m_nRows
unsigned int m_nRows
Definition: ClassifierAdaptors.h:167
te::rp::ca::RasterInputOutputAdaptor::m_value
double m_value
Definition: ClassifierAdaptors.h:226
te::rp::ca::RasterInputAdaptor::getFeaturesCount
unsigned int getFeaturesCount() const
Returns the total features per element number.
Definition: ClassifierAdaptors.h:70