All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
ComposeBandsWizardPage.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 /*!
21  \file terralib/qt/widgets/rp/ComposeBandsWizardPage.cpp
22 
23  \brief This file defines a class for a Compose / Decompose Bands Wizard page.
24 */
25 
26 // TerraLib
27 #include "../../../common/StringUtils.h"
28 #include "../../../dataaccess/dataset/DataSet.h"
29 #include "../../../dataaccess/utils/Utils.h"
30 #include "../../../raster/Raster.h"
31 #include "../../../rp/Functions.h"
32 #include "ComposeBandsWizardPage.h"
33 #include "ui_ComposeBandsWizardPageForm.h"
34 
35 // Qt
36 #include <QMessageBox>
37 
39 
41  : QWizardPage(parent),
42  m_ui(new Ui::ComposeBandsWizardPageForm)
43 {
44  //setup controls
45  m_ui->setupUi(this);
46 
47  m_ui->m_addToolButton->setIcon(QIcon::fromTheme("list-add"));
48  m_ui->m_removeToolButton->setIcon(QIcon::fromTheme("list-remove"));
49 
50  //set interpolator types
52 
53  //connects
54  connect(m_ui->m_addToolButton, SIGNAL(clicked()), this, SLOT(onAddToolButtonClicked()));
55  connect(m_ui->m_removeToolButton, SIGNAL(clicked()), this, SLOT(onRemoveToolButtonClicked()));
56 
57  //configure page
58  this->setTitle(tr("Compose / Decompose Bands"));
59  this->setSubTitle(tr("Select the operation (Compose / Decompose) and set their specific parameters."));
60 }
61 
63 {
64 
65 }
66 
68 {
69  return true;
70 }
71 
72 void te::qt::widgets::ComposeBandsWizardPage::setList(std::list<te::map::AbstractLayerPtr>& layerList)
73 {
74  m_layerList = layerList;
75 
76  m_ui->m_composeTableWidget->setRowCount(0);
77  m_ui->m_decomposeTableWidget->setRowCount(0);
78 
79  std::list<te::map::AbstractLayerPtr>::iterator it;
80 
81  //set compose table info
82  for(it = m_layerList.begin(); it!= m_layerList.end(); ++it)
83  {
85 
86  //get input raster
87  std::auto_ptr<te::da::DataSet> ds = l->getData();
88 
89  if(ds.get())
90  {
91  std::size_t rpos = te::da::GetFirstPropertyPos(ds.get(), te::dt::RASTER_TYPE);
92 
93  std::auto_ptr<te::rst::Raster> inputRst = ds->getRaster(rpos);
94 
95  if(inputRst.get())
96  {
97  int newrow = m_ui->m_composeTableWidget->rowCount();
98  m_ui->m_composeTableWidget->insertRow(newrow);
99 
100  //layer combo
101  QComboBox* layerCmbBox = new QComboBox(this);
102 
103  connect(layerCmbBox, SIGNAL(activated(int)), this, SLOT(onLayerCmbActivated(int)));
104 
105  std::list<te::map::AbstractLayerPtr>::iterator itLayer;
106 
107  int curItem;
108  int item = 0;
109 
110  for(itLayer = m_layerList.begin(); itLayer!= m_layerList.end(); ++itLayer)
111  {
112  te::map::AbstractLayerPtr lItem = *itLayer;
113 
114  layerCmbBox->addItem(lItem->getTitle().c_str(), QVariant::fromValue(lItem));
115 
116  if(lItem == l)
117  {
118  curItem = item;
119  }
120 
121  ++item;
122  }
123 
124  layerCmbBox->setCurrentIndex(curItem);
125 
126  m_ui->m_composeTableWidget->setCellWidget(newrow, 1, layerCmbBox);
127 
128  m_cmbMap.insert(std::map<QComboBox*, int>::value_type(layerCmbBox, newrow));
129 
130  //band
131  QComboBox* cmbBox = new QComboBox(this);
132 
133  for(unsigned int i = 0; i < inputRst->getNumberOfBands(); ++i)
134  {
135  cmbBox->addItem(QString::number(i));
136  }
137 
138  m_ui->m_composeTableWidget->setCellWidget(newrow, 0, cmbBox);
139  }
140  }
141  }
142 
143  //set decompose table info
144  if(!m_layerList.empty())
145  {
146  te::map::AbstractLayerPtr l = *m_layerList.begin();
147 
148  //get input raster
149  std::auto_ptr<te::da::DataSet> ds = l->getData();
150 
151  m_ui->m_rasterLineEdit->setText(l->getTitle().c_str());
152 
153  if(ds.get())
154  {
155  std::size_t rpos = te::da::GetFirstPropertyPos(ds.get(), te::dt::RASTER_TYPE);
156 
157  std::auto_ptr<te::rst::Raster> inputRst = ds->getRaster(rpos);
158 
159  if(inputRst.get())
160  {
161  for(unsigned int i = 0; i < inputRst->getNumberOfBands(); ++i)
162  {
163  int newrow = m_ui->m_decomposeTableWidget->rowCount();
164  m_ui->m_decomposeTableWidget->insertRow(newrow);
165 
166  //band item
167  QString bName(tr("Band "));
168  bName.append(QString::number(i));
169 
170  QTableWidgetItem* itemBand = new QTableWidgetItem(bName);
171  itemBand->setFlags(Qt::ItemIsEnabled | Qt::ItemIsUserCheckable);
172  itemBand->setCheckState(Qt::Checked);
173  m_ui->m_decomposeTableWidget->setItem(newrow, 0, itemBand);
174  }
175  }
176  }
177  }
178 }
179 
181 {
182  if(m_ui->m_tabWidget->currentIndex() == 0)
183  return true;
184 
185  return false;
186 }
187 
189 {
190  if(m_ui->m_tabWidget->currentIndex() == 1)
191  return true;
192 
193  return false;
194 }
195 
196 void te::qt::widgets::ComposeBandsWizardPage::getComposeParameters(std::vector<const te::rst::Raster*>& rasters, std::vector<unsigned int>& bands, te::rst::Interpolator::Method& interpMethod)
197 {
198  int rowCount = m_ui->m_composeTableWidget->rowCount();
199 
200  for(int i = 0; i < rowCount; ++i)
201  {
202  QComboBox* layerCmb = (QComboBox*)m_ui->m_composeTableWidget->cellWidget(i, 1);
203 
204  int curIdx = layerCmb->currentIndex();
205  QVariant varLayer = layerCmb->itemData(curIdx, Qt::UserRole);
206  te::map::AbstractLayerPtr layer = varLayer.value<te::map::AbstractLayerPtr>();
207 
208  //get input raster
209  std::auto_ptr<te::da::DataSet> ds = layer->getData();
210 
211  if(!ds.get())
212  throw;
213 
214  std::size_t rpos = te::da::GetFirstPropertyPos(ds.get(), te::dt::RASTER_TYPE);
215 
216  rasters.push_back(ds->getRaster(rpos).release());
217 
218 
219  QComboBox* bandCmb = (QComboBox*)m_ui->m_composeTableWidget->cellWidget(i, 0);
220 
221  bands.push_back((unsigned int)bandCmb->currentText().toInt());
222  }
223 
224  //interpolator method
225  int idx = m_ui->m_interpolatorComboBox->currentIndex();
226  interpMethod = (te::rst::Interpolator::Method)m_ui->m_interpolatorComboBox->itemData(idx).toInt();
227 }
228 
230 {
231  te::map::AbstractLayerPtr l = *m_layerList.begin();
232 
233  //get input raster
234  std::auto_ptr<te::da::DataSet> ds = l->getData();
235 
236  if(!ds.get())
237  throw;
238 
239  std::size_t rpos = te::da::GetFirstPropertyPos(ds.get(), te::dt::RASTER_TYPE);
240 
241  raster = ds->getRaster(rpos).release();
242 
243  //get bands
244  for(int r = 0; r < m_ui->m_decomposeTableWidget->rowCount(); ++r)
245  {
246  if(m_ui->m_decomposeTableWidget->item(r, 0)->checkState() == Qt::Checked)
247  {
248  bands.push_back((unsigned int)r);
249  }
250  }
251 }
252 
254 {
255  int newrow = m_ui->m_composeTableWidget->rowCount();
256  m_ui->m_composeTableWidget->insertRow(newrow);
257 
258  //layer combo
259  QComboBox* layerCmbBox = new QComboBox(this);
260 
261  connect(layerCmbBox, SIGNAL(activated(int)), this, SLOT(onLayerCmbActivated(int)));
262 
263  std::list<te::map::AbstractLayerPtr>::iterator itLayer;
264 
265  for(itLayer = m_layerList.begin(); itLayer!= m_layerList.end(); ++itLayer)
266  {
267  te::map::AbstractLayerPtr lItem = *itLayer;
268 
269  layerCmbBox->addItem(lItem->getTitle().c_str(), QVariant::fromValue(lItem));
270  }
271 
272  m_ui->m_composeTableWidget->setCellWidget(newrow, 1, layerCmbBox);
273 
274  m_cmbMap.insert(std::map<QComboBox*, int>::value_type(layerCmbBox, newrow));
275 
276 
277  //band
278  QComboBox* cmbBox = new QComboBox(this);
279 
280  m_ui->m_composeTableWidget->setCellWidget(newrow, 0, cmbBox);
281 
282  te::map::AbstractLayerPtr lFirst = *m_layerList.begin();
283 
284  if(lFirst.get())
285  {
286  std::auto_ptr<te::da::DataSet> ds = lFirst->getData();
287 
288  if(ds.get())
289  {
290  std::size_t rpos = te::da::GetFirstPropertyPos(ds.get(), te::dt::RASTER_TYPE);
291 
292  std::auto_ptr<te::rst::Raster> inputRst = ds->getRaster(rpos);
293 
294  if(inputRst.get())
295  {
296  for(unsigned int i = 0; i < inputRst->getNumberOfBands(); ++i)
297  {
298  cmbBox->addItem(QString::number(i));
299  }
300  }
301  }
302  }
303 }
304 
306 {
307  int currow = m_ui->m_composeTableWidget->currentRow();
308  m_ui->m_composeTableWidget->removeRow(currow);
309 }
310 
312 {
313  QComboBox* cmb = dynamic_cast<QComboBox*>(sender());
314 
315  QVariant varLayer = cmb->itemData(index, Qt::UserRole);
316  te::map::AbstractLayerPtr layer = varLayer.value<te::map::AbstractLayerPtr>();
317 
318  int row = m_cmbMap[cmb];
319 
320  QComboBox* bandCmb = (QComboBox*)m_ui->m_composeTableWidget->cellWidget(row, 0);
321 
322  bandCmb->clear();
323 
324  //get input raster
325  std::auto_ptr<te::da::DataSet> ds = layer->getData();
326 
327  if(ds.get())
328  {
329  std::size_t rpos = te::da::GetFirstPropertyPos(ds.get(), te::dt::RASTER_TYPE);
330 
331  std::auto_ptr<te::rst::Raster> inputRst = ds->getRaster(rpos);
332 
333  if(inputRst.get())
334  {
335  for(unsigned int i = 0; i < inputRst->getNumberOfBands(); ++i)
336  {
337  bandCmb->addItem(QString::number(i));
338  }
339  }
340  }
341 }
342 
344 {
345  m_ui->m_interpolatorComboBox->clear();
346 
347  m_ui->m_interpolatorComboBox->addItem(tr("Nearest Neighbor"), te::rst::NearestNeighbor);
348  m_ui->m_interpolatorComboBox->addItem(tr("Bilinear"), te::rst::Bilinear);
349  m_ui->m_interpolatorComboBox->addItem(tr("Bicubic"), te::rst::Bicubic);
350 }
Near neighborhood interpolation method.
Definition: Enums.h:95
std::auto_ptr< Ui::ComposeBandsWizardPageForm > m_ui
InterpolationMethod
Allowed interpolation methods.
Definition: Enums.h:92
InterpolationMethod Method
Allowed interpolation methods.
Definition: Interpolator.h:62
void setList(std::list< te::map::AbstractLayerPtr > &layerList)
Q_DECLARE_METATYPE(te::map::AbstractLayerPtr)
An abstract class for raster data strucutures.
Definition: Raster.h:71
void getComposeParameters(std::vector< const te::rst::Raster * > &rasters, std::vector< unsigned int > &bands, te::rst::Interpolator::Method &interpMethod)
Bicubic interpolation method.
Definition: Enums.h:97
void getDecomposeParameters(te::rst::Raster *&raster, std::vector< unsigned int > &bands)
Bilinear interpolation method.
Definition: Enums.h:96
This file defines a class for a Compose / Decompose Bands Wizard page.
TEDATAACCESSEXPORT std::size_t GetFirstPropertyPos(const te::da::DataSet *dataset, int datatype)
Definition: Utils.cpp:481
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr