Skip to content

Commit

Permalink
Start interface with ITK
Browse files Browse the repository at this point in the history
  • Loading branch information
jourdain committed May 26, 2017
1 parent 3fd12d2 commit 9de960f
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 3 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
45 changes: 42 additions & 3 deletions src/dataHandler.js
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -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,
});
}

Expand Down

0 comments on commit 9de960f

Please sign in to comment.