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" 44 #include "ui_ClassifierWizardPageForm.h" 47 #include <QGridLayout> 48 #include <QDoubleValidator> 49 #include <QIntValidator> 50 #include <QMessageBox> 57 te::qt::widgets::ClassifierWizardPage::ClassifierWizardPage(
QWidget* parent)
59 m_ui(new
Ui::ClassifierWizardPageForm),
66 fillClassifierTypes();
68 QIntValidator* intMaxPoints =
new QIntValidator(
this);
69 intMaxPoints->setBottom(0);
70 m_ui->m_kMeansMaxPointsLineEdit->setValidator(intMaxPoints);
72 QDoubleValidator* doubleStopCriteria =
new QDoubleValidator(
this);
73 doubleStopCriteria->setBottom(0.0);
74 m_ui->m_kMeansStopCriteriaLineEdit->setValidator(doubleStopCriteria);
77 this->setTitle(tr(
"Classifier"));
78 this->setSubTitle(tr(
"Select the type of classifier and set their specific parameters."));
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()));
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"));
101 int idx =
m_ui->m_classifierTypeComboBox->currentIndex();
102 int type =
m_ui->m_classifierTypeComboBox->itemData(idx).toInt();
106 if(
m_ui->m_isosegLayersComboBox->currentText().isEmpty())
116 if(
m_ui->m_inputRasterBandsListWidget->selectedItems().empty())
135 m_ui->m_isosegLayersComboBox->clear();
137 std::list<te::map::AbstractLayerPtr>::iterator it = layerList.begin();
139 while(it != layerList.end())
143 std::unique_ptr<te::da::DataSetType> dsType = l->getSchema();
145 if(dsType->hasGeom())
146 m_ui->m_isosegLayersComboBox->addItem(it->get()->getTitle().c_str(), QVariant::fromValue(l));
154 int idx =
m_ui->m_classifierTypeComboBox->currentIndex();
155 int type =
m_ui->m_classifierTypeComboBox->itemData(idx).toInt();
167 if(
m_ui->m_distanceTypeComboBox_->currentText() ==
"Mahalanobis" )
179 int idxLayer =
m_ui->m_isosegLayersComboBox->currentIndex();
180 QVariant varLayer =
m_ui->m_isosegLayersComboBox->itemData(idxLayer, Qt::UserRole);
184 std::unique_ptr<te::da::DataSetType> dsType = layer->getSchema();
190 std::unique_ptr<te::da::DataSet>
ds = layer->getData();
192 ds->moveBeforeFirst();
194 while(ds->moveNext())
196 std::unique_ptr<te::gm::Geometry> geometry = std::move(ds->getGeometry(gp->
getName()));
198 std::unique_ptr<te::gm::MultiPolygon> mp(dynamic_cast<te::gm::MultiPolygon*>(geometry->clone()));
200 mp->transform(
m_layer->getSRID());
202 std::vector<te::gm::Geometry*> singleGeomVec;
206 for(
auto g : singleGeomVec)
208 if(g->getMBR()->intersects(
m_layer->getExtent()))
225 classifierparameters.
m_K =
m_ui->m_kMeansClusterSpinBox->value();
228 classifierparameters.
m_epsilon =
m_ui->m_kMeansStopCriteriaLineEdit->text().toDouble();
251 classifierparameters.
m_epsilon =
m_ui->m_emStopCriteriaLineEdit->text().toDouble();
252 classifierparameters.
m_clustersMeans = std::vector<std::vector<double> >();
266 for(
int i = 0; i <
m_ui->m_samTableWidget->rowCount(); ++i)
268 double val = ((QDoubleSpinBox*)
m_ui->m_samTableWidget->cellWidget(i, 3))->value();
279 std::unique_ptr<te::da::DataSet>
ds =
m_layer->getData();
281 std::unique_ptr<te::rst::Raster> inputRst = ds->getRaster(rpos);
290 QList<QListWidgetItem*> selectedBands =
m_ui->m_inputRasterBandsListWidget->selectedItems();
292 QList<QListWidgetItem*>::const_iterator it = selectedBands.begin();
293 QList<QListWidgetItem*>::const_iterator itend = selectedBands.end();
302 return algoInputParams;
309 return algoOutputParams;
319 m_ui->m_classifierTypeComboBox->clear();
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);
331 m_ui->m_inputRasterBandsListWidget->clear();
339 for(
unsigned int i = 0; i < inputRst->getNumberOfBands(); ++i)
340 m_ui->m_inputRasterBandsListWidget->addItem(QString::number(i));
348 std::map<std::string, te::cl::ROI*> roiSetMap = rs->
getROISet();
349 std::map<std::string, te::cl::ROI*>::iterator it = roiSetMap.begin();
354 while(it != roiSetMap.end())
356 std::map<std::string, te::gm::Polygon*> roiMap = it->second->getPolygons();
357 std::map<std::string, te::gm::Polygon*>::iterator itPoly = roiMap.begin();
362 while(itPoly != roiMap.end())
373 while (itRaster != itRasterEnd)
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();
385 while(itBands != itendBands)
387 cstSelectedBands.push_back(cst.at((*itBands)->text().toInt()));
391 csct.push_back(cstSelectedBands);
399 mcsctPtr->insert(te::rp::ClassifierMAPStrategy::Parameters::MClassesSamplesCT::value_type(count, csct));
413 std::map<std::string, te::cl::ROI*> roiSetMap = rs->
getROISet();
414 std::map<std::string, te::cl::ROI*>::iterator it = roiSetMap.begin();
419 while(it != roiSetMap.end())
421 std::map<std::string, te::gm::Polygon*> roiMap = it->second->getPolygons();
422 std::map<std::string, te::gm::Polygon*>::iterator itPoly = roiMap.begin();
427 while(itPoly != roiMap.end())
438 while (itRaster != itRasterEnd)
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();
450 while(itBands != itendBands)
452 cstSelectedBands.push_back((*itBands)->text().toInt());
456 csct.push_back(cstSelectedBands);
464 mcsctPtr->insert(te::rp::ClassifierEDStrategy::Parameters::MClassesSamplesCT::value_type(count, csct));
478 std::map<std::string, te::cl::ROI*> roiSetMap = rs->
getROISet();
479 std::map<std::string, te::cl::ROI*>::iterator it = roiSetMap.begin();
484 while(it != roiSetMap.end())
486 std::map<std::string, te::gm::Polygon*> roiMap = it->second->getPolygons();
487 std::map<std::string, te::gm::Polygon*>::iterator itPoly = roiMap.begin();
492 while(itPoly != roiMap.end())
503 while (itRaster != itRasterEnd)
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();
515 while(itBands != itendBands)
517 sBands.push_back((*itBands)->text().toInt());
521 st.push_back(sBands);
529 cstPtr->insert(te::rp::ClassifierSAMStrategy::ClassesSamplesT::value_type(count, st));
552 int type =
m_ui->m_classifierTypeComboBox->itemData(index).toInt();
554 std::map<std::string, te::cl::ROI*> roiSetMap =
m_rs->
getROISet();
555 std::map<std::string, te::cl::ROI*>::iterator it = roiSetMap.begin();
557 m_ui->m_mapTableWidget->setRowCount(0);
559 m_ui->m_samTableWidget->setRowCount(0);
561 m_ui->m_edTableWidget->setRowCount(0);
566 while(it != roiSetMap.end())
585 emit completeChanged();
590 m_ui->m_acquireToolButton->setChecked(
false);
591 m_ui->m_samAcquireToolButton->setChecked(
false);
592 m_ui->m_edAcquireToolButton->setChecked(
false);
599 int idx =
m_ui->m_classifierTypeComboBox->currentIndex();
618 QColor color(roi->
getColor().c_str());
624 std::string label = roi->
getLabel();
628 samplesNum.setNum(samples);
634 int mapNewRow =
m_ui->m_mapTableWidget->rowCount();
635 m_ui->m_mapTableWidget->insertRow(mapNewRow);
638 QTableWidgetItem* mapItemColor =
new QTableWidgetItem(icon,
"");
639 mapItemColor->setFlags(Qt::ItemIsEnabled);
640 m_ui->m_mapTableWidget->setItem(mapNewRow, 0, mapItemColor);
642 QTableWidgetItem* mapItemLabel =
new QTableWidgetItem(QString::fromUtf8(label.c_str()));
643 mapItemLabel->setFlags(Qt::ItemIsEnabled);
644 m_ui->m_mapTableWidget->setItem(mapNewRow, 1, mapItemLabel);
646 QTableWidgetItem* mapItemSamples =
new QTableWidgetItem(samplesNum);
647 mapItemSamples->setFlags(Qt::ItemIsEnabled);
648 m_ui->m_mapTableWidget->setItem(mapNewRow, 2, mapItemSamples);
650 m_ui->m_mapTableWidget->resizeColumnsToContents();
658 QColor color(roi->
getColor().c_str());
664 std::string label = roi->
getLabel();
668 samplesNum.setNum(samples);
674 int samNewRow =
m_ui->m_samTableWidget->rowCount();
675 m_ui->m_samTableWidget->insertRow(samNewRow);
678 QTableWidgetItem* samItemColor =
new QTableWidgetItem(icon,
"");
679 samItemColor->setFlags(Qt::ItemIsEnabled);
680 m_ui->m_samTableWidget->setItem(samNewRow, 0, samItemColor);
682 QTableWidgetItem* samItemLabel =
new QTableWidgetItem(QString::fromUtf8(label.c_str()));
683 samItemLabel->setFlags(Qt::ItemIsEnabled);
684 m_ui->m_samTableWidget->setItem(samNewRow, 1, samItemLabel);
686 QTableWidgetItem* samItemSamples =
new QTableWidgetItem(samplesNum);
687 samItemSamples->setFlags(Qt::ItemIsEnabled);
688 m_ui->m_samTableWidget->setItem(samNewRow, 2, samItemSamples);
690 QDoubleSpinBox* dsb =
new QDoubleSpinBox(
m_ui->m_samTableWidget);
691 dsb->setMinimum(0.0);
692 dsb->setMaximum(1.0);
693 dsb->setSingleStep(0.1);
696 m_ui->m_samTableWidget->setCellWidget(samNewRow, 3, dsb);
698 m_ui->m_samTableWidget->resizeColumnsToContents();
706 QColor color(roi->
getColor().c_str());
712 std::string label = roi->
getLabel();
716 samplesNum.setNum(samples);
722 int edNewRow =
m_ui->m_edTableWidget->rowCount();
723 m_ui->m_edTableWidget->insertRow(edNewRow);
726 QTableWidgetItem* edItemColor =
new QTableWidgetItem(icon,
"");
727 edItemColor->setFlags(Qt::ItemIsEnabled);
728 m_ui->m_edTableWidget->setItem(edNewRow, 0, edItemColor);
730 QTableWidgetItem* edItemLabel =
new QTableWidgetItem(QString::fromStdString(label));
731 edItemLabel->setFlags(Qt::ItemIsEnabled);
732 m_ui->m_edTableWidget->setItem(edNewRow, 1, edItemLabel);
734 QTableWidgetItem* edItemSamples =
new QTableWidgetItem(samplesNum);
735 edItemSamples->setFlags(Qt::ItemIsEnabled);
736 m_ui->m_edTableWidget->setItem(edNewRow, 2, edItemSamples);
738 m_ui->m_edTableWidget->resizeColumnsToContents();
753 return m_ui->m_createPalleteCheckBox->isChecked();
std::map< ClassIDT, SamplesT > ClassesSamplesT
Classes samples container type definition.
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.
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.
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)
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.
void fillEDTable(te::cl::ROI *roi)
void onROIManagerClosed(te::cl::ROISet *rs)
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.
void fillClassifierTypes()
ClassesSamplesTPtr m_trainSamplesPtr
A shared pointer to a always-valid structure where trainning samples are stored.
A ROISet is a set of ROI's.
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.
Bhattacharyya Distance Type.
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.
GeomType getGeometryType() const
It returns the geometry subtype allowed for the property.
void showROIManager(bool show)
void fillMAPTable(te::cl::ROI *roi)
unsigned int m_maxInputPoints
The maximum number of points used to estimate the clusters (default = 1000).
void setActionGroup(QActionGroup *actionGroup)
Mahalanobis Distance Type.
A region of interest (often abbreviated ROI), is a selected subset of samples within a dataset identi...
DistanceType m_distanceType
Distance type.
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.
unsigned int m_maxIterations
The maximum of iterations (E/M steps) to perform if convergence is not achieved.
std::vector< SampleT > SamplesT
Class samples container type definition.
std::string getLabel()
Get the ROI label.
void fillSAMTable(te::cl::ROI *roi)
unsigned int m_maxIterations
The maximum of iterations to perform if convergence is not achieved.
te::map::AbstractLayerPtr m_layer
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)
void onChangeClassifier(int index)
void onMapDisplayExtentChanged()
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...
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.
te::rp::Classifier::OutputParameters getOutputParams()
std::vector< double > ClassSampleT
Class sample type definition.
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.
te::cl::ROISet * getROISet()
const std::string & getName() const
It returns the property name.
std::string getColor()
Get the ROI color defined by a hexadecimal color name.