Skip to content

Commit

Permalink
refactor(VolumeMapper): minor refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
bruyeret committed Mar 6, 2024
1 parent 4d490f9 commit 50314fd
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 23 deletions.
2 changes: 1 addition & 1 deletion Sources/Rendering/OpenGL/VolumeMapper/Constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export const ApiSpecificPresets = {
[ColorMixPreset.ADDITING]: `
float opacity0 = goFactor.x * pwfValue0;
float opacity1 = goFactor.y * pwfValue1;
float opacitySum = opacity0 + opacity1;
float opacitySum = clamp(opacity0 + opacity1, 0.0, 1.0);
if (opacitySum == 0.0) {
return vec4(0.0);
}
Expand Down
23 changes: 2 additions & 21 deletions Sources/Rendering/OpenGL/VolumeMapper/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as macro from 'vtk.js/Sources/macros';
import DeepEqual from 'fast-deep-equal';
import { vec3, mat3, mat4 } from 'gl-matrix';
// import vtkBoundingBox from 'vtk.js/Sources/Common/DataModel/BoundingBox';
import vtkDataArray from 'vtk.js/Sources/Common/Core/DataArray';
Expand Down Expand Up @@ -33,26 +34,6 @@ const { vtkWarningMacro, vtkErrorMacro } = macro;
// ----------------------------------------------------------------------------
// helper methods
// ----------------------------------------------------------------------------
// TODO: Do we want this in some shared utility? Shouldwe just use lodash.isEqual
function arrayEquals(a, b) {
if (a.length !== b.length) {
return false;
}
for (let i = 0; i < a.length; ++i) {
if (a[i] !== b[i]) {
return false;
}
}
return true;
}

// TODO: Do we want this in some shared utility? Shouldwe just use lodash.isEqual
function deepEqual(a, b) {
return (
typeof a === typeof b &&
(typeof a !== 'object' || arrayEquals(Object.entries(a), Object.entries(b)))
);
}

function computeFnToString(property, pwfun, numberOfComponents) {
if (pwfun) {
Expand Down Expand Up @@ -525,7 +506,7 @@ function vtkOpenGLVolumeMapper(publicAPI, model) {

// We only need to rebuild the shader if one of these variables has changed,
// since they are used in the shader template replacement step.
if (!model.previousState || !deepEqual(model.previousState, state)) {
if (!model.previousState || !DeepEqual(model.previousState, state)) {
model.previousState = state;

return true;
Expand Down
2 changes: 1 addition & 1 deletion Sources/Rendering/OpenGL/glsl/vtkVolumeFS.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -1207,7 +1207,7 @@ vec4 getColorForValue(vec4 tValue, vec3 posIS, vec3 tstep)
return vec4(tColor, alpha);
#else
/*
* Mix the color informations from all the independent components to get a single rgba output
* Mix the color information from all the independent components to get a single rgba output
*
* goFactor is computed if vtkGradientOpacityOn
* it is not computed for proportional components
Expand Down

0 comments on commit 50314fd

Please sign in to comment.