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 Enable / disable the use of raster data cache.
104  \param enable Enable (true) or disable (false) the use of raster cache.
105  */
106  void enableRasterCache( const bool& enable );
107 
108  /*!
109  \brief Enable / disable the use of multiple threads.
110  \param enable Enable (true) or disable (false) the use of multiple threads.
111  */
112  void enableMultiThread( const bool& enable );
113 
114  /*!
115  \brief Returns strategy-dependent metadata.
116  \param metadata Strategy-dependent metadata.
117  */
118  void getMetaData( std::map< std::string, std::string >& metadata ) const;
119 
120  /*!
121  \brief Enable (true) or disable (false) the creation of a paletted output raster.
122  \param enabled Enable (true) or disable (false) the creation of a paletted output raster.
123  */
124  void enableOutputPalette( const bool enabled );
125 
126  /*!
127  \brief Set the output user palette.
128  \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.
129  */
130  void setUserOutputPalette( std::vector< te::rst::BandProperty::ColorEntry >& userPalette );
131 
132  /*!
133  \brief Return the current error message if there is any.
134 
135  \return Return the current error message if there is any.
136  */
137  const std::string& getErrorMessage() const;
138 
139  protected:
140 
141  /*!
142  \brief A pointer to the input raster.
143  */
145 
146  /*!
147  \brief Progress interface status.
148  */
150 
151  /*!
152  \brief Enable or disable the use a raster data cache.
153  */
155 
156  /*!
157  \brief Enable or disable the use multipe threads.
158  */
160 
161  /*!
162  \brief Enable (true) or disable (false) the creation of a paletted output raster.
163  */
165 
166  /*!
167  \brief A pointer to the output raster.
168  */
169  std::unique_ptr< te::rst::Raster > m_outputRasterPtr;
170 
171  /*!
172  \brief Input raster bands.
173  */
174  std::vector<unsigned int> m_inputRasterBands;
175 
176  /*!
177  \brief Input polygons.
178  */
179  std::vector<te::gm::Polygon*> const * m_inputPolygonsPtr;
180 
181  /*!
182  \brief Strategy-dependent metadata.
183  */
184  std::map< std::string, std::string > m_metaData;
185 
186  /*!
187  \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.
188  */
189  std::vector< te::rst::BandProperty::ColorEntry > m_userOutputPalette;
190 
191  /*! \brief Default constructor. */
193 
194  /*!
195  \brief Create the output raster using the EXPANSIBLE driver.
196  \param bandsDataTypes Bands data types.
197  \param noDataValues A vector of no-data values for each band.
198  \return true if ok,false on errors.
199  \note A pointer to the created raster will be handled by m_outputRasterPtr.
200  */
201  bool createOutputRaster( const std::vector< int >& bandsDataTypes,
202  const std::vector< double >& noDataValues );
203 
204  /*!
205  \brief Create and set the output raster palette folowing the current internal settings.
206  \param size Palette size.
207  \return true if ok,false on errors.
208  */
209  bool setOutputRasterPalette( const unsigned int size );
210 
211  /*!
212  \brief Set the current error message.
213 
214  \param newErrorMessage New error message;
215  */
216  void setErrorMessage( const std::string& newErrorMessage );
217 
218  /*!
219  \brief Reset to an initial state
220  */
221  virtual void reset();
222 
223  private:
224 
225  /*!
226  \brief Current error message.
227  */
228  std::string m_errorMessage;
229 
230  /*!
231  \brief Copy constructor.
232 
233  \param rhs The right-hand side Raster.
234  */
236 
237  /*!
238  \brief Assignment operator.
239 
240  \param rhs The right-hand-side copy that would be used to copy from.
241 
242  \return A reference to this object.
243  */
244  const ClassifierStrategy& operator=(const ClassifierStrategy& rhs);
245  };
246 
247  } // end namespace rp
248 } // end namespace te
249 
250 #endif // __TERRALIB_RP_INTERNAL_CLASSIFIERSTRATEGY_H
251 
bool m_createRasterPalette
Enable (true) or disable (false) the creation of a paletted output raster.
bool m_enableRasterCache
Enable or disable the use a raster data cache.
#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
TerraLib.
#define TERPEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:139
bool m_enableMultiThread
Enable or disable the use multipe threads.
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.
std::string m_errorMessage
Current error message.