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 "../../widgets/canvas/Canvas.h"
42 #include "../../widgets/canvas/MapDisplay.h"
47 #include "ui_MixtureModelWizardPageForm.h"
50 #include <QtGui/QGridLayout>
53 #include <boost/uuid/random_generator.hpp>
54 #include <boost/uuid/uuid_io.hpp>
59 #define PATTERN_SIZE 12
62 : QWizardPage(parent),
63 m_ui(new Ui::MixtureModelWizardPageForm),
80 connect(
m_ui->m_tableWidget, SIGNAL(itemChanged(QTableWidgetItem*)),
this, SLOT(
onItemChanged(QTableWidgetItem*)));
82 connect(
m_ui->m_acquireToolButton, SIGNAL(toggled(
bool)),
this, SLOT(
showNavigator(
bool)));
99 this->setTitle(tr(
"Mixture Model"));
100 this->setSubTitle(tr(
"Select the type of mixture model and set their specific parameters."));
102 m_ui->m_removeToolButton->setIcon(QIcon::fromTheme(
"list-remove"));
103 m_ui->m_acquireToolButton->setIcon(QIcon::fromTheme(
"wand"));
108 m_components.clear();
117 if(m_ui->m_tableWidget->rowCount() == 0)
120 int nBands = m_ui->m_bandTableWidget->rowCount();
122 bool isChecked =
false;
123 for(
int i = 0; i < nBands; ++i)
125 QCheckBox* checkBox = (QCheckBox*)m_ui->m_bandTableWidget->cellWidget(i, 0);
127 if(checkBox->isChecked())
144 m_navigatorDlg->set(m_layer);
156 int idx = m_ui->m_typeComboBox->currentIndex();
157 int type = m_ui->m_typeComboBox->itemData(idx).toInt();
161 if(type == MIXMODEL_LINEAR)
168 else if(type == MIXMODEL_PCA)
177 unsigned selectedBands = 0;
178 std::vector<bool> selectedBandsVector;
180 for (
int i = 0; i < m_ui->m_bandTableWidget->rowCount(); ++i)
182 QCheckBox* bandCheckBox = (QCheckBox*) m_ui->m_bandTableWidget->cellWidget(i, 0);
184 if (bandCheckBox->isChecked())
186 selectedBandsVector.push_back(
true);
191 QComboBox *sensorComboBox = (QComboBox*) m_ui->m_bandTableWidget->cellWidget(i, 1);
192 algoInputParams.
m_inputSensorBands.push_back(std::string(sensorComboBox->currentText().toStdString()));
195 selectedBandsVector.push_back(
false);
199 std::map<std::string, MixModelComponent>::iterator it = m_components.begin();
200 std::vector<double> components;
202 while(it != m_components.end())
206 for (
unsigned int i = 0; i < selectedBandsVector.size(); i++)
207 if (selectedBandsVector[i])
208 components.push_back(it->second.m_values[i]);
210 algoInputParams.
m_components[it->second.m_name] = components;
216 return algoInputParams;
223 algoOutputParams.
m_normalizeOutput = m_ui->m_normalizeOutputCheckBox->isChecked();
226 return algoOutputParams;
231 if(m_components.empty() ==
false)
237 assert(m_layer.get());
242 std::auto_ptr<te::da::DataSet> ds = m_layer->getData();
247 std::auto_ptr<te::rst::Raster> inputRst = ds->getRaster(rpos);
253 int currentColumn = pixelLocation.
x;
254 int currentRow = pixelLocation.
y;
256 if (currentColumn < 0 || currentColumn >= (
int) inputRst->getNumberOfColumns())
258 if (currentRow < 0 || currentRow >= (
int) inputRst->getNumberOfRows())
262 static boost::uuids::basic_random_generator<boost::mt19937> gen;
263 boost::uuids::uuid u = gen();
264 std::string
id = boost::uuids::to_string(u);
267 QString className = QString(tr(
"Component ") + QString::number(m_countComponents++));
270 std::vector<double> componentsVector;
273 for(
unsigned b = 0 ; b < inputRst->getNumberOfBands(); b++)
275 inputRst->getValue(currentColumn, currentRow, value, b);
277 componentsVector.push_back(value);
286 mmc.
m_name = className.toStdString();
291 m_components.insert(std::map<std::string, MixModelComponent >::value_type(
id, mmc));
300 std::string
id = item->data(Qt::UserRole).toString().toStdString();
302 std::string name = item->text().toStdString();
304 std::map<std::string, MixModelComponent >::iterator it = m_components.find(
id);
308 if(it != m_components.end())
310 if(it->second.m_name != name)
312 it->second.m_name = name;
323 if(m_ui->m_tableWidget->currentRow() == -1)
326 std::string
id = m_ui->m_tableWidget->item(m_ui->m_tableWidget->currentRow(), 0)->data(Qt::UserRole).toString().toStdString();
328 std::map<std::string, MixModelComponent >::iterator it = m_components.find(
id);
330 if(it != m_components.end())
332 m_components.erase(it);
334 if(m_components.empty())
335 m_countComponents = 0;
344 m_navigatorDlg->show();
346 m_navigatorDlg->hide();
351 m_ui->m_acquireToolButton->setChecked(
false);
356 m_ui->m_typeComboBox->clear();
358 m_ui->m_typeComboBox->addItem(tr(
"Linear"), MIXMODEL_LINEAR);
359 m_ui->m_typeComboBox->addItem(tr(
"PCA - Principal Component Analysis"), MIXMODEL_PCA);
364 assert(m_layer.get());
367 std::auto_ptr<te::da::DataSet> ds = m_layer->getData();
372 std::auto_ptr<te::rst::Raster> inputRst = ds->getRaster(rpos);
377 QStringList sensorsDescriptions;
380 for(
unsigned int i = 0; i < bandNames.size(); i++)
381 sensorsDescriptions.append(bandNames[i].c_str());
383 m_ui->m_bandTableWidget->setRowCount(0);
386 for(
unsigned b = 0 ; b < inputRst->getNumberOfBands(); b++)
388 int newrow = m_ui->m_bandTableWidget->rowCount();
389 m_ui->m_bandTableWidget->insertRow(newrow);
391 QString bName(tr(
"Band "));
392 bName.append(QString::number(b));
394 QCheckBox* bandCheckBox =
new QCheckBox(bName,
this);
397 bandCheckBox->setChecked(
true);
399 QComboBox* sensorDescriptionComboBox =
new QComboBox(
this);
400 sensorDescriptionComboBox->addItems(sensorsDescriptions);
402 m_ui->m_bandTableWidget->setCellWidget(newrow, 0, bandCheckBox);
403 m_ui->m_bandTableWidget->setCellWidget(newrow, 1, sensorDescriptionComboBox);
406 m_ui->m_bandTableWidget->resizeColumnToContents(0);
415 m_display->getDraftPixmap()->fill(QColor(0, 0, 0, 0));
424 std::map<std::string, MixModelComponent>::iterator it = m_components.begin();
426 while(it != m_components.end())
434 canvasInstance.draw(&point);
439 m_display->repaint();
444 m_ui->m_tableWidget->setRowCount(0);
446 std::map<std::string, MixModelComponent>::iterator it = m_components.begin();
448 while(it != m_components.end())
450 int newrow = m_ui->m_tableWidget->rowCount();
451 m_ui->m_tableWidget->insertRow(newrow);
454 QTableWidgetItem* itemName =
new QTableWidgetItem(QString::fromStdString(it->second.m_name));
455 itemName->setFlags(Qt::ItemIsEnabled | Qt::ItemIsEditable);
456 itemName->setData(Qt::UserRole, QVariant(it->second.m_id.c_str()));
457 m_ui->m_tableWidget->setItem(newrow, 0, itemName);
460 QComboBox* combo =
new QComboBox(m_ui->m_tableWidget);
462 for(
size_t t = 0; t < it->second.m_values.size(); ++t)
464 combo->addItem(QString::number(it->second.m_values[t]));
467 m_ui->m_tableWidget->setCellWidget(newrow, 1, combo);
492 m_ui->m_tableWidget->sortByColumn(0, Qt::AscendingOrder);
496 emit completeChanged();
std::map< std::string, std::vector< double > > m_components
A set of endmembers and its radiances.
TESEEXPORT Fill * CreateFill(const std::string &color, const std::string &opacity)
Creates a fill.
void setX(const double &x)
It sets the Point x-coordinate value.
A Fill specifies the pattern for filling an area geometry.
This file has the RasterNavigatorWidget class.
te::color::RGBAColor ** m_rgbaMark
bool m_createErrorRaster
A flag to indicate that output raster will include the error bands.
void setY(const double &y)
It sets the Point y-coordinate value.
void showNavigator(bool show)
A Qt4 widget to control the display of a set of layers.
te::rp::MixtureModel::InputParameters getInputParams()
A Stroke specifies the appearance of a linear geometry.
te::gm::Coord2D m_coordGeo
TESEEXPORT Mark * CreateMark(const std::string &wellKnownName, Stroke *stroke, Fill *fill)
Creates a mark.
std::vector< std::string > m_inputSensorBands
The names of the sensor/bands.
An utility struct for representing 2D coordinates.
te::map::AbstractLayerPtr get()
std::auto_ptr< Ui::MixtureModelWizardPageForm > m_ui
bool m_normalizeOutput
A flag to indicate that output raster will be normalized, by default [0, 255].
TESEEXPORT Stroke * CreateStroke(const std::string &color, const std::string &width)
Creates a stroke.
double m_lly
Lower left corner y-coordinate.
te::gm::Coord2D m_coordGrid
std::string m_strategyName
The mixture model strategy name see each te::rp::MixtureModelStrategyFactory inherited classes docume...
std::vector< double > m_values
double m_ury
Upper right corner y-coordinate.
void fillMixtureModelTypes()
void setMixtureModelStrategyParams(const StrategyParameters &p)
Set specific mixture model strategy parameters.
A canvas built on top of Qt.
std::vector< std::string > GetBandNames()
Returns a vector os with band's names.
A point with x and y coordinate values.
TEDATAACCESSEXPORT std::size_t GetFirstPropertyPos(const te::da::DataSet *dataset, int datatype)
This file defines a class for a MixtureModel Wizard page.
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 Raster Navigator Dialog.
MixtureModel output parameters.
This class is a dialog for the RasterNavigator widget.
void Free(std::vector< T * > *v)
This function can be applied to a pointer to a vector of pointers.
void onMapDisplayExtentChanged()
double m_llx
Lower left corner x-coordinate.
MixtureModel input parameters.
te::rp::MixtureModel::OutputParameters getOutputParams()
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
MixtureModelWizardPage(QWidget *parent=0)
void onPointPicked(double x, double y, te::qt::widgets::MapDisplay *map)
static MarkRendererManager & getInstance()
It returns a reference to the singleton instance.
~MixtureModelWizardPage()
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).
std::auto_ptr< te::qt::widgets::RasterNavigatorDialog > m_navigatorDlg
void onItemChanged(QTableWidgetItem *item)
std::vector< unsigned int > m_inputRasterBands
Bands to be processed from the input raster.
void onRemoveToolButtonClicked()
void set(te::map::AbstractLayerPtr layer)
This method is used to set the selected layer for mixture model operation.