Blame view

src/ParamOutputImpl/Plot/ParameterData.hh 5.28 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
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
/*
 * 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);

private:

	/**
	 * @brief Values container
	 */
	std::vector<double> _values;
};

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

public:

	ParameterData();

	virtual ~ParameterData();

	/**
	 * @brief Adds a value by time to parameter
	 */
	void addValue(double time_, double value_, double sampling, double gapSize,
			bool &gapDetected, AMDA::Common::ParameterIndexComponent& index_);

	/**
	 * @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) {
		return _values[componentToValuesIndex(index_)].getValues(from_);
	}

	/**
	 * @brief
	 */
	double* getIntervalValues(double startTime, double stopTime, AMDA::Common::ParameterIndexComponent index_,
			int& startIndex, int& nbData)
	{
		nbData = 0;

		if (stopTime <= startTime)
			return NULL;

		startIndex = indexOf(startTime);

		int indexOfStopTime = indexOf(stopTime);
		int lastIndex;

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

		if (startIndex >= lastIndex)
			return NULL;

		nbData = lastIndex - startIndex + 1;

		return getValues(index_, startIndex);
	}

	/**
	 * @brief Returns minimum value of component.
	 */
	double getMin(AMDA::Common::ParameterIndexComponent index_ = AMDA::Common::ParameterIndexComponent(-1,-1)) {
		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)) {
		return _values[componentToValuesIndex(index_)]._minStrictPos;
	}

	/**
	 * @brief Returns maximum value of component.
	 */
	double getMax(AMDA::Common::ParameterIndexComponent index_ = AMDA::Common::ParameterIndexComponent(-1,-1)) {
		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("")) {
		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;
	}

	/**
	 * 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:
	int componentToValuesIndex(AMDA::Common::ParameterIndexComponent index)
	{
		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;
};


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