27 #include "../../../dataaccess/dataset/DataSet.h"
28 #include "../../../dataaccess/dataset/DataSetType.h"
29 #include "../../../dataaccess/utils/Utils.h"
30 #include "../../../geometry/GeometryProperty.h"
31 #include "../../../geometry/MultiPolygon.h"
32 #include "../../../raster/Raster.h"
33 #include "../../../raster/PositionIterator.h"
34 #include "../../../rp/ClassifierEMStrategy.h"
35 #include "../../../rp/ClassifierKMeansStrategy.h"
36 #include "../../../rp/ClassifierISOSegStrategy.h"
37 #include "../classification/ROIManagerDialog.h"
38 #include "../classification/ROIManagerWidget.h"
40 #include "ui_ClassifierWizardPageForm.h"
43 #include <QGridLayout>
44 #include <QDoubleValidator>
45 #include <QIntValidator>
46 #include <QMessageBox>
54 : QWizardPage(parent),
55 m_ui(new Ui::ClassifierWizardPageForm),
63 QIntValidator* intMaxPoints =
new QIntValidator(
this);
64 intMaxPoints->setBottom(0);
65 m_ui->m_kMeansMaxPointsLineEdit->setValidator(intMaxPoints);
67 QDoubleValidator* doubleStopCriteria =
new QDoubleValidator(
this);
68 doubleStopCriteria->setBottom(0.0);
69 m_ui->m_kMeansStopCriteriaLineEdit->setValidator(doubleStopCriteria);
72 this->setTitle(tr(
"Classifier"));
73 this->setSubTitle(tr(
"Select the type of classifier and set their specific parameters."));
79 connect(
m_ui->m_acquireToolButton, SIGNAL(toggled(
bool)),
this, SLOT(
showROIManager(
bool)));
80 connect(
m_ui->m_samAcquireToolButton, SIGNAL(toggled(
bool)),
this, SLOT(
showROIManager(
bool)));
85 m_ui->m_acquireToolButton->setIcon(QIcon::fromTheme(
"wand"));
86 m_ui->m_samAcquireToolButton->setIcon(QIcon::fromTheme(
"wand"));
98 m_roiMngDlg->set(m_layer);
105 m_roiMngDlg->setList(layerList);
107 m_ui->m_isosegLayersComboBox->clear();
109 std::list<te::map::AbstractLayerPtr>::iterator it = layerList.begin();
111 while(it != layerList.end())
115 std::auto_ptr<te::da::DataSetType> dsType = l->getSchema();
117 if(dsType->hasGeom())
118 m_ui->m_isosegLayersComboBox->addItem(it->get()->getTitle().c_str(), QVariant::fromValue(l));
126 int idx = m_ui->m_classifierTypeComboBox->currentIndex();
127 int type = m_ui->m_classifierTypeComboBox->itemData(idx).toInt();
131 if(type == CLASSIFIER_ISOSEG)
136 classifierparameters.
m_acceptanceThreshold = m_ui->m_acceptanceThresholdComboBox->currentText().toDouble();
139 int idxLayer = m_ui->m_isosegLayersComboBox->currentIndex();
140 QVariant varLayer = m_ui->m_isosegLayersComboBox->itemData(idxLayer, Qt::UserRole);
144 std::auto_ptr<te::da::DataSetType> dsType = layer->getSchema();
149 std::auto_ptr<te::da::DataSet> ds = layer->getData();
150 ds->moveBeforeFirst();
152 while(ds->moveNext())
163 else if(type == CLASSIFIER_KMEANS)
168 classifierparameters.
m_K = m_ui->m_kMeansClusterSpinBox->value();
169 classifierparameters.
m_maxIterations = m_ui->m_kMeansIterationsSpinBox->value();
170 classifierparameters.
m_maxInputPoints = m_ui->m_kMeansMaxPointsLineEdit->text().toInt();
171 classifierparameters.
m_epsilon = m_ui->m_kMeansStopCriteriaLineEdit->text().toDouble();
175 else if(type == CLASSIFIER_MAP)
179 std::auto_ptr<te::da::DataSet> ds = m_layer->getData();
181 std::auto_ptr<te::rst::Raster> inputRst = ds->getRaster(rpos);
184 classifierparameters.
m_trainSamplesPtr = getMAPSamples(m_roiMngDlg->getWidget()->getROISet(), inputRst.get());
188 else if(type == CLASSIFIER_EM)
194 classifierparameters.
m_maxIterations = m_ui->m_emIterationsSpinBox->value();
195 classifierparameters.
m_maxInputPoints = m_ui->m_emMaxPointsLineEdit->text().toInt();
196 classifierparameters.
m_epsilon = m_ui->m_emStopCriteriaLineEdit->text().toDouble();
197 classifierparameters.
m_clustersMeans = std::vector<std::vector<double> >();
201 else if(type == CLASSIFIER_SAM)
205 std::auto_ptr<te::da::DataSet> ds = m_layer->getData();
207 std::auto_ptr<te::rst::Raster> inputRst = ds->getRaster(rpos);
210 classifierparameters.
m_trainSamplesPtr = getSAMSamples(m_roiMngDlg->getWidget()->getROISet(), inputRst.get());
213 for(
int i = 0; i < m_ui->m_samTableWidget->rowCount(); ++i)
215 double val = ((QDoubleSpinBox*)m_ui->m_samTableWidget->cellWidget(i, 3))->value();
224 QList<QListWidgetItem*> selectedBands = m_ui->m_inputRasterBandsListWidget->selectedItems();
226 QList<QListWidgetItem*>::const_iterator it = selectedBands.begin();
227 QList<QListWidgetItem*>::const_iterator itend = selectedBands.end();
236 return algoInputParams;
243 return algoOutputParams;
248 m_ui->m_classifierTypeComboBox->clear();
250 m_ui->m_classifierTypeComboBox->addItem(tr(
"ISOSeg"), CLASSIFIER_ISOSEG);
251 m_ui->m_classifierTypeComboBox->addItem(tr(
"KMeans"), CLASSIFIER_KMEANS);
252 m_ui->m_classifierTypeComboBox->addItem(tr(
"MAP - Maximum a Posteriori Probability"), CLASSIFIER_MAP);
253 m_ui->m_classifierTypeComboBox->addItem(tr(
"EM - Expectation Maximization"), CLASSIFIER_EM);
254 m_ui->m_classifierTypeComboBox->addItem(tr(
"SAM - Spectral Angle Mapper"), CLASSIFIER_SAM);
259 m_ui->m_inputRasterBandsListWidget->clear();
261 assert(m_layer.get());
264 std::auto_ptr<te::da::DataSet> ds = m_layer->getData();
270 std::auto_ptr<te::rst::Raster> inputRst = ds->getRaster(rpos);
274 for(
unsigned int i = 0; i < inputRst->getNumberOfBands(); ++i)
276 m_ui->m_inputRasterBandsListWidget->addItem(QString::number(i));
286 std::map<std::string, te::cl::ROI*> roiSetMap = rs->
getROISet();
287 std::map<std::string, te::cl::ROI*>::iterator it = roiSetMap.begin();
292 while(it != roiSetMap.end())
294 std::map<std::string, te::gm::Polygon*> roiMap = it->second->getPolygons();
295 std::map<std::string, te::gm::Polygon*>::iterator itPoly = roiMap.begin();
300 while(itPoly != roiMap.end())
308 while (itRaster != itRasterEnd)
322 mcsctPtr->insert(te::rp::ClassifierMAPStrategy::Parameters::MClassesSamplesCT::value_type(count, csct));
336 std::map<std::string, te::cl::ROI*> roiSetMap = rs->
getROISet();
337 std::map<std::string, te::cl::ROI*>::iterator it = roiSetMap.begin();
342 while(it != roiSetMap.end())
344 std::map<std::string, te::gm::Polygon*> roiMap = it->second->getPolygons();
345 std::map<std::string, te::gm::Polygon*>::iterator itPoly = roiMap.begin();
350 while(itPoly != roiMap.end())
358 while (itRaster != itRasterEnd)
372 cstPtr->insert(te::rp::ClassifierSAMStrategy::ClassesSamplesT::value_type(count, st));
392 m_ui->m_acquireToolButton->setChecked(
false);
393 m_ui->m_samAcquireToolButton->setChecked(
false);
398 int idx = m_ui->m_classifierTypeComboBox->currentIndex();
399 int type = m_ui->m_classifierTypeComboBox->itemData(idx).toInt();
401 if(type == CLASSIFIER_MAP)
403 m_ui->m_mapTableWidget->setRowCount(0);
408 std::map<std::string, te::cl::ROI*> roiSetMap = rs->
getROISet();
409 std::map<std::string, te::cl::ROI*>::iterator it = roiSetMap.begin();
412 while(it != roiSetMap.end())
421 samplesNum.setNum(samples);
423 QColor color(r->
getColor().c_str());
426 int newrow = m_ui->m_mapTableWidget->rowCount();
427 m_ui->m_mapTableWidget->insertRow(newrow);
433 QTableWidgetItem* itemColor =
new QTableWidgetItem(icon,
"");
434 itemColor->setFlags(Qt::ItemIsEnabled);
435 m_ui->m_mapTableWidget->setItem(newrow, 0, itemColor);
437 QTableWidgetItem* itemLabel =
new QTableWidgetItem(QString::fromStdString(label));
438 itemLabel->setFlags(Qt::ItemIsEnabled);
439 m_ui->m_mapTableWidget->setItem(newrow, 1, itemLabel);
441 QTableWidgetItem* itemSamples =
new QTableWidgetItem(samplesNum);
442 itemSamples->setFlags(Qt::ItemIsEnabled);
443 m_ui->m_mapTableWidget->setItem(newrow, 2, itemSamples);
448 m_ui->m_mapTableWidget->resizeColumnsToContents();
450 else if(type == CLASSIFIER_SAM)
452 m_ui->m_samTableWidget->setRowCount(0);
457 std::map<std::string, te::cl::ROI*> roiSetMap = rs->
getROISet();
458 std::map<std::string, te::cl::ROI*>::iterator it = roiSetMap.begin();
461 while(it != roiSetMap.end())
470 samplesNum.setNum(samples);
472 QColor color(r->
getColor().c_str());
475 int newrow = m_ui->m_mapTableWidget->rowCount();
476 m_ui->m_samTableWidget->insertRow(newrow);
482 QTableWidgetItem* itemColor =
new QTableWidgetItem(icon,
"");
483 itemColor->setFlags(Qt::ItemIsEnabled);
484 m_ui->m_samTableWidget->setItem(newrow, 0, itemColor);
486 QTableWidgetItem* itemLabel =
new QTableWidgetItem(QString::fromStdString(label));
487 itemLabel->setFlags(Qt::ItemIsEnabled);
488 m_ui->m_samTableWidget->setItem(newrow, 1, itemLabel);
490 QTableWidgetItem* itemSamples =
new QTableWidgetItem(samplesNum);
491 itemSamples->setFlags(Qt::ItemIsEnabled);
492 m_ui->m_samTableWidget->setItem(newrow, 2, itemSamples);
494 QDoubleSpinBox* dsb =
new QDoubleSpinBox(m_ui->m_samTableWidget);
495 dsb->setMinimum(0.0);
496 dsb->setMaximum(1.0);
497 dsb->setSingleStep(0.1);
500 m_ui->m_samTableWidget->setCellWidget(newrow, 3, dsb);
505 m_ui->m_samTableWidget->resizeColumnsToContents();
MultiPolygon is a MultiSurface whose elements are Polygons.
std::map< ClassIDT, SamplesT > ClassesSamplesT
Classes samples container type definition.
MClassesSamplesCTPtr m_trainSamplesPtr
A shared pointer to a always-valid structure where trainning samples are stored.
te::rp::Classifier::InputParameters getInputParams()
boost::shared_ptr< MClassesSamplesCT > MClassesSamplesCTPtr
A shared pointer to a multi classes samples container type definition.
ClassifierWizardPage(QWidget *parent=0)
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::auto_ptr< te::qt::widgets::ROIManagerDialog > m_roiMngDlg
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...
unsigned int getRow() const
Returns the current row in iterator.
unsigned int m_maxInputPoints
The maximum number of points used to estimate the clusters (default = 1000).
Classifier output parameters.
boost::shared_ptr< ClassesSamplesT > ClassesSamplesTPtr
A shared pointer to a multi classes samples container type definition.
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)
std::auto_ptr< Ui::ClassifierWizardPageForm > m_ui
std::map< ClassIDT, ClassSamplesContainerT > MClassesSamplesCT
Multi-classes samples container type definition.
unsigned int m_K
The number of clusters (means) to detect in image.
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.
GeomType getGeometryType() const
It returns the geometry subtype allowed for the property.
void showROIManager(bool show)
unsigned int m_maxInputPoints
The maximum number of points used to estimate the clusters (default = 1000).
A region of interest (often abbreviated ROI), is a selected subset of samples within a dataset identi...
Q_DECLARE_METATYPE(te::map::AbstractLayerPtr)
double m_epsilon
The stop criteria. When the clusters change in a value smaller then epsilon, the convergence is achie...
void onRoiSetChanged(te::cl::ROISet *rs)
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.
static PolygonIterator begin(const te::rst::Raster *r, const te::gm::Polygon *p)
Returns an iterator referring to the first value of the band.
std::vector< SampleT > SamplesT
Class samples container type definition.
const std::vector< Geometry * > & getGeometries() const
It returns a reference to the internal list of geometries.
std::string getLabel()
Get the ROI label.
void onROIManagerClosed()
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 setList(std::list< te::map::AbstractLayerPtr > &layerList)
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()
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.
const std::string & getName() const
It returns the property name.
std::string getColor()
Get the ROI color defined by a hexadecimal color name.