diff --git a/package.json b/package.json index 774e0755..296bb886 100644 --- a/package.json +++ b/package.json @@ -22,6 +22,7 @@ "kw-web-suite": "2.2.1", "kw-doc": "1.0.20", "vtk.js": "2.24.1", + "itk": "1.0.1", "babel-polyfill": "6.13.0", "normalize.css": "5.0.0" diff --git a/src/dataHandler.js b/src/dataHandler.js index 6e1580e7..32d4e314 100644 --- a/src/dataHandler.js +++ b/src/dataHandler.js @@ -1,4 +1,8 @@ import vtkHttpDataAccessHelper from 'vtk.js/Sources/IO/Core/DataAccessHelper/HttpDataAccessHelper'; +import vtkImageData from 'vtk.js/Sources/Common/DataModel/ImageData'; +import vtkDataArray from 'vtk.js/Sources/Common/Core/ImageData'; + +import NrrdReader from 'itk/dist/itkImageIOs/itkNrrdImageIOJSBinding'; import viewer from './viewer'; @@ -7,10 +11,45 @@ function fetchZip(url) { } function processData(container, { file, ext }) { + /* eslint-disable new-cap */ + // FIXME -------------------------------------------------------------------- + const filePath = ''; + NrrdReader.mountContainingDirectory(filePath); + + const reader = new NrrdReader.ITKImageIO(); + reader.SetFileName(filePath); + // reader.SetFileContent(file); // <--- Something like that for web + reader.ReadImageInformation(); + + const array = { + values: reader.Read(), + numberOfComponents: reader.GetNumberOfComponents(), + }; + + const image = { + origin: [0, 0, 0], + spacing: [1, 1, 1], + }; + + const dimensions = [1, 1, 1]; + + for (let idx = 0; idx < reader.GetNumberOfDimensions(); idx++) { + image.origin[idx] = reader.GetOrigin(idx); + image.spacing[idx] = reader.GetSpacing(idx); + dimensions[idx] = reader.GetDimensions(idx); + } + NrrdReader.unmountContainingDirectory(filePath); + + // Create VTK Image Data + const imageData = vtkImageData.newInstance(image); + const scalar = vtkDataArray.newInstance(array); + imageData.setDimension(...dimensions); + imageData.getPointData().setScalars(scalar); + // FIXME -------------------------------------------------------------------- + viewer.createViewer(container, { - type: 'rawFile', - file, - ext, + type: 'volumeRenderering', + image: imageData, }); }