Intensity.h
1 /*
2 
3 MIT License
4 
5 Copyright (c) 2017 FMI Open Development / Markus Peura, first.last@fmi.fi
6 
7 Permission is hereby granted, free of charge, to any person obtaining a copy
8 of this software and associated documentation files (the "Software"), to deal
9 in the Software without restriction, including without limitation the rights
10 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 copies of the Software, and to permit persons to whom the Software is
12 furnished to do so, subject to the following conditions:
13 
14 The above copyright notice and this permission notice shall be included in all
15 copies or substantial portions of the Software.
16 
17 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 SOFTWARE.
24 
25 */
26 /*
27 Part of Rack development has been done in the BALTRAD projects part-financed
28 by the European Union (European Regional Development Fund and European
29 Neighbourhood Partnership Instrument, Baltic Sea Region Programme 2007-2013)
30 */
31 #ifndef INTENSITY_H_
32 #define INTENSITY_H_
33 
34 
35 #include <limits>
36 //#include <math.h>
37 //#include <cmath>
38 #include <algorithm>
39 
40 namespace drain
41 {
42 
43 namespace image
44 {
45 
46 
47 //template <class T>
48 class Intensity
49 {
50 public:
51 
53 
66  // TODO: CAST (low-level binary cast)?
67  typedef enum {NONE,DEFAULT,RANGE} scalingMode;
68 
70 
72  template <class T>
73  inline
74  static T min(){ return std::numeric_limits<T>::is_integer ? std::numeric_limits<T>::min() : 0; }
75 
77  template <class T>
78  inline
79  static T max(){ return std::numeric_limits<T>::is_integer ? std::numeric_limits<T>::max() : 1; }
80 
82  template <class T>
83  inline
84  static T maxOrigin(){ return std::numeric_limits<T>::is_integer ? std::numeric_limits<T>::max() : 0; }
85 
86 
88  template <class T>
89  static T limit(double x){
90  static const double xMin = static_cast<double>(
91  std::numeric_limits<T>::is_integer ? std::numeric_limits<T>::min() : -std::numeric_limits<T>::max() );
92  static const double xMax = static_cast<double>( std::numeric_limits<T>::max() );
93  x = std::max(xMin,x);
94  x = std::min(x,xMax);
95  return static_cast<T>(x);
96  }
97 
98 };
99 
100 
101 
102 }
103 
104 }
105 
106 #endif /*INTENSITY_H_*/
107 
108 // Drain
Definition: Intensity.h:49
static T max()
For floating-point values, returns 1.0, otherwise the upper limit of the range.
Definition: Intensity.h:79
static T min()
TODO: is this [0...1] limitation for floats valid?
Definition: Intensity.h:74
scalingMode
For setting mode of conversions between unsigned and signed numbers, and between integers and floats.
Definition: Intensity.h:67
static T maxOrigin()
Value to be used in inverting numbers; returns 0.0 for floating-point values.
Definition: Intensity.h:84
static T limit(double x)
Ensures that the value stays within the numeric range of T2.
Definition: Intensity.h:89
Definition: DataSelector.cpp:1277