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) 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 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 
51 }
52 
54 {
55  std::vector<double>::const_iterator itx = m_xValues.begin();
56  std::vector<double>::const_iterator ity = m_yValues.begin();
57  while(itx!=m_xValues.end())
58  {
59  if(*itx < m_minX)
60  m_minX = *itx;
61  if(*itx > m_maxX)
62  m_maxX = *itx;
63  ++itx;
64  }
65 
66  while(ity!=m_yValues.end())
67  {
68  if(*ity < m_minY)
69  m_minY = *ity;
70  if(*ity > m_maxY)
71  m_maxY = *ity;
72  ++ity;
73  }
74 }
75 
77 {
78  return m_xValues.size();
79 }
80 
82 {
83  return m_yValues.size();
84 }
85 
86 double te::qt::widgets::Scatter::getX(unsigned int idx)
87 {
88  return m_xValues[idx];
89 }
90 
92 {
93  return &m_xValues[0];
94 }
95 
96 double te::qt::widgets::Scatter::getY(unsigned int idx)
97 {
98  return m_yValues[idx];
99 }
100 
102 {
103  return &m_yValues[0];
104 }
105 
107 {
108  return m_minX;
109 }
110 
112 {
113  return m_maxX;
114 }
115 
117 {
118  return m_minY;
119 }
120 
122 {
123  return m_maxY;
124 }
125 
126 void te::qt::widgets::Scatter::setMinX(double& new_minX)
127 {
128  m_minX = new_minX;
129 }
130 
131 void te::qt::widgets::Scatter::setMaxX(double& new_maxX)
132 {
133  m_maxX = new_maxX;
134 }
135 
136 void te::qt::widgets::Scatter::setMinY(double& new_minY)
137 {
138  m_minY = new_minY;
139 }
140 
141 void te::qt::widgets::Scatter::setMaxY(double& new_maxY)
142 {
143  m_maxY = new_maxY;
144 }
145 
146 void te::qt::widgets::Scatter::addX(double& xValue)
147 {
148  m_xValues.push_back(xValue);
149 }
150 
151 void te::qt::widgets::Scatter::addY(double& yValue)
152 {
153  m_yValues.push_back(yValue);
154 }
155 
156 void te::qt::widgets::Scatter::addData(double& xValue, double& yValue, te::da::ObjectId* oid)
157 {
158  m_xValues.push_back(xValue);
159  m_yValues.push_back(yValue);
160  m_valuesOids.insert(te::qt::widgets::PointToObjectId(xValue, yValue, oid));
161 }
162 
163 te::da::ObjectIdSet* te::qt::widgets::Scatter::find(double& xValue, double& yValue)
164 {
165  typedef te::qt::widgets::PointToObjectIdSet::nth_index<0>::type::iterator itPointToObjectIdSet;
166  PointToObjectId aux(xValue, yValue, 0);
167 
168  std::pair<itPointToObjectIdSet, itPointToObjectIdSet> res = m_valuesOids.equal_range(aux);
169  itPointToObjectIdSet it0 = res.first; //begin
170  itPointToObjectIdSet it1 = res.second; //end
171 
173 
174  while(it0 != it1)
175  {
176  if(it0->y == yValue)
177  {
178  te::da::ObjectId* oid = new te::da::ObjectId();
179 
180  for(boost::ptr_vector<te::dt::AbstractData>::const_iterator it = it0->oid->getValue().begin(); it != it0->oid->getValue().end(); ++it)
181  {
182  oid->addValue((it)->clone());
183  }
184 
185  oids->add(oid);
186  }
187 
188  ++it0;
189  }
190  return oids;
191 }
192 
193 te::da::ObjectIdSet* te::qt::widgets::Scatter::find(std::vector<QPointF> selectedPoints)
194 {
195  typedef te::qt::widgets::PointToObjectIdSet::nth_index<0>::type::iterator itPointToObjectIdSet;
196  itPointToObjectIdSet it0, it1;
197  std::pair<itPointToObjectIdSet, itPointToObjectIdSet> res;
199 
200  //Checking all the selected points:
201  for(size_t i = 0; i < selectedPoints.size(); ++i)
202  {
203  double x = selectedPoints.at(i).x();
204  double y = selectedPoints.at(i).y();
205  PointToObjectId aux(x, y, 0);
206  res = m_valuesOids.equal_range(aux);
207  it0 = res.first;
208  it1 = res.second;
209 
210  while(it0 != it1)
211  {
212  if(it0->y == y)
213  {
214  te::da::ObjectId* oid = new te::da::ObjectId();
215 
216  for(boost::ptr_vector<te::dt::AbstractData>::const_iterator it = it0->oid->getValue().begin(); it != it0->oid->getValue().end(); ++it)
217  {
218  oid->addValue((it)->clone());
219  }
220 
221  oids->add(oid);
222  }
223 
224  ++it0;
225  }
226  }
227 
228  return oids;
229 }
230 
231 const std::pair<double, double> te::qt::widgets::Scatter::find(const te::da::ObjectId* oid)
232 {
233  te::qt::widgets::PointToObjectIdSet::nth_index<1>::type::iterator it= m_valuesOids.get<1>().find(oid->getValueAsString());
234  return std::make_pair(it->x, it->y);
235 }
double getMaxY()
It returns the maximum value of the Y axis.
Definition: Scatter.cpp:121
void addY(double &yValue)
It adds a new value to the vector containing the Y axis values.
Definition: Scatter.cpp:151
double getMaxX()
It returns the maximum value of the X axis.
Definition: Scatter.cpp:111
double getMinY()
It returns the minimum value of the Y axis.
Definition: Scatter.cpp:116
double * getX()
It returns a pointer to the first value of the scatter X axis.
Definition: Scatter.cpp:91
void setMinX(double &new_minX)
It sets the minimum value of the X axis.
Definition: Scatter.cpp:126
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:163
void addValue(te::dt::AbstractData *data)
It adds a property value to uniquely identify a data set element.
Definition: ObjectId.cpp:61
double * getY()
It returns a pointer to the first value of the scatter Y axis.
Definition: Scatter.cpp:101
void setMaxX(double &new_maxX)
It sets the maximum value of the X axis.
Definition: Scatter.cpp:131
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
void addX(double &xValue)
It adds a new value to the vector containing the X axis values.
Definition: Scatter.cpp:146
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:76
double getMinX()
It returns the minimum value of the X axis.
Definition: Scatter.cpp:106
A class to represent a scatter.
void calculateMinMaxValues()
Calculates the minimum and maximum values for both the X and Y axis.
Definition: Scatter.cpp:53
std::size_t sizeY()
It returns the size of the scatter.
Definition: Scatter.cpp:81
void add(ObjectId *oid)
It adds an object id to this object id set.
Definition: ObjectIdSet.cpp:71
void setMaxY(double &maxY)
It sets the maximum value of the Y axis.
Definition: Scatter.cpp:141
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:156
void setMinY(double &new_minY)
It sets the minimum value of the Y axis.
Definition: Scatter.cpp:136
Scatter()
Constructor.
Definition: Scatter.cpp:40