* Filter segs and fetch correct metadata. * Initiate seg loading logic on series load into viewport. Need to write. * Automatic consumption of SEG functional. * Pull in master. * Fix issues after pulling in master. * Clean up old segmentation handlers. * WIP * WIP * Poppulate viewport with metadata. * Show hide/segmentation in react-vtkjs-viewport. * feat: 🎸 View segmentations in vtkjs viewport * Filter segs and fetch correct metadata. * Initiate seg loading logic on series load into viewport. Need to write. * Automatic consumption of SEG functional. * Pull in master. * Fix issues after pulling in master. * Clean up old segmentation handlers. * WIP * WIP * Poppulate viewport with metadata. * Show hide/segmentation in react-vtkjs-viewport. * feat: 🎸 View segmentations in vtkjs viewport * Rebase on master. * format format format * add basic extension parts * Updated yarn lock * Fetch derived/referenced displaysets in sidepanel * Add buttons, expose seriesDescription, write notes for Danny. * Add growcut tool extention. -> Move to a seperate repo. * Change some text fields. * expose dialog provider * hide draggable area * No pointer events for now; need to revisit * Don't filter seg from the outset for now * fiddling about * fix path to series data * fix logic to determine next available labelmapindex * Ability to swtich between labelmaps * Return a promise so we can make sure our labelmap is loaded before pulling metadata * Better UI to toggle labelmaps * Fix accidental untoggle of active labelmap for ui * Remove brush tool from cornerstone extension * Add cstools in preInit for seg extension * Add buttons for seg magic * Hide the measurements panel for now * Slightly better seg/scissor icons * Add eraser * ability to switch segments * seg color / switcher * Fix vtk labelmap cache. * sidepanel should scroll if there's overflow * Use a fancier range slider * Slightly prettier buttons * Push in progress * A bit more reactive; handle no-meta * Update to vtk.js 11.14.0 and react-vtkjs-viewport 0.6.0 * chore: kickstart preview * Fix conflict issues * Refactor panel * Isolate increment functions * Wip segment table * Hide selector and add scroll to segmentation * Increase width of segment description * Hide not used items * Add new select for segmentations * Align ui * Fix default segmentation * Fix broken import test * Get measurements panel back and add spacing to grouped buttons * Hide brush and selector and refresh when switching segmentations * Add pointer events back and fix broken tests for measurement table * Update segment list when switching humbnails * CR Update: Minor UI adjustments * CR Update: Set active segment * Move components to components folder * Add new settings ui * Integrate configuration * Improve styles * Float numbers * Improve css * Refresh settings menu if side panel changed * Fix settings rendering logic and remove comments * Extract components * Remove not used tools * Remove non used extension * Use style variables and remove comments * Remove non used dep from lock * Remove tools * Remove segmentation from toolbar * Add todo and brushradius from config * Fix packagejson growcut import * Remove webpack config already defined in parent * Update package json description * Change component name to british english to us * Improve prop types * Rename cornerstone label map event * Scope css * Extract and add doc to helper * Update jsdocs for getDerivedDatasets * Add proptypes and cr updates * Update tablistitem proptypes * config is readonly, rollback destructuring * Remove event for side panel * Add jsdocs for util * Extract getimageid to studymetada * Use ohif log instead of console * Remove specific style from side panel * Fix default props for brush radius * Descructure configuration props from settings component to avoid invalid props * Update proptypes to be required (settings) * Update readme * Remove commandsmodule * Get configuration module inside the component * Set selected segment * Rename extension and use modality to filter * Fix for failing tests (#1423) * hello world * Finish rebase for Igor. * Re-fix cornerstoneTools version that got messed up in merge. * Fix reactivity of isDisabled, write implementation for the SEG panel. * Nuke yarn.lock to stack CST to 4.12.0 * Remove debugger statements. * WIP consume RTSTRUCT * Doc API and add endpoints. * Rebase on SEG PR. * Update DICOM Keyword variables. * Fix metadata vars format * Add basic RT panel along with configuration * Wire up configuration with settings component * Mock structure set tables * Improve design of settings * Integrate list of contours * Extract panel section * Filter by seriesuid * Fix slow settings * Add jump to image * Fix expandable items * Improvements and CR update * CR Update: Remove google config * CR Update: Remove erase tool test * CR Update: Remove instance * CR Update: Fix issue with undefined prop * CR Update: Update yarn lock * Hide actions of structure item Co-authored-by: James A. Petts <jamesapetts@gmail.com> Co-authored-by: dannyrb <danny.ri.brown@gmail.com> Co-authored-by: igoroctaviano] <igoroctaviano@users.noreply.github.com> Co-authored-by: Mirna Silva <mirna.silva@radicalimaging.com>
92 lines
2.8 KiB
JavaScript
92 lines
2.8 KiB
JavaScript
export default function transformPointsToImagePlane(points, imagePlane) {
|
|
// See Equation C.7.6.2.1-1 of the DICOM standard
|
|
|
|
const {
|
|
rowCosines,
|
|
columnCosines,
|
|
rowPixelSpacing: deltaI,
|
|
columnPixelSpacing: deltaJ,
|
|
imagePositionPatient,
|
|
} = imagePlane;
|
|
|
|
const X = [rowCosines[0], rowCosines[1], rowCosines[2]];
|
|
const Y = [columnCosines[0], columnCosines[1], columnCosines[2]];
|
|
const S = [
|
|
imagePositionPatient[0],
|
|
imagePositionPatient[1],
|
|
imagePositionPatient[2],
|
|
];
|
|
|
|
// 9 sets of simulataneous equations to choose from, choose which set to solve
|
|
// Based on the largest component of each direction cosine.
|
|
// This avoids NaNs or floating point errors caused by dividing by very small numbers and ensures a safe mapping
|
|
// when mapping between planes that are close to orthogonal.
|
|
|
|
let ix = 0;
|
|
let iy = 0;
|
|
let largestDirectionCosineMagnitude = {
|
|
x: 0,
|
|
y: 0,
|
|
};
|
|
|
|
// Find the element with the largest magnitude in each direction cosine vector.
|
|
for (let i = 0; i < X.length; i++) {
|
|
if (Math.abs(X[i]) > largestDirectionCosineMagnitude.x) {
|
|
ix = i;
|
|
largestDirectionCosineMagnitude.x = Math.abs(X[i]);
|
|
}
|
|
if (Math.abs(Y[i]) > largestDirectionCosineMagnitude.y) {
|
|
iy = i;
|
|
largestDirectionCosineMagnitude.y = Math.abs(Y[i]);
|
|
}
|
|
}
|
|
|
|
const ci = {
|
|
// Index of max elements in X and Y
|
|
ix,
|
|
iy,
|
|
};
|
|
|
|
// Sanity Check
|
|
const directionCosineMagnitude = {
|
|
x: Math.pow(X[0], 2) + Math.pow(X[1], 2) + Math.pow(X[2], 2),
|
|
y: Math.pow(Y[0], 2) + Math.pow(Y[1], 2) + Math.pow(Y[2], 2),
|
|
};
|
|
|
|
if (directionCosineMagnitude.x < 0.99 || directionCosineMagnitude.y < 0.99) {
|
|
throw Error(
|
|
`Direction cosines do not sum to 1 in quadrature. There is likely a mistake in the DICOM metadata.` +
|
|
`directionCosineMagnitudes: ${directionCosineMagnitude.x}, ${directionCosineMagnitude.y}`
|
|
);
|
|
}
|
|
|
|
// Fill in elements that won't change between points
|
|
const c = [undefined, Y[ci.ix], X[ci.ix], undefined, X[ci.iy], Y[ci.iy]];
|
|
|
|
for (let pointI = 0; pointI < points.length; pointI++) {
|
|
// Subtract imagePositionPatient from the coordinate
|
|
const r = [
|
|
points[pointI].x - S[0],
|
|
points[pointI].y - S[1],
|
|
points[pointI].z - S[2],
|
|
];
|
|
|
|
// Set the variable terms in c.
|
|
c[0] = r[ci.ix];
|
|
c[3] = r[ci.iy];
|
|
|
|
// General case: Solves the two choosen simulataneous equations to go from the patient coordinate system to the imagePlane.
|
|
const i =
|
|
(c[0] - (c[1] * c[3]) / c[5]) /
|
|
(c[2] * deltaI * (1 - (c[1] * c[4]) / (c[2] * c[5])));
|
|
const j = (c[3] - c[4] * i * deltaI) / (c[5] * deltaJ);
|
|
|
|
// NOTE: Add (0.5, 0.5) to the coordinate, as PCS reference frame is with respect to the centre of the first pixel.
|
|
points[pointI].x = i + 0.5;
|
|
points[pointI].y = j + 0.5;
|
|
delete points[pointI].z;
|
|
}
|
|
|
|
return;
|
|
}
|