glviewvol

view src/xfer_view.cc @ 6:f22be47a3572

moved to TransferFuncs completely
author John Tsiombikas <nuclear@member.fsf.org>
date Tue, 30 Dec 2014 06:22:54 +0200
parents 5417c25cb238
children 71b479ffb9f7
line source
1 #include <stdio.h>
2 #include "opengl.h"
3 #include "xfer_view.h"
4 #include "dicomview.h"
6 static TransferFunc *xfer;
8 static int act_color = 3;
10 bool xfview_init(TransferFunc *xferarg)
11 {
12 xfer = xferarg;
13 return true;
14 }
16 void xfview_destroy()
17 {
18 }
20 void xfview_draw()
21 {
22 float line_color[][3] = {
23 { 1, 0, 0 }, { 0, 1, 0 }, { 0, 0, 1 }, { 1, 1, 1 }
24 };
26 glMatrixMode(GL_PROJECTION);
27 glLoadIdentity();
28 glMatrixMode(GL_MODELVIEW);
29 glLoadIdentity();
31 int xsz, ysz;
32 get_window_size(&xsz, &ysz);
33 int nsamples = xsz / 4;
35 // paint the background a faint version of the selected color
36 glBegin(GL_QUADS);
37 glColor3f(line_color[act_color][0] * 0.1, line_color[act_color][1] * 0.1, line_color[act_color][2] * 0.1);
38 glVertex2f(-1, -1);
39 glVertex2f(1, -1);
40 glVertex2f(1, 1);
41 glVertex2f(-1, 1);
42 glEnd();
44 glEnable(GL_LINE_SMOOTH);
46 glEnable(GL_BLEND);
47 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
49 // draw curve
50 glLineWidth(2.0);
52 for(int i=0; i<3; i++) {
53 int idx;
54 if(act_color < 3) {
55 idx = (i + act_color + 1) % 3;
56 } else {
57 idx = i;
58 }
60 glColor3fv(line_color[idx]);
62 glBegin(GL_LINE_STRIP);
63 for(int j=0; j<nsamples; j++) {
64 float t = (float)j / (float)(nsamples - 1);
65 float vval[4];
66 xfer->map(t, vval);
68 glVertex2f(t * 2.0 - 1.0, vval[i] * 2.0 - 1.0);
69 }
70 glEnd();
71 }
73 glDisable(GL_BLEND);
74 }
76 void xfview_button(int bn, int press, int x, int y)
77 {
78 if(bn == 2 && press) {
79 act_color = (act_color + 1) % 4;
80 redisplay();
81 return;
82 }
84 if(bn == 1) {
85 if(press) {
86 } else {
87 }
88 }
89 }
91 void xfview_motion(int x, int y)
92 {
93 }