-
-
Notifications
You must be signed in to change notification settings - Fork 383
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(ITKHelper): Add ITK to VTK js image converter
- Loading branch information
Showing
2 changed files
with
32 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import vtkImageData from 'vtk.js/Sources/Common/DataModel/ImageData'; | ||
import vtkDataArray from 'vtk.js/Sources/Common/Core/DataArray'; | ||
|
||
/** | ||
* Converts an itk.js image to a vtk.js image. | ||
* | ||
* Requires an itk.js image as input. | ||
*/ | ||
function convertItkToVtkImage(itkImage) { | ||
// create VTK image data | ||
const imageData = vtkImageData.newInstance({ | ||
origin: itkImage.origin.slice(), | ||
spacing: itkImage.spacing.slice(), | ||
}); | ||
const scalars = vtkDataArray.newInstance({ | ||
name: 'Scalars', | ||
values: itkImage.data, | ||
numberOfComponents: itkImage.imageType.components, | ||
}); | ||
|
||
imageData.setDirection(itkImage.direction.data); | ||
imageData.setDimensions(...itkImage.size); | ||
imageData.getPointData().setScalars(scalars); | ||
|
||
return imageData; | ||
} | ||
|
||
export default { | ||
convertItkToVtkImage, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters