|
1 | 1 | import vtkHttpDataAccessHelper from 'vtk.js/Sources/IO/Core/DataAccessHelper/HttpDataAccessHelper';
|
2 | 2 | import vtkImageData from 'vtk.js/Sources/Common/DataModel/ImageData';
|
3 |
| -import vtkDataArray from 'vtk.js/Sources/Common/Core/ImageData'; |
| 3 | +import vtkDataArray from 'vtk.js/Sources/Common/Core/DataArray'; |
4 | 4 |
|
5 |
| -import NrrdReader from 'itk/dist/itkImageIOs/itkNrrdImageIOJSBinding'; |
| 5 | +import itkreadImageFile from 'itk/dist/itkreadImageFile'; |
6 | 6 |
|
7 | 7 | import viewer from './viewer';
|
8 | 8 |
|
9 |
| -function fetchZip(url) { |
10 |
| - return vtkHttpDataAccessHelper.fetchZipFile(url); |
11 |
| -} |
| 9 | +const fetchZip = url => vtkHttpDataAccessHelper.fetchZipFile(url); |
12 | 10 |
|
13 |
| -function processData(container, { file, ext }) { |
| 11 | +const processData = (container, { file, ext }) => { |
14 | 12 | /* eslint-disable new-cap */
|
15 |
| - // FIXME -------------------------------------------------------------------- |
16 |
| - const filePath = ''; |
17 |
| - NrrdReader.mountContainingDirectory(filePath); |
18 |
| - |
19 |
| - const reader = new NrrdReader.ITKImageIO(); |
20 |
| - reader.SetFileName(filePath); |
21 |
| - // reader.SetFileContent(file); // <--- Something like that for web |
22 |
| - reader.ReadImageInformation(); |
23 |
| - |
24 |
| - const array = { |
25 |
| - values: reader.Read(), |
26 |
| - numberOfComponents: reader.GetNumberOfComponents(), |
27 |
| - }; |
28 |
| - |
29 |
| - const image = { |
30 |
| - origin: [0, 0, 0], |
31 |
| - spacing: [1, 1, 1], |
32 |
| - }; |
33 |
| - |
34 |
| - const dimensions = [1, 1, 1]; |
35 |
| - |
36 |
| - for (let idx = 0; idx < reader.GetNumberOfDimensions(); idx++) { |
37 |
| - image.origin[idx] = reader.GetOrigin(idx); |
38 |
| - image.spacing[idx] = reader.GetSpacing(idx); |
39 |
| - dimensions[idx] = reader.GetDimensions(idx); |
40 |
| - } |
41 |
| - NrrdReader.unmountContainingDirectory(filePath); |
42 |
| - |
43 |
| - // Create VTK Image Data |
44 |
| - const imageData = vtkImageData.newInstance(image); |
45 |
| - const scalar = vtkDataArray.newInstance(array); |
46 |
| - imageData.setDimension(...dimensions); |
47 |
| - imageData.getPointData().setScalars(scalar); |
48 |
| - // FIXME -------------------------------------------------------------------- |
49 |
| - |
50 |
| - viewer.createViewer(container, { |
51 |
| - type: 'volumeRenderering', |
52 |
| - image: imageData, |
| 13 | + itkreadImageFile(file).then((itkImage) => { |
| 14 | + const array = { |
| 15 | + values: itkImage.buffer, |
| 16 | + numberOfComponents: itkImage.imageType.components, |
| 17 | + }; |
| 18 | + |
| 19 | + const vtkImage = { |
| 20 | + origin: [0, 0, 0], |
| 21 | + spacing: [1, 1, 1], |
| 22 | + }; |
| 23 | + |
| 24 | + const dimensions = [1, 1, 1]; |
| 25 | + |
| 26 | + for (let idx = 0; idx < itkImage.imageType.dimension; ++idx) { |
| 27 | + vtkImage.origin[idx] = itkImage.origin[idx]; |
| 28 | + vtkImage.spacing[idx] = itkImage.spacing[idx]; |
| 29 | + dimensions[idx] = itkImage.size[idx]; |
| 30 | + } |
| 31 | + |
| 32 | + // Create VTK Image Data |
| 33 | + const imageData = vtkImageData.newInstance(vtkImage); |
| 34 | + const scalar = vtkDataArray.newInstance(array); |
| 35 | + imageData.setDimension(...dimensions); |
| 36 | + imageData.getPointData().setScalars(scalar); |
| 37 | + |
| 38 | + viewer.createViewer(container, { |
| 39 | + type: 'volumeRenderering', |
| 40 | + image: imageData, |
| 41 | + }); |
53 | 42 | });
|
54 |
| -} |
| 43 | +}; |
55 | 44 |
|
56 | 45 | export default {
|
57 | 46 | fetchZip,
|
|
0 commit comments