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

wip Feat/norm16 textures #336

Closed
wants to merge 10 commits into from
Closed
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
46 changes: 41 additions & 5 deletions common/reviews/api/core.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,15 @@ declare namespace CONSTANTS {
}
export { CONSTANTS }

// @public (undocumented)
type Cornerstone3DConfig = {
rendering: {
preferSizeOverAccuracy: boolean;
hasNorm16TextureSupport: boolean;
useCPURendering: boolean;
};
};

// @public (undocumented)
interface CPUFallbackColormap {
// (undocumented)
Expand Down Expand Up @@ -430,9 +439,15 @@ function createAndCacheVolume(volumeId: string, options: VolumeLoaderOptions): P
// @public (undocumented)
function createFloat32SharedArray(length: number): Float32Array;

// @public (undocumented)
function createInt16SharedArray(length: number): Int16Array;

// @public (undocumented)
function createLocalVolume(options: LocalVolumeOptions, volumeId: string, preventCache?: boolean): ImageVolume;

// @public (undocumented)
function createUint16SharedArray(length: number): Uint16Array;

// @public (undocumented)
function createUint8SharedArray(length: number): Uint8Array;

Expand All @@ -450,6 +465,9 @@ interface CustomEvent_2<T = any> extends Event {
initCustomEvent(typeArg: string, canBubbleArg: boolean, cancelableArg: boolean, detailArg: T): void;
}

// @public (undocumented)
const deepMerge: (target?: {}, source?: {}, optionsArgument?: any) => any;

// @public (undocumented)
type ElementDisabledEvent = CustomEvent_2<ElementDisabledEventDetail>;

Expand Down Expand Up @@ -601,6 +619,9 @@ function getClosestImageId(imageVolume: IImageVolume, worldPos: Point3, viewPlan
// @public (undocumented)
function getClosestStackImageIndexForPoint(point: Point3, viewport: IStackViewport): number | null;

// @public (undocumented)
export function getConfiguration(): Cornerstone3DConfig;

// @public (undocumented)
export function getEnabledElement(element: HTMLDivElement | undefined): IEnabledElement | undefined;

Expand Down Expand Up @@ -634,6 +655,12 @@ export function getRenderingEngines(): IRenderingEngine[] | undefined;
// @public (undocumented)
function getRuntimeId(context?: unknown, separator?: string, max?: number): string;

// @public (undocumented)
function getScalarDataType(scalingParameters: ScalingParameters, scalarData?: any): string;

// @public (undocumented)
function getScalingParameters(imageId: string): ScalingParameters;

// @public (undocumented)
export function getShouldUseCPURendering(): boolean;

Expand Down Expand Up @@ -883,7 +910,7 @@ interface IImageData {
};
};
// (undocumented)
scalarData: Float32Array;
scalarData: Float32Array | Uint16Array | Uint8Array | Int16Array;
// (undocumented)
scaling?: Scaling;
// (undocumented)
Expand Down Expand Up @@ -1101,7 +1128,7 @@ export class ImageVolume implements IImageVolume {
// (undocumented)
referencedVolumeId?: string;
// (undocumented)
scalarData: Float32Array | Uint8Array;
scalarData: Float32Array | Uint8Array | Uint16Array | Int16Array;
// (undocumented)
scaling?: {
PET?: {
Expand Down Expand Up @@ -1134,7 +1161,7 @@ type ImageVolumeModifiedEventDetail = {
function indexWithinDimensions(index: Point3, dimensions: Point3): boolean;

// @public (undocumented)
export function init(defaultConfiguration?: {}): Promise<boolean>;
export function init(configuration?: {}): Promise<boolean>;

// @public (undocumented)
enum InterpolationType {
Expand Down Expand Up @@ -1398,7 +1425,7 @@ interface IVolume {
// (undocumented)
referencedVolumeId?: string;
// (undocumented)
scalarData: Float32Array | Uint8Array;
scalarData: Float32Array | Uint8Array | Uint16Array | Int16Array;
// (undocumented)
scaling?: {
PET?: {
Expand Down Expand Up @@ -1736,6 +1763,9 @@ type ScalingParameters = {
suvbsa?: number;
};

// @public (undocumented)
export function setPreferSizeOverAccuracy(status: boolean): void;

// @public (undocumented)
export class Settings {
constructor(base?: Settings);
Expand Down Expand Up @@ -1931,6 +1961,7 @@ export function triggerEvent(el: EventTarget, type: string, detail?: unknown): b

declare namespace Types {
export {
Cornerstone3DConfig,
ICamera,
IStackViewport,
IVolumeViewport,
Expand Down Expand Up @@ -2014,6 +2045,8 @@ declare namespace utilities {
isOpposite,
createFloat32SharedArray,
createUint8SharedArray,
createUint16SharedArray,
createInt16SharedArray,
windowLevel,
getClosestImageId,
getSpacingInNormalDirection,
Expand All @@ -2037,7 +2070,10 @@ declare namespace utilities {
spatialRegistrationMetadataProvider,
getViewportImageCornersInWorld,
hasNaNValues,
applyPreset
applyPreset,
deepMerge,
getScalingParameters,
getScalarDataType
}
}
export { utilities }
Expand Down
33 changes: 30 additions & 3 deletions common/reviews/api/streaming-image-volume-loader.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,33 @@ type CameraModifiedEventDetail = {
rotation?: number;
};

// @public (undocumented)
type Cornerstone3DConfig = {
rendering: {
// vtk.js supports 8bit integer textures and 32bit float textures.
// However, if the client has norm16 textures (it can be seen by visiting
// the webGl report at https://webglreport.com/?v=2), vtk will be default
// to use it to improve memory usage. However, if the client don't have
// it still another level of optimization can happen by setting the
// preferSizeOverAccuracy since it will reduce the size of the texture to half
// float at the cost of accuracy in rendering. This is a tradeoff that the
// client can decide.
//
// Read more in the following Pull Request:
// 1. HalfFloat: https://github.com/Kitware/vtk-js/pull/2046
// 2. Norm16: https://github.com/Kitware/vtk-js/pull/2058
preferSizeOverAccuracy: boolean;
// Whether the EXT_texture_norm16 extension is supported by the browser.
// WebGL 2 report (link: https://webglreport.com/?v=2) can be used to check
// if the browser supports this extension.
// In case the browser supports this extension, instead of using 32bit float
// textures, 16bit float textures will be used to reduce the memory usage where
// possible.
hasNorm16TextureSupport: boolean;
useCPURendering: boolean;
};
};

// @public (undocumented)
export function cornerstoneStreamingImageVolumeLoader(volumeId: string, options: {
imageIds: string[];
Expand Down Expand Up @@ -617,7 +644,7 @@ interface IImageData {
suvbw?: number;
};
};
scalarData: Float32Array;
scalarData: Float32Array | Uint16Array | Uint8Array | Int16Array;
scaling?: Scaling;
spacing: Point3;
}
Expand Down Expand Up @@ -941,7 +968,7 @@ interface IVolume {
metadata: Metadata;
origin: Point3;
referencedVolumeId?: string;
scalarData: Float32Array | Uint8Array;
scalarData: Float32Array | Uint8Array | Uint16Array | Int16Array;
scaling?: {
PET?: {
// @TODO: Do these values exist?
Expand Down Expand Up @@ -1216,7 +1243,7 @@ export class StreamingImageVolume extends ImageVolume {
arrayBuffer: ArrayBufferLike;
offset: number;
length: number;
type: any;
type: string;
};
preScale: {
enabled: boolean;
Expand Down
35 changes: 29 additions & 6 deletions common/reviews/api/tools.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,33 @@ declare namespace CONSTANTS {
}
export { CONSTANTS }

// @public (undocumented)
type Cornerstone3DConfig = {
rendering: {
// vtk.js supports 8bit integer textures and 32bit float textures.
// However, if the client has norm16 textures (it can be seen by visiting
// the webGl report at https://webglreport.com/?v=2), vtk will be default
// to use it to improve memory usage. However, if the client don't have
// it still another level of optimization can happen by setting the
// preferSizeOverAccuracy since it will reduce the size of the texture to half
// float at the cost of accuracy in rendering. This is a tradeoff that the
// client can decide.
//
// Read more in the following Pull Request:
// 1. HalfFloat: https://github.com/Kitware/vtk-js/pull/2046
// 2. Norm16: https://github.com/Kitware/vtk-js/pull/2058
preferSizeOverAccuracy: boolean;
// Whether the EXT_texture_norm16 extension is supported by the browser.
// WebGL 2 report (link: https://webglreport.com/?v=2) can be used to check
// if the browser supports this extension.
// In case the browser supports this extension, instead of using 32bit float
// textures, 16bit float textures will be used to reduce the memory usage where
// possible.
hasNorm16TextureSupport: boolean;
useCPURendering: boolean;
};
};

// @public (undocumented)
const CORNERSTONE_COLOR_LUT: number[][];

Expand Down Expand Up @@ -1200,9 +1227,6 @@ function debounce(func: Function, wait?: number, options?: {
trailing?: boolean;
}): Function;

// @public (undocumented)
function deepmerge(target?: {}, source?: {}, optionsArgument?: any): any;

// @public (undocumented)
const _default: {
filterAnnotationsWithinSlice: typeof filterAnnotationsWithinSlice;
Expand Down Expand Up @@ -2076,7 +2100,7 @@ interface IImageData {
suvbw?: number;
};
};
scalarData: Float32Array;
scalarData: Float32Array | Uint16Array | Uint8Array | Int16Array;
scaling?: Scaling;
spacing: Point3;
}
Expand Down Expand Up @@ -2535,7 +2559,7 @@ interface IVolume {
metadata: Metadata;
origin: Point3;
referencedVolumeId?: string;
scalarData: Float32Array | Uint8Array;
scalarData: Float32Array | Uint8Array | Uint16Array | Int16Array;
scaling?: {
PET?: {
// @TODO: Do these values exist?
Expand Down Expand Up @@ -4614,7 +4638,6 @@ declare namespace utilities {
viewportFilters,
drawing_2 as drawing,
debounce,
deepmerge as deepMerge,
throttle,
orientation_2 as orientation,
isObject,
Expand Down
43 changes: 42 additions & 1 deletion packages/core/examples/volumeAPI/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import {
volumeLoader,
getRenderingEngine,
utilities,
CONSTANTS,
hasNorm16TextureSupport,
hasActiveWebGLContext,
getConfiguration,
} from '@cornerstonejs/core';
import {
initDemo,
Expand Down Expand Up @@ -45,7 +47,31 @@ element.id = 'cornerstone-element';
element.style.width = '500px';
element.style.height = '500px';

const element1 = document.createElement('p');
const element2 = document.createElement('p');
const element3 = document.createElement('p');
const element4 = document.createElement('p');
const element5 = document.createElement('p');
const element6 = document.createElement('p');
const element7 = document.createElement('p');

// update the element div text to have hasNorm16TextureSupport
element2.innerText = `hasNorm16TextureSupport: ${hasNorm16TextureSupport()}`;
element2.style.color = 'blue';

element3.innerText = `isWebGL2Supported: ${hasActiveWebGLContext()}`;
element3.style.color = 'blue';

content.appendChild(element1);
content.appendChild(element2);
content.appendChild(element3);
content.appendChild(element5);
content.appendChild(element4);
content.appendChild(element6);
content.appendChild(element7);

content.appendChild(element);

// ============================= //

// TODO -> Maybe some of these implementations should be pushed down to some API
Expand Down Expand Up @@ -286,6 +312,21 @@ async function run() {
type: 'VOLUME',
});

// @ts-ignore
const gpuConfig = getConfiguration().detectGPU;
const useCPURendering = getConfiguration().rendering.useCPURendering;
element4.innerText = `GPU Tier: ${JSON.stringify(gpuConfig)}`;
element4.style.color = 'blue';

element5.innerText = `Use CPU Rendering: ${useCPURendering}`;
element5.style.color = 'blue';

element6.innerText = `platform: ${navigator.platform}`;
element6.style.color = 'blue';

element7.innerText = `appVersion: ${navigator.appVersion}`;
element7.style.color = 'blue';

// Instantiate a rendering engine
const renderingEngine = new RenderingEngine(renderingEngineId);

Expand Down
4 changes: 2 additions & 2 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@
"webpack:watch": "webpack --mode development --progress --watch --config ./.webpack/webpack.dev.js"
},
"peerDependencies": {
"@kitware/vtk.js": "25.9.0",
"@kitware/vtk.js": "25.15.1",
"gl-matrix": "^3.4.3"
},
"dependencies": {
"detect-gpu": "^4.0.45",
"lodash.clonedeep": "4.5.0"
},
"devDependencies": {
"@kitware/vtk.js": "25.9.0",
"@kitware/vtk.js": "25.15.1",
"detect-gpu": "^4.0.45",
"gl-matrix": "^3.4.3",
"resemblejs": "^4.1.0"
Expand Down
Loading