All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
MixtureModelWizard.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/MixtureModelWizard.cpp
22 
23  \brief A Qt dialog that allows users to run a mixture model 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/MixtureModel.h"
31 #include "../../../rp/Module.h"
32 #include "../help/HelpPushButton.h"
33 #include "../layer/search/LayerSearchWidget.h"
34 #include "../layer/search/LayerSearchWizardPage.h"
35 #include "MixtureModelWizard.h"
36 #include "MixtureModelWizardPage.h"
37 #include "RasterInfoWidget.h"
38 #include "RasterInfoWizardPage.h"
39 #include "Utils.h"
40 
41 // STL
42 #include <cassert>
43 
44 // Qt
45 #include <QApplication>
46 #include <QMessageBox>
47 
48 //STL
49 #include <memory>
50 
51 
53  : QWizard(parent)
54 {
55  //configure the wizard
56  this->setWizardStyle(QWizard::ModernStyle);
57  this->setWindowTitle(tr("Mixture Model"));
58  //this->setFixedSize(640, 480);
59 
60  this->setOption(QWizard::HaveHelpButton, true);
61  this->setOption(QWizard::HelpButtonOnRight, false);
62 
64 
65  this->setButton(QWizard::HelpButton, helpButton);
66 
67  helpButton->setPageReference("plugins/rp/rp_mixture.html");
68 
69  addPages();
70 }
71 
73 {
74 
75 }
76 
78 {
79  if(currentPage() == m_layerSearchPage.get())
80  {
81  std::list<te::map::AbstractLayerPtr> list = m_layerSearchPage->getSearchWidget()->getSelecteds();
82 
83  if(list.empty() == false)
84  {
85  te::map::AbstractLayerPtr l = *list.begin();
86 
87  m_mixtureModelPage->set(l);
88  }
89 
90  return m_layerSearchPage->isComplete();
91  }
92  else if(currentPage() == m_mixtureModelPage.get())
93  {
94  return m_mixtureModelPage->isComplete();
95  }
96  else if(currentPage() == m_rasterInfoPage.get())
97  {
98  return execute();
99  }
100 
101  return true;
102 }
103 
105 {
106  return m_outputLayer;
107 }
108 
109 void te::qt::widgets::MixtureModelWizard::setList(std::list<te::map::AbstractLayerPtr>& layerList)
110 {
111  m_layerSearchPage->getSearchWidget()->setList(layerList);
112  m_layerSearchPage->getSearchWidget()->filterOnlyByRaster();
113 }
114 
116 {
117  removePage(m_layerSearchId);
118 
119  m_mixtureModelPage->set(layer);
120 }
121 
123 {
124  m_layerSearchPage.reset(new te::qt::widgets::LayerSearchWizardPage(this));
125  m_mixtureModelPage.reset(new te::qt::widgets::MixtureModelWizardPage(this));
126  m_rasterInfoPage.reset(new te::qt::widgets::RasterInfoWizardPage(this));
127 
128  m_layerSearchId = addPage(m_layerSearchPage.get());
129  addPage(m_mixtureModelPage.get());
130  addPage(m_rasterInfoPage.get());
131 
132  //for contrast only one layer can be selected
133  m_layerSearchPage->getSearchWidget()->enableMultiSelection(false);
134 }
135 
137 {
138  if(m_rasterInfoPage->getWidget()->fileExists())
139  {
140  QMessageBox::warning(this, tr("Mixture Model"), tr("File already exists."));
141  return false;
142  }
143 
144  //get layer
145  te::map::AbstractLayerPtr l = m_mixtureModelPage->get();
146  std::auto_ptr<te::da::DataSet> ds(l->getData());
147  std::size_t rpos = te::da::GetFirstPropertyPos(ds.get(), te::dt::RASTER_TYPE);
148  std::auto_ptr<te::rst::Raster> inputRst = ds->getRaster(rpos);
149 
150  //run contrast
151  te::rp::MixtureModel algorithmInstance;
152 
153  te::rp::MixtureModel::InputParameters algoInputParams = m_mixtureModelPage->getInputParams();
154 
155  if( algoInputParams.m_inputRasterBands.size() != algoInputParams.m_components.size() )
156  {
157  QMessageBox::critical(this, tr("Mixture Model"), tr("The number of components must be the same as the number of selected bands"));
158  return false;
159  }
160 
161  algoInputParams.m_inputRasterPtr = inputRst.get();
162 
163  te::rp::MixtureModel::OutputParameters algoOutputParams = m_mixtureModelPage->getOutputParams();
164  algoOutputParams.m_rInfo = m_rasterInfoPage->getWidget()->getInfo();
165  algoOutputParams.m_rType = m_rasterInfoPage->getWidget()->getType();
166 
167  QApplication::setOverrideCursor(Qt::WaitCursor);
168 
169  if(algorithmInstance.initialize(algoInputParams))
170  {
171  if(algorithmInstance.execute(algoOutputParams))
172  {
173  algoOutputParams.reset();
174 
175  //set output layer
176  m_outputLayer = te::qt::widgets::createLayer(m_rasterInfoPage->getWidget()->getType(),
177  m_rasterInfoPage->getWidget()->getInfo());
178  QMessageBox::information(this, tr("Mixture Model"), tr("Mixture Model ended sucessfully"));
179  }
180  else
181  {
182  QMessageBox::critical(this, tr("Mixture Model"), tr("Mixture Model execution error.") +
183  ( " " + te::rp::Module::getLastLogStr() ).c_str() );
184 
185  QApplication::restoreOverrideCursor();
186 
187  return false;
188  }
189  }
190  else
191  {
192  QMessageBox::critical(this, tr("Mixture Model"), tr( "Mixture Model initialization error." ) +
193  ( " " + te::rp::Module::getLastLogStr() ).c_str() );
194 
195  QApplication::restoreOverrideCursor();
196 
197  return false;
198  }
199 
200  QApplication::restoreOverrideCursor();
201 
202  return true;
203 }
204 
void reset()
Clear all internal allocated resources and reset the parameters instance to its initial state...
Utility functions for the data access module.
This file defines a class for a MixtureModel Wizard page.
Raster decomposition using mixture model.
Definition: MixtureModel.h:59
std::string m_rType
Output raster data source type (as described in te::raster::RasterFactory ).
Definition: MixtureModel.h:150
void setPageReference(const QString &ref)
Sets the documentation page reference.
void setList(std::list< te::map::AbstractLayerPtr > &layerList)
This file defines a class for a Raster Info Wizard page.
This class is GUI used to define the mixture model parameters for the RP constast operation...
A Qt dialog that allows users to run a mixture model operation defined by RP module.
void setLayer(te::map::AbstractLayerPtr layer)
std::map< std::string, std::string > m_rInfo
The necessary information to create the raster (as described in te::raster::RasterFactory).
Definition: MixtureModel.h:151
MixtureModel input parameters.
Definition: MixtureModel.h:69
static const std::string & getLastLogStr()
Returns the last log string generated by this module.
Definition: Module.h:53
This class is GUI used to define the raster info parameters for raster factory.
This file has the RasterInfoWidget class.
te::map::AbstractLayerPtr getOutputLayer()
std::map< std::string, std::vector< double > > m_components
A set of endmembers and its radiances.
Definition: MixtureModel.h:111
MixtureModel output parameters.
Definition: MixtureModel.h:123
Push button that uses te::qt::widgets::HelpManager on its mouse pressed implementation.
bool execute(AlgorithmOutputParameters &outputParams)
Executes the algorithm using the supplied parameters.
te::rst::Raster const * m_inputRasterPtr
Input raster.
Definition: MixtureModel.h:108
TEDATAACCESSEXPORT std::size_t GetFirstPropertyPos(const te::da::DataSet *dataset, int datatype)
Definition: Utils.cpp:481
bool initialize(const AlgorithmInputParameters &inputParams)
Initialize the algorithm instance making it ready for execution.
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
std::vector< unsigned int > m_inputRasterBands
Bands to be processed from the input raster.
Definition: MixtureModel.h:109