All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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  for (size_t i = 0; i < size; i++)
118  {
119  item = QString::number(i);
120  m_ui->m_propertyComboBox->addItem((QString::fromStdString("Band: ") + item), QVariant::fromValue(i));
121  }
122  }
123  else
124  {
125  for (std::size_t i = 0; i < dataSet->getNumProperties(); i++)
126  {
127  if(dataSet->getPropertyDataType(i) != te::dt::GEOMETRY_TYPE)
128  {
129  item = QString::fromStdString(dataSet->getPropertyName(i));
130  m_ui->m_propertyComboBox->addItem(item, QVariant::fromValue(i));
131  }
132  }
133  }
134 
135  updateSummary(m_dataSet.get(), getForm());
136 
137  if(te::da::HasLinkedTable(dataType))
138  {
139  m_ui->m_summaryComboBox->show();
140  m_ui->m_summaryLabel->show();
141  }
142  else
143  {
144  m_ui->m_summaryComboBox->hide();
145  m_ui->m_summaryLabel->hide();
146  }
147 
148 // connect signal and slots
149  connect(m_ui->m_propertyComboBox, SIGNAL(currentIndexChanged(QString)), this, SLOT(onPropertyComboBoxIndexChanged(QString)));
150 }
151 
153 {
154 }
155 
156 Ui::HistogramDataWidgetForm* te::qt::widgets::HistogramDataWidget::getForm()
157 {
158  return m_ui.get();
159 }
160 
162 {
163  std::size_t rpos = te::da::GetFirstPropertyPos(m_dataSet.get(), te::dt::RASTER_TYPE);
164  te::qt::widgets::Histogram* histogram;
165 
166  if(rpos != std::string::npos)
167  {
168  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);
169  }
170  else
171  {
172  //Getting the Columns that will be used to populate the chart
173 
174  size_t selectedPropertyIdx = 0;
175 
176  for (size_t i = 0; i < m_dataSet->getNumProperties(); i++)
177  {
178  if(m_ui->m_propertyComboBox->currentText().toStdString() == m_dataSet.get()->getPropertyName(i))
179  {
180  selectedPropertyIdx = i;
181  }
182  }
183 
184  int propType = m_dataSet->getPropertyDataType(selectedPropertyIdx);
185  int stat = m_ui->m_summaryComboBox->itemData(m_ui->m_summaryComboBox->currentIndex()).toInt();
186 
187  if(propType == te::dt::DATETIME_TYPE || propType == te::dt::STRING_TYPE)
188  {
189  histogram = te::qt::widgets::createHistogram(m_dataSet.get(), m_dataType.get(), selectedPropertyIdx, stat);
190  }
191  else
192  {
193  histogram = te::qt::widgets::createHistogram(m_dataSet.get(), m_dataType.get(), selectedPropertyIdx, m_ui->m_slicesSpinBox->value(), stat);
194  }
195  }
196  return histogram;
197 }
198 
200 {
201  m_ui->m_propertyComboBox->setCurrentIndex(m_ui->m_propertyComboBox->findData(propId));
202  m_ui->m_propertyComboBox->setEnabled(false);
203 }
204 
206 {
207  std::size_t rpos = te::da::GetFirstPropertyPos(m_dataSet.get(), te::dt::RASTER_TYPE);
208  if(rpos == std::string::npos)
209  {
210  int selectedPropertyIdx= te::da::GetPropertyPos(m_dataSet.get(), m_ui->m_propertyComboBox->currentText().toStdString());
211  int propType = m_dataSet->getPropertyDataType(selectedPropertyIdx);
212 
213  if(propType == te::dt::DATETIME_TYPE || propType == te::dt::STRING_TYPE)
214  {
215  m_ui->m_slicesSpinBox->setEnabled(false);
216  }
217  else
218  {
219  m_ui->m_slicesSpinBox->setEnabled(true);
220  }
221  }
222  else
223  {
224  std::auto_ptr<te::rst::Raster> raster = m_dataSet->getRaster(rpos);
225 
228 
229  const std::complex<double>* cmin = rsMin->at(m_ui->m_propertyComboBox->currentIndex()).m_minVal;
230  const std::complex<double>* cmax = rsMax->at(m_ui->m_propertyComboBox->currentIndex()).m_maxVal;
231 
232  double min = cmin->real();
233  double max = cmax->real();
234 
235  if (min >= 0 && max <= 255)
236  m_ui->m_slicesSpinBox->setMaximum(255);
237  else
238  m_ui->m_slicesSpinBox->setMaximum(max);
239 
240  m_ui->m_slicesSpinBox->setValue(30);
241  }
242 
243  updateSummary(m_dataSet.get(), getForm());
244 
245  if(te::da::HasLinkedTable(m_dataType.get()))
246  {
247  m_ui->m_summaryComboBox->show();
248  m_ui->m_summaryLabel->show();
249  }
250  else
251  {
252  m_ui->m_summaryComboBox->hide();
253  m_ui->m_summaryLabel->hide();
254  }
255 }
Mean.
Definition: Enums.h:43
A widget used to adjust a histogram's input data.
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:1175
TEQTWIDGETSEXPORT Histogram * createHistogram(te::da::DataSet *dataset, te::da::DataSetType *dataType, int propId, int slices, int stat)
Histogram Creator.
Definition: Utils.cpp:773
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::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:88
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