Skip to content

Commit

Permalink
fix(adapters): Update the build a little to allow debugging into type…
Browse files Browse the repository at this point in the history
…script (#439)

* fix: Update the build a little to allow debugging into typescript

* fix: Minor change to make the comparison fully case insensitive
  • Loading branch information
wayfarer3130 authored Feb 17, 2023
1 parent 34562bf commit 05e6419
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 25 deletions.
3 changes: 2 additions & 1 deletion packages/adapters/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"version": "0.3.1",
"description": "Adapters for Cornerstone3D to/from formats including DICOM SR and others",
"src": "src/index.ts",
"main": "src/index.ts",
"main": "./dist/@cornerstonejs/adapters.es.js",
"module": "src/index.ts",
"files": [
"dist"
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,21 @@ import { vec3 } from "gl-matrix";
import { utilities } from "dcmjs";
import CORNERSTONE_3D_TAG from "./cornerstone3DTag";
import MeasurementReport from "./MeasurementReport";
import isValidCornerstoneTrackingIdentifier from "./isValidCornerstoneTrackingIdentifier";

const { Ellipse: TID300Ellipse } = utilities.TID300;

const ELLIPTICALROI = "EllipticalROI";
const EPSILON = 1e-4;

const trackingIdentifierTextValue = `${CORNERSTONE_3D_TAG}:${ELLIPTICALROI}`;

class EllipticalROI {
static trackingIdentifierTextValue = `${CORNERSTONE_3D_TAG}:${ELLIPTICALROI}`;
static toolType = ELLIPTICALROI;
static utilityToolType = ELLIPTICALROI;
static TID300Representation = TID300Ellipse;
static isValidCornerstoneTrackingIdentifier =
isValidCornerstoneTrackingIdentifier;

static getMeasurementData(
MeasurementGroup,
sopInstanceUIDToImageIdMap,
Expand Down Expand Up @@ -149,7 +155,7 @@ class EllipticalROI {
const topBottomLength = Math.abs(top[1] - bottom[1]);
const leftRightLength = Math.abs(left[0] - right[0]);

let points = [];
const points = [];
if (topBottomLength > leftRightLength) {
// major axis is bottom to top
points.push({ x: top[0], y: top[1] });
Expand All @@ -173,32 +179,13 @@ class EllipticalROI {
return {
area,
points,
trackingIdentifierTextValue,
trackingIdentifierTextValue: this.trackingIdentifierTextValue,
finding,
findingSites: findingSites || []
};
}
}

EllipticalROI.toolType = ELLIPTICALROI;
EllipticalROI.utilityToolType = ELLIPTICALROI;
EllipticalROI.TID300Representation = TID300Ellipse;
EllipticalROI.isValidCornerstoneTrackingIdentifier = TrackingIdentifier => {
if (!TrackingIdentifier.includes(":")) {
return false;
}

const [cornerstone3DTag, toolType] = TrackingIdentifier.split(":");

if (cornerstone3DTag !== CORNERSTONE_3D_TAG) {
return false;
}

// The following is needed since the new cornerstone3D has changed
// the EllipticalRoi toolName (which was in the old cornerstone) to EllipticalROI
return toolType.toLowerCase() === ELLIPTICALROI.toLowerCase();
};

MeasurementReport.registerTool(EllipticalROI);

export default EllipticalROI;
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { normalizers, data, utilities, derivations } from "dcmjs";

import CORNERSTONE_3D_TAG from "./cornerstone3DTag";
import { toArray, codeMeaningEquals } from "../helpers";
import Cornerstone3DCodingScheme from "./CodingScheme";

Expand Down Expand Up @@ -82,6 +83,7 @@ function getMeasurementGroup(
}

export default class MeasurementReport {
public static CORNERSTONE_3D_TAG = CORNERSTONE_3D_TAG;
public static MEASUREMENT_BY_TOOLTYPE = {};
public static CORNERSTONE_TOOL_CLASSES_BY_UTILITY_TYPE = {};
public static CORNERSTONE_TOOL_CLASSES_BY_TOOL_TYPE = {};
Expand Down Expand Up @@ -419,7 +421,11 @@ export default class MeasurementReport {
return measurementData;
}

static registerTool(toolClass) {
/**
* Register a new tool type.
* @param toolClass to perform I/O to DICOM for this tool
*/
public static registerTool(toolClass) {
MeasurementReport.CORNERSTONE_TOOL_CLASSES_BY_UTILITY_TYPE[
toolClass.utilityToolType
] = toolClass;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import CORNERSTONE_3D_TAG from "./cornerstone3DTag";

export default function isValidCornerstoneTrackingIdentifier(
trackingIdentifier: string
): boolean {
if (!trackingIdentifier.includes(":")) {
return false;
}

const [cornerstone3DTag, toolType] = trackingIdentifier.split(":");

if (cornerstone3DTag !== CORNERSTONE_3D_TAG) {
return false;
}

// The following is needed since the new cornerstone3D has changed
// case names such as EllipticalRoi to EllipticalROI
return toolType.toLowerCase() === this.toolType.toLowerCase();
}

0 comments on commit 05e6419

Please sign in to comment.