Commit 68b18f9a authored by Praetorius, Simon's avatar Praetorius, Simon

Functors for transformDOF added

parent e7e195f6
/** \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); }
};
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
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment