Skip to content

Commit

Permalink
feat(dicomImageLoader): make cornerstone to use new dicom image loade…
Browse files Browse the repository at this point in the history
…r and handle scaling correctly (#553)

* rename old example for now

* rename old example for now

* make examples work with dicom image loader

* make dicom image loader everywhere

* fix examples

* fix examples

* wip

* update package json

* try to fix build preview

* types

* refactor: Simplify code & improve accessibility in dicomImageLoaderWADOURI example

* Moved image selection buttons to a dropdown menu for better accessibility.
* Removed unnecessary code from loadAndViewImage function in index.ts file.

* wip

* work with float32 explicit for all

* colors should use uint8Array

* fix scaling issue for rescale slope and intercept

* fix the 8 bit float scaling params

* fix cpu rendering when convertFloatPixelDataToInt is set to true

* work for volume SAB and non SAB and stack GPU

* cpu pipeline work for all including float

* update build

* after rebase

* remove unnecessary code

* remove unnecessary code

* fix(rendering): Upgrade vtk.js and update rendering pipeline

The vtk.js version has been upgraded to 27.2.0, and the rendering pipeline has been updated as well. `use16BitTexture` has been replaced with `useNativeDataType` to support additional configuration flags. `updateRenderingPipeline` has been implemented in `StackViewport` and `Viewport` for updates to the rendering pipeline. `setPreferSizeOverAccuracy` and `setUseCPURendering` have been added to `cornerstone.js`. The demo has been updated with buttons to toggle CPU rendering and size versus accuracy options.

* refactor(imageLoader): move isColorImage to shared directory

This commit moves the isColorImage function from the imageLoader directory to the shared directory to be used across the dicomImageLoader package. It also updates the imports of isColorImage throughout the dicomImageLoader package. The isColorImage function checks whether the image is a color image or not based on the photometric interpretation. The commit also updates the createImage and decodeImageFrame functions to use the isColorImage function and render color image in 8-bit in case of rendering issues.

* feat(rendering): optimize pixel data handling for vtkImageData and other rendering libraries

This commit replaces the "typedArray" property of "StackViewport" with the "pixelArray" property to avoid confusion with TypedArray. We also ensure that the rendering library vtkImageData receives an optimized Uint8Array format for RGB images. Other changes include renaming "getTypedArrayFromMinMax" to "getPixelDataTypeFromMinMax" and returning the pixel data type instead of the TypedArray constructor for better semantic representation. We also ensure that the new function uses the correct numeric range for the different TypedArrays. Finally, in "createImage" and "decodeImageFrame" we apply these changes to improve the performance of rendering with image libraries.

* feat(StackViewport): add processing for color images on CPU fallback

This commit adds handling for color images in vtkImageData obtained through CPU fallback rendering. Images' pixel data was previously loaded as RGBA, so color images were left with the A channel still present, causing problems in some rendering processes. This commit's code processes the pixel data to remove the A channel for color images specifically. Related files have also been updated.

* update api

* refactor

* feat(renderer): add support for RGBA and disable the use of an extra pixel array

Refactor the StackViewport renderer code to add support for RGBA images and uses scalars to update the vtkImageData object that eliminates the need of an extra pixel array to be used. LoadImageToCanvas utility updated to support the use of RGBA.

* wip working cpu and gpu rgb little endian

* feat(dicomImageLoader): Added support for RGB and 8 bits color image types

This commit adds support for RGB and 8 bits color image types while decoding the image data. The commit also updates the code to convert the pixel data to rgba if decoding is done as RGB. The new code also takes alpha values into account when adding them to the pixel data.

* yarn lock

* upgrade vtk

* update api

* feat(imageLoader): add clean build option to webpack configs

The webpack configuration files have been updated to add the clean option for cleaning the output directory before building. This will ensure a clean build and avoid any potential conflicts with previous builds. Additionally, the createImage function in imageLoader has been refactored to use a constant for the useRGBA option instead of conditional statements. Finally, the createImageIdsAndCacheMetaData function has been updated to use SOPInstanceUID or fallback to the value at SOP_INSTANCE_UID.

* fix typo

* try to build

* update api

* add review comments
  • Loading branch information
sedghi authored Apr 26, 2023
1 parent e632cdd commit a01687a
Show file tree
Hide file tree
Showing 95 changed files with 1,698 additions and 437 deletions.
2 changes: 1 addition & 1 deletion .webpack/excludeNodeModulesExcept.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ function excludeNodeModulesExcept(modules) {
});

return function (modulePath) {
if (/cornerstoneWADOImageLoader/.test(modulePath)) {
if (/cornerstoneDICOMImageLoader/.test(modulePath)) {
return true;
}

Expand Down
4 changes: 2 additions & 2 deletions .webpack/webpack.base.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ module.exports = (env, argv, { DIST_DIR }) => {
modules: [path.resolve(PROJECT_ROOT, './node_modules'), SRC_PATH],
extensions: ['.ts', '.tsx', '.js', '.jsx'],
alias: {
'cornerstone-wado-image-loader':
'cornerstone-wado-image-loader/dist/dynamic-import/cornerstoneWADOImageLoader.min.js',
'@cornerstonejs/dicom-image-loader':
'@cornerstonejs/dicom-image-loader/dist/dynamic-import/cornerstoneDICOMImageLoader.min.js',
},
fallback: {
fs: false,
Expand Down
17 changes: 13 additions & 4 deletions common/reviews/api/core.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -1052,7 +1052,7 @@ interface IImage {
// (undocumented)
getCanvas: () => HTMLCanvasElement;
// (undocumented)
getPixelData: () => Array<number>;
getPixelData: () => PixelDataTypedArray;
// (undocumented)
height: number;
// (undocumented)
Expand All @@ -1073,8 +1073,8 @@ interface IImage {
numComps: number;
// (undocumented)
preScale?: {
scaled: boolean;
scalingParameters: {
scaled?: boolean;
scalingParameters?: {
modality?: string;
rescaleSlope?: number;
rescaleIntercept?: number;
Expand Down Expand Up @@ -1671,6 +1671,8 @@ interface IViewport {
// (undocumented)
type: ViewportType;
// (undocumented)
updateRenderingPipeline: () => void;
// (undocumented)
worldToCanvas: (worldPos: Point3) => Point2;
}

Expand Down Expand Up @@ -2045,6 +2047,9 @@ type ScalingParameters = {
// @public (undocumented)
export function setConfiguration(c: Cornerstone3DConfig): void;

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

// @public (undocumented)
export class Settings {
constructor(base?: Settings);
Expand Down Expand Up @@ -2196,6 +2201,8 @@ export class StackViewport extends Viewport implements IStackViewport {
// (undocumented)
unsetColormap: () => void;
// (undocumented)
updateRenderingPipeline: () => void;
// (undocumented)
static get useCustomRenderingPipeline(): boolean;
// (undocumented)
worldToCanvas: (worldPos: Point3) => Point2;
Expand Down Expand Up @@ -2515,7 +2522,7 @@ export class Viewport implements IViewport {
// (undocumented)
sHeight: number;
// (undocumented)
protected _shouldUse16BitTexture(): boolean;
protected _shouldUseNativeDataType(): boolean;
// (undocumented)
readonly suppressEvents: boolean;
// (undocumented)
Expand All @@ -2531,6 +2538,8 @@ export class Viewport implements IViewport {
// (undocumented)
protected updateClippingPlanesForActors(updatedCamera: ICamera): void;
// (undocumented)
updateRenderingPipeline: () => void;
// (undocumented)
static get useCustomRenderingPipeline(): boolean;
// (undocumented)
worldToCanvas: (worldPos: Point3) => Point2;
Expand Down
8 changes: 5 additions & 3 deletions common/reviews/api/streaming-image-volume-loader.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -745,7 +745,7 @@ interface IImage {
columns: number;
// (undocumented)
getCanvas: () => HTMLCanvasElement;
getPixelData: () => Array<number>;
getPixelData: () => PixelDataTypedArray;
height: number;
imageId: string;
intercept: number;
Expand All @@ -757,8 +757,8 @@ interface IImage {
modalityLUT?: CPUFallbackLUT;
numComps: number;
preScale?: {
scaled: boolean;
scalingParameters: {
scaled?: boolean;
scalingParameters?: {
modality?: string;
rescaleSlope?: number;
rescaleIntercept?: number;
Expand Down Expand Up @@ -1138,6 +1138,8 @@ interface IViewport {
sx: number;
sy: number;
type: ViewportType;
// (undocumented)
updateRenderingPipeline: () => void;
worldToCanvas: (worldPos: Point3) => Point2;
}

Expand Down
8 changes: 5 additions & 3 deletions common/reviews/api/tools.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -2444,7 +2444,7 @@ interface IImage {
columns: number;
// (undocumented)
getCanvas: () => HTMLCanvasElement;
getPixelData: () => Array<number>;
getPixelData: () => PixelDataTypedArray;
height: number;
imageId: string;
intercept: number;
Expand All @@ -2456,8 +2456,8 @@ interface IImage {
modalityLUT?: CPUFallbackLUT;
numComps: number;
preScale?: {
scaled: boolean;
scalingParameters: {
scaled?: boolean;
scalingParameters?: {
modality?: string;
rescaleSlope?: number;
rescaleIntercept?: number;
Expand Down Expand Up @@ -2993,6 +2993,8 @@ interface IViewport {
sx: number;
sy: number;
type: ViewportType;
// (undocumented)
updateRenderingPipeline: () => void;
worldToCanvas: (worldPos: Point3) => Point2;
}

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": "26.5.6",
"@kitware/vtk.js": "27.3.1",
"gl-matrix": "^3.4.3"
},
"dependencies": {
"detect-gpu": "^4.0.45",
"lodash.clonedeep": "4.5.0"
},
"devDependencies": {
"@kitware/vtk.js": "26.5.6",
"@kitware/vtk.js": "27.3.1",
"detect-gpu": "^4.0.45",
"gl-matrix": "^3.4.3",
"resemblejs": "^4.1.0"
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/RenderingEngine/BaseVolumeViewport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ abstract class BaseVolumeViewport extends Viewport implements IVolumeViewport {
super(props);

this.useCPURendering = getShouldUseCPURendering();
this.use16BitTexture = this._shouldUse16BitTexture();
this.use16BitTexture = this._shouldUseNativeDataType();

if (this.useCPURendering) {
throw new Error(
Expand Down
Loading

0 comments on commit a01687a

Please sign in to comment.