Skip to content

Commit

Permalink
Merge pull request #388 from boucaud/fix-vtkjs-opacity-pwf
Browse files Browse the repository at this point in the history
fix(glancevtkjsreader): normalize opacity pwf nodes before adding them
  • Loading branch information
floryst authored Feb 5, 2021
2 parents 3e8b4ea + b430f1c commit ddfdb71
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 17 deletions.
90 changes: 78 additions & 12 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"pug": "^3.0.0",
"pug-plain-loader": "^1.0.0",
"typeface-roboto": "0.0.75",
"vtk.js": "15.4.0",
"vtk.js": "16.2.0",
"vue": "2.6.11",
"vue-cli-plugin-vuetify": "^2.0.7",
"vuetify": "2.3.4",
Expand Down
14 changes: 10 additions & 4 deletions src/io/GlanceVtkJsReader.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,19 +213,25 @@ function vtkGlanceVtkJsReader(publicAPI, model) {
const pwf = pwfProxy.getPiecewiseFunction();
pwf.setClamping(scalarOpacity.getClamping());
const nodes = [];

const range = scalarOpacity.getRange();
pwfProxy.setDataRange(...range);

const width = range[1] - range[0];

for (
let nodeIdx = 0;
nodeIdx < scalarOpacity.getSize();
++nodeIdx
) {
const node = [];
scalarOpacity.getNodeValue(nodeIdx, node);
nodes.push([...node]);
const [x, y, midpoint, sharpness] = node;
// x needs to be normalized
nodes.push({ x: (x - range[0]) / width, y, midpoint, sharpness });
}
pwfProxy.setMode(PiecewiseFunctionProxyConstants.Mode.Nodes);
const range = scalarOpacity.getRange();
pwfProxy.setDataRange(...range);
pwfProxy.setNodes(scalarOpacity.get('nodes').nodes);
pwfProxy.setNodes(nodes);
}
}
}
Expand Down

0 comments on commit ddfdb71

Please sign in to comment.