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> 
   48 #include <QtGui/QCheckBox> 
   49 #include <QtGui/QComboBox> 
   50 #include <QtGui/QGridLayout> 
   51 #include <QtGui/QImage> 
   52 #include <QtGui/QKeyEvent> 
   53 #include <QtGui/QLineEdit> 
   54 #include <QtGui/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       algoInputParameters.
m_inputSensorBands.push_back(std::string(sensorComboBox->currentText().toAscii()));
 
  228       selectedBandsVector.push_back(
false);
 
  232   std::map<std::string, std::vector<double> >::const_iterator cit = m_components.begin();
 
  233   std::vector<double> components;
 
  234   while (cit != m_components.end())
 
  238     for (
unsigned int i = 0; i < selectedBandsVector.size(); i++)
 
  239       if (selectedBandsVector[i])
 
  240         components.push_back(cit->second[i]);
 
  242     algoInputParameters.
m_components[cit->first] = components;
 
  248   if (m_uiPtr->m_mmTypeComboBox->currentText() == 
"Linear")
 
  261   algoOutputParameters.
m_rInfo = m_outpuRasterInfo;
 
  262   algoOutputParameters.
m_rType = m_outpuRasterDSType;
 
  263   algoOutputParameters.
m_normalizeOutput = m_uiPtr->m_normalizeOutputCheckBox->isChecked();
 
  264   algoOutputParameters.
m_createErrorRaster = m_uiPtr->m_createErrorRasterCheckBox->isChecked();
 
  269   if(!MixtureModelinstance.
initialize(algoInputParameters))
 
  271     QMessageBox::critical(
this, 
"", tr(
"MixtureModel initialization error"));
 
  276   if(!MixtureModelinstance.
execute(algoOutputParameters))
 
  278     QMessageBox::critical(
this, 
"", tr(
"MixtureModel execution error"));
 
  283   QMessageBox::information(
this, 
"", tr(
"Mixture model decomposition ended sucessfully"));
 
  289   te::gm::Coord2D pixelLocation = m_inputRasterPtr->getGrid()->geoToGrid((
double) coordinate.rx(), (double)coordinate.ry());
 
  290   currentColumn = pixelLocation.
x;
 
  291   currentRow = pixelLocation.
y;
 
  297   if (currentColumn < 0 || currentColumn >= (
int) m_inputRasterPtr->getNumberOfColumns())
 
  299   if (currentRow < 0 || currentRow >= (
int) m_inputRasterPtr->getNumberOfRows())
 
  302   std::vector<double> componentsVector;
 
  304   QString* className = 
new QString(
"Change name " + QString::number(m_maxComponentsInserted++));
 
  307   for(
unsigned b = 0 ; b < m_inputRasterPtr->getNumberOfBands(); b++)
 
  309     m_inputRasterPtr->getValue(currentColumn, currentRow, value, b);
 
  311     componentsVector.push_back(value);
 
  314   m_components[className->toStdString()] = componentsVector;
 
  317   m_coordinates[className->toStdString()] = coordinate;
 
  319   updateComponentsGrid();
 
  324   QPushButton* sender = (QPushButton*) QObject::sender();
 
  327   std::string className = sender->statusTip().toStdString();
 
  329   m_components.erase(className);
 
  330   m_coordinates.erase(className);
 
  332   updateComponentsGrid();
 
  340   m_mapDisplay->getDraftPixmap()->fill(QColor(0, 0, 0, 0));
 
  344                            mapDisplayExtent.
m_urx, mapDisplayExtent.
m_ury);
 
  351   std::map<std::string, te::gm::Coord2D>::const_iterator cpit = m_coordinates.begin();
 
  352   while (cpit != m_coordinates.end())
 
  355     m_inputRasterPtr->getGrid()->gridToGeo(cpit->second.x, cpit->second.y,
 
  356                                            auxCoord2D.
x, auxCoord2D.
y);
 
  358     auxPoint.
setX(auxCoord2D.
x);
 
  359     auxPoint.
setY(auxCoord2D.
y);
 
  361     canvasInstance.draw(&auxPoint);
 
  369   QGridLayout* componentsListLayout = (QGridLayout*) m_uiPtr->m_componentsListGroupBox->layout();
 
  372   for (
int i = 0; i < (componentsListLayout->count() / 5); i++)
 
  374     std::string className = ((QLineEdit*) componentsListLayout->itemAtPosition(i, 1)->widget())->text().toStdString();
 
  375     std::string originalClassName = ((QLineEdit*) componentsListLayout->itemAtPosition(i, 1)->widget())->toolTip().toStdString();
 
  378     if (className != originalClassName)
 
  380       m_components[className] = m_components[originalClassName];
 
  381       m_coordinates[className] = m_coordinates[originalClassName];
 
  383       m_components.erase(originalClassName);
 
  384       m_coordinates.erase(originalClassName);
 
  391   while ((child = componentsListLayout->takeAt(0)) != 0)
 
  393     delete child->widget();
 
  399   m_mapDisplay->setExtent(auxEnvelope);
 
  402   std::map<std::string, std::vector<double> >::const_iterator cit = m_components.begin();
 
  403   unsigned int totalComponents = 0;
 
  404   while (cit != m_components.end())
 
  407     QPushButton* removeButton = 
new QPushButton(
"x");
 
  409     removeButton->setStatusTip(cit->first.c_str());
 
  410     removeButton->setMaximumSize(20, 20);
 
  411     connect(removeButton, SIGNAL(clicked()), SLOT(on_removeButton_clicked()));
 
  413     componentsListLayout->addWidget(removeButton, totalComponents, 0);
 
  415     QLineEdit* className = 
new QLineEdit(cit->first.c_str());
 
  416     className->setToolTip(cit->first.c_str());
 
  417     componentsListLayout->addWidget(className, totalComponents, 1);
 
  419     std::vector<double> components = cit->second;
 
  420     for (
unsigned int i = 0; i < components.size(); i++)
 
  422       QLineEdit* currentPixel = 
new QLineEdit(QString::number(components[i]));
 
  424       currentPixel->setMaximumSize(50, currentPixel->maximumHeight());
 
  426       componentsListLayout->addWidget(currentPixel, totalComponents, i + 2);
 
CoordTracking * m_coordTracking
Coordinate tracking for map display. 
 
std::map< std::string, std::vector< double > > m_components
A set of endmembers and its radiances. 
 
te::qt::widgets::Pan * m_panClickEvent
Pan click event for map display. 
 
void setX(const double &x)
It sets the Point x-coordinate value. 
 
te::rst::Raster const * m_inputRasterPtr
Input raster. 
 
virtual void setResizePolicy(const ResizePolicy &policy)
Sets the resize policy to this map display. 
 
Raster decomposition using mixture model. 
 
MixtureModelDialogMDEventFilter * m_keyboardPressTracking
The event filter to detect when user press space bar. 
 
void on_mapDisplay_extentChanged()
 
te::color::RGBAColor ** m_selectedPointPattern
The display draw pattern used for selected points. 
 
void on_keyPressedOverMapDisplay(int key)
 
bool initialize(const AlgorithmInputParameters &inputParams)
Initialize the algorithm instance making it ready for execution. 
 
A dialog used to execute mixture model decomposition. 
 
MixtureModelDialogMDEventFilter(te::qt::widgets::MapDisplay *parent)
 
A event filter to handle map display events. 
 
bool m_createErrorRaster
A flag to indicate that output raster will include the error bands. 
 
bool eventFilter(QObject *watched, QEvent *event)
 
void setY(const double &y)
It sets the Point y-coordinate value. 
 
std::map< std::string, std::string > m_rInfo
The necessary information to create the raster (as described in te::raster::RasterFactory). 
 
This class implements a concrete tool to geographic zoom operation using the mouse wheel...
 
~MixtureModelDialogMDEventFilter()
 
te::qt::widgets::ZoomWheel * m_zoomScroolEvent
Zoom event using mouse scrool for map display. 
 
This class implements a concrete tool to geographic pan operation. 
 
~MixtureModelDialog()
Destructor. 
 
std::vector< std::string > m_inputSensorBands
The names of the sensor/bands. 
 
virtual void setLayerList(const std::list< te::map::AbstractLayerPtr > &layers)
It sets the layer list to be showed in the Map Display. 
 
virtual std::size_t getNumberOfBands() const =0
Returns the number of bands (dimension of cells attribute values) in the raster. 
 
An utility struct for representing 2D coordinates. 
 
#define TE_TRANSPARENT
For an RGBA color this is the value of the alpha-channel for totally transparent. ...
 
void on_removeButton_clicked()
 
bool m_normalizeOutput
A flag to indicate that output raster will be normalized, by default [0, 255]. 
 
te::gm::Envelope * getExtent()
Returns the geographic extension of the raster data. 
 
double m_lly
Lower left corner y-coordinate. 
 
std::string m_rType
Output raster data source type (as described in te::raster::RasterFactory ). 
 
std::string m_strategyName
The mixture model strategy name see each te::rp::MixtureModelStrategyFactory inherited classes docume...
 
int getSRID() const 
Returns the raster spatial reference system identifier. 
 
TEMAPEXPORT te::rst::Raster * GetRaster(DataSetLayer *layer)
It gets the raster referenced by the given data set layer. 
 
double m_ury
Upper right corner y-coordinate. 
 
void setColor(const std::string &hexColor)
It sets the color using a two hexadecimal RGB-encoded color. 
 
MixtureModelDialog(const te::map::DataSetLayerPtr &inputLayerPtr, const std::string &outpuRasterDSType, const std::map< std::string, std::string > &outpuRasterInfo, QWidget *parent=0, Qt::WindowFlags f=0)
Constructs a basic dialog which is a child of parent, with widget flags set to f. ...
 
void setMixtureModelStrategyParams(const StrategyParameters &p)
Set specific mixture model strategy parameters. 
 
virtual void setExtent(te::gm::Envelope &e, bool doRefresh=true)
It sets the world visible area and refreshes the contents in the map display. 
 
A helper class for 32-bit RGBA (Red-Green-Blue-Alpha channel) color. 
 
A canvas built on top of Qt. 
 
void on_coordTracked_changed(QPointF &coordinate)
 
std::vector< std::string > GetBandNames()
Returns a vector os with band's names. 
 
A point with x and y coordinate values. 
 
double m_urx
Upper right corner x-coordinate. 
 
A widget to control the display of a set of layers. 
 
boost::intrusive_ptr< DataSetLayer > DataSetLayerPtr
 
std::string Convert2String(boost::int16_t value)
It converts a short integer value to a string. 
 
MixtureModel output parameters. 
 
Ui::MixtureModelForm * m_uiPtr
User interface. 
 
#define TE_OPAQUE
For an RGBA color this is the value of the alpha-channel for totally opaque. 
 
const te::rst::Raster * m_inputRasterPtr
Input raster pointer. 
 
virtual void setSRID(const int &srid, bool doRefresh=true)
It sets a new Spatial Reference System to be used by the Map Display. 
 
bool getOutputRaster(boost::shared_ptr< te::rst::Raster > &outputRasterPtr)
Returns the output result raster. 
 
double m_llx
Lower left corner x-coordinate. 
 
This class implements a concrete tool to geographic coordinate tracking on mouse move operation...
 
MixtureModel input parameters. 
 
te::qt::widgets::MapDisplay * m_mapDisplay
The map display to show the input raster. 
 
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::vector< unsigned int > m_inputRasterBands
Bands to be processed from the input raster. 
 
bool execute(AlgorithmOutputParameters &outputParams)
Executes the algorithm using the supplied parameters. 
 
void updateComponentsGrid()
 
void on_okPushButton_clicked()