glviewvol

changeset 10:89efc666105c

mostly done
author John Tsiombikas <nuclear@member.fsf.org>
date Wed, 31 Dec 2014 05:21:47 +0200
parents 931a6b35f1cd
children 73edd1b7c2da
files sdr/fast.p.glsl sdr/fast.v.glsl src/dicomview.cc src/rend_fast.cc src/renderer.cc src/renderer.h
diffstat 6 files changed, 68 insertions(+), 31 deletions(-) [+]
line diff
     1.1 --- a/sdr/fast.p.glsl	Tue Dec 30 21:20:57 2014 +0200
     1.2 +++ b/sdr/fast.p.glsl	Wed Dec 31 05:21:47 2014 +0200
     1.3 @@ -1,16 +1,18 @@
     1.4 +#version 120
     1.5 +
     1.6  uniform sampler3D vol_tex;
     1.7  uniform sampler1D xfer_tex;
     1.8  
     1.9 -const vec3 light_dir[3] = {
    1.10 +uniform vec3 light_dir[3] = vec3[3](
    1.11  	vec3(0.5, 0.5, 1.0),
    1.12  	vec3(-1.0, 0.2, 0.5),
    1.13  	vec3(-0.2, 0.0, -7.0)
    1.14 -};
    1.15 -const vec3 light_color[3] = {
    1.16 +);
    1.17 +uniform vec3 light_color[3] = vec3[3](
    1.18  	vec3(0.9, 0.7, 0.68),
    1.19  	vec3(0.5, 0.6, 0.9),
    1.20  	vec3(0.3, 0.3, 0.3)
    1.21 -};	
    1.22 +);	
    1.23  
    1.24  const vec3 ambient = vec3(0.1, 0.1, 0.1);
    1.25  const vec3 vdir = vec3(0.0, 0.0, 1.0);
     2.1 --- a/sdr/fast.v.glsl	Tue Dec 30 21:20:57 2014 +0200
     2.2 +++ b/sdr/fast.v.glsl	Wed Dec 31 05:21:47 2014 +0200
     2.3 @@ -1,3 +1,5 @@
     2.4 +uniform float zscale;
     2.5 +
     2.6  void main()
     2.7  {
     2.8  	mat4 mvmat = gl_ModelViewMatrix;
     2.9 @@ -6,5 +8,5 @@
    2.10  
    2.11  	vec4 vertex = gl_Vertex;
    2.12  	gl_Position = gl_ProjectionMatrix * mvmat * vertex;
    2.13 -	gl_TexCoord[0].xyz = gl_NormalMatrix * (vertex.xyz * vec3(1.0, 1.0, -1.0) * 1.732051) * 0.5 + 0.5;
    2.14 +	gl_TexCoord[0].xyz = gl_NormalMatrix * (vertex.xyz * vec3(1.0, 1.0, -1.0) * 1.732051) * vec3(1.0, 1.0, zscale) * 0.5 + 0.5;
    2.15  }
     3.1 --- a/src/dicomview.cc	Tue Dec 30 21:20:57 2014 +0200
     3.2 +++ b/src/dicomview.cc	Wed Dec 31 05:21:47 2014 +0200
     3.3 @@ -134,43 +134,51 @@
     3.4  	}
     3.5  }
     3.6  
     3.7 +static bool zscaling;
     3.8 +
     3.9  void ev_keyboard(int key, int press, int x, int y)
    3.10  {
    3.11  	RendererFast *fr;
    3.12  
    3.13 -	if(press) {
    3.14 -		switch(key) {
    3.15 -		case 27:
    3.16 +	switch(key) {
    3.17 +	case 27:
    3.18 +		if(press) {
    3.19  			quit();
    3.20 +		}
    3.21 +		break;
    3.22  
    3.23 -		case '=':
    3.24 -			if((fr = dynamic_cast<RendererFast*>(rend))) {
    3.25 -				int n = fr->get_proxy_count();
    3.26 -				int add = n / 4;
    3.27 -				n += add < 1 ? 1 : add;
    3.28 -				printf("proxy count: %d\n", n);
    3.29 -				fr->set_proxy_count(n);
    3.30 -			}
    3.31 +	case 'z':
    3.32 +	case 'Z':
    3.33 +		zscaling = press;
    3.34 +		break;
    3.35 +
    3.36 +	case '=':
    3.37 +		if(press && (fr = dynamic_cast<RendererFast*>(rend))) {
    3.38 +			int n = fr->get_proxy_count();
    3.39 +			int add = n / 4;
    3.40 +			n += add < 1 ? 1 : add;
    3.41 +			printf("proxy count: %d\n", n);
    3.42 +			fr->set_proxy_count(n);
    3.43  			redisplay();
    3.44 -			break;
    3.45 +		}
    3.46 +		break;
    3.47  
    3.48 -		case '-':
    3.49 -			if((fr = dynamic_cast<RendererFast*>(rend))) {
    3.50 -				int n = fr->get_proxy_count();
    3.51 -				int sub = n / 4;
    3.52 -				n -= sub < 1 ? 1 : sub;
    3.53 +	case '-':
    3.54 +		if(press && (fr = dynamic_cast<RendererFast*>(rend))) {
    3.55 +			int n = fr->get_proxy_count();
    3.56 +			int sub = n / 4;
    3.57 +			n -= sub < 1 ? 1 : sub;
    3.58  
    3.59 -				if(n < 1) n = 1;
    3.60 +			if(n < 1) n = 1;
    3.61  
    3.62 -				printf("proxy count: %d\n", n);
    3.63 -				fr->set_proxy_count(n);
    3.64 -			}
    3.65 +			printf("proxy count: %d\n", n);
    3.66 +			fr->set_proxy_count(n);
    3.67  			redisplay();
    3.68 -			break;
    3.69 +		}
    3.70 +		break;
    3.71  
    3.72 -		default:
    3.73 -			break;
    3.74 -		}
    3.75 +	default:
    3.76 +		break;
    3.77  	}
    3.78  }
    3.79  
    3.80 @@ -202,6 +210,13 @@
    3.81  
    3.82  	if((dx | dy) == 0) return;
    3.83  
    3.84 +	if(bnstate[0] && zscaling) {
    3.85 +		float s = rend->get_zscale() + (float)dy / (float)win_height;
    3.86 +		rend->set_zscale(s < 0.0 ? 0.0 : s);
    3.87 +		redisplay();
    3.88 +		return;
    3.89 +	}
    3.90 +
    3.91  	if(splitter_dragging) {
    3.92  		splitter_y += dy;
    3.93  		redisplay();
     4.1 --- a/src/rend_fast.cc	Tue Dec 30 21:20:57 2014 +0200
     4.2 +++ b/src/rend_fast.cc	Wed Dec 31 05:21:47 2014 +0200
     4.3 @@ -3,6 +3,7 @@
     4.4  #include "rend_fast.h"
     4.5  #include "sdr.h"
     4.6  
     4.7 +#define DEF_PROXY_COUNT	512
     4.8  #define XFER_MAP_SZ		512
     4.9  
    4.10  static unsigned int sdr;
    4.11 @@ -12,7 +13,7 @@
    4.12  {
    4.13  	vol_tex = xfer_tex = 0;
    4.14  	vol_tex_valid = xfer_tex_valid = false;
    4.15 -	proxy_count = 256;
    4.16 +	proxy_count = DEF_PROXY_COUNT;
    4.17  	vbo_proxy_count = 0;
    4.18  }
    4.19  
    4.20 @@ -190,6 +191,7 @@
    4.21  
    4.22  	set_uniform_int(sdr, "vol_tex", 0);
    4.23  	set_uniform_int(sdr, "xfer_tex", 1);
    4.24 +	set_uniform_float(sdr, "zscale", zscale);
    4.25  
    4.26  	glEnable(GL_BLEND);
    4.27  	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
     5.1 --- a/src/renderer.cc	Tue Dec 30 21:20:57 2014 +0200
     5.2 +++ b/src/renderer.cc	Wed Dec 31 05:21:47 2014 +0200
     5.3 @@ -10,6 +10,8 @@
     5.4  	for(int i=0; i<MAX_CLIP_PLANES; i++) {
     5.5  		disable_clipping_plane(i);
     5.6  	}
     5.7 +
     5.8 +	zscale = 1.0;
     5.9  }
    5.10  
    5.11  Renderer::~Renderer()
    5.12 @@ -36,6 +38,16 @@
    5.13  	return vol;
    5.14  }
    5.15  
    5.16 +void Renderer::set_zscale(float zs)
    5.17 +{
    5.18 +	zscale = zs;
    5.19 +}
    5.20 +
    5.21 +float Renderer::get_zscale() const
    5.22 +{
    5.23 +	return zscale;
    5.24 +}
    5.25 +
    5.26  void Renderer::set_transfer_function(TransferFunc *xfer)
    5.27  {
    5.28  	this->xfer = xfer;
     6.1 --- a/src/renderer.h	Tue Dec 30 21:20:57 2014 +0200
     6.2 +++ b/src/renderer.h	Wed Dec 31 05:21:47 2014 +0200
     6.3 @@ -14,6 +14,7 @@
     6.4  	float clip_plane[MAX_CLIP_PLANES][4];	// nx,ny,nz,dist
     6.5  
     6.6  	TransferFunc *xfer;
     6.7 +	float zscale;
     6.8  
     6.9  public:
    6.10  	Renderer();
    6.11 @@ -25,6 +26,9 @@
    6.12  	virtual void set_volume(Volume *vol);
    6.13  	virtual Volume *get_volume() const;
    6.14  
    6.15 +	virtual void set_zscale(float zs);
    6.16 +	virtual float get_zscale() const;
    6.17 +
    6.18  	virtual void set_transfer_function(TransferFunc *xfer);
    6.19  	virtual TransferFunc *get_transfer_function() const;
    6.20