Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scaling #1541

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

Scaling #1541

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61,675 changes: 18,388 additions & 43,287 deletions package-lock.json

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions src/manipulators/anyHandlesOutsideImage.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ import external from '../externalModules.js';
*/
export default function(renderData, handles) {
const image = renderData.image;
const { scaledImageFactor } = image.imageFrame;
const imageRect = {
left: 0,
top: 0,
width: image.width,
height: image.height,
width: image.width * scaledImageFactor,
height: image.height * scaledImageFactor,
};

let handleOutsideImage = false;
Expand Down
10 changes: 9 additions & 1 deletion src/manipulators/getHandlePixelPosition.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,17 @@ export default function(eventData, interactionType) {
offsetY = handleTouchOffset.y;
}

return external.cornerstone.pageToPixel(
const enabledElement = external.cornerstone.getEnabledElement(element);
const { scaledImageFactor = 1 } = enabledElement.image.imageFrame;
const localPosition = external.cornerstone.pageToPixel(
element,
page.x + offsetX,
page.y + offsetY
);

return {
...localPosition,
x: localPosition.x * scaledImageFactor,
y: localPosition.y * scaledImageFactor,
};
}
5 changes: 4 additions & 1 deletion src/manipulators/moveNewHandle.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,10 @@ function _moveHandler(
const activeTool = getActiveTool(element, buttons, interactionType);

if (activeTool instanceof BaseAnnotationTool) {
activeTool.updateCachedStats(image, element, annotation);
const scaledAnnotation = JSON.parse(JSON.stringify(annotation));

activeTool.updateCachedStats(image, element, scaledAnnotation);
// activeTool.updateCachedStats(image, element, annotation);
}

const eventType = EVENTS.MEASUREMENT_MODIFIED;
Expand Down
39 changes: 37 additions & 2 deletions src/stateManagement/imageIdSpecificStateManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,22 @@ function newImageIdSpecificToolStateManager() {
return;
}

return getImageIdToolState(enabledElement.image.imageId, toolName);
return getImageIdToolState(
enabledElement.image.imageId,
toolName,
enabledElement.image.imageFrame.scaledImageFactor
);
}

// Here you can get state - used by tools as well as modules
// That save state persistently
function getImageIdToolState(imageId, toolName) {
function getImageIdToolState(imageId, toolName, scaledImageFactor) {
// If we don't have any tool state for this imageId, return undefined
if (toolState.hasOwnProperty(imageId) === false) {
return;
}
//
// console.log(toolState);

const imageIdToolState = toolState[imageId];

Expand All @@ -91,6 +97,35 @@ function newImageIdSpecificToolStateManager() {
return;
}

for (const tool of imageIdToolState[toolName].data) {
if (tool.handles === undefined || scaledImageFactor === undefined) {
continue;
}

for (const key of Object.keys(tool.handles)) {
if (
tool.handles[key].originalX === undefined ||
tool.handles[key].moving
) {
tool.handles[key].originalX = tool.handles[key].x;
}

if (
tool.handles[key].originalY === undefined ||
tool.handles[key].moving
) {
tool.handles[key].originalY = tool.handles[key].y;
}

tool.handles[key].x =
(tool.handles[key].originalX || tool.handles[key].x) /
scaledImageFactor;
tool.handles[key].y =
(tool.handles[key].originalY || tool.handles[key].y) /
scaledImageFactor;
}
}

return imageIdToolState[toolName];
}

Expand Down
12 changes: 12 additions & 0 deletions src/stateManagement/toolState.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,18 @@ function getElementToolStateManager(element) {
function addToolState(element, toolName, measurementData) {
const toolStateManager = getElementToolStateManager(element);

if (measurementData.handles !== undefined) {
const enabledElement = external.cornerstone.getEnabledElement(element);
const { scaledImageFactor } = enabledElement.image.imageFrame;

for (const key of Object.keys(measurementData.handles)) {
if (measurementData.handles[key].x !== undefined) {
measurementData.handles[key].x *= scaledImageFactor;
measurementData.handles[key].y *= scaledImageFactor;
}
}
}

measurementData.uuid = measurementData.uuid || uuidv4();
toolStateManager.add(element, toolName, measurementData);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,41 +22,44 @@ export default function updatePerpendicularLineHandles(

const { start, end } = measurementData.handles;
const { columnPixelSpacing = 1, rowPixelSpacing = 1 } = eventData.image;
const { scaledmageFactor = 1 } = eventData.image.imageFrame;

if (start.x === end.x && start.y === end.y) {
startX = start.x;
startY = start.y;
endX = end.x;
endY = end.y;
startX = start.originalX;
startY = start.originalY;
endX = end.originalX;
endY = end.originalY;
} else {
// Mid point of long-axis line
const mid = {
x: (start.x + end.x) / 2,
y: (start.y + end.y) / 2,
x: (start.originalX + end.originalX) / 2,
y: (start.originalY + end.originalY) / 2,
};

// Inclination of the perpendicular line
const vector = getLineVector(
columnPixelSpacing,
rowPixelSpacing,
columnPixelSpacing * scaledmageFactor,
rowPixelSpacing * scaledmageFactor,
start,
end
);

const perpendicularLineLength = vector.length / 2;
const rowMultiplier = perpendicularLineLength / (2 * rowPixelSpacing);
const columnMultiplier = perpendicularLineLength / (2 * columnPixelSpacing);
const rowMultiplier =
perpendicularLineLength / (2 * rowPixelSpacing * scaledmageFactor);
const columnMultiplier =
perpendicularLineLength / (2 * columnPixelSpacing * scaledmageFactor);

startX = mid.x + columnMultiplier * vector.y;
startY = mid.y - rowMultiplier * vector.x;
endX = mid.x - columnMultiplier * vector.y;
endY = mid.y + rowMultiplier * vector.x;
}

measurementData.handles.perpendicularStart.x = startX;
measurementData.handles.perpendicularStart.y = startY;
measurementData.handles.perpendicularEnd.x = endX;
measurementData.handles.perpendicularEnd.y = endY;
measurementData.handles.perpendicularStart.originalX = startX;
measurementData.handles.perpendicularStart.originalY = startY;
measurementData.handles.perpendicularEnd.originalX = endX;
measurementData.handles.perpendicularEnd.originalY = endY;

return true;
}