ColorTransformDialog.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/ColorTransformDialog.cpp
22 
23  \brief This file defines a class for a ColorTransform dialog.
24 */
25 
26 // TerraLib
27 #include "../../../common/progress/ProgressManager.h"
28 #include "../../../common/StringUtils.h"
29 #include "../../../dataaccess/dataset/DataSet.h"
30 #include "../../../dataaccess/utils/Utils.h"
31 #include "../../../geometry/Utils.h"
32 #include "../../../maptools/Utils.h"
33 #include "../../../raster/Utils.h"
34 #include "../../../rp/Functions.h"
35 #include "../../../se/ChannelSelection.h"
36 #include "../../../se/CoverageStyle.h"
37 #include "../../../se/RasterSymbolizer.h"
38 #include "../../../raster/RasterSummaryManager.h"
39 #include "../../../se/Rule.h"
40 #include "../../../se/SelectedChannel.h"
41 #include "../../../se/Utils.h"
42 #include "../../widgets/tools/ExtentAcquire.h"
43 #include "../canvas/Canvas.h"
44 #include "../canvas/MapDisplay.h"
45 #include "../progress/ProgressViewerDialog.h"
46 #include "../layer/search/LayerSearchDialog.h"
47 #include "../layer/search/LayerSearchWidget.h"
48 #include "ColorTransformDialog.h"
49 #include "Utils.h"
50 #include "ui_ColorTransformDialogForm.h"
51 
52 // Qt
53 #include <QApplication>
54 #include <QGridLayout>
55 #include <QMessageBox>
56 
57 // stl
58 #include <memory>
59 
61 
62 te::qt::widgets::ColorTransformDialog::ColorTransformDialog(QWidget* parent)
63  : QDialog(parent),
64  m_ui(new Ui::ColorTransformDialogForm)
65 {
66 // setup controls
67  m_ui->setupUi(this);
68 
69  m_geom = nullptr;
70  m_mapDisplay = nullptr;
71 
72  m_ui->m_rgb2ihsNbitsComboBox->setEnabled(false);
73  m_ui->m_rgb2hlsNbitsComboBox->setEnabled(false);
74 
75  fillColorTransformTypes();
76 
77  //build output parameters
78  QGridLayout* outputLayout = new QGridLayout(m_ui->m_outputWidget);
79  outputLayout->setContentsMargins(0, 0, 0, 0);
80  m_outputWidget = new te::qt::widgets::OutputRasterWidget(m_ui->m_outputWidget);
81  outputLayout->addWidget(m_outputWidget);
82 
83  //connects
84  connect(m_ui->m_colorTransformTypeComboBox, SIGNAL(activated(int)), this, SLOT(colorTransformTypeComboBoxActivated(int)));
85 
86  connect(m_ui->m_rgbRComboBox, SIGNAL(activated(int)), this, SLOT(rgbRComboBoxActivated(int)));
87  connect(m_ui->m_rgbGComboBox, SIGNAL(activated(int)), this, SLOT(rgbGComboBoxActivated(int)));
88  connect(m_ui->m_rgbBComboBox, SIGNAL(activated(int)), this, SLOT(rgbBComboBoxActivated(int)));
89 
90  connect(m_ui->m_ihsIComboBox, SIGNAL(activated(int)), this, SLOT(ihsIComboBoxActivated(int)));
91  connect(m_ui->m_ihsHComboBox, SIGNAL(activated(int)), this, SLOT(ihsHComboBoxActivated(int)));
92  connect(m_ui->m_ihsSComboBox, SIGNAL(activated(int)), this, SLOT(ihsSComboBoxActivated(int)));
93 
94  connect(m_ui->m_rgb2hlsRComboBox, SIGNAL(activated(int)), this, SLOT(rgb2hlsRComboBoxActivated(int)));
95  connect(m_ui->m_rgb2hlsGComboBox, SIGNAL(activated(int)), this, SLOT(rgb2hlsGComboBoxActivated(int)));
96  connect(m_ui->m_rgb2hlsBComboBox, SIGNAL(activated(int)), this, SLOT(rgb2hlsBComboBoxActivated(int)));
97 
98  connect(m_ui->m_hlsHComboBox, SIGNAL(activated(int)), this, SLOT(hlsHComboBoxActivated(int)));
99  connect(m_ui->m_hlsLComboBox, SIGNAL(activated(int)), this, SLOT(hlsLComboBoxActivated(int)));
100  connect(m_ui->m_hlsSComboBox, SIGNAL(activated(int)), this, SLOT(hlsSComboBoxActivated(int)));
101 
102  connect(m_ui->m_newROIRToolButton, SIGNAL(clicked()), this, SLOT(onNewROIPushButtonClicked()));
103  connect(m_ui->m_newROIGToolButton, SIGNAL(clicked()), this, SLOT(onNewROIPushButtonClicked()));
104  connect(m_ui->m_newROIBToolButton, SIGNAL(clicked()), this, SLOT(onNewROIPushButtonClicked()));
105  connect(m_ui->m_newROIIToolButton, SIGNAL(clicked()), this, SLOT(onNewROIPushButtonClicked()));
106  connect(m_ui->m_newROIHToolButton, SIGNAL(clicked()), this, SLOT(onNewROIPushButtonClicked()));
107  connect(m_ui->m_newROISToolButton, SIGNAL(clicked()), this, SLOT(onNewROIPushButtonClicked()));
108  connect(m_ui->m_newROIRedToolButton, SIGNAL(clicked()), this, SLOT(onNewROIPushButtonClicked()));
109  connect(m_ui->m_newROIGreenToolButton, SIGNAL(clicked()), this, SLOT(onNewROIPushButtonClicked()));
110  connect(m_ui->m_newROIBlueToolButton, SIGNAL(clicked()), this, SLOT(onNewROIPushButtonClicked()));
111  connect(m_ui->m_newROIHueToolButton, SIGNAL(clicked()), this, SLOT(onNewROIPushButtonClicked()));
112  connect(m_ui->m_newROILightToolButton, SIGNAL(clicked()), this, SLOT(onNewROIPushButtonClicked()));
113  connect(m_ui->m_newROISatToolButton, SIGNAL(clicked()), this, SLOT(onNewROIPushButtonClicked()));
114 
115  connect(m_ui->m_searchRLayerToolButton, SIGNAL(clicked()), this, SLOT(onSearchLayerToolButtonClicked()));
116  connect(m_ui->m_searchGLayerToolButton, SIGNAL(clicked()), this, SLOT(onSearchLayerToolButtonClicked()));
117  connect(m_ui->m_searchBLayerToolButton, SIGNAL(clicked()), this, SLOT(onSearchLayerToolButtonClicked()));
118 
119  connect(m_ui->m_searchIRGBLayerToolButton, SIGNAL(clicked()), this, SLOT(onSearchLayerToolButtonClicked()));
120  connect(m_ui->m_searchHRGBLayerToolButton, SIGNAL(clicked()), this, SLOT(onSearchLayerToolButtonClicked()));
121  connect(m_ui->m_searchSRGBLayerToolButton, SIGNAL(clicked()), this, SLOT(onSearchLayerToolButtonClicked()));
122 
123  connect(m_ui->m_searchRedLayerToolButton, SIGNAL(clicked()), this, SLOT(onSearchLayerToolButtonClicked()));
124  connect(m_ui->m_searchGreenLayerToolButton, SIGNAL(clicked()), this, SLOT(onSearchLayerToolButtonClicked()));
125  connect(m_ui->m_searchBlueLayerToolButton, SIGNAL(clicked()), this, SLOT(onSearchLayerToolButtonClicked()));
126 
127  connect(m_ui->m_searchHueLayerToolButton, SIGNAL(clicked()), this, SLOT(onSearchLayerToolButtonClicked()));
128  connect(m_ui->m_searchSatLayerToolButton, SIGNAL(clicked()), this, SLOT(onSearchLayerToolButtonClicked()));
129  connect(m_ui->m_searchLightLayerToolButton, SIGNAL(clicked()), this, SLOT(onSearchLayerToolButtonClicked()));
130 
131  connect(m_ui->m_okPushButton, SIGNAL(clicked()), SLOT(onOkPushButtonClicked()));
132 
133  //set icons
134  m_ui->m_newROIRToolButton->setIcon(QIcon::fromTheme("edit-box"));
135  m_ui->m_newROIGToolButton->setIcon(QIcon::fromTheme("edit-box"));
136  m_ui->m_newROIBToolButton->setIcon(QIcon::fromTheme("edit-box"));
137  m_ui->m_newROIIToolButton->setIcon(QIcon::fromTheme("edit-box"));
138  m_ui->m_newROIHToolButton->setIcon(QIcon::fromTheme("edit-box"));
139  m_ui->m_newROISToolButton->setIcon(QIcon::fromTheme("edit-box"));
140  m_ui->m_newROIRedToolButton->setIcon(QIcon::fromTheme("edit-box"));
141  m_ui->m_newROIGreenToolButton->setIcon(QIcon::fromTheme("edit-box"));
142  m_ui->m_newROIBlueToolButton->setIcon(QIcon::fromTheme("edit-box"));
143  m_ui->m_newROIHueToolButton->setIcon(QIcon::fromTheme("edit-box"));
144  m_ui->m_newROILightToolButton->setIcon(QIcon::fromTheme("edit-box"));
145  m_ui->m_newROISatToolButton->setIcon(QIcon::fromTheme("edit-box"));
146 }
147 
149 
151 {
152  int idx = m_ui->m_colorTransformTypeComboBox->currentIndex();
153 
154  int type = m_ui->m_colorTransformTypeComboBox->itemData(idx).toInt();
155 
156  return (type == COLORTRANSFORM_RGB2IHS);
157 }
158 
160 {
161  int idx = m_ui->m_colorTransformTypeComboBox->currentIndex();
162 
163  int type = m_ui->m_colorTransformTypeComboBox->itemData(idx).toInt();
164 
165  return (type == COLORTRANSFORM_IHS2RGB);
166 }
167 
169 {
170  int idx = m_ui->m_colorTransformTypeComboBox->currentIndex();
171 
172  int type = m_ui->m_colorTransformTypeComboBox->itemData(idx).toInt();
173 
174  return (type == COLORTRANSFORM_RGB2HLS);
175 }
176 
178 {
179  int idx = m_ui->m_colorTransformTypeComboBox->currentIndex();
180 
181  int type = m_ui->m_colorTransformTypeComboBox->itemData(idx).toInt();
182 
183  return (type == COLORTRANSFORM_HLS2RGB);
184 }
185 
186 void te::qt::widgets::ColorTransformDialog::setList(std::list<te::map::AbstractLayerPtr>& layerList)
187 {
188  m_layerList = layerList;
189 }
190 
192 {
193  m_ui->m_stackedWidget->setCurrentIndex(index);
194 
195  if (index == 0 || index == 2)
196  m_ui->m_decomposeCheckBox->setChecked(true);
197  else
198  m_ui->m_decomposeCheckBox->setChecked(false);
199 
200  clearCanvas();
201 }
202 
204 {
205  //get layer
206  QVariant varLayer = m_ui->m_rgbRComboBox->itemData(index, Qt::UserRole);
207  m_layerR = varLayer.value<te::map::AbstractLayerPtr>();
208 
209  getRasterBands(m_ui->m_rgbRComboBox, index, m_ui->m_rgbRBandComboBox);
210 
211  std::unique_ptr<te::da::DataSetType> dsType = m_layerR->getSchema();
212  te::rst::RasterProperty* rasterProp = te::da::GetFirstRasterProperty(dsType.get());
213  std::unique_ptr<te::da::DataSet> dsRaster = m_layerR->getData();
214  std::unique_ptr<te::rst::Raster> raster = dsRaster->getRaster(rasterProp->getName());
215 
218  const std::complex<double>* cmin = rsMin->at(0).m_minVal;
219  const std::complex<double>* cmax = rsMax->at(0).m_maxVal;
220  double min = cmin->real();
221  double max = cmax->real();
222 
223  for (size_t b = 1; b < raster->getNumberOfBands(); b++)
224  {
227  const std::complex<double>* cmin = rsMin->at(b).m_minVal;
228  const std::complex<double>* cmax = rsMax->at(b).m_maxVal;
229 
230  min = std::min(min, cmin->real());
231  max = std::max(max, cmax->real());
232  }
233 
234  //get data type range
235  double range = max - min;
236  unsigned int nbits = (unsigned int)(std::ceil(log(range) / log(2.)));
237 
238  int i = 0;
239  switch (nbits)
240  {
241  case 10:
242  i = 1;
243  break;
244 
245  case 16:
246  i = 2;
247  break;
248 
249  case 24:
250  i = 3;
251  break;
252 
253  case 32:
254  i = 4;
255  break;
256 
257  default:
258  break;
259  }
260 
261  m_ui->m_rgb2ihsNbitsComboBox->setCurrentIndex(i);
262 }
263 
265 {
266  //get layer
267  QVariant varLayer = m_ui->m_rgbGComboBox->itemData(index, Qt::UserRole);
268  m_layerG = varLayer.value<te::map::AbstractLayerPtr>();
269 
270  getRasterBands(m_ui->m_rgbGComboBox, index, m_ui->m_rgbGBandComboBox);
271 }
272 
274 {
275  //get layer
276  QVariant varLayer = m_ui->m_rgbBComboBox->itemData(index, Qt::UserRole);
277  m_layerB = varLayer.value<te::map::AbstractLayerPtr>();
278 
279  getRasterBands(m_ui->m_rgbBComboBox, index, m_ui->m_rgbBBandComboBox);
280 }
281 
283 {
284  //get layer
285  QVariant varLayer = m_ui->m_ihsIComboBox->itemData(index, Qt::UserRole);
286  m_layerR = varLayer.value<te::map::AbstractLayerPtr>();
287 
288  getRasterBands(m_ui->m_ihsIComboBox, index, m_ui->m_ihsIBandComboBox);
289 }
290 
292 {
293  //get layer
294  QVariant varLayer = m_ui->m_ihsHComboBox->itemData(index, Qt::UserRole);
295  m_layerG = varLayer.value<te::map::AbstractLayerPtr>();
296 
297  getRasterBands(m_ui->m_ihsHComboBox, index, m_ui->m_ihsHBandComboBox);
298 }
299 
301 {
302  //get layer
303  QVariant varLayer = m_ui->m_ihsSComboBox->itemData(index, Qt::UserRole);
304  m_layerB = varLayer.value<te::map::AbstractLayerPtr>();
305 
306  getRasterBands(m_ui->m_ihsSComboBox, index, m_ui->m_ihsSBandComboBox);
307 }
308 
310 {
311  //get layer
312  QVariant varLayer = m_ui->m_rgb2hlsRComboBox->itemData(index, Qt::UserRole);
313  m_layerR = varLayer.value<te::map::AbstractLayerPtr>();
314 
315  getRasterBands(m_ui->m_rgb2hlsRComboBox, index, m_ui->m_rgb2hlsRBandComboBox);
316 
317  std::unique_ptr<te::da::DataSetType> dsType = m_layerR->getSchema();
318  te::rst::RasterProperty* rasterProp = te::da::GetFirstRasterProperty(dsType.get());
319  std::unique_ptr<te::da::DataSet> dsRaster = m_layerR->getData();
320  std::unique_ptr<te::rst::Raster> raster = dsRaster->getRaster(rasterProp->getName());
321 
324  const std::complex<double>* cmin = rsMin->at(0).m_minVal;
325  const std::complex<double>* cmax = rsMax->at(0).m_maxVal;
326  double min = cmin->real();
327  double max = cmax->real();
328 
329  for (size_t b = 1; b < raster->getNumberOfBands(); b++)
330  {
333  const std::complex<double>* cmin = rsMin->at(b).m_minVal;
334  const std::complex<double>* cmax = rsMax->at(b).m_maxVal;
335  double min = cmin->real();
336  double max = cmax->real();
337 
338  min = std::min(min, cmin->real());
339  max = std::max(max, cmax->real());
340  }
341 
342  //get data type range
343  double range = max - min;
344  unsigned int nbits = (unsigned int)(std::ceil(log(range) / log(2.)));
345 
346  int i = 0;
347  switch (nbits)
348  {
349  case 10:
350  i = 1;
351  break;
352 
353  case 16:
354  i = 2;
355  break;
356 
357  case 24:
358  i = 3;
359  break;
360 
361  case 32:
362  i = 4;
363  break;
364 
365  default:
366  break;
367  }
368 
369  m_ui->m_rgb2hlsNbitsComboBox->setCurrentIndex(i);
370 }
371 
373 {
374  //get layer
375  QVariant varLayer = m_ui->m_rgb2hlsGComboBox->itemData(index, Qt::UserRole);
376  m_layerG = varLayer.value<te::map::AbstractLayerPtr>();
377 
378  getRasterBands(m_ui->m_rgb2hlsGComboBox, index, m_ui->m_rgb2hlsGBandComboBox);
379 }
380 
382 {
383  //get layer
384  QVariant varLayer = m_ui->m_rgb2hlsBComboBox->itemData(index, Qt::UserRole);
385  m_layerB = varLayer.value<te::map::AbstractLayerPtr>();
386 
387  getRasterBands(m_ui->m_rgb2hlsBComboBox, index, m_ui->m_rgb2hlsBBandComboBox);
388 }
389 
391 {
392  //get layer
393  QVariant varLayer = m_ui->m_hlsHComboBox->itemData(index, Qt::UserRole);
394  m_layerR = varLayer.value<te::map::AbstractLayerPtr>();
395 
396  getRasterBands(m_ui->m_hlsHComboBox, index, m_ui->m_hlsHBandComboBox);
397 }
398 
400 {
401  //get layer
402  QVariant varLayer = m_ui->m_hlsLComboBox->itemData(index, Qt::UserRole);
403  m_layerG = varLayer.value<te::map::AbstractLayerPtr>();
404 
405  getRasterBands(m_ui->m_hlsLComboBox, index, m_ui->m_hlsLBandComboBox);
406 }
407 
409 {
410  //get layer
411  QVariant varLayer = m_ui->m_hlsSComboBox->itemData(index, Qt::UserRole);
412  m_layerB = varLayer.value<te::map::AbstractLayerPtr>();
413 
414  getRasterBands(m_ui->m_hlsSComboBox, index, m_ui->m_hlsSBandComboBox);
415 }
416 
418 {
419  if ((m_ui->m_stackedWidget->currentIndex() == 0 && (m_ui->m_newROIRToolButton->isChecked() || m_ui->m_newROIGToolButton->isChecked() || m_ui->m_newROIBToolButton->isChecked())) ||
420  (m_ui->m_stackedWidget->currentIndex() == 1 && (m_ui->m_newROIIToolButton->isChecked() || m_ui->m_newROIHToolButton->isChecked() || m_ui->m_newROISToolButton->isChecked())) ||
421  (m_ui->m_stackedWidget->currentIndex() == 2 && (m_ui->m_newROIRedToolButton->isChecked() || m_ui->m_newROIGreenToolButton->isChecked() || m_ui->m_newROIBlueToolButton->isChecked())) ||
422  (m_ui->m_stackedWidget->currentIndex() == 3 && (m_ui->m_newROIHueToolButton->isChecked() || m_ui->m_newROILightToolButton->isChecked() || m_ui->m_newROISatToolButton->isChecked())))
423  {
426 
427  connect(ea, SIGNAL(extentAcquired(te::gm::Envelope)), this, SLOT(onEnvelopeAcquired(te::gm::Envelope)));
428  }
429  else
430  {
431  m_mapDisplay->setCurrentTool(nullptr);
432 
433  if (m_geom && m_geom->isValid())
434  clearCanvas();
435  }
436 }
437 
439 {
440  //check input layer
441  if(m_layerList.empty())
442  {
443  QMessageBox::information(this, tr("Color Transform"), tr("Input image is empty."));
444  return;
445  }
446 
447  //check output parameters
448  if (m_outputWidget->getOutputRaster().empty())
449  {
450  QMessageBox::information(this, tr("Color Transform"), tr("Output image is not defined."));
451  return;
452  }
453 
454  if(!execute())
455  {
456  QMessageBox::information(this, tr("Color Transform"), tr("Error to execute the color transformation."));
457  return;
458  }
459 
460  accept();
461 }
462 
464 {
465  if (!env.isValid())
466  return;
467 
468  if (env.getLowerLeftX() == 0 && env.getLowerLeftY() == 0 && env.getUpperRightX() == 0 && env.getUpperRightY() == 0)
469  return;
470 
471  // verify if is necessary convert the raster to the given srid
472  bool needRemap = false;
473  if ((m_mapDisplay->getSRID() != TE_UNKNOWN_SRS) && (m_layerR->getSRID() != TE_UNKNOWN_SRS) && (m_mapDisplay->getSRID() != m_layerR->getSRID()))
474  needRemap = true;
475 
476  te::gm::Envelope envOut = env;
477 
478  // create a SRS converter
479  std::unique_ptr<te::srs::Converter> converter(new te::srs::Converter());
480 
481  if (needRemap)
482  {
483  converter->setSourceSRID(m_mapDisplay->getSRID());
484  converter->setTargetSRID(m_layerR->getSRID());
485 
486  converter->convert(envOut.getLowerLeftX(), envOut.getLowerLeftY(), envOut.m_llx, envOut.m_lly);
487  converter->convert(envOut.getUpperRightX(), envOut.getUpperRightY(), envOut.m_urx, envOut.m_ury);
488  }
489 
490  if (!envOut.intersects(m_layerR->getExtent()))
491  {
492  QMessageBox::warning(this, tr("Warning"), tr("ROI is invalid."));
493  return;
494  }
495 
496  m_geom = nullptr;
497 
498  if (env.isValid())
500 
502 
503  drawGeom();
504 }
505 
507 {
508  drawGeom();
509 
510  if (m_rasterPreview)
511  {
513  }
514 }
515 
517 {
518  std::unique_ptr<te::qt::widgets::LayerSearchDialog> dlg(new te::qt::widgets::LayerSearchDialog(this));
519  dlg->getWidget()->setList(m_layerList);
520  dlg->getWidget()->filterOnlyByRaster();
521 
522  if(dlg->exec())
523  {
524  int idx = m_ui->m_colorTransformTypeComboBox->currentIndex();
525  int type = m_ui->m_colorTransformTypeComboBox->itemData(idx).toInt();
526 
527  std::list<te::map::AbstractLayerPtr> layerList = dlg->getWidget()->getSelecteds();
528 
529  if(layerList.empty())
530  return;
531 
532  std::list<te::map::AbstractLayerPtr>::iterator it = layerList.begin();
533 
534  m_layerR = *it;
535  m_layerG = *it;
536  m_layerB = *it;
537 
538  while(it != layerList.end())
539  {
541 
542  std::unique_ptr<te::da::DataSetType> dst = l->getSchema();
543 
544  if(dst.get())
545  {
546  if(type == COLORTRANSFORM_RGB2IHS)
547  {
548  if(m_ui->m_rgbRComboBox->findText(l->getTitle().c_str()) == -1)
549  {
550  m_ui->m_rgbRComboBox->addItem(l->getTitle().c_str(), QVariant::fromValue(l));
551  m_ui->m_rgbRComboBox->setCurrentIndex(m_ui->m_rgbRComboBox->findText(l->getTitle().c_str()));
552  }
553 
554  if(m_ui->m_rgbGComboBox->findText(l->getTitle().c_str()) == -1)
555  {
556  m_ui->m_rgbGComboBox->addItem(l->getTitle().c_str(), QVariant::fromValue(l));
557  m_ui->m_rgbGComboBox->setCurrentIndex(m_ui->m_rgbGComboBox->findText(l->getTitle().c_str()));
558  }
559 
560  if(m_ui->m_rgbBComboBox->findText(l->getTitle().c_str()) == -1)
561  {
562  m_ui->m_rgbBComboBox->addItem(l->getTitle().c_str(), QVariant::fromValue(l));
563  m_ui->m_rgbBComboBox->setCurrentIndex(m_ui->m_rgbBComboBox->findText(l->getTitle().c_str()));
564  }
565  }
566  else if(type == COLORTRANSFORM_IHS2RGB)
567  {
568  if(m_ui->m_ihsIComboBox->findText(l->getTitle().c_str()) == -1)
569  {
570  m_ui->m_ihsIComboBox->addItem(l->getTitle().c_str(), QVariant::fromValue(l));
571  m_ui->m_ihsIComboBox->setCurrentIndex(m_ui->m_ihsIComboBox->findText(l->getTitle().c_str()));
572  }
573 
574  if(m_ui->m_ihsHComboBox->findText(l->getTitle().c_str()) == -1)
575  {
576  m_ui->m_ihsHComboBox->addItem(l->getTitle().c_str(), QVariant::fromValue(l));
577  m_ui->m_ihsHComboBox->setCurrentIndex(m_ui->m_ihsHComboBox->findText(l->getTitle().c_str()));
578  }
579 
580  if(m_ui->m_ihsSComboBox->findText(l->getTitle().c_str()) == -1)
581  {
582  m_ui->m_ihsSComboBox->addItem(l->getTitle().c_str(), QVariant::fromValue(l));
583  m_ui->m_ihsSComboBox->setCurrentIndex(m_ui->m_ihsSComboBox->findText(l->getTitle().c_str()));
584  }
585  }
586  else if(type == COLORTRANSFORM_RGB2HLS)
587  {
588  if(m_ui->m_rgb2hlsRComboBox->findText(l->getTitle().c_str()) == -1)
589  {
590  m_ui->m_rgb2hlsRComboBox->addItem(l->getTitle().c_str(), QVariant::fromValue(l));
591  m_ui->m_rgb2hlsRComboBox->setCurrentIndex(m_ui->m_rgb2hlsRComboBox->findText(l->getTitle().c_str()));
592  }
593 
594  if(m_ui->m_rgb2hlsGComboBox->findText(l->getTitle().c_str()) == -1)
595  {
596  m_ui->m_rgb2hlsGComboBox->addItem(l->getTitle().c_str(), QVariant::fromValue(l));
597  m_ui->m_rgb2hlsGComboBox->setCurrentIndex(m_ui->m_rgb2hlsGComboBox->findText(l->getTitle().c_str()));
598  }
599 
600  if(m_ui->m_rgb2hlsBComboBox->findText(l->getTitle().c_str()) == -1)
601  {
602  m_ui->m_rgb2hlsBComboBox->addItem(l->getTitle().c_str(), QVariant::fromValue(l));
603  m_ui->m_rgb2hlsBComboBox->setCurrentIndex(m_ui->m_rgb2hlsBComboBox->findText(l->getTitle().c_str()));
604  }
605  }
606  else
607  {
608  if(m_ui->m_hlsHComboBox->findText(l->getTitle().c_str()) == -1)
609  {
610  m_ui->m_hlsHComboBox->addItem(l->getTitle().c_str(), QVariant::fromValue(l));
611  m_ui->m_hlsHComboBox->setCurrentIndex(m_ui->m_hlsHComboBox->findText(l->getTitle().c_str()));
612  }
613 
614  if(m_ui->m_hlsLComboBox->findText(l->getTitle().c_str()) == -1)
615  {
616  m_ui->m_hlsLComboBox->addItem(l->getTitle().c_str(), QVariant::fromValue(l));
617  m_ui->m_hlsLComboBox->setCurrentIndex(m_ui->m_hlsLComboBox->findText(l->getTitle().c_str()));
618  }
619 
620  if(m_ui->m_hlsSComboBox->findText(l->getTitle().c_str()) == -1)
621  {
622  m_ui->m_hlsSComboBox->addItem(l->getTitle().c_str(), QVariant::fromValue(l));
623  m_ui->m_hlsSComboBox->setCurrentIndex(m_ui->m_hlsSComboBox->findText(l->getTitle().c_str()));
624  }
625  }
626  }
627 
628  ++it;
629  }
630 
631  if(type == COLORTRANSFORM_RGB2IHS)
632  {
636  }
637  else if(type == COLORTRANSFORM_IHS2RGB)
638  {
642  }
643  else if(type == COLORTRANSFORM_RGB2HLS)
644  {
648  }
649  else
650  {
654  }
655  }
656 }
657 
659 {
660  //progress
662 
663  QApplication::setOverrideCursor(Qt::WaitCursor);
664 
665  try
666  {
667  bool res = false;
668 
669  if (isRGB2IHS())
670  res = executeRGB2IHS();
671  else if (isIHS2RGB())
672  res = executeIHS2RGB();
673  if (isRGB2HLS())
674  res = executeRGB2HLS();
675  else if (isHLS2RGB())
676  res = executeHLS2RGB();
677 
678  if (res)
679  {
680  //set output layer
681  if (!m_ui->m_decomposeCheckBox->isChecked())
682  {
685 
686  te::qt::widgets::applyRasterMultiResolution(tr("Color Transform"), te::map::GetRaster(outputLayer.get()));
687 
688  emit addLayer(outputLayer);
689  }
690  else
691  {
692  for (std::size_t t = 0; t < 3; ++t)
693  {
694  std::map<std::string, std::string> rinfo;
695 
696  double index = (double)t + (double)1;
697 
698  rinfo["URI"] = m_outputWidget->getFilePath() + "_" + TE_TR("Band") + "_" + te::common::Convert2String(index, 0) + "." + m_outputWidget->getFileExtension();
699 
701 
702  te::qt::widgets::applyRasterMultiResolution(tr("Color Transform"), te::map::GetRaster(outputLayer.get()));
703 
704  emit addLayer(outputLayer);
705  }
706  }
707 
708  QApplication::restoreOverrideCursor();
709 
710  QMessageBox::information(this, tr("Color Transform"), tr("Color Transform ended sucessfully"));
711  }
712  else
713  {
714  QApplication::restoreOverrideCursor();
715 
716  QMessageBox::critical(this, tr("Color Transform"), tr("Color Transform execution error.") + (" " + te::rp::Module::getLastLogStr()).c_str());
717 
718  return false;
719  }
720  }
721  catch (const std::exception& e)
722  {
723  QApplication::restoreOverrideCursor();
724 
725  QMessageBox::warning(this, tr("Color Transform"), e.what());
726 
727  return false;
728  }
729  catch (...)
730  {
731  QApplication::restoreOverrideCursor();
732 
733  QMessageBox::warning(this, tr("Color Transform"), tr("An exception has occurred!"));
734 
735  return false;
736  }
737 
738  return true;
739 }
740 
742 {
743  te::rst::Raster* inputRRaster = getRRaster();
744  te::rst::Raster* inputGRaster = getGRaster();
745  te::rst::Raster* inputBRaster = getBRaster();
746  te::rst::Raster* outputRaster;
747  std::vector< boost::shared_ptr< te::rst::Raster > > outputRastersPtrs;
748  std::vector< std::map<std::string, std::string> > outputRastersInfos;
749 
750  if (!m_ui->m_decomposeCheckBox->isChecked())
751  outputRaster = buildOutputRaster();
752  else
753  {
754  outputRaster = buildMemRaster();
755 
756  for (std::size_t t = 0; t < 3; ++t)
757  {
758  std::map<std::string, std::string> rinfo;
759 
760  double index = (double)t + (double)1;
761  rinfo["URI"] = m_outputWidget->getFilePath() + "_" + TE_TR("Band") + "_" + te::common::Convert2String(index, 0) + "." + m_outputWidget->getFileExtension();
762  outputRastersInfos.push_back(rinfo);
763  }
764  }
765 
766  if (!outputRaster)
767  return false;
768 
769  unsigned int rBand = m_ui->m_rgbRBandComboBox->currentText().toUInt();
770  unsigned int gBand = m_ui->m_rgbGBandComboBox->currentText().toUInt();
771  unsigned int bBand = m_ui->m_rgbBBandComboBox->currentText().toUInt();
772 
773  int nbits = getNBits(m_ui->m_rgb2ihsNbitsComboBox->currentIndex());
774  double minValue = 0;
775  double maxValue = (double)(pow(2.0, (double)nbits)) - 1;
776 
777  bool res = te::rp::ConvertRGB2IHS(*inputRRaster, rBand, *inputGRaster, gBand, *inputBRaster, bBand, minValue, maxValue, *outputRaster);
778 
779  std::vector<unsigned int> rasterBands;
780  rasterBands.push_back(0);
781  rasterBands.push_back(1);
782  rasterBands.push_back(2);
783 
784  if (m_ui->m_decomposeCheckBox->isChecked())
785  {
786  //get output raster info
787  std::string type = m_outputWidget->getType();
788 
789  //decompose bands
790  res = te::rp::DecomposeBands(*outputRaster, rasterBands, outputRastersInfos, type, outputRastersPtrs);
791  }
792 
793  delete inputRRaster;
794  delete inputGRaster;
795  delete inputBRaster;
796  delete outputRaster;
797 
798  return res;
799 }
800 
802 {
803  te::rst::Raster* inputIRaster = getIRaster();
804  te::rst::Raster* inputHRaster = getHRaster();
805  te::rst::Raster* inputSRaster = getSRaster();
806  te::rst::Raster* outputRaster;
807 
808  std::vector< boost::shared_ptr< te::rst::Raster > > outputRastersPtrs;
809  std::vector< std::map<std::string, std::string> > outputRastersInfos;
810 
811  if (!m_ui->m_decomposeCheckBox->isChecked())
812  outputRaster = buildOutputRaster();
813  else
814  {
815  outputRaster = buildMemRaster();
816 
817  for (std::size_t t = 0; t < 3; ++t)
818  {
819  std::map<std::string, std::string> rinfo;
820 
821  double index = (double)t + (double)1;
822 
823  rinfo["URI"] = m_outputWidget->getFilePath() + "_" + TE_TR("Band") + "_" + te::common::Convert2String(index, 0) + "." + m_outputWidget->getFileExtension();
824  outputRastersInfos.push_back(rinfo);
825  }
826  }
827 
828  if (!outputRaster)
829  return false;
830 
831  unsigned int iBand = m_ui->m_ihsIBandComboBox->currentText().toUInt();
832  unsigned int hBand = m_ui->m_ihsHBandComboBox->currentText().toUInt();
833  unsigned int sBand = m_ui->m_ihsSBandComboBox->currentText().toUInt();
834 
835  int nbits = getNBits(m_ui->m_ihs2rgbNbitsComboBox->currentIndex());
836  double minValue = 0;
837 
838  //get data type range
839  double maxValue = (double)(pow(2.0, (double)nbits)) - 1;
840 
841  bool res = te::rp::ConvertIHS2RGB(*inputIRaster, iBand, *inputHRaster, hBand, *inputSRaster, sBand, minValue, maxValue, *outputRaster);
842 
843  std::vector<unsigned int> rasterBands;
844  rasterBands.push_back(0);
845  rasterBands.push_back(1);
846  rasterBands.push_back(2);
847 
848  if (m_ui->m_decomposeCheckBox->isChecked())
849  {
850  //get output raster info
851  std::string type = m_outputWidget->getType();
852 
853  //decompose bands
854  res = te::rp::DecomposeBands(*outputRaster, rasterBands, outputRastersInfos, type, outputRastersPtrs);
855  }
856 
857  delete inputIRaster;
858  delete inputHRaster;
859  delete inputSRaster;
860  delete outputRaster;
861 
862  return res;
863 }
864 
866 {
867  te::rst::Raster* inputRRaster = getRRaster();
868  te::rst::Raster* inputGRaster = getGRaster();
869  te::rst::Raster* inputBRaster = getBRaster();
870  te::rst::Raster* outputRaster;
871  std::vector< boost::shared_ptr< te::rst::Raster > > outputRastersPtrs;
872  std::vector< std::map<std::string, std::string> > outputRastersInfos;
873 
874  if (!m_ui->m_decomposeCheckBox->isChecked())
875  outputRaster = buildOutputRaster();
876  else
877  {
878  outputRaster = buildMemRaster();
879 
880  for (std::size_t t = 0; t < 3; ++t)
881  {
882  std::map<std::string, std::string> rinfo;
883 
884  double index = (double)t + (double)1;
885  rinfo["URI"] = m_outputWidget->getFilePath() + "_" + TE_TR("Band") + "_" + te::common::Convert2String(index, 0) + "." + m_outputWidget->getFileExtension();
886  outputRastersInfos.push_back(rinfo);
887  }
888  }
889 
890  if (!outputRaster)
891  return false;
892 
893  unsigned int rBand = m_ui->m_rgb2hlsRBandComboBox->currentText().toUInt();
894  unsigned int gBand = m_ui->m_rgb2hlsGBandComboBox->currentText().toUInt();
895  unsigned int bBand = m_ui->m_rgb2hlsBBandComboBox->currentText().toUInt();
896 
897  int nbits = getNBits(m_ui->m_rgb2hlsNbitsComboBox->currentIndex());
898  double minValue = 0;
899 
900  //get data type range
901  double maxValue = (double)(pow(2.0, (double)nbits)) - 1;
902 
903  bool res = te::rp::ConvertRGB2HLS(*inputRRaster, rBand, *inputGRaster, gBand, *inputBRaster, bBand, minValue, maxValue, *outputRaster);
904 
905  std::vector<unsigned int> rasterBands;
906  rasterBands.push_back(0);
907  rasterBands.push_back(1);
908  rasterBands.push_back(2);
909 
910  if (m_ui->m_decomposeCheckBox->isChecked())
911  {
912  //get output raster info
913  std::string type = m_outputWidget->getType();
914 
915  //decompose bands
916  res = te::rp::DecomposeBands(*outputRaster, rasterBands, outputRastersInfos, type, outputRastersPtrs);
917  }
918 
919  delete inputRRaster;
920  delete inputGRaster;
921  delete inputBRaster;
922  delete outputRaster;
923 
924  return res;
925 }
926 
928 {
929  te::rst::Raster* inputHRaster = getHRaster();
930  te::rst::Raster* inputLRaster = getLRaster();
931  te::rst::Raster* inputSRaster = getSRaster();
932  te::rst::Raster* outputRaster;
933 
934  std::vector< boost::shared_ptr< te::rst::Raster > > outputRastersPtrs;
935  std::vector< std::map<std::string, std::string> > outputRastersInfos;
936 
937  if (!m_ui->m_decomposeCheckBox->isChecked())
938  outputRaster = buildOutputRaster();
939  else
940  {
941  outputRaster = buildMemRaster();
942 
943  for (std::size_t t = 0; t < 3; ++t)
944  {
945  std::map<std::string, std::string> rinfo;
946 
947  double index = (double)t + (double)1;
948 
949  rinfo["URI"] = m_outputWidget->getFilePath() + "_" + TE_TR("Band") + "_" + te::common::Convert2String(index, 0) + "." + m_outputWidget->getFileExtension();
950  outputRastersInfos.push_back(rinfo);
951  }
952  }
953 
954  if (!outputRaster)
955  return false;
956 
957  unsigned int hBand = m_ui->m_hlsHBandComboBox->currentText().toUInt();
958  unsigned int lBand = m_ui->m_hlsLBandComboBox->currentText().toUInt();
959  unsigned int sBand = m_ui->m_hlsSBandComboBox->currentText().toUInt();
960 
961  int nbits = getNBits(m_ui->m_hls2rgbNbitsComboBox->currentIndex());
962  double minValue = 0;
963  double maxValue = (double)(pow(2.0, (double)nbits)) - 1;
964 
965  bool res = te::rp::ConvertHLS2RGB(*inputHRaster, hBand, *inputLRaster, lBand, *inputSRaster, sBand, minValue, maxValue, *outputRaster);
966 
967  std::vector<unsigned int> rasterBands;
968  rasterBands.push_back(0);
969  rasterBands.push_back(1);
970  rasterBands.push_back(2);
971 
972  if (m_ui->m_decomposeCheckBox->isChecked())
973  {
974  //get output raster info
975  std::string type = m_outputWidget->getType();
976 
977  //decompose bands
978  res = te::rp::DecomposeBands(*outputRaster, rasterBands, outputRastersInfos, type, outputRastersPtrs);
979  }
980 
981  delete inputHRaster;
982  delete inputLRaster;
983  delete inputSRaster;
984  delete outputRaster;
985 
986  return res;
987 }
988 
990 {
991  te::rst::Raster* rasterOut;
992 
993  //check output data type
994  int dataType = te::dt::UNKNOWN_TYPE;
995 
996  if (isRGB2IHS() || isRGB2HLS())
997  dataType = te::dt::FLOAT_TYPE;
998  else if (isIHS2RGB() || isHLS2RGB())
999  {
1000  int nbits;
1001  if (isIHS2RGB())
1002  nbits = getNBits(m_ui->m_ihs2rgbNbitsComboBox->currentIndex());
1003  else
1004  nbits = getNBits(m_ui->m_hls2rgbNbitsComboBox->currentIndex());
1005 
1006  dataType = te::dt::UCHAR_TYPE;
1007 
1008  if (nbits == 10 || nbits == 16)
1009  dataType = te::dt::UINT16_TYPE;
1010  else if (nbits == 24 || nbits == 32)
1011  dataType = te::dt::UINT32_TYPE;
1012  }
1013 
1014  //get output raster info
1015  std::string type = m_outputWidget->getType();
1016 
1017  std::map<std::string, std::string> info = m_outputWidget->getInfo();
1018 
1019  //get input raster
1020  te::rst::Raster* inputRaster;
1021 
1022  if (isRGB2IHS() || isRGB2HLS())
1023  inputRaster = getRRaster();
1024  else if (isIHS2RGB())
1025  inputRaster = getIRaster();
1026  else if (isHLS2RGB())
1027  inputRaster = getHRaster();
1028  else
1029  return nullptr;
1030 
1031  //get input bands info
1032  std::vector<te::rst::BandProperty*> bands;
1033 
1034  for (std::size_t t = 0; t < 3; ++t)
1035  {
1036  te::rst::BandProperty* bProp = new te::rst::BandProperty(*inputRaster->getBand(0)->getProperty());
1037 
1038  bProp->m_type = dataType;
1039 
1040  bands.push_back(bProp);
1041 
1042  if (t >= 2 || m_ui->m_decomposeCheckBox->isChecked())
1043  break;
1044  }
1045 
1046  //get input grid
1047  te::rst::Grid* grid = new te::rst::Grid(*inputRaster->getGrid());
1048 
1049  //build output raster
1050  rasterOut = te::rst::RasterFactory::make(type, grid, bands, info);
1051 
1052  return rasterOut;
1053 }
1054 
1056 {
1057  te::rst::Raster* rasterOut;
1058 
1059  //check output data type
1060  int dataType = te::dt::UNKNOWN_TYPE;
1061 
1062  if (isRGB2IHS() || isRGB2HLS())
1063  dataType = te::dt::FLOAT_TYPE;
1064  else if (isIHS2RGB() || isHLS2RGB())
1065  {
1066  int nbits;
1067  if (isIHS2RGB())
1068  nbits = getNBits(m_ui->m_ihs2rgbNbitsComboBox->currentIndex());
1069  else
1070  nbits = getNBits(m_ui->m_hls2rgbNbitsComboBox->currentIndex());
1071 
1072  dataType = te::dt::UCHAR_TYPE;
1073 
1074  if (nbits == 10 || nbits == 16)
1075  dataType = te::dt::UINT16_TYPE;
1076  else if (nbits == 24 || nbits == 32)
1077  dataType = te::dt::UINT32_TYPE;
1078  }
1079 
1080  //get output raster info
1081  std::string type = "MEM";
1082 
1083  //get input raster
1084  te::rst::Raster* inputRaster;
1085 
1086  if (isRGB2IHS() || isRGB2HLS())
1087  inputRaster = getRRaster();
1088  else if (isIHS2RGB())
1089  inputRaster = getIRaster();
1090  else if (isHLS2RGB())
1091  inputRaster = getHRaster();
1092  else
1093  return nullptr;
1094 
1095  std::map<std::string, std::string> info;
1096  info["MEM_RASTER_NROWS"] = boost::lexical_cast<std::string>(inputRaster->getNumberOfRows());
1097  info["MEM_RASTER_NCOLS"] = boost::lexical_cast<std::string>(inputRaster->getNumberOfColumns());
1098  info["MEM_RASTER_DATATYPE"] = boost::lexical_cast<std::string>(inputRaster->getBandDataType(0));
1099  info["MEM_RASTER_NBANDS"] = boost::lexical_cast<std::string>(inputRaster->getNumberOfBands());
1100 
1101  //get input bands info
1102  std::vector<te::rst::BandProperty*> bands;
1103 
1104  for (std::size_t t = 0; t < 3; ++t)
1105  {
1106  te::rst::BandProperty* bProp = new te::rst::BandProperty(*inputRaster->getBand(0)->getProperty());
1107 
1108  bProp->m_type = dataType;
1109 
1110  bands.push_back(bProp);
1111 
1112  if (t >= 2)
1113  break;
1114  }
1115 
1116  //get input grid
1117  te::rst::Grid* grid = new te::rst::Grid(*inputRaster->getGrid());
1118 
1119  //build output raster
1120  rasterOut = te::rst::RasterFactory::make(type, grid, bands, info);
1121 
1122  return rasterOut;
1123 }
1124 
1126 {
1127  //colorTransform types
1128  m_ui->m_colorTransformTypeComboBox->clear();
1129 
1130  m_ui->m_colorTransformTypeComboBox->addItem(tr("RGB - IHS"), COLORTRANSFORM_RGB2IHS);
1131  m_ui->m_colorTransformTypeComboBox->addItem(tr("IHS - RGB"), COLORTRANSFORM_IHS2RGB);
1132  m_ui->m_colorTransformTypeComboBox->addItem(tr("RGB - HLS"), COLORTRANSFORM_RGB2HLS);
1133  m_ui->m_colorTransformTypeComboBox->addItem(tr("HLS - RGB"), COLORTRANSFORM_HLS2RGB);
1134 }
1135 
1137 {
1138  QVariant varLayer;
1139  if (m_ui->m_colorTransformTypeComboBox->currentIndex() == 0)
1140  varLayer = m_ui->m_rgbRComboBox->itemData(m_ui->m_rgbRComboBox->currentIndex(), Qt::UserRole);
1141  else
1142  varLayer = m_ui->m_rgb2hlsRComboBox->itemData(m_ui->m_rgb2hlsRComboBox->currentIndex(), Qt::UserRole);
1143 
1145  std::unique_ptr<te::da::DataSet> ds = l->getData();
1146  std::size_t rpos = te::da::GetFirstPropertyPos(ds.get(), te::dt::RASTER_TYPE);
1147 
1148  return ds->getRaster(rpos).release();
1149 }
1150 
1152 {
1153  QVariant varLayer;
1154  if (m_ui->m_colorTransformTypeComboBox->currentIndex() == 0)
1155  varLayer = m_ui->m_rgbGComboBox->itemData(m_ui->m_rgbGComboBox->currentIndex(), Qt::UserRole);
1156  else
1157  varLayer = m_ui->m_rgb2hlsGComboBox->itemData(m_ui->m_rgb2hlsGComboBox->currentIndex(), Qt::UserRole);
1158 
1160  std::unique_ptr<te::da::DataSet> ds = l->getData();
1161  std::size_t rpos = te::da::GetFirstPropertyPos(ds.get(), te::dt::RASTER_TYPE);
1162 
1163  return ds->getRaster(rpos).release();
1164 }
1165 
1167 {
1168  QVariant varLayer;
1169  if (m_ui->m_colorTransformTypeComboBox->currentIndex() == 0)
1170  varLayer = m_ui->m_rgbBComboBox->itemData(m_ui->m_rgbBComboBox->currentIndex(), Qt::UserRole);
1171  else
1172  varLayer = m_ui->m_rgb2hlsBComboBox->itemData(m_ui->m_rgb2hlsBComboBox->currentIndex(), Qt::UserRole);
1173 
1175  std::unique_ptr<te::da::DataSet> ds = l->getData();
1176  std::size_t rpos = te::da::GetFirstPropertyPos(ds.get(), te::dt::RASTER_TYPE);
1177 
1178  return ds->getRaster(rpos).release();
1179 }
1180 
1182 {
1183  QVariant varLayer = m_ui->m_ihsIComboBox->itemData(m_ui->m_ihsIComboBox->currentIndex(), Qt::UserRole);
1185  std::unique_ptr<te::da::DataSet> ds = l->getData();
1186  std::size_t rpos = te::da::GetFirstPropertyPos(ds.get(), te::dt::RASTER_TYPE);
1187 
1188  return ds->getRaster(rpos).release();
1189 }
1190 
1192 {
1193  QVariant varLayer;
1194  if (m_ui->m_colorTransformTypeComboBox->currentIndex() == 1)
1195  varLayer = m_ui->m_ihsHComboBox->itemData(m_ui->m_ihsHComboBox->currentIndex(), Qt::UserRole);
1196  else
1197  varLayer = m_ui->m_hlsHComboBox->itemData(m_ui->m_hlsHComboBox->currentIndex(), Qt::UserRole);
1198 
1200  std::unique_ptr<te::da::DataSet> ds = l->getData();
1201  std::size_t rpos = te::da::GetFirstPropertyPos(ds.get(), te::dt::RASTER_TYPE);
1202 
1203  return ds->getRaster(rpos).release();
1204 }
1205 
1207 {
1208  QVariant varLayer;
1209  if (m_ui->m_colorTransformTypeComboBox->currentIndex() == 1)
1210  varLayer = m_ui->m_ihsSComboBox->itemData(m_ui->m_ihsSComboBox->currentIndex(), Qt::UserRole);
1211  else
1212  varLayer = m_ui->m_hlsSComboBox->itemData(m_ui->m_hlsSComboBox->currentIndex(), Qt::UserRole);
1213 
1215  std::unique_ptr<te::da::DataSet> ds = l->getData();
1216  std::size_t rpos = te::da::GetFirstPropertyPos(ds.get(), te::dt::RASTER_TYPE);
1217 
1218  return ds->getRaster(rpos).release();
1219 }
1220 
1222 {
1223  QVariant varLayer = m_ui->m_hlsLComboBox->itemData(m_ui->m_hlsLComboBox->currentIndex(), Qt::UserRole);
1225  std::unique_ptr<te::da::DataSet> ds = l->getData();
1226  std::size_t rpos = te::da::GetFirstPropertyPos(ds.get(), te::dt::RASTER_TYPE);
1227 
1228  return ds->getRaster(rpos).release();
1229 }
1230 
1232 {
1233  int nbits = 8;
1234 
1235  switch (index)
1236  {
1237  case 1:
1238  nbits = 10;
1239  break;
1240 
1241  case 2:
1242  nbits = 16;
1243  break;
1244 
1245  case 3:
1246  nbits = 24;
1247  break;
1248 
1249  case 4:
1250  nbits = 32;
1251  break;
1252 
1253  default:
1254  break;
1255  }
1256 
1257  return nbits;
1258 }
1259 
1260 void te::qt::widgets::ColorTransformDialog::getRasterBands(QComboBox* layer, int index, QComboBox* band)
1261 {
1262  //get layer
1263  QVariant varLayer = layer->itemData(index, Qt::UserRole);
1265 
1266  //get raster
1267  std::unique_ptr<te::da::DataSet> ds = l->getData();
1268  std::size_t rpos = te::da::GetFirstPropertyPos(ds.get(), te::dt::RASTER_TYPE);
1269  std::unique_ptr<te::rst::Raster> rst = ds->getRaster(rpos);
1270 
1271  //fill band info
1272  if(rst.get())
1273  {
1274  band->clear();
1275 
1276  for(std::size_t t = 0; t < rst->getNumberOfBands(); ++t)
1277  band->addItem(QString::number(t));
1278  }
1279 }
1280 
1282 {
1284  {
1285  QApplication::setOverrideCursor(Qt::WaitCursor);
1286 
1288 
1289  // verify if is necessary convert the raster to the given srid
1290  bool needRemap = false;
1291  if ((m_mapDisplay->getSRID() != TE_UNKNOWN_SRS) && (m_layerR->getSRID() != TE_UNKNOWN_SRS) && (m_mapDisplay->getSRID() != m_layerR->getSRID()))
1292  needRemap = true;
1293 
1294  // create a SRS converter
1295  std::unique_ptr<te::srs::Converter> converter(new te::srs::Converter());
1296 
1297  if (needRemap)
1298  {
1299  converter->setSourceSRID(m_mapDisplay->getSRID());
1300  converter->setTargetSRID(m_layerR->getSRID());
1301 
1302  converter->convert(env->getLowerLeftX(), env->getLowerLeftY(), env->m_llx, env->m_lly);
1303  converter->convert(env->getUpperRightX(), env->getUpperRightY(), env->m_urx, env->m_ury);
1304  }
1305 
1306  std::unique_ptr<te::da::DataSetType> dsType = m_layerR->getSchema();
1307  te::rst::RasterProperty* rasterProp = te::da::GetFirstRasterProperty(dsType.get());
1308  std::unique_ptr<te::da::DataSet> dsRasterR = m_layerR->getData();
1309  std::unique_ptr<te::rst::Raster> rasterR = dsRasterR->getRaster(rasterProp->getName());
1310 
1311  std::unique_ptr<te::da::DataSet> dsRasterG = m_layerG->getData();
1312  std::unique_ptr<te::rst::Raster> rasterG = dsRasterG->getRaster(rasterProp->getName());
1313 
1314  std::unique_ptr<te::da::DataSet> dsRasterB = m_layerB->getData();
1315  std::unique_ptr<te::rst::Raster> rasterB = dsRasterB->getRaster(rasterProp->getName());
1316 
1317  std::map<std::string, std::string> info;
1318  info["FORCE_MEM_DRIVER"] = "TRUE";
1319  //execute clipping
1320  m_rasterRPreview = rasterR->trim(env, info);
1321  m_rasterGPreview = rasterG->trim(env, info);
1322  m_rasterBPreview = rasterB->trim(env, info);
1323 
1324  applyPreview();
1325 
1326  QApplication::restoreOverrideCursor();
1327  }
1328 }
1329 
1331 {
1333  return;
1334 
1335  if (isRGB2IHS())
1337  else if (isIHS2RGB())
1339  else if (isRGB2HLS())
1341  else if (isHLS2RGB())
1343 }
1344 
1346 {
1347  //progress
1349 
1350  QApplication::setOverrideCursor(Qt::WaitCursor);
1351 
1352  //check output data type
1353  int dataType = te::dt::FLOAT_TYPE;
1354 
1355  //get output raster info
1356  std::string type = "MEM";
1357  std::map<std::string, std::string> info;
1358  info["MEM_RASTER_NROWS"] = boost::lexical_cast<std::string>(m_rasterRPreview->getNumberOfRows());
1359  info["MEM_RASTER_NCOLS"] = boost::lexical_cast<std::string>(m_rasterRPreview->getNumberOfColumns());
1360  info["MEM_RASTER_DATATYPE"] = dataType;
1361  info["MEM_RASTER_NBANDS"] = boost::lexical_cast<std::string>(m_rasterRPreview->getNumberOfBands());
1362 
1363  //get input bands info
1364  std::vector<te::rst::BandProperty*> bands;
1365 
1366  for (std::size_t t = 0; t < 3; ++t)
1367  {
1369 
1370  bProp->m_type = dataType;
1371 
1372  bands.push_back(bProp);
1373  }
1374 
1375  //get input grid
1377 
1378  //build output raster
1379  te::rst::Raster* outputRaster = te::rst::RasterFactory::make(type, grid, bands, info);
1380 
1381  if (!outputRaster)
1382  {
1383  QApplication::restoreOverrideCursor();
1384 
1385  return;
1386  }
1387 
1388  unsigned int rBand = m_ui->m_rgbRBandComboBox->currentText().toUInt();
1389  unsigned int gBand = m_ui->m_rgbGBandComboBox->currentText().toUInt();
1390  unsigned int bBand = m_ui->m_rgbBBandComboBox->currentText().toUInt();
1391 
1392  int nbits = getNBits(m_ui->m_rgb2ihsNbitsComboBox->currentIndex());
1393  double minValue = 0;
1394 
1395  //get data type range
1396  double maxValue = (double)(pow(2.0, (double)nbits)) - 1;
1397 
1398  bool res = te::rp::ConvertRGB2IHS(*m_rasterRPreview, rBand, *m_rasterGPreview, gBand, *m_rasterBPreview, bBand, minValue, maxValue, *outputRaster);
1399 
1400  if (!res)
1401  {
1402  QApplication::restoreOverrideCursor();
1403 
1404  QMessageBox::critical(this, tr("Color Transform"), tr("Color Transform execution error.") + (" " + te::rp::Module::getLastLogStr()).c_str());
1405  return;
1406  }
1407 
1408  std::vector< boost::shared_ptr< te::rst::Raster > > outputRastersPtrs;
1409 
1410  if (!m_ui->m_newROIRToolButton->isChecked() || !m_ui->m_newROIGToolButton->isChecked() || !m_ui->m_newROIBToolButton->isChecked())
1411  {
1412  std::vector< std::map<std::string, std::string> > outputRastersInfos;
1413 
1414  for (std::size_t t = 0; t < 3; ++t)
1415  {
1416  outputRastersInfos.push_back(info);
1417  }
1418 
1419  std::vector<unsigned int> rasterBands;
1420  rasterBands.push_back(0);
1421  rasterBands.push_back(1);
1422  rasterBands.push_back(2);
1423 
1424  //get output raster info
1425  std::string type = "MEM";
1426 
1427  //decompose bands
1428  res = te::rp::DecomposeBands(*outputRaster, rasterBands, outputRastersInfos, type, outputRastersPtrs);
1429  }
1430 
1431  QApplication::restoreOverrideCursor();
1432 
1433  if (res)
1434  {
1435  te::dt::AbstractData* abs = nullptr;
1436 
1437  if (m_ui->m_newROIRToolButton->isChecked() && m_ui->m_newROIGToolButton->isChecked() && m_ui->m_newROIBToolButton->isChecked())
1438  abs = outputRaster->clone();
1439  else if (m_ui->m_newROIRToolButton->isChecked())
1440  abs = outputRastersPtrs[0]->clone();
1441  else if (m_ui->m_newROIGToolButton->isChecked())
1442  abs = outputRastersPtrs[1]->clone();
1443  else if (m_ui->m_newROIBToolButton->isChecked())
1444  abs = outputRastersPtrs[2]->clone();
1445 
1446  te::rst::Raster* rst = static_cast<te::rst::Raster*>(abs);
1447 
1448  m_rasterPreview = rst;
1449 
1451  }
1452  else
1453  {
1454  QMessageBox::critical(this, tr("Color Transform"), tr("Color Transform execution error.") + (" " + te::rp::Module::getLastLogStr()).c_str());
1455  }
1456 
1457  delete outputRaster;
1458 }
1459 
1461 {
1462  //progress
1464 
1465  QApplication::setOverrideCursor(Qt::WaitCursor);
1466 
1467  //check output data type
1468  int dataType = te::dt::UCHAR_TYPE;
1469 
1470  int nbits = getNBits(m_ui->m_ihs2rgbNbitsComboBox->currentIndex());
1471 
1472  if (nbits == 10 || nbits == 16)
1473  dataType = te::dt::UINT16_TYPE;
1474  else if (nbits == 24 || nbits == 32)
1475  dataType = te::dt::UINT32_TYPE;
1476 
1477  //get output raster info
1478  std::string type = "MEM";
1479  std::map<std::string, std::string> info;
1480  info["MEM_RASTER_NROWS"] = boost::lexical_cast<std::string>(m_rasterRPreview->getNumberOfRows());
1481  info["MEM_RASTER_NCOLS"] = boost::lexical_cast<std::string>(m_rasterRPreview->getNumberOfColumns());
1482  info["MEM_RASTER_DATATYPE"] = dataType;
1483  info["MEM_RASTER_NBANDS"] = boost::lexical_cast<std::string>(m_rasterRPreview->getNumberOfBands());
1484 
1485  //get input bands info
1486  std::vector<te::rst::BandProperty*> bands;
1487 
1488  for (std::size_t t = 0; t < 3; ++t)
1489  {
1491 
1492  bProp->m_type = dataType;
1493 
1494  bands.push_back(bProp);
1495  }
1496 
1497  //get input grid
1499 
1500  //build output raster
1501  te::rst::Raster* outputRaster = te::rst::RasterFactory::make(type, grid, bands, info);
1502 
1503  if (!outputRaster)
1504  {
1505  QApplication::restoreOverrideCursor();
1506 
1507  return;
1508  }
1509 
1510  unsigned int iBand = m_ui->m_ihsIBandComboBox->currentText().toUInt();
1511  unsigned int hBand = m_ui->m_ihsHBandComboBox->currentText().toUInt();
1512  unsigned int sBand = m_ui->m_ihsSBandComboBox->currentText().toUInt();
1513 
1514  double minValue = 0;
1515 
1516  //get data type range
1517  double maxValue = (double)(pow(2.0, (double)nbits)) - 1;
1518 
1519  bool res = te::rp::ConvertIHS2RGB(*m_rasterRPreview, iBand, *m_rasterGPreview, hBand, *m_rasterBPreview, sBand, minValue, maxValue, *outputRaster);
1520 
1521  if (!res)
1522  {
1523  QApplication::restoreOverrideCursor();
1524 
1525  QMessageBox::critical(this, tr("Color Transform"), tr("Color Transform execution error.") + (" " + te::rp::Module::getLastLogStr()).c_str());
1526  return;
1527  }
1528 
1529  std::vector< boost::shared_ptr< te::rst::Raster > > outputRastersPtrs;
1530 
1531  if (!m_ui->m_newROIIToolButton->isChecked() || !m_ui->m_newROIHToolButton->isChecked() || !m_ui->m_newROISToolButton->isChecked())
1532  {
1533  std::vector< std::map<std::string, std::string> > outputRastersInfos;
1534 
1535  for (std::size_t t = 0; t < 3; ++t)
1536  {
1537  outputRastersInfos.push_back(info);
1538  }
1539 
1540  std::vector<unsigned int> rasterBands;
1541  rasterBands.push_back(0);
1542  rasterBands.push_back(1);
1543  rasterBands.push_back(2);
1544 
1545  //get output raster info
1546  std::string type = "MEM";
1547 
1548  //decompose bands
1549  res = te::rp::DecomposeBands(*outputRaster, rasterBands, outputRastersInfos, type, outputRastersPtrs);
1550  }
1551 
1552  QApplication::restoreOverrideCursor();
1553 
1554  if (res)
1555  {
1556  te::dt::AbstractData* abs = nullptr;
1557 
1558  if (m_ui->m_newROIIToolButton->isChecked() && m_ui->m_newROIHToolButton->isChecked() && m_ui->m_newROISToolButton->isChecked())
1559  abs = outputRaster->clone();
1560  else if (m_ui->m_newROIIToolButton->isChecked())
1561  abs = outputRastersPtrs[0]->clone();
1562  else if (m_ui->m_newROIHToolButton->isChecked())
1563  abs = outputRastersPtrs[1]->clone();
1564  else if (m_ui->m_newROISToolButton->isChecked())
1565  abs = outputRastersPtrs[2]->clone();
1566 
1567  te::rst::Raster* rst = static_cast<te::rst::Raster*>(abs);
1568 
1569  m_rasterPreview = rst;
1570 
1572  }
1573  else
1574  {
1575  QMessageBox::critical(this, tr("Color Transform"), tr("Color Transform execution error.") + (" " + te::rp::Module::getLastLogStr()).c_str());
1576  }
1577 
1578  delete outputRaster;
1579 }
1580 
1582 {
1583  //progress
1585 
1586  QApplication::setOverrideCursor(Qt::WaitCursor);
1587 
1588  //check output data type
1589  int dataType = te::dt::FLOAT_TYPE;
1590 
1591  //get output raster info
1592  std::string type = "MEM";
1593  std::map<std::string, std::string> info;
1594  info["MEM_RASTER_NROWS"] = boost::lexical_cast<std::string>(m_rasterRPreview->getNumberOfRows());
1595  info["MEM_RASTER_NCOLS"] = boost::lexical_cast<std::string>(m_rasterRPreview->getNumberOfColumns());
1596  info["MEM_RASTER_DATATYPE"] = dataType;
1597  info["MEM_RASTER_NBANDS"] = boost::lexical_cast<std::string>(m_rasterRPreview->getNumberOfBands());
1598 
1599  //get input bands info
1600  std::vector<te::rst::BandProperty*> bands;
1601 
1602  for (std::size_t t = 0; t < 3; ++t)
1603  {
1605 
1606  bProp->m_type = dataType;
1607 
1608  bands.push_back(bProp);
1609  }
1610 
1611  //get input grid
1613 
1614  //build output raster
1615  te::rst::Raster* outputRaster = te::rst::RasterFactory::make(type, grid, bands, info);
1616 
1617  if (!outputRaster)
1618  {
1619  QApplication::restoreOverrideCursor();
1620 
1621  return;
1622  }
1623 
1624  unsigned int rBand = m_ui->m_rgb2hlsRBandComboBox->currentText().toUInt();
1625  unsigned int gBand = m_ui->m_rgb2hlsGBandComboBox->currentText().toUInt();
1626  unsigned int bBand = m_ui->m_rgb2hlsBBandComboBox->currentText().toUInt();
1627 
1628  int nbits = getNBits(m_ui->m_rgb2hlsNbitsComboBox->currentIndex());
1629  double minValue = 0;
1630 
1631  //get data type range
1632  double maxValue = (double)(pow(2.0, (double)nbits)) - 1;
1633 
1634  bool res = te::rp::ConvertRGB2HLS(*m_rasterRPreview, rBand, *m_rasterGPreview, gBand, *m_rasterBPreview, bBand, minValue, maxValue, *outputRaster);
1635 
1636  if (!res)
1637  {
1638  QApplication::restoreOverrideCursor();
1639 
1640  QMessageBox::critical(this, tr("Color Transform"), tr("Color Transform execution error.") + (" " + te::rp::Module::getLastLogStr()).c_str());
1641  return;
1642  }
1643 
1644  std::vector< boost::shared_ptr< te::rst::Raster > > outputRastersPtrs;
1645 
1646  if (!m_ui->m_newROIRedToolButton->isChecked() || !m_ui->m_newROIGreenToolButton->isChecked() || !m_ui->m_newROIBlueToolButton->isChecked())
1647  {
1648  std::vector< std::map<std::string, std::string> > outputRastersInfos;
1649 
1650  for (std::size_t t = 0; t < 3; ++t)
1651  {
1652  outputRastersInfos.push_back(info);
1653  }
1654 
1655  std::vector<unsigned int> rasterBands;
1656  rasterBands.push_back(0);
1657  rasterBands.push_back(1);
1658  rasterBands.push_back(2);
1659 
1660  //get output raster info
1661  std::string type = "MEM";
1662 
1663  //decompose bands
1664  res = te::rp::DecomposeBands(*outputRaster, rasterBands, outputRastersInfos, type, outputRastersPtrs);
1665  }
1666 
1667  QApplication::restoreOverrideCursor();
1668 
1669  if (res)
1670  {
1671  te::dt::AbstractData* abs = nullptr;
1672 
1673  if (m_ui->m_newROIRedToolButton->isChecked() && m_ui->m_newROIGreenToolButton->isChecked() && m_ui->m_newROIBlueToolButton->isChecked())
1674  abs = outputRaster->clone();
1675  else if (m_ui->m_newROIRedToolButton->isChecked())
1676  abs = outputRastersPtrs[0]->clone();
1677  else if (m_ui->m_newROIGreenToolButton->isChecked())
1678  abs = outputRastersPtrs[1]->clone();
1679  else if (m_ui->m_newROIBlueToolButton->isChecked())
1680  abs = outputRastersPtrs[2]->clone();
1681 
1682  te::rst::Raster* rst = static_cast<te::rst::Raster*>(abs);
1683 
1684  m_rasterPreview = rst;
1685 
1687  }
1688  else
1689  {
1690  QMessageBox::critical(this, tr("Color Transform"), tr("Color Transform execution error.") + (" " + te::rp::Module::getLastLogStr()).c_str());
1691  }
1692 
1693  delete outputRaster;
1694 }
1695 
1697 {
1698  //progress
1700 
1701  QApplication::setOverrideCursor(Qt::WaitCursor);
1702 
1703  //check output data type
1704  int dataType = te::dt::UCHAR_TYPE;
1705 
1706  int nbits = getNBits(m_ui->m_hls2rgbNbitsComboBox->currentIndex());
1707 
1708  if (nbits == 10 || nbits == 16)
1709  dataType = te::dt::UINT16_TYPE;
1710  else if (nbits == 24 || nbits == 32)
1711  dataType = te::dt::UINT32_TYPE;
1712 
1713  //get output raster info
1714  std::string type = "MEM";
1715  std::map<std::string, std::string> info;
1716  info["MEM_RASTER_NROWS"] = boost::lexical_cast<std::string>(m_rasterRPreview->getNumberOfRows());
1717  info["MEM_RASTER_NCOLS"] = boost::lexical_cast<std::string>(m_rasterRPreview->getNumberOfColumns());
1718  info["MEM_RASTER_DATATYPE"] = dataType;
1719  info["MEM_RASTER_NBANDS"] = boost::lexical_cast<std::string>(m_rasterRPreview->getNumberOfBands());
1720 
1721  //get input bands info
1722  std::vector<te::rst::BandProperty*> bands;
1723 
1724  for (std::size_t t = 0; t < 3; ++t)
1725  {
1727 
1728  bProp->m_type = dataType;
1729 
1730  bands.push_back(bProp);
1731  }
1732 
1733  //get input grid
1735 
1736  //build output raster
1737  te::rst::Raster* outputRaster = te::rst::RasterFactory::make(type, grid, bands, info);
1738 
1739  if (!outputRaster)
1740  {
1741  QApplication::restoreOverrideCursor();
1742 
1743  return;
1744  }
1745 
1746  unsigned int hBand = m_ui->m_hlsHBandComboBox->currentText().toUInt();
1747  unsigned int lBand = m_ui->m_hlsLBandComboBox->currentText().toUInt();
1748  unsigned int sBand = m_ui->m_hlsSBandComboBox->currentText().toUInt();
1749 
1750  double minValue = 0;
1751 
1752  //get data type range
1753  double maxValue = (double)(pow(2.0, (double)nbits)) - 1;
1754 
1755  bool res = te::rp::ConvertHLS2RGB(*m_rasterRPreview, hBand, *m_rasterGPreview, lBand, *m_rasterBPreview, sBand, minValue, maxValue, *outputRaster);
1756 
1757  if (!res)
1758  {
1759  QApplication::restoreOverrideCursor();
1760 
1761  QMessageBox::critical(this, tr("Color Transform"), tr("Color Transform execution error.") + (" " + te::rp::Module::getLastLogStr()).c_str());
1762  return;
1763  }
1764 
1765  std::vector< boost::shared_ptr< te::rst::Raster > > outputRastersPtrs;
1766 
1767  if (!m_ui->m_newROIHueToolButton->isChecked() || !m_ui->m_newROILightToolButton->isChecked() || !m_ui->m_newROISatToolButton->isChecked())
1768  {
1769  std::vector< std::map<std::string, std::string> > outputRastersInfos;
1770 
1771  for (std::size_t t = 0; t < 3; ++t)
1772  {
1773  outputRastersInfos.push_back(info);
1774  }
1775 
1776  std::vector<unsigned int> rasterBands;
1777  rasterBands.push_back(0);
1778  rasterBands.push_back(1);
1779  rasterBands.push_back(2);
1780 
1781  //get output raster info
1782  std::string type = "MEM";
1783 
1784  //decompose bands
1785  res = te::rp::DecomposeBands(*outputRaster, rasterBands, outputRastersInfos, type, outputRastersPtrs);
1786  }
1787 
1788  QApplication::restoreOverrideCursor();
1789 
1790  if (res)
1791  {
1792  te::dt::AbstractData* abs = nullptr;
1793 
1794  if (m_ui->m_newROIHueToolButton->isChecked() && m_ui->m_newROILightToolButton->isChecked() && m_ui->m_newROISatToolButton->isChecked())
1795  abs = outputRaster->clone();
1796  else if (m_ui->m_newROIHueToolButton->isChecked())
1797  abs = outputRastersPtrs[0]->clone();
1798  else if (m_ui->m_newROILightToolButton->isChecked())
1799  abs = outputRastersPtrs[1]->clone();
1800  else if (m_ui->m_newROISatToolButton->isChecked())
1801  abs = outputRastersPtrs[2]->clone();
1802 
1803  te::rst::Raster* rst = static_cast<te::rst::Raster*>(abs);
1804 
1805  m_rasterPreview = rst;
1806 
1808  }
1809  else
1810  {
1811  QMessageBox::critical(this, tr("Color Transform"), tr("Color Transform execution error.") + (" " + te::rp::Module::getLastLogStr()).c_str());
1812  }
1813 
1814  delete outputRaster;
1815 }
1816 
1818 {
1819  QApplication::setOverrideCursor(Qt::WaitCursor);
1820 
1821  const te::gm::Envelope& envRaster = *raster->getExtent();
1822  const te::gm::Envelope& env = m_mapDisplay->getExtent();
1823 
1825 
1826  te::se::CoverageStyle* cs = dynamic_cast<te::se::CoverageStyle*>(style);
1827  assert(cs);
1828 
1829  te::qt::widgets::Canvas* canvasInstance = new Canvas(m_mapDisplay->width(), m_mapDisplay->height());
1830  canvasInstance->setDevice(m_mapDisplay->getDraftPixmap(), false);
1831  canvasInstance->setWindow(env.m_llx, env.m_lly, env.m_urx, env.m_ury);
1832 
1833  canvasInstance->setPolygonContourWidth(2);
1834  canvasInstance->setPolygonContourColor(te::color::RGBAColor(100, 177, 216, TE_OPAQUE));
1835  canvasInstance->setPolygonFillColor(te::color::RGBAColor(100, 177, 216, 0));
1836 
1837  for(std::size_t b = 0; b < raster->getNumberOfBands(); ++b)
1838  {
1841  const std::complex<double>* cmin = rsMin->at(b).m_minVal;
1842  const std::complex<double>* cmax = rsMax->at(b).m_maxVal;
1843  double min = cmin->real();
1844  double max = cmax->real();
1845 
1846  raster->getBand(static_cast<unsigned long>(b))->getProperty()->m_min = min;
1847  raster->getBand(static_cast<unsigned long>(b))->getProperty()->m_max = max;
1848  }
1849 
1850  // Draw raster
1851  bool cancel = false;
1852  te::map::DrawRaster(raster, canvasInstance, envRaster, raster->getSRID(), env, m_mapDisplay->getSRID(), cs, nullptr, m_mapDisplay->getScale(), &cancel);
1853 
1854  if (!m_geom || !m_geom->isValid())
1855  return;
1856 
1857  canvasInstance->draw(m_geom);
1858 
1859  m_mapDisplay->repaint();
1860 
1861  delete canvasInstance;
1862  delete style;
1863 
1864  QApplication::restoreOverrideCursor();
1865 }
1866 
1868 {
1869  if (!m_geom || !m_geom->isValid())
1870  return;
1871 
1872  const te::gm::Envelope& env = m_mapDisplay->getExtent();
1873 
1875  canvasInstance.setWindow(env.m_llx, env.m_lly, env.m_urx, env.m_ury);
1876 
1877  canvasInstance.setPolygonContourWidth(2);
1878  canvasInstance.setPolygonContourColor(te::color::RGBAColor(100, 177, 216, TE_OPAQUE));
1879 
1880  canvasInstance.draw(m_geom);
1881 
1882  m_mapDisplay->repaint();
1883 }
1884 
1886 {
1888 
1889  canvasInstance.clear();
1890 
1891  m_mapDisplay->repaint();
1892 }
1893 
1895 {
1896  clearCanvas();
1897 
1898  emit closeTool();
1899 }
1900 
1902 {
1903  m_mapDisplay = mapDisplay;
1904 }
virtual void setCurrentTool(te::qt::widgets::AbstractTool *tool, const bool &delPrevious=true)
Updates the current tool being used on te::qt::widgets::MapDisplay.
te::gm::Envelope * getExtent()
Returns the geographic extension of the raster data.
TEDATAACCESSEXPORT te::rst::RasterProperty * GetFirstRasterProperty(const DataSetType *dt)
void setMapDisplay(te::qt::widgets::MapDisplay *mapDisplay)
void clear()
It clears the canvas content and fills with the background color.
unsigned int band
void setDevice(QPaintDevice *device, bool takeOwnerShip)
It sets new device as QPrinter.
bool intersects(const Envelope &rhs) const
It returns true if the envelopes "spatially intersects".
The Style defines the styling that is to be applied to a geographic dataset (vector geometries or cov...
Definition: Style.h:65
Q_DECLARE_METATYPE(te::map::AbstractLayerPtr) te
#define TE_UNKNOWN_SRS
A numeric value to represent a unknown SRS identification in TerraLib.
A raster band description.
Definition: BandProperty.h:61
unsigned int getNumberOfColumns() const
Returns the raster number of columns.
void addLayer(te::map::AbstractLayerPtr layer)
std::unique_ptr< Ui::ColorTransformDialogForm > m_ui
GeomType getGeomTypeId() const _NOEXCEPT_OP(true)
It returns the geometry subclass type identifier.
The CoverageStyle defines the styling that is to be applied to a subset of Coverage data...
Definition: CoverageStyle.h:45
virtual Raster * trim(const te::gm::Envelope *env, const std::map< std::string, std::string > &rinfo) const
Subsetting operation for trimming (cropping) the raster.
const double & getUpperRightX() const
It returns a constant refernce to the x coordinate of the upper right corner.
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.
TESEEXPORT Style * CreateCoverageStyle(const std::vector< te::rst::BandProperty * > &properties)
Try creates an appropriate coverage style based on given band properties.
double m_min
Minimum pixel value (default is std::numeric_limits<double>::max() which means no value set)...
Definition: BandProperty.h:147
double m_urx
Upper right corner x-coordinate.
void setPolygonFillColor(const te::color::RGBAColor &color)
It sets the color used to fill the draw of polygon geometries.
virtual double getScale() const
Calculates and return the current scale.
#define TE_OPAQUE
For an RGBA color this is the value of the alpha-channel for totally opaque.
const double & getLowerLeftY() const
It returns a constant refernce to the y coordinate of the lower left corner.
void setPolygonContourColor(const te::color::RGBAColor &color)
It sets the pen color used to draw the boundary of polygon geometries.
A widget to control the display of a set of layers.
This class is a dialog for the LayerSearchWidget.
static te::dt::Date ds(2010, 01, 01)
int m_type
The data type of the elements in the band ( See te::dt namespace basic data types for reference )...
Definition: BandProperty.h:133
const double & getUpperRightY() const
It returns a constant refernce to the x coordinate of the upper right corner.
#define TE_TR(message)
It marks a string in order to get translated.
Definition: Translator.h:242
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.
void draw(const te::gm::Geometry *geom)
It draws the geometry on canvas.
double m_max
Maximum pixel value (default is std::numeric_limits<double>::max() which means no value set)...
Definition: BandProperty.h:148
static const std::string getLastLogStr()
Returns the last log string generated by this module.
te::qt::widgets::MapDisplay * m_mapDisplay
Raster property.
This class implements a concrete tool to define a boundary rectangle.
Definition: ExtentAcquire.h:50
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.
bool ConvertHLS2RGB(const te::rst::Raster &inputHLSRaster, const unsigned int hueBandIdx, const unsigned int lightBandIdx, const unsigned int saturationBandIdx, const double, const double rgbRangeMax, te::rst::Raster &outputRGBRaster)
HLS to RGB conversion.
int b
Definition: TsRtree.cpp:32
void setList(std::list< te::map::AbstractLayerPtr > &layerList)
TEMAPEXPORT void DrawRaster(te::da::DataSetType *type, te::da::DataSourcePtr ds, Canvas *canvas, const te::gm::Envelope &bbox, int bboxSRID, const te::gm::Envelope &visibleArea, int srid, te::se::CoverageStyle *style, te::map::RasterContrast *rc, const double &scale, bool *cancel)
void setWindow(const double &llx, const double &lly, const double &urx, const double &ury)
It sets the world (or window) coordinates area (supposing a cartesian reference system).
double m_llx
Lower left corner x-coordinate.
static RasterSummaryManager & getInstance()
It returns a reference to the singleton instance.
const Envelope * getMBR() const _NOEXCEPT_OP(true)
It returns the minimum bounding rectangle for the geometry in an internal representation.
virtual bool isValid() const _NOEXCEPT_OP(false)
It tells if the geometry is well formed.
An Envelope defines a 2D rectangular region.
An abstract class for raster data strucutures.
This file defines a class for a ColorTransform dialog.
unsigned int getNumberOfRows() const
Returns the raster number of rows.
virtual std::size_t getNumberOfBands() const =0
Returns the number of bands (dimension of cells attribute values) in the raster.
virtual int getSRID() const
It return the Spatial Reference System used by the Map Display.
BandProperty * getProperty()
Returns the band property.
URI C++ Library.
Definition: Attributes.h:37
virtual int getBandDataType(std::size_t i) const =0
Returns the data type in a particular band (or dimension).
void setPolygonContourWidth(int w)
It sets the polygon contour width.
list bands
Definition: compose.py:2
void drawPreview(te::rst::Raster *raster)
This class is used to set output layer.
virtual const te::gm::Envelope & getExtent() const
It returns the world extent showned by the MapDisplay.
boost::ptr_vector< BandSummary > RasterSummary
RasterSummary is just a typedef of a boost::ptr_vector.
Definition: RasterSummary.h:44
virtual AbstractData * clone() const =0
It returns a clone of this object.
A base class for values that can be retrieved from the data access module.
Definition: AbstractData.h:57
virtual const Band * getBand(std::size_t i) const =0
Returns the raster i-th band.
Grid * getGrid()
It returns the raster grid.
Utility functions for the data access module.
bool ConvertRGB2HLS(const te::rst::Raster &inputRGBRaster, const unsigned int redBandIdx, const unsigned int greenBandIdx, const unsigned int blueBandIdx, const double, const double rgbRangeMax, te::rst::Raster &outputHLSRaster)
RGB to HLS conversion.
std::list< te::map::AbstractLayerPtr > m_layerList
double m_lly
Lower left corner y-coordinate.
A Converter is responsible for the conversion of coordinates between different Coordinate Systems (CS...
Definition: Converter.h:53
TEMAPEXPORT te::rst::Raster * GetRaster(AbstractLayer *layer)
It gets the raster referenced by the given data set layer.
std::map< std::string, std::string > getInfo() const
int getSRID() const
Returns the raster spatial reference system identifier.
TEQTWIDGETSEXPORT te::map::AbstractLayerPtr createLayer(const std::string &driverName, const te::core::URI &connInfo)
virtual QPixmap * getDraftPixmap() const
It returns the map display draft pixmap.
double m_ury
Upper right corner y-coordinate.
static Raster * make()
It creates and returns an empty raster with default raster driver.
const double & getLowerLeftX() const
It returns a constant reference to the x coordinate of the lower left corner.
A helper class for 32-bit RGBA (Red-Green-Blue-Alpha channel) color.
Definition: RGBAColor.h:57
te::qt::widgets::OutputRasterWidget * m_outputWidget
TEDATAACCESSEXPORT std::size_t GetFirstPropertyPos(const te::da::DataSet *dataset, int datatype)
std::string Convert2String(boost::int16_t value)
It converts a short integer value to a string.
Definition: StringUtils.h:56
Calculate the min value.
A rectified grid is the spatial support for raster data.
Definition: raster/Grid.h:68
Calculate the max value.
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
void onEnvelopeAcquired(te::gm::Envelope env)
void getRasterBands(QComboBox *layer, int index, QComboBox *band)
bool isValid() const
It tells if the rectangle is valid or not.
TEQTWIDGETSEXPORT void applyRasterMultiResolution(const QString &toolName, te::rst::Raster *raster)
TEGEOMEXPORT Geometry * GetGeomFromEnvelope(const Envelope *const e, int srid)
It creates a Geometry (a polygon) from the given envelope.
const std::string & getName() const
It returns the property name.
Definition: Property.h:127