-
Notifications
You must be signed in to change notification settings - Fork 325
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Start moving adapters to shared base file to allow for updates
- Loading branch information
1 parent
5ec16c8
commit 281c4dc
Showing
4 changed files
with
163 additions
and
129 deletions.
There are no files selected for viewing
86 changes: 86 additions & 0 deletions
86
packages/adapters/src/adapters/Cornerstone3D/BaseAdapter3D.ts
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,86 @@ | ||
import CORNERSTONE_3D_TAG from "./cornerstone3DTag"; | ||
import MeasurementReport from "./MeasurementReport"; | ||
|
||
/** | ||
* This is a basic definition of adapters to be inherited for other adapters. | ||
*/ | ||
export default class BaseAdapter3D { | ||
public static toolType: string; | ||
public static utilityToolType: string; | ||
public static TID300Representation; | ||
public static trackingIdentifierTextValue: string; | ||
|
||
/** | ||
* @returns true if the tool is of the given tool type based on the tracking identifier | ||
*/ | ||
public static isValidCornerstoneTrackingIdentifier = trackingIdentifier => { | ||
if (!trackingIdentifier.includes(":")) { | ||
return false; | ||
} | ||
|
||
const [cornerstone3DTag, toolType] = trackingIdentifier.split(":"); | ||
|
||
if (cornerstone3DTag !== CORNERSTONE_3D_TAG) { | ||
return false; | ||
} | ||
|
||
return toolType === this.toolType; | ||
}; | ||
|
||
/** | ||
* Returns annotation data for CS3D to use based on the underlying | ||
* DICOM SR annotation data. | ||
*/ | ||
public static getMeasurementData( | ||
MeasurementGroup, | ||
sopInstanceUIDToImageIdMap, | ||
_imageToWorldCoords, | ||
metadata | ||
) { | ||
const { defaultState: state, ReferencedFrameNumber } = | ||
MeasurementReport.getSetupMeasurementData( | ||
MeasurementGroup, | ||
sopInstanceUIDToImageIdMap, | ||
metadata, | ||
this.toolType | ||
); | ||
|
||
state.annotation.data = { | ||
cachedStats: {}, | ||
frameNumber: ReferencedFrameNumber | ||
}; | ||
|
||
return state; | ||
} | ||
|
||
public static getTID300RepresentationArguments(tool, worldToImageCoords) { | ||
const { data, metadata } = tool; | ||
const { finding, findingSites } = tool; | ||
const { referencedImageId } = metadata; | ||
|
||
if (!referencedImageId) { | ||
throw new Error( | ||
"Probe.getTID300RepresentationArguments: referencedImageId is not defined" | ||
); | ||
} | ||
|
||
const { points } = data.handles; | ||
|
||
const pointsImage = points.map(point => { | ||
const pointImage = worldToImageCoords(referencedImageId, point); | ||
return { | ||
x: pointImage[0], | ||
y: pointImage[1] | ||
}; | ||
}); | ||
|
||
const TID300RepresentationArguments = { | ||
points: pointsImage, | ||
trackingIdentifierTextValue: this.trackingIdentifierTextValue, | ||
findingSites: findingSites || [], | ||
finding | ||
}; | ||
|
||
return TID300RepresentationArguments; | ||
} | ||
} |
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 was deleted.
Oops, something went wrong.
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,68 @@ | ||
import { utilities } from "dcmjs"; | ||
import CORNERSTONE_3D_TAG from "./cornerstone3DTag"; | ||
import MeasurementReport from "./MeasurementReport"; | ||
import BaseAdapter3D from "./BaseAdapter3D"; | ||
|
||
const { Point: TID300Point } = utilities.TID300; | ||
|
||
const PROBE = "Probe"; | ||
const trackingIdentifierTextValue = `${CORNERSTONE_3D_TAG}:${PROBE}`; | ||
|
||
class Probe extends BaseAdapter3D { | ||
public static toolType = PROBE; | ||
public static utilityToolType = PROBE; | ||
public static TID300Representation = TID300Point; | ||
|
||
static getMeasurementData( | ||
MeasurementGroup, | ||
sopInstanceUIDToImageIdMap, | ||
imageToWorldCoords, | ||
metadata | ||
) { | ||
const state = super.getMeasurementData( | ||
MeasurementGroup, | ||
sopInstanceUIDToImageIdMap, | ||
imageToWorldCoords, | ||
metadata | ||
); | ||
|
||
const { defaultState, SCOORDGroup } = | ||
MeasurementReport.getSetupMeasurementData( | ||
MeasurementGroup, | ||
sopInstanceUIDToImageIdMap, | ||
metadata, | ||
Probe.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); | ||
} | ||
|
||
state.annotation.data = { | ||
...state.annotation.data, | ||
handles: { | ||
points: worldCoords, | ||
activeHandleIndex: null, | ||
textBox: { | ||
hasMoved: false | ||
} | ||
} | ||
}; | ||
|
||
return state; | ||
} | ||
} | ||
|
||
MeasurementReport.registerTool(Probe); | ||
|
||
export default Probe; |