27 #include "../canvas/Canvas.h" 
   28 #include "../canvas/MapDisplay.h" 
   29 #include "../../../common/StringUtils.h" 
   30 #include "../../../geometry/Coord2D.h" 
   31 #include "../../../geometry/Envelope.h" 
   32 #include "../../../geometry/Point.h" 
   33 #include "../../../maptools/Utils.h" 
   34 #include "../../../raster/Grid.h" 
   35 #include "../../../rp/MixtureModel.h" 
   36 #include "../../../rp/MixtureModelLinearStrategy.h" 
   37 #include "../../../rp/MixtureModelPCAStrategy.h" 
   38 #include "../../../rp/Functions.h" 
   39 #include "../../widgets/tools/CoordTracking.h" 
   40 #include "../../widgets/tools/Pan.h" 
   41 #include "../../widgets/tools/ZoomWheel.h" 
   45 #include <ui_MixtureModelForm.h> 
   50 #include <QGridLayout> 
   54 #include <QMessageBox> 
   60   : QObject(parent), m_mDisplay(parent)
 
   70   if(event->type() == QEvent::Enter)
 
   71     m_mDisplay->grabKeyboard();
 
   72   else if(event->type() == QEvent::Leave)
 
   73     m_mDisplay->releaseKeyboard();
 
   74   else if(event->type() == QEvent::KeyPress)
 
   76     if(m_mDisplay->underMouse())
 
   77       emit(keyPressedOverMapDisplay(((QKeyEvent*)event)->key()));
 
   84                                                         const std::map<std::string, std::string>& outpuRasterInfo, QWidget* parent, Qt::WindowFlags f)
 
   86     m_inputRasterPtr(te::map::
GetRaster(inputLayerPtr.get())),
 
   87     m_outpuRasterDSType(outpuRasterDSType),
 
   88     m_outpuRasterInfo(outpuRasterInfo),
 
   89     m_maxComponentsInserted(0)
 
   91   m_uiPtr = 
new Ui::MixtureModelForm;
 
   96   QGridLayout* rasterGridLayout = 
new QGridLayout(
m_uiPtr->m_rasterFrame);
 
  101   std::list<te::map::AbstractLayerPtr> layerList;
 
  102   layerList.push_back(inputLayerPtr);
 
  126   QStringList sensorsDescriptions;
 
  128   for(
unsigned int i = 0; i < bandNames.size(); i++)
 
  129     sensorsDescriptions.append(bandNames[i].c_str());
 
  132   QGridLayout *bandsListLayout = 
new QGridLayout();
 
  136     QCheckBox* bandCheckBox = 
new QCheckBox(tr(bname.c_str()));
 
  138     QComboBox* sensorDescriptionComboBox = 
new QComboBox();
 
  139     sensorDescriptionComboBox->addItems(sensorsDescriptions);
 
  141     bandsListLayout->addWidget(bandCheckBox, b, 0);
 
  142     bandsListLayout->addWidget(sensorDescriptionComboBox, b, 1);
 
  144   m_uiPtr->m_bandsListGroupBox->setLayout(bandsListLayout);
 
  147   QGridLayout *componentsListLayout = 
new QGridLayout();
 
  148   m_uiPtr->m_componentsListGroupBox->setLayout(componentsListLayout);
 
  153   for(
unsigned int line = 0; line < 
PATTERN_W; line++)
 
  157     for(
unsigned int col = 0; col < 
PATTERN_W; col++)
 
  159       if((line == col) || (line == (PATTERN_W - col - 1)))
 
  170   for(
unsigned int line = 0; line < 
PATTERN_W; line++)
 
  171     delete[] m_selectedPointPattern[line];
 
  173   delete[] m_selectedPointPattern;
 
  181   if(m_outputRasterPtr.get())
 
  183     outputRasterPtr = m_outputRasterPtr;
 
  193   m_outputRasterPtr.reset();
 
  195   if (!m_inputRasterPtr)
 
  197     QMessageBox::critical(
this, 
"", tr(
"Invalid input raster"));
 
  206   algoInputParameters.
m_strategyName = (m_uiPtr->m_mmTypeComboBox->currentText() == 
"Linear" ? 
"linear" : 
"pca");
 
  209   unsigned selectedBands = 0;
 
  210   std::vector<bool> selectedBandsVector;
 
  211   for (
int i = 0; i < (m_uiPtr->m_bandsListGroupBox->layout()->count() - 1); i += 2)
 
  213     QCheckBox* bandCheckBox = (QCheckBox*) m_uiPtr->m_bandsListGroupBox->layout()->itemAt(i)->widget();
 
  215     if (bandCheckBox->isChecked())
 
  217       selectedBandsVector.push_back(
true);
 
  224       QComboBox *sensorComboBox = (QComboBox*) m_uiPtr->m_bandsListGroupBox->layout()->itemAt(i + 1)->widget();
 
  225 #if (QT_VERSION >= 0x050000) 
  226       algoInputParameters.
m_inputSensorBands.push_back(std::string(sensorComboBox->currentText().toLatin1()));
 
  228       algoInputParameters.
m_inputSensorBands.push_back(std::string(sensorComboBox->currentText().toAscii()));
 
  232       selectedBandsVector.push_back(
false);
 
  236   std::map<std::string, std::vector<double> >::const_iterator cit = m_components.begin();
 
  237   std::vector<double> components;
 
  238   while (cit != m_components.end())
 
  242     for (
unsigned int i = 0; i < selectedBandsVector.size(); i++)
 
  243       if (selectedBandsVector[i])
 
  244         components.push_back(cit->second[i]);
 
  246     algoInputParameters.
m_components[cit->first] = components;
 
  252   if (m_uiPtr->m_mmTypeComboBox->currentText() == 
"Linear")
 
  265   algoOutputParameters.
m_rInfo = m_outpuRasterInfo;
 
  266   algoOutputParameters.
m_rType = m_outpuRasterDSType;
 
  267   algoOutputParameters.
m_normalizeOutput = m_uiPtr->m_normalizeOutputCheckBox->isChecked();
 
  268   algoOutputParameters.
m_createErrorRaster = m_uiPtr->m_createErrorRasterCheckBox->isChecked();
 
  273   if(!MixtureModelinstance.
initialize(algoInputParameters))
 
  275     QMessageBox::critical(
this, 
"", tr(
"MixtureModel initialization error"));
 
  280   if(!MixtureModelinstance.
execute(algoOutputParameters))
 
  282     QMessageBox::critical(
this, 
"", tr(
"MixtureModel execution error"));
 
  287   QMessageBox::information(
this, 
"", tr(
"Mixture model decomposition ended sucessfully"));
 
  293   te::gm::Coord2D pixelLocation = m_inputRasterPtr->getGrid()->geoToGrid((
double) coordinate.rx(), (double)coordinate.ry());
 
  294   currentColumn = pixelLocation.
x;
 
  295   currentRow = pixelLocation.
y;
 
  301   if (currentColumn < 0 || currentColumn >= (
int) m_inputRasterPtr->getNumberOfColumns())
 
  303   if (currentRow < 0 || currentRow >= (
int) m_inputRasterPtr->getNumberOfRows())
 
  306   std::vector<double> componentsVector;
 
  308   QString* className = 
new QString(
"Change name " + QString::number(m_maxComponentsInserted++));
 
  311   for(
unsigned b = 0 ; b < m_inputRasterPtr->getNumberOfBands(); b++)
 
  313     m_inputRasterPtr->getValue(currentColumn, currentRow, value, b);
 
  315     componentsVector.push_back(value);
 
  318   m_components[className->toStdString()] = componentsVector;
 
  321   m_coordinates[className->toStdString()] = coordinate;
 
  323   updateComponentsGrid();
 
  328   QPushButton* sender = (QPushButton*) QObject::sender();
 
  331   std::string className = sender->statusTip().toStdString();
 
  333   m_components.erase(className);
 
  334   m_coordinates.erase(className);
 
  336   updateComponentsGrid();
 
  344   m_mapDisplay->getDraftPixmap()->fill(QColor(0, 0, 0, 0));
 
  348                            mapDisplayExtent.
m_urx, mapDisplayExtent.
m_ury);
 
  355   std::map<std::string, te::gm::Coord2D>::const_iterator cpit = m_coordinates.begin();
 
  356   while (cpit != m_coordinates.end())
 
  359     m_inputRasterPtr->getGrid()->gridToGeo(cpit->second.x, cpit->second.y,
 
  360                                            auxCoord2D.
x, auxCoord2D.
y);
 
  362     auxPoint.
setX(auxCoord2D.
x);
 
  363     auxPoint.
setY(auxCoord2D.
y);
 
  365     canvasInstance.draw(&auxPoint);
 
  373   QGridLayout* componentsListLayout = (QGridLayout*) m_uiPtr->m_componentsListGroupBox->layout();
 
  376   for (
int i = 0; i < (componentsListLayout->count() / 5); i++)
 
  378     std::string className = ((QLineEdit*) componentsListLayout->itemAtPosition(i, 1)->widget())->text().toStdString();
 
  379     std::string originalClassName = ((QLineEdit*) componentsListLayout->itemAtPosition(i, 1)->widget())->toolTip().toStdString();
 
  382     if (className != originalClassName)
 
  384       m_components[className] = m_components[originalClassName];
 
  385       m_coordinates[className] = m_coordinates[originalClassName];
 
  387       m_components.erase(originalClassName);
 
  388       m_coordinates.erase(originalClassName);
 
  395   while ((child = componentsListLayout->takeAt(0)) != 0)
 
  397     delete child->widget();
 
  403   m_mapDisplay->setExtent(auxEnvelope);
 
  406   std::map<std::string, std::vector<double> >::const_iterator cit = m_components.begin();
 
  407   unsigned int totalComponents = 0;
 
  408   while (cit != m_components.end())
 
  411     QPushButton* removeButton = 
new QPushButton(
"x");
 
  413     removeButton->setStatusTip(cit->first.c_str());
 
  414     removeButton->setMaximumSize(20, 20);
 
  415     connect(removeButton, SIGNAL(clicked()), SLOT(on_removeButton_clicked()));
 
  417     componentsListLayout->addWidget(removeButton, totalComponents, 0);
 
  419     QLineEdit* className = 
new QLineEdit(cit->first.c_str());
 
  420     className->setToolTip(cit->first.c_str());
 
  421     componentsListLayout->addWidget(className, totalComponents, 1);
 
  423     std::vector<double> components = cit->second;
 
  424     for (
unsigned int i = 0; i < components.size(); i++)
 
  426       QLineEdit* currentPixel = 
new QLineEdit(QString::number(components[i]));
 
  428       currentPixel->setMaximumSize(50, currentPixel->maximumHeight());
 
  430       componentsListLayout->addWidget(currentPixel, totalComponents, i + 2);
 
te::gm::Envelope * getExtent()
Returns the geographic extension of the raster data. 
 
void setColor(const std::string &hexColor)
It sets the color using a two hexadecimal RGB-encoded color. 
 
Raster decomposition using mixture model. 
 
std::string m_rType
Output raster data source type (as described in te::raster::RasterFactory ). 
 
std::vector< std::string > GetBandNames()
Returns a vector os with band's names. 
 
double m_urx
Upper right corner x-coordinate. 
 
An utility struct for representing 2D coordinates. 
 
std::map< std::string, std::string > m_rInfo
The necessary information to create the raster (as described in te::raster::RasterFactory). 
 
virtual void setLayerList(const std::list< te::map::AbstractLayerPtr > &layers)
It sets the layer list to be showed in the Map Display. 
 
double m_llx
Lower left corner x-coordinate. 
 
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. 
 
A dialog used to execute mixture model decomposition. 
 
#define TE_OPAQUE
For an RGBA color this is the value of the alpha-channel for totally opaque. 
 
virtual std::size_t getNumberOfBands() const =0
Returns the number of bands (dimension of cells attribute values) in the raster. 
 
TEMAPEXPORT te::rst::Raster * GetRaster(DataSetLayer *layer)
It gets the raster referenced by the given data set layer. 
 
double m_lly
Lower left corner y-coordinate. 
 
MixtureModel output parameters. 
 
int getSRID() const 
Returns the raster spatial reference system identifier. 
 
void setX(const double &x)
It sets the Point x-coordinate value. 
 
double m_ury
Upper right corner y-coordinate. 
 
bool execute(AlgorithmOutputParameters &outputParams)
Executes the algorithm using the supplied parameters. 
 
#define TE_TRANSPARENT
For an RGBA color this is the value of the alpha-channel for totally transparent. ...
 
boost::intrusive_ptr< DataSetLayer > DataSetLayerPtr
 
A helper class for 32-bit RGBA (Red-Green-Blue-Alpha channel) color. 
 
void setY(const double &y)
It sets the Point y-coordinate value. 
 
std::string Convert2String(boost::int16_t value)
It converts a short integer value to a string. 
 
bool m_createErrorRaster
A flag to indicate that output raster will include the error bands. 
 
bool initialize(const AlgorithmInputParameters &inputParams)
Initialize the algorithm instance making it ready for execution.