glviewvol
view 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 source
1 #include <stdio.h>
2 #include "opengl.h"
3 #include "xfer_view.h"
4 #include "dicomview.h"
6 static Renderer *rend;
8 static int act_color = 3;
9 static CurvePoint *cpsel[3];
11 bool xfview_init(Renderer *rendarg)
12 {
13 rend = rendarg;
14 return true;
15 }
17 void xfview_destroy()
18 {
19 }
21 void xfview_draw()
22 {
23 float line_color[][3] = {
24 { 1, 0, 0 }, { 0, 1, 0 }, { 0, 0, 1 }, { 1, 1, 1 }
25 };
27 glMatrixMode(GL_PROJECTION);
28 glLoadIdentity();
29 glMatrixMode(GL_MODELVIEW);
30 glLoadIdentity();
32 int xsz, ysz;
33 get_window_size(&xsz, &ysz);
34 int nsamples = xsz / 4;
36 // paint the background a faint version of the selected color
37 glBegin(GL_QUADS);
38 glColor3f(line_color[act_color][0] * 0.1, line_color[act_color][1] * 0.1, line_color[act_color][2] * 0.1);
39 glVertex2f(-1, -1);
40 glVertex2f(1, -1);
41 glVertex2f(1, 1);
42 glVertex2f(-1, 1);
43 glEnd();
45 glEnable(GL_POINT_SMOOTH);
46 glEnable(GL_LINE_SMOOTH);
48 glEnable(GL_BLEND);
49 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
51 // draw selection outline
52 if(act_color < 3) {
53 glPointSize(13.0);
54 glLineWidth(5.0);
56 const Curve &sel_curve = rend->transfer_curve(act_color);
57 glColor3f(0.7, 0.7, 0.7);
58 glBegin(GL_LINE_STRIP);
59 for(int i=0; i<nsamples; i++) {
60 float t = (float)i / (float)(nsamples - 1);
61 float val = sel_curve.value(t);
62 glVertex2f(t * 2.0 - 1.0, val * 2.0 - 1.0);
63 }
64 glEnd();
65 glBegin(GL_POINTS);
66 for(int i=0; i<sel_curve.get_num_points(); i++) {
67 const CurvePoint *p = sel_curve.get_point(i);
68 float x = 2.0 * (float)p->t_int / 65535.0 - 1.0;
69 glVertex2f(x, p->value * 2.0 - 1.0);
70 }
71 glEnd();
72 }
75 // draw curves and points
76 glPointSize(9.0);
77 glLineWidth(2.0);
79 for(int i=0; i<3; i++) {
80 int idx;
81 if(act_color < 3) {
82 idx = (i + act_color + 1) % 3;
83 } else {
84 idx = i;
85 }
87 const Curve &xfer = rend->transfer_curve(idx);
88 glColor3fv(line_color[idx]);
90 glBegin(GL_LINE_STRIP);
91 for(int j=0; j<nsamples; j++) {
92 float t = (float)j / (float)(nsamples - 1);
93 float val = xfer.value(t);
94 glVertex2f(t * 2.0 - 1.0, val * 2.0 - 1.0);
95 }
96 glEnd();
98 glBegin(GL_POINTS);
99 for(int j=0; j<xfer.get_num_points(); j++) {
100 const CurvePoint *p = xfer.get_point(j);
101 float x = 2.0 * (float)p->t_int / 65535.0 - 1.0;
102 glVertex2f(x, p->value * 2.0 - 1.0);
103 }
104 glEnd();
105 }
107 glDisable(GL_BLEND);
108 }
110 void xfview_button(int bn, int press, int x, int y)
111 {
112 if(bn == 2 && press) {
113 act_color = (act_color + 1) % 4;
114 redisplay();
115 return;
116 }
118 if(press) {
119 }
120 }
122 void xfview_motion(int x, int y)
123 {
124 }