All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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  {
38 
40  {
41  }
42 
44  {
45  }
46 
48  SegmenterStrategyParameters const* const strategyParams )
49  throw( te::rp::Exception )
50  {
51  return true;
52  }
53 
55  {
56  }
57 
59  SegmenterIdsManager& segmenterIdsManager,
60  const te::rp::SegmenterSegmentsBlock& block2ProcessInfo,
61  const te::rst::Raster& inputRaster,
62  const std::vector< unsigned int >& inputRasterBands,
63  const std::vector< double >& inputRasterNoDataValues,
64  const std::vector< double >& inputRasterBandMinValues,
65  const std::vector< double >& inputRasterBandMaxValues,
66  te::rst::Raster& outputRaster,
67  const unsigned int outputRasterBand,
68  const bool enableProgressInterface )
69  throw( te::rp::Exception )
70  {
71  assert( inputRasterBands.size() == inputRasterNoDataValues.size() );
72  assert( inputRasterNoDataValues.size() == inputRasterBandMinValues.size() );
73  assert( inputRasterBandMinValues.size() == inputRasterBandMaxValues.size() );
74  assert( block2ProcessInfo.m_topCutOffProfile.size() == block2ProcessInfo.m_width );
75  assert( block2ProcessInfo.m_bottomCutOffProfile.size() == block2ProcessInfo.m_width );
76  assert( block2ProcessInfo.m_leftCutOffProfile.size() == block2ProcessInfo.m_height );
77  assert( block2ProcessInfo.m_rightCutOffProfile.size() == block2ProcessInfo.m_height );
78 
80  segmenterIdsManager.getNewID();
81 
82  // Progress interface
83 
84  std::auto_ptr< te::common::TaskProgress > progressPtr;
85  if( enableProgressInterface )
86  {
87  progressPtr.reset( new te::common::TaskProgress );
88  progressPtr->setTotalSteps( block2ProcessInfo.m_height );
89  progressPtr->setMessage( "Segmentation" );
90  }
91 
92  // processing each block
93 
94  unsigned int blkCol = 0;
95  double value = 0;
96  unsigned int inputRasterBandsIdx = 0;
97  const unsigned int inputRasterBandsSize = inputRasterBands.size();
98  bool rasterValuesAreValid = false;
99 
100  for( unsigned int blkLine = 0 ; blkLine < block2ProcessInfo.m_height ; ++blkLine )
101  {
102  for( blkCol = 0 ; blkCol < block2ProcessInfo.m_width ; ++blkCol )
103  {
104  rasterValuesAreValid = true;
105 
106  for( inputRasterBandsIdx = 0 ; inputRasterBandsIdx <
107  inputRasterBandsSize ; ++inputRasterBandsIdx )
108  {
109  inputRaster.getValue( blkCol + block2ProcessInfo.m_startX, blkLine +
110  block2ProcessInfo.m_startY, value,
111  inputRasterBands[ inputRasterBandsIdx ] );
112 
113  if( value == inputRasterNoDataValues[ inputRasterBandsIdx ] )
114  {
115  rasterValuesAreValid = false;
116  break;
117  }
118  }
119 
120  if(
121  rasterValuesAreValid
122  &&
123  ( blkLine >= block2ProcessInfo.m_topCutOffProfile[ blkCol ] )
124  &&
125  ( blkLine <= block2ProcessInfo.m_bottomCutOffProfile[ blkCol ] )
126  &&
127  ( blkCol >= block2ProcessInfo.m_leftCutOffProfile[ blkLine ] )
128  &&
129  ( blkCol <= block2ProcessInfo.m_rightCutOffProfile[ blkLine ] )
130  )
131  {
132  outputRaster.setValue( blkCol + block2ProcessInfo.m_startX,
133  blkLine + block2ProcessInfo.m_startY, segmentId, outputRasterBand );
134  }
135  }
136 
137  if( enableProgressInterface )
138  {
139  if( ! progressPtr->isActive() )
140  {
141  return false;
142  }
143 
144  progressPtr->pulse();
145  }
146  }
147 
148  return true;
149  }
150 
152  const unsigned int bandsToProcess, const unsigned int pixelsNumber ) const
153  {
154  return (double)( sizeof(double) * bandsToProcess * pixelsNumber );
155  }
156 
158  {
159  return 10;
160  }
161 
163  : te::rp::SegmenterStrategyFactory( "Dummy" )
164  {
165  }
166 
168  {
169  }
170 
172  {
173  return new te::rp::SegmenterDummyStrategy();
174  }
175 
176  } // end namespace rp
177 } // end namespace te
178 
Segmenter segments IDs manager.
Dummy strategy (just for testing purposes).
bool initialize(SegmenterStrategyParameters const *const strategyParams)
Initialize the segmentation strategy.
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).
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.
Definition: Raster.h:71
Raster segmenter strategy base class.
bool execute(SegmenterIdsManager &segmenterIdsManager, const te::rp::SegmenterSegmentsBlock &block2ProcessInfo, const te::rst::Raster &inputRaster, const std::vector< unsigned int > &inputRasterBands, const std::vector< double > &inputRasterNoDataValues, const std::vector< double > &inputRasterBandMinValues, const std::vector< double > &inputRasterBandMaxValues, te::rst::Raster &outputRaster, const unsigned int outputRasterBand, const bool enableProgressInterface)
Executes the segmentation strategy over region delimited by the given block.
te::rp::SegmenterStrategy * build()
Concrete factories (derived from this one) must implement this method in order to create objects...
Segmenter segments block description class.
Dummy strategy (just for testing purposes).