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

fix #1176 Pan and Zoom issue with segmentation on image with non-square pixels #1183

Merged
merged 3 commits into from
Mar 2, 2020
Merged
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
30 changes: 26 additions & 4 deletions src/eventListeners/internals/renderSegmentationFill.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,7 @@ export function renderFill(evt, labelmapCanvas, isActiveLabelMap) {

transformCanvasContext(context, canvas, viewport);

const canvasViewportTranslation = {
x: viewport.translation.x * viewport.scale,
y: viewport.translation.y * viewport.scale,
};
const canvasViewportTranslation = getCanvasViewportTranslation(eventData);

context.drawImage(
labelmapCanvas,
Expand All @@ -142,3 +139,28 @@ export function renderFill(evt, labelmapCanvas, isActiveLabelMap) {

resetCanvasContextTransform(context);
}

/**
* GetCanvasViewportTranslation - Returns translation coordinations for
* canvas viewport with calculation of image row/column pixel spacing.
*
* @param {Object} eventData The data associated with the event.
* @returns {Object} The coordinates of the translation.
*/
function getCanvasViewportTranslation(eventData) {
const { viewport, image } = eventData;

let widthScale = viewport.scale;
let heightScale = viewport.scale;

if (image.rowPixelSpacing < image.columnPixelSpacing) {
widthScale *= image.columnPixelSpacing / image.rowPixelSpacing;
} else if (image.columnPixelSpacing < image.rowPixelSpacing) {
heightScale *= image.rowPixelSpacing / image.columnPixelSpacing;
}

return {
x: viewport.translation.x * widthScale,
y: viewport.translation.y * heightScale,
};
}