All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
ComposeBandsWizard.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/ComposeBandsWizard.cpp
22 
23  \brief A Qt dialog that allows users to compose or decompose bands.
24 */
25 
26 // TerraLib
27 #include "../../../common/StringUtils.h"
28 #include "../../../common/STLUtils.h"
29 #include "../../../common/progress/ProgressManager.h"
30 #include "../../../dataaccess/dataset/DataSet.h"
31 #include "../../../dataaccess/utils/Utils.h"
32 #include "../../../raster/Raster.h"
33 #include "../../../rp/FeedersRaster.h"
34 #include "../../../rp/Functions.h"
35 #include "../help/HelpPushButton.h"
36 #include "../layer/search/LayerSearchWidget.h"
37 #include "../layer/search/LayerSearchWizardPage.h"
38 #include "../progress/ProgressViewerDialog.h"
39 #include "ComposeBandsWizard.h"
40 #include "ComposeBandsWizardPage.h"
41 #include "RasterInfoWidget.h"
42 #include "RasterInfoWizardPage.h"
43 #include "Utils.h"
44 
45 // STL
46 #include <cassert>
47 
48 // Qt
49 #include <QMessageBox>
50 #include <QApplication>
51 
52 
54  : QWizard(parent)
55 {
56  //configure the wizard
57  this->setWizardStyle(QWizard::ModernStyle);
58  this->setWindowTitle(tr("Compose / Decompose Bands"));
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_compose_bands.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  m_composeBandsPage->setList(list);
84 
85  return m_layerSearchPage->isComplete();
86  }
87  else if(currentPage() == m_composeBandsPage.get())
88  {
89  return m_composeBandsPage->isComplete();
90  }
91  else if(currentPage() == m_rasterInfoPage.get())
92  {
93  return execute();
94  }
95 
96  return true;
97 }
98 
99 void te::qt::widgets::ComposeBandsWizard::setList(std::list<te::map::AbstractLayerPtr>& layerList)
100 {
101  m_layerSearchPage->getSearchWidget()->setList(layerList);
102  m_layerSearchPage->getSearchWidget()->filterOnlyByRaster();
103 }
104 
105 std::list<te::map::AbstractLayerPtr> te::qt::widgets::ComposeBandsWizard::getOutputLayers()
106 {
107  return m_outputLayerList;
108 }
109 
111 {
112  m_layerSearchPage.reset(new te::qt::widgets::LayerSearchWizardPage(this));
113  m_composeBandsPage.reset(new te::qt::widgets::ComposeBandsWizardPage(this));
114  m_rasterInfoPage.reset(new te::qt::widgets::RasterInfoWizardPage(this));
115 
116  addPage(m_layerSearchPage.get());
117  addPage(m_composeBandsPage.get());
118  addPage(m_rasterInfoPage.get());
119 
120  //for contrast only one layer can be selected
121  m_layerSearchPage->setSubTitle(tr("Allows selection of layers using filters for selection. Select one layer for DECOMPOSITION or multi layers for COMPOSITION."));
122  m_layerSearchPage->getSearchWidget()->enableMultiSelection(true);
123 }
124 
126 {
127  if(m_composeBandsPage->isCompose())
128  return executeCompose();
129 
130  if(m_composeBandsPage->isDecompose())
131  return executeDecompose();
132 
133  return false;
134 }
135 
137 {
138  //get output parameters
139  std::map<std::string, std::string> rinfo = m_rasterInfoPage->getWidget()->getInfo();
140  std::string type = m_rasterInfoPage->getWidget()->getType();
141 
142  //get input parameters
143  std::vector<const te::rst::Raster*> inputRasters;
144  std::vector<unsigned int> inputRasterBands;
145  te::rst::Interpolator::Method interpMethod;
146 
147  m_composeBandsPage->getComposeParameters(inputRasters, inputRasterBands, interpMethod);
148 
149  //set feeder
150  te::rp::FeederConstRasterVector feeder(inputRasters);
151 
152  //execute
153  std::auto_ptr<te::rst::Raster> outputRaster;
154 
155  QApplication::setOverrideCursor(Qt::WaitCursor);
156 
157  bool res = false;
158 
159  try
160  {
161  res = te::rp::ComposeBands(feeder, inputRasterBands, interpMethod, rinfo, type, outputRaster);
162  }
163  catch(const std::exception& e)
164  {
165  QMessageBox::warning(this, tr("Compose"), e.what());
166 
167  QApplication::restoreOverrideCursor();
168 
169  te::common::FreeContents(inputRasters);
170 
171  return false;
172  }
173  catch(...)
174  {
175  QMessageBox::warning(this, tr("Compose"), tr("An exception has occurred!"));
176 
177  QApplication::restoreOverrideCursor();
178 
179  te::common::FreeContents(inputRasters);
180 
181  return false;
182  }
183 
184  QApplication::restoreOverrideCursor();
185 
186  //create layer
187  if(res)
188  {
189  outputRaster.reset();
190 
192 
193  m_outputLayerList.push_back(layer);
194  }
195 
196  //clear vector
197  te::common::FreeContents(inputRasters);
198 
199  return res;
200 }
201 
203 {
204  //get output parameters
205  std::string outputDataSetNamePath = m_rasterInfoPage->getWidget()->getPath();
206  std::string outputDataSetNamePrefix = m_rasterInfoPage->getWidget()->getShortName();
207  std::string outputDataSetNameExt = m_rasterInfoPage->getWidget()->getExtension();
208  std::string type = m_rasterInfoPage->getWidget()->getType();
209  std::vector< std::map<std::string, std::string> > outputRastersInfos;
210 
211  //get input parameters
212  te::rst::Raster* inputRaster;
213  std::vector<unsigned int> inputRasterBands;
214 
215  m_composeBandsPage->getDecomposeParameters(inputRaster, inputRasterBands);
216 
217  //set output names
218  std::vector<std::string> outputDataSetNames;
219 
220  for(std::size_t t = 0; t < inputRasterBands.size(); ++t)
221  {
222  std::string name = outputDataSetNamePrefix;
223  name += "_";
224  name += te::common::Convert2String(inputRasterBands[t]);
225  name += outputDataSetNameExt;
226 
227  outputDataSetNames.push_back(name);
228 
229  outputRastersInfos.push_back(m_rasterInfoPage->getWidget()->getInfo((int)t));
230  }
231 
232  std::vector< boost::shared_ptr< te::rst::Raster > > outputRastersPtrs;
233 
234  //execute
235  bool res = false;
236 
237  try
238  {
239  res = te::rp::DecomposeBands(*inputRaster, inputRasterBands, outputRastersInfos, type, outputRastersPtrs);
240  }
241  catch(const std::exception& e)
242  {
243  QMessageBox::warning(this, tr("Decompose"), e.what());
244 
245  QApplication::restoreOverrideCursor();
246 
247  outputRastersPtrs.clear();
248 
249  return false;
250  }
251  catch(...)
252  {
253  QMessageBox::warning(this, tr("Decompose"), tr("An exception has occurred!"));
254 
255  QApplication::restoreOverrideCursor();
256 
257  outputRastersPtrs.clear();
258 
259  return false;
260  }
261 
262  QApplication::restoreOverrideCursor();
263 
264  //create layer
265  if(res)
266  {
267  outputRastersPtrs.clear();
268 
269  std::string type = m_rasterInfoPage->getWidget()->getType();
270 
271  for(std::size_t t = 0; t < outputDataSetNames.size(); ++t)
272  {
273  std::map<std::string, std::string> rinfo;
274  rinfo["URI"] = outputDataSetNamePath + outputDataSetNames[t];
275 
277 
278  m_outputLayerList.push_back(layer);
279  }
280  }
281 
282  return res;
283 }
Utility functions for the data access module.
A feeder from a input rasters vector;.
Definition: FeedersRaster.h:69
void setPageReference(const QString &ref)
Sets the documentation page reference.
bool ComposeBands(te::rp::FeederConstRaster &feeder, const std::vector< unsigned int > &inputRasterBands, const te::rst::Interpolator::Method &interpMethod, const std::map< std::string, std::string > &outputRasterInfo, const std::string &outputDataSourceType, std::auto_ptr< te::rst::Raster > &outputRasterPtr)
Compose a set of bands into one multi-band raster.
Definition: Functions.cpp:2128
bool DecomposeBands(const te::rst::Raster &inputRaster, const std::vector< unsigned int > &inputRasterBands, const std::vector< std::map< std::string, std::string > > &outputRastersInfos, const std::string &outputDataSourceType, std::vector< boost::shared_ptr< te::rst::Raster > > &outputRastersPtrs)
Decompose a multi-band raster into a set of one-band rasters.
Definition: Functions.cpp:2062
InterpolationMethod
Allowed interpolation methods.
Definition: Enums.h:92
This file defines a class for a Raster Info Wizard page.
A Qt dialog that allows users to compose or decompose bands.
This class is GUI used to defines a class for a Compose / Decompose Bands Wizard page.
An abstract class for raster data strucutures.
Definition: Raster.h:71
This class is GUI used to define the raster info parameters for raster factory.
void setList(std::list< te::map::AbstractLayerPtr > &layerList)
This file has the RasterInfoWidget class.
Push button that uses te::qt::widgets::HelpManager on its mouse pressed implementation.
This file defines a class for a Compose / Decompose Bands Wizard page.
std::string Convert2String(boost::int16_t value)
It converts a short integer value to a string.
Definition: StringUtils.h:51
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
void FreeContents(boost::unordered_map< K, V * > &m)
This function can be applied to a map of pointers. It will delete each pointer in the map...
Definition: BoostUtils.h:55
TEQTWIDGETSEXPORT te::map::AbstractLayerPtr createLayer(const std::string &driverName, const std::map< std::string, std::string > &connInfo)
Definition: Utils.cpp:40
std::list< te::map::AbstractLayerPtr > getOutputLayers()