Skip to content

Commit

Permalink
fix(imageOutline): fix the bug where outline was not showing without …
Browse files Browse the repository at this point in the history
…filling
  • Loading branch information
sedghi authored and sankhesh committed Feb 16, 2024
1 parent d6a4380 commit e7b0968
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 43 deletions.
44 changes: 24 additions & 20 deletions Sources/Rendering/OpenGL/ImageMapper/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -346,37 +346,41 @@ function vtkOpenGLImageMapper(publicAPI, model) {
float textureValue = texture2D(labelOutlineTexture1, vec2(textureCoordinate, 0.5)).r;
int actualThickness = int(textureValue * 255.0);
if (segmentIndex == 0){
gl_FragData[0] = vec4(0.0, 1.0, 1.0, 0.0);
return;
}
if (actualThickness == 0) {
gl_FragData[0] = vec4(0.0, 0.0, 1.0, 1.0);
return;
}
if (opacityToUse > 0.01) {
for (int i = -actualThickness; i <= actualThickness; i++) {
for (int j = -actualThickness; j <= actualThickness; j++) {
if (i == 0 || j == 0) {
continue;
}
vec4 neighborPixelCoord = vec4(gl_FragCoord.x + float(i),
gl_FragCoord.y + float(j),
gl_FragCoord.z, gl_FragCoord.w);
vec3 neighborPosIS = fragCoordToIndexSpace(neighborPixelCoord);
float value = texture2D(texture1, neighborPosIS.xy).r;
if (value != centerValue) {
pixelOnBorder = true;
break;
}
for (int i = -actualThickness; i <= actualThickness; i++) {
for (int j = -actualThickness; j <= actualThickness; j++) {
if (i == 0 || j == 0) {
continue;
}
if (pixelOnBorder == true) {
vec4 neighborPixelCoord = vec4(gl_FragCoord.x + float(i),
gl_FragCoord.y + float(j),
gl_FragCoord.z, gl_FragCoord.w);
vec3 neighborPosIS = fragCoordToIndexSpace(neighborPixelCoord);
float value = texture2D(texture1, neighborPosIS.xy).r;
if (value != centerValue) {
pixelOnBorder = true;
break;
}
}
if (pixelOnBorder == true) {
gl_FragData[0] = vec4(tColor, outlineOpacity);
}
else {
gl_FragData[0] = vec4(tColor, opacityToUse);
break;
}
}
if (pixelOnBorder == true) {
gl_FragData[0] = vec4(tColor, outlineOpacity);
}
else {
gl_FragData[0] = vec4(tColor, opacityToUse);
}
#else
float intensity = texture2D(texture1, tcoordVCVSOutput).r;
vec3 tcolor = texture2D(colorTexture1, vec2(intensity * cscale0 + cshift0, 0.5)).rgb;
Expand Down
51 changes: 28 additions & 23 deletions Sources/Rendering/OpenGL/glsl/vtkVolumeFS.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -988,43 +988,48 @@ vec4 getColorForValue(vec4 tValue, vec3 posIS, vec3 tstep)
return vec4(0, 0, 1, 1);
}

// If it is the background (segment index 0), we should quickly bail out.
// Previously, this was determined by tColor.a, which was incorrect as it
// prevented the outline from appearing when the fill is 0.
if (segmentIndex == 0){
return vec4(0, 0, 0, 0);
}

// Only perform outline check on fragments rendering voxels that aren't invisible.
// Saves a bunch of needless checks on the background.
// TODO define epsilon when building shader?
if (float(tColor.a) > 0.01) {
for (int i = -actualThickness; i <= actualThickness; i++) {
for (int j = -actualThickness; j <= actualThickness; j++) {
if (i == 0 || j == 0) {
continue;
}

vec4 neighborPixelCoord = vec4(gl_FragCoord.x + float(i),
gl_FragCoord.y + float(j),
gl_FragCoord.z, gl_FragCoord.w);
for (int i = -actualThickness; i <= actualThickness; i++) {
for (int j = -actualThickness; j <= actualThickness; j++) {
if (i == 0 || j == 0) {
continue;
}

vec3 neighborPosIS = fragCoordToIndexSpace(neighborPixelCoord);
vec4 value = getTextureValue(neighborPosIS);
vec4 neighborPixelCoord = vec4(gl_FragCoord.x + float(i),
gl_FragCoord.y + float(j),
gl_FragCoord.z, gl_FragCoord.w);

// If any of my neighbours are not the same value as I
// am, this means I am on the border of the segment.
// We can break the loops
if (any(notEqual(value, centerValue))) {
pixelOnBorder = true;
break;
}
}
vec3 neighborPosIS = fragCoordToIndexSpace(neighborPixelCoord);
vec4 value = getTextureValue(neighborPosIS);

if (pixelOnBorder == true) {
// If any of my neighbours are not the same value as I
// am, this means I am on the border of the segment.
// We can break the loops
if (any(notEqual(value, centerValue))) {
pixelOnBorder = true;
break;
}
}

// If I am on the border, I am displayed at full opacity
if (pixelOnBorder == true) {
tColor.a = outlineOpacity;
break;
}
}

// If I am on the border, I am displayed at full opacity
if (pixelOnBorder == true) {
tColor.a = outlineOpacity;
}

#else
// compute the normal and gradient magnitude if needed
// We compute it as a vec4 if possible otherwise a mat4
Expand Down

0 comments on commit e7b0968

Please sign in to comment.