All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
FilterWizard.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/FilterWizard.cpp
22 
23  \brief A Qt dialog that allows users to run a filter operation defined by RP module.
24 */
25 
26 // TerraLib
27 #include "../../../common/progress/ProgressManager.h"
28 #include "../../../dataaccess/dataset/DataSet.h"
29 #include "../../../dataaccess/utils/Utils.h"
30 #include "../../../raster/Raster.h"
31 #include "../../../rp/Filter.h"
32 #include "../../../rp/Module.h"
33 #include "../help/HelpPushButton.h"
34 #include "../layer/search/LayerSearchWidget.h"
35 #include "../layer/search/LayerSearchWizardPage.h"
36 #include "../progress/ProgressViewerDialog.h"
37 #include "FilterWizard.h"
38 #include "FilterWizardPage.h"
39 #include "RasterInfoWidget.h"
40 #include "RasterInfoWizardPage.h"
41 #include "Utils.h"
42 
43 // STL
44 #include <cassert>
45 
46 // Qt
47 #include <QMessageBox>
48 #include <QApplication>
49 
50 
52  : QWizard(parent)
53 {
54  //configure the wizard
55  this->setWizardStyle(QWizard::ModernStyle);
56  this->setWindowTitle(tr("Filter"));
57  //this->setFixedSize(640, 480);
58 
59  this->setOption(QWizard::HaveHelpButton, true);
60  this->setOption(QWizard::HelpButtonOnRight, false);
61 
63 
64  this->setButton(QWizard::HelpButton, helpButton);
65 
66  helpButton->setPageReference("plugins/rp/rp_filter.html");
67 
68  addPages();
69 }
70 
72 {
73 
74 }
75 
77 {
78  if(currentPage() == m_layerSearchPage.get())
79  {
80  std::list<te::map::AbstractLayerPtr> list = m_layerSearchPage->getSearchWidget()->getSelecteds();
81 
82  if(list.empty() == false)
83  {
84  te::map::AbstractLayerPtr l = *list.begin();
85 
86  m_filterPage->set(l);
87  }
88 
89  return m_layerSearchPage->isComplete();
90  }
91  else if(currentPage() == m_filterPage.get())
92  {
93  return m_filterPage->isComplete();
94  }
95  else if(currentPage() == m_rasterInfoPage.get())
96  {
97  return execute();
98  }
99 
100  return true;
101 }
102 
103 void te::qt::widgets::FilterWizard::setList(std::list<te::map::AbstractLayerPtr>& layerList)
104 {
105  m_layerSearchPage->getSearchWidget()->setList(layerList);
106  m_layerSearchPage->getSearchWidget()->filterOnlyByRaster();
107 }
108 
110 {
111  return m_outputLayer;
112 }
113 
115 {
116  m_layerSearchPage.reset(new te::qt::widgets::LayerSearchWizardPage(this));
117  m_filterPage.reset(new te::qt::widgets::FilterWizardPage(this));
118  m_rasterInfoPage.reset(new te::qt::widgets::RasterInfoWizardPage(this));
119 
120  addPage(m_layerSearchPage.get());
121  addPage(m_filterPage.get());
122  addPage(m_rasterInfoPage.get());
123 
124  //for contrast only one layer can be selected
125  m_layerSearchPage->getSearchWidget()->enableMultiSelection(false);
126 }
127 
129 {
130  //get layer
131  std::list<te::map::AbstractLayerPtr> list = m_layerSearchPage->getSearchWidget()->getSelecteds();
132  te::map::AbstractLayerPtr l = *list.begin();
133  std::auto_ptr<te::da::DataSet> ds = l->getData();
134 
135  std::size_t rpos = te::da::GetFirstPropertyPos(ds.get(), te::dt::RASTER_TYPE);
136 
137  std::auto_ptr<te::rst::Raster> inputRst = ds->getRaster(rpos);
138 
139  //run contrast
140  te::rp::Filter algorithmInstance;
141 
142  te::rp::Filter::InputParameters algoInputParams = m_filterPage->getInputParams();
143  algoInputParams.m_inRasterPtr = inputRst.get();
144 
145  te::rp::Filter::OutputParameters algoOutputParams = m_filterPage->getOutputParams();
146  algoOutputParams.m_rInfo = m_rasterInfoPage->getWidget()->getInfo();
147  algoOutputParams.m_rType = m_rasterInfoPage->getWidget()->getType();
148 
149  //progress
152 
153  QApplication::setOverrideCursor(Qt::WaitCursor);
154 
155  if(algorithmInstance.initialize(algoInputParams))
156  {
157  if(algorithmInstance.execute(algoOutputParams))
158  {
159  algoOutputParams.reset();
160 
161  //set output layer
162  m_outputLayer = te::qt::widgets::createLayer(m_rasterInfoPage->getWidget()->getType(),
163  m_rasterInfoPage->getWidget()->getInfo());
164 
165  QMessageBox::information(this, tr("Filter"), tr("Filter ended sucessfully"));
166  }
167  else
168  {
169  QMessageBox::critical(this, tr("Filter"), tr("Filter execution error.") +
170  ( " " + te::rp::Module::getLastLogStr() ).c_str());
171 
173 
174  QApplication::restoreOverrideCursor();
175 
176  return false;
177  }
178  }
179  else
180  {
181  QMessageBox::critical(this, tr("Filter"), tr("Filter initialization error.") +
182  ( " " + te::rp::Module::getLastLogStr() ).c_str() );
183 
185 
186  QApplication::restoreOverrideCursor();
187 
188  return false;
189  }
190 
192 
193  QApplication::restoreOverrideCursor();
194 
195  return true;
196 }
Utility functions for the data access module.
void setPageReference(const QString &ref)
Sets the documentation page reference.
std::string m_rType
Output raster data source type (as described in te::raster::RasterFactory ).
Definition: Filter.h:113
This file defines a class for a Raster Info Wizard page.
A Qt dialog that allows users to run a filter operation defined by RP module.
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
static const std::string & getLastLogStr()
Returns the last log string generated by this module.
Definition: Module.h:53
void removeViewer(int viewerId)
Dettach a progress viewer.
static ProgressManager & getInstance()
It returns a reference to the singleton instance.
This class is GUI used to define the raster info parameters for raster factory.
This file has the RasterInfoWidget class.
A series of well-known filtering algorithms for images, linear and non-linear..
Definition: Filter.h:47
te::map::AbstractLayerPtr getOutputLayer()
Filter input parameters.
Definition: Filter.h:55
int addViewer(AbstractProgressViewer *apv)
Attach a progress viewer.
Push button that uses te::qt::widgets::HelpManager on its mouse pressed implementation.
bool initialize(const AlgorithmInputParameters &inputParams)
Initialize the algorithm instance making it ready for execution.
Definition: Filter.cpp:365
te::rst::Raster const * m_inRasterPtr
Input raster.
Definition: Filter.h:75
void reset()
Clear all internal allocated resources and reset the parameters instance to its initial state...
Definition: Filter.cpp:113
TEDATAACCESSEXPORT std::size_t GetFirstPropertyPos(const te::da::DataSet *dataset, int datatype)
Definition: Utils.cpp:481
void setList(std::list< te::map::AbstractLayerPtr > &layerList)
Filter output parameters.
Definition: Filter.h:109
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
TEQTWIDGETSEXPORT te::map::AbstractLayerPtr createLayer(const std::string &driverName, const std::map< std::string, std::string > &connInfo)
Definition: Utils.cpp:40
bool execute(AlgorithmOutputParameters &outputParams)
Executes the algorithm using the supplied parameters.
Definition: Filter.cpp:145
virtual bool validateCurrentPage()
This file has the FilterWizardPage class.