Skip to content

Commit 453100e

Browse files
author
Alexis Girault
committed
feat(ImageMapper): implement getBoundsForSlice
1 parent 35aee8e commit 453100e

File tree

2 files changed

+69
-0
lines changed

2 files changed

+69
-0
lines changed

Sources/Rendering/Core/ImageMapper/index.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,30 @@ function vtkImageMapper(publicAPI, model) {
113113
return image.extentToBounds(ex);
114114
};
115115

116+
publicAPI.getBoundsForSlice = (slice, thickness = 0) => {
117+
const image = publicAPI.getInputData();
118+
if (!image) {
119+
return vtkMath.createUninitializedBounds();
120+
}
121+
const extent = image.getExtent();
122+
switch (publicAPI.getCurrentSlicingMode()) {
123+
case SlicingMode.X:
124+
extent[0] = slice - thickness;
125+
extent[1] = slice + thickness;
126+
break;
127+
case SlicingMode.Y:
128+
extent[2] = slice - thickness;
129+
extent[3] = slice + thickness;
130+
break;
131+
case SlicingMode.Z:
132+
extent[4] = slice - thickness;
133+
extent[5] = slice + thickness;
134+
break;
135+
default:
136+
}
137+
return image.extentToBounds(extent);
138+
};
139+
116140
publicAPI.getIsOpaque = () => true;
117141

118142
publicAPI.intersectWithLineForPointPicking = (p1, p2) => {

Sources/Rendering/Core/ImageSlice/index.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,51 @@ function vtkImageSlice(publicAPI, model) {
103103
return model.bounds;
104104
};
105105

106+
publicAPI.getBoundsForSlice = (slice, thickness = 0) => {
107+
// Check for the special case when the mapper's bounds are unknown
108+
const bds = model.mapper.getBoundsForSlice(slice, thickness);
109+
if (!bds || bds.length !== 6) {
110+
return bds;
111+
}
112+
113+
// Check for the special case when the actor is empty.
114+
if (bds[0] > bds[1]) {
115+
return bds;
116+
}
117+
118+
const bbox = [
119+
vec3.fromValues(bds[1], bds[3], bds[5]),
120+
vec3.fromValues(bds[1], bds[2], bds[5]),
121+
vec3.fromValues(bds[0], bds[2], bds[5]),
122+
vec3.fromValues(bds[0], bds[3], bds[5]),
123+
vec3.fromValues(bds[1], bds[3], bds[4]),
124+
vec3.fromValues(bds[1], bds[2], bds[4]),
125+
vec3.fromValues(bds[0], bds[2], bds[4]),
126+
vec3.fromValues(bds[0], bds[3], bds[4]),
127+
];
128+
129+
publicAPI.computeMatrix();
130+
const tmp4 = mat4.create();
131+
mat4.transpose(tmp4, model.matrix);
132+
bbox.forEach((pt) => vec3.transformMat4(pt, pt, tmp4));
133+
134+
let newBounds = [
135+
Number.MAX_VALUE,
136+
-Number.MAX_VALUE,
137+
Number.MAX_VALUE,
138+
-Number.MAX_VALUE,
139+
Number.MAX_VALUE,
140+
-Number.MAX_VALUE,
141+
];
142+
newBounds = newBounds.map(
143+
(d, i) =>
144+
i % 2 === 0
145+
? bbox.reduce((a, b) => (a > b[i / 2] ? b[i / 2] : a), d)
146+
: bbox.reduce((a, b) => (a < b[(i - 1) / 2] ? b[(i - 1) / 2] : a), d)
147+
);
148+
return newBounds;
149+
};
150+
106151
//----------------------------------------------------------------------------
107152
// Get the minimum X bound
108153
publicAPI.getMinXBound = () => {

0 commit comments

Comments
 (0)