Add measurement table functions (#415)

* fix(measurements): Add measurement table functions
- Support for labeling measurements and adding measurement description
- Jump to measurement when clicked on measurement table

* fix(layout): Fix the issues with layout when switched with different plugins

* fix(measurements): Support for deleting measurements in measurement table

* fix(measurements): Add context menu for measurements

* fix(dependencies): Bump ohif-core to 0.4.2
This commit is contained in:
Evren Ozkan authored and GitHub committed 2019-05-02 17:12:06 -04:00
1 parent 0bab19985e
commit c9ddb23d9c
33 files changed
+2219 -151

No files matched your search

+21
View File
@@ -0,0 +1,21 @@
import cornerstoneTools from 'cornerstone-tools'
import updateTableWithNewMeasurementData from './updateTableWithNewMeasurementData'
export default function getMeasurementLocationCallback(
eventData,
tool,
options
) {
const { toolType } = tool
const { element } = eventData
const doneCallback = updateTableWithNewMeasurementData
const ToolInstance = cornerstoneTools.getToolForElement(element, toolType)
ToolInstance.configuration.getMeasurementLocationCallback(
tool,
eventData,
doneCallback,
options
)
}
+110
View File
@@ -0,0 +1,110 @@
import { OHIF } from 'ohif-core'
// TODO: Move this function to OHIF itself so we can use it on the OHIF measurment table (when it is finished)
/**
* Activates a set of measurements
*
* @param measurementData
* @param viewportsState
* @param timepointManagerState
* @param options
*/
export default function jumpToRowItem(
measurementData,
viewportsState,
timepointManagerState,
options = { invertViewportTimepointsOrder: false, childToolKey: null }
) {
const numViewports = viewportsState.layout.viewports.length
const numTimepoints = timepointManagerState.timepoints.length
const { measurements, timepoints } = timepointManagerState
const numViewportsToUpdate = Math.min(numTimepoints, numViewports)
const { toolType, measurementNumber } = measurementData
if (options.invertViewportTimepointsOrder) {
timepoints.reverse()
}
const measurementsForToolGroup = measurements[toolType]
// Retrieve the measurements data
const measurementsToJumpTo = []
for (let i = 0; i < numViewportsToUpdate; i++) {
const { timepointId } = timepoints[i]
const dataAtThisTimepoint = measurementsForToolGroup.find(entry => {
return (
entry.timepointId === timepointId &&
entry.measurementNumber === measurementNumber
)
})
if (!dataAtThisTimepoint) {
measurementsToJumpTo.push(null)
continue
}
let measurement = dataAtThisTimepoint
const { tool } = OHIF.measurements.MeasurementApi.getToolConfiguration(
toolType
)
if (options.childToolKey) {
measurement = dataAtThisTimepoint[options.childToolKey]
} else if (Array.isArray(tool.childTools)) {
const key = tool.childTools.find(key => !!dataAtThisTimepoint[key])
measurement = dataAtThisTimepoint[key]
}
measurementsToJumpTo.push(measurement)
}
// TODO: Add a single viewports state action which allows
// - viewportData to be set
// - layout to be set
// - activeViewport to be set
// Needs to update viewports.viewportData state to set image set data
const displaySetContainsSopInstance = (displaySet, sopInstanceUid) =>
displaySet.images.find(
image => image.getSOPInstanceUID() === sopInstanceUid
)
const viewportSpecificData = []
measurementsToJumpTo.forEach((data, viewportIndex) => {
// Skip if there is no measurement to jump
if (!data) {
return
}
const study = OHIF.utils.studyMetadataManager.get(data.studyInstanceUid)
if (!study) {
throw new Error('Study not found.')
}
const displaySet = study.findDisplaySet(displaySet => {
return displaySetContainsSopInstance(displaySet, data.sopInstanceUid)
})
if (!displaySet) {
throw new Error('Display set not found.')
}
displaySet.sopInstanceUid = data.sopInstanceUid
if (data.frameIndex) {
displaySet.frameIndex = data.frameIndex
}
viewportSpecificData.push({
viewportIndex,
displaySet,
})
})
return {
viewportSpecificData,
layout: [], // TODO: if we need to change layout, we should return this here
}
}
@@ -0,0 +1,29 @@
import OHIF from 'ohif-core'
import cornerstone from 'cornerstone-core'
export default function updateTableWithNewMeasurementData({
toolType,
measurementNumber,
location,
description,
}) {
// Update all measurements by measurement number
const measurementApi = OHIF.measurements.MeasurementApi.Instance
const measurements = measurementApi.tools[toolType].filter(
m => m.measurementNumber === measurementNumber
)
measurements.forEach(measurement => {
measurement.location = location
measurement.description = description
measurementApi.updateMeasurement(measurement.toolType, measurement)
})
measurementApi.syncMeasurementsAndToolData()
// Update images in all active viewports
cornerstone.getEnabledElements().forEach(enabledElement => {
cornerstone.updateImage(enabledElement.element)
})
}
+46
View File
@@ -0,0 +1,46 @@
export default function bounding(elementRef, currentPosition = {}) {
if (!elementRef.current) {
return
}
const currentElement = elementRef.current
const {
offsetParent,
offsetTop,
offsetHeight,
offsetLeft,
offsetWidth,
} = currentElement
let top = currentPosition.top || offsetTop
let left = currentPosition.left || offsetLeft
if (!offsetParent) {
return
}
let maxHeight = `${offsetParent.offsetHeight}px`
if (offsetHeight + top > offsetParent.offsetHeight) {
top = top - (offsetHeight + top - offsetParent.offsetHeight)
if (top < 0) {
top = 0
}
}
if (left + offsetWidth > offsetParent.offsetWidth) {
left = offsetParent.offsetWidth - offsetWidth
if (left < 0) {
left = 0
}
}
if (maxHeight && currentElement.style.maxHeight !== maxHeight) {
currentElement.style.maxHeight = maxHeight
}
if (currentElement.style.top !== `${top}px`) {
currentElement.style.top = `${top}px`
}
if (currentElement.style.left !== `${left}px`) {
currentElement.style.left = `${left}px`
}
}