@@ -33,9 +33,9 @@ export default class SliceRepresentation extends Component {
33
33
this . lookupTable . applyColorMap ( preset ) ;
34
34
this . piecewiseFunction = vtkPiecewiseFunction . newInstance ( ) ;
35
35
this . actor = vtkImageSlice . newInstance ( { visibility : false } ) ;
36
- this . mapper = vtkImageMapper . newInstance ( ) ;
36
+ // use the mapper instance if provided, otherwise create default instance.
37
+ this . mapper = props . mapperInstance ?? vtkImageMapper . newInstance ( ) ;
37
38
this . actor . setMapper ( this . mapper ) ;
38
-
39
39
this . actor . getProperty ( ) . setRGBTransferFunction ( 0 , this . lookupTable ) ;
40
40
// this.actor.getProperty().setScalarOpacity(0, this.piecewiseFunction);
41
41
this . actor . getProperty ( ) . setInterpolationTypeToLinear ( ) ;
@@ -105,7 +105,11 @@ export default class SliceRepresentation extends Component {
105
105
if ( property && ( ! previous || property !== previous . property ) ) {
106
106
changed = this . actor . getProperty ( ) . set ( property ) || changed ;
107
107
}
108
- if ( mapper && ( ! previous || mapper !== previous . mapper ) ) {
108
+ if (
109
+ mapper &&
110
+ ( ! previous || mapper !== previous . mapper ) &&
111
+ mapper !== this . mapper
112
+ ) {
109
113
changed = this . mapper . set ( mapper ) || changed ;
110
114
}
111
115
if (
@@ -146,25 +150,35 @@ export default class SliceRepresentation extends Component {
146
150
}
147
151
}
148
152
149
- // ijk
150
- if ( iSlice != null && ( ! previous || iSlice !== previous . iSlice ) ) {
151
- changed = this . mapper . setISlice ( iSlice ) || changed ;
152
- }
153
- if ( jSlice != null && ( ! previous || jSlice !== previous . jSlice ) ) {
154
- changed = this . mapper . setJSlice ( jSlice ) || changed ;
155
- }
156
- if ( kSlice != null && ( ! previous || kSlice !== previous . kSlice ) ) {
157
- changed = this . mapper . setKSlice ( kSlice ) || changed ;
158
- }
159
- // xyz
160
- if ( xSlice != null && ( ! previous || xSlice !== previous . xSlice ) ) {
161
- changed = this . mapper . setXSlice ( xSlice ) || changed ;
162
- }
163
- if ( ySlice != null && ( ! previous || ySlice !== previous . ySlice ) ) {
164
- changed = this . mapper . setYSlice ( ySlice ) || changed ;
165
- }
166
- if ( zSlice != null && ( ! previous || zSlice !== previous . zSlice ) ) {
167
- changed = this . mapper . setZSlice ( zSlice ) || changed ;
153
+ // check if we have valid input
154
+ if ( this . validData ) {
155
+ if ( this . mapper . isA ( 'vtkImageMapper' ) ) {
156
+ // ijk
157
+ if ( iSlice != null && ( ! previous || iSlice !== previous . iSlice ) ) {
158
+ changed = this . mapper . setISlice ( iSlice ) || changed ;
159
+ }
160
+ if ( jSlice != null && ( ! previous || jSlice !== previous . jSlice ) ) {
161
+ changed = this . mapper . setJSlice ( jSlice ) || changed ;
162
+ }
163
+ if ( kSlice != null && ( ! previous || kSlice !== previous . kSlice ) ) {
164
+ changed = this . mapper . setKSlice ( kSlice ) || changed ;
165
+ }
166
+ // xyz
167
+ if ( xSlice != null && ( ! previous || xSlice !== previous . xSlice ) ) {
168
+ changed = this . mapper . setXSlice ( xSlice ) || changed ;
169
+ }
170
+ if ( ySlice != null && ( ! previous || ySlice !== previous . ySlice ) ) {
171
+ changed = this . mapper . setYSlice ( ySlice ) || changed ;
172
+ }
173
+ if ( zSlice != null && ( ! previous || zSlice !== previous . zSlice ) ) {
174
+ changed = this . mapper . setZSlice ( zSlice ) || changed ;
175
+ }
176
+ } else if ( this . mapper . isA ( 'vtkImageArrayMapper' ) ) {
177
+ // vtkImageArrayMapper only supports k-slicing
178
+ if ( kSlice != null && ( ! previous || kSlice !== previous . kSlice ) ) {
179
+ changed = this . mapper . setSlice ( kSlice ) || changed ;
180
+ }
181
+ }
168
182
}
169
183
170
184
// actor visibility
@@ -186,6 +200,11 @@ export default class SliceRepresentation extends Component {
186
200
this . validData = true ;
187
201
this . actor . setVisibility ( this . currentVisibility ) ;
188
202
203
+ // reset camera after input data is lazy-loaded
204
+ if ( this . view && this . view . props . autoResetCamera ) {
205
+ this . view . resetCamera ( ) ;
206
+ }
207
+
189
208
// trigger render
190
209
this . dataChanged ( ) ;
191
210
}
@@ -194,16 +213,18 @@ export default class SliceRepresentation extends Component {
194
213
dataChanged ( ) {
195
214
if ( this . props . colorDataRange === 'auto' ) {
196
215
this . mapper . update ( ) ;
197
- const input = this . mapper . getInputData ( ) ;
198
- const array = input && input . getPointData ( ) ?. getScalars ( ) ;
199
- const dataRange = array && array . getRange ( ) ;
200
- if ( dataRange ) {
201
- this . lookupTable . setMappingRange ( ...dataRange ) ;
202
- this . lookupTable . updateRange ( ) ;
203
- this . piecewiseFunction . setNodes ( [
204
- { x : dataRange [ 0 ] , y : 0 , midpoint : 0.5 , sharpness : 0 } ,
205
- { x : dataRange [ 1 ] , y : 1 , midpoint : 0.5 , sharpness : 0 } ,
206
- ] ) ;
216
+ if ( this . mapper . getInputData ( ) ) {
217
+ const input = this . mapper . getCurrentImage ( ) ;
218
+ const array = input && input . getPointData ( ) ?. getScalars ( ) ;
219
+ const dataRange = array && array . getRange ( ) ;
220
+ if ( dataRange ) {
221
+ this . lookupTable . setMappingRange ( ...dataRange ) ;
222
+ this . lookupTable . updateRange ( ) ;
223
+ this . piecewiseFunction . setNodes ( [
224
+ { x : dataRange [ 0 ] , y : 0 , midpoint : 0.5 , sharpness : 0 } ,
225
+ { x : dataRange [ 1 ] , y : 1 , midpoint : 0.5 , sharpness : 0 } ,
226
+ ] ) ;
227
+ }
207
228
}
208
229
209
230
if ( this . view ) {
@@ -229,6 +250,12 @@ SliceRepresentation.propTypes = {
229
250
*/
230
251
mapper : PropTypes . object ,
231
252
253
+ /**
254
+ * Optional parameter to set vtk mapper instance from outside.
255
+ * Allows to control which mapper class {vtkImageMapper, vtkImageArrayMapper} to use.
256
+ */
257
+ mapperInstance : PropTypes . object ,
258
+
232
259
/**
233
260
* Properties to set to the slice/actor
234
261
*/
0 commit comments