From 6f67907951076f4c27d7fd1c2535cafc66959a8e Mon Sep 17 00:00:00 2001 From: ivmartel Date: Fri, 24 Jan 2025 18:45:39 +0100 Subject: [PATCH] Fix merge size calc, fixes #1846 --- src/image/geometry.js | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/src/image/geometry.js b/src/image/geometry.js index d5f4ae3a6c..47edd957f9 100644 --- a/src/image/geometry.js +++ b/src/image/geometry.js @@ -632,7 +632,7 @@ export function getSliceGeometrySpacing(origins) { } /** - * Merge two geometries into one using the largest size and + * Merge two geometries into one using the merge size and * smallest resolution. * * @param {Geometry} geometry1 The first geometry. @@ -647,10 +647,6 @@ export function mergeGeometries(geometry1, geometry2) { return array1.map((v, i) => Math.max(v, array2[i])); }; - const newSize = new Size(maxByIndex( - geometry1.getSize().getValues(), - geometry2.getSize().getValues() - )); const newSpacing = new Spacing(minByIndex( geometry1.getSpacing().getValues(), geometry2.getSpacing().getValues() @@ -658,14 +654,28 @@ export function mergeGeometries(geometry1, geometry2) { const range1 = geometry1.getRange(); const range2 = geometry2.getRange(); - const minValues = minByIndex( + const minRangeValues = minByIndex( range1[0].getValues(), range2[0].getValues() ); + const maxRangeValues = maxByIndex( + range1[1].getValues(), + range2[1].getValues() + ); + + const sizeValues = []; + for (let i = 0; i < minRangeValues.length; ++i) { + sizeValues.push(Math.round( + Math.abs(maxRangeValues[i] - minRangeValues[i]) / newSpacing.get(i) + )); + } + const newSize = new Size(sizeValues); + + // TODO incorporate orientation const newOrigins = []; for (let i = 0; i < newSize.get(2); ++i) { - const values = minValues.slice(); - values[2] = minValues[2] + i * newSpacing.get(2); + const values = minRangeValues.slice(); + values[2] = minRangeValues[2] + i * newSpacing.get(2); newOrigins.push(new Point3D( values[0], values[1], values[2] ));