volmetrics
diff src/main.cc @ 6:e6485ef45e6e
visualize volume
author | Eleni Maria Stea <elene.mst@gmail.com> |
---|---|
date | Sat, 18 Jan 2014 01:57:52 +0200 |
parents | cca2e05dbabe |
children | 5455c9723d9e |
line diff
1.1 --- a/src/main.cc Fri Jan 17 23:45:56 2014 +0200 1.2 +++ b/src/main.cc Sat Jan 18 01:57:52 2014 +0200 1.3 @@ -4,7 +4,7 @@ 1.4 #include <stdio.h> 1.5 #include <assert.h> 1.6 1.7 -#include "image.h" 1.8 +#include "volume.h" 1.9 1.10 //static void init(void); 1.11 static void display(void); 1.12 @@ -19,8 +19,9 @@ 1.13 // debug TODO remove 1.14 //////////////////////////// 1.15 static bool init(); 1.16 -Image img; 1.17 -unsigned int tex; 1.18 + 1.19 +static Volume *vol; 1.20 +static float cur_z; 1.21 1.22 int main(int argc, char **argv) 1.23 { 1.24 @@ -53,15 +54,15 @@ 1.25 void display(void) 1.26 { 1.27 //render 1.28 - glBindTexture(GL_TEXTURE_2D, tex); 1.29 - glEnable(GL_TEXTURE_2D); 1.30 + glBindTexture(GL_TEXTURE_3D, vol->get_texture()); 1.31 + glEnable(GL_TEXTURE_3D); 1.32 glBegin(GL_QUADS); 1.33 - glTexCoord2f(0, 0); glVertex3f(-1, -1, 0); 1.34 - glTexCoord2f(0, 1); glVertex3f(-1, 1, 0); 1.35 - glTexCoord2f(1, 1); glVertex3f(1, 1, 0); 1.36 - glTexCoord2f(1, 0); glVertex3f(1, -1, 0); 1.37 + glTexCoord3f(0, 0, cur_z); glVertex3f(-1, -1, 0); 1.38 + glTexCoord3f(0, 1, cur_z); glVertex3f(-1, 1, 0); 1.39 + glTexCoord3f(1, 1, cur_z); glVertex3f(1, 1, 0); 1.40 + glTexCoord3f(1, 0, cur_z); glVertex3f(1, -1, 0); 1.41 glEnd(); 1.42 - glDisable(GL_TEXTURE_2D); 1.43 + glDisable(GL_TEXTURE_3D); 1.44 1.45 glutSwapBuffers(); 1.46 assert(glGetError() == GL_NO_ERROR); 1.47 @@ -100,21 +101,21 @@ 1.48 int dy = y - prev_y; 1.49 prev_x = x; 1.50 prev_y = y; 1.51 + 1.52 + if(dx != 0) { 1.53 + cur_z = (float)x / (float)win_xsz; 1.54 + glutPostRedisplay(); 1.55 + } 1.56 } 1.57 1.58 bool init() 1.59 { 1.60 - if(!img.load("data/la_colonoscopie/IM-0001-0248.png")) { 1.61 - fprintf(stderr, "Failed to load votre Colonoscopie\n"); 1.62 + vol = new Volume; 1.63 + if(!vol->load("data/test1.vol")) { 1.64 + fprintf(stderr, "Failed to load test1.vol"); 1.65 return false; 1.66 } 1.67 - 1.68 - glGenTextures(1, &tex); 1.69 - glBindTexture(GL_TEXTURE_2D, tex); 1.70 - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 1.71 - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 1.72 - glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE16F_ARB, img.get_width(), 1.73 - img.get_height(), 0, GL_LUMINANCE, GL_FLOAT, img.get_pixels()); 1.74 + cur_z = 0.5; 1.75 1.76 return true; 1.77 }