CurveData.cpp
Go to the documentation of this file.
1 /******************************************************************************
2  * Copyright (C) 2015 by Ralf Kaestner *
3  * ralf.kaestner@gmail.com *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the Lesser GNU General Public License as published by*
7  * the Free Software Foundation; either version 3 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program 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  * Lesser GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the Lesser GNU General Public License *
16  * along with this program. If not, see <http://www.gnu.org/licenses/>. *
17  ******************************************************************************/
18 
20 
21 namespace rqt_multiplot {
22 
23 /*****************************************************************************/
24 /* Constructors and Destructor */
25 /*****************************************************************************/
26 
28 }
29 
31 }
32 
33 /*****************************************************************************/
34 /* Accessors */
35 /*****************************************************************************/
36 
37 double CurveData::getValue(size_t index, CurveConfig::Axis axis) const {
38  if (axis == CurveConfig::X)
39  return getPoint(index).x();
40  else if (axis == CurveConfig::Y)
41  return getPoint(index).y();
42 
43  return std::numeric_limits<double>::quiet_NaN();
44 }
45 
46 QVector<size_t> CurveData::getPointsInDistance(double x, double maxDistance)
47  const {
48  QVector<size_t> indexes;
49 
50  if (!isEmpty()) {
51  for (size_t index = 0; index < getNumPoints(); ++index) {
52  double distance = fabs(x-getPoint(index).x());
53 
54  if (distance <= maxDistance)
55  indexes.append(index);
56  }
57  }
58 
59  return indexes;
60 }
61 
62 QPair<double, double> CurveData::getAxisBounds(CurveConfig::Axis axis) const {
63  BoundingRectangle bounds = getBounds();
64 
65  if (axis == CurveConfig::X)
66  return QPair<double, double>(bounds.getMinimum().x(),
67  bounds.getMaximum().x());
68  else if (axis == CurveConfig::Y)
69  return QPair<double, double>(bounds.getMinimum().y(),
70  bounds.getMaximum().y());
71 
72  return QPair<double, double>();
73 }
74 
75 bool CurveData::isEmpty() const {
76  return !getNumPoints();
77 }
78 
79 /*****************************************************************************/
80 /* Methods */
81 /*****************************************************************************/
82 
83 size_t CurveData::size() const {
84  return getNumPoints();
85 }
86 
87 QPointF CurveData::sample(size_t i) const {
88  return getPoint(i);
89 }
90 
91 QRectF CurveData::boundingRect() const {
92  return getBounds().getRectangle();
93 }
94 
95 void CurveData::appendPoint(double x, double y) {
96  appendPoint(QPointF(x, y));
97 }
98 
99 void CurveData::writeFormatted(QStringList& formattedX, QStringList&
100  formattedY) const {
101  formattedX.clear();
102  formattedY.clear();
103 
104  for (size_t index = 0; index < getNumPoints(); ++index) {
105  QPointF point = getPoint(index);
106 
107  formattedX.append(QString::number(point.x(), 'g', 20));
108  formattedY.append(QString::number(point.y(), 'g', 20));
109  }
110 }
111 
112 }
QPointF sample(size_t i) const
Definition: CurveData.cpp:87
size_t size() const
Definition: CurveData.cpp:83
virtual void appendPoint(const QPointF &point)=0
virtual QVector< size_t > getPointsInDistance(double x, double maxDistance) const
Definition: CurveData.cpp:46
QRectF boundingRect() const
Definition: CurveData.cpp:91
bool isEmpty() const
Definition: CurveData.cpp:75
virtual BoundingRectangle getBounds() const =0
QPair< double, double > getAxisBounds(CurveConfig::Axis axis) const
Definition: CurveData.cpp:62
virtual QPointF getPoint(size_t index) const =0
virtual size_t getNumPoints() const =0
void writeFormatted(QStringList &formattedX, QStringList &formattedY) const
Definition: CurveData.cpp:99
double getValue(size_t index, CurveConfig::Axis axis) const
Definition: CurveData.cpp:37


rqt_multiplot
Author(s): Ralf Kaestner
autogenerated on Wed Jul 10 2019 03:49:44