Skip to content

Commit

Permalink
Fixed some issues with ApplyColormap
Browse files Browse the repository at this point in the history
  • Loading branch information
smistad committed Sep 4, 2023
1 parent e6ebe71 commit 215878a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
2 changes: 1 addition & 1 deletion source/FAST/Algorithms/ApplyColormap/ApplyColormap.cl
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
15 changes: 8 additions & 7 deletions source/FAST/Algorithms/ApplyColormap/ApplyColormap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down
5 changes: 3 additions & 2 deletions source/FAST/Visualization/ImageRenderer/ImageRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ void ImageRenderer::draw(Matrix4f perspectiveMatrix, Matrix4f viewingMatrix, flo
Image::pointer input = std::static_pointer_cast<Image>(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.");

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 215878a

Please sign in to comment.