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.
Files changed (280) hide show
  1. package/README.md +4 -0
  2. package/dist/Annotation/logic/Annotation.d.ts +17 -0
  3. package/dist/Annotation/logic/Annotation.js +1 -0
  4. package/dist/Annotation/ui/AnnotationComponent.d.ts +24 -0
  5. package/dist/Annotation/ui/AnnotationComponent.js +1 -0
  6. package/dist/Annotation/ui/atoms/AnnoBar.d.ts +15 -0
  7. package/dist/Annotation/ui/atoms/AnnoBar.js +1 -0
  8. package/dist/Annotation/ui/atoms/DaviIcon.d.ts +9 -0
  9. package/dist/Annotation/ui/atoms/DaviIcon.js +19 -0
  10. package/dist/Annotation/ui/atoms/Edge.d.ts +17 -0
  11. package/dist/Annotation/ui/atoms/Edge.js +1 -0
  12. package/dist/Annotation/ui/atoms/Node.d.ts +17 -0
  13. package/dist/Annotation/ui/atoms/Node.js +1 -0
  14. package/dist/Annotation/ui/atoms/PolygonArea.d.ts +16 -0
  15. package/dist/Annotation/ui/atoms/PolygonArea.js +1 -0
  16. package/dist/Annotation/ui/tools/BBox.d.ts +21 -0
  17. package/dist/Annotation/ui/tools/BBox.js +1 -0
  18. package/dist/Annotation/ui/tools/Line.d.ts +21 -0
  19. package/dist/Annotation/ui/tools/Line.js +1 -0
  20. package/dist/Annotation/ui/tools/Point.d.ts +16 -0
  21. package/dist/Annotation/ui/tools/Point.js +1 -0
  22. package/dist/Annotation/ui/tools/Polygon.d.ts +23 -0
  23. package/dist/Annotation/ui/tools/Polygon.js +1 -0
  24. package/dist/Canvas/Canvas.d.ts +31 -0
  25. package/dist/Canvas/Canvas.js +1 -0
  26. package/dist/Canvas/LabelInput.d.ts +11 -0
  27. package/dist/Canvas/LabelInput.js +1 -0
  28. package/dist/IconButton.d.ts +25 -0
  29. package/dist/IconButton.js +1 -0
  30. package/dist/Sia.d.ts +33 -0
  31. package/dist/Sia.js +1 -0
  32. package/dist/Toolbar/Toolbar.d.ts +21 -0
  33. package/dist/Toolbar/Toolbar.js +1 -0
  34. package/dist/Toolbar/ToolbarItems/AccessibilityTools.d.ts +7 -0
  35. package/dist/Toolbar/ToolbarItems/AccessibilityTools.js +1 -0
  36. package/dist/Toolbar/ToolbarItems/AnnoToolSelector.d.ts +11 -0
  37. package/dist/Toolbar/ToolbarItems/AnnoToolSelector.js +1 -0
  38. package/dist/Toolbar/ToolbarItems/ImageToolItems/ImageLabelInput.d.ts +11 -0
  39. package/dist/Toolbar/ToolbarItems/ImageToolItems/ImageLabelInput.js +1 -0
  40. package/dist/Toolbar/ToolbarItems/ImageToolItems/TagLabel.d.ts +11 -0
  41. package/dist/Toolbar/ToolbarItems/ImageToolItems/TagLabel.js +1 -0
  42. package/dist/Toolbar/ToolbarItems/ImageTools.d.ts +13 -0
  43. package/dist/Toolbar/ToolbarItems/ImageTools.js +1 -0
  44. package/dist/Toolbar/ToolbarItems/Instructions.d.ts +2 -0
  45. package/dist/Toolbar/ToolbarItems/Instructions.js +1 -0
  46. package/dist/Toolbar/ToolbarItems/InstructionsModal.d.ts +6 -0
  47. package/dist/Toolbar/ToolbarItems/InstructionsModal.js +1 -0
  48. package/dist/assets/SIA-BV1tYu3P.css +1 -0
  49. package/dist/assets/brand-icons-Cu_C0hZ4.svg +1008 -0
  50. package/dist/assets/brand-icons-F3SPCeH1.woff +0 -0
  51. package/dist/assets/brand-icons-XL9sxUpA.woff2 +0 -0
  52. package/dist/assets/brand-icons-sqJ2Pg7a.eot +0 -0
  53. package/dist/assets/brand-icons-ubhWoxly.ttf +0 -0
  54. package/dist/assets/flags-DOLqOU7Y.png +0 -0
  55. package/dist/assets/icons-BOCtAERH.woff +0 -0
  56. package/dist/assets/icons-CHzK1VD9.eot +0 -0
  57. package/dist/assets/icons-D29ZQHHw.ttf +0 -0
  58. package/dist/assets/icons-Du6TOHnR.woff2 +0 -0
  59. package/dist/assets/icons-RwhydX30.svg +1518 -0
  60. package/dist/assets/node_modules/semantic-ui-css/semantic.min-Bvulf91l.css +346 -0
  61. package/dist/assets/outline-icons-BfdLr8tr.svg +366 -0
  62. package/dist/assets/outline-icons-DD8jm0uy.ttf +0 -0
  63. package/dist/assets/outline-icons-DInHoiqI.woff2 +0 -0
  64. package/dist/assets/outline-icons-LX8adJ4n.eot +0 -0
  65. package/dist/assets/outline-icons-aQ88nltS.woff +0 -0
  66. package/dist/index.d.ts +5 -0
  67. package/dist/index.js +1 -0
  68. package/dist/models/AnnotationMode.d.ts +11 -0
  69. package/dist/models/AnnotationMode.js +1 -0
  70. package/dist/models/AnnotationStatus.d.ts +8 -0
  71. package/dist/models/AnnotationStatus.js +1 -0
  72. package/dist/models/AnnotationTool.d.ts +7 -0
  73. package/dist/models/AnnotationTool.js +1 -0
  74. package/dist/models/CanvasAction.d.ts +28 -0
  75. package/dist/models/CanvasAction.js +1 -0
  76. package/dist/models/Direction.d.ts +7 -0
  77. package/dist/models/Direction.js +1 -0
  78. package/dist/models/EditorModes.d.ts +11 -0
  79. package/dist/models/EditorModes.js +1 -0
  80. package/dist/models/KeyAction.d.ts +22 -0
  81. package/dist/models/KeyAction.js +1 -0
  82. package/dist/models/NotificationType.d.ts +7 -0
  83. package/dist/models/NotificationType.js +1 -0
  84. package/dist/models/index.d.ts +6 -0
  85. package/dist/models/index.js +1 -0
  86. package/dist/stories/AnnotationTools.stories.d.ts +40 -0
  87. package/dist/stories/Canvas/Canvas.stories.d.ts +50 -0
  88. package/dist/stories/Canvas/CanvasOffset.d.ts +13 -0
  89. package/dist/stories/Canvas/CanvasWithOffset.stories.d.ts +36 -0
  90. package/dist/stories/FilterDropdown.stories.d.ts +19 -0
  91. package/dist/stories/MinimalSia.stories.d.ts +66 -0
  92. package/dist/stories/SIA/DemoWrapper.d.ts +8 -0
  93. package/dist/stories/SIA/DemoWrapper.stories.d.ts +27 -0
  94. package/dist/stories/SIA/SIA.stories.d.ts +72 -0
  95. package/dist/stories/Toolbar/ImageTools/TagLabel.stories.d.ts +21 -0
  96. package/dist/stories/Toolbar/Instructions.stories.d.ts +11 -0
  97. package/dist/stories/Toolbar/Toolbar.stories.d.ts +37 -0
  98. package/dist/stories/exampleData/exampleAnnotations.d.ts +8 -0
  99. package/dist/stories/exampleData/exampleExternalAnnotations.d.ts +8 -0
  100. package/dist/stories/exampleData/exampleImage.d.ts +2 -0
  101. package/dist/stories/exampleData/exampleLabels.d.ts +6 -0
  102. package/dist/types.d.ts +57 -0
  103. package/dist/types.js +1 -0
  104. package/dist/utils/KeyMapper.d.ts +9 -0
  105. package/dist/utils/KeyMapper.js +1 -0
  106. package/dist/utils/TimeUtils.d.ts +4 -0
  107. package/dist/utils/TimeUtils.js +1 -0
  108. package/dist/utils/color.d.ts +2 -0
  109. package/dist/utils/color.js +1 -0
  110. package/dist/utils/index.d.ts +2 -0
  111. package/dist/utils/index.js +1 -0
  112. package/dist/utils/mouse.d.ts +6 -0
  113. package/dist/utils/mouse.js +1 -0
  114. package/dist/utils/siaIcons.js +12 -0
  115. package/dist/utils/transform.d.ts +28 -0
  116. package/dist/utils/transform.js +1 -0
  117. package/dist/utils/uiConfig.js +1 -0
  118. package/dist/utils/windowViewport.d.ts +22 -0
  119. package/dist/utils/windowViewport.js +1 -0
  120. package/package.json +19 -16
  121. package/src/AnnoExampleViewer.jsx +18 -18
  122. package/src/Annotation/logic/Annotation.ts +24 -26
  123. package/src/Annotation/ui/AnnotationComponent.tsx +115 -86
  124. package/src/Annotation/ui/atoms/AnnoBar.tsx +51 -53
  125. package/src/Annotation/ui/atoms/DaviIcon.tsx +12 -22
  126. package/src/Annotation/ui/atoms/Edge.tsx +25 -22
  127. package/src/Annotation/ui/atoms/Node.tsx +56 -50
  128. package/src/Annotation/ui/atoms/PolygonArea.tsx +30 -35
  129. package/src/Annotation/ui/tools/BBox.tsx +136 -150
  130. package/src/Annotation/ui/tools/Line.tsx +94 -91
  131. package/src/Annotation/ui/tools/Point.tsx +19 -17
  132. package/src/Annotation/ui/tools/Polygon.tsx +126 -95
  133. package/src/Canvas/Canvas.tsx +748 -594
  134. package/src/Canvas/LabelInput.tsx +68 -45
  135. package/src/IconButton.tsx +119 -0
  136. package/src/InfoBoxes/AnnoDetails.jsx +53 -53
  137. package/src/InfoBoxes/AnnoStats.jsx +41 -41
  138. package/src/InfoBoxes/InfoBox.jsx +16 -16
  139. package/src/InfoBoxes/InfoBoxArea.jsx +32 -34
  140. package/src/InfoBoxes/LabelInfo.jsx +30 -30
  141. package/src/SIASettingButton.jsx +25 -25
  142. package/src/Sia.tsx +484 -0
  143. package/src/Toolbar/Toolbar.tsx +38 -31
  144. package/src/Toolbar/ToolbarItems/AccessibilityTools.tsx +26 -46
  145. package/src/Toolbar/ToolbarItems/AnnoToolSelector.tsx +53 -46
  146. package/src/Toolbar/ToolbarItems/ImageToolItems/ImageLabelInput.tsx +127 -0
  147. package/src/Toolbar/ToolbarItems/ImageToolItems/TagLabel.tsx +29 -28
  148. package/src/Toolbar/ToolbarItems/ImageTools.tsx +43 -40
  149. package/src/Toolbar/ToolbarItems/Instructions.tsx +47 -50
  150. package/src/Toolbar/ToolbarItems/InstructionsModal.tsx +8 -8
  151. package/src/index.ts +9 -13
  152. package/src/models/{AnnotationMode.tsx → AnnotationMode.ts} +1 -1
  153. package/src/models/{AnnotationStatus.tsx → AnnotationStatus.ts} +1 -1
  154. package/src/models/{AnnotationTool.tsx → AnnotationTool.ts} +1 -1
  155. package/src/models/{CanvasAction.tsx → CanvasAction.ts} +1 -1
  156. package/src/models/{Direction.tsx → Direction.ts} +1 -1
  157. package/src/models/{EditorModes.tsx → EditorModes.ts} +1 -1
  158. package/src/models/{KeyAction.tsx → KeyAction.ts} +3 -1
  159. package/src/models/NotificationType.ts +8 -0
  160. package/src/models/index.ts +6 -7
  161. package/src/siaDummyData.js +71 -71
  162. package/src/stories/AnnotationTools.mdx +27 -0
  163. package/src/stories/AnnotationTools.stories.tsx +104 -0
  164. package/src/stories/Canvas/Canvas.stories.tsx +59 -113
  165. package/src/stories/Canvas/CanvasOffset.tsx +54 -38
  166. package/src/stories/Canvas/CanvasWithOffset.stories.tsx +42 -113
  167. package/src/stories/FilterDropdown.stories.ts +13 -11
  168. package/src/stories/MinimalSIA.mdx +20 -0
  169. package/src/stories/MinimalSia.stories.tsx +90 -0
  170. package/src/stories/SIA/DemoWrapper.stories.tsx +71 -0
  171. package/src/stories/SIA/DemoWrapper.tsx +55 -0
  172. package/src/stories/SIA/SIA.stories.tsx +79 -45
  173. package/src/stories/Toolbar/ImageTools/TagLabel.stories.tsx +11 -12
  174. package/src/stories/Toolbar/Instructions.stories.tsx +11 -11
  175. package/src/stories/Toolbar/Toolbar.stories.tsx +32 -47
  176. package/src/stories/Welcome.mdx +5 -0
  177. package/src/stories/development/CoordinateSystems.mdx +25 -0
  178. package/src/stories/exampleData/exampleAnnotations.ts +65 -0
  179. package/src/stories/exampleData/exampleExternalAnnotations.ts +115 -0
  180. package/src/stories/{siaDummyData2.ts → exampleData/exampleImage.ts} +3 -264
  181. package/src/stories/exampleData/exampleLabels.ts +146 -0
  182. package/src/stories/main.scss +6 -0
  183. package/src/styles/style.scss +1 -26
  184. package/src/types.ts +67 -0
  185. package/src/utils/KeyMapper.ts +76 -74
  186. package/src/utils/TimeUtils.ts +11 -0
  187. package/src/utils/color.ts +25 -25
  188. package/src/utils/hist.js +22 -22
  189. package/src/utils/index.ts +2 -3
  190. package/src/utils/mouse.ts +45 -0
  191. package/src/utils/siaIcons.jsx +5 -7
  192. package/src/utils/transform.ts +186 -0
  193. package/src/utils/uiConfig.js +19 -22
  194. package/src/utils/windowViewport.ts +34 -0
  195. package/src/AnnoLabelInput.jsx +0 -109
  196. package/src/AnnoToolBar.jsx +0 -153
  197. package/src/Annotation/AnnoBar.jsx +0 -154
  198. package/src/Annotation/Annotation.jsx +0 -395
  199. package/src/Annotation/Annotation.scss +0 -47
  200. package/src/Annotation/BBox.jsx +0 -299
  201. package/src/Annotation/Edge.jsx +0 -92
  202. package/src/Annotation/InfSelectionArea.jsx +0 -72
  203. package/src/Annotation/Line.jsx +0 -68
  204. package/src/Annotation/Node.jsx +0 -282
  205. package/src/Annotation/Point.jsx +0 -200
  206. package/src/Annotation/Polygon.jsx +0 -404
  207. package/src/Annotation/logic/AnnotationUtils.ts +0 -30
  208. package/src/Canvas.jsx +0 -2194
  209. package/src/ImgBar.jsx +0 -131
  210. package/src/LabelInput.jsx +0 -238
  211. package/src/Prompt.jsx +0 -45
  212. package/src/SIAFilterButton.jsx +0 -186
  213. package/src/Sia.jsx +0 -478
  214. package/src/Sia2.tsx +0 -392
  215. package/src/SiaPopup.jsx +0 -15
  216. package/src/ToolBar.jsx +0 -463
  217. package/src/Toolbar/NavigationButtons.tsx +0 -21
  218. package/src/Toolbar/ToolbarItem.jsx +0 -30
  219. package/src/Toolbar/ToolbarItems/ImageToolItems/ImageLabel.tsx +0 -62
  220. package/src/Toolbar.css +0 -13
  221. package/src/ToolbarItem.jsx +0 -31
  222. package/src/filterTools.js +0 -5
  223. package/src/models/AllowedTools.tsx +0 -9
  224. package/src/models/AnnotationSettings.tsx +0 -9
  225. package/src/models/ExternalAnnotation.ts +0 -15
  226. package/src/models/Label.tsx +0 -8
  227. package/src/models/UiConfig.tsx +0 -6
  228. package/src/stories/Button.jsx +0 -54
  229. package/src/stories/Button.stories.js +0 -48
  230. package/src/stories/Header.jsx +0 -69
  231. package/src/stories/Header.stories.js +0 -28
  232. package/src/stories/Page.jsx +0 -87
  233. package/src/stories/Page.stories.js +0 -28
  234. package/src/stories/SIA2/DemoWrapper.stories.tsx +0 -167
  235. package/src/stories/SIA2/DemoWrapper.tsx +0 -54
  236. package/src/stories/SIA2/Sia2.stories.tsx +0 -62
  237. package/src/stories/Toolbar/ImageTools/ImageLabel.stories.tsx +0 -32
  238. package/src/stories/assets/accessibility.png +0 -0
  239. package/src/stories/assets/accessibility.svg +0 -5
  240. package/src/stories/assets/addon-library.png +0 -0
  241. package/src/stories/assets/assets.png +0 -0
  242. package/src/stories/assets/avif-test-image.avif +0 -0
  243. package/src/stories/assets/context.png +0 -0
  244. package/src/stories/assets/discord.svg +0 -15
  245. package/src/stories/assets/docs.png +0 -0
  246. package/src/stories/assets/figma-plugin.png +0 -0
  247. package/src/stories/assets/github.svg +0 -3
  248. package/src/stories/assets/share.png +0 -0
  249. package/src/stories/assets/styling.png +0 -0
  250. package/src/stories/assets/testing.png +0 -0
  251. package/src/stories/assets/theming.png +0 -0
  252. package/src/stories/assets/tutorials.svg +0 -12
  253. package/src/stories/assets/youtube.svg +0 -4
  254. package/src/stories/button.css +0 -30
  255. package/src/stories/header.css +0 -32
  256. package/src/stories/lost.js +0 -54
  257. package/src/stories/page.css +0 -69
  258. package/src/stories/siaDummyData.js +0 -263
  259. package/src/stories/store.js +0 -18
  260. package/src/test.js +0 -7
  261. package/src/types/annoStatus.js +0 -4
  262. package/src/types/canvasActions.js +0 -58
  263. package/src/types/cursorstyles.js +0 -3
  264. package/src/types/modes.js +0 -9
  265. package/src/types/notificationType.js +0 -11
  266. package/src/types/toolbarEvents.js +0 -35
  267. package/src/types/tools.js +0 -17
  268. package/src/types.tsx +0 -11
  269. package/src/utils/annoConversion.js +0 -145
  270. package/src/utils/annoConversion2.ts +0 -145
  271. package/src/utils/colorlut.js +0 -68
  272. package/src/utils/constraints.js +0 -81
  273. package/src/utils/index.js +0 -1
  274. package/src/utils/keyActions.js +0 -113
  275. package/src/utils/mouse.js +0 -14
  276. package/src/utils/mouse2.ts +0 -35
  277. package/src/utils/transform.js +0 -336
  278. package/src/utils/transform2.ts +0 -343
  279. package/src/utils/windowViewport.js +0 -34
  280. package/src/utils/windowViewport2.ts +0 -50
@@ -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
- };
@@ -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
- }