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) 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 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  HistogramValues::iterator it = m_values.begin();
39  while(it != m_values.end())
40  {
41  delete it->first;
42  ++it;
43  }
44 
45  te::qt::widgets::IntervalToObjectIdSet::iterator it2= m_valuesOids.begin();
46  while(it2 != m_valuesOids.end())
47  {
48  delete it2->oid;
49  ++it2;
50  }
51 }
52 
54 {
55  return m_histogramType;
56 }
57 
59 {
60  m_histogramType = new_type;
61 }
62 
63 std::map<double, unsigned int> te::qt::widgets::Histogram::getValues()
64 {
65  std::map<double, unsigned int> res;
66 
67  //Casting every interval into a double value
68  for(HistogramValues::iterator it = m_values.begin(); it != m_values.end(); ++it)
69  res.insert(std::make_pair(static_cast<te::dt::Double*>(it->first)->getValue(), it->second));
70 
71  return res;
72 }
73 
74 std::map<std::string, unsigned int> te::qt::widgets::Histogram::getStringValues()
75 {
76  std::map<std::string, unsigned int> res;
77  //Casting every interval into a string value
78  for(HistogramValues::iterator it = m_values.begin(); it != m_values.end(); ++it)
79  res.insert(std::make_pair(it->first->toString(), it->second));
80  return res;
81 }
82 
84 {
85  return m_minValue;
86 }
87 
88 void te::qt::widgets::Histogram::setMinValue(double new_minValue)
89 {
90  m_minValue = new_minValue;
91 }
92 
94 {
95  return m_interval;
96 }
97 
98 void te::qt::widgets::Histogram::setInterval(double new_Interval)
99 {
100  m_interval = new_Interval;
101 }
102 
104 {
105  return m_StringIntervals;
106 }
107 
108 void te::qt::widgets::Histogram::setStringInterval( std::set <std::string> new_Interval)
109 {
110  m_StringIntervals = new_Interval;
111 }
112 
113 void te::qt::widgets::Histogram::insert(std::pair<te::dt::AbstractData*, unsigned int> new_value, std::vector<te::da::ObjectId*> valuesOIds)
114 {
115  m_values.insert(new_value);
116  adjustOids(new_value.first, valuesOIds);
117 }
118 
119 void te::qt::widgets::Histogram::insert(std::pair<te::dt::AbstractData*, unsigned int> new_value)
120 {
121  m_values.insert(new_value);
122 }
123 
124 void te::qt::widgets::Histogram::insert(te::dt::AbstractData* interval, unsigned int frequency, std::vector<te::da::ObjectId*> valuesOIds)
125 {
126  insert(std::make_pair(interval, frequency), valuesOIds);
127 }
128 
129 void te::qt::widgets::Histogram::insert(te::dt::AbstractData* interval, unsigned int frequency)
130 {
131  insert(std::make_pair(interval, frequency));
132 }
133 
135 {
136  typedef te::qt::widgets::IntervalToObjectIdSet::nth_index<0>::type::iterator itIntervalToObjectIdSet;
137  IntervalToObjectId aux(interval, 0);
138 
139  std::pair<itIntervalToObjectIdSet, itIntervalToObjectIdSet> res = m_valuesOids.equal_range(aux);
140  itIntervalToObjectIdSet it0 = res.first;
141  itIntervalToObjectIdSet it1 = res.second;
142 
144 
145  while(it0 != it1)
146  {
147  te::da::ObjectId* oid = new te::da::ObjectId();
148 
149  for(boost::ptr_vector<te::dt::AbstractData>::const_iterator it = it0->oid->getValue().begin(); it != it0->oid->getValue().end(); ++it)
150  {
151  oid->addValue((it)->clone());
152  }
153 
154  oids->add(oid);
155  ++it0;
156  }
157  return oids;
158 }
159 
160 
161 te::da::ObjectIdSet* te::qt::widgets::Histogram::find(std::vector<te::dt::AbstractData*> intervals)
162 {
163  typedef te::qt::widgets::IntervalToObjectIdSet::nth_index<0>::type::iterator itIntervalToObjectIdSet;
165 
166  for(size_t i = 0; i < intervals.size(); ++i)
167  {
168  IntervalToObjectId aux(intervals[i], 0);
169 
170  std::pair<itIntervalToObjectIdSet, itIntervalToObjectIdSet> res = m_valuesOids.equal_range(aux);
171  itIntervalToObjectIdSet it0 = res.first;
172  itIntervalToObjectIdSet it1 = res.second;
173 
174  while(it0 != it1)
175  {
176  te::da::ObjectId* oid = new te::da::ObjectId();
177 
178  for(boost::ptr_vector<te::dt::AbstractData>::const_iterator it = it0->oid->getValue().begin(); it != it0->oid->getValue().end(); ++it)
179  {
180  oid->addValue((it)->clone());
181  }
182 
183  oids->add(oid);
184  ++it0;
185  }
186  delete intervals[i];
187  }
188 
189  return oids;
190 }
191 
193 {
194  te::qt::widgets::IntervalToObjectIdSet::nth_index<1>::type::iterator it= m_valuesOids.get<1>().find(oid->getValueAsString());
195  te::dt::AbstractData* interval = it->interval;
196  return interval;
197 }
198 
199 void te::qt::widgets::Histogram::adjustOids(te::dt::AbstractData* interval, std::vector<te::da::ObjectId*> valuesOIds)
200 {
201  for(size_t i = 0; i < valuesOIds.size(); ++i)
202  {
203  m_valuesOids.insert(te::qt::widgets::IntervalToObjectId(interval, valuesOIds.at(i)));
204  }
205 }
~Histogram()
Destructor.
Definition: Histogram.cpp:36
void addValue(te::dt::AbstractData *data)
It adds a property value to uniquely identify a data set element.
Definition: ObjectId.cpp:61
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:108
This class represents a set of unique ids created in the same context. i.e. from the same data set...
Definition: ObjectIdSet.h:53
This class represents an unique id for a data set element.
Definition: ObjectId.h:47
mydialect insert("+", new te::da::BinaryOpEncoder("+"))
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:74
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:83
void setInterval(double new_Interval)
It sets the histogram's interval.
Definition: Histogram.cpp:98
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:63
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:199
void setMinValue(double new_minValue)
It sets the histogram's minimum value.
Definition: Histogram.cpp:88
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:103
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:113
void add(ObjectId *oid)
It adds an object id to this object id set.
Definition: ObjectIdSet.cpp:71
double & getInterval()
It returns the histogram's interval. Will be invalid if the histogram was created based on string int...
Definition: Histogram.cpp:93
int & getType()
It returns the histogram's type.
Definition: Histogram.cpp:53
void setType(int new_type)
It sets the histogram's type.
Definition: Histogram.cpp:58
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:134