2020-06-05 17:36:11 +02:00
|
|
|
import { importInternal, getToolState, toolColors } from 'cornerstone-tools';
|
|
|
|
|
|
|
|
|
|
import TOOL_NAMES from '../constants/toolNames';
|
|
|
|
|
import SCOORD_TYPES from '../constants/scoordTypes';
|
2020-06-10 10:09:33 +02:00
|
|
|
import id from '../id';
|
2020-06-05 17:36:11 +02:00
|
|
|
|
|
|
|
|
// Cornerstone 3rd party dev kit imports
|
|
|
|
|
const draw = importInternal('drawing/draw');
|
|
|
|
|
const drawJoinedLines = importInternal('drawing/drawJoinedLines');
|
|
|
|
|
const drawCircle = importInternal('drawing/drawCircle');
|
|
|
|
|
const drawEllipse = importInternal('drawing/drawEllipse');
|
2020-06-15 13:09:48 +02:00
|
|
|
const drawHandles = importInternal('drawing/drawHandles');
|
2020-06-05 17:36:11 +02:00
|
|
|
const getNewContext = importInternal('drawing/getNewContext');
|
|
|
|
|
const BaseTool = importInternal('base/BaseTool');
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @class DICOMSRDisplayTool - Renders DICOMSR data in a read only manner (i.e. as an overlay).
|
|
|
|
|
* @extends cornerstoneTools.BaseTool
|
|
|
|
|
*/
|
|
|
|
|
export default class DICOMSRDisplayTool extends BaseTool {
|
|
|
|
|
constructor(props = {}) {
|
|
|
|
|
const defaultProps = {
|
|
|
|
|
mixins: ['enabledOrDisabledBinaryTool'],
|
|
|
|
|
name: TOOL_NAMES.DICOM_SR_DISPLAY_TOOL,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const initialProps = Object.assign(defaultProps, props);
|
|
|
|
|
|
|
|
|
|
super(initialProps);
|
2020-06-10 10:09:33 +02:00
|
|
|
|
|
|
|
|
this._module = cornerstoneTools.getModule(id);
|
2020-06-05 17:36:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
renderToolData(evt) {
|
|
|
|
|
const eventData = evt.detail;
|
|
|
|
|
const { element } = eventData;
|
2020-06-10 10:09:33 +02:00
|
|
|
const module = this._module;
|
2020-06-05 17:36:11 +02:00
|
|
|
|
|
|
|
|
const toolState = getToolState(element, this.name);
|
|
|
|
|
|
|
|
|
|
if (!toolState) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-10 10:09:33 +02:00
|
|
|
const trackingUniqueIdentifiersForElement = module.getters.trackingUniqueIdentifiersForElement(
|
|
|
|
|
element
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const {
|
|
|
|
|
activeIndex,
|
|
|
|
|
trackingUniqueIdentifiers,
|
|
|
|
|
} = trackingUniqueIdentifiersForElement;
|
|
|
|
|
|
|
|
|
|
const activeTrackingUniqueIdentifier =
|
|
|
|
|
trackingUniqueIdentifiers[activeIndex];
|
2020-06-05 17:36:11 +02:00
|
|
|
|
2020-06-10 10:09:33 +02:00
|
|
|
// Filter toolData to only render the data for the active SR.
|
|
|
|
|
const filteredToolData = toolState.data.filter(td =>
|
|
|
|
|
trackingUniqueIdentifiers.includes(td.TrackingUniqueIdentifier)
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
for (let i = 0; i < filteredToolData.length; i++) {
|
|
|
|
|
const data = filteredToolData[i];
|
2020-06-05 18:59:07 +02:00
|
|
|
const { renderableData } = data;
|
2020-06-05 17:36:11 +02:00
|
|
|
|
2020-06-10 10:09:33 +02:00
|
|
|
const color =
|
|
|
|
|
data.TrackingUniqueIdentifier === activeTrackingUniqueIdentifier
|
|
|
|
|
? toolColors.getActiveColor()
|
|
|
|
|
: toolColors.getToolColor();
|
|
|
|
|
|
|
|
|
|
const options = {
|
|
|
|
|
color,
|
|
|
|
|
lineWidth: 2,
|
|
|
|
|
handleRadius: 6,
|
|
|
|
|
};
|
|
|
|
|
|
2020-06-05 18:59:07 +02:00
|
|
|
Object.keys(renderableData).forEach(GraphicType => {
|
|
|
|
|
const renderableDataForGraphicType = renderableData[GraphicType];
|
2020-06-05 17:36:11 +02:00
|
|
|
|
|
|
|
|
switch (GraphicType) {
|
|
|
|
|
case SCOORD_TYPES.POINT:
|
|
|
|
|
case SCOORD_TYPES.MULTIPOINT:
|
2020-06-10 10:09:33 +02:00
|
|
|
this.renderPointOrMultipoint(
|
2020-06-05 18:59:07 +02:00
|
|
|
renderableDataForGraphicType,
|
|
|
|
|
eventData,
|
|
|
|
|
options
|
|
|
|
|
);
|
2020-06-05 17:36:11 +02:00
|
|
|
break;
|
|
|
|
|
case SCOORD_TYPES.POLYLINE:
|
2020-06-10 10:09:33 +02:00
|
|
|
this.renderPolyLine(
|
|
|
|
|
renderableDataForGraphicType,
|
|
|
|
|
eventData,
|
|
|
|
|
options
|
|
|
|
|
);
|
2020-06-05 17:36:11 +02:00
|
|
|
break;
|
|
|
|
|
case SCOORD_TYPES.CIRCLE:
|
2020-06-10 10:09:33 +02:00
|
|
|
this.renderCircle(renderableDataForGraphicType, eventData, options);
|
2020-06-05 17:36:11 +02:00
|
|
|
break;
|
|
|
|
|
case SCOORD_TYPES.ELLIPSE:
|
2020-06-10 10:09:33 +02:00
|
|
|
this.renderEllipse(
|
|
|
|
|
renderableDataForGraphicType,
|
|
|
|
|
eventData,
|
|
|
|
|
options
|
|
|
|
|
);
|
2020-06-05 17:36:11 +02:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
renderPolyLine(renderableData, eventData, options) {
|
|
|
|
|
const { element } = eventData;
|
|
|
|
|
const context = getNewContext(eventData.canvasContext.canvas);
|
|
|
|
|
|
|
|
|
|
renderableData.forEach(points => {
|
|
|
|
|
draw(context, context => {
|
|
|
|
|
drawJoinedLines(context, element, points[0], points, options);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
renderPointOrMultipoint(renderableData, eventData, options) {
|
|
|
|
|
const context = getNewContext(eventData.canvasContext.canvas);
|
|
|
|
|
|
|
|
|
|
renderableData.forEach(points => {
|
|
|
|
|
draw(context, context => {
|
|
|
|
|
drawHandles(context, eventData, points, options);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
renderCircle(renderableData, eventData, options) {
|
|
|
|
|
const { element } = eventData;
|
|
|
|
|
|
|
|
|
|
const context = getNewContext(eventData.canvasContext.canvas);
|
|
|
|
|
|
|
|
|
|
renderableData.forEach(circle => {
|
|
|
|
|
const { center, radius } = circle;
|
|
|
|
|
|
|
|
|
|
drawCircle(context, element, center, radius, options);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
renderEllipse(renderableData, eventData, options) {
|
|
|
|
|
const { element } = eventData;
|
|
|
|
|
|
|
|
|
|
const context = getNewContext(eventData.canvasContext.canvas);
|
|
|
|
|
|
|
|
|
|
renderableData.forEach(ellipse => {
|
|
|
|
|
const { corner1, corner2 } = ellipse;
|
|
|
|
|
|
|
|
|
|
drawEllipse(
|
|
|
|
|
context,
|
|
|
|
|
element,
|
|
|
|
|
corner1,
|
|
|
|
|
corner2,
|
|
|
|
|
options,
|
|
|
|
|
'pixel',
|
|
|
|
|
0 // TODO -> Work our the initial rotation and add it here so we render appropriately rotated ellipses.
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|