All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
FilterWizardPage.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/FilterWizardPage.h
22 
23  \brief This file has the FilterWizardPage class.
24 */
25 
26 // TerraLib
27 #include "../../../common/progress/ProgressManager.h"
28 #include "../../../dataaccess/dataset/DataSet.h"
29 #include "../../../dataaccess/dataset/DataSetType.h"
30 #include "../../../dataaccess/utils/Utils.h"
31 #include "../../../rp/Filter.h"
32 #include "../../../rp/Module.h"
33 #include "../canvas/MapDisplay.h"
34 #include "../progress/ProgressViewerDialog.h"
35 #include "FilterWizardPage.h"
36 #include "MaskDialog.h"
37 #include "RasterNavigatorWidget.h"
38 #include "Utils.h"
39 #include "ui_FilterWizardPageForm.h"
40 
41 //QT
42 #include <QApplication>
43 #include <QGridLayout>
44 #include <QMessageBox>
45 
46 //Boost
47 #include <boost/lexical_cast.hpp>
48 
50  : QWizardPage(parent),
51  m_ui(new Ui::FilterWizardPageForm)
52 {
53 //build form
54  m_ui->setupUi(this);
55 
56 // configure page
57  this->setTitle(tr("Filter"));
58  this->setSubTitle(tr("Select the type of filter and set their specific parameters."));
59 
60  m_ui->m_maskToolButton->setIcon(QIcon::fromTheme("mask"));
61  m_ui->m_loadMaskToolButton->setIcon(QIcon::fromTheme("mask-fill"));
62  m_ui->m_maskDefaultValueLineEdit->setValidator(new QDoubleValidator(this));
63 
64  //preview
65  QGridLayout* displayLayout = new QGridLayout(m_ui->m_previewWidget);
66  m_navigator.reset(new te::qt::widgets::RasterNavigatorWidget(m_ui->m_previewWidget));
67  m_navigator->showAsPreview(true, false);
68  m_navigator->hideColorCompositionTool(true);
69  displayLayout->addWidget(m_navigator.get());
70  displayLayout->setContentsMargins(0,0,0,0);
71 
72  //connects
73  connect(m_ui->m_listWidget, SIGNAL(itemSelectionChanged()), this, SIGNAL(completeChanged()));
74  connect(m_ui->m_typeComboBox, SIGNAL(activated(int)), SLOT(onFilterTypeComboBoxActivated(int)));
75  connect(m_ui->m_maskToolButton, SIGNAL(clicked()), SLOT(onMaskToolButtonClicked()));
76  connect(m_ui->m_loadMaskToolButton, SIGNAL(clicked()), SLOT(onLoadMaskToolButtonClicked()));
77  connect(m_navigator.get(), SIGNAL(previewClicked()), this, SLOT(apply()));
78 
80 }
81 
83 {
84 }
85 
87 {
88  if(m_ui->m_listWidget->selectedItems().isEmpty())
89  return false;
90 
91  return true;
92 }
93 
95 {
96  m_layer = layer;
97 
98  m_navigator->set(m_layer, true);
99 
100  m_navigator->getDisplay()->refresh();
101 
102  listBands();
103 }
104 
106 {
107  int idx = m_ui->m_typeComboBox->currentIndex();
108 
109  te::rp::Filter::InputParameters algoInputParams;
110  algoInputParams.m_iterationsNumber = m_ui->m_iterationsSpinBox->value();
111  algoInputParams.m_enableProgress = true;
112  algoInputParams.m_filterType = (te::rp::Filter::InputParameters::FilterType)m_ui->m_typeComboBox->itemData(idx).toInt();
113 
115  {
116  algoInputParams.m_windowH = m_window.size1();
117  algoInputParams.m_windowW = m_window.size2();
118  algoInputParams.m_window = m_window;
119  }
120 
121  int nBands = m_ui->m_listWidget->count();
122  for(int i = 0; i < nBands; ++i)
123  {
124  if(m_ui->m_listWidget->item(i)->isSelected())
125  algoInputParams.m_inRasterBands.push_back(i);
126  }
127 
128  return algoInputParams;
129 }
130 
132 {
133  te::rp::Filter::OutputParameters algoOutputParams;
134 
135  return algoOutputParams;
136 }
137 
139 {
140  int filterType = m_ui->m_typeComboBox->itemData(index).toInt();
141 
142  bool flag = filterType == te::rp::Filter::InputParameters::UserDefinedWindowT;
143 
144  m_ui->m_maskSizeSpinBox->setEnabled(flag);
145  m_ui->m_maskToolButton->setEnabled(flag);
146  m_ui->m_maskDefaultValueLineEdit->setEnabled(flag);
147 }
148 
150 {
151  te::qt::widgets::MaskDialog dlg(this);
152 
153  dlg.setMaskSize(m_ui->m_maskSizeSpinBox->value(), m_ui->m_maskSizeSpinBox->value(),
154  m_ui->m_maskDefaultValueLineEdit->text().isEmpty() ? 0 : m_ui->m_maskDefaultValueLineEdit->text().toDouble());
155 
156  if(dlg.exec() == QDialog::Accepted)
157  {
158  m_window = dlg.getMatrix();
159 
160  m_ui->m_loadMaskToolButton->setEnabled(true);
161  }
162 }
163 
165 {
166  te::qt::widgets::MaskDialog dlg(this);
167 
168  dlg.setMaskSize(m_window);
169 
170  m_ui->m_maskSizeSpinBox->setValue(m_window.size1());
171 
172  if(dlg.exec() == QDialog::Accepted)
173  {
174  m_window = dlg.getMatrix();
175  }
176 }
177 
179 {
180  if(m_ui->m_listWidget->selectedItems().isEmpty())
181  {
182  QMessageBox::warning(this, tr("Warning"), tr("No band was selected."));
183  return;
184  }
185 
186  QApplication::setOverrideCursor(Qt::WaitCursor);
187 
188  //get preview raster
189  te::rst::Raster* inputRst = m_navigator->getExtentRaster(true);
190 
191  //set segmenters parameters
192  te::rp::Filter::InputParameters algoInputParams = getInputParams();
193 
194  algoInputParams.m_inRasterPtr = inputRst;
195 
196  te::rp::Filter::OutputParameters algoOutputParams;
197 
198  std::map<std::string, std::string> rinfo;
199  rinfo["MEM_RASTER_NROWS"] = boost::lexical_cast<std::string>(inputRst->getNumberOfRows());
200  rinfo["MEM_RASTER_NCOLS"] = boost::lexical_cast<std::string>(inputRst->getNumberOfColumns());
201  rinfo["MEM_RASTER_DATATYPE"] = boost::lexical_cast<std::string>(inputRst->getBandDataType(0));
202  rinfo["MEM_RASTER_NBANDS"] = boost::lexical_cast<std::string>(inputRst->getNumberOfBands());
203 
204  algoOutputParams.m_rType = "MEM";
205  algoOutputParams.m_rInfo = rinfo;
206 
207  //run contrast
208  te::rp::Filter algorithmInstance;
209 
210  try
211  {
212  if(algorithmInstance.initialize(algoInputParams))
213  {
214  if(algorithmInstance.execute(algoOutputParams))
215  {
216  std::auto_ptr<te::rst::Raster> rst = algoOutputParams.m_outputRasterPtr;
217 
218  m_navigator->drawRaster(rst.get());
219  }
220  }
221  }
222  catch(...)
223  {
224  QMessageBox::warning(this, tr("Warning"), tr("Filter error."));
225  }
226 
227  QApplication::restoreOverrideCursor();
228 
229  //delete input raster dataset
230  delete inputRst;
231 }
232 
234 {
235  m_ui->m_listWidget->clear();
236 
237  //get input raster
238  std::auto_ptr<te::da::DataSet> ds = m_layer->getData();
239 
240  if(ds.get())
241  {
242  std::size_t rpos = te::da::GetFirstPropertyPos(ds.get(), te::dt::RASTER_TYPE);
243 
244  std::auto_ptr<te::rst::Raster> inputRst = ds->getRaster(rpos);
245 
246  if(inputRst.get())
247  {
248  for(unsigned int i = 0; i < inputRst->getNumberOfBands(); ++i)
249  {
250  m_ui->m_listWidget->addItem(QString::number(i));
251  }
252  }
253  }
254 }
255 
257 {
258  m_ui->m_typeComboBox->clear();
259 
260  m_ui->m_typeComboBox->addItem(tr("Sobel"), te::rp::Filter::InputParameters::SobelFilterT);
261  m_ui->m_typeComboBox->addItem(tr("Roberts"), te::rp::Filter::InputParameters::RobertsFilterT);
262  m_ui->m_typeComboBox->addItem(tr("Mean"), te::rp::Filter::InputParameters::MeanFilterT);
263  m_ui->m_typeComboBox->addItem(tr("Mode"), te::rp::Filter::InputParameters::ModeFilterT);
264  m_ui->m_typeComboBox->addItem(tr("Median"), te::rp::Filter::InputParameters::MedianFilterT);
265  m_ui->m_typeComboBox->addItem(tr("Dilation"), te::rp::Filter::InputParameters::DilationFilterT);
266  m_ui->m_typeComboBox->addItem(tr("Erosion"), te::rp::Filter::InputParameters::ErosionFilterT);
267  m_ui->m_typeComboBox->addItem(tr("User Defined"), te::rp::Filter::InputParameters::UserDefinedWindowT);
268 
269  onFilterTypeComboBoxActivated(0);
270 }
The resultant pixel will be the mode of pixels in the convolution window. When the window is multimod...
Definition: Filter.h:66
This class is a dialog to create a user defined mask.
Definition: MaskDialog.h:55
The resultant pixel will be the mean of pixels in the convolution window.
Definition: Filter.h:65
Utility functions for the data access module.
bool m_enableProgress
Enable/Disable the progress interface (default:false).
Definition: Filter.h:85
unsigned int getNumberOfColumns() const
Returns the raster number of columns.
Definition: Raster.cpp:213
The resultant pixel will be the lowest pixel value in the convolution window.
Definition: Filter.h:69
std::string m_rType
Output raster data source type (as described in te::raster::RasterFactory ).
Definition: Filter.h:113
unsigned int m_windowH
The height of the convolution window. (commonly 3, with W=3 to make a 3x3 window, and so on) ...
Definition: Filter.h:81
std::vector< unsigned int > m_inRasterBands
Bands to be used from the input raster 1.
Definition: Filter.h:77
std::auto_ptr< Ui::FilterWizardPageForm > m_ui
std::map< std::string, std::string > m_rInfo
The necessary information to create the raster (as described in te::raster::RasterFactory).
Definition: Filter.h:115
The resultant pixel will be the median of pixels in the convolution window.
Definition: Filter.h:67
unsigned int m_iterationsNumber
The number of iterations to perform (default:1).
Definition: Filter.h:79
The resultant pixel will be the highest pixel value in the convolution window.
Definition: Filter.h:68
An abstract class for raster data strucutures.
Definition: Raster.h:71
unsigned int getNumberOfRows() const
Returns the raster number of rows.
Definition: Raster.cpp:208
virtual std::size_t getNumberOfBands() const =0
Returns the number of bands (dimension of cells attribute values) in the raster.
te::rp::Filter::OutputParameters getOutputParams()
This file defines a class for a MaskDialog.
A series of well-known filtering algorithms for images, linear and non-linear..
Definition: Filter.h:47
void setMaskSize(int height, int width, double defaultValue)
Definition: MaskDialog.cpp:52
Filter input parameters.
Definition: Filter.h:55
boost::numeric::ublas::matrix< double > getMatrix()
Definition: MaskDialog.cpp:110
This class is used to navigate over a DataSetLayer (having a raster representation) and given a set o...
bool initialize(const AlgorithmInputParameters &inputParams)
Initialize the algorithm instance making it ready for execution.
Definition: Filter.cpp:365
unsigned int m_windowW
The width of the convolution window.
Definition: Filter.h:83
FilterType m_filterType
The edge filter type.
Definition: Filter.h:73
std::auto_ptr< RasterNavigatorWidget > m_navigator
This file has the RasterNavigatorWidget class.
te::rp::Filter::InputParameters getInputParams()
std::auto_ptr< te::rst::Raster > m_outputRasterPtr
A pointer the ge generated output raster (label image).
Definition: Filter.h:117
te::rst::Raster const * m_inRasterPtr
Input raster.
Definition: Filter.h:75
void set(te::map::AbstractLayerPtr layer)
This method is used to set the selected layer for mixture model operation.
TEDATAACCESSEXPORT std::size_t GetFirstPropertyPos(const te::da::DataSet *dataset, int datatype)
Definition: Utils.cpp:481
Filter output parameters.
Definition: Filter.h:109
boost::numeric::ublas::matrix< double > m_window
User defined convolution window. (The size must be equal to m_windowH x m_windowW) ...
Definition: Filter.h:87
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
virtual int getBandDataType(std::size_t i) const =0
Returns the data type in a particular band (or dimension).
The user will define the weights of a convolution window.
Definition: Filter.h:70
bool execute(AlgorithmOutputParameters &outputParams)
Executes the algorithm using the supplied parameters.
Definition: Filter.cpp:145
This file has the FilterWizardPage class.