All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
ColorTransformWizard.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/ColorTransformWizard.cpp
22 
23  \brief A Qt dialog that allows users to run a colorTransform operation defined by RP module.
24 */
25 
26 // TerraLib
27 #include "../../../common/progress/ProgressManager.h"
28 #include "../../../common/STLUtils.h"
29 #include "../../../dataaccess/dataset/DataSet.h"
30 #include "../../../dataaccess/utils/Utils.h"
31 #include "../../../raster/RasterFactory.h"
32 #include "../../../rp/Functions.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 "ColorTransformWizard.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 
51  : QWizard(parent)
52 {
53  //configure the wizard
54  this->setWizardStyle(QWizard::ModernStyle);
55  this->setWindowTitle(tr("Color Transform"));
56  //this->setFixedSize(640, 480);
57 
58  this->setOption(QWizard::HaveHelpButton, true);
59  this->setOption(QWizard::HelpButtonOnRight, false);
60 
62 
63  this->setButton(QWizard::HelpButton, helpButton);
64 
65  helpButton->setPageReference("plugins/rp/rp_colorTransform.html");
66 
67  addPages();
68 }
69 
71 {
72 
73 }
74 
76 {
77  if(currentPage() == m_layerSearchPage.get())
78  {
79  std::list<te::map::AbstractLayerPtr> list = m_layerSearchPage->getSearchWidget()->getSelecteds();
80 
81  m_colorTransformPage->setList(list);
82 
83  return m_layerSearchPage->isComplete();
84  }
85  else if(currentPage() == m_colorTransformPage.get())
86  {
87  return m_colorTransformPage->isComplete();
88  }
89  else if(currentPage() == m_rasterInfoPage.get())
90  {
91  return execute();
92  }
93 
94  return true;
95 }
96 
97 void te::qt::widgets::ColorTransformWizard::setList(std::list<te::map::AbstractLayerPtr>& layerList)
98 {
99  m_layerSearchPage->getSearchWidget()->setList(layerList);
100  m_layerSearchPage->getSearchWidget()->filterOnlyByRaster();
101  m_layerSearchPage->getSearchWidget()->enableMultiSelection(false);
102 }
103 
105 {
106  return m_outputLayer;
107 }
108 
110 {
111  m_layerSearchPage.reset(new te::qt::widgets::LayerSearchWizardPage(this));
112  m_colorTransformPage.reset(new te::qt::widgets::ColorTransformWizardPage(this));
113  m_rasterInfoPage.reset(new te::qt::widgets::RasterInfoWizardPage(this));
114 
115  addPage(m_layerSearchPage.get());
116  addPage(m_colorTransformPage.get());
117  addPage(m_rasterInfoPage.get());
118 }
119 
121 {
122  //progress
125 
126  QApplication::setOverrideCursor(Qt::WaitCursor);
127 
128  try
129  {
130  bool res = false;
131 
132  if(m_colorTransformPage->isRGB2IHS())
133  res = executeRGB2IHS();
134  else if(m_colorTransformPage->isIHS2RGB())
135  res = executeIHS2RGB();
136 
137  if(res)
138  {
139  //set output layer
140  m_outputLayer = te::qt::widgets::createLayer(m_rasterInfoPage->getWidget()->getType(),
141  m_rasterInfoPage->getWidget()->getInfo());
142 
143  QMessageBox::information(this, tr("Color Transform"), tr("Color Transform ended sucessfully"));
144  }
145  else
146  {
147  QMessageBox::critical(this, tr("Color Transform"), tr("Color Transform execution error.") + ( " " + te::rp::Module::getLastLogStr() ).c_str());
148 
150 
151  QApplication::restoreOverrideCursor();
152 
153  return false;
154  }
155  }
156  catch(const std::exception& e)
157  {
158  QMessageBox::warning(this, tr("Color Transform"), e.what());
159 
161 
162  QApplication::restoreOverrideCursor();
163 
164  return false;
165  }
166  catch(...)
167  {
168  QMessageBox::warning(this, tr("Color Transform"), tr("An exception has occurred!"));
169 
171 
172  QApplication::restoreOverrideCursor();
173 
174  return false;
175  }
176 
178 
179  QApplication::restoreOverrideCursor();
180 
181  return true;
182 }
183 
185 {
186  te::rst::Raster* inputRaster = m_colorTransformPage->getRGBRaster();
187  te::rst::Raster* outputRaster = buildOutputRaster();
188 
189  unsigned int rBand = m_colorTransformPage->getRGBRBand();
190  unsigned int gBand = m_colorTransformPage->getRGBGBand();
191  unsigned int bBand = m_colorTransformPage->getRGBBBand();
192 
193  double minValue = m_colorTransformPage->getRGBMinValue();
194  double maxValue = m_colorTransformPage->getRGBMaxValue();
195 
196  bool res = te::rp::ConvertRGB2IHS(*inputRaster, rBand, gBand, bBand, minValue, maxValue, *outputRaster);
197 
198  delete inputRaster;
199  delete outputRaster;
200 
201  return res;
202 }
203 
205 {
206  te::rst::Raster* inputRaster = m_colorTransformPage->getIHSRaster();
207  te::rst::Raster* outputRaster = buildOutputRaster();
208 
209  unsigned int rBand = m_colorTransformPage->getIHSIBand();
210  unsigned int gBand = m_colorTransformPage->getIHSHBand();
211  unsigned int bBand = m_colorTransformPage->getIHSSBand();
212 
213  double minValue = m_colorTransformPage->getIHSMinValue();
214  double maxValue = m_colorTransformPage->getIHSMaxValue();
215 
216  bool res = te::rp::ConvertIHS2RGB(*inputRaster, rBand, gBand, bBand, minValue, maxValue, *outputRaster);
217 
218  delete inputRaster;
219  delete outputRaster;
220 
221  return res;
222 }
223 
225 {
226  te::rst::Raster* rasterOut;
227 
228  //check output data type
229  int dataType = te::dt::UNKNOWN_TYPE;
230 
231  if(m_colorTransformPage->isRGB2IHS())
232  dataType = te::dt::FLOAT_TYPE;
233  else if(m_colorTransformPage->isIHS2RGB())
234  dataType = te::dt::UCHAR_TYPE;
235 
236  //get output raster info
237  std::string type = m_rasterInfoPage->getWidget()->getType();
238  std::map<std::string, std::string> info = m_rasterInfoPage->getWidget()->getInfo();
239 
240  //get input raster
241  te::rst::Raster* inputRaster;
242 
243  if(m_colorTransformPage->isRGB2IHS())
244  inputRaster = m_colorTransformPage->getRGBRaster();
245  else if(m_colorTransformPage->isIHS2RGB())
246  inputRaster = m_colorTransformPage->getIHSRaster();
247 
248  //get input bands info
249  std::vector<te::rst::BandProperty*> bands;
250 
251  for(std::size_t t = 0; t < inputRaster->getNumberOfBands(); ++t)
252  {
253  te::rst::BandProperty* bProp = new te::rst::BandProperty(*inputRaster->getBand(t)->getProperty());
254 
255  bProp->m_type = dataType;
256 
257  bands.push_back(bProp);
258 
259  if(t >= 2)
260  break;
261  }
262 
263  //get input grid
264  te::rst::Grid* grid = new te::rst::Grid(*inputRaster->getGrid());
265 
266  //build output raster
267  rasterOut = te::rst::RasterFactory::make(type, grid, bands, info);
268 
269  return rasterOut;
270 }
Utility functions for the data access module.
A raster band description.
Definition: BandProperty.h:61
virtual const Band * getBand(std::size_t i) const =0
Returns the raster i-th band.
void setPageReference(const QString &ref)
Sets the documentation page reference.
bool ConvertIHS2RGB(const te::rst::Raster &inputIHSRaster, const unsigned int intensityBandIdx, const unsigned int hueBandIdx, const unsigned int saturationBandIdx, const double rgbRangeMin, const double rgbRangeMax, te::rst::Raster &outputRGBRaster)
IHS to RGB conversion.
Definition: Functions.cpp:893
te::map::AbstractLayerPtr getOutputLayer()
int m_type
The data type of the elements in the band.
Definition: BandProperty.h:133
This file defines a class for a ColorTransform Wizard page.
This file defines a class for a Raster Info Wizard page.
bool ConvertRGB2IHS(const te::rst::Raster &inputRGBRaster, const unsigned int redBandIdx, const unsigned int greenBandIdx, const unsigned int blueBandIdx, const double rgbRangeMin, const double rgbRangeMax, te::rst::Raster &outputIHSRaster)
RGB to IHS conversion.
Definition: Functions.cpp:765
A Qt dialog that allows users to run a colorTransform operation defined by RP module.
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.
An abstract class for raster data strucutures.
Definition: Raster.h:71
void setList(std::list< te::map::AbstractLayerPtr > &layerList)
This class is GUI used to define the raster info parameters for raster factory.
BandProperty * getProperty()
Returns the band property.
Definition: Band.cpp:370
virtual std::size_t getNumberOfBands() const =0
Returns the number of bands (dimension of cells attribute values) in the raster.
This file has the RasterInfoWidget class.
Grid * getGrid()
It returns the raster grid.
Definition: Raster.cpp:94
int addViewer(AbstractProgressViewer *apv)
Attach a progress viewer.
Push button that uses te::qt::widgets::HelpManager on its mouse pressed implementation.
static Raster * make()
It creates and returns an empty raster with default raster driver.
A rectified grid is the spatial support for raster data.
Definition: Grid.h:68
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
This class is GUI used to define the colorTransform parameters for the RP colorTransform operation...