Skip to content

[Bug] Various issues with ScaleOverlayTool.ts #2393

@fbuonomo

Description

@fbuonomo

Describe the Bug

Hi, I've made a series of changes to the ScaleOverlayTool.ts file to resolve a number of issues that have arisen during use.
Here are the changes:
On line 75, I've added a check for enabled elements because they may not be there:
if (!enabledElements.length || !enabledElements[0]?.viewport) {
return;
}
In renderAnnotation, I've changed the start of the line as follows because the annotations may not yet be visible:
const renderStatus = false;
const location = this.configuration.scaleLocation;
const { viewport } = enabledElement;
if (!viewport) {
return renderStatus;
}
const annotations = getAnnotations(this.getToolName(), viewport.element);
if (!annotations?.length) {
return renderStatus;
}
const annotation = annotations.filter(
(thisAnnotation) => thisAnnotation.data.viewportId == viewport.id
)[0];
const canvas = enabledElement.viewport.canvas;

if ((annotation?.data?.handles?.points?.length ?? 0) < 4) {
return renderStatus;
}

I also modified the _getTextLines function to prevent the text from referencing cm or mm when pixel spacing information is missing. The modified version:
_hasSpacing() {
const imageId = this.editData.viewport.getCurrentImageId?.();
const imagePlaneModule = metaData.get('imagePlaneModule', imageId);
const spacing = imagePlaneModule?.pixelSpacing ?? null;
return spacing && spacing[0] > 0 && spacing[1] > 0;
}

_getTextLines(scaleSize: number): string[] | undefined {
let scaleSizeDisplayValue;
let scaleSizeUnits;
if (!this._hasSpacing()) {
scaleSizeDisplayValue = scaleSize;
scaleSizeUnits = 'px';
}
else {
if (scaleSize >= 50) {
scaleSizeDisplayValue = scaleSize / 10; //convert to cm
scaleSizeUnits = 'cm';
} else {
scaleSizeDisplayValue = scaleSize; //convert to cm
scaleSizeUnits = 'mm';
}
}
Finally, I modified the return value of the computeScaleSize function because in some cases, scaleSizes.filter may return an empty array.
return currentScaleSize[0] || 2;

With these changes, my application works fine.
If they work, I'd like to see if they can be included in the next release.

I'm attaching the new ScaleOverlayTool.ts file.

ScaleOverlayTool.zip

Steps to Reproduce

Not applicable

The current behavior

abnormal behavior and annotation blocking

The expected behavior

Not applicable

System Information

cornerstone3D versione 4.3.13
node 22.14.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions