Blame view

src/ParamOutputImpl/Plot/ParameterData.hh 6.14 KB
fbe3c2bb   Benjamin Renard   First commit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/*
 * ParameterData.hh
 *
 *  Created on: 10 déc. 2013
 *      Author: CS
 */

#ifndef PARAMETERDATA_HH_
#define PARAMETERDATA_HH_

#include <vector>
#include <map>
#include <ostream>
#include <string>
#include <cmath>

#include "ParameterIndexesTool.hh"

namespace plot {

/**
 * @brief Structure that holds a parameter component values.
 */
class ComponentParameterData {
public:

	ComponentParameterData();

	virtual ~ComponentParameterData();

	/**
	 * @brief Component min value.
	 */
	double _min;

	/**
	 * @brief Component min strictly positive value (use to determine range of a logarithmic axis).
	 */
	double _minStrictPos;

	/**
	 * @brief Component max value.
	 */
	double _max;

	/**
	 * @brief Adds a value and updates min and max values.
	 */
	void addValue(double value_);

	/**
	 * @brief Returns a pointer to the first component value at
	 * given index (default is 0).
	 */
	double* getValues(int index_ = 0) {
		return &_values[index_];
	}

	/**
	 * Gets number of parameter values.
	 */
	size_t getNumberOfData(){
		return _values.size();
	}

	/*
	 * @brief
	 */
	void preAllocate(int nbData);

d57f00dc   Benjamin Renard   Draw NO DATA
71
72
73
74
	bool noData() {
		return _noData;
	}

fbe3c2bb   Benjamin Renard   First commit
75
76
77
78
79
80
private:

	/**
	 * @brief Values container
	 */
	std::vector<double> _values;
d57f00dc   Benjamin Renard   Draw NO DATA
81
82
83
84
85

	/**
 	 * @brief Flag used to know if the component have data
 	 */
	bool _noData;
fbe3c2bb   Benjamin Renard   First commit
86
87
88
89
90
91
92
93
94
95
96
97
98
99
};

/**
 * @brief Structure that holds parameter values by component
 */
class ParameterData {

public:

	ParameterData();

	virtual ~ParameterData();

	/**
cb9423a7   Benjamin Renard   Fix data gap dete...
100
101
102
103
104
105
         * @brief Add a new time record to parameter
         */
	void addTime(double time, double sampling, bool &gapDetected);

	/**
	 * @brief Add a component value
fbe3c2bb   Benjamin Renard   First commit
106
	 */
cb9423a7   Benjamin Renard   Fix data gap dete...
107
	void addValue(double value_, AMDA::Common::ParameterIndexComponent& index_, bool gapDetected);
fbe3c2bb   Benjamin Renard   First commit
108
109
110
111
112
113

	/**
	 * @brief Returns a pointer to the given component value
	 * (index_) since from_ index.
	 */
	double* getValues(AMDA::Common::ParameterIndexComponent index_ = AMDA::Common::ParameterIndexComponent(-1,-1), int from_ = 0) {
a6490f4d   Benjamin Renard   Do not throw an e...
114
115
		if (_values.empty())
			return NULL;
fbe3c2bb   Benjamin Renard   First commit
116
117
118
119
		return _values[componentToValuesIndex(index_)].getValues(from_);
	}

	/**
d57f00dc   Benjamin Renard   Draw NO DATA
120
121
122
123
124
125
126
127
128
 	 * @bried Return true when no data
 	 */
	bool noData(AMDA::Common::ParameterIndexComponent index_ = AMDA::Common::ParameterIndexComponent(-1,-1)) {
		if (_values.empty())
			return true;
		return _values[componentToValuesIndex(index_)].noData();
	}

	/**
fbe3c2bb   Benjamin Renard   First commit
129
130
	 * @brief
	 */
8c71f50a   Benjamin Renard   Improve execution...
131
	void getIntervalBounds(double startTime, double stopTime, int& startIndex, int& nbData)
fbe3c2bb   Benjamin Renard   First commit
132
133
134
135
	{
		nbData = 0;

		if (stopTime <= startTime)
8c71f50a   Benjamin Renard   Improve execution...
136
			return;
fbe3c2bb   Benjamin Renard   First commit
137

8c71f50a   Benjamin Renard   Improve execution...
138
 		startIndex = indexOf(startTime);
fbe3c2bb   Benjamin Renard   First commit
139

c7988036   Benjamin Renard   Fix
140
141
142
		if (startIndex < 0)
			return ;

fbe3c2bb   Benjamin Renard   First commit
143
144
145
146
147
148
149
150
151
152
153
154
		int indexOfStopTime = indexOf(stopTime);
		int lastIndex;

		if (indexOfStopTime == -1)
			lastIndex = getSize() - 1;
		else
		{
			lastIndex  = indexOfStopTime;
			if (_dates[lastIndex] > stopTime)
				lastIndex -= 1;
		}

e062d6ef   Benjamin Renard   Fix axes range wh...
155
		if (startIndex > lastIndex)
8c71f50a   Benjamin Renard   Improve execution...
156
			return;
fbe3c2bb   Benjamin Renard   First commit
157
158

		nbData = lastIndex - startIndex + 1;
fbe3c2bb   Benjamin Renard   First commit
159
160
161
162
163
164
	}

	/**
	 * @brief Returns minimum value of component.
	 */
	double getMin(AMDA::Common::ParameterIndexComponent index_ = AMDA::Common::ParameterIndexComponent(-1,-1)) {
a6490f4d   Benjamin Renard   Do not throw an e...
165
166
		if (_values.empty())
			return nan("");
fbe3c2bb   Benjamin Renard   First commit
167
168
169
170
171
172
173
		return _values[componentToValuesIndex(index_)]._min;
	}

	/**
	 * @brief Returns min strictly positive value (use to determine range of a logarithmic axis)
	 */
	double getMinStrictPos(AMDA::Common::ParameterIndexComponent index_ = AMDA::Common::ParameterIndexComponent(-1,-1)) {
a6490f4d   Benjamin Renard   Do not throw an e...
174
175
		if (_values.empty())
			return nan("");
fbe3c2bb   Benjamin Renard   First commit
176
177
178
179
180
181
182
		return _values[componentToValuesIndex(index_)]._minStrictPos;
	}

	/**
	 * @brief Returns maximum value of component.
	 */
	double getMax(AMDA::Common::ParameterIndexComponent index_ = AMDA::Common::ParameterIndexComponent(-1,-1)) {
a6490f4d   Benjamin Renard   Do not throw an e...
183
184
		if (_values.empty())
			return nan("");
fbe3c2bb   Benjamin Renard   First commit
185
186
187
188
189
190
191
192
193
194
195
196
		return _values[componentToValuesIndex(index_)]._max;
	}

	int getSize() {
		return _dates.size();
	}

	/**
	 * @brief Returns a pointer to the first time equals or
	 * just after a given time
	 */
	double* getTimes(double time_ = nan("")) {
a6490f4d   Benjamin Renard   Do not throw an e...
197
198
		if (_dates.empty())
			return NULL;
fbe3c2bb   Benjamin Renard   First commit
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
		return &_dates[indexOf(time_)];
	}

	/*
	 * @brief Get dim1 size
	 */
	int getDim1Size()
	{
		return _dim1Size;
	}

	/*
	 * @brief Set dim1 size
	 */
	void setDim1Size(int dim1Size)
	{
		_dim1Size = dim1Size;
	}

	/*
	 * @brief Get dim2 size
	 */
	int getDim2Size()
	{
		return _dim2Size;
	}

	/*
	 * @brief Set dim2 size
	 */
	void setDim2Size(int dim2Size)
	{
		_dim2Size = dim2Size;
	}

225ac17f   Benjamin Renard   Fix tickmarks plot
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
	/*
	 * @brief Get param gap size (in seconds)
	 */
	double getParamGapSize()
	{
		return _paramGapSize;
	}

	/*
	 * @brief Set param gap size
	 */
	void setParamGapSize(double gapSize)
	{
		_paramGapSize = gapSize;
	}

fbe3c2bb   Benjamin Renard   First commit
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
	/**
	 * Gets the index of the given time (or just after) in time array,
	 * returns -1 if not found
	 */
	int indexOf(double time_);

	/**
	 * @brief Computes an interpolated value at a given time
	 */
	double getInterpolatedValue (double atTime = nan(""), AMDA::Common::ParameterIndexComponent index = AMDA::Common::ParameterIndexComponent(-1,-1));

	/*
	 * @brief Reset ParamData
	 */
	void reset()
	{
		_values.clear();
		_dates.clear();
		_minTime = nan("");
		_maxTime = nan("");
	}

	/*
	 * @brief
	 */
	void preAllocate(int nbData);

	/**
	 * Dump properties, for TU
	 */
	void dump(std::ostream&, std::string& prefix_);

	/**
	 * @brief List of component indexes, empty if scalar parameter
	 */
	std::vector<AMDA::Common::ParameterIndexComponent> _indexes;

	/**
	 * @brief Min value time
	 */
	double _minTime;

	/**
	 * @brief Max value time
	 */
	double _maxTime;

protected:
8c71f50a   Benjamin Renard   Improve execution...
298
	int componentToValuesIndex(AMDA::Common::ParameterIndexComponent& index)
fbe3c2bb   Benjamin Renard   First commit
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
	{
		if ((index.getDim1Index() == -1) && (index.getDim2Index() == -1))
			return 0;
		if (index.getDim2Index() == -1)
			return index.getDim1Index();
		if (index.getDim1Index() == -1)
			return index.getDim2Index();
		return index.getDim1Index() * _dim2Size + index.getDim2Index();
	}

private:

	/**
	 * @brief Values container, by component
	 */
	std::vector<ComponentParameterData> _values;

	/**
	 * @brief Dates container, synchronized with values container
	 */
	std::vector<double> _dates;

	/*
	 * @brief Dim 1 Size
	 */
	int _dim1Size;

	/*
	 * @brief Dim 2 Size
	 */
	int _dim2Size;
225ac17f   Benjamin Renard   Fix tickmarks plot
330
331
332
333
334

	/*
	 * @brief Param gap size (in seconds)
	 */
	double _paramGapSize;
fbe3c2bb   Benjamin Renard   First commit
335
336
337
338
339
};


} /* namespace plot */
#endif /* PARAMETERDATA_HH_ */