feat: cornerstone3D stack and volume viewports (#2787)
* feat: cs3d working stack viewport and tools (#19) * Squashed everything * fix weird react issue * fix eslint / prettier stuff * thumbnails work now with cpu rendering * feat: use new loadImageToCanvas in cs3d * make jump to measurement work * fix active thumbnail * fix measurement delete * fix window level presets * remove segmentation and sync groups for now * fix the dicom pdf and dicom video * fix cornerstone window assignment for cypress * apply review comments Co-authored-by: Erik <erik.sweed@gmail.com> * feat: cs3d tools and toolGroups (#20) * add more tools to work with cs3d mode * fix hotkeys * add stack manager usage for stach viewports * add image scrollbar * wip viewport overlay * fix toAnnotation schema for tools * fix the unnecessary size change that triggered resize * hanging protocol improvement to allow unmatched errors * study description matching for hanging protocol * fix the displaysetOptions to work * fix handle the active tool when a new viewport is added * fix separate toolGroups for mode * apply review comments * apply review comments * yarn lock * feat: overlay component (#21) * fix default displayset options * add viewport overlay * apply review comments * feat: loading and orientation indicators (#22) * add loading indicator * add orientation marker initial work * apply review comments * fix: orientation markers (#23) * finished the orientation markers * fix various broken cypress tests * apply review comments * update yarn lock * feat: re-working measurement tracking mode with cornerstone3d (#2805) * feat: cs3d working stack viewport and tools (#19) * Squashed everything * fix weird react issue * fix eslint / prettier stuff * thumbnails work now with cpu rendering * feat: use new loadImageToCanvas in cs3d * make jump to measurement work * fix active thumbnail * fix measurement delete * fix window level presets * remove segmentation and sync groups for now * fix the dicom pdf and dicom video * fix cornerstone window assignment for cypress * apply review comments Co-authored-by: Erik <erik.sweed@gmail.com> * feat: Add Measurement tracking mode with cs3D (#2789) * feat: first render for cornerstone3d tracked viewport * make tool active work * wip for SR extension * renamed dicom sr to cornerstone dicom sr * remove cornerstone from dicom pdf and video * move dicom sr logic to sr extension * feat: Add hydration for the length tool * fix SR display tool for length using cs3d * fix default config * fix: various bugs with sr viewport and tracking * fix promptying to continue tracking for when SR is created * feat: add keep trackign of unique identifiers * fix hydration for same imageIds * feat: Add SR toolGroup creation on modeEnter * feat: remove the need for separate mapper for SR hydration * add SR display for ellipse * handle hydration of elliptical ROI tool * remove cornerstone extension * add arrow mapping * feat: Add ArrowAnnotate SR display and hydration * apply review comments * apply review comments * move viewport labels to the viewportData * apply review comments * fix: integration cypress tests with cornerstone3D and add CINE tool (#2795) * fix: integration cypress tests with cornerstone3D * revert to addOrUpdate as it makes more sense * fix local drag and drop * fix tests * move dicomLoaderService to cornerstone extension * fix various import bugs * fix bug for local PT series * fix various unit tests * bump cs3d versions * add angle and magnify tool * bump dependencies to avoid broken peerDeps * feat: add initial work for capture using cs3d * feat: show annotations on the image capture * feat: add svg layer export * feat: Add CINE Tool * feat: remove unnecessary viewport rendering for cine state changes Co-authored-by: Erik Ziegler <erik.sweed@gmail.com> * docs: modify and improve documentation (#2800) * cleanup docs versionings * feat: Add all version explanations * version docs for 3.0 * wip for changing docs * wip for updated docs * add utility module documentation * fix demo with nohoisting of history * add slides and video to resources * apply review comments * fix: drag and drop SR into SR viewport (#2803) * update yarn lock Co-authored-by: Erik <erik.sweed@gmail.com> * update pathnames to match v3-stable * update the e2e pathname * fix: various bugs with regard to tracking workflow (#2811) * fix: various issues with measurement panel * fix: update default tool style for annotations * fix: annotatoin label getting removed * feat: Add backward compatibility for SR hydration with legacy cornerstone * fix: cursors and ellipse ROI max style * fix: ArrowAnnotate SRDisplay * apply review comments * bump package versions * fix: bugin rehydration of SR * fix: e2e tests * fix active viewport thickness and arrowTool ui * add readme for measurement tracking * use uploaded image for readme * add back images * try to fix e2e test * fix: window level presets hotkeys * Update README.md * update yarn lock * feat: volume api and TMTV mode (#2817) * feat: volumeAPI and TMTV mode * feat: use cs3d cache service to obtain viewportData * wip for volume api * wip: fusion viewport * feat: add blend mode option * wip for image scrollbar * fix drag and drop thumbnail * wip for image scrollbar for voluems * fix: element mismatch bug for scroll * feat: Add image scrollbar to volumes * feat: add syncGroups to volume api * feat: add tmtv mode initial setup * feat: add initial image options for the stack viewports * feat: Add custom load strategy for volume viewports via HP * apply review comments fix: Jump presets cs3d (#2812) * feat: Add JumpPreset to OHIF for Cornerstone3D * fix: accessing viewport service from servicesManager feat: volume API and TMTV mode (#2814) * fix: do not display overlays on mip viewports * feat: add optional disableCommands for toggle buttons * fix: toggleCrossharis * feat: config the crosshairs * feat: add PetSUV Panel for changing metadata * feat: initial work for the rectangleROIThreshold panel * wip: measurement service * roi threshold working * feat: Add displayText to segmentations * feat: add remove segmentation * feat: add csv export * feat: add RT export for annotations in tmtv mode * fix: fusion to use pt in tmtv mode and measuremet mappings * fix: various bugs * apply review comments * apply review comments * feat: add fusion color maps * add readme to tmtv mode * Update README.md * fix: try to fix build * fix unit tests * Update README.md * feat: add about to the panel * fix: changing strategy in roi panel * apply review comments * update package versions * wip for stackPrefetch * fix: cornerstone3d hydration and renaming (#2818) * update readme * renamed cornerstone extension * wip for renaming cornerstone3D variables * wip for renaming cornerstone3D variables * wip for fixing bugs for SR viewport * fix: jumpToMeasurement and initial label after hydration * fix: fileName capitalization * feat: use the new prefetch stack in the cs3d (#2820) * feat: use the new prefetch stack in the cs3d * use viewport scroll api for stack viewport * fix cine stop when scrollbar changes * feat: use new prefetch events * fix loading state to not show repeatedly * fix: various bugs for tmtv mode thresholding and new icons (#2823) * feat: make tmtv mode available in worklist * feat: add new icons for tmtv mode * feat: add fusion color icon * fix: parallel scale calculation * fix: bump Cornerstone to get large image support working * fix: Fix issues with CPU viewport flipping, including config files * fix: bump cornerstone to fix magnify tool * fix: Bump Cornerstone version to fix resetCamera issue in StackViewport * ci: Add _headers file to enable CORS headers for Netlify Drag/Drop deploys * fix: WADO-URI was not working. PET Metadata was coming from the wrong place. Fixed some minor React errors * feat(OHIF):Allow modes and extensions to be added after commpile time. (#2838) Also works with the compile time add that the existing cli uses, so that both build types work. Eric and I agreed this doesn't change existing functionality, but is almost entirely build issues/fixes. * bump: dependency versions to fix hydration bugs (#2848) * bump: dcmjs version to fix hydration bugs * try to fix tests * bump dependency versions Co-authored-by: Alireza <ar.sedghi@gmail.com> Co-authored-by: Bill Wallace <wayfarer3130@gmail.com>
This commit is contained in:
668 files changed
+41669
-13410
No files matched your search
@@ -0,0 +1,233 @@
|
||||
import React from 'react';
|
||||
import domtoimage from 'dom-to-image';
|
||||
|
||||
import {
|
||||
Enums,
|
||||
getEnabledElement,
|
||||
getOrCreateCanvas,
|
||||
StackViewport,
|
||||
} from '@cornerstonejs/core';
|
||||
import { ToolGroupManager } from '@cornerstonejs/tools';
|
||||
import PropTypes from 'prop-types';
|
||||
import { ViewportDownloadForm } from '@ohif/ui';
|
||||
|
||||
import { getEnabledElement as OHIFgetEnabledElement } from '../state';
|
||||
|
||||
const MINIMUM_SIZE = 100;
|
||||
const DEFAULT_SIZE = 512;
|
||||
const MAX_TEXTURE_SIZE = 10000;
|
||||
const VIEWPORT_ID = 'cornerstone-viewport-download-form';
|
||||
const TOOLGROUP_ID = 'cornerstone-viewport-download-form-toolgroup';
|
||||
|
||||
const CornerstoneViewportDownloadForm = ({
|
||||
onClose,
|
||||
activeViewportIndex,
|
||||
CornerstoneViewportService,
|
||||
}) => {
|
||||
const enabledElement = OHIFgetEnabledElement(activeViewportIndex);
|
||||
const activeViewportElement = enabledElement?.element;
|
||||
|
||||
const enableViewport = viewportElement => {
|
||||
if (viewportElement) {
|
||||
const renderingEngine = CornerstoneViewportService.getRenderingEngine();
|
||||
|
||||
const viewportInput = {
|
||||
viewportId: VIEWPORT_ID,
|
||||
element: viewportElement,
|
||||
type: Enums.ViewportType.STACK,
|
||||
};
|
||||
|
||||
renderingEngine.enableElement(viewportInput);
|
||||
}
|
||||
};
|
||||
|
||||
const disableViewport = viewportElement => {
|
||||
if (viewportElement) {
|
||||
const renderingEngine = CornerstoneViewportService.getRenderingEngine();
|
||||
|
||||
return new Promise(resolve => {
|
||||
renderingEngine.disableElement(VIEWPORT_ID);
|
||||
ToolGroupManager.destroyToolGroup(TOOLGROUP_ID);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
const updateViewportPreview = (
|
||||
downloadViewportElement,
|
||||
internalCanvas,
|
||||
fileType
|
||||
) =>
|
||||
new Promise(resolve => {
|
||||
const enabledElement = getEnabledElement(downloadViewportElement);
|
||||
|
||||
const { viewport: downloadViewport, renderingEngine } = enabledElement;
|
||||
|
||||
// Note: Since any trigger of dimensions will update the viewport,
|
||||
// we need to resize the offScreenCanvas to accommodate for the new
|
||||
// dimensions, this is due to the reason that we are using the GPU offScreenCanvas
|
||||
// to render the viewport for the downloadViewport.
|
||||
renderingEngine.resize();
|
||||
|
||||
// Trigger the render on the viewport to update the on screen
|
||||
downloadViewport.render();
|
||||
|
||||
downloadViewportElement.addEventListener(
|
||||
Enums.Events.IMAGE_RENDERED,
|
||||
function updateViewport(event) {
|
||||
const enabledElement = getEnabledElement(event.target);
|
||||
const { viewport } = enabledElement;
|
||||
const { element } = viewport;
|
||||
|
||||
const downloadCanvas = getOrCreateCanvas(element);
|
||||
|
||||
const type = 'image/' + fileType;
|
||||
const dataUrl = downloadCanvas.toDataURL(type, 1);
|
||||
|
||||
let newWidth = element.offsetHeight;
|
||||
let newHeight = element.offsetWidth;
|
||||
|
||||
if (newWidth > DEFAULT_SIZE || newHeight > DEFAULT_SIZE) {
|
||||
const multiplier = DEFAULT_SIZE / Math.max(newWidth, newHeight);
|
||||
newHeight *= multiplier;
|
||||
newWidth *= multiplier;
|
||||
}
|
||||
|
||||
resolve({ dataUrl, width: newWidth, height: newHeight });
|
||||
|
||||
downloadViewportElement.removeEventListener(
|
||||
Enums.Events.IMAGE_RENDERED,
|
||||
updateViewport
|
||||
);
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
const loadImage = (activeViewportElement, viewportElement, width, height) =>
|
||||
new Promise(resolve => {
|
||||
if (activeViewportElement && viewportElement) {
|
||||
const activeViewportEnabledElement = getEnabledElement(
|
||||
activeViewportElement
|
||||
);
|
||||
|
||||
if (!activeViewportEnabledElement) {
|
||||
return;
|
||||
}
|
||||
|
||||
const { viewport } = activeViewportEnabledElement;
|
||||
|
||||
if (!(viewport instanceof StackViewport)) {
|
||||
throw new Error('Viewport is not a StackViewport');
|
||||
}
|
||||
|
||||
const imageId = viewport.getCurrentImageId();
|
||||
|
||||
const renderingEngine = CornerstoneViewportService.getRenderingEngine();
|
||||
const downloadViewport = renderingEngine.getViewport(
|
||||
VIEWPORT_ID
|
||||
) as StackViewport;
|
||||
|
||||
downloadViewport.setStack([imageId]).then(() => {
|
||||
const properties = viewport.getProperties();
|
||||
downloadViewport.setProperties(properties);
|
||||
|
||||
const newWidth = Math.min(width || image.width, MAX_TEXTURE_SIZE);
|
||||
const newHeight = Math.min(height || image.height, MAX_TEXTURE_SIZE);
|
||||
|
||||
resolve({ width: newWidth, height: newHeight });
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
const toggleAnnotations = (
|
||||
toggle,
|
||||
viewportElement,
|
||||
activeViewportElement
|
||||
) => {
|
||||
const activeViewportEnabledElement = getEnabledElement(
|
||||
activeViewportElement
|
||||
);
|
||||
|
||||
const downloadViewportElement = getEnabledElement(viewportElement);
|
||||
|
||||
const {
|
||||
viewportId: activeViewportId,
|
||||
renderingEngineId,
|
||||
} = activeViewportEnabledElement;
|
||||
const { viewportId: downloadViewportId } = downloadViewportElement;
|
||||
|
||||
if (!activeViewportEnabledElement || !downloadViewportElement) {
|
||||
return;
|
||||
}
|
||||
|
||||
const toolGroup = ToolGroupManager.getToolGroupForViewport(
|
||||
activeViewportId,
|
||||
renderingEngineId
|
||||
);
|
||||
|
||||
let downloadToolGroup = ToolGroupManager.getToolGroupForViewport(
|
||||
downloadViewportId,
|
||||
renderingEngineId
|
||||
);
|
||||
|
||||
if (downloadToolGroup === undefined) {
|
||||
downloadToolGroup = ToolGroupManager.createToolGroup(TOOLGROUP_ID);
|
||||
|
||||
// what tools were in the active viewport?
|
||||
// make them all enabled instances so that they can not be interacted
|
||||
// with in the download viewport
|
||||
Object.values(toolGroup._toolInstances).forEach(tool => {
|
||||
downloadToolGroup.addTool(tool.getToolName());
|
||||
});
|
||||
|
||||
// add the viewport to the toolGroup
|
||||
downloadToolGroup.addViewport(downloadViewportId);
|
||||
}
|
||||
|
||||
Object.values(downloadToolGroup._toolInstances).forEach(tool => {
|
||||
const toolName = tool.getToolName();
|
||||
if (toggle) {
|
||||
downloadToolGroup.setToolEnabled(toolName);
|
||||
} else {
|
||||
downloadToolGroup.setToolDisabled(toolName);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
const downloadBlob = (filename, fileType) => {
|
||||
const file = `${filename}.${fileType}`;
|
||||
const divForDownloadViewport = document.querySelector(
|
||||
`div[data-viewport-uid="${VIEWPORT_ID}"]`
|
||||
);
|
||||
|
||||
domtoimage.toPng(divForDownloadViewport).then(dataUrl => {
|
||||
const link = document.createElement('a');
|
||||
link.download = file;
|
||||
link.href = dataUrl;
|
||||
link.click();
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<ViewportDownloadForm
|
||||
onClose={onClose}
|
||||
minimumSize={MINIMUM_SIZE}
|
||||
maximumSize={MAX_TEXTURE_SIZE}
|
||||
defaultSize={DEFAULT_SIZE}
|
||||
canvasClass={'cornerstone-canvas'}
|
||||
activeViewportElement={activeViewportElement}
|
||||
enableViewport={enableViewport}
|
||||
disableViewport={disableViewport}
|
||||
updateViewportPreview={updateViewportPreview}
|
||||
loadImage={loadImage}
|
||||
toggleAnnotations={toggleAnnotations}
|
||||
downloadBlob={downloadBlob}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
CornerstoneViewportDownloadForm.propTypes = {
|
||||
onClose: PropTypes.func,
|
||||
activeViewportIndex: PropTypes.number.isRequired,
|
||||
};
|
||||
|
||||
export default CornerstoneViewportDownloadForm;
|
||||
@@ -0,0 +1,14 @@
|
||||
/**
|
||||
* Jump Presets - This enum defines the 3 jump states which are available
|
||||
* to be used with the jumpToSlice utility function.
|
||||
*/
|
||||
enum JumpPresets {
|
||||
/** Jumps to first slice */
|
||||
First = 'first',
|
||||
/** Jumps to last slice */
|
||||
Last = 'last',
|
||||
/** Jumps to the middle slice */
|
||||
Middle = 'middle',
|
||||
}
|
||||
|
||||
export default JumpPresets;
|
||||
@@ -0,0 +1,82 @@
|
||||
import React from 'react';
|
||||
import { Input, Dialog } from '@ohif/ui';
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {*} data
|
||||
* @param {*} data.text
|
||||
* @param {*} data.label
|
||||
* @param {*} event
|
||||
* @param {*} callback
|
||||
* @param {*} isArrowAnnotateInputDialog
|
||||
*/
|
||||
function callInputDialog(
|
||||
UIDialogService,
|
||||
data,
|
||||
callback,
|
||||
isArrowAnnotateInputDialog = true
|
||||
) {
|
||||
const dialogId = 'enter-annotation';
|
||||
const label = data
|
||||
? isArrowAnnotateInputDialog
|
||||
? data.text
|
||||
: data.label
|
||||
: '';
|
||||
|
||||
const onSubmitHandler = ({ action, value }) => {
|
||||
switch (action.id) {
|
||||
case 'save':
|
||||
callback(value.label, action.id);
|
||||
break;
|
||||
case 'cancel':
|
||||
callback('', action.id);
|
||||
break;
|
||||
}
|
||||
UIDialogService.dismiss({ id: dialogId });
|
||||
};
|
||||
|
||||
if (UIDialogService) {
|
||||
UIDialogService.create({
|
||||
id: dialogId,
|
||||
centralize: true,
|
||||
isDraggable: false,
|
||||
showOverlay: true,
|
||||
content: Dialog,
|
||||
contentProps: {
|
||||
title: 'Enter your annotation',
|
||||
value: { label },
|
||||
noCloseButton: true,
|
||||
onClose: () => UIDialogService.dismiss({ id: dialogId }),
|
||||
actions: [
|
||||
{ id: 'cancel', text: 'Cancel', type: 'primary' },
|
||||
{ id: 'save', text: 'Save', type: 'secondary' },
|
||||
],
|
||||
onSubmit: onSubmitHandler,
|
||||
body: ({ value, setValue }) => {
|
||||
return (
|
||||
<div className="p-4 bg-primary-dark">
|
||||
<Input
|
||||
autoFocus
|
||||
className="mt-2 bg-black border-primary-main"
|
||||
type="text"
|
||||
containerClassName="mr-2"
|
||||
value={value.label}
|
||||
onChange={event => {
|
||||
event.persist();
|
||||
setValue(value => ({ ...value, label: event.target.value }));
|
||||
}}
|
||||
onKeyPress={event => {
|
||||
if (event.key === 'Enter') {
|
||||
onSubmitHandler({ value, action: { id: 'save' } });
|
||||
}
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export default callInputDialog;
|
||||
@@ -0,0 +1,139 @@
|
||||
import vtkColorTransferFunction from '@kitware/vtk.js/Rendering/Core/ColorTransferFunction';
|
||||
import vtkPiecewiseFunction from '@kitware/vtk.js/Common/DataModel/PiecewiseFunction';
|
||||
|
||||
import presets from './presets';
|
||||
|
||||
// get preset from preset name
|
||||
function getPreset(name) {
|
||||
return presets.find(preset => preset.name === name);
|
||||
}
|
||||
|
||||
// Todo: we should be able to register a new preset via the utilityModule
|
||||
// of the cornerstone extension
|
||||
export default function applyPreset(actor, presetName) {
|
||||
const preset = getPreset(presetName);
|
||||
// Create color transfer function
|
||||
const colorTransferArray = preset.colorTransfer
|
||||
.split(' ')
|
||||
.splice(1)
|
||||
.map(parseFloat);
|
||||
|
||||
const { shiftRange } = getShiftRange(colorTransferArray);
|
||||
let min = shiftRange[0];
|
||||
const width = shiftRange[1] - shiftRange[0];
|
||||
const cfun = vtkColorTransferFunction.newInstance();
|
||||
const normColorTransferValuePoints = [];
|
||||
for (let i = 0; i < colorTransferArray.length; i += 4) {
|
||||
let value = colorTransferArray[i];
|
||||
const r = colorTransferArray[i + 1];
|
||||
const g = colorTransferArray[i + 2];
|
||||
const b = colorTransferArray[i + 3];
|
||||
|
||||
value = (value - min) / width;
|
||||
normColorTransferValuePoints.push([value, r, g, b]);
|
||||
}
|
||||
|
||||
applyPointsToRGBFunction(normColorTransferValuePoints, shiftRange, cfun);
|
||||
|
||||
actor.getProperty().setRGBTransferFunction(0, cfun);
|
||||
|
||||
// Create scalar opacity function
|
||||
const scalarOpacityArray = preset.scalarOpacity
|
||||
.split(' ')
|
||||
.splice(1)
|
||||
.map(parseFloat);
|
||||
|
||||
const ofun = vtkPiecewiseFunction.newInstance();
|
||||
const normPoints = [];
|
||||
for (let i = 0; i < scalarOpacityArray.length; i += 2) {
|
||||
let value = scalarOpacityArray[i];
|
||||
const opacity = scalarOpacityArray[i + 1];
|
||||
|
||||
value = (value - min) / width;
|
||||
|
||||
normPoints.push([value, opacity]);
|
||||
}
|
||||
|
||||
applyPointsToPiecewiseFunction(normPoints, shiftRange, ofun);
|
||||
|
||||
actor.getProperty().setScalarOpacity(0, ofun);
|
||||
|
||||
const [
|
||||
gradientMinValue,
|
||||
gradientMinOpacity,
|
||||
gradientMaxValue,
|
||||
gradientMaxOpacity,
|
||||
] = preset.gradientOpacity
|
||||
.split(' ')
|
||||
.splice(1)
|
||||
.map(parseFloat);
|
||||
|
||||
actor.getProperty().setUseGradientOpacity(0, true);
|
||||
actor.getProperty().setGradientOpacityMinimumValue(0, gradientMinValue);
|
||||
actor.getProperty().setGradientOpacityMinimumOpacity(0, gradientMinOpacity);
|
||||
actor.getProperty().setGradientOpacityMaximumValue(0, gradientMaxValue);
|
||||
actor.getProperty().setGradientOpacityMaximumOpacity(0, gradientMaxOpacity);
|
||||
|
||||
if (preset.interpolation === '1') {
|
||||
actor.getProperty().setInterpolationTypeToFastLinear();
|
||||
//actor.getProperty().setInterpolationTypeToLinear()
|
||||
}
|
||||
|
||||
const ambient = parseFloat(preset.ambient);
|
||||
//const shade = preset.shade === '1'
|
||||
const diffuse = parseFloat(preset.diffuse);
|
||||
const specular = parseFloat(preset.specular);
|
||||
const specularPower = parseFloat(preset.specularPower);
|
||||
|
||||
//actor.getProperty().setShade(shade)
|
||||
actor.getProperty().setAmbient(ambient);
|
||||
actor.getProperty().setDiffuse(diffuse);
|
||||
actor.getProperty().setSpecular(specular);
|
||||
actor.getProperty().setSpecularPower(specularPower);
|
||||
}
|
||||
|
||||
function getShiftRange(colorTransferArray) {
|
||||
// Credit to paraview-glance
|
||||
// https://github.com/Kitware/paraview-glance/blob/3fec8eeff31e9c19ad5b6bff8e7159bd745e2ba9/src/components/controls/ColorBy/script.js#L133
|
||||
|
||||
// shift range is original rgb/opacity range centered around 0
|
||||
let min = Infinity;
|
||||
let max = -Infinity;
|
||||
for (let i = 0; i < colorTransferArray.length; i += 4) {
|
||||
min = Math.min(min, colorTransferArray[i]);
|
||||
max = Math.max(max, colorTransferArray[i]);
|
||||
}
|
||||
|
||||
const center = (max - min) / 2;
|
||||
|
||||
return {
|
||||
shiftRange: [-center, center],
|
||||
min,
|
||||
max,
|
||||
};
|
||||
}
|
||||
|
||||
function applyPointsToRGBFunction(points, range, cfun) {
|
||||
const width = range[1] - range[0];
|
||||
const rescaled = points.map(([x, r, g, b]) => [
|
||||
x * width + range[0],
|
||||
r,
|
||||
g,
|
||||
b,
|
||||
]);
|
||||
|
||||
cfun.removeAllPoints();
|
||||
rescaled.forEach(([x, r, g, b]) => cfun.addRGBPoint(x, r, g, b));
|
||||
|
||||
return rescaled;
|
||||
}
|
||||
|
||||
function applyPointsToPiecewiseFunction(points, range, pwf) {
|
||||
const width = range[1] - range[0];
|
||||
const rescaled = points.map(([x, y]) => [x * width + range[0], y]);
|
||||
|
||||
pwf.removeAllPoints();
|
||||
rescaled.forEach(([x, y]) => pwf.addPoint(x, y));
|
||||
|
||||
return rescaled;
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
// https://www.slicer.org/w/index.php/Slicer3:2010_GenericAnatomyColors#Lookup_table
|
||||
const colors = [
|
||||
{
|
||||
integerLabel: 0,
|
||||
textLabel: 'background',
|
||||
color: [0, 0, 0, 0],
|
||||
},
|
||||
{
|
||||
integerLabel: 1,
|
||||
textLabel: 'tissue',
|
||||
// color: [255, 174, 128, 255],
|
||||
color: [255, 0, 0, 255],
|
||||
},
|
||||
{
|
||||
integerLabel: 2,
|
||||
textLabel: 'bone',
|
||||
// color: [241, 214, 145, 255],
|
||||
color: [0, 255, 0, 255],
|
||||
},
|
||||
{
|
||||
integerLabel: 3,
|
||||
textLabel: 'skin',
|
||||
// color: [177, 122, 101, 255],
|
||||
color: [0, 0, 255, 255],
|
||||
},
|
||||
// ....
|
||||
];
|
||||
|
||||
export default colors;
|
||||
@@ -0,0 +1,435 @@
|
||||
const presets = [
|
||||
{
|
||||
name: 'CT-AAA',
|
||||
gradientOpacity: '4 0 1 255 1',
|
||||
specularPower: '10',
|
||||
scalarOpacity:
|
||||
'12 -3024 0 143.556 0 166.222 0.686275 214.389 0.696078 419.736 0.833333 3071 0.803922',
|
||||
id: 'vtkMRMLVolumePropertyNode1',
|
||||
specular: '0.2',
|
||||
shade: '1',
|
||||
ambient: '0.1',
|
||||
colorTransfer:
|
||||
'24 -3024 0 0 0 143.556 0.615686 0.356863 0.184314 166.222 0.882353 0.603922 0.290196 214.389 1 1 1 419.736 1 0.937033 0.954531 3071 0.827451 0.658824 1',
|
||||
selectable: 'true',
|
||||
diffuse: '0.9',
|
||||
interpolation: '1',
|
||||
effectiveRange: '143.556 419.736',
|
||||
},
|
||||
{
|
||||
name: 'CT-AAA2',
|
||||
gradientOpacity: '4 0 1 255 1',
|
||||
specularPower: '10',
|
||||
scalarOpacity:
|
||||
'16 -3024 0 129.542 0 145.244 0.166667 157.02 0.5 169.918 0.627451 395.575 0.8125 1578.73 0.8125 3071 0.8125',
|
||||
id: 'vtkMRMLVolumePropertyNode2',
|
||||
specular: '0.2',
|
||||
shade: '1',
|
||||
ambient: '0.1',
|
||||
colorTransfer:
|
||||
'32 -3024 0 0 0 129.542 0.54902 0.25098 0.14902 145.244 0.6 0.627451 0.843137 157.02 0.890196 0.47451 0.6 169.918 0.992157 0.870588 0.392157 395.575 1 0.886275 0.658824 1578.73 1 0.829256 0.957922 3071 0.827451 0.658824 1',
|
||||
selectable: 'true',
|
||||
diffuse: '0.9',
|
||||
interpolation: '1',
|
||||
effectiveRange: '0 1600',
|
||||
},
|
||||
{
|
||||
name: 'CT-Bone',
|
||||
gradientOpacity: '4 0 1 255 1',
|
||||
specularPower: '10',
|
||||
scalarOpacity: '8 -3024 0 -16.4458 0 641.385 0.715686 3071 0.705882',
|
||||
id: 'vtkMRMLVolumePropertyNode3',
|
||||
specular: '0.2',
|
||||
shade: '1',
|
||||
ambient: '0.1',
|
||||
colorTransfer:
|
||||
'16 -3024 0 0 0 -16.4458 0.729412 0.254902 0.301961 641.385 0.905882 0.815686 0.552941 3071 1 1 1',
|
||||
selectable: 'true',
|
||||
diffuse: '0.9',
|
||||
interpolation: '1',
|
||||
effectiveRange: '-16.4458 641.385',
|
||||
},
|
||||
{
|
||||
name: 'CT-Bones',
|
||||
gradientOpacity: '4 0 1 985.12 1',
|
||||
specularPower: '1',
|
||||
scalarOpacity: '8 -1000 0 152.19 0 278.93 0.190476 952 0.2',
|
||||
id: 'vtkMRMLVolumePropertyNode4',
|
||||
specular: '0',
|
||||
shade: '1',
|
||||
ambient: '0.2',
|
||||
colorTransfer:
|
||||
'20 -1000 0.3 0.3 1 -488 0.3 1 0.3 463.28 1 0 0 659.15 1 0.912535 0.0374849 953 1 0.3 0.3',
|
||||
selectable: 'true',
|
||||
diffuse: '1',
|
||||
interpolation: '1',
|
||||
effectiveRange: '152.19 952',
|
||||
},
|
||||
{
|
||||
name: 'CT-Cardiac',
|
||||
gradientOpacity: '4 0 1 255 1',
|
||||
specularPower: '10',
|
||||
scalarOpacity:
|
||||
'12 -3024 0 -77.6875 0 94.9518 0.285714 179.052 0.553571 260.439 0.848214 3071 0.875',
|
||||
id: 'vtkMRMLVolumePropertyNode5',
|
||||
specular: '0.2',
|
||||
shade: '1',
|
||||
ambient: '0.1',
|
||||
colorTransfer:
|
||||
'24 -3024 0 0 0 -77.6875 0.54902 0.25098 0.14902 94.9518 0.882353 0.603922 0.290196 179.052 1 0.937033 0.954531 260.439 0.615686 0 0 3071 0.827451 0.658824 1',
|
||||
selectable: 'true',
|
||||
diffuse: '0.9',
|
||||
interpolation: '1',
|
||||
effectiveRange: '-77.6875 260.439',
|
||||
},
|
||||
{
|
||||
name: 'CT-Cardiac2',
|
||||
gradientOpacity: '4 0 1 255 1',
|
||||
specularPower: '10',
|
||||
scalarOpacity:
|
||||
'12 -3024 0 42.8964 0 163.488 0.428571 277.642 0.776786 1587 0.754902 3071 0.754902',
|
||||
id: 'vtkMRMLVolumePropertyNode6',
|
||||
specular: '0.2',
|
||||
shade: '1',
|
||||
ambient: '0.1',
|
||||
colorTransfer:
|
||||
'24 -3024 0 0 0 42.8964 0.54902 0.25098 0.14902 163.488 0.917647 0.639216 0.0588235 277.642 1 0.878431 0.623529 1587 1 1 1 3071 0.827451 0.658824 1',
|
||||
selectable: 'true',
|
||||
diffuse: '0.9',
|
||||
interpolation: '1',
|
||||
effectiveRange: '42.8964 1587',
|
||||
},
|
||||
{
|
||||
name: 'CT-Cardiac3',
|
||||
gradientOpacity: '4 0 1 255 1',
|
||||
specularPower: '10',
|
||||
scalarOpacity:
|
||||
'14 -3024 0 -86.9767 0 45.3791 0.169643 139.919 0.589286 347.907 0.607143 1224.16 0.607143 3071 0.616071',
|
||||
id: 'vtkMRMLVolumePropertyNode7',
|
||||
specular: '0.2',
|
||||
shade: '1',
|
||||
ambient: '0.1',
|
||||
colorTransfer:
|
||||
'28 -3024 0 0 0 -86.9767 0 0.25098 1 45.3791 1 0 0 139.919 1 0.894893 0.894893 347.907 1 1 0.25098 1224.16 1 1 1 3071 0.827451 0.658824 1',
|
||||
selectable: 'true',
|
||||
diffuse: '0.9',
|
||||
interpolation: '1',
|
||||
effectiveRange: '-86.9767 1224.16',
|
||||
},
|
||||
{
|
||||
name: 'CT-Chest-Contrast-Enhanced',
|
||||
gradientOpacity: '4 0 1 255 1',
|
||||
specularPower: '10',
|
||||
scalarOpacity:
|
||||
'10 -3024 0 67.0106 0 251.105 0.446429 439.291 0.625 3071 0.616071',
|
||||
id: 'vtkMRMLVolumePropertyNode8',
|
||||
specular: '0.2',
|
||||
shade: '1',
|
||||
ambient: '0.1',
|
||||
colorTransfer:
|
||||
'20 -3024 0 0 0 67.0106 0.54902 0.25098 0.14902 251.105 0.882353 0.603922 0.290196 439.291 1 0.937033 0.954531 3071 0.827451 0.658824 1',
|
||||
selectable: 'true',
|
||||
diffuse: '0.9',
|
||||
interpolation: '1',
|
||||
effectiveRange: '67.0106 439.291',
|
||||
},
|
||||
{
|
||||
name: 'CT-Chest-Vessels',
|
||||
gradientOpacity: '4 0 1 255 1',
|
||||
specularPower: '1',
|
||||
scalarOpacity:
|
||||
'10 -3024 0 -1278.35 0 22.8277 0.428571 439.291 0.625 3071 0.616071',
|
||||
id: 'vtkMRMLVolumePropertyNode9',
|
||||
specular: '0',
|
||||
shade: '1',
|
||||
ambient: '0.2',
|
||||
colorTransfer:
|
||||
'20 -3024 0 0 0 -1278.35 0.54902 0.25098 0.14902 22.8277 0.882353 0.603922 0.290196 439.291 1 0.937033 0.954531 3071 0.827451 0.658824 1',
|
||||
selectable: 'true',
|
||||
diffuse: '1',
|
||||
interpolation: '1',
|
||||
effectiveRange: '-1278.35 439.291',
|
||||
},
|
||||
{
|
||||
name: 'CT-Coronary-Arteries',
|
||||
gradientOpacity: '4 0 1 255 1',
|
||||
specularPower: '1',
|
||||
scalarOpacity:
|
||||
'12 -2048 0 136.47 0 159.215 0.258929 318.43 0.571429 478.693 0.776786 3661 1',
|
||||
id: 'vtkMRMLVolumePropertyNode10',
|
||||
specular: '0',
|
||||
shade: '0',
|
||||
ambient: '0.2',
|
||||
colorTransfer:
|
||||
'24 -2048 0 0 0 136.47 0 0 0 159.215 0.159804 0.159804 0.159804 318.43 0.764706 0.764706 0.764706 478.693 1 1 1 3661 1 1 1',
|
||||
selectable: 'true',
|
||||
diffuse: '1',
|
||||
interpolation: '1',
|
||||
effectiveRange: '136.47 478.693',
|
||||
},
|
||||
{
|
||||
name: 'CT-Coronary-Arteries-2',
|
||||
gradientOpacity: '4 0 1 255 1',
|
||||
specularPower: '1',
|
||||
scalarOpacity:
|
||||
'14 -2048 0 142.677 0 145.016 0.116071 192.174 0.5625 217.24 0.776786 384.347 0.830357 3661 0.830357',
|
||||
id: 'vtkMRMLVolumePropertyNode11',
|
||||
specular: '0',
|
||||
shade: '1',
|
||||
ambient: '0.2',
|
||||
colorTransfer:
|
||||
'28 -2048 0 0 0 142.677 0 0 0 145.016 0.615686 0 0.0156863 192.174 0.909804 0.454902 0 217.24 0.972549 0.807843 0.611765 384.347 0.909804 0.909804 1 3661 1 1 1',
|
||||
selectable: 'true',
|
||||
diffuse: '1',
|
||||
interpolation: '1',
|
||||
effectiveRange: '142.677 384.347',
|
||||
},
|
||||
{
|
||||
name: 'CT-Coronary-Arteries-3',
|
||||
gradientOpacity: '4 0 1 255 1',
|
||||
specularPower: '10',
|
||||
scalarOpacity:
|
||||
'14 -2048 0 128.643 0 129.982 0.0982143 173.636 0.669643 255.884 0.857143 584.878 0.866071 3661 1',
|
||||
id: 'vtkMRMLVolumePropertyNode12',
|
||||
specular: '0.2',
|
||||
shade: '1',
|
||||
ambient: '0.1',
|
||||
colorTransfer:
|
||||
'28 -2048 0 0 0 128.643 0 0 0 129.982 0.615686 0 0.0156863 173.636 0.909804 0.454902 0 255.884 0.886275 0.886275 0.886275 584.878 0.968627 0.968627 0.968627 3661 1 1 1',
|
||||
selectable: 'true',
|
||||
diffuse: '0.9',
|
||||
interpolation: '1',
|
||||
effectiveRange: '128.643 584.878',
|
||||
},
|
||||
{
|
||||
name: 'CT-Cropped-Volume-Bone',
|
||||
gradientOpacity: '4 0 1 255 1',
|
||||
specularPower: '1',
|
||||
scalarOpacity: '10 -2048 0 -451 0 -450 1 1050 1 3661 1',
|
||||
id: 'vtkMRMLVolumePropertyNode13',
|
||||
specular: '0',
|
||||
shade: '0',
|
||||
ambient: '0.2',
|
||||
colorTransfer:
|
||||
'20 -2048 0 0 0 -451 0 0 0 -450 0.0556356 0.0556356 0.0556356 1050 1 1 1 3661 1 1 1',
|
||||
selectable: 'true',
|
||||
diffuse: '1',
|
||||
interpolation: '1',
|
||||
effectiveRange: '-451 1050',
|
||||
},
|
||||
{
|
||||
name: 'CT-Fat',
|
||||
gradientOpacity: '6 0 1 985.12 1 988 1',
|
||||
specularPower: '1',
|
||||
scalarOpacity: '14 -1000 0 -100 0 -99 0.15 -60 0.15 -59 0 101.2 0 952 0',
|
||||
id: 'vtkMRMLVolumePropertyNode14',
|
||||
specular: '0',
|
||||
references: '0',
|
||||
shade: '0',
|
||||
ambient: '0.2',
|
||||
colorTransfer:
|
||||
'36 -1000 0.3 0.3 1 -497.5 0.3 1 0.3 -99 0 0 1 -76.946 0 1 0 -65.481 0.835431 0.888889 0.0165387 83.89 1 0 0 463.28 1 0 0 659.15 1 0.912535 0.0374849 2952 1 0.300267 0.299886',
|
||||
selectable: 'true',
|
||||
diffuse: '1',
|
||||
interpolation: '1',
|
||||
effectiveRange: '-100 101.2',
|
||||
},
|
||||
{
|
||||
name: 'CT-Liver-Vasculature',
|
||||
gradientOpacity: '4 0 1 255 1',
|
||||
specularPower: '1',
|
||||
scalarOpacity:
|
||||
'14 -2048 0 149.113 0 157.884 0.482143 339.96 0.660714 388.526 0.830357 1197.95 0.839286 3661 0.848214',
|
||||
id: 'vtkMRMLVolumePropertyNode15',
|
||||
specular: '0',
|
||||
shade: '0',
|
||||
ambient: '0.2',
|
||||
colorTransfer:
|
||||
'28 -2048 0 0 0 149.113 0 0 0 157.884 0.501961 0.25098 0 339.96 0.695386 0.59603 0.36886 388.526 0.854902 0.85098 0.827451 1197.95 1 1 1 3661 1 1 1',
|
||||
selectable: 'true',
|
||||
diffuse: '1',
|
||||
interpolation: '1',
|
||||
effectiveRange: '149.113 1197.95',
|
||||
},
|
||||
{
|
||||
name: 'CT-Lung',
|
||||
gradientOpacity: '6 0 1 985.12 1 988 1',
|
||||
specularPower: '1',
|
||||
scalarOpacity: '12 -1000 0 -600 0 -599 0.15 -400 0.15 -399 0 2952 0',
|
||||
id: 'vtkMRMLVolumePropertyNode16',
|
||||
specular: '0',
|
||||
references: '0',
|
||||
shade: '1',
|
||||
ambient: '0.2',
|
||||
colorTransfer:
|
||||
'24 -1000 0.3 0.3 1 -600 0 0 1 -530 0.134704 0.781726 0.0724558 -460 0.929244 1 0.109473 -400 0.888889 0.254949 0.0240258 2952 1 0.3 0.3',
|
||||
selectable: 'true',
|
||||
diffuse: '1',
|
||||
interpolation: '1',
|
||||
effectiveRange: '-600 -399',
|
||||
},
|
||||
{
|
||||
name: 'CT-MIP',
|
||||
gradientOpacity: '4 0 1 255 1',
|
||||
specularPower: '10',
|
||||
scalarOpacity: '8 -3024 0 -637.62 0 700 1 3071 1',
|
||||
id: 'vtkMRMLVolumePropertyNode17',
|
||||
specular: '0.2',
|
||||
shade: '1',
|
||||
ambient: '0.1',
|
||||
colorTransfer: '16 -3024 0 0 0 -637.62 1 1 1 700 1 1 1 3071 1 1 1',
|
||||
selectable: 'true',
|
||||
diffuse: '0.9',
|
||||
interpolation: '1',
|
||||
effectiveRange: '-637.62 700',
|
||||
},
|
||||
{
|
||||
name: 'CT-Muscle',
|
||||
gradientOpacity: '4 0 1 255 1',
|
||||
specularPower: '10',
|
||||
scalarOpacity:
|
||||
'10 -3024 0 -155.407 0 217.641 0.676471 419.736 0.833333 3071 0.803922',
|
||||
id: 'vtkMRMLVolumePropertyNode18',
|
||||
specular: '0.2',
|
||||
shade: '1',
|
||||
ambient: '0.1',
|
||||
colorTransfer:
|
||||
'20 -3024 0 0 0 -155.407 0.54902 0.25098 0.14902 217.641 0.882353 0.603922 0.290196 419.736 1 0.937033 0.954531 3071 0.827451 0.658824 1',
|
||||
selectable: 'true',
|
||||
diffuse: '0.9',
|
||||
interpolation: '1',
|
||||
effectiveRange: '-155.407 419.736',
|
||||
},
|
||||
{
|
||||
name: 'CT-Pulmonary-Arteries',
|
||||
gradientOpacity: '4 0 1 255 1',
|
||||
specularPower: '1',
|
||||
scalarOpacity:
|
||||
'14 -2048 0 -568.625 0 -364.081 0.0714286 -244.813 0.401786 18.2775 0.607143 447.798 0.830357 3592.73 0.839286',
|
||||
id: 'vtkMRMLVolumePropertyNode19',
|
||||
specular: '0',
|
||||
shade: '1',
|
||||
ambient: '0.2',
|
||||
colorTransfer:
|
||||
'28 -2048 0 0 0 -568.625 0 0 0 -364.081 0.396078 0.301961 0.180392 -244.813 0.611765 0.352941 0.0705882 18.2775 0.843137 0.0156863 0.156863 447.798 0.752941 0.752941 0.752941 3592.73 1 1 1',
|
||||
selectable: 'true',
|
||||
diffuse: '1',
|
||||
interpolation: '1',
|
||||
effectiveRange: '-568.625 447.798',
|
||||
},
|
||||
{
|
||||
name: 'CT-Soft-Tissue',
|
||||
gradientOpacity: '4 0 1 255 1',
|
||||
specularPower: '1',
|
||||
scalarOpacity: '10 -2048 0 -167.01 0 -160 1 240 1 3661 1',
|
||||
id: 'vtkMRMLVolumePropertyNode20',
|
||||
specular: '0',
|
||||
shade: '0',
|
||||
ambient: '0.2',
|
||||
colorTransfer:
|
||||
'20 -2048 0 0 0 -167.01 0 0 0 -160 0.0556356 0.0556356 0.0556356 240 1 1 1 3661 1 1 1',
|
||||
selectable: 'true',
|
||||
diffuse: '1',
|
||||
interpolation: '1',
|
||||
effectiveRange: '-167.01 240',
|
||||
},
|
||||
{
|
||||
name: 'CT-Air',
|
||||
gradientOpacity: '4 0 1 255 1',
|
||||
specularPower: '10',
|
||||
scalarOpacity: '8 -3024 0.705882 -900.0 0.715686 -500.0 0 3071 0',
|
||||
id: 'vtkMRMLVolumePropertyNode21',
|
||||
specular: '0.2',
|
||||
shade: '1',
|
||||
ambient: '0.1',
|
||||
colorTransfer:
|
||||
'16 -3024 1 1 1 -900.0 0.2 1.0 1.0 -500.0 0.3 0.3 1.0 3071 0 0 0 ',
|
||||
selectable: 'true',
|
||||
diffuse: '0.9',
|
||||
interpolation: '1',
|
||||
effectiveRange: '-1200.0 -200.0',
|
||||
},
|
||||
{
|
||||
name: 'MR-Angio',
|
||||
gradientOpacity: '4 0 1 255 1',
|
||||
specularPower: '1',
|
||||
scalarOpacity:
|
||||
'12 -2048 0 151.354 0 158.279 0.4375 190.112 0.580357 200.873 0.732143 3661 0.741071',
|
||||
id: 'vtkMRMLVolumePropertyNode22',
|
||||
specular: '0',
|
||||
shade: '1',
|
||||
ambient: '0.2',
|
||||
colorTransfer:
|
||||
'24 -2048 0 0 0 151.354 0 0 0 158.279 0.74902 0.376471 0 190.112 1 0.866667 0.733333 200.873 0.937255 0.937255 0.937255 3661 1 1 1',
|
||||
selectable: 'true',
|
||||
diffuse: '1',
|
||||
interpolation: '1',
|
||||
effectiveRange: '151.354 200.873',
|
||||
},
|
||||
{
|
||||
name: 'MR-Default',
|
||||
gradientOpacity: '4 0 1 255 1',
|
||||
specularPower: '1',
|
||||
scalarOpacity: '12 0 0 20 0 40 0.15 120 0.3 220 0.375 1024 0.5',
|
||||
id: 'vtkMRMLVolumePropertyNode23',
|
||||
specular: '0',
|
||||
shade: '1',
|
||||
ambient: '0.2',
|
||||
colorTransfer:
|
||||
'24 0 0 0 0 20 0.168627 0 0 40 0.403922 0.145098 0.0784314 120 0.780392 0.607843 0.380392 220 0.847059 0.835294 0.788235 1024 1 1 1',
|
||||
selectable: 'true',
|
||||
diffuse: '1',
|
||||
interpolation: '1',
|
||||
effectiveRange: '0 220',
|
||||
},
|
||||
{
|
||||
name: 'MR-MIP',
|
||||
gradientOpacity: '4 0 1 255 1',
|
||||
specularPower: '1',
|
||||
scalarOpacity: '8 0 0 98.3725 0 416.637 1 2800 1',
|
||||
id: 'vtkMRMLVolumePropertyNode24',
|
||||
specular: '0',
|
||||
shade: '0',
|
||||
ambient: '0.2',
|
||||
colorTransfer: '16 0 1 1 1 98.3725 1 1 1 416.637 1 1 1 2800 1 1 1',
|
||||
selectable: 'true',
|
||||
diffuse: '1',
|
||||
interpolation: '1',
|
||||
effectiveRange: '0 416.637',
|
||||
},
|
||||
{
|
||||
name: 'MR-T2-Brain',
|
||||
gradientOpacity: '4 0 1 160.25 1',
|
||||
specularPower: '40',
|
||||
scalarOpacity: '10 0 0 36.05 0 218.302 0.171429 412.406 1 641 1',
|
||||
id: 'vtkMRMLVolumePropertyNode25',
|
||||
specular: '0.5',
|
||||
shade: '1',
|
||||
ambient: '0.3',
|
||||
colorTransfer:
|
||||
'16 0 0 0 0 98.7223 0.956863 0.839216 0.192157 412.406 0 0.592157 0.807843 641 1 1 1',
|
||||
selectable: 'true',
|
||||
diffuse: '0.6',
|
||||
interpolation: '1',
|
||||
effectiveRange: '0 412.406',
|
||||
},
|
||||
{
|
||||
name: 'DTI-FA-Brain',
|
||||
gradientOpacity: '4 0 1 0.9950 1',
|
||||
specularPower: '40',
|
||||
scalarOpacity:
|
||||
'16 0 0 0 0 0.3501 0.0158 0.49379 0.7619 0.6419 1 0.9920 1 0.9950 0 0.9950 0',
|
||||
id: 'vtkMRMLVolumePropertyNode26',
|
||||
specular: '0.5',
|
||||
shade: '1',
|
||||
ambient: '0.3',
|
||||
colorTransfer:
|
||||
'28 0 1 0 0 0 1 0 0 0.24974 0.4941 1 0 0.49949 0 0.9882 1 0.7492 0.51764 0 1 0.9950 1 0 0 0.9950 1 0 0',
|
||||
selectable: 'true',
|
||||
diffuse: '0.9',
|
||||
interpolation: '1',
|
||||
effectiveRange: '0 1',
|
||||
},
|
||||
];
|
||||
|
||||
export default presets;
|
||||
@@ -0,0 +1,93 @@
|
||||
import { cache, utilities } from '@cornerstonejs/core';
|
||||
import vtkColorMaps from '@kitware/vtk.js/Rendering/Core/ColorTransferFunction/ColorMaps';
|
||||
import vtkColorTransferFunction from '@kitware/vtk.js/Rendering/Core/ColorTransferFunction';
|
||||
import vtkPiecewiseFunction from '@kitware/vtk.js/Common/DataModel/PiecewiseFunction';
|
||||
|
||||
const colormaps = {};
|
||||
|
||||
export function registerColormap(colormap) {
|
||||
colormaps[colormap.Name] = colormap;
|
||||
}
|
||||
|
||||
function setColorTransferFunctionFromVolumeMetadata({
|
||||
volumeActor,
|
||||
volumeId,
|
||||
inverted,
|
||||
}) {
|
||||
let lower, upper, windowWidth, windowCenter;
|
||||
|
||||
if (volumeId) {
|
||||
const volume = cache.getVolume(volumeId);
|
||||
const voiLutModule = volume.metadata.voiLut[0];
|
||||
if (voiLutModule) {
|
||||
windowWidth = voiLutModule.windowWidth;
|
||||
windowCenter = voiLutModule.windowCenter;
|
||||
}
|
||||
} else {
|
||||
windowWidth = 400;
|
||||
windowCenter = 40;
|
||||
}
|
||||
|
||||
if (windowWidth == undefined || windowCenter === undefined) {
|
||||
// Set to something so we can window level it manually.
|
||||
lower = 200;
|
||||
upper = 400;
|
||||
} else {
|
||||
lower = windowCenter - windowWidth / 2.0;
|
||||
upper = windowCenter + windowWidth / 2.0;
|
||||
}
|
||||
|
||||
setLowerUpperColorTransferFunction({ volumeActor, lower, upper, inverted });
|
||||
}
|
||||
|
||||
function setLowerUpperColorTransferFunction({
|
||||
volumeActor,
|
||||
lower,
|
||||
upper,
|
||||
inverted,
|
||||
}) {
|
||||
volumeActor
|
||||
.getProperty()
|
||||
.getRGBTransferFunction(0)
|
||||
.setMappingRange(lower, upper);
|
||||
|
||||
if (inverted) {
|
||||
utilities.invertRgbTransferFunction(
|
||||
volumeActor.getProperty().getRGBTransferFunction(0)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
function setColormap(volumeActor, colormap) {
|
||||
const mapper = volumeActor.getMapper();
|
||||
mapper.setSampleDistance(1.0);
|
||||
|
||||
const cfun = vtkColorTransferFunction.newInstance();
|
||||
|
||||
// if we have a custom colormap, use it
|
||||
let preset;
|
||||
if (colormaps[colormap]) {
|
||||
preset = colormaps[colormap];
|
||||
} else {
|
||||
preset = vtkColorMaps.getPresetByName(colormap);
|
||||
}
|
||||
|
||||
cfun.applyColorMap(preset);
|
||||
cfun.setMappingRange(0, 5);
|
||||
|
||||
volumeActor.getProperty().setRGBTransferFunction(0, cfun);
|
||||
|
||||
// Create scalar opacity function
|
||||
const ofun = vtkPiecewiseFunction.newInstance();
|
||||
ofun.addPoint(0, 0.0);
|
||||
ofun.addPoint(0.1, 0.9);
|
||||
ofun.addPoint(5, 1.0);
|
||||
|
||||
volumeActor.getProperty().setScalarOpacity(0, ofun);
|
||||
}
|
||||
|
||||
export {
|
||||
setColormap,
|
||||
setColorTransferFunctionFromVolumeMetadata,
|
||||
setLowerUpperColorTransferFunction,
|
||||
};
|
||||
@@ -0,0 +1,207 @@
|
||||
import { imageLoader } from '@cornerstonejs/core';
|
||||
import cornerstoneWADOImageLoader from 'cornerstone-wado-image-loader';
|
||||
import { api } from 'dicomweb-client';
|
||||
import { DICOMWeb, errorHandler } from '@ohif/core';
|
||||
|
||||
const getImageId = imageObj => {
|
||||
if (!imageObj) {
|
||||
return;
|
||||
}
|
||||
|
||||
return typeof imageObj.getImageId === 'function'
|
||||
? imageObj.getImageId()
|
||||
: imageObj.url;
|
||||
};
|
||||
|
||||
const findImageIdOnStudies = (studies, displaySetInstanceUID) => {
|
||||
const study = studies.find(study => {
|
||||
const displaySet = study.displaySets.some(
|
||||
displaySet => displaySet.displaySetInstanceUID === displaySetInstanceUID
|
||||
);
|
||||
return displaySet;
|
||||
});
|
||||
const { series = [] } = study;
|
||||
const { instances = [] } = series[0] || {};
|
||||
const instance = instances[0];
|
||||
|
||||
return getImageId(instance);
|
||||
};
|
||||
|
||||
const someInvalidStrings = strings => {
|
||||
const stringsArray = Array.isArray(strings) ? strings : [strings];
|
||||
const emptyString = string => !string;
|
||||
let invalid = stringsArray.some(emptyString);
|
||||
return invalid;
|
||||
};
|
||||
|
||||
const getImageInstance = dataset => {
|
||||
return dataset && dataset.images && dataset.images[0];
|
||||
};
|
||||
|
||||
const getImageInstanceId = imageInstance => {
|
||||
return getImageId(imageInstance);
|
||||
};
|
||||
|
||||
const fetchIt = (url, headers = DICOMWeb.getAuthorizationHeader()) => {
|
||||
return fetch(url, headers).then(response => response.arrayBuffer());
|
||||
};
|
||||
|
||||
const cornerstoneRetriever = imageId => {
|
||||
return imageLoader.loadAndCacheImage(imageId).then(image => {
|
||||
return image && image.data && image.data.byteArray.buffer;
|
||||
});
|
||||
};
|
||||
|
||||
const wadorsRetriever = (
|
||||
url,
|
||||
studyInstanceUID,
|
||||
seriesInstanceUID,
|
||||
sopInstanceUID,
|
||||
headers = DICOMWeb.getAuthorizationHeader(),
|
||||
errorInterceptor = errorHandler.getHTTPErrorHandler()
|
||||
) => {
|
||||
const config = {
|
||||
url,
|
||||
headers,
|
||||
errorInterceptor,
|
||||
};
|
||||
const dicomWeb = new api.DICOMwebClient(config);
|
||||
|
||||
return dicomWeb.retrieveInstance({
|
||||
studyInstanceUID,
|
||||
seriesInstanceUID,
|
||||
sopInstanceUID,
|
||||
});
|
||||
};
|
||||
|
||||
const getImageLoaderType = imageId => {
|
||||
const loaderRegExp = /^\w+\:/;
|
||||
const loaderType = loaderRegExp.exec(imageId);
|
||||
|
||||
return (
|
||||
(loaderRegExp.lastIndex === 0 &&
|
||||
loaderType &&
|
||||
loaderType[0] &&
|
||||
loaderType[0].replace(':', '')) ||
|
||||
''
|
||||
);
|
||||
};
|
||||
|
||||
class DicomLoaderService {
|
||||
getLocalData(dataset, studies) {
|
||||
if (dataset && dataset.localFile) {
|
||||
// Use referenced imageInstance
|
||||
const imageInstance = getImageInstance(dataset);
|
||||
let imageId = getImageInstanceId(imageInstance);
|
||||
|
||||
// or Try to get it from studies
|
||||
if (someInvalidStrings(imageId)) {
|
||||
imageId = findImageIdOnStudies(studies, dataset.displaySetInstanceUID);
|
||||
}
|
||||
|
||||
if (!someInvalidStrings(imageId)) {
|
||||
return cornerstoneWADOImageLoader.wadouri.loadFileRequest(imageId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
getDataByImageType(dataset) {
|
||||
const imageInstance = getImageInstance(dataset);
|
||||
|
||||
if (imageInstance) {
|
||||
const imageId = getImageInstanceId(imageInstance);
|
||||
let getDicomDataMethod = fetchIt;
|
||||
const loaderType = getImageLoaderType(imageId);
|
||||
|
||||
switch (loaderType) {
|
||||
case 'dicomfile':
|
||||
getDicomDataMethod = cornerstoneRetriever.bind(this, imageId);
|
||||
break;
|
||||
case 'wadors':
|
||||
const url = imageInstance.getData().wadoRoot;
|
||||
const studyInstanceUID = imageInstance.getStudyInstanceUID();
|
||||
const seriesInstanceUID = imageInstance.getSeriesInstanceUID();
|
||||
const sopInstanceUID = imageInstance.getSOPInstanceUID();
|
||||
const invalidParams = someInvalidStrings([
|
||||
url,
|
||||
studyInstanceUID,
|
||||
seriesInstanceUID,
|
||||
sopInstanceUID,
|
||||
]);
|
||||
if (invalidParams) {
|
||||
return;
|
||||
}
|
||||
|
||||
getDicomDataMethod = wadorsRetriever.bind(
|
||||
this,
|
||||
url,
|
||||
studyInstanceUID,
|
||||
seriesInstanceUID,
|
||||
sopInstanceUID
|
||||
);
|
||||
break;
|
||||
case 'wadouri':
|
||||
// Strip out the image loader specifier
|
||||
imageId = imageId.substring(imageId.indexOf(':') + 1);
|
||||
|
||||
if (someInvalidStrings(imageId)) {
|
||||
return;
|
||||
}
|
||||
getDicomDataMethod = fetchIt.bind(this, imageId);
|
||||
break;
|
||||
default:
|
||||
throw new Error(
|
||||
`Unsupported image type: ${loaderType} for imageId: ${imageId}`
|
||||
);
|
||||
}
|
||||
|
||||
return getDicomDataMethod();
|
||||
}
|
||||
}
|
||||
|
||||
getDataByDatasetType(dataset) {
|
||||
const {
|
||||
StudyInstanceUID,
|
||||
SeriesInstanceUID,
|
||||
SOPInstanceUID,
|
||||
authorizationHeaders,
|
||||
wadoRoot,
|
||||
wadoUri,
|
||||
} = dataset;
|
||||
// Retrieve wadors or just try to fetch wadouri
|
||||
if (!someInvalidStrings(wadoRoot)) {
|
||||
return wadorsRetriever(
|
||||
wadoRoot,
|
||||
StudyInstanceUID,
|
||||
SeriesInstanceUID,
|
||||
SOPInstanceUID,
|
||||
authorizationHeaders
|
||||
);
|
||||
} else if (!someInvalidStrings(wadoUri)) {
|
||||
return fetchIt(wadoUri, { headers: authorizationHeaders });
|
||||
}
|
||||
}
|
||||
|
||||
*getLoaderIterator(dataset, studies) {
|
||||
yield this.getLocalData(dataset, studies);
|
||||
yield this.getDataByImageType(dataset);
|
||||
yield this.getDataByDatasetType(dataset);
|
||||
}
|
||||
|
||||
findDicomDataPromise(dataset, studies) {
|
||||
const loaderIterator = this.getLoaderIterator(dataset, studies);
|
||||
// it returns first valid retriever method.
|
||||
for (const loader of loaderIterator) {
|
||||
if (loader) {
|
||||
return loader;
|
||||
}
|
||||
}
|
||||
|
||||
// in case of no valid loader
|
||||
throw new Error('Invalid dicom data loader');
|
||||
}
|
||||
}
|
||||
|
||||
const dicomLoaderService = new DicomLoaderService();
|
||||
|
||||
export default dicomLoaderService;
|
||||
@@ -0,0 +1,17 @@
|
||||
import { Enums } from '@cornerstonejs/core';
|
||||
|
||||
const MIP = 'mip';
|
||||
|
||||
export default function getCornerstoneBlendMode(
|
||||
blendMode: string
|
||||
): Enums.BlendModes {
|
||||
if (!blendMode) {
|
||||
return Enums.BlendModes.COMPOSITE;
|
||||
}
|
||||
|
||||
if (blendMode.toLowerCase() === MIP) {
|
||||
return Enums.BlendModes.MAXIMUM_INTENSITY_BLEND;
|
||||
}
|
||||
|
||||
throw new Error();
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
import cornerstoneTools from 'cornerstone-tools';
|
||||
|
||||
const { globalImageIdSpecificToolStateManager } = cornerstoneTools;
|
||||
|
||||
export default function getCornerstoneMeasurementById(id) {
|
||||
const globalToolState = globalImageIdSpecificToolStateManager.saveToolState();
|
||||
|
||||
const imageIds = Object.keys(globalToolState);
|
||||
|
||||
for (let i = 0; i < imageIds.length; i++) {
|
||||
const imageId = imageIds[i];
|
||||
const imageIdSpecificToolState = globalToolState[imageId];
|
||||
|
||||
const toolTypes = Object.keys(imageIdSpecificToolState);
|
||||
|
||||
for (let j = 0; j < toolTypes.length; j++) {
|
||||
const toolType = toolTypes[j];
|
||||
const toolData = imageIdSpecificToolState[toolType].data;
|
||||
|
||||
if (toolData) {
|
||||
for (let k = 0; k < toolData.length; k++) {
|
||||
const toolDataK = toolData[k];
|
||||
|
||||
if (toolDataK.id === id) {
|
||||
return toolDataK;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
import { CONSTANTS } from '@cornerstonejs/core';
|
||||
import { log } from '@ohif/core';
|
||||
|
||||
const AXIAL = 'axial';
|
||||
const SAGITTAL = 'sagittal';
|
||||
const CORONAL = 'coronal';
|
||||
|
||||
export default function getCornerstoneOrientation(
|
||||
orientation: string
|
||||
): CONSTANTS.ORIENTATION {
|
||||
switch (orientation.toLowerCase()) {
|
||||
case AXIAL:
|
||||
return CONSTANTS.ORIENTATION.AXIAL;
|
||||
case SAGITTAL:
|
||||
return CONSTANTS.ORIENTATION.SAGITTAL;
|
||||
case CORONAL:
|
||||
return CONSTANTS.ORIENTATION.CORONAL;
|
||||
default:
|
||||
log.wanr('Choosing default orientation: axial');
|
||||
return CONSTANTS.ORIENTATION.AXIAL;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
import { Enums } from '@cornerstonejs/core';
|
||||
|
||||
const STACK = 'stack';
|
||||
const VOLUME = 'volume';
|
||||
|
||||
export default function getCornerstoneViewportType(
|
||||
viewportType: string
|
||||
): Enums.ViewportType {
|
||||
if (viewportType.toLowerCase() === STACK) {
|
||||
return Enums.ViewportType.STACK;
|
||||
}
|
||||
|
||||
if (viewportType.toLowerCase() === VOLUME) {
|
||||
return Enums.ViewportType.ORTHOGRAPHIC;
|
||||
}
|
||||
|
||||
throw new Error(
|
||||
`Invalid viewport type: ${viewportType}. Valid types are: stack, volume`
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
export default function getInterleavedFrames(imageIds) {
|
||||
const minImageIdIndex = 0;
|
||||
const maxImageIdIndex = imageIds.length - 1;
|
||||
|
||||
const middleImageIdIndex = Math.floor(imageIds.length / 2);
|
||||
|
||||
let lowerImageIdIndex = middleImageIdIndex;
|
||||
let upperImageIdIndex = middleImageIdIndex;
|
||||
|
||||
// Build up an array of images to prefetch, starting with the current image.
|
||||
const imageIdsToPrefetch = [
|
||||
{ imageId: imageIds[middleImageIdIndex], imageIdIndex: middleImageIdIndex },
|
||||
];
|
||||
|
||||
const prefetchQueuedFilled = {
|
||||
currentPositionDownToMinimum: false,
|
||||
currentPositionUpToMaximum: false,
|
||||
};
|
||||
|
||||
// Check if on edges and some criteria is already fulfilled
|
||||
|
||||
if (middleImageIdIndex === minImageIdIndex) {
|
||||
prefetchQueuedFilled.currentPositionDownToMinimum = true;
|
||||
} else if (middleImageIdIndex === maxImageIdIndex) {
|
||||
prefetchQueuedFilled.currentPositionUpToMaximum = true;
|
||||
}
|
||||
|
||||
while (
|
||||
!prefetchQueuedFilled.currentPositionDownToMinimum ||
|
||||
!prefetchQueuedFilled.currentPositionUpToMaximum
|
||||
) {
|
||||
if (!prefetchQueuedFilled.currentPositionDownToMinimum) {
|
||||
// Add imageId bellow
|
||||
lowerImageIdIndex--;
|
||||
imageIdsToPrefetch.push({
|
||||
imageId: imageIds[lowerImageIdIndex],
|
||||
imageIdIndex: lowerImageIdIndex,
|
||||
});
|
||||
|
||||
if (lowerImageIdIndex === minImageIdIndex) {
|
||||
prefetchQueuedFilled.currentPositionDownToMinimum = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!prefetchQueuedFilled.currentPositionUpToMaximum) {
|
||||
// Add imageId above
|
||||
upperImageIdIndex++;
|
||||
imageIdsToPrefetch.push({
|
||||
imageId: imageIds[upperImageIdIndex],
|
||||
imageIdIndex: upperImageIdIndex,
|
||||
});
|
||||
|
||||
if (upperImageIdIndex === maxImageIdIndex) {
|
||||
prefetchQueuedFilled.currentPositionUpToMaximum = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return imageIdsToPrefetch;
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
import csTools from 'cornerstone-tools';
|
||||
|
||||
const toolsGroupedByType = {
|
||||
touch: [csTools.PanMultiTouchTool, csTools.ZoomTouchPinchTool],
|
||||
annotations: [
|
||||
csTools.ArrowAnnotateTool,
|
||||
csTools.BidirectionalTool,
|
||||
csTools.LengthTool,
|
||||
csTools.AngleTool,
|
||||
csTools.FreehandRoiTool,
|
||||
csTools.EllipticalRoiTool,
|
||||
csTools.DragProbeTool,
|
||||
csTools.RectangleRoiTool,
|
||||
],
|
||||
other: [
|
||||
csTools.PanTool,
|
||||
csTools.ZoomTool,
|
||||
csTools.WwwcTool,
|
||||
csTools.WwwcRegionTool,
|
||||
csTools.MagnifyTool,
|
||||
csTools.StackScrollTool,
|
||||
csTools.StackScrollMouseWheelTool,
|
||||
csTools.OverlayTool,
|
||||
],
|
||||
};
|
||||
|
||||
export default function getTools() {
|
||||
const tools = [];
|
||||
Object.keys(toolsGroupedByType).forEach(toolsGroup =>
|
||||
tools.push(...toolsGroupedByType[toolsGroup])
|
||||
);
|
||||
|
||||
return tools;
|
||||
}
|
||||
|
||||
export { toolsGroupedByType };
|
||||
@@ -0,0 +1,150 @@
|
||||
import { cache, imageLoadPoolManager, Enums } from '@cornerstonejs/core';
|
||||
import getInterleavedFrames from './getInterleavedFrames';
|
||||
import { compact, flatten, zip } from 'lodash';
|
||||
|
||||
// Map of volumeId and SeriesInstanceId
|
||||
const volumeIdMapsToLoad = new Map<string, string>();
|
||||
const viewportIdVolumeInputArrayMap = new Map<string, unknown[]>();
|
||||
|
||||
/**
|
||||
* This function caches the volumeUIDs until all the volumes inside the
|
||||
* hangging protocol are initialized. Then it goes through the imageIds
|
||||
* of the volumes, and interleav them, in order for the volumes to be loaded
|
||||
* together from middle to the start and the end.
|
||||
* @param {Object} props image loading properties from Cornerstone ViewportService
|
||||
* @returns
|
||||
*/
|
||||
export default function interleaveCenterLoader({
|
||||
data: { viewportId, volumeInputArray },
|
||||
displaySetsMatchDetails,
|
||||
matchDetails,
|
||||
}) {
|
||||
viewportIdVolumeInputArrayMap.set(viewportId, volumeInputArray);
|
||||
|
||||
// Based on the volumeInputs store the volumeIds and SeriesInstanceIds
|
||||
// to keep track of the volumes being loaded
|
||||
for (const volumeInput of volumeInputArray) {
|
||||
const { volumeId } = volumeInput;
|
||||
const volume = cache.getVolume(volumeId);
|
||||
|
||||
if (!volume) {
|
||||
return;
|
||||
}
|
||||
|
||||
// if the volumeUID is not in the volumeUIDs array, add it
|
||||
if (!volumeIdMapsToLoad.has(volumeId)) {
|
||||
const { metadata } = volume;
|
||||
volumeIdMapsToLoad.set(volumeId, metadata.SeriesInstanceUID);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The following is checking if all the viewports that were matched in the HP has been
|
||||
* successfully created their cornerstone viewport or not. Todo: This can be
|
||||
* improved by not checking it, and as soon as the matched DisplaySets have their
|
||||
* volume loaded, we start the loading, but that comes at the cost of viewports
|
||||
* not being created yet (e.g., in a 10 viewport ptCT fusion, when one ct viewport and one
|
||||
* pt viewport are created we have a guarantee that the volumes are created in the cache
|
||||
* but the rest of the viewports (fusion, mip etc.) are not created yet. So
|
||||
* we can't initiate setting the volumes for those viewports. One solution can be
|
||||
* to add an event when a viewport is created (not enabled element event) and then
|
||||
* listen to it and as the other viewports are created we can set the volumes for them
|
||||
* since volumes are already started loading.
|
||||
*/
|
||||
if (matchDetails.length !== viewportIdVolumeInputArrayMap.size) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if all the matched volumes are loaded
|
||||
for (const [_, details] of displaySetsMatchDetails.entries()) {
|
||||
const { SeriesInstanceUID } = details;
|
||||
|
||||
// HangingProtocol has matched, but don't have all the volumes created yet, so return
|
||||
if (!Array.from(volumeIdMapsToLoad.values()).includes(SeriesInstanceUID)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
const volumeIds = Array.from(volumeIdMapsToLoad.keys()).slice();
|
||||
// get volumes from cache
|
||||
const volumes = volumeIds.map(volumeId => {
|
||||
return cache.getVolume(volumeId);
|
||||
});
|
||||
|
||||
// iterate over all volumes, and get their imageIds, and interleave
|
||||
// the imageIds and save them in AllRequests for later use
|
||||
const AllRequests = [];
|
||||
volumes.forEach(volume => {
|
||||
const requests = volume.getImageLoadRequests();
|
||||
|
||||
if (!requests.length || !requests[0] || !requests[0].imageId) {
|
||||
return;
|
||||
}
|
||||
|
||||
const requestImageIds = requests.map(request => {
|
||||
return request.imageId;
|
||||
});
|
||||
|
||||
const imageIds = getInterleavedFrames(requestImageIds);
|
||||
|
||||
const reOrderedRequests = imageIds.map(({ imageId }) => {
|
||||
const request = requests.find(req => req.imageId === imageId);
|
||||
return request;
|
||||
});
|
||||
|
||||
AllRequests.push(reOrderedRequests);
|
||||
});
|
||||
|
||||
// flatten the AllRequests array, which will result in a list of all the
|
||||
// imageIds for all the volumes but interleaved
|
||||
const interleavedRequests = compact(flatten(zip(...AllRequests)));
|
||||
|
||||
// set the finalRequests to the imageLoadPoolManager
|
||||
const finalRequests = [];
|
||||
interleavedRequests.forEach(request => {
|
||||
const { imageId } = request;
|
||||
|
||||
AllRequests.forEach(volumeRequests => {
|
||||
const volumeImageIdRequest = volumeRequests.find(
|
||||
req => req.imageId === imageId
|
||||
);
|
||||
if (volumeImageIdRequest) {
|
||||
finalRequests.push(volumeImageIdRequest);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
const requestType = Enums.RequestType.Prefetch;
|
||||
const priority = 0;
|
||||
|
||||
finalRequests.forEach(
|
||||
({ callLoadImage, additionalDetails, imageId, imageIdIndex, options }) => {
|
||||
const callLoadImageBound = callLoadImage.bind(
|
||||
null,
|
||||
imageId,
|
||||
imageIdIndex,
|
||||
options
|
||||
);
|
||||
|
||||
imageLoadPoolManager.addRequest(
|
||||
callLoadImageBound,
|
||||
requestType,
|
||||
additionalDetails,
|
||||
priority
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
// clear the volumeIdMapsToLoad
|
||||
volumeIdMapsToLoad.clear();
|
||||
|
||||
// copy the viewportIdVolumeInputArrayMap
|
||||
const viewportIdVolumeInputArrayMapCopy = new Map(
|
||||
viewportIdVolumeInputArrayMap
|
||||
);
|
||||
|
||||
// reset the viewportIdVolumeInputArrayMap
|
||||
viewportIdVolumeInputArrayMap.clear();
|
||||
|
||||
return viewportIdVolumeInputArrayMapCopy;
|
||||
}
|
||||
@@ -0,0 +1,139 @@
|
||||
import { cache, imageLoadPoolManager, Enums } from '@cornerstonejs/core';
|
||||
import { compact, flatten, zip } from 'lodash';
|
||||
|
||||
// Map of volumeId and SeriesInstanceId
|
||||
const volumeIdMapsToLoad = new Map<string, string>();
|
||||
const viewportIdVolumeInputArrayMap = new Map<string, unknown[]>();
|
||||
|
||||
/**
|
||||
* This function caches the volumeIds until all the volumes inside the
|
||||
* hanging protocol are initialized. Then it goes through the imageIds
|
||||
* of the volumes, and interleave them, in order for the volumes to be loaded
|
||||
* together from middle to the start and the end.
|
||||
* @param {Object} {viewportData, displaySetMatchDetails}
|
||||
* @returns
|
||||
*/
|
||||
export default function interleaveTopToBottom({
|
||||
data: { viewportId, volumeInputArray },
|
||||
displaySetsMatchDetails,
|
||||
matchDetails,
|
||||
}) {
|
||||
viewportIdVolumeInputArrayMap.set(viewportId, volumeInputArray);
|
||||
|
||||
// Based on the volumeInputs store the volumeIds and SeriesInstanceIds
|
||||
// to keep track of the volumes being loaded
|
||||
for (const volumeInput of volumeInputArray) {
|
||||
const { volumeId } = volumeInput;
|
||||
const volume = cache.getVolume(volumeId);
|
||||
|
||||
if (!volume) {
|
||||
return;
|
||||
}
|
||||
|
||||
// if the volumeUID is not in the volumeUIDs array, add it
|
||||
if (!volumeIdMapsToLoad.has(volumeId)) {
|
||||
const { metadata } = volume;
|
||||
volumeIdMapsToLoad.set(volumeId, metadata.SeriesInstanceUID);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The following is checking if all the viewports that were matched in the HP has been
|
||||
* successfully created their cornerstone viewport or not. Todo: This can be
|
||||
* improved by not checking it, and as soon as the matched DisplaySets have their
|
||||
* volume loaded, we start the loading, but that comes at the cost of viewports
|
||||
* not being created yet (e.g., in a 10 viewport ptCT fusion, when one ct viewport and one
|
||||
* pt viewport are created we have a guarantee that the volumes are created in the cache
|
||||
* but the rest of the viewports (fusion, mip etc.) are not created yet. So
|
||||
* we can't initiate setting the volumes for those viewports. One solution can be
|
||||
* to add an event when a viewport is created (not enabled element event) and then
|
||||
* listen to it and as the other viewports are created we can set the volumes for them
|
||||
* since volumes are already started loading.
|
||||
*/
|
||||
if (matchDetails.length !== viewportIdVolumeInputArrayMap.size) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if all the matched volumes are loaded
|
||||
for (const [_, details] of displaySetsMatchDetails.entries()) {
|
||||
const { SeriesInstanceUID } = details;
|
||||
|
||||
// HangingProtocol has matched, but don't have all the volumes created yet, so return
|
||||
if (!Array.from(volumeIdMapsToLoad.values()).includes(SeriesInstanceUID)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
const volumeIds = Array.from(volumeIdMapsToLoad.keys()).slice();
|
||||
// get volumes from cache
|
||||
const volumes = volumeIds.map(volumeId => {
|
||||
return cache.getVolume(volumeId);
|
||||
});
|
||||
|
||||
// iterate over all volumes, and get their imageIds, and interleave
|
||||
// the imageIds and save them in AllRequests for later use
|
||||
const AllRequests = [];
|
||||
volumes.forEach(volume => {
|
||||
const requests = volume.getImageLoadRequests();
|
||||
|
||||
if (!requests.length || !requests[0] || !requests[0].imageId) {
|
||||
return;
|
||||
}
|
||||
|
||||
// reverse the requests
|
||||
AllRequests.push(requests.reverse());
|
||||
});
|
||||
|
||||
// flatten the AllRequests array, which will result in a list of all the
|
||||
// imageIds for all the volumes but interleaved
|
||||
const interleavedRequests = compact(flatten(zip(...AllRequests)));
|
||||
|
||||
// set the finalRequests to the imageLoadPoolManager
|
||||
const finalRequests = [];
|
||||
interleavedRequests.forEach(request => {
|
||||
const { imageId } = request;
|
||||
|
||||
AllRequests.forEach(volumeRequests => {
|
||||
const volumeImageIdRequest = volumeRequests.find(
|
||||
req => req.imageId === imageId
|
||||
);
|
||||
if (volumeImageIdRequest) {
|
||||
finalRequests.push(volumeImageIdRequest);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
const requestType = Enums.RequestType.Prefetch;
|
||||
const priority = 0;
|
||||
|
||||
finalRequests.forEach(
|
||||
({ callLoadImage, additionalDetails, imageId, imageIdIndex, options }) => {
|
||||
const callLoadImageBound = callLoadImage.bind(
|
||||
null,
|
||||
imageId,
|
||||
imageIdIndex,
|
||||
options
|
||||
);
|
||||
|
||||
imageLoadPoolManager.addRequest(
|
||||
callLoadImageBound,
|
||||
requestType,
|
||||
additionalDetails,
|
||||
priority
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
// clear the volumeIdMapsToLoad
|
||||
volumeIdMapsToLoad.clear();
|
||||
|
||||
// copy the viewportIdVolumeInputArrayMap
|
||||
const viewportIdVolumeInputArrayMapCopy = new Map(
|
||||
viewportIdVolumeInputArrayMap
|
||||
);
|
||||
|
||||
// reset the viewportIdVolumeInputArrayMap
|
||||
viewportIdVolumeInputArrayMap.clear();
|
||||
|
||||
return viewportIdVolumeInputArrayMapCopy;
|
||||
}
|
||||
@@ -1,57 +1,142 @@
|
||||
import SUPPORTED_TOOLS from './constants/supportedTools';
|
||||
import getPointsFromHandles from './utils/getPointsFromHandles';
|
||||
import getHandlesFromPoints from './utils/getHandlesFromPoints';
|
||||
import getSOPInstanceAttributes from './utils/getSOPInstanceAttributes';
|
||||
|
||||
const ArrowAnnotate = {
|
||||
toAnnotation: (measurement, definition) => {},
|
||||
const Length = {
|
||||
toAnnotation: measurement => {},
|
||||
|
||||
/**
|
||||
* Maps cornerstone annotation event data to measurement service format.
|
||||
*
|
||||
* @param {Object} cornerstone Cornerstone event data
|
||||
* @return {Measurement} Measurement instance
|
||||
*/
|
||||
toMeasurement: (
|
||||
csToolsAnnotation,
|
||||
csToolsEventDetail,
|
||||
DisplaySetService,
|
||||
CornerstoneViewportService,
|
||||
getValueTypeFromToolType
|
||||
) => {
|
||||
const { element, measurementData } = csToolsAnnotation;
|
||||
const tool =
|
||||
csToolsAnnotation.toolType ||
|
||||
csToolsAnnotation.toolName ||
|
||||
measurementData.toolType;
|
||||
const { annotation, viewportId } = csToolsEventDetail;
|
||||
const { metadata, data, annotationUID } = annotation;
|
||||
|
||||
const validToolType = toolName => SUPPORTED_TOOLS.includes(toolName);
|
||||
if (!metadata || !data) {
|
||||
console.warn('Length tool: Missing metadata or data');
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!validToolType(tool)) {
|
||||
const { toolName, referencedImageId, FrameOfReferenceUID } = metadata;
|
||||
const validToolType = SUPPORTED_TOOLS.includes(toolName);
|
||||
|
||||
if (!validToolType) {
|
||||
throw new Error('Tool not supported');
|
||||
}
|
||||
|
||||
const {
|
||||
SOPInstanceUID,
|
||||
FrameOfReferenceUID,
|
||||
SeriesInstanceUID,
|
||||
StudyInstanceUID,
|
||||
} = getSOPInstanceAttributes(element);
|
||||
|
||||
const displaySet = DisplaySetService.getDisplaySetForSOPInstanceUID(
|
||||
SOPInstanceUID,
|
||||
SeriesInstanceUID
|
||||
} = getSOPInstanceAttributes(
|
||||
referencedImageId,
|
||||
CornerstoneViewportService,
|
||||
viewportId
|
||||
);
|
||||
|
||||
const points = [];
|
||||
points.push(measurementData.handles);
|
||||
let displaySet;
|
||||
|
||||
if (SOPInstanceUID) {
|
||||
displaySet = DisplaySetService.getDisplaySetForSOPInstanceUID(
|
||||
SOPInstanceUID,
|
||||
SeriesInstanceUID
|
||||
);
|
||||
} else {
|
||||
displaySet = DisplaySetService.getDisplaySetsForSeries(SeriesInstanceUID);
|
||||
}
|
||||
|
||||
const { points } = data.handles;
|
||||
|
||||
const mappedAnnotations = getMappedAnnotations(
|
||||
annotation,
|
||||
DisplaySetService
|
||||
);
|
||||
|
||||
const displayText = getDisplayText(mappedAnnotations, displaySet);
|
||||
|
||||
return {
|
||||
id: measurementData.id,
|
||||
uid: annotationUID,
|
||||
SOPInstanceUID,
|
||||
FrameOfReferenceUID,
|
||||
points,
|
||||
metadata,
|
||||
referenceSeriesUID: SeriesInstanceUID,
|
||||
referenceStudyUID: StudyInstanceUID,
|
||||
toolName: metadata.toolName,
|
||||
displaySetInstanceUID: displaySet.displaySetInstanceUID,
|
||||
label: measurementData.text,
|
||||
description: measurementData.description,
|
||||
unit: measurementData.unit,
|
||||
text: measurementData.text,
|
||||
type: getValueTypeFromToolType(tool),
|
||||
points: getPointsFromHandles(measurementData.handles),
|
||||
label: data.text,
|
||||
text: data.text,
|
||||
displayText: displayText,
|
||||
data: data.cachedStats,
|
||||
type: getValueTypeFromToolType(toolName),
|
||||
getReport: () => {
|
||||
throw new Error('Not implemented');
|
||||
},
|
||||
};
|
||||
},
|
||||
};
|
||||
|
||||
export default ArrowAnnotate;
|
||||
function getMappedAnnotations(annotation, DisplaySetService) {
|
||||
const { metadata, data } = annotation;
|
||||
const { text } = data;
|
||||
const { referencedImageId } = metadata;
|
||||
|
||||
const annotations = [];
|
||||
|
||||
const { SOPInstanceUID, SeriesInstanceUID } = getSOPInstanceAttributes(
|
||||
referencedImageId
|
||||
);
|
||||
|
||||
const displaySet = DisplaySetService.getDisplaySetForSOPInstanceUID(
|
||||
SOPInstanceUID,
|
||||
SeriesInstanceUID
|
||||
);
|
||||
|
||||
const { SeriesNumber } = displaySet;
|
||||
|
||||
annotations.push({
|
||||
SeriesInstanceUID,
|
||||
SOPInstanceUID,
|
||||
SeriesNumber,
|
||||
text,
|
||||
});
|
||||
|
||||
return annotations;
|
||||
}
|
||||
|
||||
function getDisplayText(mappedAnnotations, displaySet) {
|
||||
if (!mappedAnnotations) {
|
||||
return '';
|
||||
}
|
||||
|
||||
const displayText = [];
|
||||
|
||||
// Area is the same for all series
|
||||
const { SeriesNumber, SOPInstanceUID } = mappedAnnotations[0];
|
||||
|
||||
const instance = displaySet.images.find(
|
||||
image => image.SOPInstanceUID === SOPInstanceUID
|
||||
);
|
||||
|
||||
let InstanceNumber;
|
||||
if (instance) {
|
||||
InstanceNumber = instance.InstanceNumber;
|
||||
}
|
||||
|
||||
displayText.push(
|
||||
InstanceNumber
|
||||
? `(S: ${SeriesNumber} I: ${InstanceNumber})`
|
||||
: `(S: ${SeriesNumber})`
|
||||
);
|
||||
|
||||
return displayText;
|
||||
}
|
||||
|
||||
export default Length;
|
||||
@@ -1,59 +1,197 @@
|
||||
import { annotation } from '@cornerstonejs/tools';
|
||||
|
||||
import SUPPORTED_TOOLS from './constants/supportedTools';
|
||||
import getSOPInstanceAttributes from './utils/getSOPInstanceAttributes';
|
||||
import getHandlesFromPoints from './utils/getHandlesFromPoints';
|
||||
import { utils } from '@ohif/core';
|
||||
|
||||
const Bidirectional = {
|
||||
toAnnotation: (measurement, definition) => {},
|
||||
toAnnotation: measurement => {},
|
||||
toMeasurement: (
|
||||
csToolsAnnotation,
|
||||
csToolsEventDetail,
|
||||
DisplaySetService,
|
||||
CornerstoneViewportService,
|
||||
getValueTypeFromToolType
|
||||
) => {
|
||||
const { element, measurementData } = csToolsAnnotation;
|
||||
const tool =
|
||||
csToolsAnnotation.toolType ||
|
||||
csToolsAnnotation.toolName ||
|
||||
measurementData.toolType;
|
||||
const { annotation, viewportId } = csToolsEventDetail;
|
||||
const { metadata, data, annotationUID } = annotation;
|
||||
|
||||
const validToolType = toolName => SUPPORTED_TOOLS.includes(toolName);
|
||||
if (!metadata || !data) {
|
||||
console.warn('Length tool: Missing metadata or data');
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!validToolType(tool)) {
|
||||
const { toolName, referencedImageId, FrameOfReferenceUID } = metadata;
|
||||
const validToolType = SUPPORTED_TOOLS.includes(toolName);
|
||||
|
||||
if (!validToolType) {
|
||||
throw new Error('Tool not supported');
|
||||
}
|
||||
|
||||
const {
|
||||
SOPInstanceUID,
|
||||
FrameOfReferenceUID,
|
||||
SeriesInstanceUID,
|
||||
StudyInstanceUID,
|
||||
} = getSOPInstanceAttributes(element);
|
||||
|
||||
const displaySet = DisplaySetService.getDisplaySetForSOPInstanceUID(
|
||||
SOPInstanceUID,
|
||||
SeriesInstanceUID
|
||||
} = getSOPInstanceAttributes(
|
||||
referencedImageId,
|
||||
CornerstoneViewportService,
|
||||
viewportId
|
||||
);
|
||||
|
||||
const { handles } = measurementData;
|
||||
let displaySet;
|
||||
|
||||
const longAxis = [handles.start, handles.end];
|
||||
const shortAxis = [handles.perpendicularStart, handles.perpendicularEnd];
|
||||
if (SOPInstanceUID) {
|
||||
displaySet = DisplaySetService.getDisplaySetForSOPInstanceUID(
|
||||
SOPInstanceUID,
|
||||
SeriesInstanceUID
|
||||
);
|
||||
} else {
|
||||
displaySet = DisplaySetService.getDisplaySetsForSeries(SeriesInstanceUID);
|
||||
}
|
||||
|
||||
const { points } = data.handles;
|
||||
|
||||
const mappedAnnotations = getMappedAnnotations(
|
||||
annotation,
|
||||
DisplaySetService
|
||||
);
|
||||
|
||||
const displayText = getDisplayText(mappedAnnotations, displaySet);
|
||||
const getReport = () =>
|
||||
_getReport(mappedAnnotations, points, FrameOfReferenceUID);
|
||||
|
||||
return {
|
||||
id: measurementData.id,
|
||||
uid: annotationUID,
|
||||
SOPInstanceUID,
|
||||
FrameOfReferenceUID,
|
||||
points,
|
||||
metadata,
|
||||
referenceSeriesUID: SeriesInstanceUID,
|
||||
referenceStudyUID: StudyInstanceUID,
|
||||
toolName: metadata.toolName,
|
||||
displaySetInstanceUID: displaySet.displaySetInstanceUID,
|
||||
label: measurementData.label,
|
||||
description: measurementData.description,
|
||||
unit: measurementData.unit,
|
||||
shortestDiameter: measurementData.shortestDiameter,
|
||||
longestDiameter: measurementData.longestDiameter,
|
||||
type: getValueTypeFromToolType(tool),
|
||||
points: { longAxis, shortAxis },
|
||||
label: data.label,
|
||||
displayText: displayText,
|
||||
data: data.cachedStats,
|
||||
type: getValueTypeFromToolType(toolName),
|
||||
getReport,
|
||||
};
|
||||
},
|
||||
};
|
||||
|
||||
function getMappedAnnotations(annotation, DisplaySetService) {
|
||||
const { metadata, data } = annotation;
|
||||
const { cachedStats } = data;
|
||||
const { referencedImageId, referencedSeriesInstanceUID } = metadata;
|
||||
const targets = Object.keys(cachedStats);
|
||||
|
||||
if (!targets.length) {
|
||||
return;
|
||||
}
|
||||
|
||||
const annotations = [];
|
||||
Object.keys(cachedStats).forEach(targetId => {
|
||||
const targetStats = cachedStats[targetId];
|
||||
|
||||
let displaySet;
|
||||
|
||||
if (referencedImageId) {
|
||||
const { SOPInstanceUID, SeriesInstanceUID } = getSOPInstanceAttributes(
|
||||
referencedImageId
|
||||
);
|
||||
|
||||
displaySet = DisplaySetService.getDisplaySetForSOPInstanceUID(
|
||||
SOPInstanceUID,
|
||||
SeriesInstanceUID
|
||||
);
|
||||
} else {
|
||||
throw new Error(
|
||||
'Non-acquisition plane measurement mapping not supported'
|
||||
);
|
||||
}
|
||||
|
||||
const { SeriesNumber, SeriesInstanceUID } = displaySet;
|
||||
const { length, width } = targetStats;
|
||||
const unit = 'mm';
|
||||
|
||||
annotations.push({
|
||||
SeriesInstanceUID,
|
||||
SeriesNumber,
|
||||
unit,
|
||||
length,
|
||||
width,
|
||||
});
|
||||
});
|
||||
|
||||
return annotations;
|
||||
}
|
||||
|
||||
/*
|
||||
This function is used to convert the measurement data to a format that is
|
||||
suitable for the report generation (e.g. for the csv report). The report
|
||||
returns a list of columns and corresponding values.
|
||||
*/
|
||||
function _getReport(mappedAnnotations, points, FrameOfReferenceUID) {
|
||||
const columns = [];
|
||||
const values = [];
|
||||
|
||||
// Add Type
|
||||
columns.push('AnnotationType');
|
||||
values.push('Cornerstone:Bidirectional');
|
||||
|
||||
mappedAnnotations.forEach(annotation => {
|
||||
const { length, width } = annotation;
|
||||
columns.push(`Length (mm)`, `Width (mm)`);
|
||||
values.push(length, width);
|
||||
});
|
||||
|
||||
if (FrameOfReferenceUID) {
|
||||
columns.push('FrameOfReferenceUID');
|
||||
values.push(FrameOfReferenceUID);
|
||||
}
|
||||
|
||||
if (points) {
|
||||
columns.push('points');
|
||||
// points has the form of [[x1, y1, z1], [x2, y2, z2], ...]
|
||||
// convert it to string of [[x1 y1 z1];[x2 y2 z2];...]
|
||||
// so that it can be used in the csv report
|
||||
values.push(points.map(p => p.join(' ')).join(';'));
|
||||
}
|
||||
|
||||
return {
|
||||
columns,
|
||||
values,
|
||||
};
|
||||
}
|
||||
|
||||
function getDisplayText(mappedAnnotations, displaySet) {
|
||||
if (!mappedAnnotations || !mappedAnnotations.length) {
|
||||
return '';
|
||||
}
|
||||
|
||||
const displayText = [];
|
||||
|
||||
// Area is the same for all series
|
||||
const { length, width, SeriesNumber, SOPInstanceUID } = mappedAnnotations[0];
|
||||
const roundedLength = utils.roundNumber(length, 1);
|
||||
const roundedWidth = utils.roundNumber(width, 1);
|
||||
|
||||
const instance = displaySet.images.find(
|
||||
image => image.SOPInstanceUID === SOPInstanceUID
|
||||
);
|
||||
|
||||
let InstanceNumber;
|
||||
if (instance) {
|
||||
InstanceNumber = instance.InstanceNumber;
|
||||
}
|
||||
|
||||
displayText.push(
|
||||
InstanceNumber
|
||||
? `L: ${roundedLength} mm (S: ${SeriesNumber} I: ${InstanceNumber})`
|
||||
: `L: ${roundedLength} mm (S: ${SeriesNumber})`
|
||||
);
|
||||
displayText.push(`W: ${roundedWidth} mm`);
|
||||
|
||||
return displayText;
|
||||
}
|
||||
|
||||
export default Bidirectional;
|
||||
@@ -0,0 +1,219 @@
|
||||
import SUPPORTED_TOOLS from './constants/supportedTools';
|
||||
import getSOPInstanceAttributes from './utils/getSOPInstanceAttributes';
|
||||
import getModalityUnit from './utils/getModalityUnit';
|
||||
import { utils } from '@ohif/core';
|
||||
|
||||
const EllipticalROI = {
|
||||
toAnnotation: measurement => {},
|
||||
toMeasurement: (
|
||||
csToolsEventDetail,
|
||||
DisplaySetService,
|
||||
CornerstoneViewportService,
|
||||
getValueTypeFromToolType
|
||||
) => {
|
||||
const { annotation, viewportId } = csToolsEventDetail;
|
||||
const { metadata, data, annotationUID } = annotation;
|
||||
|
||||
if (!metadata || !data) {
|
||||
console.warn('Length tool: Missing metadata or data');
|
||||
return null;
|
||||
}
|
||||
|
||||
const { toolName, referencedImageId, FrameOfReferenceUID } = metadata;
|
||||
const validToolType = SUPPORTED_TOOLS.includes(toolName);
|
||||
|
||||
if (!validToolType) {
|
||||
throw new Error('Tool not supported');
|
||||
}
|
||||
|
||||
const {
|
||||
SOPInstanceUID,
|
||||
SeriesInstanceUID,
|
||||
StudyInstanceUID,
|
||||
} = getSOPInstanceAttributes(
|
||||
referencedImageId,
|
||||
CornerstoneViewportService,
|
||||
viewportId
|
||||
);
|
||||
|
||||
let displaySet;
|
||||
|
||||
if (SOPInstanceUID) {
|
||||
displaySet = DisplaySetService.getDisplaySetForSOPInstanceUID(
|
||||
SOPInstanceUID,
|
||||
SeriesInstanceUID
|
||||
);
|
||||
} else {
|
||||
displaySet = DisplaySetService.getDisplaySetsForSeries(SeriesInstanceUID);
|
||||
}
|
||||
|
||||
const { points } = data.handles;
|
||||
|
||||
const mappedAnnotations = getMappedAnnotations(
|
||||
annotation,
|
||||
DisplaySetService
|
||||
);
|
||||
|
||||
const displayText = getDisplayText(mappedAnnotations, displaySet);
|
||||
const getReport = () =>
|
||||
_getReport(mappedAnnotations, points, FrameOfReferenceUID);
|
||||
|
||||
return {
|
||||
uid: annotationUID,
|
||||
SOPInstanceUID,
|
||||
FrameOfReferenceUID,
|
||||
points,
|
||||
metadata,
|
||||
referenceSeriesUID: SeriesInstanceUID,
|
||||
referenceStudyUID: StudyInstanceUID,
|
||||
toolName: metadata.toolName,
|
||||
displaySetInstanceUID: displaySet.displaySetInstanceUID,
|
||||
label: data.label,
|
||||
displayText: displayText,
|
||||
data: data.cachedStats,
|
||||
type: getValueTypeFromToolType(toolName),
|
||||
getReport,
|
||||
};
|
||||
},
|
||||
};
|
||||
|
||||
function getMappedAnnotations(annotation, DisplaySetService) {
|
||||
const { metadata, data } = annotation;
|
||||
const { cachedStats } = data;
|
||||
const { referencedImageId } = metadata;
|
||||
const targets = Object.keys(cachedStats);
|
||||
|
||||
if (!targets.length) {
|
||||
return;
|
||||
}
|
||||
|
||||
const annotations = [];
|
||||
Object.keys(cachedStats).forEach(targetId => {
|
||||
const targetStats = cachedStats[targetId];
|
||||
|
||||
let displaySet;
|
||||
|
||||
if (referencedImageId) {
|
||||
const { SOPInstanceUID, SeriesInstanceUID } = getSOPInstanceAttributes(
|
||||
referencedImageId
|
||||
);
|
||||
|
||||
displaySet = DisplaySetService.getDisplaySetForSOPInstanceUID(
|
||||
SOPInstanceUID,
|
||||
SeriesInstanceUID
|
||||
);
|
||||
} else {
|
||||
// Todo: Non-acquisition plane measurement mapping not supported yet
|
||||
throw new Error(
|
||||
'Non-acquisition plane measurement mapping not supported'
|
||||
);
|
||||
}
|
||||
|
||||
const { SeriesNumber, SeriesInstanceUID } = displaySet;
|
||||
const { mean, stdDev, max, area, Modality } = targetStats;
|
||||
const unit = getModalityUnit(Modality);
|
||||
|
||||
annotations.push({
|
||||
SeriesInstanceUID,
|
||||
SeriesNumber,
|
||||
Modality,
|
||||
unit,
|
||||
mean,
|
||||
stdDev,
|
||||
max,
|
||||
area,
|
||||
});
|
||||
});
|
||||
|
||||
return annotations;
|
||||
}
|
||||
|
||||
/*
|
||||
This function is used to convert the measurement data to a format that is
|
||||
suitable for the report generation (e.g. for the csv report). The report
|
||||
returns a list of columns and corresponding values.
|
||||
*/
|
||||
function _getReport(mappedAnnotations, points, FrameOfReferenceUID) {
|
||||
const columns = [];
|
||||
const values = [];
|
||||
|
||||
// Add Type
|
||||
columns.push('AnnotationType');
|
||||
values.push('Cornerstone:EllipticalROI');
|
||||
|
||||
mappedAnnotations.forEach(annotation => {
|
||||
const { mean, stdDev, max, area, unit } = annotation;
|
||||
|
||||
if (!mean || !unit || !max || !area) {
|
||||
return;
|
||||
}
|
||||
|
||||
columns.push(
|
||||
`max (${unit})`,
|
||||
`mean (${unit})`,
|
||||
`std (${unit})`,
|
||||
`area (mm2)`
|
||||
);
|
||||
values.push(max, mean, stdDev, area);
|
||||
});
|
||||
|
||||
if (FrameOfReferenceUID) {
|
||||
columns.push('FrameOfReferenceUID');
|
||||
values.push(FrameOfReferenceUID);
|
||||
}
|
||||
|
||||
if (points) {
|
||||
columns.push('points');
|
||||
// points has the form of [[x1, y1, z1], [x2, y2, z2], ...]
|
||||
// convert it to string of [[x1 y1 z1];[x2 y2 z2];...]
|
||||
// so that it can be used in the csv report
|
||||
values.push(points.map(p => p.join(' ')).join(';'));
|
||||
}
|
||||
|
||||
return {
|
||||
columns,
|
||||
values,
|
||||
};
|
||||
}
|
||||
|
||||
function getDisplayText(mappedAnnotations, displaySet) {
|
||||
if (!mappedAnnotations || !mappedAnnotations.length) {
|
||||
return '';
|
||||
}
|
||||
|
||||
const displayText = [];
|
||||
|
||||
// Area is the same for all series
|
||||
const { area, SOPInstanceUID } = mappedAnnotations[0];
|
||||
|
||||
const instance = displaySet.images.find(
|
||||
image => image.SOPInstanceUID === SOPInstanceUID
|
||||
);
|
||||
|
||||
let InstanceNumber;
|
||||
if (instance) {
|
||||
InstanceNumber = instance.InstanceNumber;
|
||||
}
|
||||
|
||||
const roundedArea = utils.roundNumber(area, 2);
|
||||
displayText.push(`${roundedArea} mm<sup>2</sup>`);
|
||||
|
||||
// Todo: we need a better UI for displaying all these information
|
||||
mappedAnnotations.forEach(mappedAnnotation => {
|
||||
const { unit, max, SeriesNumber } = mappedAnnotation;
|
||||
|
||||
if (max) {
|
||||
const roundedMax = utils.roundNumber(max, 2);
|
||||
|
||||
displayText.push(
|
||||
InstanceNumber
|
||||
? `Max: ${roundedMax} <small>${unit}</small> (S:${SeriesNumber} I:${InstanceNumber})`
|
||||
: `Max: ${roundedMax} <small>${unit}</small> (S:${SeriesNumber})`
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
return displayText;
|
||||
}
|
||||
|
||||
export default EllipticalROI;
|
||||
@@ -1,100 +0,0 @@
|
||||
import SUPPORTED_TOOLS from './constants/supportedTools';
|
||||
import getSOPInstanceAttributes from './utils/getSOPInstanceAttributes';
|
||||
import getHandlesFromPoints from './utils/getHandlesFromPoints';
|
||||
|
||||
const EllipticalRoi = {
|
||||
toAnnotation: (measurement, definition) => {},
|
||||
toMeasurement: (
|
||||
csToolsAnnotation,
|
||||
DisplaySetService,
|
||||
getValueTypeFromToolType
|
||||
) => {
|
||||
const { element, measurementData } = csToolsAnnotation;
|
||||
const tool =
|
||||
csToolsAnnotation.toolType ||
|
||||
csToolsAnnotation.toolName ||
|
||||
measurementData.toolType;
|
||||
|
||||
const validToolType = toolName => SUPPORTED_TOOLS.includes(toolName);
|
||||
|
||||
if (!validToolType(tool)) {
|
||||
throw new Error('Tool not supported');
|
||||
}
|
||||
|
||||
const {
|
||||
SOPInstanceUID,
|
||||
FrameOfReferenceUID,
|
||||
SeriesInstanceUID,
|
||||
StudyInstanceUID,
|
||||
} = getSOPInstanceAttributes(element);
|
||||
|
||||
const displaySet = DisplaySetService.getDisplaySetForSOPInstanceUID(
|
||||
SOPInstanceUID,
|
||||
SeriesInstanceUID
|
||||
);
|
||||
|
||||
const { cachedStats, handles } = measurementData;
|
||||
|
||||
const { start, end } = handles;
|
||||
|
||||
const halfXLength = Math.abs(start.x - end.x) / 2;
|
||||
const halfYLength = Math.abs(start.y - end.y) / 2;
|
||||
|
||||
const points = [];
|
||||
const center = { x: (start.x + end.x) / 2, y: (start.y + end.y) / 2 };
|
||||
|
||||
// To store similar to SR.
|
||||
if (halfXLength > halfYLength) {
|
||||
// X-axis major
|
||||
// Major axis
|
||||
points.push({ x: center.x - halfXLength, y: center.y });
|
||||
points.push({ x: center.x + halfXLength, y: center.y });
|
||||
// Minor axis
|
||||
points.push({ x: center.x, y: center.y - halfYLength });
|
||||
points.push({ x: center.x, y: center.y + halfYLength });
|
||||
} else {
|
||||
// Y-axis major
|
||||
// Major axis
|
||||
points.push({ x: center.x, y: center.y - halfYLength });
|
||||
points.push({ x: center.x, y: center.y + halfYLength });
|
||||
// Minor axis
|
||||
points.push({ x: center.x - halfXLength, y: center.y });
|
||||
points.push({ x: center.x + halfXLength, y: center.y });
|
||||
}
|
||||
|
||||
let meanSUV;
|
||||
let stdDevSUV;
|
||||
|
||||
if (
|
||||
cachedStats &&
|
||||
cachedStats.meanStdDevSUV &&
|
||||
cachedStats.meanStdDevSUV.mean !== 0
|
||||
) {
|
||||
const { meanStdDevSUV } = cachedStats;
|
||||
|
||||
meanSUV = meanStdDevSUV.mean;
|
||||
stdDevSUV = meanStdDevSUV.stdDev;
|
||||
}
|
||||
|
||||
return {
|
||||
id: measurementData.id,
|
||||
SOPInstanceUID,
|
||||
FrameOfReferenceUID,
|
||||
referenceSeriesUID: SeriesInstanceUID,
|
||||
referenceStudyUID: StudyInstanceUID,
|
||||
displaySetInstanceUID: displaySet.displaySetInstanceUID,
|
||||
label: measurementData.label,
|
||||
description: measurementData.description,
|
||||
unit: measurementData.unit,
|
||||
area: cachedStats && cachedStats.area,
|
||||
mean: cachedStats && cachedStats.mean,
|
||||
stdDev: cachedStats && cachedStats.stdDev,
|
||||
meanSUV,
|
||||
stdDevSUV,
|
||||
type: getValueTypeFromToolType(tool),
|
||||
points,
|
||||
};
|
||||
},
|
||||
};
|
||||
|
||||
export default EllipticalRoi;
|
||||
@@ -1,10 +1,9 @@
|
||||
import SUPPORTED_TOOLS from './constants/supportedTools';
|
||||
import getHandlesFromPoints from './utils/getHandlesFromPoints';
|
||||
import getPointsFromHandles from './utils/getPointsFromHandles';
|
||||
import getSOPInstanceAttributes from './utils/getSOPInstanceAttributes';
|
||||
import { DisplaySetService, utils } from '@ohif/core';
|
||||
|
||||
const Length = {
|
||||
toAnnotation: (measurement, definition) => {},
|
||||
toAnnotation: measurement => {},
|
||||
|
||||
/**
|
||||
* Maps cornerstone annotation event data to measurement service format.
|
||||
@@ -13,49 +12,188 @@ const Length = {
|
||||
* @return {Measurement} Measurement instance
|
||||
*/
|
||||
toMeasurement: (
|
||||
csToolsAnnotation,
|
||||
csToolsEventDetail,
|
||||
DisplaySetService,
|
||||
CornerstoneViewportService,
|
||||
getValueTypeFromToolType
|
||||
) => {
|
||||
const { element, measurementData } = csToolsAnnotation;
|
||||
const tool =
|
||||
csToolsAnnotation.toolType ||
|
||||
csToolsAnnotation.toolName ||
|
||||
measurementData.toolType;
|
||||
const { annotation, viewportId } = csToolsEventDetail;
|
||||
const { metadata, data, annotationUID } = annotation;
|
||||
|
||||
const validToolType = toolName => SUPPORTED_TOOLS.includes(toolName);
|
||||
if (!metadata || !data) {
|
||||
console.warn('Length tool: Missing metadata or data');
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!validToolType(tool)) {
|
||||
const { toolName, referencedImageId, FrameOfReferenceUID } = metadata;
|
||||
const validToolType = SUPPORTED_TOOLS.includes(toolName);
|
||||
|
||||
if (!validToolType) {
|
||||
throw new Error('Tool not supported');
|
||||
}
|
||||
|
||||
const {
|
||||
SOPInstanceUID,
|
||||
FrameOfReferenceUID,
|
||||
SeriesInstanceUID,
|
||||
StudyInstanceUID,
|
||||
} = getSOPInstanceAttributes(element);
|
||||
|
||||
const displaySet = DisplaySetService.getDisplaySetForSOPInstanceUID(
|
||||
SOPInstanceUID,
|
||||
SeriesInstanceUID
|
||||
} = getSOPInstanceAttributes(
|
||||
referencedImageId,
|
||||
CornerstoneViewportService,
|
||||
viewportId
|
||||
);
|
||||
|
||||
let displaySet;
|
||||
|
||||
if (SOPInstanceUID) {
|
||||
displaySet = DisplaySetService.getDisplaySetForSOPInstanceUID(
|
||||
SOPInstanceUID,
|
||||
SeriesInstanceUID
|
||||
);
|
||||
} else {
|
||||
displaySet = DisplaySetService.getDisplaySetsForSeries(SeriesInstanceUID);
|
||||
}
|
||||
|
||||
const { points } = data.handles;
|
||||
|
||||
const mappedAnnotations = getMappedAnnotations(
|
||||
annotation,
|
||||
DisplaySetService
|
||||
);
|
||||
|
||||
const displayText = getDisplayText(mappedAnnotations, displaySet);
|
||||
const getReport = () =>
|
||||
_getReport(mappedAnnotations, points, FrameOfReferenceUID);
|
||||
|
||||
return {
|
||||
id: measurementData.id,
|
||||
uid: annotationUID,
|
||||
SOPInstanceUID,
|
||||
FrameOfReferenceUID,
|
||||
points,
|
||||
metadata,
|
||||
referenceSeriesUID: SeriesInstanceUID,
|
||||
referenceStudyUID: StudyInstanceUID,
|
||||
toolName: metadata.toolName,
|
||||
displaySetInstanceUID: displaySet.displaySetInstanceUID,
|
||||
label: measurementData.label,
|
||||
description: measurementData.description,
|
||||
unit: measurementData.unit,
|
||||
length: measurementData.length,
|
||||
type: getValueTypeFromToolType(tool),
|
||||
points: getPointsFromHandles(measurementData.handles),
|
||||
label: data.label,
|
||||
displayText: displayText,
|
||||
data: data.cachedStats,
|
||||
type: getValueTypeFromToolType(toolName),
|
||||
getReport,
|
||||
};
|
||||
},
|
||||
};
|
||||
|
||||
function getMappedAnnotations(annotation, DisplaySetService) {
|
||||
const { metadata, data } = annotation;
|
||||
const { cachedStats } = data;
|
||||
const { referencedImageId } = metadata;
|
||||
const targets = Object.keys(cachedStats);
|
||||
|
||||
if (!targets.length) {
|
||||
return;
|
||||
}
|
||||
|
||||
const annotations = [];
|
||||
Object.keys(cachedStats).forEach(targetId => {
|
||||
const targetStats = cachedStats[targetId];
|
||||
|
||||
let displaySet;
|
||||
|
||||
if (referencedImageId) {
|
||||
const { SOPInstanceUID, SeriesInstanceUID } = getSOPInstanceAttributes(
|
||||
referencedImageId
|
||||
);
|
||||
|
||||
displaySet = DisplaySetService.getDisplaySetForSOPInstanceUID(
|
||||
SOPInstanceUID,
|
||||
SeriesInstanceUID
|
||||
);
|
||||
} else {
|
||||
throw new Error(
|
||||
'Non-acquisition plane measurement mapping not supported'
|
||||
);
|
||||
}
|
||||
|
||||
const { SeriesNumber, SeriesInstanceUID } = displaySet;
|
||||
const { length } = targetStats;
|
||||
const unit = 'mm';
|
||||
|
||||
annotations.push({
|
||||
SeriesInstanceUID,
|
||||
SeriesNumber,
|
||||
unit,
|
||||
length,
|
||||
});
|
||||
});
|
||||
|
||||
return annotations;
|
||||
}
|
||||
|
||||
/*
|
||||
This function is used to convert the measurement data to a format that is
|
||||
suitable for the report generation (e.g. for the csv report). The report
|
||||
returns a list of columns and corresponding values.
|
||||
*/
|
||||
function _getReport(mappedAnnotations, points, FrameOfReferenceUID) {
|
||||
const columns = [];
|
||||
const values = [];
|
||||
|
||||
// Add Type
|
||||
columns.push('AnnotationType');
|
||||
values.push('Cornerstone:Length');
|
||||
|
||||
mappedAnnotations.forEach(annotation => {
|
||||
const { length } = annotation;
|
||||
columns.push(`Length (mm)`);
|
||||
values.push(length);
|
||||
});
|
||||
|
||||
if (FrameOfReferenceUID) {
|
||||
columns.push('FrameOfReferenceUID');
|
||||
values.push(FrameOfReferenceUID);
|
||||
}
|
||||
|
||||
if (points) {
|
||||
columns.push('points');
|
||||
// points has the form of [[x1, y1, z1], [x2, y2, z2], ...]
|
||||
// convert it to string of [[x1 y1 z1];[x2 y2 z2];...]
|
||||
// so that it can be used in the csv report
|
||||
values.push(points.map(p => p.join(' ')).join(';'));
|
||||
}
|
||||
|
||||
return {
|
||||
columns,
|
||||
values,
|
||||
};
|
||||
}
|
||||
|
||||
function getDisplayText(mappedAnnotations, displaySet) {
|
||||
if (!mappedAnnotations || !mappedAnnotations.length) {
|
||||
return '';
|
||||
}
|
||||
|
||||
const displayText = [];
|
||||
|
||||
// Area is the same for all series
|
||||
const { length, SeriesNumber, SOPInstanceUID } = mappedAnnotations[0];
|
||||
|
||||
const instance = displaySet.images.find(
|
||||
image => image.SOPInstanceUID === SOPInstanceUID
|
||||
);
|
||||
|
||||
let InstanceNumber;
|
||||
if (instance) {
|
||||
InstanceNumber = instance.InstanceNumber;
|
||||
}
|
||||
|
||||
const roundedLength = utils.roundNumber(length, 2);
|
||||
displayText.push(
|
||||
InstanceNumber
|
||||
? `${roundedLength} mm (S: ${SeriesNumber} I: ${InstanceNumber})`
|
||||
: `${roundedLength} mm (S: ${SeriesNumber})`
|
||||
);
|
||||
|
||||
return displayText;
|
||||
}
|
||||
|
||||
export default Length;
|
||||
+1
-1
@@ -1 +1 @@
|
||||
export default ['Length', 'EllipticalRoi', 'Bidirectional', 'ArrowAnnotate'];
|
||||
export default ['Length', 'EllipticalROI', 'Bidirectional', 'ArrowAnnotate'];
|
||||
+26
-19
@@ -1,11 +1,12 @@
|
||||
import Length from './Length';
|
||||
import Bidirectional from './Bidirectional';
|
||||
import EllipticalROI from './EllipticalROI';
|
||||
import ArrowAnnotate from './ArrowAnnotate';
|
||||
import EllipticalRoi from './EllipticalRoi';
|
||||
|
||||
const measurementServiceMappingsFactory = (
|
||||
MeasurementService,
|
||||
DisplaySetService
|
||||
DisplaySetService,
|
||||
CornerstoneViewportService
|
||||
) => {
|
||||
/**
|
||||
* Maps measurement service format object to cornerstone annotation object.
|
||||
@@ -19,16 +20,18 @@ const measurementServiceMappingsFactory = (
|
||||
const {
|
||||
POLYLINE,
|
||||
ELLIPSE,
|
||||
POINT,
|
||||
RECTANGLE,
|
||||
BIDIRECTIONAL,
|
||||
POINT,
|
||||
} = MeasurementService.VALUE_TYPES;
|
||||
|
||||
// TODO -> I get why this was attemped, but its not nearly flexible enough.
|
||||
// TODO -> I get why this was attempted, but its not nearly flexible enough.
|
||||
// A single measurement may have an ellipse + a bidirectional measurement, for instances.
|
||||
// You can't define a bidirectional tool as a single type..
|
||||
const TOOL_TYPE_TO_VALUE_TYPE = {
|
||||
Length: POLYLINE,
|
||||
EllipticalRoi: ELLIPSE,
|
||||
EllipticalROI: ELLIPSE,
|
||||
RectangleROI: RECTANGLE,
|
||||
Bidirectional: BIDIRECTIONAL,
|
||||
ArrowAnnotate: POINT,
|
||||
};
|
||||
@@ -43,6 +46,7 @@ const measurementServiceMappingsFactory = (
|
||||
Length.toMeasurement(
|
||||
csToolsAnnotation,
|
||||
DisplaySetService,
|
||||
CornerstoneViewportService,
|
||||
_getValueTypeFromToolType
|
||||
),
|
||||
matchingCriteria: [
|
||||
@@ -58,6 +62,7 @@ const measurementServiceMappingsFactory = (
|
||||
Bidirectional.toMeasurement(
|
||||
csToolsAnnotation,
|
||||
DisplaySetService,
|
||||
CornerstoneViewportService,
|
||||
_getValueTypeFromToolType
|
||||
),
|
||||
matchingCriteria: [
|
||||
@@ -73,12 +78,28 @@ const measurementServiceMappingsFactory = (
|
||||
},
|
||||
],
|
||||
},
|
||||
EllipticalROI: {
|
||||
toAnnotation: EllipticalROI.toAnnotation,
|
||||
toMeasurement: csToolsAnnotation =>
|
||||
EllipticalROI.toMeasurement(
|
||||
csToolsAnnotation,
|
||||
DisplaySetService,
|
||||
CornerstoneViewportService,
|
||||
_getValueTypeFromToolType
|
||||
),
|
||||
matchingCriteria: [
|
||||
{
|
||||
valueType: MeasurementService.VALUE_TYPES.ELLIPSE,
|
||||
},
|
||||
],
|
||||
},
|
||||
ArrowAnnotate: {
|
||||
toAnnotation: ArrowAnnotate.toAnnotation,
|
||||
toMeasurement: csToolsAnnotation =>
|
||||
ArrowAnnotate.toMeasurement(
|
||||
csToolsAnnotation,
|
||||
DisplaySetService,
|
||||
CornerstoneViewportService,
|
||||
_getValueTypeFromToolType
|
||||
),
|
||||
matchingCriteria: [
|
||||
@@ -88,20 +109,6 @@ const measurementServiceMappingsFactory = (
|
||||
},
|
||||
],
|
||||
},
|
||||
EllipticalRoi: {
|
||||
toAnnotation: EllipticalRoi.toAnnotation,
|
||||
toMeasurement: csToolsAnnotation =>
|
||||
EllipticalRoi.toMeasurement(
|
||||
csToolsAnnotation,
|
||||
DisplaySetService,
|
||||
_getValueTypeFromToolType
|
||||
),
|
||||
matchingCriteria: [
|
||||
{
|
||||
valueType: MeasurementService.VALUE_TYPES.ELLIPSE,
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
-102
@@ -1,102 +0,0 @@
|
||||
import measurementServiceMappingsFactory from './measurementServiceMappingsFactory';
|
||||
|
||||
jest.mock('cornerstone-core', () => ({
|
||||
...jest.requireActual('cornerstone-core'),
|
||||
getEnabledElement: () => ({
|
||||
image: { imageId: 123 },
|
||||
}),
|
||||
metaData: {
|
||||
...jest.requireActual('cornerstone-core').metaData,
|
||||
get: () => ({
|
||||
SOPInstanceUID: '123',
|
||||
FrameOfReferenceUID: '123',
|
||||
SeriesInstanceUID: '123',
|
||||
StudyInstanceUID: '1234',
|
||||
}),
|
||||
},
|
||||
}));
|
||||
|
||||
describe('measurementServiceMappings.js', () => {
|
||||
let mappings;
|
||||
let handles;
|
||||
let points;
|
||||
let csToolsAnnotation;
|
||||
let measurement;
|
||||
let measurementServiceMock;
|
||||
let displaySetServiceMock;
|
||||
let definition = 'Length';
|
||||
|
||||
beforeEach(() => {
|
||||
measurementServiceMock = {
|
||||
VALUE_TYPES: {
|
||||
POLYLINE: 'value_type::polyline',
|
||||
POINT: 'value_type::point',
|
||||
ELLIPSE: 'value_type::ellipse',
|
||||
MULTIPOINT: 'value_type::multipoint',
|
||||
CIRCLE: 'value_type::circle',
|
||||
},
|
||||
};
|
||||
displaySetServiceMock = {
|
||||
getDisplaySetForSOPInstanceUID: (SOPInstanceUID, SeriesInstanceUID) => {
|
||||
console.warn('SOPInstanceUID');
|
||||
|
||||
return {
|
||||
displaySetInstanceUID: '1.2.3.4'
|
||||
}
|
||||
}
|
||||
};
|
||||
mappings = measurementServiceMappingsFactory(measurementServiceMock, displaySetServiceMock);
|
||||
handles = { start: { x: 1, y: 2 }, end: { x: 1, y: 2 } };
|
||||
points = [
|
||||
{ x: 1, y: 2 },
|
||||
{ x: 1, y: 2 },
|
||||
];
|
||||
csToolsAnnotation = {
|
||||
toolName: definition,
|
||||
measurementData: {
|
||||
id: 1,
|
||||
label: 'Test',
|
||||
SOPInstanceUID: '123',
|
||||
FrameOfReferenceUID: '123',
|
||||
SeriesInstanceUID: '123',
|
||||
handles,
|
||||
text: 'Test',
|
||||
description: 'Test',
|
||||
unit: 'mm',
|
||||
length: undefined
|
||||
},
|
||||
};
|
||||
measurement = {
|
||||
id: 1,
|
||||
SOPInstanceUID: '123',
|
||||
FrameOfReferenceUID: '123',
|
||||
referenceSeriesUID: '123',
|
||||
referenceStudyUID: '1234',
|
||||
displaySetInstanceUID: '1.2.3.4',
|
||||
label: 'Test',
|
||||
description: 'Test',
|
||||
unit: 'mm',
|
||||
type: measurementServiceMock.VALUE_TYPES.POLYLINE,
|
||||
points,
|
||||
};
|
||||
jest.clearAllMocks();
|
||||
});
|
||||
|
||||
/*describe('toAnnotation()', () => {
|
||||
it('map measurement service format to annotation', async () => {
|
||||
const mappedMeasurement = await mappings[csToolsAnnotation.toolName].toAnnotation(
|
||||
measurement,
|
||||
definition
|
||||
);
|
||||
expect(mappedMeasurement).toEqual(csToolsAnnotation);
|
||||
});
|
||||
});*/
|
||||
|
||||
describe('toMeasurement()', () => {
|
||||
it('map annotation to measurement service format', async () => {
|
||||
const getValueTypeFromToolType = (toolType) => 'valueType';
|
||||
const mappedAnnotation = await mappings[csToolsAnnotation.toolName].toMeasurement(csToolsAnnotation, displaySetServiceMock, getValueTypeFromToolType);
|
||||
expect(mappedAnnotation).toEqual(measurement);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,11 @@
|
||||
function getModalityUnit(modality) {
|
||||
if (modality === 'CT') {
|
||||
return 'HU';
|
||||
} else if (modality === 'PT') {
|
||||
return 'SUV';
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
export default getModalityUnit;
|
||||
-12
@@ -1,12 +0,0 @@
|
||||
export default function getPointsFromHandles(handles) {
|
||||
let points = [];
|
||||
Object.keys(handles).map(handle => {
|
||||
if (['start', 'end'].includes(handle)) {
|
||||
let point = {};
|
||||
if (handles[handle].x) point.x = handles[handle].x;
|
||||
if (handles[handle].y) point.y = handles[handle].y;
|
||||
points.push(point);
|
||||
}
|
||||
});
|
||||
return points;
|
||||
}
|
||||
+60
-5
@@ -1,14 +1,69 @@
|
||||
import cornerstone from 'cornerstone-core';
|
||||
import * as cornerstone from '@cornerstonejs/core';
|
||||
|
||||
export default function getSOPInstanceAttributes(element) {
|
||||
const enabledElement = cornerstone.getEnabledElement(element);
|
||||
const imageId = enabledElement.image.imageId;
|
||||
/**
|
||||
* It checks if the imageId is provided then it uses it to query
|
||||
* the metadata and get the SOPInstanceUID, SeriesInstanceUID and StudyInstanceUID.
|
||||
* If the imageId is not provided then it uses the sceneUID to get the viewports
|
||||
* inside the scene and then it checks each viewport to find the one that has
|
||||
* acquisition plane view, and uses the currentImageId of the viewport to
|
||||
* query the metadata and get UIDs.
|
||||
* @param {string} imageId The image id of the referenced image
|
||||
* @param {string} sceneUID The scene UID of the measurement tool
|
||||
* @returns
|
||||
*/
|
||||
export default function getSOPInstanceAttributes(
|
||||
imageId,
|
||||
CornerstoneViewportService,
|
||||
viewportId
|
||||
) {
|
||||
if (imageId) {
|
||||
return _getUIDFromImageID(imageId);
|
||||
}
|
||||
|
||||
// Todo: implement for volume viewports and use the referencedSeriesInstanceUID
|
||||
|
||||
// if no imageId => measurement is not in the acquisition plane
|
||||
// const metadata = getUIDFromScene(CornerstoneViewportService, viewportId);
|
||||
|
||||
// if (!metadata) {
|
||||
// throw new Error('Not viewport with imageId found');
|
||||
// }
|
||||
|
||||
// // Since the series and study UID is derived from another viewport in the
|
||||
// // same scene, we cannot include the SOPInstanceUID
|
||||
// return {
|
||||
// SOPInstanceUID: null,
|
||||
// SeriesInstanceUID: metadata.SeriesInstanceUID,
|
||||
// StudyInstanceUID: metadata.StudyInstanceUID,
|
||||
// };
|
||||
}
|
||||
|
||||
function _getUIDFromImageID(imageId) {
|
||||
const instance = cornerstone.metaData.get('instance', imageId);
|
||||
|
||||
return {
|
||||
SOPInstanceUID: instance.SOPInstanceUID,
|
||||
FrameOfReferenceUID: instance.FrameOfReferenceUID,
|
||||
SeriesInstanceUID: instance.SeriesInstanceUID,
|
||||
StudyInstanceUID: instance.StudyInstanceUID,
|
||||
};
|
||||
}
|
||||
|
||||
// function getUIDFromScene(CornerstoneViewportService) {
|
||||
// const renderingEngine = CornerstoneViewportService.getRenderingEngine();
|
||||
// const scene = renderingEngine.getScene(sceneUID);
|
||||
|
||||
// const viewportUIDs = scene.getViewportIds();
|
||||
|
||||
// if (viewportUIDs.length === 0) {
|
||||
// throw new Error('No viewport found in scene');
|
||||
// }
|
||||
|
||||
// for (let i = 0; i < viewportUIDs.length; i++) {
|
||||
// const vp = renderingEngine.getViewport(viewportUIDs[i]);
|
||||
// const imageId = vp.getCurrentImageId();
|
||||
|
||||
// if (imageId) {
|
||||
// return _getUIDFromImageID(imageId);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
@@ -0,0 +1,30 @@
|
||||
import { Enums as csToolsEnums } from '@cornerstonejs/tools';
|
||||
|
||||
const Labelmap = {
|
||||
toSegmentation: segmentationState => {
|
||||
const {
|
||||
activeSegmentIndex,
|
||||
cachedStats: data,
|
||||
segmentsLocked,
|
||||
representationData,
|
||||
label,
|
||||
segmentationId,
|
||||
text,
|
||||
} = segmentationState;
|
||||
|
||||
const labelmapRepresentationData =
|
||||
representationData[csToolsEnums.SegmentationRepresentations.Labelmap];
|
||||
|
||||
return {
|
||||
id: segmentationId,
|
||||
activeSegmentIndex,
|
||||
segmentsLocked,
|
||||
data,
|
||||
label,
|
||||
volumeId: labelmapRepresentationData.volumeId,
|
||||
displayText: text || [],
|
||||
};
|
||||
},
|
||||
};
|
||||
|
||||
export default Labelmap;
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
import Labelmap from './Labelmap';
|
||||
|
||||
const segmentationServiceMappingsFactory = (
|
||||
SegmentationService,
|
||||
DisplaySetService
|
||||
) => {
|
||||
return {
|
||||
Labelmap: {
|
||||
matchingCriteria: {},
|
||||
toSegmentation: csToolsSegmentation =>
|
||||
Labelmap.toSegmentation(csToolsSegmentation, DisplaySetService),
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
export default segmentationServiceMappingsFactory;
|
||||
@@ -1,21 +0,0 @@
|
||||
import csTools from 'cornerstone-tools';
|
||||
|
||||
export default function _setActiveAndPassiveToolsForElement(element, tools) {
|
||||
const BaseAnnotationTool = csTools.importInternal('base/BaseAnnotationTool');
|
||||
|
||||
tools.forEach(tool => {
|
||||
if (tool.prototype instanceof BaseAnnotationTool) {
|
||||
// BaseAnnotationTool would likely come from csTools lib exports
|
||||
const toolName = new tool().name;
|
||||
csTools.setToolPassiveForElement(element, toolName); // there may be a better place to determine name; may not be on uninstantiated class
|
||||
}
|
||||
});
|
||||
|
||||
csTools.setToolActiveForElement(element, 'Pan', { mouseButtonMask: 4 });
|
||||
csTools.setToolActiveForElement(element, 'Zoom', { mouseButtonMask: 2 });
|
||||
csTools.setToolActiveForElement(element, 'Wwwc', { mouseButtonMask: 1 });
|
||||
csTools.setToolActiveForElement(element, 'StackScrollMouseWheel', {}); // TODO: Empty options should not be required
|
||||
csTools.setToolActiveForElement(element, 'PanMultiTouch', { pointers: 2 }); // TODO: Better error if no options
|
||||
csTools.setToolActiveForElement(element, 'ZoomTouchPinch', {});
|
||||
csTools.setToolEnabledForElement(element, 'Overlay', {});
|
||||
}
|
||||
Reference in new issue
Block a user