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

Improve warning-toasts regarding segmentation #2715

Merged
merged 3 commits into from
Jun 12, 2018
Merged
Show file tree
Hide file tree
Changes from 2 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
12 changes: 0 additions & 12 deletions app/assets/javascripts/oxalis/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -449,18 +449,6 @@ export class OxalisModel {
return layers.map(adaptResolutionInfoForLayer);
}

shouldDisplaySegmentationData(): boolean {
const segmentationOpacity = Store.getState().datasetConfiguration.segmentationOpacity;
if (segmentationOpacity === 0) {
return false;
}
const currentViewMode = Store.getState().temporaryConfiguration.viewMode;

// Currently segmentation data can only be displayed in orthogonal and volume mode
const canModeDisplaySegmentationData = constants.MODES_PLANE.includes(currentViewMode);
return this.getSegmentationBinary() != null && canModeDisplaySegmentationData;
}

computeBoundaries() {
this.lowerBoundary = [Infinity, Infinity, Infinity];
this.upperBoundary = [-Infinity, -Infinity, -Infinity];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,21 @@ export function getContourTracingMode(tracing: TracingType): Maybe<ContourModeTy
}

export function isVolumeTracingDisallowed(state: OxalisState) {
return getRequestLogZoomStep(state) > 1;
const isVolumeTracing = state.tracing.type === "volume";
const isWrongZoomStep = getRequestLogZoomStep(state) > 1;
return isVolumeTracing && isWrongZoomStep;
}

export function displaysUnsampledVolumeData(state: OxalisState): boolean {
return getRequestLogZoomStep(state) === 1;
export function isSegmentationMissingForZoomstep(
state: OxalisState,
maxZoomStepForSegmentation: number,
): boolean {
return getRequestLogZoomStep(state) > maxZoomStepForSegmentation;
}

export function displaysDownsampledVolumeData(
state: OxalisState,
maxUnsampledZoomStepForSegmentation: number,
): boolean {
return getRequestLogZoomStep(state) === maxUnsampledZoomStepForSegmentation + 1;
}
66 changes: 65 additions & 1 deletion app/assets/javascripts/oxalis/model/sagas/annotation_saga.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
// @flow
import { takeEvery, call, select } from "redux-saga/effects";
import Model from "oxalis/model";
import { take, takeEvery, call, select } from "redux-saga/effects";
import { editAnnotation } from "admin/admin_rest_api";
import messages from "messages";
import Toast from "libs/toast";
import {
isVolumeTracingDisallowed,
displaysDownsampledVolumeData,
isSegmentationMissingForZoomstep,
} from "oxalis/model/accessors/volumetracing_accessor";
import constants from "oxalis/constants";
import Store from "oxalis/store";

export function* pushAnnotationUpdateAsync(): Generator<*, *, *> {
const tracing = yield select(state => state.tracing);
Expand All @@ -13,6 +23,60 @@ export function* pushAnnotationUpdateAsync(): Generator<*, *, *> {
];
}

function shouldDisplaySegmentationData(): boolean {
const { segmentationOpacity } = Store.getState().datasetConfiguration;
if (segmentationOpacity === 0) {
return false;
}
const currentViewMode = Store.getState().temporaryConfiguration.viewMode;

// Currently segmentation data can only be displayed in orthogonal and volume mode
const canModeDisplaySegmentationData = constants.MODES_PLANE.includes(currentViewMode);
return Model.getSegmentationBinary() != null && canModeDisplaySegmentationData;
}

export function* warnAboutSegmentationOpacity(): Generator<*, *, *> {
function* warnMaybe() {
const segmentationBinary = Model.getSegmentationBinary();
if (!segmentationBinary) {
return;
}
const isDisallowed = yield select(isVolumeTracingDisallowed);
const isSegmentationMissing = yield select(state =>
isSegmentationMissingForZoomstep(state, segmentationBinary.cube.MAX_ZOOM_STEP),
);

if (shouldDisplaySegmentationData() && (isDisallowed || isSegmentationMissing)) {
Toast.message("error", messages["tracing.segmentation_zoom_warning"], false, 3000);
} else {
Toast.close(messages["tracing.segmentation_zoom_warning"]);
}
const displaysDownsampled = yield select(state =>
displaysDownsampledVolumeData(state, segmentationBinary.cube.MAX_UNSAMPLED_ZOOM_STEP),
);
if (shouldDisplaySegmentationData() && displaysDownsampled) {
Toast.message("warning", messages["tracing.segmentation_downsampled_data_warning"]);
} else {
Toast.close(messages["tracing.segmentation_downsampled_data_warning"]);
}
}

yield take("INITIALIZE_SETTINGS");
yield* warnMaybe();

while (true) {
yield take([
"ZOOM_IN",
"ZOOM_OUT",
"ZOOM_BY_DELTA",
"SET_ZOOM_STEP",
action =>
action.type === "UPDATE_DATASET_SETTING" && action.propertyName === "segmentationOpacity",
]);
yield* warnMaybe();
}
}

export function* watchAnnotationAsync(): Generator<*, *, *> {
yield takeEvery("SET_ANNOTATION_NAME", pushAnnotationUpdateAsync);
yield takeEvery("SET_ANNOTATION_PUBLIC", pushAnnotationUpdateAsync);
Expand Down
56 changes: 5 additions & 51 deletions app/assets/javascripts/oxalis/model/sagas/root_saga.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,12 @@ import {
disallowVolumeTracingWarning,
watchVolumeTracingAsync,
} from "oxalis/model/sagas/volumetracing_saga";
import { watchAnnotationAsync } from "oxalis/model/sagas/annotation_saga";
import { alert } from "libs/window";
import { select, fork, take, cancel } from "redux-saga/effects";
import Model from "oxalis/model";
import Toast from "libs/toast";
import messages from "messages";
import {
isVolumeTracingDisallowed,
displaysUnsampledVolumeData,
} from "oxalis/model/accessors/volumetracing_accessor";
warnAboutSegmentationOpacity,
watchAnnotationAsync,
} from "oxalis/model/sagas/annotation_saga";
import { alert } from "libs/window";
import { fork, take, cancel } from "redux-saga/effects";

export default function* rootSaga(): Generator<*, *, *> {
while (true) {
Expand Down Expand Up @@ -53,45 +49,3 @@ Please reload the page to avoid losing data.
${err} ${err.stack}`);
}
}

// TODO: move this saga functionality as soon as annotation_saga.js was merged

function* warnAboutSegmentationOpacity(): Generator<*, *, *> {
const warnMaybe = function* warnMaybe() {
const shouldWarn = Model.shouldDisplaySegmentationData();
const isDisallowed = yield select(isVolumeTracingDisallowed);

if (shouldWarn && isDisallowed) {
const isVolumeTracing = yield select(state => state.tracing.type === "volume");
Toast.message(
"error",
messages["tracing.segmentation_zoom_warning"],
isVolumeTracing,
isVolumeTracing ? 6000 : 3000,
);
} else {
Toast.close(messages["tracing.segmentation_zoom_warning"]);
}
const displaysUnsampled = yield select(displaysUnsampledVolumeData);
if (shouldWarn && displaysUnsampled) {
Toast.message("warning", messages["tracing.segmentation_downsampled_data_warning"]);
} else {
Toast.close(messages["tracing.segmentation_downsampled_data_warning"]);
}
};

yield take("INITIALIZE_SETTINGS");
yield* warnMaybe();

while (true) {
yield take([
"ZOOM_IN",
"ZOOM_OUT",
"ZOOM_BY_DELTA",
"SET_ZOOM_STEP",
action =>
action.type === "UPDATE_DATASET_SETTING" && action.propertyName === "segmentationOpacity",
]);
yield* warnMaybe();
}
}