All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Scatter.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 Scatter.cpp
22 
23  \brief A class to represent a scatter.
24 */
25 
26 //Terralib
27 #include "Scatter.h"
28 #include "../../../dataaccess/dataset/ObjectIdSet.h"
29 
30 //STL
31 #include <limits>
32 
33 te::qt::widgets::Scatter::Scatter(const std::vector<double>& axisX, const std::vector<double>& axisY)
34  : m_xValues(axisX),
35  m_yValues(axisY)
36 {
38 }
39 
41  : m_minX(std::numeric_limits<double>::max()),
42  m_maxX(-std::numeric_limits<double>::max()),
43  m_minY(std::numeric_limits<double>::max()),
44  m_maxY(-std::numeric_limits<double>::max())
45 {
46 }
47 
49 {
50  te::qt::widgets::PointToObjectIdSet::iterator it= m_valuesOids.begin();
51  while(it != m_valuesOids.end())
52  {
53  delete it->oid;
54  ++it;
55  }
56  m_valuesOids.clear();
57 }
58 
60 {
61  std::vector<double>::const_iterator itx = m_xValues.begin();
62  std::vector<double>::const_iterator ity = m_yValues.begin();
63  while(itx!=m_xValues.end())
64  {
65  if(*itx < m_minX)
66  m_minX = *itx;
67  if(*itx > m_maxX)
68  m_maxX = *itx;
69  ++itx;
70  }
71 
72  while(ity!=m_yValues.end())
73  {
74  if(*ity < m_minY)
75  m_minY = *ity;
76  if(*ity > m_maxY)
77  m_maxY = *ity;
78  ++ity;
79  }
80 }
81 
83 {
84  return m_xValues.size();
85 }
86 
88 {
89  return m_yValues.size();
90 }
91 
93 {
94  return m_xValues;
95 }
96 
97 double te::qt::widgets::Scatter::getX(unsigned int idx)
98 {
99  return m_xValues[idx];
100 }
101 
103 {
104  return &m_xValues[0];
105 }
106 
108 {
109  return m_yValues;
110 }
111 
112 double te::qt::widgets::Scatter::getY(unsigned int idx)
113 {
114  return m_yValues[idx];
115 }
116 
118 {
119  return &m_yValues[0];
120 }
121 
123 {
124  return m_minX;
125 }
126 
128 {
129  return m_maxX;
130 }
131 
133 {
134  return m_minY;
135 }
136 
138 {
139  return m_maxY;
140 }
141 
142 void te::qt::widgets::Scatter::setXValues(std::vector<double> xValues)
143 {
144  m_xValues = xValues;
145 }
146 
147 void te::qt::widgets::Scatter::setMinX(double& new_minX)
148 {
149  m_minX = new_minX;
150 }
151 
152 void te::qt::widgets::Scatter::setMaxX(double& new_maxX)
153 {
154  m_maxX = new_maxX;
155 }
156 
157 void te::qt::widgets::Scatter::setYValues(std::vector<double> yValues)
158 {
159  m_yValues = yValues;
160 }
161 
162 void te::qt::widgets::Scatter::setMinY(double& new_minY)
163 {
164  m_minY = new_minY;
165 }
166 
167 void te::qt::widgets::Scatter::setMaxY(double& new_maxY)
168 {
169  m_maxY = new_maxY;
170 }
171 
172 void te::qt::widgets::Scatter::addX(double& xValue)
173 {
174  m_xValues.push_back(xValue);
175 }
176 
177 void te::qt::widgets::Scatter::addY(double& yValue)
178 {
179  m_yValues.push_back(yValue);
180 }
181 
182 void te::qt::widgets::Scatter::addData(double& xValue, double& yValue, te::da::ObjectId* oid)
183 {
184  m_xValues.push_back(xValue);
185  m_yValues.push_back(yValue);
186  m_valuesOids.insert(te::qt::widgets::PointToObjectId(xValue, yValue, oid));
187 }
188 
189 te::da::ObjectIdSet* te::qt::widgets::Scatter::find(double& xValue, double& yValue)
190 {
191  typedef te::qt::widgets::PointToObjectIdSet::nth_index<0>::type::iterator itPointToObjectIdSet;
192  PointToObjectId aux(xValue, yValue, 0);
193 
194  std::pair<itPointToObjectIdSet, itPointToObjectIdSet> res = m_valuesOids.equal_range(aux);
195  itPointToObjectIdSet it0 = res.first; //begin
196  itPointToObjectIdSet it1 = res.second; //end
197 
199 
200  while(it0 != it1)
201  {
202  if(it0->y == yValue)
203  {
204  te::da::ObjectId* oid = new te::da::ObjectId(*it0->oid);
205  oids->add(oid);
206  }
207 
208  ++it0;
209  }
210  return oids;
211 }
212 
213 te::da::ObjectIdSet* te::qt::widgets::Scatter::find(std::vector<QPointF> selectedPoints)
214 {
215  typedef te::qt::widgets::PointToObjectIdSet::nth_index<0>::type::iterator itPointToObjectIdSet;
216  itPointToObjectIdSet it0, it1;
217  std::pair<itPointToObjectIdSet, itPointToObjectIdSet> res;
219 
220  //Checking all the selected points:
221  for(size_t i = 0; i < selectedPoints.size(); ++i)
222  {
223  double x = selectedPoints.at(i).x();
224  double y = selectedPoints.at(i).y();
225  PointToObjectId aux(x, y, 0);
226  res = m_valuesOids.equal_range(aux);
227  it0 = res.first;
228  it1 = res.second;
229 
230  while(it0 != it1)
231  {
232  if(it0->y == y)
233  {
234  te::da::ObjectId* oid = new te::da::ObjectId(*it0->oid);
235  oids->add(oid);
236  }
237  ++it0;
238  }
239  }
240 
241  return oids;
242 }
243 
244 const std::pair<double, double> te::qt::widgets::Scatter::find(const te::da::ObjectId* oid)
245 {
246  te::qt::widgets::PointToObjectIdSet::nth_index<1>::type::iterator it= m_valuesOids.get<1>().find(oid->getValueAsString());
247  return std::make_pair(it->x, it->y);
248 }
std::vector< double > getYValues()
It returns the vector containing the values of the scatter Y axis.
Definition: Scatter.cpp:107
double getMaxY()
It returns the maximum value of the Y axis.
Definition: Scatter.cpp:137
void addY(double &yValue)
It adds a new value to the vector containing the Y axis values.
Definition: Scatter.cpp:177
double getMaxX()
It returns the maximum value of the X axis.
Definition: Scatter.cpp:127
double getMinY()
It returns the minimum value of the Y axis.
Definition: Scatter.cpp:132
double * getX()
It returns a pointer to the first value of the scatter X axis.
Definition: Scatter.cpp:102
void setMinX(double &new_minX)
It sets the minimum value of the X axis.
Definition: Scatter.cpp:147
te::da::ObjectIdSet * find(double &xValue, double &yValue)
It returns a pointer to an ObjectIdSet that contains all of the scatter's selected points...
Definition: Scatter.cpp:189
double * getY()
It returns a pointer to the first value of the scatter Y axis.
Definition: Scatter.cpp:117
void setYValues(std::vector< double > yValues)
It sets the values of the Y axis.
Definition: Scatter.cpp:157
void setMaxX(double &new_maxX)
It sets the maximum value of the X axis.
Definition: Scatter.cpp:152
std::vector< double > getXValues()
It returns the vector containing the values of the scatter X axis.
Definition: Scatter.cpp:92
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
void addX(double &xValue)
It adds a new value to the vector containing the X axis values.
Definition: Scatter.cpp:172
std::string getValueAsString() const
It gets the properties values used to uniquely identify a data set element as string.
Definition: ObjectId.cpp:51
~Scatter()
Destructor.
Definition: Scatter.cpp:48
std::size_t sizeX()
It returns the size of the scatter.
Definition: Scatter.cpp:82
double getMinX()
It returns the minimum value of the X axis.
Definition: Scatter.cpp:122
A class to represent a scatter.
void setXValues(std::vector< double > xValues)
It sets the values of the X axis.
Definition: Scatter.cpp:142
void calculateMinMaxValues()
Calculates the minimum and maximum values for both the X and Y axis.
Definition: Scatter.cpp:59
std::size_t sizeY()
It returns the size of the scatter.
Definition: Scatter.cpp:87
void add(ObjectId *oid)
It adds an object id to this object id set.
Definition: ObjectIdSet.cpp:83
void setMaxY(double &maxY)
It sets the maximum value of the Y axis.
Definition: Scatter.cpp:167
void addData(double &xValue, double &yValue, te::da::ObjectId *oid)
It adds the x and Y axis values to the scatter's vectors and the associeted objectId to the scatter's...
Definition: Scatter.cpp:182
void setMinY(double &new_minY)
It sets the minimum value of the Y axis.
Definition: Scatter.cpp:162
Scatter()
Constructor.
Definition: Scatter.cpp:40