@labelbee/lb-annotation 1.14.0-alpha.2 → 1.14.0-alpha.3

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 (187) hide show
  1. package/dist/_virtual/MathUtilsWorker.js +8 -1
  2. package/dist/_virtual/_rollup-plugin-web-worker-loader__helper__browser__createBase64WorkerFactory.js +35 -2
  3. package/dist/_virtual/filterBoxWorker.js +8 -1
  4. package/dist/_virtual/highlightWorker.js +8 -1
  5. package/dist/assets/attributeIcon/icon_canvasEdit0.svg.js +5 -1
  6. package/dist/assets/attributeIcon/icon_canvasEdit1.svg.js +5 -1
  7. package/dist/assets/attributeIcon/icon_canvasEdit2.svg.js +5 -1
  8. package/dist/assets/attributeIcon/icon_canvasEdit3.svg.js +5 -1
  9. package/dist/assets/attributeIcon/icon_canvasEdit4.svg.js +5 -1
  10. package/dist/assets/attributeIcon/icon_canvasEdit5.svg.js +5 -1
  11. package/dist/assets/attributeIcon/icon_canvasEdit6.svg.js +5 -1
  12. package/dist/assets/attributeIcon/icon_canvasEdit7.svg.js +5 -1
  13. package/dist/assets/attributeIcon/icon_canvasEdit8.svg.js +5 -1
  14. package/dist/assets/attributeIcon/icon_canvasEdit_miss.svg.js +5 -1
  15. package/dist/assets/attributeIcon/icon_cuboidFAB.svg.js +5 -5
  16. package/dist/assets/attributeIcon/icon_cuboidLeft.svg.js +5 -7
  17. package/dist/assets/attributeIcon/icon_cuboidMore.svg.js +5 -5
  18. package/dist/assets/attributeIcon/icon_cuboidRight.svg.js +5 -5
  19. package/dist/assets/attributeIcon/icon_cuboidTop.svg.js +5 -12
  20. package/dist/assets/attributeIcon/icon_editFEN.svg.js +5 -1
  21. package/dist/assets/attributeIcon/icon_editHUANG.svg.js +5 -1
  22. package/dist/assets/attributeIcon/icon_editLAN.svg.js +5 -1
  23. package/dist/assets/attributeIcon/icon_editLV.svg.js +5 -1
  24. package/dist/assets/attributeIcon/icon_editQING.svg.js +5 -1
  25. package/dist/constant/annotation.js +127 -1
  26. package/dist/constant/annotationTask.js +30 -1
  27. package/dist/constant/defaultConfig.js +266 -1
  28. package/dist/constant/keyCode.js +38 -1
  29. package/dist/constant/style.js +98 -1
  30. package/dist/constant/tool.js +236 -1
  31. package/dist/core/index.js +150 -1
  32. package/dist/core/pointCloud/OrbitControls.js +665 -1
  33. package/dist/core/pointCloud/PCDLoader.js +260 -2
  34. package/dist/core/pointCloud/annotation.js +215 -1
  35. package/dist/core/pointCloud/cache.js +53 -1
  36. package/dist/core/pointCloud/index.js +991 -5
  37. package/dist/core/pointCloud/matrix.js +138 -1
  38. package/dist/core/pointCloud/segmentation.js +144 -0
  39. package/dist/core/pointCloud/selector/Sse3dLassoSelector.js +26 -0
  40. package/dist/core/pointCloud/selector/Sse3dSelector.js +16 -0
  41. package/dist/core/scheduler.js +233 -1
  42. package/dist/core/toolOperation/LineToolOperation.js +1434 -1
  43. package/dist/core/toolOperation/ScribbleTool.js +292 -1
  44. package/dist/core/toolOperation/TextToolOperation.js +131 -1
  45. package/dist/core/toolOperation/ViewOperation.js +556 -1
  46. package/dist/core/toolOperation/basicToolOperation.js +881 -1
  47. package/dist/core/toolOperation/checkOperation.js +208 -1
  48. package/dist/core/toolOperation/cuboidOperation.js +754 -1
  49. package/dist/core/toolOperation/cuboidToggleButtonClass.js +152 -7
  50. package/dist/core/toolOperation/eventListener.js +37 -1
  51. package/dist/core/toolOperation/measureOperation.js +41 -1
  52. package/dist/core/toolOperation/pointCloud2dOperation.js +365 -1
  53. package/dist/core/toolOperation/pointOperation.js +696 -1
  54. package/dist/core/toolOperation/polygonOperation.js +1251 -1
  55. package/dist/core/toolOperation/rectOperation.js +1233 -1
  56. package/dist/core/toolOperation/segmentByRect.js +174 -1
  57. package/dist/core/toolOperation/tagOperation.js +201 -3
  58. package/dist/core/toolOperation/textAttributeClass.js +182 -16
  59. package/dist/index.js +185 -1
  60. package/dist/locales/constants.js +24 -1
  61. package/dist/locales/en_US/message.js +25 -1
  62. package/dist/locales/index.js +19 -1
  63. package/dist/locales/zh_CN/message.js +25 -1
  64. package/dist/newCore/CanvasScheduler.js +35 -1
  65. package/dist/types/core/pointCloud/segmentation.d.ts +0 -0
  66. package/dist/types/core/pointCloud/selector/Sse3dLassoSelector.d.ts +0 -0
  67. package/dist/types/core/pointCloud/selector/Sse3dSelector.d.ts +0 -0
  68. package/dist/utils/ActionsHistory.js +84 -1
  69. package/dist/utils/ImgUtils.js +23 -1
  70. package/dist/utils/MathUtils.js +385 -2
  71. package/dist/utils/VectorUtils.js +25 -1
  72. package/dist/utils/tool/AttributeUtils.js +218 -1
  73. package/dist/utils/tool/AxisUtils.js +340 -1
  74. package/dist/utils/tool/CanvasUtils.js +62 -1
  75. package/dist/utils/tool/CommonToolUtils.js +174 -1
  76. package/dist/utils/tool/CuboidUtils.js +704 -1
  77. package/dist/utils/tool/DblClickEventListener.js +102 -1
  78. package/dist/utils/tool/DrawUtils.js +492 -3
  79. package/dist/utils/tool/EnhanceCommonToolUtils.js +53 -1
  80. package/dist/utils/tool/ImgPosUtils.js +58 -1
  81. package/dist/utils/tool/LineToolUtils.js +261 -1
  82. package/dist/utils/tool/MarkerUtils.js +56 -1
  83. package/dist/utils/tool/PolygonUtils.js +460 -1
  84. package/dist/utils/tool/RectUtils.js +155 -1
  85. package/dist/utils/tool/RenderDomClass.js +57 -7
  86. package/dist/utils/tool/RenderDomUtils.js +21 -4
  87. package/dist/utils/tool/StyleUtils.js +31 -1
  88. package/dist/utils/tool/TagUtils.js +129 -1
  89. package/dist/utils/tool/UnitUtils.js +12 -1
  90. package/dist/utils/tool/ZoomUtils.js +72 -1
  91. package/dist/utils/tool/polygonTool.js +133 -1
  92. package/dist/utils/uuid.js +26 -1
  93. package/es/_virtual/MathUtilsWorker.js +6 -1
  94. package/es/_virtual/_rollup-plugin-web-worker-loader__helper__auto__createBase64WorkerFactory.js +12 -0
  95. package/es/_virtual/_rollup-plugin-web-worker-loader__helper__auto__isNodeJS.js +7 -0
  96. package/es/_virtual/_rollup-plugin-web-worker-loader__helper__browser__createBase64WorkerFactory.js +31 -2
  97. package/es/_virtual/_rollup-plugin-web-worker-loader__helper__node__WorkerClass.js +11 -0
  98. package/es/_virtual/_rollup-plugin-web-worker-loader__helper__node__createBase64WorkerFactory.js +18 -0
  99. package/es/_virtual/filterBoxWorker.js +6 -1
  100. package/es/_virtual/highlightWorker.js +6 -1
  101. package/es/assets/attributeIcon/icon_canvasEdit0.svg.js +3 -1
  102. package/es/assets/attributeIcon/icon_canvasEdit1.svg.js +3 -1
  103. package/es/assets/attributeIcon/icon_canvasEdit2.svg.js +3 -1
  104. package/es/assets/attributeIcon/icon_canvasEdit3.svg.js +3 -1
  105. package/es/assets/attributeIcon/icon_canvasEdit4.svg.js +3 -1
  106. package/es/assets/attributeIcon/icon_canvasEdit5.svg.js +3 -1
  107. package/es/assets/attributeIcon/icon_canvasEdit6.svg.js +3 -1
  108. package/es/assets/attributeIcon/icon_canvasEdit7.svg.js +3 -1
  109. package/es/assets/attributeIcon/icon_canvasEdit8.svg.js +3 -1
  110. package/es/assets/attributeIcon/icon_canvasEdit_miss.svg.js +3 -1
  111. package/es/assets/attributeIcon/icon_cuboidFAB.svg.js +3 -5
  112. package/es/assets/attributeIcon/icon_cuboidLeft.svg.js +3 -7
  113. package/es/assets/attributeIcon/icon_cuboidMore.svg.js +3 -5
  114. package/es/assets/attributeIcon/icon_cuboidRight.svg.js +3 -5
  115. package/es/assets/attributeIcon/icon_cuboidTop.svg.js +3 -12
  116. package/es/assets/attributeIcon/icon_editFEN.svg.js +3 -1
  117. package/es/assets/attributeIcon/icon_editHUANG.svg.js +3 -1
  118. package/es/assets/attributeIcon/icon_editLAN.svg.js +3 -1
  119. package/es/assets/attributeIcon/icon_editLV.svg.js +3 -1
  120. package/es/assets/attributeIcon/icon_editQING.svg.js +3 -1
  121. package/es/constant/annotation.js +113 -1
  122. package/es/constant/annotationTask.js +25 -1
  123. package/es/constant/defaultConfig.js +260 -1
  124. package/es/constant/keyCode.js +36 -1
  125. package/es/constant/style.js +74 -1
  126. package/es/constant/tool.js +220 -1
  127. package/es/core/index.js +148 -1
  128. package/es/core/pointCloud/OrbitControls.js +661 -1
  129. package/es/core/pointCloud/PCDLoader.js +256 -2
  130. package/es/core/pointCloud/annotation.js +211 -1
  131. package/es/core/pointCloud/cache.js +49 -1
  132. package/es/core/pointCloud/index.js +962 -5
  133. package/es/core/pointCloud/matrix.js +109 -1
  134. package/es/core/pointCloud/segmentation.js +120 -0
  135. package/es/core/pointCloud/selector/Sse3dLassoSelector.js +24 -0
  136. package/es/core/pointCloud/selector/Sse3dSelector.js +14 -0
  137. package/es/core/scheduler.js +228 -1
  138. package/es/core/toolOperation/LineToolOperation.js +1421 -1
  139. package/es/core/toolOperation/ScribbleTool.js +290 -1
  140. package/es/core/toolOperation/TextToolOperation.js +129 -1
  141. package/es/core/toolOperation/ViewOperation.js +549 -1
  142. package/es/core/toolOperation/basicToolOperation.js +877 -1
  143. package/es/core/toolOperation/checkOperation.js +206 -1
  144. package/es/core/toolOperation/cuboidOperation.js +752 -1
  145. package/es/core/toolOperation/cuboidToggleButtonClass.js +150 -7
  146. package/es/core/toolOperation/eventListener.js +35 -1
  147. package/es/core/toolOperation/measureOperation.js +39 -1
  148. package/es/core/toolOperation/pointCloud2dOperation.js +359 -1
  149. package/es/core/toolOperation/pointOperation.js +690 -1
  150. package/es/core/toolOperation/polygonOperation.js +1245 -1
  151. package/es/core/toolOperation/rectOperation.js +1228 -1
  152. package/es/core/toolOperation/scribbleTool2.js +249 -0
  153. package/es/core/toolOperation/segmentByRect.js +172 -1
  154. package/es/core/toolOperation/tagOperation.js +199 -3
  155. package/es/core/toolOperation/textAttributeClass.js +180 -16
  156. package/es/index.js +46 -1
  157. package/es/locales/constants.js +22 -1
  158. package/es/locales/en_US/message.js +23 -1
  159. package/es/locales/index.js +17 -1
  160. package/es/locales/zh_CN/message.js +23 -1
  161. package/es/newCore/CanvasScheduler.js +31 -1
  162. package/es/utils/ActionsHistory.js +78 -1
  163. package/es/utils/ImgUtils.js +21 -1
  164. package/es/utils/MathUtils.js +380 -2
  165. package/es/utils/VectorUtils.js +23 -1
  166. package/es/utils/tool/AttributeUtils.js +212 -1
  167. package/es/utils/tool/AxisUtils.js +335 -1
  168. package/es/utils/tool/CanvasUtils.js +60 -1
  169. package/es/utils/tool/CommonToolUtils.js +172 -1
  170. package/es/utils/tool/CuboidUtils.js +680 -1
  171. package/es/utils/tool/DblClickEventListener.js +100 -1
  172. package/es/utils/tool/DrawUtils.js +490 -3
  173. package/es/utils/tool/EnhanceCommonToolUtils.js +48 -1
  174. package/es/utils/tool/ImgPosUtils.js +56 -1
  175. package/es/utils/tool/LineToolUtils.js +255 -1
  176. package/es/utils/tool/MarkerUtils.js +54 -1
  177. package/es/utils/tool/PolygonUtils.js +458 -1
  178. package/es/utils/tool/RectUtils.js +153 -1
  179. package/es/utils/tool/RenderDomClass.js +55 -7
  180. package/es/utils/tool/RenderDomUtils.js +19 -4
  181. package/es/utils/tool/StyleUtils.js +29 -1
  182. package/es/utils/tool/TagUtils.js +127 -1
  183. package/es/utils/tool/UnitUtils.js +10 -1
  184. package/es/utils/tool/ZoomUtils.js +70 -1
  185. package/es/utils/tool/polygonTool.js +126 -1
  186. package/es/utils/uuid.js +24 -1
  187. package/package.json +7 -5
@@ -1 +1,109 @@
1
- import*as p from"three";import{MatrixUtils as x,PointCloudUtils as w}from"@labelbee/lb-utils";import _ from"../../utils/uuid.js";var g=Object.defineProperty,h=Object.defineProperties,z=Object.getOwnPropertyDescriptors,m=Object.getOwnPropertySymbols,O=Object.prototype.hasOwnProperty,T=Object.prototype.propertyIsEnumerable,M=(r,t,e)=>t in r?g(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,P=(r,t)=>{for(var e in t||(t={}))O.call(t,e)&&M(r,e,t[e]);if(m)for(var e of m(t))T.call(t,e)&&M(r,e,t[e]);return r},V=(r,t)=>h(r,z(t));function u(r){return new p.Matrix4().set(...r)}function d(r,t,e){const o=x.transferMatrix34FromKitti2Three(r),n=x.transferMatrix33FromKitti2Three(t),a=x.transferMatrix34FromKitti2Three(e),l=u(o),c=u(n),s=u(a);return{composeMatrix4:s.clone().premultiply(c).premultiply(l),PM:l,RM:c,TM:s}}function y(r,t,e){var o;const n=new p.Vector3(r.x,r.y,(o=r==null?void 0:r.z)!=null?o:1),a=new p.Matrix4().makeRotationZ(e),l=new p.Matrix4().makeTranslation(t.x,t.y,t.z),c=new p.Matrix4().makeTranslation(-t.x,-t.y,-t.z);return n.clone().applyMatrix4(c).applyMatrix4(a).applyMatrix4(l)}function v(r,t){const o=new p.Vector4(r.x,r.y,r.z).applyMatrix4(t);if(o.z<0)return;const n=1/o.z,a=new p.Matrix4().set(n,0,0,0,0,n,0,0,0,0,n,0,0,0,0,1);return o.applyMatrix4(a)}function R(r){const{center:t,width:e,height:o,depth:n,rotation:a}=r,l=[{x:t.x+e/2,y:t.y-o/2},{x:t.x+e/2,y:t.y+o/2},{x:t.x-e/2,y:t.y+o/2},{x:t.x-e/2,y:t.y-o/2}].map(i=>{const f=y(i,t,a);return{x:f.x,y:f.y}}),c=t.z+n/2,s=t.z-n/2;return V(P({},r),{polygonPointList:l,zMax:c,zMin:s})}function b(r,t){const e=w.getAllViewData(r),{P:o,R:n,T:a}=t,{composeMatrix4:l}=d(o,n,a);return e.map(s=>({type:s.type,pointList:s.pointList.map(i=>y(i,r.center,r.rotation)).map(i=>v(i,l)).map(i=>{if(!!i)return{id:_(),x:i==null?void 0:i.x,y:i==null?void 0:i.y}}).filter(i=>i!==void 0)})).filter(s=>s.pointList.length!==0)}export{u as createThreeMatrix4,R as getCuboidFromPointCloudBox,v as lidar2image,b as pointCloudLidar2image,y as rotatePoint,d as transferKitti2Matrix};
1
+ import * as THREE from 'three';
2
+ import { MatrixUtils, PointCloudUtils } from '@labelbee/lb-utils';
3
+ import uuid from '../../utils/uuid.js';
4
+
5
+ var __defProp = Object.defineProperty;
6
+ var __defProps = Object.defineProperties;
7
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
8
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
9
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
10
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
11
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, {enumerable: true, configurable: true, writable: true, value}) : obj[key] = value;
12
+ var __spreadValues = (a, b) => {
13
+ for (var prop in b || (b = {}))
14
+ if (__hasOwnProp.call(b, prop))
15
+ __defNormalProp(a, prop, b[prop]);
16
+ if (__getOwnPropSymbols)
17
+ for (var prop of __getOwnPropSymbols(b)) {
18
+ if (__propIsEnum.call(b, prop))
19
+ __defNormalProp(a, prop, b[prop]);
20
+ }
21
+ return a;
22
+ };
23
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
24
+ function createThreeMatrix4(matrix4) {
25
+ return new THREE.Matrix4().set(...matrix4);
26
+ }
27
+ function transferKitti2Matrix(P, R, T) {
28
+ const PMA = MatrixUtils.transferMatrix34FromKitti2Three(P);
29
+ const RMA = MatrixUtils.transferMatrix33FromKitti2Three(R);
30
+ const TMA = MatrixUtils.transferMatrix34FromKitti2Three(T);
31
+ const PM = createThreeMatrix4(PMA);
32
+ const RM = createThreeMatrix4(RMA);
33
+ const TM = createThreeMatrix4(TMA);
34
+ return {
35
+ composeMatrix4: TM.clone().premultiply(RM).premultiply(PM),
36
+ PM,
37
+ RM,
38
+ TM
39
+ };
40
+ }
41
+ function rotatePoint(points, centerPoint, rotationZ) {
42
+ var _a;
43
+ const pointVector = new THREE.Vector3(points.x, points.y, (_a = points == null ? void 0 : points.z) != null ? _a : 1);
44
+ const Rz = new THREE.Matrix4().makeRotationZ(rotationZ);
45
+ const TFrom = new THREE.Matrix4().makeTranslation(centerPoint.x, centerPoint.y, centerPoint.z);
46
+ const TBack = new THREE.Matrix4().makeTranslation(-centerPoint.x, -centerPoint.y, -centerPoint.z);
47
+ return pointVector.clone().applyMatrix4(TBack).applyMatrix4(Rz).applyMatrix4(TFrom);
48
+ }
49
+ function lidar2image(point, composeMatrix4) {
50
+ const vector = new THREE.Vector4(point.x, point.y, point.z);
51
+ const newV = vector.applyMatrix4(composeMatrix4);
52
+ if (newV.z < 0) {
53
+ return void 0;
54
+ }
55
+ const z = 1 / newV.z;
56
+ const fixMatrix4 = new THREE.Matrix4().set(z, 0, 0, 0, 0, z, 0, 0, 0, 0, z, 0, 0, 0, 0, 1);
57
+ return newV.applyMatrix4(fixMatrix4);
58
+ }
59
+ function getCuboidFromPointCloudBox(boxParams) {
60
+ const {center, width, height, depth, rotation} = boxParams;
61
+ const polygonPointList = [
62
+ {
63
+ x: center.x + width / 2,
64
+ y: center.y - height / 2
65
+ },
66
+ {
67
+ x: center.x + width / 2,
68
+ y: center.y + height / 2
69
+ },
70
+ {
71
+ x: center.x - width / 2,
72
+ y: center.y + height / 2
73
+ },
74
+ {
75
+ x: center.x - width / 2,
76
+ y: center.y - height / 2
77
+ }
78
+ ].map((v) => {
79
+ const vector = rotatePoint(v, center, rotation);
80
+ return {
81
+ x: vector.x,
82
+ y: vector.y
83
+ };
84
+ });
85
+ const zMax = center.z + depth / 2;
86
+ const zMin = center.z - depth / 2;
87
+ return __spreadProps(__spreadValues({}, boxParams), {
88
+ polygonPointList,
89
+ zMax,
90
+ zMin
91
+ });
92
+ }
93
+ function pointCloudLidar2image(boxParams, cameraMatrix) {
94
+ const allViewData = PointCloudUtils.getAllViewData(boxParams);
95
+ const {P, R, T} = cameraMatrix;
96
+ const {composeMatrix4} = transferKitti2Matrix(P, R, T);
97
+ const transferViewData = allViewData.map((viewData) => ({
98
+ type: viewData.type,
99
+ pointList: viewData.pointList.map((point) => rotatePoint(point, boxParams.center, boxParams.rotation)).map((point) => lidar2image(point, composeMatrix4)).map((point) => {
100
+ if (!point) {
101
+ return void 0;
102
+ }
103
+ return {id: uuid(), x: point == null ? void 0 : point.x, y: point == null ? void 0 : point.y};
104
+ }).filter((v) => v !== void 0)
105
+ })).filter((v) => v.pointList.length !== 0);
106
+ return transferViewData;
107
+ }
108
+
109
+ export { createThreeMatrix4, getCuboidFromPointCloudBox, lidar2image, pointCloudLidar2image, rotatePoint, transferKitti2Matrix };
@@ -0,0 +1,120 @@
1
+ import DrawUtils from '../../utils/tool/DrawUtils.js';
2
+ import * as THREE from 'three';
3
+ import Sse3dLassoSelector from './selector/Sse3dLassoSelector.js';
4
+
5
+ class PointCloudSegmentOperation {
6
+ constructor(props) {
7
+ this.pointer = new THREE.Vector2();
8
+ this._forbidRender = false;
9
+ this.polygon = [];
10
+ this.startX = NaN;
11
+ this.startY = NaN;
12
+ this.onMouseMove = (iev) => {
13
+ const coord = this.getCoordinate(iev);
14
+ this.pointer.x = coord.x / this.dom.clientWidth * 2 - 1;
15
+ this.pointer.y = -(coord.y / this.dom.clientHeight) * 2 + 1;
16
+ const ev = {
17
+ offsetX: iev.offsetX,
18
+ offsetY: iev.offsetY,
19
+ pageX: iev.pageX,
20
+ pageY: iev.pageY,
21
+ which: iev.buttons === 2 ? 3 : 0
22
+ };
23
+ this.selector.mouseDrag(ev);
24
+ };
25
+ this.onMouseDown = (iev) => {
26
+ this._forbidRender = true;
27
+ const ev = {
28
+ offsetX: iev.offsetX,
29
+ offsetY: iev.offsetY,
30
+ pageX: iev.pageX,
31
+ pageY: iev.pageY,
32
+ which: iev.buttons === 2 ? 3 : 0
33
+ };
34
+ this.selector.mouseDown(ev);
35
+ };
36
+ this.onMouseUp = (iev) => {
37
+ const ev = {
38
+ offsetX: iev.offsetX,
39
+ offsetY: iev.offsetY,
40
+ pageX: iev.pageX,
41
+ pageY: iev.pageY,
42
+ which: iev.buttons === 2 ? 3 : 0
43
+ };
44
+ this.selector.mouseUp(ev);
45
+ };
46
+ this.render = ({camera, scene}) => {
47
+ const originPolygon = this.selector.polygon;
48
+ const polygon = [];
49
+ if (originPolygon.length > 0 && this.mouseCanvas) {
50
+ for (let i = 0; i < originPolygon.length; i += 2) {
51
+ polygon.push({
52
+ x: originPolygon[i * 2],
53
+ y: originPolygon[i * 2 + 1]
54
+ });
55
+ }
56
+ console.log("polygon", polygon);
57
+ DrawUtils.drawPolygon(this.mouseCanvas, polygon, {isClose: false, color: "red"});
58
+ }
59
+ };
60
+ this.dom = props.dom;
61
+ this.selector = new Sse3dLassoSelector(this);
62
+ const canvas = document.createElement("canvas");
63
+ canvas.id = "canvasMouse";
64
+ this.updateCanvasBasicStyle(canvas, {width: this.dom.clientWidth, height: this.dom.clientHeight}, 10);
65
+ this.dom.appendChild(canvas);
66
+ canvas.addEventListener("pointermove", this.onMouseMove);
67
+ canvas.addEventListener("pointerdown", this.onMouseDown);
68
+ canvas.addEventListener("pointerup", this.onMouseUp);
69
+ canvas.oncontextmenu = (e) => {
70
+ e.preventDefault();
71
+ };
72
+ canvas.getContext("2d");
73
+ this.mouseCanvas = canvas;
74
+ this.getPointsInPolygon = props.getPointsInPolygon;
75
+ this.setupRaycaster();
76
+ const geometry = new THREE.BufferGeometry();
77
+ const pointsMaterial = new THREE.PointsMaterial({size: 10, color: "red"});
78
+ geometry.setAttribute("position", new THREE.BufferAttribute(new Float32Array([0, 0, 0]), 3));
79
+ this._highlight_Point = new THREE.Points(geometry, pointsMaterial);
80
+ this.emitRender = props.render;
81
+ const geometry2 = new THREE.BufferGeometry();
82
+ const pointsMaterial2 = new THREE.PointsMaterial({size: 5, color: "white"});
83
+ geometry2.setAttribute("position", new THREE.BufferAttribute(new Float32Array([0, 0, 0]), 3));
84
+ this._temp = new THREE.Points(geometry2, pointsMaterial2);
85
+ }
86
+ updateCanvasBasicStyle(canvas, size, zIndex) {
87
+ const pixel = 2;
88
+ canvas.style.position = "absolute";
89
+ canvas.width = size.width * pixel;
90
+ canvas.height = size.height * pixel;
91
+ canvas.style.width = `${size.width}px`;
92
+ canvas.style.height = `${size.height}px`;
93
+ canvas.style.left = "0";
94
+ canvas.style.top = "0";
95
+ canvas.style.zIndex = `${zIndex} `;
96
+ }
97
+ addMorePoint(scene) {
98
+ scene.add(this._highlight_Point);
99
+ scene.add(this._temp);
100
+ }
101
+ getCoordinate(e) {
102
+ const bounding = this.dom.getBoundingClientRect();
103
+ return {
104
+ x: e.clientX - bounding.left,
105
+ y: e.clientY - bounding.top
106
+ };
107
+ }
108
+ setupRaycaster() {
109
+ const boundingBox = {x: 10, y: 10, z: 10};
110
+ const numberOfPoints = 10;
111
+ this.raycaster = new THREE.Raycaster();
112
+ const threshold = Math.cbrt(boundingBox.x * boundingBox.y * boundingBox.z / numberOfPoints) / 3;
113
+ if (this.raycaster) {
114
+ this.raycaster.params.Points.threshold = threshold;
115
+ this.raycaster.linePrecision = 0.1;
116
+ }
117
+ }
118
+ }
119
+
120
+ export { PointCloudSegmentOperation };
@@ -0,0 +1,24 @@
1
+ import Sse3dSelector from './Sse3dSelector.js';
2
+
3
+ class Sse3dLassoSelector extends Sse3dSelector {
4
+ mouseDown(ev) {
5
+ if (ev.which === 3) {
6
+ this.pushPoint(ev.offsetX, ev.offsetY);
7
+ }
8
+ }
9
+ mouseUp(ev) {
10
+ if (ev.which === 3) {
11
+ this.scene.getPointsInPolygon(this.polygon);
12
+ this.polygon.length = 0;
13
+ }
14
+ }
15
+ mouseDrag(ev) {
16
+ console.log("ev", ev.which);
17
+ if (ev.which === 3) {
18
+ this.pushPoint(ev.offsetX, ev.offsetY);
19
+ this.scene.emitRender(true);
20
+ }
21
+ }
22
+ }
23
+
24
+ export { Sse3dLassoSelector as default };
@@ -0,0 +1,14 @@
1
+ class Sse3dSelector {
2
+ constructor(scene) {
3
+ this.scene = scene;
4
+ this.polygon = [];
5
+ }
6
+ pushPoint(x, y) {
7
+ this.polygon.push([x, y]);
8
+ }
9
+ deactivate() {
10
+ this.polygon.length = 0;
11
+ }
12
+ }
13
+
14
+ export { Sse3dSelector as default };
@@ -1 +1,228 @@
1
- import{getConfig as f,styleDefaultConfig as L}from"../constant/defaultConfig.js";import{getCurrentOperation as y}from"../utils/tool/EnhanceCommonToolUtils.js";import{BasicToolOperation as v}from"./toolOperation/basicToolOperation.js";const D=e=>{const t=document.createElement("canvas");t.width=e.width,t.height=e.height;const i=t.getContext("2d");return i?(i.fillStyle="transparent",i.fillRect(0,0,e.width,e.height),t.toDataURL()):""},p=(e,t,i)=>{const o=e[t];return e[t]=e[i],e[i]=o,e},g=class{static isSingleTool(e){return!this.isHybridTool(e)}static isHybridTool(e){return Array.isArray(e)}};let u=g;u.getTopToolName=e=>g.isHybridTool(e)?e[e.length-1]:e;class I{constructor(t){this.toolOperationList=[],this.toolOperationDom=[],this.toolOperationNameList=[];var i,o;this.init(),this.container=t.container,this.size=t.size,this.imgNode=t.imgNode,this.config=(i=t.config)!=null?i:JSON.stringify(f(u.getTopToolName(t.toolName))),this.style=(o=t.style)!=null?o:L}setImgNode(t,i){this.toolOperationList.forEach(o=>{o.setImgNode(t,i)})}setImgAttribute(t){this.toolOperationList.forEach(i=>{i.setImgAttribute(t)})}setSize(t){this.toolOperationList.forEach(i=>{i.setSize(t)})}syncPosition(t,i,o,s){this.toolOperationList.forEach(a=>{s!==a&&(a.setCurrentPos(t),a.setZoom(i),a.setImgInfo(o),a.renderBasicCanvas(),a.render())})}get defaultSize(){var t,i;return{width:((t=this.imgNode)==null?void 0:t.width)||this.size.width,height:((i=this.imgNode)==null?void 0:i.height)||this.size.height}}createDom(){const{width:t,height:i}=this.defaultSize,o=window.document.createElement("div");o.style.position="absolute",o.style.left="0",o.style.top="0",o.style.width=`${t}px`,o.style.height=`${i}px`;const s=this.toolOperationList.length+1;return o.style.zIndex=`${s}`,o}getEmptyImage(t,i){const o=D({width:t,height:i}),s=new Image;return s.src=o,s}createOperation(t,i,o){var s;const{width:a,height:l}=this.defaultSize,r=this.createDom(),d=this.getEmptyImage(a,l),h={container:r,size:this.size,config:(s=this==null?void 0:this.config)!=null?s:"{}",drawOutSideTarget:!1,style:this.style,imgNode:i||d,hiddenImg:!!t};o&&Object.assign(h,o);let n;if(!t)n=new v(h),r.style.zIndex="0",n.init();else{const c=y(t);if(!c)return;n=new c(h)}return n==null||n.init(),n.canvas.id=t!=null?t:"basicCanvas",n.on("dragMove",({currentPos:c,zoom:m,imgInfo:O})=>{this.syncPosition(c,m,O,n)}),n.on("renderZoom",(c,m,O)=>{c&&m&&this.syncPosition(m,c,O,n)}),t?(this.container.appendChild(r),this.toolOperationList.push(n),this.toolOperationNameList.push(t),this.toolOperationDom.push(r),n):(this.container.insertBefore(r,this.container.childNodes[0]),this.toolOperationList.unshift(n),this.toolOperationDom.unshift(r),n)}switchLastTwoCanvas(){if(this.toolOperationDom.length<3){console.error("switchLastTwoCanvas is just used the layer which has 3 canvas");return}const t=this.toolOperationDom.length,i=t-1,o=t-2,s=this.toolOperationDom[i],a=this.toolOperationDom[o];if(!(!a||!s))return s.style.zIndex=`${i-1}`,a.style.zIndex=`${i}`,this.toolOperationList[i].clearActiveStatus(),this.toolOperationList[i].clearCursorLine(),this.toolOperationList[i].render(),this.toolOperationList=p(this.toolOperationList,i,o),this.toolOperationDom=p(this.toolOperationDom,i,o),this.toolOperationList[i]}getFirstToolOperation(){return this.toolOperationList.length>1?this.toolOperationList[1]:this.toolOperationList[0]}switchToCanvas(t){var i,o,s,a;const l=this.toolOperationNameList.indexOf(t);if(l<0||this.toolOperationList.length<1||l>this.toolOperationDom.length-1)return;const r=this.toolOperationDom.length-1,d=this.toolOperationDom[l],h=this.toolOperationDom[r];if(!d||!h)return;const n=h.style.zIndex;return h.style.zIndex=`${d.style.zIndex}`,d.style.zIndex=`${n}`,(o=(i=this.toolOperationList[r]).clearActiveStatus)==null||o.call(i),(a=(s=this.toolOperationList[r]).clearCursorLine)==null||a.call(s),this.toolOperationList[r].render(),this.toolOperationList=p(this.toolOperationList,r,l),this.toolOperationDom=p(this.toolOperationDom,r,l),this.toolOperationNameList=p(this.toolOperationNameList,r,l),this.toolOperationList[r]}updateDataByToolName(t,i){const o=this.toolOperationNameList.indexOf(t);o>=0&&this.toolOperationList[o].setResult(i)}clearStatusAndResult(){this.toolOperationList.forEach(t=>{var i;(i=t.clearActiveStatus)==null||i.call(t),t.clearResult()})}destroyAllLayer(){this.toolOperationList.forEach(t=>{t.destroyCanvas(),this.init()})}init(){this.toolOperationList=[],this.toolOperationDom=[]}}export{u as HybridToolUtils,I as ToolScheduler};
1
+ import { getConfig, styleDefaultConfig } from '../constant/defaultConfig.js';
2
+ import { getCurrentOperation } from '../utils/tool/EnhanceCommonToolUtils.js';
3
+ import { BasicToolOperation } from './toolOperation/basicToolOperation.js';
4
+
5
+ const createEmptyImage = (size) => {
6
+ const canvas = document.createElement("canvas");
7
+ canvas.width = size.width;
8
+ canvas.height = size.height;
9
+ const ctx = canvas.getContext("2d");
10
+ if (ctx) {
11
+ ctx.fillStyle = "transparent";
12
+ ctx.fillRect(0, 0, size.width, size.height);
13
+ return canvas.toDataURL();
14
+ }
15
+ return "";
16
+ };
17
+ const arraySwap = (array, index1, index2) => {
18
+ const a = array[index1];
19
+ array[index1] = array[index2];
20
+ array[index2] = a;
21
+ return array;
22
+ };
23
+ const _HybridToolUtils = class {
24
+ static isSingleTool(toolName) {
25
+ return !this.isHybridTool(toolName);
26
+ }
27
+ static isHybridTool(toolName) {
28
+ return Array.isArray(toolName);
29
+ }
30
+ };
31
+ let HybridToolUtils = _HybridToolUtils;
32
+ HybridToolUtils.getTopToolName = (toolName) => {
33
+ return _HybridToolUtils.isHybridTool(toolName) ? toolName[toolName.length - 1] : toolName;
34
+ };
35
+ class ToolScheduler {
36
+ constructor(props) {
37
+ this.toolOperationList = [];
38
+ this.toolOperationDom = [];
39
+ this.toolOperationNameList = [];
40
+ var _a, _b;
41
+ this.init();
42
+ this.container = props.container;
43
+ this.size = props.size;
44
+ this.imgNode = props.imgNode;
45
+ this.config = (_a = props.config) != null ? _a : JSON.stringify(getConfig(HybridToolUtils.getTopToolName(props.toolName)));
46
+ this.style = (_b = props.style) != null ? _b : styleDefaultConfig;
47
+ }
48
+ setImgNode(imgNode, basicImgInfo) {
49
+ this.toolOperationList.forEach((toolInstance) => {
50
+ toolInstance.setImgNode(imgNode, basicImgInfo);
51
+ });
52
+ }
53
+ setImgAttribute(imgAttribute) {
54
+ this.toolOperationList.forEach((toolInstance) => {
55
+ toolInstance.setImgAttribute(imgAttribute);
56
+ });
57
+ }
58
+ setSize(size) {
59
+ this.toolOperationList.forEach((toolInstance) => {
60
+ toolInstance.setSize(size);
61
+ });
62
+ }
63
+ syncPosition(currentPos, zoom, imgInfo, currentToolInstance) {
64
+ this.toolOperationList.forEach((toolInstance) => {
65
+ if (currentToolInstance === toolInstance) {
66
+ return;
67
+ }
68
+ toolInstance.setCurrentPos(currentPos);
69
+ toolInstance.setZoom(zoom);
70
+ toolInstance.setImgInfo(imgInfo);
71
+ toolInstance.renderBasicCanvas();
72
+ toolInstance.render();
73
+ });
74
+ }
75
+ get defaultSize() {
76
+ var _a, _b;
77
+ return {
78
+ width: ((_a = this.imgNode) == null ? void 0 : _a.width) || this.size.width,
79
+ height: ((_b = this.imgNode) == null ? void 0 : _b.height) || this.size.height
80
+ };
81
+ }
82
+ createDom() {
83
+ const {width, height} = this.defaultSize;
84
+ const dom = window.document.createElement("div");
85
+ dom.style.position = "absolute";
86
+ dom.style.left = "0";
87
+ dom.style.top = "0";
88
+ dom.style.width = `${width}px`;
89
+ dom.style.height = `${height}px`;
90
+ const zIndex = this.toolOperationList.length + 1;
91
+ dom.style.zIndex = `${zIndex}`;
92
+ return dom;
93
+ }
94
+ getEmptyImage(width, height) {
95
+ const imgSrc = createEmptyImage({width, height});
96
+ const emptyImgNode = new Image();
97
+ emptyImgNode.src = imgSrc;
98
+ return emptyImgNode;
99
+ }
100
+ createOperation(tool, imgNode, config) {
101
+ var _a;
102
+ const {width, height} = this.defaultSize;
103
+ const dom = this.createDom();
104
+ const emptyImgNode = this.getEmptyImage(width, height);
105
+ const defaultData = {
106
+ container: dom,
107
+ size: this.size,
108
+ config: (_a = this == null ? void 0 : this.config) != null ? _a : "{}",
109
+ drawOutSideTarget: false,
110
+ style: this.style,
111
+ imgNode: imgNode || emptyImgNode,
112
+ hiddenImg: !!tool
113
+ };
114
+ if (config) {
115
+ Object.assign(defaultData, config);
116
+ }
117
+ let toolInstance;
118
+ if (!tool) {
119
+ toolInstance = new BasicToolOperation(defaultData);
120
+ dom.style.zIndex = "0";
121
+ toolInstance.init();
122
+ } else {
123
+ const ToolOperation = getCurrentOperation(tool);
124
+ if (!ToolOperation) {
125
+ return;
126
+ }
127
+ toolInstance = new ToolOperation(defaultData);
128
+ }
129
+ toolInstance == null ? void 0 : toolInstance.init();
130
+ toolInstance.canvas.id = tool != null ? tool : "basicCanvas";
131
+ toolInstance.on("dragMove", ({currentPos, zoom, imgInfo}) => {
132
+ this.syncPosition(currentPos, zoom, imgInfo, toolInstance);
133
+ });
134
+ toolInstance.on("renderZoom", (zoom, currentPos, imgInfo) => {
135
+ if (zoom && currentPos) {
136
+ this.syncPosition(currentPos, zoom, imgInfo, toolInstance);
137
+ }
138
+ });
139
+ if (!tool) {
140
+ this.container.insertBefore(dom, this.container.childNodes[0]);
141
+ this.toolOperationList.unshift(toolInstance);
142
+ this.toolOperationDom.unshift(dom);
143
+ return toolInstance;
144
+ }
145
+ this.container.appendChild(dom);
146
+ this.toolOperationList.push(toolInstance);
147
+ this.toolOperationNameList.push(tool);
148
+ this.toolOperationDom.push(dom);
149
+ return toolInstance;
150
+ }
151
+ switchLastTwoCanvas() {
152
+ if (this.toolOperationDom.length < 3) {
153
+ console.error("switchLastTwoCanvas is just used the layer which has 3 canvas");
154
+ return;
155
+ }
156
+ const len = this.toolOperationDom.length;
157
+ const lastOneIndex = len - 1;
158
+ const last2SecondIndex = len - 2;
159
+ const lastOneDom = this.toolOperationDom[lastOneIndex];
160
+ const last2SecondDom = this.toolOperationDom[last2SecondIndex];
161
+ if (!last2SecondDom || !lastOneDom) {
162
+ return;
163
+ }
164
+ lastOneDom.style.zIndex = `${lastOneIndex - 1}`;
165
+ last2SecondDom.style.zIndex = `${lastOneIndex}`;
166
+ this.toolOperationList[lastOneIndex].clearActiveStatus();
167
+ this.toolOperationList[lastOneIndex].clearCursorLine();
168
+ this.toolOperationList[lastOneIndex].render();
169
+ this.toolOperationList = arraySwap(this.toolOperationList, lastOneIndex, last2SecondIndex);
170
+ this.toolOperationDom = arraySwap(this.toolOperationDom, lastOneIndex, last2SecondIndex);
171
+ return this.toolOperationList[lastOneIndex];
172
+ }
173
+ getFirstToolOperation() {
174
+ if (this.toolOperationList.length > 1) {
175
+ return this.toolOperationList[1];
176
+ }
177
+ return this.toolOperationList[0];
178
+ }
179
+ switchToCanvas(toolName) {
180
+ var _a, _b, _c, _d;
181
+ const chosenIndex = this.toolOperationNameList.indexOf(toolName);
182
+ if (chosenIndex < 0 || this.toolOperationList.length < 1 || chosenIndex > this.toolOperationDom.length - 1) {
183
+ return;
184
+ }
185
+ const lastOneIndex = this.toolOperationDom.length - 1;
186
+ const chosenDom = this.toolOperationDom[chosenIndex];
187
+ const lastOneDom = this.toolOperationDom[lastOneIndex];
188
+ if (!chosenDom || !lastOneDom) {
189
+ return;
190
+ }
191
+ const temp = lastOneDom.style.zIndex;
192
+ lastOneDom.style.zIndex = `${chosenDom.style.zIndex}`;
193
+ chosenDom.style.zIndex = `${temp}`;
194
+ (_b = (_a = this.toolOperationList[lastOneIndex]).clearActiveStatus) == null ? void 0 : _b.call(_a);
195
+ (_d = (_c = this.toolOperationList[lastOneIndex]).clearCursorLine) == null ? void 0 : _d.call(_c);
196
+ this.toolOperationList[lastOneIndex].render();
197
+ this.toolOperationList = arraySwap(this.toolOperationList, lastOneIndex, chosenIndex);
198
+ this.toolOperationDom = arraySwap(this.toolOperationDom, lastOneIndex, chosenIndex);
199
+ this.toolOperationNameList = arraySwap(this.toolOperationNameList, lastOneIndex, chosenIndex);
200
+ return this.toolOperationList[lastOneIndex];
201
+ }
202
+ updateDataByToolName(toolName, result) {
203
+ const operationIndex = this.toolOperationNameList.indexOf(toolName);
204
+ if (operationIndex >= 0) {
205
+ const operationInstance = this.toolOperationList[operationIndex];
206
+ operationInstance.setResult(result);
207
+ }
208
+ }
209
+ clearStatusAndResult() {
210
+ this.toolOperationList.forEach((toolInstance) => {
211
+ var _a;
212
+ (_a = toolInstance.clearActiveStatus) == null ? void 0 : _a.call(toolInstance);
213
+ toolInstance.clearResult();
214
+ });
215
+ }
216
+ destroyAllLayer() {
217
+ this.toolOperationList.forEach((toolInstance) => {
218
+ toolInstance.destroyCanvas();
219
+ this.init();
220
+ });
221
+ }
222
+ init() {
223
+ this.toolOperationList = [];
224
+ this.toolOperationDom = [];
225
+ }
226
+ }
227
+
228
+ export { HybridToolUtils, ToolScheduler };