All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator 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 "../../../dataaccess/dataset/DataSet.h"
28 #include "../../../dataaccess/utils/Utils.h"
29 #include "../../../raster/Raster.h"
30 #include "../../../rp/Classifier.h"
31 #include "../../../rp/Module.h"
32 #include "ClassifierWizard.h"
33 #include "ClassifierWizardPage.h"
34 #include "LayerSearchWidget.h"
35 #include "LayerSearchWizardPage.h"
36 #include "RasterInfoWidget.h"
37 #include "RasterInfoWizardPage.h"
38 #include "RasterNavigatorWidget.h"
40 
41 // STL
42 #include <cassert>
43 
44 // Qt
45 #include <QtGui/QMessageBox>
46 
47 
49  : QWizard(parent)
50 {
51  //configure the wizard
52  this->setWizardStyle(QWizard::ModernStyle);
53  this->setWindowTitle(tr("Classifier"));
54  //this->setFixedSize(640, 480);
55 
56  addPages();
57 }
58 
60 {
61 
62 }
63 
65 {
66  if(currentPage() == m_layerSearchPage.get())
67  {
68  std::list<te::map::AbstractLayerPtr> list = m_layerSearchPage->getSearchWidget()->getSelecteds();
69 
70  if(list.empty() == false)
71  {
72  te::map::AbstractLayerPtr l = *list.begin();
73 
74  m_classifierPage->set(l);
75  m_navigatorPage->set(l);
76  }
77 
78  return m_layerSearchPage->isComplete();
79  }
80  else if(currentPage() == m_classifierPage.get())
81  {
82  return m_classifierPage->isComplete();
83  }
84  else if(currentPage() == m_navigatorPage.get())
85  {
86  return m_navigatorPage->isComplete();
87  }
88  else if(currentPage() == m_rasterInfoPage.get())
89  {
90  return execute();
91  }
92 
93  return true;
94 }
95 
96 void te::qt::widgets::ClassifierWizard::setList(std::list<te::map::AbstractLayerPtr>& layerList)
97 {
98  m_layerSearchPage->getSearchWidget()->setList(layerList);
99 }
100 
102 {
103  m_layerSearchPage.reset(new te::qt::widgets::LayerSearchWizardPage(this));
104  m_classifierPage.reset(new te::qt::widgets::ClassifierWizardPage(this));
105  m_rasterInfoPage.reset(new te::qt::widgets::RasterInfoWizardPage(this));
106  m_navigatorPage.reset(new te::qt::widgets::RasterNavigatorWizardPage(this));
107 
108  addPage(m_layerSearchPage.get());
109  addPage(m_classifierPage.get());
110  addPage(m_navigatorPage.get());
111  addPage(m_rasterInfoPage.get());
112 
113  //for contrast only one layer can be selected
114  m_layerSearchPage->getSearchWidget()->enableMultiSelection(false);
115 
116  //configure raster navigator
117  m_navigatorPage->getWidget()->hidePickerTool(true);
118 
119  //connects
120  connect(m_navigatorPage->getWidget(), SIGNAL(mapDisplayExtentChanged()), m_classifierPage.get(), SLOT(onMapDisplayExtentChanged()));
121  connect(m_navigatorPage->getWidget(), SIGNAL(geomAquired(te::gm::Polygon*, te::qt::widgets::MapDisplay*)),
122  m_classifierPage.get(), SLOT(onGeomAquired(te::gm::Polygon*, te::qt::widgets::MapDisplay*)));
123 }
124 
126 {
127  //get layer
128  std::list<te::map::AbstractLayerPtr> list = m_layerSearchPage->getSearchWidget()->getSelecteds();
129  te::map::AbstractLayerPtr l = *list.begin();
130  std::auto_ptr<te::da::DataSet> ds = l->getData();
131 
132  std::size_t rpos = te::da::GetFirstPropertyPos(ds.get(), te::dt::RASTER_TYPE);
133 
134  std::auto_ptr<te::rst::Raster> inputRst = ds->getRaster(rpos);
135 
136  //run contrast
137  te::rp::Classifier algorithmInstance;
138 
139  te::rp::Classifier::InputParameters algoInputParams = m_classifierPage->getInputParams();
140  algoInputParams.m_inputRasterPtr = inputRst.get();
141 
142  te::rp::Classifier::OutputParameters algoOutputParams = m_classifierPage->getOutputParams();
143  algoOutputParams.m_rInfo = m_rasterInfoPage->getWidget()->getInfo();
144  algoOutputParams.m_rType = m_rasterInfoPage->getWidget()->getType();
145 
146 
147  if(algorithmInstance.initialize(algoInputParams))
148  {
149  if(algorithmInstance.execute(algoOutputParams))
150  {
151  algoOutputParams.reset();
152 
153  QMessageBox::information(this, tr("Classifier"), tr("Classifier ended sucessfully"));
154  }
155  else
156  {
157  QMessageBox::critical(this, tr("Classifier"), tr("Classifier execution error.") +
158  ( " " + te::rp::Module::getLastLogStr() ).c_str());
159  return false;
160  }
161  }
162  else
163  {
164  QMessageBox::critical(this, tr("Classifier"), tr("Classifier initialization error.") +
165  ( " " + te::rp::Module::getLastLogStr() ).c_str() );
166  return false;
167  }
168 
169  return true;
170 }
This file has the RasterNavigatorWidget class.
This class is a wizard page for the RasterNavigator widget.
std::string m_rType
Output raster data source type (as described in te::raster::RasterFactory ).
Definition: Classifier.h:154
Polygon is a subclass of CurvePolygon whose rings are defined by linear rings.
Definition: Polygon.h:50
static const std::string & getLastLogStr()
Returns the last log string generated by this module.
Definition: Module.h:53
void setList(std::list< te::map::AbstractLayerPtr > &layerList)
This file defines a class for a Raster Info Wizard page.
This file has the RasterInfoWidget class.
te::rst::Raster const * m_inputRasterPtr
Input raster.
Definition: Classifier.h:113
This file defines the LayerSearchWizardPage class.
bool execute(AlgorithmOutputParameters &outputParams)
Executes the algorithm using the supplied parameters.
Definition: Classifier.cpp:158
This file defines the LayerSearchWidget class.
Classifier output parameters.
Definition: Classifier.h:127
This file defines a class for a Raster Navigator Wizard page.
Raster classification.
Definition: Classifier.h:64
void reset()
Clear all internal allocated resources and reset the parameters instance to its initial state...
Definition: Classifier.cpp:126
TEDATAACCESSEXPORT std::size_t GetFirstPropertyPos(const te::da::DataSet *dataset, int datatype)
Definition: Utils.cpp:428
This class is GUI used to define the raster info parameters for raster factory.
A widget to control the display of a set of layers.
Definition: MapDisplay.h:65
This file defines a class for a Classifier Wizard page.
A Qt dialog that allows users to run a classifier operation defined by RP module. ...
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
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
Classifier input parameters.
Definition: Classifier.h:74
bool initialize(const AlgorithmInputParameters &inputParams)
Initialize the algorithm instance making it ready for execution.
Definition: Classifier.cpp:200
This class is GUI used to define the classifier parameters for the RP constast operation.