glviewvol
diff src/xfermap.cc @ 6:f22be47a3572
moved to TransferFuncs completely
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Tue, 30 Dec 2014 06:22:54 +0200 |
parents | |
children | 71b479ffb9f7 |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/xfermap.cc Tue Dec 30 06:22:54 2014 +0200 1.3 @@ -0,0 +1,77 @@ 1.4 +#include <algorithm> 1.5 +#include "xfermap.h" 1.6 + 1.7 +TransferFunc::~TransferFunc() 1.8 +{ 1.9 +} 1.10 + 1.11 + 1.12 +// ---- TransferWindow ---- 1.13 + 1.14 +TransferWindow::TransferWindow() 1.15 +{ 1.16 + soft_rad = 0.5; 1.17 + for(int i=0; i<4; i++) { 1.18 + low[i] = 0.5; 1.19 + high[i] = 2.0; 1.20 + } 1.21 +} 1.22 + 1.23 +void TransferWindow::set_interval(float a, float b) 1.24 +{ 1.25 + float v0 = std::min(a, b); 1.26 + float v1 = std::max(a, b); 1.27 + 1.28 + for(int i=0; i<4; i++) { 1.29 + low[i] = v0; 1.30 + high[i] = v1; 1.31 + } 1.32 +} 1.33 + 1.34 +void TransferWindow::set_interval(float *rgba_low, float *rgba_high) 1.35 +{ 1.36 + for(int i=0; i<4; i++) { 1.37 + low[i] = std::min(rgba_low[i], rgba_high[i]); 1.38 + high[i] = std::max(rgba_low[i], rgba_high[i]); 1.39 + } 1.40 +} 1.41 + 1.42 +void TransferWindow::set_interval_rgba(int channel, float a, float b) 1.43 +{ 1.44 + low[channel] = std::min(a, b); 1.45 + high[channel] = std::max(a, b); 1.46 +} 1.47 + 1.48 +void TransferWindow::set_soft_radius(float s) 1.49 +{ 1.50 + soft_rad = s; 1.51 +} 1.52 + 1.53 +float TransferWindow::get_soft_radius() const 1.54 +{ 1.55 + return soft_rad; 1.56 +} 1.57 + 1.58 +static inline float smoothstep(float a, float b, float x) 1.59 +{ 1.60 + if(x < a) return 0.0f; 1.61 + if(x >= b) return 1.0f; 1.62 + 1.63 + float t = (x - a) / (b - a); 1.64 + return t * t * (3.0f - 2.0f * t); 1.65 +} 1.66 + 1.67 +float TransferWindow::map(float x) const 1.68 +{ 1.69 + return smoothstep(low[3] - soft_rad, high[3] - soft_rad, x) * 1.70 + (1.0 - smoothstep(low[3] + soft_rad, high[3] + soft_rad, x)); 1.71 +} 1.72 + 1.73 +void TransferWindow::map(float x, float *rgba_value) const 1.74 +{ 1.75 + for(int i=0; i<4; i++) { 1.76 + float val = smoothstep(low[i] - soft_rad, high[i] - soft_rad, x); 1.77 + val *= 1.0 - smoothstep(low[i] + soft_rad, high[i] + soft_rad, x); 1.78 + rgba_value[i] = val; 1.79 + } 1.80 +}