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 "Config.h"
29 #include "../classification/Adaptors.h"
30 #include "../raster/Raster.h"
31 
32 namespace te
33 {
34  namespace rp
35  {
36  namespace ca
37  {
38  /*!
39  \class RasterInputAdaptor
40  \brief Classifiers raster input data adaptor.
41 
42  */
43  template<typename DataType>
44  class RasterInputAdaptor : public te::cl::InputAdaptor< DataType >
45  {
46  public:
47 
49  : m_raster( raster ), m_nRows( raster.getNumberOfRows() ),
50  m_nCols( raster.getNumberOfColumns() )
51  {};
52 
54 
55  // overload
56  void getFeature(const unsigned int& elementIndex, const unsigned int& featureIndex,
57  DataType& featureValue ) const
58  {
59  m_raster.getValue( elementIndex % m_nCols, elementIndex / m_nCols, featureValue, featureIndex );
60  };
61 
62  // overload
63  unsigned int getElementsCount() const
64  {
65  return ( m_nRows * m_nCols );
66  };
67 
68  // overload
69  unsigned int getFeaturesCount() const
70  {
71  return static_cast<unsigned int>(m_raster.getNumberOfBands());
72  };
73 
74  protected :
75 
77  unsigned int m_nRows;
78  unsigned int m_nCols;
79  };
80 
81  /*!
82  \class RasterOutputAdaptor
83  \brief Classifiers raster output data adaptor.
84 
85  */
86  template<typename DataType>
87  class RasterOutputAdaptor : public te::cl::OutputAdaptor< DataType >
88  {
89  public:
90 
92  : m_raster( raster ), m_nRows( raster.getNumberOfRows() ),
93  m_nCols( raster.getNumberOfColumns() )
94  {};
95 
97 
98  // overload
99  void setFeature(const unsigned int& elementIndex,
100  const unsigned int& featureIndex, const DataType& value )
101  {
102  m_raster.setValue( elementIndex % m_nCols, elementIndex / m_nCols, (double)value,
103  featureIndex );
104  };
105 
106  // overload
107  unsigned int getElementsCount() const
108  {
109  return ( m_nRows * m_nCols );
110  };
111 
112  // overload
113  unsigned int getFeaturesCount() const
114  {
115  return static_cast<unsigned int>(m_raster.getNumberOfBands());
116  };
117 
118  protected :
119 
121  unsigned int m_nRows;
122  unsigned int m_nCols;
123  double m_value;
124  };
125  } // end namespace ca
126  } // end namespace rp
127 } // end namespace te
128 
129 #endif // __TERRALIB_RP_INTERNAL_CLASSIFIERADAPTORS_H
130 
void setFeature(const unsigned int &elementIndex, const unsigned int &featureIndex, const DataType &value)
Set one feature value.
unsigned int getFeaturesCount() const
Returns the total features per element number.
unsigned int getElementsCount() const
Returns the total elements number.
RasterInputAdaptor(const te::rst::Raster &raster)
unsigned int getFeaturesCount() const
Returns the total features per element number.
unsigned int getElementsCount() const
Returns the total elements number.
void getFeature(const unsigned int &elementIndex, const unsigned int &featureIndex, DataType &featureValue) const
Returns one feature value.
Classifiers input data adaptor.
Definition: Adaptors.h:45
An abstract class for raster data strucutures.
Definition: Raster.h:71
virtual std::size_t getNumberOfBands() const =0
Returns the number of bands (dimension of cells attribute values) in the raster.
Classifiers output data adaptor.
Definition: Adaptors.h:79
URI C++ Library.
Classifiers raster input data adaptor.
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.
const te::rst::Raster & m_raster
Configuration flags for the Raster Processing module of TerraLib.
Classifiers raster output data adaptor.
RasterOutputAdaptor(te::rst::Raster &raster)
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.