Skip to content

Commit

Permalink
fix: average blend mode and trackball rotate reset camera (#1700)
Browse files Browse the repository at this point in the history
* fix average blend mode

* feat: add decodeImageFrame function and improve VoxelManager image handling

- Introduced a new public function `decodeImageFrame` in the DICOM image loader API for decoding image frames asynchronously.
- Updated the `VoxelManager` class to skip processing for unloaded images and return a default range if no images are loaded.
- Integrated the new `decodeImageFrame` function into the cornerstone DICOM image loader module.

* fix: enhance TrackballRotateTool camera reset functionality

- Added retrieval and restoration of the view presentation in the TrackballRotateTool.
- Ensured that the viewport's camera reset maintains the current view presentation after rendering.
  • Loading branch information
sedghi authored Dec 11, 2024
1 parent dd6a80b commit 0f3f4a0
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 1 deletion.
4 changes: 4 additions & 0 deletions common/reviews/api/dicom-image-loader.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,16 @@ const cornerstoneDICOMImageLoader: {
setOptions: setOptions;
getOptions: getOptions;
};
decodeImageFrame: typeof decodeImageFrame;
};
export default cornerstoneDICOMImageLoader;

// @public (undocumented)
export function createImage(imageId: string, pixelData: ByteArray, transferSyntax: string, options?: DICOMLoaderImageOptions): Promise<DICOMLoaderIImage | Types_2.IImageFrame>;

// @public (undocumented)
export function decodeImageFrame(imageFrame: any, transferSyntax: any, pixelData: any, decodeConfig: any, options: any, callbackFn: any): Promise<any>;

// @public (undocumented)
export function decodeJPEGBaseline8BitColor(imageFrame: Types_2.IImageFrame, pixelData: ByteArray, canvas: HTMLCanvasElement): Promise<Types_2.IImageFrame>;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,15 @@ function vtkStreamingOpenGLTexture(publicAPI, model) {
);
};

const superUpdate = publicAPI.updateVolumeInfoForGL;

publicAPI.updateVolumeInfoForGL = (dataType, numComps) => {
const isScalingApplied = superUpdate(dataType, numComps);
model.volumeInfo.dataComputedScale = [1];
model.volumeInfo.dataComputedOffset = [0];
return isScalingApplied;
};

/**
* This function updates the GPU texture memory to match the current
* representation of data held in RAM.
Expand Down
11 changes: 11 additions & 0 deletions packages/core/src/utilities/VoxelManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -796,6 +796,11 @@ export default class VoxelManager<T> {
for (const imageId of imageIds) {
const image = cache.getImage(imageId);

// Skip if image not loaded yet
if (!image) {
continue;
}

// min and max pixel value is correct, //todo this is not true
// for dynamically changing data such as labelmaps in segmentation
if (image.minPixelValue < minValue) {
Expand All @@ -805,6 +810,12 @@ export default class VoxelManager<T> {
maxValue = image.maxPixelValue;
}
}

// If no images were loaded yet, return default range
if (minValue === Infinity && maxValue === -Infinity) {
return [0, 0];
}

return [minValue, maxValue];
};

Expand Down
2 changes: 1 addition & 1 deletion packages/dicomImageLoader/src/decodeImageFrameWorker.js
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ function scaleImageFrame(imageFrame, targetBuffer, TypedArrayConstructor) {
* This is an async function return the result, or you can provide an optional
* callbackFn that is called with the results.
*/
async function decodeImageFrame(
export async function decodeImageFrame(
imageFrame,
transferSyntax,
pixelData,
Expand Down
3 changes: 3 additions & 0 deletions packages/dicomImageLoader/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { default as getPixelData } from './imageLoader/wadors/getPixelData';
import { internal } from './imageLoader/internal/index';
import * as constants from './constants';
import type * as Types from './types';
import { decodeImageFrame } from './decodeImageFrameWorker';

const cornerstoneDICOMImageLoader = {
constants,
Expand All @@ -40,6 +41,7 @@ const cornerstoneDICOMImageLoader = {
isColorImage,
isJPEGBaseline8BitColor,
internal,
decodeImageFrame,
};

export {
Expand All @@ -61,6 +63,7 @@ export {
isColorImage,
isJPEGBaseline8BitColor,
internal,
decodeImageFrame,
};

export type { Types };
Expand Down
5 changes: 5 additions & 0 deletions packages/tools/src/tools/TrackballRotateTool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,12 @@ class TrackballRotateTool extends BaseTool {
return;
}
const { viewport } = element;

const viewPresentation = viewport.getViewPresentation();

viewport.resetCamera();

viewport.setViewPresentation(viewPresentation);
viewport.render();
});

Expand Down

0 comments on commit 0f3f4a0

Please sign in to comment.