Skip to content

Commit d98d55c

Browse files
authored
feat: 🎸 Allows configuration of a the segmentation properties (#77)
* Pass down colorLUT options to View2D & View3D * Ability to toggle segmentation on/off * Ability to set segmentation LUTs and global opacity. * feat: 🎸 Allows configuration of a the segmentation properties * Update examples and View3D port.
1 parent 4a55534 commit d98d55c

File tree

5 files changed

+98
-18
lines changed

5 files changed

+98
-18
lines changed

‎src/VTKViewport/View2D.js‎

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,11 @@ import vtkSVGWidgetManager from './vtkSVGWidgetManager';
1111
import ViewportOverlay from '../ViewportOverlay/ViewportOverlay.js';
1212
import { ViewTypes } from 'vtk.js/Sources/Widgets/Core/WidgetManager/Constants';
1313
import { createSub } from '../lib/createSub.js';
14+
import realsApproximatelyEqual from '../lib/math/realsApproximatelyEqual';
1415
import createLabelPipeline from './createLabelPipeline';
1516

17+
const minSlabThickness = 0.1; // TODO -> Should this be configurable or not?
18+
1619
export default class View2D extends Component {
1720
static propTypes = {
1821
volumes: PropTypes.array.isRequired,
@@ -27,10 +30,14 @@ export default class View2D extends Component {
2730
onCreated: PropTypes.func,
2831
onDestroyed: PropTypes.func,
2932
orientation: PropTypes.object,
33+
labelmapRenderingOptions: PropTypes.object,
3034
};
3135

3236
static defaultProps = {
3337
painting: false,
38+
labelmapRenderingOptions: {
39+
visible: true,
40+
},
3441
};
3542

3643
constructor(props) {
@@ -258,8 +265,6 @@ export default class View2D extends Component {
258265
if (currentIStyle.getSlabThickness) {
259266
return currentIStyle.getSlabThickness();
260267
}
261-
262-
//return this.currentSlabThickness;
263268
}
264269

265270
setSlabThickness(slabThickness) {
@@ -268,6 +273,23 @@ export default class View2D extends Component {
268273

269274
if (istyle.setSlabThickness) {
270275
istyle.setSlabThickness(slabThickness);
276+
277+
if (this.props.paintFilterLabelMapImageData) {
278+
const labelmapActor = this.labelmap.actor;
279+
280+
if (realsApproximatelyEqual(slabThickness, minSlabThickness)) {
281+
if (
282+
labelmapActor.getVisibility() !==
283+
this.props.labelmapRenderingOptions.visible
284+
) {
285+
labelmapActor.setVisibility(
286+
this.props.labelmapRenderingOptions.visible
287+
);
288+
}
289+
} else {
290+
labelmapActor.setVisibility(false);
291+
}
292+
}
271293
}
272294

273295
renderWindow.render();
@@ -392,7 +414,8 @@ export default class View2D extends Component {
392414
const labelmapImageData = this.props.paintFilterLabelMapImageData;
393415
const labelmap = createLabelPipeline(
394416
this.props.paintFilterBackgroundImageData,
395-
labelmapImageData
417+
labelmapImageData,
418+
this.props.labelmapRenderingOptions
396419
);
397420

398421
this.labelmap = labelmap;
@@ -410,6 +433,16 @@ export default class View2D extends Component {
410433
);
411434
}
412435

436+
if (
437+
prevProps.labelmapRenderingOptions &&
438+
prevProps.labelmapRenderingOptions.visible !==
439+
this.props.labelmapRenderingOptions.visible
440+
) {
441+
this.labelmap.actor.setVisibility(
442+
prevProps.labelmapRenderingOptions.visible
443+
);
444+
}
445+
413446
if (prevProps.painting !== this.props.painting) {
414447
if (this.props.painting) {
415448
this.viewWidget = this.widgetManager.addWidget(

‎src/VTKViewport/View3D.js‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,15 @@ export default class View3D extends Component {
2424
dataDetails: PropTypes.object,
2525
onCreated: PropTypes.func,
2626
onDestroyed: PropTypes.func,
27+
labelmapRenderingOptions: PropTypes.object,
2728
};
2829

2930
static defaultProps = {
3031
painting: false,
3132
sliceNormal: [0, 0, 1],
33+
labelmapRenderingOptions: {
34+
visible: true,
35+
},
3236
};
3337

3438
constructor(props) {
@@ -189,6 +193,7 @@ export default class View3D extends Component {
189193
const labelmap = createLabelPipeline(
190194
this.props.paintFilterBackgroundImageData,
191195
labelmapImageData,
196+
this.props.labelmapRenderingOptions,
192197
true
193198
);
194199

‎src/VTKViewport/createLabelPipeline.js‎

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,21 @@ import vtkPiecewiseFunction from 'vtk.js/Sources/Common/DataModel/PiecewiseFunct
88
export default function createLabelPipeline(
99
backgroundImageData,
1010
paintFilterLabelMapImageData,
11+
options,
1112
useSampleDistance = false
1213
) {
1314
let labelMapData;
1415

16+
let { colorLUT, globalOpacity, visible } = options;
17+
18+
if (visible === undefined) {
19+
visible = false;
20+
}
21+
22+
if (globalOpacity === undefined) {
23+
globalOpacity = 1.0;
24+
}
25+
1526
if (paintFilterLabelMapImageData) {
1627
labelMapData = paintFilterLabelMapImageData;
1728
} else {
@@ -53,17 +64,41 @@ export default function createLabelPipeline(
5364

5465
// labelmap pipeline
5566
labelMap.actor.setMapper(labelMap.mapper);
67+
labelMap.actor.setVisibility(visible);
68+
labelMap.ofun.addPoint(0, 0);
5669

5770
// set up labelMap color and opacity mapping
58-
labelMap.cfun.addRGBPoint(1, 1, 0, 0); // label '1' will be red
59-
labelMap.cfun.addRGBPoint(2, 0, 1, 0); // label '2' will be green
60-
labelMap.cfun.addRGBPoint(3, 0, 1, 1); // label '3' will be blue
61-
labelMap.ofun.addPoint(0, 0);
62-
labelMap.ofun.addPoint(1, 0.9);
71+
if (colorLUT) {
72+
// TODO -> It seems to crash if you set it higher than 256??
73+
const numColors = Math.min(256, colorLUT.length);
74+
75+
for (let i = 0; i < numColors; i++) {
76+
//for (let i = 0; i < colorLUT.length; i++) {
77+
const color = colorLUT[i];
78+
labelMap.cfun.addRGBPoint(
79+
i,
80+
color[0] / 255,
81+
color[1] / 255,
82+
color[2] / 255
83+
);
84+
85+
const segmentOpacity = (color[3] / 255) * globalOpacity;
86+
labelMap.ofun.addPointLong(i, segmentOpacity, 0.5, 1.0);
87+
}
88+
} else {
89+
// Some default.
90+
labelMap.cfun.addRGBPoint(1, 1, 0, 0); // label '1' will be red
91+
labelMap.cfun.addRGBPoint(2, 0, 1, 0); // label '2' will be green
92+
labelMap.cfun.addRGBPoint(3, 0, 1, 1); // label '3' will be blue
93+
labelMap.ofun.addPoint(1, 0.5); // All labels full opacity
94+
}
6395

6496
labelMap.actor.getProperty().setRGBTransferFunction(0, labelMap.cfun);
6597
labelMap.actor.getProperty().setScalarOpacity(0, labelMap.ofun);
98+
6699
labelMap.actor.getProperty().setInterpolationTypeToNearest();
100+
labelMap.actor.getProperty().setScalarOpacityUnitDistance(0, 0.1);
101+
labelMap.actor.getProperty().setUseGradientOpacity(0, false);
67102

68103
return labelMap;
69104
}

‎src/helpers/formatDA.js‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,12 @@ export default function formatDA(date, strFormat = 'MMM D, YYYY') {
55
return;
66
}
77

8-
const parsedDateTime = parse(date, 'YYYYMMDD');
8+
try {
9+
const parsedDateTime = parse(date, 'yyyyMMdd', new Date());
10+
const formattedDateTime = format(parsedDateTime, strFormat);
911

10-
return format(parsedDateTime, strFormat);
12+
return formattedDateTime;
13+
} catch (err) {
14+
// swallow?
15+
}
1116
}

‎src/helpers/formatTM.js‎

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,16 @@ export default function formatTM(time, strFormat = 'HH:mm:ss') {
55
return;
66
}
77

8-
// DICOM Time is stored as HHmmss.SSS, where:
9-
// HH 24 hour time:
10-
// m mm 0..59 Minutes
11-
// s ss 0..59 Seconds
12-
// S SS SSS 0..999 Fractional seconds
13-
//
14-
// See MomentJS: http://momentjs.com/docs/#/parsing/string-format/
15-
const parsedDateTime = parse(time, 'HHmmss.SSS');
8+
try {
9+
const inputFormat = 'HHmmss.SSS';
10+
const strTime = time.toString().substring(0, inputFormat.length);
11+
const parsedDateTime = parse(strTime, 'HHmmss.SSS', new Date(0));
12+
const formattedDateTime = format(parsedDateTime, strFormat);
13+
14+
return formattedDateTime;
15+
} catch (err) {
16+
// swallow?
17+
}
1618

1719
return format(parsedDateTime, strFormat);
1820
}

0 commit comments

Comments
 (0)