glviewvol
changeset 5:5417c25cb238
moving to a simpler transfer function
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Mon, 29 Dec 2014 15:59:55 +0200 |
parents | 04330eb80b36 |
children | f22be47a3572 |
files | src/rend_fast.cc src/rend_fast.h src/renderer.cc src/renderer.h src/xfer_view.cc |
diffstat | 5 files changed, 53 insertions(+), 3 deletions(-) [+] |
line diff
1.1 --- a/src/rend_fast.cc Mon Dec 29 05:41:36 2014 +0200 1.2 +++ b/src/rend_fast.cc Mon Dec 29 15:59:55 2014 +0200 1.3 @@ -3,6 +3,8 @@ 1.4 #include "rend_fast.h" 1.5 #include "sdr.h" 1.6 1.7 +static inline float smoothstep(float a, float b, float x); 1.8 + 1.9 #define XFER_MAP_SZ 1024 1.10 1.11 static unsigned int sdr; 1.12 @@ -55,6 +57,12 @@ 1.13 return Renderer::transfer_curve(color); 1.14 } 1.15 1.16 +void RendererFast::set_simple_transfer(float low, float high) 1.17 +{ 1.18 + xfer_tex_valid = false; 1.19 + Renderer::set_simple_transfer(low, high); 1.20 +} 1.21 + 1.22 void RendererFast::update(unsigned int msec) 1.23 { 1.24 if(!vol) return; 1.25 @@ -118,9 +126,18 @@ 1.26 1.27 for(int i=0; i<XFER_MAP_SZ; i++) { 1.28 float x = (float)i / (float)(XFER_MAP_SZ - 1); 1.29 + 1.30 + // TODO make 0.1 a tweakable parameter 1.31 + float val = smoothstep(xfer_low - 0.1, xfer_low + 0.1, x); 1.32 + val *= 1.0 - smoothstep(xfer_high - 0.1, xfer_high + 0.1, x); 1.33 + *pptr++ = val; 1.34 + *pptr++ = val; 1.35 + *pptr++ = val; 1.36 + /* 1.37 *pptr++ = xfer[0].value(x); 1.38 *pptr++ = xfer[1].value(x); 1.39 *pptr++ = xfer[2].value(x); 1.40 + */ 1.41 } 1.42 1.43 glBindTexture(GL_TEXTURE_1D, xfer_tex); 1.44 @@ -168,3 +185,12 @@ 1.45 glMatrixMode(GL_MODELVIEW); 1.46 glPopMatrix(); 1.47 } 1.48 + 1.49 +static inline float smoothstep(float a, float b, float x) 1.50 +{ 1.51 + if(x < a) return 0.0; 1.52 + if(x >= b) return 1.0; 1.53 + 1.54 + x = (x - a) / (b - a); 1.55 + return x * x * (3.0 - 2.0 * x); 1.56 +}
2.1 --- a/src/rend_fast.h Mon Dec 29 05:41:36 2014 +0200 2.2 +++ b/src/rend_fast.h Mon Dec 29 15:59:55 2014 +0200 2.3 @@ -16,6 +16,7 @@ 2.4 2.5 void set_volume(Volume *vol); 2.6 Curve &transfer_curve(int color); 2.7 + void set_simple_transfer(float low, float high); 2.8 2.9 void update(unsigned int msec); 2.10 void render() const;
3.1 --- a/src/renderer.cc Mon Dec 29 05:41:36 2014 +0200 3.2 +++ b/src/renderer.cc Mon Dec 29 15:59:55 2014 +0200 3.3 @@ -12,6 +12,9 @@ 3.4 xfer[i].set_point(1, 1); 3.5 } 3.6 3.7 + xfer_low = 0.0; 3.8 + xfer_high = 1.0; 3.9 + 3.10 for(int i=0; i<MAX_CLIP_PLANES; i++) { 3.11 disable_clipping_plane(i); 3.12 } 3.13 @@ -51,6 +54,18 @@ 3.14 return xfer[color]; 3.15 } 3.16 3.17 +void Renderer::set_simple_transfer(float low, float high) 3.18 +{ 3.19 + xfer_low = std::min(low, high); 3.20 + xfer_high = std::max(low, high); 3.21 +} 3.22 + 3.23 +void Renderer::get_simple_transfer(float *low, float *high) const 3.24 +{ 3.25 + *low = xfer_low; 3.26 + *high = xfer_high; 3.27 +} 3.28 + 3.29 void Renderer::set_clipping_plane(int idx, float nx, float ny, float nz, float dist) 3.30 { 3.31 float len = sqrt(nx * nx + ny * ny + nz * nz);
4.1 --- a/src/renderer.h Mon Dec 29 05:41:36 2014 +0200 4.2 +++ b/src/renderer.h Mon Dec 29 15:59:55 2014 +0200 4.3 @@ -14,6 +14,7 @@ 4.4 float clip_plane[MAX_CLIP_PLANES][4]; // nx,ny,nz,dist 4.5 4.6 Curve xfer[3]; // rgb transfer function 4.7 + float xfer_low, xfer_high; // simple transfer function bounds 4.8 4.9 public: 4.10 Renderer(); 4.11 @@ -28,6 +29,9 @@ 4.12 virtual Curve &transfer_curve(int color); 4.13 virtual const Curve &transfer_curve(int color) const; 4.14 4.15 + virtual void set_simple_transfer(float low, float high); 4.16 + virtual void get_simple_transfer(float *low, float *high) const; 4.17 + 4.18 virtual void set_clipping_plane(int idx, float nx, float ny, float nz, float dist); 4.19 virtual void disable_clipping_plane(int idx); 4.20
5.1 --- a/src/xfer_view.cc Mon Dec 29 05:41:36 2014 +0200 5.2 +++ b/src/xfer_view.cc Mon Dec 29 15:59:55 2014 +0200 5.3 @@ -6,7 +6,7 @@ 5.4 static Renderer *rend; 5.5 5.6 static int act_color = 3; 5.7 -static CurvePoint *cpsel[3]; 5.8 +static CurvePoint *cpsel; 5.9 5.10 bool xfview_init(Renderer *rendarg) 5.11 { 5.12 @@ -109,13 +109,17 @@ 5.13 5.14 void xfview_button(int bn, int press, int x, int y) 5.15 { 5.16 - if(bn == 2 && press) { 5.17 + if(bn == 2 && press && !cpsel) { 5.18 act_color = (act_color + 1) % 4; 5.19 redisplay(); 5.20 return; 5.21 } 5.22 5.23 - if(press) { 5.24 + if(bn == 1) { 5.25 + if(press) { 5.26 + } else { 5.27 + cpsel = 0; 5.28 + } 5.29 } 5.30 } 5.31