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) 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/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 "../../../dataaccess/dataset/DataSet.h"
28 #include "../../../dataaccess/utils/Utils.h"
29 #include "../../../raster/Raster.h"
30 #include "../../../rp/Contrast.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 "ContrastWizard.h"
36 #include "ContrastWizardPage.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 
50  : QWizard(parent)
51 {
52  //configure the wizard
53  this->setWizardStyle(QWizard::ModernStyle);
54  this->setWindowTitle(tr("Contrast"));
55  //this->setFixedSize(640, 480);
56 
57  this->setOption(QWizard::HaveHelpButton, true);
58  this->setOption(QWizard::HelpButtonOnRight, false);
59 
61 
62  this->setButton(QWizard::HelpButton, helpButton);
63 
64  helpButton->setPageReference("plugins/rp/rp_contrast.html");
65 
66  addPages();
67 }
68 
70 {
71 
72 }
73 
75 {
76  if(currentPage() == m_layerSearchPage.get())
77  {
78  std::list<te::map::AbstractLayerPtr> list = m_layerSearchPage->getSearchWidget()->getSelecteds();
79 
80  if(list.empty() == false)
81  {
82  te::map::AbstractLayerPtr l = *list.begin();
83 
84  m_contrastPage->set(l);
85  }
86 
87  return m_layerSearchPage->isComplete();
88  }
89  else if(currentPage() == m_contrastPage.get())
90  {
91  bool res = m_contrastPage->isComplete();
92 
93  if(!res)
94  QMessageBox::warning(this, tr("Warning"), tr("Select at least one band."));
95 
96  return res;
97  }
98  else if(currentPage() == m_rasterInfoPage.get())
99  {
100  return execute();
101  }
102 
103  return true;
104 }
105 
106 void te::qt::widgets::ContrastWizard::setList(std::list<te::map::AbstractLayerPtr>& layerList)
107 {
108  m_layerSearchPage->getSearchWidget()->setList(layerList);
109  m_layerSearchPage->getSearchWidget()->filterOnlyByRaster();
110 }
111 
113 {
114  removePage(m_layerSearchId);
115 
116  m_contrastPage->set(layer);
117 }
118 
120 {
121  return m_outputLayer;
122 }
123 
125 {
126  m_layerSearchPage.reset(new te::qt::widgets::LayerSearchWizardPage(this));
127  m_contrastPage.reset(new te::qt::widgets::ContrastWizardPage(this));
128  m_rasterInfoPage.reset(new te::qt::widgets::RasterInfoWizardPage(this));
129 
130  m_layerSearchId = addPage(m_layerSearchPage.get());
131  addPage(m_contrastPage.get());
132  addPage(m_rasterInfoPage.get());
133 
134  //for contrast only one layer can be selected
135  m_layerSearchPage->getSearchWidget()->enableMultiSelection(false);
136 }
137 
139 {
140  if(m_rasterInfoPage->getWidget()->fileExists())
141  {
142  QMessageBox::warning(this, tr("Contrast"), tr("File already exists."));
143  return false;
144  }
145 
146  //get layer
147  te::map::AbstractLayerPtr l = m_contrastPage->get();
148  std::auto_ptr<te::da::DataSet> ds = l->getData();
149 
150  std::size_t rpos = te::da::GetFirstPropertyPos(ds.get(), te::dt::RASTER_TYPE);
151 
152  std::auto_ptr<te::rst::Raster> inputRst = ds->getRaster(rpos);
153 
154  //run contrast
155  te::rp::Contrast algorithmInstance;
156 
157  te::rp::Contrast::InputParameters algoInputParams = m_contrastPage->getInputParams();
158  algoInputParams.m_inRasterPtr = inputRst.get();
159  algoInputParams.m_enableProgress = true;
160 
161  te::rp::Contrast::OutputParameters algoOutputParams;
162  algoOutputParams.m_createdOutRasterDSType = m_rasterInfoPage->getWidget()->getType();
163  algoOutputParams.m_createdOutRasterInfo = m_rasterInfoPage->getWidget()->getInfo();
164  algoOutputParams.m_outRasterBands = algoInputParams.m_inRasterBands;
165 
166  QApplication::setOverrideCursor(Qt::WaitCursor);
167 
168  if(algorithmInstance.initialize(algoInputParams))
169  {
170  if(algorithmInstance.execute(algoOutputParams))
171  {
172  algoOutputParams.reset();
173 
174  //set output layer
175  m_outputLayer = te::qt::widgets::createLayer(m_rasterInfoPage->getWidget()->getType(),
176  m_rasterInfoPage->getWidget()->getInfo());
177 
178  QMessageBox::information(this, tr("Contrast"), tr("Contrast enhencement ended sucessfully"));
179  }
180  else
181  {
182  QMessageBox::critical(this, tr("Contrast"), tr("Contrast enhencement 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("Contrast"), tr("Contrast enhencement 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 }
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:64
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.
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:126
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.
void reset()
Clear all internal allocated resources and reset the parameters instance to its initial state...
Definition: Contrast.cpp:114
bool initialize(const AlgorithmInputParameters &inputParams)
Initialize the algorithm instance making it ready for execution.
Definition: Contrast.cpp:251
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:150
std::string m_createdOutRasterDSType
Output raster data source type (as described in te::raster::RasterFactory ), leave empty if the resul...
Definition: Contrast.h:128
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:432
Contrast output parameters.
Definition: Contrast.h:118
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:130
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:56