lost-sia 2.0.0-alpha0 → 2.0.0-alpha2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +20 -3
- package/src/AnnoExampleViewer.jsx +61 -48
- package/src/AnnoLabelInput.jsx +94 -84
- package/src/AnnoToolBar.jsx +118 -97
- package/src/Annotation/AnnoBar.jsx +137 -131
- package/src/Annotation/Annotation.jsx +364 -328
- package/src/Annotation/Annotation.scss +24 -24
- package/src/Annotation/BBox.jsx +259 -251
- package/src/Annotation/Edge.jsx +79 -69
- package/src/Annotation/InfSelectionArea.jsx +56 -55
- package/src/Annotation/Line.jsx +60 -52
- package/src/Annotation/Node.jsx +242 -238
- package/src/Annotation/Point.jsx +175 -171
- package/src/Annotation/Polygon.jsx +337 -310
- package/src/Canvas.jsx +1910 -1720
- package/src/ImgBar.jsx +115 -107
- package/src/InfoBoxes/AnnoDetails.jsx +141 -141
- package/src/InfoBoxes/AnnoStats.jsx +90 -87
- package/src/InfoBoxes/InfoBox.jsx +63 -65
- package/src/InfoBoxes/InfoBoxArea.jsx +132 -130
- package/src/InfoBoxes/LabelInfo.jsx +103 -83
- package/src/LabelInput.jsx +204 -190
- package/src/Prompt.jsx +37 -38
- package/src/SIA.scss +8 -9
- package/src/SIAFilterButton.jsx +178 -169
- package/src/SIASettingButton.jsx +112 -107
- package/src/Sia.jsx +272 -285
- package/src/SiaPopup.jsx +13 -8
- package/src/ToolBar.jsx +394 -375
- package/src/Toolbar.css +8 -8
- package/src/ToolbarItem.jsx +28 -22
- package/src/filterTools.js +3 -3
- package/src/index.js +9 -11
- package/src/scss/_custom.scss +3 -0
- package/src/scss/_fixes.scss +6 -0
- package/src/scss/_layout.scss +6 -0
- package/src/scss/_variables.scss +4 -0
- package/src/scss/style-wrapper.scss +4 -0
- package/src/scss/style.scss +13 -0
- package/src/siaDummyData.js +241 -243
- package/src/stories/Button.jsx +54 -0
- package/src/stories/Button.stories.js +48 -0
- package/src/stories/Configure.mdx +369 -0
- package/src/stories/Header.jsx +69 -0
- package/src/stories/Header.stories.js +28 -0
- package/src/stories/Page.jsx +87 -0
- package/src/stories/Page.stories.js +28 -0
- package/src/stories/Sia.stories.jsx +61 -0
- package/src/stories/assets/accessibility.png +0 -0
- package/src/stories/assets/accessibility.svg +5 -0
- package/src/stories/assets/addon-library.png +0 -0
- package/src/stories/assets/assets.png +0 -0
- package/src/stories/assets/avif-test-image.avif +0 -0
- package/src/stories/assets/context.png +0 -0
- package/src/stories/assets/discord.svg +15 -0
- package/src/stories/assets/docs.png +0 -0
- package/src/stories/assets/figma-plugin.png +0 -0
- package/src/stories/assets/github.svg +3 -0
- package/src/stories/assets/share.png +0 -0
- package/src/stories/assets/styling.png +0 -0
- package/src/stories/assets/testing.png +0 -0
- package/src/stories/assets/theming.png +0 -0
- package/src/stories/assets/tutorials.svg +12 -0
- package/src/stories/assets/youtube.svg +4 -0
- package/src/stories/button.css +30 -0
- package/src/stories/header.css +32 -0
- package/src/stories/lost.js +54 -0
- package/src/stories/page.css +69 -0
- package/src/stories/siaDummyData.js +263 -0
- package/src/stories/store.js +18 -0
- package/src/types/annoStatus.js +4 -4
- package/src/types/canvasActions.js +51 -51
- package/src/types/cursorstyles.js +3 -3
- package/src/types/modes.js +8 -8
- package/src/types/notificationType.js +4 -4
- package/src/types/toolbarEvents.js +31 -31
- package/src/types/tools.js +9 -9
- package/src/utils/annoConversion.js +129 -99
- package/src/utils/colorlut.js +33 -32
- package/src/utils/constraints.js +76 -70
- package/src/utils/hist.js +52 -53
- package/src/utils/keyActions.js +96 -97
- package/src/utils/mouse.js +10 -10
- package/src/utils/siaIcons.jsx +106 -67
- package/src/utils/transform.js +259 -241
- package/src/utils/uiConfig.js +45 -45
- package/src/utils/windowViewport.js +26 -27
package/src/Canvas.jsx
CHANGED
|
@@ -1,47 +1,54 @@
|
|
|
1
|
-
import React, { Component } from
|
|
2
|
-
import _, { transform } from
|
|
3
|
-
import Annotation from
|
|
4
|
-
import AnnoLabelInput from
|
|
5
|
-
import ImgBar from
|
|
6
|
-
import Prompt from
|
|
7
|
-
import LabelInput from
|
|
8
|
-
import AnnoToolBar from
|
|
9
|
-
|
|
10
|
-
import * as annoConversion from
|
|
11
|
-
import * as keyActions from
|
|
12
|
-
import KeyMapper from
|
|
13
|
-
import * as TOOLS from
|
|
14
|
-
import * as modes from
|
|
15
|
-
import UndoRedo from
|
|
16
|
-
import * as transformAnnos from
|
|
17
|
-
import * as annoStatus from
|
|
18
|
-
import * as canvasActions from
|
|
19
|
-
import {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
1
|
+
import React, { Component } from "react";
|
|
2
|
+
import _, { transform } from "lodash";
|
|
3
|
+
import Annotation from "./Annotation/Annotation";
|
|
4
|
+
import AnnoLabelInput from "./AnnoLabelInput";
|
|
5
|
+
import ImgBar from "./ImgBar";
|
|
6
|
+
import Prompt from "./Prompt";
|
|
7
|
+
import LabelInput from "./LabelInput";
|
|
8
|
+
import AnnoToolBar from "./AnnoToolBar";
|
|
9
|
+
|
|
10
|
+
import * as annoConversion from "./utils/annoConversion";
|
|
11
|
+
import * as keyActions from "./utils/keyActions";
|
|
12
|
+
import KeyMapper from "./utils/keyActions";
|
|
13
|
+
import * as TOOLS from "./types/tools";
|
|
14
|
+
import * as modes from "./types/modes";
|
|
15
|
+
import UndoRedo from "./utils/hist";
|
|
16
|
+
import * as transformAnnos from "./utils/transform";
|
|
17
|
+
import * as annoStatus from "./types/annoStatus";
|
|
18
|
+
import * as canvasActions from "./types/canvasActions";
|
|
19
|
+
import {
|
|
20
|
+
Loader,
|
|
21
|
+
Dimmer,
|
|
22
|
+
Icon,
|
|
23
|
+
Header,
|
|
24
|
+
Button,
|
|
25
|
+
Form,
|
|
26
|
+
TextArea,
|
|
27
|
+
} from "semantic-ui-react";
|
|
28
|
+
import * as mouse from "./utils/mouse";
|
|
29
|
+
import * as colorlut from "./utils/colorlut";
|
|
30
|
+
import * as notificationType from "./types/notificationType";
|
|
31
|
+
import * as wv from "./utils/windowViewport";
|
|
32
|
+
|
|
33
|
+
import "./SIA.scss";
|
|
34
|
+
import InfoBoxes from "./InfoBoxes/InfoBoxArea";
|
|
28
35
|
|
|
29
36
|
/**
|
|
30
37
|
* SIA Canvas element that handles annotations within an image
|
|
31
|
-
*
|
|
38
|
+
*
|
|
32
39
|
* @param {React.Ref} container - A react ref to a div that defines the
|
|
33
40
|
* space where this Canvas lives in.
|
|
34
|
-
* @param {object} annos - A json object containing all annotation
|
|
41
|
+
* @param {object} annos - A json object containing all annotation
|
|
35
42
|
* information for an image
|
|
36
43
|
* {
|
|
37
44
|
* image : {
|
|
38
|
-
* id: int,
|
|
39
|
-
* number: int,
|
|
40
|
-
* amount: int,
|
|
41
|
-
* isFirst: bool,
|
|
45
|
+
* id: int,
|
|
46
|
+
* number: int,
|
|
47
|
+
* amount: int,
|
|
48
|
+
* isFirst: bool,
|
|
42
49
|
* isLast: bool,
|
|
43
50
|
* description: string, // -> optional
|
|
44
|
-
* imgActions: list of string, // -> optional
|
|
51
|
+
* imgActions: list of string, // -> optional
|
|
45
52
|
* },
|
|
46
53
|
* annotations: {
|
|
47
54
|
* bBoxes: [{
|
|
@@ -58,20 +65,20 @@ import InfoBoxes from './InfoBoxes/InfoBoxArea'
|
|
|
58
65
|
* }
|
|
59
66
|
* @param {object} annoSaveResponse - Backend response when updating an annotation in backend
|
|
60
67
|
* {
|
|
61
|
-
* tempId: int or str, // temporal frontend Id
|
|
68
|
+
* tempId: int or str, // temporal frontend Id
|
|
62
69
|
* dbId: int, // Id from backend
|
|
63
70
|
* newStatus: str // new Status for the annotation
|
|
64
71
|
* }
|
|
65
|
-
* @param {object} possibleLabels - Possible labels that can be assigned to
|
|
72
|
+
* @param {object} possibleLabels - Possible labels that can be assigned to
|
|
66
73
|
* an annotation.
|
|
67
|
-
* {
|
|
68
|
-
* id: int,
|
|
69
|
-
* description: str,
|
|
70
|
-
* label: str, (name of the label)
|
|
74
|
+
* {
|
|
75
|
+
* id: int,
|
|
76
|
+
* description: str,
|
|
77
|
+
* label: str, (name of the label)
|
|
71
78
|
* color: str (color is optional)
|
|
72
79
|
* }
|
|
73
80
|
* @param {blob} imageBlob - The actual image blob that will be displayed
|
|
74
|
-
* @param {object} uiConfig - User interface configs
|
|
81
|
+
* @param {object} uiConfig - User interface configs
|
|
75
82
|
* {
|
|
76
83
|
* nodesRadius: int, strokeWidth: int,
|
|
77
84
|
* layoutOffset: {left:int, top:int, right:int, bottom:int}, -> Offset of the canvas inside the container
|
|
@@ -82,7 +89,7 @@ import InfoBoxes from './InfoBoxes/InfoBoxArea'
|
|
|
82
89
|
* }
|
|
83
90
|
* @param {int} layoutUpdate - A counter that triggers a layout update
|
|
84
91
|
* everytime it is incremented.
|
|
85
|
-
* @param {string} selectedTool - The tool that is selected to draw an
|
|
92
|
+
* @param {string} selectedTool - The tool that is selected to draw an
|
|
86
93
|
* annotation. Possible choices are: 'bBox', 'point', 'line', 'polygon'
|
|
87
94
|
* @param {object} canvasConfig - Configuration for this canvas
|
|
88
95
|
* {
|
|
@@ -117,26 +124,26 @@ import InfoBoxes from './InfoBoxes/InfoBoxArea'
|
|
|
117
124
|
* @param {bool} preventScrolling Prevent scrolling on mouseEnter
|
|
118
125
|
* @param {bool} lockedAnnos A list of AnnoIds of annos that should only be displayed.
|
|
119
126
|
* Such annos can not be edited in any way.
|
|
120
|
-
* @event onAnnoSaveEvent - Callback with update information for a single
|
|
127
|
+
* @event onAnnoSaveEvent - Callback with update information for a single
|
|
121
128
|
* annotation or the current image that can be used for backend updates
|
|
122
129
|
* args: {
|
|
123
|
-
* action: the action that was performed in frontend,
|
|
124
|
-
* anno: anno information,
|
|
130
|
+
* action: the action that was performed in frontend,
|
|
131
|
+
* anno: anno information,
|
|
125
132
|
* img: image information
|
|
126
133
|
* }
|
|
127
134
|
* @event onNotification - Callback for Notification messages
|
|
128
135
|
* args: {title: str, message: str, type: str}
|
|
129
|
-
* @event onKeyDown - Fires for keyDown on canvas
|
|
130
|
-
* @event onKeyUp - Fires for keyUp on canvas
|
|
136
|
+
* @event onKeyDown - Fires for keyDown on canvas
|
|
137
|
+
* @event onKeyUp - Fires for keyUp on canvas
|
|
131
138
|
* @event onAnnoEvent - Fires when an anno performed an action
|
|
132
139
|
* args: {anno: annoObject, newAnnos: list of annoObjects, pAction: str}
|
|
133
140
|
* @event onCanvasEvent - Fires on canvas event
|
|
134
141
|
* args: {action: action, data: dataObject}
|
|
135
|
-
* action -> CANVAS_SVG_UPDATE
|
|
142
|
+
* action -> CANVAS_SVG_UPDATE
|
|
136
143
|
* data: {width: int, height: int, scale: float, translateX: float,
|
|
137
144
|
* translateY:float}
|
|
138
145
|
* action -> CANVAS_UI_CONFIG_UPDATE
|
|
139
|
-
* action -> CANVAS_LABEL_INPUT_CLOSE
|
|
146
|
+
* action -> CANVAS_LABEL_INPUT_CLOSE
|
|
140
147
|
* action -> CANVAS_IMG_LOADED
|
|
141
148
|
* action -> CANVAS_IMGBAR_CLOSE
|
|
142
149
|
* @event onImgBarClose - Fires when close button on ImgBar was hit.
|
|
@@ -147,1693 +154,1876 @@ import InfoBoxes from './InfoBoxes/InfoBoxArea'
|
|
|
147
154
|
* getAnnos(annos,removeFrontendIds)
|
|
148
155
|
*/
|
|
149
156
|
class Canvas extends Component {
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
this.setState({
|
|
225
|
-
imgLabelIds: this.props.imageMeta.labelIds,
|
|
226
|
-
imgAnnoTime: this.props.imageMeta.annoTime,
|
|
227
|
-
imgActions: this.props.imageMeta.imgActions ? this.props.imageMeta.imgActions : [],
|
|
228
|
-
imgLoadTimestamp: performance.now()
|
|
229
|
-
})
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
if (prevProps.annos !== this.props.annos) {
|
|
233
|
-
if (this.state.imageBlob) {
|
|
234
|
-
this.updateCanvasView(
|
|
235
|
-
annoConversion.fixBackendAnnos(this.props.annos)
|
|
236
|
-
)
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
if (prevProps.isJunk !== this.props.isJunk) {
|
|
240
|
-
if (this.state.isJunk !== this.props.isJunk) {
|
|
241
|
-
this.setState({
|
|
242
|
-
isJunk: this.props.isJunk
|
|
243
|
-
})
|
|
244
|
-
|
|
245
|
-
// do not save junk changes when image is currently changing (comparing junk state of previous and next image)
|
|
246
|
-
if (this.state.imageLoaded && !this.props.isImageChanging) {
|
|
247
|
-
this.handleAnnoSaveEvent(canvasActions.IMG_JUNK_UPDATE, undefined,
|
|
248
|
-
{ isJunk: this.props.isJunk })
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
if (this.state.imageBlob !== this.props.imageBlob) {
|
|
253
|
-
this.setState({ imageBlob: this.props.imageBlob })
|
|
254
|
-
}
|
|
255
|
-
if (this.props.possibleLabels !== prevProps.possibleLabels) {
|
|
256
|
-
this.updatePossibleLabels()
|
|
257
|
-
}
|
|
258
|
-
if (this.state.performedImageInit) {
|
|
259
|
-
// Initialize canvas history
|
|
260
|
-
this.setState({
|
|
261
|
-
performedImageInit: false,
|
|
262
|
-
annoToolBarVisible: false
|
|
263
|
-
})
|
|
264
|
-
if (this.props.uiConfig.imgBarVisible) {
|
|
265
|
-
this.setState({ imgBarVisible: true })
|
|
266
|
-
}
|
|
267
|
-
this.hist.clearHist()
|
|
268
|
-
this.hist.push({
|
|
269
|
-
...this.getAnnos(),
|
|
270
|
-
selectedAnnoId: undefined
|
|
271
|
-
}, 'init')
|
|
272
|
-
}
|
|
273
|
-
if (this.state.imageLoaded) {
|
|
274
|
-
// Selected annotation should be on top
|
|
275
|
-
this.putSelectedOnTop(prevState)
|
|
276
|
-
if (prevState.imgLoadCount !== this.state.imgLoadCount) {
|
|
277
|
-
this.updateCanvasView(
|
|
278
|
-
annoConversion.fixBackendAnnos(this.props.annos)
|
|
279
|
-
)
|
|
280
|
-
if (this.props.imageMeta) {
|
|
281
|
-
this.setImageLabels(this.props.imageMeta.labelIds)
|
|
282
|
-
this.setState({
|
|
283
|
-
performedImageInit: true
|
|
284
|
-
})
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
if (prevProps.layoutUpdate !== this.props.layoutUpdate) {
|
|
288
|
-
this.selectAnnotation(undefined)
|
|
289
|
-
this.updateCanvasView(annoConversion.canvasToBackendAnnos(
|
|
290
|
-
this.state.annos, this.state.svg, false, this.state.imageOffset
|
|
291
|
-
))
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
onImageLoad() {
|
|
157
|
+
constructor(props) {
|
|
158
|
+
super(props);
|
|
159
|
+
this.state = {
|
|
160
|
+
svg: {
|
|
161
|
+
width: "100%",
|
|
162
|
+
height: "100%",
|
|
163
|
+
scale: 1.0,
|
|
164
|
+
translateX: 0,
|
|
165
|
+
translateY: 0,
|
|
166
|
+
},
|
|
167
|
+
image: {
|
|
168
|
+
width: undefined,
|
|
169
|
+
height: undefined,
|
|
170
|
+
},
|
|
171
|
+
imageOffset: {
|
|
172
|
+
x: 0,
|
|
173
|
+
y: 0,
|
|
174
|
+
},
|
|
175
|
+
annos: [],
|
|
176
|
+
mode: modes.VIEW,
|
|
177
|
+
selectedAnnoId: undefined,
|
|
178
|
+
showSingleAnno: undefined,
|
|
179
|
+
showLabelInput: false,
|
|
180
|
+
imageLoaded: false,
|
|
181
|
+
imgLoadCount: 0,
|
|
182
|
+
imgLabelIds: [],
|
|
183
|
+
imgLabelChanged: false,
|
|
184
|
+
imgAnnoTime: 0,
|
|
185
|
+
imgLoadTimestamp: 0,
|
|
186
|
+
performedImageInit: false,
|
|
187
|
+
prevLabel: [],
|
|
188
|
+
imageBlob: undefined,
|
|
189
|
+
isJunk: props.isJunk,
|
|
190
|
+
imgBarVisible: false,
|
|
191
|
+
annoToolBarVisible: false,
|
|
192
|
+
possibleLabels: undefined,
|
|
193
|
+
annoCommentInputTrigger: 0,
|
|
194
|
+
imgActions: [],
|
|
195
|
+
};
|
|
196
|
+
this.img = React.createRef();
|
|
197
|
+
this.svg = React.createRef();
|
|
198
|
+
this.container = React.createRef();
|
|
199
|
+
this.hist = new UndoRedo();
|
|
200
|
+
this.keyMapper = new KeyMapper((keyAction) =>
|
|
201
|
+
this.handleKeyAction(keyAction),
|
|
202
|
+
);
|
|
203
|
+
this.mousePosAbs = undefined;
|
|
204
|
+
this.clipboard = undefined;
|
|
205
|
+
this.delayedBackendUpdates = {};
|
|
206
|
+
this.tempIdMap = {};
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
componentDidMount() {
|
|
210
|
+
this.updatePossibleLabels();
|
|
211
|
+
if (Number.isInteger(this.props.defaultLabel)) {
|
|
212
|
+
this.setState({ prevLabel: [this.props.defaultLabel] });
|
|
213
|
+
}
|
|
214
|
+
if (this.props.onGetFunction) {
|
|
215
|
+
this.props.onGetFunction({
|
|
216
|
+
deleteAllAnnos: () => this.deleteAllAnnos(),
|
|
217
|
+
unloadImage: () => this.unloadImage(),
|
|
218
|
+
resetZoom: () => this.resetZoom(),
|
|
219
|
+
getAnnos: (annos, removeFrontendIds) =>
|
|
220
|
+
this.getAnnos(annos, removeFrontendIds),
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
componentDidUpdate(prevProps, prevState) {
|
|
226
|
+
if (prevProps.annoSaveResponse !== this.props.annoSaveResponse) {
|
|
227
|
+
this.updateAnnoBySaveResponse(this.props.annoSaveResponse);
|
|
228
|
+
}
|
|
229
|
+
if (prevProps.imageMeta !== this.props.imageMeta) {
|
|
230
|
+
if (this.props.imageMeta) {
|
|
298
231
|
this.setState({
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
onMouseLeave() {
|
|
317
|
-
if (this.props.preventScrolling) {
|
|
318
|
-
document.body.style.overflow = ''
|
|
319
|
-
}
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
onWheel(e) {
|
|
323
|
-
// Zoom implementation. Note that svg is first scaled and
|
|
324
|
-
// second translated!
|
|
325
|
-
const up = e.deltaY < 0
|
|
326
|
-
const mousePos = this.getMousePosition(e)
|
|
327
|
-
const zoomFactor = 1.25
|
|
328
|
-
let nextScale
|
|
329
|
-
if (up) {
|
|
330
|
-
nextScale = this.state.svg.scale * zoomFactor
|
|
331
|
-
|
|
332
|
-
} else {
|
|
333
|
-
nextScale = this.state.svg.scale / zoomFactor
|
|
334
|
-
}
|
|
335
|
-
let newTranslation
|
|
336
|
-
//Constrain zoom
|
|
337
|
-
if (nextScale < 1.0) {
|
|
338
|
-
nextScale = 1.0
|
|
339
|
-
newTranslation = { x: 0, y: 0 }
|
|
340
|
-
} else if (nextScale > 200.0) {
|
|
341
|
-
nextScale = 200.0
|
|
342
|
-
newTranslation = wv.getZoomTranslation(mousePos, this.state.svg, nextScale)
|
|
343
|
-
} else {
|
|
344
|
-
newTranslation = wv.getZoomTranslation(mousePos, this.state.svg, nextScale)
|
|
345
|
-
}
|
|
232
|
+
imgLabelIds: this.props.imageMeta.labelIds,
|
|
233
|
+
imgAnnoTime: this.props.imageMeta.annoTime,
|
|
234
|
+
imgActions: this.props.imageMeta.imgActions
|
|
235
|
+
? this.props.imageMeta.imgActions
|
|
236
|
+
: [],
|
|
237
|
+
imgLoadTimestamp: performance.now(),
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
if (prevProps.annos !== this.props.annos) {
|
|
242
|
+
if (this.state.imageBlob) {
|
|
243
|
+
this.updateCanvasView(annoConversion.fixBackendAnnos(this.props.annos));
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
if (prevProps.isJunk !== this.props.isJunk) {
|
|
247
|
+
if (this.state.isJunk !== this.props.isJunk) {
|
|
346
248
|
this.setState({
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
}
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
this.
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
}
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
}
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
//
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
if (
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
*/
|
|
557
|
-
handleAnnoEvent(anno, pAction) {
|
|
558
|
-
console.log('handleAnnoEvent', pAction, anno)
|
|
559
|
-
let newAnnos = undefined
|
|
560
|
-
let actionHistoryStore = undefined
|
|
561
|
-
|
|
562
|
-
switch (pAction) {
|
|
563
|
-
case canvasActions.ANNO_ENTER_CREATE_MODE:
|
|
564
|
-
break
|
|
565
|
-
case canvasActions.ANNO_MARK_EXAMPLE:
|
|
566
|
-
newAnnos = this.updateSelectedAnno(anno, modes.VIEW)
|
|
567
|
-
this.pushHist(
|
|
568
|
-
newAnnos, anno.id,
|
|
569
|
-
pAction, this.state.showSingleAnno
|
|
570
|
-
)
|
|
571
|
-
this.handleAnnoSaveEvent(pAction, anno)
|
|
572
|
-
break
|
|
573
|
-
case canvasActions.ANNO_SELECTED:
|
|
574
|
-
this.selectAnnotation(anno.id)
|
|
575
|
-
// this.pushHist(
|
|
576
|
-
// this.state.annos, anno.id,
|
|
577
|
-
// pAction, this.state.showSingleAnno
|
|
578
|
-
// )
|
|
579
|
-
break
|
|
580
|
-
case canvasActions.ANNO_START_CREATING:
|
|
581
|
-
newAnnos = this.updateSelectedAnno(anno)
|
|
582
|
-
this.pushHist(
|
|
583
|
-
newAnnos, anno.id,
|
|
584
|
-
pAction, this.state.showSingleAnno
|
|
585
|
-
)
|
|
586
|
-
break
|
|
587
|
-
case canvasActions.ANNO_CREATED:
|
|
588
|
-
actionHistoryStore = [...this.state.imgActions, pAction]
|
|
589
|
-
anno = this.stopAnnotimeMeasure(anno)
|
|
590
|
-
newAnnos = this.updateSelectedAnno({ ...anno, status: annoStatus.DATABASE }, modes.VIEW)
|
|
591
|
-
this.pushHist(
|
|
592
|
-
newAnnos, anno.id,
|
|
593
|
-
pAction, undefined
|
|
594
|
-
)
|
|
595
|
-
this.showSingleAnno(undefined)
|
|
596
|
-
this.setState({ annoToolBarVisible: true })
|
|
597
|
-
this.handleAnnoSaveEvent(pAction, anno, { imgActions: actionHistoryStore })
|
|
598
|
-
break
|
|
599
|
-
case canvasActions.ANNO_MOVED:
|
|
600
|
-
actionHistoryStore = [...this.state.imgActions, pAction]
|
|
601
|
-
anno = this.stopAnnotimeMeasure(anno)
|
|
602
|
-
newAnnos = this.updateSelectedAnno(anno, modes.VIEW)
|
|
603
|
-
this.showSingleAnno(undefined)
|
|
604
|
-
this.pushHist(
|
|
605
|
-
newAnnos, anno.id,
|
|
606
|
-
pAction, undefined
|
|
607
|
-
)
|
|
608
|
-
this.setState({ annoToolBarVisible: true })
|
|
609
|
-
this.handleAnnoSaveEvent(pAction, anno, { imgActions: actionHistoryStore })
|
|
610
|
-
break
|
|
611
|
-
case canvasActions.ANNO_ENTER_MOVE_MODE:
|
|
612
|
-
anno = this.startAnnotimeMeasure(anno)
|
|
613
|
-
this.updateSelectedAnno(anno, modes.MOVE)
|
|
614
|
-
this.showSingleAnno(anno.id)
|
|
615
|
-
this.setState({ annoToolBarVisible: false })
|
|
616
|
-
break
|
|
617
|
-
case canvasActions.ANNO_ENTER_EDIT_MODE:
|
|
618
|
-
anno = this.startAnnotimeMeasure(anno)
|
|
619
|
-
this.updateSelectedAnno(anno, modes.EDIT)
|
|
620
|
-
// this.showSingleAnno(anno.id)
|
|
621
|
-
this.setState({ annoToolBarVisible: false })
|
|
622
|
-
break
|
|
623
|
-
case canvasActions.ANNO_ADDED_NODE:
|
|
624
|
-
actionHistoryStore = [...this.state.imgActions, pAction]
|
|
625
|
-
newAnnos = this.updateSelectedAnno(anno, modes.VIEW)
|
|
626
|
-
this.pushHist(
|
|
627
|
-
newAnnos, anno.id,
|
|
628
|
-
pAction, this.state.showSingleAnno
|
|
629
|
-
)
|
|
630
|
-
this.handleAnnoSaveEvent(pAction, anno, { imgActions: actionHistoryStore })
|
|
631
|
-
break
|
|
632
|
-
case canvasActions.ANNO_REMOVED_NODE:
|
|
633
|
-
actionHistoryStore = [...this.state.imgActions, pAction]
|
|
634
|
-
if (!this.checkAnnoLength(anno)) {
|
|
635
|
-
newAnnos = this.updateSelectedAnno(anno, modes.DELETED)
|
|
636
|
-
this.showSingleAnno(undefined)
|
|
637
|
-
} else {
|
|
638
|
-
newAnnos = this.updateSelectedAnno(anno, modes.CREATE)
|
|
639
|
-
}
|
|
640
|
-
this.pushHist(
|
|
641
|
-
newAnnos, anno.id,
|
|
642
|
-
pAction, this.state.showSingleAnno
|
|
643
|
-
)
|
|
644
|
-
if (anno.status !== annoStatus.NEW) {
|
|
645
|
-
this.handleAnnoSaveEvent(pAction, anno, { imgActions: actionHistoryStore })
|
|
646
|
-
}
|
|
647
|
-
break
|
|
648
|
-
case canvasActions.ANNO_EDITED:
|
|
649
|
-
actionHistoryStore = [...this.state.imgActions, pAction]
|
|
650
|
-
anno = this.stopAnnotimeMeasure(anno)
|
|
651
|
-
newAnnos = this.updateSelectedAnno(anno, modes.VIEW)
|
|
652
|
-
this.pushHist(
|
|
653
|
-
newAnnos, anno.id,
|
|
654
|
-
pAction, this.state.showSingleAnno
|
|
655
|
-
)
|
|
656
|
-
this.setState({ annoToolBarVisible: true })
|
|
657
|
-
this.handleAnnoSaveEvent(pAction, anno, { imgActions: actionHistoryStore })
|
|
658
|
-
break
|
|
659
|
-
case canvasActions.ANNO_DELETED:
|
|
660
|
-
actionHistoryStore = [...this.state.imgActions, pAction]
|
|
661
|
-
const res = this.updateSelectedAnno(anno, modes.DELETED, true)
|
|
662
|
-
newAnnos = res.newAnnos
|
|
663
|
-
this.selectAnnotation(undefined)
|
|
664
|
-
this.showSingleAnno(undefined)
|
|
665
|
-
this.pushHist(
|
|
666
|
-
newAnnos, undefined,
|
|
667
|
-
pAction, this.state.showSingleAnno
|
|
668
|
-
)
|
|
669
|
-
this.handleAnnoSaveEvent(pAction, res.newAnno, { imgActions: actionHistoryStore })
|
|
670
|
-
break
|
|
671
|
-
case canvasActions.ANNO_COMMENT_UPDATE:
|
|
672
|
-
actionHistoryStore = [...this.state.imgActions, pAction]
|
|
673
|
-
const res_comment = this.updateSelectedAnno(anno, modes.VIEW, true)
|
|
674
|
-
newAnnos = res_comment.newAnnos
|
|
675
|
-
this.pushHist(
|
|
676
|
-
newAnnos, anno.id,
|
|
677
|
-
pAction, this.state.showSingleAnno
|
|
678
|
-
)
|
|
679
|
-
this.handleNotification({
|
|
680
|
-
title: "Saved comment",
|
|
681
|
-
message: `Saved comment: ${anno.comment}`,
|
|
682
|
-
type: notificationType.SUCCESS
|
|
683
|
-
})
|
|
684
|
-
this.handleAnnoSaveEvent(pAction, res_comment.newAnno, { imgActions: actionHistoryStore })
|
|
685
|
-
break
|
|
686
|
-
case canvasActions.ANNO_LABEL_UPDATE:
|
|
687
|
-
actionHistoryStore = [...this.state.imgActions, pAction]
|
|
688
|
-
anno = this.stopAnnotimeMeasure(anno)
|
|
689
|
-
anno = this.checkAndCorrectAnno(anno)
|
|
690
|
-
console.log('ANNO_LABEL_UPDATE aftercheckAndCorrect', anno)
|
|
691
|
-
// this.updateSelectedAnno(anno, anno.mode)
|
|
692
|
-
if (anno.mode === modes.DELETED) {
|
|
693
|
-
this.updateSelectedAnno(anno, modes.DELETED)
|
|
694
|
-
} else {
|
|
695
|
-
this.updateSelectedAnno({ ...anno, status: annoStatus.DATABASE }, modes.VIEW)
|
|
696
|
-
}
|
|
697
|
-
// if (!this.checkAnnoLength(anno)){
|
|
698
|
-
// newAnnos = this.updateSelectedAnno(anno, modes.DELETED)
|
|
699
|
-
// } else {
|
|
700
|
-
// newAnnos = this.updateSelectedAnno(anno, modes.VIEW)
|
|
701
|
-
// }
|
|
702
|
-
this.setState({ annoToolBarVisible: true })
|
|
703
|
-
if (anno.mode !== modes.DELETED) {
|
|
704
|
-
this.pushHist(
|
|
705
|
-
newAnnos, anno.id,
|
|
706
|
-
pAction, undefined
|
|
707
|
-
)
|
|
708
|
-
this.handleAnnoSaveEvent(pAction, anno, { imgActions: actionHistoryStore })
|
|
709
|
-
}
|
|
710
|
-
break
|
|
711
|
-
case canvasActions.ANNO_CREATED_NODE:
|
|
712
|
-
actionHistoryStore = [...this.state.imgActions, pAction]
|
|
713
|
-
anno = this.stopAnnotimeMeasure(anno)
|
|
714
|
-
newAnnos = this.updateSelectedAnno(anno, modes.CREATE)
|
|
715
|
-
this.pushHist(
|
|
716
|
-
newAnnos, anno.id,
|
|
717
|
-
pAction, this.state.showSingleAnno
|
|
718
|
-
)
|
|
719
|
-
break
|
|
720
|
-
case canvasActions.ANNO_CREATED_FINAL_NODE:
|
|
721
|
-
actionHistoryStore = [...this.state.imgActions, pAction]
|
|
722
|
-
anno = this.stopAnnotimeMeasure(anno)
|
|
723
|
-
newAnnos = this.updateSelectedAnno({ ...anno, status: annoStatus.DATABASE }, modes.VIEW)
|
|
724
|
-
this.pushHist(
|
|
725
|
-
newAnnos, anno.id,
|
|
726
|
-
pAction, undefined
|
|
727
|
-
)
|
|
728
|
-
this.showSingleAnno(undefined)
|
|
729
|
-
this.setState({ annoToolBarVisible: true })
|
|
730
|
-
this.handleAnnoSaveEvent(pAction, anno, { imgActions: actionHistoryStore })
|
|
731
|
-
break
|
|
732
|
-
default:
|
|
733
|
-
console.warn('Action not handled', pAction)
|
|
734
|
-
break
|
|
735
|
-
}
|
|
736
|
-
if (actionHistoryStore) {
|
|
737
|
-
this.setState({ imgActions: actionHistoryStore })
|
|
738
|
-
}
|
|
739
|
-
if (this.props.onAnnoEvent) {
|
|
740
|
-
this.props.onAnnoEvent(anno, newAnnos, pAction)
|
|
741
|
-
}
|
|
742
|
-
}
|
|
743
|
-
|
|
744
|
-
handleAnnoSaveEvent(action, anno, img) {
|
|
745
|
-
const imgData = {
|
|
746
|
-
...img,
|
|
747
|
-
imgId: this.props.imageMeta.id,
|
|
748
|
-
annoTime: this.props.imageMeta.annoTime + (performance.now() - this.state.imgLoadTimestamp) / 1000
|
|
749
|
-
}
|
|
750
|
-
let backendAnno = undefined
|
|
249
|
+
isJunk: this.props.isJunk,
|
|
250
|
+
});
|
|
251
|
+
|
|
252
|
+
// do not save junk changes when image is currently changing (comparing junk state of previous and next image)
|
|
253
|
+
if (this.state.imageLoaded && !this.props.isImageChanging) {
|
|
254
|
+
this.handleAnnoSaveEvent(canvasActions.IMG_JUNK_UPDATE, undefined, {
|
|
255
|
+
isJunk: this.props.isJunk,
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
if (this.state.imageBlob !== this.props.imageBlob) {
|
|
261
|
+
this.setState({ imageBlob: this.props.imageBlob });
|
|
262
|
+
}
|
|
263
|
+
if (this.props.possibleLabels !== prevProps.possibleLabels) {
|
|
264
|
+
this.updatePossibleLabels();
|
|
265
|
+
}
|
|
266
|
+
if (this.state.performedImageInit) {
|
|
267
|
+
// Initialize canvas history
|
|
268
|
+
this.setState({
|
|
269
|
+
performedImageInit: false,
|
|
270
|
+
annoToolBarVisible: false,
|
|
271
|
+
});
|
|
272
|
+
if (this.props.uiConfig.imgBarVisible) {
|
|
273
|
+
this.setState({ imgBarVisible: true });
|
|
274
|
+
}
|
|
275
|
+
this.hist.clearHist();
|
|
276
|
+
this.hist.push(
|
|
277
|
+
{
|
|
278
|
+
...this.getAnnos(),
|
|
279
|
+
selectedAnnoId: undefined,
|
|
280
|
+
},
|
|
281
|
+
"init",
|
|
282
|
+
);
|
|
283
|
+
}
|
|
284
|
+
if (this.state.imageLoaded) {
|
|
285
|
+
// Selected annotation should be on top
|
|
286
|
+
this.putSelectedOnTop(prevState);
|
|
287
|
+
if (prevState.imgLoadCount !== this.state.imgLoadCount) {
|
|
288
|
+
this.updateCanvasView(annoConversion.fixBackendAnnos(this.props.annos));
|
|
289
|
+
if (this.props.imageMeta) {
|
|
290
|
+
this.setImageLabels(this.props.imageMeta.labelIds);
|
|
291
|
+
this.setState({
|
|
292
|
+
performedImageInit: true,
|
|
293
|
+
});
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
if (prevProps.layoutUpdate !== this.props.layoutUpdate) {
|
|
297
|
+
this.selectAnnotation(undefined);
|
|
298
|
+
this.updateCanvasView(
|
|
299
|
+
annoConversion.canvasToBackendAnnos(
|
|
300
|
+
this.state.annos,
|
|
301
|
+
this.state.svg,
|
|
302
|
+
false,
|
|
303
|
+
this.state.imageOffset,
|
|
304
|
+
),
|
|
305
|
+
);
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
onImageLoad() {
|
|
311
|
+
this.setState({
|
|
312
|
+
imageLoaded: true,
|
|
313
|
+
imgLoadCount: this.state.imgLoadCount + 1,
|
|
314
|
+
showLabelInput: false,
|
|
315
|
+
showSingleAnno: undefined,
|
|
316
|
+
selectedAnnoId: undefined,
|
|
317
|
+
});
|
|
318
|
+
this.triggerCanvasEvent(canvasActions.CANVAS_IMG_LOADED);
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
onMouseOver() {
|
|
322
|
+
this.svg.current.focus();
|
|
323
|
+
//Prevent scrolling on svg
|
|
324
|
+
if (this.props.preventScrolling) {
|
|
325
|
+
document.body.style.overflow = "hidden";
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
onMouseLeave() {
|
|
330
|
+
if (this.props.preventScrolling) {
|
|
331
|
+
document.body.style.overflow = "";
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
onWheel(e) {
|
|
336
|
+
// Zoom implementation. Note that svg is first scaled and
|
|
337
|
+
// second translated!
|
|
338
|
+
const up = e.deltaY < 0;
|
|
339
|
+
const mousePos = this.getMousePosition(e);
|
|
340
|
+
const zoomFactor = 1.25;
|
|
341
|
+
let nextScale;
|
|
342
|
+
if (up) {
|
|
343
|
+
nextScale = this.state.svg.scale * zoomFactor;
|
|
344
|
+
} else {
|
|
345
|
+
nextScale = this.state.svg.scale / zoomFactor;
|
|
346
|
+
}
|
|
347
|
+
let newTranslation;
|
|
348
|
+
//Constrain zoom
|
|
349
|
+
if (nextScale < 1.0) {
|
|
350
|
+
nextScale = 1.0;
|
|
351
|
+
newTranslation = { x: 0, y: 0 };
|
|
352
|
+
} else if (nextScale > 200.0) {
|
|
353
|
+
nextScale = 200.0;
|
|
354
|
+
newTranslation = wv.getZoomTranslation(
|
|
355
|
+
mousePos,
|
|
356
|
+
this.state.svg,
|
|
357
|
+
nextScale,
|
|
358
|
+
);
|
|
359
|
+
} else {
|
|
360
|
+
newTranslation = wv.getZoomTranslation(
|
|
361
|
+
mousePos,
|
|
362
|
+
this.state.svg,
|
|
363
|
+
nextScale,
|
|
364
|
+
);
|
|
365
|
+
}
|
|
366
|
+
this.setState({
|
|
367
|
+
svg: {
|
|
368
|
+
...this.state.svg,
|
|
369
|
+
scale: nextScale,
|
|
370
|
+
// translateX: -1*(mousePos.x * nextScale - mousePos.x)/nextScale,
|
|
371
|
+
// translateY: -1*(mousePos.y * nextScale - mousePos.y)/nextScale
|
|
372
|
+
translateX: newTranslation.x,
|
|
373
|
+
translateY: newTranslation.y,
|
|
374
|
+
},
|
|
375
|
+
});
|
|
376
|
+
return false;
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
onRightClick(e) {
|
|
380
|
+
e.preventDefault();
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
onMouseDown(e) {
|
|
384
|
+
if (e.button === 0) {
|
|
385
|
+
this.selectAnnotation(undefined);
|
|
386
|
+
} else if (e.button === 1) {
|
|
387
|
+
this.setMode(modes.CAMERA_MOVE);
|
|
388
|
+
} else if (e.button === 2) {
|
|
389
|
+
//Create annotation on right click
|
|
390
|
+
this.createNewAnnotation(e);
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
onAnnoMouseDown(e) {
|
|
395
|
+
if (e.button === 1) {
|
|
396
|
+
// this.collectAnnos()
|
|
397
|
+
this.setMode(modes.CAMERA_MOVE);
|
|
398
|
+
} else if (e.button === 2) {
|
|
399
|
+
//Create annotation on right click
|
|
400
|
+
this.createNewAnnotation(e);
|
|
401
|
+
} else if (e.button === 0) {
|
|
402
|
+
if (this.state.showLabelInput) {
|
|
403
|
+
const anno = this.findAnno(this.state.selectedAnnoId);
|
|
404
|
+
this.updateSelectedAnno(anno, modes.VIEW);
|
|
405
|
+
this.showSingleAnno(undefined);
|
|
406
|
+
this.showLabelInput(false);
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
onMouseUp(e) {
|
|
412
|
+
switch (e.button) {
|
|
413
|
+
case 1:
|
|
414
|
+
this.setMode(modes.VIEW);
|
|
415
|
+
break;
|
|
416
|
+
default:
|
|
417
|
+
break;
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
updateAnnoComment(comment) {
|
|
422
|
+
const anno = this.findAnno(this.state.selectedAnnoId);
|
|
423
|
+
anno.comment = comment;
|
|
424
|
+
this.handleAnnoEvent(anno, canvasActions.ANNO_COMMENT_UPDATE);
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
handleKeyAction(action) {
|
|
428
|
+
const anno = this.findAnno(this.state.selectedAnnoId);
|
|
429
|
+
const camKeyStepSize = 20 * this.state.svg.scale;
|
|
430
|
+
|
|
431
|
+
switch (action) {
|
|
432
|
+
case keyActions.EDIT_LABEL:
|
|
433
|
+
// Need to get the newest version of annotation data directly
|
|
434
|
+
// from annotation object, when editing label/ hitting enter
|
|
435
|
+
// in create mode, since annotation data in canvas are not updated
|
|
436
|
+
// to this point in time.
|
|
437
|
+
const ar = this.findAnnoRef(this.state.selectedAnnoId);
|
|
438
|
+
let myAnno = undefined;
|
|
439
|
+
if (ar !== undefined) {
|
|
440
|
+
myAnno = ar.current.myAnno.current.getResult();
|
|
441
|
+
}
|
|
442
|
+
this.editAnnoLabel(myAnno);
|
|
443
|
+
break;
|
|
444
|
+
case keyActions.DELETE_ANNO:
|
|
445
|
+
this.deleteAnnotation(anno);
|
|
446
|
+
break;
|
|
447
|
+
case keyActions.TOGGLE_ANNO_COMMENT_INPUT:
|
|
448
|
+
if (this.state.selectedAnnoId) {
|
|
449
|
+
this.setState({
|
|
450
|
+
annoCommentInputTrigger: this.state.annoCommentInputTrigger + 1,
|
|
451
|
+
});
|
|
452
|
+
}
|
|
453
|
+
break;
|
|
454
|
+
case keyActions.DELETE_ANNO_IN_CREATION:
|
|
455
|
+
this.deleteAnnoInCreationMode(anno);
|
|
456
|
+
break;
|
|
457
|
+
case keyActions.ENTER_ANNO_ADD_MODE:
|
|
751
458
|
if (anno) {
|
|
752
|
-
|
|
753
|
-
if (!myAnno) return
|
|
754
|
-
if (myAnno.id in this.tempIdMap) {
|
|
755
|
-
myAnno = { ...myAnno, id: this.tempIdMap[myAnno.id] }
|
|
756
|
-
}
|
|
757
|
-
backendAnno = annoConversion.canvasToBackendSingleAnno(myAnno, this.state.svg,
|
|
758
|
-
false, this.state.imageOffset)
|
|
759
|
-
}
|
|
760
|
-
const saveData = {
|
|
761
|
-
anno: backendAnno,
|
|
762
|
-
img: imgData,
|
|
763
|
-
action
|
|
764
|
-
}
|
|
765
|
-
if (this.props.onAnnoSaveEvent) {
|
|
766
|
-
this.props.onAnnoSaveEvent(saveData)
|
|
767
|
-
}
|
|
768
|
-
}
|
|
769
|
-
|
|
770
|
-
onAnnoLabelInputUpdate(anno) {
|
|
771
|
-
this.updateSelectedAnno(anno)
|
|
772
|
-
}
|
|
773
|
-
|
|
774
|
-
onAnnoLabelInputClose() {
|
|
775
|
-
this.svg.current.focus()
|
|
776
|
-
this.showLabelInput(false)
|
|
777
|
-
this.showSingleAnno(undefined)
|
|
778
|
-
const anno = this.findAnno(this.state.selectedAnnoId)
|
|
779
|
-
this.handleAnnoEvent(anno, canvasActions.ANNO_LABEL_UPDATE)
|
|
780
|
-
}
|
|
781
|
-
|
|
782
|
-
handleImgBarClose() {
|
|
783
|
-
this.triggerCanvasEvent(canvasActions.CANVAS_IMGBAR_CLOSE)
|
|
784
|
-
}
|
|
785
|
-
|
|
786
|
-
gotNewLabel(label) {
|
|
787
|
-
let ret = false
|
|
788
|
-
if (label.length === 0) {
|
|
789
|
-
if (this.state.imgLabelIds.length !== 0) {
|
|
790
|
-
return true
|
|
791
|
-
} else {
|
|
792
|
-
return false
|
|
793
|
-
}
|
|
794
|
-
}
|
|
795
|
-
label.forEach(e => {
|
|
796
|
-
if (!this.state.imgLabelIds.includes(e)) ret = true
|
|
797
|
-
})
|
|
798
|
-
return ret
|
|
799
|
-
}
|
|
800
|
-
|
|
801
|
-
handleImgLabelUpdate(label) {
|
|
802
|
-
if (this.gotNewLabel(label)) {
|
|
803
|
-
const imgActions = [...this.state.imgActions, canvasActions.IMG_LABEL_UPDATE]
|
|
804
|
-
console.log('gotNewLabel', label)
|
|
805
|
-
this.setState({
|
|
806
|
-
imgLabelIds: label,
|
|
807
|
-
imgLabelChanged: true,
|
|
808
|
-
imgActions: imgActions,
|
|
809
|
-
})
|
|
810
|
-
this.pushHist(this.state.annos,
|
|
811
|
-
this.state.selectedAnnoId,
|
|
812
|
-
canvasActions.IMG_LABEL_UPDATE,
|
|
813
|
-
this.state.showSingleAnno,
|
|
814
|
-
label
|
|
815
|
-
)
|
|
816
|
-
const imgData = {
|
|
817
|
-
imgLabelIds: label,
|
|
818
|
-
imgLabelChanged: true,
|
|
819
|
-
imgActions: imgActions,
|
|
820
|
-
}
|
|
821
|
-
this.handleAnnoSaveEvent(canvasActions.IMG_LABEL_UPDATE, undefined, imgData)
|
|
822
|
-
}
|
|
823
|
-
}
|
|
824
|
-
|
|
825
|
-
handleCanvasClick(e) {
|
|
826
|
-
if (this.props.uiConfig.imgBarVisible) {
|
|
827
|
-
this.setState({ imgBarVisible: true })
|
|
828
|
-
}
|
|
829
|
-
}
|
|
830
|
-
|
|
831
|
-
handleImgBarMouseEnter(e) {
|
|
832
|
-
this.setState({ imgBarVisible: false })
|
|
833
|
-
}
|
|
834
|
-
|
|
835
|
-
handleImgLabelInputClose() {
|
|
836
|
-
this.triggerCanvasEvent(canvasActions.CANVAS_LABEL_INPUT_CLOSE)
|
|
837
|
-
}
|
|
838
|
-
|
|
839
|
-
handleSvgMouseMove(e) {
|
|
840
|
-
this.mousePosAbs = mouse.getMousePositionAbs(e, this.state.svg)
|
|
841
|
-
}
|
|
842
|
-
|
|
843
|
-
handleNotification(messageObj) {
|
|
844
|
-
if (this.props.onNotification) {
|
|
845
|
-
this.props.onNotification(messageObj)
|
|
459
|
+
this.updateSelectedAnno(anno, modes.ADD);
|
|
846
460
|
}
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
461
|
+
break;
|
|
462
|
+
case keyActions.LEAVE_ANNO_ADD_MODE:
|
|
463
|
+
if (anno) {
|
|
464
|
+
this.updateSelectedAnno(anno, modes.VIEW);
|
|
465
|
+
}
|
|
466
|
+
break;
|
|
467
|
+
case keyActions.UNDO:
|
|
468
|
+
this.undo();
|
|
469
|
+
break;
|
|
470
|
+
case keyActions.REDO:
|
|
471
|
+
this.redo();
|
|
472
|
+
break;
|
|
473
|
+
case keyActions.TRAVERSE_ANNOS:
|
|
474
|
+
this.traverseAnnos();
|
|
475
|
+
break;
|
|
476
|
+
case keyActions.CAM_MOVE_LEFT:
|
|
477
|
+
this.moveCamera(camKeyStepSize, 0);
|
|
478
|
+
break;
|
|
479
|
+
case keyActions.CAM_MOVE_RIGHT:
|
|
480
|
+
this.moveCamera(-camKeyStepSize, 0);
|
|
481
|
+
break;
|
|
482
|
+
case keyActions.CAM_MOVE_UP:
|
|
483
|
+
this.moveCamera(0, camKeyStepSize);
|
|
484
|
+
break;
|
|
485
|
+
case keyActions.CAM_MOVE_DOWN:
|
|
486
|
+
this.moveCamera(0, -camKeyStepSize);
|
|
487
|
+
break;
|
|
488
|
+
case keyActions.CAM_MOVE_STOP:
|
|
489
|
+
break;
|
|
490
|
+
case keyActions.COPY_ANNOTATION:
|
|
491
|
+
this.copyAnnotation();
|
|
492
|
+
break;
|
|
493
|
+
case keyActions.PASTE_ANNOTATION:
|
|
494
|
+
this.pasteAnnotation(0);
|
|
495
|
+
break;
|
|
496
|
+
case keyActions.RECREATE_ANNO:
|
|
497
|
+
// recreate selected annotation using the anno id
|
|
498
|
+
if (this.state.selectedAnnoId)
|
|
499
|
+
this.recreateAnnotation(this.state.selectedAnnoId);
|
|
500
|
+
break;
|
|
501
|
+
default:
|
|
502
|
+
// console.warn("Unknown key action", action);
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
onKeyDown(e) {
|
|
507
|
+
e.preventDefault();
|
|
508
|
+
this.keyMapper.keyDown(e.key);
|
|
509
|
+
if (this.props.onKeyDown) {
|
|
510
|
+
this.props.onKeyDown(e);
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
onKeyUp(e) {
|
|
515
|
+
e.preventDefault();
|
|
516
|
+
this.keyMapper.keyUp(e.key);
|
|
517
|
+
if (this.props.onKeyUp) {
|
|
518
|
+
this.props.onKeyUp(e);
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
onMouseMove(e) {
|
|
523
|
+
if (this.state.mode === modes.CAMERA_MOVE) {
|
|
524
|
+
this.moveCamera(e.movementX, e.movementY);
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
onLabelInputDeleteClick(annoId) {
|
|
529
|
+
this.removeSelectedAnno();
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
/**
|
|
533
|
+
* Trigger canvas event
|
|
534
|
+
* @param {String} action Action that was performed
|
|
535
|
+
* @param {Object} data Data object of the action
|
|
536
|
+
*/
|
|
537
|
+
triggerCanvasEvent(action, data) {
|
|
538
|
+
if (this.props.onCanvasEvent) {
|
|
539
|
+
this.props.onCanvasEvent(action, data);
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
checkAndCorrectAnno(anno) {
|
|
544
|
+
// Check if annoation is within image bounds
|
|
545
|
+
const corrected = transformAnnos.correctAnnotation(
|
|
546
|
+
anno.data,
|
|
547
|
+
this.state.svg,
|
|
548
|
+
this.state.imageOffset,
|
|
549
|
+
);
|
|
550
|
+
let newAnno = { ...anno, data: corrected };
|
|
551
|
+
const area = transformAnnos.getArea(
|
|
552
|
+
corrected,
|
|
553
|
+
this.state.svg,
|
|
554
|
+
anno.type,
|
|
555
|
+
this.state.image,
|
|
556
|
+
);
|
|
557
|
+
if (area !== undefined) {
|
|
558
|
+
if (area < this.props.canvasConfig.annos.minArea) {
|
|
888
559
|
this.handleNotification({
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
560
|
+
title: "Annotation to small",
|
|
561
|
+
message:
|
|
562
|
+
"Annotation area was " +
|
|
563
|
+
Math.round(area) +
|
|
564
|
+
"px but needs to be bigger than " +
|
|
565
|
+
this.props.canvasConfig.annos.minArea +
|
|
566
|
+
" px",
|
|
567
|
+
type: notificationType.WARNING,
|
|
568
|
+
});
|
|
569
|
+
// newAnno = {...newAnno, mode: modes.DELETED}
|
|
570
|
+
newAnno = { ...newAnno, mode: modes.DELETED };
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
if (!this.checkAnnoLength(anno)) {
|
|
574
|
+
newAnno = { ...newAnno, mode: modes.DELETED };
|
|
575
|
+
}
|
|
576
|
+
return newAnno;
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
/**
|
|
580
|
+
* Handle actions that have been performed by an annotation
|
|
581
|
+
* @param {Number} anno Id of the annotation
|
|
582
|
+
* @param {String} pAction Action that was performed
|
|
583
|
+
*/
|
|
584
|
+
handleAnnoEvent(anno, pAction) {
|
|
585
|
+
// console.log("handleAnnoEvent", pAction, anno);
|
|
586
|
+
let newAnnos = undefined;
|
|
587
|
+
let actionHistoryStore = undefined;
|
|
588
|
+
|
|
589
|
+
switch (pAction) {
|
|
590
|
+
case canvasActions.ANNO_ENTER_CREATE_MODE:
|
|
591
|
+
break;
|
|
592
|
+
case canvasActions.ANNO_MARK_EXAMPLE:
|
|
593
|
+
newAnnos = this.updateSelectedAnno(anno, modes.VIEW);
|
|
594
|
+
this.pushHist(newAnnos, anno.id, pAction, this.state.showSingleAnno);
|
|
595
|
+
this.handleAnnoSaveEvent(pAction, anno);
|
|
596
|
+
break;
|
|
597
|
+
case canvasActions.ANNO_SELECTED:
|
|
598
|
+
this.selectAnnotation(anno.id);
|
|
599
|
+
// this.pushHist(
|
|
600
|
+
// this.state.annos, anno.id,
|
|
601
|
+
// pAction, this.state.showSingleAnno
|
|
602
|
+
// )
|
|
603
|
+
break;
|
|
604
|
+
case canvasActions.ANNO_START_CREATING:
|
|
605
|
+
newAnnos = this.updateSelectedAnno(anno);
|
|
606
|
+
this.pushHist(newAnnos, anno.id, pAction, this.state.showSingleAnno);
|
|
607
|
+
break;
|
|
608
|
+
case canvasActions.ANNO_CREATED:
|
|
609
|
+
actionHistoryStore = [...this.state.imgActions, pAction];
|
|
610
|
+
anno = this.stopAnnotimeMeasure(anno);
|
|
611
|
+
newAnnos = this.updateSelectedAnno(
|
|
612
|
+
{ ...anno, status: annoStatus.DATABASE },
|
|
613
|
+
modes.VIEW,
|
|
614
|
+
);
|
|
615
|
+
this.pushHist(newAnnos, anno.id, pAction, undefined);
|
|
616
|
+
this.showSingleAnno(undefined);
|
|
617
|
+
this.setState({ annoToolBarVisible: true });
|
|
618
|
+
this.handleAnnoSaveEvent(pAction, anno, {
|
|
619
|
+
imgActions: actionHistoryStore,
|
|
620
|
+
});
|
|
621
|
+
break;
|
|
622
|
+
case canvasActions.ANNO_MOVED:
|
|
623
|
+
actionHistoryStore = [...this.state.imgActions, pAction];
|
|
624
|
+
anno = this.stopAnnotimeMeasure(anno);
|
|
625
|
+
newAnnos = this.updateSelectedAnno(anno, modes.VIEW);
|
|
626
|
+
this.showSingleAnno(undefined);
|
|
627
|
+
this.pushHist(newAnnos, anno.id, pAction, undefined);
|
|
628
|
+
this.setState({ annoToolBarVisible: true });
|
|
629
|
+
this.handleAnnoSaveEvent(pAction, anno, {
|
|
630
|
+
imgActions: actionHistoryStore,
|
|
631
|
+
});
|
|
632
|
+
break;
|
|
633
|
+
case canvasActions.ANNO_ENTER_MOVE_MODE:
|
|
634
|
+
anno = this.startAnnotimeMeasure(anno);
|
|
635
|
+
this.updateSelectedAnno(anno, modes.MOVE);
|
|
636
|
+
this.showSingleAnno(anno.id);
|
|
637
|
+
this.setState({ annoToolBarVisible: false });
|
|
638
|
+
break;
|
|
639
|
+
case canvasActions.ANNO_ENTER_EDIT_MODE:
|
|
640
|
+
anno = this.startAnnotimeMeasure(anno);
|
|
641
|
+
this.updateSelectedAnno(anno, modes.EDIT);
|
|
642
|
+
// this.showSingleAnno(anno.id)
|
|
643
|
+
this.setState({ annoToolBarVisible: false });
|
|
644
|
+
break;
|
|
645
|
+
case canvasActions.ANNO_ADDED_NODE:
|
|
646
|
+
actionHistoryStore = [...this.state.imgActions, pAction];
|
|
647
|
+
newAnnos = this.updateSelectedAnno(anno, modes.VIEW);
|
|
648
|
+
this.pushHist(newAnnos, anno.id, pAction, this.state.showSingleAnno);
|
|
649
|
+
this.handleAnnoSaveEvent(pAction, anno, {
|
|
650
|
+
imgActions: actionHistoryStore,
|
|
651
|
+
});
|
|
652
|
+
break;
|
|
653
|
+
case canvasActions.ANNO_REMOVED_NODE:
|
|
654
|
+
actionHistoryStore = [...this.state.imgActions, pAction];
|
|
655
|
+
if (!this.checkAnnoLength(anno)) {
|
|
656
|
+
newAnnos = this.updateSelectedAnno(anno, modes.DELETED);
|
|
657
|
+
this.showSingleAnno(undefined);
|
|
945
658
|
} else {
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
this.
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
this.showLabelInput()
|
|
982
|
-
this.updateSelectedAnno(myAnno, modes.EDIT_LABEL)
|
|
983
|
-
}
|
|
984
|
-
}
|
|
985
|
-
unloadImage() {
|
|
986
|
-
console.log('unloadImage', this.state, this.props.imageMeta)
|
|
987
|
-
if (this.state.imageLoaded) {
|
|
988
|
-
this.setState({ imageLoaded: false })
|
|
989
|
-
}
|
|
990
|
-
this.handleAnnoSaveEvent(canvasActions.IMG_ANNO_TIME_UPDATE, undefined, undefined)
|
|
991
|
-
}
|
|
992
|
-
/**
|
|
993
|
-
* Find a annotation by id in current state
|
|
994
|
-
*
|
|
995
|
-
* @param {int} annoId - Id of the annotation to find
|
|
996
|
-
*/
|
|
997
|
-
findAnno(annoId) {
|
|
998
|
-
return this.state.annos.find(e => {
|
|
999
|
-
return e.id === annoId
|
|
1000
|
-
})
|
|
1001
|
-
}
|
|
1002
|
-
|
|
1003
|
-
findAnnoRef(annoId) {
|
|
1004
|
-
if (this.state.selectedAnnoId === undefined) return undefined
|
|
1005
|
-
return this.annoRefs.find(e => {
|
|
1006
|
-
if (e.current) {
|
|
1007
|
-
return e.current.isSelected()
|
|
1008
|
-
} else {
|
|
1009
|
-
return false
|
|
1010
|
-
}
|
|
1011
|
-
})
|
|
1012
|
-
}
|
|
1013
|
-
|
|
1014
|
-
pushHist(annos, selectedAnnoId, pAction, showSingleAnno, imgLabelIds = this.state.imgLabelIds) {
|
|
1015
|
-
this.hist.push({
|
|
1016
|
-
...this.getAnnos(annos, false),
|
|
1017
|
-
selectedAnnoId: selectedAnnoId,
|
|
1018
|
-
showSingleAnno: showSingleAnno,
|
|
1019
|
-
imgLabelIds: imgLabelIds
|
|
1020
|
-
}, pAction)
|
|
1021
|
-
console.log('hist', this.hist)
|
|
1022
|
-
}
|
|
1023
|
-
|
|
1024
|
-
undo() {
|
|
1025
|
-
this.handleNotification({
|
|
1026
|
-
title: "Redo/ Undo not supported",
|
|
1027
|
-
message: `Redo and Undo functions are currently not supported`,
|
|
1028
|
-
type: notificationType.WARNING
|
|
1029
|
-
})
|
|
1030
|
-
return
|
|
1031
|
-
//TODO: Make UNDO great again
|
|
1032
|
-
// if (!this.hist.isEmpty()){
|
|
1033
|
-
// const cState = this.hist.undo()
|
|
1034
|
-
// console.log('hist', this.hist)
|
|
1035
|
-
// this.setCanvasState(
|
|
1036
|
-
// cState.entry.annotations,
|
|
1037
|
-
// cState.entry.imgLabelIds,
|
|
1038
|
-
// cState.entry.selectedAnnoId,
|
|
1039
|
-
// cState.entry.showSingleAnno)
|
|
1040
|
-
// }
|
|
1041
|
-
}
|
|
1042
|
-
|
|
1043
|
-
redo() {
|
|
659
|
+
newAnnos = this.updateSelectedAnno(anno, modes.CREATE);
|
|
660
|
+
}
|
|
661
|
+
this.pushHist(newAnnos, anno.id, pAction, this.state.showSingleAnno);
|
|
662
|
+
if (anno.status !== annoStatus.NEW) {
|
|
663
|
+
this.handleAnnoSaveEvent(pAction, anno, {
|
|
664
|
+
imgActions: actionHistoryStore,
|
|
665
|
+
});
|
|
666
|
+
}
|
|
667
|
+
break;
|
|
668
|
+
case canvasActions.ANNO_EDITED:
|
|
669
|
+
actionHistoryStore = [...this.state.imgActions, pAction];
|
|
670
|
+
anno = this.stopAnnotimeMeasure(anno);
|
|
671
|
+
newAnnos = this.updateSelectedAnno(anno, modes.VIEW);
|
|
672
|
+
this.pushHist(newAnnos, anno.id, pAction, this.state.showSingleAnno);
|
|
673
|
+
this.setState({ annoToolBarVisible: true });
|
|
674
|
+
this.handleAnnoSaveEvent(pAction, anno, {
|
|
675
|
+
imgActions: actionHistoryStore,
|
|
676
|
+
});
|
|
677
|
+
break;
|
|
678
|
+
case canvasActions.ANNO_DELETED:
|
|
679
|
+
actionHistoryStore = [...this.state.imgActions, pAction];
|
|
680
|
+
const res = this.updateSelectedAnno(anno, modes.DELETED, true);
|
|
681
|
+
newAnnos = res.newAnnos;
|
|
682
|
+
this.selectAnnotation(undefined);
|
|
683
|
+
this.showSingleAnno(undefined);
|
|
684
|
+
this.pushHist(newAnnos, undefined, pAction, this.state.showSingleAnno);
|
|
685
|
+
this.handleAnnoSaveEvent(pAction, res.newAnno, {
|
|
686
|
+
imgActions: actionHistoryStore,
|
|
687
|
+
});
|
|
688
|
+
break;
|
|
689
|
+
case canvasActions.ANNO_COMMENT_UPDATE:
|
|
690
|
+
actionHistoryStore = [...this.state.imgActions, pAction];
|
|
691
|
+
const res_comment = this.updateSelectedAnno(anno, modes.VIEW, true);
|
|
692
|
+
newAnnos = res_comment.newAnnos;
|
|
693
|
+
this.pushHist(newAnnos, anno.id, pAction, this.state.showSingleAnno);
|
|
1044
694
|
this.handleNotification({
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
})
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
//
|
|
1058
|
-
//
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
}
|
|
1062
|
-
|
|
1063
|
-
deleteAnnotation(anno) {
|
|
1064
|
-
if (anno) {
|
|
1065
|
-
if (anno.mode === modes.CREATE) {
|
|
1066
|
-
const ar = this.findAnnoRef(this.state.selectedAnnoId)
|
|
1067
|
-
if (ar !== undefined) ar.current.myAnno.current.removeLastNode()
|
|
1068
|
-
|
|
1069
|
-
} else {
|
|
1070
|
-
this.handleAnnoEvent(anno, canvasActions.ANNO_DELETED)
|
|
1071
|
-
}
|
|
1072
|
-
}
|
|
1073
|
-
}
|
|
1074
|
-
|
|
1075
|
-
deleteAnnoInCreationMode(anno) {
|
|
1076
|
-
if (anno) {
|
|
1077
|
-
if (anno.mode === modes.CREATE) {
|
|
1078
|
-
this.handleAnnoEvent(anno, canvasActions.ANNO_DELETED)
|
|
1079
|
-
} else {
|
|
1080
|
-
}
|
|
1081
|
-
}
|
|
1082
|
-
}
|
|
1083
|
-
|
|
1084
|
-
deleteAllAnnos() {
|
|
1085
|
-
let newAnnos = []
|
|
1086
|
-
this.state.annos.forEach(e => {
|
|
1087
|
-
if ((typeof e.id) !== "string") {
|
|
1088
|
-
const anno = { ...e, status: annoStatus.DELETED }
|
|
1089
|
-
this.handleAnnoEvent(anno, canvasActions.ANNO_DELETED)
|
|
1090
|
-
}
|
|
1091
|
-
})
|
|
1092
|
-
this.selectAnnotation(undefined)
|
|
1093
|
-
this.showSingleAnno(undefined)
|
|
1094
|
-
}
|
|
1095
|
-
|
|
1096
|
-
/**
|
|
1097
|
-
* Set state of Canvas annotations and imageLabels.
|
|
1098
|
-
*
|
|
1099
|
-
* @param {list} annotations - Annotations in backend format
|
|
1100
|
-
* @param {list} imgLabelIds - IDs of the image labels
|
|
1101
|
-
* @param {object} selectedAnno - The selected annotation
|
|
1102
|
-
* @param {int} showSingleAnno - The id of the single annotation
|
|
1103
|
-
* that should be visible
|
|
1104
|
-
*/
|
|
1105
|
-
setCanvasState(annotations, imgLabelIds, selectedAnnoId, showSingleAnno) {
|
|
1106
|
-
this.updateCanvasView({ ...annotations })
|
|
1107
|
-
this.setImageLabels([...imgLabelIds])
|
|
1108
|
-
this.selectAnnotation(selectedAnnoId)
|
|
1109
|
-
this.setState({ showSingleAnno: showSingleAnno })
|
|
1110
|
-
}
|
|
1111
|
-
|
|
1112
|
-
isLocked(annoId) {
|
|
1113
|
-
if (this.props.lockedAnnos) {
|
|
1114
|
-
if (this.props.lockedAnnos.includes(annoId)) {
|
|
1115
|
-
return true
|
|
1116
|
-
}
|
|
1117
|
-
}
|
|
1118
|
-
return false
|
|
1119
|
-
}
|
|
1120
|
-
|
|
1121
|
-
selectAnnotation(annoId) {
|
|
1122
|
-
if (this.isLocked(annoId)) {
|
|
1123
|
-
this.handleNotification({
|
|
1124
|
-
title: "Annotation locked",
|
|
1125
|
-
message: `Annotation with id ${annoId} is locked and can not be edited`,
|
|
1126
|
-
type: notificationType.WARNING
|
|
1127
|
-
})
|
|
1128
|
-
return
|
|
1129
|
-
}
|
|
1130
|
-
if (annoId) {
|
|
1131
|
-
const anno = this.findAnno(annoId)
|
|
1132
|
-
this.setState({
|
|
1133
|
-
selectedAnnoId: annoId
|
|
1134
|
-
})
|
|
1135
|
-
if (anno) {
|
|
1136
|
-
if (anno.mode !== modes.CREATE) {
|
|
1137
|
-
this.setState({
|
|
1138
|
-
annoToolBarVisible: true
|
|
1139
|
-
})
|
|
1140
|
-
}
|
|
1141
|
-
}
|
|
695
|
+
title: "Saved comment",
|
|
696
|
+
message: `Saved comment: ${anno.comment}`,
|
|
697
|
+
type: notificationType.SUCCESS,
|
|
698
|
+
});
|
|
699
|
+
this.handleAnnoSaveEvent(pAction, res_comment.newAnno, {
|
|
700
|
+
imgActions: actionHistoryStore,
|
|
701
|
+
});
|
|
702
|
+
break;
|
|
703
|
+
case canvasActions.ANNO_LABEL_UPDATE:
|
|
704
|
+
actionHistoryStore = [...this.state.imgActions, pAction];
|
|
705
|
+
anno = this.stopAnnotimeMeasure(anno);
|
|
706
|
+
anno = this.checkAndCorrectAnno(anno);
|
|
707
|
+
// console.log("ANNO_LABEL_UPDATE aftercheckAndCorrect", anno);
|
|
708
|
+
// this.updateSelectedAnno(anno, anno.mode)
|
|
709
|
+
if (anno.mode === modes.DELETED) {
|
|
710
|
+
this.updateSelectedAnno(anno, modes.DELETED);
|
|
1142
711
|
} else {
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
}
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
this.
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
}
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
return
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
}
|
|
1250
|
-
|
|
1251
|
-
|
|
712
|
+
this.updateSelectedAnno(
|
|
713
|
+
{ ...anno, status: annoStatus.DATABASE },
|
|
714
|
+
modes.VIEW,
|
|
715
|
+
);
|
|
716
|
+
}
|
|
717
|
+
// if (!this.checkAnnoLength(anno)){
|
|
718
|
+
// newAnnos = this.updateSelectedAnno(anno, modes.DELETED)
|
|
719
|
+
// } else {
|
|
720
|
+
// newAnnos = this.updateSelectedAnno(anno, modes.VIEW)
|
|
721
|
+
// }
|
|
722
|
+
this.setState({ annoToolBarVisible: true });
|
|
723
|
+
if (anno.mode !== modes.DELETED) {
|
|
724
|
+
this.pushHist(newAnnos, anno.id, pAction, undefined);
|
|
725
|
+
this.handleAnnoSaveEvent(pAction, anno, {
|
|
726
|
+
imgActions: actionHistoryStore,
|
|
727
|
+
});
|
|
728
|
+
}
|
|
729
|
+
break;
|
|
730
|
+
case canvasActions.ANNO_CREATED_NODE:
|
|
731
|
+
actionHistoryStore = [...this.state.imgActions, pAction];
|
|
732
|
+
anno = this.stopAnnotimeMeasure(anno);
|
|
733
|
+
newAnnos = this.updateSelectedAnno(anno, modes.CREATE);
|
|
734
|
+
this.pushHist(newAnnos, anno.id, pAction, this.state.showSingleAnno);
|
|
735
|
+
break;
|
|
736
|
+
case canvasActions.ANNO_CREATED_FINAL_NODE:
|
|
737
|
+
actionHistoryStore = [...this.state.imgActions, pAction];
|
|
738
|
+
anno = this.stopAnnotimeMeasure(anno);
|
|
739
|
+
newAnnos = this.updateSelectedAnno(
|
|
740
|
+
{ ...anno, status: annoStatus.DATABASE },
|
|
741
|
+
modes.VIEW,
|
|
742
|
+
);
|
|
743
|
+
this.pushHist(newAnnos, anno.id, pAction, undefined);
|
|
744
|
+
this.showSingleAnno(undefined);
|
|
745
|
+
this.setState({ annoToolBarVisible: true });
|
|
746
|
+
this.handleAnnoSaveEvent(pAction, anno, {
|
|
747
|
+
imgActions: actionHistoryStore,
|
|
748
|
+
});
|
|
749
|
+
break;
|
|
750
|
+
default:
|
|
751
|
+
// console.warn("Action not handled", pAction);
|
|
752
|
+
break;
|
|
753
|
+
}
|
|
754
|
+
if (actionHistoryStore) {
|
|
755
|
+
this.setState({ imgActions: actionHistoryStore });
|
|
756
|
+
}
|
|
757
|
+
if (this.props.onAnnoEvent) {
|
|
758
|
+
this.props.onAnnoEvent(anno, newAnnos, pAction);
|
|
759
|
+
}
|
|
760
|
+
}
|
|
761
|
+
|
|
762
|
+
handleAnnoSaveEvent(action, anno, img) {
|
|
763
|
+
const imgData = {
|
|
764
|
+
...img,
|
|
765
|
+
imgId: this.props.imageMeta.id,
|
|
766
|
+
annoTime:
|
|
767
|
+
this.props.imageMeta.annoTime +
|
|
768
|
+
(performance.now() - this.state.imgLoadTimestamp) / 1000,
|
|
769
|
+
};
|
|
770
|
+
let backendAnno = undefined;
|
|
771
|
+
if (anno) {
|
|
772
|
+
let myAnno = this.addDelayedBackendUpdate(anno, action);
|
|
773
|
+
if (!myAnno) return;
|
|
774
|
+
if (myAnno.id in this.tempIdMap) {
|
|
775
|
+
myAnno = { ...myAnno, id: this.tempIdMap[myAnno.id] };
|
|
776
|
+
}
|
|
777
|
+
backendAnno = annoConversion.canvasToBackendSingleAnno(
|
|
778
|
+
myAnno,
|
|
779
|
+
this.state.svg,
|
|
780
|
+
false,
|
|
781
|
+
this.state.imageOffset,
|
|
782
|
+
);
|
|
783
|
+
}
|
|
784
|
+
const saveData = {
|
|
785
|
+
anno: backendAnno,
|
|
786
|
+
img: imgData,
|
|
787
|
+
action,
|
|
788
|
+
};
|
|
789
|
+
if (this.props.onAnnoSaveEvent) {
|
|
790
|
+
this.props.onAnnoSaveEvent(saveData);
|
|
791
|
+
}
|
|
792
|
+
}
|
|
793
|
+
|
|
794
|
+
onAnnoLabelInputUpdate(anno) {
|
|
795
|
+
this.updateSelectedAnno(anno);
|
|
796
|
+
}
|
|
797
|
+
|
|
798
|
+
onAnnoLabelInputClose() {
|
|
799
|
+
this.svg.current.focus();
|
|
800
|
+
this.showLabelInput(false);
|
|
801
|
+
this.showSingleAnno(undefined);
|
|
802
|
+
const anno = this.findAnno(this.state.selectedAnnoId);
|
|
803
|
+
this.handleAnnoEvent(anno, canvasActions.ANNO_LABEL_UPDATE);
|
|
804
|
+
}
|
|
805
|
+
|
|
806
|
+
handleImgBarClose() {
|
|
807
|
+
this.triggerCanvasEvent(canvasActions.CANVAS_IMGBAR_CLOSE);
|
|
808
|
+
}
|
|
809
|
+
|
|
810
|
+
gotNewLabel(label) {
|
|
811
|
+
let ret = false;
|
|
812
|
+
if (label.length === 0) {
|
|
813
|
+
if (this.state.imgLabelIds.length !== 0) {
|
|
814
|
+
return true;
|
|
815
|
+
} else {
|
|
816
|
+
return false;
|
|
817
|
+
}
|
|
818
|
+
}
|
|
819
|
+
label.forEach((e) => {
|
|
820
|
+
if (!this.state.imgLabelIds.includes(e)) ret = true;
|
|
821
|
+
});
|
|
822
|
+
return ret;
|
|
823
|
+
}
|
|
824
|
+
|
|
825
|
+
handleImgLabelUpdate(label) {
|
|
826
|
+
if (this.gotNewLabel(label)) {
|
|
827
|
+
const imgActions = [
|
|
828
|
+
...this.state.imgActions,
|
|
829
|
+
canvasActions.IMG_LABEL_UPDATE,
|
|
830
|
+
];
|
|
831
|
+
// console.log("gotNewLabel", label);
|
|
832
|
+
this.setState({
|
|
833
|
+
imgLabelIds: label,
|
|
834
|
+
imgLabelChanged: true,
|
|
835
|
+
imgActions: imgActions,
|
|
836
|
+
});
|
|
837
|
+
this.pushHist(
|
|
838
|
+
this.state.annos,
|
|
839
|
+
this.state.selectedAnnoId,
|
|
840
|
+
canvasActions.IMG_LABEL_UPDATE,
|
|
841
|
+
this.state.showSingleAnno,
|
|
842
|
+
label,
|
|
843
|
+
);
|
|
844
|
+
const imgData = {
|
|
845
|
+
imgLabelIds: label,
|
|
846
|
+
imgLabelChanged: true,
|
|
847
|
+
imgActions: imgActions,
|
|
848
|
+
};
|
|
849
|
+
this.handleAnnoSaveEvent(
|
|
850
|
+
canvasActions.IMG_LABEL_UPDATE,
|
|
851
|
+
undefined,
|
|
852
|
+
imgData,
|
|
853
|
+
);
|
|
854
|
+
}
|
|
855
|
+
}
|
|
856
|
+
|
|
857
|
+
handleCanvasClick(e) {
|
|
858
|
+
if (this.props.uiConfig.imgBarVisible) {
|
|
859
|
+
this.setState({ imgBarVisible: true });
|
|
860
|
+
}
|
|
861
|
+
}
|
|
862
|
+
|
|
863
|
+
handleImgBarMouseEnter(e) {
|
|
864
|
+
this.setState({ imgBarVisible: false });
|
|
865
|
+
}
|
|
866
|
+
|
|
867
|
+
handleImgLabelInputClose() {
|
|
868
|
+
this.triggerCanvasEvent(canvasActions.CANVAS_LABEL_INPUT_CLOSE);
|
|
869
|
+
}
|
|
870
|
+
|
|
871
|
+
handleSvgMouseMove(e) {
|
|
872
|
+
this.mousePosAbs = mouse.getMousePositionAbs(e, this.state.svg);
|
|
873
|
+
}
|
|
874
|
+
|
|
875
|
+
handleNotification(messageObj) {
|
|
876
|
+
if (this.props.onNotification) {
|
|
877
|
+
this.props.onNotification(messageObj);
|
|
878
|
+
}
|
|
879
|
+
}
|
|
880
|
+
|
|
881
|
+
handleHideLbl(lbl, hide) {
|
|
882
|
+
let hiddenSelected = false;
|
|
883
|
+
const newAnnos = this.state.annos.map((anno) => {
|
|
884
|
+
const newAnno = { ...anno };
|
|
885
|
+
if (anno.labelIds.includes(lbl.id)) {
|
|
886
|
+
newAnno.visible = !hide;
|
|
887
|
+
if (anno.id === this.state.selectedAnnoId) hiddenSelected = true;
|
|
888
|
+
} else if (anno.labelIds.length === 0) {
|
|
889
|
+
// no label case
|
|
890
|
+
if (lbl.id === -1) {
|
|
891
|
+
// -1 indicates no label
|
|
892
|
+
newAnno.visible = !hide;
|
|
893
|
+
if (anno.id === this.state.selectedAnnoId) hiddenSelected = true;
|
|
894
|
+
}
|
|
895
|
+
}
|
|
896
|
+
return newAnno;
|
|
897
|
+
});
|
|
898
|
+
this.setState({ annos: newAnnos });
|
|
899
|
+
if (hiddenSelected) {
|
|
900
|
+
this.selectAnnotation(undefined);
|
|
901
|
+
}
|
|
902
|
+
}
|
|
903
|
+
|
|
904
|
+
handleMarkExample(anno) {
|
|
905
|
+
const newAnno = { ...anno };
|
|
906
|
+
if (newAnno.isExample == undefined) {
|
|
907
|
+
newAnno.isExample = true;
|
|
908
|
+
} else if (newAnno.isExample) {
|
|
909
|
+
newAnno.isExample = false;
|
|
910
|
+
} else {
|
|
911
|
+
newAnno.isExample = true;
|
|
912
|
+
}
|
|
913
|
+
this.handleAnnoEvent(newAnno, canvasActions.ANNO_MARK_EXAMPLE);
|
|
914
|
+
}
|
|
915
|
+
|
|
916
|
+
/*************
|
|
917
|
+
* LOGIC *
|
|
918
|
+
**************/
|
|
919
|
+
copyAnnotation() {
|
|
920
|
+
this.clipboard = this.findAnno(this.state.selectedAnnoId);
|
|
921
|
+
this.handleNotification({
|
|
922
|
+
title: "Copyed annotation to clipboard",
|
|
923
|
+
message: "Copyed " + this.clipboard.type,
|
|
924
|
+
type: notificationType.SUCCESS,
|
|
925
|
+
});
|
|
926
|
+
}
|
|
927
|
+
|
|
928
|
+
pasteAnnotation(offset = 0) {
|
|
929
|
+
// const corrected = transform.correctAnnotation(anno.data, this.props.svg, this.props.imageOffset)
|
|
930
|
+
if (this.clipboard) {
|
|
931
|
+
// let annos = [...this.state.annos]
|
|
932
|
+
const uid = _.uniqueId("new");
|
|
933
|
+
// this.handleAnnoEvent()
|
|
934
|
+
const newData = this.clipboard.data.map((e) => {
|
|
935
|
+
return { x: e.x + offset, y: e.y + offset };
|
|
936
|
+
});
|
|
937
|
+
const newAnno = {
|
|
938
|
+
...this.clipboard,
|
|
939
|
+
id: uid,
|
|
940
|
+
annoTime: 0,
|
|
941
|
+
status: annoStatus.NEW,
|
|
942
|
+
mode: modes.VIEW,
|
|
943
|
+
data: transformAnnos.correctAnnotation(
|
|
944
|
+
newData,
|
|
945
|
+
this.state.svg,
|
|
946
|
+
this.state.imageOffset,
|
|
947
|
+
),
|
|
948
|
+
};
|
|
949
|
+
// annos.push(newAnno)
|
|
950
|
+
// this.setState({annos: annos, selectedAnnoId: uid})
|
|
951
|
+
this.handleNotification({
|
|
952
|
+
title: "Pasted annotation to canvas",
|
|
953
|
+
message: "Pasted and selected " + this.clipboard.type,
|
|
954
|
+
type: notificationType.SUCCESS,
|
|
955
|
+
});
|
|
956
|
+
this.handleAnnoEvent(newAnno, canvasActions.ANNO_CREATED);
|
|
957
|
+
// this.handleAnnoSaveEvent(canvasActions.ANNO_CREATED, newAnno)
|
|
958
|
+
}
|
|
959
|
+
}
|
|
960
|
+
|
|
961
|
+
checkAnnoLength(anno) {
|
|
962
|
+
if (anno.type === "polygon" && anno.data.length < 3) {
|
|
963
|
+
this.handleNotification({
|
|
964
|
+
title: "Invalid polygon!",
|
|
965
|
+
message: "A vaild polygon needs at least 3 points!",
|
|
966
|
+
type: notificationType.WARNING,
|
|
967
|
+
});
|
|
968
|
+
return false;
|
|
969
|
+
}
|
|
970
|
+
return true;
|
|
971
|
+
}
|
|
972
|
+
|
|
973
|
+
startAnnotimeMeasure(anno) {
|
|
974
|
+
anno.timestamp = performance.now();
|
|
975
|
+
return anno;
|
|
976
|
+
}
|
|
977
|
+
|
|
978
|
+
stopAnnotimeMeasure(anno) {
|
|
979
|
+
if (anno.timestamp === undefined) {
|
|
980
|
+
// console.warn(
|
|
981
|
+
// "No timestamp for annotime measurement. Check if you started measurement",
|
|
982
|
+
// anno,
|
|
983
|
+
// );
|
|
984
|
+
} else {
|
|
985
|
+
let now = performance.now();
|
|
986
|
+
anno.annoTime += (now - anno.timestamp) / 1000;
|
|
987
|
+
anno.timestamp = now;
|
|
988
|
+
return anno;
|
|
989
|
+
}
|
|
990
|
+
return anno;
|
|
991
|
+
}
|
|
992
|
+
|
|
993
|
+
updatePossibleLabels() {
|
|
994
|
+
if (!this.props.possibleLabels) return;
|
|
995
|
+
if (this.props.possibleLabels.length <= 0) return;
|
|
996
|
+
let lbls = this.props.possibleLabels;
|
|
997
|
+
lbls = lbls.map((e) => {
|
|
998
|
+
if (!("color" in e)) {
|
|
1252
999
|
return {
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
}
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
return
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1000
|
+
...e,
|
|
1001
|
+
color: colorlut.getColor(e.id),
|
|
1002
|
+
};
|
|
1003
|
+
} else {
|
|
1004
|
+
return { ...e };
|
|
1005
|
+
}
|
|
1006
|
+
});
|
|
1007
|
+
this.setState({
|
|
1008
|
+
possibleLabels: [...lbls],
|
|
1009
|
+
});
|
|
1010
|
+
}
|
|
1011
|
+
|
|
1012
|
+
editAnnoLabel(anno) {
|
|
1013
|
+
if (this.state.selectedAnnoId) {
|
|
1014
|
+
let myAnno;
|
|
1015
|
+
if (anno === undefined) {
|
|
1016
|
+
myAnno = this.findAnno(this.state.selectedAnnoId);
|
|
1017
|
+
} else {
|
|
1018
|
+
myAnno = { ...anno };
|
|
1019
|
+
}
|
|
1020
|
+
myAnno = this.startAnnotimeMeasure(myAnno);
|
|
1021
|
+
this.showLabelInput();
|
|
1022
|
+
this.updateSelectedAnno(myAnno, modes.EDIT_LABEL);
|
|
1023
|
+
}
|
|
1024
|
+
}
|
|
1025
|
+
unloadImage() {
|
|
1026
|
+
// console.log("unloadImage", this.state, this.props.imageMeta);
|
|
1027
|
+
if (this.state.imageLoaded) {
|
|
1028
|
+
this.setState({ imageLoaded: false });
|
|
1029
|
+
}
|
|
1030
|
+
this.handleAnnoSaveEvent(
|
|
1031
|
+
canvasActions.IMG_ANNO_TIME_UPDATE,
|
|
1032
|
+
undefined,
|
|
1033
|
+
undefined,
|
|
1034
|
+
);
|
|
1035
|
+
}
|
|
1036
|
+
/**
|
|
1037
|
+
* Find a annotation by id in current state
|
|
1038
|
+
*
|
|
1039
|
+
* @param {int} annoId - Id of the annotation to find
|
|
1040
|
+
*/
|
|
1041
|
+
findAnno(annoId) {
|
|
1042
|
+
return this.state.annos.find((e) => {
|
|
1043
|
+
return e.id === annoId;
|
|
1044
|
+
});
|
|
1045
|
+
}
|
|
1046
|
+
|
|
1047
|
+
findAnnoRef(annoId) {
|
|
1048
|
+
if (this.state.selectedAnnoId === undefined) return undefined;
|
|
1049
|
+
return this.annoRefs.find((e) => {
|
|
1050
|
+
if (e.current) {
|
|
1051
|
+
return e.current.isSelected();
|
|
1052
|
+
} else {
|
|
1053
|
+
return false;
|
|
1054
|
+
}
|
|
1055
|
+
});
|
|
1056
|
+
}
|
|
1057
|
+
|
|
1058
|
+
pushHist(
|
|
1059
|
+
annos,
|
|
1060
|
+
selectedAnnoId,
|
|
1061
|
+
pAction,
|
|
1062
|
+
showSingleAnno,
|
|
1063
|
+
imgLabelIds = this.state.imgLabelIds,
|
|
1064
|
+
) {
|
|
1065
|
+
this.hist.push(
|
|
1066
|
+
{
|
|
1067
|
+
...this.getAnnos(annos, false),
|
|
1068
|
+
selectedAnnoId: selectedAnnoId,
|
|
1069
|
+
showSingleAnno: showSingleAnno,
|
|
1070
|
+
imgLabelIds: imgLabelIds,
|
|
1071
|
+
},
|
|
1072
|
+
pAction,
|
|
1073
|
+
);
|
|
1074
|
+
// console.log("hist", this.hist);
|
|
1075
|
+
}
|
|
1076
|
+
|
|
1077
|
+
undo() {
|
|
1078
|
+
this.handleNotification({
|
|
1079
|
+
title: "Redo/ Undo not supported",
|
|
1080
|
+
message: `Redo and Undo functions are currently not supported`,
|
|
1081
|
+
type: notificationType.WARNING,
|
|
1082
|
+
});
|
|
1083
|
+
return;
|
|
1084
|
+
//TODO: Make UNDO great again
|
|
1085
|
+
// if (!this.hist.isEmpty()){
|
|
1086
|
+
// const cState = this.hist.undo()
|
|
1087
|
+
// // console.log('hist', this.hist)
|
|
1088
|
+
// this.setCanvasState(
|
|
1089
|
+
// cState.entry.annotations,
|
|
1090
|
+
// cState.entry.imgLabelIds,
|
|
1091
|
+
// cState.entry.selectedAnnoId,
|
|
1092
|
+
// cState.entry.showSingleAnno)
|
|
1093
|
+
// }
|
|
1094
|
+
}
|
|
1095
|
+
|
|
1096
|
+
redo() {
|
|
1097
|
+
this.handleNotification({
|
|
1098
|
+
title: "Redo/ Undo not supported",
|
|
1099
|
+
message: `Redo and Undo functions are currently not supported`,
|
|
1100
|
+
type: notificationType.WARNING,
|
|
1101
|
+
});
|
|
1102
|
+
return;
|
|
1103
|
+
//TODO: Make REDO great again
|
|
1104
|
+
// if (!this.hist.isEmpty()){
|
|
1105
|
+
// const cState = this.hist.redo()
|
|
1106
|
+
// // console.log('hist', this.hist)
|
|
1107
|
+
// this.setCanvasState(
|
|
1108
|
+
// cState.entry.annotations,
|
|
1109
|
+
// cState.entry.imgLabelIds,
|
|
1110
|
+
// cState.entry.selectedAnnoId,
|
|
1111
|
+
// cState.entry.showSingleAnno
|
|
1112
|
+
// )
|
|
1113
|
+
// }
|
|
1114
|
+
}
|
|
1115
|
+
|
|
1116
|
+
deleteAnnotation(anno) {
|
|
1117
|
+
if (anno) {
|
|
1118
|
+
if (anno.mode === modes.CREATE) {
|
|
1119
|
+
const ar = this.findAnnoRef(this.state.selectedAnnoId);
|
|
1120
|
+
if (ar !== undefined) ar.current.myAnno.current.removeLastNode();
|
|
1121
|
+
} else {
|
|
1122
|
+
this.handleAnnoEvent(anno, canvasActions.ANNO_DELETED);
|
|
1123
|
+
}
|
|
1124
|
+
}
|
|
1125
|
+
}
|
|
1126
|
+
|
|
1127
|
+
deleteAnnoInCreationMode(anno) {
|
|
1128
|
+
if (anno) {
|
|
1129
|
+
if (anno.mode === modes.CREATE) {
|
|
1130
|
+
this.handleAnnoEvent(anno, canvasActions.ANNO_DELETED);
|
|
1131
|
+
} else {
|
|
1132
|
+
}
|
|
1133
|
+
}
|
|
1134
|
+
}
|
|
1135
|
+
|
|
1136
|
+
deleteAllAnnos() {
|
|
1137
|
+
let newAnnos = [];
|
|
1138
|
+
this.state.annos.forEach((e) => {
|
|
1139
|
+
if (typeof e.id !== "string") {
|
|
1140
|
+
const anno = { ...e, status: annoStatus.DELETED };
|
|
1141
|
+
this.handleAnnoEvent(anno, canvasActions.ANNO_DELETED);
|
|
1142
|
+
}
|
|
1143
|
+
});
|
|
1144
|
+
this.selectAnnotation(undefined);
|
|
1145
|
+
this.showSingleAnno(undefined);
|
|
1146
|
+
}
|
|
1147
|
+
|
|
1148
|
+
/**
|
|
1149
|
+
* Set state of Canvas annotations and imageLabels.
|
|
1150
|
+
*
|
|
1151
|
+
* @param {list} annotations - Annotations in backend format
|
|
1152
|
+
* @param {list} imgLabelIds - IDs of the image labels
|
|
1153
|
+
* @param {object} selectedAnno - The selected annotation
|
|
1154
|
+
* @param {int} showSingleAnno - The id of the single annotation
|
|
1155
|
+
* that should be visible
|
|
1156
|
+
*/
|
|
1157
|
+
setCanvasState(annotations, imgLabelIds, selectedAnnoId, showSingleAnno) {
|
|
1158
|
+
this.updateCanvasView({ ...annotations });
|
|
1159
|
+
this.setImageLabels([...imgLabelIds]);
|
|
1160
|
+
this.selectAnnotation(selectedAnnoId);
|
|
1161
|
+
this.setState({ showSingleAnno: showSingleAnno });
|
|
1162
|
+
}
|
|
1163
|
+
|
|
1164
|
+
isLocked(annoId) {
|
|
1165
|
+
if (this.props.lockedAnnos) {
|
|
1166
|
+
if (this.props.lockedAnnos.includes(annoId)) {
|
|
1167
|
+
return true;
|
|
1168
|
+
}
|
|
1169
|
+
}
|
|
1170
|
+
return false;
|
|
1171
|
+
}
|
|
1172
|
+
|
|
1173
|
+
selectAnnotation(annoId) {
|
|
1174
|
+
if (this.isLocked(annoId)) {
|
|
1175
|
+
this.handleNotification({
|
|
1176
|
+
title: "Annotation locked",
|
|
1177
|
+
message: `Annotation with id ${annoId} is locked and can not be edited`,
|
|
1178
|
+
type: notificationType.WARNING,
|
|
1179
|
+
});
|
|
1180
|
+
return;
|
|
1181
|
+
}
|
|
1182
|
+
if (annoId) {
|
|
1183
|
+
const anno = this.findAnno(annoId);
|
|
1184
|
+
this.setState({
|
|
1185
|
+
selectedAnnoId: annoId,
|
|
1186
|
+
});
|
|
1187
|
+
if (anno) {
|
|
1188
|
+
if (anno.mode !== modes.CREATE) {
|
|
1189
|
+
this.setState({
|
|
1190
|
+
annoToolBarVisible: true,
|
|
1191
|
+
});
|
|
1192
|
+
}
|
|
1193
|
+
}
|
|
1194
|
+
} else {
|
|
1195
|
+
this.setState({
|
|
1196
|
+
selectedAnnoId: undefined,
|
|
1197
|
+
annoToolBarVisible: false,
|
|
1198
|
+
});
|
|
1199
|
+
if (this.state.showLabelInput) {
|
|
1200
|
+
this.onAnnoLabelInputClose();
|
|
1201
|
+
}
|
|
1202
|
+
}
|
|
1203
|
+
}
|
|
1204
|
+
|
|
1205
|
+
/**
|
|
1206
|
+
* Traverse annotations by key hit
|
|
1207
|
+
*/
|
|
1208
|
+
traverseAnnos() {
|
|
1209
|
+
if (this.state.annos.length > 0) {
|
|
1210
|
+
const myAnnos = this.state.annos.filter((e) => {
|
|
1211
|
+
return (
|
|
1212
|
+
e.status !== annoStatus.DELETED &&
|
|
1213
|
+
!this.isLocked(e.id) &&
|
|
1214
|
+
!(e.visible === false)
|
|
1215
|
+
);
|
|
1216
|
+
});
|
|
1217
|
+
if (myAnnos.length > 0) {
|
|
1218
|
+
if (!this.state.selectedAnnoId) {
|
|
1219
|
+
this.selectAnnotation(myAnnos[0].id);
|
|
1463
1220
|
} else {
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1221
|
+
let currentIdx = myAnnos.findIndex((e) => {
|
|
1222
|
+
return e.id === this.state.selectedAnnoId;
|
|
1223
|
+
});
|
|
1224
|
+
if (currentIdx + 1 < myAnnos.length) {
|
|
1225
|
+
this.selectAnnotation(myAnnos[currentIdx + 1].id);
|
|
1226
|
+
} else {
|
|
1227
|
+
this.selectAnnotation(myAnnos[0].id);
|
|
1228
|
+
}
|
|
1229
|
+
}
|
|
1230
|
+
}
|
|
1231
|
+
}
|
|
1232
|
+
}
|
|
1233
|
+
|
|
1234
|
+
getAnnos(annos = undefined, removeFrontedIds = true) {
|
|
1235
|
+
const myAnnos = annos ? annos : this.state.annos;
|
|
1236
|
+
// const backendFormat = this.getAnnoBackendFormat(removeFrontedIds, myAnnos)
|
|
1237
|
+
const backendFormat = annoConversion.canvasToBackendAnnos(
|
|
1238
|
+
myAnnos,
|
|
1239
|
+
this.state.svg,
|
|
1240
|
+
removeFrontedIds,
|
|
1241
|
+
this.state.imageOffset,
|
|
1242
|
+
);
|
|
1243
|
+
const finalData = {
|
|
1244
|
+
imgId: this.props.imageMeta.id,
|
|
1245
|
+
imgLabelIds: this.state.imgLabelIds,
|
|
1246
|
+
imgLabelChanged: this.state.imgLabelChanged,
|
|
1247
|
+
imgActions: this.state.imgActions,
|
|
1248
|
+
annotations: backendFormat,
|
|
1249
|
+
isJunk: this.state.isJunk,
|
|
1250
|
+
annoTime:
|
|
1251
|
+
this.props.imageMeta.annoTime +
|
|
1252
|
+
(performance.now() - this.state.imgLoadTimestamp) / 1000,
|
|
1253
|
+
};
|
|
1254
|
+
return finalData;
|
|
1255
|
+
}
|
|
1256
|
+
|
|
1257
|
+
/**
|
|
1258
|
+
* Reset zoom level on Canvas
|
|
1259
|
+
*/
|
|
1260
|
+
resetZoom() {
|
|
1261
|
+
this.setState({
|
|
1262
|
+
svg: {
|
|
1263
|
+
...this.state.svg,
|
|
1264
|
+
translateX: 0,
|
|
1265
|
+
translateY: 0,
|
|
1266
|
+
scale: 1.0,
|
|
1267
|
+
},
|
|
1268
|
+
});
|
|
1269
|
+
}
|
|
1270
|
+
|
|
1271
|
+
moveCamera(movementX, movementY) {
|
|
1272
|
+
let trans_x = this.state.svg.translateX + movementX / this.state.svg.scale;
|
|
1273
|
+
let trans_y = this.state.svg.translateY + movementY / this.state.svg.scale;
|
|
1274
|
+
const vXMin = this.state.svg.width * 0.25;
|
|
1275
|
+
const vXMax = this.state.svg.width * 0.75;
|
|
1276
|
+
const yXMin = this.state.svg.height * 0.25;
|
|
1277
|
+
const yXMax = this.state.svg.height * 0.75;
|
|
1278
|
+
const vLeft = wv.getViewportCoordinates({ x: 0, y: 0 }, this.state.svg);
|
|
1279
|
+
const vRight = wv.getViewportCoordinates(
|
|
1280
|
+
{ x: this.state.svg.width, y: this.state.svg.height },
|
|
1281
|
+
this.state.svg,
|
|
1282
|
+
);
|
|
1283
|
+
if (vLeft.vX >= vXMin) {
|
|
1284
|
+
trans_x = this.state.svg.translateX - 5;
|
|
1285
|
+
} else if (vRight.vX <= vXMax) {
|
|
1286
|
+
trans_x = this.state.svg.translateX + 5;
|
|
1287
|
+
}
|
|
1288
|
+
if (vLeft.vY >= yXMin) {
|
|
1289
|
+
trans_y = this.state.svg.translateY - 5;
|
|
1290
|
+
} else if (vRight.vY <= yXMax) {
|
|
1291
|
+
trans_y = this.state.svg.translateY + 5;
|
|
1292
|
+
}
|
|
1293
|
+
this.setState({
|
|
1294
|
+
svg: {
|
|
1295
|
+
...this.state.svg,
|
|
1296
|
+
translateX: trans_x,
|
|
1297
|
+
translateY: trans_y,
|
|
1298
|
+
},
|
|
1299
|
+
});
|
|
1300
|
+
}
|
|
1301
|
+
|
|
1302
|
+
setMode(mode) {
|
|
1303
|
+
if (this.state.mode !== mode) {
|
|
1304
|
+
this.setState({ mode: mode });
|
|
1305
|
+
}
|
|
1306
|
+
}
|
|
1307
|
+
|
|
1308
|
+
getMousePosition(e) {
|
|
1309
|
+
const absPos = this.getMousePositionAbs(e);
|
|
1310
|
+
return {
|
|
1311
|
+
x: absPos.x / this.state.svg.scale - this.state.svg.translateX,
|
|
1312
|
+
y: absPos.y / this.state.svg.scale - this.state.svg.translateY,
|
|
1313
|
+
};
|
|
1314
|
+
}
|
|
1315
|
+
|
|
1316
|
+
getMousePositionAbs(e) {
|
|
1317
|
+
return {
|
|
1318
|
+
x: e.pageX - this.svg.current.getBoundingClientRect().left,
|
|
1319
|
+
y: e.pageY - this.svg.current.getBoundingClientRect().top,
|
|
1320
|
+
};
|
|
1321
|
+
}
|
|
1322
|
+
|
|
1323
|
+
showLabelInput(visible = true) {
|
|
1324
|
+
this.setState({
|
|
1325
|
+
showLabelInput: visible,
|
|
1326
|
+
});
|
|
1327
|
+
if (visible) {
|
|
1328
|
+
this.showSingleAnno(this.state.selectedAnnoId);
|
|
1329
|
+
}
|
|
1330
|
+
}
|
|
1331
|
+
|
|
1332
|
+
createNewAnnotation(e) {
|
|
1333
|
+
//Do not create new Annotation if controlKey was pressed!
|
|
1334
|
+
let allowed = false;
|
|
1335
|
+
if (this.keyMapper.controlDown) return;
|
|
1336
|
+
if (this.props.selectedTool) {
|
|
1337
|
+
const maxAnnos = this.props.canvasConfig.annos.maxAnnos;
|
|
1338
|
+
if (maxAnnos) {
|
|
1339
|
+
if (this.state.annos.length < maxAnnos) {
|
|
1340
|
+
allowed = true;
|
|
1508
1341
|
} else {
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1342
|
+
// console.warn(
|
|
1343
|
+
// "Maximum number of annotations reached! MaxAnnos:",
|
|
1344
|
+
// maxAnnos,
|
|
1345
|
+
// );
|
|
1346
|
+
this.handleNotification({
|
|
1347
|
+
title: "Maximum number of annotations reached!",
|
|
1348
|
+
message: `Only ${maxAnnos} annotations per image are allowed by config`,
|
|
1349
|
+
type: notificationType.WARNING,
|
|
1350
|
+
});
|
|
1351
|
+
}
|
|
1352
|
+
} else {
|
|
1353
|
+
allowed = true;
|
|
1354
|
+
}
|
|
1355
|
+
} else {
|
|
1356
|
+
// console.warn("No annotation tool selected!");
|
|
1357
|
+
this.handleNotification({
|
|
1358
|
+
title: "No tool selected!",
|
|
1359
|
+
message: "Please select an annotation tool in the toolbar.",
|
|
1360
|
+
type: notificationType.INFO,
|
|
1361
|
+
});
|
|
1362
|
+
}
|
|
1363
|
+
if (allowed) {
|
|
1364
|
+
const mousePos = this.getMousePosition(e);
|
|
1365
|
+
// const selAnno = this.findAnno(this.state.selectedAnnoId)
|
|
1366
|
+
let newAnno = {
|
|
1367
|
+
id: this.props.nextAnnoId ? this.props.nextAnnoId : _.uniqueId("new"),
|
|
1368
|
+
type: this.props.selectedTool,
|
|
1369
|
+
data: [
|
|
1370
|
+
{
|
|
1371
|
+
x: mousePos.x,
|
|
1372
|
+
y: mousePos.y,
|
|
1373
|
+
},
|
|
1374
|
+
{
|
|
1375
|
+
x: mousePos.x,
|
|
1376
|
+
y: mousePos.y,
|
|
1377
|
+
},
|
|
1378
|
+
],
|
|
1379
|
+
mode: modes.CREATE,
|
|
1380
|
+
status: annoStatus.NEW,
|
|
1381
|
+
labelIds: this.state.prevLabel,
|
|
1382
|
+
selectedNode: 1,
|
|
1383
|
+
annoTime: 0.0,
|
|
1384
|
+
};
|
|
1385
|
+
newAnno = this.startAnnotimeMeasure(newAnno);
|
|
1386
|
+
this.setState({
|
|
1387
|
+
annos: [...this.state.annos, newAnno],
|
|
1388
|
+
selectedAnnoId: newAnno.id,
|
|
1389
|
+
showSingleAnno: newAnno.id,
|
|
1390
|
+
annoToolBarVisible: false,
|
|
1391
|
+
});
|
|
1392
|
+
if (
|
|
1393
|
+
this.props.selectedTool !== TOOLS.BBOX &&
|
|
1394
|
+
this.props.selectedTool !== TOOLS.POINT
|
|
1395
|
+
) {
|
|
1396
|
+
const merged = this.mergeSelectedAnno(newAnno);
|
|
1397
|
+
this.pushHist(
|
|
1398
|
+
merged.newAnnos,
|
|
1399
|
+
newAnno.id,
|
|
1400
|
+
canvasActions.ANNO_CREATED_NODE,
|
|
1401
|
+
newAnno.id,
|
|
1402
|
+
);
|
|
1403
|
+
}
|
|
1404
|
+
this.handleAnnoEvent(newAnno, canvasActions.ANNO_ENTER_CREATE_MODE);
|
|
1405
|
+
}
|
|
1406
|
+
}
|
|
1407
|
+
|
|
1408
|
+
/**
|
|
1409
|
+
* recreate an existing annotation in case the creation process was not finished
|
|
1410
|
+
* @param {string} id of annotation
|
|
1411
|
+
*/
|
|
1412
|
+
recreateAnnotation(annoID) {
|
|
1413
|
+
// console.log("AnnoSave -> recreateAnnotation ", annoID);
|
|
1414
|
+
|
|
1415
|
+
let annos = this.state.annos;
|
|
1416
|
+
|
|
1417
|
+
// search for id of selected anno in all annos (should normally be last item in list, but to be sure)
|
|
1418
|
+
let annoIndex;
|
|
1419
|
+
let anno;
|
|
1420
|
+
|
|
1421
|
+
for (var k in annos)
|
|
1422
|
+
if (annos[k].id == annoID) {
|
|
1423
|
+
annoIndex = k;
|
|
1424
|
+
anno = annos[k];
|
|
1425
|
+
break;
|
|
1426
|
+
}
|
|
1427
|
+
|
|
1428
|
+
// editing is only allowed on line and polygon
|
|
1429
|
+
if (!["line", "polygon"].includes(anno.type)) return; // console.log(
|
|
1430
|
+
// "Cant recreate annotation: Type " + anno.type + " is forbidden",
|
|
1431
|
+
// );
|
|
1432
|
+
|
|
1433
|
+
// remove the old annotation
|
|
1434
|
+
this.state.annos.splice(annoIndex, 1);
|
|
1435
|
+
|
|
1436
|
+
// create a new annotation based on the datapoints of the old annotation
|
|
1437
|
+
let newAnno = {
|
|
1438
|
+
id: anno.id,
|
|
1439
|
+
type: anno.type,
|
|
1440
|
+
data: anno.data,
|
|
1441
|
+
mode: modes.CREATE,
|
|
1442
|
+
status:
|
|
1443
|
+
anno.status === "database" || anno.status === "changed"
|
|
1444
|
+
? annoStatus.CHANGED
|
|
1445
|
+
: annoStatus.NEW,
|
|
1446
|
+
labelIds: anno.labelIds,
|
|
1447
|
+
selectedNode: anno.data.length - 1,
|
|
1448
|
+
annoTime: anno.annoTime,
|
|
1449
|
+
};
|
|
1450
|
+
|
|
1451
|
+
newAnno = this.startAnnotimeMeasure(newAnno);
|
|
1452
|
+
this.setState({
|
|
1453
|
+
annos: [...this.state.annos, newAnno],
|
|
1454
|
+
selectedAnnoId: newAnno.id,
|
|
1455
|
+
showSingleAnno: newAnno.id,
|
|
1456
|
+
annoToolBarVisible: false,
|
|
1457
|
+
});
|
|
1458
|
+
|
|
1459
|
+
// console.log("Annotation recreated");
|
|
1460
|
+
this.handleAnnoEvent(newAnno, canvasActions.ANNO_ENTER_CREATE_MODE);
|
|
1461
|
+
}
|
|
1462
|
+
|
|
1463
|
+
putSelectedOnTop(prevState) {
|
|
1464
|
+
// The selected annotation need to be rendered as last one in
|
|
1465
|
+
// oder to be above all other annotations.
|
|
1466
|
+
if (this.state.selectedAnnoId) {
|
|
1467
|
+
if (prevState.selectedAnnoId !== this.state.selectedAnnoId) {
|
|
1468
|
+
const annos = this.state.annos.filter((el) => {
|
|
1469
|
+
return el.id !== this.state.selectedAnnoId;
|
|
1470
|
+
});
|
|
1471
|
+
const lastAnno = this.state.annos.find((el) => {
|
|
1472
|
+
return el.id === this.state.selectedAnnoId;
|
|
1473
|
+
});
|
|
1474
|
+
annos.push(lastAnno);
|
|
1516
1475
|
this.setState({
|
|
1517
|
-
|
|
1518
|
-
})
|
|
1519
|
-
|
|
1520
|
-
|
|
1476
|
+
annos: [...annos],
|
|
1477
|
+
});
|
|
1478
|
+
}
|
|
1479
|
+
}
|
|
1480
|
+
}
|
|
1481
|
+
|
|
1482
|
+
getLabel(lblId) {
|
|
1483
|
+
return this.state.possibleLabels.find((e) => {
|
|
1484
|
+
return e.id === lblId;
|
|
1485
|
+
});
|
|
1486
|
+
}
|
|
1487
|
+
|
|
1488
|
+
getAnnoColor() {
|
|
1489
|
+
if (this.state.selectedAnnoId) {
|
|
1490
|
+
const anno = this.findAnno(this.state.selectedAnnoId);
|
|
1491
|
+
if (anno) {
|
|
1492
|
+
if (anno.labelIds.length > 0) {
|
|
1493
|
+
return this.getLabel(anno.labelIds[0]).color;
|
|
1494
|
+
}
|
|
1495
|
+
}
|
|
1496
|
+
}
|
|
1497
|
+
return colorlut.getDefaultColor();
|
|
1498
|
+
}
|
|
1499
|
+
|
|
1500
|
+
updateDelayedBackendUpdates(tempId, dbId) {
|
|
1501
|
+
// console.log(
|
|
1502
|
+
// "updateDelayedBackendUpdates ",
|
|
1503
|
+
// tempId,
|
|
1504
|
+
// dbId,
|
|
1505
|
+
// this.delayedBackendUpdates,
|
|
1506
|
+
// );
|
|
1507
|
+
if (tempId !== dbId) this.tempIdMap[tempId] = dbId;
|
|
1508
|
+
if (tempId in this.delayedBackendUpdates) {
|
|
1509
|
+
if (this.delayedBackendUpdates[tempId] !== null) {
|
|
1510
|
+
const { anno, action } = this.delayedBackendUpdates[tempId];
|
|
1511
|
+
const myAnno = {
|
|
1512
|
+
...anno,
|
|
1513
|
+
status:
|
|
1514
|
+
anno.status === annoStatus.NEW ? annoStatus.CHANGED : anno.status,
|
|
1515
|
+
};
|
|
1516
|
+
delete this.delayedBackendUpdates[tempId];
|
|
1517
|
+
// console.log("PerformDelayedBackendUpdate", action, myAnno);
|
|
1518
|
+
this.handleAnnoSaveEvent(action, myAnno);
|
|
1519
|
+
} else {
|
|
1520
|
+
delete this.delayedBackendUpdates[tempId];
|
|
1521
|
+
}
|
|
1522
|
+
}
|
|
1523
|
+
}
|
|
1524
|
+
|
|
1525
|
+
addDelayedBackendUpdate(anno, action) {
|
|
1526
|
+
// take care of tempIds while receiving a dbId from backend.
|
|
1527
|
+
// handling tempIds is only required if instant anno backend update is
|
|
1528
|
+
// used.
|
|
1529
|
+
if (this.props.onAnnoSaveEvent) {
|
|
1530
|
+
if (typeof anno.id === "string") {
|
|
1531
|
+
if (!(anno.id in this.tempIdMap)) {
|
|
1532
|
+
let myAnno = undefined;
|
|
1533
|
+
if (anno.id in this.delayedBackendUpdates) {
|
|
1534
|
+
this.delayedBackendUpdates[anno.id] = { anno, action };
|
|
1535
|
+
} else {
|
|
1536
|
+
this.delayedBackendUpdates[anno.id] = null;
|
|
1537
|
+
myAnno = anno;
|
|
1538
|
+
}
|
|
1539
|
+
// console.log(
|
|
1540
|
+
// "addDelayedBackendUpdate ",
|
|
1541
|
+
// myAnno,
|
|
1542
|
+
// action,
|
|
1543
|
+
// anno,
|
|
1544
|
+
// this.delayedBackendUpdates,
|
|
1545
|
+
// );
|
|
1546
|
+
return myAnno;
|
|
1547
|
+
}
|
|
1548
|
+
}
|
|
1549
|
+
// else if ((typeof anno.id) === "string"){
|
|
1550
|
+
// this.delayedBackendUpdates[anno.id] = {anno, action}
|
|
1551
|
+
// }
|
|
1552
|
+
} else {
|
|
1553
|
+
console.error(
|
|
1554
|
+
"onAnnoSaveEvent needs to be provided in order to use SIA Canvas in a correct war!",
|
|
1555
|
+
);
|
|
1556
|
+
}
|
|
1557
|
+
return anno;
|
|
1558
|
+
}
|
|
1559
|
+
|
|
1560
|
+
updateAnnoBySaveResponse(res) {
|
|
1561
|
+
if (!res) return;
|
|
1562
|
+
if (res.tempId !== res.dbId) {
|
|
1563
|
+
//TODO: Replace tempId with dbId in undo/redo hist
|
|
1564
|
+
const anno = this.findAnno(res.tempId);
|
|
1565
|
+
if (!anno) return;
|
|
1566
|
+
// anno.id = res.dbId
|
|
1567
|
+
// anno.status = annoStatus.DATABASE
|
|
1568
|
+
//TODO: Should not update if the anno is currently in edit or move mode
|
|
1569
|
+
// this.updateAnno(anno)
|
|
1570
|
+
// if (this.state.selectedAnnoId === res.tempId) this.setState({selectedAnnoId: res.dbId})
|
|
1571
|
+
this.updateDelayedBackendUpdates(res.tempId, res.dbId);
|
|
1572
|
+
}
|
|
1573
|
+
// else {
|
|
1574
|
+
// const anno = this.findAnno(res.dbId)
|
|
1575
|
+
// if (!anno) return
|
|
1576
|
+
// anno.status = res.newStatus
|
|
1577
|
+
// // this.updateAnno(anno)
|
|
1578
|
+
// }
|
|
1579
|
+
}
|
|
1580
|
+
|
|
1581
|
+
/**
|
|
1582
|
+
* Update selected anno and override mode if desired
|
|
1583
|
+
*
|
|
1584
|
+
* @param {object} anno - The new annotation that becomes the selected anno
|
|
1585
|
+
* @param {string} mode - The new mode for the selected anno
|
|
1586
|
+
* @returns The new anno that was set as selectedAnno in state and
|
|
1587
|
+
* the new annos list that was set in state
|
|
1588
|
+
*/
|
|
1589
|
+
updateSelectedAnno(anno, mode = undefined, returnNewAnno = false) {
|
|
1590
|
+
if (!anno) return;
|
|
1591
|
+
const { newAnnos, newAnno } = this.mergeSelectedAnno(anno, mode);
|
|
1592
|
+
this.setState({
|
|
1593
|
+
annos: newAnnos,
|
|
1594
|
+
selectedAnnoId: anno.id,
|
|
1595
|
+
prevLabel: anno.labelIds,
|
|
1596
|
+
});
|
|
1597
|
+
if (returnNewAnno) {
|
|
1598
|
+
return { newAnnos, newAnno };
|
|
1599
|
+
} else {
|
|
1600
|
+
return newAnnos;
|
|
1601
|
+
}
|
|
1602
|
+
}
|
|
1603
|
+
|
|
1604
|
+
updateAnno(anno, mode = undefined, returnNewAnno = false) {
|
|
1605
|
+
if (!anno) return;
|
|
1606
|
+
const { newAnnos, newAnno } = this.mergeSelectedAnno(anno, mode);
|
|
1607
|
+
this.setState({
|
|
1608
|
+
annos: newAnnos,
|
|
1609
|
+
});
|
|
1610
|
+
if (returnNewAnno) {
|
|
1611
|
+
return { newAnnos, newAnno };
|
|
1612
|
+
} else {
|
|
1613
|
+
return newAnnos;
|
|
1614
|
+
}
|
|
1615
|
+
}
|
|
1616
|
+
|
|
1617
|
+
mergeSelectedAnno(anno, mode = undefined) {
|
|
1618
|
+
let filtered = this.state.annos.filter((el) => {
|
|
1619
|
+
return el.id !== anno.id;
|
|
1620
|
+
});
|
|
1621
|
+
filtered = filtered.map((e) => {
|
|
1622
|
+
return { ...e, mode: modes.VIEW };
|
|
1623
|
+
});
|
|
1624
|
+
let newAnno;
|
|
1625
|
+
if (mode) {
|
|
1626
|
+
newAnno = { ...anno, mode: mode };
|
|
1627
|
+
if (mode === modes.DELETED) {
|
|
1628
|
+
if (anno.status !== annoStatus.NEW) {
|
|
1629
|
+
newAnno = {
|
|
1630
|
+
...newAnno,
|
|
1631
|
+
status: annoStatus.DELETED,
|
|
1632
|
+
};
|
|
1521
1633
|
} else {
|
|
1522
|
-
|
|
1523
|
-
}
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1634
|
+
newAnno = null;
|
|
1635
|
+
}
|
|
1636
|
+
} else {
|
|
1637
|
+
newAnno = {
|
|
1638
|
+
...newAnno,
|
|
1639
|
+
status:
|
|
1640
|
+
anno.status !== annoStatus.NEW
|
|
1641
|
+
? annoStatus.CHANGED
|
|
1642
|
+
: annoStatus.NEW,
|
|
1643
|
+
};
|
|
1644
|
+
}
|
|
1645
|
+
} else {
|
|
1646
|
+
newAnno = { ...anno };
|
|
1647
|
+
}
|
|
1648
|
+
if (newAnno !== null) {
|
|
1649
|
+
filtered.push(newAnno);
|
|
1650
|
+
}
|
|
1651
|
+
const newAnnos = [...filtered];
|
|
1652
|
+
return { newAnnos, newAnno };
|
|
1653
|
+
}
|
|
1654
|
+
|
|
1655
|
+
showSingleAnno(annoId) {
|
|
1656
|
+
if (this.state.showSingleAnno !== annoId) {
|
|
1657
|
+
this.setState({ showSingleAnno: annoId });
|
|
1658
|
+
}
|
|
1659
|
+
}
|
|
1660
|
+
|
|
1661
|
+
updateImageSize() {
|
|
1662
|
+
var container = this.props.container.current.getBoundingClientRect();
|
|
1663
|
+
var clientHeight = document.documentElement.clientHeight;
|
|
1664
|
+
var canvasTop;
|
|
1665
|
+
var canvasLeft;
|
|
1666
|
+
var maxImgHeight;
|
|
1667
|
+
var maxImgWidth;
|
|
1668
|
+
const layoutOffset = this.props.uiConfig.layoutOffset;
|
|
1669
|
+
if (layoutOffset) {
|
|
1670
|
+
canvasTop = container.top + layoutOffset.top;
|
|
1671
|
+
canvasLeft = container.left + layoutOffset.left;
|
|
1672
|
+
maxImgHeight =
|
|
1673
|
+
clientHeight - container.top - layoutOffset.bottom - layoutOffset.top;
|
|
1674
|
+
maxImgWidth = container.right - canvasLeft - layoutOffset.right;
|
|
1675
|
+
} else {
|
|
1676
|
+
canvasTop = container.top;
|
|
1677
|
+
canvasLeft = container.left;
|
|
1678
|
+
maxImgHeight = clientHeight - container.top;
|
|
1679
|
+
maxImgWidth = container.right - canvasLeft;
|
|
1680
|
+
}
|
|
1681
|
+
var ratio = this.img.current.naturalWidth / this.img.current.naturalHeight;
|
|
1682
|
+
var imgWidth = "100%";
|
|
1683
|
+
var imgHeight = "100%";
|
|
1684
|
+
if (maxImgHeight * ratio > maxImgWidth) {
|
|
1685
|
+
imgWidth = maxImgWidth;
|
|
1686
|
+
imgHeight = maxImgWidth / ratio;
|
|
1687
|
+
} else {
|
|
1688
|
+
imgWidth = maxImgHeight * ratio;
|
|
1689
|
+
imgHeight = maxImgHeight;
|
|
1690
|
+
}
|
|
1691
|
+
var svg;
|
|
1692
|
+
const imgOffset = { x: 0, y: 0 };
|
|
1693
|
+
if (this.props.uiConfig.maxCanvas) {
|
|
1694
|
+
imgOffset.x = (maxImgWidth - imgWidth) / 2;
|
|
1695
|
+
imgOffset.y = (maxImgHeight - imgHeight) / 2;
|
|
1696
|
+
// console.log(`imgOffset: `, imgOffset);
|
|
1697
|
+
svg = {
|
|
1698
|
+
...this.state.svg,
|
|
1699
|
+
width: maxImgWidth,
|
|
1700
|
+
height: maxImgHeight,
|
|
1701
|
+
left: canvasLeft,
|
|
1702
|
+
top: canvasTop,
|
|
1703
|
+
};
|
|
1704
|
+
} else {
|
|
1705
|
+
if (this.props.uiConfig.centerCanvasInContainer) {
|
|
1706
|
+
const resSpaceX = maxImgWidth - imgWidth;
|
|
1707
|
+
if (resSpaceX > 2) {
|
|
1708
|
+
canvasLeft = canvasLeft + resSpaceX / 2;
|
|
1709
|
+
}
|
|
1710
|
+
const resSpaceY = maxImgHeight - imgHeight;
|
|
1711
|
+
if (resSpaceY > 2) {
|
|
1712
|
+
canvasTop = canvasTop + resSpaceY / 2;
|
|
1713
|
+
}
|
|
1714
|
+
}
|
|
1715
|
+
svg = {
|
|
1716
|
+
...this.state.svg,
|
|
1717
|
+
width: imgWidth,
|
|
1718
|
+
height: imgHeight,
|
|
1719
|
+
left: canvasLeft,
|
|
1720
|
+
top: canvasTop,
|
|
1721
|
+
};
|
|
1722
|
+
}
|
|
1723
|
+
this.setState({
|
|
1724
|
+
svg,
|
|
1725
|
+
image: {
|
|
1726
|
+
width: this.img.current.naturalWidth,
|
|
1727
|
+
height: this.img.current.naturalHeight,
|
|
1728
|
+
},
|
|
1729
|
+
imageOffset: imgOffset,
|
|
1730
|
+
});
|
|
1731
|
+
this.svgUpdate(svg);
|
|
1732
|
+
return {
|
|
1733
|
+
imgWidth: this.props.fixedImageSize
|
|
1734
|
+
? this.props.fixedImageSize
|
|
1735
|
+
: imgWidth,
|
|
1736
|
+
imgHeight: this.props.fixedImageSize
|
|
1737
|
+
? this.props.fixedImageSize
|
|
1738
|
+
: imgHeight,
|
|
1739
|
+
imgOffset,
|
|
1740
|
+
};
|
|
1741
|
+
}
|
|
1742
|
+
|
|
1743
|
+
svgUpdate(svg) {
|
|
1744
|
+
this.triggerCanvasEvent(canvasActions.CANVAS_SVG_UPDATE, svg);
|
|
1745
|
+
}
|
|
1746
|
+
|
|
1747
|
+
setImageLabels(labelIds) {
|
|
1748
|
+
if (labelIds !== this.state.imgLabelIds) {
|
|
1749
|
+
this.setState({
|
|
1750
|
+
imgLabelIds: labelIds,
|
|
1751
|
+
});
|
|
1752
|
+
}
|
|
1753
|
+
}
|
|
1754
|
+
|
|
1755
|
+
updateCanvasView(annotations) {
|
|
1756
|
+
var annos = [];
|
|
1757
|
+
//Annotation data should be present and a pixel accurate value
|
|
1758
|
+
//for svg should be calculated
|
|
1759
|
+
if (annotations) {
|
|
1760
|
+
const imgSize = this.updateImageSize();
|
|
1761
|
+
this.setState({
|
|
1762
|
+
annos: [
|
|
1763
|
+
...annoConversion.backendAnnosToCanvas(
|
|
1764
|
+
annotations,
|
|
1765
|
+
{ width: imgSize.imgWidth, height: imgSize.imgHeight },
|
|
1766
|
+
imgSize.imgOffset,
|
|
1767
|
+
),
|
|
1768
|
+
],
|
|
1769
|
+
});
|
|
1770
|
+
}
|
|
1771
|
+
}
|
|
1772
|
+
|
|
1773
|
+
renderAnnotations() {
|
|
1774
|
+
// Do not render annotations while moving the camera!
|
|
1775
|
+
if (this.state.mode !== modes.CAMERA_MOVE) {
|
|
1776
|
+
this.annoRefs = [];
|
|
1777
|
+
const annos = this.state.annos.map((el) => {
|
|
1778
|
+
this.annoRefs.push(React.createRef());
|
|
1779
|
+
return (
|
|
1780
|
+
<Annotation
|
|
1781
|
+
type={el.type}
|
|
1782
|
+
data={el}
|
|
1783
|
+
key={el.id}
|
|
1784
|
+
svg={{ ...this.state.svg }}
|
|
1785
|
+
imageOffset={this.state.imageOffset}
|
|
1786
|
+
ref={this.annoRefs[this.annoRefs.length - 1]}
|
|
1787
|
+
onMouseDown={(e) => this.onAnnoMouseDown(e)}
|
|
1788
|
+
onAction={(anno, pAction) => this.handleAnnoEvent(anno, pAction)}
|
|
1789
|
+
selectedAnno={this.state.selectedAnnoId}
|
|
1790
|
+
// onModeChange={(anno) => this.onAnnoModeChange(anno)}
|
|
1791
|
+
showSingleAnno={this.state.showSingleAnno}
|
|
1792
|
+
uiConfig={this.props.uiConfig}
|
|
1793
|
+
allowedActions={this.props.canvasConfig.annos.actions}
|
|
1794
|
+
possibleLabels={this.state.possibleLabels}
|
|
1795
|
+
image={this.state.image}
|
|
1796
|
+
canvasConfig={this.props.canvasConfig}
|
|
1797
|
+
onNotification={(messageObj) => this.handleNotification(messageObj)}
|
|
1798
|
+
defaultLabel={this.props.defaultLabel}
|
|
1799
|
+
/>
|
|
1800
|
+
);
|
|
1801
|
+
});
|
|
1802
|
+
return <g>{annos}</g>;
|
|
1803
|
+
} else {
|
|
1804
|
+
return null;
|
|
1805
|
+
}
|
|
1806
|
+
}
|
|
1807
|
+
|
|
1808
|
+
renderImgLabelInput() {
|
|
1809
|
+
if (!this.props.imageMeta) return null;
|
|
1810
|
+
return (
|
|
1811
|
+
<Prompt
|
|
1812
|
+
onClick={() => this.handleImgLabelInputClose()}
|
|
1813
|
+
active={this.props.uiConfig.imgLabelInputVisible}
|
|
1814
|
+
header={<div>Add label for the whole image</div>}
|
|
1815
|
+
content={
|
|
1816
|
+
<div>
|
|
1817
|
+
<LabelInput
|
|
1818
|
+
// multilabels={true}
|
|
1819
|
+
multilabels={this.props.canvasConfig.img.multilabels}
|
|
1820
|
+
// relatedId={this.props.annos.image.id}
|
|
1821
|
+
visible={true}
|
|
1822
|
+
onLabelUpdate={(label) => this.handleImgLabelUpdate(label)}
|
|
1823
|
+
possibleLabelsProp={this.state.possibleLabels}
|
|
1824
|
+
initLabelIds={this.state.imgLabelIds}
|
|
1825
|
+
relatedId={this.props.imageMeta.id}
|
|
1826
|
+
defaultLabel={this.props.defaultLabel}
|
|
1827
|
+
// onLabelConfirmed = {label => this.handleImgLabelUpdate(label)}
|
|
1828
|
+
// disabled={!this.props.allowedActions.label}
|
|
1829
|
+
// renderPopup
|
|
1830
|
+
/>
|
|
1831
|
+
<Button
|
|
1832
|
+
basic
|
|
1833
|
+
color="green"
|
|
1834
|
+
inverted
|
|
1835
|
+
onClick={() => this.handleImgLabelInputClose()}
|
|
1836
|
+
>
|
|
1837
|
+
<Icon name="check"></Icon>
|
|
1838
|
+
OK
|
|
1839
|
+
</Button>
|
|
1840
|
+
</div>
|
|
1841
|
+
}
|
|
1842
|
+
/>
|
|
1843
|
+
);
|
|
1844
|
+
}
|
|
1845
|
+
|
|
1846
|
+
renderAnnoToolBar(selectedAnno) {
|
|
1847
|
+
let visible = this.state.annoToolBarVisible;
|
|
1848
|
+
if (this.state.mode === modes.CAMERA_MOVE) visible = false;
|
|
1849
|
+
return (
|
|
1850
|
+
<AnnoToolBar
|
|
1851
|
+
visible={visible}
|
|
1852
|
+
selectedAnno={selectedAnno}
|
|
1853
|
+
svg={this.state.svg}
|
|
1854
|
+
onClick={() => this.editAnnoLabel()}
|
|
1855
|
+
color={this.getAnnoColor()}
|
|
1856
|
+
/>
|
|
1857
|
+
);
|
|
1858
|
+
}
|
|
1859
|
+
|
|
1860
|
+
renderAnnoLabelInpput(selectedAnno) {
|
|
1861
|
+
let visible = this.state.showLabelInput;
|
|
1862
|
+
if (this.state.mode === modes.CAMERA_MOVE) visible = false;
|
|
1863
|
+
return (
|
|
1864
|
+
<AnnoLabelInput
|
|
1865
|
+
svg={this.state.svg}
|
|
1866
|
+
// svgRef={this.svg}
|
|
1867
|
+
onClose={() => this.onAnnoLabelInputClose()}
|
|
1868
|
+
onDeleteClick={(annoId) => this.onLabelInputDeleteClick(annoId)}
|
|
1869
|
+
selectedAnno={selectedAnno}
|
|
1870
|
+
visible={visible}
|
|
1871
|
+
onLabelUpdate={(anno) => this.onAnnoLabelInputUpdate(anno)}
|
|
1872
|
+
possibleLabels={this.state.possibleLabels}
|
|
1873
|
+
allowedActions={this.props.canvasConfig.annos.actions}
|
|
1874
|
+
multilabels={this.props.canvasConfig.annos.multilabels}
|
|
1875
|
+
mousePos={this.mousePosAbs}
|
|
1876
|
+
defaultLabel={this.props.defaultLabel}
|
|
1877
|
+
/>
|
|
1878
|
+
);
|
|
1879
|
+
}
|
|
1880
|
+
|
|
1881
|
+
render() {
|
|
1882
|
+
const selectedAnno = this.findAnno(this.state.selectedAnnoId);
|
|
1883
|
+
return (
|
|
1884
|
+
<div ref={this.container}>
|
|
1885
|
+
<div
|
|
1886
|
+
height={this.state.svg.height}
|
|
1887
|
+
style={{
|
|
1888
|
+
position: this.props.isStaticPosition ? "static" : "fixed",
|
|
1889
|
+
top: this.state.svg.top,
|
|
1890
|
+
left: this.state.svg.left,
|
|
1891
|
+
}}
|
|
1892
|
+
>
|
|
1893
|
+
{/* {this.renderAnnoCommentInput(selectedAnno)} */}
|
|
1894
|
+
{this.renderImgLabelInput()}
|
|
1895
|
+
<ImgBar
|
|
1896
|
+
container={this.container}
|
|
1897
|
+
visible={this.state.imgBarVisible}
|
|
1898
|
+
possibleLabels={this.state.possibleLabels}
|
|
1899
|
+
annos={this.props.annos}
|
|
1900
|
+
annoTaskId={this.props.annoTaskId}
|
|
1901
|
+
svg={this.state.svg}
|
|
1902
|
+
imageMeta={this.props.imageMeta}
|
|
1903
|
+
onClose={() => this.handleImgBarClose()}
|
|
1904
|
+
imgLabelIds={this.state.imgLabelIds}
|
|
1905
|
+
// onLabelUpdate={label => this.handleImgLabelUpdate(label)}
|
|
1906
|
+
// imgLabelIds={this.state.imgLabelIds}
|
|
1907
|
+
// multilabels={this.props.canvasConfig.img.multilabels}
|
|
1908
|
+
// allowedActions={this.props.canvasConfig.img.actions}
|
|
1909
|
+
onMouseEnter={(e) => this.handleImgBarMouseEnter(e)}
|
|
1910
|
+
/>
|
|
1911
|
+
|
|
1912
|
+
<Dimmer active={!this.state.imageLoaded || this.props.blocked}>
|
|
1913
|
+
{(!this.state.imageLoaded || this.props.blocked) && (
|
|
1914
|
+
<Loader>Loading</Loader>
|
|
1915
|
+
)}
|
|
1916
|
+
</Dimmer>
|
|
1917
|
+
<Dimmer active={this.state.isJunk}>
|
|
1918
|
+
{this.state.isJunk && (
|
|
1919
|
+
<Header
|
|
1920
|
+
as="h2"
|
|
1921
|
+
icon
|
|
1922
|
+
inverted
|
|
1923
|
+
style={{ background: "rgba(0,0,0,0)" }}
|
|
1924
|
+
>
|
|
1925
|
+
<Icon name="ban" />
|
|
1926
|
+
Marked as Junk
|
|
1927
|
+
</Header>
|
|
1928
|
+
)}
|
|
1929
|
+
</Dimmer>
|
|
1930
|
+
|
|
1931
|
+
{this.renderAnnoToolBar(selectedAnno)}
|
|
1932
|
+
{/* <div style={{position: 'fixed', top: this.props.container.top, left: this.props.container.left}}> */}
|
|
1933
|
+
{this.renderAnnoLabelInpput(selectedAnno)}
|
|
1934
|
+
<InfoBoxes
|
|
1935
|
+
container={this.props.container}
|
|
1936
|
+
layoutUpdate={this.props.layoutUpdate}
|
|
1937
|
+
annos={this.state.annos}
|
|
1938
|
+
selectedAnno={selectedAnno}
|
|
1939
|
+
possibleLabels={this.state.possibleLabels}
|
|
1940
|
+
allowedToMarkExample={this.props.canvasConfig.allowedToMarkExample}
|
|
1941
|
+
uiConfig={this.props.uiConfig}
|
|
1942
|
+
imgLoadCount={this.state.imgLoadCount}
|
|
1943
|
+
onCommentUpdate={(comment) => this.updateAnnoComment(comment)}
|
|
1944
|
+
onUiConfigUpdate={(e) =>
|
|
1945
|
+
this.triggerCanvasEvent(canvasActions.CANVAS_UI_CONFIG_UPDATE, e)
|
|
1548
1946
|
}
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
return { newAnnos, newAnno }
|
|
1557
|
-
}
|
|
1558
|
-
|
|
1559
|
-
showSingleAnno(annoId) {
|
|
1560
|
-
if (this.state.showSingleAnno !== annoId) {
|
|
1561
|
-
this.setState({ showSingleAnno: annoId })
|
|
1562
|
-
}
|
|
1563
|
-
}
|
|
1564
|
-
|
|
1565
|
-
updateImageSize() {
|
|
1566
|
-
|
|
1567
|
-
var container = this.props.container.current.getBoundingClientRect()
|
|
1568
|
-
var clientHeight = document.documentElement.clientHeight
|
|
1569
|
-
var canvasTop
|
|
1570
|
-
var canvasLeft
|
|
1571
|
-
var maxImgHeight
|
|
1572
|
-
var maxImgWidth
|
|
1573
|
-
const layoutOffset = this.props.uiConfig.layoutOffset
|
|
1574
|
-
if (layoutOffset) {
|
|
1575
|
-
canvasTop = container.top + layoutOffset.top
|
|
1576
|
-
canvasLeft = container.left + layoutOffset.left
|
|
1577
|
-
maxImgHeight = clientHeight - container.top - layoutOffset.bottom - layoutOffset.top
|
|
1578
|
-
maxImgWidth = container.right - canvasLeft - layoutOffset.right
|
|
1579
|
-
} else {
|
|
1580
|
-
canvasTop = container.top
|
|
1581
|
-
canvasLeft = container.left
|
|
1582
|
-
maxImgHeight = clientHeight - container.top
|
|
1583
|
-
maxImgWidth = container.right - canvasLeft
|
|
1584
|
-
}
|
|
1585
|
-
var ratio = this.img.current.naturalWidth / this.img.current.naturalHeight
|
|
1586
|
-
var imgWidth = "100%"
|
|
1587
|
-
var imgHeight = "100%"
|
|
1588
|
-
if (maxImgHeight * ratio > maxImgWidth) {
|
|
1589
|
-
imgWidth = maxImgWidth
|
|
1590
|
-
imgHeight = maxImgWidth / ratio
|
|
1591
|
-
} else {
|
|
1592
|
-
imgWidth = maxImgHeight * ratio
|
|
1593
|
-
imgHeight = maxImgHeight
|
|
1594
|
-
}
|
|
1595
|
-
var svg
|
|
1596
|
-
const imgOffset = { x: 0, y: 0 }
|
|
1597
|
-
if (this.props.uiConfig.maxCanvas) {
|
|
1598
|
-
imgOffset.x = (maxImgWidth - imgWidth) / 2
|
|
1599
|
-
imgOffset.y = (maxImgHeight - imgHeight) / 2
|
|
1600
|
-
console.log(`imgOffset: `, imgOffset)
|
|
1601
|
-
svg = {
|
|
1602
|
-
...this.state.svg, width: maxImgWidth, height: maxImgHeight,
|
|
1603
|
-
left: canvasLeft, top: canvasTop
|
|
1947
|
+
onHideLbl={(lbl, hide) => this.handleHideLbl(lbl, hide)}
|
|
1948
|
+
onMarkExample={(anno) => this.handleMarkExample(anno)}
|
|
1949
|
+
commentInputTrigger={this.state.annoCommentInputTrigger}
|
|
1950
|
+
onGetAnnoExample={(exampleArgs) =>
|
|
1951
|
+
this.props.onGetAnnoExample
|
|
1952
|
+
? this.props.onGetAnnoExample(exampleArgs)
|
|
1953
|
+
: {}
|
|
1604
1954
|
}
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
canvasTop = canvasTop + resSpaceY / 2
|
|
1614
|
-
}
|
|
1955
|
+
exampleImg={this.props.exampleImg}
|
|
1956
|
+
/>
|
|
1957
|
+
<svg
|
|
1958
|
+
ref={this.svg}
|
|
1959
|
+
width={
|
|
1960
|
+
this.props.fixedImageSize
|
|
1961
|
+
? this.props.fixedImageSize
|
|
1962
|
+
: this.state.svg.width
|
|
1615
1963
|
}
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1964
|
+
height={
|
|
1965
|
+
this.props.fixedImageSize
|
|
1966
|
+
? this.props.fixedImageSize
|
|
1967
|
+
: this.state.svg.height
|
|
1619
1968
|
}
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
defaultLabel={this.props.defaultLabel}
|
|
1679
|
-
/>
|
|
1680
|
-
})
|
|
1681
|
-
return <g>{annos}</g>
|
|
1682
|
-
} else {
|
|
1683
|
-
return null
|
|
1684
|
-
}
|
|
1685
|
-
|
|
1686
|
-
}
|
|
1687
|
-
|
|
1688
|
-
renderImgLabelInput() {
|
|
1689
|
-
if (!this.props.imageMeta) return null
|
|
1690
|
-
return <Prompt
|
|
1691
|
-
onClick={() => this.handleImgLabelInputClose()}
|
|
1692
|
-
active={this.props.uiConfig.imgLabelInputVisible}
|
|
1693
|
-
header={<div>
|
|
1694
|
-
Add label for the whole image
|
|
1695
|
-
</div>}
|
|
1696
|
-
content={<div>
|
|
1697
|
-
<LabelInput
|
|
1698
|
-
// multilabels={true}
|
|
1699
|
-
multilabels={this.props.canvasConfig.img.multilabels}
|
|
1700
|
-
// relatedId={this.props.annos.image.id}
|
|
1701
|
-
visible={true}
|
|
1702
|
-
onLabelUpdate={label => this.handleImgLabelUpdate(label)}
|
|
1703
|
-
possibleLabelsProp={this.state.possibleLabels}
|
|
1704
|
-
initLabelIds={this.state.imgLabelIds}
|
|
1705
|
-
relatedId={this.props.imageMeta.id}
|
|
1706
|
-
defaultLabel={this.props.defaultLabel}
|
|
1707
|
-
// onLabelConfirmed = {label => this.handleImgLabelUpdate(label)}
|
|
1708
|
-
// disabled={!this.props.allowedActions.label}
|
|
1709
|
-
// renderPopup
|
|
1710
|
-
/>
|
|
1711
|
-
<Button basic color="green" inverted
|
|
1712
|
-
onClick={() => this.handleImgLabelInputClose()}
|
|
1713
|
-
>
|
|
1714
|
-
<Icon name='check'></Icon>
|
|
1715
|
-
OK
|
|
1716
|
-
</Button>
|
|
1717
|
-
</div>}
|
|
1718
|
-
/>
|
|
1719
|
-
}
|
|
1720
|
-
|
|
1721
|
-
renderAnnoToolBar(selectedAnno) {
|
|
1722
|
-
let visible = this.state.annoToolBarVisible
|
|
1723
|
-
if (this.state.mode === modes.CAMERA_MOVE) visible = false
|
|
1724
|
-
return <AnnoToolBar visible={visible}
|
|
1725
|
-
selectedAnno={selectedAnno}
|
|
1726
|
-
svg={this.state.svg}
|
|
1727
|
-
onClick={() => this.editAnnoLabel()}
|
|
1728
|
-
color={this.getAnnoColor()}
|
|
1729
|
-
/>
|
|
1730
|
-
}
|
|
1731
|
-
|
|
1732
|
-
renderAnnoLabelInpput(selectedAnno) {
|
|
1733
|
-
let visible = this.state.showLabelInput
|
|
1734
|
-
if (this.state.mode === modes.CAMERA_MOVE) visible = false
|
|
1735
|
-
return <AnnoLabelInput svg={this.state.svg}
|
|
1736
|
-
// svgRef={this.svg}
|
|
1737
|
-
onClose={() => this.onAnnoLabelInputClose()}
|
|
1738
|
-
onDeleteClick={annoId => this.onLabelInputDeleteClick(annoId)}
|
|
1739
|
-
selectedAnno={selectedAnno}
|
|
1740
|
-
visible={visible}
|
|
1741
|
-
onLabelUpdate={anno => this.onAnnoLabelInputUpdate(anno)}
|
|
1742
|
-
possibleLabels={this.state.possibleLabels}
|
|
1743
|
-
allowedActions={this.props.canvasConfig.annos.actions}
|
|
1744
|
-
multilabels={this.props.canvasConfig.annos.multilabels}
|
|
1745
|
-
mousePos={this.mousePosAbs}
|
|
1746
|
-
defaultLabel={this.props.defaultLabel}
|
|
1747
|
-
/>
|
|
1748
|
-
}
|
|
1749
|
-
|
|
1750
|
-
render() {
|
|
1751
|
-
const selectedAnno = this.findAnno(this.state.selectedAnnoId)
|
|
1752
|
-
return (
|
|
1753
|
-
<div ref={this.container} >
|
|
1754
|
-
<div height={this.state.svg.height}
|
|
1755
|
-
style={{ position: 'fixed', top: this.state.svg.top, left: this.state.svg.left }}
|
|
1756
|
-
>
|
|
1757
|
-
{/* {this.renderAnnoCommentInput(selectedAnno)} */}
|
|
1758
|
-
{this.renderImgLabelInput()}
|
|
1759
|
-
<ImgBar container={this.container}
|
|
1760
|
-
visible={this.state.imgBarVisible}
|
|
1761
|
-
possibleLabels={this.state.possibleLabels}
|
|
1762
|
-
annos={this.props.annos}
|
|
1763
|
-
annoTaskId={this.props.annoTaskId}
|
|
1764
|
-
svg={this.state.svg}
|
|
1765
|
-
imageMeta={this.props.imageMeta}
|
|
1766
|
-
onClose={() => this.handleImgBarClose()}
|
|
1767
|
-
imgLabelIds={this.state.imgLabelIds}
|
|
1768
|
-
// onLabelUpdate={label => this.handleImgLabelUpdate(label)}
|
|
1769
|
-
// imgLabelIds={this.state.imgLabelIds}
|
|
1770
|
-
// multilabels={this.props.canvasConfig.img.multilabels}
|
|
1771
|
-
// allowedActions={this.props.canvasConfig.img.actions}
|
|
1772
|
-
onMouseEnter={e => this.handleImgBarMouseEnter(e)}
|
|
1773
|
-
/>
|
|
1774
|
-
<Dimmer active={!this.state.imageLoaded || this.props.blocked}><Loader>Loading</Loader></Dimmer>
|
|
1775
|
-
<Dimmer active={this.state.isJunk}>
|
|
1776
|
-
<Header as='h2' icon inverted style={{ background: 'rgba(0,0,0,0)' }}>
|
|
1777
|
-
<Icon name='ban' />
|
|
1778
|
-
Marked as Junk
|
|
1779
|
-
</Header>
|
|
1780
|
-
</Dimmer>
|
|
1781
|
-
{this.renderAnnoToolBar(selectedAnno)}
|
|
1782
|
-
{/* <div style={{position: 'fixed', top: this.props.container.top, left: this.props.container.left}}> */}
|
|
1783
|
-
{this.renderAnnoLabelInpput(selectedAnno)}
|
|
1784
|
-
<InfoBoxes container={this.props.container}
|
|
1785
|
-
layoutUpdate={this.props.layoutUpdate}
|
|
1786
|
-
annos={this.state.annos}
|
|
1787
|
-
selectedAnno={selectedAnno}
|
|
1788
|
-
possibleLabels={this.state.possibleLabels}
|
|
1789
|
-
allowedToMarkExample={this.props.canvasConfig.allowedToMarkExample}
|
|
1790
|
-
uiConfig={this.props.uiConfig}
|
|
1791
|
-
imgLoadCount={this.state.imgLoadCount}
|
|
1792
|
-
onCommentUpdate={comment => this.updateAnnoComment(comment)}
|
|
1793
|
-
onUiConfigUpdate={e => this.triggerCanvasEvent(canvasActions.CANVAS_UI_CONFIG_UPDATE, e)}
|
|
1794
|
-
onHideLbl={(lbl, hide) => this.handleHideLbl(lbl, hide)}
|
|
1795
|
-
onMarkExample={anno => this.handleMarkExample(anno)}
|
|
1796
|
-
commentInputTrigger={this.state.annoCommentInputTrigger}
|
|
1797
|
-
onGetAnnoExample={(exampleArgs) => this.props.onGetAnnoExample ? this.props.onGetAnnoExample(exampleArgs) : {}}
|
|
1798
|
-
exampleImg={this.props.exampleImg}
|
|
1799
|
-
/>
|
|
1800
|
-
<svg ref={this.svg} width={this.state.svg.width}
|
|
1801
|
-
height={this.state.svg.height}
|
|
1802
|
-
onKeyDown={e => this.onKeyDown(e)}
|
|
1803
|
-
onKeyUp={e => this.onKeyUp(e)}
|
|
1804
|
-
onClick={e => this.handleCanvasClick(e)}
|
|
1805
|
-
onMouseMove={e => this.handleSvgMouseMove(e)}
|
|
1806
|
-
tabIndex="0"
|
|
1807
|
-
>
|
|
1808
|
-
<g
|
|
1809
|
-
transform={`scale(${this.state.svg.scale}) translate(${this.state.svg.translateX}, ${this.state.svg.translateY})`}
|
|
1810
|
-
onMouseOver={() => { this.onMouseOver() }}
|
|
1811
|
-
onMouseLeave={() => { this.onMouseLeave() }}
|
|
1812
|
-
// onMouseEnter={() => this.svg.current.focus()}
|
|
1813
|
-
onMouseUp={(e) => { this.onMouseUp(e) }}
|
|
1814
|
-
onWheel={(e) => this.onWheel(e)}
|
|
1815
|
-
onMouseMove={(e) => { this.onMouseMove(e) }}
|
|
1816
|
-
>
|
|
1817
|
-
<image
|
|
1818
|
-
onContextMenu={(e) => this.onRightClick(e)}
|
|
1819
|
-
onMouseDown={(e) => this.onMouseDown(e)}
|
|
1820
|
-
href={this.props.imageBlob}
|
|
1821
|
-
width={this.state.svg.width}
|
|
1822
|
-
height={this.state.svg.height}
|
|
1823
|
-
/>
|
|
1824
|
-
{this.renderAnnotations()}
|
|
1825
|
-
</g>
|
|
1826
|
-
</svg>
|
|
1827
|
-
<img
|
|
1828
|
-
alt='sia' style={{ display: 'none' }} ref={this.img}
|
|
1829
|
-
onLoad={() => { this.onImageLoad() }} src={this.state.imageBlob}
|
|
1830
|
-
width="100%" height="100%"
|
|
1831
|
-
/>
|
|
1832
|
-
</div>
|
|
1833
|
-
{/* Placeholder for Layout*/}
|
|
1834
|
-
<div style={{ minHeight: this.state.svg.height }}></div>
|
|
1835
|
-
</div>)
|
|
1836
|
-
}
|
|
1969
|
+
onKeyDown={(e) => this.onKeyDown(e)}
|
|
1970
|
+
onKeyUp={(e) => this.onKeyUp(e)}
|
|
1971
|
+
onClick={(e) => this.handleCanvasClick(e)}
|
|
1972
|
+
onMouseMove={(e) => this.handleSvgMouseMove(e)}
|
|
1973
|
+
tabIndex="0"
|
|
1974
|
+
>
|
|
1975
|
+
<g
|
|
1976
|
+
transform={`scale(${this.state.svg.scale}) translate(${this.state.svg.translateX}, ${this.state.svg.translateY})`}
|
|
1977
|
+
onMouseOver={() => {
|
|
1978
|
+
this.onMouseOver();
|
|
1979
|
+
}}
|
|
1980
|
+
onMouseLeave={() => {
|
|
1981
|
+
this.onMouseLeave();
|
|
1982
|
+
}}
|
|
1983
|
+
// onMouseEnter={() => this.svg.current.focus()}
|
|
1984
|
+
onMouseUp={(e) => {
|
|
1985
|
+
this.onMouseUp(e);
|
|
1986
|
+
}}
|
|
1987
|
+
onWheel={(e) => this.onWheel(e)}
|
|
1988
|
+
onMouseMove={(e) => {
|
|
1989
|
+
this.onMouseMove(e);
|
|
1990
|
+
}}
|
|
1991
|
+
>
|
|
1992
|
+
<image
|
|
1993
|
+
onContextMenu={(e) => this.onRightClick(e)}
|
|
1994
|
+
onMouseDown={(e) => this.onMouseDown(e)}
|
|
1995
|
+
href={this.props.imageBlob}
|
|
1996
|
+
width={
|
|
1997
|
+
this.props.fixedImageSize
|
|
1998
|
+
? this.props.fixedImageSize
|
|
1999
|
+
: this.state.svg.width
|
|
2000
|
+
}
|
|
2001
|
+
height={
|
|
2002
|
+
this.props.fixedImageSize
|
|
2003
|
+
? this.props.fixedImageSize
|
|
2004
|
+
: this.state.svg.height
|
|
2005
|
+
}
|
|
2006
|
+
/>
|
|
2007
|
+
{this.renderAnnotations()}
|
|
2008
|
+
</g>
|
|
2009
|
+
</svg>
|
|
2010
|
+
<img
|
|
2011
|
+
alt="sia"
|
|
2012
|
+
style={{ display: "none" }}
|
|
2013
|
+
ref={this.img}
|
|
2014
|
+
onLoad={() => {
|
|
2015
|
+
this.onImageLoad();
|
|
2016
|
+
}}
|
|
2017
|
+
src={this.state.imageBlob}
|
|
2018
|
+
width="100%"
|
|
2019
|
+
height="100%"
|
|
2020
|
+
/>
|
|
2021
|
+
</div>
|
|
2022
|
+
{/* Placeholder for Layout*/}
|
|
2023
|
+
<div style={{ minHeight: this.state.svg.height }}></div>
|
|
2024
|
+
</div>
|
|
2025
|
+
);
|
|
2026
|
+
}
|
|
1837
2027
|
}
|
|
1838
2028
|
|
|
1839
|
-
export default Canvas
|
|
2029
|
+
export default Canvas;
|