00001 #include "VVolumeRenderer.h"
00002 #include "glew.h"
00003
00004 VVolumeRenderer::VVolumeRenderer() :
00005 m_ProgramLoaded(false),
00006 m_TransferFunctionHandle(0),
00007 m_TransferFunction2DHandle(0),
00008 m_FrontFaceTexture(NULL),
00009 m_BackFaceTexture(NULL),
00010 m_WorldFrontFaceTexture(NULL),
00011 m_WorldBackFaceTexture(NULL),
00012 m_ProxyGeometryDisplayListHandle(0),
00013 m_tf_activated(0),
00014 swmip(this),
00015 swmiptf(this),
00016 swmiptf2d(this),
00017 swdvr(this),
00018 swdvrtf(this),
00019 swdvrtf2d(this),
00020 swdvrbtf(this),
00021 swdvrbtftf(this),
00022 swdvrbtftf2d(this),
00023 swdvrcombphong(this),
00024 swdvrcombphongcont(this),
00025 swdvrcombphongshadow(this),
00026 swdvrcombphongcontshadow(this),
00027 swdvrcombphongt2f(this),
00028 swdvrcombphongcontt2f(this),
00029 swdvrcombphongshadowt2f(this),
00030 swdvrcombphongcontshadowt2f(this),
00031
00032 swdvrcombtoon(this),
00033 swdvrcombtooncont(this),
00034 swdvrcombtoonshadow(this),
00035 swdvrcombtooncontshadow(this),
00036 swdvrcombtoon2f(this),
00037 swdvrcombtooncont2f(this),
00038 swdvrcombtoonshadow2f(this),
00039 swdvrcombtooncontshadow2f(this),
00040
00041 swdvrcombmetal(this),
00042 swdvrcombmetalcont(this),
00043 swdvrcombmetalshadow(this),
00044 swdvrcombmetalcontshadow(this),
00045 swdvrcombmetal2f(this),
00046 swdvrcombmetalcont2f(this),
00047 swdvrcombmetalshadow2f(this),
00048 swdvrcombmetalcontshadow2f(this),
00049 swcurvature(this),
00050 m_ContourHandle(0),
00051 m_thresholdH(0.5f),
00052 m_thresholdL(0.5f)
00053 {
00054 m_Volume = NULL;
00055 VVector eye(0.0f, 0.0f, -1.0f);
00056 VVector view(0.0f, 0.0f, 1.0f);
00057 VVector up(0.0f, 1.0f, 0.0f);
00058
00059 m_VolumeSize[0] = 1.0f;
00060 m_VolumeSize[1] = 1.0f;
00061 m_VolumeSize[2] = 1.0f;
00062 m_VolumeSize[3] = 1.0f;
00063
00064 m_Camera.lookInDirection(eye, view, up);
00065
00066 m_renderMode = MIP;
00067 m_lightMode = PHONG;
00068
00069 m_shadows = false;
00070 m_contours = false;
00071
00072 m_Raycast = &swmip;
00073
00074 maxSize = 0.5f;
00075 xsize = 1.0f;
00076 ysize = 1.0f;
00077 zsize = 1.0f;
00078
00079 m_ClipPlanes[LEFT_RIGHT] = 0.0f;
00080 m_ClipPlanes[RIGHT_LEFT] = 1.0f;
00081 m_ClipPlanes[BOTTOM_TOP] = 0.0f;
00082 m_ClipPlanes[TOP_BOTTOM] = 1.0f;
00083 m_ClipPlanes[FRONT_BACK] = 0.0f;
00084 m_ClipPlanes[BACK_FRONT] = 1.0f;
00085
00086 float xneg = m_ClipPlanes[LEFT_RIGHT];
00087 float xpos = m_ClipPlanes[RIGHT_LEFT];
00088
00089 float yneg = m_ClipPlanes[BOTTOM_TOP];
00090 float ypos = m_ClipPlanes[TOP_BOTTOM];
00091
00092 float zneg = m_ClipPlanes[FRONT_BACK];
00093 float zpos = m_ClipPlanes[BACK_FRONT];
00094
00095 m_ClipPlaneObj[LEFT_RIGHT] = VPlane(VVector(-1.0f, 0.0f, 0.0f), VVector((-xsize) + (xneg * xsize/0.5f), 0.0f, 0.0f));
00096 m_ClipPlaneObj[RIGHT_LEFT] = VPlane(VVector(1.0f, 0.0f, 0.0f), VVector(xsize - ((1.0f - xpos) * xsize/0.5f), 0.0f, 0.0f));
00097
00098 m_ClipPlaneObj[BOTTOM_TOP] = VPlane(VVector(0.0f, -1.0f, 0.0f), VVector(0.0f, (-ysize) + (yneg * ysize/0.5f), 0.0f));
00099 m_ClipPlaneObj[TOP_BOTTOM] = VPlane(VVector(0.0f, 1.0f, 0.0f), VVector(0.0f, ysize - ((1.0f - ypos) * ysize/0.5f), 0.0f));
00100
00101 m_ClipPlaneObj[FRONT_BACK] = VPlane(VVector(0.0f, 0.0f, -1.0f), VVector(0.0f, 0.0f, (-zsize) + (zneg * zsize/0.5f)));
00102 m_ClipPlaneObj[BACK_FRONT] = VPlane(VVector(0.0f, 0.0f, 1.0f), VVector(0.0f, 0.0f, zsize - ((1.0f - zpos) * zsize/0.5f)));
00103
00104 m_updateDL = true;
00105
00106 m_ClearColor[0] = 0.0f;
00107 m_ClearColor[1] = 0.0f;
00108 m_ClearColor[2] = 0.0f;
00109
00110 m_LightDir[0] = 0.0f;
00111 m_LightDir[1] = 1.0f;
00112 m_LightDir[2] = 0.0f;
00113
00114 m_Tex2WorldSpace.scale(VVector(2.0f, 2.0f, 2.0f));
00115 m_Tex2WorldSpace.translate(VVector(-0.5f, -0.5f, -0.5f));
00116
00117 m_NoiseTex = new VImage();
00118 m_ToonTex = new VImage();
00119 m_MetalTex = new VImage();
00120 }
00121
00122
00123 VVolumeRenderer::VVolumeRenderer(VVolume * volume) :
00124 m_ProgramLoaded(false),
00125 m_TransferFunctionHandle(0),
00126 m_TransferFunction2DHandle(0),
00127 m_FrontFaceTexture(NULL),
00128 m_BackFaceTexture(NULL),
00129 m_WorldFrontFaceTexture(NULL),
00130 m_WorldBackFaceTexture(NULL),
00131 m_ProxyGeometryDisplayListHandle(0),
00132 swmip(this),
00133 swmiptf(this),
00134 swmiptf2d(this),
00135 swdvr(this),
00136 swdvrtf(this),
00137 swdvrtf2d(this),
00138 swdvrbtf(this),
00139 swdvrbtftf(this),
00140 swdvrbtftf2d(this),
00141 swdvrcombphong(this),
00142 swdvrcombphongcont(this),
00143 swdvrcombphongshadow(this),
00144 swdvrcombphongcontshadow(this),
00145 swdvrcombphongt2f(this),
00146 swdvrcombphongcontt2f(this),
00147 swdvrcombphongshadowt2f(this),
00148 swdvrcombphongcontshadowt2f(this),
00149 swdvrcombtoon(this),
00150 swdvrcombtooncont(this),
00151 swdvrcombtoonshadow(this),
00152 swdvrcombtooncontshadow(this),
00153 swdvrcombtoon2f(this),
00154 swdvrcombtooncont2f(this),
00155 swdvrcombtoonshadow2f(this),
00156 swdvrcombtooncontshadow2f(this),
00157 swdvrcombmetal(this),
00158 swdvrcombmetalcont(this),
00159 swdvrcombmetalshadow(this),
00160 swdvrcombmetalcontshadow(this),
00161 swdvrcombmetal2f(this),
00162 swdvrcombmetalcont2f(this),
00163 swdvrcombmetalshadow2f(this),
00164 swdvrcombmetalcontshadow2f(this),
00165 swcurvature(this),
00166 m_ContourHandle(0),
00167 m_thresholdH(0.5f),
00168 m_thresholdL(0.5f)
00169 {
00170 m_Volume = volume;
00171
00172 VVector eye(0.0f, 0.0f, -1.0f);
00173 VVector view(0.0f, 0.0f, 1.0f);
00174 VVector up(0.0f, 1.0f, 0.0f);
00175 m_Camera.lookInDirection(eye, view, up);
00176
00177 m_VolumeSize[0] = 1.0f;
00178 m_VolumeSize[1] = 1.0f;
00179 m_VolumeSize[2] = 1.0f;
00180 m_VolumeSize[3] = 1.0f;
00181
00182 m_renderMode = MIP;
00183 m_lightMode = PHONG;
00184
00185 m_shadows = false;
00186 m_contours = false;
00187
00188 ShaderWrapperMIP sw(this);
00189 m_Raycast = &sw;
00190
00191 maxSize = (m_Volume->getDimX() < m_Volume->getDimY()) ? (float)m_Volume->getDimY() : (float)m_Volume->getDimX();
00192 maxSize = (maxSize < m_Volume->getDimZ()) ? (float)m_Volume->getDimZ() : maxSize;
00193 xsize = (float)(m_Volume->getDimX())/(float)(2*maxSize);
00194 ysize = (float)(m_Volume->getDimY())/(float)(2*maxSize);
00195 zsize = (float)(m_Volume->getDimZ())/(float)(2*maxSize);
00196
00197 m_ClipPlanes[LEFT_RIGHT] = 0.0f;
00198 m_ClipPlanes[RIGHT_LEFT] = 1.0f;
00199 m_ClipPlanes[BOTTOM_TOP] = 0.0f;
00200 m_ClipPlanes[TOP_BOTTOM] = 1.0f;
00201 m_ClipPlanes[FRONT_BACK] = 0.0f;
00202 m_ClipPlanes[BACK_FRONT] = 1.0f;
00203
00204 float xneg = m_ClipPlanes[LEFT_RIGHT];
00205 float xpos = m_ClipPlanes[RIGHT_LEFT];
00206
00207 float yneg = m_ClipPlanes[BOTTOM_TOP];
00208 float ypos = m_ClipPlanes[TOP_BOTTOM];
00209
00210 float zneg = m_ClipPlanes[FRONT_BACK];
00211 float zpos = m_ClipPlanes[BACK_FRONT];
00212
00213 m_ClipPlaneObj[LEFT_RIGHT] = VPlane(VVector(-1.0f, 0.0f, 0.0f), VVector((-xsize) + (xneg * xsize/0.5f), 0.0f, 0.0f));
00214 m_ClipPlaneObj[RIGHT_LEFT] = VPlane(VVector(1.0f, 0.0f, 0.0f), VVector(xsize - ((1.0f - xpos) * xsize/0.5f), 0.0f, 0.0f));
00215
00216 m_ClipPlaneObj[BOTTOM_TOP] = VPlane(VVector(0.0f, -1.0f, 0.0f), VVector(0.0f, (-ysize) + (yneg * ysize/0.5f), 0.0f));
00217 m_ClipPlaneObj[TOP_BOTTOM] = VPlane(VVector(0.0f, 1.0f, 0.0f), VVector(0.0f, ysize - ((1.0f - ypos) * ysize/0.5f), 0.0f));
00218
00219 m_ClipPlaneObj[FRONT_BACK] = VPlane(VVector(0.0f, 0.0f, -1.0f), VVector(0.0f, 0.0f, (-zsize) + (zneg * zsize/0.5f)));
00220 m_ClipPlaneObj[BACK_FRONT] = VPlane(VVector(0.0f, 0.0f, 1.0f), VVector(0.0f, 0.0f, zsize - ((1.0f - zpos) * zsize/0.5f)));
00221
00222 m_updateDL = true;
00223
00224 m_ClearColor[0] = 0.0f;
00225 m_ClearColor[1] = 0.0f;
00226 m_ClearColor[2] = 0.0f;
00227
00228 m_LightDir[0] = 0.0f;
00229 m_LightDir[1] = 1.0f;
00230 m_LightDir[2] = 0.0f;
00231
00232 m_Tex2WorldSpace.scale(VVector(2.0f * xsize, 2.0f * ysize, 2.0f * zsize));
00233 m_Tex2WorldSpace.translate(VVector(-0.5f, -0.5f, -0.5f));
00234
00235 m_NoiseTex = new VImage();
00236 m_ToonTex = new VImage();
00237 m_MetalTex = new VImage();
00238
00239 }
00240
00241 void VVolumeRenderer::setRenderMode(RenderMode rm )
00242 {
00243 m_renderMode = rm;
00244
00245 if (rm == MIP && m_tf_activated==0)
00246 {
00247 m_Raycast = &swmip;
00248
00249 }else if (rm == MIP && m_tf_activated==1)
00250 {
00251
00252 m_Raycast = &swmiptf;
00253
00254 }else if (rm == MIP && m_tf_activated==2)
00255 {
00256 m_Raycast = &swmiptf2d;
00257 }
00258
00259 if (rm == DVR_FTB && m_tf_activated==0)
00260 {
00261 m_Raycast = &swdvr;
00262
00263 }else if (rm == DVR_FTB && m_tf_activated==1)
00264 {
00265 m_Raycast = &swdvrtf;
00266
00267 }else if (rm == DVR_FTB && m_tf_activated==2)
00268 {
00269 m_Raycast = &swdvrtf2d;
00270 }
00271
00272 if (rm == DVR_BTF && m_tf_activated==0)
00273 {
00274 m_Raycast = &swdvrbtf;
00275
00276 }else if (rm == DVR_BTF && m_tf_activated==1)
00277 {
00278 m_Raycast = &swdvrbtftf;
00279
00280 }else if (rm == DVR_BTF && m_tf_activated==2)
00281 {
00282 m_Raycast = &swdvrbtftf2d;
00283 }
00284
00285
00286
00287 if (rm == COMB && m_lightMode == PHONG && !m_shadows && !m_contours)
00288 {
00289 if(m_tf_activated==1)
00290 m_Raycast = &swdvrcombphong;
00291 else if(m_tf_activated==2)
00292 m_Raycast = &swdvrcombphongt2f;
00293
00294 }else if (rm == COMB && m_lightMode == PHONG && !m_shadows && m_contours)
00295 {
00296 if(m_tf_activated==1)
00297 m_Raycast = &swdvrcombphongcont;
00298 else if(m_tf_activated==2)
00299 m_Raycast = &swdvrcombphongcontt2f;
00300
00301 }else if (rm == COMB && m_lightMode == PHONG && m_shadows && m_contours)
00302 {
00303 if(m_tf_activated==1)
00304 m_Raycast = &swdvrcombphongcontshadow;
00305 else if(m_tf_activated==2)
00306 m_Raycast = &swdvrcombphongcontshadowt2f;
00307
00308 }else if (rm == COMB && m_lightMode == PHONG && m_shadows && !m_contours)
00309 {
00310 if(m_tf_activated==1)
00311 m_Raycast = &swdvrcombphongshadow;
00312 else if(m_tf_activated==2)
00313 m_Raycast = &swdvrcombphongshadowt2f;
00314 }
00315
00316
00317 else if (rm == COMB && m_lightMode == TOON && !m_shadows && !m_contours)
00318 {
00319 if(m_tf_activated==1)
00320 m_Raycast = &swdvrcombtoon;
00321 else if(m_tf_activated==2)
00322 m_Raycast = &swdvrcombtoon2f;
00323
00324 }else if (rm == COMB && m_lightMode == TOON && !m_shadows && m_contours)
00325 {
00326 if(m_tf_activated==1)
00327 m_Raycast = &swdvrcombtooncont;
00328 else if(m_tf_activated==2)
00329 m_Raycast = &swdvrcombtooncont2f;
00330
00331 }else if (rm == COMB && m_lightMode == TOON && m_shadows && m_contours)
00332 {
00333 if(m_tf_activated==1)
00334 m_Raycast = &swdvrcombtooncontshadow;
00335 else if(m_tf_activated==2)
00336 m_Raycast = &swdvrcombtooncontshadow2f;
00337
00338 }else if (rm == COMB && m_lightMode == TOON && m_shadows && !m_contours)
00339 {
00340 if(m_tf_activated==1)
00341 m_Raycast = &swdvrcombtoonshadow;
00342 else if(m_tf_activated==2)
00343 m_Raycast = &swdvrcombtoonshadow2f;
00344 }
00345
00346
00347 else if (rm == COMB && m_lightMode == METAL && !m_shadows && !m_contours)
00348 {
00349 if(m_tf_activated==1)
00350 m_Raycast = &swdvrcombmetal;
00351 else if(m_tf_activated==2)
00352 m_Raycast = &swdvrcombmetal2f;
00353
00354 }else if (rm == COMB && m_lightMode == METAL && !m_shadows && m_contours)
00355 {
00356 if(m_tf_activated==1)
00357 m_Raycast = &swdvrcombmetalcont;
00358 else if(m_tf_activated==2)
00359 m_Raycast = &swdvrcombmetalcont2f;
00360
00361 }else if (rm == COMB && m_lightMode == METAL && m_shadows && m_contours)
00362 {
00363 if(m_tf_activated==1)
00364 m_Raycast = &swdvrcombmetalcontshadow;
00365 else if(m_tf_activated==2)
00366 m_Raycast = &swdvrcombmetalcontshadow2f;
00367
00368 }else if (rm == COMB && m_lightMode == METAL && m_shadows && !m_contours)
00369 {
00370 if(m_tf_activated==1)
00371 m_Raycast = &swdvrcombmetalshadow;
00372 else if(m_tf_activated==2)
00373 m_Raycast = &swdvrcombmetalshadow2f;
00374 }
00375
00376 if(rm == CURVATURE)
00377 {
00378 m_Raycast = &swcurvature;
00379 }
00380
00381 }
00382
00383 void VVolumeRenderer::drawFrontFaces()
00384 {
00385 if(m_ProxyGeometryDisplayListHandle == 0)
00386 {
00387 generateProxyGeometryDisplayList();
00388 }
00389 if(m_updateDL)
00390 {
00391 generateProxyGeometryDisplayList();
00392 }
00393
00394 m_WorldPosProgram.bind();
00395
00396 m_Camera.updateProjMatrix();
00397 m_Camera.updateViewMatrix();
00398
00399 glUniformMatrix4fv(m_WorldPosProgram.getUniformLocation("mModelMatrix"),1,false,m_Volume->getModelMatrix());
00400 glUniformMatrix4fv(m_WorldPosProgram.getUniformLocation("mViewMatrix"),1,false,m_Camera.getViewMatrix());
00401 glUniformMatrix4fv(m_WorldPosProgram.getUniformLocation("mProjectionMatrix"),1,false,m_Camera.getProjectionMatrix());
00402 glUniform4fv(m_WorldPosProgram.getUniformLocation("mVolumeSize"), 1, m_VolumeSize);
00403 m_FrontFaceTexture->bind();
00404
00405 glEnable(GL_CULL_FACE);
00406 glCullFace(GL_BACK);
00407
00408 glCallList(m_ProxyGeometryDisplayListHandle);
00409
00410 GLenum glError = glGetError();
00411
00412 if (glError != GL_NO_ERROR)
00413 std::cout << "Error Rendering Proxy Geometry Front " << gluErrorString(glError) << std::endl;
00414
00415 m_FrontFaceTexture->unbind();
00416
00417 m_WorldPosProgram.release();
00418
00419
00420
00421
00422 m_WorldWorldProgram.bind();
00423
00424 glUniformMatrix4fv(m_WorldWorldProgram.getUniformLocation("mModelMatrix"),1,false,m_Volume->getModelMatrix());
00425 glUniformMatrix4fv(m_WorldWorldProgram.getUniformLocation("mViewMatrix"),1,false,m_Camera.getViewMatrix());
00426 glUniformMatrix4fv(m_WorldWorldProgram.getUniformLocation("mProjectionMatrix"),1,false,m_Camera.getProjectionMatrix());
00427 glUniform4fv(m_WorldWorldProgram.getUniformLocation("mVolumeSize"), 1, m_VolumeSize);
00428 m_WorldFrontFaceTexture->bind();
00429
00430 glEnable(GL_CULL_FACE);
00431 glCullFace(GL_BACK);
00432
00433 glCallList(m_ProxyGeometryDisplayListHandle);
00434
00435 glError = glGetError();
00436
00437 if (glError != GL_NO_ERROR)
00438 std::cout << "Error Rendering Proxy Geometry Front " << gluErrorString(glError) << std::endl;
00439
00440 m_WorldFrontFaceTexture->unbind();
00441
00442 m_WorldWorldProgram.release();
00443 }
00444
00445 void VVolumeRenderer::drawFrontFacesToSmallQuad()
00446 {
00447 m_WorldFrontFaceTexture->renderToLowerLeftQuad();
00448 }
00449
00450 void VVolumeRenderer::drawBackFaces()
00451 {
00452
00453 if(m_ProxyGeometryDisplayListHandle == 0)
00454 {
00455 generateProxyGeometryDisplayList();
00456 }
00457 if(m_updateDL)
00458 {
00459 generateProxyGeometryDisplayList();
00460 }
00461
00462 m_WorldPosProgram.bind();
00463
00464 m_Camera.updateProjMatrix();
00465 m_Camera.updateViewMatrix();
00466
00467 glUniformMatrix4fv(m_WorldPosProgram.getUniformLocation("mModelMatrix"),1,false,m_Volume->getModelMatrix());
00468 glUniformMatrix4fv(m_WorldPosProgram.getUniformLocation("mViewMatrix"),1,false,m_Camera.getViewMatrix());
00469 glUniformMatrix4fv(m_WorldPosProgram.getUniformLocation("mProjectionMatrix"),1,false,m_Camera.getProjectionMatrix());
00470 glUniform4fv(m_WorldPosProgram.getUniformLocation("mVolumeSize"), 1, m_VolumeSize);
00471
00472
00473 m_BackFaceTexture->bind();
00474
00475 glEnable(GL_CULL_FACE);
00476 glCullFace(GL_FRONT);
00477
00478 glCallList(m_ProxyGeometryDisplayListHandle);
00479
00480 GLenum glError = glGetError();
00481
00482 if (glError != GL_NO_ERROR)
00483 std::cout << "Error Rendering Proxy Geometry Back " << gluErrorString(glError) << std::endl;
00484
00485 m_BackFaceTexture->unbind();
00486
00487 m_WorldPosProgram.release();
00488
00489
00490 m_WorldWorldProgram.bind();
00491
00492 glUniformMatrix4fv(m_WorldWorldProgram.getUniformLocation("mModelMatrix"),1,false,m_Volume->getModelMatrix());
00493 glUniformMatrix4fv(m_WorldWorldProgram.getUniformLocation("mViewMatrix"),1,false,m_Camera.getViewMatrix());
00494 glUniformMatrix4fv(m_WorldWorldProgram.getUniformLocation("mProjectionMatrix"),1,false,m_Camera.getProjectionMatrix());
00495 glUniform4fv(m_WorldWorldProgram.getUniformLocation("mVolumeSize"), 1, m_VolumeSize);
00496
00497
00498 m_WorldBackFaceTexture->bind();
00499
00500 glEnable(GL_CULL_FACE);
00501 glCullFace(GL_FRONT);
00502
00503 glCallList(m_ProxyGeometryDisplayListHandle);
00504
00505 glError = glGetError();
00506
00507 if (glError != GL_NO_ERROR)
00508 std::cout << "Error Rendering Proxy Geometry Back " << gluErrorString(glError) << std::endl;
00509
00510 m_WorldBackFaceTexture->unbind();
00511
00512 m_WorldWorldProgram.release();
00513 }
00514
00515 void VVolumeRenderer::drawBackFacesToSmallQuad()
00516 {
00517 m_WorldBackFaceTexture->renderToLowerRightQuad();
00518 }
00519
00520 void VVolumeRenderer::draw()
00521 {
00522 if(m_ContourHandle == 0)
00523 {
00524 initContourTexture();
00525 }
00526
00527 m_Raycast->set();
00528
00529 float fw = 662.0f / (float)m_Width;
00530 float fh = 662.0f / (float)m_Height;
00531
00532 float w0 = 1.0f;
00533 float h0 = 1.0f;
00534 float aspect = ((float)m_Volume->getDimX()/(float)m_Volume->getDimZ());
00535
00536
00537
00538 if (fw > fh)
00539 {
00540 h0 /= fw;
00541 h0 *= fh;
00542
00543 }else
00544 {
00545 w0 /= fh;
00546 w0 *= fw;
00547 }
00548
00549
00550 glBegin(GL_QUADS);
00551 glTexCoord2f(0.0f, 0.0f);
00552 glVertex3f(-w0, -h0, 0.0);
00553
00554 glTexCoord2f(0.0f, 1.0f);
00555 glVertex3f(-w0, h0, 0.0);
00556
00557 glTexCoord2f(1.0f, 1.0f);
00558 glVertex3f(w0, h0, 0.0);
00559
00560 glTexCoord2f(1.0f, 0.0f);
00561 glVertex3f(w0, -h0, 0.0);
00562 glEnd();
00563
00564 m_Raycast->clean();
00565
00566
00567 }
00568
00569 void VVolumeRenderer::generateProxyGeometryDisplayList()
00570 {
00571 if(m_ProxyGeometryDisplayListHandle != 0)
00572 {
00573 glDeleteLists(m_ProxyGeometryDisplayListHandle, 1);
00574 }
00575 m_ProxyGeometryDisplayListHandle = glGenLists(1);
00576
00577 float xneg = m_ClipPlanes[LEFT_RIGHT];
00578 float xpos = m_ClipPlanes[RIGHT_LEFT];
00579
00580 float yneg = m_ClipPlanes[BOTTOM_TOP];
00581 float ypos = m_ClipPlanes[TOP_BOTTOM];
00582
00583 float zneg = m_ClipPlanes[FRONT_BACK];
00584 float zpos = m_ClipPlanes[BACK_FRONT];
00585
00586 m_VolumeSize[0] = xsize;
00587 m_VolumeSize[1] = ysize;
00588 m_VolumeSize[2] = zsize;
00589 m_VolumeSize[3] = 1.0f;
00590
00591 glNewList(m_ProxyGeometryDisplayListHandle, GL_COMPILE);
00592 glBegin(GL_QUADS);
00593
00594
00595 glMultiTexCoord3f(GL_TEXTURE0, xneg, yneg, zpos);
00596 glVertex3f(float((-xsize) + (xneg * xsize/0.5f)), float((-ysize) + (yneg * ysize/0.5f)), float(zsize - ((1.0f - zpos) * zsize/0.5f)));
00597
00598 glMultiTexCoord3f(GL_TEXTURE0, xpos, yneg, zpos);
00599 glVertex3f( float(xsize - ((1.0f - xpos) * xsize/0.5f)), float((-ysize) + (yneg * ysize/0.5f)), float(zsize - ((1.0f - zpos) * zsize/0.5f)));
00600
00601 glMultiTexCoord3f(GL_TEXTURE0, xpos, ypos, zpos);
00602 glVertex3f( float(xsize - ((1.0f - xpos) * xsize/0.5f)), float(ysize - ((1.0f - ypos) * ysize/0.5f)), float(zsize - ((1.0f - zpos) * zsize/0.5f)));
00603
00604 glMultiTexCoord3f(GL_TEXTURE0, xneg, ypos, zpos);
00605 glVertex3f(float((-xsize) + (xneg * xsize/0.5f)), float(ysize - ((1.0f - ypos) * ysize/0.5f)), float(zsize - ((1.0f - zpos) * zsize/0.5f)));
00606
00607
00608
00609 glMultiTexCoord3f(GL_TEXTURE0, xneg, yneg, zneg);
00610 glVertex3f(float((-xsize) + (xneg * xsize/0.5f)), float((-ysize) + (yneg * ysize/0.5f)), float((-zsize) + (zneg * zsize/0.5f)));
00611
00612 glMultiTexCoord3f(GL_TEXTURE0, xneg, ypos, zneg);
00613 glVertex3f(float((-xsize) + (xneg * xsize/0.5f)), float(ysize - ((1.0f - ypos) * ysize/0.5f)), float((-zsize) + (zneg * zsize/0.5f)));
00614
00615 glMultiTexCoord3f(GL_TEXTURE0, xpos, ypos, zneg);
00616 glVertex3f( float(xsize - ((1.0f - xpos) * xsize/0.5f)), float(ysize - ((1.0f - ypos) * ysize/0.5f)), float((-zsize) + (zneg * zsize/0.5f)));
00617
00618 glMultiTexCoord3f(GL_TEXTURE0, xpos, yneg, zneg);
00619 glVertex3f( float(xsize - ((1.0f - xpos) * xsize/0.5f)), float((-ysize) + (yneg * ysize/0.5f)), float((-zsize) + (zneg * zsize/0.5f)));
00620
00621
00622
00623 glMultiTexCoord3f(GL_TEXTURE0, xneg, ypos, zneg);
00624 glVertex3f(float((-xsize) + (xneg * xsize/0.5f)), float(ysize - ((1.0f - ypos) * ysize/0.5f)), float((-zsize) + (zneg * zsize/0.5f)));
00625
00626 glMultiTexCoord3f(GL_TEXTURE0, xneg, ypos, zpos);
00627 glVertex3f(float((-xsize) + (xneg * xsize/0.5f)), float(ysize - ((1.0f - ypos) * ysize/0.5f)), float(zsize - ((1.0f - zpos) * zsize/0.5f)));
00628
00629 glMultiTexCoord3f(GL_TEXTURE0, xpos, ypos, zpos);
00630 glVertex3f( float(xsize - ((1.0f - xpos) * xsize/0.5f)), float(ysize - ((1.0f - ypos) * ysize/0.5f)), float(zsize - ((1.0f - zpos) * zsize/0.5f)));
00631
00632 glMultiTexCoord3f(GL_TEXTURE0, xpos, ypos, zneg);
00633 glVertex3f( float(xsize - ((1.0f - xpos) * xsize/0.5f)), float(ysize - ((1.0f - ypos) * ysize/0.5f)), float((-zsize) + (zneg * zsize/0.5f)));
00634
00635
00636
00637 glMultiTexCoord3f(GL_TEXTURE0, xneg, yneg, zneg);
00638 glVertex3f(float((-xsize) + (xneg * xsize/0.5f)), float((-ysize) + (yneg * ysize/0.5f)), float((-zsize) + (zneg * zsize/0.5f)));
00639
00640 glMultiTexCoord3f(GL_TEXTURE0, xpos, yneg, zneg);
00641 glVertex3f( float(xsize - ((1.0f - xpos) * xsize/0.5f)), float((-ysize) + (yneg * ysize/0.5f)), float((-zsize) + (zneg * zsize/0.5f)));
00642
00643 glMultiTexCoord3f(GL_TEXTURE0, xpos, yneg, zpos);
00644 glVertex3f( float(xsize - ((1.0f - xpos) * xsize/0.5f)), float((-ysize) + (yneg * ysize/0.5f)), float(zsize - ((1.0f - zpos) * zsize/0.5f)));
00645
00646 glMultiTexCoord3f(GL_TEXTURE0, xneg, yneg, zpos);
00647 glVertex3f(float((-xsize) + (xneg * xsize/0.5f)), float((-ysize) + (yneg * ysize/0.5f)), float(zsize - ((1.0f - zpos) * zsize/0.5f)));
00648
00649
00650
00651 glMultiTexCoord3f(GL_TEXTURE0, xpos, yneg, zneg);
00652 glVertex3f( float(xsize - ((1.0f - xpos) * xsize/0.5f)), float((-ysize) + (yneg * ysize/0.5f)), float((-zsize) + (zneg * zsize/0.5f)));
00653
00654 glMultiTexCoord3f(GL_TEXTURE0, xpos, ypos, zneg);
00655 glVertex3f( float(xsize - ((1.0f - xpos) * xsize/0.5f)), float(ysize - ((1.0f - ypos) * ysize/0.5f)), float((-zsize) + (zneg * zsize/0.5f)));
00656
00657 glMultiTexCoord3f(GL_TEXTURE0, xpos, ypos, zpos);
00658 glVertex3f( float(xsize - ((1.0f - xpos) * xsize/0.5f)), float(ysize - ((1.0f - ypos) * ysize/0.5f)), float(zsize - ((1.0f - zpos) * zsize/0.5f)));
00659
00660 glMultiTexCoord3f(GL_TEXTURE0, xpos, yneg, zpos);
00661 glVertex3f( float(xsize - ((1.0f - xpos) * xsize/0.5f)), float((-ysize) + (yneg * ysize/0.5f)), float(zsize - ((1.0f - zpos) * zsize/0.5f)));
00662
00663
00664
00665 glMultiTexCoord3f(GL_TEXTURE0, xneg, yneg, zneg);
00666 glVertex3f(float((-xsize) + (xneg * xsize/0.5f)), float((-ysize) + (yneg * ysize/0.5f)), float((-zsize) + (zneg * zsize/0.5f)));
00667
00668 glMultiTexCoord3f(GL_TEXTURE0, xneg, yneg, zpos);
00669 glVertex3f(float((-xsize) + (xneg * xsize/0.5f)), float((-ysize) + (yneg * ysize/0.5f)), float(zsize - ((1.0f - zpos) * zsize/0.5f)));
00670
00671 glMultiTexCoord3f(GL_TEXTURE0, xneg, ypos, zpos);
00672 glVertex3f(float((-xsize) + (xneg * xsize/0.5f)), float(ysize - ((1.0f - ypos) * ysize/0.5f)), float(zsize - ((1.0f - zpos) * zsize/0.5f)));
00673
00674 glMultiTexCoord3f(GL_TEXTURE0, xneg, ypos, zneg);
00675 glVertex3f(float((-xsize) + (xneg * xsize/0.5f)), float(ysize - ((1.0f - ypos) * ysize/0.5f)), float((-zsize) + (zneg * zsize/0.5f)));
00676 glEnd();
00677 glEndList();
00678
00679 const GLenum glError = glGetError();
00680
00681 if (glError != GL_NO_ERROR)
00682 std::cout << "Error generating display List " << gluErrorString(glError) << std::endl;
00683 m_updateDL = false;
00684 }
00685
00686 void VVolumeRenderer::resize(int width, int height)
00687 {
00688 m_Camera.setProjection(width, height);
00689
00690 if(m_FrontFaceTexture)
00691 {
00692 delete m_FrontFaceTexture;
00693 }
00694 m_FrontFaceTexture = new VFramebufferObject(width, height, GL_RGBA16F_ARB);
00695 if(m_BackFaceTexture)
00696 {
00697 delete m_BackFaceTexture;
00698 }
00699 m_BackFaceTexture = new VFramebufferObject(width, height, GL_RGBA16F_ARB);
00700 m_FrontFaceTexture->init();
00701 m_BackFaceTexture->init();
00702
00703 if(m_WorldFrontFaceTexture)
00704 {
00705 delete m_WorldFrontFaceTexture;
00706 }
00707 m_WorldFrontFaceTexture = new VFramebufferObject(width, height, GL_RGBA16F_ARB);
00708 if(m_WorldBackFaceTexture)
00709 {
00710 delete m_WorldBackFaceTexture;
00711 }
00712 m_WorldBackFaceTexture = new VFramebufferObject(width, height, GL_RGBA16F_ARB);
00713 m_WorldFrontFaceTexture->init();
00714 m_WorldBackFaceTexture->init();
00715
00716 m_NoiseTex->loadImage("./tex/noisetexture1024.png");
00717 m_ToonTex->loadImage("./tex/toonnew512.png");
00718 m_MetalTex->loadImage("./tex/metaltex.png");
00719 }
00720
00721
00722 void VVolumeRenderer::processGuiInput(float dist, VVector position, VVector view, VVector up, VVector lookAt)
00723 {
00724
00725 view.normalize();
00726 view *= dist;
00727
00728 VVector campos = lookAt - view;
00729
00730 view.normalize();
00731
00732 m_Camera.lookInDirection(campos, view, up);
00733 }
00734
00735 void VVolumeRenderer::processInput(guiInput input)
00736 {
00737
00738
00739
00740
00741 }
00742
00743
00744 void VVolumeRenderer::setOrthoMode(bool m_orth, int width, int height)
00745 {
00746 m_Camera.setOrthogonalCamera(VVector((float)width, (float)height, 0.0f), m_orth);
00747 }
00748
00749 void VVolumeRenderer::initContourTexture()
00750 {
00751 int texturesize = 512;
00752
00753 std::vector<VVector> m_Colors;
00754
00755 for(int i = 0; i < texturesize; ++i)
00756 {
00757 float value = 0.0f + 1.0f/texturesize * i;
00758 m_Colors.push_back(VVector(value, value, value));
00759 }
00760
00761 glEnable(GL_TEXTURE_2D);
00762 if(m_ContourHandle == 0)
00763 {
00764 glGenTextures(1, &m_ContourHandle);
00765 }
00766
00767 glBindTexture(GL_TEXTURE_2D, m_ContourHandle);
00768
00769 int iInternalFormat = GL_RGB;
00770
00771 glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
00772 glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
00773
00774 glTexImage2D(GL_TEXTURE_2D, 0, iInternalFormat, texturesize, 2, 0, GL_RGB, GL_FLOAT, &m_Colors[0]);
00775
00776 const GLenum glError = glGetError();
00777
00778 if (glError != GL_NO_ERROR)
00779 std::cout << "Error Setting up Contour Texture " << gluErrorString(glError) << std::endl;
00780
00781
00782 glBindTexture(GL_TEXTURE_2D, 0);
00783 glDisable(GL_TEXTURE_2D);
00784 }
00785