lost-sia 2.0.1-alpha8 → 3.0.0
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/README.md +4 -0
- package/dist/Annotation/logic/Annotation.d.ts +17 -0
- package/dist/Annotation/logic/Annotation.js +1 -0
- package/dist/Annotation/ui/AnnotationComponent.d.ts +24 -0
- package/dist/Annotation/ui/AnnotationComponent.js +1 -0
- package/dist/Annotation/ui/atoms/AnnoBar.d.ts +15 -0
- package/dist/Annotation/ui/atoms/AnnoBar.js +1 -0
- package/dist/Annotation/ui/atoms/DaviIcon.d.ts +9 -0
- package/dist/Annotation/ui/atoms/DaviIcon.js +19 -0
- package/dist/Annotation/ui/atoms/Edge.d.ts +17 -0
- package/dist/Annotation/ui/atoms/Edge.js +1 -0
- package/dist/Annotation/ui/atoms/Node.d.ts +17 -0
- package/dist/Annotation/ui/atoms/Node.js +1 -0
- package/dist/Annotation/ui/atoms/PolygonArea.d.ts +16 -0
- package/dist/Annotation/ui/atoms/PolygonArea.js +1 -0
- package/dist/Annotation/ui/tools/BBox.d.ts +21 -0
- package/dist/Annotation/ui/tools/BBox.js +1 -0
- package/dist/Annotation/ui/tools/Line.d.ts +21 -0
- package/dist/Annotation/ui/tools/Line.js +1 -0
- package/dist/Annotation/ui/tools/Point.d.ts +16 -0
- package/dist/Annotation/ui/tools/Point.js +1 -0
- package/dist/Annotation/ui/tools/Polygon.d.ts +23 -0
- package/dist/Annotation/ui/tools/Polygon.js +1 -0
- package/dist/Canvas/Canvas.d.ts +31 -0
- package/dist/Canvas/Canvas.js +1 -0
- package/dist/Canvas/LabelInput.d.ts +11 -0
- package/dist/Canvas/LabelInput.js +1 -0
- package/dist/IconButton.d.ts +25 -0
- package/dist/IconButton.js +1 -0
- package/dist/Sia.d.ts +33 -0
- package/dist/Sia.js +1 -0
- package/dist/Toolbar/Toolbar.d.ts +21 -0
- package/dist/Toolbar/Toolbar.js +1 -0
- package/dist/Toolbar/ToolbarItems/AccessibilityTools.d.ts +7 -0
- package/dist/Toolbar/ToolbarItems/AccessibilityTools.js +1 -0
- package/dist/Toolbar/ToolbarItems/AnnoToolSelector.d.ts +11 -0
- package/dist/Toolbar/ToolbarItems/AnnoToolSelector.js +1 -0
- package/dist/Toolbar/ToolbarItems/ImageToolItems/ImageLabelInput.d.ts +11 -0
- package/dist/Toolbar/ToolbarItems/ImageToolItems/ImageLabelInput.js +1 -0
- package/dist/Toolbar/ToolbarItems/ImageToolItems/TagLabel.d.ts +11 -0
- package/dist/Toolbar/ToolbarItems/ImageToolItems/TagLabel.js +1 -0
- package/dist/Toolbar/ToolbarItems/ImageTools.d.ts +13 -0
- package/dist/Toolbar/ToolbarItems/ImageTools.js +1 -0
- package/dist/Toolbar/ToolbarItems/Instructions.d.ts +2 -0
- package/dist/Toolbar/ToolbarItems/Instructions.js +1 -0
- package/dist/Toolbar/ToolbarItems/InstructionsModal.d.ts +6 -0
- package/dist/Toolbar/ToolbarItems/InstructionsModal.js +1 -0
- package/dist/assets/SIA-BV1tYu3P.css +1 -0
- package/dist/assets/brand-icons-Cu_C0hZ4.svg +1008 -0
- package/dist/assets/brand-icons-F3SPCeH1.woff +0 -0
- package/dist/assets/brand-icons-XL9sxUpA.woff2 +0 -0
- package/dist/assets/brand-icons-sqJ2Pg7a.eot +0 -0
- package/dist/assets/brand-icons-ubhWoxly.ttf +0 -0
- package/dist/assets/flags-DOLqOU7Y.png +0 -0
- package/dist/assets/icons-BOCtAERH.woff +0 -0
- package/dist/assets/icons-CHzK1VD9.eot +0 -0
- package/dist/assets/icons-D29ZQHHw.ttf +0 -0
- package/dist/assets/icons-Du6TOHnR.woff2 +0 -0
- package/dist/assets/icons-RwhydX30.svg +1518 -0
- package/dist/assets/node_modules/semantic-ui-css/semantic.min-Bvulf91l.css +346 -0
- package/dist/assets/outline-icons-BfdLr8tr.svg +366 -0
- package/dist/assets/outline-icons-DD8jm0uy.ttf +0 -0
- package/dist/assets/outline-icons-DInHoiqI.woff2 +0 -0
- package/dist/assets/outline-icons-LX8adJ4n.eot +0 -0
- package/dist/assets/outline-icons-aQ88nltS.woff +0 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +1 -0
- package/dist/models/AnnotationMode.d.ts +11 -0
- package/dist/models/AnnotationMode.js +1 -0
- package/dist/models/AnnotationStatus.d.ts +8 -0
- package/dist/models/AnnotationStatus.js +1 -0
- package/dist/models/AnnotationTool.d.ts +7 -0
- package/dist/models/AnnotationTool.js +1 -0
- package/dist/models/CanvasAction.d.ts +28 -0
- package/dist/models/CanvasAction.js +1 -0
- package/dist/models/Direction.d.ts +7 -0
- package/dist/models/Direction.js +1 -0
- package/dist/models/EditorModes.d.ts +11 -0
- package/dist/models/EditorModes.js +1 -0
- package/dist/models/KeyAction.d.ts +22 -0
- package/dist/models/KeyAction.js +1 -0
- package/dist/models/NotificationType.d.ts +7 -0
- package/dist/models/NotificationType.js +1 -0
- package/dist/models/index.d.ts +6 -0
- package/dist/models/index.js +1 -0
- package/dist/stories/AnnotationTools.stories.d.ts +40 -0
- package/dist/stories/Canvas/Canvas.stories.d.ts +50 -0
- package/dist/stories/Canvas/CanvasOffset.d.ts +13 -0
- package/dist/stories/Canvas/CanvasWithOffset.stories.d.ts +36 -0
- package/dist/stories/FilterDropdown.stories.d.ts +19 -0
- package/dist/stories/MinimalSia.stories.d.ts +66 -0
- package/dist/stories/SIA/DemoWrapper.d.ts +8 -0
- package/dist/stories/SIA/DemoWrapper.stories.d.ts +27 -0
- package/dist/stories/SIA/SIA.stories.d.ts +72 -0
- package/dist/stories/Toolbar/ImageTools/TagLabel.stories.d.ts +21 -0
- package/dist/stories/Toolbar/Instructions.stories.d.ts +11 -0
- package/dist/stories/Toolbar/Toolbar.stories.d.ts +37 -0
- package/dist/stories/exampleData/exampleAnnotations.d.ts +8 -0
- package/dist/stories/exampleData/exampleExternalAnnotations.d.ts +8 -0
- package/dist/stories/exampleData/exampleImage.d.ts +2 -0
- package/dist/stories/exampleData/exampleLabels.d.ts +6 -0
- package/dist/types.d.ts +57 -0
- package/dist/types.js +1 -0
- package/dist/utils/KeyMapper.d.ts +9 -0
- package/dist/utils/KeyMapper.js +1 -0
- package/dist/utils/TimeUtils.d.ts +4 -0
- package/dist/utils/TimeUtils.js +1 -0
- package/dist/utils/color.d.ts +2 -0
- package/dist/utils/color.js +1 -0
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/index.js +1 -0
- package/dist/utils/mouse.d.ts +6 -0
- package/dist/utils/mouse.js +1 -0
- package/dist/utils/siaIcons.js +12 -0
- package/dist/utils/transform.d.ts +28 -0
- package/dist/utils/transform.js +1 -0
- package/dist/utils/uiConfig.js +1 -0
- package/dist/utils/windowViewport.d.ts +22 -0
- package/dist/utils/windowViewport.js +1 -0
- package/package.json +19 -16
- package/src/AnnoExampleViewer.jsx +18 -18
- package/src/Annotation/logic/Annotation.ts +24 -26
- package/src/Annotation/ui/AnnotationComponent.tsx +115 -86
- package/src/Annotation/ui/atoms/AnnoBar.tsx +51 -53
- package/src/Annotation/ui/atoms/DaviIcon.tsx +12 -22
- package/src/Annotation/ui/atoms/Edge.tsx +25 -22
- package/src/Annotation/ui/atoms/Node.tsx +56 -50
- package/src/Annotation/ui/atoms/PolygonArea.tsx +30 -35
- package/src/Annotation/ui/tools/BBox.tsx +136 -150
- package/src/Annotation/ui/tools/Line.tsx +94 -91
- package/src/Annotation/ui/tools/Point.tsx +19 -17
- package/src/Annotation/ui/tools/Polygon.tsx +126 -95
- package/src/Canvas/Canvas.tsx +748 -594
- package/src/Canvas/LabelInput.tsx +68 -45
- package/src/IconButton.tsx +119 -0
- package/src/InfoBoxes/AnnoDetails.jsx +53 -53
- package/src/InfoBoxes/AnnoStats.jsx +41 -41
- package/src/InfoBoxes/InfoBox.jsx +16 -16
- package/src/InfoBoxes/InfoBoxArea.jsx +32 -34
- package/src/InfoBoxes/LabelInfo.jsx +30 -30
- package/src/SIASettingButton.jsx +25 -25
- package/src/Sia.tsx +484 -0
- package/src/Toolbar/Toolbar.tsx +38 -31
- package/src/Toolbar/ToolbarItems/AccessibilityTools.tsx +26 -46
- package/src/Toolbar/ToolbarItems/AnnoToolSelector.tsx +53 -46
- package/src/Toolbar/ToolbarItems/ImageToolItems/ImageLabelInput.tsx +127 -0
- package/src/Toolbar/ToolbarItems/ImageToolItems/TagLabel.tsx +29 -28
- package/src/Toolbar/ToolbarItems/ImageTools.tsx +43 -40
- package/src/Toolbar/ToolbarItems/Instructions.tsx +47 -50
- package/src/Toolbar/ToolbarItems/InstructionsModal.tsx +8 -8
- package/src/index.ts +9 -13
- package/src/models/{AnnotationMode.tsx → AnnotationMode.ts} +1 -1
- package/src/models/{AnnotationStatus.tsx → AnnotationStatus.ts} +1 -1
- package/src/models/{AnnotationTool.tsx → AnnotationTool.ts} +1 -1
- package/src/models/{CanvasAction.tsx → CanvasAction.ts} +1 -1
- package/src/models/{Direction.tsx → Direction.ts} +1 -1
- package/src/models/{EditorModes.tsx → EditorModes.ts} +1 -1
- package/src/models/{KeyAction.tsx → KeyAction.ts} +3 -1
- package/src/models/NotificationType.ts +8 -0
- package/src/models/index.ts +6 -7
- package/src/siaDummyData.js +71 -71
- package/src/stories/AnnotationTools.mdx +27 -0
- package/src/stories/AnnotationTools.stories.tsx +104 -0
- package/src/stories/Canvas/Canvas.stories.tsx +59 -113
- package/src/stories/Canvas/CanvasOffset.tsx +54 -38
- package/src/stories/Canvas/CanvasWithOffset.stories.tsx +42 -113
- package/src/stories/FilterDropdown.stories.ts +13 -11
- package/src/stories/MinimalSIA.mdx +20 -0
- package/src/stories/MinimalSia.stories.tsx +90 -0
- package/src/stories/SIA/DemoWrapper.stories.tsx +71 -0
- package/src/stories/SIA/DemoWrapper.tsx +55 -0
- package/src/stories/SIA/SIA.stories.tsx +79 -45
- package/src/stories/Toolbar/ImageTools/TagLabel.stories.tsx +11 -12
- package/src/stories/Toolbar/Instructions.stories.tsx +11 -11
- package/src/stories/Toolbar/Toolbar.stories.tsx +32 -47
- package/src/stories/Welcome.mdx +5 -0
- package/src/stories/development/CoordinateSystems.mdx +25 -0
- package/src/stories/exampleData/exampleAnnotations.ts +65 -0
- package/src/stories/exampleData/exampleExternalAnnotations.ts +115 -0
- package/src/stories/{siaDummyData2.ts → exampleData/exampleImage.ts} +3 -264
- package/src/stories/exampleData/exampleLabels.ts +146 -0
- package/src/stories/main.scss +6 -0
- package/src/styles/style.scss +1 -26
- package/src/types.ts +67 -0
- package/src/utils/KeyMapper.ts +76 -74
- package/src/utils/TimeUtils.ts +11 -0
- package/src/utils/color.ts +25 -25
- package/src/utils/hist.js +22 -22
- package/src/utils/index.ts +2 -3
- package/src/utils/mouse.ts +45 -0
- package/src/utils/siaIcons.jsx +5 -7
- package/src/utils/transform.ts +186 -0
- package/src/utils/uiConfig.js +19 -22
- package/src/utils/windowViewport.ts +34 -0
- package/src/AnnoLabelInput.jsx +0 -109
- package/src/AnnoToolBar.jsx +0 -153
- package/src/Annotation/AnnoBar.jsx +0 -154
- package/src/Annotation/Annotation.jsx +0 -395
- package/src/Annotation/Annotation.scss +0 -47
- package/src/Annotation/BBox.jsx +0 -299
- package/src/Annotation/Edge.jsx +0 -92
- package/src/Annotation/InfSelectionArea.jsx +0 -72
- package/src/Annotation/Line.jsx +0 -68
- package/src/Annotation/Node.jsx +0 -282
- package/src/Annotation/Point.jsx +0 -200
- package/src/Annotation/Polygon.jsx +0 -404
- package/src/Annotation/logic/AnnotationUtils.ts +0 -30
- package/src/Canvas.jsx +0 -2194
- package/src/ImgBar.jsx +0 -131
- package/src/LabelInput.jsx +0 -238
- package/src/Prompt.jsx +0 -45
- package/src/SIAFilterButton.jsx +0 -186
- package/src/Sia.jsx +0 -478
- package/src/Sia2.tsx +0 -392
- package/src/SiaPopup.jsx +0 -15
- package/src/ToolBar.jsx +0 -463
- package/src/Toolbar/NavigationButtons.tsx +0 -21
- package/src/Toolbar/ToolbarItem.jsx +0 -30
- package/src/Toolbar/ToolbarItems/ImageToolItems/ImageLabel.tsx +0 -62
- package/src/Toolbar.css +0 -13
- package/src/ToolbarItem.jsx +0 -31
- package/src/filterTools.js +0 -5
- package/src/models/AllowedTools.tsx +0 -9
- package/src/models/AnnotationSettings.tsx +0 -9
- package/src/models/ExternalAnnotation.ts +0 -15
- package/src/models/Label.tsx +0 -8
- package/src/models/UiConfig.tsx +0 -6
- package/src/stories/Button.jsx +0 -54
- package/src/stories/Button.stories.js +0 -48
- package/src/stories/Header.jsx +0 -69
- package/src/stories/Header.stories.js +0 -28
- package/src/stories/Page.jsx +0 -87
- package/src/stories/Page.stories.js +0 -28
- package/src/stories/SIA2/DemoWrapper.stories.tsx +0 -167
- package/src/stories/SIA2/DemoWrapper.tsx +0 -54
- package/src/stories/SIA2/Sia2.stories.tsx +0 -62
- package/src/stories/Toolbar/ImageTools/ImageLabel.stories.tsx +0 -32
- package/src/stories/assets/accessibility.png +0 -0
- package/src/stories/assets/accessibility.svg +0 -5
- 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 +0 -15
- package/src/stories/assets/docs.png +0 -0
- package/src/stories/assets/figma-plugin.png +0 -0
- package/src/stories/assets/github.svg +0 -3
- 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 +0 -12
- package/src/stories/assets/youtube.svg +0 -4
- package/src/stories/button.css +0 -30
- package/src/stories/header.css +0 -32
- package/src/stories/lost.js +0 -54
- package/src/stories/page.css +0 -69
- package/src/stories/siaDummyData.js +0 -263
- package/src/stories/store.js +0 -18
- package/src/test.js +0 -7
- package/src/types/annoStatus.js +0 -4
- package/src/types/canvasActions.js +0 -58
- package/src/types/cursorstyles.js +0 -3
- package/src/types/modes.js +0 -9
- package/src/types/notificationType.js +0 -11
- package/src/types/toolbarEvents.js +0 -35
- package/src/types/tools.js +0 -17
- package/src/types.tsx +0 -11
- package/src/utils/annoConversion.js +0 -145
- package/src/utils/annoConversion2.ts +0 -145
- package/src/utils/colorlut.js +0 -68
- package/src/utils/constraints.js +0 -81
- package/src/utils/index.js +0 -1
- package/src/utils/keyActions.js +0 -113
- package/src/utils/mouse.js +0 -14
- package/src/utils/mouse2.ts +0 -35
- package/src/utils/transform.js +0 -336
- package/src/utils/transform2.ts +0 -343
- package/src/utils/windowViewport.js +0 -34
- package/src/utils/windowViewport2.ts +0 -50
package/src/utils/transform.js
DELETED
|
@@ -1,336 +0,0 @@
|
|
|
1
|
-
export function toSia(data, image, type, imgOffset) {
|
|
2
|
-
switch (type) {
|
|
3
|
-
case "bBox":
|
|
4
|
-
const w = image.width * data.w;
|
|
5
|
-
const h = image.height * data.h;
|
|
6
|
-
const x0 = imgOffset.x + image.width * data.x - w / 2.0;
|
|
7
|
-
const y0 = imgOffset.y + image.height * data.y - h / 2.0;
|
|
8
|
-
return [
|
|
9
|
-
{
|
|
10
|
-
x: x0,
|
|
11
|
-
y: y0,
|
|
12
|
-
},
|
|
13
|
-
{
|
|
14
|
-
x: x0 + w,
|
|
15
|
-
y: y0,
|
|
16
|
-
},
|
|
17
|
-
{
|
|
18
|
-
x: x0 + w,
|
|
19
|
-
y: y0 + h,
|
|
20
|
-
},
|
|
21
|
-
{
|
|
22
|
-
x: x0,
|
|
23
|
-
y: y0 + h,
|
|
24
|
-
},
|
|
25
|
-
];
|
|
26
|
-
case "point":
|
|
27
|
-
return [
|
|
28
|
-
{
|
|
29
|
-
x: imgOffset.x + image.width * data.x,
|
|
30
|
-
y: imgOffset.y + image.height * data.y,
|
|
31
|
-
},
|
|
32
|
-
];
|
|
33
|
-
case "line":
|
|
34
|
-
case "polygon":
|
|
35
|
-
return data.map((e) => {
|
|
36
|
-
return {
|
|
37
|
-
x: imgOffset.x + image.width * e.x,
|
|
38
|
-
y: imgOffset.y + image.height * e.y,
|
|
39
|
-
};
|
|
40
|
-
});
|
|
41
|
-
default:
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Transform a sia annotation to backend format.
|
|
47
|
-
*
|
|
48
|
-
* @param {Array} data Annotation data
|
|
49
|
-
* @param {*} svg Image object {width, height}
|
|
50
|
-
* @param {String} type Type of the annotation bBox, point, line, polygon
|
|
51
|
-
* @returns Annotation data in backend style (relative, centered)
|
|
52
|
-
*/
|
|
53
|
-
export function toBackend(data, svg, type, imgOffset = { x: 0, y: 0 }) {
|
|
54
|
-
const imgWidth = svg.width - 2 * imgOffset.x;
|
|
55
|
-
const imgHeight = svg.height - 2 * imgOffset.y;
|
|
56
|
-
switch (type) {
|
|
57
|
-
case "bBox":
|
|
58
|
-
// const w = svg.width * data.w
|
|
59
|
-
// const h = svg.height * data.h
|
|
60
|
-
// const x0 = svg.width * data.x - w/2.0
|
|
61
|
-
// const y0 = svg.height * data.y - h/2.0
|
|
62
|
-
|
|
63
|
-
// console.error('GO On Here! w = max_x - min_x; h = max_y - min_y')
|
|
64
|
-
const xList = data.map((e) => {
|
|
65
|
-
return e.x;
|
|
66
|
-
});
|
|
67
|
-
const yList = data.map((e) => {
|
|
68
|
-
return e.y;
|
|
69
|
-
});
|
|
70
|
-
const minX = Math.min(...xList) - imgOffset.x;
|
|
71
|
-
const maxX = Math.max(...xList) - imgOffset.x;
|
|
72
|
-
const minY = Math.min(...yList) - imgOffset.y;
|
|
73
|
-
const maxY = Math.max(...yList) - imgOffset.y;
|
|
74
|
-
const w = maxX - minX;
|
|
75
|
-
const h = maxY - minY;
|
|
76
|
-
const x = minX + w / 2.0;
|
|
77
|
-
const y = minY + h / 2.0;
|
|
78
|
-
return {
|
|
79
|
-
x: x / imgWidth,
|
|
80
|
-
y: y / imgHeight,
|
|
81
|
-
w: w / imgWidth,
|
|
82
|
-
h: h / imgHeight,
|
|
83
|
-
};
|
|
84
|
-
case "point":
|
|
85
|
-
return {
|
|
86
|
-
x: (data[0].x - imgOffset.x) / imgWidth,
|
|
87
|
-
y: (data[0].y - imgOffset.y) / imgHeight,
|
|
88
|
-
};
|
|
89
|
-
case "line":
|
|
90
|
-
case "polygon":
|
|
91
|
-
return data.map((e) => {
|
|
92
|
-
return {
|
|
93
|
-
x: (e.x - imgOffset.x) / imgWidth,
|
|
94
|
-
y: (e.y - imgOffset.y) / imgHeight,
|
|
95
|
-
};
|
|
96
|
-
});
|
|
97
|
-
default:
|
|
98
|
-
// console.warn("Wrong annotation type!");
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
export function getMinMaxPoints(data) {
|
|
103
|
-
const xList = data.map((e) => {
|
|
104
|
-
return e.x;
|
|
105
|
-
});
|
|
106
|
-
const yList = data.map((e) => {
|
|
107
|
-
return e.y;
|
|
108
|
-
});
|
|
109
|
-
const minPoint = { x: Math.min(...xList), y: Math.min(...yList) };
|
|
110
|
-
const maxPoint = { x: Math.max(...xList), y: Math.max(...yList) };
|
|
111
|
-
return [minPoint, maxPoint];
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
/**
|
|
115
|
-
* Get area relative to the image
|
|
116
|
-
*
|
|
117
|
-
* @param {Array} data Annotation data
|
|
118
|
-
* @param {*} scaledImg The scaled image object {width, height}
|
|
119
|
-
* @param {String} type Type of the annotation bBox, point, line, polygon
|
|
120
|
-
* @param {object} originalImg The original image
|
|
121
|
-
* @returns Area relative
|
|
122
|
-
*/
|
|
123
|
-
export function getArea(data, scaledImg, type, originalImg) {
|
|
124
|
-
const relData = toBackend(data, scaledImg, type);
|
|
125
|
-
switch (type) {
|
|
126
|
-
case "bBox":
|
|
127
|
-
return (
|
|
128
|
-
Math.abs(relData.w * relData.h) * originalImg.width * originalImg.height
|
|
129
|
-
);
|
|
130
|
-
// return relData.w*relData.h
|
|
131
|
-
case "line":
|
|
132
|
-
case "point":
|
|
133
|
-
return undefined;
|
|
134
|
-
case "polygon":
|
|
135
|
-
let area = 0.0; // Accumulates area in the loop
|
|
136
|
-
if (relData.length > 2) {
|
|
137
|
-
let j = relData.length - 1; // The last vertex is the 'previous' one to the first
|
|
138
|
-
|
|
139
|
-
for (let i = 0; i < relData.length; i++) {
|
|
140
|
-
area =
|
|
141
|
-
area +
|
|
142
|
-
(relData[j].x + relData[i].x) * (relData[j].y - relData[i].y);
|
|
143
|
-
j = i; //j is previous vertex to i
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
return Math.abs(area / 2) * originalImg.width * originalImg.height;
|
|
147
|
-
default:
|
|
148
|
-
// console.warn("Wrong annotation type!");
|
|
149
|
-
return undefined;
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
export function move(data, movementX, movementY) {
|
|
154
|
-
return data.map((e) => {
|
|
155
|
-
return {
|
|
156
|
-
x: e.x + movementX,
|
|
157
|
-
y: e.y + movementY,
|
|
158
|
-
};
|
|
159
|
-
});
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
export function getBox(data, type) {
|
|
163
|
-
switch (type) {
|
|
164
|
-
case "bBox":
|
|
165
|
-
return data;
|
|
166
|
-
case "point":
|
|
167
|
-
case "line":
|
|
168
|
-
case "polygon":
|
|
169
|
-
let maxX = 0;
|
|
170
|
-
let maxY = 0;
|
|
171
|
-
let minX = Infinity;
|
|
172
|
-
let minY = Infinity;
|
|
173
|
-
data.forEach((el) => {
|
|
174
|
-
if (el.x > maxX) maxX = el.x;
|
|
175
|
-
if (el.y > maxY) maxY = el.y;
|
|
176
|
-
if (el.x < minX) minX = el.x;
|
|
177
|
-
if (el.y < minY) minY = el.y;
|
|
178
|
-
});
|
|
179
|
-
return [
|
|
180
|
-
{ x: minX, y: minY },
|
|
181
|
-
{ x: maxX, y: minY },
|
|
182
|
-
{ x: minX, y: maxY },
|
|
183
|
-
{ x: maxX, y: maxY },
|
|
184
|
-
];
|
|
185
|
-
default:
|
|
186
|
-
break;
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
export function getCenter(data, type) {
|
|
191
|
-
let box = undefined;
|
|
192
|
-
switch (type) {
|
|
193
|
-
case "point":
|
|
194
|
-
return data[0];
|
|
195
|
-
case "line":
|
|
196
|
-
case "polygon":
|
|
197
|
-
case "bBox":
|
|
198
|
-
box = getBox(data, type);
|
|
199
|
-
const w = box[1].x - box[0].x;
|
|
200
|
-
const h = box[3].y - box[0].y;
|
|
201
|
-
return {
|
|
202
|
-
x: box[0].x + w / 2.0,
|
|
203
|
-
y: box[0].y + h / 2.0,
|
|
204
|
-
};
|
|
205
|
-
default:
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
/**
|
|
210
|
-
* Get point that is closest to the left browser side.
|
|
211
|
-
*
|
|
212
|
-
* @param {object} data list of points {x,y}
|
|
213
|
-
* @returns {object} A list of point [{x,y}...]. Multiple points are
|
|
214
|
-
* returned when multiple points have the same distance to the left side.
|
|
215
|
-
*/
|
|
216
|
-
export function getMostLeftPoint(data) {
|
|
217
|
-
let minX = Infinity;
|
|
218
|
-
let minXList = [];
|
|
219
|
-
data.forEach((el) => {
|
|
220
|
-
if (el.x < minX) {
|
|
221
|
-
minX = el.x;
|
|
222
|
-
minXList = [];
|
|
223
|
-
minXList.push(el);
|
|
224
|
-
} else if (el.x === minX) {
|
|
225
|
-
minXList.push(el);
|
|
226
|
-
}
|
|
227
|
-
});
|
|
228
|
-
return minXList;
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
/**
|
|
232
|
-
* Get point that is closest to the top of the browser.
|
|
233
|
-
*
|
|
234
|
-
* @param {object} data list of points {x,y}
|
|
235
|
-
* @returns {object} A list of point [{x,y}...]. Multiple points are
|
|
236
|
-
* returned when multiple points have the same distance to the top.
|
|
237
|
-
*/
|
|
238
|
-
export function getTopPoint(data) {
|
|
239
|
-
let minY = Infinity;
|
|
240
|
-
let minYList = [];
|
|
241
|
-
data.forEach((el) => {
|
|
242
|
-
if (el.y < minY) {
|
|
243
|
-
minY = el.y;
|
|
244
|
-
minYList = [];
|
|
245
|
-
minYList.push(el);
|
|
246
|
-
} else if (el.y === minY) {
|
|
247
|
-
minYList.push(el);
|
|
248
|
-
}
|
|
249
|
-
});
|
|
250
|
-
return minYList;
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
/**
|
|
254
|
-
* Check if all nodes of an annotation are within the image. If not,
|
|
255
|
-
* correct the annotation
|
|
256
|
-
* @param {object} data
|
|
257
|
-
* @param {object} image
|
|
258
|
-
* @param {object} imageOffset
|
|
259
|
-
*/
|
|
260
|
-
export function correctAnnotation(data, image, imageOffset) {
|
|
261
|
-
const imgWidth = image.width - 2 * imageOffset.x;
|
|
262
|
-
const imgHeight = image.height - 2 * imageOffset.y;
|
|
263
|
-
const corrected = data.map((el) => {
|
|
264
|
-
let x = el.x;
|
|
265
|
-
let y = el.y;
|
|
266
|
-
if (el.x <= imageOffset.x) {
|
|
267
|
-
x = imageOffset.x;
|
|
268
|
-
} else if (el.x > imgWidth + imageOffset.x) {
|
|
269
|
-
x = imgWidth + imageOffset.x;
|
|
270
|
-
}
|
|
271
|
-
if (el.y < imageOffset.y) {
|
|
272
|
-
y = imageOffset.y;
|
|
273
|
-
} else if (el.y > imgHeight + imageOffset.y) {
|
|
274
|
-
y = imgHeight + imageOffset.y;
|
|
275
|
-
}
|
|
276
|
-
return { x: x, y: y };
|
|
277
|
-
});
|
|
278
|
-
return corrected;
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
/**
|
|
282
|
-
* Rotate annotation around center.
|
|
283
|
-
* @param {*} data list of points {x:int,y:int}
|
|
284
|
-
* @param {*} center Center to rotate point
|
|
285
|
-
* @param {*} angle Rotation angle
|
|
286
|
-
*/
|
|
287
|
-
export function rotateAnnotation(data, center, angle) {
|
|
288
|
-
angle = angle * (Math.PI / 180); // Convert to radians
|
|
289
|
-
const rotated = data.map((point) => {
|
|
290
|
-
return {
|
|
291
|
-
x: Math.round(
|
|
292
|
-
Math.cos(angle) * (point.x - center.x) -
|
|
293
|
-
Math.sin(angle) * (point.y - center.y) +
|
|
294
|
-
center.x,
|
|
295
|
-
),
|
|
296
|
-
y: Math.round(
|
|
297
|
-
Math.sin(angle) * (point.x - center.x) +
|
|
298
|
-
Math.cos(angle) * (point.y - center.y) +
|
|
299
|
-
center.y,
|
|
300
|
-
),
|
|
301
|
-
};
|
|
302
|
-
});
|
|
303
|
-
return rotated;
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
/**
|
|
307
|
-
* Resize annotation data in canvas format to new image size
|
|
308
|
-
* @param {*} data Annotation data in canvas format [{x:int, y:int},...]
|
|
309
|
-
* @param {*} sizeOld Size of old image {width:int, height:int}
|
|
310
|
-
* @param {*} sizeNew Size of new image {width:int, height:int}
|
|
311
|
-
*/
|
|
312
|
-
export function resizeAnnoData(data, sizeOld, sizeNew) {
|
|
313
|
-
const xRatio = sizeNew.width / sizeOld.width;
|
|
314
|
-
const yRatio = sizeNew.height / sizeOld.height;
|
|
315
|
-
return data.map((e) => {
|
|
316
|
-
return {
|
|
317
|
-
x: parseInt(e.x * xRatio),
|
|
318
|
-
y: parseInt(e.y * yRatio),
|
|
319
|
-
};
|
|
320
|
-
});
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
export default {
|
|
324
|
-
toSia,
|
|
325
|
-
toBackend,
|
|
326
|
-
getMinMaxPoints,
|
|
327
|
-
getArea,
|
|
328
|
-
move,
|
|
329
|
-
getBox,
|
|
330
|
-
getCenter,
|
|
331
|
-
getMostLeftPoint,
|
|
332
|
-
getTopPoint,
|
|
333
|
-
correctAnnotation,
|
|
334
|
-
rotateAnnotation,
|
|
335
|
-
resizeAnnoData,
|
|
336
|
-
};
|
package/src/utils/transform2.ts
DELETED
|
@@ -1,343 +0,0 @@
|
|
|
1
|
-
import { Point } from "../types";
|
|
2
|
-
|
|
3
|
-
export function toSia(data, image, type, imgOffset) {
|
|
4
|
-
switch (type) {
|
|
5
|
-
case "bBox":
|
|
6
|
-
const w = image.width * data.w;
|
|
7
|
-
const h = image.height * data.h;
|
|
8
|
-
const x0 = imgOffset.x + image.width * data.x - w / 2.0;
|
|
9
|
-
const y0 = imgOffset.y + image.height * data.y - h / 2.0;
|
|
10
|
-
|
|
11
|
-
return [
|
|
12
|
-
{
|
|
13
|
-
x: x0,
|
|
14
|
-
y: y0,
|
|
15
|
-
},
|
|
16
|
-
{
|
|
17
|
-
x: x0 + w,
|
|
18
|
-
y: y0,
|
|
19
|
-
},
|
|
20
|
-
{
|
|
21
|
-
x: x0 + w,
|
|
22
|
-
y: y0 + h,
|
|
23
|
-
},
|
|
24
|
-
{
|
|
25
|
-
x: x0,
|
|
26
|
-
y: y0 + h,
|
|
27
|
-
},
|
|
28
|
-
];
|
|
29
|
-
case "point":
|
|
30
|
-
return [
|
|
31
|
-
{
|
|
32
|
-
x: imgOffset.x + image.width * data.x,
|
|
33
|
-
y: imgOffset.y + image.height * data.y,
|
|
34
|
-
},
|
|
35
|
-
];
|
|
36
|
-
case "line":
|
|
37
|
-
case "polygon":
|
|
38
|
-
return data.map((e) => {
|
|
39
|
-
return {
|
|
40
|
-
x: imgOffset.x + image.width * e.x,
|
|
41
|
-
y: imgOffset.y + image.height * e.y,
|
|
42
|
-
};
|
|
43
|
-
});
|
|
44
|
-
default:
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* Transform a sia annotation to backend format.
|
|
50
|
-
*
|
|
51
|
-
* @param {Array} data Annotation data
|
|
52
|
-
* @param {*} svg Image object {width, height}
|
|
53
|
-
* @param {String} type Type of the annotation bBox, point, line, polygon
|
|
54
|
-
* @returns Annotation data in backend style (relative, centered)
|
|
55
|
-
*/
|
|
56
|
-
export function toBackend(data, svg, type, imgOffset = { x: 0, y: 0 }) {
|
|
57
|
-
const imgWidth = svg.width - 2 * imgOffset.x;
|
|
58
|
-
const imgHeight = svg.height - 2 * imgOffset.y;
|
|
59
|
-
switch (type) {
|
|
60
|
-
case "bBox":
|
|
61
|
-
// const w = svg.width * data.w
|
|
62
|
-
// const h = svg.height * data.h
|
|
63
|
-
// const x0 = svg.width * data.x - w/2.0
|
|
64
|
-
// const y0 = svg.height * data.y - h/2.0
|
|
65
|
-
|
|
66
|
-
// console.error('GO On Here! w = max_x - min_x; h = max_y - min_y')
|
|
67
|
-
const xList = data.map((e) => {
|
|
68
|
-
return e.x;
|
|
69
|
-
});
|
|
70
|
-
const yList = data.map((e) => {
|
|
71
|
-
return e.y;
|
|
72
|
-
});
|
|
73
|
-
const minX = Math.min(...xList) - imgOffset.x;
|
|
74
|
-
const maxX = Math.max(...xList) - imgOffset.x;
|
|
75
|
-
const minY = Math.min(...yList) - imgOffset.y;
|
|
76
|
-
const maxY = Math.max(...yList) - imgOffset.y;
|
|
77
|
-
const w = maxX - minX;
|
|
78
|
-
const h = maxY - minY;
|
|
79
|
-
const x = minX + w / 2.0;
|
|
80
|
-
const y = minY + h / 2.0;
|
|
81
|
-
return {
|
|
82
|
-
x: x / imgWidth,
|
|
83
|
-
y: y / imgHeight,
|
|
84
|
-
w: w / imgWidth,
|
|
85
|
-
h: h / imgHeight,
|
|
86
|
-
};
|
|
87
|
-
case "point":
|
|
88
|
-
return {
|
|
89
|
-
x: (data[0].x - imgOffset.x) / imgWidth,
|
|
90
|
-
y: (data[0].y - imgOffset.y) / imgHeight,
|
|
91
|
-
};
|
|
92
|
-
case "line":
|
|
93
|
-
case "polygon":
|
|
94
|
-
return data.map((e) => {
|
|
95
|
-
return {
|
|
96
|
-
x: (e.x - imgOffset.x) / imgWidth,
|
|
97
|
-
y: (e.y - imgOffset.y) / imgHeight,
|
|
98
|
-
};
|
|
99
|
-
});
|
|
100
|
-
default:
|
|
101
|
-
// console.warn("Wrong annotation type!");
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
export function getMinMaxPoints(data) {
|
|
106
|
-
const xList = data.map((e) => {
|
|
107
|
-
return e.x;
|
|
108
|
-
});
|
|
109
|
-
const yList = data.map((e) => {
|
|
110
|
-
return e.y;
|
|
111
|
-
});
|
|
112
|
-
const minPoint = { x: Math.min(...xList), y: Math.min(...yList) };
|
|
113
|
-
const maxPoint = { x: Math.max(...xList), y: Math.max(...yList) };
|
|
114
|
-
return [minPoint, maxPoint];
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
/**
|
|
118
|
-
* Get area relative to the image
|
|
119
|
-
*
|
|
120
|
-
* @param {Array} data Annotation data
|
|
121
|
-
* @param {*} scaledImg The scaled image object {width, height}
|
|
122
|
-
* @param {String} type Type of the annotation bBox, point, line, polygon
|
|
123
|
-
* @param {object} originalImg The original image
|
|
124
|
-
* @returns Area relative
|
|
125
|
-
*/
|
|
126
|
-
export function getArea(data, scaledImg, type, originalImg) {
|
|
127
|
-
const relData = toBackend(data, scaledImg, type);
|
|
128
|
-
switch (type) {
|
|
129
|
-
case "bBox":
|
|
130
|
-
return (
|
|
131
|
-
Math.abs(relData.w * relData.h) * originalImg.width * originalImg.height
|
|
132
|
-
);
|
|
133
|
-
// return relData.w*relData.h
|
|
134
|
-
case "line":
|
|
135
|
-
case "point":
|
|
136
|
-
return undefined;
|
|
137
|
-
case "polygon":
|
|
138
|
-
let area = 0.0; // Accumulates area in the loop
|
|
139
|
-
if (relData.length > 2) {
|
|
140
|
-
let j = relData.length - 1; // The last vertex is the 'previous' one to the first
|
|
141
|
-
|
|
142
|
-
for (let i = 0; i < relData.length; i++) {
|
|
143
|
-
area =
|
|
144
|
-
area +
|
|
145
|
-
(relData[j].x + relData[i].x) * (relData[j].y - relData[i].y);
|
|
146
|
-
j = i; //j is previous vertex to i
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
return Math.abs(area / 2) * originalImg.width * originalImg.height;
|
|
150
|
-
default:
|
|
151
|
-
// console.warn("Wrong annotation type!");
|
|
152
|
-
return undefined;
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
export function move(data, movementX, movementY) {
|
|
157
|
-
return data.map((e) => {
|
|
158
|
-
return {
|
|
159
|
-
x: e.x + movementX,
|
|
160
|
-
y: e.y + movementY,
|
|
161
|
-
};
|
|
162
|
-
});
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
export function getBox(data, type) {
|
|
166
|
-
switch (type) {
|
|
167
|
-
case "bBox":
|
|
168
|
-
return data;
|
|
169
|
-
case "point":
|
|
170
|
-
case "line":
|
|
171
|
-
case "polygon":
|
|
172
|
-
let maxX = 0;
|
|
173
|
-
let maxY = 0;
|
|
174
|
-
let minX = Infinity;
|
|
175
|
-
let minY = Infinity;
|
|
176
|
-
data.forEach((el) => {
|
|
177
|
-
if (el.x > maxX) maxX = el.x;
|
|
178
|
-
if (el.y > maxY) maxY = el.y;
|
|
179
|
-
if (el.x < minX) minX = el.x;
|
|
180
|
-
if (el.y < minY) minY = el.y;
|
|
181
|
-
});
|
|
182
|
-
return [
|
|
183
|
-
{ x: minX, y: minY },
|
|
184
|
-
{ x: maxX, y: minY },
|
|
185
|
-
{ x: minX, y: maxY },
|
|
186
|
-
{ x: maxX, y: maxY },
|
|
187
|
-
];
|
|
188
|
-
default:
|
|
189
|
-
break;
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
export function getCenter(data, type) {
|
|
194
|
-
let box = undefined;
|
|
195
|
-
switch (type) {
|
|
196
|
-
case "point":
|
|
197
|
-
return data[0];
|
|
198
|
-
case "line":
|
|
199
|
-
case "polygon":
|
|
200
|
-
case "bBox":
|
|
201
|
-
box = getBox(data, type);
|
|
202
|
-
const w = box[1].x - box[0].x;
|
|
203
|
-
const h = box[3].y - box[0].y;
|
|
204
|
-
return {
|
|
205
|
-
x: box[0].x + w / 2.0,
|
|
206
|
-
y: box[0].y + h / 2.0,
|
|
207
|
-
};
|
|
208
|
-
default:
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
/**
|
|
213
|
-
* Get point that is closest to the left browser side.
|
|
214
|
-
*
|
|
215
|
-
* @param points list of points {x,y}
|
|
216
|
-
* @returns {object} A list of point [{x,y}...]. Multiple points are
|
|
217
|
-
* returned when multiple points have the same distance to the left side.
|
|
218
|
-
*/
|
|
219
|
-
export const getMostLeftPoints = (points: Point[]): Point[] => {
|
|
220
|
-
let minX = Infinity;
|
|
221
|
-
let minXList: Point[] = [];
|
|
222
|
-
points.forEach((point: Point) => {
|
|
223
|
-
if (point.x < minX) {
|
|
224
|
-
// new most left point - replace list
|
|
225
|
-
minX = point.x;
|
|
226
|
-
minXList = [];
|
|
227
|
-
minXList.push(point);
|
|
228
|
-
} else if (point.x === minX) {
|
|
229
|
-
// same x as current most left point - add to list
|
|
230
|
-
minXList.push(point);
|
|
231
|
-
}
|
|
232
|
-
});
|
|
233
|
-
return minXList;
|
|
234
|
-
};
|
|
235
|
-
|
|
236
|
-
/**
|
|
237
|
-
* Get point that is closest to the top of the browser.
|
|
238
|
-
*
|
|
239
|
-
* @param points list of points [x,y]
|
|
240
|
-
* @returns A list of point [[x,y]...]. Multiple points are
|
|
241
|
-
* returned when multiple points have the same distance to the top.
|
|
242
|
-
*/
|
|
243
|
-
export const getTopPoint = (points: Point[]): Point[] => {
|
|
244
|
-
let minY = Infinity;
|
|
245
|
-
let minYList: Point[] = [];
|
|
246
|
-
points.forEach((point: Point) => {
|
|
247
|
-
if (point.y < minY) {
|
|
248
|
-
// new hightest point - replace list
|
|
249
|
-
minY = point.y;
|
|
250
|
-
minYList = [];
|
|
251
|
-
minYList.push(point);
|
|
252
|
-
} else if (point.y === minY) {
|
|
253
|
-
// same height as highest point - add to list
|
|
254
|
-
minYList.push(point);
|
|
255
|
-
}
|
|
256
|
-
});
|
|
257
|
-
return minYList;
|
|
258
|
-
};
|
|
259
|
-
|
|
260
|
-
/**
|
|
261
|
-
* Check if all nodes of an annotation are within the image. If not,
|
|
262
|
-
* correct the annotation
|
|
263
|
-
* @param {object} data
|
|
264
|
-
* @param {object} image
|
|
265
|
-
* @param {object} imageOffset
|
|
266
|
-
*/
|
|
267
|
-
export function correctAnnotation(data, image, imageOffset) {
|
|
268
|
-
const imgWidth = image.width - 2 * imageOffset.x;
|
|
269
|
-
const imgHeight = image.height - 2 * imageOffset.y;
|
|
270
|
-
const corrected = data.map((el) => {
|
|
271
|
-
let x = el.x;
|
|
272
|
-
let y = el.y;
|
|
273
|
-
if (el.x <= imageOffset.x) {
|
|
274
|
-
x = imageOffset.x;
|
|
275
|
-
} else if (el.x > imgWidth + imageOffset.x) {
|
|
276
|
-
x = imgWidth + imageOffset.x;
|
|
277
|
-
}
|
|
278
|
-
if (el.y < imageOffset.y) {
|
|
279
|
-
y = imageOffset.y;
|
|
280
|
-
} else if (el.y > imgHeight + imageOffset.y) {
|
|
281
|
-
y = imgHeight + imageOffset.y;
|
|
282
|
-
}
|
|
283
|
-
return { x: x, y: y };
|
|
284
|
-
});
|
|
285
|
-
return corrected;
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
/**
|
|
289
|
-
* Rotate annotation around center.
|
|
290
|
-
* @param {*} data list of points {x:int,y:int}
|
|
291
|
-
* @param {*} center Center to rotate point
|
|
292
|
-
* @param {*} angle Rotation angle
|
|
293
|
-
*/
|
|
294
|
-
export function rotateAnnotation(data, center, angle) {
|
|
295
|
-
angle = angle * (Math.PI / 180); // Convert to radians
|
|
296
|
-
const rotated = data.map((point) => {
|
|
297
|
-
return {
|
|
298
|
-
x: Math.round(
|
|
299
|
-
Math.cos(angle) * (point.x - center.x) -
|
|
300
|
-
Math.sin(angle) * (point.y - center.y) +
|
|
301
|
-
center.x,
|
|
302
|
-
),
|
|
303
|
-
y: Math.round(
|
|
304
|
-
Math.sin(angle) * (point.x - center.x) +
|
|
305
|
-
Math.cos(angle) * (point.y - center.y) +
|
|
306
|
-
center.y,
|
|
307
|
-
),
|
|
308
|
-
};
|
|
309
|
-
});
|
|
310
|
-
return rotated;
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
/**
|
|
314
|
-
* Resize annotation data in canvas format to new image size
|
|
315
|
-
* @param {*} data Annotation data in canvas format [{x:int, y:int},...]
|
|
316
|
-
* @param {*} sizeOld Size of old image {width:int, height:int}
|
|
317
|
-
* @param {*} sizeNew Size of new image {width:int, height:int}
|
|
318
|
-
*/
|
|
319
|
-
export function resizeAnnoData(data, sizeOld, sizeNew) {
|
|
320
|
-
const xRatio = sizeNew.width / sizeOld.width;
|
|
321
|
-
const yRatio = sizeNew.height / sizeOld.height;
|
|
322
|
-
return data.map((e) => {
|
|
323
|
-
return {
|
|
324
|
-
x: parseInt(e.x * xRatio),
|
|
325
|
-
y: parseInt(e.y * yRatio),
|
|
326
|
-
};
|
|
327
|
-
});
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
export default {
|
|
331
|
-
toSia,
|
|
332
|
-
toBackend,
|
|
333
|
-
getMinMaxPoints,
|
|
334
|
-
getArea,
|
|
335
|
-
move,
|
|
336
|
-
getBox,
|
|
337
|
-
getCenter,
|
|
338
|
-
getMostLeftPoints,
|
|
339
|
-
getTopPoint,
|
|
340
|
-
correctAnnotation,
|
|
341
|
-
rotateAnnotation,
|
|
342
|
-
resizeAnnoData,
|
|
343
|
-
};
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
export function getViewportCoordinates(w, svg) {
|
|
2
|
-
const window = {
|
|
3
|
-
xMin: -1 * svg.translateX,
|
|
4
|
-
xMax: -1 * svg.translateX + svg.width / svg.scale,
|
|
5
|
-
yMin: -1 * svg.translateY,
|
|
6
|
-
yMax: -1 * svg.translateY + svg.height / svg.scale,
|
|
7
|
-
};
|
|
8
|
-
const viewport = {
|
|
9
|
-
xMin: 0,
|
|
10
|
-
xMax: svg.width,
|
|
11
|
-
yMin: 0,
|
|
12
|
-
yMax: svg.height,
|
|
13
|
-
};
|
|
14
|
-
const scaleX = (viewport.xMax - viewport.xMin) / (window.xMax - window.xMin);
|
|
15
|
-
const scaleY = (viewport.yMax - viewport.yMin) / (window.yMax - window.yMin);
|
|
16
|
-
|
|
17
|
-
const vX = viewport.xMin + (w.x - window.xMin) * scaleX;
|
|
18
|
-
const vY = viewport.yMin + (w.y - window.yMin) * scaleY;
|
|
19
|
-
return { window, viewport, vX, vY, scaleX, scaleY };
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
*
|
|
24
|
-
* @param {*} w0 Point in image coordinate system
|
|
25
|
-
* @param {*} svg Svg with old translation values and old scales
|
|
26
|
-
* @param {*} s1 New scale/zoom
|
|
27
|
-
*/
|
|
28
|
-
export function getZoomTranslation(w0, svg, s1) {
|
|
29
|
-
const s0 = svg.scale;
|
|
30
|
-
let translation = { x: 0, y: 0 };
|
|
31
|
-
translation.x = (s0 / s1) * (w0.x + svg.translateX) - w0.x;
|
|
32
|
-
translation.y = (s0 / s1) * (w0.y + svg.translateY) - w0.y;
|
|
33
|
-
return translation;
|
|
34
|
-
}
|