@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,2 +1,256 @@
1
- import{Loader as z,FileLoader as C,LoaderUtils as v,BufferGeometry as _,Float32BufferAttribute as F,PointsMaterial as b,Points as L}from"three";import{COLOR_MAP_JET as B}from"@labelbee/lb-utils";class I extends z{constructor(a){super(a);this.littleEndian=!0}load(a,c,h,g){const i=this,l=new C(i.manager);l.setPath(i.path),l.setResponseType("arraybuffer"),l.setRequestHeader(i.requestHeader),l.setWithCredentials(i.withCredentials),l.load(a,function(d){try{c(i.parse(d))}catch(f){g?g(f):console.error(f),i.manager.itemError(a)}},h,g)}parse(a){function c(o,t){const p=o.length,n=new Uint8Array(t);let r=0,e=0,s,w,u;do if(s=o[r++],s<1<<5){if(s++,e+s>t)throw new Error("Output buffer is not large enough");if(r+s>p)throw new Error("Invalid compressed data");do n[e++]=o[r++];while(--s)}else{if(w=s>>5,u=e-((s&31)<<8)-1,r>=p)throw new Error("Invalid compressed data");if(w===7&&(w+=o[r++],r>=p))throw new Error("Invalid compressed data");if(u-=o[r++],e+w+2>t)throw new Error("Output buffer is not large enough");if(u<0)throw new Error("Invalid compressed data");if(u>=e)throw new Error("Invalid compressed data");do n[e++]=n[u++];while(--w+2)}while(r<p);return n}function h(o){const t={},p=o.search(/[\n\r]data\s(\S*)\s/i),n=/[\n\r]data\s(\S*)\s/i.exec(o.slice(p-1));if(t.data=n[1],t.headerLen=n[0].length+p,t.str=o.slice(0,t.headerLen),t.str=t.str.replace(/#.*/gi,""),t.version=/version (.*)/i.exec(t.str),t.fields=/fields (.*)/i.exec(t.str),t.size=/size (.*)/i.exec(t.str),t.type=/type (.*)/i.exec(t.str),t.count=/count (.*)/i.exec(t.str),t.width=/width (.*)/i.exec(t.str),t.height=/height (.*)/i.exec(t.str),t.viewpoint=/viewpoint (.*)/i.exec(t.str),t.points=/points (.*)/i.exec(t.str),t.version!==null&&(t.version=parseFloat(t.version[1])),t.fields=t.fields!==null?t.fields[1].split(" "):[],t.type!==null&&(t.type=t.type[1].split(" ")),t.width!==null&&(t.width=parseInt(t.width[1])),t.height!==null&&(t.height=parseInt(t.height[1])),t.viewpoint!==null&&(t.viewpoint=t.viewpoint[1]),t.points!==null&&(t.points=parseInt(t.points[1],10)),t.points===null&&(t.points=t.width*t.height),t.size!==null&&(t.size=t.size[1].split(" ").map(function(e){return parseInt(e,10)})),t.count!==null)t.count=t.count[1].split(" ").map(function(e){return parseInt(e,10)});else{t.count=[];for(let e=0,s=t.fields.length;e<s;e++)t.count.push(1)}t.offset={};let r=0;for(let e=0,s=t.fields.length;e<s;e++)t.data==="ascii"?t.offset[t.fields[e]]=e:(t.offset[t.fields[e]]=r,r+=t.size[e]*t.count[e]);return t.rowSize=r,t}const g=v.decodeText(new Uint8Array(a)),i=h(g),l=[],d=[],f=[];if(i.data==="ascii"){const{offset:o}=i,p=g.slice(i.headerLen).split(`
2
- `);for(let n=0,r=p.length;n<r;n++){if(p[n]==="")continue;const e=p[n].split(" ");if(o.x!==void 0&&(l.push(parseFloat(e[o.x])),l.push(parseFloat(e[o.y])),l.push(parseFloat(e[o.z]))),this.genColorByZ){const w=this.genColorByZ(parseFloat(e[o.x]),parseFloat(e[o.y]),parseFloat(e[o.z])).map(u=>u/255);f.push(...w)}o.normal_x!==void 0&&(d.push(parseFloat(e[o.normal_x])),d.push(parseFloat(e[o.normal_y])),d.push(parseFloat(e[o.normal_z])))}}if(i.data==="binary_compressed"){const o=new Uint32Array(a.slice(i.headerLen,i.headerLen+8)),t=o[0],p=o[1],n=c(new Uint8Array(a,i.headerLen+8,t),p),r=new DataView(n.buffer),{offset:e}=i;for(let s=0;s<i.points;s++)if(e.x!==void 0&&(l.push(r.getFloat32(i.points*e.x+i.size[0]*s,this.littleEndian)),l.push(r.getFloat32(i.points*e.y+i.size[1]*s,this.littleEndian)),l.push(r.getFloat32(i.points*e.z+i.size[2]*s,this.littleEndian))),e.normal_x!==void 0&&(d.push(r.getFloat32(i.points*e.normal_x+i.size[4]*s,this.littleEndian)),d.push(r.getFloat32(i.points*e.normal_y+i.size[5]*s,this.littleEndian)),d.push(r.getFloat32(i.points*e.normal_z+i.size[6]*s,this.littleEndian))),this.genColorByZ){const u=this.genColorByZ(r.getFloat32(i.points*e.x+i.size[0]*s,this.littleEndian),r.getFloat32(i.points*e.y+i.size[0]*s,this.littleEndian),r.getFloat32(i.points*e.z+i.size[0]*s,this.littleEndian)).map(E=>E/255);f.push(...u)}}if(i.data==="binary"){const o=new DataView(a,i.headerLen),{offset:t}=i;for(let p=0,n=0;p<i.points;p++,n+=i.rowSize)if(t.x!==void 0&&(l.push(o.getFloat32(n+t.x,this.littleEndian)),l.push(o.getFloat32(n+t.y,this.littleEndian)),l.push(o.getFloat32(n+t.z,this.littleEndian))),t.normal_x!==void 0&&(d.push(o.getFloat32(n+t.normal_x,this.littleEndian)),d.push(o.getFloat32(n+t.normal_y,this.littleEndian)),d.push(o.getFloat32(n+t.normal_z,this.littleEndian))),this.genColorByZ){const e=this.genColorByZ(o.getFloat32(n+t.x,this.littleEndian),o.getFloat32(n+t.y,this.littleEndian),o.getFloat32(n+t.z,this.littleEndian)).map(s=>s/255);f.push(...e)}}const x=new _;l.length>0&&x.setAttribute("position",new F(l,3)),d.length>0&&x.setAttribute("normal",new F(d,3)),f.length>0&&x.setAttribute("color",new F(f,3)),x.computeBoundingSphere();const y=new b({size:.01});return f.length>0?y.vertexColors=!0:y.color.setHex(16777215),new L(x,y)}genColorByCoord(a,c,h){return h<=0?[128,128,128]:h<5?[255,0,0]:h<10?[0,255,0]:[0,0,255]}genColorByZ(a,c,h){const g=Z(h),i=B[g];return[i[0],i[1],i[2]]}}function Z(m){const a=-7,c=3,h=c-a;return m<a&&(m=a),m>c&&(m=c),Math.floor((m-a)/h*255)}export{I as PCDLoader};
1
+ import { Loader, FileLoader, LoaderUtils, BufferGeometry, Float32BufferAttribute, PointsMaterial, Points } from 'three';
2
+ import { COLOR_MAP_JET } from '@labelbee/lb-utils';
3
+
4
+ class PCDLoader extends Loader {
5
+ constructor(manager) {
6
+ super(manager);
7
+ this.littleEndian = true;
8
+ }
9
+ load(url, onLoad, onProgress, onError) {
10
+ const scope = this;
11
+ const loader = new FileLoader(scope.manager);
12
+ loader.setPath(scope.path);
13
+ loader.setResponseType("arraybuffer");
14
+ loader.setRequestHeader(scope.requestHeader);
15
+ loader.setWithCredentials(scope.withCredentials);
16
+ loader.load(url, function(data) {
17
+ try {
18
+ onLoad(scope.parse(data));
19
+ } catch (e) {
20
+ if (onError) {
21
+ onError(e);
22
+ } else {
23
+ console.error(e);
24
+ }
25
+ scope.manager.itemError(url);
26
+ }
27
+ }, onProgress, onError);
28
+ }
29
+ parse(data) {
30
+ function decompressLZF(inData, outLength) {
31
+ const inLength = inData.length;
32
+ const outData = new Uint8Array(outLength);
33
+ let inPtr = 0;
34
+ let outPtr = 0;
35
+ let ctrl;
36
+ let len;
37
+ let ref;
38
+ do {
39
+ ctrl = inData[inPtr++];
40
+ if (ctrl < 1 << 5) {
41
+ ctrl++;
42
+ if (outPtr + ctrl > outLength)
43
+ throw new Error("Output buffer is not large enough");
44
+ if (inPtr + ctrl > inLength)
45
+ throw new Error("Invalid compressed data");
46
+ do {
47
+ outData[outPtr++] = inData[inPtr++];
48
+ } while (--ctrl);
49
+ } else {
50
+ len = ctrl >> 5;
51
+ ref = outPtr - ((ctrl & 31) << 8) - 1;
52
+ if (inPtr >= inLength)
53
+ throw new Error("Invalid compressed data");
54
+ if (len === 7) {
55
+ len += inData[inPtr++];
56
+ if (inPtr >= inLength)
57
+ throw new Error("Invalid compressed data");
58
+ }
59
+ ref -= inData[inPtr++];
60
+ if (outPtr + len + 2 > outLength)
61
+ throw new Error("Output buffer is not large enough");
62
+ if (ref < 0)
63
+ throw new Error("Invalid compressed data");
64
+ if (ref >= outPtr)
65
+ throw new Error("Invalid compressed data");
66
+ do {
67
+ outData[outPtr++] = outData[ref++];
68
+ } while (--len + 2);
69
+ }
70
+ } while (inPtr < inLength);
71
+ return outData;
72
+ }
73
+ function parseHeader(data2) {
74
+ const PCDheader2 = {};
75
+ const result1 = data2.search(/[\n\r]data\s(\S*)\s/i);
76
+ const result2 = /[\n\r]data\s(\S*)\s/i.exec(data2.slice(result1 - 1));
77
+ PCDheader2.data = result2[1];
78
+ PCDheader2.headerLen = result2[0].length + result1;
79
+ PCDheader2.str = data2.slice(0, PCDheader2.headerLen);
80
+ PCDheader2.str = PCDheader2.str.replace(/#.*/gi, "");
81
+ PCDheader2.version = /version (.*)/i.exec(PCDheader2.str);
82
+ PCDheader2.fields = /fields (.*)/i.exec(PCDheader2.str);
83
+ PCDheader2.size = /size (.*)/i.exec(PCDheader2.str);
84
+ PCDheader2.type = /type (.*)/i.exec(PCDheader2.str);
85
+ PCDheader2.count = /count (.*)/i.exec(PCDheader2.str);
86
+ PCDheader2.width = /width (.*)/i.exec(PCDheader2.str);
87
+ PCDheader2.height = /height (.*)/i.exec(PCDheader2.str);
88
+ PCDheader2.viewpoint = /viewpoint (.*)/i.exec(PCDheader2.str);
89
+ PCDheader2.points = /points (.*)/i.exec(PCDheader2.str);
90
+ if (PCDheader2.version !== null)
91
+ PCDheader2.version = parseFloat(PCDheader2.version[1]);
92
+ PCDheader2.fields = PCDheader2.fields !== null ? PCDheader2.fields[1].split(" ") : [];
93
+ if (PCDheader2.type !== null)
94
+ PCDheader2.type = PCDheader2.type[1].split(" ");
95
+ if (PCDheader2.width !== null)
96
+ PCDheader2.width = parseInt(PCDheader2.width[1]);
97
+ if (PCDheader2.height !== null)
98
+ PCDheader2.height = parseInt(PCDheader2.height[1]);
99
+ if (PCDheader2.viewpoint !== null)
100
+ PCDheader2.viewpoint = PCDheader2.viewpoint[1];
101
+ if (PCDheader2.points !== null)
102
+ PCDheader2.points = parseInt(PCDheader2.points[1], 10);
103
+ if (PCDheader2.points === null)
104
+ PCDheader2.points = PCDheader2.width * PCDheader2.height;
105
+ if (PCDheader2.size !== null) {
106
+ PCDheader2.size = PCDheader2.size[1].split(" ").map(function(x) {
107
+ return parseInt(x, 10);
108
+ });
109
+ }
110
+ if (PCDheader2.count !== null) {
111
+ PCDheader2.count = PCDheader2.count[1].split(" ").map(function(x) {
112
+ return parseInt(x, 10);
113
+ });
114
+ } else {
115
+ PCDheader2.count = [];
116
+ for (let i = 0, l = PCDheader2.fields.length; i < l; i++) {
117
+ PCDheader2.count.push(1);
118
+ }
119
+ }
120
+ PCDheader2.offset = {};
121
+ let sizeSum = 0;
122
+ for (let i = 0, l = PCDheader2.fields.length; i < l; i++) {
123
+ if (PCDheader2.data === "ascii") {
124
+ PCDheader2.offset[PCDheader2.fields[i]] = i;
125
+ } else {
126
+ PCDheader2.offset[PCDheader2.fields[i]] = sizeSum;
127
+ sizeSum += PCDheader2.size[i] * PCDheader2.count[i];
128
+ }
129
+ }
130
+ PCDheader2.rowSize = sizeSum;
131
+ return PCDheader2;
132
+ }
133
+ const textData = LoaderUtils.decodeText(new Uint8Array(data));
134
+ const PCDheader = parseHeader(textData);
135
+ const position = [];
136
+ const normal = [];
137
+ const color = [];
138
+ if (PCDheader.data === "ascii") {
139
+ const {offset} = PCDheader;
140
+ const pcdData = textData.slice(PCDheader.headerLen);
141
+ const lines = pcdData.split("\n");
142
+ for (let i = 0, l = lines.length; i < l; i++) {
143
+ if (lines[i] === "")
144
+ continue;
145
+ const line = lines[i].split(" ");
146
+ if (offset.x !== void 0) {
147
+ position.push(parseFloat(line[offset.x]));
148
+ position.push(parseFloat(line[offset.y]));
149
+ position.push(parseFloat(line[offset.z]));
150
+ }
151
+ if (this.genColorByZ) {
152
+ const pdColor = this.genColorByZ(parseFloat(line[offset.x]), parseFloat(line[offset.y]), parseFloat(line[offset.z]));
153
+ const pdColorUnit8 = pdColor.map((hex) => hex / 255);
154
+ color.push(...pdColorUnit8);
155
+ }
156
+ if (offset.normal_x !== void 0) {
157
+ normal.push(parseFloat(line[offset.normal_x]));
158
+ normal.push(parseFloat(line[offset.normal_y]));
159
+ normal.push(parseFloat(line[offset.normal_z]));
160
+ }
161
+ }
162
+ }
163
+ if (PCDheader.data === "binary_compressed") {
164
+ const sizes = new Uint32Array(data.slice(PCDheader.headerLen, PCDheader.headerLen + 8));
165
+ const compressedSize = sizes[0];
166
+ const decompressedSize = sizes[1];
167
+ const decompressed = decompressLZF(new Uint8Array(data, PCDheader.headerLen + 8, compressedSize), decompressedSize);
168
+ const dataview = new DataView(decompressed.buffer);
169
+ const {offset} = PCDheader;
170
+ for (let i = 0; i < PCDheader.points; i++) {
171
+ if (offset.x !== void 0) {
172
+ position.push(dataview.getFloat32(PCDheader.points * offset.x + PCDheader.size[0] * i, this.littleEndian));
173
+ position.push(dataview.getFloat32(PCDheader.points * offset.y + PCDheader.size[1] * i, this.littleEndian));
174
+ position.push(dataview.getFloat32(PCDheader.points * offset.z + PCDheader.size[2] * i, this.littleEndian));
175
+ }
176
+ if (offset.normal_x !== void 0) {
177
+ normal.push(dataview.getFloat32(PCDheader.points * offset.normal_x + PCDheader.size[4] * i, this.littleEndian));
178
+ normal.push(dataview.getFloat32(PCDheader.points * offset.normal_y + PCDheader.size[5] * i, this.littleEndian));
179
+ normal.push(dataview.getFloat32(PCDheader.points * offset.normal_z + PCDheader.size[6] * i, this.littleEndian));
180
+ }
181
+ if (this.genColorByZ) {
182
+ const pdColor = this.genColorByZ(dataview.getFloat32(PCDheader.points * offset.x + PCDheader.size[0] * i, this.littleEndian), dataview.getFloat32(PCDheader.points * offset.y + PCDheader.size[0] * i, this.littleEndian), dataview.getFloat32(PCDheader.points * offset.z + PCDheader.size[0] * i, this.littleEndian));
183
+ const pdColorUnit8 = pdColor.map((hex) => hex / 255);
184
+ color.push(...pdColorUnit8);
185
+ }
186
+ }
187
+ }
188
+ if (PCDheader.data === "binary") {
189
+ const dataview = new DataView(data, PCDheader.headerLen);
190
+ const {offset} = PCDheader;
191
+ for (let i = 0, row = 0; i < PCDheader.points; i++, row += PCDheader.rowSize) {
192
+ if (offset.x !== void 0) {
193
+ position.push(dataview.getFloat32(row + offset.x, this.littleEndian));
194
+ position.push(dataview.getFloat32(row + offset.y, this.littleEndian));
195
+ position.push(dataview.getFloat32(row + offset.z, this.littleEndian));
196
+ }
197
+ if (offset.normal_x !== void 0) {
198
+ normal.push(dataview.getFloat32(row + offset.normal_x, this.littleEndian));
199
+ normal.push(dataview.getFloat32(row + offset.normal_y, this.littleEndian));
200
+ normal.push(dataview.getFloat32(row + offset.normal_z, this.littleEndian));
201
+ }
202
+ if (this.genColorByZ) {
203
+ const pdColor = this.genColorByZ(dataview.getFloat32(row + offset.x, this.littleEndian), dataview.getFloat32(row + offset.y, this.littleEndian), dataview.getFloat32(row + offset.z, this.littleEndian));
204
+ const pdColorUnit8 = pdColor.map((hex) => hex / 255);
205
+ color.push(...pdColorUnit8);
206
+ }
207
+ }
208
+ }
209
+ const geometry = new BufferGeometry();
210
+ if (position.length > 0)
211
+ geometry.setAttribute("position", new Float32BufferAttribute(position, 3));
212
+ if (normal.length > 0)
213
+ geometry.setAttribute("normal", new Float32BufferAttribute(normal, 3));
214
+ if (color.length > 0)
215
+ geometry.setAttribute("color", new Float32BufferAttribute(color, 3));
216
+ geometry.computeBoundingSphere();
217
+ const material = new PointsMaterial({size: 0.01});
218
+ if (color.length > 0) {
219
+ material.vertexColors = true;
220
+ } else {
221
+ material.color.setHex(16777215);
222
+ }
223
+ return new Points(geometry, material);
224
+ }
225
+ genColorByCoord(x, y, z) {
226
+ if (z <= 0) {
227
+ return [128, 128, 128];
228
+ }
229
+ if (z < 5) {
230
+ return [255, 0, 0];
231
+ }
232
+ if (z < 10) {
233
+ return [0, 255, 0];
234
+ }
235
+ return [0, 0, 255];
236
+ }
237
+ genColorByZ(x, y, z) {
238
+ const index = getIndex(z);
239
+ const color = COLOR_MAP_JET[index];
240
+ return [color[0], color[1], color[2]];
241
+ }
242
+ }
243
+ function getIndex(z) {
244
+ const minZ = -7;
245
+ const maxZ = 3;
246
+ const len = maxZ - minZ;
247
+ if (z < minZ) {
248
+ z = minZ;
249
+ }
250
+ if (z > maxZ) {
251
+ z = maxZ;
252
+ }
253
+ return Math.floor((z - minZ) / len * 255);
254
+ }
255
+
256
+ export { PCDLoader };
@@ -1 +1,211 @@
1
- import{PointCloudUtils as d}from"@labelbee/lb-utils";import{EToolName as h,EPolygonPattern as T}from"../../constant/tool.js";import{CanvasScheduler as R}from"../../newCore/CanvasScheduler.js";import{PointCloud as j}from"./index.js";import{ToolScheduler as B,HybridToolUtils as E}from"../scheduler.js";var A=Object.defineProperty,V=Object.defineProperties,F=Object.getOwnPropertyDescriptors,y=Object.getOwnPropertySymbols,N=Object.prototype.hasOwnProperty,x=Object.prototype.propertyIsEnumerable,w=(n,t,o)=>t in n?A(n,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):n[t]=o,g=(n,t)=>{for(var o in t||(t={}))N.call(t,o)&&w(n,o,t[o]);if(y)for(var o of y(t))x.call(t,o)&&w(n,o,t[o]);return n},m=(n,t)=>V(n,F(t));const S=n=>{const t=document.createElement("canvas");t.width=n.width,t.height=n.height;const o=t.getContext("2d");return o?(o.fillStyle="black",o.fillRect(0,0,n.width,n.height),t.toDataURL()):""};class U{constructor({size:t,container:o,pcdPath:a,extraProps:L,config:O,checkMode:_,toolName:c}){this.updateLineList=s=>{const l=s.map(i=>{var e;return m(g({},i),{pointList:(e=i==null?void 0:i.pointList)==null?void 0:e.map(r=>d.transferWorld2Canvas(r,this.toolInstance.size))})});this.toolScheduler.updateDataByToolName(h.Line,l)},this.updatePolygonList=(s,l)=>{let i=s.map(e=>{var r;const{polygon2d:I}=this.pointCloudInstance.getBoxTopPolygon2DCoordinate(e);return{id:e.id,sourceID:"",pointList:I,isRect:!0,valid:(r=e.valid)!=null?r:!0,attribute:e.attribute}});l&&(i=i.concat(l.map(e=>{var r;return m(g({},e),{pointList:(r=e==null?void 0:e.pointList)==null?void 0:r.map(I=>d.transferWorld2Canvas(I,this.toolInstance.size))})}))),this.toolScheduler.updateDataByToolName(h.PointCloudPolygon,i)},this.updatePointList=s=>{const l=s==null?void 0:s.map(i=>{var e;const{point2d:r}=this.pointCloudInstance.getSphereTopPoint2DCoordinate(i);return m(g({},r),{id:i.id,sourceID:"",valid:(e=i.valid)!=null?e:!0,attribute:i.attribute,textAttribute:""})});this.toolScheduler.updateDataByToolName(h.Point,l)};const b=this.getDefaultOrthographic(t),D=S(t),p=new Image;p.src=D;const C=new B({container:o,size:t,toolName:c}),v=new R({container:o}),f=new j({container:o,noAppend:!0,isOrthographicCamera:!0,orthographicParams:b});a&&f.loadPCDFile(a),v.createCanvas(f.renderer.domElement);const P={size:t,config:JSON.stringify(m(g({},O),{attributeConfigurable:!0,hideAttribute:!0})),imgNode:p,checkMode:_};L&&Object.assign(P,L);let u=[];E.isSingleTool(c)?u=[c]:u=c,u.forEach((s,l)=>{let i;if(s===h.PointCloudPolygon){const e=C.createOperation(s,p,P);e.eventBinding(),e.setPattern(T.Rect),this.toolInstance=e,this.toolInstance.eventBinding(),this.pointCloud2dOperation=e}else i=C.createOperation(s,p,P);l===u.length-1&&(this.toolInstance||(this.toolInstance=i,this.toolInstance.eventBinding()))}),this.pointCloudInstance=f,this.canvasScheduler=v,this.toolScheduler=C,this.config=O}updateConfig(t){this.config=t,this.pointCloud2dOperation.setConfig(JSON.stringify(t))}getDefaultOrthographic(t){return{left:-t.width/2,right:t.width/2,top:t.height/2,bottom:-t.height/2,near:100,far:-100}}initSize(t){this.pointCloudInstance.updateTopCamera(),this.pointCloudInstance.setDefaultControls(),this.pointCloudInstance.initRenderer(),this.pointCloudInstance.initOrthographicCamera(this.getDefaultOrthographic(t)),this.pointCloudInstance.render();const o=S(t),a=new Image;a.src=o,a.onload=()=>{this.toolInstance.setImgNode(a),this.toolInstance.initImgPos()},this.pointCloud2dOperation.setCanvasSize(t)}addPolygonListOnTopView(t){const o=d.getBoxParamsFromResultList(t),a=d.getPolygonListFromResultList(t);this.updatePolygonList(o,a)}addLineListOnTopView(t){const o=d.getLineListFromResultList(t);this.updateLineList(o)}addPointListOnTopView(t){const o=d.getSphereParamsFromResultList(t);this.updatePointList(o)}updateData(t,o,a){!this.toolInstance||!this.pointCloudInstance||(this.pointCloudInstance.loadPCDFile(t,a==null?void 0:a.radius),this.addPolygonListOnTopView(o),this.addLineListOnTopView(o),this.addPointListOnTopView(o))}switchToCanvas(t){const o=this.toolScheduler.switchToCanvas(t);return o?(o.eventBinding(),this.toolInstance=o,o):this.toolInstance}initAllPosition(){this.pointCloudInstance.updateTopCamera(),this.pointCloud2dOperation.initPosition()}clearAllData(){this.pointCloudInstance.clearPointCloudAndRender(),this.pointCloud2dOperation.clearResult()}}export{U as PointCloudAnnotation};
1
+ import { PointCloudUtils } from '@labelbee/lb-utils';
2
+ import { EToolName, EPolygonPattern } from '../../constant/tool.js';
3
+ import { CanvasScheduler } from '../../newCore/CanvasScheduler.js';
4
+ import { PointCloud } from './index.js';
5
+ import { ToolScheduler, HybridToolUtils } from '../scheduler.js';
6
+
7
+ var __defProp = Object.defineProperty;
8
+ var __defProps = Object.defineProperties;
9
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
10
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
11
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
12
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
13
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, {enumerable: true, configurable: true, writable: true, value}) : obj[key] = value;
14
+ var __spreadValues = (a, b) => {
15
+ for (var prop in b || (b = {}))
16
+ if (__hasOwnProp.call(b, prop))
17
+ __defNormalProp(a, prop, b[prop]);
18
+ if (__getOwnPropSymbols)
19
+ for (var prop of __getOwnPropSymbols(b)) {
20
+ if (__propIsEnum.call(b, prop))
21
+ __defNormalProp(a, prop, b[prop]);
22
+ }
23
+ return a;
24
+ };
25
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
26
+ const createEmptyImage = (size) => {
27
+ const canvas = document.createElement("canvas");
28
+ canvas.width = size.width;
29
+ canvas.height = size.height;
30
+ const ctx = canvas.getContext("2d");
31
+ if (ctx) {
32
+ ctx.fillStyle = "black";
33
+ ctx.fillRect(0, 0, size.width, size.height);
34
+ return canvas.toDataURL();
35
+ }
36
+ return "";
37
+ };
38
+ class PointCloudAnnotation {
39
+ constructor({size, container, pcdPath, extraProps, config, checkMode, toolName}) {
40
+ this.updateLineList = (lineList) => {
41
+ const list = lineList.map((v) => {
42
+ var _a;
43
+ return __spreadProps(__spreadValues({}, v), {
44
+ pointList: (_a = v == null ? void 0 : v.pointList) == null ? void 0 : _a.map((point) => PointCloudUtils.transferWorld2Canvas(point, this.toolInstance.size))
45
+ });
46
+ });
47
+ this.toolScheduler.updateDataByToolName(EToolName.Line, list);
48
+ };
49
+ this.updatePolygonList = (pointCloudDataList, extraList) => {
50
+ let polygonList = pointCloudDataList.map((v) => {
51
+ var _a;
52
+ const {polygon2d: pointList} = this.pointCloudInstance.getBoxTopPolygon2DCoordinate(v);
53
+ return {
54
+ id: v.id,
55
+ sourceID: "",
56
+ pointList,
57
+ isRect: true,
58
+ valid: (_a = v.valid) != null ? _a : true,
59
+ attribute: v.attribute
60
+ };
61
+ });
62
+ if (extraList) {
63
+ polygonList = polygonList.concat(extraList.map((v) => {
64
+ var _a;
65
+ return __spreadProps(__spreadValues({}, v), {
66
+ pointList: (_a = v == null ? void 0 : v.pointList) == null ? void 0 : _a.map((point) => PointCloudUtils.transferWorld2Canvas(point, this.toolInstance.size))
67
+ });
68
+ }));
69
+ }
70
+ this.toolScheduler.updateDataByToolName(EToolName.PointCloudPolygon, polygonList);
71
+ };
72
+ this.updatePointList = (sphereList) => {
73
+ const pointList = sphereList == null ? void 0 : sphereList.map((v) => {
74
+ var _a;
75
+ const {point2d} = this.pointCloudInstance.getSphereTopPoint2DCoordinate(v);
76
+ return __spreadProps(__spreadValues({}, point2d), {
77
+ id: v.id,
78
+ sourceID: "",
79
+ valid: (_a = v.valid) != null ? _a : true,
80
+ attribute: v.attribute,
81
+ textAttribute: ""
82
+ });
83
+ });
84
+ this.toolScheduler.updateDataByToolName(EToolName.Point, pointList);
85
+ };
86
+ const defaultOrthographic = this.getDefaultOrthographic(size);
87
+ const imgSrc = createEmptyImage(size);
88
+ const image = new Image();
89
+ image.src = imgSrc;
90
+ const toolScheduler = new ToolScheduler({container, size, toolName});
91
+ const canvasScheduler = new CanvasScheduler({container});
92
+ const pointCloud = new PointCloud({
93
+ container,
94
+ noAppend: true,
95
+ isOrthographicCamera: true,
96
+ orthographicParams: defaultOrthographic
97
+ });
98
+ if (pcdPath) {
99
+ pointCloud.loadPCDFile(pcdPath);
100
+ }
101
+ canvasScheduler.createCanvas(pointCloud.renderer.domElement);
102
+ const defaultProps = {
103
+ size,
104
+ config: JSON.stringify(__spreadProps(__spreadValues({}, config), {attributeConfigurable: true, hideAttribute: true})),
105
+ imgNode: image,
106
+ checkMode
107
+ };
108
+ if (extraProps) {
109
+ Object.assign(defaultProps, extraProps);
110
+ }
111
+ let toolList = [];
112
+ if (HybridToolUtils.isSingleTool(toolName)) {
113
+ toolList = [toolName];
114
+ } else {
115
+ toolList = toolName;
116
+ }
117
+ toolList.forEach((tool, i) => {
118
+ let toolInstance;
119
+ if (tool === EToolName.PointCloudPolygon) {
120
+ const pointCloudPolygonOperation = toolScheduler.createOperation(tool, image, defaultProps);
121
+ pointCloudPolygonOperation.eventBinding();
122
+ pointCloudPolygonOperation.setPattern(EPolygonPattern.Rect);
123
+ this.toolInstance = pointCloudPolygonOperation;
124
+ this.toolInstance.eventBinding();
125
+ this.pointCloud2dOperation = pointCloudPolygonOperation;
126
+ } else {
127
+ toolInstance = toolScheduler.createOperation(tool, image, defaultProps);
128
+ }
129
+ if (i === toolList.length - 1) {
130
+ if (!this.toolInstance) {
131
+ this.toolInstance = toolInstance;
132
+ this.toolInstance.eventBinding();
133
+ }
134
+ }
135
+ });
136
+ this.pointCloudInstance = pointCloud;
137
+ this.canvasScheduler = canvasScheduler;
138
+ this.toolScheduler = toolScheduler;
139
+ this.config = config;
140
+ }
141
+ updateConfig(config) {
142
+ this.config = config;
143
+ this.pointCloud2dOperation.setConfig(JSON.stringify(config));
144
+ }
145
+ getDefaultOrthographic(size) {
146
+ return {
147
+ left: -size.width / 2,
148
+ right: size.width / 2,
149
+ top: size.height / 2,
150
+ bottom: -size.height / 2,
151
+ near: 100,
152
+ far: -100
153
+ };
154
+ }
155
+ initSize(size) {
156
+ this.pointCloudInstance.updateTopCamera();
157
+ this.pointCloudInstance.setDefaultControls();
158
+ this.pointCloudInstance.initRenderer();
159
+ this.pointCloudInstance.initOrthographicCamera(this.getDefaultOrthographic(size));
160
+ this.pointCloudInstance.render();
161
+ const imgSrc = createEmptyImage(size);
162
+ const image = new Image();
163
+ image.src = imgSrc;
164
+ image.onload = () => {
165
+ this.toolInstance.setImgNode(image);
166
+ this.toolInstance.initImgPos();
167
+ };
168
+ this.pointCloud2dOperation.setCanvasSize(size);
169
+ }
170
+ addPolygonListOnTopView(result) {
171
+ const pointCloudDataList = PointCloudUtils.getBoxParamsFromResultList(result);
172
+ const polygonList = PointCloudUtils.getPolygonListFromResultList(result);
173
+ this.updatePolygonList(pointCloudDataList, polygonList);
174
+ }
175
+ addLineListOnTopView(result) {
176
+ const lineList = PointCloudUtils.getLineListFromResultList(result);
177
+ this.updateLineList(lineList);
178
+ }
179
+ addPointListOnTopView(result) {
180
+ const sphereList = PointCloudUtils.getSphereParamsFromResultList(result);
181
+ this.updatePointList(sphereList);
182
+ }
183
+ updateData(pcdPath, result, config) {
184
+ if (!this.toolInstance || !this.pointCloudInstance) {
185
+ return;
186
+ }
187
+ this.pointCloudInstance.loadPCDFile(pcdPath, config == null ? void 0 : config.radius);
188
+ this.addPolygonListOnTopView(result);
189
+ this.addLineListOnTopView(result);
190
+ this.addPointListOnTopView(result);
191
+ }
192
+ switchToCanvas(toolName) {
193
+ const newInstance = this.toolScheduler.switchToCanvas(toolName);
194
+ if (newInstance) {
195
+ newInstance.eventBinding();
196
+ this.toolInstance = newInstance;
197
+ return newInstance;
198
+ }
199
+ return this.toolInstance;
200
+ }
201
+ initAllPosition() {
202
+ this.pointCloudInstance.updateTopCamera();
203
+ this.pointCloud2dOperation.initPosition();
204
+ }
205
+ clearAllData() {
206
+ this.pointCloudInstance.clearPointCloudAndRender();
207
+ this.pointCloud2dOperation.clearResult();
208
+ }
209
+ }
210
+
211
+ export { PointCloudAnnotation };
@@ -1 +1,49 @@
1
- import{PCDLoader as h}from"./PCDLoader.js";class i{constructor(){this.MAX_SIZE=50,this.cacheList=[],this.loadPCDFile=t=>new Promise((s,c)=>{const e=this.pointsMap.get(t),a=this.colorMap.get(t);if(e&&a){s({points:e,color:a});return}if(this.cacheList.length>this.MAX_SIZE){const o=this.cacheList.shift();o&&this.pointsMap.delete(o.src)}this.cacheList.push({src:t}),this.pcdLoader.load(t,o=>{const n=o.geometry.attributes.position.array,r=o.geometry.attributes.color.array;this.pointsMap.set(t,n),this.colorMap.set(t,r),s({points:n,color:r})},()=>{},o=>{c(o)})}),this.pcdLoader=new h,this.pointsMap=new Map,this.colorMap=new Map}static getInstance(){return this.instance==null&&(this.instance=new i),this.instance}updateColor(t,s){this.colorMap.set(t,s)}}export{i as PointCloudCache};
1
+ import { PCDLoader } from './PCDLoader.js';
2
+
3
+ class PointCloudCache {
4
+ constructor() {
5
+ this.MAX_SIZE = 50;
6
+ this.cacheList = [];
7
+ this.loadPCDFile = (src) => {
8
+ return new Promise((resolve, reject) => {
9
+ const clonePoints = this.pointsMap.get(src);
10
+ const cloneColor = this.colorMap.get(src);
11
+ if (clonePoints && cloneColor) {
12
+ resolve({points: clonePoints, color: cloneColor});
13
+ return;
14
+ }
15
+ if (this.cacheList.length > this.MAX_SIZE) {
16
+ const firstCacheInfo = this.cacheList.shift();
17
+ if (firstCacheInfo) {
18
+ this.pointsMap.delete(firstCacheInfo.src);
19
+ }
20
+ }
21
+ this.cacheList.push({src});
22
+ this.pcdLoader.load(src, (points) => {
23
+ const pointsArray = points.geometry.attributes.position.array;
24
+ const colorArray = points.geometry.attributes.color.array;
25
+ this.pointsMap.set(src, pointsArray);
26
+ this.colorMap.set(src, colorArray);
27
+ resolve({points: pointsArray, color: colorArray});
28
+ }, () => {
29
+ }, (err) => {
30
+ reject(err);
31
+ });
32
+ });
33
+ };
34
+ this.pcdLoader = new PCDLoader();
35
+ this.pointsMap = new Map();
36
+ this.colorMap = new Map();
37
+ }
38
+ static getInstance() {
39
+ if (this.instance == null) {
40
+ this.instance = new PointCloudCache();
41
+ }
42
+ return this.instance;
43
+ }
44
+ updateColor(src, color) {
45
+ this.colorMap.set(src, color);
46
+ }
47
+ }
48
+
49
+ export { PointCloudCache };