Skip to content

Commit 98c1c27

Browse files
committed
docs(usage): add simple RemoveImageData test
1 parent 2e84f19 commit 98c1c27

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed

usage/src/App.jsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ const demos = new Map([
4040
'Tests/SimpleSliceRendering',
4141
lazy(() => import('./Tests/SimpleSliceRendering')),
4242
],
43+
['Tests/RemoveImageData', lazy(() => import('./Tests/RemoveImageData'))],
4344
[
4445
'Tests/ChangeInteractorStyle',
4546
lazy(() => import('./Tests/ChangeInteractorStyle')),
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import { useState } from 'react';
2+
import {
3+
DataArray,
4+
ImageData,
5+
PointData,
6+
SliceRepresentation,
7+
View,
8+
} from 'react-vtk-js';
9+
10+
function generateRandomVolumeField(iMax, jMax, kMax) {
11+
const array = [];
12+
for (let k = 0; k < kMax; k++) {
13+
for (let j = 0; j < jMax; j++) {
14+
for (let i = 0; i < iMax; i++) {
15+
array.push(Math.random());
16+
}
17+
}
18+
}
19+
return array;
20+
}
21+
22+
const VALUES = generateRandomVolumeField(10, 10, 10);
23+
24+
function Example() {
25+
const [showImage, setShowImage] = useState(true);
26+
27+
const removeImage = () => {
28+
setShowImage(false);
29+
};
30+
31+
const im = showImage ? (
32+
<ImageData spacing={[1, 1, 1]} dimensions={[10, 10, 10]} origin={[0, 0, 0]}>
33+
<PointData>
34+
<DataArray
35+
registration='setScalars'
36+
type='Float32Array'
37+
values={VALUES}
38+
/>
39+
</PointData>
40+
</ImageData>
41+
) : null;
42+
43+
return (
44+
<div style={{ width: '100%', height: '100%', position: 'relative' }}>
45+
<View>
46+
<SliceRepresentation
47+
iSlice={8}
48+
property={{ colorWindow: 1, colorLevel: 0.5 }}
49+
>
50+
{im}
51+
</SliceRepresentation>
52+
</View>
53+
<div style={{ position: 'absolute', top: 0 }}>
54+
<button onClick={removeImage}>Remove Image</button>
55+
</div>
56+
</div>
57+
);
58+
}
59+
60+
export default Example;

0 commit comments

Comments
 (0)