All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Histogram.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 Histogram.cpp
22 
23  \brief A class to represent a histogram.
24 */
25 
26 //terralib
27 #include "../../../datatype.h"
28 #include "../../../dataaccess/dataset/ObjectIdSet.h"
29 #include "Histogram.h"
30 
32 {
33 
34 }
35 
37 {
38  clear();
39 }
40 
42 {
43  return m_histogramType;
44 }
45 
47 {
48  m_histogramType = new_type;
49 }
50 
52 {
53  return m_isSummarized;
54 }
55 
57 {
58  m_isSummarized = summarized;
59 }
60 
61 std::map<double, unsigned int> te::qt::widgets::Histogram::getValues()
62 {
63  std::map<double, unsigned int> res;
64 
65  //Casting every interval into a double value
66  for(HistogramValues::iterator it = m_values.begin(); it != m_values.end(); ++it)
67  res.insert(std::make_pair(static_cast<te::dt::Double*>(it->first)->getValue(), it->second));
68 
69  return res;
70 }
71 
72 void te::qt::widgets::Histogram::setValues(std::map<te::dt::AbstractData*, unsigned int> values)
73 {
74  clear();
75  std::map<te::dt::AbstractData*, unsigned int>::iterator valItbegin = values.begin();
76  std::map<te::dt::AbstractData*, unsigned int>::iterator valItend = values.end();
77 
78  while(valItbegin != valItend)
79  {
80  m_values.insert(*valItbegin);
81  valItbegin++;
82  }
83 }
84 
85 std::map<std::string, unsigned int> te::qt::widgets::Histogram::getStringValues()
86 {
87  std::map<std::string, unsigned int> res;
88  //Casting every interval into a string value
89  for(HistogramValues::iterator it = m_values.begin(); it != m_values.end(); ++it)
90  res.insert(std::make_pair(it->first->toString(), it->second));
91  return res;
92 }
93 
95 {
96  return m_minValue;
97 }
98 
99 void te::qt::widgets::Histogram::setMinValue(double new_minValue)
100 {
101  m_minValue = new_minValue;
102 }
103 
105 {
106  return m_interval;
107 }
108 
110 {
111  m_interval = new_Interval;
112 }
113 
115 {
116  return m_StringIntervals;
117 }
118 
119 void te::qt::widgets::Histogram::setStringInterval( std::set <std::string> new_Interval)
120 {
121  m_StringIntervals = new_Interval;
122 }
123 
124 void te::qt::widgets::Histogram::insert(std::pair<te::dt::AbstractData*, unsigned int> new_value, std::vector<te::da::ObjectId*> valuesOIds)
125 {
126  m_values.insert(new_value);
127  adjustOids(new_value.first, valuesOIds);
128 }
129 
130 void te::qt::widgets::Histogram::insert(std::pair<te::dt::AbstractData*, unsigned int> new_value)
131 {
132  m_values.insert(new_value);
133 }
134 
135 void te::qt::widgets::Histogram::insert(te::dt::AbstractData* interval, unsigned int frequency, std::vector<te::da::ObjectId*> valuesOIds)
136 {
137  insert(std::make_pair(interval, frequency), valuesOIds);
138 }
139 
140 void te::qt::widgets::Histogram::insert(te::dt::AbstractData* interval, unsigned int frequency)
141 {
142  insert(std::make_pair(interval, frequency));
143 }
144 
146 {
147  HistogramValues::iterator it = m_values.begin();
148  while(it != m_values.end())
149  {
150  delete it->first;
151  ++it;
152  }
153  m_values.clear();
154 
155  te::qt::widgets::IntervalToObjectIdSet::iterator it2= m_valuesOids.begin();
156  while(it2 != m_valuesOids.end())
157  {
158  delete it2->oid;
159  ++it2;
160  }
161  m_valuesOids.clear();
162 }
163 
165 {
166  typedef te::qt::widgets::IntervalToObjectIdSet::nth_index<0>::type::iterator itIntervalToObjectIdSet;
167  IntervalToObjectId aux(interval, 0);
168 
169  std::pair<itIntervalToObjectIdSet, itIntervalToObjectIdSet> res = m_valuesOids.equal_range(aux);
170  itIntervalToObjectIdSet it0 = res.first;
171  itIntervalToObjectIdSet it1 = res.second;
172 
174 
175  while(it0 != it1)
176  {
177  te::da::ObjectId* oid = new te::da::ObjectId(*it0->oid);
178  oids->add(oid);
179  ++it0;
180  }
181  return oids;
182 }
183 
184 te::da::ObjectIdSet* te::qt::widgets::Histogram::find(std::vector<te::dt::AbstractData*> intervals)
185 {
186  typedef te::qt::widgets::IntervalToObjectIdSet::nth_index<0>::type::iterator itIntervalToObjectIdSet;
188 
189  for(size_t i = 0; i < intervals.size(); ++i)
190  {
191  IntervalToObjectId aux(intervals[i], 0);
192 
193  std::pair<itIntervalToObjectIdSet, itIntervalToObjectIdSet> res = m_valuesOids.equal_range(aux);
194  itIntervalToObjectIdSet it0 = res.first;
195  itIntervalToObjectIdSet it1 = res.second;
196 
197  while(it0 != it1)
198  {
199  te::da::ObjectId* oid = new te::da::ObjectId(*it0->oid);
200  oids->add(oid);
201  ++it0;
202  }
203  delete intervals[i];
204  }
205 
206  return oids;
207 }
208 
210 {
211  te::qt::widgets::IntervalToObjectIdSet::nth_index<1>::type::iterator it= m_valuesOids.get<1>().find(oid->getValueAsString());
212  te::dt::AbstractData* interval = it->interval;
213  if(it != m_valuesOids.get<1>().end())
214  return interval;
215  else
216  return NULL;
217 }
218 
219 void te::qt::widgets::Histogram::adjustOids(te::dt::AbstractData* interval, std::vector<te::da::ObjectId*> valuesOIds)
220 {
221  for(size_t i = 0; i < valuesOIds.size(); ++i)
222  {
223  m_valuesOids.insert(te::qt::widgets::IntervalToObjectId(interval, valuesOIds.at(i)));
224  }
225 }
~Histogram()
Destructor.
Definition: Histogram.cpp:36
A class to represent a histogram.
void setStringInterval(std::set< std::string > new_Interval)
It sets the histogram's string set of intervals.
Definition: Histogram.cpp:119
This class represents a set of unique ids created in the same context. i.e. from the same data set...
Definition: ObjectIdSet.h:55
This class represents an unique id for a data set element.
Definition: ObjectId.h:47
mydialect insert("+", new te::da::BinaryOpEncoder("+"))
void setSummarized(bool summarized)
It sets the property that holds whether the histogram has been created from summarized values or not...
Definition: Histogram.cpp:56
void clear()
A function used to clear the contents of the histogram, deleting the pointers contained by the boost ...
Definition: Histogram.cpp:145
std::map< std::string, unsigned int > getStringValues()
It returns the map containing the histogram String values. The key is a unique string that represents...
Definition: Histogram.cpp:85
std::string getValueAsString() const
It gets the properties values used to uniquely identify a data set element as string.
Definition: ObjectId.cpp:51
A base class for values that can be retrieved from the data access module.
Definition: AbstractData.h:57
double & getMinValue()
It returns the histogram's minimum value. Will be invalid if the histogram was created based on strin...
Definition: Histogram.cpp:94
void setInterval(double new_Interval)
It sets the histogram's interval.
Definition: Histogram.cpp:109
void setValues(std::map< te::dt::AbstractData *, unsigned int > values)
It sets the histogram's values.
Definition: Histogram.cpp:72
std::map< double, unsigned int > getValues()
It returns the map containing the histogram values. The key is the minimum values of the histogram's ...
Definition: Histogram.cpp:61
Histogram()
Constructor.
Definition: Histogram.cpp:31
void adjustOids(te::dt::AbstractData *interval, std::vector< te::da::ObjectId * > valuesOIds)
It will populate the IntervalToObjectIdSet with the given interval and it's matching objectIds...
Definition: Histogram.cpp:219
void setMinValue(double new_minValue)
It sets the histogram's minimum value.
Definition: Histogram.cpp:99
std::set< std::string > & getStringInterval()
It returns the histogram's string set of intervals. Will be invalid if the histogram was created base...
Definition: Histogram.cpp:114
void insert(std::pair< te::dt::AbstractData *, unsigned int > new_value, std::vector< te::da::ObjectId * > valuesOIds)
It adds a new value to the map containing the histogram values.
Definition: Histogram.cpp:124
void add(ObjectId *oid)
It adds an object id to this object id set.
Definition: ObjectIdSet.cpp:83
bool isSummarized()
It returns a boolean that holds whether the histogram has been created from summarized values or not...
Definition: Histogram.cpp:51
double & getInterval()
It returns the histogram's interval. Will be invalid if the histogram was created based on string int...
Definition: Histogram.cpp:104
int & getType()
It returns the histogram's type.
Definition: Histogram.cpp:41
void setType(int new_type)
It sets the histogram's type.
Definition: Histogram.cpp:46
te::da::ObjectIdSet * find(te::dt::AbstractData *interval)
It returns an ObjectIdSet containing all the object Ids associeted with the given interval...
Definition: Histogram.cpp:164