All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
ClassifierWizard.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2001-2009 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/ClassifierWizard.cpp
22 
23  \brief A Qt dialog that allows users to run a classifier 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/Classifier.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 "ClassifierWizard.h"
38 #include "ClassifierWizardPage.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("Classifier"));
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_classifier.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_classifierPage->set(l);
87  }
88 
89  return m_layerSearchPage->isComplete();
90  }
91  else if(currentPage() == m_classifierPage.get())
92  {
93  return m_classifierPage->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::ClassifierWizard::setList(std::list<te::map::AbstractLayerPtr>& layerList)
104 {
105  m_layerSearchPage->getSearchWidget()->setList(layerList);
106  m_layerSearchPage->getSearchWidget()->filterOnlyByRaster();
107 
108  m_classifierPage->setList(layerList);
109 }
110 
112 {
113  return m_outputLayer;
114 }
115 
117 {
118  m_layerSearchPage.reset(new te::qt::widgets::LayerSearchWizardPage(this));
119  m_classifierPage.reset(new te::qt::widgets::ClassifierWizardPage(this));
120  m_rasterInfoPage.reset(new te::qt::widgets::RasterInfoWizardPage(this));
121 
122  addPage(m_layerSearchPage.get());
123  addPage(m_classifierPage.get());
124  addPage(m_rasterInfoPage.get());
125 
126  //for contrast only one layer can be selected
127  m_layerSearchPage->getSearchWidget()->enableMultiSelection(false);
128 }
129 
131 {
132  //get layer
133  std::list<te::map::AbstractLayerPtr> list = m_layerSearchPage->getSearchWidget()->getSelecteds();
134  te::map::AbstractLayerPtr l = *list.begin();
135  std::auto_ptr<te::da::DataSet> ds = l->getData();
136 
137  std::size_t rpos = te::da::GetFirstPropertyPos(ds.get(), te::dt::RASTER_TYPE);
138 
139  std::auto_ptr<te::rst::Raster> inputRst = ds->getRaster(rpos);
140 
141  //run contrast
142  te::rp::Classifier algorithmInstance;
143 
144  te::rp::Classifier::InputParameters algoInputParams = m_classifierPage->getInputParams();
145  algoInputParams.m_inputRasterPtr = inputRst.get();
146 
147  te::rp::Classifier::OutputParameters algoOutputParams = m_classifierPage->getOutputParams();
148  algoOutputParams.m_rInfo = m_rasterInfoPage->getWidget()->getInfo();
149  algoOutputParams.m_rType = m_rasterInfoPage->getWidget()->getType();
150 
151  //progress
154 
155  QApplication::setOverrideCursor(Qt::WaitCursor);
156 
157  if(algorithmInstance.initialize(algoInputParams))
158  {
159  if(algorithmInstance.execute(algoOutputParams))
160  {
161  algoOutputParams.reset();
162 
163  //set output layer
164  m_outputLayer = te::qt::widgets::createLayer(m_rasterInfoPage->getWidget()->getType(),
165  m_rasterInfoPage->getWidget()->getInfo());
166 
167  QMessageBox::information(this, tr("Classifier"), tr("Classifier ended sucessfully"));
168  }
169  else
170  {
171  QMessageBox::critical(this, tr("Classifier"), tr("Classifier execution error.") +
172  ( " " + te::rp::Module::getLastLogStr() ).c_str());
173 
175 
176  QApplication::restoreOverrideCursor();
177 
178  return false;
179  }
180  }
181  else
182  {
183  QMessageBox::critical(this, tr("Classifier"), tr("Classifier initialization error.") +
184  ( " " + te::rp::Module::getLastLogStr() ).c_str() );
185 
187 
188  QApplication::restoreOverrideCursor();
189 
190  return false;
191  }
192 
194 
195  QApplication::restoreOverrideCursor();
196 
197  return true;
198 }
Raster classification.
Definition: Classifier.h:64
Utility functions for the data access module.
te::rst::Raster const * m_inputRasterPtr
Input raster.
Definition: Classifier.h:113
A Qt dialog that allows users to run a classifier operation defined by RP module. ...
bool execute(AlgorithmOutputParameters &outputParams)
Executes the algorithm using the supplied parameters.
Definition: Classifier.cpp:158
void setPageReference(const QString &ref)
Sets the documentation page reference.
te::map::AbstractLayerPtr getOutputLayer()
Classifier output parameters.
Definition: Classifier.h:127
This file defines a class for a Raster Info Wizard page.
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 file defines a class for a Classifier Wizard page.
This class is GUI used to define the raster info parameters for raster factory.
This class is GUI used to define the classifier parameters for the RP constast operation.
This file has the RasterInfoWidget class.
int addViewer(AbstractProgressViewer *apv)
Attach a progress viewer.
Push button that uses te::qt::widgets::HelpManager on its mouse pressed implementation.
void reset()
Clear all internal allocated resources and reset the parameters instance to its initial state...
Definition: Classifier.cpp:126
bool initialize(const AlgorithmInputParameters &inputParams)
Initialize the algorithm instance making it ready for execution.
Definition: Classifier.cpp:200
TEDATAACCESSEXPORT std::size_t GetFirstPropertyPos(const te::da::DataSet *dataset, int datatype)
Definition: Utils.cpp:432
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
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
Classifier input parameters.
Definition: Classifier.h:74
void setList(std::list< te::map::AbstractLayerPtr > &layerList)