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