Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only show wrong mesh scale warning in console if not matching to any segmentation layer resolution #7921

Merged
merged 2 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ For upgrade instructions, please check the [migration guide](MIGRATIONS.released
- The context menu that is opened upon right-clicking a segment in the dataview port now contains the segment's name. [#7920](https://github.com/scalableminds/webknossos/pull/7920)

### Changed
- The warning about a mismatch between the scale of a pre-computed mesh and the dataset scale's factor now also considers all supported mags of the active segmentation layer. This reduces the false posive rate regarding this warning. [#7921](https://github.com/scalableminds/webknossos/pull/7921/)

### Fixed

Expand Down
4 changes: 4 additions & 0 deletions frontend/javascripts/libs/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1080,6 +1080,10 @@ export function diffObjects(
return changes(object, base);
}

export function areVec3AlmostEqual(a: Vector3, b: Vector3, epsilon: number = 1e-6): boolean {
return _.every(a.map((v, i) => Math.abs(v - b[i]) < epsilon));
}

export function coalesce<T extends {}>(e: T, token: any): T[keyof T] | null {
return Object.values(e).includes(token as T[keyof T]) ? token : null;
}
Expand Down
20 changes: 15 additions & 5 deletions frontend/javascripts/oxalis/model/sagas/mesh_saga.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { saveAs } from "file-saver";
import _ from "lodash";
import { V3 } from "libs/mjs";
import { chunkDynamically, sleep } from "libs/utils";
import { areVec3AlmostEqual, chunkDynamically, sleep } from "libs/utils";
import ErrorHandling from "libs/error_handling";
import type { APIDataset, APIMeshFile, APISegmentationLayer } from "types/api_flow_types";
import { mergeBufferGeometries } from "libs/BufferGeometryUtils";
Expand Down Expand Up @@ -1027,11 +1027,21 @@ function _getLoadChunksTasks(
// Compute vertex normals to achieve smooth shading
bufferGeometries.forEach((geometry) => geometry.computeVertexNormals());

// Check if the mesh scale is different to the dataset scale and warn in the console to make debugging easier in such a case.
if (!_.isEqual(scale, dataset.dataSource.scale.factor)) {
console.warn(
`Scale of mesh ${id} is different to dataset scale. Mesh scale: ${scale}, Dataset scale: ${dataset.dataSource.scale.factor}. This might lead to unexpected rendering results.`,
// Check if the mesh scale is different to all supported resolutions of the active segmentation scaled by the dataset scale and warn in the console to make debugging easier in such a case.
// This hint at the mesh file being computed when the dataset scale was different than currently configured.
const segmentationLayerResolutions = yield* select(
(state) => getVisibleSegmentationLayer(state)?.resolutions,
);
const datasetScaleFactor = dataset.dataSource.scale.factor;
if (segmentationLayerResolutions && scale) {
const doesSomeSegmResolutionMatchMeshScale = segmentationLayerResolutions.some(
(res) => areVec3AlmostEqual(V3.scale3(datasetScaleFactor, res), scale),
);
if (!doesSomeSegmResolutionMatchMeshScale) {
console.warn(
`Scale of mesh ${id} is different to dataset scale. Mesh scale: ${scale}, Dataset scale: ${dataset.dataSource.scale.factor}. This might lead to unexpected rendering results.`,
);
}
}

yield* call(
Expand Down