17 #include "vtkWindows.h" 19 #include "vtkMitkOpenGLVolumeTextureMapper3D.h" 21 #define GPU_INFO MITK_INFO("mapper.vr") 22 #define GPU_WARN MITK_WARN("mapper.vr") 24 #include "vtkCamera.h" 25 #include "vtkDataArray.h" 26 #include "vtkImageData.h" 28 #include "vtkLightCollection.h" 30 #include "vtkMatrix4x4.h" 31 #include "vtkObjectFactory.h" 32 #include "vtkOpenGLExtensionManager.h" 34 #include "vtkPlaneCollection.h" 35 #include "vtkPointData.h" 36 #include "vtkRenderWindow.h" 37 #include "vtkRenderer.h" 38 #include "vtkTimerLog.h" 39 #include "vtkTransform.h" 40 #include "vtkVolumeProperty.h" 43 #include "vtkOpenGLRenderWindow.h" 45 #define myGL_COMPRESSED_RGB_S3TC_DXT1_EXT 0x83F0 46 #define myGL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT 0x8C72 47 #define myGL_COMPRESSED_RGBA_S3TC_DXT5_EXT 0x83F3 52 "TEMP index, normal, finalColor;\n" 53 "TEMP temp,temp1, temp2, temp3,temp4; \n" 55 "TEMP ndotl, ndoth, ndotv; \n" 56 "TEMP lightInfo, lightResult;\n" 60 "ATTRIB tex0 = fragment.texcoord[0];\n" 63 "PARAM lightDirection = program.local[0];\n" 64 "PARAM halfwayVector = program.local[1];\n" 65 "PARAM coefficient = program.local[2];\n" 66 "PARAM lightDiffColor = program.local[3]; \n" 67 "PARAM lightSpecColor = program.local[4]; \n" 68 "PARAM viewVector = program.local[5];\n" 69 "PARAM constants = program.local[6];\n" 72 "OUTPUT out = result.color;\n" 76 "TEX temp2, tex0, texture[0], 3D;\n" 80 "MAD normal, temp2, constants.x, constants.y;\n" 82 "DP3 temp4, normal, normal;\n" 83 "RSQ temp, temp4.x;\n" 84 "MUL normal, normal, temp;\n" 92 "TEX sampleColor, tex0, texture[1], 3D;\n" 96 "DP3 ndotl, normal, lightDirection;\n" 100 "DP3 ndoth, normal, halfwayVector;\n" 102 "DP3 ndotv, normal, viewVector;\n" 105 "MUL temp3, ndotl, constants.y; \n" 106 "CMP ndotl, ndotv, ndotl, temp3;\n" 107 "MUL temp3, ndoth, constants.y; \n" 108 "CMP ndoth, ndotv, ndoth, temp3;\n" 111 "MOV lightInfo.x, ndotl.x; \n" 112 "MOV lightInfo.y, ndoth.x; \n" 113 "MOV lightInfo.w, coefficient.w; \n" 116 "LIT lightResult, lightInfo;\n" 119 "MUL lightResult, lightResult, 4.0;\n" 122 "MUL finalColor, coefficient.x, sampleColor;\n" 125 "MUL temp3, lightDiffColor, sampleColor;\n" 126 "MUL temp3, temp3, lightResult.y;\n" 127 "ADD finalColor, finalColor, temp3;\n" 130 "MUL temp3, lightSpecColor, lightResult.z; \n" 134 "ADD out, finalColor, temp3;\n" 135 "MOV out.w, temp2.w;\n" 145 "TEMP index, normal, finalColor;\n" 146 "TEMP temp,temp1, temp2, temp3,temp4; \n" 147 "TEMP sampleColor;\n" 148 "TEMP ndotl, ndoth, ndotv; \n" 149 "TEMP lightInfo, lightResult;\n" 153 "ATTRIB tex0 = fragment.texcoord[0];\n" 156 "PARAM lightDirection = program.local[0];\n" 157 "PARAM halfwayVector = program.local[1];\n" 158 "PARAM coefficient = program.local[2];\n" 159 "PARAM lightDiffColor = program.local[3]; \n" 160 "PARAM lightSpecColor = program.local[4]; \n" 161 "PARAM viewVector = program.local[5];\n" 162 "PARAM constants = program.local[6];\n" 165 "OUTPUT out = result.color;\n" 169 "TEX temp2, tex0, texture[0], 3D;\n" 207 "MOV index.x,temp2.a;\n" 211 "MAD normal, temp2, constants.x, constants.y;\n" 221 "DP3 temp4, normal, normal;\n" 223 "RSQ temp, temp4.x;\n" 225 "RCP temp4,temp.x;\n" 227 "MUL normal, normal, temp;\n" 229 "MOV index.y, temp4.x;\n" 231 "TEX sampleColor, index, texture[1], 2D;\n" 237 "DP3 ndotl, normal, lightDirection;\n" 241 "DP3 ndoth, normal, halfwayVector;\n" 243 "DP3 ndotv, normal, viewVector;\n" 246 "MUL temp3, ndotl, constants.y; \n" 247 "CMP ndotl, ndotv, ndotl, temp3;\n" 248 "MUL temp3, ndoth, constants.y; \n" 249 "CMP ndoth, ndotv, ndoth, temp3;\n" 252 "MOV lightInfo.x, ndotl.x; \n" 253 "MOV lightInfo.y, ndoth.x; \n" 254 "MOV lightInfo.w, coefficient.w; \n" 257 "LIT lightResult, lightInfo;\n" 260 "MUL lightResult, lightResult, 4.0;\n" 263 "MUL finalColor, coefficient.x, sampleColor;\n" 266 "MUL temp3, lightDiffColor, sampleColor;\n" 267 "MUL temp3, temp3, lightResult.y;\n" 268 "ADD finalColor, finalColor, temp3;\n" 271 "MUL temp3, lightSpecColor, lightResult.z; \n" 275 "ADD out, finalColor, temp3;\n" 276 "MOV out.w, sampleColor.w;\n" 284 vtkMitkOpenGLVolumeTextureMapper3D::vtkMitkOpenGLVolumeTextureMapper3D()
288 this->Initialized = 0;
289 this->Volume1Index = 0;
290 this->Volume2Index = 0;
291 this->Volume3Index = 0;
292 this->ColorLookupIndex = 0;
293 this->AlphaLookupIndex = 0;
294 this->RenderWindow =
nullptr;
295 this->SupportsCompressedTexture =
false;
297 prgOneComponentShade = 0;
301 vtkMitkOpenGLVolumeTextureMapper3D::~vtkMitkOpenGLVolumeTextureMapper3D()
304 if (prgOneComponentShade)
305 vtkgl::DeleteProgramsARB(1, &prgOneComponentShade);
308 vtkgl::DeleteProgramsARB(1, &prgRGBAShade);
312 void vtkMitkOpenGLVolumeTextureMapper3D::ReleaseGraphicsResources(vtkWindow *renWin)
316 if ((this->Volume1Index || this->Volume2Index || this->Volume3Index || this->ColorLookupIndex) && renWin)
318 static_cast<vtkRenderWindow *
>(renWin)->MakeCurrent();
319 #ifdef GL_VERSION_1_1 321 this->DeleteTextureIndex(&this->Volume1Index);
322 this->DeleteTextureIndex(&this->Volume2Index);
323 this->DeleteTextureIndex(&this->Volume3Index);
324 this->DeleteTextureIndex(&this->ColorLookupIndex);
325 this->DeleteTextureIndex(&this->AlphaLookupIndex);
328 this->Volume1Index = 0;
329 this->Volume2Index = 0;
330 this->Volume3Index = 0;
331 this->ColorLookupIndex = 0;
332 this->RenderWindow =
nullptr;
333 this->SupportsCompressedTexture =
false;
334 this->SupportsNonPowerOfTwoTextures =
false;
340 void vtkMitkOpenGLVolumeTextureMapper3D::ReleaseGraphicsResources(
mitk::BaseRenderer *renderer)
344 vtkWindow *renWin = renderer->
GetVtkRenderer()->GetRenderWindow();
346 if ((this->Volume1Index || this->Volume2Index || this->Volume3Index || this->ColorLookupIndex) && renWin)
348 static_cast<vtkRenderWindow *
>(renWin)->MakeCurrent();
349 #ifdef GL_VERSION_1_1 351 this->DeleteTextureIndex(&this->Volume1Index);
352 this->DeleteTextureIndex(&this->Volume2Index);
353 this->DeleteTextureIndex(&this->Volume3Index);
354 this->DeleteTextureIndex(&this->ColorLookupIndex);
355 this->DeleteTextureIndex(&this->AlphaLookupIndex);
358 this->Volume1Index = 0;
359 this->Volume2Index = 0;
360 this->Volume3Index = 0;
361 this->ColorLookupIndex = 0;
362 this->RenderWindow =
nullptr;
363 this->SupportsCompressedTexture =
false;
364 this->SupportsNonPowerOfTwoTextures =
false;
369 void vtkMitkOpenGLVolumeTextureMapper3D::Render(vtkRenderer *ren, vtkVolume *vol)
373 ren->GetRenderWindow()->MakeCurrent();
375 if (!this->Initialized)
378 this->Initialize(ren);
381 if (!this->RenderPossible)
383 vtkErrorMacro(
"required extensions not supported");
387 vtkMatrix4x4 *matrix = vtkMatrix4x4::New();
388 vtkPlaneCollection *clipPlanes;
390 int numClipPlanes = 0;
391 double planeEquation[4];
394 vol->GetMatrix(matrix);
397 glPushAttrib(GL_ENABLE_BIT | GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_POLYGON_BIT |
403 clipPlanes = this->ClippingPlanes;
406 numClipPlanes = clipPlanes->GetNumberOfItems();
407 if (numClipPlanes > 6)
409 vtkErrorMacro(<<
"OpenGL guarantees only 6 additional clipping planes");
412 for (i = 0; i < numClipPlanes; i++)
414 glEnable(static_cast<GLenum>(GL_CLIP_PLANE0 + i));
416 plane =
static_cast<vtkPlane *
>(clipPlanes->GetItemAsObject(i));
418 planeEquation[0] = plane->GetNormal()[0];
419 planeEquation[1] = plane->GetNormal()[1];
420 planeEquation[2] = plane->GetNormal()[2];
421 planeEquation[3] = -(planeEquation[0] * plane->GetOrigin()[0] + planeEquation[1] * plane->GetOrigin()[1] +
422 planeEquation[2] * plane->GetOrigin()[2]);
423 glClipPlane(static_cast<GLenum>(GL_CLIP_PLANE0 + i), planeEquation);
428 glMatrixMode(GL_MODELVIEW);
430 glMultMatrixd(matrix->Element[0]);
432 glColor4f(1.0, 1.0, 1.0, 1.0);
435 glDisable(GL_LIGHTING);
439 this->RenderFP(ren, vol);
442 glMatrixMode(GL_MODELVIEW);
449 void vtkMitkOpenGLVolumeTextureMapper3D::RenderFP(vtkRenderer *ren, vtkVolume *vol)
459 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
461 int components = this->GetInput()->GetNumberOfScalarComponents();
465 this->RenderOneIndependentShadeFP(ren, vol);
469 this->RenderRGBAShadeFP(ren, vol);
473 vtkgl::ActiveTexture(vtkgl::TEXTURE2);
474 glDisable(GL_TEXTURE_2D);
475 glDisable(vtkgl::TEXTURE_3D);
477 vtkgl::ActiveTexture(vtkgl::TEXTURE1);
478 glDisable(GL_TEXTURE_2D);
479 glDisable(vtkgl::TEXTURE_3D);
481 vtkgl::ActiveTexture(vtkgl::TEXTURE0);
482 glDisable(GL_TEXTURE_2D);
483 glDisable(vtkgl::TEXTURE_3D);
488 void vtkMitkOpenGLVolumeTextureMapper3D::DeleteTextureIndex(GLuint *index)
492 if (glIsTexture(*index))
496 glDeleteTextures(1, &tempIndex);
501 void vtkMitkOpenGLVolumeTextureMapper3D::CreateTextureIndex(GLuint *index)
505 GLuint tempIndex = 0;
506 glGenTextures(1, &tempIndex);
507 *index =
static_cast<long>(tempIndex);
510 void vtkMitkOpenGLVolumeTextureMapper3D::RenderPolygons(vtkRenderer *ren, vtkVolume *vol,
int stages[4])
514 vtkRenderWindow *renWin = ren->GetRenderWindow();
516 if (renWin->CheckAbortStatus())
521 double bounds[27][6];
532 this->GetInput()->GetBounds(bounds[0]);
536 else if (this->CroppingRegionFlags == 0x2000)
538 this->GetCroppingRegionPlanes(bounds[0]);
546 ren->GetActiveCamera()->GetPosition(camPos);
549 this->GetInput()->GetBounds(volBounds);
553 vtkMatrix4x4 *volMatrix = vtkMatrix4x4::New();
554 vol->GetMatrix(volMatrix);
557 volMatrix->MultiplyPoint(camPos, camPos);
561 camPos[0] /= camPos[3];
562 camPos[1] /= camPos[3];
563 camPos[2] /= camPos[3];
571 for (i = 0; i < 3; i++)
573 limit[i * 4] = volBounds[i * 2];
574 limit[i * 4 + 1] = this->CroppingRegionPlanes[i * 2];
575 limit[i * 4 + 2] = this->CroppingRegionPlanes[i * 2 + 1];
576 limit[i * 4 + 3] = volBounds[i * 2 + 1];
584 for (region = 0; region < 27; region++)
586 int regionFlag = 1 << region;
588 if (this->CroppingRegionFlags & regionFlag)
593 loc[1] = (region / 3) % 3;
594 loc[2] = (region / 9) % 3;
598 for (i = 0; i < 3; i++)
600 bounds[numRegions][i * 2] = limit[4 * i + loc[i]];
601 bounds[numRegions][i * 2 + 1] = limit[4 * i + loc[i] + 1];
602 center[i] = (bounds[numRegions][i * 2] + bounds[numRegions][i * 2 + 1]) / 2.0;
606 distance2[numRegions] = (camPos[0] - center[0]) * (camPos[0] - center[0]) +
607 (camPos[1] - center[1]) * (camPos[1] - center[1]) +
608 (camPos[2] - center[2]) * (camPos[2] - center[2]);
616 for (i = 1; i < numRegions; i++)
618 for (j = i; j > 0 && distance2[j] > distance2[j - 1]; j--)
623 for (k = 0; k < 6; k++)
625 tmpBounds[
k] = bounds[j][
k];
627 tmpDistance2 = distance2[j];
629 for (k = 0; k < 6; k++)
631 bounds[j][
k] = bounds[j - 1][
k];
633 distance2[j] = distance2[j - 1];
635 for (k = 0; k < 6; k++)
637 bounds[j - 1][
k] = tmpBounds[
k];
639 distance2[j - 1] = tmpDistance2;
643 numIterations = numRegions;
647 for (
int loop = 0; loop < numIterations; loop++)
651 this->ComputePolygons(ren, vol, bounds[loop]);
654 for (i = 0; i < this->NumberOfPolygons; i++)
656 if (renWin->CheckAbortStatus())
661 float *ptr = this->PolygonBuffer + 36 * i;
663 glBegin(GL_TRIANGLE_FAN);
665 for (j = 0; j < 6; j++)
672 for (k = 0; k < 4; k++)
676 vtkgl::MultiTexCoord3fv(vtkgl::TEXTURE0 + k, ptr);
679 glVertex3fv(ptr + 3);
714 class ScalarGradientCompute
717 unsigned char *tmpPtr;
718 unsigned char *tmpPtr2;
730 int currentChunkStart;
739 ScalarGradientCompute(T *_dataPtr,
740 unsigned char *_tmpPtr,
741 unsigned char *_tmpPtr2,
763 sizeXY = sizeX * sizeY;
768 fullXY = fullX * fullY;
769 currentChunkStart = 0;
774 inline float sample(
int x,
int y,
int z) {
return float(dataPtr[x + y * sizeX + z * sizeXY]); }
775 inline void fill(
int x,
int y,
int z)
777 int doff = x + y * fullX + (z - offZ) * fullXY;
779 tmpPtr[doff * 4 + 0] = 0;
780 tmpPtr[doff * 4 + 1] = 0;
781 tmpPtr[doff * 4 + 2] = 0;
782 tmpPtr[doff * 4 + 3] = 0;
790 inline int clamp(
int x)
799 inline void write(
int x,
int y,
int z,
float grayValue,
float gx,
float gy,
float gz)
808 int iGrayValue =
static_cast<int>((grayValue +
offset) * scale + 0.5f);
814 float t = sqrtf(gx * gx + gy * gy + gz * gz);
820 float fac = 2.0f / t;
827 float fac = 255.0f / t;
838 int nx =
static_cast<int>(0.5f * gx + 127.5f);
839 int ny =
static_cast<int>(0.5f * gy + 127.5f);
840 int nz =
static_cast<int>(0.5f * gz + 127.5f);
842 int doff = x + y * fullX + (z - offZ) * fullXY;
846 tmpPtr[doff * 4 + 0] = clamp(nx);
847 tmpPtr[doff * 4 + 1] = clamp(ny);
848 tmpPtr[doff * 4 + 2] = clamp(nz);
849 tmpPtr[doff * 4 + 3] = clamp(iGrayValue);
858 inline void compute(
int x,
int y,
int z)
860 float grayValue = sample(x, y, z);
863 gx = sample(x + 1, y, z) - sample(x - 1, y, z);
864 gy = sample(x, y + 1, z) - sample(x, y - 1, z);
865 gz = sample(x, y, z + 1) - sample(x, y, z - 1);
867 write(x, y, z, grayValue, gx, gy, gz);
870 inline void computeClamp(
int x,
int y,
int z)
872 float grayValue = sample(x, y, z);
876 gx = 2.0f * (sample(x + 1, y, z) - grayValue);
877 else if (x == sizeXm1)
878 gx = 2.0f * (grayValue - sample(x - 1, y, z));
880 gx = sample(x + 1, y, z) - sample(x - 1, y, z);
883 gy = 2.0f * (sample(x, y + 1, z) - grayValue);
884 else if (y == sizeYm1)
885 gy = 2.0f * (grayValue - sample(x, y - 1, z));
887 gy = sample(x, y + 1, z) - sample(x, y - 1, z);
890 gz = 2.0f * (sample(x, y, z + 1) - grayValue);
891 else if (z == sizeZm1)
892 gz = 2.0f * (grayValue - sample(x, y, z - 1));
894 gz = sample(x, y, z + 1) - sample(x, y, z - 1);
896 write(x, y, z, grayValue, gx, gy, gz);
899 inline void compute1D(
int y,
int z)
904 computeClamp(x, y, z);
907 while (x < sizeX - 1)
915 computeClamp(x, y, z);
926 inline void fill1D(
int y,
int z)
938 inline void computeClamp1D(
int y,
int z)
946 computeClamp(x, y, z);
957 inline void computeClamp2D(
int z)
965 computeClamp1D(y, z);
976 inline void compute2D(
int z)
981 computeClamp1D(y, z);
984 while (y < sizeY - 1)
992 computeClamp1D(y, z);
1003 inline void fill2D(
int z)
1015 inline void fillSlices(
int currentChunkStart,
int currentChunkEnd)
1017 offZ = currentChunkStart;
1024 #pragma omp parallel for 1025 for (
int z = currentChunkStart; z <= currentChunkEnd; z++)
1027 if (z == 0 || z == sizeZ - 1)
1029 else if (z >= sizeZ)
1039 T *dataPtr, vtkMitkVolumeTextureMapper3D *me,
float offset,
float scale, GLuint volume1, GLuint )
1046 int inputDimensions[3];
1047 double inputSpacing[3];
1048 vtkImageData *input = me->GetInput();
1050 input->GetDimensions(inputDimensions);
1051 input->GetSpacing(inputSpacing);
1053 int outputDimensions[3];
1054 float outputSpacing[3];
1055 me->GetVolumeDimensions(outputDimensions);
1056 me->GetVolumeSpacing(outputSpacing);
1069 int fullX = outputDimensions[0];
1070 int fullY = outputDimensions[1];
1071 int fullZ = outputDimensions[2];
1073 int sizeX = inputDimensions[0];
1074 int sizeY = inputDimensions[1];
1075 int sizeZ = inputDimensions[2];
1079 if (fullZ < chunkSize)
1082 int numChunks = (fullZ + (chunkSize - 1)) / chunkSize;
1086 unsigned char *tmpPtr =
new unsigned char[fullX * fullY * chunkSize * 4];
1087 unsigned char *tmpPtr2 = 0;
1091 ScalarGradientCompute<T> sgc(dataPtr, tmpPtr, tmpPtr2, sizeX, sizeY, sizeZ, fullX, fullY, fullZ, offset, scale);
1093 int currentChunk = 0;
1095 while (currentChunk < numChunks)
1097 int currentChunkStart = currentChunk * chunkSize;
1098 int currentChunkEnd = currentChunkStart + chunkSize - 1;
1100 if (currentChunkEnd > (fullZ - 1))
1101 currentChunkEnd = (fullZ - 1);
1103 int currentChunkSize = currentChunkEnd - currentChunkStart + 1;
1105 sgc.fillSlices(currentChunkStart, currentChunkEnd);
1107 glBindTexture(vtkgl::TEXTURE_3D, volume1);
1108 vtkgl::TexSubImage3D(vtkgl::TEXTURE_3D,
1128 unsigned char *dataPtr;
1129 unsigned char *tmpPtr;
1130 unsigned char *tmpPtr2;
1148 RGBACompute(
unsigned char *_dataPtr,
1149 unsigned char *_tmpPtr,
1150 unsigned char *_tmpPtr2,
1168 sizeXY = sizeX * sizeY;
1169 sizeXm1 = sizeX - 1;
1170 sizeYm1 = sizeY - 1;
1171 sizeZm1 = sizeZ - 1;
1173 fullXY = fullX * fullY;
1177 inline int sample(
int x,
int y,
int z) {
return dataPtr[(x + y * sizeX + z * sizeXY) * 4 + 3]; }
1178 inline void fill(
int x,
int y,
int z)
1180 int doff = x + y * fullX + (z - offZ) * fullXY;
1182 tmpPtr[doff * 4 + 0] = 0;
1183 tmpPtr[doff * 4 + 1] = 0;
1184 tmpPtr[doff * 4 + 2] = 0;
1185 tmpPtr[doff * 4 + 3] = 0;
1187 tmpPtr2[doff * 3 + 0] = 0;
1188 tmpPtr2[doff * 3 + 1] = 0;
1189 tmpPtr2[doff * 3 + 2] = 0;
1192 inline int clamp(
int x)
1201 inline void write(
int x,
int y,
int z,
int iGrayValue,
int gx,
int gy,
int gz)
1208 int nx =
static_cast<int>(0.5f * gx + 127.5f);
1209 int ny =
static_cast<int>(0.5f * gy + 127.5f);
1210 int nz =
static_cast<int>(0.5f * gz + 127.5f);
1212 int doff = x + y * fullX + (z - offZ) * fullXY;
1216 tmpPtr[doff * 4 + 0] = clamp(nx);
1217 tmpPtr[doff * 4 + 1] = clamp(ny);
1218 tmpPtr[doff * 4 + 2] = clamp(nz);
1219 tmpPtr[doff * 4 + 3] = clamp(iGrayValue);
1221 int soff = x + y * sizeX + z * sizeXY;
1223 tmpPtr2[doff * 3 + 0] = dataPtr[soff * 4 + 0];
1224 tmpPtr2[doff * 3 + 1] = dataPtr[soff * 4 + 1];
1225 tmpPtr2[doff * 3 + 2] = dataPtr[soff * 4 + 2];
1234 inline void compute(
int x,
int y,
int z)
1236 int grayValue = sample(x, y, z);
1239 gx = sample(x + 1, y, z) - sample(x - 1, y, z);
1240 gy = sample(x, y + 1, z) - sample(x, y - 1, z);
1241 gz = sample(x, y, z + 1) - sample(x, y, z - 1);
1243 write(x, y, z, grayValue, gx, gy, gz);
1246 inline void computeClamp(
int x,
int y,
int z)
1248 int grayValue = sample(x, y, z);
1252 gx = 2 * (sample(x + 1, y, z) - grayValue);
1253 else if (x == sizeXm1)
1254 gx = 2 * (grayValue - sample(x - 1, y, z));
1256 gx = sample(x + 1, y, z) - sample(x - 1, y, z);
1259 gy = 2 * (sample(x, y + 1, z) - grayValue);
1260 else if (y == sizeYm1)
1261 gy = 2 * (grayValue - sample(x, y - 1, z));
1263 gy = sample(x, y + 1, z) - sample(x, y - 1, z);
1266 gz = 2 * (sample(x, y, z + 1) - grayValue);
1267 else if (z == sizeZm1)
1268 gz = 2 * (grayValue - sample(x, y, z - 1));
1270 gz = sample(x, y, z + 1) - sample(x, y, z - 1);
1272 write(x, y, z, grayValue, gx, gy, gz);
1275 inline void compute1D(
int y,
int z)
1279 computeClamp(x, y, z);
1282 while (x < sizeX - 1)
1290 computeClamp(x, y, z);
1301 inline void fill1D(
int y,
int z)
1312 inline void computeClamp1D(
int y,
int z)
1318 computeClamp(x, y, z);
1329 inline void computeClamp2D(
int z)
1335 computeClamp1D(y, z);
1346 inline void compute2D(
int z)
1350 computeClamp1D(y, z);
1353 while (y < sizeY - 1)
1361 computeClamp1D(y, z);
1372 inline void fill2D(
int z)
1383 inline void fillSlices(
int currentChunkStart,
int currentChunkEnd)
1385 offZ = currentChunkStart;
1387 #pragma omp parallel for 1388 for (
int z = currentChunkStart; z <= currentChunkEnd; z++)
1390 if (z == 0 || z == sizeZ - 1)
1392 else if (z >= sizeZ)
1401 vtkMitkVolumeTextureMapper3D *me,
1410 int inputDimensions[3];
1411 double inputSpacing[3];
1412 vtkImageData *input = me->GetInput();
1414 input->GetDimensions(inputDimensions);
1415 input->GetSpacing(inputSpacing);
1417 int outputDimensions[3];
1418 float outputSpacing[3];
1419 me->GetVolumeDimensions(outputDimensions);
1420 me->GetVolumeSpacing(outputSpacing);
1422 int components = input->GetNumberOfScalarComponents();
1424 MITK_INFO <<
"components are " << components;
1435 int fullX = outputDimensions[0];
1436 int fullY = outputDimensions[1];
1437 int fullZ = outputDimensions[2];
1439 int sizeX = inputDimensions[0];
1440 int sizeY = inputDimensions[1];
1441 int sizeZ = inputDimensions[2];
1445 if (fullZ < chunkSize)
1448 int numChunks = (fullZ + (chunkSize - 1)) / chunkSize;
1452 unsigned char *tmpPtr =
new unsigned char[fullX * fullY * chunkSize * 4];
1453 unsigned char *tmpPtr2 =
new unsigned char[fullX * fullY * chunkSize * 3];
1457 RGBACompute sgc(dataPtr, tmpPtr, tmpPtr2, sizeX, sizeY, sizeZ, fullX, fullY, fullZ);
1459 int currentChunk = 0;
1461 while (currentChunk < numChunks)
1465 int currentChunkStart = currentChunk * chunkSize;
1466 int currentChunkEnd = currentChunkStart + chunkSize - 1;
1468 if (currentChunkEnd > (fullZ - 1))
1469 currentChunkEnd = (fullZ - 1);
1471 int currentChunkSize = currentChunkEnd - currentChunkStart + 1;
1473 sgc.fillSlices(currentChunkStart, currentChunkEnd);
1475 glBindTexture(vtkgl::TEXTURE_3D, volume1);
1476 vtkgl::TexSubImage3D(vtkgl::TEXTURE_3D,
1488 glBindTexture(vtkgl::TEXTURE_3D, volume2);
1489 vtkgl::TexSubImage3D(vtkgl::TEXTURE_3D,
1510 void vtkMitkOpenGLVolumeTextureMapper3D::ComputeVolumeDimensions()
1513 vtkImageData *input = this->GetInput();
1517 input->GetDimensions(dim);
1519 int powerOfTwoDim[3];
1521 if (this->SupportsNonPowerOfTwoTextures)
1523 for (
int i = 0; i < 3; i++)
1524 powerOfTwoDim[i] = (dim[i] + 1) & ~1;
1532 for (
int i = 0; i < 3; i++)
1534 powerOfTwoDim[i] = 4;
1535 while (powerOfTwoDim[i] < dim[i])
1536 powerOfTwoDim[i] *= 2;
1539 MITK_WARN <<
"using power-two textures (" 1541 double(dim[0] * dim[1] * dim[2]) / double(powerOfTwoDim[0] * powerOfTwoDim[1] * powerOfTwoDim[2])) *
1543 <<
"% memory wasted)";
1547 this->VolumeDimensions[0] = powerOfTwoDim[0];
1548 this->VolumeDimensions[1] = powerOfTwoDim[1];
1549 this->VolumeDimensions[2] = powerOfTwoDim[2];
1553 input->GetSpacing(spacing);
1556 this->VolumeSpacing[0] = (dim[0] - 1.01) * spacing[0] /
static_cast<double>(this->VolumeDimensions[0] - 1);
1557 this->VolumeSpacing[1] = (dim[1] - 1.01) * spacing[1] /
static_cast<double>(this->VolumeDimensions[1] - 1);
1558 this->VolumeSpacing[2] = ((dim[2]) - 1.01) * spacing[2] /
static_cast<double>(this->VolumeDimensions[2] - 1);
1562 bool vtkMitkOpenGLVolumeTextureMapper3D::UpdateVolumes(vtkVolume *vtkNotUsed(vol))
1565 vtkImageData *input = this->GetInput();
1568 bool needUpdate =
false;
1571 if (this->SavedTextureInput != input || this->SavedTextureMTime.GetMTime() < input->GetMTime())
1575 if (!this->Volume1Index)
1581 ComputeVolumeDimensions();
1583 int components = input->GetNumberOfScalarComponents();
1586 double scalarRange[2];
1587 input->GetPointData()->GetScalars()->GetRange(scalarRange, components - 1);
1598 int arraySizeNeeded;
1600 int scalarType = input->GetScalarType();
1602 if (scalarType == VTK_FLOAT || scalarType == VTK_DOUBLE || scalarRange[1] - scalarRange[0] > 255)
1604 arraySizeNeeded = 256;
1605 offset = -scalarRange[0];
1606 scale = 255.0 / (scalarRange[1] - scalarRange[0]);
1610 arraySizeNeeded =
static_cast<int>(scalarRange[1] - scalarRange[0] + 1);
1611 offset = -scalarRange[0];
1615 this->ColorTableSize = arraySizeNeeded;
1616 this->ColorTableOffset =
offset;
1617 this->ColorTableScale = scale;
1622 this->DeleteTextureIndex(&this->Volume1Index);
1623 this->DeleteTextureIndex(&this->Volume2Index);
1624 this->DeleteTextureIndex(&this->Volume3Index);
1626 this->CreateTextureIndex(&this->Volume1Index);
1630 this->GetVolumeDimensions(dim);
1632 vtkgl::ActiveTexture(vtkgl::TEXTURE0);
1634 MITK_INFO <<
"allocating volume on gpu";
1636 GLint gradientScalarTextureFormat = GL_RGBA8;
1638 if (this->UseCompressedTexture && SupportsCompressedTexture)
1641 glBindTexture(vtkgl::TEXTURE_3D, this->Volume1Index);
1643 vtkgl::TEXTURE_3D, 0, gradientScalarTextureFormat, dim[0], dim[1], dim[2], 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
1644 this->Setup3DTextureParameters(
true);
1648 void *dataPtr = input->GetScalarPointer();
1653 static_cast<VTK_TT *>(dataPtr),
this, offset, scale, this->Volume1Index, this->Volume2Index));
1656 this->SavedTextureInput = input;
1657 this->SavedTextureMTime.Modified();
1663 bool vtkMitkOpenGLVolumeTextureMapper3D::UpdateVolumesRGBA(vtkVolume *vtkNotUsed(vol))
1666 vtkImageData *input = this->GetInput();
1669 bool needUpdate =
false;
1672 if (this->SavedTextureInput != input || this->SavedTextureMTime.GetMTime() < input->GetMTime())
1676 if (!this->Volume1Index)
1684 ComputeVolumeDimensions();
1689 this->DeleteTextureIndex(&this->Volume1Index);
1690 this->DeleteTextureIndex(&this->Volume2Index);
1691 this->DeleteTextureIndex(&this->Volume3Index);
1693 this->CreateTextureIndex(&this->Volume1Index);
1694 this->CreateTextureIndex(&this->Volume2Index);
1697 this->GetVolumeDimensions(dim);
1699 MITK_INFO <<
"allocating volume on gpu";
1701 GLint gradientScalarTextureFormat = GL_RGBA8;
1702 GLint colorTextureFormat = GL_RGB8;
1704 if (this->UseCompressedTexture && SupportsCompressedTexture)
1710 vtkgl::ActiveTexture(vtkgl::TEXTURE0);
1711 glBindTexture(vtkgl::TEXTURE_3D, this->Volume1Index);
1713 vtkgl::TEXTURE_3D, 0, gradientScalarTextureFormat, dim[0], dim[1], dim[2], 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
1714 this->Setup3DTextureParameters(
true);
1716 glBindTexture(vtkgl::TEXTURE_3D, this->Volume2Index);
1717 vtkgl::TexImage3D(vtkgl::TEXTURE_3D, 0, colorTextureFormat, dim[0], dim[1], dim[2], 0, GL_RGB, GL_UNSIGNED_BYTE, 0);
1718 this->Setup3DTextureParameters(
true);
1722 unsigned char *dataPtr = (
unsigned char *)input->GetScalarPointer();
1725 this->SavedTextureInput = input;
1726 this->SavedTextureMTime.Modified();
1731 void vtkMitkOpenGLVolumeTextureMapper3D::Setup3DTextureParameters(
bool linear)
1737 glTexParameterf(vtkgl::TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1738 glTexParameterf(vtkgl::TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1742 glTexParameterf(vtkgl::TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
1743 glTexParameterf(vtkgl::TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
1746 glTexParameterf(vtkgl::TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_CLAMP);
1747 glTexParameterf(vtkgl::TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_CLAMP);
1750 void vtkMitkOpenGLVolumeTextureMapper3D::SetupOneIndependentTextures(vtkRenderer *vtkNotUsed(ren), vtkVolume *vol)
1753 this->UpdateVolumes(vol);
1757 if (this->UpdateColorLookup(vol) || !this->ColorLookupIndex)
1759 this->DeleteTextureIndex(&this->ColorLookupIndex);
1760 this->DeleteTextureIndex(&this->AlphaLookupIndex);
1762 this->CreateTextureIndex(&this->ColorLookupIndex);
1764 vtkgl::ActiveTexture(vtkgl::TEXTURE1);
1765 glBindTexture(GL_TEXTURE_2D, this->ColorLookupIndex);
1767 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
1768 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
1769 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
1770 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
1774 GLint colorLookupTextureFormat = GL_RGBA8;
1776 if (this->UseCompressedTexture && SupportsCompressedTexture)
1779 glTexImage2D(GL_TEXTURE_2D, 0, colorLookupTextureFormat, 256, 256, 0, GL_RGBA, GL_UNSIGNED_BYTE, this->ColorLookup);
1783 void vtkMitkOpenGLVolumeTextureMapper3D::SetupRGBATextures(vtkRenderer *vtkNotUsed(ren), vtkVolume *vol)
1785 MITK_INFO <<
"SetupFourDependentTextures";
1787 this->UpdateVolumesRGBA(vol);
1880 void vtkMitkOpenGLVolumeTextureMapper3D::RenderOneIndependentShadeFP(vtkRenderer *ren, vtkVolume *vol)
1884 this->SetupOneIndependentTextures(ren, vol);
1886 glEnable(vtkgl::FRAGMENT_PROGRAM_ARB);
1888 vtkgl::BindProgramARB(vtkgl::FRAGMENT_PROGRAM_ARB, prgOneComponentShade);
1890 this->SetupProgramLocalsForShadingFP(ren, vol);
1894 vtkgl::ActiveTexture(vtkgl::TEXTURE0);
1895 glDisable(GL_TEXTURE_2D);
1896 glEnable(vtkgl::TEXTURE_3D);
1897 glBindTexture(vtkgl::TEXTURE_3D, this->Volume1Index);
1899 vtkgl::ActiveTexture(vtkgl::TEXTURE1);
1900 glEnable(GL_TEXTURE_2D);
1901 glDisable(vtkgl::TEXTURE_3D);
1902 glBindTexture(GL_TEXTURE_2D, this->ColorLookupIndex);
1904 vtkgl::ActiveTexture(vtkgl::TEXTURE2);
1905 glDisable(GL_TEXTURE_2D);
1906 glEnable(vtkgl::TEXTURE_3D);
1907 glBindTexture(vtkgl::TEXTURE_3D, this->Volume2Index);
1910 int stages[4] = {1, 1, 1, 0};
1911 this->RenderPolygons(ren, vol, stages);
1913 glDisable(vtkgl::FRAGMENT_PROGRAM_ARB);
1916 void vtkMitkOpenGLVolumeTextureMapper3D::RenderRGBAShadeFP(vtkRenderer *ren, vtkVolume *vol)
1918 this->SetupRGBATextures(ren, vol);
1920 glEnable(vtkgl::FRAGMENT_PROGRAM_ARB);
1922 vtkgl::BindProgramARB(vtkgl::FRAGMENT_PROGRAM_ARB, prgRGBAShade);
1924 this->SetupProgramLocalsForShadingFP(ren, vol);
1928 vtkgl::ActiveTexture(vtkgl::TEXTURE0);
1929 glDisable(GL_TEXTURE_2D);
1930 glEnable(vtkgl::TEXTURE_3D);
1931 glBindTexture(vtkgl::TEXTURE_3D, this->Volume1Index);
1933 vtkgl::ActiveTexture(vtkgl::TEXTURE1);
1934 glDisable(GL_TEXTURE_2D);
1935 glEnable(vtkgl::TEXTURE_3D);
1936 glBindTexture(vtkgl::TEXTURE_3D, this->Volume2Index);
1939 int stages[4] = {1, 1, 1, 0};
1940 this->RenderPolygons(ren, vol, stages);
1942 glDisable(vtkgl::FRAGMENT_PROGRAM_ARB);
1945 void vtkMitkOpenGLVolumeTextureMapper3D::GetLightInformation(vtkRenderer *ren,
1947 GLfloat lightDirection[2][4],
1948 GLfloat lightDiffuseColor[2][4],
1949 GLfloat lightSpecularColor[2][4],
1950 GLfloat halfwayVector[2][4],
1951 GLfloat ambientColor[4])
1955 float ambient = vol->GetProperty()->GetAmbient();
1956 float diffuse = vol->GetProperty()->GetDiffuse();
1957 float specular = vol->GetProperty()->GetSpecular();
1959 vtkTransform *volumeTransform = vtkTransform::New();
1961 volumeTransform->SetMatrix(vol->GetMatrix());
1962 volumeTransform->Inverse();
1964 vtkLightCollection *lights = ren->GetLights();
1965 lights->InitTraversal();
1968 light[0] = lights->GetNextItem();
1969 light[1] = lights->GetNextItem();
1973 double cameraPosition[3];
1974 double cameraFocalPoint[3];
1976 ren->GetActiveCamera()->GetPosition(cameraPosition);
1977 ren->GetActiveCamera()->GetFocalPoint(cameraFocalPoint);
1979 double viewDirection[3];
1981 volumeTransform->TransformPoint(cameraPosition, cameraPosition);
1982 volumeTransform->TransformPoint(cameraFocalPoint, cameraFocalPoint);
1984 viewDirection[0] = cameraFocalPoint[0] - cameraPosition[0];
1985 viewDirection[1] = cameraFocalPoint[1] - cameraPosition[1];
1986 viewDirection[2] = cameraFocalPoint[2] - cameraPosition[2];
1990 ambientColor[0] = 0.0;
1991 ambientColor[1] = 0.0;
1992 ambientColor[2] = 0.0;
1993 ambientColor[3] = 0.0;
1995 for (lightIndex = 0; lightIndex < 2; lightIndex++)
1997 float dir[3] = {0, 0, 0};
1998 float half[3] = {0, 0, 0};
2000 if (light[lightIndex] ==
nullptr || light[lightIndex]->GetSwitch() == 0)
2002 lightDiffuseColor[lightIndex][0] = 0.0;
2003 lightDiffuseColor[lightIndex][1] = 0.0;
2004 lightDiffuseColor[lightIndex][2] = 0.0;
2005 lightDiffuseColor[lightIndex][3] = 0.0;
2007 lightSpecularColor[lightIndex][0] = 0.0;
2008 lightSpecularColor[lightIndex][1] = 0.0;
2009 lightSpecularColor[lightIndex][2] = 0.0;
2010 lightSpecularColor[lightIndex][3] = 0.0;
2014 float lightIntensity = light[lightIndex]->GetIntensity();
2015 double lightColor[3];
2017 light[lightIndex]->GetDiffuseColor(lightColor);
2019 double lightPosition[3];
2020 double lightFocalPoint[3];
2021 light[lightIndex]->GetTransformedPosition(lightPosition);
2022 light[lightIndex]->GetTransformedFocalPoint(lightFocalPoint);
2024 volumeTransform->TransformPoint(lightPosition, lightPosition);
2025 volumeTransform->TransformPoint(lightFocalPoint, lightFocalPoint);
2027 dir[0] = lightPosition[0] - lightFocalPoint[0];
2028 dir[1] = lightPosition[1] - lightFocalPoint[1];
2029 dir[2] = lightPosition[2] - lightFocalPoint[2];
2033 lightDiffuseColor[lightIndex][0] = lightColor[0] * diffuse * lightIntensity;
2034 lightDiffuseColor[lightIndex][1] = lightColor[1] * diffuse * lightIntensity;
2035 lightDiffuseColor[lightIndex][2] = lightColor[2] * diffuse * lightIntensity;
2036 lightDiffuseColor[lightIndex][3] = 1.0;
2038 lightSpecularColor[lightIndex][0] = lightColor[0] * specular * lightIntensity;
2039 lightSpecularColor[lightIndex][1] = lightColor[1] * specular * lightIntensity;
2040 lightSpecularColor[lightIndex][2] = lightColor[2] * specular * lightIntensity;
2041 lightSpecularColor[lightIndex][3] = 0.0;
2043 half[0] = dir[0] - viewDirection[0];
2044 half[1] = dir[1] - viewDirection[1];
2045 half[2] = dir[2] - viewDirection[2];
2049 ambientColor[0] += ambient * lightColor[0];
2050 ambientColor[1] += ambient * lightColor[1];
2051 ambientColor[2] += ambient * lightColor[2];
2054 lightDirection[lightIndex][0] = (dir[0] + 1.0) / 2.0;
2055 lightDirection[lightIndex][1] = (dir[1] + 1.0) / 2.0;
2056 lightDirection[lightIndex][2] = (dir[2] + 1.0) / 2.0;
2057 lightDirection[lightIndex][3] = 0.0;
2059 halfwayVector[lightIndex][0] = (half[0] + 1.0) / 2.0;
2060 halfwayVector[lightIndex][1] = (half[1] + 1.0) / 2.0;
2061 halfwayVector[lightIndex][2] = (half[2] + 1.0) / 2.0;
2062 halfwayVector[lightIndex][3] = 0.0;
2065 volumeTransform->Delete();
2068 void vtkMitkOpenGLVolumeTextureMapper3D::SetupProgramLocalsForShadingFP(vtkRenderer *ren, vtkVolume *vol)
2072 GLfloat lightDirection[2][4];
2073 GLfloat lightDiffuseColor[2][4];
2074 GLfloat lightSpecularColor[2][4];
2075 GLfloat halfwayVector[2][4];
2076 GLfloat ambientColor[4];
2078 float ambient = vol->GetProperty()->GetAmbient();
2079 float diffuse = vol->GetProperty()->GetDiffuse();
2080 float specular = vol->GetProperty()->GetSpecular();
2081 float specularPower = vol->GetProperty()->GetSpecularPower();
2083 vtkTransform *volumeTransform = vtkTransform::New();
2085 volumeTransform->SetMatrix(vol->GetMatrix());
2086 volumeTransform->Inverse();
2088 vtkLightCollection *lights = ren->GetLights();
2089 lights->InitTraversal();
2092 light[0] = lights->GetNextItem();
2093 light[1] = lights->GetNextItem();
2097 double cameraPosition[3];
2098 double cameraFocalPoint[3];
2100 ren->GetActiveCamera()->GetPosition(cameraPosition);
2101 ren->GetActiveCamera()->GetFocalPoint(cameraFocalPoint);
2103 volumeTransform->TransformPoint(cameraPosition, cameraPosition);
2104 volumeTransform->TransformPoint(cameraFocalPoint, cameraFocalPoint);
2106 double viewDirection[4];
2108 viewDirection[0] = cameraFocalPoint[0] - cameraPosition[0];
2109 viewDirection[1] = cameraFocalPoint[1] - cameraPosition[1];
2110 viewDirection[2] = cameraFocalPoint[2] - cameraPosition[2];
2111 viewDirection[3] = 0.0;
2115 ambientColor[0] = 0.0;
2116 ambientColor[1] = 0.0;
2117 ambientColor[2] = 0.0;
2118 ambientColor[3] = 0.0;
2120 for (lightIndex = 0; lightIndex < 2; lightIndex++)
2122 float dir[3] = {0, 0, 0};
2123 float half[3] = {0, 0, 0};
2125 if (light[lightIndex] ==
nullptr || light[lightIndex]->GetSwitch() == 0)
2127 lightDiffuseColor[lightIndex][0] = 0.0;
2128 lightDiffuseColor[lightIndex][1] = 0.0;
2129 lightDiffuseColor[lightIndex][2] = 0.0;
2130 lightDiffuseColor[lightIndex][3] = 0.0;
2132 lightSpecularColor[lightIndex][0] = 0.0;
2133 lightSpecularColor[lightIndex][1] = 0.0;
2134 lightSpecularColor[lightIndex][2] = 0.0;
2135 lightSpecularColor[lightIndex][3] = 0.0;
2139 float lightIntensity = light[lightIndex]->GetIntensity();
2140 double lightColor[3];
2142 light[lightIndex]->GetDiffuseColor(lightColor);
2144 double lightPosition[3];
2145 double lightFocalPoint[3];
2146 light[lightIndex]->GetTransformedPosition(lightPosition);
2147 light[lightIndex]->GetTransformedFocalPoint(lightFocalPoint);
2149 volumeTransform->TransformPoint(lightPosition, lightPosition);
2150 volumeTransform->TransformPoint(lightFocalPoint, lightFocalPoint);
2152 dir[0] = lightPosition[0] - lightFocalPoint[0];
2153 dir[1] = lightPosition[1] - lightFocalPoint[1];
2154 dir[2] = lightPosition[2] - lightFocalPoint[2];
2158 lightDiffuseColor[lightIndex][0] = lightColor[0] * diffuse * lightIntensity;
2159 lightDiffuseColor[lightIndex][1] = lightColor[1] * diffuse * lightIntensity;
2160 lightDiffuseColor[lightIndex][2] = lightColor[2] * diffuse * lightIntensity;
2161 lightDiffuseColor[lightIndex][3] = 0.0;
2163 lightSpecularColor[lightIndex][0] = lightColor[0] * specular * lightIntensity;
2164 lightSpecularColor[lightIndex][1] = lightColor[1] * specular * lightIntensity;
2165 lightSpecularColor[lightIndex][2] = lightColor[2] * specular * lightIntensity;
2166 lightSpecularColor[lightIndex][3] = 0.0;
2168 half[0] = dir[0] - viewDirection[0];
2169 half[1] = dir[1] - viewDirection[1];
2170 half[2] = dir[2] - viewDirection[2];
2174 ambientColor[0] += ambient * lightColor[0];
2175 ambientColor[1] += ambient * lightColor[1];
2176 ambientColor[2] += ambient * lightColor[2];
2179 lightDirection[lightIndex][0] = dir[0];
2180 lightDirection[lightIndex][1] = dir[1];
2181 lightDirection[lightIndex][2] = dir[2];
2182 lightDirection[lightIndex][3] = 0.0;
2184 halfwayVector[lightIndex][0] = half[0];
2185 halfwayVector[lightIndex][1] = half[1];
2186 halfwayVector[lightIndex][2] = half[2];
2187 halfwayVector[lightIndex][3] = 0.0;
2190 volumeTransform->Delete();
2192 vtkgl::ProgramLocalParameter4fARB(vtkgl::FRAGMENT_PROGRAM_ARB,
2194 lightDirection[0][0],
2195 lightDirection[0][1],
2196 lightDirection[0][2],
2197 lightDirection[0][3]);
2199 vtkgl::ProgramLocalParameter4fARB(
2200 vtkgl::FRAGMENT_PROGRAM_ARB, 1, halfwayVector[0][0], halfwayVector[0][1], halfwayVector[0][2], halfwayVector[0][3]);
2202 vtkgl::ProgramLocalParameter4fARB(vtkgl::FRAGMENT_PROGRAM_ARB, 2, ambient, diffuse, specular, specularPower);
2204 vtkgl::ProgramLocalParameter4fARB(vtkgl::FRAGMENT_PROGRAM_ARB,
2206 lightDiffuseColor[0][0],
2207 lightDiffuseColor[0][1],
2208 lightDiffuseColor[0][2],
2209 lightDiffuseColor[0][3]);
2211 vtkgl::ProgramLocalParameter4fARB(vtkgl::FRAGMENT_PROGRAM_ARB,
2213 lightSpecularColor[0][0],
2214 lightSpecularColor[0][1],
2215 lightSpecularColor[0][2],
2216 lightSpecularColor[0][3]);
2218 vtkgl::ProgramLocalParameter4fARB(
2219 vtkgl::FRAGMENT_PROGRAM_ARB, 5, viewDirection[0], viewDirection[1], viewDirection[2], viewDirection[3]);
2221 vtkgl::ProgramLocalParameter4fARB(vtkgl::FRAGMENT_PROGRAM_ARB, 6, 2.0, -1.0, 0.0, 0.0);
2224 int vtkMitkOpenGLVolumeTextureMapper3D::IsRenderSupported(vtkRenderer *renderer, vtkVolumeProperty * )
2228 if (!this->Initialized)
2231 this->Initialize(renderer);
2234 if (!this->RenderPossible)
2236 MITK_WARN <<
"vtkMitkOpenGLVolumeTextureMapper3D::IsRenderSupported Rendering not possible";
2240 if (!this->GetInput())
2242 MITK_WARN <<
"vtkMitkOpenGLVolumeTextureMapper3D::IsRenderSupported No input available";
2249 void vtkMitkOpenGLVolumeTextureMapper3D::Initialize(vtkRenderer *renderer)
2253 this->Initialized = 1;
2256 vtkOpenGLExtensionManager *extensions =
2257 static_cast<vtkOpenGLRenderWindow *
>(renderer->GetRenderWindow())->GetExtensionManager();
2259 int supports_texture3D = extensions->ExtensionSupported(
"GL_VERSION_1_2");
2260 if (supports_texture3D)
2262 extensions->LoadExtension(
"GL_VERSION_1_2");
2266 supports_texture3D = extensions->ExtensionSupported(
"GL_EXT_texture3D");
2267 if (supports_texture3D)
2269 extensions->LoadCorePromotedExtension(
"GL_EXT_texture3D");
2273 int supports_multitexture = extensions->ExtensionSupported(
"GL_VERSION_1_3");
2274 if (supports_multitexture)
2276 extensions->LoadExtension(
"GL_VERSION_1_3");
2280 supports_multitexture = extensions->ExtensionSupported(
"GL_ARB_multitexture");
2281 if (supports_multitexture)
2283 extensions->LoadCorePromotedExtension(
"GL_ARB_multitexture");
2287 this->SupportsCompressedTexture = extensions->ExtensionSupported(
"GL_VERSION_1_3") == 1;
2288 if (!this->SupportsCompressedTexture)
2290 this->SupportsCompressedTexture = extensions->ExtensionSupported(
"GL_ARB_texture_compression") == 1;
2291 if (this->SupportsCompressedTexture)
2293 extensions->LoadCorePromotedExtension(
"GL_ARB_texture_compression");
2298 this->SupportsNonPowerOfTwoTextures = extensions->ExtensionSupported(
"GL_VERSION_2_0") ||
2299 extensions->ExtensionSupported(
"GL_ARB_texture_non_power_of_two");
2303 int supports_GL_ARB_fragment_program = extensions->ExtensionSupported(
"GL_ARB_fragment_program");
2304 if (supports_GL_ARB_fragment_program)
2306 extensions->LoadExtension(
"GL_ARB_fragment_program");
2309 int supports_GL_ARB_vertex_program = extensions->ExtensionSupported(
"GL_ARB_vertex_program");
2310 if (supports_GL_ARB_vertex_program)
2312 extensions->LoadExtension(
"GL_ARB_vertex_program");
2317 if (supports_texture3D && supports_multitexture && supports_GL_ARB_fragment_program &&
2318 supports_GL_ARB_vertex_program && vtkgl::TexImage3D && vtkgl::ActiveTexture && vtkgl::MultiTexCoord3fv &&
2319 vtkgl::GenProgramsARB && vtkgl::DeleteProgramsARB && vtkgl::BindProgramARB && vtkgl::ProgramStringARB &&
2320 vtkgl::ProgramLocalParameter4fARB)
2326 std::string errString =
2327 "no gpu-acceleration possible cause following extensions/methods are missing or unsupported:";
2328 if (!supports_texture3D)
2329 errString +=
" EXT_TEXTURE3D";
2330 if (!supports_multitexture)
2331 errString +=
" EXT_MULTITEXTURE";
2332 if (!supports_GL_ARB_fragment_program)
2333 errString +=
" ARB_FRAGMENT_PROGRAM";
2334 if (!supports_GL_ARB_vertex_program)
2335 errString +=
" ARB_VERTEX_PROGRAM";
2336 if (!vtkgl::TexImage3D)
2337 errString +=
" glTexImage3D";
2338 if (!vtkgl::ActiveTexture)
2339 errString +=
" glActiveTexture";
2340 if (!vtkgl::MultiTexCoord3fv)
2341 errString +=
" glMultiTexCoord3fv";
2342 if (!vtkgl::GenProgramsARB)
2343 errString +=
" glGenProgramsARB";
2344 if (!vtkgl::DeleteProgramsARB)
2345 errString +=
" glDeleteProgramsARB";
2346 if (!vtkgl::BindProgramARB)
2347 errString +=
" glBindProgramARB";
2348 if (!vtkgl::ProgramStringARB)
2349 errString +=
" glProgramStringARB";
2350 if (!vtkgl::ProgramLocalParameter4fARB)
2351 errString +=
" glProgramLocalParameter4fARB";
2357 vtkgl::GenProgramsARB(1, &prgOneComponentShade);
2358 vtkgl::BindProgramARB(vtkgl::FRAGMENT_PROGRAM_ARB, prgOneComponentShade);
2359 vtkgl::ProgramStringARB(vtkgl::FRAGMENT_PROGRAM_ARB,
2360 vtkgl::PROGRAM_FORMAT_ASCII_ARB,
2364 vtkgl::GenProgramsARB(1, &prgRGBAShade);
2365 vtkgl::BindProgramARB(vtkgl::FRAGMENT_PROGRAM_ARB, prgRGBAShade);
2366 vtkgl::ProgramStringARB(vtkgl::FRAGMENT_PROGRAM_ARB,
2367 vtkgl::PROGRAM_FORMAT_ASCII_ARB,
2375 void vtkMitkOpenGLVolumeTextureMapper3D::PrintSelf(ostream &os, vtkIndent indent)
2380 os << indent <<
"Initialized " << this->Initialized << endl;
2413 if (this->RenderWindow != 0)
2415 vtkOpenGLExtensionManager *extensions =
2416 static_cast<vtkOpenGLRenderWindow *
>(this->RenderWindow)->GetExtensionManager();
2418 if (this->Initialized)
2420 os << indent <<
"Supports GL_VERSION_1_2:" << extensions->ExtensionSupported(
"GL_VERSION_1_2") << endl;
2421 os << indent <<
"Supports GL_EXT_texture3D:" << extensions->ExtensionSupported(
"GL_EXT_texture3D") << endl;
2422 os << indent <<
"Supports GL_VERSION_1_3:" << extensions->ExtensionSupported(
"GL_VERSION_1_3") << endl;
2423 os << indent <<
"Supports GL_ARB_multitexture: " << extensions->ExtensionSupported(
"GL_ARB_multitexture") << endl;
2424 os << indent <<
"Supports GL_NV_texture_shader2: " << extensions->ExtensionSupported(
"GL_NV_texture_shader2")
2427 <<
"Supports GL_NV_register_combiners2: " << extensions->ExtensionSupported(
"GL_NV_register_combiners2")
2429 os << indent <<
"Supports GL_ATI_fragment_shader: " << extensions->ExtensionSupported(
"GL_ATI_fragment_shader")
2431 os << indent <<
"Supports GL_ARB_fragment_program: " << extensions->ExtensionSupported(
"GL_ARB_fragment_program")
2434 <<
"Supports GL_ARB_texture_compression: " << extensions->ExtensionSupported(
"GL_ARB_texture_compression")
2436 os << indent <<
"Supports GL_VERSION_2_0:" << extensions->ExtensionSupported(
"GL_VERSION_2_0") << endl;
2437 os << indent <<
"Supports GL_ARB_texture_non_power_of_two:" 2438 << extensions->ExtensionSupported(
"GL_ARB_texture_non_power_of_two") << endl;
2442 this->Superclass::PrintSelf(os, indent);
const char * vtkMitkVolumeTextureMapper3D_FourDependentShadeFP
vtkRenderer * GetVtkRenderer() const
const char * vtkMitkVolumeTextureMapper3D_OneComponentShadeFP
Organizes the rendering process.
void vtkVolumeTextureMapper3DComputeScalars(T *dataPtr, vtkMitkVolumeTextureMapper3D *me, float offset, float scale, GLuint volume1, GLuint)
#define myGL_COMPRESSED_RGB_S3TC_DXT1_EXT
#define myGL_COMPRESSED_RGBA_S3TC_DXT5_EXT
vtkStandardNewMacro(vtkMitkOpenGLVolumeTextureMapper3D)
void Normalize(itk::Image< TPixel, VImageDimension > *itkImage, mitk::Image::Pointer im2, mitk::Image::Pointer mask1, std::string output)
void vtkVolumeTextureMapper3DComputeRGBA(unsigned char *dataPtr, vtkMitkVolumeTextureMapper3D *me, GLuint volume1, GLuint volume2)