1
- import cornerstone from 'cornerstone-core' ;
2
-
3
- // insert the slice at the z index location.
1
+ /**
2
+ *
3
+ * @param {Object } imageData - The vtkImageData
4
+ * @param {* } sliceIndex - The index of the slice you are inserting.
5
+ * @param {* } acquistionDirection - The acquistion direction of the slice.
6
+ * @param {* } image The cornerstone image to pull pixel data data from.
7
+ * @param {* } modality The modality of the image.
8
+ * @param {* } modalitySpecificScalingParameters Specific scaling paramaters for this modality. E.g. Patient weight.
9
+ */
4
10
export default function insertSlice (
5
11
imageData ,
6
12
sliceIndex ,
13
+ acquistionDirection ,
7
14
image ,
8
15
modality ,
9
16
modalitySpecificScalingParameters
10
17
) {
11
- const pixels = image . getPixelData ( ) ;
12
- const { rows, columns } = image ;
13
18
const scalars = imageData . getPointData ( ) . getScalars ( ) ;
14
19
const scalarData = scalars . getData ( ) ;
15
- const sliceLength = pixels . length ;
16
- let pixelIndex = 0 ;
17
20
18
21
const scalingFunction = _getScalingFunction (
19
22
modality ,
20
23
image ,
21
24
modalitySpecificScalingParameters
22
25
) ;
23
26
27
+ const vtkImageDimensions = imageData . getDimensions ( ) ;
28
+
29
+ let minAndMax ;
30
+
31
+ switch ( acquistionDirection ) {
32
+ case 'coronal' :
33
+ minAndMax = insertCoronalSlice (
34
+ image ,
35
+ sliceIndex ,
36
+ vtkImageDimensions ,
37
+ scalarData ,
38
+ scalingFunction
39
+ ) ;
40
+ break ;
41
+ case 'sagittal' :
42
+ minAndMax = insertSagittalSlice (
43
+ image ,
44
+ sliceIndex ,
45
+ vtkImageDimensions ,
46
+ scalarData ,
47
+ scalingFunction
48
+ ) ;
49
+ break ;
50
+ case 'axial' :
51
+ minAndMax = insertAxialSlice (
52
+ image ,
53
+ sliceIndex ,
54
+ scalarData ,
55
+ scalingFunction
56
+ ) ;
57
+ break ;
58
+ }
59
+
60
+ return minAndMax ;
61
+ }
62
+
63
+ /**
64
+ *
65
+ * @param {object } image The cornerstone image to pull pixel data data from.
66
+ * @param {number } xIndex The x index of axially oriented vtk volume to put the sagital slice.
67
+ * @param {number[] } vtkImageDimensions The dimensions of the axially oriented vtk volume.
68
+ * @param {number[] } scalarData The data array for the axially oriented vtk volume.
69
+ * @param {function } scalingFunction The modality specific scaling function.
70
+ *
71
+ * @returns {object } The min and max pixel values in the inserted slice.
72
+ */
73
+ function insertSagittalSlice (
74
+ image ,
75
+ xIndex ,
76
+ vtkImageDimensions ,
77
+ scalarData ,
78
+ scalingFunction
79
+ ) {
80
+ const pixels = image . getPixelData ( ) ;
81
+ const { rows, columns } = image ;
82
+
83
+ let pixelIndex = 0 ;
84
+ let max = scalingFunction ( pixels [ pixelIndex ] ) ;
85
+ let min = max ;
86
+
87
+ const vtkImageDimensionsX = vtkImageDimensions [ 0 ] ;
88
+ const vtkImageDimensionsY = vtkImageDimensions [ 1 ] ;
89
+ const vtkImageDimensionsZ = vtkImageDimensions [ 2 ] ;
90
+
91
+ const axialSliceLength = vtkImageDimensionsX * vtkImageDimensionsY ;
92
+
93
+ for ( let row = 0 ; row < rows ; row ++ ) {
94
+ for ( let col = 0 ; col < columns ; col ++ ) {
95
+ const yPos = vtkImageDimensionsY - col ;
96
+ const zPos = vtkImageDimensionsZ - row ;
97
+
98
+ const destIdx =
99
+ zPos * axialSliceLength + yPos * vtkImageDimensionsX + xIndex ;
100
+
101
+ const pixel = pixels [ pixelIndex ] ;
102
+ const pixelValue = scalingFunction ( pixel ) ;
103
+
104
+ if ( pixelValue > max ) {
105
+ max = pixelValue ;
106
+ } else if ( pixelValue < min ) {
107
+ min = pixelValue ;
108
+ }
109
+
110
+ scalarData [ destIdx ] = pixelValue ;
111
+ pixelIndex ++ ;
112
+ }
113
+ }
114
+
115
+ return { min, max } ;
116
+ }
117
+
118
+ /**
119
+ *
120
+ * @param {object } image The cornerstone image to pull pixel data data from.
121
+ * @param {number } yIndex The y index of axially oriented vtk volume to put the coronal slice.
122
+ * @param {number[] } vtkImageDimensions The dimensions of the axially oriented vtk volume.
123
+ * @param {number[] } scalarData The data array for the axially oriented vtk volume.
124
+ * @param {function } scalingFunction The modality specific scaling function.
125
+ *
126
+ * @returns {object } The min and max pixel values in the inserted slice.
127
+ */
128
+ function insertCoronalSlice (
129
+ image ,
130
+ yIndex ,
131
+ vtkImageDimensions ,
132
+ scalarData ,
133
+ scalingFunction
134
+ ) {
135
+ const pixels = image . getPixelData ( ) ;
136
+ const { rows, columns } = image ;
137
+
138
+ let pixelIndex = 0 ;
24
139
let max = scalingFunction ( pixels [ pixelIndex ] ) ;
25
140
let min = max ;
26
141
27
- for ( let row = 0 ; row <= rows ; row ++ ) {
28
- for ( let col = 0 ; col <= columns ; col ++ ) {
29
- const destIdx = pixelIndex + sliceIndex * sliceLength ;
142
+ const vtkImageDimensionsX = vtkImageDimensions [ 0 ] ;
143
+ const vtkImageDimensionsY = vtkImageDimensions [ 1 ] ;
144
+ const vtkImageDimensionsZ = vtkImageDimensions [ 2 ] ;
145
+
146
+ const axialSliceLength = vtkImageDimensionsX * vtkImageDimensionsY ;
147
+
148
+ for ( let row = 0 ; row < rows ; row ++ ) {
149
+ for ( let col = 0 ; col < columns ; col ++ ) {
150
+ const xPos = col ;
151
+ const yPos = yIndex ;
152
+ const zPos = vtkImageDimensionsZ - row ;
153
+
154
+ const destIdx =
155
+ zPos * axialSliceLength + yPos * vtkImageDimensionsX + xPos ;
156
+
30
157
const pixel = pixels [ pixelIndex ] ;
31
158
const pixelValue = scalingFunction ( pixel ) ;
32
159
@@ -44,6 +171,40 @@ export default function insertSlice(
44
171
return { min, max } ;
45
172
}
46
173
174
+ /**
175
+ *
176
+ * @param {object } image The cornerstone image to pull pixel data data from.
177
+ * @param {number } zIndex The z index of axially oriented vtk volume to put the axial slice.
178
+ * @param {number[] } scalarData The data array for the axially oriented vtk volume.
179
+ * @param {function } scalingFunction The modality specific scaling function.
180
+ *
181
+ * @returns {object } The min and max pixel values in the inserted slice.
182
+ */
183
+ function insertAxialSlice ( image , zIndex , scalarData , scalingFunction ) {
184
+ const pixels = image . getPixelData ( ) ;
185
+ const sliceLength = pixels . length ;
186
+
187
+ let pixelIndex = 0 ;
188
+ let max = scalingFunction ( pixels [ pixelIndex ] ) ;
189
+ let min = max ;
190
+
191
+ for ( let pixelIndex = 0 ; pixelIndex < pixels . length ; pixelIndex ++ ) {
192
+ const destIdx = pixelIndex + zIndex * sliceLength ;
193
+ const pixel = pixels [ pixelIndex ] ;
194
+ const pixelValue = scalingFunction ( pixel ) ;
195
+
196
+ if ( pixelValue > max ) {
197
+ max = pixelValue ;
198
+ } else if ( pixelValue < min ) {
199
+ min = pixelValue ;
200
+ }
201
+
202
+ scalarData [ destIdx ] = pixelValue ;
203
+ }
204
+
205
+ return { min, max } ;
206
+ }
207
+
47
208
function _getScalingFunction (
48
209
modality ,
49
210
image ,
0 commit comments