Skip to content

Commit

Permalink
feat(browser): use ITK's browser-based file reading API
Browse files Browse the repository at this point in the history
  • Loading branch information
thewtex committed May 29, 2017
1 parent 9de960f commit 33b752a
Showing 1 changed file with 34 additions and 45 deletions.
79 changes: 34 additions & 45 deletions src/dataHandler.js
Original file line number Diff line number Diff line change
@@ -1,57 +1,46 @@
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 vtkDataArray from 'vtk.js/Sources/Common/Core/DataArray';

import NrrdReader from 'itk/dist/itkImageIOs/itkNrrdImageIOJSBinding';
import itkreadImageFile from 'itk/dist/itkreadImageFile';

import viewer from './viewer';

function fetchZip(url) {
return vtkHttpDataAccessHelper.fetchZipFile(url);
}
const fetchZip = url => vtkHttpDataAccessHelper.fetchZipFile(url);

function processData(container, { file, ext }) {
const 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: 'volumeRenderering',
image: imageData,
itkreadImageFile(file).then((itkImage) => {
const array = {
values: itkImage.buffer,
numberOfComponents: itkImage.imageType.components,
};

const vtkImage = {
origin: [0, 0, 0],
spacing: [1, 1, 1],
};

const dimensions = [1, 1, 1];

for (let idx = 0; idx < itkImage.imageType.dimension; ++idx) {
vtkImage.origin[idx] = itkImage.origin[idx];
vtkImage.spacing[idx] = itkImage.spacing[idx];
dimensions[idx] = itkImage.size[idx];
}

// Create VTK Image Data
const imageData = vtkImageData.newInstance(vtkImage);
const scalar = vtkDataArray.newInstance(array);
imageData.setDimension(...dimensions);
imageData.getPointData().setScalars(scalar);

viewer.createViewer(container, {
type: 'volumeRenderering',
image: imageData,
});
});
}
};

export default {
fetchZip,
Expand Down

0 comments on commit 33b752a

Please sign in to comment.