关键词:OpenGL、GLSL、DICOM
一、数据读取
DICOM文件的读取使用DCMTK库,DcmFileFormat 成员函数findAndGetUint16Array(DCM_PixelData, pPixels);pPixels是指向数据的指针。
二、创建查找表并保存为纹理
glGenTextures(1, &lutTexture); glBindTexture(GL_TEXTURE_1D,lutTexture); glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexImage1D(GL_TEXTURE_1D, 0, GL_LUMINANCE16, texSize, 0, GL_LUMINANCE, GL_UNSIGNED_SHORT, lut16U);
lut16U是查找表指针。
三、将图像数据保存为纹理
glPixelStorei(GL_UNPACK_ALIGNMENT,2); glGenTextures(1, &imgTexture); glBindTexture(GL_TEXTURE_2D, imgTexture); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE16, img_width, img_height,0, GL_LUMINANCE, GL_UNSIGNED_SHORT,pData);
pData是数据指针
三、着色器代码
void main() { vec4 finalCol; float tmpColor; vec4 color = vec4(texture2D(mainTexture, gl_TexCoord[0].st)) * multiplier; color.rgb -= minVal; if (invertGray == true) { finalCol.r = 1-texture1D(lutTexture, color.r).r; finalCol.g = 1-texture1D(lutTexture, color.g).g; finalCol.b = 1-texture1D(lutTexture, color.b).b; finalCol.a = color.a; } else{ finalCol.r = texture1D(lutTexture, color.r).r; finalCol.g = texture1D(lutTexture, color.g).g; finalCol.b = texture1D(lutTexture, color.b).b; finalCol.a = color.a; } gl_FragColor = finalCol; }
已实现功能:右键调节窗宽窗位、反色、缩放、平移;
待实现功能:测量工具、汉字显示、高级应用。