PCAWizardPage.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2008 National Institute For Space Research (INPE) - Brazil.
2 
3 This file is part of the TerraLib - a Framework for building GIS enabled applications.
4 
5 TerraLib is free software: you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9 
10 TerraLib is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
14 
15 You should have received a copy of the GNU Lesser General Public License
16 along with TerraLib. See COPYING. If not, write to
17 TerraLib Team at <terralib-team@terralib.org>.
18 */
19 
20 //Terralib
21 #include "../../../datatype/DataType.h"
22 #include "../../../dataaccess/utils/Utils.h"
23 #include "../../../raster/Band.h"
24 #include "../../../raster/Raster.h"
25 #include "../../../se/ColorMap.h"
26 #include "../charts/ChartDisplay.h"
27 #include "../charts/ChartStyle.h"
28 #include "../charts/Histogram.h"
29 #include "../charts/HistogramChart.h"
30 #include "../charts/HistogramStyle.h"
31 #include "../charts/Utils.h"
32 #include "../utils/ScopedCursor.h"
33 #include "PCAWizardPage.h"
34 #include "ui_PCAWizardPageForm.h"
35 
36 // QT
37 #include <QComboBox>
38 #include <QString>
39 #include <QFileDialog>
40 
42  QWizardPage(parent)
43 {
44  m_ui.reset(new Ui::PCAWizardPageForm);
45 
46  m_ui->setupUi(this);
47 
48  //configure page
49  this->setTitle(tr("Principal Components Analysis"));
50  this->setSubTitle(tr("Define PCA parameters."));
51 
52  m_ui->m_outputDataTypeComboBox->addItem( "Unsigned Int 8 bits" );
53  m_ui->m_outputDataTypeComboBox->addItem( "Unsigned Int 16 bits" );
54  m_ui->m_outputDataTypeComboBox->addItem( "Unsigned Int 32 bits" );
55  m_ui->m_outputDataTypeComboBox->addItem( "Float" );
56  m_ui->m_outputDataTypeComboBox->addItem( "Double" );
57 
58  m_ui->m_outputDataTypeComboBox->setCurrentIndex( 4 );
59 
60  connect(m_ui->m_inversePCACheckBox, SIGNAL(toggled(bool)), this, SLOT(inversePCACheckBoxToggled(bool)));
61  connect(m_ui->m_loadPCAMatrixFilePushButton, SIGNAL(clicked(bool)), this, SLOT(loadPCAMatrixFilePushButtonClicked(bool)));
62 }
63 
65 
66 std::vector< unsigned int > te::qt::widgets::PCAWizardPage::getSelectedBands() const
67 {
68  std::vector< unsigned int > returnVector;
69 
70  QList<QListWidgetItem *> selectedItens = m_ui->m_layerBandsListWidget->selectedItems();
71 
72  QList<QListWidgetItem *>::iterator it = selectedItens.begin();
73  QList<QListWidgetItem *>::iterator itEnd = selectedItens.end();
74 
75  while( it != itEnd )
76  {
77  returnVector.push_back( (*it)->text().toUInt() );
78  ++it;
79  }
80 
81  return returnVector;
82 }
83 
85 {
86  return m_ui->m_pcaMatrixFileLineEdit->text().toStdString();
87 }
88 
90 {
91  switch( m_ui->m_outputDataTypeComboBox->currentIndex() )
92  {
93  case 0 : // "Unsigned Int 8 bits"
94  {
95  return te::dt::UCHAR_TYPE;
96  break;
97  }
98  case 1 : // "Unsigned Int 16 bits"
99  {
100  return te::dt::UINT16_TYPE;
101  break;
102  }
103  case 2 : // "Unsigned Int 32 bits"
104  {
105  return te::dt::UINT32_TYPE;
106  break;
107  }
108  case 3 : // "Float"
109  {
110  return te::dt::FLOAT_TYPE;
111  break;
112  }
113  default : // "Double"
114  {
115  return te::dt::DOUBLE_TYPE;
116  break;
117  }
118  }
119 
120  return te::dt::DOUBLE_TYPE;
121 }
122 
124 {
125  m_rasterLayer = layer;
126 
127  //get input raster
128  std::unique_ptr<te::da::DataSet> ds = m_rasterLayer->getData();
129 
130  if (ds.get())
131  {
132  std::size_t rpos = te::da::GetFirstPropertyPos(ds.get(), te::dt::RASTER_TYPE);
133 
134  std::unique_ptr<te::rst::Raster> inputRst = ds->getRaster(rpos);
135 
136  if (inputRst.get())
137  {
138  m_raster.reset(inputRst.release());
139 
140  size_t bandsNumber = m_raster->getNumberOfBands();
141 
142  m_ui->m_layerBandsListWidget->clear();
143  for (size_t band = 0; band < bandsNumber; ++band)
144  {
145  m_ui->m_layerBandsListWidget->addItem(QString::number(band));
146  }
147 
148  m_ui->m_layerBandsListWidget->selectAll();
149  }
150  }
151 }
152 
154 {
155  QList<QListWidgetItem *> selectedItens = m_ui->m_layerBandsListWidget->selectedItems();
156 
157  if (
158  ( selectedItens.empty() )
159  ||
160  (
161  ( m_ui->m_inversePCACheckBox->checkState() == Qt::Checked )
162  &&
163  ( m_ui->m_pcaMatrixFileLineEdit->text().isEmpty() )
164  )
165  )
166  {
167  return false;
168  }
169  else
170  {
171  return true;
172  }
173 }
174 
176 {
177  return ( m_ui->m_inversePCACheckBox->checkState() == Qt::Checked );
178 }
179 
181 {
182  m_ui->m_pcaMatrixFileLineEdit->clear();
183 
184  if( checked )
185  {
186  m_ui->m_loadPCAMatrixFilePushButton->setText( tr( "Load" ) );
187 
188  m_ui->m_outputDataTypeComboBox->setEnabled( true );
189  }
190  else
191  {
192  m_ui->m_loadPCAMatrixFilePushButton->setText( tr( "Save" ) );
193 
194  m_ui->m_outputDataTypeComboBox->setCurrentIndex( 4 );
195  m_ui->m_outputDataTypeComboBox->setEnabled( false );
196  }
197 
198  emit completeChanged();
199 }
200 
202  bool /*checked*/)
203 {
204  QString fileName;
205 
206  if( m_ui->m_inversePCACheckBox->checkState() == Qt::Checked )
207  {
208  fileName = QFileDialog::getOpenFileName(this, tr("Select File"),
209  ".", "*", nullptr, QFileDialog::ReadOnly);
210  }
211  else
212  {
213  fileName = QFileDialog::getSaveFileName(this, tr("Select the output file name"),
214  ".", "*", nullptr , QFileDialog::DontConfirmOverwrite);
215  }
216 
217  m_ui->m_pcaMatrixFileLineEdit->setText( fileName );
218 
219  emit completeChanged();
220 }
221 
int getOutputRasterDataType() const
This function returns the output raster data type.
unsigned int band
void loadPCAMatrixFilePushButtonClicked(bool checked)
te::map::AbstractLayerPtr m_rasterLayer
Testing a better way to show the chart.
std::unique_ptr< Ui::PCAWizardPageForm > m_ui
The wizard page form.
std::vector< unsigned int > getSelectedBands() const
This function returns the bands from the raster taht will be used.
std::unique_ptr< te::rst::Raster > m_raster
The raster that will be processed.
static te::dt::Date ds(2010, 01, 01)
void inversePCACheckBoxToggled(bool checked)
bool inversePCASelected() const
Returnes true the inverse PCA option is selected.
PCAWizardPage(QWidget *parent=0)
Constructor.
std::string getMatrixFileName() const
This function returns the bands from the raster taht will be used.
TEDATAACCESSEXPORT std::size_t GetFirstPropertyPos(const te::da::DataSet *dataset, int datatype)
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
void setLayer(te::map::AbstractLayerPtr layer)
This function sets the layer that contains the raster that will be sliced.