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  } // end namespace ca
171  } // end namespace rp
172 } // end namespace te
173 
174 #endif // __TERRALIB_RP_INTERNAL_CLASSIFIERADAPTORS_H
175 
void setFeature(const unsigned int &elementIndex, const unsigned int &featureIndex, const DataType &value)
Set one feature value.
MatrixOutputAdaptor(te::rp::Matrix< DataType > &matrix)
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.
RasterInputAdaptor(const te::rst::Raster &raster)
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.
Classifiers matrix 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.
Classifiers input data adaptor.
Definition: Adaptors.h:45
An abstract class for raster data strucutures.
Definition: Raster.h:71
Classifiers output data adaptor.
Definition: Adaptors.h:79
TerraLib.
virtual std::size_t getNumberOfBands() const =0
Returns the number of bands (dimension of cells attribute values) in the raster.
Classifiers raster input data adaptor.
Generic template matrix.
unsigned int getElementsCount() const
Returns the total elements number.
const te::rst::Raster & m_raster
Configuration flags for the Raster Processing module of TerraLib.
unsigned int getFeaturesCount() const
Returns the total features per element number.
Classifiers raster output data adaptor.
RasterOutputAdaptor(te::rst::Raster &raster)
unsigned int getElementsCount() const
Returns the total elements number.
unsigned int getFeaturesCount() const
Returns the total features per element number.
te::rp::Matrix< DataType > & m_matrix
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.