ClassifierWizardPage.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/ClassifierWizardPage.cpp
22 
23  \brief This file defines a class for a Classifier Wizard page.
24 */
25 
26 // TerraLib
27 #include "../../../dataaccess/dataset/DataSet.h"
28 #include "../../../dataaccess/dataset/DataSetType.h"
29 #include "../../../dataaccess/dataset/DataSetAdapter.h"
30 #include "../../../dataaccess/dataset/DataSetTypeConverter.h"
31 #include "../../../dataaccess/utils/Utils.h"
32 #include "../../../geometry/GeometryProperty.h"
33 #include "../../../geometry/MultiPolygon.h"
34 #include "../../../maptools/Utils.h"
35 #include "../../../raster/Raster.h"
36 #include "../../../raster/PositionIterator.h"
37 #include "../../../rp/ClassifierEMStrategy.h"
38 #include "../../../rp/ClassifierEDStrategy.h"
39 #include "../../../rp/ClassifierKMeansStrategy.h"
40 #include "../../../rp/ClassifierISOSegStrategy.h"
41 #include "../classification/ROIManagerDialog.h"
42 #include "../classification/ROIManagerWidget.h"
43 #include "ClassifierWizardPage.h"
44 #include "ui_ClassifierWizardPageForm.h"
45 
46 // Qt
47 #include <QGridLayout>
48 #include <QDoubleValidator>
49 #include <QIntValidator>
50 #include <QMessageBox>
51 
52 // stl
53 #include <memory>
54 
56 
57 te::qt::widgets::ClassifierWizardPage::ClassifierWizardPage(QWidget* parent)
58  : QWizardPage(parent),
59  m_ui(new Ui::ClassifierWizardPageForm),
60  m_layer(nullptr),
61  m_rs(nullptr)
62 {
63 // setup controls
64  m_ui->setupUi(this);
65 
66  fillClassifierTypes();
67 
68  QIntValidator* intMaxPoints = new QIntValidator(this);
69  intMaxPoints->setBottom(0);
70  m_ui->m_kMeansMaxPointsLineEdit->setValidator(intMaxPoints);
71 
72  QDoubleValidator* doubleStopCriteria = new QDoubleValidator(this);
73  doubleStopCriteria->setBottom(0.0);
74  m_ui->m_kMeansStopCriteriaLineEdit->setValidator(doubleStopCriteria);
75 
76  //configure page
77  this->setTitle(tr("Classifier"));
78  this->setSubTitle(tr("Select the type of classifier and set their specific parameters."));
79 
80  //configure roi manager
81  m_roiMngDlg.reset(new te::qt::widgets::ROIManagerDialog(this, Qt::Tool));
82 
83  //connects
84  connect(m_ui->m_acquireToolButton, SIGNAL(toggled(bool)), this, SLOT(showROIManager(bool)));
85  connect(m_ui->m_samAcquireToolButton, SIGNAL(toggled(bool)), this, SLOT(showROIManager(bool)));
86  connect(m_ui->m_edAcquireToolButton, SIGNAL(toggled(bool)), this, SLOT(showROIManager(bool)));
87  connect(m_ui->m_classifierTypeComboBox, SIGNAL(activated(int)), this, SIGNAL(completeChanged()));
88  connect(m_ui->m_classifierTypeComboBox, SIGNAL(activated(int)), this, SLOT(onChangeClassifier(int)));
89  connect(m_ui->m_inputRasterBandsListWidget, SIGNAL(itemSelectionChanged()), this, SIGNAL(completeChanged()));
90  connect(m_roiMngDlg.get(), SIGNAL(roiManagerClosed(te::cl::ROISet*)), this, SLOT(onROIManagerClosed(te::cl::ROISet*)));
91 
92  m_ui->m_acquireToolButton->setIcon(QIcon::fromTheme("wand"));
93  m_ui->m_samAcquireToolButton->setIcon(QIcon::fromTheme("wand"));
94  m_ui->m_edAcquireToolButton->setIcon(QIcon::fromTheme("wand"));
95 }
96 
98 
100 {
101  int idx = m_ui->m_classifierTypeComboBox->currentIndex();
102  int type = m_ui->m_classifierTypeComboBox->itemData(idx).toInt();
103 
104  if(type == CLASSIFIER_ISOSEG)
105  {
106  if(m_ui->m_isosegLayersComboBox->currentText().isEmpty())
107  return false;
108  }
109  else if(type == CLASSIFIER_MAP || type == CLASSIFIER_SAM
110  || type == CLASSIFIER_ED)
111  {
112  if(!m_checkNumSamples)
113  return false;
114  }
115 
116  if(m_ui->m_inputRasterBandsListWidget->selectedItems().empty())
117  return false;
118 
119  return true;
120 }
121 
123 {
124  m_layer = layer;
125 
126  m_roiMngDlg->set(m_layer);
127 
128  listBands();
129 }
130 
131 void te::qt::widgets::ClassifierWizardPage::setList(std::list<te::map::AbstractLayerPtr>& layerList)
132 {
133  m_roiMngDlg->setList(layerList);
134 
135  m_ui->m_isosegLayersComboBox->clear();
136 
137  std::list<te::map::AbstractLayerPtr>::iterator it = layerList.begin();
138 
139  while(it != layerList.end())
140  {
142 
143  std::unique_ptr<te::da::DataSetType> dsType = l->getSchema();
144 
145  if(dsType->hasGeom())
146  m_ui->m_isosegLayersComboBox->addItem(it->get()->getTitle().c_str(), QVariant::fromValue(l));
147 
148  ++it;
149  }
150 }
151 
153 {
154  int idx = m_ui->m_classifierTypeComboBox->currentIndex();
155  int type = m_ui->m_classifierTypeComboBox->itemData(idx).toInt();
156 
157  te::rp::Classifier::InputParameters algoInputParams;
158  algoInputParams.m_enableProgressInterface = true;
159 
160  if(type == CLASSIFIER_ISOSEG)
161  {
162  algoInputParams.m_strategyName = "isoseg";
163 
165  classifierparameters.m_acceptanceThreshold = m_ui->m_acceptanceThresholdComboBox->currentText().toDouble();
166 
167  if( m_ui->m_distanceTypeComboBox_->currentText() == "Mahalanobis" )
168  {
169  classifierparameters.m_distanceType =
171  }
172  else // Bhattacharyya
173  {
174  classifierparameters.m_distanceType =
176  }
177 
178  //get layer
179  int idxLayer = m_ui->m_isosegLayersComboBox->currentIndex();
180  QVariant varLayer = m_ui->m_isosegLayersComboBox->itemData(idxLayer, Qt::UserRole);
181  te::map::AbstractLayerPtr layer = varLayer.value<te::map::AbstractLayerPtr>();
182 
183  //get polygons
184  std::unique_ptr<te::da::DataSetType> dsType = layer->getSchema();
185 
187 
188  if(gp && gp->getGeometryType() == te::gm::MultiPolygonType)
189  {
190  std::unique_ptr<te::da::DataSet> ds = layer->getData();
191 
192  ds->moveBeforeFirst();
193 
194  while(ds->moveNext())
195  {
196  std::unique_ptr<te::gm::Geometry> geometry = std::move(ds->getGeometry(gp->getName()));
197 
198  std::unique_ptr<te::gm::MultiPolygon> mp(dynamic_cast<te::gm::MultiPolygon*>(geometry->clone()));
199 
200  mp->transform(m_layer->getSRID());
201 
202  std::vector<te::gm::Geometry*> singleGeomVec;
203 
204  te::gm::Multi2Single(mp.get(), singleGeomVec);
205 
206  for(auto g : singleGeomVec)
207  {
208  if(g->getMBR()->intersects(m_layer->getExtent()))
209  {
210  te::gm::Polygon* poly = dynamic_cast<te::gm::Polygon*>(g->clone());
211  algoInputParams.m_inputPolygons.push_back(poly);
212  }
213  }
214  te::common::FreeContents(singleGeomVec);
215  }
216  }
217 
218  algoInputParams.setClassifierStrategyParams(classifierparameters);
219  }
220  else if(type == CLASSIFIER_KMEANS)
221  {
222  algoInputParams.m_strategyName = "kmeans";
223 
225  classifierparameters.m_K = m_ui->m_kMeansClusterSpinBox->value();
226  classifierparameters.m_maxIterations = m_ui->m_kMeansIterationsSpinBox->value();
227  classifierparameters.m_maxInputPoints = m_ui->m_kMeansMaxPointsLineEdit->text().toInt();
228  classifierparameters.m_epsilon = m_ui->m_kMeansStopCriteriaLineEdit->text().toDouble();
229 
230  algoInputParams.setClassifierStrategyParams(classifierparameters);
231  }
232  else if(type == CLASSIFIER_MAP)
233  {
234  algoInputParams.m_strategyName = "map";
235 
236  std::unique_ptr<te::rst::Raster> inputRst(te::map::GetRaster(m_layer.get()));
237 
238  te::rp::ClassifierMAPStrategy::Parameters classifierparameters;
239  classifierparameters.m_trainSamplesPtr = getMAPSamples(m_roiMngDlg->getWidget()->getROISet(), inputRst.get());
240 
241  algoInputParams.setClassifierStrategyParams(classifierparameters);
242  }
243  else if(type == CLASSIFIER_EM)
244  {
245  algoInputParams.m_strategyName = "em";
246 
247  te::rp::ClassifierEMStrategy::Parameters classifierparameters;
248  classifierparameters.m_numberOfClusters = m_ui->m_emClusterSpinBox->value();
249  classifierparameters.m_maxIterations = m_ui->m_emIterationsSpinBox->value();
250  classifierparameters.m_maxInputPoints = m_ui->m_emMaxPointsLineEdit->text().toInt();
251  classifierparameters.m_epsilon = m_ui->m_emStopCriteriaLineEdit->text().toDouble();
252  classifierparameters.m_clustersMeans = std::vector<std::vector<double> >();
253 
254  algoInputParams.setClassifierStrategyParams(classifierparameters);
255  }
256  else if(type == CLASSIFIER_SAM)
257  {
258  algoInputParams.m_strategyName = "sam";
259 
260  std::unique_ptr<te::rst::Raster> inputRst(te::map::GetRaster(m_layer.get()));
261 
262  te::rp::ClassifierSAMStrategy::Parameters classifierparameters;
263  classifierparameters.m_trainSamplesPtr = getSAMSamples(m_roiMngDlg->getWidget()->getROISet(), inputRst.get());
264 
265  //get angle values
266  for(int i = 0; i < m_ui->m_samTableWidget->rowCount(); ++i)
267  {
268  double val = ((QDoubleSpinBox*)m_ui->m_samTableWidget->cellWidget(i, 3))->value();
269 
270  classifierparameters.m_maxAngularDistances.push_back(val);
271  }
272 
273  algoInputParams.setClassifierStrategyParams(classifierparameters);
274  }
275  else if(type == CLASSIFIER_ED)
276  {
277  algoInputParams.m_strategyName = "ed";
278 
279  std::unique_ptr<te::da::DataSet> ds = m_layer->getData();
280  std::size_t rpos = te::da::GetFirstPropertyPos(ds.get(), te::dt::RASTER_TYPE);
281  std::unique_ptr<te::rst::Raster> inputRst = ds->getRaster(rpos);
282 
283  te::rp::ClassifierEDStrategy::Parameters classifierparameters;
284  classifierparameters.m_trainSamplesPtr = getEDSamples(m_roiMngDlg->getWidget()->getROISet(), inputRst.get());
285 
286  algoInputParams.setClassifierStrategyParams(classifierparameters);
287  }
288 
289  //get bands
290  QList<QListWidgetItem*> selectedBands = m_ui->m_inputRasterBandsListWidget->selectedItems();
291 
292  QList<QListWidgetItem*>::const_iterator it = selectedBands.begin();
293  QList<QListWidgetItem*>::const_iterator itend = selectedBands.end();
294 
295  while(it != itend)
296  {
297  algoInputParams.m_inputRasterBands.push_back((*it)->text().toUInt());
298 
299  ++it;
300  }
301 
302  return algoInputParams;
303 }
304 
306 {
307  te::rp::Classifier::OutputParameters algoOutputParams;
308 
309  return algoOutputParams;
310 }
311 
313 {
314  return m_roiMngDlg->getWidget()->getROISet();
315 }
316 
318 {
319  m_ui->m_classifierTypeComboBox->clear();
320 
321  m_ui->m_classifierTypeComboBox->addItem(tr("ISOSeg"), CLASSIFIER_ISOSEG);
322  m_ui->m_classifierTypeComboBox->addItem(tr("K-Means"), CLASSIFIER_KMEANS);
323  m_ui->m_classifierTypeComboBox->addItem(tr("MAP - Maximum a Posteriori Probability"), CLASSIFIER_MAP);
324  m_ui->m_classifierTypeComboBox->addItem(tr("EM - Expectation Maximization"), CLASSIFIER_EM);
325  m_ui->m_classifierTypeComboBox->addItem(tr("SAM - Spectral Angle Mapper"), CLASSIFIER_SAM);
326  m_ui->m_classifierTypeComboBox->addItem(tr("ED - Euclidean Distance"), CLASSIFIER_ED);
327 }
328 
330 {
331  m_ui->m_inputRasterBandsListWidget->clear();
332 
333  assert(m_layer.get());
334 
335  std::unique_ptr<te::rst::Raster> inputRst(te::map::GetRaster(m_layer.get()));
336 
337  if(inputRst.get())
338  {
339  for(unsigned int i = 0; i < inputRst->getNumberOfBands(); ++i)
340  m_ui->m_inputRasterBandsListWidget->addItem(QString::number(i));
341  }
342 }
343 
345 {
347 
348  std::map<std::string, te::cl::ROI*> roiSetMap = rs->getROISet();
349  std::map<std::string, te::cl::ROI*>::iterator it = roiSetMap.begin();
350 
351  int count = 1;
352 
353  //iterate roi set
354  while(it != roiSetMap.end())
355  {
356  std::map<std::string, te::gm::Polygon*> roiMap = it->second->getPolygons();
357  std::map<std::string, te::gm::Polygon*>::iterator itPoly = roiMap.begin();
358 
360 
361  //iterate roi
362  while(itPoly != roiMap.end())
363  {
364  te::gm::Polygon* p = itPoly->second;
365 
366  if(p->getSRID() != m_layer->getSRID())
367  p->transform(m_layer->getSRID());
368 
371 
372  //iterate polygon
373  while (itRaster != itRasterEnd)
374  {
376 
377  raster->getValues(itRaster.getColumn(), itRaster.getRow(), cst);
378 
379  QList<QListWidgetItem*> selectedBands = m_ui->m_inputRasterBandsListWidget->selectedItems();
380  QList<QListWidgetItem*>::const_iterator itBands = selectedBands.begin();
381  QList<QListWidgetItem*>::const_iterator itendBands = selectedBands.end();
382 
384 
385  while(itBands != itendBands)
386  {
387  cstSelectedBands.push_back(cst.at((*itBands)->text().toInt()));
388  ++itBands;
389  }
390 
391  csct.push_back(cstSelectedBands);
392 
393  ++itRaster;
394  }
395 
396  ++itPoly;
397  }
398 
399  mcsctPtr->insert(te::rp::ClassifierMAPStrategy::Parameters::MClassesSamplesCT::value_type(count, csct));
400 
401  ++count;
402 
403  ++it;
404  }
405 
406  return mcsctPtr;
407 }
408 
410 {
412 
413  std::map<std::string, te::cl::ROI*> roiSetMap = rs->getROISet();
414  std::map<std::string, te::cl::ROI*>::iterator it = roiSetMap.begin();
415 
416  int count = 1;
417 
418  //iterate roi set
419  while(it != roiSetMap.end())
420  {
421  std::map<std::string, te::gm::Polygon*> roiMap = it->second->getPolygons();
422  std::map<std::string, te::gm::Polygon*>::iterator itPoly = roiMap.begin();
423 
425 
426  //iterate roi
427  while(itPoly != roiMap.end())
428  {
429  te::gm::Polygon* p = itPoly->second;
430 
431  if(p->getSRID() != m_layer->getSRID())
432  p->transform(m_layer->getSRID());
433 
436 
437  //iterate polygon
438  while (itRaster != itRasterEnd)
439  {
441 
442  raster->getValues(itRaster.getColumn(), itRaster.getRow(), cst);
443 
444  QList<QListWidgetItem*> selectedBands = m_ui->m_inputRasterBandsListWidget->selectedItems();
445  QList<QListWidgetItem*>::const_iterator itBands = selectedBands.begin();
446  QList<QListWidgetItem*>::const_iterator itendBands = selectedBands.end();
447 
449 
450  while(itBands != itendBands)
451  {
452  cstSelectedBands.push_back((*itBands)->text().toInt());
453  ++itBands;
454  }
455 
456  csct.push_back(cstSelectedBands);
457 
458  ++itRaster;
459  }
460 
461  ++itPoly;
462  }
463 
464  mcsctPtr->insert(te::rp::ClassifierEDStrategy::Parameters::MClassesSamplesCT::value_type(count, csct));
465 
466  ++count;
467 
468  ++it;
469  }
470 
471  return mcsctPtr;
472 }
473 
475 {
477 
478  std::map<std::string, te::cl::ROI*> roiSetMap = rs->getROISet();
479  std::map<std::string, te::cl::ROI*>::iterator it = roiSetMap.begin();
480 
481  int count = 1;
482 
483  //iterate roi set
484  while(it != roiSetMap.end())
485  {
486  std::map<std::string, te::gm::Polygon*> roiMap = it->second->getPolygons();
487  std::map<std::string, te::gm::Polygon*>::iterator itPoly = roiMap.begin();
488 
490 
491  //iterate roi
492  while(itPoly != roiMap.end())
493  {
494  te::gm::Polygon* p = itPoly->second;
495 
496  if(p->getSRID() != m_layer->getSRID())
497  p->transform(m_layer->getSRID());
498 
501 
502  //iterate polygon
503  while (itRaster != itRasterEnd)
504  {
506 
507  raster->getValues(itRaster.getColumn(), itRaster.getRow(), s);
508 
509  QList<QListWidgetItem*> selectedBands = m_ui->m_inputRasterBandsListWidget->selectedItems();
510  QList<QListWidgetItem*>::const_iterator itBands = selectedBands.begin();
511  QList<QListWidgetItem*>::const_iterator itendBands = selectedBands.end();
512 
514 
515  while(itBands != itendBands)
516  {
517  sBands.push_back((*itBands)->text().toInt());
518  ++itBands;
519  }
520 
521  st.push_back(sBands);
522 
523  ++itRaster;
524  }
525 
526  ++itPoly;
527  }
528 
529  cstPtr->insert(te::rp::ClassifierSAMStrategy::ClassesSamplesT::value_type(count, st));
530 
531  ++count;
532 
533  ++it;
534  }
535 
536  return cstPtr;
537 }
538 
540 {
541  if(show)
542  m_roiMngDlg->show();
543  else
544  m_roiMngDlg->hide();
545 }
546 
548 {
549  if(!m_rs)
550  return;
551 
552  int type = m_ui->m_classifierTypeComboBox->itemData(index).toInt();
553 
554  std::map<std::string, te::cl::ROI*> roiSetMap = m_rs->getROISet();
555  std::map<std::string, te::cl::ROI*>::iterator it = roiSetMap.begin();
556 
557  m_ui->m_mapTableWidget->setRowCount(0);
558 
559  m_ui->m_samTableWidget->setRowCount(0);
560 
561  m_ui->m_edTableWidget->setRowCount(0);
562 
563  m_checkNumSamples = true;
564 
565  //iterate roi set
566  while(it != roiSetMap.end())
567  {
568  //get roi info
569  if(type == CLASSIFIER_MAP)
570  {
571  fillMAPTable(it->second);
572  }
573  else if(type == CLASSIFIER_SAM)
574  {
575  fillSAMTable(it->second);
576  }
577  else if(type == CLASSIFIER_ED)
578  {
579  fillEDTable(it->second);
580  }
581 
582  ++it;
583  }
584 
585  emit completeChanged();
586 }
587 
589 {
590  m_ui->m_acquireToolButton->setChecked(false);
591  m_ui->m_samAcquireToolButton->setChecked(false);
592  m_ui->m_edAcquireToolButton->setChecked(false);
593 
594  if(!rs)
595  return;
596 
597  m_rs = rs;
598 
599  int idx = m_ui->m_classifierTypeComboBox->currentIndex();
600  onChangeClassifier(idx);
601 }
602 
604 {
605  m_roiMngDlg->setMapDisplay(mapDisplay);
606 }
607 
609 {
610  m_roiMngDlg->setActionGroup(actionGroup);
611 }
612 
614 {
615  if(!roi)
616  return;
617 
618  QColor color(roi->getColor().c_str());
619 
620  QPixmap pix(16,16);
621  pix.fill(color);
622  QIcon icon(pix);
623 
624  std::string label = roi->getLabel();
625 
626  std::size_t samples = roi->getPolygons().size();
627  QString samplesNum;
628  samplesNum.setNum(samples);
629 
630  if(samples == 0)
631  m_checkNumSamples = false;
632 
633  //add table entry
634  int mapNewRow = m_ui->m_mapTableWidget->rowCount();
635  m_ui->m_mapTableWidget->insertRow(mapNewRow);
636 
637  //Fill map table
638  QTableWidgetItem* mapItemColor = new QTableWidgetItem(icon, "");
639  mapItemColor->setFlags(Qt::ItemIsEnabled);
640  m_ui->m_mapTableWidget->setItem(mapNewRow, 0, mapItemColor);
641 
642  QTableWidgetItem* mapItemLabel = new QTableWidgetItem(QString::fromUtf8(label.c_str()));
643  mapItemLabel->setFlags(Qt::ItemIsEnabled);
644  m_ui->m_mapTableWidget->setItem(mapNewRow, 1, mapItemLabel);
645 
646  QTableWidgetItem* mapItemSamples = new QTableWidgetItem(samplesNum);
647  mapItemSamples->setFlags(Qt::ItemIsEnabled);
648  m_ui->m_mapTableWidget->setItem(mapNewRow, 2, mapItemSamples);
649 
650  m_ui->m_mapTableWidget->resizeColumnsToContents();
651 }
652 
654 {
655  if(!roi)
656  return;
657 
658  QColor color(roi->getColor().c_str());
659 
660  QPixmap pix(16,16);
661  pix.fill(color);
662  QIcon icon(pix);
663 
664  std::string label = roi->getLabel();
665 
666  std::size_t samples = roi->getPolygons().size();
667  QString samplesNum;
668  samplesNum.setNum(samples);
669 
670  if(samples == 0)
671  m_checkNumSamples = false;
672 
673  //add table entry
674  int samNewRow = m_ui->m_samTableWidget->rowCount();
675  m_ui->m_samTableWidget->insertRow(samNewRow);
676 
677  //Fill sam table
678  QTableWidgetItem* samItemColor = new QTableWidgetItem(icon, "");
679  samItemColor->setFlags(Qt::ItemIsEnabled);
680  m_ui->m_samTableWidget->setItem(samNewRow, 0, samItemColor);
681 
682  QTableWidgetItem* samItemLabel = new QTableWidgetItem(QString::fromUtf8(label.c_str()));
683  samItemLabel->setFlags(Qt::ItemIsEnabled);
684  m_ui->m_samTableWidget->setItem(samNewRow, 1, samItemLabel);
685 
686  QTableWidgetItem* samItemSamples = new QTableWidgetItem(samplesNum);
687  samItemSamples->setFlags(Qt::ItemIsEnabled);
688  m_ui->m_samTableWidget->setItem(samNewRow, 2, samItemSamples);
689 
690  QDoubleSpinBox* dsb = new QDoubleSpinBox(m_ui->m_samTableWidget);
691  dsb->setMinimum(0.0);
692  dsb->setMaximum(1.0);
693  dsb->setSingleStep(0.1);
694  dsb->setValue(0.1);
695 
696  m_ui->m_samTableWidget->setCellWidget(samNewRow, 3, dsb);
697 
698  m_ui->m_samTableWidget->resizeColumnsToContents();
699 }
700 
702 {
703  if(!roi)
704  return;
705 
706  QColor color(roi->getColor().c_str());
707 
708  QPixmap pix(16,16);
709  pix.fill(color);
710  QIcon icon(pix);
711 
712  std::string label = roi->getLabel();
713 
714  std::size_t samples = roi->getPolygons().size();
715  QString samplesNum;
716  samplesNum.setNum(samples);
717 
718  if(samples == 0)
719  m_checkNumSamples = false;
720 
721  //add table entry
722  int edNewRow = m_ui->m_edTableWidget->rowCount();
723  m_ui->m_edTableWidget->insertRow(edNewRow);
724 
725  //Fill ed table
726  QTableWidgetItem* edItemColor = new QTableWidgetItem(icon, "");
727  edItemColor->setFlags(Qt::ItemIsEnabled);
728  m_ui->m_edTableWidget->setItem(edNewRow, 0, edItemColor);
729 
730  QTableWidgetItem* edItemLabel = new QTableWidgetItem(QString::fromStdString(label));
731  edItemLabel->setFlags(Qt::ItemIsEnabled);
732  m_ui->m_edTableWidget->setItem(edNewRow, 1, edItemLabel);
733 
734  QTableWidgetItem* edItemSamples = new QTableWidgetItem(samplesNum);
735  edItemSamples->setFlags(Qt::ItemIsEnabled);
736  m_ui->m_edTableWidget->setItem(edNewRow, 2, edItemSamples);
737 
738  m_ui->m_edTableWidget->resizeColumnsToContents();
739 }
740 
742 {
743  m_roiMngDlg->clearCanvas();
744 }
745 
747 {
748  m_roiMngDlg->onMapDisplayExtentChanged();
749 }
750 
752 {
753  return m_ui->m_createPalleteCheckBox->isChecked();
754 }
std::vector< te::gm::Polygon * > m_inputPolygons
The polygons to be classified when using object-based image analysis (OBIA).
Definition: Classifier.h:120
std::map< ClassIDT, SamplesT > ClassesSamplesT
Classes samples container type definition.
Geometric property.
std::unique_ptr< Ui::ClassifierWizardPageForm > m_ui
MClassesSamplesCTPtr m_trainSamplesPtr
A shared pointer to a always-valid structure where trainning samples are stored.
boost::shared_ptr< MClassesSamplesCT > MClassesSamplesCTPtr
A shared pointer to a multi classes samples container type definition.
te::rp::Classifier::InputParameters getInputParams()
boost::shared_ptr< MClassesSamplesCT > MClassesSamplesCTPtr
A shared pointer to a multi classes samples container type definition.
bool m_enableProgressInterface
Enable (true) or disable (false) the use of a progress interface (default: disabled).
Definition: Classifier.h:115
void transform(int srid)
It converts the coordinate values of the geometry to the new spatial reference system.
unsigned int m_numberOfClusters
The number of clusters (classes) to estimate in the image.
std::string m_strategyName
The classifier strategy name see each te::rp::ClassifierStrategyFactory inherited classes documentati...
Definition: Classifier.h:121
void set(te::map::AbstractLayerPtr layer)
This method is used to set the selected layer for classifier operation.
std::map< ClassIDT, ClassSamplesContainerT > MClassesSamplesCT
Multi-classes samples container type definition.
virtual void getValues(unsigned int c, unsigned int r, std::vector< double > &values) const
Returns the imaginary attribute values in all complex bands of a cell.
This class implements the strategy to iterate with spatial restriction, the iteration occurs inside a...
void setMapDisplay(te::qt::widgets::MapDisplay *mapDisplay)
te::rp::ClassifierEDStrategy::Parameters::MClassesSamplesCTPtr getEDSamples(te::cl::ROISet *rs, te::rst::Raster *raster)
A widget to control the display of a set of layers.
unsigned int getRow() const
Returns the current row in iterator.
static te::dt::Date ds(2010, 01, 01)
unsigned int m_maxInputPoints
The maximum number of points used to estimate the clusters (default = 1000).
Classifier output parameters.
Definition: Classifier.h:133
boost::shared_ptr< ClassesSamplesT > ClassesSamplesTPtr
A shared pointer to a multi classes samples container type definition.
TEGEOMEXPORT void Multi2Single(const te::gm::Geometry *g, std::vector< te::gm::Geometry * > &geoms)
It will get a GeometryCollection and distribute in a vector.
ClassesSamplesTPtr m_trainSamplesPtr
A shared pointer to a always-valid structure where trainning samples are stored.
A ROISet is a set of ROI&#39;s.
Definition: ROISet.h:53
te::rp::ClassifierMAPStrategy::Parameters::MClassesSamplesCTPtr getMAPSamples(te::cl::ROISet *rs, te::rst::Raster *raster)
std::vector< double > SampleT
Class sample type definition.
te::rp::ClassifierSAMStrategy::ClassesSamplesTPtr getSAMSamples(te::cl::ROISet *rs, te::rst::Raster *raster)
MClassesSamplesCTPtr m_trainSamplesPtr
A shared pointer to a always-valid structure where trainning samples are stored.
std::map< ClassIDT, ClassSamplesContainerT > MClassesSamplesCT
Multi-classes samples container type definition.
unsigned int m_K
The number of clusters (means) to detect in image.
int getSRID() const _NOEXCEPT_OP(true)
It returns the Spatial Reference System ID associated to this geometric object.
std::vector< double > ClassSampleT
Class sample type definition.
static PolygonIterator end(const te::rst::Raster *r, const te::gm::Polygon *p)
Returns an iterator referring to after the end of the iterator.
This file defines a class for a Classifier Wizard page.
An abstract class for raster data strucutures.
This class is a dialog for the ROI Manager widget.
URI C++ Library.
Definition: Attributes.h:37
GeomType getGeometryType() const
It returns the geometry subtype allowed for the property.
te::gm::Polygon * p
std::vector< unsigned int > m_inputRasterBands
Bands to be processed from the input raster.
Definition: Classifier.h:119
unsigned int m_maxInputPoints
The maximum number of points used to estimate the clusters (default = 1000).
void setActionGroup(QActionGroup *actionGroup)
A region of interest (often abbreviated ROI), is a selected subset of samples within a dataset identi...
Definition: ROI.h:60
Q_DECLARE_METATYPE(te::map::AbstractLayerPtr) te
double m_epsilon
The stop criteria. When the clusters change in a value smaller then epsilon, the convergence is achie...
std::unique_ptr< te::qt::widgets::ROIManagerDialog > m_roiMngDlg
static PolygonIterator begin(const te::rst::Raster *r, const te::gm::Polygon *p, const IterationType iterationType)
Returns an iterator referring to the first value of the band.
TEMAPEXPORT te::rst::Raster * GetRaster(AbstractLayer *layer)
It gets the raster referenced by the given data set layer.
Polygon is a subclass of CurvePolygon whose rings are defined by linear rings.
Definition: Polygon.h:50
unsigned int m_maxIterations
The maximum of iterations (E/M steps) to perform if convergence is not achieved.
void setClassifierStrategyParams(const ClassifierStrategyParameters &p)
Set specific classifier strategy parameters.
std::vector< SampleT > SamplesT
Class samples container type definition.
std::string getLabel()
Get the ROI label.
Definition: ROI.cpp:47
unsigned int m_maxIterations
The maximum of iterations to perform if convergence is not achieved.
double m_acceptanceThreshold
The acceptance threshold (the closer to 100%, few clusters are created).
TEDATAACCESSEXPORT std::size_t GetFirstPropertyPos(const te::da::DataSet *dataset, int datatype)
unsigned int getColumn() const
Returns the current column in iterator.
TEDATAACCESSEXPORT te::gm::GeometryProperty * GetFirstGeomProperty(const DataSetType *dt)
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
std::vector< ClassSampleT > ClassSamplesContainerT
Class samples container type definition.
void FreeContents(boost::unordered_map< K, V * > &m)
This function can be applied to a map of pointers. It will delete each pointer in the map...
Definition: BoostUtils.h:55
void setList(std::list< te::map::AbstractLayerPtr > &layerList)
std::vector< ClassSampleT > ClassSamplesContainerT
Class samples container type definition.
std::vector< double > m_maxAngularDistances
This is a vector of maximum acceptable angles (radians) between one pixel spectra and the reference s...
std::vector< std::vector< double > > m_clustersMeans
The previously estimated means of the clusters (optional).
std::map< std::string, te::cl::ROI * > & getROISet()
Get the roi set map.
Definition: ROISet.cpp:77
te::rp::Classifier::OutputParameters getOutputParams()
std::vector< double > ClassSampleT
Class sample type definition.
Classifier input parameters.
Definition: Classifier.h:75
double m_epsilon
The stop criteria. When the clusters change in a value smaller then epsilon, the convergence is achie...
std::map< std::string, te::gm::Polygon * > & getPolygons()
Get all polygons belongs to this roi.
Definition: ROI.cpp:62
const std::string & getName() const
It returns the property name.
Definition: Property.h:127
std::string getColor()
Get the ROI color defined by a hexadecimal color name.
Definition: ROI.cpp:57