Functors.h 5.09 KB
Newer Older
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
/** \file Functors.h */

#ifndef AMDIS_FUNCTORS_H
#define AMDIS_FUNCTORS_H

#include "AbstractFunction.h"

namespace AMDiS {

template<typename T>
struct Id : public AbstractFunction<T,T>
{
  T operator()(const T &v) const { return v; }
};

template<typename T1,typename T2>
struct Const : public AbstractFunction<T1,T2>
{
  Const(T1 val_) : val(val_) {}
  T1 operator()(const T2 &v) const { return val; }
private:
  T1 val;
};

template<typename T>
struct Factor : public AbstractFunction<T,T>
{
  Factor(double fac_) : fac(fac_) {}
  T operator()(const T& x) const { return fac*x; };
private:
  double fac;
};

template<typename T>
struct Add : public BinaryAbstractFunction<T,T,T>
{
  T operator()(const T &v1, const T &v2) const { return v1+v2; }
};

template<typename T>
struct AddFactor : public BinaryAbstractFunction<T,T,T>
{
  AddFactor(double factor_ = 1.0) : factor(factor_) {}
  T operator()(const T &v1, const T &v2) const { return v1 + factor*v2; }
private:
  double factor;
};

template<typename T>
struct Subtract : public BinaryAbstractFunction<T,T,T>
{
  T operator()(const T &v1, const T &v2) const { return v1-v2; }
};

template<typename T>
struct AddScal : public AbstractFunction<T,T>
{
  AddScal(T scal_) : scal(scal_) {}
  T operator()(const T &v) const { return v+scal; }
private:
  T scal;
};

template<typename T>
struct Mult : public BinaryAbstractFunction<T,T,T>
{
  T operator()(const T &v1, const T &v2) const { return v1*v2; }
};

template<typename T1, typename T2, typename T3>
struct Mult2 : public BinaryAbstractFunction<T1,T2,T3>
{
  T1 operator()(const T2 &v1, const T3 &v2) const { return v1*v2; }
};

template<typename T>
struct MultScal : public AbstractFunction<T,T>
{
  MultScal(T scal_) : scal(scal_) {}
  T operator()(const T &v) const { return v*scal; }
private:
  T scal;
};

template<typename T>
struct Max : public BinaryAbstractFunction<T,T,T>
{
  T operator()(const T &v1, const T &v2) const { return std::max(v1,v2); }
};

template<typename T>
struct Min : public BinaryAbstractFunction<T,T,T>
{
  T operator()(const T &v1, const T &v2) const { return std::min(v1,v2); }
};

template<typename T>
struct Diff : public BinaryAbstractFunction<T,T,T>
{
  T operator()(const T &v1, const T &v2) const { return abs(v1-v2); }
};

template<typename T>
struct L1Diff : public BinaryAbstractFunction<T,T,T>
{
  T operator()(const T &v1, const T &v2) const { return abs(v1-v2); }
};

template<typename T>
struct L2Diff : public BinaryAbstractFunction<T,T,T>
{
  T operator()(const T &v1, const T &v2) const { return sqr(v1-v2); }
};

template<typename T>
struct Abs : public AbstractFunction<T,T>
{
  T operator()(const T &v) const { return abs(v); }
};

template<typename T>
struct Signum : public AbstractFunction<T,T>
{
  T operator()(const T &v) const { return (v>0.0?1.0:(v<0.0?-1.0:0.0)); }
};

template<typename T>
struct Sqr : public AbstractFunction<T,T>
{
  T operator()(const T &v) const { return sqr(v); }
};

template<typename T>
struct Sqrt : public AbstractFunction<T,T>
{
  T operator()(const T &v) const { return sqrt(v); }
};

template<typename T>
struct Pow : public AbstractFunction<T,T>
{
  Pow(double p_) : p(p_) {}
  T operator()(const T &v) const { return pow(v,p); }
private:
  double p;
};

template<typename T1, typename T2>
struct Norm2 : public AbstractFunction<T1,T2>
{
  T1 operator()(const T2 &v) const { return sqrt(v*v); }
};

template<typename T1, typename T2>
struct Norm2Sqr : public AbstractFunction<T1,T2>
{
  T1 operator()(const T2 &v) const { return v*v; }
};

template<typename T>
struct Norm2_comp2 : public BinaryAbstractFunction<T,T,T>
{
  T operator()(const T &v1, const T &v2) const { return sqrt(sqr(v1)+sqr(v2)); }
};

template<typename T>
struct Norm2Sqr_comp2 : public BinaryAbstractFunction<T,T,T>
{
  T operator()(const T &v1, const T &v2) const { return sqr(v1)+sqr(v2); }
};

template<typename T>
struct Norm2_comp3 : public TertiaryAbstractFunction<T,T,T,T>
{
  T operator()(const T &v1, const T &v2, const T &v3) const { return sqrt(sqr(v1)+sqr(v2)+sqr(v3)); }
};

template<typename T>
struct Norm2Sqr_comp3 : public TertiaryAbstractFunction<T,T,T,T>
{
  T operator()(const T &v1, const T &v2, const T &v3) const { return sqr(v1)+sqr(v2)+sqr(v3); }
};

184
185
186
187
188
189
190
191
192
template<typename T>
struct Vec1WorldVec : public AbstractFunction<WorldVector<T>,T>
{
  WorldVector<T> operator()(const T &v0) const {
    WorldVector<T> result;
    result[0]=v0;
    return result;
  }
};
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
template<typename T>
struct Vec2WorldVec : public BinaryAbstractFunction<WorldVector<T>,T,T>
{
  WorldVector<T> operator()(const T &v0, const T &v1) const {
    WorldVector<T> result;
    result[0]=v0; result[1]=v1;
    return result;
  }
};
template<typename T>
struct Vec3WorldVec : public TertiaryAbstractFunction<WorldVector<T>,T,T,T>
{
  WorldVector<T> operator()(const T &v0, const T &v1, const T &v2) const {
    WorldVector<T> result;
    result[0]=v0; result[1]=v1; result[2]=v2;
    return result;
  }
};

struct FadeOut : public TertiaryAbstractFunction<double, double, double ,double>
{
  double operator()(const double &v, const double &dist, const double &mean) const {
    return dist*mean+(1.0-dist)*v;
  }
};

}

#endif // AMDIS_FUNCTORS_H