HistogramDataWidget.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/charts/histogramDataWidget.cpp
22 
23  \brief A widget used to adjust a histogram's input data.
24 */
25 
26 //Terralib
27 #include "../../../qt/widgets/charts/Utils.h"
28 #include "../../../dataaccess.h"
29 #include "../../../datatype/Property.h"
30 #include "../../../raster.h"
31 #include "../../../raster/RasterSummaryManager.h"
32 #include "../../../statistics/core/Enums.h"
33 #include "../../../statistics/core/Utils.h"
34 #include "Histogram.h"
35 #include "HistogramDataWidget.h"
36 #include "ui_HistogramDataWidgetForm.h"
37 
38 #include <iostream>
39 
40 void updateSummary(te::da::DataSet* dataSet, Ui::HistogramDataWidgetForm* ui)
41 {
42  ui->m_summaryComboBox->clear();
43 
44  size_t selectedPropertyIdx = 0;
45  for (size_t i = 0; i < dataSet->getNumProperties(); i++)
46  {
47  if(ui->m_propertyComboBox->currentText().toStdString() == dataSet->getPropertyName(i))
48  selectedPropertyIdx = i;
49  }
50 
51  int propType = dataSet->getPropertyDataType(selectedPropertyIdx);
52 
53  if(propType == te::dt::DATETIME_TYPE || propType == te::dt::STRING_TYPE)
54  {
55  ui->m_summaryComboBox->addItem(QString::fromStdString("None"), QVariant(-1));
56  ui->m_summaryComboBox->addItem(QString(te::stat::GetStatSummaryFullName(te::stat::MIN_VALUE).c_str()), QVariant(te::stat::MIN_VALUE));
57  ui->m_summaryComboBox->addItem(QString(te::stat::GetStatSummaryFullName(te::stat::MAX_VALUE).c_str()), QVariant(te::stat::MAX_VALUE));
58  //ui->m_summaryComboBox->addItem(QString(te::stat::GetStatSummaryFullName(te::stat::COUNT).c_str()), QVariant(te::stat::COUNT));
59  //ui->m_summaryComboBox->addItem(QString(te::stat::GetStatSummaryFullName(te::stat::VALID_COUNT).c_str()), QVariant(te::stat::VALID_COUNT));
60  }
61  else
62  {
63  ui->m_summaryComboBox->addItem(QString::fromStdString("None"), QVariant(-1));
64  ui->m_summaryComboBox->addItem(QString(te::stat::GetStatSummaryFullName(te::stat::MIN_VALUE).c_str()), QVariant(te::stat::MIN_VALUE));
65  ui->m_summaryComboBox->addItem(QString(te::stat::GetStatSummaryFullName(te::stat::MAX_VALUE).c_str()), QVariant(te::stat::MAX_VALUE));
66  //ui->m_summaryComboBox->addItem(QString(te::stat::GetStatSummaryFullName(te::stat::COUNT).c_str()), QVariant(te::stat::COUNT));
67  //ui->m_summaryComboBox->addItem(QString(te::stat::GetStatSummaryFullName(te::stat::VALID_COUNT).c_str()), QVariant(te::stat::VALID_COUNT));
68  ui->m_summaryComboBox->addItem(QString(te::stat::GetStatSummaryFullName(te::stat::MEAN).c_str()), QVariant(te::stat::MEAN));
69  ui->m_summaryComboBox->addItem(QString(te::stat::GetStatSummaryFullName(te::stat::SUM).c_str()), QVariant(te::stat::SUM));
70  ui->m_summaryComboBox->addItem(QString(te::stat::GetStatSummaryFullName(te::stat::STANDARD_DEVIATION).c_str()), QVariant(te::stat::STANDARD_DEVIATION));
71  ui->m_summaryComboBox->addItem(QString(te::stat::GetStatSummaryFullName(te::stat::VARIANCE).c_str()), QVariant(te::stat::VARIANCE));
72  ui->m_summaryComboBox->addItem(QString(te::stat::GetStatSummaryFullName(te::stat::SKEWNESS).c_str()), QVariant(te::stat::SKEWNESS));
73  ui->m_summaryComboBox->addItem(QString(te::stat::GetStatSummaryFullName(te::stat::KURTOSIS).c_str()), QVariant(te::stat::KURTOSIS));
74  ui->m_summaryComboBox->addItem(QString(te::stat::GetStatSummaryFullName(te::stat::AMPLITUDE).c_str()), QVariant(te::stat::AMPLITUDE));
75  ui->m_summaryComboBox->addItem(QString(te::stat::GetStatSummaryFullName(te::stat::MEDIAN).c_str()), QVariant(te::stat::MEDIAN));
76  ui->m_summaryComboBox->addItem(QString(te::stat::GetStatSummaryFullName(te::stat::VAR_COEFF).c_str()), QVariant(te::stat::VAR_COEFF));
77  //ui->m_summaryComboBox->addItem(QString(te::stat::GetStatSummaryFullName(te::stat::MODE).c_str()), QVariant(te::stat::MODE));
78  }
79  ui->m_summaryComboBox->setCurrentIndex(0);
80 }
81 
83  : QWidget(parent, f),
84  m_ui(new Ui::HistogramDataWidgetForm),
85  m_dataSet (dataSet),
86  m_dataType(dataType)
87 {
88  m_ui->setupUi(this);
89 
90  QString item;
91 
93 
94  if(rpos != std::string::npos)
95  {
96  //Adjusting the widget to work with a raster file.
97  std::auto_ptr<te::rst::Raster> raster = m_dataSet->getRaster(rpos);
98 
101 
102  const std::complex<double>* cmin = rsMin->at(0).m_minVal;
103  const std::complex<double>* cmax = rsMax->at(0).m_maxVal;
104 
105  double min = cmin->real();
106  double max = cmax->real();
107 
108  size_t size = raster->getNumberOfBands();
109  m_ui->m_slicesSpinBox->setMinimum(0);
110  m_ui->m_slicesSpinBox->setValue(30);
111 
112  if (min >= 0 && max <= 255)
113  m_ui->m_slicesSpinBox->setMaximum(255);
114  else
115  m_ui->m_slicesSpinBox->setMaximum(max);
116 
117  m_ui->m_slicesSpinBox->setValue(255);
118 
119  for (size_t i = 0; i < size; i++)
120  {
121  item = QString::number(i);
122  m_ui->m_propertyComboBox->addItem((QString::fromStdString("Band: ") + item), QVariant::fromValue(i));
123  }
124  }
125  else
126  {
127  for (std::size_t i = 0; i < dataSet->getNumProperties(); i++)
128  {
129  if(dataSet->getPropertyDataType(i) != te::dt::GEOMETRY_TYPE)
130  {
131  item = QString::fromStdString(dataSet->getPropertyName(i));
132  m_ui->m_propertyComboBox->addItem(item, QVariant::fromValue(i));
133  }
134  }
135  }
136 
137  updateSummary(m_dataSet.get(), getForm());
138 
139  if(te::da::HasLinkedTable(dataType))
140  {
141  m_ui->m_summaryComboBox->show();
142  m_ui->m_summaryLabel->show();
143  }
144  else
145  {
146  m_ui->m_summaryComboBox->hide();
147  m_ui->m_summaryLabel->hide();
148  }
149 
150 // connect signal and slots
151  connect(m_ui->m_propertyComboBox, SIGNAL(currentIndexChanged(QString)), this, SLOT(onPropertyComboBoxIndexChanged(QString)));
152 }
153 
155 {
156 }
157 
158 Ui::HistogramDataWidgetForm* te::qt::widgets::HistogramDataWidget::getForm()
159 {
160  return m_ui.get();
161 }
162 
164 {
165  std::size_t rpos = te::da::GetFirstPropertyPos(m_dataSet.get(), te::dt::RASTER_TYPE);
166  te::qt::widgets::Histogram* histogram;
167 
168  if(rpos != std::string::npos)
169  {
170  histogram = te::qt::widgets::createHistogram(m_dataSet.get(), m_dataType.get(), m_ui->m_propertyComboBox->itemData(m_ui->m_propertyComboBox->currentIndex()).toInt(), m_ui->m_slicesSpinBox->value(), -1);
171  }
172  else
173  {
174  //Getting the Columns that will be used to populate the chart
175 
176  size_t selectedPropertyIdx = 0;
177 
178  for (size_t i = 0; i < m_dataSet->getNumProperties(); i++)
179  {
180  if(m_ui->m_propertyComboBox->currentText().toStdString() == m_dataSet.get()->getPropertyName(i))
181  {
182  selectedPropertyIdx = i;
183  }
184  }
185 
186  int propType = m_dataSet->getPropertyDataType(selectedPropertyIdx);
187  int stat = m_ui->m_summaryComboBox->itemData(m_ui->m_summaryComboBox->currentIndex()).toInt();
188 
189  if(propType == te::dt::DATETIME_TYPE || propType == te::dt::STRING_TYPE)
190  {
191  histogram = te::qt::widgets::createHistogram(m_dataSet.get(), m_dataType.get(), (int)selectedPropertyIdx, stat);
192  }
193  else
194  {
195  histogram = te::qt::widgets::createHistogram(m_dataSet.get(), m_dataType.get(), (int)selectedPropertyIdx, m_ui->m_slicesSpinBox->value(), stat);
196  }
197  }
198  return histogram;
199 }
200 
202 {
203  m_ui->m_propertyComboBox->setCurrentIndex(m_ui->m_propertyComboBox->findData(propId));
204  m_ui->m_propertyComboBox->setEnabled(false);
205 }
206 
208 {
209  std::size_t rpos = te::da::GetFirstPropertyPos(m_dataSet.get(), te::dt::RASTER_TYPE);
210  if(rpos == std::string::npos)
211  {
212  size_t selectedPropertyIdx= te::da::GetPropertyPos(m_dataSet.get(), m_ui->m_propertyComboBox->currentText().toStdString());
213  int propType = m_dataSet->getPropertyDataType(selectedPropertyIdx);
214 
215  if(propType == te::dt::DATETIME_TYPE || propType == te::dt::STRING_TYPE)
216  {
217  m_ui->m_slicesSpinBox->setEnabled(false);
218  }
219  else
220  {
221  m_ui->m_slicesSpinBox->setEnabled(true);
222  }
223  }
224  else
225  {
226  std::auto_ptr<te::rst::Raster> raster = m_dataSet->getRaster(rpos);
227 
230 
231  const std::complex<double>* cmin = rsMin->at(m_ui->m_propertyComboBox->currentIndex()).m_minVal;
232  const std::complex<double>* cmax = rsMax->at(m_ui->m_propertyComboBox->currentIndex()).m_maxVal;
233 
234  double min = cmin->real();
235  double max = cmax->real();
236 
237  if (min >= 0 && max <= 255)
238  m_ui->m_slicesSpinBox->setMaximum(255);
239  else
240  m_ui->m_slicesSpinBox->setMaximum(max);
241 
242  m_ui->m_slicesSpinBox->setValue(255);
243  }
244 
245  updateSummary(m_dataSet.get(), getForm());
246 
247  if(te::da::HasLinkedTable(m_dataType.get()))
248  {
249  m_ui->m_summaryComboBox->show();
250  m_ui->m_summaryLabel->show();
251  }
252  else
253  {
254  m_ui->m_summaryComboBox->hide();
255  m_ui->m_summaryLabel->hide();
256  }
257 }
258 
260 {
261  return m_ui->m_summaryComboBox->currentText().toStdString();
262 }
Mean.
Definition: Enums.h:43
Skewness.
Definition: Enums.h:49
te::qt::widgets::Histogram * getHistogram()
Returns a pointer to the widget's form.
TEDATAACCESSEXPORT bool HasLinkedTable(te::da::DataSetType *type)
It checks if the datasettype has a linked table.
Definition: Utils.cpp:1213
TEQTWIDGETSEXPORT Histogram * createHistogram(te::da::DataSet *dataset, te::da::DataSetType *dataType, int propId, int slices, int stat)
Histogram Creator.
Definition: Utils.cpp:786
A class that models the description of a dataset.
Definition: DataSetType.h:72
TEDATAACCESSEXPORT std::size_t GetPropertyPos(const DataSet *dataset, const std::string &name)
Definition: Utils.cpp:500
void setHistogramProperty(int propId)
Sets the property to be used in order to generate the histogram.
std::auto_ptr< Ui::HistogramDataWidgetForm > m_ui
The widget's form.
A class to represent a Histogram.
Definition: Histogram.h:56
Minimum value.
Definition: Enums.h:41
A class to represent a histogram.
static RasterSummaryManager & getInstance()
It returns a reference to the singleton instance.
Median.
Definition: Enums.h:52
virtual std::string getPropertyName(std::size_t i) const =0
It returns the property name at position pos.
std::string getSummaryFunction()
Returns the name of the chosen summary function. Default is None.
std::auto_ptr< te::da::DataSet > m_dataSet
The dataset that will be used to generate the histogram graph.
HistogramDataWidget(te::da::DataSet *dataSet, te::da::DataSetType *dataType, QWidget *parent=0, Qt::WindowFlags f=0)
Constructor.
Kurtosis.
Definition: Enums.h:50
Standard deviation.
Definition: Enums.h:47
Sum of values.
Definition: Enums.h:44
boost::ptr_vector< BandSummary > RasterSummary
RasterSummary is just a typedef of a boost::ptr_vector.
Definition: RasterSummary.h:44
TESTATEXPORT std::string GetStatSummaryFullName(const int &e)
Get the statistical parameter full name ffrom its enumerator.
Definition: Utils.cpp:94
void updateSummary(te::da::DataSet *dataSet, Ui::HistogramDataWidgetForm *ui)
virtual std::size_t getNumProperties() const =0
It returns the number of properties that composes an item of the dataset.
Coefficient variation.
Definition: Enums.h:53
A dataset is the unit of information manipulated by the data access module of TerraLib.
Definition: DataSet.h:112
Ui::HistogramDataWidgetForm * getForm()
Returns a pointer to the widget's form.
TEDATAACCESSEXPORT std::size_t GetFirstPropertyPos(const te::da::DataSet *dataset, int datatype)
Definition: Utils.cpp:481
Calculate the min value.
Definition: Enums.h:40
virtual int getPropertyDataType(std::size_t i) const =0
It returns the underlying data type of the property at position pos.
Calculate the max value.
Definition: Enums.h:41
Variance.
Definition: Enums.h:48
Maximum value.
Definition: Enums.h:42
Amplitude.
Definition: Enums.h:51