rev |
line source |
nuclear@6
|
1 #include <algorithm>
|
nuclear@6
|
2 #include "xfermap.h"
|
nuclear@6
|
3
|
nuclear@6
|
4 TransferFunc::~TransferFunc()
|
nuclear@6
|
5 {
|
nuclear@6
|
6 }
|
nuclear@6
|
7
|
nuclear@6
|
8
|
nuclear@6
|
9 // ---- TransferWindow ----
|
nuclear@6
|
10
|
nuclear@6
|
11 TransferWindow::TransferWindow()
|
nuclear@6
|
12 {
|
nuclear@6
|
13 soft_rad = 0.5;
|
nuclear@6
|
14 for(int i=0; i<4; i++) {
|
nuclear@6
|
15 low[i] = 0.5;
|
nuclear@6
|
16 high[i] = 2.0;
|
nuclear@6
|
17 }
|
nuclear@6
|
18 }
|
nuclear@6
|
19
|
nuclear@6
|
20 void TransferWindow::set_interval(float a, float b)
|
nuclear@6
|
21 {
|
nuclear@6
|
22 float v0 = std::min(a, b);
|
nuclear@6
|
23 float v1 = std::max(a, b);
|
nuclear@6
|
24
|
nuclear@6
|
25 for(int i=0; i<4; i++) {
|
nuclear@6
|
26 low[i] = v0;
|
nuclear@6
|
27 high[i] = v1;
|
nuclear@6
|
28 }
|
nuclear@6
|
29 }
|
nuclear@6
|
30
|
nuclear@6
|
31 void TransferWindow::set_interval(float *rgba_low, float *rgba_high)
|
nuclear@6
|
32 {
|
nuclear@6
|
33 for(int i=0; i<4; i++) {
|
nuclear@6
|
34 low[i] = std::min(rgba_low[i], rgba_high[i]);
|
nuclear@6
|
35 high[i] = std::max(rgba_low[i], rgba_high[i]);
|
nuclear@6
|
36 }
|
nuclear@6
|
37 }
|
nuclear@6
|
38
|
nuclear@6
|
39 void TransferWindow::set_interval_rgba(int channel, float a, float b)
|
nuclear@6
|
40 {
|
nuclear@6
|
41 low[channel] = std::min(a, b);
|
nuclear@6
|
42 high[channel] = std::max(a, b);
|
nuclear@6
|
43 }
|
nuclear@6
|
44
|
nuclear@6
|
45 void TransferWindow::set_soft_radius(float s)
|
nuclear@6
|
46 {
|
nuclear@6
|
47 soft_rad = s;
|
nuclear@6
|
48 }
|
nuclear@6
|
49
|
nuclear@6
|
50 float TransferWindow::get_soft_radius() const
|
nuclear@6
|
51 {
|
nuclear@6
|
52 return soft_rad;
|
nuclear@6
|
53 }
|
nuclear@6
|
54
|
nuclear@6
|
55 static inline float smoothstep(float a, float b, float x)
|
nuclear@6
|
56 {
|
nuclear@6
|
57 if(x < a) return 0.0f;
|
nuclear@6
|
58 if(x >= b) return 1.0f;
|
nuclear@6
|
59
|
nuclear@6
|
60 float t = (x - a) / (b - a);
|
nuclear@6
|
61 return t * t * (3.0f - 2.0f * t);
|
nuclear@6
|
62 }
|
nuclear@6
|
63
|
nuclear@6
|
64 float TransferWindow::map(float x) const
|
nuclear@6
|
65 {
|
nuclear@6
|
66 return smoothstep(low[3] - soft_rad, high[3] - soft_rad, x) *
|
nuclear@6
|
67 (1.0 - smoothstep(low[3] + soft_rad, high[3] + soft_rad, x));
|
nuclear@6
|
68 }
|
nuclear@6
|
69
|
nuclear@6
|
70 void TransferWindow::map(float x, float *rgba_value) const
|
nuclear@6
|
71 {
|
nuclear@6
|
72 for(int i=0; i<4; i++) {
|
nuclear@6
|
73 float val = smoothstep(low[i] - soft_rad, high[i] - soft_rad, x);
|
nuclear@6
|
74 val *= 1.0 - smoothstep(low[i] + soft_rad, high[i] + soft_rad, x);
|
nuclear@6
|
75 rgba_value[i] = val;
|
nuclear@6
|
76 }
|
nuclear@6
|
77 }
|