Skip to content

Commit 97f32b0

Browse files
committed
fix(paint): use labelmap's coordinate transform
Paint strokes now convert world coordinates to index space using the labelmap's worldToIndex matrix instead of the parent image's. This fixes painting at wrong locations when segment groups have different direction matrices than their parent image.
1 parent 9d455cf commit 97f32b0

2 files changed

Lines changed: 31 additions & 21 deletions

File tree

src/components/tools/paint/PaintWidget2D.vue

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,8 @@ export default defineComponent({
5757
() => imageMetadata.value.lpsOrientation[viewAxis.value]
5858
);
5959
60-
const worldPointToIndex = (worldPoint: vec3) => {
61-
const { worldToIndex } = imageMetadata.value;
62-
const indexPoint = vec3.create();
63-
vec3.transformMat4(indexPoint, worldPoint, worldToIndex);
64-
return indexPoint;
60+
const cloneWorldPoint = (worldPoint: vec3) => {
61+
return vec3.clone(worldPoint);
6562
};
6663
6764
const widget = view.widgetManager.addWidget(
@@ -95,17 +92,17 @@ export default defineComponent({
9592
if (!imageId.value) return;
9693
paintStore.setSliceAxis(viewAxisIndex.value, imageId.value);
9794
const origin = widgetState.getBrush().getOrigin()!;
98-
const indexPoint = worldPointToIndex(origin);
99-
paintStore.startStroke(indexPoint, viewAxisIndex.value, imageId.value);
95+
const worldPoint = cloneWorldPoint(origin);
96+
paintStore.startStroke(worldPoint, viewAxisIndex.value, imageId.value);
10097
paintStore.updatePaintPosition(origin, viewId.value);
10198
});
10299
103100
onVTKEvent(widget, 'onInteractionEvent', () => {
104101
if (!imageId.value) return;
105102
const origin = widgetState.getBrush().getOrigin()!;
106-
const indexPoint = worldPointToIndex(origin);
103+
const worldPoint = cloneWorldPoint(origin);
107104
paintStore.placeStrokePoint(
108-
indexPoint,
105+
worldPoint,
109106
viewAxisIndex.value,
110107
imageId.value
111108
);
@@ -114,8 +111,8 @@ export default defineComponent({
114111
115112
onVTKEvent(widget, 'onEndInteractionEvent', () => {
116113
if (!imageId.value) return;
117-
const indexPoint = worldPointToIndex(widgetState.getBrush().getOrigin()!);
118-
paintStore.endStroke(indexPoint, viewAxisIndex.value, imageId.value);
114+
const worldPoint = cloneWorldPoint(widgetState.getBrush().getOrigin()!);
115+
paintStore.endStroke(worldPoint, viewAxisIndex.value, imageId.value);
119116
});
120117
121118
// --- manipulator --- //

src/store/tools/paint.ts

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -196,14 +196,27 @@ export const usePaintToolStore = defineStore('paint', () => {
196196

197197
const lastIndex = strokePoints.value.length - 1;
198198
if (lastIndex >= 0) {
199-
const lastPoint = strokePoints.value[lastIndex];
200-
const prevPoint =
199+
const labelmapWorldToIndex = labelmap.getWorldToIndex();
200+
const worldToLabelmapIndex = (worldPoint: vec3) => {
201+
const indexPoint = vec3.create();
202+
vec3.transformMat4(indexPoint, worldPoint, labelmapWorldToIndex);
203+
return indexPoint;
204+
};
205+
206+
const lastWorldPoint = strokePoints.value[lastIndex];
207+
const prevWorldPoint =
201208
lastIndex >= 1 ? strokePoints.value[lastIndex - 1] : undefined;
209+
210+
const lastIndexPoint = worldToLabelmapIndex(lastWorldPoint);
211+
const prevIndexPoint = prevWorldPoint
212+
? worldToLabelmapIndex(prevWorldPoint)
213+
: undefined;
214+
202215
this.$paint.paintLabelmap(
203216
labelmap,
204217
axisIndex,
205-
lastPoint,
206-
prevPoint,
218+
lastIndexPoint,
219+
prevIndexPoint,
207220
shouldPaint
208221
);
209222
}
@@ -250,32 +263,32 @@ export const usePaintToolStore = defineStore('paint', () => {
250263

251264
function startStroke(
252265
this: _This,
253-
indexPoint: vec3,
266+
worldPoint: vec3,
254267
axisIndex: 0 | 1 | 2,
255268
imageID: string
256269
) {
257270
switchToSegmentGroupForImage.call(this, imageID);
258-
strokePoints.value = [vec3.clone(indexPoint)];
271+
strokePoints.value = [vec3.clone(worldPoint)];
259272
doPaintStroke.call(this, axisIndex, imageID);
260273
}
261274

262275
function placeStrokePoint(
263276
this: _This,
264-
indexPoint: vec3,
277+
worldPoint: vec3,
265278
axisIndex: 0 | 1 | 2,
266279
imageID: string
267280
) {
268-
strokePoints.value.push(indexPoint);
281+
strokePoints.value.push(worldPoint);
269282
doPaintStroke.call(this, axisIndex, imageID);
270283
}
271284

272285
function endStroke(
273286
this: _This,
274-
indexPoint: vec3,
287+
worldPoint: vec3,
275288
axisIndex: 0 | 1 | 2,
276289
imageID: string
277290
) {
278-
strokePoints.value.push(indexPoint);
291+
strokePoints.value.push(worldPoint);
279292
doPaintStroke.call(this, axisIndex, imageID);
280293
}
281294

0 commit comments

Comments
 (0)