@@ -14,7 +14,7 @@ import vtkVolume from 'vtk.js/Sources/Rendering/Core/Volume';
14
14
const { EVENTS } = cornerstoneTools ;
15
15
window . cornerstoneTools = cornerstoneTools ;
16
16
17
- function setupSyncedBrush ( imageDataObject , element ) {
17
+ function setupSyncedBrush ( imageDataObject ) {
18
18
// Create buffer the size of the 3D volume
19
19
const dimensions = imageDataObject . dimensions ;
20
20
const width = dimensions [ 0 ] ;
@@ -128,10 +128,7 @@ class VTKCornerstonePaintingSyncExample extends Component {
128
128
} ;
129
129
130
130
const imageDataObject = getImageData ( imageIds , displaySetInstanceUid ) ;
131
- const labelMapInputData = setupSyncedBrush (
132
- imageDataObject ,
133
- this . cornerstoneElements [ 0 ]
134
- ) ;
131
+ const labelMapInputData = setupSyncedBrush ( imageDataObject ) ;
135
132
136
133
this . onMeasurementsChanged = event => {
137
134
if ( event . type !== EVENTS . LABELMAP_MODIFIED ) {
@@ -160,7 +157,7 @@ class VTKCornerstonePaintingSyncExample extends Component {
160
157
) ;
161
158
}
162
159
163
- onPaintEnd = ( ) => {
160
+ onPaintEnd = strokeBuffer => {
164
161
const element = this . cornerstoneElements [ 0 ] ;
165
162
const enabledElement = cornerstone . getEnabledElement ( element ) ;
166
163
const { getters, setters } = cornerstoneTools . getModule ( 'segmentation' ) ;
@@ -174,16 +171,35 @@ class VTKCornerstonePaintingSyncExample extends Component {
174
171
175
172
const stackData = stackState . data [ 0 ] ;
176
173
const numberOfFrames = stackData . imageIds . length ;
174
+ const segmentIndex = labelmap3D . activeSegmentIndex ;
177
175
178
- // TODO -> Can do more efficiently if we can grab the strokeBuffer from vtk-js.
179
176
for ( let i = 0 ; i < numberOfFrames ; i ++ ) {
180
- const labelmap2D = getters . labelmap2DByImageIdIndex (
181
- labelmap3D ,
182
- i ,
183
- rows ,
184
- columns
185
- ) ;
186
- setters . updateSegmentsOnLabelmap2D ( labelmap2D ) ;
177
+ let labelmap2D = labelmap3D . labelmaps2D [ i ] ;
178
+
179
+ if ( labelmap2D && labelmap2D . segmentsOnLabelmap . includes ( segmentIndex ) ) {
180
+ continue ;
181
+ }
182
+
183
+ const frameLength = rows * columns ;
184
+ const byteOffset = frameLength * i ;
185
+ const strokeArray = new Uint8Array ( strokeBuffer , byteOffset , frameLength ) ;
186
+
187
+ const strokeOnFrame = strokeArray . some ( element => element === 1 ) ;
188
+
189
+ if ( ! strokeOnFrame ) {
190
+ continue ;
191
+ }
192
+
193
+ if ( labelmap2D ) {
194
+ labelmap2D . segmentsOnLabelmap . push ( segmentIndex ) ;
195
+ } else {
196
+ labelmap2D = getters . labelmap2DByImageIdIndex (
197
+ labelmap3D ,
198
+ i ,
199
+ rows ,
200
+ columns
201
+ ) ;
202
+ }
187
203
}
188
204
189
205
cornerstone . updateImage ( element ) ;
0 commit comments