RasterSlicingWizard.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 #include "RasterSlicingWizard.h"
21 
22 //Terralib
23 #include "../../../common/progress/ProgressManager.h"
24 #include "../../../dataaccess/datasource/DataSourceManager.h"
25 #include "../../../dataaccess/utils/Utils.h"
26 #include "../../../rp/Functions.h"
27 #include "../../../maptools/Utils.h"
28 #include "../../../se/Categorize.h"
29 #include "../../../se/ColorMap.h"
30 #include "../../../se/ParameterValue.h"
31 #include "../../../se/RasterSymbolizer.h"
32 #include "../../../se/SelectedChannel.h"
33 #include "../../../se/Utils.h"
34 #include "../help/HelpPushButton.h"
35 #include "../layer/search/LayerSearchWidget.h"
36 #include "../layer/search/LayerSearchWizardPage.h"
37 #include "../progress/ProgressViewerDialog.h"
38 #include "../utils/ScopedCursor.h"
40 #include "RasterInfoWizardPage.h"
41 #include "../raster/RasterInfoWidget.h"
42 #include "Utils.h"
43 
44 // Qt
45 #include <QApplication>
46 #include <QMessageBox>
47 
49 QWizard(parent)
50 {
51  this->setWizardStyle(QWizard::ModernStyle);
52  this->setWindowTitle(tr("Raster Slicing"));
53 
54  this->setOption(QWizard::HaveHelpButton, true);
55  this->setOption(QWizard::HelpButtonOnRight, false);
56 
58 
59  this->setButton(QWizard::HelpButton, helpButton);
60 
61  helpButton->setPageReference("plugins/rp/rp_rasterslicing.html");
62 
63  connect(this, SIGNAL(currentIdChanged(int)), SLOT(onPageChanged(int)));
64 
65  addPages();
66 }
67 
69 {
70  m_wizardPage->clearCanvas();
71 }
72 
74 {
75  if(currentPage() == m_layerSearchPage.get())
76  {
77  te::qt::widgets::ScopedCursor cursor(Qt::WaitCursor);
78  std::list<te::map::AbstractLayerPtr> list = m_layerSearchPage->getSearchWidget()->getSelecteds();
79 
80  if(list.empty() == false)
81  {
82  te::map::AbstractLayerPtr layerPtr = *list.begin();
83 
84  if( layerPtr.get() != nullptr )
85  m_wizardPage->setLayer(layerPtr);
86  }
87 
88  return m_layerSearchPage->isComplete();
89  }
90  else if(currentPage() == m_wizardPage.get())
91  {
92  return m_wizardPage->isComplete();
93  }
94  else if(currentPage() == m_rasterInfoPage.get())
95  {
96  return execute();
97  }
98 
99  return true;
100 }
101 
102 void te::qt::widgets::RasterSlicingWizard::setList(std::list<te::map::AbstractLayerPtr> &layerList)
103 {
104  m_layerSearchPage->getSearchWidget()->setList(layerList);
105  m_layerSearchPage->getSearchWidget()->filterOnlyByRaster();
106 }
107 
109 {
110  return m_outputLayer;
111 }
112 
114 {
115  m_wizardPage->setExtent(extent);
116 }
117 
119 {
120  m_wizardPage->setSRID(srid);
121 }
122 
124 {
125  m_wizardPage->setMapDisplay(mapDisplay);
126 }
127 
129 {
130  m_wizardPage->setActionGroup(actionGroup);
131 }
132 
134 {
135  m_wizardPage->applyPreview();
136 }
137 
139 {
140  m_layerSearchPage.reset(new LayerSearchWizardPage(this));
141  m_layerSearchPage->getSearchWidget()->enableMultiSelection(false);
142  addPage(m_layerSearchPage.get());
143 
144  m_wizardPage.reset(new RasterSlicingWizardPage(this));
145  addPage(m_wizardPage.get());
146 
148  addPage(m_rasterInfoPage.get());
149 
150  this->resize(m_wizardPage->sizeHint());
151 }
152 
154 {
155  if(m_rasterInfoPage->getWidget()->fileExists())
156  {
157  QMessageBox::warning(this, tr("Raster Slicing"), tr("File already exists."));
158  return false;
159  }
160 
161  //get layer
162  std::list<te::map::AbstractLayerPtr> list = m_layerSearchPage->getSearchWidget()->getSelecteds();
163  te::map::AbstractLayerPtr l = *list.begin();
164 
165  std::unique_ptr<te::rst::Raster> inputRst;
166 
167  unsigned int inputRasterBand = 0;
168  bool eqHistogram = false;
169  m_wizardPage->getParameters( inputRasterBand, eqHistogram );
170 
171  //progress
173 
174  // Execute slicing
175  QApplication::setOverrideCursor(Qt::WaitCursor);
176  std::unique_ptr< te::rst::Raster > outRasterPtr;
177 
178  bool trimRaster = m_wizardPage->trimRaster();
179 
180  if(trimRaster)
181  {
182  std::unique_ptr<te::rst::Raster> tempRaster(te::map::GetRaster(l.get()));
183 
184  std::map<std::string, std::string> rinfo = tempRaster->getInfo();
185  rinfo["FORCE_MEM_DRIVER"] = "TRUE";
186 
187  inputRst.reset(tempRaster->trim(&m_wizardPage->getExtent(), rinfo));
188  }
189  else
190  {
191  inputRst.reset(te::map::GetRaster(l.get()));
192  }
193 
194  //Creating the color palette
195  te::se::ColorMap* colorMap = m_wizardPage->getColorMap();
196 
197  std::vector<te::se::ParameterValue*> values = colorMap->getCategorize()->getThresholds();
198  std::map<double, double> slice_limits;
199  for (size_t i = 0; i < values.size(); ++i)
200  {
201  std::string limits = te::se::GetString(values[i]);
202  size_t pos = limits.find(" ");
203  double min = std::stod(limits.substr(0, pos));
204  double max = std::stod(limits.substr(pos));
205  slice_limits.insert(std::pair< double, double >(min, max));
206  }
207 
208  std::vector<te::se::ParameterValue*> colors = colorMap->getCategorize()->getThresholdValues();
209 
210  std::vector< te::rst::BandProperty::ColorEntry > palette;
211 
212  for(size_t i = 0; i < colors.size(); ++i)
213  {
214  //Acquiring each color and inserting it in the palette
215  std::string colorName = te::se::GetString(colors[i]);
216  te::color::RGBAColor rgbac(colorName);
217 
219  color.c1 = rgbac.getRed();
220  color.c2 = rgbac.getGreen();
221  color.c3 = rgbac.getBlue();
222  color.c4 = rgbac.getAlpha();
223  palette.push_back(color);
224  }
225 
226  if( te::rp::RasterSlicing( *inputRst, inputRasterBand, true,
227  static_cast<int>(palette.size()), eqHistogram, m_rasterInfoPage->getWidget()->getInfo(),
228  m_rasterInfoPage->getWidget()->getType(), true, &palette, outRasterPtr, slice_limits) )
229  {
230  outRasterPtr.reset();
231 
232  //set output layer
234  m_rasterInfoPage->getWidget()->getInfo());
235 
236  QApplication::restoreOverrideCursor();
237  QMessageBox::information(this, tr("Raster slicing"), tr("Raster slicing ended sucessfully"));
238  }
239  else
240  {
241  QApplication::restoreOverrideCursor();
242 
243  QMessageBox::critical(this, tr("Raster slicing"), tr("Raster slicing execution error.") +
244  ( " " + te::rp::Module::getLastLogStr() ).c_str());
245 
246  return false;
247  }
248 
250 
251  emit addLayer(m_outputLayer);
252 
253  return true;
254 }
255 
257 {
258  this->adjustSize();
259 }
int getRed() const
It returns the red component color value (a value from 0 to 255).
Definition: RGBAColor.h:307
void setPageReference(const QString &ref)
Sets the documentation page reference.
bool RasterSlicing(const te::rst::Raster &inputRaster, const unsigned int inputRasterBand, const bool createPaletteRaster, const unsigned int slicesNumber, const bool eqHistogram, const std::map< std::string, std::string > &rasterInfo, const std::string &rasterType, const bool enableProgress, std::vector< te::rst::BandProperty::ColorEntry > const *const palettePtr, std::unique_ptr< te::rst::Raster > &outRasterPtr, std::map< double, double > limits)
Generate all wavelet planes from the given input raster.
te::map::AbstractLayerPtr getOutputLayer()
This function returns the layer that has been created by the wizard with the sliced raster...
int getBlue() const
It returns the blue component color value (a value from 0 to 255).
Definition: RGBAColor.h:317
int getGreen() const
It returns the green component color value (a value from 0 to 255).
Definition: RGBAColor.h:312
short c4
alpha or blackband.
Definition: BandProperty.h:75
bool validateCurrentPage()
Overridden function that checks if the current page&#39;s configuration is done in order to proceed to th...
A widget to control the display of a set of layers.
void setSRID(int srid=0)
This function sets the srid of the display when the wizard was initiated.
static const std::string getLastLogStr()
Returns the last log string generated by this module.
This file defines a class for a Raster Info Wizard page.
const std::vector< ParameterValue * > & getThresholds() const
Definition: Categorize.cpp:109
RasterSlicingWizard(QWidget *parent=0)
Constructor.
void setExtent(const te::gm::Envelope &extent)
This function sets the envelope that will be used to trim tha raster if the user requests it...
An Envelope defines a 2D rectangular region.
This class is GUI used to define the raster info parameters for raster factory.
int getAlpha() const
It returns the alpha component color value (a value from 0 to 255).
Definition: RGBAColor.h:322
void addLayer(te::map::AbstractLayerPtr layer)
te::map::AbstractLayerPtr m_outputLayer
Utility functions for the data access module.
void setActionGroup(QActionGroup *actionGroup)
This function sets the QActionGroup.
void setMapDisplay(te::qt::widgets::MapDisplay *mapDisplay)
This function sets the map display.
TEMAPEXPORT te::rst::Raster * GetRaster(AbstractLayer *layer)
It gets the raster referenced by the given data set layer.
short c1
gray, red, cyan or hue.
Definition: BandProperty.h:72
TEQTWIDGETSEXPORT te::map::AbstractLayerPtr createLayer(const std::string &driverName, const te::core::URI &connInfo)
Push button that uses te::qt::widgets::HelpManager on its mouse pressed implementation.
std::unique_ptr< te::qt::widgets::RasterInfoWizardPage > m_rasterInfoPage
The wizard page used to define the output layer parameters.
void onMapDisplayExtentChanged()
This function refreshes the map display when the layer extent was changed.
A helper class for 32-bit RGBA (Red-Green-Blue-Alpha channel) color.
Definition: RGBAColor.h:57
short c3
blue, yellow, or saturation.
Definition: BandProperty.h:74
Categorize * getCategorize() const
Definition: ColorMap.cpp:73
void setList(std::list< te::map::AbstractLayerPtr > &layerList)
This function sets the list of layers from which the raster that will be sliced will come from...
An structure to represent a color tuple.
Definition: BandProperty.h:70
std::unique_ptr< te::qt::widgets::RasterSlicingWizardPage > m_wizardPage
The wizard page used to define the slicing parameters.
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
TESEEXPORT std::string GetString(const te::se::ParameterValue *param)
It gets the parameter value as a string.
A ColorMap defines either the colors of a pallette-type raster source or the mapping of numeric pixel...
Definition: ColorMap.h:61
std::unique_ptr< te::qt::widgets::LayerSearchWizardPage > m_layerSearchPage
The wizard page used to select an input layer.
short c2
green, magenta, or lightness.
Definition: BandProperty.h:73
TEQTWIDGETSEXPORT void applyRasterMultiResolution(const QString &toolName, te::rst::Raster *raster)
const std::vector< ParameterValue * > & getThresholdValues() const
Definition: Categorize.cpp:114
An object that when created shows a cursor during its scope.
Definition: ScopedCursor.h:48