VMTK
vmtkRender3D.cpp
1 #include "vmtkRender3D.h"
2 
4 {
5  m_bInitialized = false;
6  m_refThreshold = 0.0f;
7  m_blender=0.5f;
8  m_rotationMatrix.identity();
9  m_mapRef=0;
10  m_mapFloat=0;
11 }
12 
14 {
15  m_RefData = acq1;
16  float volume_real_dimension[3];
17 
18  m_maxSliceLeft = m_RefData->dims[0];
19  for(int i = 0; i < 3; i++)
20  volume_real_dimension[i] = m_RefData->dims[i] * m_RefData->space[i];
21 
22  float maxDimension = std::max(std::max(volume_real_dimension[0], volume_real_dimension[1]), volume_real_dimension[2]);
23 
24  for (int i = 0; i < 3; i++) {
25  m_refScaleFactors[i] = volume_real_dimension[i] / maxDimension;
26  }
27  m_refScaleFactors[3] = 1.0;
28 
29 
30  m_FloatData = acq2;
31  for(int i = 0; i < 3; i++)
32  volume_real_dimension[i] = m_FloatData->dims[i] * m_FloatData->space[i];
33 
34  maxDimension = std::max(std::max(volume_real_dimension[0], volume_real_dimension[1]), volume_real_dimension[2]);
35  for (int i = 0; i < 3; i++) {
36  m_floatScaleFactors[i] = volume_real_dimension[i] / maxDimension;
37  }
38  m_floatScaleFactors[3] = 1.0;
39 
40  for (int i = 0; i < 3; i++) {
41  m_refPhyDimensions[i] = m_RefData->dims[i];
42  }
43  m_refPhyDimensions[3] = 1.0;
44 
45  for (int i = 0; i < 3; i++) {
46  m_floatPhyDimensions[i] = m_FloatData->dims[i];
47  }
48  m_floatPhyDimensions[3] = 1.0;
49 }
50 
51 void vmtkRender3D::setRotation(float ax, float ay, float az)
52 {
53  m_rotationMatrix = m_rotationMatrix.createRotationAroundAxis(ax,ay,az);
54 }
55 
56 void vmtkRender3D::setThreshold(int threshold)
57 {
58  m_refThreshold = m_mapRef[(unsigned short)(threshold)] / (pow(2, m_RefData->nbitsalloc) - 1);
59 }
60 
61 void vmtkRender3D::setBlender(float blender)
62 {
63  m_blender = blender;
64  std::cout<<"blender: "<< blender <<std::endl;
65 }
66 
67 void vmtkRender3D::initialize(int width, int height)
68 {
69  Shaders sh;
70 
71  this->m_iHeight = width;
72  this->m_iWidth = height;
73 
74  this->m_BackFBO = new vmtkFrameBufferObject(width, height);
75  this->m_FrontFBO = new vmtkFrameBufferObject(width, height);
76 
77  m_fClipXLeft = -1.0f;
78  m_fClipXRight = 1.0f;
79  m_fClipYTop = 1.0f;
80  m_fClipYBottom = -1.0f;
81  m_fClipZBack = 1.0f;
82  m_fClipZFront = -1.0f;
83 
84  m_ColorShader = sh.carregueShaders("./shaders/position_is_color.vert", "./shaders/position_is_color.frag");
85  m_RaytraceShader = sh.carregueShaders("./shaders/raytrace.vert", "./shaders/castregister_with_planar_clipping.frag");
86 
87  loadVolumetoTexture();
88  loadTransferFtoTexture();
89 
90  createVectorPlanes();
91  createBuffers();
92  initDrawCube();
93  initRenderPlane();
94  m_bInitialized = true;
95 }
96 
97 void vmtkRender3D::createVectorPlanes()
98 {
99  v1=vmath::Vector2f(-1.0f,-1.0f);
100  v2=vmath::Vector2f(1.0f,-1.0f);
101  v3=vmath::Vector2f(1.0f,1.0f);
102  v4=vmath::Vector2f(-1.0f,1.0f);
103  vt1=vmath::Vector2f(0.0f,0.0f);
104  vt2=vmath::Vector2f(1.0f,0.0f);
105  vt3=vmath::Vector2f(1.0f,1.0f);
106  vt4=vmath::Vector2f(0.0f,1.0f);
107 }
108 
109 void vmtkRender3D::loadVolumetoTexture()
110 {
111  int threshold = 23;
112  Equalize eq;
113 
114  int intensidade, di, iz, iy, ix, volSize;
115  unsigned short *texbuffer;
116 
117  // Gera nomes de 1 textura
118  glActiveTexture(GL_TEXTURE0);
119  glGenTextures(1, &m_refTexture);
120  // Define a unidade de alinhamento nos acessos
121  glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
122 
123  //Reference
124 
125  // Equaliza o histograma para aumentar a escala dinamica das intensidades
126  // como uma forma de contornar a perda de resolucao durante normalizacao
127  // feita pelas unidades de textura
128  eq.EqualizeHistogram (m_RefData->dims[0], m_RefData->dims[1], m_RefData->dims[2],
129  (reinterpret_cast<unsigned short*>(m_RefData->buffer)),
130  m_RefData->nbitsalloc, m_RefData->umax, &m_mapRef);
131 
132  volSize = m_RefData->dims[0]*m_RefData->dims[1]*m_RefData->dims[2];
133  texbuffer = new unsigned short[volSize];
134  memset(texbuffer, 0x00, volSize*sizeof(unsigned short));
135 
136  for (di=0, iz = 0; iz < m_RefData->dims[2]; iz++) {
137  for (iy =0; iy < m_RefData->dims[1]; iy++) {
138  for (ix =0; ix < m_RefData->dims[0]; ix++) {
139  intensidade = (int)((reinterpret_cast<unsigned short*>(m_RefData->buffer))[iz*m_RefData->dims[0]*m_RefData->dims[1]+iy*m_RefData->dims[0]+ix]);
140  texbuffer[di++] = (unsigned short)(m_mapRef[intensidade]);
141  }
142  }
143  }
144 
145  m_refThreshold = m_mapRef[(unsigned short)(threshold)] / (pow(2, m_RefData->nbitsalloc) - 1);
146  //Carrega o volume equalizado como textura 3D
147  glBindTexture(GL_TEXTURE_3D, m_refTexture);
148  glTexImage3D(GL_TEXTURE_3D, 0, GL_LUMINANCE, m_RefData->dims[0],
149  m_RefData->dims[1], m_RefData->dims[2], 0, GL_LUMINANCE,
150  GL_UNSIGNED_SHORT, texbuffer);
151 
152  glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
153  glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
154 
155  glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
156  glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
157  glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
158 
159  delete [] texbuffer;
160 
161  //Floating
162  eq.EqualizeHistogram (m_FloatData->dims[0], m_FloatData->dims[1], m_FloatData->dims[2],
163  (reinterpret_cast<unsigned short*>(m_FloatData->buffer)),
164  m_FloatData->nbitsalloc, m_FloatData->umax, &m_mapFloat);
165 
166  volSize = m_FloatData->dims[0]*m_FloatData->dims[1]*m_FloatData->dims[2];
167  texbuffer = new unsigned short[volSize];
168  memset(texbuffer, 0x00, volSize*sizeof(unsigned short));
169 
170  for (di=0, iz = 0; iz < m_FloatData->dims[2]; iz++) {
171  for (iy =0; iy < m_FloatData->dims[1]; iy++) {
172  for (ix =0; ix < m_FloatData->dims[0]; ix++) {
173  intensidade = (int)((reinterpret_cast<unsigned short*>(m_FloatData->buffer))[iz*m_FloatData->dims[0]*m_FloatData->dims[1]+iy*m_FloatData->dims[0]+ix]);
174  texbuffer[di++] = (unsigned short)(m_mapFloat[intensidade]);
175  }
176  }
177  }
178 
179  glActiveTexture(GL_TEXTURE1);
180  glGenTextures(1, &m_floatTexture);
181  glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
182 
183  //Carrega o volume equalizado como textura 3D
184  glBindTexture(GL_TEXTURE_3D, m_floatTexture);
185  glTexImage3D(GL_TEXTURE_3D, 0, GL_LUMINANCE, m_FloatData->dims[0],
186  m_FloatData->dims[1], m_FloatData->dims[2], 0, GL_LUMINANCE,
187  GL_UNSIGNED_SHORT, texbuffer);
188 
189  glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
190  glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
191 
192  glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
193  glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
194  glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
195 
196  delete [] texbuffer;
197 }
198 
199 void vmtkRender3D::loadTransferFtoTexture()
200 {
201  int dim;
202  unsigned char *tf;
203  TransferFunction tfunc;
204 
205  //Reference
206  tfunc.GetGrayScaleTF (4, 0, pow(2,m_RefData->nbitsalloc), &dim, &tf, m_RefData->nbitsalloc);
207 
208  glActiveTexture(GL_TEXTURE2);
209  glGenTextures(1, &m_refTF);
210  glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
211  // Carrega a funcao de transferencia como textura 1D
212  glBindTexture(GL_TEXTURE_1D, m_refTF);
213  glTexImage1D(GL_TEXTURE_1D, 0, GL_LUMINANCE, dim, 0, GL_LUMINANCE,
214  GL_UNSIGNED_BYTE, tf);
215 
216  glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
217  glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
218 
219  glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
220  glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
221  glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
222 
223  //Float
224  tfunc.GetGrayScaleTF (4, 0, pow(2,m_FloatData->nbitsalloc), &dim, &tf, m_FloatData->nbitsalloc);
225 
226  glActiveTexture(GL_TEXTURE3);
227  glGenTextures(1, &m_floatTF);
228  glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
229  // Carrega a funcao de transferencia como textura 1D
230  glBindTexture(GL_TEXTURE_1D, m_floatTF);
231  glTexImage1D(GL_TEXTURE_1D, 0, GL_LUMINANCE, dim, 0, GL_LUMINANCE,
232  GL_UNSIGNED_BYTE, tf);
233 
234  glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
235  glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
236 
237  glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
238  glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
239  glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
240 }
241 
242 void vmtkRender3D::createBuffers()
243 {
244  /*create buffers to Cube*/
245  glGenVertexArrays(1, &vaosCube);
246  glGenBuffers(1, &vboCube);
247  glGenBuffers(1, &eboCube);
248 
249  /*create buffer to RenderPlane */
250  glGenVertexArrays(1, &vaosRenderPlane);
251  glGenBuffers(1, &vboRenderPlane);
252  glGenBuffers(1, &eboRenderPlane);
253 }
254 
255 void vmtkRender3D::initRenderPlane()
256 {
257  VertexData vertices[] = {
258  {v1, vt1}, // v0
259  {v2, vt2}, // v1
260  {v3, vt3}, // v2
261  {v4, vt4}, // v3
262  };
263 
264  GLushort indices[] = { 0, 1, 2, 3};
265 
266  glBindVertexArray(vaosRenderPlane);
267 
268  glBindBuffer(GL_ARRAY_BUFFER, vboRenderPlane);
269  glBufferData(GL_ARRAY_BUFFER, 4 * sizeof(VertexData), vertices, GL_STATIC_DRAW);
270 
271  GLuint offset = 0;
272  glEnableVertexAttribArray(0);
273  glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, sizeof(VertexData), (const void *)offset);
274 
275  offset += sizeof(vmath::Vector2f);
276 
277  glEnableVertexAttribArray(1);
278  glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(VertexData), (const void *)offset);
279 
280  glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, eboRenderPlane);
281  glBufferData(GL_ELEMENT_ARRAY_BUFFER, 4 * sizeof(GLushort), indices, GL_STATIC_DRAW);
282  glBindVertexArray(0);
283 }
284 
286 {
287  vmath::Matrix4f mvp;
288 
289  m_modelViewMatrix=m_translationMatrix*m_rotationMatrix*m_scalationMatrix;
290  mvp = m_projectionMatrix * m_modelViewMatrix;
291 
292  preRender(mvp);
293  raycasting();
294 }
295 
296 void vmtkRender3D::preRender(vmath::Matrix4f mvp)
297 {
298  glEnable(GL_CULL_FACE);
299 
300  glCullFace(GL_FRONT);
301  this->m_BackFBO->binding();
302  glClearColor(0.,0.,0.,1.);
303  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //clear buffers
304  glViewport(0,0,m_iWidth, m_iHeight);
305  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
306  this->itlDrawColorCube(mvp);
307  this->m_BackFBO->releasing();
308 
309  glCullFace(GL_BACK);
310  this->m_FrontFBO->binding();
311  glClearColor(0.,0.,0.,1.);
312  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //clear buffers
313  glViewport(0,0,m_iWidth,m_iHeight);
314  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
315  this->itlDrawColorCube(mvp);
316  this->m_FrontFBO->releasing();
317 }
318 
319 void vmtkRender3D::raycasting()
320 {
321  glClearColor(0.,0.,0.,1.);
322  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //clear buffers
323  glViewport(0,0,m_iWidth,m_iHeight);
324 
325  glUseProgram(m_RaytraceShader);
326 
327  glUniform1i(glGetUniformLocation(m_RaytraceShader,"width"), m_RefData->dims[0]);
328  glUniform1i(glGetUniformLocation(m_RaytraceShader,"height"), m_RefData->dims[1]);
329  glUniform1i(glGetUniformLocation(m_RaytraceShader,"depth"), m_RefData->dims[2]);
330 
331  glUniform1i(glGetUniformLocation(m_RaytraceShader,"steps_mode"), 300);
332 
333  /*Volumes*/
334  glActiveTexture(GL_TEXTURE0);
335  glBindTexture(GL_TEXTURE_3D, m_refTexture);
336  glTexParameteri(GL_TEXTURE_3D,GL_TEXTURE_MIN_FILTER, GL_LINEAR);
337  glTexParameteri(GL_TEXTURE_3D,GL_TEXTURE_MAG_FILTER, GL_LINEAR);
338  glUniform1i(glGetUniformLocation(m_RaytraceShader, "ref_volumetexture"),0);
339 
340  glActiveTexture(GL_TEXTURE1);
341  glBindTexture(GL_TEXTURE_3D, m_floatTexture);
342  glTexParameteri(GL_TEXTURE_3D,GL_TEXTURE_MIN_FILTER, GL_LINEAR);
343  glTexParameteri(GL_TEXTURE_3D,GL_TEXTURE_MAG_FILTER, GL_LINEAR);
344  glUniform1i(glGetUniformLocation(m_RaytraceShader, "float_volumetexture"),1);
345 
346  /*Transfer Function*/
347  glActiveTexture(GL_TEXTURE2);
348  glBindTexture(GL_TEXTURE_1D, m_refTF);
349  glUniform1i(glGetUniformLocation(m_RaytraceShader, "ref_transferfunction"),2);
350 
351  glActiveTexture(GL_TEXTURE3);
352  glBindTexture(GL_TEXTURE_1D, m_floatTF);
353  glUniform1i(glGetUniformLocation(m_RaytraceShader, "float_transferfunction"),3);
354 
355  /*Front-Back face*/
356  glActiveTexture(GL_TEXTURE4);
357  glBindTexture(GL_TEXTURE_2D, this->m_BackFBO->getTexture());
358  glUniform1i(glGetUniformLocation(m_RaytraceShader,"backface_fbo"), 4);
359 
360  glActiveTexture(GL_TEXTURE5);
361  glBindTexture(GL_TEXTURE_2D, this->m_FrontFBO->getTexture());
362  glUniform1i(glGetUniformLocation(m_RaytraceShader,"frontface_fbo"), 5);
363 
364  //register matrix
365  glUniformMatrix4fv(glGetUniformLocation(m_RaytraceShader,"inv_registration_matrix"), 1, GL_TRUE , m_registration_matrix_inv);
366 
367  glUniform4fv(glGetUniformLocation(m_RaytraceShader,"ref_phyDimensions"), 1, m_refPhyDimensions);
368  glUniform4fv(glGetUniformLocation(m_RaytraceShader,"float_phyDimensions"), 1, m_floatPhyDimensions);
369 
370  glUniform1f(glGetUniformLocation(m_RaytraceShader,"noise_threshold"), m_refThreshold);
371  glUniform1f(glGetUniformLocation(m_RaytraceShader,"blending_factor"), m_blender);
372 
373  drawPlaneRayTraced();
374  glUseProgram(0);
375 }
376 
377 void vmtkRender3D::drawPlaneRayTraced()
378 {
379  glBindVertexArray(vaosRenderPlane);
380  glDrawElements(GL_TRIANGLE_FAN, 4, GL_UNSIGNED_SHORT, 0);
381  glBindVertexArray(0);
382 }
383 
384 void vmtkRender3D::resize(int width, int height)
385 {
386  const float zNear = -100.0f, zFar =100.0f; //, fov = 45.0f;
387 
388  m_projectionMatrix = m_projectionMatrix.createOrtho(-1.0f,1.0f,-1.0f,1.0f,zNear,zFar);
389 
390  delete this->m_BackFBO;
391  delete this->m_FrontFBO;
392 
393  this->m_BackFBO = new vmtkFrameBufferObject(width, height);
394  this->m_FrontFBO = new vmtkFrameBufferObject(width, height);
395 
396  this->m_iHeight = height;
397  this->m_iWidth = width;
398 }
399 
400 void vmtkRender3D::itlDrawColorCube(vmath::Matrix4f mvp)
401 {
402 
403  initDrawCube();
404 
405  glUseProgram(m_ColorShader);
406  GLuint id = glGetUniformLocation(m_ColorShader,"mvp_matrix");
407  glUniformMatrix4fv(id, 1, GL_FALSE, mvp);
408 
409  glUniform4fv(glGetUniformLocation(m_ColorShader,"scaleFactors"), 1, m_refScaleFactors);
410  drawCube();
411  glUseProgram(0);
412 }
413 
415 
416  const float clip_x_left = m_fClipXLeft;
417  const float clip_x_right = m_fClipXRight;
418  const float clip_y_top = m_fClipYTop;
419  const float clip_y_bottom = m_fClipYBottom;
420  const float clip_z_front = m_fClipZBack;
421  const float clip_z_back = m_fClipZFront;
422 
423  //left side
424  vc1=vmath::Vector3f(clip_x_left, clip_y_bottom, clip_z_back);
425  vc2=vmath::Vector3f(clip_x_left, clip_y_bottom, clip_z_front);
426  vc3=vmath::Vector3f(clip_x_left, clip_y_top, clip_z_front);
427  vc4=vmath::Vector3f(clip_x_left, clip_y_top, clip_z_back);
428 
429  //front side
430  vc5=vmath::Vector3f(clip_x_left, clip_y_top, clip_z_front);
431  vc6=vmath::Vector3f(clip_x_left, clip_y_bottom, clip_z_front);
432  vc7=vmath::Vector3f(clip_x_right, clip_y_bottom, clip_z_front);
433  vc8=vmath::Vector3f(clip_x_right, clip_y_top, clip_z_front);
434 
435  //right side
436  vc9=vmath::Vector3f(clip_x_right, clip_y_top, clip_z_back);
437  vc10=vmath::Vector3f(clip_x_right, clip_y_top, clip_z_front);
438  vc11=vmath::Vector3f(clip_x_right, clip_y_bottom, clip_z_front);
439  vc12=vmath::Vector3f(clip_x_right, clip_y_bottom, clip_z_back);
440 
441  //back side
442  vc13=vmath::Vector3f(clip_x_right, clip_y_top, clip_z_back);
443  vc14=vmath::Vector3f(clip_x_right, clip_y_bottom, clip_z_back);
444  vc15=vmath::Vector3f(clip_x_left, clip_y_bottom, clip_z_back);
445  vc16=vmath::Vector3f(clip_x_left, clip_y_top, clip_z_back);
446 
447  //bottom
448  vc17=vmath::Vector3f(clip_x_left, clip_y_bottom, clip_z_back);
449  vc18=vmath::Vector3f(clip_x_right, clip_y_bottom, clip_z_back);
450  vc19=vmath::Vector3f(clip_x_right, clip_y_bottom, clip_z_front);
451  vc20=vmath::Vector3f(clip_x_left, clip_y_bottom, clip_z_front);
452 
453  //top
454  vc21=vmath::Vector3f(clip_x_left, clip_y_top, clip_z_back);
455  vc22=vmath::Vector3f(clip_x_left, clip_y_top, clip_z_front);
456  vc23=vmath::Vector3f(clip_x_right, clip_y_top, clip_z_front);
457  vc24=vmath::Vector3f(clip_x_right, clip_y_top, clip_z_back);
458 
459  VertexDataCube vertices[] = {
460  {vc1}, // 0
461  {vc2}, // 1
462  {vc3}, // 2
463  {vc4}, // 3
464  {vc5}, // 4
465  {vc6}, // 5
466  {vc7}, // 6
467  {vc8}, // 7
468  {vc9}, // 8
469  {vc10}, // 9
470  {vc11}, // 10
471  {vc12}, // 11
472  {vc13}, // 12
473  {vc14}, // 13
474  {vc15}, // 14
475  {vc16}, // 15
476  {vc17}, // 16
477  {vc18}, // 17
478  {vc19}, // 18
479  {vc20}, // 19
480  {vc21}, // 20
481  {vc22}, // 21
482  {vc23}, // 22
483  {vc24} // 23
484  };
485 
486  GLushort indices[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23};
487  glBindVertexArray(vaosCube);
488  glBindBuffer(GL_ARRAY_BUFFER, vboCube);
489  glBufferData(GL_ARRAY_BUFFER, 24 * sizeof(VertexDataCube), vertices, GL_DYNAMIC_DRAW);
490  glEnableVertexAttribArray(0);
491  glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, (const void *) 0);
492 
493  glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, eboCube);
494  glBufferData(GL_ELEMENT_ARRAY_BUFFER, 24 * sizeof(GLushort), indices, GL_DYNAMIC_DRAW);
495 }
496 
497 bool vmtkRender3D::readMatrix(const char *s)
498 {
499  int k = 0;
500  float x;
501  std::ifstream file(s);
502  if(file.is_open())
503  {
504  while(file)
505  {
506  file >> x;
507  m_registration_matrix.data[k] = x;
508  k++;
509  }
510 
511  std::cout << "Co-register matrix" << std::endl;
512  for (int i = 0; i < 4; i++)
513  {
514  for (int j = 0; j < 4; j++)
515  std::cout << m_registration_matrix.at(i,j) << " ";
516  std::cout << std::endl;
517  }
518  file.close();
519  m_registration_matrix_inv = m_registration_matrix.inverse();
520  return true;
521  }
522  else
523  std::cerr << "Matrix not found!" << std::endl;
524  return false;
525 }
526 
527 void vmtkRender3D::setClipLeftX(float left_x)
528 {
529  m_fClipXLeft = (left_x/m_RefData->dims[0])*2-1;
530 }
531 
532 void vmtkRender3D::drawCube()
533 {
534  glBindVertexArray(vaosCube);
535  glDrawElements(GL_TRIANGLE_FAN, 4, GL_UNSIGNED_SHORT, 0);
536  glDrawElements(GL_TRIANGLE_FAN, 4, GL_UNSIGNED_SHORT, (const GLvoid *)(sizeof(GLushort)*4));
537  glDrawElements(GL_TRIANGLE_FAN, 4, GL_UNSIGNED_SHORT, (const GLvoid *)(sizeof(GLushort)*8));
538  glDrawElements(GL_TRIANGLE_FAN, 4, GL_UNSIGNED_SHORT, (const GLvoid *)(sizeof(GLushort)*12));
539  glDrawElements(GL_TRIANGLE_FAN, 4, GL_UNSIGNED_SHORT, (const GLvoid *)(sizeof(GLushort)*16));
540  glDrawElements(GL_TRIANGLE_FAN, 4, GL_UNSIGNED_SHORT, (const GLvoid *)(sizeof(GLushort)*20));
541 
542  glBindVertexArray(0);
543 }
544 
546 {
547  return m_maxSliceLeft;
548 }
void render()
renders the data with the specified redering mode.
void preRender(vmath::Matrix4f mvp)
renders the color cube in the fbos.
void initialize(int width, int height)
initializes 3D volume rendering
void initDrawCube()
initializes the geometry of a cube to be rendered for getting back and front depth maps...
vmtkRender3D()
vmtkRenderer3D constructor
Definition: vmtkRender3D.cpp:3
void itlDrawColorCube(vmath::Matrix4f mvp)
draws a unit cube to get the front and the back depth maps of the volume cube, after updating the cli...
void resize(int width, int height)
resizes the dimensions of the display
GLuint getTexture() const
gets the texture bound to the FBO.
void setThreshold(int threshold)
sets the threshold.
void setBlender(float blender)
sets the blender factor.
void setClipLeftX(float left_x)
sets the clipping plane.
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 setAcquisition(Import::ImgFormat *acq1, Import::ImgFormat *acq2)
sets the volumes to be registered
bool binding()
binds the FBO to the framebuffer target.
bool releasing()
releases the FBO from the framebuffer target.