-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathResliceRepresentation.js
More file actions
150 lines (134 loc) · 3.83 KB
/
ResliceRepresentation.js
File metadata and controls
150 lines (134 loc) · 3.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
import React from 'react';
import PropTypes from 'prop-types';
import vtkSliceRepresentation from './SliceRepresentation';
import { ViewContext, RepresentationContext, DownstreamContext } from './View';
import vtkImageResliceMapper from '@kitware/vtk.js/Rendering/Core/ImageResliceMapper.js';
import { SlabTypes } from '@kitware/vtk.js/Rendering/Core/ImageResliceMapper/Constants.js';
/**
* ResliceRepresentation is an image slice representation that allows:
* - Orthogonal slicing
* - Oblique slicing
* - Slab mode (thick slices)
* - Slice a volume using arbitary geometry
*/
export default class ResliceRepresentation extends vtkSliceRepresentation {
constructor(props) {
super(props);
// Create the vtk.js objects
this.mapper = props.mapperInstance ?? vtkImageResliceMapper.newInstance();
this.actor.setMapper(this.mapper);
this.actor.getProperty().setRGBTransferFunction(0, this.lookupTable);
// this.actor.getProperty().setScalarOpacity(0, this.piecewiseFunction);
this.actor.getProperty().setInterpolationTypeToLinear();
}
render() {
return (
<ViewContext.Consumer>
{(view) => {
if (!this.view) {
view.renderer.addActor(this.actor);
this.view = view;
}
return (
<RepresentationContext.Provider value={this}>
<DownstreamContext.Provider value={this.mapper}>
<div key={this.props.id} id={this.props.id}>
{this.props.children}
</div>
</DownstreamContext.Provider>
</RepresentationContext.Provider>
);
}}
</ViewContext.Consumer>
);
}
componentDidMount() {
this.update(this.props);
}
componentDidUpdate(prevProps, prevState, snapshot) {
this.update(this.props, prevProps);
}
componentWillUnmount() {
super.componentWillUnmount();
if (this.view && this.view.renderer) {
this.view.renderer.removeActor(this.actor);
}
}
update(props, previous) {
const {
slicePlane,
slicePolyData,
slabType,
slabThickness,
slabTrapezoidIntegration,
} = props;
let changed = false;
if (!previous || slicePlane !== previous.slicePlane) {
changed = this.mapper.setSlicePlane(slicePlane);
}
if (!previous || slicePolyData !== previous.slicePolyData) {
changed = this.mapper.setSlicePolyData(slicePolyData);
}
if (this.validData) {
if (
slabType != null &&
(!previous || slabType !== previous.slabType) &&
slabType >= SlabTypes.MIN &&
slabType <= SlabTypes.SUM
) {
changed = this.mapper.setSlabType(slabType);
}
if (
slabThickness != null &&
(!previous || slabThickness !== previous.slabThickness)
) {
changed = this.mapper.setSlabThickness(slabThickness);
}
if (
slabTrapezoidIntegration != null &&
(!previous ||
slabTrapezoidIntegration !== previous.slabTrapezoidIntegration)
) {
changed = this.mapper.setSlabTrapezoidIntegration(
slabTrapezoidIntegration
);
}
}
super.update(props, previous);
// trigger render
if (changed) {
super.dataChanged();
}
}
}
ResliceRepresentation.defaultProps = {
sliceThickness: 0.0,
slabType: SlabTypes.MEAN,
slabTrapezoidIntegration: false,
};
ResliceRepresentation.propTypes = {
/**
* Slice plane
*/
slicePlane: PropTypes.object,
/**
* Optional slice polydata
*/
slicePolyData: PropTypes.object,
/**
* Slab type
*/
slabType: PropTypes.number,
/**
* Slab thickness
*/
slabThickness: PropTypes.number,
/**
* Slab trapezoid integration
*/
slabTrapezoidIntegration: PropTypes.bool,
children: PropTypes.oneOfType([
PropTypes.arrayOf(PropTypes.node),
PropTypes.node,
]),
};