Skip to content

Commit

Permalink
feat(segmentation): add stack viewport segmentations rendering and to…
Browse files Browse the repository at this point in the history
…ols (#894)

* Add getImage method to Cache class

Co-authored-by: rodrigobasilio2022 <[email protected]>

* initial setup

* Add labelmap segmentation support to stack viewport

* Add SegmentationToolsOperationData types and
update segmentation strategies

* Refactored fillCircle function to use segmentIndex
instead of hard-coded value.

* Fix segmentation tool bugs

* Update Segmentation Tool Operation Data types

* Add volume segmentation support to
RectangleScissorsTool

* Refactor eraseRectangle function to use
fillInsideRectangle

* Update codebase with changes from git diff

* Update segmentation image rendering

* Refactor segmentation image change event listener

* Refactor pointInEllipse function to use
destructuring and simplify calculations.

* Refactor pointInEllipse function to accept
optional inverts parameter

* Refactor sphere manipulation and ellipse point
calculation.

* Add isVolumeSegmentation function to BrushTool.ts

* Remove unused import and console.log statement in
derivedImageMetadataProvider.ts

* Fix segmentation tool bugs and update example data

* Updated example-info.json with revised
descriptions

* api

* Add getBufferConfiguration utility function

* Remove unused imports and event listeners

* Refactor code and update dependencies

* Add new utility function findMapKeyByValue and
update labelmapDisplay

* Add SegmentationRepresentations import and handle
different types of labelmap data

* Fix segmentation rendering issue and handle
missing segmentation slices

* update

* Remove unused function and import statements

* api

---------

Co-authored-by: rodrigobasilio2022 <[email protected]>
  • Loading branch information
sedghi and rodrigobasilio2022 authored Nov 28, 2023
1 parent 0a00cbe commit 5d23572
Show file tree
Hide file tree
Showing 60 changed files with 2,379 additions and 569 deletions.
96 changes: 94 additions & 2 deletions common/reviews/api/core.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { vec3 } from 'gl-matrix';
import type vtkActor from '@kitware/vtk.js/Rendering/Core/Actor';
import type { vtkCamera } from '@kitware/vtk.js/Rendering/Core/Camera';
import vtkColorTransferFunction from '@kitware/vtk.js/Rendering/Core/ColorTransferFunction';
import type { vtkImageData } from '@kitware/vtk.js/Common/DataModel/ImageData';
import { vtkImageData } from '@kitware/vtk.js/Common/DataModel/ImageData';
import vtkImageSlice from '@kitware/vtk.js/Rendering/Core/ImageSlice';
import type { vtkObject } from '@kitware/vtk.js/interfaces';
import vtkPlane from '@kitware/vtk.js/Common/DataModel/Plane';
Expand Down Expand Up @@ -43,6 +43,9 @@ type ActorSliceRange = {
current: number;
};

// @public (undocumented)
export function addImageSlicesToViewports(renderingEngine: IRenderingEngine, stackInputs: Array<IStackInput>, viewportIds: Array<string>, immediateRender?: boolean, suppressEvents?: boolean): Promise<void>;

// @public (undocumented)
function addProvider(provider: (type: string, ...query: string[]) => any, priority?: number): void;

Expand Down Expand Up @@ -529,12 +532,21 @@ type CPUImageData = {
getDimensions?: () => Point3;
};

// @public (undocumented)
function createAndCacheDerivedImage(referencedImageId: string, options?: DerivedImageOptions, preventCache?: boolean): Promise<IImage>;

// @public (undocumented)
function createAndCacheDerivedImages(referencedImageIds: Array<string>, getDerivedImageId?: (referencedImageId: string) => string): DerivedImages;

// @public (undocumented)
function createAndCacheDerivedVolume(referencedVolumeId: string, options: DerivedVolumeOptions): Promise<ImageVolume>;

// @public (undocumented)
function createAndCacheGeometry(geometryId: string, options: GeometryOptions): Promise<IGeometry>;

// @public (undocumented)
function createAndCacheLocalImage(options: LocalImageOptions, imageId: string, preventCache?: boolean): IImage;

// @public (undocumented)
function createAndCacheVolume(volumeId: string, options?: VolumeLoaderOptions): Promise<Record<string, any>>;

Expand Down Expand Up @@ -800,6 +812,15 @@ enum GeometryType {
SURFACE = "Surface"
}

// @public (undocumented)
function getBufferConfiguration(targetBufferType: PixelDataTypedArrayString, length: number, options?: {
use16BitTexture?: boolean;
isVolumeBuffer?: boolean;
}): {
numBytes: number;
TypedArrayConstructor: new (length: number | SharedArrayBuffer) => PixelDataTypedArray;
};

// @public (undocumented)
function getClosestImageId(imageVolume: IImageVolume, worldPos: Point3, viewPlaneNormal: Point3): string;

Expand Down Expand Up @@ -1191,6 +1212,8 @@ interface IImage {
};
};
// (undocumented)
referencedImageId?: string;
// (undocumented)
render?: (enabledElement: CPUFallbackEnabledElement, invalidated: boolean) => unknown;
// (undocumented)
rgba: boolean;
Expand Down Expand Up @@ -1407,6 +1430,9 @@ declare namespace imageLoader {
loadImage,
loadAndCacheImage,
loadAndCacheImages,
createAndCacheDerivedImage,
createAndCacheDerivedImages,
createAndCacheLocalImage,
cancelLoadImage,
cancelLoadImages,
cancelLoadAll,
Expand Down Expand Up @@ -1745,8 +1771,22 @@ function isOpposite(v1: Point3, v2: Point3, tolerance?: number): boolean;
// @public (undocumented)
const isPTPrescaledWithSUV: (image: IImage) => number;

// @public (undocumented)
interface IStackInput {
// (undocumented)
actorUID?: string;
// (undocumented)
callback?: StackInputCallback;
// (undocumented)
imageId: string;
// (undocumented)
visibility?: boolean;
}

// @public (undocumented)
interface IStackViewport extends IViewport {
// (undocumented)
addImages(stackInputs: Array<IStackInput>, immediateRender: boolean, suppressEvents: boolean): any;
// (undocumented)
calibrateSpacing(imageId: string): void;
// (undocumented)
Expand Down Expand Up @@ -1775,6 +1815,8 @@ interface IStackViewport extends IViewport {
// (undocumented)
getImageData(): IImageData | CPUIImageData;
// (undocumented)
getImageDataMetadata(image: IImage): any;
// (undocumented)
getImageIds: () => string[];
// (undocumented)
getProperties: () => StackViewportProperties;
Expand Down Expand Up @@ -1836,6 +1878,9 @@ interface IStreamingVolumeProperties {
};
}

// @public (undocumented)
function isValidVolume(imageIds: string[]): boolean;

// @public (undocumented)
function isVideoTransferSyntax(uidOrUids: string | string[]): string | false;

Expand Down Expand Up @@ -2114,6 +2159,9 @@ function loadImageToCanvas(options: LoadImageOptions): Promise<string>;
// @public (undocumented)
function loadVolume(volumeId: string, options?: VolumeLoaderOptions): Promise<Types.IImageVolume>;

// @public (undocumented)
function makeVolumeMetadata(imageIds: Array<string>): Metadata;

// @public (undocumented)
type Mat3 = [number, number, number, number, number, number, number, number, number] | Float32Array;

Expand Down Expand Up @@ -2172,6 +2220,13 @@ const metadataProvider: {
get: (type: string, imageId: string) => IImageCalibration;
};

// @public (undocumented)
const metadataProvider_2: {
add: (imageId: string, payload: any) => void;
get: (type: string, imageId: string) => any;
clear: () => void;
};

// @public (undocumented)
const mprCameraValues: any;

Expand Down Expand Up @@ -2212,6 +2267,9 @@ type OrientationVectors = {
// @public (undocumented)
type PixelDataTypedArray = Float32Array | Int16Array | Uint16Array | Uint8Array | Int8Array | Uint8ClampedArray;

// @public (undocumented)
type PixelDataTypedArrayString = 'Float32Array' | 'Int16Array' | 'Uint16Array' | 'Uint8Array' | 'Int8Array' | 'Uint8ClampedArray';

declare namespace planar {
export {
linePlaneIntersection,
Expand Down Expand Up @@ -2552,6 +2610,9 @@ function snapFocalPointToSlice(focalPoint: Point3, position: Point3, sliceRange:
newPosition: Point3;
};

// @public (undocumented)
function sortImageIdsAndGetSpacing(imageIds: Array<string>, scanAxisNormal?: vec3): SortedImageIdsItem;

// @public (undocumented)
const spatialRegistrationMetadataProvider: {
add: (query: string[], payload: mat4) => void;
Expand All @@ -2566,6 +2627,12 @@ enum SpeedUnit {
SECOND = "s"
}

// @public (undocumented)
type StackInputCallback = (params: {
imageActor: ImageActor;
imageId: string;
}) => unknown;

// @public (undocumented)
type StackNewImageEvent = CustomEvent_2<StackNewImageEventDetail>;

Expand All @@ -2586,12 +2653,23 @@ export class StackViewport extends Viewport implements IStackViewport, IImagesLo
// (undocumented)
addActors: (actors: Array<ActorEntry>) => void;
// (undocumented)
addImages(stackInputs: Array<IStackInput>): Promise<void>;
// (undocumented)
calibrateSpacing(imageId: string): void;
// (undocumented)
canvasToWorld: (canvasPos: Point2) => Point3;
// (undocumented)
clearDefaultProperties(imageId?: string): void;
// (undocumented)
createVTKImageData({ origin, direction, dimensions, spacing, numComps, pixelArray, }: {
origin: any;
direction: any;
dimensions: any;
spacing: any;
numComps: any;
pixelArray: any;
}): vtkImageData;
// (undocumented)
customRenderViewportToCanvas: () => {
canvas: HTMLCanvasElement;
element: HTMLDivElement;
Expand Down Expand Up @@ -2622,6 +2700,8 @@ export class StackViewport extends Viewport implements IStackViewport, IImagesLo
// (undocumented)
getImageData: () => IImageData | CPUIImageData;
// (undocumented)
getImageDataMetadata(image: IImage): ImageDataMetaData;
// (undocumented)
getImageIds: () => Array<string>;
// (undocumented)
getLoaderImageOptions(imageId: string): {
Expand Down Expand Up @@ -2835,6 +2915,8 @@ declare namespace Types {
IVolumeLoadObject,
IVolumeInput,
VolumeInputCallback,
IStackInput,
StackInputCallback,
ViewportPreset,
Metadata,
OrientationVectors,
Expand Down Expand Up @@ -2879,6 +2961,7 @@ declare namespace Types {
ColormapPublic,
ColormapRegistration,
PixelDataTypedArray,
PixelDataTypedArrayString,
ImagePixelModule,
ImagePlaneModule,
AffineMatrix,
Expand All @@ -2892,6 +2975,9 @@ export { Types }
// @public (undocumented)
function unregisterAllImageLoaders(): void;

// @public (undocumented)
function updateVTKImageDataWithCornerstoneImage(sourceImageData: vtkImageData, image: IImage): void;

declare namespace utilities {
export {
eventListener,
Expand Down Expand Up @@ -2953,7 +3039,13 @@ declare namespace utilities {
decimate,
imageRetrieveMetadataProvider,
transferFunctionUtils,
isVideoTransferSyntax
updateVTKImageDataWithCornerstoneImage,
sortImageIdsAndGetSpacing,
makeVolumeMetadata,
isValidVolume,
metadataProvider_2 as genericMetadataProvider,
isVideoTransferSyntax,
getBufferConfiguration
}
}
export { utilities }
Expand Down
2 changes: 0 additions & 2 deletions common/reviews/api/streaming-image-volume-loader.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import type { GetGPUTier } from 'detect-gpu';
import type { mat4 } from 'gl-matrix';
import type { TierResult } from 'detect-gpu';
import { vec3 } from 'gl-matrix';
import type vtkActor from '@kitware/vtk.js/Rendering/Core/Actor';
import type { vtkImageData } from '@kitware/vtk.js/Common/DataModel/ImageData';
import vtkImageSlice from '@kitware/vtk.js/Rendering/Core/ImageSlice';
Expand Down Expand Up @@ -40,7 +39,6 @@ enum Events_2 {
// @public (undocumented)
export const helpers: {
getDynamicVolumeInfo: typeof getDynamicVolumeInfo;
sortImageIdsAndGetSpacing: typeof sortImageIdsAndGetSpacing;
};

// @public (undocumented)
Expand Down
53 changes: 45 additions & 8 deletions common/reviews/api/tools.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -853,9 +853,10 @@ export class CircleScissorsTool extends BaseTool {
// (undocumented)
editData: {
annotation: any;
segmentation: any;
segmentIndex: number;
segmentationId: string;
volumeId: string;
referencedVolumeId: string;
imageIdReferenceMap: Map<string, string>;
segmentsLocked: number[];
segmentColor: [number, number, number, number];
viewportIdsToRender: string[];
Expand All @@ -864,6 +865,7 @@ export class CircleScissorsTool extends BaseTool {
newAnnotation?: boolean;
hasMoved?: boolean;
centerCanvas?: Array<number>;
segmentationRepresentationUID?: string;
} | null;
// (undocumented)
_endCallback: (evt: EventTypes_2.InteractionEventType) => void;
Expand Down Expand Up @@ -2443,15 +2445,43 @@ type LabelmapRenderingConfig = {
};

// @public (undocumented)
type LabelmapSegmentationData = {
type LabelmapSegmentationData = LabelmapSegmentationDataVolume | LabelmapSegmentationDataStack;

// @public (undocumented)
type LabelmapSegmentationDataStack = {
imageIdReferenceMap: Map<string, string>;
};

// @public (undocumented)
type LabelmapSegmentationDataVolume = {
volumeId: string;
referencedVolumeId?: string;
};

// @public (undocumented)
type LabelmapToolOperationData = {
segmentationId: string;
segmentIndex: number;
segmentsLocked: number[];
viewPlaneNormal: number[];
viewUp: number[];
strategySpecificConfiguration: any;
constraintFn: (pointIJK: number) => boolean;
segmentationRepresentationUID: string;
};

// @public (undocumented)
type LabelmapToolOperationDataStack = LabelmapToolOperationData & LabelmapSegmentationDataStack;

// @public (undocumented)
type LabelmapToolOperationDataVolume = LabelmapToolOperationData & LabelmapSegmentationDataVolume;

declare namespace LabelmapTypes {
export {
LabelmapConfig,
LabelmapRenderingConfig,
LabelmapSegmentationDataVolume,
LabelmapSegmentationDataStack,
LabelmapSegmentationData
}
}
Expand Down Expand Up @@ -3035,7 +3065,7 @@ declare namespace point {
const pointCanProjectOnLine: (p: Types_2.Point2, p1: Types_2.Point2, p2: Types_2.Point2, proximity: number) => boolean;

// @public (undocumented)
function pointInEllipse(ellipse: Ellipse, pointLPS: vec3): boolean;
function pointInEllipse(ellipse: any, pointLPS: any, inverts?: Inverts): boolean;

// @public (undocumented)
function pointInShapeCallback(imageData: vtkImageData | Types_2.CPUImageData, pointInShapeFn: ShapeFnCriteria, callback?: PointInShapeCallback, boundsIJK?: BoundsIJK): Array<PointInShape>;
Expand Down Expand Up @@ -3421,9 +3451,11 @@ export class RectangleScissorsTool extends BaseTool {
_dragCallback: (evt: EventTypes_2.InteractionEventType) => void;
// (undocumented)
editData: {
imageIdReferenceMap: Map<string, string>;
volumeId: string;
referencedVolumeId: string;
annotation: any;
segmentationId: string;
segmentation: any;
segmentIndex: number;
segmentsLocked: number[];
segmentColor: [number, number, number, number];
Expand Down Expand Up @@ -3976,10 +4008,12 @@ export class SphereScissorsTool extends BaseTool {
// (undocumented)
editData: {
annotation: any;
segmentation: any;
segmentIndex: number;
segmentsLocked: number[];
segmentationId: string;
segmentationRepresentationUID: string;
volumeId: string;
referencedVolumeId: string;
imageIdReferenceMap: Map<string, string>;
toolGroupId: string;
segmentColor: [number, number, number, number];
viewportIdsToRender: string[];
Expand Down Expand Up @@ -4579,7 +4613,10 @@ declare namespace Types {
FloodFillGetter,
FloodFillOptions,
ContourSegmentationData,
Statistics
Statistics,
LabelmapToolOperationData,
LabelmapToolOperationDataStack,
LabelmapToolOperationDataVolume
}
}
export { Types }
Expand Down
Loading

0 comments on commit 5d23572

Please sign in to comment.