SegmenterDialog.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/widgets/se/SegmenterDialog.cpp
22 
23  \brief A dialog used to execute image segmentation
24 */
25 
26 
27 #include "SegmenterDialog.h"
28 
29 #include "../../../rp/Segmenter.h"
30 #include "../../../rp/SegmenterRegionGrowingBaatzStrategy.h"
31 #include "../../../rp/SegmenterRegionGrowingMeanStrategy.h"
32 #include <ui_SegmenterForm.h>
33 
34 #include <QMessageBox>
35 #include <QListWidgetItem>
36 
37 // TerraLib
38 
40  te::rst::Raster const* inputRasterPtr, const std::string& outpuRasterDSType,
41  const std::map< std::string, std::string >& outpuRasterInfo,
42  QWidget* parent, Qt::WindowFlags f)
43  : QDialog( parent, f ),
44  m_inputRasterPtr( inputRasterPtr ),
45  m_outpuRasterDSType( outpuRasterDSType ),
46  m_outpuRasterInfo( outpuRasterInfo )
47 {
48  m_uiPtr = new Ui::SegmenterForm;
49  m_uiPtr->setupUi(this);
50 
51  // Signals & slots
52  connect(m_uiPtr->m_okPushButton, SIGNAL(clicked()), SLOT(on_okPushButton_clicked()));
53 
54  // initializing the input raster bands combo
55 
56  for( unsigned int inRasterBandsIdx = 0 ; inRasterBandsIdx <
57  inputRasterPtr->getNumberOfBands() ; ++inRasterBandsIdx )
58  {
59  m_uiPtr->m_inputRasterBandsListWidget->addItem(
60  QString::number( inRasterBandsIdx ) );
61  }
62 }
63 
65 {
66  delete m_uiPtr;
67 }
68 
70  boost::shared_ptr< te::rst::Raster >& outputRasterPtr )
71 {
72  if( m_outputRasterPtr.get() )
73  {
74  outputRasterPtr = m_outputRasterPtr;
75  return true;
76  }
77  else
78  {
79  return false;
80  }
81 }
82 
84 {
85  m_outputRasterPtr.reset();
86 
87  if( m_inputRasterPtr )
88  {
89  // Creating the algorithm parameters
90 
91  te::rp::Segmenter::InputParameters algoInputParams;
92 
93  algoInputParams.m_inputRasterPtr = m_inputRasterPtr;
94 
95  QList<QListWidgetItem *> selectedBands =
96  m_uiPtr->m_inputRasterBandsListWidget->selectedItems();
97 
98  if( selectedBands.size() > 0 )
99  {
100  QList<QListWidgetItem *>::const_iterator itBegin = selectedBands.begin();
101  QList<QListWidgetItem *>::const_iterator itEnd = selectedBands.end();
102  while( itBegin != itEnd )
103  {
104  algoInputParams.m_inputRasterBands.push_back( (*itBegin)->text().toUInt() );
105  ++itBegin;
106  }
107 
108  algoInputParams.m_enableThreadedProcessing =
109  m_uiPtr->m_enableThreadedProcessingcheckBox->isChecked();
110  algoInputParams.m_maxSegThreads = m_uiPtr->m_maximumThreadsNumberLineEdit->text().toUInt();
111  algoInputParams.m_enableBlockProcessing =
112  m_uiPtr->m_enableBlockProcessingcheckBox->isChecked();
113 // algoInputParams.m_enableBlockMerging =
114 // m_uiPtr->m_enableBlockMergingCheckBox->isChecked();
115  algoInputParams.m_maxBlockSize = m_uiPtr->m_maximumBlockSizeLineEdit->text().toUInt();
116 
117 
118  algoInputParams.m_strategyName = m_uiPtr->m_segmenterStrategyComboBox->currentText().toUtf8().data();
119 
120  if( algoInputParams.m_strategyName == "RegionGrowingMean" )
121  {
123  strategyParameters.m_minSegmentSize =
124  m_uiPtr->m_minimumSegmentSizeRGLineEdit->text().toUInt();
125  strategyParameters.m_segmentsSimilarityThreshold =
126  m_uiPtr->m_segmentsSimilarityThresholdRGLineEdit->text().toDouble();
127  algoInputParams.setSegStrategyParams( strategyParameters );
128  }
129 
130 
131  if( algoInputParams.m_strategyName == "RegionGrowingBaatz" )
132  {
134  strategyParameters.m_minSegmentSize =
135  m_uiPtr->m_minimumSegmentSizeRGLineEdit->text().toUInt();
136  strategyParameters.m_segmentsSimilarityThreshold =
137  m_uiPtr->m_segmentsSimilarityThresholdRGLineEdit->text().toDouble();
138  algoInputParams.setSegStrategyParams( strategyParameters );
139  }
140 
141  te::rp::Segmenter::OutputParameters algoOutputParams;
142  algoOutputParams.m_rInfo = m_outpuRasterInfo;
143  algoOutputParams.m_rType = m_outpuRasterDSType;
144 
145  // Executing the algorithm
146 
147  te::rp::Segmenter algorithmInstance;
148 
149  if( algorithmInstance.initialize( algoInputParams ) )
150  {
151  if( algorithmInstance.execute( algoOutputParams ) )
152  {
153  m_outputRasterPtr = std::move(algoOutputParams.m_outputRasterPtr);
154  QMessageBox::information(this, "", tr("Segmentation ended sucessfully"));
155  }
156  else
157  {
158  QMessageBox::critical(this, "", tr("Segmentation execution error"));
159  }
160  }
161  else
162  {
163  QMessageBox::critical(this, "", tr("Segmentation initialization error"));
164  }
165  }
166  else
167  {
168  QMessageBox::critical(this, "", tr("Invalid number of bands"));
169  }
170  }
171  else
172  {
173  QMessageBox::critical(this, "", tr("Invalid input raster"));
174  }
175 }
std::string m_strategyName
The segmenter strategy name see each te::rp::SegmenterStrategyFactory inherited classes documentation...
std::map< std::string, std::string > m_outpuRasterInfo
Output raster data source type (as described in te::raster::RasterFactory ).
te::rst::Raster const * m_inputRasterPtr
User interface.
Raster segmentation.
double m_segmentsSimilarityThreshold
Segments similarity treshold - Use lower values to merge only those segments that are more similar - ...
bool initialize(const AlgorithmInputParameters &inputParams)
Initialize the algorithm instance making it ready for execution.
std::string m_outpuRasterDSType
Input raster pointer.
std::string m_rType
Output raster data source type (as described in te::raster::RasterFactory ).
unsigned int m_minSegmentSize
A positive minimum segment size (pixels number - default: 100).
unsigned int m_maxBlockSize
The input image will be split into blocks with this width for processing, this parameter tells the ma...
A dialog used to execute image segmentation.
void setSegStrategyParams(const SegmenterStrategyParameters &segStratParams)
Set specific segmenter strategy parameters.
An abstract class for raster data strucutures.
virtual std::size_t getNumberOfBands() const =0
Returns the number of bands (dimension of cells attribute values) in the raster.
te::rst::Raster const * m_inputRasterPtr
Input raster.
bool getOutputRaster(boost::shared_ptr< te::rst::Raster > &outputRasterPtr)
Returns the output result raster.
double m_segmentsSimilarityThreshold
Segments similarity treshold - Use lower values to merge only those segments that are more similar - ...
unsigned int m_minSegmentSize
A positive minimum segment size (pixels number - default: 100).
std::map< std::string, std::string > m_rInfo
The necessary information to create the raster (as described in te::raster::RasterFactory).
SegmenterDialog(te::rst::Raster const *inputRasterPtr, const std::string &outpuRasterDSType, const std::map< std::string, std::string > &outpuRasterInfo, QWidget *parent=0, Qt::WindowFlags f=0)
Constructs a basic dialog which is a child of parent, with widget flags set to f. ...
bool m_enableThreadedProcessing
If true, threaded processing will be performed (best with multi-core or multi-processor systems (defa...
boost::shared_ptr< te::rst::Raster > m_outputRasterPtr
The necessary information to create the raster (as described in te::raster::RasterFactory).
bool execute(AlgorithmOutputParameters &outputParams)
Executes the algorithm using the supplied parameters.
unsigned int m_maxSegThreads
The maximum number of concurrent segmenter threads (default:0 - automatically found).
std::unique_ptr< te::rst::Raster > m_outputRasterPtr
A pointer the ge generated output raster (label image).
std::vector< unsigned int > m_inputRasterBands
Bands to be processed from the input raster.
bool m_enableBlockProcessing
If true, the original raster will be splitted into small blocks, each one will be segmented independe...