dRonin  adbada4
dRonin GCS
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Groups Pages
plotdata.cpp
Go to the documentation of this file.
1 
13 /*
14  * This program is free software; you can redistribute it and/or modify
15  * it under the terms of the GNU General Public License as published by
16  * the Free Software Foundation; either version 3 of the License, or
17  * (at your option) any later version.
18  *
19  * This program is distributed in the hope that it will be useful, but
20  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
21  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  * for more details.
23  *
24  * You should have received a copy of the GNU General Public License along
25  * with this program; if not, see <http://www.gnu.org/licenses/>
26  */
27 
30 
31 #include "scopes2d/plotdata2d.h"
32 #include "scopes3d/plotdata3d.h"
33 
34 #include <math.h>
35 #include <QDebug>
36 
42 Plot2dData::Plot2dData(QString p_uavObject, QString p_uavFieldName)
43  : yDataHistory(nullptr)
44  , dataUpdated(false)
45 {
46  uavObjectName = p_uavObject;
47 
48  if (p_uavFieldName.contains(
49  "-")) // For fields with multiple indices, '-' followed by an index indicates which one
50  {
51  QStringList fieldSubfield = p_uavFieldName.split("-", QString::SkipEmptyParts);
52  uavFieldName = fieldSubfield.at(0);
53  uavSubFieldName = fieldSubfield.at(1);
54  haveSubField = true;
55  } else {
56  uavFieldName = p_uavFieldName;
57  haveSubField = false;
58  }
59 
60  xData = new QVector<double>();
61  yData = new QVector<double>();
62  yDataHistory = new QVector<double>();
63 
64  scalePower = 0;
65  meanSamples = 1;
66  meanSum = 0.0f;
67  correctionSum = 0.0f;
68  correctionCount = 0;
69  yMinimum = 0;
70  yMaximum = 120;
71 
72  m_xWindowSize = 0;
73 }
74 
80 Plot3dData::Plot3dData(QString p_uavObject, QString p_uavFieldName)
81  : dataUpdated(false)
82 {
83  uavObjectName = p_uavObject;
84 
85  if (p_uavFieldName.contains(
86  "-")) // For fields with multiple indices, '-' followed by an index indicates which one
87  {
88  QStringList fieldSubfield = p_uavFieldName.split("-", QString::SkipEmptyParts);
89  uavFieldName = fieldSubfield.at(0);
90  uavSubFieldName = fieldSubfield.at(1);
91  haveSubField = true;
92  } else {
93  uavFieldName = p_uavFieldName;
94  haveSubField = false;
95  }
96 
97  xData = new QVector<double>();
98  yData = new QVector<double>();
99  zData = new QVector<double>();
100  zDataHistory = new QVector<double>();
101  timeDataHistory = new QVector<double>();
102 
103  scalePower = 0;
104  meanSamples = 1;
105  meanSum = 0.0f;
106  correctionSum = 0.0f;
107  correctionCount = 0;
108  xMinimum = 0;
109  xMaximum = 16;
110  yMinimum = 0;
111  yMaximum = 60;
112  zMinimum = 0;
113  zMaximum = 100;
114 }
115 
117 {
118  if (xData != NULL)
119  delete xData;
120  if (yData != NULL)
121  delete yData;
122  if (yDataHistory != NULL)
123  delete yDataHistory;
124 }
125 
127 {
128  if (xData != NULL)
129  delete xData;
130  if (yData != NULL)
131  delete yData;
132  if (zData != NULL)
133  delete zData;
134  if (zDataHistory != NULL)
135  delete zDataHistory;
136  if (timeDataHistory != NULL)
137  delete timeDataHistory;
138 }
139 
148 double PlotData::valueAsDouble(UAVObject *obj, UAVObjectField *field, bool haveSubField,
149  QString uavSubFieldName)
150 {
151  Q_UNUSED(obj);
152  QVariant value;
153 
154  if (haveSubField) {
155  int indexOfSubField = field->getElementNames().indexOf(
156  QRegExp(uavSubFieldName, Qt::CaseSensitive, QRegExp::FixedString));
157  value = field->getValue(indexOfSubField);
158  } else
159  value = field->getValue();
160 
161  return value.toDouble();
162 }
double zMaximum
Definition: plotdata3d.h:67
unsigned int meanSamples
Definition: plotdata.h:105
double zMinimum
Definition: plotdata3d.h:66
QVector< double > * xData
Definition: plotdata.h:90
QVector< double > * yDataHistory
Definition: plotdata2d.h:47
QVector< double > * timeDataHistory
Definition: plotdata3d.h:49
double correctionSum
Definition: plotdata.h:109
QString uavFieldName
Definition: plotdata.h:100
QVariant getValue(int index=0) const
double meanSum
Definition: plotdata.h:107
int correctionCount
Definition: plotdata.h:110
QVector< double > * zData
Definition: plotdata3d.h:47
QVector< double > * zDataHistory
Definition: plotdata3d.h:48
QVector< double > * yData
Definition: plotdata.h:91
double yMinimum
Definition: plotdata.h:96
double xMinimum
Definition: plotdata.h:94
double yMaximum
Definition: plotdata.h:97
QString uavSubFieldName
Definition: plotdata.h:101
int scalePower
Definition: plotdata.h:104
Plot3dData(QString uavObject, QString uavField)
Plot3dData::Plot3dData Default 3d constructor.
Definition: plotdata.cpp:80
QStringList getElementNames() const
double xMaximum
Definition: plotdata.h:95
bool haveSubField
Definition: plotdata.h:102
Plot2dData(QString uavObject, QString uavField)
Plot2dData::Plot2dData Default 2d constructor.
Definition: plotdata.cpp:42
double valueAsDouble(UAVObject *obj, UAVObjectField *field, bool haveSubField, QString uavSubFieldName)
valueAsDouble Fetch the value from the UAVO and return it as a double
Definition: plotdata.cpp:148
QString uavObjectName
Definition: plotdata.h:99
double m_xWindowSize
Definition: plotdata.h:93