Skip to content

Commit

Permalink
Fix merge size calc, fixes #1846
Browse files Browse the repository at this point in the history
  • Loading branch information
ivmartel committed Jan 24, 2025
1 parent 99f61dd commit 6f67907
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions src/image/geometry.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -647,25 +647,35 @@ 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()
));

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]
));
Expand Down

0 comments on commit 6f67907

Please sign in to comment.