Skip to content

Commit

Permalink
Fix mm/px (#331)
Browse files Browse the repository at this point in the history
* fixed tools length, rectangleRoi, ellipticalRoi + imageTracker

* build + version + docs

* Update docs

* logs removed + rebuild

* Update docs

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
1 parent f11078c commit 2a92943
Show file tree
Hide file tree
Showing 11 changed files with 156 additions and 20 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@

## Dicom Image Toolkit for CornerstoneJS

### Current version: 2.4.11
### Current version: 2.4.12

### Latest Published Release: 2.4.11
### Latest Published Release: 2.4.12

This library provides common DICOM functionalities to be used in web-applications: it's wrapper that simplifies the use of cornerstone-js environment.

Expand Down
2 changes: 1 addition & 1 deletion dist/larvitar.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/larvitar.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/documentation/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ <h3> </h3>
<h1 id="larvitar">Larvitar</h1>
<p><a href="https://github.com/dvisionlab/Larvitar"><img src="https://img.shields.io/badge/dynamic/json.svg?label=type-coverage&amp;prefix=%E2%89%A5&amp;suffix=%25&amp;query=$.typeCoverage.atLeast&amp;uri=https%3A%2F%2Fraw.githubusercontent.com%2Fplantain-00%2Ftype-coverage%2Fmaster%2Fpackage.json" alt="type-coverage"></a></p>
<h2 id="dicom-image-toolkit-for-cornerstonejs">Dicom Image Toolkit for CornerstoneJS</h2>
<h3 id="current-version%3A-2.4.11">Current version: 2.4.11</h3>
<h3 id="latest-published-release%3A-2.4.11">Latest Published Release: 2.4.11</h3>
<h3 id="current-version%3A-2.4.12">Current version: 2.4.12</h3>
<h3 id="latest-published-release%3A-2.4.12">Latest Published Release: 2.4.12</h3>
<p>This library provides common DICOM functionalities to be used in web-applications: it's wrapper that simplifies the use of cornerstone-js environment.</p>
<h2 id="features%3A">Features:</h2>
<ul>
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/larvitar.js

Large diffs are not rendered by default.

8 changes: 6 additions & 2 deletions imaging/imageLoading.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ import { loadReslicedImage } from "./loaders/resliceLoader";
import { loadMultiFrameImage } from "./loaders/multiframeLoader";
import { loadDsaImage } from "./loaders/dsaImageLoader";
import { ImageObject, Instance, Series, StagedProtocol } from "./types";
import { getLarvitarManager } from "./loaders/commonLoader";
import {
getLarvitarImageTracker,
getLarvitarManager
} from "./loaders/commonLoader";

/**
* Global standard configuration
Expand Down Expand Up @@ -154,6 +157,7 @@ export const updateLoadedStack = function (
customId?: string,
sliceIndex?: number
) {
let imageTracker = getLarvitarImageTracker();
let lid = seriesData.metadata.larvitarSeriesInstanceUID;
let sid = seriesData.metadata.seriesUID;
let ssid = seriesData.metadata.studyUID;
Expand Down Expand Up @@ -250,7 +254,7 @@ export const updateLoadedStack = function (
let imageId = cornerstoneDICOMImageLoader.wadouri.fileManager.add(
seriesData.file
) as string;

imageTracker[imageId] = lid as string;
if (sliceIndex !== undefined) {
allSeriesStack[id].imageIds[sliceIndex] = imageId;
} else {
Expand Down
41 changes: 39 additions & 2 deletions imaging/tools/custom/EllipticalRoiUSTool.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//external imports
import cornerstoneTools from "cornerstone-tools";
import { default as cornerstoneDICOMImageLoader } from "cornerstone-wado-image-loader";
const external = cornerstoneTools.external;
const BaseAnnotationTool = cornerstoneTools.importInternal(
"base/BaseAnnotationTool"
Expand Down Expand Up @@ -49,9 +50,10 @@ import {
Rectangle,
Stats
} from "../types";
import { StoreViewport } from "../../types";
import { LarvitarManager, Series, StoreViewport } from "../../types";
import store from "../../imageStore";

import { getLarvitarImageTracker } from "../../loaders/commonLoader";
import { getLarvitarManager } from "../../loaders/commonLoader";
/**
* @public
* @class EllipticalRoiTool
Expand Down Expand Up @@ -199,6 +201,25 @@ export default class EllipticalRoiTool extends BaseAnnotationTool {
data: MeasurementData
) {
const pixelSpacing: PixelSpacing = getPixelSpacing(image);
if (
pixelSpacing.rowPixelSpacing ||
pixelSpacing.colPixelSpacing === undefined
) {
let parsedImageId = cornerstoneDICOMImageLoader.wadouri.parseImageId(
image.imageId
);
let rootImageId = parsedImageId.scheme + ":" + parsedImageId.url;
let imageTracker = getLarvitarImageTracker();
let seriesId = imageTracker[rootImageId];
let manager = getLarvitarManager() as LarvitarManager;
if (manager && seriesId) {
let series = manager[seriesId] as Series;
pixelSpacing.rowPixelSpacing =
series.instances[image.imageId].metadata.pixelSpacing![0];
pixelSpacing.colPixelSpacing =
series.instances[image.imageId].metadata.pixelSpacing![1];
}
}

const stats: Stats = _calculateStats(
image,
Expand Down Expand Up @@ -237,6 +258,22 @@ export default class EllipticalRoiTool extends BaseAnnotationTool {
colPixelSpacing = image.columnPixelSpacing;
rowPixelSpacing = image.rowPixelSpacing;
}
if (rowPixelSpacing || colPixelSpacing === undefined) {
let parsedImageId = cornerstoneDICOMImageLoader.wadouri.parseImageId(
eventData.image.imageId
);
let rootImageId = parsedImageId.scheme + ":" + parsedImageId.url;
let imageTracker = getLarvitarImageTracker();
let seriesId = imageTracker[rootImageId];
let manager = getLarvitarManager() as LarvitarManager;
if (manager && seriesId) {
let series = manager[seriesId] as Series;
rowPixelSpacing =
series.instances[eventData.image.imageId].metadata.pixelSpacing![0];
colPixelSpacing =
series.instances[eventData.image.imageId].metadata.pixelSpacing![1];
}
}
const hasPixelSpacing: boolean =
rowPixelSpacing != undefined &&
rowPixelSpacing != 0 &&
Expand Down
44 changes: 41 additions & 3 deletions imaging/tools/custom/FreehandRoiUSTool.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//external imports
import csTools from "cornerstone-tools";
import { default as cornerstoneDICOMImageLoader } from "cornerstone-wado-image-loader";
// cornerstone tools imports
const external = csTools.external;
const EVENTS = csTools.EVENTS;
Expand Down Expand Up @@ -27,6 +28,7 @@ const throttle = csTools.importInternal("util/throttle");
const freehandUtils = csTools.importInternal("util/freehandUtils");
const getModule = csTools.getModule;
const state = getModule("segmentation").state;

const {
insertOrDelete,
freehandArea,
Expand All @@ -37,7 +39,8 @@ const {

//internal imports
import store from "../../imageStore";

import { getLarvitarImageTracker } from "../../loaders/commonLoader";
import { getLarvitarManager } from "../../loaders/commonLoader";
/**
* @public
* @class FreehandRoiTool
Expand Down Expand Up @@ -318,6 +321,23 @@ export default class FreehandRoiTool extends BaseAnnotationTool {
colPixelSpacing = image.columnPixelSpacing;
rowPixelSpacing = image.rowPixelSpacing;
}
if (rowPixelSpacing || colPixelSpacing === undefined) {
let parsedImageId = cornerstoneDICOMImageLoader.wadouri.parseImageId(
image.imageId
);
let rootImageId = parsedImageId.scheme + ":" + parsedImageId.url;
let imageTracker = getLarvitarImageTracker();
let seriesId = imageTracker[rootImageId];
let manager = getLarvitarManager();
if (manager && seriesId) {
let series = manager[seriesId];
rowPixelSpacing =
series.instances[image.imageId].metadata.pixelSpacing[0];
colPixelSpacing =
series.instances[image.imageId].metadata.pixelSpacing[1];
}
}

const scaling = (colPixelSpacing || 1) * (rowPixelSpacing || 1);

const area = freehandArea(data.handles.points, scaling);
Expand Down Expand Up @@ -546,6 +566,24 @@ export default class FreehandRoiTool extends BaseAnnotationTool {
colPixelSpacing = image.columnPixelSpacing;
rowPixelSpacing = image.rowPixelSpacing;
}
if (rowPixelSpacing || colPixelSpacing === undefined) {
let parsedImageId = cornerstoneDICOMImageLoader.wadouri.parseImageId(
eventData.image.imageId
);
let rootImageId = parsedImageId.scheme + ":" + parsedImageId.url;
let imageTracker = getLarvitarImageTracker();
let seriesId = imageTracker[rootImageId];
let manager = getLarvitarManager();
if (manager && seriesId) {
let series = manager[seriesId];
rowPixelSpacing =
series.instances[eventData.image.imageId].metadata
.pixelSpacing[0];
colPixelSpacing =
series.instances[eventData.image.imageId].metadata
.pixelSpacing[1];
}
}

if (
rowPixelSpacing === undefined ||
Expand Down Expand Up @@ -1501,7 +1539,7 @@ export default class FreehandRoiTool extends BaseAnnotationTool {
this._drawingInteractionType = interactionType;

state.isMultiPartToolActive = true;
hideToolCursor(this.element);
// hideToolCursor(this.element);

// Polygonal Mode
element.addEventListener(EVENTS.MOUSE_DOWN, this._drawingMouseDownCallback);
Expand Down Expand Up @@ -1548,7 +1586,7 @@ export default class FreehandRoiTool extends BaseAnnotationTool {
state.isMultiPartToolActive = false;
this._activeDrawingToolReference = null;
this._drawingInteractionType = null;
setToolCursor(this.element, this.svgCursor);
//setToolCursor(this.element, this.svgCursor);

element.removeEventListener(
EVENTS.MOUSE_DOWN,
Expand Down
23 changes: 22 additions & 1 deletion imaging/tools/custom/LengthUSTool.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// external libraries
import cornerstoneTools from "cornerstone-tools";
import { default as cornerstoneDICOMImageLoader } from "cornerstone-wado-image-loader";
const getToolState = cornerstoneTools.getToolState;
const toolColors = cornerstoneTools.toolColors;
const draw = cornerstoneTools.importInternal("drawing/draw");
Expand Down Expand Up @@ -29,8 +30,10 @@ import {
EventData
} from "../types";

import { StoreViewport } from "../../types";
import { LarvitarManager, Series, StoreViewport } from "../../types";
import store from "../../imageStore";
import { getLarvitarImageTracker } from "../../loaders/commonLoader";
import { getLarvitarManager } from "../../loaders/commonLoader";
/*
/**
*
Expand Down Expand Up @@ -194,6 +197,24 @@ export default class LengthTool extends BaseAnnotationTool {
colPixelSpacing = image.columnPixelSpacing;
rowPixelSpacing = image.rowPixelSpacing;
}

if (rowPixelSpacing || colPixelSpacing === undefined) {
let parsedImageId = cornerstoneDICOMImageLoader.wadouri.parseImageId(
eventData.image.imageId
);
let rootImageId = parsedImageId.scheme + ":" + parsedImageId.url;
let imageTracker = getLarvitarImageTracker();
let seriesId = imageTracker[rootImageId];
let manager = getLarvitarManager() as LarvitarManager;
if (manager && seriesId) {
let series = manager[seriesId] as Series;
rowPixelSpacing =
series.instances[eventData.image.imageId].metadata.pixelSpacing![0];
colPixelSpacing =
series.instances[eventData.image.imageId].metadata.pixelSpacing![1];
}
}

const lineWidth: number = toolStyle.getToolWidth();
const lineDash: boolean = getModule("globalConfiguration").configuration
.lineDash;
Expand Down
44 changes: 40 additions & 4 deletions imaging/tools/custom/RectangleRoiUSTool.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//external imports
import cornerstoneTools from "cornerstone-tools";
import { default as cornerstoneDICOMImageLoader } from "cornerstone-wado-image-loader";
const external = cornerstoneTools.external;
const BaseAnnotationTool = cornerstoneTools.importInternal(
"base/BaseAnnotationTool"
Expand Down Expand Up @@ -43,8 +44,10 @@ import {
Rectangle,
Stats
} from "../types";
import { StoreViewport } from "../../types";
import { LarvitarManager, Series, StoreViewport } from "../../types";
import store from "../../imageStore";
import { getLarvitarImageTracker } from "../../loaders/commonLoader";
import { getLarvitarManager } from "../../loaders/commonLoader";

/**
* @public
Expand Down Expand Up @@ -172,6 +175,25 @@ export default class RectangleRoiTool extends BaseAnnotationTool {
) {
const pixelSpacing: { colPixelSpacing: number; rowPixelSpacing: number } =
getPixelSpacing(image);
if (
pixelSpacing.rowPixelSpacing ||
pixelSpacing.colPixelSpacing === undefined
) {
let parsedImageId = cornerstoneDICOMImageLoader.wadouri.parseImageId(
image.imageId
);
let rootImageId = parsedImageId.scheme + ":" + parsedImageId.url;
let imageTracker = getLarvitarImageTracker();
let seriesId = imageTracker[rootImageId];
let manager = getLarvitarManager() as LarvitarManager;
if (manager && seriesId) {
let series = manager[seriesId] as Series;
pixelSpacing.rowPixelSpacing =
series.instances[image.imageId].metadata.pixelSpacing![0];
pixelSpacing.colPixelSpacing =
series.instances[image.imageId].metadata.pixelSpacing![1];
}
}

const stats: Stats = _calculateStats(
image,
Expand Down Expand Up @@ -205,13 +227,27 @@ export default class RectangleRoiTool extends BaseAnnotationTool {
const context: CanvasRenderingContext2D = getNewContext(
eventData.canvasContext.canvas
);
let { rowPixelSpacing, colPixelSpacing }: PixelSpacing =
getPixelSpacing(image);
let { rowPixelSpacing, colPixelSpacing }: PixelSpacing = getPixelSpacing;
if (this.modality === "US") {
colPixelSpacing = image.columnPixelSpacing;
rowPixelSpacing = image.rowPixelSpacing;
}

if (rowPixelSpacing || colPixelSpacing === undefined) {
let parsedImageId = cornerstoneDICOMImageLoader.wadouri.parseImageId(
eventData.image.imageId
);
let rootImageId = parsedImageId.scheme + ":" + parsedImageId.url;
let imageTracker = getLarvitarImageTracker();
let seriesId = imageTracker[rootImageId];
let manager = getLarvitarManager() as LarvitarManager;
if (manager && seriesId) {
let series = manager[seriesId] as Series;
rowPixelSpacing =
series.instances[eventData.image.imageId].metadata.pixelSpacing![0];
colPixelSpacing =
series.instances[eventData.image.imageId].metadata.pixelSpacing![1];
}
}
const hasPixelSpacing: boolean =
rowPixelSpacing != undefined &&
rowPixelSpacing != 0 &&
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"medical",
"cornerstone"
],
"version": "2.4.11",
"version": "2.4.12",
"description": "typescript library for parsing, loading, rendering and interacting with DICOM images",
"repository": {
"url": "https://github.com/dvisionlab/Larvitar.git",
Expand Down

0 comments on commit 2a92943

Please sign in to comment.