ClassifierStrategy.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/ClassifierStrategy.h
22 
23  \brief Raster classifier strategy base class.
24  */
25 
26 #ifndef __TERRALIB_RP_INTERNAL_CLASSIFIERSTRATEGY_H
27 #define __TERRALIB_RP_INTERNAL_CLASSIFIERSTRATEGY_H
28 
29 // TerraLib
30 #include "../raster/Raster.h"
31 #include "../raster/BandProperty.h"
33 #include "Config.h"
34 #include "Exception.h"
35 
36 // STL
37 #include <vector>
38 #include <memory>
39 
40 namespace te
41 {
42  namespace rp
43  {
44  /*!
45  \class ClassifierStrategy
46  \brief Raster classifier strategy base class.
47  */
49  {
50  public:
51 
52  /*! \brief Virtual destructor. */
53  virtual ~ClassifierStrategy();
54 
55  /*!
56  \brief Initialize the classification strategy.
57 
58  \param strategyParams A pointer to the user given specific classification strategy parameters ou NULL if no parameters are present.
59 
60  \return true if OK, false on errors.
61  */
62  virtual bool initialize(ClassifierStrategyParameters const* const strategyParams) _NOEXCEPT_OP(false) = 0;
63 
64  /*!
65  \brief Executes the classification strategy.
66  \return true if OK, false on errors.
67  */
68  virtual bool execute() _NOEXCEPT_OP(false) = 0;
69 
70  /*!
71  \brief Set the input raster.
72  \param raster Input raster.
73  */
74  void setInputRaster( const te::rst::Raster& raster );
75 
76  /*!
77  \brief Set the input raste bandsr.
78  \param rasterBands Input raster bands.
79  */
80  void setInputRasterBands( const std::vector<unsigned int>& rasterBands );
81 
82  /*!
83  \brief Returns a pointer to the output raster or a void pointer if there is none.
84  \return Returns a pointer to the output raster or a void pointer if there is none.
85  \note The caller of this method must take the ownership of the returned object.
86  */
87  std::unique_ptr< te::rst::Raster > releaseOutputRaster();
88 
89  /*!
90  \brief Set the input polygons.
91  \param polygonsPtrs Input polygons pointers.
92  \note The caller of this method must keep the ownership of the objects.
93  */
94  void setInputPolygons( const std::vector<te::gm::Polygon*>& polygonsPtrs );
95 
96  /*!
97  \brief Enable / disable the progress interface.
98  \param enable Enable (true) or disable (false) the progress interface.
99  */
100  void enableProgressInterface( const bool& enable );
101 
102  /*!
103  \brief Returns strategy-dependent metadata.
104  \param metadata Strategy-dependent metadata.
105  */
106  void getMetaData( std::map< std::string, std::string >& metadata ) const;
107 
108  /*!
109  \brief Enable (true) or disable (false) the creation of a paletted output raster.
110  \param enabled Enable (true) or disable (false) the creation of a paletted output raster.
111  */
112  void enableOutputPalette( const bool enabled );
113 
114  /*!
115  \brief Set the output user palette.
116  \param userPalette User output raster palette (it must be large enough to accomodate all classifyier generated classes or an empty vector to automatically generate an random palette.
117  */
118  void setUserOutputPalette( std::vector< te::rst::BandProperty::ColorEntry >& userPalette );
119 
120  protected:
121 
122  /*!
123  \brief A pointer to the input raster.
124  */
126 
127  /*!
128  \brief Progress interface status.
129  */
131 
132  /*!
133  \brief Enable (true) or disable (false) the creation of a paletted output raster.
134  */
136 
137  /*!
138  \brief A pointer to the output raster.
139  */
140  std::unique_ptr< te::rst::Raster > m_outputRasterPtr;
141 
142  /*!
143  \brief Input raster bands.
144  */
145  std::vector<unsigned int> m_inputRasterBands;
146 
147  /*!
148  \brief Input polygons.
149  */
150  std::vector<te::gm::Polygon*> const * m_inputPolygonsPtr;
151 
152  /*!
153  \brief Strategy-dependent metadata.
154  */
155  std::map< std::string, std::string > m_metaData;
156 
157  /*!
158  \brief User output raster palette (it must be large enough to accomodate all classifyier generated classes or an empty vector to automatically generate an random palette.
159  */
160  std::vector< te::rst::BandProperty::ColorEntry > m_userOutputPalette;
161 
162  /*! \brief Default constructor. */
164 
165  /*!
166  \brief Create the output raster using the EXPANSIBLE driver.
167  \param bandsDataTypes Bands data types.
168  \param noDataValues A vector of no-data values for each band.
169  \return true if ok,false on errors.
170  \note A pointer to the created raster will be handled by m_outputRasterPtr.
171  */
172  bool createOutputRaster( const std::vector< int >& bandsDataTypes,
173  const std::vector< double >& noDataValues );
174 
175  /*!
176  \brief Create and set the output raster palette folowing the current internal settings.
177  \param size Palette size.
178  \return true if ok,false on errors.
179  */
180  bool setOutputRasterPalette( const unsigned int size );
181 
182  private:
183 
184  /*!
185  \brief Copy constructor.
186 
187  \param rhs The right-hand side Raster.
188  */
190 
191  /*!
192  \brief Assignment operator.
193 
194  \param rhs The right-hand-side copy that would be used to copy from.
195 
196  \return A reference to this object.
197  */
198  const ClassifierStrategy& operator=(const ClassifierStrategy& rhs);
199 
200  /*!
201  \brief Reset to an initial state
202  */
203  void reset();
204  };
205 
206  } // end namespace rp
207 } // end namespace te
208 
209 #endif // __TERRALIB_RP_INTERNAL_CLASSIFIERSTRATEGY_H
210 
bool m_createRasterPalette
Enable (true) or disable (false) the creation of a paletted output raster.
#define _NOEXCEPT_OP(x)
std::map< std::string, std::string > m_metaData
Strategy-dependent metadata.
std::vector< unsigned int > m_inputRasterBands
Input raster bands.
Exception class.
Raster classifier strategy parameters base class.
An abstract class for raster data strucutures.
Definition: Raster.h:71
URI C++ Library.
#define TERPEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:139
std::unique_ptr< te::rst::Raster > m_outputRasterPtr
A pointer to the output raster.
Configuration flags for the Raster Processing module of TerraLib.
bool m_progressInterfaceEnabled
Progress interface status.
te::rst::Raster const * m_inputRasterPtr
A pointer to the input raster.
Raster classifier strategy base class.
std::vector< te::rst::BandProperty::ColorEntry > m_userOutputPalette
User output raster palette (it must be large enough to accomodate all classifyier generated classes o...
std::vector< te::gm::Polygon * > const * m_inputPolygonsPtr
Input polygons.