@@ -110,22 +110,22 @@ function _imageChangeEventListener(evt) {
110
110
// is there any extra actor that needs to be removed
111
111
// or any actor that needs to be added (which it is added later down), but remove
112
112
// it here if it is not needed
113
- labelmapActors . forEach ( ( actor ) => {
114
- // if cannot find a representation for this actor means it has stuck around
115
- // form previous renderings and should be removed
116
- const validActor = labelmapRepresentations . find ( ( representation ) => {
117
- const derivedImageId = getCurrentLabelmapImageIdForViewport (
118
- viewportId ,
119
- representation . segmentationId
120
- ) ;
121
-
122
- return derivedImageId === actor . referencedId ;
123
- } ) ;
124
-
125
- if ( ! validActor ) {
126
- viewport . removeActors ( [ actor . uid ] ) ;
127
- }
128
- } ) ;
113
+ // labelmapActors.forEach((actor) => {
114
+ // // if cannot find a representation for this actor means it has stuck around
115
+ // // form previous renderings and should be removed
116
+ // const validActor = labelmapRepresentations.find((representation) => {
117
+ // const derivedImageId = getCurrentLabelmapImageIdForViewport(
118
+ // viewportId,
119
+ // representation.segmentationId
120
+ // );
121
+
122
+ // return derivedImageId === actor.referencedId;
123
+ // });
124
+
125
+ // if (!validActor) {
126
+ // viewport.removeActors([actor.uid]);
127
+ // }
128
+ // });
129
129
130
130
labelmapRepresentations . forEach ( ( representation ) => {
131
131
const { segmentationId } = representation ;
@@ -149,85 +149,86 @@ function _imageChangeEventListener(evt) {
149
149
}
150
150
151
151
// re-use the old labelmap actor for the new image labelmap for speed and memory
152
- const segmentationActorInput = actors . find (
153
- ( actor ) => actor . referencedId === derivedImageId
154
- ) ;
155
-
156
- if ( ! segmentationActorInput ) {
157
- // i guess we need to create here
158
- const { dimensions, spacing, direction } =
159
- viewport . getImageDataMetadata ( derivedImage ) ;
160
-
161
- const currentImage =
162
- cache . getImage ( currentImageId ) ||
163
- ( {
164
- imageId : currentImageId ,
165
- } as Types . IImage ) ;
166
-
167
- const { origin : currentOrigin } =
168
- viewport . getImageDataMetadata ( currentImage ) ;
169
-
170
- // IMPORTANT: We need to make sure that the origin of the segmentation
171
- // is the same as the current image origin. This is because due to some
172
- // floating point precision issues, when coming from volume to stack
173
- // the origin of the segmentation can be slightly different from the
174
- // current image origin. This can cause the segmentation to be rendered
175
- // in the wrong location.
176
- // Todo: This will not work for segmentations that are not in the same frame
177
- // of reference or derived from the same image. This can happen when we have
178
- // a segmentation that happens to exist in the same space as the image but is
179
- // not derived from it. We need to find a way to handle this case, but don't think
180
- // it makes sense to do it for the stack viewport, as the volume viewport is designed to handle this case.
181
- const originToUse = currentOrigin ;
182
- const constructor = derivedImage . voxelManager . getConstructor ( ) ;
183
- const newPixelData = derivedImage . voxelManager . getScalarData ( ) ;
184
-
185
- const scalarArray = vtkDataArray . newInstance ( {
186
- name : 'Pixels' ,
187
- numberOfComponents : 1 ,
188
- // @ts -expect-error
189
- values : new constructor ( newPixelData ) ,
190
- } ) ;
191
-
192
- const imageData = vtkImageData . newInstance ( ) ;
193
-
194
- imageData . setDimensions ( dimensions [ 0 ] , dimensions [ 1 ] , 1 ) ;
195
- imageData . setSpacing ( spacing ) ;
196
- imageData . setDirection ( direction ) ;
197
- imageData . setOrigin ( originToUse ) ;
198
- imageData . getPointData ( ) . setScalars ( scalarArray ) ;
199
- imageData . modified ( ) ;
200
-
201
- viewport . addImages ( [
202
- {
203
- imageId : derivedImageId ,
204
- representationUID : `${ segmentationId } -${ SegmentationRepresentations . Labelmap } ` ,
205
- callback : ( { imageActor } ) => {
206
- imageActor . getMapper ( ) . setInputData ( imageData ) ;
207
- } ,
208
- } ,
209
- ] ) ;
210
-
211
- triggerSegmentationRender ( viewportId ) ;
212
- return ;
152
+ // there is only one actor in this case. and its referenceId does not match with derivedImageId
153
+ // in 1.0 we did not have this logic of filtering actors by their reference ids
154
+ const segmentationActorInput = actors . find ( ( actor ) => actor ) ;
155
+
156
+ // if (!segmentationActorInput) {
157
+ // // i guess we need to create here
158
+ // const { dimensions, spacing, direction } =
159
+ // viewport.getImageDataMetadata(derivedImage);
160
+
161
+ // const currentImage =
162
+ // cache.getImage(currentImageId) ||
163
+ // ({
164
+ // imageId: currentImageId,
165
+ // } as Types.IImage);
166
+
167
+ // const { origin: currentOrigin } =
168
+ // viewport.getImageDataMetadata(currentImage);
169
+
170
+ // // IMPORTANT: We need to make sure that the origin of the segmentation
171
+ // // is the same as the current image origin. This is because due to some
172
+ // // floating point precision issues, when coming from volume to stack
173
+ // // the origin of the segmentation can be slightly different from the
174
+ // // current image origin. This can cause the segmentation to be rendered
175
+ // // in the wrong location.
176
+ // // Todo: This will not work for segmentations that are not in the same frame
177
+ // // of reference or derived from the same image. This can happen when we have
178
+ // // a segmentation that happens to exist in the same space as the image but is
179
+ // // not derived from it. We need to find a way to handle this case, but don't think
180
+ // // it makes sense to do it for the stack viewport, as the volume viewport is designed to handle this case.
181
+ // const originToUse = currentOrigin;
182
+ // const constructor = derivedImage.voxelManager.getConstructor();
183
+ // const newPixelData = derivedImage.voxelManager.getScalarData();
184
+
185
+ // const scalarArray = vtkDataArray.newInstance({
186
+ // name: 'Pixels',
187
+ // numberOfComponents: 1,
188
+ // // @ts -expect-error
189
+ // values: new constructor(newPixelData),
190
+ // });
191
+
192
+ // const imageData = vtkImageData.newInstance();
193
+
194
+ // imageData.setDimensions(dimensions[0], dimensions[1], 1);
195
+ // imageData.setSpacing(spacing);
196
+ // imageData.setDirection(direction);
197
+ // imageData.setOrigin(originToUse);
198
+ // imageData.getPointData().setScalars(scalarArray);
199
+ // imageData.modified();
200
+
201
+ // viewport.addImages([
202
+ // {
203
+ // imageId: derivedImageId,
204
+ // representationUID: `${segmentationId}-${SegmentationRepresentations.Labelmap}`,
205
+ // callback: ({ imageActor }) => {
206
+ // imageActor.getMapper().setInputData(imageData);
207
+ // },
208
+ // },
209
+ // ]);
210
+
211
+ // triggerSegmentationRender(viewportId);
212
+ // return;
213
+ // } else {
214
+ // // if actor found
215
+ // // update the image data
216
+
217
+ // }
218
+
219
+ const segmentationImageData = segmentationActorInput . actor
220
+ . getMapper ( )
221
+ . getInputData ( ) ;
222
+
223
+ if ( segmentationImageData . setDerivedImage ) {
224
+ // Update the derived image data, whether vtk or other as appropriate
225
+ // to the actor(s) displaying the data.
226
+ segmentationImageData . setDerivedImage ( derivedImage ) ;
213
227
} else {
214
- // if actor found
215
- // update the image data
216
-
217
- const segmentationImageData = segmentationActorInput . actor
218
- . getMapper ( )
219
- . getInputData ( ) ;
220
-
221
- if ( segmentationImageData . setDerivedImage ) {
222
- // Update the derived image data, whether vtk or other as appropriate
223
- // to the actor(s) displaying the data.
224
- segmentationImageData . setDerivedImage ( derivedImage ) ;
225
- } else {
226
- utilities . updateVTKImageDataWithCornerstoneImage (
227
- segmentationImageData ,
228
- derivedImage
229
- ) ;
230
- }
228
+ utilities . updateVTKImageDataWithCornerstoneImage (
229
+ segmentationImageData ,
230
+ derivedImage
231
+ ) ;
231
232
}
232
233
233
234
viewport . render ( ) ;
0 commit comments