27 #include "../../../common/STLUtils.h"
28 #include "../../../dataaccess/dataset/DataSet.h"
29 #include "../../../dataaccess/utils/Utils.h"
30 #include "../../../geometry/Point.h"
31 #include "../../../maptools/MarkRendererManager.h"
32 #include "../../../raster/Raster.h"
33 #include "../../../rp/MixtureModel.h"
34 #include "../../../rp/MixtureModelLinearStrategy.h"
35 #include "../../../rp/MixtureModelPCAStrategy.h"
36 #include "../../../rp/Functions.h"
37 #include "../../../se/Fill.h"
38 #include "../../../se/Mark.h"
39 #include "../../../se/Stroke.h"
40 #include "../../../se/Utils.h"
41 #include "../canvas/Canvas.h"
42 #include "../canvas/MapDisplay.h"
46 #include "ui_MixtureModelWizardPageForm.h"
49 #include <QGridLayout>
52 #include <boost/uuid/random_generator.hpp>
53 #include <boost/uuid/uuid_io.hpp>
58 #define PATTERN_SIZE 12
61 : QWizardPage(parent),
62 m_ui(new Ui::MixtureModelWizardPageForm),
79 connect(
m_ui->m_tableWidget, SIGNAL(itemChanged(QTableWidgetItem*)),
this, SLOT(
onItemChanged(QTableWidgetItem*)));
81 connect(
m_ui->m_acquireToolButton, SIGNAL(toggled(
bool)),
this, SLOT(
showNavigator(
bool)));
98 this->setTitle(tr(
"Mixture Model"));
99 this->setSubTitle(tr(
"Select the type of mixture model and set their specific parameters."));
101 m_ui->m_removeToolButton->setIcon(QIcon::fromTheme(
"list-remove"));
102 m_ui->m_acquireToolButton->setIcon(QIcon::fromTheme(
"wand"));
107 m_components.clear();
116 if(m_ui->m_tableWidget->rowCount() == 0)
119 int nBands = m_ui->m_bandTableWidget->rowCount();
121 bool isChecked =
false;
122 for(
int i = 0; i < nBands; ++i)
124 QCheckBox* checkBox = (QCheckBox*)m_ui->m_bandTableWidget->cellWidget(i, 0);
126 if(checkBox->isChecked())
143 m_navigatorDlg->set(m_layer);
155 int idx = m_ui->m_typeComboBox->currentIndex();
156 int type = m_ui->m_typeComboBox->itemData(idx).toInt();
160 if(type == MIXMODEL_LINEAR)
167 else if(type == MIXMODEL_PCA)
176 unsigned selectedBands = 0;
177 std::vector<bool> selectedBandsVector;
179 for (
int i = 0; i < m_ui->m_bandTableWidget->rowCount(); ++i)
181 QCheckBox* bandCheckBox = (QCheckBox*) m_ui->m_bandTableWidget->cellWidget(i, 0);
183 if (bandCheckBox->isChecked())
185 selectedBandsVector.push_back(
true);
190 QComboBox *sensorComboBox = (QComboBox*) m_ui->m_bandTableWidget->cellWidget(i, 1);
191 algoInputParams.
m_inputSensorBands.push_back(std::string(sensorComboBox->currentText().toStdString()));
194 selectedBandsVector.push_back(
false);
198 std::map<std::string, MixModelComponent>::iterator it = m_components.begin();
199 std::vector<double> components;
201 while(it != m_components.end())
205 for (
unsigned int i = 0; i < selectedBandsVector.size(); i++)
206 if (selectedBandsVector[i])
207 components.push_back(it->second.m_values[i]);
209 algoInputParams.
m_components[it->second.m_name] = components;
215 return algoInputParams;
222 algoOutputParams.
m_normalizeOutput = m_ui->m_normalizeOutputCheckBox->isChecked();
225 return algoOutputParams;
230 if(m_components.empty() ==
false)
236 assert(m_layer.get());
239 std::auto_ptr<te::da::DataSet> ds = m_layer->getData();
244 std::auto_ptr<te::rst::Raster> inputRst = ds->getRaster(rpos);
250 int currentColumn = pixelLocation.
x;
251 int currentRow = pixelLocation.
y;
253 if (currentColumn < 0 || currentColumn >= (
int) inputRst->getNumberOfColumns())
255 if (currentRow < 0 || currentRow >= (
int) inputRst->getNumberOfRows())
259 static boost::uuids::basic_random_generator<boost::mt19937> gen;
260 boost::uuids::uuid u = gen();
261 std::string
id = boost::uuids::to_string(u);
264 QString className = QString(tr(
"Component ") + QString::number(m_countComponents++));
267 std::vector<double> componentsVector;
270 for(
unsigned b = 0 ; b < inputRst->getNumberOfBands(); b++)
272 inputRst->getValue(currentColumn, currentRow, value, b);
274 componentsVector.push_back(value);
283 mmc.
m_name = className.toStdString();
288 m_components.insert(std::map<std::string, MixModelComponent >::value_type(
id, mmc));
297 std::string
id = item->data(Qt::UserRole).toString().toStdString();
299 std::string name = item->text().toStdString();
301 std::map<std::string, MixModelComponent >::iterator it = m_components.find(
id);
305 if(it != m_components.end())
307 if(it->second.m_name != name)
309 it->second.m_name = name;
320 if(m_ui->m_tableWidget->currentRow() == -1)
323 std::string
id = m_ui->m_tableWidget->item(m_ui->m_tableWidget->currentRow(), 0)->data(Qt::UserRole).toString().toStdString();
325 std::map<std::string, MixModelComponent >::iterator it = m_components.find(
id);
327 if(it != m_components.end())
329 m_components.erase(it);
331 if(m_components.empty())
332 m_countComponents = 0;
341 m_navigatorDlg->show();
343 m_navigatorDlg->hide();
348 m_ui->m_acquireToolButton->setChecked(
false);
353 m_ui->m_typeComboBox->clear();
355 m_ui->m_typeComboBox->addItem(tr(
"Linear"), MIXMODEL_LINEAR);
356 m_ui->m_typeComboBox->addItem(tr(
"PCA - Principal Component Analysis"), MIXMODEL_PCA);
361 assert(m_layer.get());
364 std::auto_ptr<te::da::DataSet> ds = m_layer->getData();
369 std::auto_ptr<te::rst::Raster> inputRst = ds->getRaster(rpos);
374 QStringList sensorsDescriptions;
377 for(
unsigned int i = 0; i < bandNames.size(); i++)
378 sensorsDescriptions.append(bandNames[i].c_str());
380 m_ui->m_bandTableWidget->setRowCount(0);
383 for(
unsigned b = 0 ; b < inputRst->getNumberOfBands(); b++)
385 int newrow = m_ui->m_bandTableWidget->rowCount();
386 m_ui->m_bandTableWidget->insertRow(newrow);
388 QString bName(tr(
"Band "));
389 bName.append(QString::number(b));
391 QCheckBox* bandCheckBox =
new QCheckBox(bName,
this);
394 bandCheckBox->setChecked(
true);
396 QComboBox* sensorDescriptionComboBox =
new QComboBox(
this);
397 sensorDescriptionComboBox->addItems(sensorsDescriptions);
399 m_ui->m_bandTableWidget->setCellWidget(newrow, 0, bandCheckBox);
400 m_ui->m_bandTableWidget->setCellWidget(newrow, 1, sensorDescriptionComboBox);
403 m_ui->m_bandTableWidget->resizeColumnToContents(0);
421 std::map<std::string, MixModelComponent>::iterator it = m_components.begin();
423 while(it != m_components.end())
431 canvasInstance.draw(&point);
436 mapDisplay->repaint();
441 m_ui->m_tableWidget->setRowCount(0);
443 std::map<std::string, MixModelComponent>::iterator it = m_components.begin();
445 while(it != m_components.end())
447 int newrow = m_ui->m_tableWidget->rowCount();
448 m_ui->m_tableWidget->insertRow(newrow);
451 QTableWidgetItem* itemName =
new QTableWidgetItem(QString::fromStdString(it->second.m_name));
452 itemName->setFlags(Qt::ItemIsEnabled | Qt::ItemIsEditable);
453 itemName->setData(Qt::UserRole, QVariant(it->second.m_id.c_str()));
454 m_ui->m_tableWidget->setItem(newrow, 0, itemName);
457 QComboBox* combo =
new QComboBox(m_ui->m_tableWidget);
459 for(
size_t t = 0; t < it->second.m_values.size(); ++t)
461 combo->addItem(QString::number(it->second.m_values[t]));
464 m_ui->m_tableWidget->setCellWidget(newrow, 1, combo);
489 m_ui->m_tableWidget->sortByColumn(0, Qt::AscendingOrder);
493 emit completeChanged();
te::color::RGBAColor ** m_rgbaMark
This file defines a class for a MixtureModel Wizard page.
te::rp::MixtureModel::InputParameters getInputParams()
std::auto_ptr< te::qt::widgets::RasterNavigatorDialog > m_navigatorDlg
std::vector< double > m_values
std::vector< std::string > GetBandNames()
Returns a vector os with band's names.
double m_urx
Upper right corner x-coordinate.
void fillMixtureModelTypes()
An utility struct for representing 2D coordinates.
void onItemChanged(QTableWidgetItem *item)
void onRemoveToolButtonClicked()
void onMapDisplayExtentChanged()
te::map::AbstractLayerPtr get()
void showNavigator(bool show)
This file defines a class for a Raster Navigator Dialog.
void Free(std::vector< T * > *v)
This function can be applied to a pointer to a vector of pointers.
double m_llx
Lower left corner x-coordinate.
static MarkRendererManager & getInstance()
It returns a reference to the singleton instance.
bool m_normalizeOutput
A flag to indicate that output raster will be normalized, by default [0, 255].
A point with x and y coordinate values.
An Envelope defines a 2D rectangular region.
std::auto_ptr< Ui::MixtureModelWizardPageForm > m_ui
virtual const te::gm::Envelope & getExtent() const
It returns the world extent showned by the MapDisplay.
void set(te::map::AbstractLayerPtr layer)
This method is used to set the selected layer for mixture model operation.
A Fill specifies the pattern for filling an area geometry.
TESEEXPORT Mark * CreateMark(const std::string &wellKnownName, Stroke *stroke, Fill *fill)
Creates a mark.
MixtureModelWizardPage(QWidget *parent=0)
double m_lly
Lower left corner y-coordinate.
TESEEXPORT Stroke * CreateStroke(const std::string &color, const std::string &width)
Creates a stroke.
te::rp::MixtureModel::OutputParameters getOutputParams()
MixtureModel output parameters.
void onPointPicked(double x, double y)
void setX(const double &x)
It sets the Point x-coordinate value.
double m_ury
Upper right corner y-coordinate.
A Stroke specifies the appearance of a linear geometry.
TEDATAACCESSEXPORT std::size_t GetFirstPropertyPos(const te::da::DataSet *dataset, int datatype)
void setY(const double &y)
It sets the Point y-coordinate value.
bool m_createErrorRaster
A flag to indicate that output raster will include the error bands.
te::gm::Coord2D m_coordGrid
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
~MixtureModelWizardPage()
te::gm::Coord2D m_coordGeo
TESEEXPORT Fill * CreateFill(const std::string &color, const std::string &opacity)
Creates a fill.