Loading...
Searching...
No Matches
Intensity.h
1/*
2
3MIT License
4
5Copyright (c) 2017 FMI Open Development / Markus Peura, first.last@fmi.fi
6
7Permission is hereby granted, free of charge, to any person obtaining a copy
8of this software and associated documentation files (the "Software"), to deal
9in the Software without restriction, including without limitation the rights
10to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11copies of the Software, and to permit persons to whom the Software is
12furnished to do so, subject to the following conditions:
13
14The above copyright notice and this permission notice shall be included in all
15copies or substantial portions of the Software.
16
17THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23SOFTWARE.
24
25*/
26/*
27Part of Rack development has been done in the BALTRAD projects part-financed
28by the European Union (European Regional Development Fund and European
29Neighbourhood 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
40namespace drain
41{
42
43namespace image
44{
45
46
47//template <class T>
49{
50public:
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