SegmenterDummyStrategy.cpp
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/SegmenterDummyStrategy.cpp
22  \briefRaster dummy strategy.
23 */
24 
25 #include "SegmenterDummyStrategy.h"
26 #include "../common/progress/TaskProgress.h"
27 
28 namespace
29 {
31  segmenterDummyStrategyFactoryInstance;
32 }
33 
34 namespace te
35 {
36  namespace rp
37  {
39 
41 
43  initialize(SegmenterStrategyParameters const* const /*strategyParams*/) throw(
44  te::rp::Exception)
45  {
46  return true;
47  }
48 
50  {
52  }
53 
55  SegmenterIdsManager& segmenterIdsManager,
56  const te::rp::SegmenterSegmentsBlock& block2ProcessInfo,
57  const te::rst::Raster& inputRaster,
58  const std::vector< unsigned int >& inputRasterBands,
59  const std::vector< std::complex< double > >& inputRasterNoDataValues,
60  const std::vector< std::complex< double > >& inputRasterBandMinValues,
61  const std::vector< std::complex< double > >& inputRasterBandMaxValues,
62  te::rst::Raster& outputRaster,
63  const unsigned int outputRasterBand,
64  const bool enableProgressInterface )
65  throw( te::rp::Exception )
66  {
67  assert( inputRasterBands.size() == inputRasterNoDataValues.size() );
68  assert( inputRasterNoDataValues.size() == inputRasterBandMinValues.size() );
69  assert( inputRasterBandMinValues.size() == inputRasterBandMaxValues.size() );
70  assert( block2ProcessInfo.m_topCutOffProfile.size() == block2ProcessInfo.m_width );
71  assert( block2ProcessInfo.m_bottomCutOffProfile.size() == block2ProcessInfo.m_width );
72  assert( block2ProcessInfo.m_leftCutOffProfile.size() == block2ProcessInfo.m_height );
73  assert( block2ProcessInfo.m_rightCutOffProfile.size() == block2ProcessInfo.m_height );
74 
76  segmenterIdsManager.getNewID();
77 
78  // Progress interface
79 
80  std::unique_ptr< te::common::TaskProgress > progressPtr;
81  if( enableProgressInterface )
82  {
83  progressPtr.reset( new te::common::TaskProgress );
84  progressPtr->setTotalSteps( block2ProcessInfo.m_height );
85  progressPtr->setMessage( "Segmentation" );
86  }
87 
88  // processing each block
89 
90  unsigned int blkCol = 0;
91  double value = 0;
92  unsigned int inputRasterBandsIdx = 0;
93  const unsigned int inputRasterBandsSize = static_cast<unsigned int>(inputRasterBands.size());
94  bool rasterValuesAreValid = false;
95 
96  for( unsigned int blkLine = 0 ; blkLine < block2ProcessInfo.m_height ; ++blkLine )
97  {
98  for( blkCol = 0 ; blkCol < block2ProcessInfo.m_width ; ++blkCol )
99  {
100  rasterValuesAreValid = true;
101 
102  for( inputRasterBandsIdx = 0 ; inputRasterBandsIdx <
103  inputRasterBandsSize ; ++inputRasterBandsIdx )
104  {
105  inputRaster.getValue( blkCol + block2ProcessInfo.m_startX, blkLine +
106  block2ProcessInfo.m_startY, value,
107  inputRasterBands[ inputRasterBandsIdx ] );
108 
109  if( value == inputRasterNoDataValues[ inputRasterBandsIdx ] )
110  {
111  rasterValuesAreValid = false;
112  break;
113  }
114  }
115 
116  if(
117  rasterValuesAreValid
118  &&
119  ( blkLine >= block2ProcessInfo.m_topCutOffProfile[ blkCol ] )
120  &&
121  ( blkLine <= block2ProcessInfo.m_bottomCutOffProfile[ blkCol ] )
122  &&
123  ( blkCol >= block2ProcessInfo.m_leftCutOffProfile[ blkLine ] )
124  &&
125  ( blkCol <= block2ProcessInfo.m_rightCutOffProfile[ blkLine ] )
126  )
127  {
128  outputRaster.setValue( blkCol + block2ProcessInfo.m_startX,
129  blkLine + block2ProcessInfo.m_startY, segmentId, outputRasterBand );
130  }
131  }
132 
133  if( enableProgressInterface )
134  {
135  if( ! progressPtr->isActive() )
136  {
137  return false;
138  }
139 
140  progressPtr->pulse();
141  }
142  }
143 
144  return true;
145  }
146 
148  const unsigned int bandsToProcess, const unsigned int pixelsNumber ) const
149  {
150  return (double)( sizeof(double) * bandsToProcess * pixelsNumber );
151  }
152 
154  {
155  return 10;
156  }
157 
159  {
160  return true;
161  }
162 
164  {
166  }
167 
169  : te::rp::SegmenterStrategyFactory( "Dummy" )
170  {
171  }
172 
174 
176  {
177  return new te::rp::SegmenterDummyStrategy();
178  }
179 
180  } // end namespace rp
181 } // end namespace te
182 
Segmenter segments IDs manager.
Dummy strategy (just for testing purposes).
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)
Executes the segmentation strategy over region delimited by the given block.
BlocksMergingMethod getBlocksMergingMethod() const
Return the strategy blocks merging method.
bool initialize(SegmenterStrategyParameters const *const strategyParams)
Initialize the segmentation strategy.
Base exception class for plugin module.
This class can be used to inform the progress of a task.
Definition: TaskProgress.h:53
unsigned int getOptimalBlocksOverlapSize() const
Returns a optimal blocks overlap size (number of border pixels overlapped between blocks...
double getMemUsageEstimation(const unsigned int bandsToProcess, const unsigned int pixelsNumber) const
Returns a memory estimation (bytes).
bool shouldComputeMinMaxValues() const
Returns if the min and max pixel values should be computed.
Raster dummy segmenter strategy factory.
void reset()
Clear all internal allocated resources and go back to the initial not-initialized state...
Raster segmenter strategy factory base class.
An abstract class for raster data strucutures.
URI C++ Library.
Definition: Attributes.h:37
Raster segmenter strategy base class.
te::rp::SegmenterStrategy * build()
Concrete factories (derived from this one) must implement this method in order to create objects...
BlocksMergingMethod
Blocks merging method.
Segmenter segments block description class.
virtual void reset()
Clear all internal allocated resources and go back to the initial not-initialized state...
Dummy strategy (just for testing purposes).