File tree Expand file tree Collapse file tree 2 files changed +32
-0
lines changed
Expand file tree Collapse file tree 2 files changed +32
-0
lines changed Original file line number Diff line number Diff line change 1+ import vtkImageData from 'vtk.js/Sources/Common/DataModel/ImageData' ;
2+ import vtkDataArray from 'vtk.js/Sources/Common/Core/DataArray' ;
3+
4+ /**
5+ * Converts an itk.js image to a vtk.js image.
6+ *
7+ * Requires an itk.js image as input.
8+ */
9+ function convertItkToVtkImage ( itkImage ) {
10+ // create VTK image data
11+ const imageData = vtkImageData . newInstance ( {
12+ origin : itkImage . origin . slice ( ) ,
13+ spacing : itkImage . spacing . slice ( ) ,
14+ } ) ;
15+ const scalars = vtkDataArray . newInstance ( {
16+ name : 'Scalars' ,
17+ values : itkImage . data ,
18+ numberOfComponents : itkImage . imageType . components ,
19+ } ) ;
20+
21+ imageData . setDirection ( itkImage . direction . data ) ;
22+ imageData . setDimensions ( ...itkImage . size ) ;
23+ imageData . getPointData ( ) . setScalars ( scalars ) ;
24+
25+ return imageData ;
26+ }
27+
28+ export default {
29+ convertItkToVtkImage,
30+ } ;
Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ import vtkCone from './Cone';
55import vtkCylinder from './Cylinder' ;
66import vtkDataSet from './DataSet' ;
77import vtkDataSetAttributes from './DataSetAttributes' ;
8+ import vtkITKHelper from './ITKHelper' ;
89import vtkImageData from './ImageData' ;
910import vtkImplicitBoolean from './ImplicitBoolean' ;
1011import vtkLine from './Line' ;
@@ -25,6 +26,7 @@ export default {
2526 vtkCylinder,
2627 vtkDataSet,
2728 vtkDataSetAttributes,
29+ vtkITKHelper,
2830 vtkImageData,
2931 vtkImplicitBoolean,
3032 vtkLine,
You can’t perform that action at this time.
0 commit comments