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

feat: dynamic threshold sphere #1598

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 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
57 changes: 51 additions & 6 deletions common/reviews/api/core.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -989,6 +989,7 @@ declare namespace Enums {
VideoEnums,
MetadataModules,
ImageQualityStatus,
VoxelManagerEnum,
GenerateImageType
}
}
Expand Down Expand Up @@ -2685,7 +2686,7 @@ export function peerImport(moduleId: string): any;
type PixelDataTypedArray = Float32Array | Int16Array | Uint16Array | Uint8Array | Int8Array | Uint8ClampedArray;

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

declare namespace planar {
export {
Expand Down Expand Up @@ -2745,6 +2746,8 @@ class PointsManager<T> {
// (undocumented)
getPointArray(index: number): T;
// (undocumented)
getTypedArray(): Float32Array;
// (undocumented)
protected grow(additionalSize?: number, growSize?: number): void;
// (undocumented)
growSize: number;
Expand Down Expand Up @@ -3056,7 +3059,7 @@ type RGB = [number, number, number];
function rgbToHex(r: any, g: any, b: any): string;

// @public (undocumented)
interface RLERun<T> {
interface RLERun_2<T> {
// (undocumented)
end: number;
// (undocumented)
Expand All @@ -3073,18 +3076,42 @@ class RLEVoxelMap<T> {
// (undocumented)
defaultValue: T;
// (undocumented)
delete(index: number): void;
// (undocumented)
protected depth: number;
// (undocumented)
fillFrom(getter: (i: number, j: number, k: number) => T, boundsIJK: BoundsIJK): void;
// (undocumented)
findAdjacents(item: [RLERun<T>, number, number, Point3[]?], { diagonals, planar, singlePlane }: {
diagonals?: boolean;
planar?: boolean;
singlePlane?: boolean;
}): any[];
// (undocumented)
protected findIndex(row: RLERun<T>[], i: number): number;
// (undocumented)
floodFill(i: number, j: number, k: number, value: T, options?: {
planar?: boolean;
diagonals?: boolean;
singlePlane?: boolean;
}): number;
// (undocumented)
forEach(callback: any, options?: {
rowModified?: boolean;
}): void;
// (undocumented)
forEachRow(callback: any): void;
// (undocumented)
get: (index: number) => T;
// (undocumented)
getPixelData(k?: number, pixelData?: PixelDataTypedArray): PixelDataTypedArray;
// (undocumented)
protected getRLE(i: number, j: number, k?: number): RLERun<T> | undefined;
protected getRLE(i: number, j: number, k?: number): RLERun<T>;
// (undocumented)
getRun: (j: number, k: number) => RLERun<T>[];
// (undocumented)
has(index: number): boolean;
// (undocumented)
protected height: number;
// (undocumented)
protected jMultiple: number;
Expand All @@ -3093,14 +3120,20 @@ class RLEVoxelMap<T> {
// (undocumented)
protected kMultiple: number;
// (undocumented)
protected numberOfComponents: number;
normalizer: PlaneNormalizer;
// (undocumented)
protected numComps: number;
// (undocumented)
pixelDataConstructor: Uint8ArrayConstructor;
// (undocumented)
protected rows: Map<number, RLERun<T>[]>;
// (undocumented)
set: (index: number, value: T) => void;
// (undocumented)
toIJK(index: number): Point3;
// (undocumented)
toIndex([i, j, k]: Point3): number;
// (undocumented)
protected width: number;
}

Expand Down Expand Up @@ -3779,7 +3812,7 @@ declare namespace Types {
LocalVolumeOptions,
IVoxelManager,
IRLEVoxelMap,
RLERun,
RLERun_2 as RLERun,
ViewportInput,
ImageLoadRequests,
IBaseVolumeViewport,
Expand Down Expand Up @@ -4808,6 +4841,8 @@ class VoxelManager<T> {
dimension: Point3;
}): IVoxelManager<T>;
// (undocumented)
static createRLEHistoryVoxelManager<T>(sourceVoxelManager: VoxelManager<T>): VoxelManager<T>;
// (undocumented)
static createRLEVoxelManager<T>({ dimensions, }: {
dimensions: Point3;
}): VoxelManager<T>;
Expand Down Expand Up @@ -4837,7 +4872,7 @@ class VoxelManager<T> {
isInObject?: (pointLPS: any, pointIJK: any) => boolean;
returnPoints?: boolean;
imageData?: vtkImageData | CPUImageData;
}) => any[];
}) => void | any[];
// (undocumented)
frameSize: number;
// (undocumented)
Expand Down Expand Up @@ -4897,6 +4932,8 @@ class VoxelManager<T> {
// (undocumented)
resetModifiedSlices(): void;
// (undocumented)
rleForEach(callback: any, options?: any): void;
// (undocumented)
_set: (index: number, v: T) => boolean;
// (undocumented)
setAtIJK: (i: number, j: number, k: number, v: any) => boolean;
Expand All @@ -4922,6 +4959,14 @@ class VoxelManager<T> {
width: number;
}

// @public (undocumented)
enum VoxelManagerEnum {
// (undocumented)
RLE = "RLE",
// (undocumented)
Volume = "Volume"
}

declare namespace windowLevel {
export {
toWindowLevel,
Expand Down
3 changes: 2 additions & 1 deletion common/reviews/api/tools.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -2506,12 +2506,13 @@ type FloodFillOptions = {
onBoundary?: (x: number, y: number, z?: number) => void;
equals?: (a: any, b: any) => boolean;
diagonals?: boolean;
bounds?: Map<number, Types_2.Point2 | Types_2.Point3>;
filter?: (point: any) => boolean;
};

// @public (undocumented)
type FloodFillResult = {
flooded: Types_2.Point2[] | Types_2.Point3[];
boundaries: Types_2.Point2[] | Types_2.Point3[];
};

// @public (undocumented)
Expand Down
2 changes: 1 addition & 1 deletion packages/core/examples/multiVolumeCanvasToWorld/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ async function run() {
Math.floor(evt.clientX - rect.left),
Math.floor(evt.clientY - rect.top),
] as Types.Point2;
// Convert canvas coordiantes to world coordinates
// Convert canvas coordinates to world coordinates
const worldPos = viewport.canvasToWorld(canvasPos);

canvasPosElement.innerText = `canvas: (${canvasPos[0]}, ${canvasPos[1]})`;
Expand Down
29 changes: 29 additions & 0 deletions packages/core/src/enums/VoxelManagerEnum.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
* The voxel manager enum is used to select from various voxel managers.
* This allows different representations of the underlying imaging data for
* a volume or image slice. Some representations are better for some types of
* operations, or are required to support specific sizes of operation data.
*/
enum VoxelManagerEnum {
/**
* The RLE Voxel manager defines rows within a volume as a set of Run Length
* encoded values, where all the values between successive i indices on the
* same row/slice have the given value.
* This is very efficient when there are long runs on i values all having the
* same value, as is typical in many segmentations.
* It is also allows for multi-valued segmentations, for example, having
* segments 1 and 3 for a single run. Note that such segmentations need to
* be converted to simple segmentations for actual display.
*/
RLE = 'RLE',

/**
* The volume voxel manager represents data in a TypeArray that is pixel selection first,
* column second, row third, and finally slice number. This is the same representation
* as Image data used in ITK and VTK.
* This requires a full pixel data TypedArray instance.
*/
Volume = 'Volume',
}

export default VoxelManagerEnum;
2 changes: 2 additions & 0 deletions packages/core/src/enums/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import ViewportStatus from './ViewportStatus';
import ImageQualityStatus from './ImageQualityStatus';
import * as VideoEnums from './VideoEnums';
import MetadataModules from './MetadataModules';
import VoxelManagerEnum from './VoxelManagerEnum';
import { GenerateImageType } from './GenerateImageType';

export {
Expand All @@ -31,5 +32,6 @@ export {
VideoEnums,
MetadataModules,
ImageQualityStatus,
VoxelManagerEnum,
GenerateImageType,
};
9 changes: 8 additions & 1 deletion packages/core/src/loaders/volumeLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import '@kitware/vtk.js/Rendering/Profiles/Volume';
import { ImageVolume } from '../cache/classes/ImageVolume';
import cache from '../cache/cache';
import Events from '../enums/Events';
import type VoxelManagerEnum from '../enums/VoxelManagerEnum';
import eventTarget from '../eventTarget';
import triggerEvent from '../utilities/triggerEvent';

Expand Down Expand Up @@ -38,6 +39,7 @@ interface DerivedVolumeOptions {
targetBuffer?: {
type: PixelDataTypedArrayString;
};
voxelRepresentation?: VoxelManagerEnum;
}

export interface LocalVolumeOptions {
Expand Down Expand Up @@ -204,6 +206,8 @@ export function createAndCacheDerivedVolume(
}

let { volumeId } = options;
const { targetBuffer, voxelRepresentation } = options;
const { type } = targetBuffer;

if (volumeId === undefined) {
volumeId = uuidv4();
Expand Down Expand Up @@ -503,7 +507,10 @@ export function createAndCacheDerivedLabelmapVolume(
): IImageVolume {
return createAndCacheDerivedVolume(referencedVolumeId, {
...options,
targetBuffer: { type: 'Uint8Array' },
targetBuffer: {
type: 'Uint8Array',
...options?.targetBuffer,
},
});
}

Expand Down
4 changes: 3 additions & 1 deletion packages/core/src/types/PixelDataTypedArray.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ export type PixelDataTypedArrayString =
| 'Uint16Array'
| 'Uint8Array'
| 'Int8Array'
| 'Uint8ClampedArray';
| 'Uint8ClampedArray'
// Used to not create an array object
| 'none';
8 changes: 8 additions & 0 deletions packages/core/src/utilities/PointsManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,14 @@ export default class PointsManager<T> {
}
}

/**
* Gets the raw underlying data - note this can change. Use for fast calculations
* on a fully filled array.
*/
public getTypedArray() {
return this.data;
}

/**
* Push a new point onto this arrays object
*/
Expand Down
Loading