glviewvol
diff src/xfer_view.cc @ 4:04330eb80b36
lots of stuff
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Mon, 29 Dec 2014 05:41:36 +0200 |
parents | |
children | 5417c25cb238 |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/xfer_view.cc Mon Dec 29 05:41:36 2014 +0200 1.3 @@ -0,0 +1,124 @@ 1.4 +#include <stdio.h> 1.5 +#include "opengl.h" 1.6 +#include "xfer_view.h" 1.7 +#include "dicomview.h" 1.8 + 1.9 +static Renderer *rend; 1.10 + 1.11 +static int act_color = 3; 1.12 +static CurvePoint *cpsel[3]; 1.13 + 1.14 +bool xfview_init(Renderer *rendarg) 1.15 +{ 1.16 + rend = rendarg; 1.17 + return true; 1.18 +} 1.19 + 1.20 +void xfview_destroy() 1.21 +{ 1.22 +} 1.23 + 1.24 +void xfview_draw() 1.25 +{ 1.26 + float line_color[][3] = { 1.27 + { 1, 0, 0 }, { 0, 1, 0 }, { 0, 0, 1 }, { 1, 1, 1 } 1.28 + }; 1.29 + 1.30 + glMatrixMode(GL_PROJECTION); 1.31 + glLoadIdentity(); 1.32 + glMatrixMode(GL_MODELVIEW); 1.33 + glLoadIdentity(); 1.34 + 1.35 + int xsz, ysz; 1.36 + get_window_size(&xsz, &ysz); 1.37 + int nsamples = xsz / 4; 1.38 + 1.39 + // paint the background a faint version of the selected color 1.40 + glBegin(GL_QUADS); 1.41 + glColor3f(line_color[act_color][0] * 0.1, line_color[act_color][1] * 0.1, line_color[act_color][2] * 0.1); 1.42 + glVertex2f(-1, -1); 1.43 + glVertex2f(1, -1); 1.44 + glVertex2f(1, 1); 1.45 + glVertex2f(-1, 1); 1.46 + glEnd(); 1.47 + 1.48 + glEnable(GL_POINT_SMOOTH); 1.49 + glEnable(GL_LINE_SMOOTH); 1.50 + 1.51 + glEnable(GL_BLEND); 1.52 + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 1.53 + 1.54 + // draw selection outline 1.55 + if(act_color < 3) { 1.56 + glPointSize(13.0); 1.57 + glLineWidth(5.0); 1.58 + 1.59 + const Curve &sel_curve = rend->transfer_curve(act_color); 1.60 + glColor3f(0.7, 0.7, 0.7); 1.61 + glBegin(GL_LINE_STRIP); 1.62 + for(int i=0; i<nsamples; i++) { 1.63 + float t = (float)i / (float)(nsamples - 1); 1.64 + float val = sel_curve.value(t); 1.65 + glVertex2f(t * 2.0 - 1.0, val * 2.0 - 1.0); 1.66 + } 1.67 + glEnd(); 1.68 + glBegin(GL_POINTS); 1.69 + for(int i=0; i<sel_curve.get_num_points(); i++) { 1.70 + const CurvePoint *p = sel_curve.get_point(i); 1.71 + float x = 2.0 * (float)p->t_int / 65535.0 - 1.0; 1.72 + glVertex2f(x, p->value * 2.0 - 1.0); 1.73 + } 1.74 + glEnd(); 1.75 + } 1.76 + 1.77 + 1.78 + // draw curves and points 1.79 + glPointSize(9.0); 1.80 + glLineWidth(2.0); 1.81 + 1.82 + for(int i=0; i<3; i++) { 1.83 + int idx; 1.84 + if(act_color < 3) { 1.85 + idx = (i + act_color + 1) % 3; 1.86 + } else { 1.87 + idx = i; 1.88 + } 1.89 + 1.90 + const Curve &xfer = rend->transfer_curve(idx); 1.91 + glColor3fv(line_color[idx]); 1.92 + 1.93 + glBegin(GL_LINE_STRIP); 1.94 + for(int j=0; j<nsamples; j++) { 1.95 + float t = (float)j / (float)(nsamples - 1); 1.96 + float val = xfer.value(t); 1.97 + glVertex2f(t * 2.0 - 1.0, val * 2.0 - 1.0); 1.98 + } 1.99 + glEnd(); 1.100 + 1.101 + glBegin(GL_POINTS); 1.102 + for(int j=0; j<xfer.get_num_points(); j++) { 1.103 + const CurvePoint *p = xfer.get_point(j); 1.104 + float x = 2.0 * (float)p->t_int / 65535.0 - 1.0; 1.105 + glVertex2f(x, p->value * 2.0 - 1.0); 1.106 + } 1.107 + glEnd(); 1.108 + } 1.109 + 1.110 + glDisable(GL_BLEND); 1.111 +} 1.112 + 1.113 +void xfview_button(int bn, int press, int x, int y) 1.114 +{ 1.115 + if(bn == 2 && press) { 1.116 + act_color = (act_color + 1) % 4; 1.117 + redisplay(); 1.118 + return; 1.119 + } 1.120 + 1.121 + if(press) { 1.122 + } 1.123 +} 1.124 + 1.125 +void xfview_motion(int x, int y) 1.126 +{ 1.127 +}