VMTK
main_glsl_dvr.cpp
1 #define FREEGLUT_STATIC
2 
3 #ifndef GLEW_STATIC
4 #define GLEW_STATIC
5 #endif
6 #ifdef __WIN32__
7 #include <GL/glew.h>
8 #elif __linux__
9 #include <GL/glew.h>
10 #elif __APPLE__
11 #include <glew.h>
12 #endif
13 
14 #include <sys/types.h>
15 #include <sys/stat.h>
16 #include <cstdio>
17 #include <cstring>
18 #include <string>
19 #include <iostream>
20 #include <stdio.h>
21 #include <stdint.h>
22 #include <stdlib.h>
23 #include <string.h>
24 #include <limits.h>
25 #include <math.h>
26 #include <GL/freeglut.h>
27 
28 #include "vmtkRender3D.h"
29 
30 using namespace std;
31 
32 vmtkRender3D volumeRender;
33 GLfloat spin_x=0.0, spin_y=0.0, spin_z=0.0;
34 GLuint VIEWPORT_WIDTH=600, VIEWPORT_HEIGHT=600;
35 int threshold=23;
36 float blender=0.5f;
37 int slice_x = 0;
38 
39 void init()
40 {
41  volumeRender.initialize(VIEWPORT_WIDTH, VIEWPORT_HEIGHT);
42 }
43 
44 void keyboard(unsigned char key, int x, int y)
45 {
46 
47 switch (key) {
48  case 'w':
49  case 'W':
50  /* incrementa +5.0 no ângulo de rotação em torno do eixo x */
51  spin_x += 5.0;
52  break;
53  case 's':
54  case 'S':
55  /* incrementa +5.0 no ângulo de rotação em torno do eixo x */
56  spin_x -= 5.0;
57  break;
58  case 'q':
59  case 'Q':
60  /* incrementa +5.0 no ângulo de rotação em torno do eixo y */
61  spin_y += 5.0;
62  break;
63  case 'e':
64  case 'E':
65  /* incrementa +5.0 no ângulo de rotação em torno do eixo y */
66  spin_y -= 5.0;
67  break;
68  case 'a':
69  case 'A':
70  /* incrementa +5.0 no ângulo de rotação em torno do eixo z */
71  spin_z += 5.0;
72  break;
73  case 'd':
74  case 'D':
75  /* incrementa +5.0 no ângulo de rotação em torno do eixo z */
76  spin_z -= 5.0;
77  break;
78  case 'r':
79  case 'R':
80  /* Reseta */
81  spin_x = spin_y = spin_z = 0.0;
82  break;
83  case '+':
84  /* Aumenta o limiar */
85  threshold += 1;
86  break;
87  case '-':
88  /* Diminue o limiar */
89  threshold -= 1;
90  break;
91  case 'b':
92  case 'B':
93  blender += 0.1;
94  if (blender > 1.0)
95  blender = 1.0;
96  break;
97  case 'n':
98  case 'N':
99  blender -= 0.1;
100  if (blender < 0.0)
101  blender = 0.0;
102  break;
103  case 'o':
104  case 'O':
105  slice_x++;
106  if (slice_x > volumeRender.getMaxSliceLeft())
107  slice_x = volumeRender.getMaxSliceLeft();
108  break;
109  case 'p':
110  case 'P':
111  slice_x--;
112  if (slice_x < 0)
113  slice_x = 0;
114  break;
115  default:
116  return;
117  }
118 
119  volumeRender.setClipLeftX(slice_x);
120  volumeRender.setRotation(spin_x,spin_y,spin_z);
121  if(threshold<=0){threshold=0;}
122  volumeRender.setThreshold(threshold);
123  volumeRender.setBlender(blender);
124 
125  /* Gera o evento "Display" */
126  glutPostRedisplay();
127 }
128 
129 void reshape(int w, int h)
130 {
131  volumeRender.resize(w, h);
132 }
133 
134 void drawProxyGeometry()
135 {
136  volumeRender.render();
137  glutSwapBuffers();
138 }
139 
140 int main(int argc, char *argv[])
141 {
142  Import load;
143  Import::ImgFormat data1, data2;
144  string path1, path2;
145 
146  if( argc < 2 )
147  {
148  cerr << "Usage: " << endl;
149  cerr << argv[0] << " inputVolume1 inputVolume2 registeredMatrix" << endl;
150  return EXIT_FAILURE;
151  }
152 
153  //reading first volume
154  path1 = argv[1];
155  data1.umax = -pow(2,30);
156  data1.umin = pow(2,30);
157  if (!load.DICOMImage (path1, &data1)) {
158  std::cout << path1 << " Cannot be imported!" << std::endl;
159  return 0;
160  }
161 
162  //reading second volume
163  path2 = argv[2];
164  data2.umax = -pow(2,30);
165  data2.umin = pow(2,30);
166  if (!load.DICOMImage (path2, &data2)) {
167  std::cout << path1 << " Cannot be imported!" << std::endl;
168  return 0;
169  }
170 
171  volumeRender.setAcquisition(&data1, &data2);
172  if(!volumeRender.readMatrix(argv[3]))
173  return 0;
174 
175  /* Initializa OpenGL */
176  glutInit(&argc, argv);
177  glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);
178 
179  /* Seta contexto GL */
180  glutCreateWindow("VMTK-SPS");
181  std::cout << "OpenGL version supported by this platform: " << glGetString(GL_VERSION) << std::endl;
182 
183  glewInit();
184  init();
185 
186  /* Configura a janela */
187  glutPositionWindow(10, 10);
188  glutReshapeWindow(VIEWPORT_WIDTH, VIEWPORT_HEIGHT);
189 
190  glutReshapeFunc(reshape);
191  glutDisplayFunc(drawProxyGeometry);
192  glutKeyboardFunc(keyboard);
193 
194  /* Espera por eventos */
195  glutMainLoop();
196 
197  return 0;
198 }
void render()
renders the data with the specified redering mode.
void initialize(int width, int height)
initializes 3D volume rendering
void resize(int width, int height)
resizes the dimensions of the display
Definition: vmath.h:3922
void setThreshold(int threshold)
sets the threshold.
void setBlender(float blender)
sets the blender factor.
void setClipLeftX(float left_x)
sets the clipping plane.
int DICOMImage(std::string &filename, ImgFormat *imgformat)
Destructor.
bool readMatrix(const char *s)
reads the co-register matrix.
void setRotation(float ax, float ay, float az)
sets the rotation matrix.
int getMaxSliceLeft()
gets the maximum number of the slices from the axis X.
void main(void)
Main function.
void setAcquisition(Import::ImgFormat *acq1, Import::ImgFormat *acq2)
sets the volumes to be registered