Mercurial > hg > orthanc-stone
changeset 2064:4e31d76c7ecd deep-learning
making ImageProcessingProgram compatible with 3D volumes
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 04 May 2023 11:06:19 +0200 |
parents | b6b5e1ca1cc2 |
children | 15f2e52835a1 |
files | OrthancStone/Sources/OpenGL/ImageProcessingProgram.cpp OrthancStone/Sources/OpenGL/ImageProcessingProgram.h OrthancStone/Sources/OpenGL/OpenGLFramebuffer.cpp |
diffstat | 3 files changed, 44 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/OrthancStone/Sources/OpenGL/ImageProcessingProgram.cpp Wed May 03 22:00:38 2023 +0200 +++ b/OrthancStone/Sources/OpenGL/ImageProcessingProgram.cpp Thu May 04 11:06:19 2023 +0200 @@ -50,7 +50,7 @@ * "a_position" (position in the target frame buffer) ranges from -1 * to 1, whereas texture samplers range from 0 to 1. **/ -static const char* VERTEX_SHADER = +static const char* VERTEX_SHADER_2D = "in vec2 a_position; \n" "out vec2 v_position; \n" "void main() { \n" @@ -59,6 +59,21 @@ "} \n"; +/** + * VERTEX_SHADER_3D allows to sample a 3D texture by introducing the + * "u_z" uniform whose range is in [0,1] and that allows to scan a 3D + * texture along its Z axis. + **/ +static const char* VERTEX_SHADER_3D = + "in vec2 a_position; \n" + "out vec3 v_position; \n" + "uniform float u_z; \n" + "void main() { \n" + " v_position = vec3((a_position + 1.0) / 2.0, u_z); \n" + " gl_Position = vec4(a_position, u_z, 1.0); \n" + "} \n"; + + namespace OrthancStone { namespace OpenGL @@ -74,7 +89,8 @@ ImageProcessingProgram::ImageProcessingProgram(IOpenGLContext& context, - const std::string& fragmentShader) : + const std::string& fragmentShader, + bool addUniformZ) : program_(context), quad_vertexbuffer(0) { @@ -103,7 +119,8 @@ version = ("#version 300 es\n" "precision highp float;\n" "precision highp sampler2D;\n" - "precision highp sampler2DArray;\n"); + "precision highp sampler2DArray;\n" + "precision highp sampler3D;\n"); #else /** * "#version 130" corresponds to: @@ -113,7 +130,18 @@ version = "#version 130\n"; #endif - program_.CompileShaders(version + VERTEX_SHADER, version + fragmentShader); + std::string vertexShader; + + if (addUniformZ) + { + vertexShader = version + VERTEX_SHADER_3D; + } + else + { + vertexShader = version + VERTEX_SHADER_2D; + } + + program_.CompileShaders(vertexShader, version + fragmentShader); glGenBuffers(1, &quad_vertexbuffer); if (quad_vertexbuffer == 0)
--- a/OrthancStone/Sources/OpenGL/ImageProcessingProgram.h Wed May 03 22:00:38 2023 +0200 +++ b/OrthancStone/Sources/OpenGL/ImageProcessingProgram.h Thu May 04 11:06:19 2023 +0200 @@ -33,6 +33,7 @@ class OpenGLFramebuffer; class OpenGLTexture; class OpenGLTextureArray; + class OpenGLTextureVolume; class ImageProcessingProgram : public boost::noncopyable { @@ -44,7 +45,8 @@ public: ImageProcessingProgram(IOpenGLContext& context, - const std::string& fragmentShader); + const std::string& fragmentShader, + bool addUniformZ /* for 3D texture sampling */); ~ImageProcessingProgram(); @@ -57,6 +59,11 @@ OpenGLFramebuffer& framebuffer, bool checkStatus); + void Use(OpenGLTextureVolume& volume, + unsigned int z, + OpenGLFramebuffer& framebuffer, + bool checkStatus); + void Render(); GLint GetUniformLocation(const std::string& name)
--- a/OrthancStone/Sources/OpenGL/OpenGLFramebuffer.cpp Wed May 03 22:00:38 2023 +0200 +++ b/OrthancStone/Sources/OpenGL/OpenGLFramebuffer.cpp Thu May 04 11:06:19 2023 +0200 @@ -191,6 +191,8 @@ void OpenGLFramebuffer::SetTarget(OpenGLTexture& target) { glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, target.GetId(), 0); + ORTHANC_OPENGL_CHECK("glFramebufferTexture2D()"); + SetupTextureTarget(); glViewport(0, 0, target.GetWidth(), target.GetHeight()); } @@ -206,6 +208,8 @@ else { glFramebufferTextureLayer(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, target.GetId(), 0, layer); + ORTHANC_OPENGL_CHECK("glFramebufferTextureLayer()"); + SetupTextureTarget(); glViewport(0, 0, target.GetWidth(), target.GetHeight()); }