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)));
82 connect(
m_ui->m_classifierTypeComboBox, SIGNAL(activated(
int)),
this, SIGNAL(completeChanged()));
83 connect(
m_ui->m_inputRasterBandsListWidget, SIGNAL(itemSelectionChanged()),
this, SIGNAL(completeChanged()));
87 m_ui->m_acquireToolButton->setIcon(QIcon::fromTheme(
"wand"));
88 m_ui->m_samAcquireToolButton->setIcon(QIcon::fromTheme(
"wand"));
98 int idx = m_ui->m_classifierTypeComboBox->currentIndex();
99 int type = m_ui->m_classifierTypeComboBox->itemData(idx).toInt();
101 if(type == CLASSIFIER_ISOSEG)
103 if(m_ui->m_isosegLayersComboBox->currentText().isEmpty())
106 else if(type == CLASSIFIER_MAP)
108 if(m_ui->m_mapTableWidget->rowCount() == 0)
111 else if(type == CLASSIFIER_SAM)
113 if(m_ui->m_samTableWidget->rowCount() == 0)
117 if(m_ui->m_inputRasterBandsListWidget->selectedItems().empty())
127 m_roiMngDlg->set(m_layer);
134 m_roiMngDlg->setList(layerList);
136 m_ui->m_isosegLayersComboBox->clear();
138 std::list<te::map::AbstractLayerPtr>::iterator it = layerList.begin();
140 while(it != layerList.end())
144 std::auto_ptr<te::da::DataSetType> dsType = l->getSchema();
146 if(dsType->hasGeom())
147 m_ui->m_isosegLayersComboBox->addItem(it->get()->getTitle().c_str(), QVariant::fromValue(l));
155 int idx = m_ui->m_classifierTypeComboBox->currentIndex();
156 int type = m_ui->m_classifierTypeComboBox->itemData(idx).toInt();
160 if(type == CLASSIFIER_ISOSEG)
165 classifierparameters.
m_acceptanceThreshold = m_ui->m_acceptanceThresholdComboBox->currentText().toDouble();
168 int idxLayer = m_ui->m_isosegLayersComboBox->currentIndex();
169 QVariant varLayer = m_ui->m_isosegLayersComboBox->itemData(idxLayer, Qt::UserRole);
173 std::auto_ptr<te::da::DataSetType> dsType = layer->getSchema();
178 std::auto_ptr<te::da::DataSet> ds = layer->getData();
179 ds->moveBeforeFirst();
181 while(ds->moveNext())
192 else if(type == CLASSIFIER_KMEANS)
197 classifierparameters.
m_K = m_ui->m_kMeansClusterSpinBox->value();
198 classifierparameters.
m_maxIterations = m_ui->m_kMeansIterationsSpinBox->value();
199 classifierparameters.
m_maxInputPoints = m_ui->m_kMeansMaxPointsLineEdit->text().toInt();
200 classifierparameters.
m_epsilon = m_ui->m_kMeansStopCriteriaLineEdit->text().toDouble();
204 else if(type == CLASSIFIER_MAP)
208 std::auto_ptr<te::da::DataSet> ds = m_layer->getData();
210 std::auto_ptr<te::rst::Raster> inputRst = ds->getRaster(rpos);
213 classifierparameters.
m_trainSamplesPtr = getMAPSamples(m_roiMngDlg->getWidget()->getROISet(), inputRst.get());
217 else if(type == CLASSIFIER_EM)
223 classifierparameters.
m_maxIterations = m_ui->m_emIterationsSpinBox->value();
224 classifierparameters.
m_maxInputPoints = m_ui->m_emMaxPointsLineEdit->text().toInt();
225 classifierparameters.
m_epsilon = m_ui->m_emStopCriteriaLineEdit->text().toDouble();
226 classifierparameters.
m_clustersMeans = std::vector<std::vector<double> >();
230 else if(type == CLASSIFIER_SAM)
234 std::auto_ptr<te::da::DataSet> ds = m_layer->getData();
236 std::auto_ptr<te::rst::Raster> inputRst = ds->getRaster(rpos);
239 classifierparameters.
m_trainSamplesPtr = getSAMSamples(m_roiMngDlg->getWidget()->getROISet(), inputRst.get());
242 for(
int i = 0; i < m_ui->m_samTableWidget->rowCount(); ++i)
244 double val = ((QDoubleSpinBox*)m_ui->m_samTableWidget->cellWidget(i, 3))->value();
253 QList<QListWidgetItem*> selectedBands = m_ui->m_inputRasterBandsListWidget->selectedItems();
255 QList<QListWidgetItem*>::const_iterator it = selectedBands.begin();
256 QList<QListWidgetItem*>::const_iterator itend = selectedBands.end();
265 return algoInputParams;
272 return algoOutputParams;
277 return m_roiMngDlg->getWidget()->
getROISet();
282 m_ui->m_classifierTypeComboBox->clear();
284 m_ui->m_classifierTypeComboBox->addItem(tr(
"ISOSeg"), CLASSIFIER_ISOSEG);
285 m_ui->m_classifierTypeComboBox->addItem(tr(
"KMeans"), CLASSIFIER_KMEANS);
286 m_ui->m_classifierTypeComboBox->addItem(tr(
"MAP - Maximum a Posteriori Probability"), CLASSIFIER_MAP);
287 m_ui->m_classifierTypeComboBox->addItem(tr(
"EM - Expectation Maximization"), CLASSIFIER_EM);
288 m_ui->m_classifierTypeComboBox->addItem(tr(
"SAM - Spectral Angle Mapper"), CLASSIFIER_SAM);
293 m_ui->m_inputRasterBandsListWidget->clear();
295 assert(m_layer.get());
298 std::auto_ptr<te::da::DataSet> ds = m_layer->getData();
304 std::auto_ptr<te::rst::Raster> inputRst = ds->getRaster(rpos);
308 for(
unsigned int i = 0; i < inputRst->getNumberOfBands(); ++i)
310 m_ui->m_inputRasterBandsListWidget->addItem(QString::number(i));
320 std::map<std::string, te::cl::ROI*> roiSetMap = rs->
getROISet();
321 std::map<std::string, te::cl::ROI*>::iterator it = roiSetMap.begin();
326 while(it != roiSetMap.end())
328 std::map<std::string, te::gm::Polygon*> roiMap = it->second->getPolygons();
329 std::map<std::string, te::gm::Polygon*>::iterator itPoly = roiMap.begin();
334 while(itPoly != roiMap.end())
342 while (itRaster != itRasterEnd)
356 mcsctPtr->insert(te::rp::ClassifierMAPStrategy::Parameters::MClassesSamplesCT::value_type(count, csct));
370 std::map<std::string, te::cl::ROI*> roiSetMap = rs->
getROISet();
371 std::map<std::string, te::cl::ROI*>::iterator it = roiSetMap.begin();
376 while(it != roiSetMap.end())
378 std::map<std::string, te::gm::Polygon*> roiMap = it->second->getPolygons();
379 std::map<std::string, te::gm::Polygon*>::iterator itPoly = roiMap.begin();
384 while(itPoly != roiMap.end())
392 while (itRaster != itRasterEnd)
406 cstPtr->insert(te::rp::ClassifierSAMStrategy::ClassesSamplesT::value_type(count, st));
426 m_ui->m_acquireToolButton->setChecked(
false);
427 m_ui->m_samAcquireToolButton->setChecked(
false);
432 int idx = m_ui->m_classifierTypeComboBox->currentIndex();
433 int type = m_ui->m_classifierTypeComboBox->itemData(idx).toInt();
435 if(type == CLASSIFIER_MAP)
437 m_ui->m_mapTableWidget->setRowCount(0);
442 std::map<std::string, te::cl::ROI*> roiSetMap = rs->
getROISet();
443 std::map<std::string, te::cl::ROI*>::iterator it = roiSetMap.begin();
446 while(it != roiSetMap.end())
455 samplesNum.setNum(samples);
457 QColor color(r->
getColor().c_str());
460 int newrow = m_ui->m_mapTableWidget->rowCount();
461 m_ui->m_mapTableWidget->insertRow(newrow);
467 QTableWidgetItem* itemColor =
new QTableWidgetItem(icon,
"");
468 itemColor->setFlags(Qt::ItemIsEnabled);
469 m_ui->m_mapTableWidget->setItem(newrow, 0, itemColor);
471 QTableWidgetItem* itemLabel =
new QTableWidgetItem(QString::fromStdString(label));
472 itemLabel->setFlags(Qt::ItemIsEnabled);
473 m_ui->m_mapTableWidget->setItem(newrow, 1, itemLabel);
475 QTableWidgetItem* itemSamples =
new QTableWidgetItem(samplesNum);
476 itemSamples->setFlags(Qt::ItemIsEnabled);
477 m_ui->m_mapTableWidget->setItem(newrow, 2, itemSamples);
482 m_ui->m_mapTableWidget->resizeColumnsToContents();
484 else if(type == CLASSIFIER_SAM)
486 m_ui->m_samTableWidget->setRowCount(0);
491 std::map<std::string, te::cl::ROI*> roiSetMap = rs->
getROISet();
492 std::map<std::string, te::cl::ROI*>::iterator it = roiSetMap.begin();
495 while(it != roiSetMap.end())
504 samplesNum.setNum(samples);
506 QColor color(r->
getColor().c_str());
509 int newrow = m_ui->m_mapTableWidget->rowCount();
510 m_ui->m_samTableWidget->insertRow(newrow);
516 QTableWidgetItem* itemColor =
new QTableWidgetItem(icon,
"");
517 itemColor->setFlags(Qt::ItemIsEnabled);
518 m_ui->m_samTableWidget->setItem(newrow, 0, itemColor);
520 QTableWidgetItem* itemLabel =
new QTableWidgetItem(QString::fromStdString(label));
521 itemLabel->setFlags(Qt::ItemIsEnabled);
522 m_ui->m_samTableWidget->setItem(newrow, 1, itemLabel);
524 QTableWidgetItem* itemSamples =
new QTableWidgetItem(samplesNum);
525 itemSamples->setFlags(Qt::ItemIsEnabled);
526 m_ui->m_samTableWidget->setItem(newrow, 2, itemSamples);
528 QDoubleSpinBox* dsb =
new QDoubleSpinBox(m_ui->m_samTableWidget);
529 dsb->setMinimum(0.0);
530 dsb->setMaximum(1.0);
531 dsb->setSingleStep(0.1);
534 m_ui->m_samTableWidget->setCellWidget(newrow, 3, dsb);
539 m_ui->m_samTableWidget->resizeColumnsToContents();
542 emit completeChanged();
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.
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.