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) 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/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()->setMinRasterBands(3);
102  m_layerSearchPage->getSearchWidget()->enableMultiSelection(false);
103 }
104 
106 {
107  return m_outputLayer;
108 }
109 
111 {
112  m_layerSearchPage.reset(new te::qt::widgets::LayerSearchWizardPage(this));
113  m_colorTransformPage.reset(new te::qt::widgets::ColorTransformWizardPage(this));
114  m_rasterInfoPage.reset(new te::qt::widgets::RasterInfoWizardPage(this));
115 
116  addPage(m_layerSearchPage.get());
117  addPage(m_colorTransformPage.get());
118  addPage(m_rasterInfoPage.get());
119 }
120 
122 {
123  //progress
126 
127  QApplication::setOverrideCursor(Qt::WaitCursor);
128 
129  try
130  {
131  bool res = false;
132 
133  if(m_colorTransformPage->isRGB2IHS())
134  res = executeRGB2IHS();
135  else if(m_colorTransformPage->isIHS2RGB())
136  res = executeIHS2RGB();
137 
138  if(res)
139  {
140  //set output layer
141  m_outputLayer = te::qt::widgets::createLayer(m_rasterInfoPage->getWidget()->getType(),
142  m_rasterInfoPage->getWidget()->getInfo());
143 
144  QMessageBox::information(this, tr("Color Transform"), tr("Color Transform ended sucessfully"));
145  }
146  else
147  {
148  QMessageBox::critical(this, tr("Color Transform"), tr("Color Transform execution error.") + ( " " + te::rp::Module::getLastLogStr() ).c_str());
149 
151 
152  QApplication::restoreOverrideCursor();
153 
154  return false;
155  }
156  }
157  catch(const std::exception& e)
158  {
159  QMessageBox::warning(this, tr("Color Transform"), e.what());
160 
162 
163  QApplication::restoreOverrideCursor();
164 
165  return false;
166  }
167  catch(...)
168  {
169  QMessageBox::warning(this, tr("Color Transform"), tr("An exception has occurred!"));
170 
172 
173  QApplication::restoreOverrideCursor();
174 
175  return false;
176  }
177 
179 
180  QApplication::restoreOverrideCursor();
181 
182  return true;
183 }
184 
186 {
187  te::rst::Raster* inputRaster = m_colorTransformPage->getRGBRaster();
188  te::rst::Raster* outputRaster = buildOutputRaster();
189 
190  if(!outputRaster)
191  return false;
192 
193  unsigned int rBand = m_colorTransformPage->getRGBRBand();
194  unsigned int gBand = m_colorTransformPage->getRGBGBand();
195  unsigned int bBand = m_colorTransformPage->getRGBBBand();
196 
197  double minValue = m_colorTransformPage->getRGBMinValue();
198  double maxValue = m_colorTransformPage->getRGBMaxValue();
199 
200  bool res = te::rp::ConvertRGB2IHS(*inputRaster, rBand, gBand, bBand, minValue, maxValue, *outputRaster);
201 
202  delete inputRaster;
203  delete outputRaster;
204 
205  return res;
206 }
207 
209 {
210  te::rst::Raster* inputRaster = m_colorTransformPage->getIHSRaster();
211  te::rst::Raster* outputRaster = buildOutputRaster();
212 
213  unsigned int rBand = m_colorTransformPage->getIHSIBand();
214  unsigned int gBand = m_colorTransformPage->getIHSHBand();
215  unsigned int bBand = m_colorTransformPage->getIHSSBand();
216 
217  double minValue = m_colorTransformPage->getIHSMinValue();
218  double maxValue = m_colorTransformPage->getIHSMaxValue();
219 
220  bool res = te::rp::ConvertIHS2RGB(*inputRaster, rBand, gBand, bBand, minValue, maxValue, *outputRaster);
221 
222  delete inputRaster;
223  delete outputRaster;
224 
225  return res;
226 }
227 
229 {
230  te::rst::Raster* rasterOut;
231 
232  //check output data type
233  int dataType = te::dt::UNKNOWN_TYPE;
234 
235  if(m_colorTransformPage->isRGB2IHS())
236  dataType = te::dt::FLOAT_TYPE;
237  else if(m_colorTransformPage->isIHS2RGB())
238  dataType = te::dt::UCHAR_TYPE;
239 
240  //get output raster info
241  std::string type = m_rasterInfoPage->getWidget()->getType();
242  std::map<std::string, std::string> info = m_rasterInfoPage->getWidget()->getInfo();
243 
244  //get input raster
245  te::rst::Raster* inputRaster;
246 
247  if(m_colorTransformPage->isRGB2IHS())
248  inputRaster = m_colorTransformPage->getRGBRaster();
249  else if(m_colorTransformPage->isIHS2RGB())
250  inputRaster = m_colorTransformPage->getIHSRaster();
251  else
252  return 0;
253 
254  //get input bands info
255  std::vector<te::rst::BandProperty*> bands;
256 
257  for(std::size_t t = 0; t < inputRaster->getNumberOfBands(); ++t)
258  {
259  te::rst::BandProperty* bProp = new te::rst::BandProperty(*inputRaster->getBand(t)->getProperty());
260 
261  bProp->m_type = dataType;
262 
263  bands.push_back(bProp);
264 
265  if(t >= 2)
266  break;
267  }
268 
269  //get input grid
270  te::rst::Grid* grid = new te::rst::Grid(*inputRaster->getGrid());
271 
272  //build output raster
273  rasterOut = te::rst::RasterFactory::make(type, grid, bands, info);
274 
275  return rasterOut;
276 }
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:873
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:745
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:428
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...