Skip to content

Commit

Permalink
fix: Create CrosshairSpecificToolData interface
Browse files Browse the repository at this point in the history
  • Loading branch information
swederik authored and sedghi committed Jun 3, 2021
1 parent a9e35d0 commit 204bae9
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 15 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"test": "karma start",
"test:ci": "karma start --single-run",
"lint-staged": "lint-staged",
"lint": "eslint --quiet -c .eslintrc.json src",
"lint": "eslint --quiet -c .eslintrc.json packages/**/src",
"predeploy": "yarn install && yarn run build:release",
"prepublishOnly": "yarn run build && yarn run build:release",
"compile": "tsc -p tsconfig.build.json"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export default function mouseDown(evt) {

if (annotationToolsWithMoveableHandles.length > 0) {
const { tool, toolData, handle } = selectSuitableAnnotationTool(
annotationToolsWithMoveableHandles as [ToolAndToolData]
annotationToolsWithMoveableHandles as ToolAndToolData[]
)

toggleToolDataSelection(toolData, isMultiSelect)
Expand All @@ -131,7 +131,7 @@ export default function mouseDown(evt) {

if (moveableAnnotationTools.length > 0) {
const { tool, toolData } = selectSuitableAnnotationTool(
moveableAnnotationTools as [ToolAndToolData]
moveableAnnotationTools as ToolAndToolData[]
)

toggleToolDataSelection(toolData, isMultiSelect)
Expand All @@ -155,7 +155,7 @@ export default function mouseDown(evt) {
}

function selectSuitableAnnotationTool(
annotationTools: [ToolAndToolData]
annotationTools: ToolAndToolData[]
): ToolAndToolData {
return (
(annotationTools.length > 1 &&
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { ToolSpecificToolData, ToolAndToolStateArray, Point2 } from '../types'
import BaseAnnotationTool from '../tools/base/BaseAnnotationTool';

type ToolAndToolData = {
tool: any
tool: BaseAnnotationTool
toolData: ToolSpecificToolData
}

Expand Down
42 changes: 33 additions & 9 deletions packages/cornerstone-tools/src/tools/CrosshairsTool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,20 @@ interface ToolConfiguration {
}
}

interface CrosshairsSpecificToolData extends ToolSpecificToolData {
data: {
handles: {
rotationPoints: any[], // rotation handles, used for rotation interactions
slabThicknessPoints: any[], // slab thickness handles, used for setting the slab thickness
activeOperation: Number | null, // 0 translation, 1 rotation handles, 2 slab thickness handles
},
active: boolean,
activeViewportUIDs: string[], // a list of the viewport uids connected to the reference lines being translated
viewportUID: string,
sceneUID: string,
},
}

function defaultReferenceLineColor() {
return 'rgb(200, 200, 200)'
}
Expand Down Expand Up @@ -112,21 +126,31 @@ export default class CrosshairsTool extends BaseAnnotationTool {
this._mouseDragCallback = this._mouseDragCallback.bind(this)
}

addNewMeasurement(evt: CustomEvent, interactionType: string): any {
addNewMeasurement(evt: CustomEvent, interactionType: string): CrosshairsSpecificToolData {
// not used, but is necessary if BaseAnnotationTool.
// NOTE: this is a BaseAnnotationTool and not a BaseTool, because in future
// we will likely pre-filter all tools using typeof / instanceof
// in the mouse down dispatchers where we check for methods like pointNearTool.
const toolSpecificToolData = {
metadata: {
viewPlaneNormal: [0, 0, 0],
viewUp: [0, 0, 0],
viewPlaneNormal: <Point3>[0, 0, 0],
viewUp: <Point3>[0, 0, 0],
toolUID: '1',
FrameOfReferenceUID: '1',
referencedImageId: '1',
toolName: this.name,
},
data: {},
data: {
handles: {
rotationPoints: [], // rotation handles, used for rotation interactions
slabThicknessPoints: [], // slab thickness handles, used for setting the slab thickness
activeOperation: null, // 0 translation, 1 rotation handles, 2 slab thickness handles
},
active: false,
activeViewportUIDs: [], // a list of the viewport uids connected to the reference lines being translated
viewportUID: '1',
sceneUID: '1',
},
}

return toolSpecificToolData
Expand Down Expand Up @@ -331,7 +355,7 @@ export default class CrosshairsTool extends BaseAnnotationTool {
}

// viewport ToolData
const viewportToolData = filteredToolState[0]
const viewportToolData = filteredToolState[0] as CrosshairsSpecificToolData

// -- Update the camera of other linked viewports in the same scene that
// have the same camera in case of translation
Expand Down Expand Up @@ -447,7 +471,7 @@ export default class CrosshairsTool extends BaseAnnotationTool {
let imageNeedsUpdate = false

for (let i = 0; i < filteredToolState.length; i++) {
const toolData = filteredToolState[i]
const toolData = filteredToolState[i] as CrosshairsSpecificToolData

if (isToolDataLocked(toolData)) {
continue
Expand Down Expand Up @@ -1555,7 +1579,7 @@ export default class CrosshairsTool extends BaseAnnotationTool {
vtkMath.subtract(jumpWorld, this.toolCenter, delta)

const viewportToolData = toolState.find(
(toolData) => toolData.data.viewportUID === viewport.uid
(toolData: CrosshairsSpecificToolData) => toolData.data.viewportUID === viewport.uid
)

this._applyDeltaShiftToViewportCamera(
Expand Down Expand Up @@ -1768,7 +1792,7 @@ export default class CrosshairsTool extends BaseAnnotationTool {
} else if (handles.activeOperation === OPERATION.SLAB) {
// SLAB THICKNESS
// this should be just the active one under the mouse,
const viewportsToolDataToUpdate = toolState.filter((toolData) => {
const viewportsToolDataToUpdate = toolState.filter((toolData: CrosshairsSpecificToolData) => {
const { data } = toolData
const scene = renderingEngine.getScene(data.sceneUID)
const otherViewport = scene.getViewport(data.viewportUID)
Expand All @@ -1778,7 +1802,7 @@ export default class CrosshairsTool extends BaseAnnotationTool {
)
})

viewportsToolDataToUpdate.forEach((toolData) => {
viewportsToolDataToUpdate.forEach((toolData: CrosshairsSpecificToolData) => {
const { data } = toolData

const scene = renderingEngine.getScene(data.sceneUID)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,6 @@ export default class EllipticalRoiTool extends BaseAnnotationTool {
data.active = false
data.handles.activeHandleIndex = null

delete data.isDrawing
delete data.isDrawing

this._deactivateModify(element)
Expand Down

0 comments on commit 204bae9

Please sign in to comment.