Chore/kill yalc with fire (#629)
* init * more shifting * Move @babel dependencies up to workspace root * Begin updating dependent libraries to use sync'd webpack builds w/ watches * Commit changes before a long weekend * Split packages into platform and extensions * Consolidate how/where we specify file/module type entrypoints * Make it possible to pass in extensions as App props * Resolve viewer's modules * Target for UMD bundle * Add Webpack Stylus loader * Provide WebPack build options for microscopy, vtk, and ui * Better entrypoint for extensions * Push changes up to switch PCs * Fix ESM symlink build for Viewers * Shift docs to root * Specify additional lerna config props * Begin providing basic readme info * Rename example extension folder * Shift links to bottom of doc * First attempt at a netlify deploy preview * Attempt to fix deploy preview build * push workspace enabled to initial command; remove second yarn install; use npx to call gitbook cli commands * Try to use global gitbook-cli * Export node_modules path * More agressive with modifying PATH * Follow deploy log output advice * try again to set bin path * Try swapping bash with a new shell * Try bash -l instead of exec bash * Annd let's try again * and again * We may have figured it out johnny, boy * We need to pull cornerstone-wado-image-loader files from hoisted node_modules * Attempt to fix ticks/escapes * Change copy syntax; try running tests on viewers from root for circleci * Lower version to match circleci image * Try alternative jest-canvas-mock location and version file syntax * Run version command instead of calling node directly * Try alternative jest transform * Set path and enable workspaces * Add codecov flags * Use cpx so our copying finishes? * Get all platform unit tests to run * Run and report individually and in parallel * Try once relying on codecov yaml to split w/ flags * Add projects to split by flags * Generate separate reports * Trigger codecov after everything has finished running; these may not support flags * Use recommended flags from issue comments for codecov * Fix typo * Remove clear flag * Shift back to calling codecov from root * Generate example for codecov issue * Try fixing paths * Simplify * Try using codecov orb * Bump circleci version * Upload core and viewer * Use full string paths * Remove individual codecov calls * Fix dir * Combine files before upload * Escape anchors * tryfix syntax * Escape string literal * Combine lines to reduce path * long paths * Use home alias * Fix filename * Try to see the contents of our cat'd file * Also upload `core` * Try running with aliased folder * Fix path; split PR and Merge unit tests into separate jobs * Set default threshold * Fix typo * Changing to scoped package names * Adding note * Catch more updates * chore(release): publish %s [skip ci] - @ohif/extension-cornerstone@0.0.39-alpha.0 - @ohif/extension-dicom-html@0.0.4-alpha.0 - @ohif/extension-dicom-microscopy@0.0.9-alpha.0 - @ohif/extension-dicom-pdf@0.0.8-alpha.0 - @ohif/extension-vtk@0.1.4-alpha.0 - @ohif/core@0.11.1-alpha.0 - @ohif/i18n@0.2.3-alpha.0 - @ohif/ui@0.2.18-alpha.0 - @ohif/viewer@0.0.22-alpha.0 * Clean up primary readme * Support for dev and dev:* commands * Shift build command; satisfy default PWA build * Remove old scripts * Clean up UI to set webpack scripts * Tidy up project links * Clean duplicate code in UI project * Update UI project's docs * Clean up ui and i18n config * Reduce duplicate code in `@ohif/core` * Fix @ohif/ui versions * bump @ohif/core versions * Redux testkit dep * Remove unused/duplicate config files for projects/packages * ohif-core --> @ohif/core * Safer publish command * chore(release): publish %s [skip ci] - @ohif/extension-cornerstone@0.0.39-alpha.1 - @ohif/extension-dicom-html@0.0.4-alpha.1 - @ohif/extension-dicom-microscopy@0.0.9-alpha.1 - @ohif/extension-dicom-pdf@0.0.8-alpha.1 - @ohif/extension-vtk@0.1.4-alpha.1 - @ohif/core@0.11.1-alpha.1 - @ohif/i18n@0.2.3-alpha.1 - @ohif/ui@0.2.18-alpha.1 - @ohif/viewer@0.0.22-alpha.1 * test version bump * Add global prettier config * chore(release): publish %s [skip ci] - @ohif/viewer@0.0.22-alpha.2 * test lerna publish * Update package.jsons * Fix build scripts * catch changes * chore(release): publish %s [skip ci] - @ohif/extension-cornerstone@0.0.39-alpha.2 - @ohif/extension-dicom-html@0.0.4-alpha.2 - @ohif/extension-dicom-microscopy@0.0.9-alpha.2 - @ohif/extension-dicom-pdf@0.0.8-alpha.2 - @ohif/extension-vtk@0.1.4-alpha.2 - @ohif/core@0.11.1-alpha.2 - @ohif/i18n@0.2.3-alpha.2 - @ohif/ui@0.2.18-alpha.2 - @ohif/viewer@0.0.22-alpha.3 * fix eslint issues caused by eslint 6 and our react-app config * Publish with canary tag * chore(release): publish %s [skip ci] - @ohif/extension-cornerstone@0.0.39-alpha.3 - @ohif/extension-dicom-html@0.0.4-alpha.3 - @ohif/extension-dicom-microscopy@0.0.9-alpha.3 - @ohif/extension-dicom-pdf@0.0.8-alpha.3 - @ohif/extension-vtk@0.1.4-alpha.3 - @ohif/core@0.11.1-alpha.3 - @ohif/i18n@0.2.3-alpha.3 - @ohif/ui@0.2.18-alpha.3 - @ohif/viewer@0.0.22-alpha.4 * chore(release): publish %s [skip ci] - @ohif/extension-cornerstone@0.0.39-alpha.4 - @ohif/extension-dicom-html@0.0.4-alpha.4 - @ohif/extension-dicom-microscopy@0.0.9-alpha.4 - @ohif/extension-dicom-pdf@0.0.8-alpha.4 - @ohif/extension-vtk@0.1.4-alpha.4 - @ohif/core@0.11.1-alpha.4 - @ohif/i18n@0.2.3-alpha.4 - @ohif/ui@0.2.18-alpha.4 - @ohif/viewer@0.0.22-alpha.5 * Simplify build * chore(release): publish %s [skip ci] - @ohif/extension-cornerstone@0.0.39-alpha.5 - @ohif/extension-dicom-html@0.0.4-alpha.5 - @ohif/extension-dicom-microscopy@0.0.9-alpha.5 - @ohif/extension-dicom-pdf@0.0.8-alpha.5 - @ohif/extension-vtk@0.1.4-alpha.5 - @ohif/core@0.11.1-alpha.5 - @ohif/i18n@0.2.3-alpha.5 - @ohif/ui@0.2.18-alpha.5 - @ohif/viewer@0.0.22-alpha.6 * chore(release): publish %s [skip ci] - @ohif/extension-cornerstone@0.0.39-alpha.6 - @ohif/extension-dicom-html@0.0.4-alpha.6 - @ohif/extension-dicom-microscopy@0.0.9-alpha.6 - @ohif/extension-dicom-pdf@0.0.8-alpha.6 - @ohif/extension-vtk@0.1.4-alpha.6 - @ohif/core@0.11.1-alpha.6 - @ohif/i18n@0.2.3-alpha.6 - @ohif/ui@0.2.18-alpha.6 - @ohif/viewer@0.0.22-alpha.7 * Split version and publish * chore(release): publish %s [skip ci] - @ohif/extension-cornerstone@0.0.39-alpha.7 - @ohif/extension-dicom-html@0.0.4-alpha.7 - @ohif/extension-dicom-microscopy@0.0.9-alpha.7 - @ohif/extension-dicom-pdf@0.0.8-alpha.7 - @ohif/extension-vtk@0.1.4-alpha.7 - @ohif/core@0.11.1-alpha.7 - @ohif/i18n@0.2.3-alpha.7 - @ohif/ui@0.2.18-alpha.7 - @ohif/viewer@0.0.22-alpha.8 * Try simplify netlify build * react-viewerbase --> @ohif/ui * add test for stylus loader * Try new way to specify publish path * Use an output folder that won't be ignored * Try move command * fiddle with paths * Dig for some information * Make sure we're in root for our commands * Remove discovery * Setup script-tag example * Fix typo * Move config folder * Update cornerstone extension to use shared/root webpack configs * capture changes * Update extension webpack configs * Don't check in docz output * Fix babel runtime resolution issue * Simplify ui build steps * Push in progress * Shift directories * Get viewer dev path to work * Fix viewer commonjs build * Fix build pwa config for viewers * Make sure our package specific command can be called from root * Update notes * Fix imports and misc. merge notes * Bump wado-image-loader version * Switch up commands to remove webworkers copy * Fix CI config * Fix more broken package references * Add react-dropzone * Persist so e2e test can use * Fix lockfile * Use cypress orb to simplify CI * Fix config * Try again * Install yarn latest for orb * Install yarn a different way * Wait on correct port * Run tests in viewer project * Fix cypress config * Make Cypress happier - use default location * Simplify e2e testing * Capture UI changes since fork * Catch core up * Grab latest deps after merge * Fix broken import * Make sure cornerstone-wado-image-loader resolves to 3+ * Note regarding orbs * Fix refresh on 404 routes * Fix odd error for cornerstone-wado-image-loader * Different target for UMD * Simplify dev script * Try to get fancy with netlify output * Let's do it again * Try to fix measurementTools issue * See if we can get our lerna magic to work on merge to monorepo branch
This commit is contained in:
1 parent
cac911f08e
commit
08ff214ea6
919 files changed
+45652
-52097
No files matched your search
@@ -0,0 +1,327 @@
|
||||
import cornerstone from 'cornerstone-core';
|
||||
import cornerstoneTools from 'cornerstone-tools';
|
||||
|
||||
function getBoundingBox(context, textLines, x, y, options) {
|
||||
if (Object.prototype.toString.call(textLines) !== '[object Array]') {
|
||||
textLines = [textLines];
|
||||
}
|
||||
|
||||
const padding = 5;
|
||||
const font = cornerstoneTools.textStyle.getFont();
|
||||
const fontSize = cornerstoneTools.textStyle.getFontSize();
|
||||
|
||||
context.save();
|
||||
context.font = font;
|
||||
context.textBaseline = 'top';
|
||||
|
||||
// Find the longest text width in the array of text data
|
||||
let maxWidth = 0;
|
||||
|
||||
textLines.forEach(text => {
|
||||
// Get the text width in the current font
|
||||
const width = context.measureText(text).width;
|
||||
|
||||
// Find the maximum with for all the text rows;
|
||||
maxWidth = Math.max(maxWidth, width);
|
||||
});
|
||||
|
||||
// Calculate the bounding box for this text box
|
||||
const boundingBox = {
|
||||
width: maxWidth + padding * 2,
|
||||
height: padding + textLines.length * (fontSize + padding),
|
||||
};
|
||||
|
||||
if (options && options.centering && options.centering.x === true) {
|
||||
x -= boundingBox.width / 2;
|
||||
}
|
||||
|
||||
if (options && options.centering && options.centering.y === true) {
|
||||
y -= boundingBox.height / 2;
|
||||
}
|
||||
|
||||
boundingBox.left = x;
|
||||
boundingBox.top = y;
|
||||
|
||||
context.restore();
|
||||
|
||||
// Return the bounding box so it can be used for pointNearHandle
|
||||
return boundingBox;
|
||||
}
|
||||
|
||||
function pixelToPage(element, position) {
|
||||
const enabledElement = cornerstone.getEnabledElement(element);
|
||||
const result = {
|
||||
x: 0,
|
||||
y: 0,
|
||||
};
|
||||
|
||||
// Stop here if the cornerstone element is not enabled or position is not an object
|
||||
if (!enabledElement || typeof position !== 'object') {
|
||||
return result;
|
||||
}
|
||||
|
||||
const canvas = enabledElement.canvas;
|
||||
|
||||
const canvasOffset = $(canvas).offset();
|
||||
result.x += canvasOffset.left;
|
||||
result.y += canvasOffset.top;
|
||||
|
||||
const canvasPosition = cornerstone.pixelToCanvas(element, position);
|
||||
result.x += canvasPosition.x;
|
||||
result.y += canvasPosition.y;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
function repositionTextBox(eventData, measurementData, config) {
|
||||
// Stop here if it's not a measurement creating
|
||||
if (!measurementData.isCreating) {
|
||||
return;
|
||||
}
|
||||
|
||||
const element = eventData.element;
|
||||
const enabledElement = cornerstone.getEnabledElement(element);
|
||||
const image = enabledElement.image;
|
||||
|
||||
const allowedBorders = OHIF.uiSettings.autoPositionMeasurementsTextCallOuts;
|
||||
const allow = {
|
||||
T: !allowedBorders || allowedBorders.includes('T'),
|
||||
R: !allowedBorders || allowedBorders.includes('R'),
|
||||
B: !allowedBorders || allowedBorders.includes('B'),
|
||||
L: !allowedBorders || allowedBorders.includes('L'),
|
||||
};
|
||||
|
||||
const getAvailableBlankAreas = (enabledElement, labelWidth, labelHeight) => {
|
||||
const { element, canvas, image } = enabledElement;
|
||||
|
||||
const topLeft = cornerstone.pixelToCanvas(element, {
|
||||
x: 0,
|
||||
y: 0,
|
||||
});
|
||||
|
||||
const bottomRight = cornerstone.pixelToCanvas(element, {
|
||||
x: image.width,
|
||||
y: image.height,
|
||||
});
|
||||
|
||||
const $canvas = $(canvas);
|
||||
const canvasWidth = $canvas.outerWidth();
|
||||
const canvasHeight = $canvas.outerHeight();
|
||||
|
||||
const result = {};
|
||||
result['x-1'] = allow.L && topLeft.x > labelWidth;
|
||||
result['y-1'] = allow.T && topLeft.y > labelHeight;
|
||||
result.x1 = allow.R && canvasWidth - bottomRight.x > labelWidth;
|
||||
result.y1 = allow.B && canvasHeight - bottomRight.y > labelHeight;
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
const getRenderingInformation = (limits, tool) => {
|
||||
const mid = {};
|
||||
mid.x = limits.x / 2;
|
||||
mid.y = limits.y / 2;
|
||||
|
||||
const directions = {};
|
||||
directions.x = tool.x < mid.x ? -1 : 1;
|
||||
directions.y = tool.y < mid.y ? -1 : 1;
|
||||
|
||||
const diffX = directions.x < 0 ? tool.x : limits.x - tool.x;
|
||||
const diffY = directions.y < 0 ? tool.y : limits.y - tool.y;
|
||||
let cornerAxis = diffY < diffX ? 'y' : 'x';
|
||||
|
||||
const map = {
|
||||
'x-1': 'L',
|
||||
'y-1': 'T',
|
||||
x1: 'R',
|
||||
y1: 'B',
|
||||
};
|
||||
|
||||
let current = 0;
|
||||
while (current < 4 && !allow[map[cornerAxis + directions[cornerAxis]]]) {
|
||||
// Invert the direction for the next iteration
|
||||
directions[cornerAxis] *= -1;
|
||||
|
||||
// Invert the tempCornerAxis
|
||||
cornerAxis = cornerAxis === 'x' ? 'y' : 'x';
|
||||
|
||||
current++;
|
||||
}
|
||||
|
||||
return {
|
||||
directions,
|
||||
cornerAxis,
|
||||
};
|
||||
};
|
||||
|
||||
const calculateAxisCenter = (axis, start, end) => {
|
||||
const a = start[axis];
|
||||
const b = end[axis];
|
||||
const lowest = Math.min(a, b);
|
||||
const highest = Math.max(a, b);
|
||||
return lowest + (highest - lowest) / 2;
|
||||
};
|
||||
|
||||
const getTextBoxSizeInPixels = (element, bounds) => {
|
||||
const topLeft = cornerstone.pageToPixel(element, 0, 0);
|
||||
const bottomRight = cornerstone.pageToPixel(element, bounds.x, bounds.y);
|
||||
return {
|
||||
x: bottomRight.x - topLeft.x,
|
||||
y: bottomRight.y - topLeft.y,
|
||||
};
|
||||
};
|
||||
|
||||
function getTextBoxOffset(config, cornerAxis, toolAxis, boxSize) {
|
||||
config = config || {};
|
||||
const centering = config.centering || {};
|
||||
const centerX = !!centering.x;
|
||||
const centerY = !!centering.y;
|
||||
const halfBoxSizeX = boxSize.x / 2;
|
||||
const halfBoxSizeY = boxSize.y / 2;
|
||||
const offset = {
|
||||
x: [],
|
||||
y: [],
|
||||
};
|
||||
|
||||
if (cornerAxis === 'x') {
|
||||
const offsetY = centerY ? 0 : halfBoxSizeY;
|
||||
|
||||
offset.x[-1] = centerX ? halfBoxSizeX : 0;
|
||||
offset.x[1] = centerX ? -halfBoxSizeX : -boxSize.x;
|
||||
offset.y[-1] = offsetY;
|
||||
offset.y[1] = offsetY;
|
||||
} else {
|
||||
const offsetX = centerX ? 0 : halfBoxSizeX;
|
||||
|
||||
offset.x[-1] = offsetX;
|
||||
offset.x[1] = offsetX;
|
||||
offset.y[-1] = centerY ? halfBoxSizeY : 0;
|
||||
offset.y[1] = centerY ? -halfBoxSizeY : -boxSize.y;
|
||||
}
|
||||
|
||||
return offset;
|
||||
}
|
||||
|
||||
const handles = measurementData.handles;
|
||||
const textBox = handles.textBox;
|
||||
|
||||
const $canvas = $(enabledElement.canvas);
|
||||
const canvasWidth = $canvas.outerWidth();
|
||||
const canvasHeight = $canvas.outerHeight();
|
||||
const offset = $canvas.offset();
|
||||
const canvasDimensions = {
|
||||
x: canvasWidth,
|
||||
y: canvasHeight,
|
||||
};
|
||||
|
||||
const bounds = {};
|
||||
bounds.x = textBox.boundingBox.width;
|
||||
bounds.y = textBox.boundingBox.height;
|
||||
|
||||
const getHandlePosition = key => {
|
||||
const { x, y } = handles[key];
|
||||
|
||||
return { x, y };
|
||||
};
|
||||
const start = getHandlePosition('start');
|
||||
const end = getHandlePosition('end');
|
||||
|
||||
const tool = {};
|
||||
tool.x = calculateAxisCenter('x', start, end);
|
||||
tool.y = calculateAxisCenter('y', start, end);
|
||||
|
||||
let limits = {};
|
||||
limits.x = image.width;
|
||||
limits.y = image.height;
|
||||
|
||||
let { directions, cornerAxis } = getRenderingInformation(limits, tool);
|
||||
|
||||
const availableAreas = getAvailableBlankAreas(
|
||||
enabledElement,
|
||||
bounds.x,
|
||||
bounds.y
|
||||
);
|
||||
const tempDirections = Object.assign({}, directions);
|
||||
let tempCornerAxis = cornerAxis;
|
||||
let foundPlace = false;
|
||||
let current = 0;
|
||||
while (current < 4) {
|
||||
if (availableAreas[tempCornerAxis + tempDirections[tempCornerAxis]]) {
|
||||
foundPlace = true;
|
||||
break;
|
||||
}
|
||||
|
||||
// Invert the direction for the next iteration
|
||||
tempDirections[tempCornerAxis] *= -1;
|
||||
|
||||
// Invert the tempCornerAxis
|
||||
tempCornerAxis = tempCornerAxis === 'x' ? 'y' : 'x';
|
||||
|
||||
current++;
|
||||
}
|
||||
|
||||
let cornerAxisPosition;
|
||||
if (foundPlace) {
|
||||
directions = Object.assign({}, directions, tempDirections);
|
||||
cornerAxis = tempCornerAxis;
|
||||
cornerAxisPosition = directions[cornerAxis] < 0 ? 0 : limits[cornerAxis];
|
||||
} else {
|
||||
limits = Object.assign({}, limits, canvasDimensions);
|
||||
|
||||
const toolPositionOnCanvas = cornerstone.pixelToCanvas(element, tool);
|
||||
const renderingInformation = getRenderingInformation(
|
||||
limits,
|
||||
toolPositionOnCanvas
|
||||
);
|
||||
directions = renderingInformation.directions;
|
||||
cornerAxis = renderingInformation.cornerAxis;
|
||||
|
||||
const position = {
|
||||
x: directions.x < 0 ? offset.left : offset.left + canvasWidth,
|
||||
y: directions.y < 0 ? offset.top : offset.top + canvasHeight,
|
||||
};
|
||||
|
||||
const pixelPosition = cornerstone.pageToPixel(
|
||||
element,
|
||||
position.x,
|
||||
position.y
|
||||
);
|
||||
cornerAxisPosition = pixelPosition[cornerAxis];
|
||||
}
|
||||
|
||||
const toolAxis = cornerAxis === 'x' ? 'y' : 'x';
|
||||
const boxSize = getTextBoxSizeInPixels(element, bounds);
|
||||
|
||||
textBox[cornerAxis] = cornerAxisPosition;
|
||||
textBox[toolAxis] = tool[toolAxis];
|
||||
|
||||
// Adjust the text box position reducing its size from the corner axis
|
||||
const textBoxOffset = getTextBoxOffset(config, cornerAxis, toolAxis, boxSize);
|
||||
textBox[cornerAxis] += textBoxOffset[cornerAxis][directions[cornerAxis]];
|
||||
|
||||
// Preventing the text box from partially going outside the canvas area
|
||||
const topLeft = cornerstone.pixelToCanvas(element, textBox);
|
||||
const bottomRight = {
|
||||
x: topLeft.x + bounds.x,
|
||||
y: topLeft.y + bounds.y,
|
||||
};
|
||||
const canvasBorders = {
|
||||
x0: offset.left,
|
||||
y0: offset.top,
|
||||
x1: offset.left + canvasWidth,
|
||||
y1: offset.top + canvasHeight,
|
||||
};
|
||||
if (topLeft[toolAxis] < 0) {
|
||||
const x = canvasBorders.x0;
|
||||
const y = canvasBorders.y0;
|
||||
const pixelPosition = cornerstone.pageToPixel(element, x, y);
|
||||
textBox[toolAxis] = pixelPosition[toolAxis];
|
||||
} else if (bottomRight[toolAxis] > canvasDimensions[toolAxis]) {
|
||||
const x = canvasBorders.x1 - bounds.x;
|
||||
const y = canvasBorders.y1 - bounds.y;
|
||||
const pixelPosition = cornerstone.pageToPixel(element, x, y);
|
||||
textBox[toolAxis] = pixelPosition[toolAxis];
|
||||
}
|
||||
}
|
||||
|
||||
export { getBoundingBox, pixelToPage, repositionTextBox };
|
||||
@@ -0,0 +1,2 @@
|
||||
import './cornerstone.js';
|
||||
import './parsingUtils.js';
|
||||
@@ -0,0 +1,90 @@
|
||||
import dicomParser from 'dicom-parser';
|
||||
|
||||
/**
|
||||
* A small set of utilities to help parsing DICOM element values.
|
||||
* In the future the functionality provided by this library might
|
||||
* be incorporated into dicomParser library.
|
||||
*/
|
||||
|
||||
export const parsingUtils = {
|
||||
/**
|
||||
* Check if supplied argument is a valid instance of the dicomParser.DataSet class.
|
||||
* @param data {Object} An instance of the dicomParser.DataSet class.
|
||||
* @returns {Boolean} Returns true if data is a valid instance of the dicomParser.DataSet class.
|
||||
*/
|
||||
isValidDataSet: function(data) {
|
||||
return data instanceof dicomParser.DataSet;
|
||||
},
|
||||
|
||||
/**
|
||||
* Parses an element tag according to the 'AT' VR definition.
|
||||
* @param data {Object} An instance of the dicomParser.DataSet class.
|
||||
* @param tag {String} A DICOM tag with in the format xGGGGEEEE.
|
||||
* @returns {String} A string representation of a data element tag or null if the field is not present or data is not long enough.
|
||||
*/
|
||||
attributeTag: function(data, tag) {
|
||||
if (this.isValidDataSet(data) && tag in data.elements) {
|
||||
let element = data.elements[tag];
|
||||
if (element && element.length === 4) {
|
||||
let parser = data.byteArrayParser.readUint16,
|
||||
bytes = data.byteArray,
|
||||
offset = element.dataOffset;
|
||||
return (
|
||||
'x' +
|
||||
(
|
||||
'00000000' +
|
||||
(
|
||||
parser(bytes, offset) * 256 * 256 +
|
||||
parser(bytes, offset + 2)
|
||||
).toString(16)
|
||||
).substr(-8)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
},
|
||||
|
||||
/**
|
||||
* Parses the string representation of a multi-valued element into an array of strings. If the parser
|
||||
* parameter is passed and is a function, it will be applied to each element of the resulting array.
|
||||
* @param data {Object} An instance of the dicomParser.DataSet class.
|
||||
* @param tag {String} A DICOM tag with in the format xGGGGEEEE.
|
||||
* @param parser {Function} An optional parser function that can be applied to each element of the array.
|
||||
* @returns {Array} An array of floating point numbers or null if the field is not present or data is not long enough.
|
||||
*/
|
||||
multiValue: function(data, tag, parser) {
|
||||
if (this.isValidDataSet(data) && tag in data.elements) {
|
||||
let element = data.elements[tag];
|
||||
if (element && element.length > 0) {
|
||||
let string = dicomParser.readFixedString(
|
||||
data.byteArray,
|
||||
element.dataOffset,
|
||||
element.length
|
||||
);
|
||||
if (typeof string === 'string' && string.length > 0) {
|
||||
if (typeof parser !== 'function') {
|
||||
parser = null;
|
||||
}
|
||||
|
||||
return string.split('\\').map(function(value) {
|
||||
value = value.trim();
|
||||
return parser !== null ? parser(value) : value;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
},
|
||||
|
||||
/**
|
||||
* Parses a string to an array of floats for a multi-valued element.
|
||||
* @param data {Object} An instance of the dicomParser.DataSet class.
|
||||
* @param tag {String} A DICOM tag with in the format xGGGGEEEE.
|
||||
* @returns {Array} An array of floating point numbers or null if the field is not present or data is not long enough.
|
||||
*/
|
||||
floatArray: function(data, tag) {
|
||||
return this.multiValue(data, tag, parseFloat);
|
||||
},
|
||||
};
|
||||
Reference in new issue
Block a user