STIR 6.4.0
stir_math.h
1/*
2 Copyright (C) 2016, UCL
3 This file is part of STIR.
4
5 SPDX-License-Identifier: Apache-2.0
6
7 See STIR/LICENSE.txt for details
8*/
9
10#ifndef __stir_STIR_MATH_H__
11#define __stir_STIR_MATH_H__
12
13using std::cout;
14using std::endl;
15using std::fstream;
16using std::transform;
17using std::max;
18using std::min;
19using std::string;
20using std::vector;
21
22USING_NAMESPACE_STIR
23
24// Nikos Efthimiou: Minimal header file to be able to use this class from other
25// places in the code.
26
27// a function object that takes a power of a float, and then multiplies with a float, and finally adds a float
28class pow_times_add
29{
30public:
31 pow_times_add(
32 const float add_scalar, const float mult_scalar, const float power, const float min_threshold, const float max_threshold)
33 : add(add_scalar),
34 mult(mult_scalar),
35 power(power),
36 min_threshold(min_threshold),
37 max_threshold(max_threshold)
38 {}
39
40 float operator()(float const arg) const
41 {
42 const float value = min(max(arg, min_threshold), max_threshold);
43 return add + mult * (power == 1 ? value : pow(value, power));
44 }
45
46private:
47 const float add;
48 const float mult;
49 const float power;
50 const float min_threshold;
51 const float max_threshold;
52};
53
54#endif