11import React , { useState , useContext } from 'react' ;
22import vtkColorMaps from '@kitware/vtk.js/Rendering/Core/ColorTransferFunction/ColorMaps.js' ;
33import { SlabTypes } from '@kitware/vtk.js/Rendering/Core/ImageResliceMapper/Constants.js' ;
4+ import { InterpolationType } from '@kitware/vtk.js/Rendering/Core/ImageProperty/Constants.js' ;
5+ import { newInstance as newVtkCylinderInstance } from '@kitware/vtk.js/Filters/Sources/CylinderSource.js' ;
6+ import { newInstance as newVtkPlaneInstance } from '@kitware/vtk.js/Common/DataModel/Plane.js' ;
47
58import {
69 View ,
@@ -12,6 +15,18 @@ import {
1215 VolumeRepresentation ,
1316} from 'react-vtk-js' ;
1417
18+ const plane = newVtkPlaneInstance ( {
19+ origin : [ 127 , 0 , 0 ] ,
20+ normal : [ 1 , 0 , 0 ] ,
21+ } ) ;
22+ const cyl = newVtkCylinderInstance ( {
23+ height : 255 ,
24+ radius : 50 ,
25+ resolution : 20 ,
26+ capping : 1 ,
27+ center : [ 127 , 127 , 94 ] ,
28+ } ) ;
29+
1530function Slider ( props ) {
1631 const view = useContext ( Contexts . ViewContext ) ;
1732 const onChange = ( e ) => {
@@ -50,16 +65,13 @@ function Slider(props) {
5065
5166function DropDown ( props ) {
5267 const view = useContext ( Contexts . ViewContext ) ;
53- console . log ( props . options ) ;
5468 function onChange ( e ) {
5569 const value = e . currentTarget . value ;
5670 props . setValue ( value ) ;
5771 setTimeout ( view . renderView , 0 ) ;
5872 }
5973 return (
60- < select
61- value = { props . value }
62- onChange = { onChange }
74+ < label
6375 style = { {
6476 position : 'absolute' ,
6577 zIndex : 100 ,
@@ -68,19 +80,30 @@ function DropDown(props) {
6880 ...props . style ,
6981 } }
7082 >
71- { props . options . map ( ( opt ) => (
72- < option key = { opt } value = { opt } >
73- { opt }
74- </ option >
75- ) ) }
76- </ select >
83+ { props . label }
84+ < select
85+ value = { props . value }
86+ onChange = { onChange }
87+ style = { {
88+ position : 'sticky' ,
89+ zIndex : 100 ,
90+ ...props . style ,
91+ } }
92+ >
93+ { props . options . map ( ( opt ) => (
94+ < option key = { opt } value = { opt } >
95+ { opt }
96+ </ option >
97+ ) ) }
98+ </ select >
99+ </ label >
77100 ) ;
78101}
79102
80103function EnumDropDown ( props ) {
81104 const view = useContext ( Contexts . ViewContext ) ;
82105 function onChange ( e ) {
83- const value = e . currentTarget . value ;
106+ const value = parseInt ( e . currentTarget . value ) ;
84107 props . setValue ( value ) ;
85108 setTimeout ( view . renderView , 0 ) ;
86109 }
@@ -103,8 +126,6 @@ function EnumDropDown(props) {
103126 style = { {
104127 position : 'sticky' ,
105128 zIndex : 100 ,
106- // left: '15px',
107- // top: '5px',
108129 ...props . style ,
109130 } }
110131 >
@@ -153,18 +174,73 @@ function CheckBox(props) {
153174 ) ;
154175}
155176
177+ function SliceFunction ( props ) {
178+ const view = useContext ( Contexts . ViewContext ) ;
179+ function onChange ( e ) {
180+ const value = e . currentTarget . checked ;
181+ if ( value ) {
182+ // Using a slice polydata
183+ cyl . update ( ) ;
184+ props . setSlicePolyData ( cyl . getOutputData ( ) ) ;
185+ } else {
186+ // plane.update();
187+ // props.setSlicePolyData(plane.getOutputData());
188+ props . setSlicePolyData ( null ) ;
189+ props . setSlicePlane ( plane ) ;
190+ }
191+ props . setValue ( value ) ;
192+ setTimeout ( view . renderView , 0 ) ;
193+ setTimeout ( view . resetCamera , 0 ) ;
194+ }
195+ return (
196+ < label
197+ style = { {
198+ position : 'absolute' ,
199+ zIndex : 100 ,
200+ left : '5px' ,
201+ top : '55px' ,
202+ ...props . style ,
203+ } }
204+ >
205+ { props . label }
206+ < input
207+ type = 'checkbox'
208+ checked = { props . value }
209+ onChange = { onChange }
210+ style = { {
211+ position : 'sticky' ,
212+ zIndex : 100 ,
213+ left : '105px' ,
214+ ...props . style ,
215+ } }
216+ />
217+ </ label >
218+ ) ;
219+ }
220+
221+ function PosSlider ( props ) {
222+ const s = Slider ( props ) ;
223+ plane . setOrigin ( props . value , 0 , 0 ) ;
224+ return s ;
225+ }
226+
156227function Example ( props ) {
157- const [ iSlice , setISlice ] = useState ( 128 ) ;
158- const [ jSlice , setJSlice ] = useState ( 128 ) ;
159- const [ kSlice , setKSlice ] = useState ( 47 ) ;
160228 const [ slabThickness , setSlabThickness ] = useState ( 0 ) ;
161229 const [ slabType , setSlabType ] = useState ( SlabTypes . MAX ) ;
162- const [ slabTrapezoidIntegration , setSlabTrapezoidIntegration ] = useState ( false ) ;
230+ const [ interpolationType , setInterpolationType ] = useState (
231+ InterpolationType . LINEAR
232+ ) ;
233+ const [ slabTrapezoidIntegration , setSlabTrapezoidIntegration ] =
234+ useState ( false ) ;
163235 const [ colorWindow , setColorWindow ] = useState ( 2095 ) ;
164236 const [ colorLevel , setColorLevel ] = useState ( 1000 ) ;
165237 const [ colorPreset , setColorPreset ] = useState ( 'Grayscale' ) ;
166238 const [ useLookupTableScalarRange , setUseLookupTableScalarRange ] =
167239 useState ( false ) ;
240+ const [ usePolyData , setUsePolyData ] = useState ( false ) ;
241+ const [ slicePolyData , setSlicePolyData ] = useState ( null ) ;
242+ const [ slicePlane , setSlicePlane ] = useState ( plane ) ;
243+ const [ slicePos , setSlicePos ] = useState ( 127 ) ;
168244 return (
169245 < div style = { { width : '100%' , height : '100%' } } >
170246 < div style = { { width : '50vw' , height : '100%' , display : 'inline-block' } } >
@@ -173,35 +249,14 @@ function Example(props) {
173249 cameraPosition = { [ 1 , 0 , 0 ] }
174250 cameraViewUp = { [ 0 , 0 , - 1 ] }
175251 cameraParallelProjection = { false }
176- background = { [ 1 , 1 , 1 ] }
252+ background = { [ 0.34 , 0.35 , 0.34 ] }
177253 >
178254 < ShareDataSet >
179255 < Reader
180256 vtkClass = 'vtkXMLImageDataReader'
181257 url = 'https://data.kitware.com/api/v1/item/59e12e988d777f31ac6455c5/download'
182258 />
183259 </ ShareDataSet >
184- < Slider
185- label = 'iSlice'
186- max = { 256 }
187- value = { iSlice }
188- setValue = { setISlice }
189- style = { { left : '5px' } }
190- />
191- < Slider
192- label = 'jSlice'
193- max = { 256 }
194- value = { jSlice }
195- setValue = { setJSlice }
196- style = { { left : '255px' } }
197- />
198- < Slider
199- label = 'kSlice'
200- max = { 95 }
201- value = { kSlice }
202- setValue = { setKSlice }
203- style = { { left : '505px' } }
204- />
205260 < Slider
206261 label = 'colorLevel'
207262 max = { 4095 }
@@ -214,12 +269,29 @@ function Example(props) {
214269 max = { 4095 }
215270 value = { colorWindow }
216271 setValue = { setColorWindow }
272+ style = { { top : '30px' , left : '255px' } }
273+ />
274+ < EnumDropDown
275+ options = { {
276+ Linear : InterpolationType . LINEAR ,
277+ Nearest : InterpolationType . NEAREST ,
278+ } }
279+ label = 'interpolationType'
280+ value = { interpolationType }
281+ setValue = { setInterpolationType }
217282 style = { { top : '30px' , left : '505px' } }
218283 />
219284 < DropDown
285+ label = 'lookupTable'
220286 options = { vtkColorMaps . rgbPresetNames }
221287 value = { colorPreset }
222288 setValue = { setColorPreset }
289+ style = { { top : '60px' , left : '5px' } }
290+ />
291+ < CheckBox
292+ label = 'useLookupTableScalarRange'
293+ value = { useLookupTableScalarRange }
294+ setValue = { setUseLookupTableScalarRange }
223295 style = { { top : '60px' , left : '505px' } }
224296 />
225297 < Slider
@@ -245,23 +317,35 @@ function Example(props) {
245317 label = 'slabTrapezoidIntegration'
246318 value = { slabTrapezoidIntegration }
247319 setValue = { setSlabTrapezoidIntegration }
248- style = { { top : '60px ' , left : '5px ' } }
320+ style = { { top : '90px ' , left : '505px ' } }
249321 />
250- < CheckBox
251- label = 'useLookupTableScalarRange'
252- value = { useLookupTableScalarRange }
253- setValue = { setUseLookupTableScalarRange }
254- style = { { top : '60px' , left : '5px' } }
322+ < SliceFunction
323+ label = 'SliceFunction'
324+ value = { usePolyData }
325+ setValue = { setUsePolyData }
326+ setSlicePolyData = { setSlicePolyData }
327+ setSlicePlane = { setSlicePlane }
328+ style = { { top : '5px' , left : '5px' } }
329+ />
330+ < PosSlider
331+ label = 'slicePosition'
332+ max = { 255 }
333+ value = { slicePos }
334+ setValue = { setSlicePos }
335+ // setSlicePolyData={setSlicePolyData}
336+ style = { { top : '5px' , left : '255px' } }
255337 />
256338 < ResliceRepresentation
257339 slabThickness = { slabThickness }
258340 slabType = { slabType }
259341 slabTrapezoidIntegration = { slabTrapezoidIntegration }
260- jSlice = { jSlice }
342+ slicePolyData = { slicePolyData }
343+ slicePlane = { slicePlane }
261344 property = { {
262345 colorWindow,
263346 colorLevel,
264347 useLookupTableScalarRange,
348+ interpolationType,
265349 } }
266350 colorMapPreset = { colorPreset }
267351 >
0 commit comments