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  m_minValue = std::numeric_limits<double>::min();
34  m_interval = std::numeric_limits<double>::max();
35 }
36 
38 {
39  clear();
40 }
41 
43 {
44  return m_histogramType;
45 }
46 
48 {
49  m_histogramType = new_type;
50 }
51 
53 {
54  return m_isSummarized;
55 }
56 
58 {
59  m_isSummarized = summarized;
60 }
61 
62 std::map<double, unsigned int> te::qt::widgets::Histogram::getValues()
63 {
64  std::map<double, unsigned int> res;
65 
66  //Casting every interval into a double value
67  for(HistogramValues::iterator it = m_values.begin(); it != m_values.end(); ++it)
68  res.insert(std::make_pair(static_cast<te::dt::Double*>(it->first)->getValue(), it->second));
69 
70  return res;
71 }
72 
73 void te::qt::widgets::Histogram::setValues(std::map<te::dt::AbstractData*, unsigned int> values)
74 {
75  clear();
76  std::map<te::dt::AbstractData*, unsigned int>::iterator valItbegin = values.begin();
77  std::map<te::dt::AbstractData*, unsigned int>::iterator valItend = values.end();
78 
79  while(valItbegin != valItend)
80  {
81  m_values.insert(*valItbegin);
82  valItbegin++;
83  }
84 }
85 
86 std::map<std::string, unsigned int> te::qt::widgets::Histogram::getStringValues()
87 {
88  std::map<std::string, unsigned int> res;
89  //Casting every interval into a string value
90  for(HistogramValues::iterator it = m_values.begin(); it != m_values.end(); ++it)
91  res.insert(std::make_pair(it->first->toString(), it->second));
92  return res;
93 }
94 
96 {
97  return m_minValue;
98 }
99 
101 {
102  m_minValue = new_minValue;
103 }
104 
106 {
107  return m_interval;
108 }
109 
111 {
112  m_interval = new_Interval;
113 }
114 
116 {
117  return m_StringIntervals;
118 }
119 
120 void te::qt::widgets::Histogram::setStringInterval( std::set <std::string> new_Interval)
121 {
122  m_StringIntervals = new_Interval;
123 }
124 
125 void te::qt::widgets::Histogram::insert(std::pair<te::dt::AbstractData*, unsigned int> new_value, std::vector<te::da::ObjectId*> valuesOIds)
126 {
127  m_values.insert(new_value);
128  adjustOids(new_value.first, valuesOIds);
129 }
130 
131 void te::qt::widgets::Histogram::insert(std::pair<te::dt::AbstractData*, unsigned int> new_value)
132 {
133  m_values.insert(new_value);
134 }
135 
136 void te::qt::widgets::Histogram::insert(te::dt::AbstractData* interval, unsigned int frequency, std::vector<te::da::ObjectId*> valuesOIds)
137 {
138  insert(std::make_pair(interval, frequency), valuesOIds);
139 }
140 
141 void te::qt::widgets::Histogram::insert(te::dt::AbstractData* interval, unsigned int frequency)
142 {
143  insert(std::make_pair(interval, frequency));
144 }
145 
147 {
148  HistogramValues::iterator it = m_values.begin();
149  while(it != m_values.end())
150  {
151  delete it->first;
152  ++it;
153  }
154  m_values.clear();
155 
156  te::qt::widgets::IntervalToObjectIdSet::iterator it2= m_valuesOids.begin();
157  while(it2 != m_valuesOids.end())
158  {
159  delete it2->oid;
160  ++it2;
161  }
162  m_valuesOids.clear();
163 }
164 
166 {
167  typedef te::qt::widgets::IntervalToObjectIdSet::nth_index<0>::type::iterator itIntervalToObjectIdSet;
168  IntervalToObjectId aux(interval, 0);
169 
170  std::pair<itIntervalToObjectIdSet, itIntervalToObjectIdSet> res = m_valuesOids.equal_range(aux);
171  itIntervalToObjectIdSet it0 = res.first;
172  itIntervalToObjectIdSet it1 = res.second;
173 
175 
176  while(it0 != it1)
177  {
178  te::da::ObjectId* oid = new te::da::ObjectId(*it0->oid);
179  oids->add(oid);
180  ++it0;
181  }
182  return oids;
183 }
184 
185 te::da::ObjectIdSet* te::qt::widgets::Histogram::find(std::vector<te::dt::AbstractData*> intervals)
186 {
187  typedef te::qt::widgets::IntervalToObjectIdSet::nth_index<0>::type::iterator itIntervalToObjectIdSet;
189 
190  for(size_t i = 0; i < intervals.size(); ++i)
191  {
192  IntervalToObjectId aux(intervals[i], 0);
193 
194  std::pair<itIntervalToObjectIdSet, itIntervalToObjectIdSet> res = m_valuesOids.equal_range(aux);
195  itIntervalToObjectIdSet it0 = res.first;
196  itIntervalToObjectIdSet it1 = res.second;
197 
198  while(it0 != it1)
199  {
200  te::da::ObjectId* oid = new te::da::ObjectId(*it0->oid);
201  oids->add(oid);
202  ++it0;
203  }
204  delete intervals[i];
205  }
206 
207  return oids;
208 }
209 
211 {
212  te::qt::widgets::IntervalToObjectIdSet::nth_index<1>::type::iterator it= m_valuesOids.get<1>().find(oid->getValueAsString());
213  te::dt::AbstractData* interval = it->interval;
214  if(it != m_valuesOids.get<1>().end())
215  return interval;
216  else
217  return NULL;
218 }
219 
220 void te::qt::widgets::Histogram::adjustOids(te::dt::AbstractData* interval, std::vector<te::da::ObjectId*> valuesOIds)
221 {
222  for(size_t i = 0; i < valuesOIds.size(); ++i)
223  {
224  m_valuesOids.insert(te::qt::widgets::IntervalToObjectId(interval, valuesOIds.at(i)));
225  }
226 }
~Histogram()
Destructor.
Definition: Histogram.cpp:37
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:120
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:57
void clear()
A function used to clear the contents of the histogram, deleting the pointers contained by the boost ...
Definition: Histogram.cpp:146
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:86
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:95
void setInterval(double new_Interval)
It sets the histogram's interval.
Definition: Histogram.cpp:110
void setValues(std::map< te::dt::AbstractData *, unsigned int > values)
It sets the histogram's values.
Definition: Histogram.cpp:73
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:62
double m_minValue
Histogram's minimum numeric value.
Definition: Histogram.h:252
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:220
void setMinValue(double new_minValue)
It sets the histogram's minimum value.
Definition: Histogram.cpp:100
double m_interval
Histogram's numeric interval.
Definition: Histogram.h:253
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:115
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:125
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:52
double & getInterval()
It returns the histogram's interval. Will be invalid if the histogram was created based on string int...
Definition: Histogram.cpp:105
int & getType()
It returns the histogram's type.
Definition: Histogram.cpp:42
void setType(int new_type)
It sets the histogram's type.
Definition: Histogram.cpp:47
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:165