SegmenterStrategy.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/SegmenterStrategy.h
22  \brief Raster segmenter strategy base class.
23  */
24 
25 #ifndef __TERRALIB_RP_INTERNAL_SEGMENTERSTRATEGY_H
26 #define __TERRALIB_RP_INTERNAL_SEGMENTERSTRATEGY_H
27 
28 #include "SegmenterIdsManager.h"
30 #include "SegmenterSegmentsBlock.h"
31 #include "Config.h"
32 #include "Exception.h"
33 
34 #include "../raster/Raster.h"
35 
36 #include <vector>
37 
38 namespace te
39 {
40  namespace rp
41  {
42  /*!
43  \class SegmenterStrategy
44  \brief Raster segmenter strategy base class.
45  */
47  {
48  public:
49  /*!
50  \brief Blocks merging method.
51  */
53  {
54  NoMerging = 0, //!< No merging.
55  GradientMerging = 1 //!< Gradient Merging.
56  };
57 
58  virtual ~SegmenterStrategy();
59 
60  /*!
61  \brief Initialize the segmentation strategy.
62  \param strategyParams A pointer to the user given specific segmentation
63  strategy parameters ou NULL if no parameters are present.
64  \return true if OK, false on errors.
65  */
66  virtual bool initialize(
67  SegmenterStrategyParameters const* const strategyParams ) = 0;
68 
69  /*!
70  \brief Clear all internal allocated resources and go back to the initial not-initialized state.
71  */
72  virtual void reset();
73 
74  /*!
75  \brief Executes the segmentation strategy over region delimited by the given block.
76  \param segmenterIdsManager The segments IDs manager to be used when acquiring/releaseing unique segment IDs.
77  \param block2ProcessInfo The information about the block of raster that must be processed.
78  \param inputRaster Input raster.
79  \param inputRasterBands Input raster bands.
80  \param inputRasterNoDataValues A vector of values to be used as input raster no-data values.
81  \param inputRasterBandMinValues The minimum value present on each band.
82  \param inputRasterBandMinValues The maximum value present on each band.
83  \param outputRaster Output raster.
84  \param outputRasterBand Output raster band.
85  \param enableProgressInterface Enable the internal strategy to update
86  the progress interface.
87  \return true if OK, false on errors.
88  \note The used gaind/ofset calcule: new_value = ( old_value + offset ) * gain
89  */
90  virtual bool execute(
91  SegmenterIdsManager& segmenterIdsManager,
92  const te::rp::SegmenterSegmentsBlock& block2ProcessInfo,
93  const te::rst::Raster& inputRaster,
94  const std::vector< unsigned int >& inputRasterBands,
95  const std::vector< std::complex< double > >& inputRasterNoDataValues,
96  const std::vector< std::complex< double > >& inputRasterBandMinValues,
97  const std::vector< std::complex< double > >& inputRasterBandMaxValues,
98  te::rst::Raster& outputRaster,
99  const unsigned int outputRasterBand,
100  const bool enableProgressInterface ) = 0;
101 
102  /*!
103  \brief Returns a memory estimation (bytes).
104  \details This parameter is used by the segmenter to guess the sub-image blocks size.
105  \param bandsToProcess The number of input raster bands that will be processed at the strategy execution time.
106  \param pixelsNumber The number of pixels.
107  \return A positive memory use estimation.
108  */
109  virtual double getMemUsageEstimation( const unsigned int bandsToProcess,
110  const unsigned int pixelsNumber ) const = 0;
111 
112  /*!
113  \brief Returns a optimal blocks overlap size (number of border pixels
114  overlapped between blocks, under one direction).
115  \note This value will be used in the case
116  where the image is splitted into blocks for segmentation.
117  \return The blocks overlap size.
118  */
119  virtual unsigned int getOptimalBlocksOverlapSize() const = 0;
120 
121  /*!
122  \brief Returns if the min and max pixel values should be computed.
123  \return True if min and max values should be computed. False otherwise.
124  */
125  virtual bool shouldComputeMinMaxValues() const = 0;
126 
127  /*!
128  \brief Return the strategy blocks merging method.
129  \return The blocks merging method.
130  */
132 
133  /*!
134  \brief Return the current error message if there is any.
135 
136  \return Return the current error message if there is any.
137  */
138  const std::string& getErrorMessage() const;
139 
140  protected:
141 
143 
144  /*!
145  \brief Set the current error message.
146 
147  \param newErrorMessage New error message;
148  */
149  void setErrorMessage( const std::string& newErrorMessage );
150 
151  private:
152 
153  /*!
154  \brief Current error message.
155  */
156  std::string m_errorMessage;
157 
159 
161  };
162 
163  } // end namespace rp
164 } // end namespace te
165 
166 #endif // __TERRALIB_RP_INTERNAL_ALGORITHM_H
167 
Segments IDs manager.
Raster segmenter strategy parameters base class.
Segmenter segments IDs manager.
Segmenter segments block description class.
Raster segmenter strategy base class.
SegmenterStrategy(const SegmenterStrategy &)
SegmenterStrategy & operator=(const SegmenterStrategy &)
virtual double getMemUsageEstimation(const unsigned int bandsToProcess, const unsigned int pixelsNumber) const =0
Returns a memory estimation (bytes).
std::string m_errorMessage
Current error message.
BlocksMergingMethod
Blocks merging method.
virtual BlocksMergingMethod getBlocksMergingMethod() const =0
Return the strategy blocks merging method.
virtual unsigned int getOptimalBlocksOverlapSize() const =0
Returns a optimal blocks overlap size (number of border pixels overlapped between blocks,...
virtual void reset()
Clear all internal allocated resources and go back to the initial not-initialized state.
virtual bool shouldComputeMinMaxValues() const =0
Returns if the min and max pixel values should be computed.
void setErrorMessage(const std::string &newErrorMessage)
Set the current error message.
virtual bool execute(SegmenterIdsManager &segmenterIdsManager, const te::rp::SegmenterSegmentsBlock &block2ProcessInfo, const te::rst::Raster &inputRaster, const std::vector< unsigned int > &inputRasterBands, const std::vector< std::complex< double > > &inputRasterNoDataValues, const std::vector< std::complex< double > > &inputRasterBandMinValues, const std::vector< std::complex< double > > &inputRasterBandMaxValues, te::rst::Raster &outputRaster, const unsigned int outputRasterBand, const bool enableProgressInterface)=0
Executes the segmentation strategy over region delimited by the given block.
const std::string & getErrorMessage() const
Return the current error message if there is any.
virtual bool initialize(SegmenterStrategyParameters const *const strategyParams)=0
Initialize the segmentation strategy.
An abstract class for raster data strucutures.
Definition: Raster.h:72
TerraLib.
#define TERPEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:139
Proxy configuration file for TerraView (see terraview_config.h).
An exception class for the XML module.