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

Fix opacity reset #7186

Merged
merged 7 commits into from
Nov 29, 2023
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
4 changes: 4 additions & 0 deletions changelog.d/20231127_123423_klakhov_fix_opacity_reset.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
### Fixed

- Shape settings **opacity** and **selected opacity** reset on each frame change
(<https://github.com/opencv/cvat/pull/7186>)
41 changes: 16 additions & 25 deletions cvat-ui/src/reducers/settings-reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { AnnotationActionTypes } from 'actions/annotation-actions';
import {
SettingsState, GridColor, FrameSpeed, ColorBy,
} from 'reducers';
import { ObjectState, ShapeType, DimensionType } from 'cvat-core-wrapper';
import { clampOpacity } from 'utils/clamp-opacity';

const defaultState: SettingsState = {
shapes: {
Expand Down Expand Up @@ -441,37 +441,28 @@ export default (state = defaultState, action: AnyAction): SettingsState => {
case AnnotationActionTypes.UPLOAD_JOB_ANNOTATIONS_SUCCESS:
case AnnotationActionTypes.CREATE_ANNOTATIONS_SUCCESS:
case AnnotationActionTypes.CHANGE_FRAME_SUCCESS: {
{
const MIN_OPACITY = 30;
const { shapes: { opacity } } = state;
if (opacity < MIN_OPACITY) {
return {
...state,
shapes: {
...state.shapes,
opacity: MIN_OPACITY,
selectedOpacity: MIN_OPACITY * 2,
},
};
}
}

return state;
const { states } = action.payload;
const { shapes } = state;
const [clampedOpacity, clampedSelectedOpacity] = clampOpacity(states, shapes);
return {
...state,
shapes: {
...state.shapes,
opacity: clampedOpacity,
selectedOpacity: clampedSelectedOpacity,
},
};
}
case BoundariesActionTypes.RESET_AFTER_ERROR:
case AnnotationActionTypes.GET_JOB_SUCCESS: {
const { job, states } = action.payload;
const { shapes } = state;
const filters = [...state.imageFilters];
filters.forEach((imageFilter) => {
imageFilter.modifier.currentProcessedImage = null;
});

const withMasks = states
.some((_state: ObjectState): boolean => _state.shapeType === ShapeType.MASK);
const opacity = withMasks || job.dimension === DimensionType.DIMENSION_3D ?
Math.max(state.shapes.opacity, 30) : state.shapes.opacity;
const selectedOpacity = withMasks || job.dimension === DimensionType.DIMENSION_3D ?
Math.max(state.shapes.selectedOpacity, 60) : state.shapes.selectedOpacity;
const [clampedOpacity, clampedSelectedOpacity] = clampOpacity(states, shapes, job);

return {
...state,
Expand All @@ -480,8 +471,8 @@ export default (state = defaultState, action: AnyAction): SettingsState => {
},
shapes: {
...defaultState.shapes,
opacity,
selectedOpacity,
opacity: clampedOpacity,
selectedOpacity: clampedSelectedOpacity,
},
imageFilters: filters,
};
Expand Down
36 changes: 36 additions & 0 deletions cvat-ui/src/utils/clamp-opacity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Copyright (C) 2023 CVAT.ai Corporation
//
// SPDX-License-Identifier: MIT

import { Job } from 'cvat-core-wrapper';
import { ShapeType, DimensionType } from 'cvat-core/src/enums';
import ObjectState from 'cvat-core/src/object-state';
import { SettingsState } from 'reducers';

export function clampOpacity(
states: ObjectState[],
shapes: SettingsState['shapes'],
job?: Job,
): [number, number] {
const ENHANCED_DEFAULT_OPACITY = 30;
const ENHANCED_DEFAULT_SELECTED_OPACITY = 60;

if (shapes.opacity >= ENHANCED_DEFAULT_OPACITY && shapes.selectedOpacity >= ENHANCED_DEFAULT_SELECTED_OPACITY) {
return [shapes.opacity, shapes.selectedOpacity];
}

const opacity = Math.max(shapes.opacity, ENHANCED_DEFAULT_OPACITY);
const selectedOpacity = Math.max(shapes.selectedOpacity, ENHANCED_DEFAULT_SELECTED_OPACITY);

if (job?.dimension === DimensionType.DIMENSION_3D) {
return [opacity, selectedOpacity];
}

const withMasks = states
.some((_state: ObjectState): boolean => _state.shapeType === ShapeType.MASK);
if (withMasks) {
return [opacity, selectedOpacity];
}

return [shapes.opacity, shapes.selectedOpacity];
}
Loading