Skip to content

Commit 7b3f85c

Browse files
jadh4vclaude
andcommitted
refactor(compose-functions): drop unused dataRange param from compose()
compose() no longer needs an explicit dataRange since outputFn's mapping range is already derived from its node positions via addRGBPoint's sortAndUpdateRange. Update the example and tests to match the new compose(fnList, colorFn, outputFn) signature. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 3240737 commit 7b3f85c

3 files changed

Lines changed: 19 additions & 22 deletions

File tree

Examples/Rendering/ComposePiecewiseFunctions/index.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,9 @@ function buildColorFunction(presetName) {
121121
colorFn.applyColorMap(vtkColorMaps.getPresetByName(presetName));
122122
}
123123

124-
function example_recompose(dataRange) {
124+
function example_recompose() {
125125
const fnList = [modalityFn, voiFn, userFn];
126-
compose(dataRange, fnList, colorFn, resultFn);
126+
compose(fnList, colorFn, resultFn);
127127
actor.getProperty().setUseLookupTableScalarRange(true);
128128
actor.getProperty().setRGBTransferFunction(0, resultFn);
129129
}
@@ -303,7 +303,7 @@ function renderDicom(file) {
303303
// User interactive adjustment (window/level)
304304
buildUserFn(getOutputRange(voiFn), colorWindow, colorLevel);
305305
// Compose into a single transferfunction to feed into the mapper.
306-
example_recompose(dataRange);
306+
example_recompose();
307307

308308
if (!renderer.getActors().length) {
309309
renderer.addActor(actor);
@@ -354,7 +354,7 @@ function renderDicom(file) {
354354
(val) => {
355355
modalityShift = val;
356356
buildModalityFunction(dataRange, modalityShift, modalityScale);
357-
example_recompose(dataRange);
357+
example_recompose();
358358
renderWindow.render();
359359
}
360360
);
@@ -369,7 +369,7 @@ function renderDicom(file) {
369369
(val) => {
370370
modalityScale = val;
371371
buildModalityFunction(dataRange, modalityShift, modalityScale);
372-
example_recompose(dataRange);
372+
example_recompose();
373373
renderWindow.render();
374374
},
375375
scaleFormat
@@ -422,7 +422,7 @@ function renderDicom(file) {
422422
Number(windowInput.value),
423423
Number(levelInput.value)
424424
);
425-
example_recompose(dataRange);
425+
example_recompose();
426426
renderWindow.render();
427427
}
428428
);
@@ -443,7 +443,7 @@ function renderDicom(file) {
443443
Number(windowInput.value),
444444
Number(levelInput.value)
445445
);
446-
example_recompose(dataRange);
446+
example_recompose();
447447
renderWindow.render();
448448
},
449449
scaleFormat
@@ -468,7 +468,7 @@ function renderDicom(file) {
468468
1,
469469
(val) => {
470470
buildUserFn(getOutputRange(voiFn), val, Number(levelInput.value));
471-
example_recompose(dataRange);
471+
example_recompose();
472472
renderWindow.render();
473473
}
474474
));
@@ -482,7 +482,7 @@ function renderDicom(file) {
482482
1,
483483
(val) => {
484484
buildUserFn(getOutputRange(voiFn), Number(windowInput.value), val);
485-
example_recompose(dataRange);
485+
example_recompose();
486486
renderWindow.render();
487487
}
488488
));
@@ -519,7 +519,7 @@ function renderDicom(file) {
519519
presetSelector.addEventListener('change', () => {
520520
currentPreset = presetSelector.value;
521521
buildColorFunction(currentPreset);
522-
example_recompose(dataRange);
522+
example_recompose();
523523
renderWindow.render();
524524
});
525525
controlPanel.appendChild(presetSelector);

Sources/Common/DataModel/PiecewiseFunction/helpers.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,11 @@ function getColorFunctionXValues(cfun) {
1919
* and must be pulled back through f-inverse; h's x-values need g-inverse then
2020
* f-inverse, and so on.
2121
*
22-
* @param {Range} dataRange input data range to apply to the output function
2322
* @param {vtkPiecewiseFunction[]} fnList ordered list of value transform functions, e.g. [modalityFn, voiFn, userFn]
2423
* @param {vtkColorTransferFunction} colorFn final-stage color transfer function
2524
* @param {vtkColorTransferFunction} outputFn function to populate with the composed result
2625
*/
27-
export function compose(dataRange, fnList, colorFn, outputFn) {
26+
export function compose(fnList, colorFn, outputFn) {
2827
const xSet = new Set();
2928

3029
// Each function's breakpoint x-values live in that function's input domain.
@@ -54,6 +53,9 @@ export function compose(dataRange, fnList, colorFn, outputFn) {
5453
if (t != null) xSet.add(t);
5554
});
5655

56+
// Now use the gathered x values to propogate through the entire set of
57+
// functions to determine the final color values for each, and add them
58+
// as nodes to our new color transfer function.
5759
const xs = Array.from(xSet).sort((a, b) => a - b);
5860
outputFn.removeAllPoints();
5961
xs.forEach((x) => {
@@ -62,9 +64,4 @@ export function compose(dataRange, fnList, colorFn, outputFn) {
6264
colorFn.getColor(finalScalar, rgb);
6365
outputFn.addRGBPoint(x, rgb[0], rgb[1], rgb[2]);
6466
});
65-
66-
outputFn.setRange(...dataRange);
67-
outputFn.setMappingRange(...dataRange);
68-
outputFn.updateRange();
69-
outputFn.modified();
7067
}

Sources/Common/DataModel/PiecewiseFunction/test/testHelpers.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ it('Test compose with an identity transform passes colorFn through unchanged', (
2323
colorFn.addRGBPoint(100, 0, 0, 1);
2424

2525
const outputFn = vtkColorTransferFunction.newInstance();
26-
compose([0, 100], [identityFn], colorFn, outputFn);
26+
compose([identityFn], colorFn, outputFn);
2727

2828
expect(getNodeXs(outputFn)).toEqual([0, 100]);
2929
expect(outputFn.getRange()).toEqual([0, 100]);
@@ -49,7 +49,7 @@ it('Test compose maps a color function breakpoint back to its source domain', ()
4949
colorFn.addRGBPoint(110, 0, 0, 1);
5050

5151
const outputFn = vtkColorTransferFunction.newInstance();
52-
compose([0, 100], [fn], colorFn, outputFn);
52+
compose([fn], colorFn, outputFn);
5353

5454
const xs = getNodeXs(outputFn);
5555
expect(xs.length).toBe(3);
@@ -84,7 +84,7 @@ it('Test compose chains multiple transform functions and propagates breakpoints
8484
colorFn.addRGBPoint(100, 0, 0, 1);
8585

8686
const outputFn = vtkColorTransferFunction.newInstance();
87-
compose([0, 100], [fn1, fn2], colorFn, outputFn);
87+
compose([fn1, fn2], colorFn, outputFn);
8888

8989
const xs = getNodeXs(outputFn);
9090
expect(xs.length).toBe(3);
@@ -115,12 +115,12 @@ it('Test compose clears previously composed points on subsequent calls', () => {
115115
colorFn.addRGBPoint(100, 0, 0, 1);
116116

117117
const outputFn = vtkColorTransferFunction.newInstance();
118-
compose([0, 100], [fn], colorFn, outputFn);
118+
compose([fn], colorFn, outputFn);
119119
expect(outputFn.getSize()).toBe(3);
120120

121121
colorFn.removeAllPoints();
122122
colorFn.addRGBPoint(0, 1, 1, 1);
123123
colorFn.addRGBPoint(100, 0, 0, 0);
124-
compose([0, 100], [fn], colorFn, outputFn);
124+
compose([fn], colorFn, outputFn);
125125
expect(outputFn.getSize()).toBe(2);
126126
});

0 commit comments

Comments
 (0)