Skip to content

Commit 5d71b4b

Browse files
authored
Color LUT api (#87)
fix: 🐛 Add api to change segment colors in View2D labelmap
1 parent 1ba78ef commit 5d71b4b

File tree

2 files changed

+39
-24
lines changed

2 files changed

+39
-24
lines changed

src/VTKViewport/View2D.js

Lines changed: 38 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -158,29 +158,6 @@ export default class View2D extends Component {
158158
filters = [this.paintFilter];
159159
widgets = [this.paintWidget];
160160

161-
/*
162-
TODO: Enable normal orthogonal slicing / window level as default instead of
163-
rotation tool
164-
165-
const istyle = CustomSliceInteractorStyle.newInstance();
166-
this.istyle = istyle
167-
this.renderWindow.getInteractor().setInteractorStyle(istyle)
168-
istyle.setCurrentVolumeNumber(0); // background volume
169-
istyle.setSlicingMode(1, true); // force set slice mode
170-
171-
interactor.setInteractorStyle(istyle);
172-
*/
173-
174-
/*
175-
TODO: Use for maintaining clipping range for MIP
176-
177-
const interactor = this.renderWindow.getInteractor();
178-
//const clippingRange = renderer.getActiveCamera().getClippingRange();
179-
180-
interactor.onAnimation(() => {
181-
renderer.getActiveCamera().setClippingRange(...r);
182-
});*/
183-
184161
// Set orientation based on props
185162
if (this.props.orientation) {
186163
const { orientation } = this.props;
@@ -222,6 +199,10 @@ export default class View2D extends Component {
222199
const boundAddSVGWidget = this.addSVGWidget.bind(this);
223200
const boundGetApiProperty = this.getApiProperty.bind(this);
224201
const boundSetApiProperty = this.setApiProperty.bind(this);
202+
const boundSetSegmentRGB = this.setSegmentRGB.bind(this);
203+
const boundSetSegmentRGBA = this.setSegmentRGBA.bind(this);
204+
const boundSetSegmentAlpha = this.setSegmentAlpha.bind(this);
205+
const boundUpdateImage = this.updateImage.bind(this);
225206

226207
this.svgWidgets = {};
227208

@@ -243,11 +224,15 @@ export default class View2D extends Component {
243224
actors,
244225
volumes,
245226
_component: this,
227+
updateImage: boundUpdateImage,
246228
updateVOI: boundUpdateVOI,
247229
getOrientation: boundGetOrienation,
248230
setInteractorStyle: boundSetInteractorStyle,
249231
getSlabThickness: boundGetSlabThickness,
250232
setSlabThickness: boundSetSlabThickness,
233+
setSegmentRGB: boundSetSegmentRGB,
234+
setSegmentRGBA: boundSetSegmentRGBA,
235+
setSegmentAlpha: boundSetSegmentAlpha,
251236
get: boundGetApiProperty,
252237
set: boundSetApiProperty,
253238
type: 'VIEW2D',
@@ -311,6 +296,12 @@ export default class View2D extends Component {
311296
renderWindow.render();
312297
}
313298

299+
updateImage() {
300+
const renderWindow = this.genericRenderWindow.getRenderWindow();
301+
302+
renderWindow.render();
303+
}
304+
314305
setInteractorStyle({ istyle, callbacks = {}, configuration = {} }) {
315306
const { volumes } = this.props;
316307
const renderWindow = this.genericRenderWindow.getRenderWindow();
@@ -373,6 +364,30 @@ export default class View2D extends Component {
373364
return this.props.orientation;
374365
}
375366

367+
setSegmentRGBA(segmentIndex, [red, green, blue, alpha]) {
368+
this.setSegmentRGB(segmentIndex, [red, green, blue]);
369+
this.setSegmentAlpha(segmentIndex, alpha);
370+
}
371+
372+
setSegmentRGB(segmentIndex, [red, green, blue]) {
373+
const { labelmap } = this;
374+
375+
labelmap.cfun.addRGBPoint(segmentIndex, red / 255, green / 255, blue / 255);
376+
}
377+
378+
setSegmentAlpha(segmentIndex, alpha) {
379+
const { labelmap } = this;
380+
let { globalOpacity } = this.props.labelmapRenderingOptions;
381+
382+
if (globalOpacity === undefined) {
383+
globalOpacity = 1.0;
384+
}
385+
386+
const segmentOpacity = (alpha / 255) * globalOpacity;
387+
388+
labelmap.ofun.addPoint(segmentIndex, segmentOpacity, 0.5, 1.0);
389+
}
390+
376391
componentDidUpdate(prevProps) {
377392
if (prevProps.volumes !== this.props.volumes) {
378393
this.props.volumes.forEach(volume => {

src/VTKViewport/createLabelPipeline.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ export default function createLabelPipeline(
9494

9595
// Set the opacity per label.
9696
const segmentOpacity = (color[3] / 255) * globalOpacity;
97-
labelMap.ofun.addPoint(1, segmentOpacity, 0.5, 1.0);
97+
labelMap.ofun.addPoint(i, segmentOpacity, 0.5, 1.0);
9898
}
9999
} else {
100100
// Some default.

0 commit comments

Comments
 (0)