-
Notifications
You must be signed in to change notification settings - Fork 334
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(CobbAngle): Add CobbAngle tool (#353)
* fix: Fix the build and usage of the adapters * feat: Add Cobb Angle tool
- Loading branch information
1 parent
378cd7f
commit b9bd701
Showing
11 changed files
with
1,195 additions
and
219 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
125 changes: 125 additions & 0 deletions
125
packages/adapters/src/adapters/Cornerstone3D/CobbAngle.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
import { utilities } from "dcmjs"; | ||
import CORNERSTONE_3D_TAG from "./cornerstone3DTag"; | ||
import MeasurementReport from "./MeasurementReport"; | ||
|
||
const { CobbAngle: TID300CobbAngle } = utilities.TID300; | ||
|
||
const MEASUREMENT_TYPE = "CobbAngle"; | ||
const trackingIdentifierTextValue = `${CORNERSTONE_3D_TAG}:${MEASUREMENT_TYPE}`; | ||
|
||
class CobbAngle { | ||
// TODO: this function is required for all Cornerstone Tool Adapters, since it is called by MeasurementReport. | ||
static getMeasurementData( | ||
MeasurementGroup, | ||
sopInstanceUIDToImageIdMap, | ||
imageToWorldCoords, | ||
metadata | ||
) { | ||
const { defaultState, NUMGroup, SCOORDGroup, ReferencedFrameNumber } = | ||
MeasurementReport.getSetupMeasurementData( | ||
MeasurementGroup, | ||
sopInstanceUIDToImageIdMap, | ||
metadata, | ||
CobbAngle.toolType | ||
); | ||
|
||
const referencedImageId = | ||
defaultState.annotation.metadata.referencedImageId; | ||
|
||
const { GraphicData } = SCOORDGroup; | ||
const worldCoords = []; | ||
for (let i = 0; i < GraphicData.length; i += 2) { | ||
const point = imageToWorldCoords(referencedImageId, [ | ||
GraphicData[i], | ||
GraphicData[i + 1] | ||
]); | ||
worldCoords.push(point); | ||
} | ||
|
||
const state = defaultState; | ||
|
||
state.annotation.data = { | ||
handles: { | ||
points: [ | ||
worldCoords[0], | ||
worldCoords[1], | ||
worldCoords[2], | ||
worldCoords[3] | ||
], | ||
activeHandleIndex: 0, | ||
textBox: { | ||
hasMoved: false | ||
} | ||
}, | ||
cachedStats: { | ||
[`imageId:${referencedImageId}`]: { | ||
angle: NUMGroup | ||
? NUMGroup.MeasuredValueSequence.NumericValue | ||
: null | ||
} | ||
}, | ||
frameNumber: ReferencedFrameNumber | ||
}; | ||
|
||
return state; | ||
} | ||
|
||
static getTID300RepresentationArguments(tool, worldToImageCoords) { | ||
const { data, finding, findingSites, metadata } = tool; | ||
const { cachedStats = {}, handles } = data; | ||
|
||
const { referencedImageId } = metadata; | ||
|
||
if (!referencedImageId) { | ||
throw new Error( | ||
"CobbAngle.getTID300RepresentationArguments: referencedImageId is not defined" | ||
); | ||
} | ||
|
||
const start1 = worldToImageCoords(referencedImageId, handles.points[0]); | ||
const end1 = worldToImageCoords(referencedImageId, handles.points[1]); | ||
|
||
const start2 = worldToImageCoords(referencedImageId, handles.points[2]); | ||
const end2 = worldToImageCoords(referencedImageId, handles.points[3]); | ||
|
||
const point1 = { x: start1[0], y: start1[1] }; | ||
const point2 = { x: end1[0], y: end1[1] }; | ||
const point3 = { x: start2[0], y: start2[1] }; | ||
const point4 = { x: end2[0], y: end2[1] }; | ||
|
||
const { angle } = cachedStats[`imageId:${referencedImageId}`] || {}; | ||
|
||
return { | ||
point1, | ||
point2, | ||
point3, | ||
point4, | ||
rAngle: angle, | ||
trackingIdentifierTextValue, | ||
finding, | ||
findingSites: findingSites || [] | ||
}; | ||
} | ||
} | ||
|
||
CobbAngle.toolType = MEASUREMENT_TYPE; | ||
CobbAngle.utilityToolType = MEASUREMENT_TYPE; | ||
console.log("TID300CobbAngle=", TID300CobbAngle); | ||
CobbAngle.TID300Representation = TID300CobbAngle; | ||
CobbAngle.isValidCornerstoneTrackingIdentifier = TrackingIdentifier => { | ||
if (!TrackingIdentifier.includes(":")) { | ||
return false; | ||
} | ||
|
||
const [cornerstone3DTag, toolType] = TrackingIdentifier.split(":"); | ||
|
||
if (cornerstone3DTag !== CORNERSTONE_3D_TAG) { | ||
return false; | ||
} | ||
|
||
return toolType === MEASUREMENT_TYPE; | ||
}; | ||
|
||
MeasurementReport.registerTool(CobbAngle); | ||
|
||
export default CobbAngle; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.