glviewvol

view src/main.cc @ 14:0d2447b9c512

did the histogram... doesn't seem to work right
author John Tsiombikas <nuclear@member.fsf.org>
date Thu, 01 Jan 2015 06:36:45 +0200
parents 73edd1b7c2da
children
line source
1 /*
2 glviewvol is an OpenGL 3D volume data viewer
3 Copyright (C) 2014 John Tsiombikas <nuclear@member.fsf.org>
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18 // GLUT frontend
19 #ifdef USE_GLUT
21 #include <stdlib.h>
22 #include "opengl.h"
24 #ifdef __APPLE__
25 #include <GLUT/glut.h>
26 #else
27 #include <GL/glut.h>
28 #endif
30 #include "viewer.h"
31 #include "opt.h"
33 static void display();
34 static void reshape(int x, int y);
35 static void key_down(unsigned char key, int x, int y);
36 static void key_up(unsigned char key, int x, int y);
37 static void mouse(int bn, int state, int x, int y);
38 static void motion(int x, int y);
40 static int win_width, win_height;
41 static unsigned int mod;
43 int main(int argc, char **argv)
44 {
45 glutInit(&argc, argv);
47 if(parse_args(argc, argv) == -1) {
48 return 1;
49 }
51 glutInitWindowSize(opt.xsz, opt.ysz);
52 glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);
53 glutCreateWindow("dicom viewer");
55 glutDisplayFunc(display);
56 glutReshapeFunc(reshape);
57 glutKeyboardFunc(key_down);
58 glutKeyboardUpFunc(key_up);
59 glutMouseFunc(mouse);
60 glutMotionFunc(motion);
61 glutPassiveMotionFunc(motion);
63 glewInit();
65 if(init() == -1) {
66 return 1;
67 }
69 glutMainLoop();
70 return 0;
71 }
73 void swap_buffers()
74 {
75 glutSwapBuffers();
76 }
78 void redisplay()
79 {
80 glutPostRedisplay();
81 }
83 void quit()
84 {
85 cleanup();
86 exit(0);
87 }
89 void get_window_size(int *xsz, int *ysz)
90 {
91 *xsz = win_width;
92 *ysz = win_height;
93 }
95 unsigned int get_modifiers()
96 {
97 return mod;
98 }
100 static void display()
101 {
102 ev_display();
103 }
105 static void reshape(int x, int y)
106 {
107 win_width = x;
108 win_height = y;
109 ev_reshape(x, y);
110 }
112 static void key_down(unsigned char key, int x, int y)
113 {
114 mod = glutGetModifiers();
116 switch(key) {
117 case 'i':
118 {
119 static bool fullrate;
120 fullrate = !fullrate;
121 glutIdleFunc(fullrate ? glutPostRedisplay : 0);
122 }
123 break;
124 }
126 ev_keyboard(key, 1, x, y);
127 }
129 static void key_up(unsigned char key, int x, int y)
130 {
131 mod = glutGetModifiers();
132 ev_keyboard(key, 0, x, y);
133 }
135 static void mouse(int bn, int state, int x, int y)
136 {
137 mod = glutGetModifiers();
138 ev_mouse_button(bn - GLUT_LEFT_BUTTON, state == GLUT_DOWN ? 1 : 0, x, y);
139 }
141 static void motion(int x, int y)
142 {
143 ev_mouse_motion(x, y);
144 }
146 #endif // USE_GLUT