Skip to content

Commit

Permalink
feat(webgpu): growcut base tools (#1670)
Browse files Browse the repository at this point in the history
  • Loading branch information
lscoder authored Dec 4, 2024
1 parent 5a7542d commit 7494c9e
Show file tree
Hide file tree
Showing 66 changed files with 4,429 additions and 316 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
*.json
packages/adapters/config/webpack/*.js
packages/docs/*.js
packages/tools/src/utilities/segmentation/growCut/runGrowCut.ts
2 changes: 1 addition & 1 deletion .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"recommendations": ["esbenp.prettier-vscode", "dbaeumer.vscode-eslint"]
"recommendations": ["esbenp.prettier-vscode", "dbaeumer.vscode-eslint", "PolyMeilex.wgsl"]
}
Binary file modified bun.lockb
Binary file not shown.
25 changes: 24 additions & 1 deletion common/reviews/api/core.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -848,6 +848,13 @@ function createLocalVolume(volumeId: string, options?: LocalVolumeOptions): IIma
// @public (undocumented)
function createSigmoidRGBTransferFunction(voiRange: VOIRange, approximationNodes?: number): vtkColorTransferFunction;

// @public (undocumented)
function createSubVolume(referencedVolumeId: string, boundsIJK: AABB3, options?: {
targetBuffer?: {
type: PixelDataTypedArrayString;
};
}): ImageVolume;

// @public (undocumented)
export function createVolumeActor(props: createVolumeActorInterface, element: HTMLDivElement, viewportId: string, suppressEvents?: boolean): Promise<VolumeActor>;

Expand Down Expand Up @@ -1356,6 +1363,16 @@ function getVoiFromSigmoidRGBTransferFunction(cfun: vtkColorTransferFunction): [
// @public (undocumented)
function getVolumeActorCorners(volumeActor: any): Point3[];

// @public (undocumented)
function getVolumeDirectionVectors(imageData: any, camera: any): {
worldVecRowDir: vec3;
worldVecColDir: vec3;
worldVecSliceDir: vec3;
ijkVecRowDir: vec3;
ijkVecColDir: vec3;
ijkVecSliceDir: vec3;
};

// @public (undocumented)
const getVolumeId: (targetId: string) => string;

Expand Down Expand Up @@ -3719,6 +3736,9 @@ type TransformMatrix2D = [number, number, number, number, number, number];
// @public (undocumented)
function transformWorldToIndex(imageData: any, worldPos: Point3): any;

// @public (undocumented)
function transformWorldToIndexContinuous(imageData: any, worldPos: Point3): any;

// @public (undocumented)
export function triggerEvent(el: EventTarget, type: string, detail?: unknown): boolean;

Expand Down Expand Up @@ -3964,7 +3984,10 @@ declare namespace utilities {
deepEqual,
jumpToSlice,
scroll_2 as scroll,
clip
clip,
transformWorldToIndexContinuous,
createSubVolume,
getVolumeDirectionVectors
}
}
export { utilities }
Expand Down
118 changes: 110 additions & 8 deletions common/reviews/api/tools.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -2741,13 +2741,7 @@ function getSegmentIndexVisibility(viewportId: string, specifier: {
function getSignedArea(polyline: Types_2.Point2[]): number;

// @public (undocumented)
function getSphereBoundsInfo(circlePoints: [Types_2.Point3, Types_2.Point3], imageData: vtkImageData, viewport: any): {
boundsIJK: BoundsIJK_2;
centerWorld: Types_2.Point3;
radiusWorld: number;
topLeftWorld: Types_2.Point3;
bottomRightWorld: Types_2.Point3;
};
function getSphereBoundsInfo(circlePoints: [Types_2.Point3, Types_2.Point3], imageData: vtkImageData): SphereBoundsInfo;

// @public (undocumented)
function getStackSegmentationImageIdsForViewport(viewportId: string, segmentationId: string): string[];
Expand Down Expand Up @@ -2815,6 +2809,52 @@ type GroupSpecificAnnotations = {
[toolName: string]: Annotations;
};

declare namespace growCut {
export {
runGrowCut as run,
runGrowCutForSphere,
runGrowCutForBoundingBox,
runOneClickGrowCut,
SphereInfo,
GrowCutOptions as GrowCutSphereOptions,
GrowCutBoundingBoxOptions,
GrowCutOneClickOptions
}
}

// @public (undocumented)
type GrowCutBoundingBoxOptions = GrowCutOptions & {
positiveSeedValue?: number;
negativeSeedValue?: number;
negativePixelRange: [number, number];
positivePixelRange: [number, number];
};

// @public (undocumented)
type GrowCutOneClickOptions = GrowCutOptions & {
positiveSeedValue?: number;
negativeSeedValue?: number;
positiveSeedVariance?: number;
negativeSeedVariance?: number;
subVolumePaddingPercentage?: number | [number, number, number];
subVolumeMinPadding?: number | [number, number, number];
};

// @public (undocumented)
type GrowCutOptions = {
maxProcessingTime?: number;
windowSize?: number;
positiveSeedValue?: number;
negativeSeedValue?: number;
positiveSeedVariance?: number;
negativeSeedVariance?: number;
inspection?: {
numCyclesInterval?: number;
numCyclesBelowThreashold?: number;
threshold?: number;
};
};

// @public (undocumented)
function hasCustomStyle(specifier: {
viewportId?: string;
Expand Down Expand Up @@ -4523,6 +4563,34 @@ export class ReferenceLinesTool extends AnnotationDisplayTool {
static toolName: any;
}

// @public (undocumented)
export class RegionSegmentPlusTool extends GrowCutBaseTool {
constructor(toolProps?: PublicToolProps, defaultToolProps?: ToolProps);
// (undocumented)
protected getGrowCutLabelmap(): Promise<Types_2.IImageVolume>;
// (undocumented)
protected growCutData: RegionSegmentPlusToolData | null;
// (undocumented)
preMouseDownCallback(evt: EventTypes_2.MouseDownActivateEventType): Promise<boolean>;
// (undocumented)
static toolName: any;
}

// @public (undocumented)
export class RegionSegmentTool extends GrowCutBaseTool {
constructor(toolProps?: PublicToolProps, defaultToolProps?: ToolProps);
// (undocumented)
protected getGrowCutLabelmap(): Promise<Types_2.IImageVolume>;
// (undocumented)
protected growCutData: RegionSegmentToolData | null;
// (undocumented)
preMouseDownCallback(evt: EventTypes_2.MouseDownActivateEventType): Promise<boolean>;
// (undocumented)
renderAnnotation(enabledElement: Types_2.IEnabledElement, svgDrawingHelper: SVGDrawingHelper): void;
// (undocumented)
static toolName: any;
}

// @public (undocumented)
function registerCursor(toolName: string, iconContent: string, viewBox: {
x: number;
Expand Down Expand Up @@ -4614,6 +4682,18 @@ interface ROICachedStats {
// @public (undocumented)
const roundNumber_2: typeof utilities_2.roundNumber;

// @public (undocumented)
function runGrowCut(referenceVolumeId: string, labelmapVolumeId: string, options?: GrowCutOptions): Promise<void>;

// @public (undocumented)
function runGrowCutForBoundingBox(referencedVolumeId: string, boundingBoxInfo: BoundingBoxInfo, options?: GrowCutBoundingBoxOptions): Promise<Types_2.IImageVolume>;

// @public (undocumented)
function runGrowCutForSphere(referencedVolumeId: string, sphereInfo: SphereInfo, viewport: Types_2.IViewport, options?: GrowCutOptions): Promise<Types_2.IImageVolume>;

// @public (undocumented)
function runOneClickGrowCut(referencedVolumeId: string, worldPosition: Types_2.Point3, viewport: Types_2.IViewport, options?: GrowCutOneClickOptions): Promise<Types_2.IImageVolume>;

// @public (undocumented)
interface ScaleOverlayAnnotation extends Annotation {
// (undocumented)
Expand Down Expand Up @@ -4783,7 +4863,8 @@ declare namespace segmentation_2 {
getSegmentIndexAtWorldPoint,
getSegmentIndexAtLabelmapBorder,
getHoveredContourSegmentationAnnotation,
getBrushToolInstances
getBrushToolInstances,
growCut
}
}

Expand Down Expand Up @@ -5030,6 +5111,12 @@ function showAllAnnotations(): void;
// @public (undocumented)
function smoothAnnotation(annotation: PlanarFreehandROIAnnotation, options?: SmoothOptions): boolean;

// @public (undocumented)
type SphereInfo = {
center: Types_2.Point3;
radius: number;
};

// @public (undocumented)
export class SphereScissorsTool extends BaseTool {
constructor(toolProps?: PublicToolProps, defaultToolProps?: ToolProps);
Expand Down Expand Up @@ -6291,6 +6378,21 @@ class VolumetricCalculator extends BasicStatsCalculator_2 {
}): NamedStatistics;
}

// @public (undocumented)
export class WholeBodySegmentTool extends GrowCutBaseTool {
constructor(toolProps?: PublicToolProps, defaultToolProps?: ToolProps);
// (undocumented)
protected getGrowCutLabelmap(): Promise<Types_2.IImageVolume>;
// (undocumented)
protected growCutData: WholeBodySegmentToolData | null;
// (undocumented)
preMouseDownCallback(evt: EventTypes_2.MouseDownActivateEventType): Promise<boolean>;
// (undocumented)
renderAnnotation(enabledElement: Types_2.IEnabledElement, svgDrawingHelper: SVGDrawingHelper): void;
// (undocumented)
static toolName: any;
}

declare namespace windowLevel_2 {
export {
getLuminanceFromRegion,
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
"@rollup/plugin-typescript": "^11.1.6",
"@rspack/cli": "^1.1.4",
"@rspack/core": "^1.1.4",
"@types/dom-webcodecs": "^0.1.11",
"@types/emscripten": "^1.39.6",
"@types/jasmine": "^4.3.1",
"@types/jest": "^29.5.12",
Expand All @@ -87,6 +88,7 @@
"@types/react-dom": "^17.0.20",
"@typescript-eslint/eslint-plugin": "^8.1.0",
"@typescript-eslint/parser": "^8.1.0",
"@webgpu/types": "^0.1.40",
"acorn": "^8.8.2",
"acorn-jsx": "^5.3.2",
"ajv": "^8.17.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/adapters/examples/segmentationExport/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ function createMockEllipsoidSegmentation(

async function addSegmentationsToState() {
// Create a segmentation of the same resolution as the source data
segmentationVolume = await volumeLoader.createAndCacheDerivedLabelmapVolume(
segmentationVolume = volumeLoader.createAndCacheDerivedLabelmapVolume(
volumeId,
{
volumeId: segmentationId
Expand Down
Loading

0 comments on commit 7494c9e

Please sign in to comment.