Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(segmentation): fix segmentation for video viewports #1595

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions packages/core/src/RenderingEngine/VideoViewport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -836,6 +836,9 @@ class VideoViewport extends Viewport {
return false;
}
const match = referencedImageId.match(VideoViewport.frameRangeExtractor);
if (!match) {
return true;
}
if (!match[2]) {
return true;
}
Expand Down Expand Up @@ -1130,16 +1133,17 @@ class VideoViewport extends Viewport {
public addImages(stackInputs: IStackInput[]) {
const actors = this.getActors();
stackInputs.forEach((stackInput) => {
const image = cache.getImage(stackInput.imageId);
const { imageId, ...rest } = stackInput;
const image = cache.getImage(imageId);

const imageActor = this.createActorMapper(image);
const uid = stackInput.actorUID ?? uuidv4();
if (imageActor) {
actors.push({ uid, actor: imageActor });
actors.push({ uid, actor: imageActor, referencedId: imageId, ...rest });
if (stackInput.callback) {
stackInput.callback({
imageActor: imageActor as unknown as ImageActor,
imageId: stackInput.imageId,
imageId,
});
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,14 @@ async function addImageSlicesToViewports(
stackInputs: IStackInput[],
viewportIds: string[]
): Promise<void> {
// Check if all viewports are volumeViewports
for (const viewportId of viewportIds) {
const viewport = renderingEngine.getStackViewport(viewportId);
const viewport = renderingEngine.getViewport(viewportId) as IStackViewport;

if (!viewport) {
throw new Error(`Viewport with Id ${viewportId} does not exist`);
}

// if not instance of BaseVolumeViewport, throw
// if the viewport does not support addImages, log a warning and skip
if (!viewport.addImages) {
console.warn(
`Viewport with Id ${viewportId} does not have addImages. Cannot add image segmentation to this viewport.`
Expand All @@ -40,8 +39,7 @@ async function addImageSlicesToViewports(
}

const addStackPromises = viewportIds.map(async (viewportId) => {
const viewport = renderingEngine.getStackViewport(viewportId);

const viewport = renderingEngine.getViewport(viewportId) as IStackViewport;
viewport.addImages(stackInputs);
});

Expand Down