Skip to content

fix(labelmap) : Display labelmap on volume3d viewport #1993

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

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 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
24 changes: 24 additions & 0 deletions packages/core/src/RenderingEngine/BaseVolumeViewport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1881,6 +1881,30 @@ abstract class BaseVolumeViewport extends Viewport {
public getAllVolumeIds(): string[] {
return Array.from(this.volumeIds);
}

/**
* Gets the blend mode for the volume viewport. If filterActorUIDs is provided,
* it will return the blend mode for the first matching actor. Otherwise, it returns
* the blend mode of the first actor.
*
* @param filterActorUIDs - Optional array of actor UIDs to filter by
* @returns The blend mode of the matched actor
*/
public getBlendMode(filterActorUIDs?: string[]): BlendModes {
const actorEntries = this.getActors();
const actorForBlend =
filterActorUIDs?.length > 0
? actorEntries.find((actorEntry) =>
filterActorUIDs.includes(actorEntry.uid)
)
: actorEntries[0];

return (
actorForBlend?.blendMode ||
// @ts-ignore vtk incorrect typing
actorForBlend?.actor.getMapper().getBlendMode()
);
}
}

export default BaseVolumeViewport;
24 changes: 0 additions & 24 deletions packages/core/src/RenderingEngine/VolumeViewport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,30 +273,6 @@ class VolumeViewport extends BaseVolumeViewport {
this.resetCamera();
}

/**
* Gets the blend mode for the volume viewport. If filterActorUIDs is provided,
* it will return the blend mode for the first matching actor. Otherwise, it returns
* the blend mode of the first actor.
*
* @param filterActorUIDs - Optional array of actor UIDs to filter by
* @returns The blend mode of the matched actor
*/
public getBlendMode(filterActorUIDs?: string[]): BlendModes {
const actorEntries = this.getActors();
const actorForBlend =
filterActorUIDs?.length > 0
? actorEntries.find((actorEntry) =>
filterActorUIDs.includes(actorEntry.uid)
)
: actorEntries[0];

return (
actorForBlend?.blendMode ||
// @ts-ignore vtk incorrect typing
actorForBlend?.actor.getMapper().getBlendMode()
);
}

/**
* Sets the blend mode for actors in the volume viewport. Can optionally filter which
* actors to apply the blend mode to using filterActorUIDs.
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/utilities/getViewportImageIds.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { VolumeViewport } from '../RenderingEngine';
import BaseVolumeViewport from '../RenderingEngine/BaseVolumeViewport';
import cache from '../cache/cache';
import type { IViewport, IStackViewport } from '../types';

Expand All @@ -9,7 +10,7 @@ import type { IViewport, IStackViewport } from '../types';
* @returns An array of image IDs.
*/
function getViewportImageIds(viewport: IViewport) {
if (viewport instanceof VolumeViewport) {
if (viewport instanceof BaseVolumeViewport) {
const volume = cache.getVolume(viewport.getVolumeId());
return volume.imageIds;
} else if ((viewport as IStackViewport).getImageIds) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import type { Types } from '@cornerstonejs/core';
import { volumeLoader, imageLoader, VolumeViewport } from '@cornerstonejs/core';
import {
volumeLoader,
imageLoader,
BaseVolumeViewport,
} from '@cornerstonejs/core';
import { utilities } from '@cornerstonejs/tools';
import * as cornerstoneTools from '@cornerstonejs/tools';
import type { Types as ToolsTypes } from '@cornerstonejs/tools';
Expand Down Expand Up @@ -70,7 +74,7 @@ async function computeLabelmapFromContourSegmentation(
| ToolsTypes.LabelmapSegmentationDataStack
> {
const isVolume = options.viewport
? options.viewport instanceof VolumeViewport
? options.viewport instanceof BaseVolumeViewport
: true;

if (isVolume && !options.viewport) {
Expand Down Expand Up @@ -111,7 +115,7 @@ async function computeLabelmapFromSurfaceSegmentation(
| ToolsTypes.LabelmapSegmentationDataStack
> {
const { viewport } = options;
const isVolume = viewport ? viewport instanceof VolumeViewport : true;
const isVolume = viewport ? viewport instanceof BaseVolumeViewport : true;

const segmentIndices = options.segmentIndices?.length
? options.segmentIndices
Expand Down
2 changes: 1 addition & 1 deletion packages/tools/examples/labelmapMIP/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ async function run() {
},
{
viewportId: viewportId2,
type: ViewportType.ORTHOGRAPHIC,
type: ViewportType.VOLUME_3D,
element: element2,
defaultOptions: {
orientation: Enums.OrientationAxis.SAGITTAL,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
VolumeViewport,
getEnabledElementByViewportId,
StackViewport,
BaseVolumeViewport,
} from '@cornerstonejs/core';

import type { SegmentationDataModifiedEventType } from '../../../types/EventTypes';
Expand All @@ -25,7 +26,7 @@ const onLabelmapSegmentationDataModified = function (

const hasVolumeViewport = viewportIds.some((viewportId) => {
const { viewport } = getEnabledElementByViewportId(viewportId);
return viewport instanceof VolumeViewport;
return viewport instanceof BaseVolumeViewport;
});

const hasStackViewport = viewportIds.some((viewportId) => {
Expand All @@ -38,7 +39,7 @@ const onLabelmapSegmentationDataModified = function (
viewportIds.forEach((viewportId) => {
const { viewport } = getEnabledElementByViewportId(viewportId);

if (viewport instanceof VolumeViewport) {
if (viewport instanceof BaseVolumeViewport) {
// For combined stack and volume scenarios in the rendering engine, updating only affected
// slices is not ideal. Stack indices (e.g., 0 for just one image) don't
// correspond to image indices in the volume. In this case, we update all slices.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {
cache,
utilities as csUtils,
VolumeViewport,
getEnabledElementByViewportId,
BaseVolumeViewport,
} from '@cornerstonejs/core';

import { SegmentationRepresentations } from '../../../enums';
Expand Down Expand Up @@ -43,7 +43,7 @@ export function performStackLabelmapUpdate({

const { viewport } = enabledElement;

if (viewport instanceof VolumeViewport) {
if (viewport instanceof BaseVolumeViewport) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Types } from '@cornerstonejs/core';
import {
BaseVolumeViewport,
getEnabledElementByViewportId,
VolumeViewport,
} from '@cornerstonejs/core';

import type {
Expand Down Expand Up @@ -157,7 +157,7 @@ async function render(
return;
}

if (viewport instanceof VolumeViewport) {
if (viewport instanceof BaseVolumeViewport) {
if (!labelmapActorEntries?.length) {
// only add the labelmap to ToolGroup viewports if it is not already added
await _addLabelmapToViewport(
Expand Down
Loading