All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
ClassifierDialog.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/ClassifierDialog.cpp
22 
23  \brief A dialog used to execute image classification.
24 */
25 
26 // TerraLib
27 #include "../../../rp/Classifier.h"
28 #include "../../../rp/ClassifierISOSegStrategy.h"
29 
30 // GUI
31 #include "ClassifierDialog.h"
32 #include <ui_ClassifierForm.h>
33 
34 // QT
35 #include <QListWidgetItem>
36 #include <QMessageBox>
37 
38 te::qt::widgets::ClassifierDialog::ClassifierDialog(const te::rst::Raster* inputRasterPtr, std::vector<te::gm::Polygon*> inputPolygons,
39  const std::string& outpuRasterDSType, const std::map<std::string, std::string>& outpuRasterInfo,
40  QWidget* parent, Qt::WindowFlags f)
41  : QDialog(parent, f),
42  m_inputRasterPtr(inputRasterPtr),
43  m_inputPolygons(inputPolygons),
44  m_outpuRasterDSType(outpuRasterDSType),
45  m_outpuRasterInfo(outpuRasterInfo)
46 {
47  m_uiPtr = new Ui::ClassifierForm;
48 
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  for(unsigned b = 0 ; b < inputRasterPtr->getNumberOfBands(); b++)
56  m_uiPtr->m_inputRasterBandsListWidget->addItem(QString::number(b));
57 
58  m_uiPtr->m_helpPushButton->setPageReference("widgets/rp/classifier.html");
59 }
60 
62 {
63  delete m_uiPtr;
64 }
65 
66 bool te::qt::widgets::ClassifierDialog::getOutputRaster(boost::shared_ptr<te::rst::Raster>& outputRasterPtr)
67 {
68  if(m_outputRasterPtr.get())
69  {
70  outputRasterPtr = m_outputRasterPtr;
71 
72  return true;
73  }
74 
75  return false;
76 }
77 
79 {
80  m_outputRasterPtr.reset();
81 
82  if (!m_inputRasterPtr)
83  {
84  QMessageBox::critical(this, "", tr("Invalid input raster"));
85 
86  return;
87  }
88 
89 // define classification parameters
90 
91 // input parameters
92  te::rp::Classifier::InputParameters algoInputParameters;
93  algoInputParameters.m_strategyName = "isoseg";
94  algoInputParameters.m_inputPolygons = m_inputPolygons;
95  algoInputParameters.m_inputRasterPtr = m_inputRasterPtr;
96 
97  QList<QListWidgetItem*> selectedBands = m_uiPtr->m_inputRasterBandsListWidget->selectedItems();
98 
99  if(selectedBands.size() <= 0)
100  {
101  QMessageBox::critical(this, "", tr("Invalid number of bands"));
102 
103  return;
104  }
105 
106  QList<QListWidgetItem*>::const_iterator it = selectedBands.begin();
107  QList<QListWidgetItem*>::const_iterator itend = selectedBands.end();
108 
109  while(it != itend)
110  {
111  algoInputParameters.m_inputRasterBands.push_back((*it)->text().toUInt());
112 
113  ++it;
114  }
115 
116 // link specific parameters with chosen implementation
118  classifierparameters.m_acceptanceThreshold = m_uiPtr->m_acceptanceThresholdComboBox->currentText().toDouble();
119 
120  algoInputParameters.setClassifierStrategyParams(classifierparameters);
121 
122 // output parameters
123  te::rp::Classifier::OutputParameters algoOutputParameters;
124  algoOutputParameters.m_rInfo = m_outpuRasterInfo;
125  algoOutputParameters.m_rType = m_outpuRasterDSType;
126 
127 // execute the algorithm
128  te::rp::Classifier classifierinstance;
129 
130  if(!classifierinstance.initialize(algoInputParameters))
131  {
132  QMessageBox::critical(this, "", tr("Classifier initialization error"));
133 
134  return;
135  }
136  if(!classifierinstance.execute(algoOutputParameters))
137  {
138  QMessageBox::critical(this, "", tr("Classifier execution error"));
139 
140  return;
141  }
142 
143  QMessageBox::information(this, "", tr("Classification ended sucessfully"));
144 
145 }
std::vector< te::gm::Polygon * > m_inputPolygons
The polygons to be classified when using object-based image analysis (OBIA).
Definition: Classifier.h:115
A dialog used to execute image classification.
Raster classification.
Definition: Classifier.h:64
ClassifierDialog(const te::rst::Raster *inputRasterPtr, std::vector< te::gm::Polygon * > inputPolygons, 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. ...
te::rst::Raster const * m_inputRasterPtr
Input raster.
Definition: Classifier.h:113
std::string m_strategyName
The classifier strategy name see each te::rp::ClassifierStrategyFactory inherited classes documentati...
Definition: Classifier.h:116
bool execute(AlgorithmOutputParameters &outputParams)
Executes the algorithm using the supplied parameters.
Definition: Classifier.cpp:158
void setClassifierStrategyParams(const StrategyParameters &p)
Set specific classifier strategy parameters.
Definition: Classifier.cpp:60
Classifier output parameters.
Definition: Classifier.h:127
bool getOutputRaster(boost::shared_ptr< te::rst::Raster > &outputRasterPtr)
Returns the output result raster.
An abstract class for raster data strucutures.
Definition: Raster.h:71
virtual std::size_t getNumberOfBands() const =0
Returns the number of bands (dimension of cells attribute values) in the raster.
std::vector< unsigned int > m_inputRasterBands
Bands to be processed from the input raster.
Definition: Classifier.h:114
bool initialize(const AlgorithmInputParameters &inputParams)
Initialize the algorithm instance making it ready for execution.
Definition: Classifier.cpp:200
Ui::ClassifierForm * m_uiPtr
User interface.
double m_acceptanceThreshold
The acceptance threshold (the closer to 100%, few clusters are created).
std::map< std::string, std::string > m_rInfo
The necessary information to create the raster (as described in te::raster::RasterFactory).
Definition: Classifier.h:155
std::string m_rType
Output raster data source type (as described in te::raster::RasterFactory ).
Definition: Classifier.h:154
Classifier input parameters.
Definition: Classifier.h:74