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) 2010-2013 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/RasterSummary.h"
32 #include "../../../raster/RasterSummaryManager.h"
33 #include "Histogram.h"
34 #include "HistogramDataWidget.h"
35 #include "ui_HistogramDataWidgetForm.h"
36 
37 #include <iostream>
38 
40  : QWidget(parent, f),
41  m_ui(new Ui::HistogramDataWidgetForm),
42  m_dataSet (dataSet),
43  m_dataType(dataType)
44 {
45  m_ui->setupUi(this);
46 
47  QString item;
48 
50 
51  if(rpos != std::string::npos)
52  {
53  //Adjusting the widget to work with a raster file.
54  std::auto_ptr<te::rst::Raster> raster = m_dataSet->getRaster(rpos);
55 
58 
59  const std::complex<double>* cmin = rsMin->at(0).m_minVal;
60  const std::complex<double>* cmax = rsMax->at(0).m_maxVal;
61 
62  double min = cmin->real();
63  double max = cmax->real();
64 
65  size_t size = raster->getNumberOfBands();
66  m_ui->m_slicesSpinBox->setMinimum(0);
67  m_ui->m_slicesSpinBox->setValue(0);
68 
69  if (min >= 0 && max <= 255)
70  m_ui->m_slicesSpinBox->setMaximum(255);
71  else
72  m_ui->m_slicesSpinBox->setMaximum(max);
73 
74  for (size_t i = 0; i < size; i++)
75  {
76  item = QString::number(i);
77  m_ui->m_propertyComboBox->addItem((QString::fromStdString("Band: ") + item));
78  }
79  }
80  else
81  {
82 
83  for (std::size_t i = 0; i < dataSet->getNumProperties(); i++)
84  {
86  {
87  item = QString::fromStdString(dataSet->getPropertyName(i));
88  m_ui->m_propertyComboBox->addItem(item);
89  }
90  }
91  }
92 
93 // connect signal and slots
94  connect(m_ui->m_propertyComboBox, SIGNAL(currentIndexChanged(QString)), this, SLOT(onPropertyComboBoxIndexChanged(QString)));
95 }
96 
98 {
99 }
100 
101 Ui::HistogramDataWidgetForm* te::qt::widgets::HistogramDataWidget::getForm()
102 {
103  return m_ui.get();
104 }
105 
107 {
108  std::size_t rpos = te::da::GetFirstPropertyPos(m_dataSet.get(), te::dt::RASTER_TYPE);
109  te::qt::widgets::Histogram* histogram;
110 
111  if(rpos != std::string::npos)
112  {
113  histogram = te::qt::widgets::createHistogram(m_dataSet.get(), m_dataType.get(), m_ui->m_propertyComboBox->currentIndex(), m_ui->m_slicesSpinBox->value());
114  }
115  else
116  {
117  //Getting the Columns that will be used to populate the chart
118 
119  size_t selectedPropertyIdx = 0;
120 
121  for (size_t i = 0; i < m_dataSet->getNumProperties(); i++)
122  {
123  if(m_ui->m_propertyComboBox->currentText().toStdString() == m_dataSet.get()->getPropertyName(i))
124  selectedPropertyIdx = i;
125  }
126 
127  int propType = m_dataSet->getPropertyDataType(selectedPropertyIdx);
128 
129  if(propType == te::dt::DATETIME_TYPE || propType == te::dt::STRING_TYPE)
130  {
131  histogram = te::qt::widgets::createHistogram(m_dataSet.get(), m_dataType.get(), selectedPropertyIdx);
132  }
133  else
134  {
135  histogram = te::qt::widgets::createHistogram(m_dataSet.get(), m_dataType.get(), selectedPropertyIdx, m_ui->m_slicesSpinBox->value());
136  }
137  }
138  return histogram;
139 }
140 
142 {
143  std::size_t rpos = te::da::GetFirstPropertyPos(m_dataSet.get(), te::dt::RASTER_TYPE);
144  if(rpos == std::string::npos)
145  {
146  int selectedPropertyIdx= te::da::GetPropertyPos(m_dataSet.get(), m_ui->m_propertyComboBox->currentText().toStdString());
147  int propType = m_dataSet->getPropertyDataType(selectedPropertyIdx);
148 
149  if(propType == te::dt::DATETIME_TYPE || propType == te::dt::STRING_TYPE)
150  {
151  m_ui->m_slicesSpinBox->setEnabled(false);
152  }
153  else
154  {
155  m_ui->m_slicesSpinBox->setEnabled(true);
156  }
157  }
158  else
159  {
160  std::auto_ptr<te::rst::Raster> raster = m_dataSet->getRaster(rpos);
161 
164 
165  const std::complex<double>* cmin = rsMin->at(m_ui->m_propertyComboBox->currentIndex()).m_minVal;
166  const std::complex<double>* cmax = rsMax->at(m_ui->m_propertyComboBox->currentIndex()).m_maxVal;
167 
168  double min = cmin->real();
169  double max = cmax->real();
170 
171  if (min >= 0 && max <= 255)
172  m_ui->m_slicesSpinBox->setMaximum(255);
173  else
174  m_ui->m_slicesSpinBox->setMaximum(max);
175 
176  m_ui->m_slicesSpinBox->setValue(0);
177  }
178 }
A widget used to adjust a histogram's input data.
te::qt::widgets::Histogram * getHistogram()
Returns a pointer to the widget's form.
A class that models the description of a dataset.
Definition: DataSetType.h:72
TEQTWIDGETSEXPORT Histogram * createHistogram(te::da::DataSet *dataset, te::da::DataSetType *dataType, int propId, int slices)
Histogram Creator.
Definition: Utils.cpp:291
TEDATAACCESSEXPORT std::size_t GetPropertyPos(const DataSet *dataset, const std::string &name)
Definition: Utils.cpp:451
std::auto_ptr< Ui::HistogramDataWidgetForm > m_ui
The widget's form.
A class to represent a Histogram.
Definition: Histogram.h:56
A class to represent a histogram.
static RasterSummaryManager & getInstance()
It returns a reference to the singleton instance.
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.
boost::ptr_vector< BandSummary > RasterSummary
RasterSummary is just a typedef of a boost::ptr_vector.
Definition: RasterSummary.h:44
virtual std::size_t getNumProperties() const =0
It returns the number of properties that composes an item of the dataset.
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:432
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