27 #include "../../../common/StringUtils.h"
28 #include "../../../dataaccess/dataset/DataSet.h"
29 #include "../../../dataaccess/utils/Utils.h"
30 #include "../../../raster/Raster.h"
31 #include "../../../rp/ClassifierISOSegStrategy.h"
32 #include "../../widgets/canvas/Canvas.h"
33 #include "../../widgets/canvas/MapDisplay.h"
35 #include "ui_ClassifierWizardPageForm.h"
38 #include <QGridLayout>
39 #include <QtGui/QMessageBox>
42 #include <boost/uuid/random_generator.hpp>
43 #include <boost/uuid/uuid_io.hpp>
50 : QWizardPage(parent),
51 m_ui(new Ui::ClassifierWizardPageForm),
61 connect(
m_ui->m_tableWidget, SIGNAL(itemChanged(QTableWidgetItem*)),
this, SLOT(
onItemChanged(QTableWidgetItem*)));
66 this->setTitle(tr(
"Classifier"));
67 this->setSubTitle(tr(
"Select the type of classifier and set their specific parameters."));
69 m_ui->m_removeToolButton->setIcon(QIcon::fromTheme(
"list-remove"));
74 std::map<std::string, ClassifierSamples>::iterator it = m_samples.begin();
76 while(it != m_samples.end())
78 delete it->second.m_poly;
95 int idx = m_ui->m_classifierTypeComboBox->currentIndex();
96 int type = m_ui->m_classifierTypeComboBox->itemData(idx).toInt();
100 if(type == CLASSIFIER_ISOSEG)
105 classifierparameters.
m_acceptanceThreshold = m_ui->m_acceptanceThresholdComboBox->currentText().toDouble();
111 QList<QListWidgetItem*> selectedBands = m_ui->m_inputRasterBandsListWidget->selectedItems();
113 QList<QListWidgetItem*>::const_iterator it = selectedBands.begin();
114 QList<QListWidgetItem*>::const_iterator itend = selectedBands.end();
124 std::map<std::string, ClassifierSamples>::iterator itSamples = m_samples.begin();
126 std::vector<te::gm::Polygon*> polyVec;
128 while(itSamples != m_samples.end())
130 polyVec.push_back(itSamples->second.m_poly);
137 return algoInputParams;
144 return algoOutputParams;
149 m_ui->m_classifierTypeComboBox->clear();
151 m_ui->m_classifierTypeComboBox->addItem(tr(
"ISOSeg"), CLASSIFIER_ISOSEG);
156 m_ui->m_inputRasterBandsListWidget->clear();
158 assert(m_layer.get());
161 std::auto_ptr<te::da::DataSet> ds = m_layer->getData();
167 std::auto_ptr<te::rst::Raster> inputRst = ds->getRaster(rpos);
171 for(
unsigned int i = 0; i < inputRst->getNumberOfBands(); ++i)
173 m_ui->m_inputRasterBandsListWidget->addItem(QString::number(i));
183 m_display->getDraftPixmap()->fill(QColor(0, 0, 0, 0));
191 canvasInstance.setPolygonContourWidth(1);
194 std::map<std::string, ClassifierSamples>::iterator it = m_samples.begin();
196 while(it != m_samples.end())
200 canvasInstance.draw(poly);
205 m_display->repaint();
210 m_ui->m_tableWidget->setRowCount(0);
212 std::map<std::string, ClassifierSamples>::iterator it = m_samples.begin();
214 while(it != m_samples.end())
216 int newrow = m_ui->m_tableWidget->rowCount();
217 m_ui->m_tableWidget->insertRow(newrow);
220 QTableWidgetItem* itemName =
new QTableWidgetItem(QString::fromStdString(it->second.m_name));
221 itemName->setFlags(Qt::ItemIsEnabled | Qt::ItemIsEditable);
222 itemName->setData(Qt::UserRole, QVariant(it->second.m_id.c_str()));
223 m_ui->m_tableWidget->setItem(newrow, 0, itemName);
228 m_ui->m_tableWidget->sortByColumn(0, Qt::AscendingOrder);
235 if(m_samples.empty() ==
false)
241 assert(m_layer.get());
246 static boost::uuids::basic_random_generator<boost::mt19937> gen;
247 boost::uuids::uuid u = gen();
248 std::string
id = boost::uuids::to_string(u);
251 QString className = QString(tr(
"Sample ") + QString::number(m_countSamples++));
255 cs.
m_name = className.toStdString();
258 m_samples.insert(std::map<std::string, ClassifierSamples >::value_type(
id, cs));
265 std::string
id = item->data(Qt::UserRole).toString().toStdString();
267 std::string name = item->text().toStdString();
269 std::map<std::string, ClassifierSamples >::iterator it = m_samples.find(
id);
273 if(it != m_samples.end())
275 if(it->second.m_name != name)
277 it->second.m_name = name;
288 if(m_ui->m_tableWidget->currentRow() == -1)
291 std::string
id = m_ui->m_tableWidget->item(m_ui->m_tableWidget->currentRow(), 0)->data(Qt::UserRole).toString().toStdString();
293 std::map<std::string, ClassifierSamples >::iterator it = m_samples.find(
id);
295 if(it != m_samples.end())
299 if(m_samples.empty())
std::vector< te::gm::Polygon * > m_inputPolygons
The polygons to be classified when using object-based image analysis (OBIA).
double m_acceptanceThreshold
The acceptance threshold (the closer to 100%, few clusters are created).
std::auto_ptr< Ui::ClassifierWizardPageForm > m_ui
te::rp::Classifier::OutputParameters getOutputParams()
Polygon is a subclass of CurvePolygon whose rings are defined by linear rings.
te::rp::Classifier::InputParameters getInputParams()
std::vector< unsigned int > m_inputRasterBands
Bands to be processed from the input raster.
ClassifierWizardPage(QWidget *parent=0)
double m_lly
Lower left corner y-coordinate.
Classifier output parameters.
double m_ury
Upper right corner y-coordinate.
void onItemChanged(QTableWidgetItem *item)
A helper class for 32-bit RGBA (Red-Green-Blue-Alpha channel) color.
A canvas built on top of Qt.
TEDATAACCESSEXPORT std::size_t GetFirstPropertyPos(const te::da::DataSet *dataset, int datatype)
double m_urx
Upper right corner x-coordinate.
A widget to control the display of a set of layers.
This file defines a class for a Classifier Wizard page.
void set(te::map::AbstractLayerPtr layer)
This method is used to set the selected layer for classifier operation.
#define TE_OPAQUE
For an RGBA color this is the value of the alpha-channel for totally opaque.
std::string m_strategyName
The classifier strategy name see each te::rp::ClassifierStrategyFactory inherited classes documentati...
double m_llx
Lower left corner x-coordinate.
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
void onMapDisplayExtentChanged()
void fillClassifierTypes()
An Envelope defines a 2D rectangular region.
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).
Classifier input parameters.
void onRemoveToolButtonClicked()
void onGeomAquired(te::gm::Polygon *poly, te::qt::widgets::MapDisplay *map)
void setClassifierStrategyParams(const StrategyParameters &p)
Set specific classifier strategy parameters.