From 215878a5df0dfcf78c99e11699620f31ae3c4670 Mon Sep 17 00:00:00 2001 From: Erik Smistad Date: Mon, 4 Sep 2023 15:36:42 +0200 Subject: [PATCH] Fixed some issues with ApplyColormap --- .../Algorithms/ApplyColormap/ApplyColormap.cl | 2 +- .../Algorithms/ApplyColormap/ApplyColormap.cpp | 15 ++++++++------- .../Visualization/ImageRenderer/ImageRenderer.cpp | 5 +++-- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/source/FAST/Algorithms/ApplyColormap/ApplyColormap.cl b/source/FAST/Algorithms/ApplyColormap/ApplyColormap.cl index 6c62f99d6..479333d5c 100644 --- a/source/FAST/Algorithms/ApplyColormap/ApplyColormap.cl +++ b/source/FAST/Algorithms/ApplyColormap/ApplyColormap.cl @@ -113,7 +113,7 @@ float4 getColorFromColormap(float intensity, __constant float* colormap, int ste return first; } -__kernel void applyColormapGrayscale( +__kernel void applyColormap( __read_only image2d_t input, __write_only image2d_t output, __constant float* colormap, diff --git a/source/FAST/Algorithms/ApplyColormap/ApplyColormap.cpp b/source/FAST/Algorithms/ApplyColormap/ApplyColormap.cpp index 32f4eaaba..54a211929 100644 --- a/source/FAST/Algorithms/ApplyColormap/ApplyColormap.cpp +++ b/source/FAST/Algorithms/ApplyColormap/ApplyColormap.cpp @@ -49,7 +49,7 @@ void ApplyColormap::execute() { m_bufferUpToDate = true; } - cl::Kernel kernel(getOpenCLProgram(device), "applyColormapGrayscale"); + cl::Kernel kernel(getOpenCLProgram(device), "applyColormap"); float minValue = m_minValue; float maxValue = m_maxValue; @@ -68,7 +68,7 @@ void ApplyColormap::execute() { kernel.setArg(3, m_colormap.getSteps()); kernel.setArg(4, (char)(m_colormap.isInterpolated() ? 1 : 0)); kernel.setArg(5, (char)(m_colormap.isGrayscale() ? 1 : 0)); - kernel.setArg(6, (char)(m_colormap.hasOpacity() ? 1 : 0)); + kernel.setArg(6, (char)((m_colormap.hasOpacity() || m_opacity < 1.0f) ? 1 : 0)); kernel.setArg(7, (char)(m_colormap.isIntensityInvariant() ? 1 : 0)); kernel.setArg(8, minValue); kernel.setArg(9, maxValue); @@ -102,6 +102,7 @@ void ApplyColormap::setOpacity(float opacity) { throw Exception("Opacity must be within range [0, 1] in ApplyColormap"); m_opacity = opacity; + m_bufferUpToDate = false; setModified(true); } @@ -181,7 +182,7 @@ cl::Buffer Colormap::getAsOpenCLBuffer(OpenCLDevice::pointer device, float opaci for(int i = 0; i < m_data.size(); ++i) { dataToTransfer.push_back(m_data[i]); if((i+1) % elements == 0) - dataToTransfer.push_back(opacity); + dataToTransfer.push_back(opacity*255.0f); } } else { for(int i = elements-1; i < m_data.size(); i += elements) { @@ -274,10 +275,10 @@ Colormap Colormap::Fire(bool withOpacity) { float enableOpacity = withOpacity ? 1.0f : -1.0f; return Colormap({ {0, Color(0, 0, 0, withOpacity ? 0.0f : -1.0f)}, - {0.1, Color(40.0f/255, 25.0f/255, 0, 0.05f*enableOpacity)}, - {0.3, Color(80.0f/255, 35.0f/255, 0, 0.1f*enableOpacity)}, - {0.4, Color(140.0f/255, 30.0f/255, 0, 0.3f*enableOpacity)}, - {0.6, Color(200.0f/255, 160.0f/255, 0, 0.5f*enableOpacity)}, + {0.1, Color(40.0f/255, 25.0f/255, 0, 0.1f*enableOpacity)}, + {0.3, Color(80.0f/255, 35.0f/255, 0, 0.2f*enableOpacity)}, + {0.4, Color(140.0f/255, 30.0f/255, 0, 0.4f*enableOpacity)}, + {0.6, Color(200.0f/255, 160.0f/255, 0, 0.6f*enableOpacity)}, {0.9, Color(252.0f/255, 252.0f/255, 160.0f/255, 0.75f*enableOpacity)}, {1.0, Color(255.0f/255, 255.0f/255, 255.0f/255, 0.8f*enableOpacity)}, }, true, true); diff --git a/source/FAST/Visualization/ImageRenderer/ImageRenderer.cpp b/source/FAST/Visualization/ImageRenderer/ImageRenderer.cpp index 01ffd21fd..4545707b1 100644 --- a/source/FAST/Visualization/ImageRenderer/ImageRenderer.cpp +++ b/source/FAST/Visualization/ImageRenderer/ImageRenderer.cpp @@ -88,6 +88,9 @@ void ImageRenderer::draw(Matrix4f perspectiveMatrix, Matrix4f viewingMatrix, flo Image::pointer input = std::static_pointer_cast(it.second); uint inputNr = it.first; + if(input->getNrOfChannels() == 4) + transparentImage = true; + if(input->getDimensions() != 2) throw Exception("ImageRenderer only supports 2D images. Use ImageSlicer to extract a 2D slice from a 3D image."); @@ -124,8 +127,6 @@ void ImageRenderer::draw(Matrix4f perspectiveMatrix, Matrix4f viewingMatrix, flo mTexturesToRender[inputNr] = textureID; mImageUsed[inputNr] = input; mDataTimestamp[inputNr] = input->getTimestamp(); - if(input->getNrOfChannels() == 4) - transparentImage = true; } if(m_opacity >= 0.0f || transparentImage) { glEnable(GL_BLEND);