Blame view

src/InternLib/Resampling.hh 30.5 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
/**
 * Resampling.hh
 *
 *  Created on: 31 oct. 2012
 *      Author: AKKA IS
 */

#ifndef Resampling_HH_
#define Resampling_HH_

#include <list>
#include "ParamData.hh"
#include "DataTypeMath.hh"
#include "VisitorOfParamData.hh"
#include "Operation.hh"

#include "TimeInterval.hh"

namespace AMDA {
namespace Parameters {

namespace Resampling {

ca31a786   Benjamin Renard   Fix other side ef...
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
class MarkerAbstract {
public:
	MarkerAbstract() : _startTime(0.), _stopTime(0.), _samplingTime(0.), _markerMinTime(0.), _markerMaxTime(0.), _targetTime(0.) {
	}

	virtual bool init(double pStartTime, double pStopTime, int /*currentTimeIntervalIndex*/, double pSamplingTime) {
		_startTime = pStartTime;
		_stopTime = pStopTime;
		_samplingTime = pSamplingTime;
		return true;
	}

	virtual bool nextTarget() = 0;

	double getTargetTime() {
		return _targetTime;
	}

	double getMarkerMinTime() {
		return _markerMinTime;
	}

	double getMarkerMaxTime() {
		return _markerMaxTime;
	}

	virtual bool isFinished() = 0;

protected:
	bool setTargetTime(double pTargetTime) {
		_targetTime = pTargetTime;
		_markerMinTime = _targetTime - _samplingTime / 2.;
		if (_markerMinTime < _startTime) {
			_markerMinTime = _startTime;
		}
		_markerMaxTime = _targetTime + _samplingTime / 2.;
		return !isFinished();
	}

	double _startTime;
	double _stopTime;
	double _samplingTime;
	double _markerMinTime;
        double _markerMaxTime;
	double _targetTime;
};

class MarkerRefParam: public MarkerAbstract {
public:
	MarkerRefParam() : MarkerAbstract(), _refParamDataPtr(NULL), _crtRefIndex(-1) {
	}

	void setRefParamData(ParamData* refParamDataPtr) {
		_refParamDataPtr = refParamDataPtr;
	}

	bool init(double pStartTime, double pStopTime, int currentTimeIntervalIndex, double pSamplingTime) {
		MarkerAbstract::init(pStartTime, pStopTime, currentTimeIntervalIndex, pSamplingTime);
		if (_refParamDataPtr == NULL) {
			return false;
		}
		if (_refParamDataPtr->getIndexInfo()._endTimeIntIndexList.empty() || (currentTimeIntervalIndex == 0)) {
			_crtRefIndex = 0;
		}
		else {
			std::list<unsigned int>::iterator it = _refParamDataPtr->getIndexInfo()._endTimeIntIndexList.begin();
			std::advance(it, currentTimeIntervalIndex-1);
			_crtRefIndex = *it;
		}
deefda79   Benjamin Renard   Addapt resampling...
93
		while (pStartTime > _refTimes[_crtRefIndex]) {
ca31a786   Benjamin Renard   Fix other side ef...
94
95
96
97
98
99
			++_crtRefIndex;
			if (_crtRefIndex >= (int)_refParamDataPtr->getDataNumber()) {
				_crtRefIndex = -1;
				return false;
			}
		}
deefda79   Benjamin Renard   Addapt resampling...
100
		return setTargetTime(_refTimes[_crtRefIndex]);
ca31a786   Benjamin Renard   Fix other side ef...
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
	}

	bool nextTarget() {
		if (_crtRefIndex < 0) {
			return false;
		}
		if (_refParamDataPtr == NULL) {
			_crtRefIndex = -1;
			return false;
		}
		++_crtRefIndex;
		if (_crtRefIndex >= (int)_refParamDataPtr->getDataNumber()) {
			_crtRefIndex = -1;
			return false;
		}
deefda79   Benjamin Renard   Addapt resampling...
116
		return setTargetTime(_refTimes[_crtRefIndex]);
ca31a786   Benjamin Renard   Fix other side ef...
117
118
119
120
121
122
	}

	bool isFinished() {
		return (_crtRefIndex == -1);
	}

deefda79   Benjamin Renard   Addapt resampling...
123
124
125
126
	void pushTime(double time) {
		_refTimes.push_back(time);
	}

ca31a786   Benjamin Renard   Fix other side ef...
127
128
129
130
private:
	ParamData* _refParamDataPtr;

	int _crtRefIndex;
deefda79   Benjamin Renard   Addapt resampling...
131
132

	std::vector<double> _refTimes;
ca31a786   Benjamin Renard   Fix other side ef...
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
};

class MarkerSampling: public MarkerAbstract {
public:
	MarkerSampling() : MarkerAbstract() {
	}

	bool init(double pStartTime, double pStopTime, int currentTimeIntervalIndex, double pSamplingTime) {
		MarkerAbstract::init(pStartTime, pStopTime, currentTimeIntervalIndex, pSamplingTime);
		return setTargetTime(pStartTime);
	}

	bool nextTarget() {
		return setTargetTime(getTargetTime() + _samplingTime);
	}

	bool isFinished() {
		return (_targetTime < _startTime || _targetTime > _stopTime);
	}
};


fbe3c2bb   Benjamin Renard   First commit
155
156
157
158
159
160
161
162
/**
 * Define type Resampling.
 */
class ResamplingAbstract: public Operation {
public:
	/**
	 * @brief constructor
	 */
ca31a786   Benjamin Renard   Fix other side ef...
163
164
	ResamplingAbstract(Process& pProcess, bool pUseNearestValue) :
			Operation(pProcess), _isNewInt(true), _useNearestValue(pUseNearestValue) {
fbe3c2bb   Benjamin Renard   First commit
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182

	}
	/**
	 * @brief destructor.
	 */
	virtual ~ResamplingAbstract() {
	}
	/**
	 * @brief compute static data
	 */
	virtual void init() = 0;

	/**
	 * @overload Operation::reset(double pStartTime, double pTimeInt)
	 * @brief reset static data to process another TimeInterval
	 */
	virtual void reset() {
		Operation::reset();
a6490f4d   Benjamin Renard   Do not throw an e...
183
		resetResampling();
fbe3c2bb   Benjamin Renard   First commit
184
185
186
187
188
189
190
191
		_isNewInt = true;
	}

	/*
	 * @brief return sampling value
	 */
	virtual double getSampling() = 0;

a6490f4d   Benjamin Renard   Do not throw an e...
192
193
194
195
196
	/*
	 * @brief reset resampling
	 */
	virtual void resetResampling() = 0;

deefda79   Benjamin Renard   Addapt resampling...
197
198
	virtual void pushTime(double time) = 0;

01acda3f   Benjamin Renard   Fix a regression ...
199
200
201
202
	virtual bool isNewInt() {
		return _isNewInt;
	}

fbe3c2bb   Benjamin Renard   First commit
203
protected:
fbe3c2bb   Benjamin Renard   First commit
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
	/**
	 *@brief  tag to know if a new time interval is set
	 */
	bool _isNewInt;

	/*
	 * @brief  Define the resampling strategy
	 */
	bool _useNearestValue;
};

/**
 * Simple Resampling abstract class, depand of paramData type
 */
template<typename TParamData>
class ResamplingSimpleAbstract: public ResamplingAbstract {

public:
	/**
	 * @brief  Element type of paramData
	 */
	typedef typename TParamData::ElementType ElementType;

	/**
	 * @brief  Constructor
	 */
3ff2d228   Benjamin Renard   Fix bug in sampli...
230
	ResamplingSimpleAbstract(Process& pProcess, MarkerAbstract* pMarkerPtr, TimeIntervalListSPtr pTimeIntervalList, double gapSize, TParamData &param, bool pUseNearestValue, bool pSameParam = false) :
ca31a786   Benjamin Renard   Fix other side ef...
231
232
233
234
			ResamplingAbstract(pProcess, pUseNearestValue),
					_markerPtr(pMarkerPtr),
					_timeIntervalList(pTimeIntervalList),
					_currentTimeInterval(_timeIntervalList->begin()), _currentTimeIntervalIndex(0), _samplingMode(INTERPOLATION), _nearestTime(NAN), _lastTime(0),
fbe3c2bb   Benjamin Renard   First commit
235
					_leftEffect(true), _paramOutput(new TParamData()), _paramInput(param),
3ff2d228   Benjamin Renard   Fix bug in sampli...
236
					_gapSize(gapSize), _sameParam(pSameParam) {
fbe3c2bb   Benjamin Renard   First commit
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
		_paramDataOutput = _paramOutput;
	}

	/**
	 * @brief  Destructor
	 */
	virtual ~ResamplingSimpleAbstract() {
	}
	;

	/**
	 * @brief Type List of Element type of paramData
	 */
	typedef std::list<ElementType> ListValue;

	/**
	 * @overload ResamplingAbstract::ResamplingAbstract::write()
	 */
	void write(ParamDataIndexInfo &pParamDataIndexInfo) {
3ff2d228   Benjamin Renard   Fix bug in sampli...
256
		if (_isNewInt && !_sameParam)
fbe3c2bb   Benjamin Renard   First commit
257
		{
ca31a786   Benjamin Renard   Fix other side ef...
258
			_markerPtr->init((*_currentTimeInterval)._startTime, (*_currentTimeInterval)._stopTime, _currentTimeIntervalIndex, getSampling());
fbe3c2bb   Benjamin Renard   First commit
259
260
261
262
263
			_isNewInt = false;
		}

		if ((pParamDataIndexInfo._nbDataToProcess > 0)) {
			//init _val with the first data value (to init dimensions)
65aa1ad5   Benjamin Renard   Fix a bug in resa...
264
265
266
267
268
269
270
			if (pParamDataIndexInfo._startIndex == 0)
			{
				_val = _paramInput.get(pParamDataIndexInfo._startIndex);
				_nearestValue = _paramInput.get(pParamDataIndexInfo._startIndex);
				_val << NotANumber();
				_nearestValue << NotANumber();
			}
fbe3c2bb   Benjamin Renard   First commit
271
272
273
274
275

			switch (_samplingMode)
			{
			case AVERAGE :
				writeAverage(pParamDataIndexInfo);
fbe3c2bb   Benjamin Renard   First commit
276
277
278
279
280
281
282
				break;
			case NEARESTVALUE :
				writeNearestValue(pParamDataIndexInfo);
				break;
			case INTERPOLATION :
				writeInterpolation(pParamDataIndexInfo);
				break;
3ff2d228   Benjamin Renard   Fix bug in sampli...
283
284
285
			case SAMEPARAM :
				writeSameParam(pParamDataIndexInfo);
				break;
fbe3c2bb   Benjamin Renard   First commit
286
			}
ca31a786   Benjamin Renard   Fix other side ef...
287
		}
bb672c4c   Benjamin Renard   Fix side effect i...
288
		if (pParamDataIndexInfo._timeIntToProcessChanged || pParamDataIndexInfo._noMoreTimeInt) {
fbe3c2bb   Benjamin Renard   First commit
289
290
291
292
293
294
295
296
			terminated();
		}
	}

	/**
	 * @brief compute and write last value, right effect
	 */
	virtual void terminated() {
3ff2d228   Benjamin Renard   Fix bug in sampli...
297
298
299
300
		if (_sameParam) {
			return;
		}

ca31a786   Benjamin Renard   Fix other side ef...
301
		if (_markerPtr->isFinished()) {
bb672c4c   Benjamin Renard   Fix side effect i...
302
303
			return;
		}
fbe3c2bb   Benjamin Renard   First commit
304
305
		switch (_samplingMode)
		{
fbe3c2bb   Benjamin Renard   First commit
306
		case AVERAGE :
a40aa278   Benjamin Renard   Fix resampling
307
308
309
310
311
312
313
			do {
				if (!_mem.empty()) {
					_val = average(_mem,_paramInput.getDim1(),_paramInput.getDim2());
				}
				else {
					_val << NotANumber();
				}
fbe3c2bb   Benjamin Renard   First commit
314
				_paramOutput->push(_val);
ca31a786   Benjamin Renard   Fix other side ef...
315
				_paramDataOutput->pushTime(_markerPtr->getTargetTime());
fbe3c2bb   Benjamin Renard   First commit
316
				_mem.clear();
a40aa278   Benjamin Renard   Fix resampling
317
			} while(_markerPtr->nextTarget());
fbe3c2bb   Benjamin Renard   First commit
318
			break;
2f932bad   Benjamin Renard   Fix interpolation...
319
		case INTERPOLATION :
fbe3c2bb   Benjamin Renard   First commit
320
		case NEARESTVALUE :
bb672c4c   Benjamin Renard   Fix side effect i...
321
			//Fix  side-off effects - Right boundary - CONSTANTS
ca31a786   Benjamin Renard   Fix other side ef...
322
323
324
325
326
327
328
329
330
			do {
				if ((_markerPtr->getTargetTime() - _lastTime) <= _gapSize)
					_val = _valMoins1;
				else
					_val << NotANumber();
				_paramOutput->pushTime(_markerPtr->getTargetTime());
				_paramOutput->push(_val);
			
			} while(_markerPtr->nextTarget());
bb672c4c   Benjamin Renard   Fix side effect i...
331
			break;
3ff2d228   Benjamin Renard   Fix bug in sampli...
332
333
334
335
336
337
338
339
340
341
342
343
344
345
		case SAMEPARAM :
			//Nothing to do
			break;
		}
	}

	void writeSameParam(ParamDataIndexInfo &pParamDataIndexInfo)
	{
		for (unsigned int index = pParamDataIndexInfo._startIndex;
			index < pParamDataIndexInfo._startIndex
				+ pParamDataIndexInfo._nbDataToProcess; index++)
		{
			_paramOutput->pushTime(_paramInput.getTime(index));
			_paramOutput->push(_paramInput.get(index));
2f932bad   Benjamin Renard   Fix interpolation...
346
		}
fbe3c2bb   Benjamin Renard   First commit
347
348
349
350
351
352
353
354
355
356
357
358
359
	}

	/**
	 * @brief compute and write new value in average mode
	 */
	void writeNearestValue(ParamDataIndexInfo &pParamDataIndexInfo)
	{
		for (unsigned int index = pParamDataIndexInfo._startIndex;
				index < pParamDataIndexInfo._startIndex
					+ pParamDataIndexInfo._nbDataToProcess; index++)
		{
			double timeCurrent = _paramInput.getTime(index);

ca31a786   Benjamin Renard   Fix other side ef...
360
			if (timeCurrent < _markerPtr->getMarkerMaxTime())
fbe3c2bb   Benjamin Renard   First commit
361
			{
ca31a786   Benjamin Renard   Fix other side ef...
362
363
364
				if (timeCurrent < _markerPtr->getMarkerMinTime()) {
					continue;
				}
fbe3c2bb   Benjamin Renard   First commit
365
366
367
368
369
				if (isNAN(_nearestTime))
				{
					_nearestValue = _paramInput.get(index);
					_nearestTime = timeCurrent;
				}
ca31a786   Benjamin Renard   Fix other side ef...
370
				else if (abs(_nearestTime-_markerPtr->getTargetTime()) > abs(timeCurrent-_markerPtr->getTargetTime()))
fbe3c2bb   Benjamin Renard   First commit
371
372
373
374
375
376
				{
					_nearestValue = _paramInput.get(index);
					_nearestTime = timeCurrent;
				}
			} else {
				_paramOutput->push(_nearestValue);
ca31a786   Benjamin Renard   Fix other side ef...
377
378
				_paramDataOutput->pushTime(_markerPtr->getTargetTime());
				if(!_markerPtr->nextTarget())
fbe3c2bb   Benjamin Renard   First commit
379
					break;
ca31a786   Benjamin Renard   Fix other side ef...
380
				while (_markerPtr->getMarkerMaxTime() < timeCurrent)
fbe3c2bb   Benjamin Renard   First commit
381
				{
2f932bad   Benjamin Renard   Fix interpolation...
382
					if (timeCurrent - _lastTime < _gapSize) {
80265e6a   Benjamin Renard   Compute interpola...
383
						//Interpolation
ca31a786   Benjamin Renard   Fix other side ef...
384
						double coefT = (float) (_markerPtr->getTargetTime() - _lastTime) / (timeCurrent - _lastTime);
2f932bad   Benjamin Renard   Fix interpolation...
385
						_val = interpolation(_valMoins1, _paramInput.get(index), coefT, _paramInput.getDim1(),_paramInput.getDim2());
80265e6a   Benjamin Renard   Compute interpola...
386
					}
2f932bad   Benjamin Renard   Fix interpolation...
387
					else {
80265e6a   Benjamin Renard   Compute interpola...
388
						_val << NotANumber();
2f932bad   Benjamin Renard   Fix interpolation...
389
					}
fbe3c2bb   Benjamin Renard   First commit
390
					_paramOutput->push(_val);
ca31a786   Benjamin Renard   Fix other side ef...
391
					_paramDataOutput->pushTime(_markerPtr->getTargetTime());
fbe3c2bb   Benjamin Renard   First commit
392
					_nearestTime << NotANumber();
ca31a786   Benjamin Renard   Fix other side ef...
393
					if(!_markerPtr->nextTarget())
fbe3c2bb   Benjamin Renard   First commit
394
						break;
fbe3c2bb   Benjamin Renard   First commit
395
				}
fbe3c2bb   Benjamin Renard   First commit
396
397
398
				_nearestValue = _paramInput.get(index);
				_nearestTime = timeCurrent;
			}
80265e6a   Benjamin Renard   Compute interpola...
399
400
401

			_lastTime = _paramInput.getTime(index);
			_valMoins1 = _paramInput.get(index);
fbe3c2bb   Benjamin Renard   First commit
402
403
404
405
406
407
408
		}
	}

	/**
	 * @brief compute and write new value in average mode
	 */
	void writeAverage(ParamDataIndexInfo &pParamDataIndexInfo) {
fbe3c2bb   Benjamin Renard   First commit
409
410
411
412
413
414
415
416
		for (unsigned int index = pParamDataIndexInfo._startIndex;
				index
						< pParamDataIndexInfo._startIndex
								+ pParamDataIndexInfo._nbDataToProcess;
				index++) {

			double timeCurrent = _paramInput.getTime(index);

ca31a786   Benjamin Renard   Fix other side ef...
417
418
419
420
			if (timeCurrent < _markerPtr->getMarkerMaxTime()) {
				if (timeCurrent >= _markerPtr->getMarkerMinTime()) { 
					_mem.push_back(_paramInput.get(index));
				}
fbe3c2bb   Benjamin Renard   First commit
421
			} else {
ca31a786   Benjamin Renard   Fix other side ef...
422
				if (!_mem.empty()) {
c6877b6f   Benjamin Renard   Fix average for v...
423
					_val = average(_mem,_paramInput.getDim1(),_paramInput.getDim2());
ca31a786   Benjamin Renard   Fix other side ef...
424
				}
2f932bad   Benjamin Renard   Fix interpolation...
425
				else if (timeCurrent - _lastTime < _gapSize) {
80265e6a   Benjamin Renard   Compute interpola...
426
					//Interpolation
ca31a786   Benjamin Renard   Fix other side ef...
427
					double coefT = (float) (_markerPtr->getTargetTime() - _lastTime) / (timeCurrent - _lastTime);
2f932bad   Benjamin Renard   Fix interpolation...
428
					_val = interpolation(_valMoins1, _paramInput.get(index), coefT, _paramInput.getDim1(),_paramInput.getDim2());
80265e6a   Benjamin Renard   Compute interpola...
429
				}
ca31a786   Benjamin Renard   Fix other side ef...
430
				else {
fbe3c2bb   Benjamin Renard   First commit
431
					_val << NotANumber();
ca31a786   Benjamin Renard   Fix other side ef...
432
				}
fbe3c2bb   Benjamin Renard   First commit
433
				_paramOutput->push(_val);
ca31a786   Benjamin Renard   Fix other side ef...
434
435
				_paramDataOutput->pushTime(_markerPtr->getTargetTime());
				_mem.clear();
fbe3c2bb   Benjamin Renard   First commit
436

ca31a786   Benjamin Renard   Fix other side ef...
437
				if(!_markerPtr->nextTarget())
fbe3c2bb   Benjamin Renard   First commit
438
					break;
fbe3c2bb   Benjamin Renard   First commit
439

ca31a786   Benjamin Renard   Fix other side ef...
440
				while (_markerPtr->getMarkerMaxTime() < timeCurrent)
fbe3c2bb   Benjamin Renard   First commit
441
				{
2f932bad   Benjamin Renard   Fix interpolation...
442
					if (timeCurrent - _lastTime < _gapSize) {
80265e6a   Benjamin Renard   Compute interpola...
443
						//Interpolation
ca31a786   Benjamin Renard   Fix other side ef...
444
						double coefT = (float) (_markerPtr->getTargetTime() - _lastTime) / (timeCurrent - _lastTime);
2f932bad   Benjamin Renard   Fix interpolation...
445
						_val = interpolation(_valMoins1, _paramInput.get(index), coefT, _paramInput.getDim1(),_paramInput.getDim2());
80265e6a   Benjamin Renard   Compute interpola...
446
447
448
					}
					else
						_val << NotANumber();
fbe3c2bb   Benjamin Renard   First commit
449
					_paramOutput->push(_val);
ca31a786   Benjamin Renard   Fix other side ef...
450
451
					_paramDataOutput->pushTime(_markerPtr->getTargetTime());
					if(!_markerPtr->nextTarget())
fbe3c2bb   Benjamin Renard   First commit
452
						break;
fbe3c2bb   Benjamin Renard   First commit
453
				}
ca31a786   Benjamin Renard   Fix other side ef...
454
455
456
				if ((timeCurrent >= _markerPtr->getMarkerMinTime()) && (timeCurrent < _markerPtr->getMarkerMaxTime())) {
					_mem.push_back(_paramInput.get(index));
				}
fbe3c2bb   Benjamin Renard   First commit
457
			}
80265e6a   Benjamin Renard   Compute interpola...
458
459
			_lastTime = _paramInput.getTime(index);
			_valMoins1 = _paramInput.get(index);
fbe3c2bb   Benjamin Renard   First commit
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
		}
	}

	/**
	 * @brief compute and write new value in interpolation mode
	 */
	void writeInterpolation(ParamDataIndexInfo &pParamDataIndexInfo) {
		for (unsigned int index = pParamDataIndexInfo._startIndex;
				index
						< pParamDataIndexInfo._startIndex
								+ pParamDataIndexInfo._nbDataToProcess;
				index++) {

			double timeCurrent = _paramInput.getTime(index);

fbe3c2bb   Benjamin Renard   First commit
475
476
			//Fix  side-off effects - Left boundary - CONSTANTS
			if (_leftEffect) {
ca31a786   Benjamin Renard   Fix other side ef...
477
478
				while (_markerPtr->getTargetTime() <= timeCurrent) {
					if (abs(timeCurrent - _markerPtr->getTargetTime()) <= _gapSize) {
fbe3c2bb   Benjamin Renard   First commit
479
480
481
482
						_val = _paramInput.get(index);
					} else {
						_val << NotANumber();
					}
ca31a786   Benjamin Renard   Fix other side ef...
483
					_paramDataOutput->pushTime(_markerPtr->getTargetTime());
fbe3c2bb   Benjamin Renard   First commit
484
					_paramOutput->push(_val);
ca31a786   Benjamin Renard   Fix other side ef...
485
					if (!_markerPtr->nextTarget())
fbe3c2bb   Benjamin Renard   First commit
486
487
488
489
						break;
				}
				_leftEffect = false;
			} else {
ca31a786   Benjamin Renard   Fix other side ef...
490
				if (_markerPtr->getTargetTime() <= timeCurrent) {
d1f2a5f0   Benjamin Renard   Fix bug with samp...
491
					while ((_markerPtr->getTargetTime() <= timeCurrent) && !_markerPtr->isFinished()) {
fbe3c2bb   Benjamin Renard   First commit
492
493
						double deltaT = (float) (timeCurrent - _lastTime);
						if (deltaT <= _gapSize) {
ca31a786   Benjamin Renard   Fix other side ef...
494
							double coefT = (float) (_markerPtr->getTargetTime() - _lastTime) / deltaT;
2f932bad   Benjamin Renard   Fix interpolation...
495
							_val = interpolation(_valMoins1, _paramInput.get(index), coefT, _paramInput.getDim1(),_paramInput.getDim2());
fbe3c2bb   Benjamin Renard   First commit
496
497
498
						} else {
							_val << NotANumber();
						}
ca31a786   Benjamin Renard   Fix other side ef...
499
						_paramDataOutput->pushTime(_markerPtr->getTargetTime());
fbe3c2bb   Benjamin Renard   First commit
500
						_paramOutput->push(_val);
ca31a786   Benjamin Renard   Fix other side ef...
501
						if (!_markerPtr->nextTarget())
fbe3c2bb   Benjamin Renard   First commit
502
503
504
505
							break;
					}
				}
			}
fbe3c2bb   Benjamin Renard   First commit
506
507
508
509
510
511
512
513
514
515
			_lastTime = _paramInput.getTime(index);
			_valMoins1 = _paramInput.get(index);
		}
	}

	/**
	 * @overload ResamplingAbstract::ResamplingAbstract::init()
	 */
	virtual void init() {
		//Compute Sampling mode
3ff2d228   Benjamin Renard   Fix bug in sampli...
516
517
518
519
520
		if (_sameParam)
		{
			_samplingMode = SAMEPARAM;
		}
		else if (_useNearestValue)
fbe3c2bb   Benjamin Renard   First commit
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
		{
			_samplingMode = NEARESTVALUE;
			_nearestValue = ElementType();
			_nearestTime << NotANumber();
		}
		else
		{
			float minSampling = _paramInput.getMinSampling();

			if ((minSampling * 2) < getSampling()) {
				_samplingMode = AVERAGE;
			}
		}

		_isNewInt = true;
	}

	/**
	 * @overload ResamplingAbstract::reset(double pStartTime, double pTimeInt)
	 */
a6490f4d   Benjamin Renard   Do not throw an e...
541
	virtual void resetResampling() {
fbe3c2bb   Benjamin Renard   First commit
542
543
544
		if (_currentTimeInterval == _timeIntervalList->end())
			return;

fbe3c2bb   Benjamin Renard   First commit
545
546
		// Get next TimeInteval;
		++_currentTimeInterval;
ca31a786   Benjamin Renard   Fix other side ef...
547
		++_currentTimeIntervalIndex;
fbe3c2bb   Benjamin Renard   First commit
548
549
550
		_samplingMode = INTERPOLATION;
		_lastTime = 0;
		_leftEffect = true;
599e1446   Benjamin Renard   Fix new interval ...
551
552
		_valMoins1 << NotANumber();
		_val<< NotANumber();
fbe3c2bb   Benjamin Renard   First commit
553
554
555
556
557
		_mem.clear();

		init();
	}

ca31a786   Benjamin Renard   Fix other side ef...
558
	virtual double getSampling() = 0;
fbe3c2bb   Benjamin Renard   First commit
559

deefda79   Benjamin Renard   Addapt resampling...
560

fbe3c2bb   Benjamin Renard   First commit
561
562
563
564
	/**
	 * @brief sampling mode
	 */
	enum SamplingMode {
3ff2d228   Benjamin Renard   Fix bug in sampli...
565
		INTERPOLATION, AVERAGE, NEARESTVALUE, SAMEPARAM
fbe3c2bb   Benjamin Renard   First commit
566
567
	};

fbe3c2bb   Benjamin Renard   First commit
568
569
570
571
572
573
574
private:

	/**
	 * @brief stored val to compute average in average mode
	 */
	ListValue _mem;

ca31a786   Benjamin Renard   Fix other side ef...
575
576
	MarkerAbstract* _markerPtr;
	
fbe3c2bb   Benjamin Renard   First commit
577
578
579
580
	TimeIntervalListSPtr _timeIntervalList;

	TimeIntervalList::iterator _currentTimeInterval;

ca31a786   Benjamin Renard   Fix other side ef...
581
	int _currentTimeIntervalIndex;
fbe3c2bb   Benjamin Renard   First commit
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630

	/**<
	 * @brief current sampling mode
	 */
	SamplingMode _samplingMode;

	/**<
	 * @brief last computed value
	 */
	ElementType _val;

	/**
	 * @brief nearest time
	 */
	double _nearestTime;

	/**
	 * @brief nearest value
	 */
	ElementType _nearestValue;

	/**<
	 * @brief last input value
	 */
	ElementType _valMoins1;
	/**<
	 * @brief time of  last input value
	 */
	double _lastTime;

	/**
	 * @brief left effect indicator in interpolation mode
	 */
	bool _leftEffect;

	/**
	 * @brief real ParamData Output
	 */
	TParamData *_paramOutput;

	/**
	 * @brief real ParamData Input
	 */
	TParamData& _paramInput;

	/**
	 * @brief gap size for input data
	 */
	double _gapSize;
3ff2d228   Benjamin Renard   Fix bug in sampli...
631
632

	bool _sameParam;
fbe3c2bb   Benjamin Renard   First commit
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
}
;

/**
 * Resampling implementation with a given sampling time , depand of paramData type
 */
template<typename TParamData>
class ResamplingWithSamplingTime : public ResamplingSimpleAbstract<TParamData> {

public:
	/**
	 * @brief  Constructor
	 */
	ResamplingWithSamplingTime(Process& pProcess, TimeIntervalListSPtr pTimeIntervalList,
			double sampling, double gapSize, TParamData &param, bool  pUseNearestValue) :
ca31a786   Benjamin Renard   Fix other side ef...
648
649
			ResamplingSimpleAbstract<TParamData>(pProcess, &_marker, pTimeIntervalList,
						gapSize, param, pUseNearestValue), _samplingTime(sampling) {
fbe3c2bb   Benjamin Renard   First commit
650
651
652
653
654
655
656
657
	}

	/**
	 * @brief  Destructor
	 */
	virtual ~ResamplingWithSamplingTime() {
	}

ca31a786   Benjamin Renard   Fix other side ef...
658
659
	double getSampling() {
		return _samplingTime;
fbe3c2bb   Benjamin Renard   First commit
660
661
	}

deefda79   Benjamin Renard   Addapt resampling...
662
663
664
665
	void pushTime(double /*time*/) {
		//Not used
	}

fbe3c2bb   Benjamin Renard   First commit
666
private:
ca31a786   Benjamin Renard   Fix other side ef...
667
668
669
670
	MarkerSampling _marker;

	double _samplingTime;
};
fbe3c2bb   Benjamin Renard   First commit
671
672
673
674
675
676
677
678
679
680
681
682
683


/**
 * Resampling implementation with a given reference parameter for time definition , depand of paramData type
 */
template<typename TParamData>
class ResamplingWithRefParam: public ResamplingSimpleAbstract<TParamData> {

public:
	/**
	 * @brief  Constructor
	 */
	ResamplingWithRefParam(Process& pProcess, TimeIntervalListSPtr pTimeIntervalList,
3ff2d228   Benjamin Renard   Fix bug in sampli...
684
			TParamData &param, ParamData &refParamData, double gapSize, bool  pUseNearestValue, bool pSameParam) :
ca31a786   Benjamin Renard   Fix other side ef...
685
			ResamplingSimpleAbstract<TParamData>(pProcess, &_marker, pTimeIntervalList,
3ff2d228   Benjamin Renard   Fix bug in sampli...
686
					gapSize, param, pUseNearestValue, pSameParam), _refParamData(refParamData) {
ca31a786   Benjamin Renard   Fix other side ef...
687
		_marker.setRefParamData(&refParamData);
fbe3c2bb   Benjamin Renard   First commit
688
689
690
691
692
693
694
695
	}

	/**
	 * @brief  Destructor
	 */
	virtual ~ResamplingWithRefParam() {
	}

ca31a786   Benjamin Renard   Fix other side ef...
696
	double getSampling() {
fbe3c2bb   Benjamin Renard   First commit
697
		return _refParamData.getMinSampling();
ca31a786   Benjamin Renard   Fix other side ef...
698
        }
fbe3c2bb   Benjamin Renard   First commit
699

deefda79   Benjamin Renard   Addapt resampling...
700
701
702
703
	void pushTime(double time) {
		_marker.pushTime(time);
	}

fbe3c2bb   Benjamin Renard   First commit
704
private:
ca31a786   Benjamin Renard   Fix other side ef...
705
	MarkerRefParam _marker;
fbe3c2bb   Benjamin Renard   First commit
706

fbe3c2bb   Benjamin Renard   First commit
707
	ParamData& _refParamData;
ca31a786   Benjamin Renard   Fix other side ef...
708
};
fbe3c2bb   Benjamin Renard   First commit
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727

/**
 * create the real Resampling implementation with visitor design pattern
 */
class CreateResampling: public VisitorOfParamData {
public:
	enum ResamplingType {
		RT_WITHSAMPLINGTIME,
		RT_WITHREFTIMELIST
	};

	/**
	 * @brief constructor
	 */
	CreateResampling(Process& pProcess, TimeIntervalListSPtr pTimeIntervalList,
			double sampling, double gapSize, ParamData &paramData, bool useNearestValue) :
			_type(ResamplingType::RT_WITHSAMPLINGTIME),
			_process(pProcess), _paramData(paramData), _resampling(NULL), _timeIntervalList(
					pTimeIntervalList), _sampling(sampling), _gapSize(
3ff2d228   Benjamin Renard   Fix bug in sampli...
728
					gapSize), _refParamData(paramData), _useNearestValue(useNearestValue), _sameParam(false) {
fbe3c2bb   Benjamin Renard   First commit
729
730
731
732
733
734
735
		_paramData.accept(*this);
	}

	/**
	 * @brief constructor
	 */
	CreateResampling(Process& pProcess, TimeIntervalListSPtr pTimeIntervalList,
3ff2d228   Benjamin Renard   Fix bug in sampli...
736
			ParamData &paramData, ParamData& refParamData, double gapSize, bool useNearestValue, bool sameParam = false) :
fbe3c2bb   Benjamin Renard   First commit
737
738
739
			_type(ResamplingType::RT_WITHREFTIMELIST),
			_process(pProcess), _paramData(paramData), _resampling(NULL), _timeIntervalList(
					pTimeIntervalList), _sampling(0.), _gapSize(
3ff2d228   Benjamin Renard   Fix bug in sampli...
740
					gapSize),_refParamData(refParamData), _useNearestValue(useNearestValue), _sameParam(sameParam) {
fbe3c2bb   Benjamin Renard   First commit
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
		_paramData.accept(*this);
	}

	/**
	 * @overload VisitorOfParamData::visit(ParamDataScalaireShort *)
	 */
	virtual void visit(ParamDataScalaireShort *) {
		switch (_type)
		{
		case ResamplingType::RT_WITHSAMPLINGTIME :
			_resampling = new ResamplingWithSamplingTime<ParamDataScalaireShort>(_process,
					_timeIntervalList, _sampling, _gapSize,
					dynamic_cast<ParamDataScalaireShort &>(_paramData), _useNearestValue);
			break;
		case ResamplingType::RT_WITHREFTIMELIST :
			_resampling = new ResamplingWithRefParam<ParamDataScalaireShort>(_process,
				_timeIntervalList,
				dynamic_cast<ParamDataScalaireShort &>(_paramData),
				_refParamData,
3ff2d228   Benjamin Renard   Fix bug in sampli...
760
				_gapSize, _useNearestValue, _sameParam);
fbe3c2bb   Benjamin Renard   First commit
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
			break;
		}
	}

	/**
	 * @overload VisitorOfParamData::visit(ParamDataScalaireFloat *)
	 */
	virtual void visit(ParamDataScalaireFloat *) {
		switch (_type)
		{
		case ResamplingType::RT_WITHSAMPLINGTIME :
			_resampling = new ResamplingWithSamplingTime<ParamDataScalaireFloat>(_process,
							_timeIntervalList, _sampling, _gapSize,
							dynamic_cast<ParamDataScalaireFloat &>(_paramData), _useNearestValue);
			break;
		case ResamplingType::RT_WITHREFTIMELIST :
			_resampling = new ResamplingWithRefParam<ParamDataScalaireFloat>(_process,
							_timeIntervalList,
							dynamic_cast<ParamDataScalaireFloat &>(_paramData),
							_refParamData,
3ff2d228   Benjamin Renard   Fix bug in sampli...
781
							_gapSize, _useNearestValue, _sameParam);
fbe3c2bb   Benjamin Renard   First commit
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
			break;
		}
	}

	/**
	 * @overload VisitorOfParamData::visit(ParamDataScalaireDouble *)
	 */
	virtual void visit(ParamDataScalaireDouble *) {
		switch (_type)
		{
		case ResamplingType::RT_WITHSAMPLINGTIME :
			_resampling = new ResamplingWithSamplingTime<ParamDataScalaireDouble>(_process,
				_timeIntervalList, _sampling, _gapSize,
				dynamic_cast<ParamDataScalaireDouble &>(_paramData), _useNearestValue);
			break;
		case ResamplingType::RT_WITHREFTIMELIST :
			_resampling = new ResamplingWithRefParam<ParamDataScalaireDouble>(_process,
				_timeIntervalList,
				dynamic_cast<ParamDataScalaireDouble &>(_paramData),
				_refParamData,
3ff2d228   Benjamin Renard   Fix bug in sampli...
802
				_gapSize, _useNearestValue, _sameParam);
fbe3c2bb   Benjamin Renard   First commit
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
			break;
		}
	}

	/**
	 * @overload VisitorOfParamData::visit(ParamDataScalaireLongDouble *)
	 */
	virtual void visit(ParamDataScalaireLongDouble *) {
		switch (_type)
		{
		case ResamplingType::RT_WITHSAMPLINGTIME :
			_resampling = new ResamplingWithSamplingTime<ParamDataScalaireLongDouble>(_process,
				_timeIntervalList, _sampling, _gapSize,
				dynamic_cast<ParamDataScalaireLongDouble &>(_paramData), _useNearestValue);
			break;
		case ResamplingType::RT_WITHREFTIMELIST :
			_resampling = new ResamplingWithRefParam<ParamDataScalaireLongDouble>(_process,
				_timeIntervalList,
				dynamic_cast<ParamDataScalaireLongDouble &>(_paramData),
				_refParamData,
3ff2d228   Benjamin Renard   Fix bug in sampli...
823
				_gapSize, _useNearestValue, _sameParam);
fbe3c2bb   Benjamin Renard   First commit
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
			break;
		}
	}

	/**
	 * @overload VisitorOfParamData::visit(ParamDataScalaireInt *)
	 */
	virtual void visit(ParamDataScalaireInt *) {
		switch (_type)
		{
		case ResamplingType::RT_WITHSAMPLINGTIME :
			_resampling = new ResamplingWithSamplingTime<ParamDataScalaireInt>(_process,
					_timeIntervalList, _sampling, _gapSize,
					dynamic_cast<ParamDataScalaireInt &>(_paramData), _useNearestValue);
			break;
		case ResamplingType::RT_WITHREFTIMELIST :
			_resampling = new ResamplingWithRefParam<ParamDataScalaireInt>(_process,
				_timeIntervalList,
				dynamic_cast<ParamDataScalaireInt &>(_paramData),
				_refParamData,
3ff2d228   Benjamin Renard   Fix bug in sampli...
844
				_gapSize, _useNearestValue, _sameParam);
fbe3c2bb   Benjamin Renard   First commit
845
846
847
848
849
850
851
852
			break;
		}
	}

	/**
	 * @overload VisitorOfParamData::visit(ParamDataLogicalData *)
	 */
	virtual void visit(ParamDataLogicalData *) {
7578a549   Benjamin Renard   Add boolean suppo...
853
854
855
856
857
858
859
860
861
862
863
864
865
866
		switch (_type)
		{
		case ResamplingType::RT_WITHSAMPLINGTIME :
			// !! Force the use of the nearest value
			_resampling = new ResamplingWithSamplingTime<ParamDataLogicalData>(_process,
					_timeIntervalList, _sampling, _gapSize,
					dynamic_cast<ParamDataLogicalData &>(_paramData), true);
			break;
		case ResamplingType::RT_WITHREFTIMELIST :
			// !! Force the use of the nearest value
			_resampling = new ResamplingWithRefParam<ParamDataLogicalData>(_process,
				_timeIntervalList,
				dynamic_cast<ParamDataLogicalData &>(_paramData),
				_refParamData,
3ff2d228   Benjamin Renard   Fix bug in sampli...
867
				_gapSize, true, _sameParam);
7578a549   Benjamin Renard   Add boolean suppo...
868
869
			break;
		}
fbe3c2bb   Benjamin Renard   First commit
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
	}

	/**
	 * @overload VisitorOfParamData::visit(ParamDataTab1DShort *)
	 */
	virtual void visit(ParamDataTab1DShort *) {
		switch (_type)
		{
		case ResamplingType::RT_WITHSAMPLINGTIME :
			_resampling = new ResamplingWithSamplingTime<ParamDataTab1DShort>(_process,
				_timeIntervalList, _sampling, _gapSize,
				dynamic_cast<ParamDataTab1DShort &>(_paramData), _useNearestValue);
			break;
		case ResamplingType::RT_WITHREFTIMELIST :
			_resampling = new ResamplingWithRefParam<ParamDataTab1DShort>(_process,
				_timeIntervalList,
				dynamic_cast<ParamDataTab1DShort &>(_paramData),
				_refParamData,
3ff2d228   Benjamin Renard   Fix bug in sampli...
888
				_gapSize, _useNearestValue, _sameParam);
fbe3c2bb   Benjamin Renard   First commit
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
			break;
		}
	}

	/**
	 * @overload VisitorOfParamData::visit(ParamDataTab1DFloat *)
	 */
	virtual void visit(ParamDataTab1DFloat *) {
		switch (_type)
		{
		case ResamplingType::RT_WITHSAMPLINGTIME :
			_resampling = new ResamplingWithSamplingTime<ParamDataTab1DFloat>(_process,
				_timeIntervalList, _sampling, _gapSize,
				dynamic_cast<ParamDataTab1DFloat &>(_paramData), _useNearestValue);
			break;
		case ResamplingType::RT_WITHREFTIMELIST :
			_resampling = new ResamplingWithRefParam<ParamDataTab1DFloat>(_process,
				_timeIntervalList,
				dynamic_cast<ParamDataTab1DFloat &>(_paramData),
				_refParamData,
3ff2d228   Benjamin Renard   Fix bug in sampli...
909
				_gapSize, _useNearestValue, _sameParam);
fbe3c2bb   Benjamin Renard   First commit
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
			break;
		}
	}

	/**
	 * @overload VisitorOfParamData::visit(ParamDataTab1DDouble *)
	 */
	virtual void visit(ParamDataTab1DDouble *) {
		switch (_type)
		{
		case ResamplingType::RT_WITHSAMPLINGTIME :
			_resampling = new ResamplingWithSamplingTime<ParamDataTab1DDouble>(_process,
				_timeIntervalList, _sampling, _gapSize,
				dynamic_cast<ParamDataTab1DDouble &>(_paramData), _useNearestValue);
			break;
		case ResamplingType::RT_WITHREFTIMELIST :
			_resampling = new ResamplingWithRefParam<ParamDataTab1DDouble>(_process,
				_timeIntervalList,
				dynamic_cast<ParamDataTab1DDouble &>(_paramData),
				_refParamData,
3ff2d228   Benjamin Renard   Fix bug in sampli...
930
				_gapSize, _useNearestValue, _sameParam);
fbe3c2bb   Benjamin Renard   First commit
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
			break;
		}
	}

	/**
	 * @overload VisitorOfParamData::visit(ParamDataTab1DLongDouble *)
	 */
	virtual void visit(ParamDataTab1DLongDouble *) {
		switch (_type)
		{
		case ResamplingType::RT_WITHSAMPLINGTIME :
			_resampling = new ResamplingWithSamplingTime<ParamDataTab1DLongDouble>(_process,
				_timeIntervalList, _sampling, _gapSize,
				dynamic_cast<ParamDataTab1DLongDouble &>(_paramData), _useNearestValue);
			break;
		case ResamplingType::RT_WITHREFTIMELIST :
			_resampling = new ResamplingWithRefParam<ParamDataTab1DLongDouble>(_process,
				_timeIntervalList,
				dynamic_cast<ParamDataTab1DLongDouble &>(_paramData),
				_refParamData,
3ff2d228   Benjamin Renard   Fix bug in sampli...
951
				_gapSize, _useNearestValue, _sameParam);
fbe3c2bb   Benjamin Renard   First commit
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
			break;
		}
	}

	/**
	 * @overload VisitorOfParamData::visit(ParamDataTab1DInt *)
	 */
	virtual void visit(ParamDataTab1DInt *) {
		switch (_type)
		{
		case ResamplingType::RT_WITHSAMPLINGTIME :
			_resampling = new ResamplingWithSamplingTime<ParamDataTab1DInt>(_process,
				_timeIntervalList, _sampling, _gapSize,
				dynamic_cast<ParamDataTab1DInt &>(_paramData), _useNearestValue);
			break;
		case ResamplingType::RT_WITHREFTIMELIST :
			_resampling = new ResamplingWithRefParam<ParamDataTab1DInt>(_process,
				_timeIntervalList,
				dynamic_cast<ParamDataTab1DInt &>(_paramData),
				_refParamData,
3ff2d228   Benjamin Renard   Fix bug in sampli...
972
				_gapSize, _useNearestValue, _sameParam);
fbe3c2bb   Benjamin Renard   First commit
973
974
975
976
977
978
979
980
			break;
		}
	}

	/**
	 * @overload VisitorOfParamData::visit(ParamDataTab1DLogicalData *)
	 */
	virtual void visit(ParamDataTab1DLogicalData *) {
7578a549   Benjamin Renard   Add boolean suppo...
981
982
983
984
985
986
987
988
989
990
991
992
993
994
		switch (_type)
		{
		case ResamplingType::RT_WITHSAMPLINGTIME :
			// !! Force the use of the nearest value
			_resampling = new ResamplingWithSamplingTime<ParamDataTab1DLogicalData>(_process,
				_timeIntervalList, _sampling, _gapSize,
				dynamic_cast<ParamDataTab1DLogicalData &>(_paramData), true);
			break;
		case ResamplingType::RT_WITHREFTIMELIST :
			// !! Force the use of the nearest value
			_resampling = new ResamplingWithRefParam<ParamDataTab1DLogicalData>(_process,
				_timeIntervalList,
				dynamic_cast<ParamDataTab1DLogicalData &>(_paramData),
				_refParamData,
3ff2d228   Benjamin Renard   Fix bug in sampli...
995
				_gapSize, true, _sameParam);
7578a549   Benjamin Renard   Add boolean suppo...
996
997
			break;
		}
fbe3c2bb   Benjamin Renard   First commit
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
	}

	/**
	 * @overload VisitorOfParamData::visit(ParamDataTab2DShort *)
	 */
	virtual void visit(ParamDataTab2DShort *) {
		switch (_type)
		{
		case ResamplingType::RT_WITHSAMPLINGTIME :
			_resampling = new ResamplingWithSamplingTime<ParamDataTab2DShort>(_process,
					_timeIntervalList, _sampling, _gapSize,
					dynamic_cast<ParamDataTab2DShort &>(_paramData), _useNearestValue);
			break;
		case ResamplingType::RT_WITHREFTIMELIST :
			_resampling = new ResamplingWithRefParam<ParamDataTab2DShort>(_process,
				_timeIntervalList,
				dynamic_cast<ParamDataTab2DShort &>(_paramData),
				_refParamData,
3ff2d228   Benjamin Renard   Fix bug in sampli...
1016
				_gapSize, _useNearestValue, _sameParam);
fbe3c2bb   Benjamin Renard   First commit
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
			break;
		}
	}

	/**
	 * @overload VisitorOfParamData::visit(ParamDataTab2DFloat *)
	 */
	virtual void visit(ParamDataTab2DFloat *) {
		switch (_type)
		{
		case ResamplingType::RT_WITHSAMPLINGTIME :
			_resampling = new ResamplingWithSamplingTime<ParamDataTab2DFloat>(_process,
					_timeIntervalList, _sampling, _gapSize,
					dynamic_cast<ParamDataTab2DFloat &>(_paramData), _useNearestValue);
			break;
		case ResamplingType::RT_WITHREFTIMELIST :
			_resampling = new ResamplingWithRefParam<ParamDataTab2DFloat>(_process,
				_timeIntervalList,
				dynamic_cast<ParamDataTab2DFloat &>(_paramData),
				_refParamData,
3ff2d228   Benjamin Renard   Fix bug in sampli...
1037
				_gapSize, _useNearestValue, _sameParam);
fbe3c2bb   Benjamin Renard   First commit
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
			break;
		}
	}

	/**
	 * @overload VisitorOfParamData::visit(ParamDataTab2DDouble *)
	 */
	virtual void visit(ParamDataTab2DDouble *) {
		switch (_type)
		{
		case ResamplingType::RT_WITHSAMPLINGTIME :
			_resampling = new ResamplingWithSamplingTime<ParamDataTab2DDouble>(_process,
					_timeIntervalList, _sampling, _gapSize,
					dynamic_cast<ParamDataTab2DDouble &>(_paramData), _useNearestValue);
			break;
		case ResamplingType::RT_WITHREFTIMELIST :
			_resampling = new ResamplingWithRefParam<ParamDataTab2DDouble>(_process,
				_timeIntervalList,
				dynamic_cast<ParamDataTab2DDouble &>(_paramData),
				_refParamData,
3ff2d228   Benjamin Renard   Fix bug in sampli...
1058
				_gapSize, _useNearestValue, _sameParam);
fbe3c2bb   Benjamin Renard   First commit
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
			break;
		}
	}

	/**
	 * @overload VisitorOfParamData::visit(ParamDataTab2DLongDouble *)
	 */
	virtual void visit(ParamDataTab2DLongDouble *) {
		switch (_type)
		{
		case ResamplingType::RT_WITHSAMPLINGTIME :
			_resampling = new ResamplingWithSamplingTime<ParamDataTab2DLongDouble>(_process,
					_timeIntervalList, _sampling, _gapSize,
					dynamic_cast<ParamDataTab2DLongDouble &>(_paramData), _useNearestValue);
			break;
		case ResamplingType::RT_WITHREFTIMELIST :
			_resampling = new ResamplingWithRefParam<ParamDataTab2DLongDouble>(_process,
				_timeIntervalList,
				dynamic_cast<ParamDataTab2DLongDouble &>(_paramData),
				_refParamData,
3ff2d228   Benjamin Renard   Fix bug in sampli...
1079
				_gapSize, _useNearestValue, _sameParam);
fbe3c2bb   Benjamin Renard   First commit
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
			break;
		}
	}

	/**
	 * @overload VisitorOfParamData::visit(ParamDataTab2DInt *)
	 */
	virtual void visit(ParamDataTab2DInt *) {
		switch (_type)
		{
		case ResamplingType::RT_WITHSAMPLINGTIME :
			_resampling = new ResamplingWithSamplingTime<ParamDataTab2DInt>(_process,
					_timeIntervalList, _sampling, _gapSize,
					dynamic_cast<ParamDataTab2DInt &>(_paramData), _useNearestValue);
			break;
		case ResamplingType::RT_WITHREFTIMELIST :
			_resampling = new ResamplingWithRefParam<ParamDataTab2DInt>(_process,
				_timeIntervalList,
				dynamic_cast<ParamDataTab2DInt &>(_paramData),
				_refParamData,
3ff2d228   Benjamin Renard   Fix bug in sampli...
1100
				_gapSize, _useNearestValue, _sameParam);
fbe3c2bb   Benjamin Renard   First commit
1101
1102
1103
1104
1105
1106
1107
1108
			break;
		}
	}

	/**
	 * @overload VisitorOfParamData::visit(ParamDataTab2DLogicalData *)
	 */
	virtual void visit(ParamDataTab2DLogicalData *) {
7578a549   Benjamin Renard   Add boolean suppo...
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
		switch (_type)
		{
		case ResamplingType::RT_WITHSAMPLINGTIME :
			// !! Force the use of the nearest value
			_resampling = new ResamplingWithSamplingTime<ParamDataTab2DLogicalData>(_process,
					_timeIntervalList, _sampling, _gapSize,
					dynamic_cast<ParamDataTab2DLogicalData &>(_paramData), true);
			break;
		case ResamplingType::RT_WITHREFTIMELIST :
			// !! Force the use of the nearest value
			_resampling = new ResamplingWithRefParam<ParamDataTab2DLogicalData>(_process,
					_timeIntervalList,
					dynamic_cast<ParamDataTab2DLogicalData &>(_paramData),
					_refParamData,
3ff2d228   Benjamin Renard   Fix bug in sampli...
1123
					_gapSize, true, _sameParam);
7578a549   Benjamin Renard   Add boolean suppo...
1124
1125
                        break;
                }
fbe3c2bb   Benjamin Renard   First commit
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
	}

	/**
	 * @brief Good resampling getter
	 */
	ResamplingAbstract* getResampling() const {
		return _resampling;
	}
private:
	ResamplingType _type;
	Process &_process;
	ParamData &_paramData;
	ResamplingAbstract *_resampling;
	TimeIntervalListSPtr _timeIntervalList;
	double _sampling;
	double _gapSize;
	ParamData& _refParamData;
	bool _useNearestValue;
3ff2d228   Benjamin Renard   Fix bug in sampli...
1144
	bool _sameParam;
fbe3c2bb   Benjamin Renard   First commit
1145
1146
1147
1148
1149
1150
1151
};

} /* Resampling */
} /* AMDA */
} /* Parameters */

#endif /* Resampling_HH_ */