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) 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/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 "../../../se/Categorize.h"
34 #include "../../../se/ColorMap.h"
35 #include "../../../se/ParameterValue.h"
36 #include "../../../se/RasterSymbolizer.h"
37 #include "../../../se/Utils.h"
38 #include "../help/HelpPushButton.h"
39 #include "../layer/search/LayerSearchWidget.h"
40 #include "../layer/search/LayerSearchWizardPage.h"
41 #include "../progress/ProgressViewerDialog.h"
42 #include "ClassifierWizard.h"
43 #include "ClassifierWizardPage.h"
44 #include "RasterInfoWidget.h"
45 #include "RasterInfoWizardPage.h"
46 #include "Utils.h"
47 
48 // STL
49 #include <cassert>
50 
51 // Qt
52 #include <QMessageBox>
53 #include <QApplication>
54 
55 
57  : QWizard(parent)
58 {
59  //configure the wizard
60  this->setWizardStyle(QWizard::ModernStyle);
61  this->setWindowTitle(tr("Classifier"));
62  //this->setFixedSize(640, 480);
63 
64  this->setOption(QWizard::HaveHelpButton, true);
65  this->setOption(QWizard::HelpButtonOnRight, false);
66 
68 
69  this->setButton(QWizard::HelpButton, helpButton);
70 
71  helpButton->setPageReference("plugins/rp/rp_classifier.html");
72 
73  addPages();
74 }
75 
77 {
78 
79 }
80 
82 {
83  if(currentPage() == m_layerSearchPage.get())
84  {
85  std::list<te::map::AbstractLayerPtr> list = m_layerSearchPage->getSearchWidget()->getSelecteds();
86 
87  if(list.empty() == false)
88  {
89  te::map::AbstractLayerPtr l = *list.begin();
90 
91  m_classifierPage->set(l);
92  }
93 
94  return m_layerSearchPage->isComplete();
95  }
96  else if(currentPage() == m_classifierPage.get())
97  {
98  return m_classifierPage->isComplete();
99  }
100  else if(currentPage() == m_rasterInfoPage.get())
101  {
102  return execute();
103  }
104 
105  return true;
106 }
107 
108 void te::qt::widgets::ClassifierWizard::setList(std::list<te::map::AbstractLayerPtr>& layerList)
109 {
110  m_layerSearchPage->getSearchWidget()->setList(layerList);
111  m_layerSearchPage->getSearchWidget()->filterOnlyByRaster();
112 
113  m_classifierPage->setList(layerList);
114 }
115 
117 {
118  return m_outputLayer;
119 }
120 
122 {
123  m_layerSearchPage.reset(new te::qt::widgets::LayerSearchWizardPage(this));
124  m_classifierPage.reset(new te::qt::widgets::ClassifierWizardPage(this));
125  m_rasterInfoPage.reset(new te::qt::widgets::RasterInfoWizardPage(this));
126 
127  addPage(m_layerSearchPage.get());
128  addPage(m_classifierPage.get());
129  addPage(m_rasterInfoPage.get());
130 
131  //for contrast only one layer can be selected
132  m_layerSearchPage->getSearchWidget()->enableMultiSelection(false);
133 }
134 
136 {
137  //get layer
138  std::list<te::map::AbstractLayerPtr> list = m_layerSearchPage->getSearchWidget()->getSelecteds();
139  te::map::AbstractLayerPtr l = *list.begin();
140  std::auto_ptr<te::da::DataSet> ds = l->getData();
141 
142  std::size_t rpos = te::da::GetFirstPropertyPos(ds.get(), te::dt::RASTER_TYPE);
143 
144  std::auto_ptr<te::rst::Raster> inputRst = ds->getRaster(rpos);
145 
146  //run contrast
147  te::rp::Classifier algorithmInstance;
148 
149  te::rp::Classifier::InputParameters algoInputParams = m_classifierPage->getInputParams();
150  algoInputParams.m_inputRasterPtr = inputRst.get();
151 
152  te::rp::Classifier::OutputParameters algoOutputParams = m_classifierPage->getOutputParams();
153  algoOutputParams.m_rInfo = m_rasterInfoPage->getWidget()->getInfo();
154  algoOutputParams.m_rType = m_rasterInfoPage->getWidget()->getType();
155 
156  //progress
159 
160  QApplication::setOverrideCursor(Qt::WaitCursor);
161 
162  if(algorithmInstance.initialize(algoInputParams))
163  {
164  if(algorithmInstance.execute(algoOutputParams))
165  {
166  algoOutputParams.reset();
167 
168  //set output layer
169  m_outputLayer = te::qt::widgets::createLayer(m_rasterInfoPage->getWidget()->getType(),
170  m_rasterInfoPage->getWidget()->getInfo());
171 
172  QMessageBox::information(this, tr("Classifier"), tr("Classifier ended sucessfully"));
173  }
174  else
175  {
176  QMessageBox::critical(this, tr("Classifier"), tr("Classifier execution error.") +
177  ( " " + te::rp::Module::getLastLogStr() ).c_str());
178 
180 
181  QApplication::restoreOverrideCursor();
182 
183  return false;
184  }
185  }
186  else
187  {
188  QMessageBox::critical(this, tr("Classifier"), tr("Classifier initialization error.") +
189  ( " " + te::rp::Module::getLastLogStr() ).c_str() );
190 
192 
193  QApplication::restoreOverrideCursor();
194 
195  return false;
196  }
197 
198  //create legend
199  te::cl::ROISet* rs = m_classifierPage->getROISet();
200 
201  if(rs && rs->getROISet().empty() == false)
202  {
204 
206 
207  c->setFallbackValue("#000000");
208  c->setLookupValue(new te::se::ParameterValue("Rasterdata"));
209 
210  QColor cWhite(Qt::white);
211  std::string colorWhiteStr = cWhite.name().toLatin1().data();
212 
213  //added dummy color for values < than min values...
214  c->addValue(new te::se::ParameterValue(colorWhiteStr));
215 
216  std::map<std::string, te::cl::ROI*> roiSetMap = rs->getROISet();
217  std::map<std::string, te::cl::ROI*>::iterator it = roiSetMap.begin();
218 
219  int count = 1;
220 
221  while(it != roiSetMap.end())
222  {
223  std::string color = it->second->getColor();
224  std::string range = QString::number(count).toStdString();
225 
226 
227  c->addThreshold(new te::se::ParameterValue(range));
228  c->addValue(new te::se::ParameterValue(color));
229 
230  if(count == roiSetMap.size())
231  {
232  std::string rangeNext = QString::number(count + 1).toStdString();
233  c->addThreshold(new te::se::ParameterValue(rangeNext));
234  }
235 
236  ++count;
237  ++it;
238  }
239 
240  //added dummy color for values > than max values...
241  c->addValue(new te::se::ParameterValue(colorWhiteStr));
242 
244  cm->setCategorize(c);
245 
246  te::se::RasterSymbolizer* rasterSymb = te::se::GetRasterSymbolizer(m_outputLayer->getStyle());
247  rasterSymb->setColorMap(cm);
248  }
249 
251 
252  QApplication::restoreOverrideCursor();
253 
254  return true;
255 }
Raster classification.
Definition: Classifier.h:64
Utility functions for the data access module.
The transformation of continuous values to distinct values (Categorize function). ...
Definition: Categorize.h:90
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.
TESEEXPORT RasterSymbolizer * GetRasterSymbolizer(Style *s)
Try to get raster symbolizer from a style.
Definition: Utils.cpp:371
te::map::AbstractLayerPtr getOutputLayer()
void setLookupValue(ParameterValue *v)
Definition: Categorize.cpp:81
void setCategorize(Categorize *c)
Definition: ColorMap.cpp:58
Classifier output parameters.
Definition: Classifier.h:127
The "ParameterValueType" uses WFS-Filter expressions to give values for SE graphic parameters...
A ROISet is a set of ROI's.
Definition: ROISet.h:53
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.
The RasterSymbolizer describes how to render raster/matrix-coverage data (e.g., satellite photos...
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
void setColorMap(ColorMap *c)
TEDATAACCESSEXPORT std::size_t GetFirstPropertyPos(const te::da::DataSet *dataset, int datatype)
Definition: Utils.cpp:481
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
void setThresholdsBelongTo(ThresholdsBelongToType t)
Definition: Categorize.cpp:104
TEQTWIDGETSEXPORT te::map::AbstractLayerPtr createLayer(const std::string &driverName, const std::map< std::string, std::string > &connInfo)
Definition: Utils.cpp:40
void addThreshold(ParameterValue *v)
Definition: Categorize.cpp:94
A ColorMap defines either the colors of a pallette-type raster source or the mapping of numeric pixel...
Definition: ColorMap.h:60
void addValue(ParameterValue *v)
Definition: Categorize.cpp:99
std::map< std::string, te::cl::ROI * > & getROISet()
Get the roi set map.
Definition: ROISet.cpp:79
Classifier input parameters.
Definition: Classifier.h:74
void setFallbackValue(const std::string &v)
Definition: Function.cpp:37
void setList(std::list< te::map::AbstractLayerPtr > &layerList)