ContrastDialogForm.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/ContrastDialogForm.cpp
22 
23  \brief This file defines a class for a Contrast dialog.
24 */
25 
26 // TerraLib
27 #include "../../af/ApplicationController.h"
28 #include "../../../raster/Grid.h"
29 #include "../../../common/progress/ProgressManager.h"
30 #include "../../../common/StringUtils.h"
31 #include "../../../dataaccess/dataset/DataSet.h"
32 #include "../../../dataaccess/utils/Utils.h"
33 #include "../../../geometry/GeometryProperty.h"
34 #include "../../../geometry/Utils.h"
35 #include "../../../memory/DataSet.h"
36 #include "../../../memory/DataSetItem.h"
37 #include "../../../raster/Raster.h"
38 #include "../../../raster/RasterProperty.h"
39 #include "../../../raster/RasterSummaryManager.h"
40 #include "../../../raster/Utils.h"
41 #include "../../../maptools/Utils.h"
42 #include "../../../rp/Module.h"
43 #include "../../../qt/widgets/rp/Utils.h"
44 #include "../../../qt/widgets/utils/ScopedCursor.h"
45 #include "../../../se/CoverageStyle.h"
46 #include "../../../se/RasterSymbolizer.h"
47 #include "../../../se/Rule.h"
48 #include "../../../se/SelectedChannel.h"
49 #include "../../../se/Symbolizer.h"
50 #include "../../../se/Utils.h"
51 #include "../../af/ApplicationController.h"
52 #include "../../af/events/ApplicationEvents.h"
53 #include "../../af/events/LayerEvents.h"
54 #include "../../widgets/tools/ExtentAcquire.h"
55 #include "../canvas/Canvas.h"
56 #include "../progress/ProgressViewerDialog.h"
57 #include "Utils.h"
58 #include "ContrastDialogForm.h"
59 #include "RasterHistogramWidget.h"
60 #include "RasterNavigatorWidget.h"
61 #include "OutputRasterWidget.h"
62 #include "ui_ContrastDialogForm.h"
63 
64 // Qt
65 #include <QGridLayout>
66 #include <QMessageBox>
67 
68 // Boost
69 #include <boost/lexical_cast.hpp>
70 
71 //STL
72 #include <memory>
73 
75  : QDialog(parent),
76  m_ui(new Ui::ContrastDialogForm),
77  m_layer(nullptr),
78  m_outputWidget(nullptr),
79  m_mapDisplay(nullptr)
80 {
81  m_lastText = "";
82  m_updatePreview = false;
83  m_bandChecked = true;
84 
85 // setup controls
86  m_ui->setupUi(this);
87 
89 
90  //build histogram
91  QGridLayout* histogramLayout = new QGridLayout(m_ui->m_histWidget);
93  histogramLayout->addWidget(m_histogramWidget.get());
94  histogramLayout->setContentsMargins(0,0,0,0);
95 
96  QGridLayout* displayLayout = new QGridLayout(m_ui->m_navigatorWidget);
97  m_navigator.reset(new te::qt::widgets::RpToolsWidget(m_ui->m_navigatorWidget));
98  displayLayout->addWidget(m_navigator.get());
99  displayLayout->setContentsMargins(0, 0, 0, 0);
100 
101  m_ui->m_navigatorWidget->setEnabled(true);
102 
103  m_ui->m_resetToolButton->setIcon(QIcon::fromTheme("edit-undo"));
104 
105  //build output parameters
106  QGridLayout* outputLayout = new QGridLayout(m_ui->m_outputWidget);
107  outputLayout->setContentsMargins(0, 0, 0, 0);
109  outputLayout->addWidget(m_outputWidget);
110 
111 //connects
112  connect(m_ui->m_contrastTypeComboBox, SIGNAL(activated(int)), this, SLOT(onContrastTypeComboBoxActivated(int)));
113  connect(m_ui->m_bandTableWidget, SIGNAL(cellClicked(int, int)), this, SLOT(onCellClicked(int, int)));
114  connect(m_ui->m_bandTableWidget, SIGNAL(cellDoubleClicked(int, int)), this, SLOT(onCellDoubleClicked(int, int)));
115  connect(m_ui->m_bandTableWidget, SIGNAL(cellChanged(int, int)), this, SLOT(onCellChanged(int,int)));
116 
117  connect(m_ui->m_previewCheckBox, SIGNAL(toggled(bool)), this, SLOT(onPreviewCheckBoxToggled(bool)));
118  connect(m_ui->m_resetToolButton, SIGNAL(clicked()), this, SLOT(onResetValuesToolButtonClicked()));
119 
120  connect(m_ui->m_allImageRadioButton, SIGNAL(toggled(bool)), this, SLOT(onAllImageRadioButtonToggled(bool)));
121  connect(m_ui->m_visibleAreaRadioButton, SIGNAL(toggled(bool)), this, SLOT(onVisibleAreaRadioButtonToggled(bool)));
122  connect(m_ui->m_roiRadioButton, SIGNAL(toggled(bool)), this, SLOT(onRoiRadioButtonToggled(bool)));
123  connect(m_ui->m_okPushButton, SIGNAL(clicked()), this, SLOT(onOkPushButtonClicked()));
124  connect(m_navigator.get(), SIGNAL(envelopeAcquired(te::gm::Envelope)), this, SLOT(onEnvelopeAcquired(te::gm::Envelope)));
125 
126  m_ui->m_helpPushButton->setNameSpace("dpi.inpe.br.plugins");
127  m_ui->m_helpPushButton->setPageReference("plugins/rp/rp_contrast.html");
128 }
129 
131 
133 {
134  m_layer = layer;
135 
136  std::unique_ptr<te::rst::Raster> raster(te::map::GetRaster(m_layer.get()));
137 
138  m_minValue.clear();
139  m_maxValue.clear();
140 
141  for (std::size_t b = 0; b < raster->getNumberOfBands(); ++b)
142  {
145  const std::complex<double>* cmin = rsMin->at(b).m_minVal;
146  const std::complex<double>* cmax = rsMax->at(b).m_maxVal;
147  double min = cmin->real();
148  double max = cmax->real();
149 
150  m_minValue.push_back(min);
151  m_maxValue.push_back(max);
152  }
153 
154  if (raster->getBand(0)->getProperty()->getType() == te::dt::UCHAR_TYPE || raster->getBand(0)->getProperty()->getType() == te::dt::UINT16_TYPE ||
155  raster->getBand(0)->getProperty()->getType() == te::dt::UINT32_TYPE || raster->getBand(0)->getProperty()->getType() == te::dt::UINT64_TYPE)
156  {
157  connect(m_histogramWidget.get(), SIGNAL(minValueSelected(int, int)), this, SLOT(onMinValueSelected(int, int)));
158  connect(m_histogramWidget.get(), SIGNAL(maxValueSelected(int, int)), this, SLOT(onMaxValueSelected(int, int)));
159  }
160  else
161  {
162  connect(m_histogramWidget.get(), SIGNAL(minValueSelected(double, int)), this, SLOT(onMinValueSelected(double, int)));
163  connect(m_histogramWidget.get(), SIGNAL(maxValueSelected(double, int)), this, SLOT(onMaxValueSelected(double, int)));
164  }
165 
166  m_histogramWidget->setEnableNavigationTools(true);
167 
168  listBands();
169 }
170 
172 {
173  m_ui->m_roiRadioButton->setChecked(true);
174 }
175 
177 {
178  m_navigator->setMapDisplay(mapDisplay);
179  m_mapDisplay = mapDisplay;
180 }
181 
183 {
184  //configure tools
185  m_navigator->setActionGroup(actionGroup);
186  m_navigator->enableBoxAction();
187 }
188 
190 {
191  return m_outputLayer;
192 }
193 
195 {
196  return m_layer;
197 }
198 
200 {
201  //get contrast type
202  int index = m_ui->m_contrastTypeComboBox->currentIndex();
203  int contrastType = m_ui->m_contrastTypeComboBox->itemData(index).toInt();
204  int nBands = m_ui->m_bandTableWidget->rowCount();
205 
206  te::rp::Contrast::InputParameters algoInputParams;
207 
209  {
211 
212  for(int i = 0; i < nBands; ++i)
213  {
214  QCheckBox* bandCheckBox = (QCheckBox*)m_ui->m_bandTableWidget->cellWidget(i, 0);
215 
216  if(bandCheckBox->isChecked())
217  {
218  QTableWidgetItem* item = m_ui->m_bandTableWidget->item(i, 1);
219  QTableWidgetItem* item1 = m_ui->m_bandTableWidget->item(i, 2);
220 
221  if (item)
222  {
223  QString valueMin = item->text();
224  algoInputParams.m_lCMinInput.push_back(valueMin.toDouble());
225  }
226 
227  if (item1)
228  {
229  QString valueMax = item1->text();
230  algoInputParams.m_lCMaxInput.push_back(valueMax.toDouble());
231  }
232  }
233  }
234  }
236  {
238 
239  for(int i = 0; i < nBands; ++i)
240  {
241  QCheckBox* bandCheckBox = (QCheckBox*)m_ui->m_bandTableWidget->cellWidget(i, 0);
242 
243  if(bandCheckBox->isChecked())
244  {
245  QTableWidgetItem* item = m_ui->m_bandTableWidget->item(i, 1);
246 
247  if (item)
248  {
249  QString valueMax = item->text();
250  algoInputParams.m_hECMaxInput.push_back(valueMax.toDouble());
251  }
252  }
253  }
254  }
256  {
258 
259  for(int i = 0; i < nBands; ++i)
260  {
261  QCheckBox* bandCheckBox = (QCheckBox*)m_ui->m_bandTableWidget->cellWidget(i, 0);
262 
263  if(bandCheckBox->isChecked())
264  {
265  QTableWidgetItem* item = m_ui->m_bandTableWidget->item(i, 1);
266  QTableWidgetItem* item1 = m_ui->m_bandTableWidget->item(i, 2);
267 
268  if (item)
269  {
270  QString valueMean = item->text();
271  algoInputParams.m_sMASCMeanInput.push_back(valueMean.toDouble());
272  }
273 
274  if (item1)
275  {
276  QString valueStdDev = item1->text();
277  algoInputParams.m_sMASCStdInput.push_back(valueStdDev.toDouble());
278  }
279  }
280  }
281  }
283  {
285 
286  for(int i = 0; i < nBands; ++i)
287  {
288  QCheckBox* bandCheckBox = (QCheckBox*)m_ui->m_bandTableWidget->cellWidget(i, 0);
289 
290  if(bandCheckBox->isChecked())
291  {
292  QTableWidgetItem* item = m_ui->m_bandTableWidget->item(i, 1);
293  QTableWidgetItem* item1 = m_ui->m_bandTableWidget->item(i, 2);
294 
295  if (item)
296  {
297  QString valueMin = item->text();
298  algoInputParams.m_squareCMinInput.push_back(valueMin.toDouble());
299  }
300 
301  if (item1)
302  {
303  QString valueMax = item1->text();
304  algoInputParams.m_squareCMaxInput.push_back(valueMax.toDouble());
305  }
306  }
307  }
308  }
310  {
312 
313  for(int i = 0; i < nBands; ++i)
314  {
315  QCheckBox* bandCheckBox = (QCheckBox*)m_ui->m_bandTableWidget->cellWidget(i, 0);
316 
317  if(bandCheckBox->isChecked())
318  {
319  QTableWidgetItem* item = m_ui->m_bandTableWidget->item(i, 1);
320  QTableWidgetItem* item1 = m_ui->m_bandTableWidget->item(i, 2);
321 
322  if (item)
323  {
324  QString valueMin = item->text();
325  algoInputParams.m_squareRootCMinInput.push_back(valueMin.toDouble());
326  }
327 
328  if (item1)
329  {
330  QString valueMax = item1->text();
331  algoInputParams.m_squareRootCMaxInput.push_back(valueMax.toDouble());
332  }
333  }
334  }
335  }
336  else if(contrastType == te::rp::Contrast::InputParameters::LogContrastT)
337  {
339 
340  for(int i = 0; i < nBands; ++i)
341  {
342  QCheckBox* bandCheckBox = (QCheckBox*)m_ui->m_bandTableWidget->cellWidget(i, 0);
343 
344  if(bandCheckBox->isChecked())
345  {
346  QTableWidgetItem* item = m_ui->m_bandTableWidget->item(i, 1);
347 
348  if (item)
349  {
350  QString valueMin = item->text();
351  algoInputParams.m_logCMinInput.push_back(valueMin.toDouble());
352  }
353 
354  QTableWidgetItem* item1 = m_ui->m_bandTableWidget->item(i, 2);
355 
356  if (item1)
357  {
358  QString valueMax = item1->text();
359  algoInputParams.m_logCMaxInput.push_back(valueMax.toDouble());
360  }
361  }
362  }
363  }
365  {
367  }
368 
369  QVector<unsigned int> bandsSelected;
370 
371  for(int i = 0; i < nBands; ++i)
372  {
373  QCheckBox* bandCheckBox = (QCheckBox*)m_ui->m_bandTableWidget->cellWidget(i, 0);
374 
375  if(bandCheckBox->isChecked())
376  bandsSelected.push_back(i);
377  }
378 
379  if(!getChannelSelection()->getGrayChannel())
380  {
381  QString bRed = QString::fromStdString(getChannelSelection()->getRedChannel()->getSourceChannelName());
382 
383  QString bGreen = QString::fromStdString(getChannelSelection()->getGreenChannel()->getSourceChannelName());
384 
385  QString bBlue = QString::fromStdString(getChannelSelection()->getBlueChannel()->getSourceChannelName());
386 
387  algoInputParams.m_inRasterBands.clear();
388 
389  if(bandsSelected.contains(bRed.toInt()))
390  algoInputParams.m_inRasterBands.push_back(bRed.toInt());
391 
392  if(bandsSelected.contains(bGreen.toInt()))
393  algoInputParams.m_inRasterBands.push_back(bGreen.toInt());
394 
395  if(bandsSelected.contains(bBlue.toInt()))
396  algoInputParams.m_inRasterBands.push_back(bBlue.toInt());
397  }
398  else
399  algoInputParams.m_inRasterBands = bandsSelected.toStdVector();
400 
401  return algoInputParams;
402 }
403 
405 {
406  if(isChecked)
407  {
408  te::qt::widgets::ScopedCursor cursor(Qt::WaitCursor);
409 
410  if(!m_mapDisplay->getExtent().isValid())
411  return;
412 
413  if(m_layer)
414  {
415  te::gm::Envelope* env = new te::gm::Envelope(m_layer->getExtent());
416 
417  std::unique_ptr<te::rst::Raster> raster(te::map::GetRaster(m_layer.get()));
418 
419  std::map<std::string, std::string> info;
420  info["FORCE_MEM_DRIVER"] = "TRUE";
421 
422  m_raster.reset(raster->trim(env, info));
423 
424  m_histogramWidget->setInputRaster(m_raster.get());
425 
426  if(m_ui->m_previewCheckBox->isChecked())
427  applyPreview();
428 
429  delete env;
430  }
431  }
432 }
433 
435 {
436  m_ui->m_contrastTypeComboBox->clear();
437 
438  m_ui->m_contrastTypeComboBox->addItem(tr("Linear"), te::rp::Contrast::InputParameters::LinearContrastT);
439  m_ui->m_contrastTypeComboBox->addItem(tr("Histogram Equalization"), te::rp::Contrast::InputParameters::HistogramEqualizationContrastT);
440  m_ui->m_contrastTypeComboBox->addItem(tr("Square Constrast"), te::rp::Contrast::InputParameters::SquareContrastT);
441  m_ui->m_contrastTypeComboBox->addItem(tr("Square Root Constrast"), te::rp::Contrast::InputParameters::SquareRootContrastT);
442  m_ui->m_contrastTypeComboBox->addItem(tr("Log Constrast"), te::rp::Contrast::InputParameters::LogContrastT);
443  m_ui->m_contrastTypeComboBox->addItem(tr("Mean and Standard Deviation"), te::rp::Contrast::InputParameters::MeanAndStdContrastT);
444  m_ui->m_contrastTypeComboBox->addItem(tr("Decorrelation Enhancement"), te::rp::Contrast::InputParameters::DecorrelationEnhancementT);
445 }
446 
448 {
449  assert(m_layer.get());
450 
451  if(m_layer)
452  {
453  std::unique_ptr<te::rst::Raster> inputRst(te::map::GetRaster(m_layer.get()));
454 
455  if(inputRst.get())
456  {
457  m_ui->m_bandTableWidget->setRowCount((int)inputRst->getNumberOfBands());
458 
459  for (std::size_t b = 0; b < inputRst->getNumberOfBands(); ++b)
460  {
461  QString bandName(tr("Band "));
462  bandName.append(QString::number(b));
463 
464  QCheckBox* bandCheckBox = new QCheckBox(bandName, this);
465  bandCheckBox->setChecked(true);
466 
467  connect(bandCheckBox, SIGNAL(stateChanged(int)), this, SLOT(onBandChecked()));
468 
469  m_ui->m_bandTableWidget->setCellWidget(static_cast<int>(b), 0, bandCheckBox);
470  }
471  }
472  }
473 
474  m_ui->m_bandTableWidget->resizeColumnsToContents();
475 
476  m_ui->m_bandTableWidget->selectRow(0);
477 
478 #if (QT_VERSION >= 0x050000)
479  m_ui->m_bandTableWidget->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
480 #else
481  m_ui->m_bandTableWidget->horizontalHeader()->setResizeMode(QHeaderView::ResizeToContents);
482 #endif
483 
484  onContrastTypeComboBoxActivated(m_ui->m_contrastTypeComboBox->currentIndex());
485 }
486 
488 {
489  if (!m_raster)
490  return;
491 
492  //progress
494 
495  te::qt::widgets::ScopedCursor cursor(Qt::WaitCursor);
496 
497  //set contrast parameters
499 
500  algoInputParams.m_inRasterPtr = m_raster.get();
501 
502  double vmin = std::numeric_limits<double>::max();
503  double vmax = std::numeric_limits<double>::min();
504 
505  vmin = std::min(vmin, m_minValue[0]);
506  vmax = std::max(vmax, m_maxValue[0]);
507 
508  double range = vmax - vmin;
509  unsigned int nbits = (unsigned int)(std::ceil(log(range) / log(2.)));
510  double maxValue = (double)(pow(2.0, (double)nbits)) - 1;
511 
512  algoInputParams.m_outRangeMin = 0;
513  algoInputParams.m_outRangeMax = maxValue;
514 
515  te::rp::Contrast::OutputParameters algoOutputParams;
516 
517  std::map<std::string, std::string> rinfo;
518  rinfo["MEM_RASTER_NROWS"] = boost::lexical_cast<std::string>(m_raster->getNumberOfRows());
519  rinfo["MEM_RASTER_NCOLS"] = boost::lexical_cast<std::string>(m_raster->getNumberOfColumns());
520  rinfo["MEM_RASTER_DATATYPE"] = boost::lexical_cast<std::string>(m_raster->getBandDataType(0));
521  rinfo["MEM_RASTER_NBANDS"] = boost::lexical_cast<std::string>(m_raster->getNumberOfBands());
522 
523  algoOutputParams.m_createdOutRasterDSType = "MEM";
524  algoOutputParams.m_createdOutRasterInfo = rinfo;
525 
526  //run contrast
527  te::rp::Contrast algorithmInstance;
528 
529  try
530  {
531  if (algorithmInstance.initialize(algoInputParams))
532  {
533  if (algorithmInstance.execute(algoOutputParams))
534  {
535  te::dt::AbstractData* abs = algoOutputParams.m_outRasterPtr->clone();
536 
537  te::rst::Raster* rst = static_cast<te::rst::Raster*>(abs);
538 
539  m_histogramWidget->setOutputRaster(algoOutputParams.m_createdOutRasterPtr.release());
540 
541  if (m_ui->m_previewCheckBox->isChecked())
542  drawPreview(rst);
543 
544  drawHistogram();
545  }
546  }
547  }
548  catch (...)
549  {
550  QMessageBox::warning(this, tr("Warning"), tr("Constrast error."));
551 
552  QApplication::restoreOverrideCursor();
553  }
554 }
555 
557 {
558  if (m_geom->getGeomTypeId() == te::gm::PolygonType)
559  {
560  te::qt::widgets::ScopedCursor cursor(Qt::WaitCursor);
561 
562  te::gm::Envelope* env = new te::gm::Envelope(*m_geom->getMBR());
563 
564  std::unique_ptr<te::rst::Raster> raster(te::map::GetRaster(m_layer.get()));
565 
566  std::map<std::string, std::string> info;
567  info["FORCE_MEM_DRIVER"] = "TRUE";
568 
569  //execute clipping
570  m_raster.reset(raster->trim(env, info));
571 
572  m_histogramWidget->setInputRaster(m_raster.get());
573 
574  if(m_ui->m_previewCheckBox->isChecked())
575  applyPreview();
576 
577  delete env;
578  }
579 }
580 
582 {
583  if (m_outputWidget->fileExists())
584  {
585  QMessageBox::warning(this, tr("Contrast"), tr("File already exists."));
586  return false;
587  }
588 
589  if(m_ui->m_roiRadioButton->isChecked())
590  {
591  if(!m_geom.get() || !m_geom->isValid())
592  {
593  QMessageBox::warning(this, tr("Contrast"), tr("The region of interest informed is invalid."));
594  return false;
595  }
596  }
597 
598  std::unique_ptr<te::rst::Raster> inputRst(te::map::GetRaster(m_layer.get()));
599 
600  //run contrast
601  te::rp::Contrast algorithmInstance;
602 
604  algoInputParams.m_inRasterPtr = inputRst.get();
605  algoInputParams.m_enableProgress = true;
606 
607  double vmin = std::numeric_limits<double>::max();
608  double vmax = std::numeric_limits<double>::min();
609 
610  vmin = std::min(vmin, m_minValue[0]);
611  vmax = std::max(vmax, m_maxValue[0]);
612 
613  double range = vmax - vmin;
614  unsigned int nbits = (unsigned int)(std::ceil(log(range) / log(2.)));
615  double maxValue = (double)(pow(2.0, (double)nbits)) - 1;
616 
617  algoInputParams.m_outRangeMin = 0;
618  algoInputParams.m_outRangeMax = maxValue;
619 
620  te::rp::Contrast::OutputParameters algoOutputParams;
621  algoOutputParams.m_createdOutRasterDSType = m_outputWidget->getType();
622  algoOutputParams.m_createdOutRasterInfo = m_outputWidget->getInfo();
623  algoOutputParams.m_outRasterBands = algoInputParams.m_inRasterBands;
624 
625  //progress
627 
628  te::qt::widgets::ScopedCursor cursor(Qt::WaitCursor);
629 
630  try
631  {
632  if (algorithmInstance.initialize(algoInputParams))
633  {
634  if (algorithmInstance.execute(algoOutputParams))
635  {
636  algoOutputParams.reset();
637 
638  //set output layer
641 
642  QMessageBox::information(this, tr("Contrast"), tr("Contrast enhencement ended sucessfully"));
643  }
644  else
645  {
646  QMessageBox::critical(this, tr("Contrast"), tr("Contrast enhencement execution error.") +
647  (" " + algorithmInstance.getErrorMessage()).c_str());
648 
649  QApplication::restoreOverrideCursor();
650 
651  return false;
652  }
653  }
654  else
655  {
656  QMessageBox::critical(this, tr("Contrast"), tr("Contrast enhencement initialization error.") +
657  (" " + algorithmInstance.getErrorMessage()).c_str());
658 
659  QApplication::restoreOverrideCursor();
660 
661  return false;
662  }
663  }
664  catch (const std::exception& e)
665  {
666  QMessageBox::warning(this, tr("Contrast"), e.what());
667 
668  QApplication::restoreOverrideCursor();
669 
670  return false;
671  }
672  catch (...)
673  {
674  QMessageBox::warning(this, tr("Contrast"), tr("An exception has occurred!"));
675 
676  QApplication::restoreOverrideCursor();
677 
678  return false;
679  }
680 
682 
683  emit addLayer(m_outputLayer);
684 
685  return true;
686 }
687 
689 {
691 
692  canvasInstance.clear();
693 
694  m_mapDisplay->repaint();
695 }
696 
698 {
699  te::se::Style* style = m_layer->getStyle();
700  assert(style);
701 
702  te::se::CoverageStyle* cs = dynamic_cast<te::se::CoverageStyle*>(style);
703  assert(cs);
704 
705  // for while, consider one rule
706  const te::se::Rule* rule = cs->getRule(0);
707 
708  const std::vector<te::se::Symbolizer*>& symbolizers = rule->getSymbolizers();
709  assert(!symbolizers.empty());
710 
711  // for while, consider one raster symbolizer
712  te::se::RasterSymbolizer* symbolizer = dynamic_cast<te::se::RasterSymbolizer*>(symbolizers[0]);
713  assert(symbolizer);
714 
715  return symbolizer->getChannelSelection();
716 }
717 
719 {
720  clearCanvas();
721 
722  emit closeTool();
723 }
724 
726 {
727  std::unique_ptr<te::da::DataSetType> dsType = layer->getSchema();
728  //Checking if the layer contains a raster property
729  if (!dsType->hasRaster())
730  {
731  QMessageBox::warning(this, tr("Warning"), tr("There is no selected raster layer."));
732 
733  m_ui->m_typeGroupBox->setEnabled(false);
734  m_ui->m_bandsGroupBox->setEnabled(false);
735  m_ui->m_histogramGroupBox->setEnabled(false);
736  m_ui->m_histWidget->setEnabled(false);
737  m_ui->m_histAreaGroupBox->setEnabled(false);
738  m_ui->m_outputWidget->setEnabled(false);
739 
740  m_histogramWidget->clear();
741 
742  m_ui->m_bandTableWidget->setRowCount(0);
743 
744  m_layer = nullptr;
745 
746  return;
747  }
748 
749  te::rst::RasterProperty* rasterProp = te::da::GetFirstRasterProperty(dsType.get());
750 
751  if (rasterProp->getBandProperties().empty())
752  {
753  QMessageBox::warning(this, tr("Warning"), tr("Layers without Band information!"));
754 
755  m_ui->m_typeGroupBox->setEnabled(false);
756  m_ui->m_bandsGroupBox->setEnabled(false);
757  m_ui->m_histogramGroupBox->setEnabled(false);
758  m_ui->m_histWidget->setEnabled(false);
759  m_ui->m_histAreaGroupBox->setEnabled(false);
760  m_ui->m_outputWidget->setEnabled(false);
761 
762  m_histogramWidget->clear();
763 
764  m_ui->m_bandTableWidget->setRowCount(0);
765 
766  m_layer = 0;
767 
768  return;
769  }
770 
771  if (rasterProp->getBandProperties()[0]->m_colorInterp == te::rst::PaletteIdxCInt)
772  {
773  QMessageBox::warning(this, tr("Warning"), tr("Layers with raster palette are not able to apply contrast!"));
774 
775  m_ui->m_typeGroupBox->setEnabled(false);
776  m_ui->m_bandsGroupBox->setEnabled(false);
777  m_ui->m_histogramGroupBox->setEnabled(false);
778  m_ui->m_histWidget->setEnabled(false);
779  m_ui->m_histAreaGroupBox->setEnabled(false);
780  m_ui->m_outputWidget->setEnabled(false);
781 
782  m_histogramWidget->clear();
783 
784  m_ui->m_bandTableWidget->setRowCount(0);
785 
786  m_layer = nullptr;
787 
788  return;
789  }
790 
791  te::qt::widgets::ScopedCursor cursor(Qt::WaitCursor);
792 
793  m_ui->m_typeGroupBox->setEnabled(true);
794  m_ui->m_bandsGroupBox->setEnabled(true);
795  m_ui->m_histogramGroupBox->setEnabled(true);
796  m_ui->m_histWidget->setEnabled(true);
797  m_ui->m_histAreaGroupBox->setEnabled(true);
798  m_ui->m_outputWidget->setEnabled(true);
799 
800  clearCanvas();
801 
802  m_histogramWidget->clear();
803 
804  m_ui->m_bandTableWidget->setRowCount(0);
805 
806  m_ui->m_roiRadioButton->setChecked(true);
807 
808  set(layer);
809 
810  std::list<te::map::AbstractLayerPtr> layerList;
811  layerList.push_back(layer);
812 
813  te::gm::Envelope displayExtent = te::map::GetExtent(layerList, m_mapDisplay->getSRID(), true);
814 
815  m_mapDisplay->setExtent(displayExtent, false);
816 
817  m_mapDisplay->setLayerList(layerList);
818 
819  m_mapDisplay->refresh(true);
820 }
821 
823 {
824  te::qt::widgets::ScopedCursor cursor(Qt::WaitCursor);
825 
826  m_ui->m_bandTableWidget->setEnabled(false);
827 
828  const te::gm::Envelope& envRaster = *raster->getExtent();
829  const te::gm::Envelope& env = m_mapDisplay->getExtent();
830 
832 
833  te::se::CoverageStyle* cs = dynamic_cast<te::se::CoverageStyle*>(style);
834  assert(cs);
835 
836  te::qt::widgets::Canvas* canvasInstance = new Canvas(m_mapDisplay->width(), m_mapDisplay->height());
837  canvasInstance->setDevice(m_mapDisplay->getDraftPixmap(), false);
838  canvasInstance->setWindow(env.m_llx, env.m_lly, env.m_urx, env.m_ury);
839 
840  canvasInstance->setPolygonContourWidth(2);
841  canvasInstance->setPolygonContourColor(te::color::RGBAColor(100, 177, 216, TE_OPAQUE));
842  canvasInstance->setPolygonFillColor(te::color::RGBAColor(100, 177, 216, 0));
843 
844  // Draw raster
845  bool cancel = false;
846  te::map::DrawRaster(raster, canvasInstance, envRaster, raster->getSRID(), env, m_mapDisplay->getSRID(), cs, nullptr, m_mapDisplay->getScale(), &cancel);
847 
848  if (m_ui->m_roiRadioButton->isChecked())
849  {
850  if (!m_geom.get() || !m_geom->isValid())
851  return;
852 
853  if(m_geom->getSRID() != m_mapDisplay->getSRID())
854  m_geom->transform(m_mapDisplay->getSRID());
855 
856  canvasInstance->draw(m_geom.get());
857  }
858 
859  m_ui->m_bandTableWidget->setEnabled(true);
860 
861  m_mapDisplay->repaint();
862 
863  delete canvasInstance;
864 
865  delete style;
866 }
867 
869 {
870  if (!m_geom.get() || !m_geom->isValid())
871  return;
872 
873  const te::gm::Envelope& env = m_mapDisplay->getExtent();
874 
876  canvasInstance.setWindow(env.m_llx, env.m_lly, env.m_urx, env.m_ury);
877 
878  canvasInstance.setPolygonContourWidth(2);
879  canvasInstance.setPolygonContourColor(te::color::RGBAColor(100, 177, 216, TE_OPAQUE));
880 
881  if(m_geom->getSRID() != m_mapDisplay->getSRID())
882  m_geom->transform(m_mapDisplay->getSRID());
883 
884  canvasInstance.draw(m_geom.get());
885 
886  m_mapDisplay->repaint();
887 }
888 
890 {
891  int row = m_ui->m_bandTableWidget->currentRow();
892 
897  {
898  bool reset = true;
899 
900  if(m_ui->m_bandTableWidget->horizontalHeaderItem(2) && m_ui->m_bandTableWidget->horizontalHeaderItem(2)->text() == tr("Minimum") &&
901  m_ui->m_bandTableWidget->horizontalHeaderItem(3) && m_ui->m_bandTableWidget->horizontalHeaderItem(3)->text() == tr("Maximum"))
902  reset = false;
903 
904  if(reset)
905  {
906  QStringList list;
907  list.append(tr("Band"));
908  list.append(tr("Minimum"));
909  list.append(tr("Maximum"));
910 
911  m_ui->m_bandTableWidget->setColumnCount(3);
912  m_ui->m_bandTableWidget->setHorizontalHeaderLabels(list);
913 
914  int nBands = m_ui->m_bandTableWidget->rowCount();
915 
916  for(int i = 0; i < nBands; ++i)
917  {
918  QTableWidgetItem* itemMin = new QTableWidgetItem(te::common::Convert2String(m_minValue[i], 2).c_str());
919  itemMin->setFlags(Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsSelectable);
920  m_ui->m_bandTableWidget->setItem(i, 1, itemMin);
921 
922  QTableWidgetItem* itemMax = new QTableWidgetItem(te::common::Convert2String(m_maxValue[i], 2).c_str());
923  itemMax->setFlags(Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsSelectable);
924  m_ui->m_bandTableWidget->setItem(i, 2, itemMax);
925  }
926  }
927 
928  m_histogramWidget->setMinimumValueEnabled(true);
929  m_histogramWidget->setMaximumValueEnabled(true);
930 
931  m_histogramWidget->updateMinimumValueLabel(tr("Minimum"));
932  m_histogramWidget->updateMaximumValueLabel(tr("Maximum"));
933 
934  m_histogramWidget->updateMinimumValueLine(m_minValue[row], false);
935  m_histogramWidget->updateMaximumValueLine(m_maxValue[row], false);
936 
937  m_ui->m_tipLabel->setText(tr("Use left button to set minimum value and right button to define maximum value over the histogram."));
938  }
940  {
941  QStringList list;
942  list.append(tr("Band"));
943  list.append(tr("Maximum"));
944 
945  m_ui->m_bandTableWidget->setColumnCount(2);
946  m_ui->m_bandTableWidget->setHorizontalHeaderLabels(list);
947 
948  std::unique_ptr<te::rst::Raster> raster(te::map::GetRaster(m_layer.get()));
949  int nBands = m_ui->m_bandTableWidget->rowCount();
950  double currentRowMaxValue = 0;
951 
952  for(int i = 0; i < nBands; ++i)
953  {
954  const int bandDataType = raster->getBand( i )->getProperty()->m_type;
955  const bool isRealValuesBand = ( bandDataType == te::dt::FLOAT_TYPE ) ||
956  ( bandDataType == te::dt::DOUBLE_TYPE );
957  double bandMaxValue = isRealValuesBand ? 255.0 : m_maxValue[i];
958 
959  QTableWidgetItem* itemMax = new QTableWidgetItem(te::common::Convert2String(bandMaxValue, 2).c_str());
960  itemMax->setFlags(Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsSelectable);
961  m_ui->m_bandTableWidget->setItem(i, 1, itemMax);
962 
963  if( i == row )
964  {
965  currentRowMaxValue = bandMaxValue;
966  }
967  }
968 
969  m_histogramWidget->setMinimumValueEnabled(true);
970  m_histogramWidget->setMaximumValueEnabled(false);
971 
972  m_histogramWidget->updateMinimumValueLabel(tr("Maximum"));
973 
974  m_histogramWidget->updateMinimumValueLine(currentRowMaxValue, false);
975 
976  m_ui->m_tipLabel->setText(tr("Use left button to set maximum value over the histogram."));
977  }
979  {
980  QStringList list;
981  list.append(tr("Band"));
982  list.append(tr("Mean"));
983  list.append(tr("Std Dev"));
984 
985  m_ui->m_bandTableWidget->setColumnCount(3);
986  m_ui->m_bandTableWidget->setHorizontalHeaderLabels(list);
987 
988  int nBands = m_ui->m_bandTableWidget->rowCount();
989 
990  for(int i = 0; i < nBands; ++i)
991  {
992  QTableWidgetItem* itemMean = new QTableWidgetItem("127");
993  itemMean->setFlags(Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsSelectable);
994  m_ui->m_bandTableWidget->setItem(i, 1, itemMean);
995 
996  QTableWidgetItem* itemStdDev = new QTableWidgetItem("50");
997  itemStdDev->setFlags(Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsSelectable);
998  m_ui->m_bandTableWidget->setItem(i, 2, itemStdDev);
999  }
1000 
1001  m_histogramWidget->setMinimumValueEnabled(true);
1002  m_histogramWidget->setMaximumValueEnabled(true);
1003 
1004  m_histogramWidget->updateMinimumValueLabel(tr("Mean"));
1005  m_histogramWidget->updateMaximumValueLabel(tr("Std Dev"));
1006 
1007  m_histogramWidget->updateMinimumValueLine(127, false);
1008  m_histogramWidget->updateMaximumValueLine(50, false);
1009 
1010  m_ui->m_tipLabel->setText(tr("Use left button to set Mean value and right button to define Std Dev value over the histogram."));
1011  }
1013  {
1014  QStringList list;
1015  list.append(tr("Band"));
1016 
1017  m_ui->m_bandTableWidget->setColumnCount(1);
1018  m_ui->m_bandTableWidget->setHorizontalHeaderLabels(list);
1019 
1020  m_histogramWidget->setMinimumValueEnabled(false);
1021  m_histogramWidget->setMaximumValueEnabled(false);
1022 
1023  m_ui->m_tipLabel->setText(tr(""));
1024  }
1025 
1026  if(m_raster && m_ui->m_previewCheckBox->isChecked())
1027  {
1028  applyPreview();
1029  }
1030 
1031  m_ui->m_bandTableWidget->resizeColumnsToContents();
1032  #if (QT_VERSION >= 0x050000)
1033  m_ui->m_bandTableWidget->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
1034  #else
1035  m_ui->m_bandTableWidget->horizontalHeader()->setResizeMode(QHeaderView::ResizeToContents);
1036  #endif
1037 }
1038 
1040 {
1041  int contrastType = m_ui->m_contrastTypeComboBox->itemData(index).toInt();
1042 
1043  setDefaultValues(contrastType);
1044 }
1045 
1047 {
1048  QCheckBox* bandCheckBox = (QCheckBox*)m_ui->m_bandTableWidget->cellWidget(row, 0);
1049 
1050  if(bandCheckBox->isChecked())
1051  drawHistogram();
1052 }
1053 
1055 {
1056  if (column == 0)
1057  return;
1058 
1059  m_lastText = m_ui->m_bandTableWidget->item(row, column)->text().toUtf8().data();
1060  m_updatePreview = true;
1061 }
1062 
1064 {
1065  bool isNumeric;
1066 
1067  m_ui->m_bandTableWidget->item(row, column)->text().toDouble(&isNumeric);
1068 
1069  if(!isNumeric)
1070  {
1071  m_ui->m_bandTableWidget->item(row, column)->setText(m_lastText.c_str());
1072  return;
1073  }
1074 
1075  if(m_updatePreview)
1076  {
1077  std::unique_ptr<te::rst::Raster> raster(te::map::GetRaster(m_layer.get()));
1078 
1079  int index = m_ui->m_contrastTypeComboBox->currentIndex();
1080 
1081  int contrastType = m_ui->m_contrastTypeComboBox->itemData(index).toInt();
1082 
1083  m_updatePreview = false;
1084 
1085  if(column == 1)
1086  {
1091  {
1092  if(raster->getBand(0)->getProperty()->getType() == te::dt::UCHAR_TYPE || raster->getBand(0)->getProperty()->getType() == te::dt::UINT16_TYPE ||
1093  raster->getBand(0)->getProperty()->getType() == te::dt::UINT32_TYPE || raster->getBand(0)->getProperty()->getType() == te::dt::UINT64_TYPE)
1094  {
1095  int value = m_ui->m_bandTableWidget->item(row, column)->text().toDouble();
1096  int maxValue = m_ui->m_bandTableWidget->item(row, 2)->text().toDouble();
1097 
1098  if(value > maxValue)
1099  {
1100  m_ui->m_bandTableWidget->item(row, column)->setText(m_lastText.c_str());
1101  return;
1102  }
1103 
1104  m_histogramWidget->updateMinimumValueLine(value, true);
1105  }
1106  else
1107  {
1108  double value = m_ui->m_bandTableWidget->item(row, column)->text().toDouble();
1109  double maxValue = m_ui->m_bandTableWidget->item(row, 2)->text().toDouble();
1110 
1111  if(value > maxValue)
1112  {
1113  m_ui->m_bandTableWidget->item(row, column)->setText(m_lastText.c_str());
1114  return;
1115  }
1116 
1117  m_histogramWidget->updateMinimumValueLine(value, true);
1118  }
1119  }
1122  {
1123  if(raster->getBand(0)->getProperty()->getType() == te::dt::UCHAR_TYPE || raster->getBand(0)->getProperty()->getType() == te::dt::UINT16_TYPE ||
1124  raster->getBand(0)->getProperty()->getType() == te::dt::UINT32_TYPE || raster->getBand(0)->getProperty()->getType() == te::dt::UINT64_TYPE)
1125  {
1126  int minValue = m_ui->m_bandTableWidget->item(row, column)->text().toDouble();
1127 
1128  m_histogramWidget->updateMinimumValueLine(minValue, true);
1129  }
1130  else
1131  {
1132  double minValue = m_ui->m_bandTableWidget->item(row, column)->text().toDouble();
1133 
1134  m_histogramWidget->updateMinimumValueLine(minValue, true);
1135  }
1136  }
1137  }
1138  else if(column == 2)
1139  {
1144  {
1145  if(raster->getBand(0)->getProperty()->getType() == te::dt::UCHAR_TYPE || raster->getBand(0)->getProperty()->getType() == te::dt::UINT16_TYPE ||
1146  raster->getBand(0)->getProperty()->getType() == te::dt::UINT32_TYPE || raster->getBand(0)->getProperty()->getType() == te::dt::UINT64_TYPE)
1147  {
1148  int value = m_ui->m_bandTableWidget->item(row, column)->text().toDouble();
1149  int minValue = m_ui->m_bandTableWidget->item(row, 1)->text().toDouble();
1150 
1151  if(value < minValue)
1152  {
1153  m_ui->m_bandTableWidget->item(row, column)->setText(m_lastText.c_str());
1154  return;
1155  }
1156 
1157  m_histogramWidget->updateMaximumValueLine(value, true);
1158  }
1159  else
1160  {
1161  double value = m_ui->m_bandTableWidget->item(row, column)->text().toDouble();
1162  double minValue = m_ui->m_bandTableWidget->item(row, 1)->text().toDouble();
1163 
1164  if(value < minValue)
1165  {
1166  m_ui->m_bandTableWidget->item(row, column)->setText(m_lastText.c_str());
1167  return;
1168  }
1169 
1170  m_histogramWidget->updateMaximumValueLine(value, true);
1171  }
1172  }
1174  {
1175  if(raster->getBand(0)->getProperty()->getType() == te::dt::UCHAR_TYPE || raster->getBand(0)->getProperty()->getType() == te::dt::UINT16_TYPE ||
1176  raster->getBand(0)->getProperty()->getType() == te::dt::UINT32_TYPE || raster->getBand(0)->getProperty()->getType() == te::dt::UINT64_TYPE)
1177  {
1178  int maxValue = m_ui->m_bandTableWidget->item(row, column)->text().toDouble();
1179 
1180  m_histogramWidget->updateMaximumValueLine(maxValue, true);
1181  }
1182  else
1183  {
1184  double maxValue = m_ui->m_bandTableWidget->item(row, column)->text().toDouble();
1185 
1186  m_histogramWidget->updateMaximumValueLine(maxValue, true);
1187  }
1188  }
1189  }
1190 
1191  applyPreview();
1192  }
1193 }
1194 
1196  int /*band*/)
1197 {
1198  if (!m_layer || !m_raster)
1199  return;
1200 
1201  m_updatePreview = true;
1202 
1203  int row = m_ui->m_bandTableWidget->currentRow();
1204 
1205  int index = m_ui->m_contrastTypeComboBox->currentIndex();
1206 
1207  int contrastType = m_ui->m_contrastTypeComboBox->itemData(index).toInt();
1208 
1213  {
1214  int max = m_ui->m_bandTableWidget->item(row, 2)->text().toDouble();
1215 
1216  if(value > max)
1217  return;
1218 
1219  m_ui->m_bandTableWidget->item(row, 1)->setText(QString::number(value));
1220  m_ui->m_bandTableWidget->setCurrentCell(row, 1);
1221 
1222  m_histogramWidget->updateMinimumValueLine(value, true);
1223  }
1225  {
1226  m_ui->m_bandTableWidget->item(row, 1)->setText(QString::number(value));
1227  m_ui->m_bandTableWidget->setCurrentCell(row, 1);
1228 
1229  m_histogramWidget->updateMinimumValueLine(value, true);
1230  }
1232  {
1233  m_ui->m_bandTableWidget->item(row, 1)->setText(QString::number(value));
1234  m_ui->m_bandTableWidget->setCurrentCell(row, 1);
1235 
1236  m_histogramWidget->updateMinimumValueLine(value, true);
1237  }
1238  else
1239  {
1240  return;
1241  }
1242 }
1243 
1245  int /*band*/)
1246 {
1247  if (!m_layer || !m_raster)
1248  return;
1249 
1250  m_updatePreview = true;
1251 
1252  int row = m_ui->m_bandTableWidget->currentRow();
1253 
1254  int index = m_ui->m_contrastTypeComboBox->currentIndex();
1255 
1256  int contrastType = m_ui->m_contrastTypeComboBox->itemData(index).toInt();
1257 
1262  {
1263  double max = m_ui->m_bandTableWidget->item(row, 2)->text().toDouble();
1264 
1265  if(value > max)
1266  return;
1267 
1268  m_ui->m_bandTableWidget->item(row, 1)->setText(QString::number(value));
1269  m_ui->m_bandTableWidget->setCurrentCell(row, 1);
1270 
1271  m_histogramWidget->updateMinimumValueLine(value, true);
1272  }
1274  {
1275  m_ui->m_bandTableWidget->item(row, 1)->setText(QString::number(value));
1276  m_ui->m_bandTableWidget->setCurrentCell(row, 1);
1277 
1278  m_histogramWidget->updateMinimumValueLine(value, true);
1279  }
1281  {
1282  m_ui->m_bandTableWidget->item(row, 1)->setText(QString::number(value));
1283  m_ui->m_bandTableWidget->setCurrentCell(row, 1);
1284 
1285  m_histogramWidget->updateMinimumValueLine(value, true);
1286  }
1287  else
1288  {
1289  return;
1290  }
1291 }
1292 
1294  int /*band*/)
1295 {
1296  if (!m_layer || !m_raster)
1297  return;
1298 
1299  m_updatePreview = true;
1300 
1301  int row = m_ui->m_bandTableWidget->currentRow();
1302 
1303  int index = m_ui->m_contrastTypeComboBox->currentIndex();
1304 
1305  int contrastType = m_ui->m_contrastTypeComboBox->itemData(index).toInt();
1306 
1311  {
1312  int min = m_ui->m_bandTableWidget->item(row, 1)->text().toDouble();
1313 
1314  if(value < min)
1315  return;
1316 
1317  m_ui->m_bandTableWidget->item(row, 2)->setText(QString::number(value));
1318  m_ui->m_bandTableWidget->setCurrentCell(row, 2);
1319 
1320  m_histogramWidget->updateMaximumValueLine(value, true);
1321  }
1323  {
1324  if (!m_ui->m_bandTableWidget->item(row, 1)->text().isEmpty())
1325  {
1326  double mean = m_ui->m_bandTableWidget->item(row, 1)->text().toDouble();
1327 
1328  double stdDev = std::abs(mean - (double)value);
1329 
1330  m_ui->m_bandTableWidget->item(row, 2)->setText(QString::number(stdDev));
1331  m_ui->m_bandTableWidget->setCurrentCell(row, 2);
1332 
1333  m_histogramWidget->updateMaximumValueLine(value, true);
1334  }
1335  }
1336  else
1337  {
1338  return;
1339  }
1340 }
1341 
1343  int /*band*/)
1344 {
1345  if (!m_layer || !m_raster)
1346  return;
1347 
1348  m_updatePreview = true;
1349 
1350  int row = m_ui->m_bandTableWidget->currentRow();
1351 
1352  int index = m_ui->m_contrastTypeComboBox->currentIndex();
1353 
1354  int contrastType = m_ui->m_contrastTypeComboBox->itemData(index).toInt();
1355 
1360  {
1361  double min = m_ui->m_bandTableWidget->item(row, 1)->text().toDouble();
1362 
1363  if(value < min)
1364  return;
1365 
1366  m_ui->m_bandTableWidget->item(row, 2)->setText(QString::number(value));
1367  m_ui->m_bandTableWidget->setCurrentCell(row, 2);
1368 
1369  m_histogramWidget->updateMaximumValueLine(value, true);
1370  }
1372  {
1373  if (!m_ui->m_bandTableWidget->item(row, 1)->text().isEmpty())
1374  {
1375  double mean = m_ui->m_bandTableWidget->item(row, 1)->text().toDouble();
1376 
1377  double stdDev = std::abs(mean - value);
1378 
1379  m_ui->m_bandTableWidget->item(row, 2)->setText(QString::number(stdDev));
1380  m_ui->m_bandTableWidget->setCurrentCell(row, 2);
1381 
1382  m_histogramWidget->updateMaximumValueLine(value, true);
1383  }
1384  }
1385  else
1386  {
1387  return;
1388  }
1389 }
1390 
1392 {
1393  //check output parameters
1394  if (m_outputWidget->getOutputRaster().empty())
1395  {
1396  QMessageBox::information(this, tr("Contrast"), tr("Output image is not defined."));
1397  return;
1398  }
1399 
1400  if(!m_bandChecked)
1401  {
1402  QMessageBox::information(this, tr("Contrast"), tr("Invalid number of bands."));
1403  return;
1404  }
1405 
1406  if (!execute())
1407  {
1408  QMessageBox::information(this, tr("Contrast"), tr("Error to apply contrast."));
1409  return;
1410  }
1411 
1412  clearCanvas();
1413 
1414  emit closeTool();
1415 }
1416 
1418 {
1419  if (isChecked)
1420  {
1421  applyPreview();
1422  }
1423  else
1424  {
1425  if (m_raster)
1426  drawPreview(m_raster.get());
1427  }
1428 }
1429 
1431 {
1432  if (isChecked)
1433  {
1434  m_ui->m_navigatorWidget->setEnabled(true);
1435  m_navigator->setEnvelopeTool(true);
1436  }
1437  else
1438  {
1439  m_ui->m_navigatorWidget->setEnabled(false);
1440  m_navigator->setEnvelopeTool(false);
1441  }
1442 }
1443 
1445 {
1446  if(isChecked)
1447  {
1448  if(!m_mapDisplay->getExtent().isValid())
1449  return;
1450 
1451  m_ui->m_navigatorWidget->setEnabled(false);
1452 
1453  te::qt::widgets::ScopedCursor cursor(Qt::WaitCursor);
1454 
1455  te::gm::Envelope reprojectedBBOX(m_mapDisplay->getExtent());
1456  reprojectedBBOX.transform(m_mapDisplay->getSRID(), m_layer->getSRID());
1457 
1458  if (!reprojectedBBOX.intersects(m_layer->getExtent()))
1459  {
1460  QMessageBox::warning(this, tr("Warning"), tr("Visible area doesn't intersect with the layer."));
1461  return;
1462  }
1463 
1464  te::gm::Envelope ibbox = reprojectedBBOX.intersection(m_layer->getExtent());
1465 
1466  if (ibbox.isValid())
1468 
1469  getRasterFromROI();
1470 
1471  drawGeom();
1472  }
1473 }
1474 
1476 {
1477  int bandIdx = -1;
1478 
1479  for(int i = 0; i <= m_ui->m_bandTableWidget->currentRow(); ++i)
1480  {
1481  QCheckBox* bandCheckBox = (QCheckBox*)m_ui->m_bandTableWidget->cellWidget(i, 0);
1482 
1483  if(bandCheckBox->isChecked())
1484  ++bandIdx;
1485  }
1486 
1487  if(bandIdx == -1)
1488  return;
1489 
1490  if (!m_raster)
1491  return;
1492 
1493  te::qt::widgets::ScopedCursor cursor(Qt::WaitCursor);
1494 
1495  int index = m_ui->m_contrastTypeComboBox->currentIndex();
1496 
1497  int contrastType = m_ui->m_contrastTypeComboBox->itemData(index).toInt();
1498 
1503  {
1504  QTableWidgetItem* item = m_ui->m_bandTableWidget->item(bandIdx, 1);
1505  QTableWidgetItem* item1 = m_ui->m_bandTableWidget->item(bandIdx, 2);
1506 
1507  if (item && item1)
1508  {
1509  double min = item->text().toDouble();
1510  double max = item1->text().toDouble();
1511 
1512  m_histogramWidget->updateMinimumValueLine(min, false);
1513  m_histogramWidget->updateMaximumValueLine(max, false);
1514  }
1515  }
1517  {
1518  QTableWidgetItem* item = m_ui->m_bandTableWidget->item(bandIdx, 1);
1519  if (item)
1520  {
1521  double min = item->text().toDouble();
1522 
1523  m_histogramWidget->updateMinimumValueLine(min, false);
1524  }
1525  }
1527  {
1528  QTableWidgetItem* item = m_ui->m_bandTableWidget->item(bandIdx, 1);
1529  QTableWidgetItem* item1 = m_ui->m_bandTableWidget->item(bandIdx, 2);
1530 
1531  if (item && item1)
1532  {
1533  double min = item->text().toDouble();
1534  double max = item1->text().toDouble();
1535 
1536  m_histogramWidget->updateMinimumValueLine(min, false);
1537  m_histogramWidget->updateMaximumValueLine(max, false);
1538  }
1539  }
1540 
1541  m_histogramWidget->drawHistogram(bandIdx);
1542 }
1543 
1545 {
1547  {
1549 
1550  te::map::AbstractLayerPtr layer = evt->m_layer;
1551  assert(layer);
1552 
1553  if (layer == nullptr)
1554  {
1555  return;
1556  }
1557 
1558  resetWindow(layer);
1559  }
1560 }
1561 
1563 {
1564  drawGeom();
1565 
1566  if (m_ui->m_previewCheckBox->isChecked())
1567  {
1568  applyPreview();
1569  }
1570 }
1571 
1573 {
1574  if(m_mapDisplay->getSRID() != m_layer->getSRID())
1575  env.transform(m_mapDisplay->getSRID(), m_layer->getSRID());
1576 
1577  if(!env.isValid() || !env.intersects(m_layer->getExtent()))
1578  return;
1579 
1580  m_geom.reset(te::gm::GetGeomFromEnvelope(&env, m_layer->getSRID()));
1581 
1582  getRasterFromROI();
1583 
1584  drawGeom();
1585 }
1586 
1588 {
1589  int band = -1;
1590 
1591  std::unique_ptr<te::rst::Raster> inputRst(te::map::GetRaster(m_layer.get()));
1592 
1593  for(unsigned int i = 0; i < inputRst->getNumberOfBands(); ++i)
1594  {
1595  QCheckBox* bandCheckBox = (QCheckBox*)m_ui->m_bandTableWidget->cellWidget(i, 0);
1596 
1597  if(bandCheckBox->isChecked())
1598  ++band;
1599  }
1600 
1601  if(band == -1)
1602  {
1603  m_bandChecked = false;
1604  return;
1605  }
1606 
1607  m_bandChecked = true;
1608 
1609  applyPreview();
1610 }
1611 
1613 {
1614  int index = m_ui->m_contrastTypeComboBox->currentIndex();
1615 
1616  setDefaultValues(m_ui->m_contrastTypeComboBox->itemData(index).toInt());
1617 }
const std::string & getErrorMessage() const
Return the current error message if there is any.
void onMaxValueSelected(int value, int band)
te::gm::Envelope * getExtent()
Returns the geographic extension of the raster data.
virtual void refresh(bool redraw=false)
It updates the contents in the map display.
TEDATAACCESSEXPORT te::rst::RasterProperty * GetFirstRasterProperty(const DataSetType *dt)
Palette indexes color interpretation.
void clear()
It clears the canvas content and fills with the background color.
unsigned int band
te::qt::widgets::MapDisplay * m_mapDisplay
This file has the RasterHistogramWidget class.
std::vector< double > m_logCMaxInput
The contrast maximum input greyscale value of each band.
Definition: Contrast.h:150
te::qt::widgets::OutputRasterWidget * m_outputWidget
std::vector< double > m_lCMinInput
The contrast minimum input greyscale value of each band.
Definition: Contrast.h:106
te::rst::Raster * m_outRasterPtr
A pointer to a valid initiated raster instance where the result must be written, leave NULL to create...
Definition: Contrast.h:192
void set(te::map::AbstractLayerPtr layer)
This method is used to set the selected layer for contrast operation.
void setDevice(QPaintDevice *device, bool takeOwnerShip)
It sets new device as QPrinter.
double m_outRangeMin
Minimum value of data type range (default: -1.0 * std::numeric_limits<double>::max() )...
Definition: Contrast.h:93
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
te::map::AbstractLayerPtr m_outputLayer
std::unique_ptr< te::gm::Geometry > m_geom
void onAllImageRadioButtonToggled(bool isChecked)
ContrastType m_type
The contrast type to be applied.
Definition: Contrast.h:87
void onApplicationTriggered(te::qt::af::evt::Event *e)
TEMAPEXPORT te::gm::Envelope GetExtent(const std::list< te::map::AbstractLayerPtr > &layers, int srid, bool onlyVisibles)
It calculates the extent of the given layers in the given SRID.
A base class for application events.
The CoverageStyle defines the styling that is to be applied to a subset of Coverage data...
Definition: CoverageStyle.h:45
std::vector< double > m_squareRootCMinInput
The contrast minimum input greyscale value of each band.
Definition: Contrast.h:137
TESEEXPORT Style * CreateCoverageStyle(const std::vector< te::rst::BandProperty * > &properties)
Try creates an appropriate coverage style based on given band properties.
te::map::AbstractLayerPtr m_layer
Pointer to the selected layer.
Definition: LayerEvents.h:196
te::rp::Contrast::InputParameters getInputParams()
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.
std::vector< double > m_squareRootCMaxInput
The contrast maximum input greyscale value of each band.
Definition: Contrast.h:139
#define TE_OPAQUE
For an RGBA color this is the value of the alpha-channel for totally opaque.
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.
void onEnvelopeAcquired(te::gm::Envelope env)
void draw(const te::gm::Geometry *geom)
It draws the geometry on canvas.
te::se::ChannelSelection * getChannelSelection()
Raster property.
void setMapDisplay(te::qt::widgets::MapDisplay *mapDisplay)
std::vector< double > m_logCMinInput
The contrast minimum input greyscale value of each band.
Definition: Contrast.h:148
Rule * getRule(std::size_t i) const
Definition: Style.cpp:105
This event indicates that the layer has been selected.
Definition: LayerEvents.h:183
int b
Definition: TsRtree.cpp:32
This class is used to define a component for viewing overlaid layers.
virtual void setLayerList(const std::list< te::map::AbstractLayerPtr > &layers)
It sets the layer list to be showed in the Map Display.
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).
Contrast input parameters.
Definition: Contrast.h:65
double m_llx
Lower left corner x-coordinate.
static RasterSummaryManager & getInstance()
It returns a reference to the singleton instance.
This file has the OutputRasterWidget class.
An Envelope defines a 2D rectangular region.
te::map::AbstractLayerPtr getOutputLayer()
An abstract class for raster data strucutures.
virtual std::size_t getNumberOfBands() const =0
Returns the number of bands (dimension of cells attribute values) in the raster.
std::vector< unsigned int > m_outRasterBands
Bands to be processed from the output raster.
Definition: Contrast.h:196
virtual int getSRID() const
It return the Spatial Reference System used by the Map Display.
double m_outRangeMax
Maximum value of data type range (default: std::numeric_limits<double>::max().
Definition: Contrast.h:95
std::unique_ptr< te::rst::Raster > m_raster
void setPolygonContourWidth(int w)
It sets the polygon contour width.
This class is used to set output layer.
virtual const te::gm::Envelope & getExtent() const
It returns the world extent showned by the MapDisplay.
std::vector< unsigned int > m_inRasterBands
Bands to be processed from the input raster.
Definition: Contrast.h:91
boost::ptr_vector< BandSummary > RasterSummary
RasterSummary is just a typedef of a boost::ptr_vector.
Definition: RasterSummary.h:44
bool m_enableProgress
Enable/Disable the progress interface (default:false).
Definition: Contrast.h:97
std::vector< double > m_hECMaxInput
The contrast maximum input greyscale value of each band.
Definition: Contrast.h:117
virtual AbstractData * clone() const =0
It returns a clone of this object.
The RasterSymbolizer describes how to render raster/matrix-coverage data (e.g., satellite photos...
A base class for values that can be retrieved from the data access module.
Definition: AbstractData.h:57
Utility functions for the data access module.
void addLayer(te::map::AbstractLayerPtr layer)
void setActionGroup(QActionGroup *actionGroup)
This class is GUI used to define the contrast parameters for the RP constast operation.
const std::vector< Symbolizer * > & getSymbolizers() const
Definition: Rule.cpp:158
double m_lly
Lower left corner y-coordinate.
std::vector< double > m_sMASCStdInput
The standard deviation to be applied in each band.
Definition: Contrast.h:161
rasterPointer reset(te::rst::RasterFactory::make("MEM", new te::rst::Grid(nCols, nLines), bandsProps, std::map< std::string, std::string >(), 0, 0))
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
void reset()
Clear all internal allocated resources and reset the parameters instance to its initial state...
int getSRID() const
Returns the raster spatial reference system identifier.
std::unique_ptr< te::rst::Raster > m_createdOutRasterPtr
A pointer to the created output raster instance, or an empty pointer empty if the result must be writ...
Definition: Contrast.h:194
A Rule is used to attach property/scale conditions to and group the individual symbols used for rende...
Definition: Rule.h:76
std::vector< double > m_squareCMaxInput
The contrast maximum input greyscale value of each band.
Definition: Contrast.h:128
bool initialize(const AlgorithmInputParameters &inputParams)
Initialize the algorithm instance making it ready for execution.
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.
std::vector< double > m_lCMaxInput
The contrast maximum input greyscale value of each band.
Definition: Contrast.h:108
This file defines a class for a Contrast dialog.
A helper class for 32-bit RGBA (Red-Green-Blue-Alpha channel) color.
Definition: RGBAColor.h:57
void resetWindow(te::map::AbstractLayerPtr layer)
bool execute(AlgorithmOutputParameters &outputParams)
Executes the algorithm using the supplied parameters.
std::unique_ptr< te::qt::widgets::RasterHistogramWidget > m_histogramWidget
This class is used to navigate over a DataSetLayer (having a raster representation) and given a set o...
Definition: RpToolsWidget.h:70
std::vector< double > m_sMASCMeanInput
The mean greyscale to be applied in each band.
Definition: Contrast.h:159
This file has the RasterNavigatorWidget class.
std::string m_createdOutRasterDSType
Output raster data source type (as described in te::raster::RasterFactory ), leave empty if the resul...
Definition: Contrast.h:198
void onMinValueSelected(int value, int band)
te::rst::Raster const * m_inRasterPtr
Input raster.
Definition: Contrast.h:89
std::vector< te::rst::BandProperty * > & getBandProperties()
Returns a reference to the list of bands definitions.
std::string Convert2String(boost::int16_t value)
It converts a short integer value to a string.
Definition: StringUtils.h:56
void drawPreview(te::rst::Raster *raster)
Envelope intersection(const Envelope &rhs) const
It returns an envelope that represents the point set intersection with another envelope.
Calculate the min value.
Contrast output parameters.
Definition: Contrast.h:188
Calculate the max value.
void onVisibleAreaRadioButtonToggled(bool isChecked)
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
void transform(int oldsrid, int newsrid)
It will transform the coordinates of the Envelope from the old SRS to the new one.
std::map< std::string, std::string > m_createdOutRasterInfo
The necessary information to create the raster (as described in te::raster::RasterFactory), leave empty if the result must be written to the raster pointed m_outRasterPtr.
Definition: Contrast.h:200
virtual void setExtent(te::gm::Envelope &e, bool doRefresh=true)
It sets the world visible area and refreshes the contents in the map display.
void onCellDoubleClicked(int row, int column)
bool isValid() const
It tells if the rectangle is valid or not.
std::unique_ptr< te::qt::widgets::RpToolsWidget > m_navigator
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.
An object that when created shows a cursor during its scope.
Definition: ScopedCursor.h:48
std::unique_ptr< Ui::ContrastDialogForm > m_ui
Contrast enhancement.
Definition: Contrast.h:57
std::vector< double > m_squareCMinInput
The contrast minimum input greyscale value of each band.
Definition: Contrast.h:126
ChannelSelection specifies the false-color channel selection for a multi-spectral raster source (such...