Project

General

Profile

Statistics
| Branch: | Revision:

root / src / scave / filternodes.h @ a3be1d55

History | View | Annotate | Download (16.2 KB)

1
//=========================================================================
2
//  FILTERNODES.H - part of
3
//                  OMNeT++/OMNEST
4
//           Discrete System Simulation in C++
5
//
6
//  Author: Andras Varga
7
//
8
//=========================================================================
9

    
10
/*--------------------------------------------------------------*
11
  Copyright (C) 1992-2008 Andras Varga
12
  Copyright (C) 2006-2008 OpenSim Ltd.
13

14
  This file is distributed WITHOUT ANY WARRANTY. See the file
15
  `license' for details on this and other legal matters.
16
*--------------------------------------------------------------*/
17

    
18
#ifndef _FILTERNODES_H_
19
#define _FILTERNODES_H_
20

    
21
#include "commonnodes.h"
22

    
23
NAMESPACE_BEGIN
24

    
25

    
26
/**
27
 * Processing node which does nothing but copying its input to its output.
28
 */
29
class SCAVE_API NopNode : public FilterNode
30
{
31
    public:
32
        NopNode()  {}
33
        virtual ~NopNode() {}
34
        virtual bool isReady() const;
35
        virtual void process();
36
};
37

    
38
class SCAVE_API NopNodeType : public FilterNodeType
39
{
40
    public:
41
        virtual const char *getName() const {return "nop";}
42
        virtual const char *getDescription() const;
43
        virtual void getAttributes(StringMap& attrs) const;
44
        virtual Node *create(DataflowManager *mgr, StringMap& attrs) const;
45
};
46

    
47
//----
48

    
49
/**
50
 * Processing node which adds a constant to every value.
51
 */
52
class SCAVE_API AdderNode : public FilterNode
53
{
54
    protected:
55
        double c;
56
    public:
57
        AdderNode(double c)  {this->c = c;}
58
        virtual ~AdderNode() {}
59
        virtual bool isReady() const;
60
        virtual void process();
61
};
62

    
63
class SCAVE_API AdderNodeType : public FilterNodeType
64
{
65
    public:
66
        virtual const char *getName() const {return "add";}
67
        virtual const char *getDescription() const;
68
        virtual void getAttributes(StringMap& attrs) const;
69
        virtual Node *create(DataflowManager *mgr, StringMap& attrs) const;
70
        virtual void mapVectorAttributes(/*inout*/StringMap &attrs, /*out*/StringVector &warnings) const;
71
};
72

    
73
//----
74

    
75
/**
76
 * Processing node which multiplies every value by a constant.
77
 */
78
class SCAVE_API MultiplierNode : public FilterNode
79
{
80
    protected:
81
        double a;
82
    public:
83
        MultiplierNode(double a)  {this->a = a;}
84
        virtual ~MultiplierNode() {}
85
        virtual bool isReady() const;
86
        virtual void process();
87
};
88

    
89
class SCAVE_API MultiplierNodeType : public FilterNodeType
90
{
91
    public:
92
        virtual const char *getName() const {return "multiply-by";}
93
        virtual const char *getDescription() const;
94
        virtual void getAttributes(StringMap& attrs) const;
95
        virtual void getAttrDefaults(StringMap& attrs) const;
96
        virtual Node *create(DataflowManager *mgr, StringMap& attrs) const;
97
        virtual void mapVectorAttributes(/*inout*/StringMap &attrs, /*out*/StringVector &warnings) const;
98
};
99

    
100
//----
101

    
102
/**
103
 * Processing node which divides every value by a constant.
104
 */
105
class SCAVE_API DividerNode : public FilterNode
106
{
107
    protected:
108
        double a;
109
    public:
110
        DividerNode(double a)  {this->a = a;}
111
        virtual ~DividerNode() {}
112
        virtual bool isReady() const;
113
        virtual void process();
114
};
115

    
116
class SCAVE_API DividerNodeType : public FilterNodeType
117
{
118
    public:
119
        virtual const char *getName() const {return "divide-by";}
120
        virtual const char *getDescription() const;
121
        virtual void getAttributes(StringMap& attrs) const;
122
        virtual void getAttrDefaults(StringMap& attrs) const;
123
        virtual Node *create(DataflowManager *mgr, StringMap& attrs) const;
124
        virtual void mapVectorAttributes(/*inout*/StringMap &attrs, /*out*/StringVector &warnings) const;
125
};
126

    
127
//----
128

    
129
/**
130
 * Processing node which computes value modulo a constant.
131
 */
132
class SCAVE_API ModuloNode : public FilterNode
133
{
134
    protected:
135
        double a;
136
    public:
137
        ModuloNode(double a)  {this->a = a;}
138
        virtual ~ModuloNode() {}
139
        virtual bool isReady() const;
140
        virtual void process();
141
};
142

    
143
class SCAVE_API ModuloNodeType : public FilterNodeType
144
{
145
    public:
146
        virtual const char *getName() const {return "modulo";}
147
        virtual const char *getDescription() const;
148
        virtual void getAttributes(StringMap& attrs) const;
149
        virtual void getAttrDefaults(StringMap& attrs) const;
150
        virtual Node *create(DataflowManager *mgr, StringMap& attrs) const;
151
        virtual void mapVectorAttributes(/*inout*/StringMap &attrs, /*out*/StringVector &warnings) const;
152
};
153

    
154
//----
155

    
156
/**
157
 * Processing node which substracts the previous value from every value
158
 */
159
class SCAVE_API DifferenceNode : public FilterNode
160
{
161
    protected:
162
        double prevy;
163
    public:
164
        DifferenceNode()  {prevy = 0;}
165
        virtual ~DifferenceNode() {}
166
        virtual bool isReady() const;
167
        virtual void process();
168
};
169

    
170
class SCAVE_API DifferenceNodeType : public FilterNodeType
171
{
172
    public:
173
        virtual const char *getName() const {return "difference";}
174
        virtual const char *getDescription() const;
175
        virtual void getAttributes(StringMap& attrs) const;
176
        virtual void getAttrDefaults(StringMap& attrs) const;
177
        virtual Node *create(DataflowManager *mgr, StringMap& attrs) const;
178
        virtual void mapVectorAttributes(/*inout*/StringMap &attrs, /*out*/StringVector &warnings) const;
179
};
180

    
181
//----
182

    
183
/**
184
 * Processing node which substracts the previous value from every value
185
 */
186
class SCAVE_API TimeDiffNode : public FilterNode
187
{
188
    protected:
189
        double prevx;
190
    public:
191
        TimeDiffNode()  {prevx = 0;}
192
        virtual ~TimeDiffNode() {}
193
        virtual bool isReady() const;
194
        virtual void process();
195
};
196

    
197
class SCAVE_API TimeDiffNodeType : public FilterNodeType
198
{
199
    public:
200
        virtual const char *getName() const {return "timediff";}
201
        virtual const char *getDescription() const;
202
        virtual void getAttributes(StringMap& attrs) const;
203
        virtual void getAttrDefaults(StringMap& attrs) const;
204
        virtual Node *create(DataflowManager *mgr, StringMap& attrs) const;
205
        virtual void mapVectorAttributes(/*inout*/StringMap &attrs, /*out*/StringVector &warnings) const;
206
};
207

    
208
//----
209

    
210
/**
211
 * Processing node which calculates moving average
212
 */
213
class SCAVE_API MovingAverageNode : public FilterNode
214
{
215
    protected:
216
        double alpha;
217
        bool firstRead;
218
        double prevy;
219
    public:
220
        MovingAverageNode(double alph);
221
        virtual ~MovingAverageNode() {}
222
        virtual bool isReady() const;
223
        virtual void process();
224
};
225

    
226
class SCAVE_API MovingAverageNodeType : public FilterNodeType
227
{
228
    public:
229
        virtual const char *getName() const {return "movingavg";}
230
        virtual const char *getDescription() const;
231
        virtual void getAttributes(StringMap& attrs) const;
232
        virtual void getAttrDefaults(StringMap& attrs) const;
233
        virtual Node *create(DataflowManager *mgr, StringMap& attrs) const;
234
        virtual void mapVectorAttributes(/*inout*/StringMap &attrs, /*out*/StringVector &warnings) const;
235
};
236

    
237
//----
238

    
239
/**
240
 * Processing node which sums up values
241
 */
242
class SCAVE_API SumNode : public FilterNode
243
{
244
    protected:
245
        double sum;
246
    public:
247
        SumNode()    {sum = 0;}
248
        virtual ~SumNode() {}
249
        virtual bool isReady() const;
250
        virtual void process();
251
};
252

    
253
class SCAVE_API SumNodeType : public FilterNodeType
254
{
255
    public:
256
        virtual const char *getName() const {return "sum";}
257
        virtual const char *getDescription() const;
258
        virtual void getAttributes(StringMap& attrs) const;
259
        virtual void getAttrDefaults(StringMap& attrs) const;
260
        virtual Node *create(DataflowManager *mgr, StringMap& attrs) const;
261
        virtual void mapVectorAttributes(/*inout*/StringMap &attrs, /*out*/StringVector &warnings) const;
262
};
263
//----
264

    
265
/**
266
 * Processing node which shifts every value in time.
267
 */
268
class SCAVE_API TimeShiftNode : public FilterNode
269
{
270
    protected:
271
        double dt;
272
    public:
273
        TimeShiftNode(double dt)  {this->dt = dt;}
274
        virtual ~TimeShiftNode() {}
275
        virtual bool isReady() const;
276
        virtual void process();
277
};
278

    
279
class SCAVE_API TimeShiftNodeType : public FilterNodeType
280
{
281
    public:
282
        virtual const char *getName() const {return "timeshift";}
283
        virtual const char *getDescription() const;
284
        virtual void getAttributes(StringMap& attrs) const;
285
        virtual Node *create(DataflowManager *mgr, StringMap& attrs) const;
286
};
287

    
288
//----
289

    
290
/**
291
 * Processing node which adds linear trend to its input.
292
 */
293
class SCAVE_API LinearTrendNode : public FilterNode
294
{
295
    protected:
296
        double a;
297
    public:
298
        LinearTrendNode(double a)  {this->a = a;}
299
        virtual ~LinearTrendNode() {}
300
        virtual bool isReady() const;
301
        virtual void process();
302
};
303

    
304
class SCAVE_API LinearTrendNodeType : public FilterNodeType
305
{
306
    public:
307
        virtual const char *getName() const {return "lineartrend";}
308
        virtual const char *getDescription() const;
309
        virtual void getAttributes(StringMap& attrs) const;
310
        virtual void getAttrDefaults(StringMap& attrs) const;
311
        virtual Node *create(DataflowManager *mgr, StringMap& attrs) const;
312
        virtual void mapVectorAttributes(/*inout*/StringMap &attrs, /*out*/StringVector &warnings) const;
313
};
314

    
315
//----
316

    
317
/**
318
 * Processing node which deletes values outside a specified time interval.
319
 */
320
class SCAVE_API CropNode : public FilterNode
321
{
322
    protected:
323
        double from, to;
324
    public:
325
        CropNode(double from, double to)  {this->from = from; this->to = to;}
326
        virtual ~CropNode() {}
327
        virtual bool isReady() const;
328
        virtual void process();
329
};
330

    
331
class SCAVE_API CropNodeType : public FilterNodeType
332
{
333
    public:
334
        virtual const char *getName() const {return "crop";}
335
        virtual const char *getDescription() const;
336
        virtual void getAttributes(StringMap& attrs) const;
337
        virtual Node *create(DataflowManager *mgr, StringMap& attrs) const;
338
};
339

    
340
//----
341

    
342
/**
343
 * Processing node which calculates mean on (0,t)
344
 */
345
class SCAVE_API MeanNode : public FilterNode
346
{
347
    protected:
348
        double sum;
349
        long count;
350
    public:
351
        MeanNode()  {sum=0; count=0;}
352
        virtual ~MeanNode() {}
353
        virtual bool isReady() const;
354
        virtual void process();
355
};
356

    
357
class SCAVE_API MeanNodeType : public FilterNodeType
358
{
359
    public:
360
        virtual const char *getName() const {return "mean";}
361
        virtual const char *getDescription() const;
362
        virtual void getAttributes(StringMap& attrs) const;
363
        virtual Node *create(DataflowManager *mgr, StringMap& attrs) const;
364
        virtual void mapVectorAttributes(/*inout*/StringMap &attrs, /*out*/StringVector &warnings) const;
365
};
366

    
367
//----
368

    
369
/**
370
 * Processing node which removes repeated y values.
371
 */
372
class SCAVE_API RemoveRepeatsNode : public FilterNode
373
{
374
    protected:
375
        bool first;
376
        double prevy;
377
    public:
378
        RemoveRepeatsNode()  {first = true;}
379
        virtual ~RemoveRepeatsNode() {}
380
        virtual bool isReady() const;
381
        virtual void process();
382
};
383

    
384
class SCAVE_API RemoveRepeatsNodeType : public FilterNodeType
385
{
386
    public:
387
        virtual const char *getName() const {return "removerepeats";}
388
        virtual const char *getDescription() const;
389
        virtual void getAttributes(StringMap& attrs) const;
390
        virtual void getAttrDefaults(StringMap& attrs) const;
391
        virtual Node *create(DataflowManager *mgr, StringMap& attrs) const;
392
        virtual void mapVectorAttributes(/*inout*/StringMap &attrs, /*out*/StringVector &warnings) const;
393
};
394

    
395
//----
396

    
397
/**
398
 * Processing node which compares the value against a constant.
399
 */
400
class SCAVE_API CompareNode : public FilterNode
401
{
402
    protected:
403
        double threshold;
404
        bool replaceIfLess;
405
        bool replaceIfGreater;
406
        bool replaceIfEqual;
407
        double valueIfLess;
408
        double valueIfGreater;
409
        double valueIfEqual;
410
    public:
411
        CompareNode()  {replaceIfLess = replaceIfGreater = replaceIfEqual = false;}
412
        virtual ~CompareNode() {}
413

    
414
        void setThreshold(double d)  {threshold = d;}
415
        void setLessValue(double d)  {valueIfLess = d; replaceIfLess = true;}
416
        void setEqualValue(double d)  {valueIfEqual = d; replaceIfEqual = true;}
417
        void setGreaterValue(double d)  {valueIfGreater = d; replaceIfGreater = true;}
418

    
419
        virtual bool isReady() const;
420
        virtual void process();
421
};
422

    
423
class SCAVE_API CompareNodeType : public FilterNodeType
424
{
425
    public:
426
        virtual const char *getName() const {return "compare";}
427
        virtual const char *getDescription() const;
428
        virtual void getAttributes(StringMap& attrs) const;
429
        virtual void getAttrDefaults(StringMap& attrs) const;
430
        virtual Node *create(DataflowManager *mgr, StringMap& attrs) const;
431
};
432

    
433
//----
434

    
435
/**
436
 * Processing node which regards the input as a step function
437
 * ("sample-hold"), and integrates it.
438
 */
439
class SCAVE_API IntegrateNode : public FilterNode
440
{
441
    protected:
442
        InterpolationMode interpolationmode;
443
        bool isPrevValid; // false before collecting the 1st value
444
        double integral;
445
        double prevx, prevy;
446
    public:
447
        IntegrateNode(InterpolationMode mode)  {interpolationmode = mode; integral = prevx = prevy = 0; isPrevValid = false;}
448
        virtual ~IntegrateNode() {}
449

    
450
        virtual bool isReady() const;
451
        virtual void process();
452
};
453

    
454
class SCAVE_API IntegrateNodeType : public FilterNodeType
455
{
456
    public:
457
        virtual const char *getName() const {return "integrate";}
458
        virtual const char *getDescription() const;
459
        virtual void getAttributes(StringMap& attrs) const;
460
        virtual void getAttrDefaults(StringMap& attrs) const;
461
        virtual Node *create(DataflowManager *mgr, StringMap& attrs) const;
462
        virtual void mapVectorAttributes(/*inout*/StringMap &attrs, /*out*/StringVector &warnings) const;
463
};
464

    
465
//----
466

    
467
/**
468
 * Processing node which calculates time average
469
 */
470
class SCAVE_API TimeAverageNode : public FilterNode
471
{
472
    protected:
473
        InterpolationMode interpolationmode;
474
        bool isPrevValid; // false before collecting the 1st value
475
        double integral;
476
        double startx;
477
        double prevx, prevy;
478
    public:
479
        TimeAverageNode(InterpolationMode mode)  {interpolationmode = mode; integral = startx = prevx = prevy = 0; isPrevValid = false;}
480
        virtual ~TimeAverageNode() {}
481

    
482
        virtual bool isReady() const;
483
        virtual void process();
484
};
485

    
486
class SCAVE_API TimeAverageNodeType : public FilterNodeType
487
{
488
    public:
489
        virtual const char *getName() const {return "timeavg";}
490
        virtual const char *getDescription() const;
491
        virtual void getAttributes(StringMap& attrs) const;
492
        virtual void getAttrDefaults(StringMap& attrs) const;
493
        virtual Node *create(DataflowManager *mgr, StringMap& attrs) const;
494
        virtual void mapVectorAttributes(/*inout*/StringMap &attrs, /*out*/StringVector &warnings) const;
495
};
496

    
497
//----
498

    
499
/**
500
 * Processing node that divides each value by t.
501
 */
502
class SCAVE_API DivideByTimeNode : public FilterNode
503
{
504
    public:
505
        DivideByTimeNode()  {}
506
        virtual ~DivideByTimeNode() {}
507

    
508
        virtual bool isReady() const;
509
        virtual void process();
510
};
511

    
512
class SCAVE_API DivideByTimeNodeType : public FilterNodeType
513
{
514
    public:
515
        virtual const char *getName() const {return "divtime";}
516
        virtual const char *getDescription() const;
517
        virtual void getAttributes(StringMap& attrs) const;
518
        virtual Node *create(DataflowManager *mgr, StringMap& attrs) const;
519
        virtual void mapVectorAttributes(/*inout*/StringMap &attrs, /*out*/StringVector &warnings) const;
520
};
521

    
522
/**
523
 * Processing node that replaces t values with their serial.
524
 */
525
class SCAVE_API TimeToSerialNode : public FilterNode
526
{
527
    protected:
528
        int64 serial;
529
    public:
530
        TimeToSerialNode() : serial(0) {}
531
        virtual ~TimeToSerialNode() {}
532

    
533
        virtual bool isReady() const;
534
        virtual void process();
535
};
536

    
537
class SCAVE_API TimeToSerialNodeType : public FilterNodeType
538
{
539
    public:
540
        virtual const char *getName() const {return "timetoserial";}
541
        virtual const char *getDescription() const;
542
        virtual void getAttributes(StringMap& attrs) const;
543
        virtual Node *create(DataflowManager *mgr, StringMap& attrs) const;
544
        virtual void mapVectorAttributes(/*inout*/StringMap &attrs, /*out*/StringVector &warnings) const;
545
};
546

    
547
NAMESPACE_END
548

    
549
#endif
550