All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
ContrastWizard.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/ContrastWizard.cpp
22 
23  \brief A Qt dialog that allows users to run a contrast 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/Contrast.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 "ContrastWizard.h"
38 #include "ContrastWizardPage.h"
39 #include "RasterInfoWidget.h"
40 #include "RasterInfoWizardPage.h"
41 #include "Utils.h"
42 
43 // STL
44 #include <cassert>
45 
46 // Qt
47 #include <QApplication>
48 #include <QMessageBox>
49 
50 
52  : QWizard(parent)
53 {
54  //configure the wizard
55  this->setWizardStyle(QWizard::ModernStyle);
56  this->setWindowTitle(tr("Contrast"));
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_contrast.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_contrastPage->set(l);
87  }
88 
89  return m_layerSearchPage->isComplete();
90  }
91  else if(currentPage() == m_contrastPage.get())
92  {
93  bool res = m_contrastPage->isComplete();
94 
95  if(!res)
96  QMessageBox::warning(this, tr("Warning"), tr("Select at least one band."));
97 
98  return res;
99  }
100  else if(currentPage() == m_rasterInfoPage.get())
101  {
102  return execute();
103  }
104 
105  return true;
106 }
107 
108 void te::qt::widgets::ContrastWizard::setList(std::list<te::map::AbstractLayerPtr>& layerList)
109 {
110  m_layerSearchPage->getSearchWidget()->setList(layerList);
111  m_layerSearchPage->getSearchWidget()->filterOnlyByRaster();
112 }
113 
115 {
116  removePage(m_layerSearchId);
117 
118  m_contrastPage->set(layer);
119 }
120 
122 {
123  return m_outputLayer;
124 }
125 
127 {
128  m_layerSearchPage.reset(new te::qt::widgets::LayerSearchWizardPage(this));
129  m_contrastPage.reset(new te::qt::widgets::ContrastWizardPage(this));
130  m_rasterInfoPage.reset(new te::qt::widgets::RasterInfoWizardPage(this));
131 
132  m_layerSearchId = addPage(m_layerSearchPage.get());
133  addPage(m_contrastPage.get());
134  addPage(m_rasterInfoPage.get());
135 
136  //for contrast only one layer can be selected
137  m_layerSearchPage->getSearchWidget()->enableMultiSelection(false);
138 }
139 
141 {
142  if(m_rasterInfoPage->getWidget()->fileExists())
143  {
144  QMessageBox::warning(this, tr("Contrast"), tr("File already exists."));
145  return false;
146  }
147 
148  //get layer
149  te::map::AbstractLayerPtr l = m_contrastPage->get();
150  std::auto_ptr<te::da::DataSet> ds = l->getData();
151 
152  std::size_t rpos = te::da::GetFirstPropertyPos(ds.get(), te::dt::RASTER_TYPE);
153 
154  std::auto_ptr<te::rst::Raster> inputRst = ds->getRaster(rpos);
155 
156  //run contrast
157  te::rp::Contrast algorithmInstance;
158 
159  te::rp::Contrast::InputParameters algoInputParams = m_contrastPage->getInputParams();
160  algoInputParams.m_inRasterPtr = inputRst.get();
161  algoInputParams.m_enableProgress = true;
162 
163  te::rp::Contrast::OutputParameters algoOutputParams;
164  algoOutputParams.m_createdOutRasterDSType = m_rasterInfoPage->getWidget()->getType();
165  algoOutputParams.m_createdOutRasterInfo = m_rasterInfoPage->getWidget()->getInfo();
166  algoOutputParams.m_outRasterBands = algoInputParams.m_inRasterBands;
167 
168  //progress
171 
172  QApplication::setOverrideCursor(Qt::WaitCursor);
173 
174  try
175  {
176  if(algorithmInstance.initialize(algoInputParams))
177  {
178  if(algorithmInstance.execute(algoOutputParams))
179  {
180  algoOutputParams.reset();
181 
182  //set output layer
183  m_outputLayer = te::qt::widgets::createLayer(m_rasterInfoPage->getWidget()->getType(),
184  m_rasterInfoPage->getWidget()->getInfo());
185 
186  QMessageBox::information(this, tr("Contrast"), tr("Contrast enhencement ended sucessfully"));
187  }
188  else
189  {
190  QMessageBox::critical(this, tr("Contrast"), tr("Contrast enhencement execution error.") +
191  ( " " + te::rp::Module::getLastLogStr() ).c_str());
192 
193  QApplication::restoreOverrideCursor();
194 
195  return false;
196  }
197  }
198  else
199  {
200  QMessageBox::critical(this, tr("Contrast"), tr("Contrast enhencement initialization error.") +
201  ( " " + te::rp::Module::getLastLogStr() ).c_str() );
202 
203  QApplication::restoreOverrideCursor();
204 
205  return false;
206  }
207  }
208  catch(const std::exception& e)
209  {
210  QMessageBox::warning(this, tr("Contrast"), e.what());
211 
213 
214  QApplication::restoreOverrideCursor();
215 
216  return false;
217  }
218  catch(...)
219  {
220  QMessageBox::warning(this, tr("Contrast"), tr("An exception has occurred!"));
221 
223 
224  QApplication::restoreOverrideCursor();
225 
226  return false;
227  }
228 
230 
231  QApplication::restoreOverrideCursor();
232 
233  return true;
234 }
te::map::AbstractLayerPtr getOutputLayer()
Utility functions for the data access module.
void setLayer(te::map::AbstractLayerPtr layer)
void setPageReference(const QString &ref)
Sets the documentation page reference.
This file defines a class for a Raster Info Wizard page.
void setList(std::list< te::map::AbstractLayerPtr > &layerList)
Contrast input parameters.
Definition: Contrast.h:65
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 contrast parameters for the RP constast operation.
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.
std::vector< unsigned int > m_outRasterBands
Bands to be processed from the output raster.
Definition: Contrast.h:192
std::vector< unsigned int > m_inRasterBands
Bands to be processed from the input raster.
Definition: Contrast.h:91
This file has the RasterInfoWidget class.
bool m_enableProgress
Enable/Disable the progress interface (default:false).
Definition: Contrast.h:93
A Qt dialog that allows users to run a contrast operation defined by RP module.
This file defines a class for a Contrast Wizard page.
int addViewer(AbstractProgressViewer *apv)
Attach a progress viewer.
void reset()
Clear all internal allocated resources and reset the parameters instance to its initial state...
Definition: Contrast.cpp:142
bool initialize(const AlgorithmInputParameters &inputParams)
Initialize the algorithm instance making it ready for execution.
Definition: Contrast.cpp:299
Push button that uses te::qt::widgets::HelpManager on its mouse pressed implementation.
bool execute(AlgorithmOutputParameters &outputParams)
Executes the algorithm using the supplied parameters.
Definition: Contrast.cpp:178
std::string m_createdOutRasterDSType
Output raster data source type (as described in te::raster::RasterFactory ), leave empty if the resul...
Definition: Contrast.h:194
te::rst::Raster const * m_inRasterPtr
Input raster.
Definition: Contrast.h:89
TEDATAACCESSEXPORT std::size_t GetFirstPropertyPos(const te::da::DataSet *dataset, int datatype)
Definition: Utils.cpp:481
Contrast output parameters.
Definition: Contrast.h:184
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
std::map< std::string, std::string > m_createdOutRasterInfo
The necessary information to create the raster (as described in te::raster::RasterFactory), leave empty if the result must be written to the raster pointed m_outRasterPtr.
Definition: Contrast.h:196
TEQTWIDGETSEXPORT te::map::AbstractLayerPtr createLayer(const std::string &driverName, const std::map< std::string, std::string > &connInfo)
Definition: Utils.cpp:40
Contrast enhancement.
Definition: Contrast.h:57