Skip to content

Commit 799a6a9

Browse files
committed
fix scaling of plane geometries; fix incorrectly scaled matrix when transforms were changed
1 parent 9349267 commit 799a6a9

File tree

4 files changed

+40
-9
lines changed

4 files changed

+40
-9
lines changed

frontend/javascripts/viewer/geometries/plane.ts

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ class Plane {
6161
// Different baseRotations for each of the planes ensures that the planes stay orthogonal to each other.
6262
baseRotation: Euler;
6363
storePropertyUnsubscribers: Array<() => void> = [];
64-
datasetScaleFactor: Vector3 = [1, 1, 1];
64+
originalDatasetScaleFactor: Vector3 = [1, 1, 1];
65+
transformedDatasetScaleFactor: Vector3 = [1, 1, 1];
6566

6667
// Properties are only created here to avoid new creating objects for each setRotation call.
6768
baseRotationMatrix = new Matrix4();
@@ -169,7 +170,7 @@ class Plane {
169170
// Account for the dataset scale to match one world space coordinate to one dataset scale unit.
170171
const scaleVector: Vector3 = V3.multiply(
171172
[1 * xFactor, 1 * yFactor, 1],
172-
this.datasetScaleFactor,
173+
this.originalDatasetScaleFactor,
173174
);
174175
this.getMeshes().map((mesh) => mesh.scale.set(...scaleVector));
175176
}
@@ -195,10 +196,9 @@ class Plane {
195196
positionOffset: Vector3 = DEFAULT_POSITION_OFFSET,
196197
): void => {
197198
// The world scaling by the dataset scale factor is inverted by the scene group
198-
199199
// containing all planes to avoid sheering in anisotropic scaled datasets.
200200
// Thus, this scale needs to be applied manually to the position here.
201-
const scaledPosition = V3.multiply(originalPosition, this.datasetScaleFactor);
201+
const scaledPosition = V3.multiply(originalPosition, this.transformedDatasetScaleFactor);
202202
// The offset is in world space already so no scaling is necessary.
203203
const offsetPosition = V3.add(scaledPosition, positionOffset);
204204
this.TDViewBorders.position.set(...offsetPosition);
@@ -234,7 +234,25 @@ class Plane {
234234
storeState.dataset,
235235
storeState.datasetConfiguration.nativelyRenderedLayerName,
236236
).factor,
237-
(scaleFactor) => (this.datasetScaleFactor = scaleFactor),
237+
(scaleFactor) => {
238+
// todop / workaround so that setScale uses new factor
239+
this.lastScaleFactors[0] = -1;
240+
this.transformedDatasetScaleFactor = scaleFactor;
241+
},
242+
true,
243+
),
244+
listenToStoreProperty(
245+
(storeState) =>
246+
getTransformedVoxelSize(
247+
storeState.dataset,
248+
storeState.datasetConfiguration.nativelyRenderedLayerName,
249+
true,
250+
).factor,
251+
(scaleFactor) => {
252+
// todop / workaround so that setScale uses new factor
253+
this.lastScaleFactors[0] = -1;
254+
this.originalDatasetScaleFactor = scaleFactor;
255+
},
238256
true,
239257
),
240258
];

frontend/javascripts/viewer/model/accessors/flycam_accessor.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,8 @@ export function _getMaximumZoomForAllMags(
198198
}
199199

200200
// Only exported for testing.
201-
export const _getDummyFlycamMatrix = memoizeOne((scale: Vector3) => {
202-
const scaleMatrix = getMatrixScale(scale);
201+
export const _getDummyFlycamMatrix = memoizeOne((voxelSize: Vector3) => {
202+
const scaleMatrix = getMatrixScale(voxelSize);
203203
return rotateOnAxis(M4x4.scale(scaleMatrix, M4x4.identity(), []), Math.PI, [0, 0, 1]);
204204
});
205205

frontend/javascripts/viewer/model/reducers/flycam_reducer.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,13 @@ function FlycamReducer(state: WebknossosState, action: Action): WebknossosState
213213
return update(state, {
214214
flycam: {
215215
currentMatrix: {
216-
$set: resetMatrix(state.flycam.currentMatrix, action.dataset.dataSource.scale.factor),
216+
$set: resetMatrix(
217+
state.flycam.currentMatrix,
218+
getTransformedVoxelSize(
219+
state.dataset,
220+
state.datasetConfiguration.nativelyRenderedLayerName,
221+
).factor,
222+
),
217223
},
218224
rotation: {
219225
$set: [0, 0, 0],
@@ -307,6 +313,13 @@ function FlycamReducer(state: WebknossosState, action: Action): WebknossosState
307313
return setDirectionReducer(state, action.direction);
308314
}
309315

316+
case "UPDATE_DATASET_SETTING": {
317+
if (action.propertyName === "nativelyRenderedLayerName") {
318+
return setRotationReducer(state, state.flycam.rotation);
319+
}
320+
return state;
321+
}
322+
310323
case "MOVE_FLYCAM": {
311324
if (action.vector.includes(Number.NaN)) {
312325
// if the action vector is invalid, do not update

frontend/javascripts/viewer/store.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -604,7 +604,7 @@ export const combinedReducer = reduceReducers(
604604
ProofreadingReducer,
605605
TaskReducer,
606606
SaveReducer,
607-
FlycamReducer,
607+
FlycamReducer, // needs to be executed after the settings reducer because of UPDATE_DATASET_SETTING handling in flycam reducer
608608
FlycamInfoCacheReducer,
609609
ViewModeReducer,
610610
AnnotationReducer,

0 commit comments

Comments
 (0)