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) 2011-2012 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 QIntValidator(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_typeComboBox, SIGNAL(activated(int)), SLOT(onFilterTypeComboBoxActivated(int)));
74  connect(m_ui->m_maskToolButton, SIGNAL(clicked()), SLOT(onMaskToolButtonClicked()));
75  connect(m_ui->m_loadMaskToolButton, SIGNAL(clicked()), SLOT(onLoadMaskToolButtonClicked()));
76  connect(m_navigator.get(), SIGNAL(previewClicked()), this, SLOT(apply()));
77 
79 }
80 
82 {
83 }
84 
86 {
87  return true;
88 }
89 
91 {
92  m_layer = layer;
93 
94  m_navigator->set(m_layer, true);
95 
96  m_navigator->getDisplay()->refresh();
97 
98  listBands();
99 }
100 
102 {
103  int idx = m_ui->m_typeComboBox->currentIndex();
104 
105  te::rp::Filter::InputParameters algoInputParams;
106  algoInputParams.m_iterationsNumber = m_ui->m_iterationsSpinBox->value();
107  algoInputParams.m_enableProgress = true;
108  algoInputParams.m_filterType = (te::rp::Filter::InputParameters::FilterType)m_ui->m_typeComboBox->itemData(idx).toInt();
109 
111  {
112  algoInputParams.m_windowH = m_window.size1();
113  algoInputParams.m_windowW = m_window.size2();
114  algoInputParams.m_window = m_window;
115  }
116 
117  int nBands = m_ui->m_listWidget->count();
118  for(int i = 0; i < nBands; ++i)
119  {
120  if(m_ui->m_listWidget->item(i)->isSelected())
121  algoInputParams.m_inRasterBands.push_back(i);
122  }
123 
124  return algoInputParams;
125 }
126 
128 {
129  te::rp::Filter::OutputParameters algoOutputParams;
130 
131  return algoOutputParams;
132 }
133 
135 {
136  int filterType = m_ui->m_typeComboBox->itemData(index).toInt();
137 
138  bool flag = filterType == te::rp::Filter::InputParameters::UserDefinedWindowT;
139 
140  m_ui->m_maskSizeSpinBox->setEnabled(flag);
141  m_ui->m_maskToolButton->setEnabled(flag);
142  m_ui->m_maskDefaultValueLineEdit->setEnabled(flag);
143 }
144 
146 {
147  te::qt::widgets::MaskDialog dlg(this);
148 
149  dlg.setMaskSize(m_ui->m_maskSizeSpinBox->value(),
150  m_ui->m_maskDefaultValueLineEdit->text().isEmpty() ? 0 : m_ui->m_maskDefaultValueLineEdit->text().toInt());
151 
152  if(dlg.exec() == QDialog::Accepted)
153  {
154  m_window = dlg.getMatrix();
155 
156  m_ui->m_loadMaskToolButton->setEnabled(true);
157  }
158 }
159 
161 {
162  te::qt::widgets::MaskDialog dlg(this);
163 
164  dlg.setMaskSize(m_window);
165 
166  m_ui->m_maskSizeSpinBox->setValue(m_window.size1());
167 
168  if(dlg.exec() == QDialog::Accepted)
169  {
170  m_window = dlg.getMatrix();
171  }
172 }
173 
175 {
176  QApplication::setOverrideCursor(Qt::WaitCursor);
177 
178  //get preview raster
179  te::rst::Raster* inputRst = m_navigator->getExtentRaster(true);
180 
181  //set segmenters parameters
182  te::rp::Filter::InputParameters algoInputParams = getInputParams();
183 
184  algoInputParams.m_inRasterPtr = inputRst;
185 
186  te::rp::Filter::OutputParameters algoOutputParams;
187 
188  std::map<std::string, std::string> rinfo;
189  rinfo["MEM_RASTER_NROWS"] = boost::lexical_cast<std::string>(inputRst->getNumberOfRows());
190  rinfo["MEM_RASTER_NCOLS"] = boost::lexical_cast<std::string>(inputRst->getNumberOfColumns());
191  rinfo["MEM_RASTER_DATATYPE"] = boost::lexical_cast<std::string>(inputRst->getBandDataType(0));
192  rinfo["MEM_RASTER_NBANDS"] = boost::lexical_cast<std::string>(inputRst->getNumberOfBands());
193 
194  algoOutputParams.m_rType = "MEM";
195  algoOutputParams.m_rInfo = rinfo;
196 
197  //run contrast
198  te::rp::Filter algorithmInstance;
199 
200  try
201  {
202  if(algorithmInstance.initialize(algoInputParams))
203  {
204  if(algorithmInstance.execute(algoOutputParams))
205  {
206  std::auto_ptr<te::rst::Raster> rst = algoOutputParams.m_outputRasterPtr;
207 
208  m_navigator->drawRaster(rst.get());
209  }
210  }
211  }
212  catch(...)
213  {
214  QMessageBox::warning(this, tr("Warning"), tr("Filter error."));
215  }
216 
217  QApplication::restoreOverrideCursor();
218 
219  //delete input raster dataset
220  delete inputRst;
221 }
222 
224 {
225  m_ui->m_listWidget->clear();
226 
227  //get input raster
228  std::auto_ptr<te::da::DataSet> ds = m_layer->getData();
229 
230  if(ds.get())
231  {
232  std::size_t rpos = te::da::GetFirstPropertyPos(ds.get(), te::dt::RASTER_TYPE);
233 
234  std::auto_ptr<te::rst::Raster> inputRst = ds->getRaster(rpos);
235 
236  if(inputRst.get())
237  {
238  for(unsigned int i = 0; i < inputRst->getNumberOfBands(); ++i)
239  {
240  m_ui->m_listWidget->addItem(QString::number(i));
241  }
242  }
243  }
244 }
245 
247 {
248  m_ui->m_typeComboBox->clear();
249 
250  m_ui->m_typeComboBox->addItem(tr("Sobel"), te::rp::Filter::InputParameters::SobelFilterT);
251  m_ui->m_typeComboBox->addItem(tr("Roberts"), te::rp::Filter::InputParameters::RobertsFilterT);
252  m_ui->m_typeComboBox->addItem(tr("Mean"), te::rp::Filter::InputParameters::MeanFilterT);
253  m_ui->m_typeComboBox->addItem(tr("Mode"), te::rp::Filter::InputParameters::ModeFilterT);
254  m_ui->m_typeComboBox->addItem(tr("Median"), te::rp::Filter::InputParameters::MedianFilterT);
255  m_ui->m_typeComboBox->addItem(tr("Dilation"), te::rp::Filter::InputParameters::DilationFilterT);
256  m_ui->m_typeComboBox->addItem(tr("Erosion"), te::rp::Filter::InputParameters::ErosionFilterT);
257  m_ui->m_typeComboBox->addItem(tr("User Defined"), te::rp::Filter::InputParameters::UserDefinedWindowT);
258 
259  onFilterTypeComboBoxActivated(0);
260 }
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
void setMaskSize(int size, int defaultValue)
Definition: MaskDialog.cpp:52
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
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:432
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.