00001
00002
00007 #ifdef _WIN32
00008 #include<windows.h>
00009 #endif
00010
00011 #include <GL/glew.h>
00012 #include <GL/glut.h>
00013 #include <GL/glext.h>
00014
00015 #include <stdio.h>
00016 #include <math.h>
00017
00018
00019 #include "VolumeBuffer.h"
00020
00021 PFNGLTEXIMAGE3DPROC glTexImage3D;
00022
00023 VolumeBuffer::VolumeBuffer(GLenum format, int width, int height, int depth, int banks)
00024 : m_width(width),
00025 m_height(height),
00026 m_depth(depth),
00027 m_banks(banks),
00028 m_blendMode(BLEND_NONE)
00029 {
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053 m_volume_size = m_width*m_height*m_depth;
00054 m_volume_data_raw = new unsigned char [m_volume_size];
00055
00056
00057
00058 if(banks >= 1)
00059 {
00060 m_scale1_raw = new unsigned char [m_volume_size];
00061
00062 }
00063
00064 if(banks >= 2)
00065 {
00066 m_scale2_raw = new unsigned char [m_volume_size];
00067
00068 }
00069
00070 if(banks >= 3)
00071 {
00072 m_scale3_raw = new unsigned char [m_volume_size];
00073
00074 }
00075
00076 m_tex = new GLuint [m_banks];
00077 glEnable(GL_TEXTURE_2D);
00078 m_tex_z = new unsigned int [m_depth];
00079 m_tex_x = new unsigned int [m_width];
00080 m_tex_y = new unsigned int [m_height];
00081
00082 m_tex_z_s1 = new unsigned int [m_depth];
00083 m_tex_z_s2 = new unsigned int [m_depth];
00084 m_tex_z_s3 = new unsigned int [m_depth];
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104 vertex[0].x=-0.5; vertex[0].y=-0.5; vertex[0].z=-0.5;
00105 vertex[1].x= 0.5; vertex[1].y=-0.5; vertex[1].z=-0.5;
00106 vertex[2].x= 0.5; vertex[2].y= 0.5; vertex[2].z=-0.5;
00107 vertex[3].x=-0.5; vertex[3].y= 0.5; vertex[3].z=-0.5;
00108 vertex[4].x=-0.5; vertex[4].y=-0.5; vertex[4].z= 0.5;
00109 vertex[5].x= 0.5; vertex[5].y=-0.5; vertex[5].z= 0.5;
00110 vertex[6].x= 0.5; vertex[6].y= 0.5; vertex[6].z= 0.5;
00111 vertex[7].x=-0.5; vertex[7].y= 0.5; vertex[7].z= 0.5;
00112
00113
00114
00115
00116
00117
00118
00120 normal[0].x=0; normal[0].y=0; normal[0].z=-1;
00121 normal[1].x=1; normal[1].y=0; normal[1].z=0;
00122 normal[2].x=0; normal[2].y=0; normal[2].z=1;
00123 normal[3].x=-1; normal[3].y=0; normal[3].z=0;
00124 normal[4].x=0; normal[4].y=1; normal[4].z=0;
00125 normal[5].x=0; normal[5].y=-1; normal[5].z=0;
00126
00127 m_textures_ready = 0;
00128 }
00129
00130 VolumeBuffer::~VolumeBuffer()
00131 {
00132
00133 for(int i=0; i<m_banks; i++) {
00134 glDeleteTextures(1, &m_tex[i]);
00135 }
00136 for(int i=0; i<m_depth; i++) {
00137 glDeleteTextures(1, &m_tex_z[i]);
00138
00139 glDeleteTextures(1, &m_tex_z_s1[i]);
00140 glDeleteTextures(1, &m_tex_z_s2[i]);
00141 glDeleteTextures(1, &m_tex_z_s3[i]);
00142 }
00143
00144 for(int i=0; i<m_width; i++) {
00145 glDeleteTextures(1, &m_tex_y[i]);
00146 }
00147
00148 for(int i=0; i<m_height; i++) {
00149 glDeleteTextures(1, &m_tex_x[i]);
00150 }
00151
00152 delete [] m_tex_z;
00153 delete [] m_tex_x;
00154 delete [] m_tex_y;
00155
00156 delete [] m_tex_z_s1;
00157 delete [] m_tex_z_s2;
00158 delete [] m_tex_z_s3;
00159
00160 delete [] m_tex;
00161 delete [] m_volume_data_raw;
00162
00163
00164 if(m_banks >= 1)
00165 {
00166 delete [] m_scale1_raw;
00167
00168 }
00169 if(m_banks >= 2)
00170 {
00171 delete [] m_scale2_raw;
00172
00173 }
00174 if(m_banks >= 3)
00175 {
00176 delete [] m_scale3_raw;
00177
00178 }
00179 }
00180
00181 GLuint
00182 VolumeBuffer::create3dTexture(GLenum internalformat, int w, int h, int d)
00183 {
00184 GLuint tex;
00185 glGenTextures(1, &tex);
00186 glBindTexture(GL_TEXTURE_3D, tex);
00187 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
00188 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
00189 GLint mode = GL_CLAMP_TO_BORDER;
00190 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, mode);
00191 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, mode);
00192 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, mode);
00193
00194
00195
00196
00197
00198
00199
00200 #ifdef _WIN32
00201 PFNGLTEXIMAGE3DPROC glTexImage3D=0;
00202 glTexImage3D = (PFNGLTEXIMAGE3DPROC) wglGetProcAddress("glTexImage3D");
00203 #endif
00204 if (glTexImage3D == NULL) {
00205 printf("Error in line %d: Couldn't load glTexImage3D function. Aborting.\n", __LINE__);
00206 return -1;
00207 }
00208
00209 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA, w, h, d, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
00210
00211 return tex;
00212 }
00213
00214 GLuint
00215 VolumeBuffer::create2dTexture(GLenum internalformat, int w, int h, int d)
00216 {
00217 GLuint tex;
00218 glGenTextures(1, &tex);
00219 #ifdef GL_VERSION_1_1
00220 glBindTexture(GL_TEXTURE_2D, tex);
00221 #endif
00222 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
00223 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
00224
00225
00226 GLint mode = GL_CLAMP;
00227 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, mode);
00228 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, mode);
00229
00230 #ifdef GL_VERSION_1_1
00231 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, internalformat, 0);
00232
00233 #else
00234 glTexImage2D(GL_TEXTURE_2D, 0, 4, w, h, 0, GL_LUMINANCE, internalformat, 0);
00235 #endif
00236 return tex;
00237 }
00238
00239 GLuint
00240 VolumeBuffer::create2DTextures(GLenum internalformat)
00241 {
00242 if(m_textures_ready == 0)
00243 {
00244
00245
00246 create2DTexturesZ(internalformat);
00247 create2DTexturesZscale1(internalformat);
00248 create2DTexturesZscale2(internalformat);
00249 create2DTexturesZscale3(internalformat);
00250 m_textures_ready = 1;
00251 }
00252 return 0;
00253 }
00254
00255 GLuint
00256 VolumeBuffer::create2DTexturesZ(GLenum internalformat)
00257 {
00258
00259 glGenTextures(m_depth, (m_tex_z));
00260
00261 int ix,iy,iz,value;
00262
00263
00264 unsigned char* tex_z = new unsigned char [m_width*m_height*4];
00265
00266 for(iz = 0; iz < m_depth; iz++)
00267 {
00268
00269 memset(tex_z,0,m_width*m_height*4*sizeof(unsigned char));
00270
00271
00272 for (iy = 0; iy < m_height; iy++)
00273 {
00274 for (ix = 0; ix < m_width; ix++)
00275 {
00276 value = m_volume_data_raw[(m_height*m_width)*iz + (m_width)*iy + ix];
00277
00278 tex_z[((m_width)*iy + ix)*4 + 0] = (GLubyte) value;
00279 tex_z[((m_width)*iy + ix)*4 + 1] = (GLubyte) value;
00280 tex_z[((m_width)*iy + ix)*4 + 2] = (GLubyte) value;
00281 tex_z[((m_width)*iy + ix)*4 + 3] = (GLubyte) 255;
00282 }
00283 }
00284
00285
00286 glBindTexture(GL_TEXTURE_2D,(m_tex_z)[iz]);
00287
00288
00289 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
00290 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
00291
00292 GLint mode = GL_CLAMP;
00293 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, mode);
00294 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, mode);
00295
00296
00297 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, m_width, m_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, tex_z);
00298 }
00299
00300 delete [] tex_z;
00301 return 0;
00302 }
00303
00304 GLuint
00305 VolumeBuffer::create2DTexturesZscale1(GLenum internalformat)
00306 {
00307
00308 glGenTextures(m_depth, (m_tex_z_s1));
00309
00310 int ix,iy,iz,value;
00311
00312
00313 unsigned char* tex_z = new unsigned char [m_width*m_height*4];
00314
00315 for(iz = 0; iz < m_depth; iz++)
00316 {
00317
00318 memset(tex_z,0,m_width*m_height*4*sizeof(unsigned char));
00319
00320
00321 for (iy = 0; iy < m_height; iy++)
00322 {
00323 for (ix = 0; ix < m_width; ix++)
00324 {
00325 value = m_scale1_raw[(m_height*m_width)*iz + (m_width)*iy + ix];
00326
00327 tex_z[((m_width)*iy + ix)*4 + 0] = (GLubyte) value;
00328 tex_z[((m_width)*iy + ix)*4 + 1] = (GLubyte) value;
00329 tex_z[((m_width)*iy + ix)*4 + 2] = (GLubyte) value;
00330 tex_z[((m_width)*iy + ix)*4 + 3] = (GLubyte) 255;
00331 }
00332 }
00333
00334
00335 glBindTexture(GL_TEXTURE_2D,(m_tex_z_s1)[iz]);
00336
00337
00338 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
00339 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
00340
00341 GLint mode = GL_CLAMP;
00342 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, mode);
00343 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, mode);
00344
00345
00346 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, m_width, m_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, tex_z);
00347 }
00348
00349 delete [] tex_z;
00350 return 0;
00351 }
00352
00353 GLuint
00354 VolumeBuffer::create2DTexturesZscale2(GLenum internalformat)
00355 {
00356
00357 glGenTextures(m_depth, (m_tex_z_s2));
00358
00359 int ix,iy,iz,value;
00360
00361
00362 unsigned char* tex_z = new unsigned char [m_width*m_height*4];
00363
00364 for(iz = 0; iz < m_depth; iz++)
00365 {
00366
00367 memset(tex_z,0,m_width*m_height*4*sizeof(unsigned char));
00368
00369
00370 for (iy = 0; iy < m_height; iy++)
00371 {
00372 for (ix = 0; ix < m_width; ix++)
00373 {
00374 value = m_scale2_raw[(m_height*m_width)*iz + (m_width)*iy + ix];
00375
00376 tex_z[((m_width)*iy + ix)*4 + 0] = (GLubyte) value;
00377 tex_z[((m_width)*iy + ix)*4 + 1] = (GLubyte) value;
00378 tex_z[((m_width)*iy + ix)*4 + 2] = (GLubyte) value;
00379 tex_z[((m_width)*iy + ix)*4 + 3] = (GLubyte) 255;
00380 }
00381 }
00382
00383
00384 glBindTexture(GL_TEXTURE_2D,(m_tex_z_s2)[iz]);
00385
00386
00387 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
00388 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
00389
00390 GLint mode = GL_CLAMP;
00391 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, mode);
00392 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, mode);
00393
00394
00395 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, m_width, m_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, tex_z);
00396 }
00397
00398 delete [] tex_z;
00399 return 0;
00400 }
00401
00402 GLuint
00403 VolumeBuffer::create2DTexturesZscale3(GLenum internalformat)
00404 {
00405
00406 glGenTextures(m_depth, (m_tex_z_s3));
00407
00408 int ix,iy,iz,value;
00409
00410
00411 unsigned char* tex_z = new unsigned char [m_width*m_height*4];
00412
00413 for(iz = 0; iz < m_depth; iz++)
00414 {
00415
00416 memset(tex_z,0,m_width*m_height*4*sizeof(unsigned char));
00417
00418
00419 for (iy = 0; iy < m_height; iy++)
00420 {
00421 for (ix = 0; ix < m_width; ix++)
00422 {
00423 value = m_scale3_raw[(m_height*m_width)*iz + (m_width)*iy + ix];
00424
00425 tex_z[((m_width)*iy + ix)*4 + 0] = (GLubyte) value;
00426 tex_z[((m_width)*iy + ix)*4 + 1] = (GLubyte) value;
00427 tex_z[((m_width)*iy + ix)*4 + 2] = (GLubyte) value;
00428 tex_z[((m_width)*iy + ix)*4 + 3] = (GLubyte) 255;
00429 }
00430 }
00431
00432
00433 glBindTexture(GL_TEXTURE_2D,(m_tex_z_s3)[iz]);
00434
00435
00436 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
00437 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
00438
00439 GLint mode = GL_CLAMP;
00440 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, mode);
00441 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, mode);
00442
00443
00444 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, m_width, m_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, tex_z);
00445 }
00446
00447 delete [] tex_z;
00448 return 0;
00449 }
00450
00451 GLuint
00452 VolumeBuffer::create2DTexturesX(GLenum internalformat)
00453 {
00454
00455 glGenTextures(m_width, (m_tex_x));
00456
00457 int ix,iy,iz,value;
00458
00459
00460 unsigned char* tex_x = new unsigned char [m_height*m_depth*4];
00461
00462 for(ix = 0; ix < m_width; ix++)
00463 {
00464
00465 memset(tex_x,0,m_height*m_depth*4*sizeof(unsigned char));
00466
00467
00468 for(iz = 0; iz < m_depth; iz++)
00469 {
00470 for (iy = 0; iy < m_height; iy++)
00471 {
00472 value = m_volume_data_raw[(m_height*m_width)*iz + (m_width)*iy + ix];
00473
00474 tex_x[((m_height)*iz + iy)*4 + 0] = (GLubyte) value;
00475 tex_x[((m_height)*iz + iy)*4 + 1] = (GLubyte) value;
00476 tex_x[((m_height)*iz + iy)*4 + 2] = (GLubyte) value;
00477 tex_x[((m_height)*iz + iy)*4 + 3] = (GLubyte) 255;
00478 }
00479 }
00480
00481
00482 glBindTexture(GL_TEXTURE_2D,(m_tex_x)[ix]);
00483
00484
00485 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
00486 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
00487
00488 GLint mode = GL_CLAMP;
00489 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, mode);
00490 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, mode);
00491
00492
00493 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, m_height, m_depth, 0, GL_RGBA, GL_UNSIGNED_BYTE, tex_x);
00494 }
00495
00496 delete [] tex_x;
00497 return 0;
00498 }
00499
00500 GLuint
00501 VolumeBuffer::create2DTexturesY(GLenum internalformat)
00502 {
00503
00504 glGenTextures(m_height, (m_tex_y));
00505
00506 int ix,iy,iz,value;
00507
00508
00509 unsigned char* tex_y = new unsigned char [m_width*m_depth*4];
00510
00511 for(iy = 0; iy < m_height; iy++)
00512 {
00513
00514 memset(tex_y,0,m_width*m_depth*4*sizeof(unsigned char));
00515
00516
00517 for(iz = 0; iz < m_depth; iz++)
00518 {
00519 for (ix = 0; ix < m_width; ix++)
00520 {
00521 value = m_volume_data_raw[(m_height*m_width)*iz + (m_width)*iy + ix];
00522
00523 tex_y[((m_width)*iz + ix)*4 + 0] = (GLubyte) value;
00524 tex_y[((m_width)*iz + ix)*4 + 1] = (GLubyte) value;
00525 tex_y[((m_width)*iz + ix)*4 + 2] = (GLubyte) value;
00526 tex_y[((m_width)*iz + ix)*4 + 3] = (GLubyte) 255;
00527 }
00528 }
00529
00530
00531 glBindTexture(GL_TEXTURE_2D,(m_tex_y)[iy]);
00532
00533
00534 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
00535 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
00536
00537 GLint mode = GL_CLAMP;
00538 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, mode);
00539 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, mode);
00540
00541
00542 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, m_width, m_depth, 0, GL_RGBA, GL_UNSIGNED_BYTE, tex_y);
00543 }
00544
00545 delete [] tex_y;
00546 return 0;
00547 }
00548
00549 void
00550 VolumeBuffer::setWrapMode(GLint mode, int bank)
00551 {
00552 glBindTexture(GL_TEXTURE_3D, m_tex[bank]);
00553 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, mode);
00554 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, mode);
00555 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, mode);
00556 }
00557
00558 void
00559 VolumeBuffer::setFiltering(GLint mode, int bank)
00560 {
00561 glBindTexture(GL_TEXTURE_3D, m_tex[bank]);
00562 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, mode);
00563 glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, mode);
00564 }
00565
00566 int
00567 VolumeBuffer::setData(unsigned char *data, int bank)
00568 {
00569 glBindTexture(GL_TEXTURE_3D, m_tex[bank]);
00570
00571
00572
00573
00574
00575
00576 glTexImage3D = (PFNGLTEXIMAGE3DPROC) wglGetProcAddress("glTexImage3D");
00577 if (glTexImage3D == NULL) {
00578 printf("Error in line %d: Couldn't load glTexImage3D function. Aborting.\n", __LINE__);
00579 return -1;
00580 }
00581
00582
00583 glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA, m_width, m_height, m_depth, 0 , GL_RGBA, GL_UNSIGNED_BYTE, data);
00584 }
00585
00586 void
00587
00588 VolumeBuffer::set2DData(unsigned char* data, int bank)
00589 {
00590 glBindTexture(GL_TEXTURE_2D, m_tex[bank]);
00591 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, m_width, m_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
00592
00593 }
00594
00595
00596 void
00597 VolumeBuffer::drawSlice(float z)
00598 {
00599 glEnable(GL_TEXTURE_3D);
00600 glPixelStorei (GL_UNPACK_ALIGNMENT, 1);
00601 glBegin(GL_QUADS);
00602 glTexCoord3f(0.0f, 0.0f, z); glVertex3f(-1.0f, -1.0f, 0.0f);
00603 glTexCoord3f(1.0f, 0.0f, z); glVertex3f(1.0f, -1.0f, 0.0f);
00604 glTexCoord3f(1.0f, 1.0f, z); glVertex3f(1.0f, 1.0f, 0.0f);
00605 glTexCoord3f(0.0f, 1.0f, z); glVertex3f(-1.0f, 1.0f, 0.0f);
00606 glEnd();
00607 }
00608
00609 void
00610 VolumeBuffer::drawOneSlice()
00611 {
00612 glBegin(GL_QUADS);
00613
00614 glTexCoord3f(0.0f, 0.0f, 0.0f); glVertex3f (-1.0f, -1.0f, 0.0f);
00615 glTexCoord3f(0.0f, 1.0f, 0.0f); glVertex3f (1.0f, -1.0f, 0.0f);
00616 glTexCoord3f(1.0f, 1.0f, 0.0f); glVertex3f (1.0f, 1.0f, 0.0f);
00617 glTexCoord3f(1.0f, 0.0f, 0.0f); glVertex3f (-1.0f, 1.0f, 0.0f);
00618
00619 glEnd();
00620 }
00621
00622 void
00623 VolumeBuffer::drawZSlice(int iz)
00624 {
00625 glBindTexture(GL_TEXTURE_2D, m_tex_z[iz]);
00626
00627 glBegin(GL_QUADS);
00628
00629 glTexCoord3f(0.0f, 0.0f, 0.0f); glVertex3f (-1.0f, -1.0f, 0.0f);
00630 glTexCoord3f(0.0f, 1.0f, 0.0f); glVertex3f (1.0f, -1.0f, 0.0f);
00631 glTexCoord3f(1.0f, 1.0f, 0.0f); glVertex3f (1.0f, 1.0f, 0.0f);
00632 glTexCoord3f(1.0f, 0.0f, 0.0f); glVertex3f (-1.0f, 1.0f, 0.0f);
00633
00634 glEnd();
00635 }
00636
00637 void
00638 VolumeBuffer::drawXSlice(int ix)
00639 {
00640 glBindTexture(GL_TEXTURE_2D, m_tex_x[ix]);
00641
00642 glBegin(GL_QUADS);
00643
00644 glTexCoord3f(0.0f, 0.0f, 0.0f); glVertex3f (-1.0f, -1.0f, 0.0f);
00645 glTexCoord3f(0.0f, 1.0f, 0.0f); glVertex3f (1.0f, -1.0f, 0.0f);
00646 glTexCoord3f(1.0f, 1.0f, 0.0f); glVertex3f (1.0f, 1.0f, 0.0f);
00647 glTexCoord3f(1.0f, 0.0f, 0.0f); glVertex3f (-1.0f, 1.0f, 0.0f);
00648
00649 glEnd();
00650 }
00651
00652 void
00653 VolumeBuffer::drawYSlice(int iy)
00654 {
00655 glBindTexture(GL_TEXTURE_2D, m_tex_y[iy]);
00656
00657 glBegin(GL_QUADS);
00658
00659 glTexCoord3f(0.0f, 0.0f, 0.0f); glVertex3f (-1.0f, -1.0f, 0.0f);
00660 glTexCoord3f(0.0f, 1.0f, 0.0f); glVertex3f (1.0f, -1.0f, 0.0f);
00661 glTexCoord3f(1.0f, 1.0f, 0.0f); glVertex3f (1.0f, 1.0f, 0.0f);
00662 glTexCoord3f(1.0f, 0.0f, 0.0f); glVertex3f (-1.0f, 1.0f, 0.0f);
00663
00664 glEnd();
00665 }
00666
00667 int
00668 VolumeBuffer::readRawFile(char *filename)
00669 {
00670 FILE *fp = fopen(filename, "rb");
00671
00672 if (!fp) {
00673 fprintf(stderr, "Error opening file '%s'\n", filename);
00674 return 0;
00675 }
00676
00677 size_t read = fread(m_volume_data_raw, sizeof(unsigned char), m_volume_size, fp);
00678 fclose(fp);
00679
00680
00681
00682 int i, j, k, c;
00683
00684 for (i = 0; i < m_depth; i++) {
00685 for (j = 0; j < m_height; j++) {
00686 for (k = 0; k < m_width; k++) {
00687
00688 c = m_volume_data_raw[(m_height*m_width)*i + (m_width)*j + k];
00689
00690
00691
00692
00693
00694
00695
00696 }
00697 }
00698 }
00699
00700 printf("Read '%s', %d bytes\n", filename, read);
00701
00702 }
00703
00704 int
00705 VolumeBuffer::readScale1File(char *filename)
00706 {
00707 FILE *fp = fopen(filename, "rb");
00708
00709 if (!fp) {
00710 fprintf(stderr, "Error opening file '%s'\n", filename);
00711 return 0;
00712 }
00713
00714 size_t read = fread(m_scale1_raw, sizeof(unsigned char), m_volume_size, fp);
00715 fclose(fp);
00716
00717
00718
00719 int i, j, k, c;
00720
00721 for (i = 0; i < m_depth; i++) {
00722 for (j = 0; j < m_height; j++) {
00723 for (k = 0; k < m_width; k++) {
00724
00725 c = m_scale1_raw[(m_height*m_width)*i + (m_width)*j + k];
00726
00727
00728
00729
00730
00731
00732
00733 }
00734 }
00735 }
00736
00737 printf("Scale1: read '%s', %d bytes\n", filename, read);
00738
00739 }
00740
00741 int
00742 VolumeBuffer::readScale2File(char *filename)
00743 {
00744 FILE *fp = fopen(filename, "rb");
00745
00746 if (!fp) {
00747 fprintf(stderr, "Error opening file '%s'\n", filename);
00748 return 0;
00749 }
00750
00751 size_t read = fread(m_scale2_raw, sizeof(unsigned char), m_volume_size, fp);
00752 fclose(fp);
00753
00754
00755
00756 int i, j, k, c;
00757
00758 for (i = 0; i < m_depth; i++) {
00759 for (j = 0; j < m_height; j++) {
00760 for (k = 0; k < m_width; k++) {
00761
00762 c = m_scale2_raw[(m_height*m_width)*i + (m_width)*j + k];
00763
00764
00765
00766
00767
00768
00769
00770 }
00771 }
00772 }
00773
00774 printf("Scale2: read '%s', %d bytes\n", filename, read);
00775
00776 }
00777
00778 int
00779 VolumeBuffer::readScale3File(char *filename)
00780 {
00781 FILE *fp = fopen(filename, "rb");
00782
00783 if (!fp) {
00784 fprintf(stderr, "Error opening file '%s'\n", filename);
00785 return 0;
00786 }
00787
00788 size_t read = fread(m_scale3_raw, sizeof(unsigned char), m_volume_size, fp);
00789 fclose(fp);
00790
00791
00792
00793 int i, j, k, c;
00794
00795 for (i = 0; i < m_depth; i++) {
00796 for (j = 0; j < m_height; j++) {
00797 for (k = 0; k < m_width; k++) {
00798
00799 c = m_scale3_raw[(m_height*m_width)*i + (m_width)*j + k];
00800
00801
00802
00803
00804
00805
00806
00807 }
00808 }
00809 }
00810
00811 printf("Scale3: read '%s', %d bytes\n", filename, read);
00812
00813 }