PostClassificationWidget.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/qt/widgets/rp/PostClassificationWidget.cpp
22 
23  \brief This file has the PostClassificationWidget class.
24 */
25 
26 // TerraLib
27 #include "../../../common/StringUtils.h"
28 #include "../../../common/progress/ProgressManager.h"
29 #include "../../../dataaccess/utils/Utils.h"
30 #include "../../../geometry/Utils.h"
31 #include "../../../maptools/Utils.h"
32 #include "../../../raster/BandProperty.h"
33 #include "../../../raster/RasterProperty.h"
34 #include "../../../rp/Module.h"
35 #include "../../../rp/PostClassification.h"
36 #include "../../../se/CoverageStyle.h"
37 #include "../../../se/RasterSymbolizer.h"
38 #include "../../../se/Utils.h"
39 #include "../progress/ProgressViewerDialog.h"
41 #include "Utils.h"
42 #include "ui_PostClassificationWidgetForm.h"
43 
44 //Qt
45 #include <QMessageBox>
46 
48  : QWidget(parent, f),
49  m_ui(new Ui::PostClassificationWidgetForm),
50  m_layer(nullptr)
51 {
52  m_ui->setupUi(this);
53 
54  m_ui->m_weightLineEdit->setText("1");
55  m_ui->m_thresholdLineEdit->setText("1");
56 
57  //build input layer
58  QGridLayout* inputLayout = new QGridLayout(m_ui->m_inputWidget);
59  inputLayout->setContentsMargins(0, 0, 0, 0);
61  inputLayout->addWidget(m_inputWidget);
62 
63  //build output parameters
64  QGridLayout* outputLayout = new QGridLayout(m_ui->m_outputWidget);
65  outputLayout->setContentsMargins(0, 0, 0, 0);
67  outputLayout->addWidget(m_outputWidget);
68 
69  //connects
70  connect(m_ui->m_weightSlider, SIGNAL(valueChanged(int)), this, SLOT(weightSliderValueChanged(int)));
71  connect(m_ui->m_thresholdSlider, SIGNAL(valueChanged(int)), this, SLOT(thresholdSliderValueChanged(int)));
72 }
73 
75  default;
76 
77 Ui::PostClassificationWidgetForm* te::qt::widgets::PostClassificationWidget::getForm() const
78 {
79  return m_ui.get();
80 }
81 
82 void te::qt::widgets::PostClassificationWidget::setList(std::list<te::map::AbstractLayerPtr>& layerList)
83 {
84  std::list<te::map::AbstractLayerPtr> layersRasterList;
85 
86  std::list<te::map::AbstractLayerPtr>::iterator it = layerList.begin();
87  //Filter only raster layers
88  while (it != layerList.end())
89  {
90  std::unique_ptr<te::da::DataSetType> dsType = it->get()->getSchema();
91 
92  if (dsType->hasRaster())
93  {
94  te::se::RasterSymbolizer* rs = te::se::GetRasterSymbolizer(it->get()->getStyle());
95 
96  if(rs && rs->getColorMap())
97  layersRasterList.push_back(it->get());
98  }
99 
100  ++it;
101  }
102 
103  if(!layersRasterList.empty())
104  {
105  m_inputWidget->setLayerList(layersRasterList);
106 
107  m_layer = layersRasterList.begin()->get();
108  }
109 }
110 
112 {
113  if(!m_layer)
114  {
115  QMessageBox::warning(this, tr("Post Classification"), tr("Input image is not defined."));
116  return false;
117  }
118 
119  //check output parameters
120  if (m_outputWidget->getOutputRaster().empty())
121  {
122  QMessageBox::warning(this, tr("Post Classification"), tr("Output image is not defined."));
123  return false;
124  }
125 
126  //get layer
127  std::unique_ptr<te::da::DataSet> ds = m_layer->getData();
128 
129  std::size_t rpos = te::da::GetFirstPropertyPos(ds.get(), te::dt::RASTER_TYPE);
130 
131  std::unique_ptr<te::rst::Raster> inputRst = ds->getRaster(rpos);
132 
133  //run post classification
134  te::rp::PostClassification algorithmInstance;
135 
137  algoInputParams.m_inRasterPtr = inputRst.get();
138  algoInputParams.m_weight = (unsigned int)m_ui->m_weightLineEdit->text().toUtf8().toInt();
139  algoInputParams.m_threshold = (unsigned int)m_ui->m_thresholdLineEdit->text().toUtf8().toInt();
140 
142  algoOutputParams.m_rInfo = m_outputWidget->getInfo();
143  algoOutputParams.m_rType = m_outputWidget->getType();
144 
145  //progress
147 
148  QApplication::setOverrideCursor(Qt::WaitCursor);
149 
150  if (algorithmInstance.initialize(algoInputParams))
151  {
152  if (algorithmInstance.execute(algoOutputParams))
153  {
154  algoOutputParams.reset();
155 
156  //set output layer
159 
160  m_outputLayer->setStyle(m_layer->getStyle()->clone());
161 
162  QApplication::restoreOverrideCursor();
163 
164  QMessageBox::information(this, tr("Post Classification"), tr("Post Classification ended sucessfully."));
165  }
166  else
167  {
168  QApplication::restoreOverrideCursor();
169 
170  QMessageBox::critical(this, tr("Post Classification"), tr("Post Classification execution error.") +
171  (" " + algorithmInstance.getErrorMessage() ).c_str());
172 
173  return false;
174  }
175  }
176  else
177  {
178  QApplication::restoreOverrideCursor();
179 
180  QMessageBox::critical(this, tr("Post Classification"), tr("Post Classification initialization error.") +
181  (" " + algorithmInstance.getErrorMessage() ).c_str());
182 
183  return false;
184  }
185 
186  emit addLayer(m_outputLayer);
187 
188  return true;
189 }
190 
192 {
193  m_ui->m_weightLineEdit->setText(te::common::Convert2String(value).c_str());
194 }
195 
197 {
198  m_ui->m_thresholdLineEdit->setText(te::common::Convert2String(value).c_str());
199 }
const std::string & getErrorMessage() const
Return the current error message if there is any.
PostClassification output parameters.
std::string m_rType
Output raster data source type (as described in te::raster::RasterFactory ).
Raster post classification.
TESEEXPORT RasterSymbolizer * GetRasterSymbolizer(Style *s)
Try to get raster symbolizer from a style.
This file has the PostClassificationWidget class.
static te::dt::Date ds(2010, 01, 01)
unsigned int m_weight
The weight value defines the number of times the frequency of the central point has to be considered...
te::qt::widgets::OutputRasterWidget * m_outputWidget
void reset() _NOEXCEPT_OP(false)
Clear all internal allocated resources and reset the parameters instance to its initial state...
void setList(std::list< te::map::AbstractLayerPtr > &layerList)
unsigned int m_threshold
The threshold value is the frequency value above which the central point is modified.
bool initialize(const AlgorithmInputParameters &inputParams) _NOEXCEPT_OP(false)
Initialize the algorithm instance making it ready for execution.
This class is used to set output layer.
This class is used to set input layer.
The RasterSymbolizer describes how to render raster/matrix-coverage data (e.g., satellite photos...
PostClassificationWidget(QWidget *parent=0, Qt::WindowFlags f=0)
bool execute(AlgorithmOutputParameters &outputParams) _NOEXCEPT_OP(false)
Executes the algorithm using the supplied parameters.
Utility functions for the data access module.
te::qt::widgets::InputLayerWidget * m_inputWidget
std::unique_ptr< Ui::PostClassificationWidgetForm > m_ui
Ui::PostClassificationWidgetForm * getForm() const
std::map< std::string, std::string > m_rInfo
The necessary information to create the raster (as described in te::raster::RasterFactory).
std::map< std::string, std::string > getInfo() const
TEQTWIDGETSEXPORT te::map::AbstractLayerPtr createLayer(const std::string &driverName, const te::core::URI &connInfo)
void addLayer(te::map::AbstractLayerPtr layer)
void setLayerList(std::list< te::map::AbstractLayerPtr > list)
te::rst::Raster const * m_inRasterPtr
Input raster.
te::se::ColorMap * getColorMap() const
TEDATAACCESSEXPORT std::size_t GetFirstPropertyPos(const te::da::DataSet *dataset, int datatype)
std::string Convert2String(boost::int16_t value)
It converts a short integer value to a string.
Definition: StringUtils.h:56