Skip to content

Commit

Permalink
fix(normalization): now works fully with normalized outlines
Browse files Browse the repository at this point in the history
  • Loading branch information
sedghi committed Nov 27, 2023
1 parent 0a8f494 commit 4bcbe41
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 14 deletions.
5 changes: 0 additions & 5 deletions Examples/Volume/VolumeOutline/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,4 @@ reader
renderer.addVolume(labelMap.actor);
renderer.getActiveCamera().setViewUp(1, 0, 0);
renderWindow.render();

setTimeout(() => {
labelMap.actor.getProperty().setLabelOutlineThickness([2, 4]);
renderWindow.render();
}, 1000);
});
17 changes: 9 additions & 8 deletions Sources/Rendering/OpenGL/VolumeMapper/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1621,14 +1621,17 @@ function vtkOpenGLVolumeMapper(publicAPI, model) {
const maxThickness = Math.max(...labelOutlineThicknessArray);

for (let i = 0; i < lWidth; ++i) {
const thickness = labelOutlineThicknessArray[i];
let normalizedThickness;
// Retrieve the thickness value for the current segment index.
// If the value is undefined, null, or 0, use the first element's value as a default.
let thickness = labelOutlineThicknessArray[i];
if (thickness === undefined || thickness === null || thickness === 0) {
normalizedThickness = labelOutlineThicknessArray[0] / maxThickness;
} else {
normalizedThickness = thickness / maxThickness;
thickness = labelOutlineThicknessArray[0];
}
lTable[i] = 255.0 * normalizedThickness;

// Normalize the thickness value to the range [0, 1].
const normalizedThickness = thickness / maxThickness;

lTable[i] = Math.round(255.0 * normalizedThickness);
}

model.labelOutlineThicknessTexture.releaseGraphicsResources(
Expand All @@ -1638,8 +1641,6 @@ function vtkOpenGLVolumeMapper(publicAPI, model) {
model.labelOutlineThicknessTexture.resetFormatAndType();
model.labelOutlineThicknessTexture.setMinificationFilter(Filter.NEAREST);
model.labelOutlineThicknessTexture.setMagnificationFilter(Filter.NEAREST);
model.labelOutlineThicknessTexture.setWrapS(Wrap.CLAMP_TO_EDGE);
model.labelOutlineThicknessTexture.setWrapT(Wrap.CLAMP_TO_EDGE);

// Create a 2D texture (acting as 1D) from the raw data
model.labelOutlineThicknessTexture.create2DFromRaw(
Expand Down
3 changes: 2 additions & 1 deletion Sources/Rendering/OpenGL/glsl/vtkVolumeFS.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -984,7 +984,8 @@ vec4 getColorForValue(vec4 tValue, vec3 posIS, vec3 tstep)

// // Use texture sampling for outlineThickness
float normalizedThickness = texture2D(ttexture, vec2(float(segmentIndex - 1 ) / 1024.0, 0.5)).r;
int actualThickness = int(normalizedThickness * uMaxLabelOutlineThickness);

int actualThickness = int(round(normalizedThickness * uMaxLabelOutlineThickness));

// Only perform outline check on fragments rendering voxels that aren't invisible.
// Saves a bunch of needless checks on the background.
Expand Down

0 comments on commit 4bcbe41

Please sign in to comment.