@labelbee/lb-annotation 1.13.0 → 1.13.1

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 (27) hide show
  1. package/dist/core/pointCloud/index.js +2 -2
  2. package/dist/types/core/pointCloud/index.d.ts +8 -3
  3. package/es/_virtual/_rollup-plugin-web-worker-loader__helper__auto__createBase64WorkerFactory.js +12 -0
  4. package/es/_virtual/_rollup-plugin-web-worker-loader__helper__auto__isNodeJS.js +7 -0
  5. package/es/_virtual/_rollup-plugin-web-worker-loader__helper__node__WorkerClass.js +11 -0
  6. package/es/_virtual/_rollup-plugin-web-worker-loader__helper__node__createBase64WorkerFactory.js +18 -0
  7. package/es/assets/attributeIcon/icon_cuboidFAB.svg.js +3 -0
  8. package/es/assets/attributeIcon/icon_cuboidLeft.svg.js +3 -0
  9. package/es/assets/attributeIcon/icon_cuboidMore.svg.js +3 -0
  10. package/es/assets/attributeIcon/icon_cuboidRight.svg.js +3 -0
  11. package/es/assets/attributeIcon/icon_cuboidTop.svg.js +3 -0
  12. package/es/core/pointCloud/index.js +2 -2
  13. package/es/core/pointCloud/render/index.js +131 -0
  14. package/es/core/pointCloud/segmentation.js +95 -0
  15. package/es/core/pointCloud/selector/Sse3dLassoSelector.js +23 -0
  16. package/es/core/pointCloud/selector/Sse3dSelector.js +15 -0
  17. package/es/core/pointCloud/selector/circleSelector.js +39 -0
  18. package/es/core/pointCloud/selector/lassoSelector.js +22 -0
  19. package/es/core/pointCloud/selector/selector.js +16 -0
  20. package/es/core/pointCloud/store/fsm.js +41 -0
  21. package/es/core/pointCloud/store/index.js +376 -0
  22. package/es/core/toolOperation/Selection.js +101 -0
  23. package/es/core/toolOperation/cuboidOperation.js +752 -0
  24. package/es/core/toolOperation/cuboidToggleButtonClass.js +174 -0
  25. package/es/core/toolOperation/scribbleTool2.js +249 -0
  26. package/es/utils/tool/CuboidUtils.js +680 -0
  27. package/package.json +3 -3
@@ -1,4 +1,4 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var THREE=require("three"),lbUtils=require("@labelbee/lb-utils"),highlightWorker$1=require("../../_virtual/highlightWorker.js"),filterBoxWorker=require("../../_virtual/filterBoxWorker.js"),polygonTool=require("../../utils/tool/polygonTool.js"),uuid=require("../../utils/uuid.js"),PCDLoader=require("./PCDLoader.js"),OrbitControls=require("./OrbitControls.js"),cache=require("./cache.js"),matrix=require("./matrix.js");require("../../constant/tool.js"),require("../../constant/annotation.js"),require("../../utils/MathUtils.js"),require("@turf/turf"),require("../../utils/tool/CommonToolUtils.js"),require("../../utils/tool/LineToolUtils.js"),require("../../utils/tool/DrawUtils.js"),require("lodash"),require("../../constant/keyCode.js"),require("../../locales/index.js"),require("../../locales/constants.js"),require("../../constant/style.js"),require("../../utils/tool/CanvasUtils.js"),require("../../utils/tool/ZoomUtils.js");function _interopNamespace(d){if(d&&d.__esModule)return d;var t=Object.create(null);return d&&Object.keys(d).forEach(function(e){if(e!=="default"){var r=Object.getOwnPropertyDescriptor(d,e);Object.defineProperty(t,e,r.get?r:{enumerable:!0,get:function(){return d[e]}})}}),t.default=d,Object.freeze(t)}var THREE__namespace=_interopNamespace(THREE),__defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnPropDescs=Object.getOwnPropertyDescriptors,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(d,t,e)=>t in d?__defProp(d,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):d[t]=e,__spreadValues=(d,t)=>{for(var e in t||(t={}))__hasOwnProp.call(t,e)&&__defNormalProp(d,e,t[e]);if(__getOwnPropSymbols)for(var e of __getOwnPropSymbols(t))__propIsEnum.call(t,e)&&__defNormalProp(d,e,t[e]);return d},__spreadProps=(d,t)=>__defProps(d,__getOwnPropDescs(t)),__async=(d,t,e)=>new Promise((r,n)=>{var s=o=>{try{i(e.next(o))}catch(c){n(c)}},a=o=>{try{i(e.throw(o))}catch(c){n(c)}},i=o=>o.done?r(o.value):Promise.resolve(o.value).then(s,a);i((e=e.apply(d,t)).next())});const DEFAULT_DISTANCE=30,highlightWorker=new highlightWorker$1({type:"module"});class PointCloud{constructor({container:t,noAppend:e,isOrthographicCamera:r,orthographicParams:n,backgroundColor:s="#4C4C4C",config:a}){this.zAxisLimit=10,this.initCameraPosition=this.DEFAULT_INIT_CAMERA_POSITION,this.isOrthographicCamera=!1,this.pointsUuid="",this.pointCloudObjectName="pointCloud",this.rangeObjectName="range",this.showDirection=!0,this.AddBoxToSense=(i,o=16777215)=>{var c;const h=(c=i.id)!=null?c:uuid();this.removeObjectByName(h);const{center:l,width:u,height:m,depth:x,rotation:y}=i,p=new THREE__namespace.Group,w=new THREE__namespace.BoxGeometry(u,m,x),g=new THREE__namespace.MeshBasicMaterial({color:"blue"}),f=new THREE__namespace.Mesh(w,g),C=new THREE__namespace.BoxHelper(f,o),P=this.generateBoxArrow(i);p.add(C),p.add(P),p.position.set(l.x,l.y,l.z),p.rotation.set(0,0,y),p.name=h,this.scene.add(p)},this.applyCameraTarget=i=>{if(this.camera.type==="OrthographicCamera"&&i){const o=this.getOrthographicCameraTarget(i);this.updateCameraZoom(i.zoom),this.updateCamera(i.position,o)}},this.overridePointShader=i=>{i.vertexShader=`
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var THREE=require("three"),lbUtils=require("@labelbee/lb-utils"),highlightWorker$1=require("../../_virtual/highlightWorker.js"),filterBoxWorker=require("../../_virtual/filterBoxWorker.js"),polygonTool=require("../../utils/tool/polygonTool.js"),uuid=require("../../utils/uuid.js"),PCDLoader=require("./PCDLoader.js"),OrbitControls=require("./OrbitControls.js"),cache=require("./cache.js"),matrix=require("./matrix.js");require("../../constant/tool.js"),require("../../constant/annotation.js"),require("../../utils/MathUtils.js"),require("@turf/turf"),require("../../utils/tool/CommonToolUtils.js"),require("../../utils/tool/LineToolUtils.js"),require("../../utils/tool/DrawUtils.js"),require("lodash"),require("../../constant/keyCode.js"),require("../../locales/index.js"),require("../../locales/constants.js"),require("../../constant/style.js"),require("../../utils/tool/CanvasUtils.js"),require("../../utils/tool/ZoomUtils.js");function _interopNamespace(d){if(d&&d.__esModule)return d;var t=Object.create(null);return d&&Object.keys(d).forEach(function(e){if(e!=="default"){var r=Object.getOwnPropertyDescriptor(d,e);Object.defineProperty(t,e,r.get?r:{enumerable:!0,get:function(){return d[e]}})}}),t.default=d,Object.freeze(t)}var THREE__namespace=_interopNamespace(THREE),__defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnPropDescs=Object.getOwnPropertyDescriptors,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(d,t,e)=>t in d?__defProp(d,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):d[t]=e,__spreadValues=(d,t)=>{for(var e in t||(t={}))__hasOwnProp.call(t,e)&&__defNormalProp(d,e,t[e]);if(__getOwnPropSymbols)for(var e of __getOwnPropSymbols(t))__propIsEnum.call(t,e)&&__defNormalProp(d,e,t[e]);return d},__spreadProps=(d,t)=>__defProps(d,__getOwnPropDescs(t)),__async=(d,t,e)=>new Promise((r,o)=>{var s=n=>{try{i(e.next(n))}catch(c){o(c)}},a=n=>{try{i(e.throw(n))}catch(c){o(c)}},i=n=>n.done?r(n.value):Promise.resolve(n.value).then(s,a);i((e=e.apply(d,t)).next())});const DEFAULT_DISTANCE=30,highlightWorker=new highlightWorker$1({type:"module"});class PointCloud{constructor({container:t,noAppend:e,isOrthographicCamera:r,orthographicParams:o,backgroundColor:s="#4C4C4C",config:a}){this.zAxisLimit=10,this.initCameraPosition=this.DEFAULT_INIT_CAMERA_POSITION,this.isOrthographicCamera=!1,this.pointsUuid="",this.pointCloudObjectName="pointCloud",this.rangeObjectName="range",this.showDirection=!0,this.pointsMaterialSize=1,this.addBoxToSense=(i,n=16777215)=>{var c;const h=(c=i.id)!=null?c:uuid();this.removeObjectByName(h);const{center:l,width:u,height:g,depth:y,rotation:x}=i,p=new THREE__namespace.Group,w=new THREE__namespace.BoxGeometry(u,g,y),m=new THREE__namespace.MeshBasicMaterial({color:"blue"}),f=new THREE__namespace.Mesh(w,m),C=new THREE__namespace.BoxHelper(f,n),P=this.generateBoxArrow(i);p.add(C),p.add(P),p.position.set(l.x,l.y,l.z),p.rotation.set(0,0,x),p.name=h,this.scene.add(p)},this.applyCameraTarget=i=>{if(this.camera.type==="OrthographicCamera"&&i){const n=this.getOrthographicCameraTarget(i);this.updateCameraZoom(i.zoom),this.updateCamera(i.position,n)}},this.overridePointShader=i=>{i.vertexShader=`
2
2
  attribute float sizes;
3
3
  attribute float visibility;
4
4
  varying float vVisible;
@@ -8,4 +8,4 @@
8
8
  varying float vVisible;
9
9
  ${i.fragmentShader}`.replace("#include <clipping_planes_fragment>",`
10
10
  if (vVisible < 0.5) discard;
11
- #include <clipping_planes_fragment>`)},this.loadPCDFile=(i,o)=>__async(this,null,function*(){this.clearPointCloud(),this.currentPCDSrc=i;const{points:c,color:h}=yield this.cacheInstance.loadPCDFile(i),l=new THREE__namespace.BufferGeometry;l.setAttribute("position",new THREE__namespace.BufferAttribute(c,3)),l.setAttribute("color",new THREE__namespace.BufferAttribute(h,3));const u=new THREE__namespace.Points(l);this.renderPointCloud(u,o)}),this.loadPCDFileByBox=(i,o,c)=>__async(this,null,function*(){const h=(m,x)=>__async(this,null,function*(){const{width:y=0,height:p=0,depth:w=0}=c!=null?c:{},g=yield this.filterPointsByBox(__spreadProps(__spreadValues({},o),{width:o.width+y,height:o.height+p,depth:o.depth+w}),m,x);if(!g){console.error("filter Error");return}this.clearPointCloud(),this.currentPCDSrc=i;const f=new THREE__namespace.Points(g.geometry);f.name=this.pointCloudObjectName,this.scene.add(f),this.render()}),{points:l,color:u}=yield this.cacheInstance.loadPCDFile(i);h(l,u)}),this.generateRange=i=>{const o=this.createRange(i);this.scene.add(o)},this.generateBoxArrow=({width:i})=>{const o=new THREE__namespace.Vector3(1,0,0),c=new THREE__namespace.Vector3(i/2,0,0),h=2,l=16776960,u=new THREE__namespace.ArrowHelper(o,c,h,l);return u.visible=this.showDirection,u},this.generateBoxTrackID=i=>{if(!i.trackID)return;const o=new THREE__namespace.Texture(this.getTextCanvas(i.trackID.toString()));o.needsUpdate=!0;const c=new THREE__namespace.SpriteMaterial({map:o,depthWrite:!1}),h=new THREE__namespace.Sprite(c);return h.scale.set(5,5,5),h.position.set(-i.width/2,0,i.depth/2+.5),h},this.applyZAxisPoints=i=>{this.zAxisLimit=i,this.filterZAxisPoints(),this.render()},this.updatePointSize=i=>{const o=this.scene.getObjectByName(this.pointCloudObjectName);if(!o)return;const c=o.material.size;i?o.material.size=Math.min(c*1.2,10):o.material.size=Math.max(c/1.2,1),this.render()},this.container=t,this.renderer=new THREE__namespace.WebGLRenderer({antialias:!0}),this.backgroundColor=s,this.config=a,r&&n?(this.isOrthographicCamera=!0,this.camera=new THREE__namespace.OrthographicCamera(n.left,n.right,n.top,n.bottom,n.near,n.far)):this.camera=new THREE__namespace.PerspectiveCamera(30,this.containerWidth/this.containerHeight,1,1e3),this.initCamera(),this.scene=new THREE__namespace.Scene,this.controls=new OrbitControls.OrbitControls(this.camera,this.renderer.domElement),this.pcdLoader=new PCDLoader.PCDLoader,this.axesHelper=new THREE__namespace.AxesHelper(1e3),this.scene.add(this.camera),e||t.appendChild(this.renderer.domElement),this.init(),this.cacheInstance=cache.PointCloudCache.getInstance()}get DEFAULT_INIT_CAMERA_POSITION(){return new THREE__namespace.Vector3(-.01,0,10)}get containerWidth(){return this.container.clientWidth}get containerHeight(){return this.container.clientHeight}setInitCameraPosition(t){this.initCameraPosition=t}setConfig(t){this.config=t}initOrthographicCamera(t){if(this.camera.type!=="OrthographicCamera")return;const{left:e,right:r,top:n,bottom:s,near:a,far:i}=t;this.camera.left=e,this.camera.right=r,this.camera.top=n,this.camera.bottom=s,this.camera.near=a,this.camera.far=i,this.camera.updateProjectionMatrix()}initPerspectiveCamera(){this.camera.type==="PerspectiveCamera"&&(this.camera.fov=30,this.camera.aspect=this.containerWidth/this.containerHeight,this.camera.near=1,this.camera.far=1e3,this.camera.updateProjectionMatrix())}initCamera(){const{camera:t}=this;if(this.isOrthographicCamera){const{x:e,y:r,z:n}=this.initCameraPosition;t.position.set(e,r,n)}else t.position.set(-1,0,500);t.up.set(0,0,1)}initControls(){const{controls:t}=this;t.addEventListener("change",()=>{this.render()}),this.setDefaultControls()}setDefaultControls(){const{controls:t}=this,e=[0,0,0];t.target=new THREE__namespace.Vector3(...e),t.addEventListener("change",()=>{this.render()}),t.maxPolarAngle=Math.PI/2,t.update()}initRenderer(){const{renderer:t}=this;t.setPixelRatio(window.devicePixelRatio),t.setSize(this.containerWidth,this.containerHeight)}init(){const{scene:t}=this;t.background=new THREE__namespace.Color(this.backgroundColor),this.initControls(),this.initRenderer()}removeObjectByName(t){const e=this.scene.getObjectByName(t);e&&e.removeFromParent()}generateBox(t,e=16777215){const r=e;this.AddBoxToSense(t,r),this.render()}getAllAttributeColor(t){return t.reduce((e,r)=>(e[r.attribute]=lbUtils.toolStyleConverter.getColorFromConfig({attribute:r.attribute},__spreadProps(__spreadValues({},this.config),{attributeConfigurable:!0}),{}),e),{})}generateBoxes(t){t.forEach(e=>{this.generateBox(e)}),this.render()}getOrthographicCamera(t){const{center:e,width:r,height:n}=t,s=10,a=e.x-r/2-s,i=e.x-r/2+s,o=e.y+n/2+s,c=e.y-n/2-s,h=100,l=-100,u=500/h;return{left:a,right:i,top:o,bottom:c,near:h,far:l,zoom:u}}updateCameraZoom(t){this.camera.zoom=t,this.camera.updateProjectionMatrix()}updateCameraByBox(t,e,r){const{center:n,width:s,height:a,depth:i,rotation:o}=t,c=this.getCameraVector(n,o,{width:s,height:a,depth:i},e);return r?(this.updateCamera(r,n),new THREE__namespace.Vector3(r.x,r.y,r.z)):(this.updateCamera(c,n),c)}updateOrthoCamera(t,e){const r=this.updateCameraByBox(t,e);return this.camera.zoom=1,this.camera.updateProjectionMatrix(),{cameraPositionVector:r}}updateTopCamera(){this.setInitCameraPosition(this.DEFAULT_INIT_CAMERA_POSITION),this.camera.zoom=1,this.initCamera(),this.setDefaultControls(),this.camera.updateProjectionMatrix(),this.render()}updateCamera(t,e){this.camera.position.set(t.x,t.y,t.z),this.controls.target=new THREE__namespace.Vector3(e.x,e.y,e.z),this.controls.update()}resetCamera(){this.updateCamera(this.DEFAULT_INIT_CAMERA_POSITION,{x:0,y:0,z:0})}getOrthographicCameraTarget(t){const e=new THREE__namespace.Vector3(0,0,-1).applyQuaternion(t.quaternion);return t.position.clone().add(e)}createThreeMatrix4(t){return new THREE__namespace.Matrix4().set(...t)}filterPointsByBox(t,e,r){var n,s,a;if(!e){const i=this.scene.getObjectByName(this.pointCloudObjectName);if(!i)return console.error("There is no corresponding point cloud object"),Promise.resolve(void 0);e=(a=(s=(n=i==null?void 0:i.geometry)==null?void 0:n.attributes)==null?void 0:s.position)==null?void 0:a.array}if(window.Worker){const{zMin:i,zMax:o,polygonPointList:c}=matrix.getCuboidFromPointCloudBox(t),h=e;r=r!=null?r:new Float32Array([]);const l={boxParams:t,zMin:i,zMax:o,polygonPointList:c,color:r,position:h};return new Promise(u=>{const m=new filterBoxWorker;m.postMessage(l),m.onmessage=x=>{const{color:y,position:p,num:w}=x.data,g=new THREE__namespace.BufferGeometry;g.setAttribute("position",new THREE__namespace.Float32BufferAttribute(p,3)),g.setAttribute("color",new THREE__namespace.Float32BufferAttribute(y,3)),g.computeBoundingSphere(),m.terminate(),u({geometry:g,num:w})}})}return Promise.resolve(void 0)}getCameraVector(t,e,r,n=lbUtils.EPerspectiveView.Front,s=DEFAULT_DISTANCE){let a=lbUtils.PerspectiveShiftUtils.frontViewMatrix4(s);switch(n){case lbUtils.EPerspectiveView.Front:break;case lbUtils.EPerspectiveView.Back:a=lbUtils.PerspectiveShiftUtils.backViewMatrix4(s);break;case lbUtils.EPerspectiveView.Left:a=lbUtils.PerspectiveShiftUtils.leftViewMatrix4(s);break;case lbUtils.EPerspectiveView.Right:a=lbUtils.PerspectiveShiftUtils.rightViewMatrix4(s);break;case lbUtils.EPerspectiveView.Top:a=lbUtils.PerspectiveShiftUtils.topViewMatrix4(s);break;case lbUtils.EPerspectiveView.LFT:a=lbUtils.PerspectiveShiftUtils.leftFrontTopViewMatrix4(s,r);break;case lbUtils.EPerspectiveView.RBT:a=lbUtils.PerspectiveShiftUtils.rightBackTopViewMatrix4(s,r);break}const i=this.createThreeMatrix4(a),o=new THREE__namespace.Matrix4().makeTranslation(-t.x,-t.y,-t.z),c=new THREE__namespace.Matrix4().makeTranslation(t.x,t.y,t.z),h=new THREE__namespace.Matrix4().makeRotationZ(e);return new THREE__namespace.Vector3(t.x,t.y,t.z).clone().applyMatrix4(i).applyMatrix4(o).applyMatrix4(h).applyMatrix4(c)}createRange(t){this.removeObjectByName(this.rangeObjectName);const r=new THREE__namespace.EllipseCurve(0,0,t,t,0,2*Math.PI,!1,0).getPoints(50),n=new THREE__namespace.BufferGeometry().setFromPoints(r),s=new THREE__namespace.LineBasicMaterial({color:16711680}),a=new THREE__namespace.Line(n,s);return a.name=this.rangeObjectName,a}renderPointCloud(t,e){t.name=this.pointCloudObjectName;const r=new THREE__namespace.PointsMaterial({vertexColors:!0});r.onBeforeCompile=this.overridePointShader,r.size=1.2,e&&this.generateRange(e),this.pointsUuid=t.uuid,t.material=r,this.filterZAxisPoints(t),this.scene.add(t),this.render()}clearPointCloud(){this.removeObjectByName(this.pointCloudObjectName)}clearPointCloudAndRender(){this.clearPointCloud(),this.render()}highlightOriginPointCloud(t){const e=this.scene.getObjectByName(this.pointCloudObjectName);if(!!e)return this.highlightPCDSrc=this.currentPCDSrc,new Promise(r=>{if(window.Worker){const s=(t?[...t]:[]).map(o=>matrix.getCuboidFromPointCloudBox(o)),a=this.getAllAttributeColor(s),i={cuboidList:s,position:e.geometry.attributes.position.array,color:e.geometry.attributes.color.array,colorList:a};highlightWorker.postMessage(i),highlightWorker.onmessage=o=>{const{color:c}=o.data,h=new THREE__namespace.BufferAttribute(c,3);this.highlightPCDSrc&&(this.cacheInstance.updateColor(this.highlightPCDSrc,c),this.highlightPCDSrc=void 0),h.needsUpdate=!0,e.geometry.setAttribute("color",h),r(c),this.render()}}})}updateColor(t){const e=this.scene.getObjectByName(this.pointCloudObjectName);if(e){const r=new THREE__namespace.BufferAttribute(t,3);r.needsUpdate=!0,e.geometry.setAttribute("color",r),this.render()}}setShowDirection(t){this.showDirection=t,this.scene.children.forEach(e=>{e.type==="Group"&&e.children.forEach(r=>{r.type==="ArrowHelper"&&(r.visible=t)})}),this.render()}getTextCanvas(t){const e=document.createElement("canvas"),r=e.getContext("2d");return r&&(r.font=`${50}px " bold`,r.fillStyle="white",r.textAlign="center",r.textBaseline="middle",r.fillText(t,e.width/2,e.height/2)),e}getSensesPointZAxisInPolygon(t,e){const r=this.scene.children.find(o=>o.uuid===this.pointsUuid);let n=0,s=0,a=0,i=0;if(r&&(r==null?void 0:r.geometry)){const o=r==null?void 0:r.geometry.attributes.position.array;for(let c=0;c<o.length;c+=3){const h=o[c],l=o[c+1],u=o[c+2];polygonTool.isInPolygon({x:h,y:l},t)&&u&&(s=Math.max(u,s),n=Math.min(u,n),i++,e&&u>=e[0]&&u<=e[1]&&a++)}}return{maxZ:s,minZ:n,count:a,zCount:i}}getBasicCoordinate2Canvas(t){const e=this.containerWidth/2,r=this.containerHeight/2;return{x:t.x*e+e,y:t.y*r+r,z:t.z}}get basicCoordinate2CanvasMatrix4(){const t=this.containerWidth/2,e=this.containerHeight/2;return new THREE__namespace.Matrix4().set(t,0,0,t,0,e,0,e,0,0,1,0,0,0,0,1)}getCanvas2BasicCoordinate(t){const e=this.containerWidth/2,r=this.containerHeight/2;return new THREE__namespace.Vector3(t.x/e-e/2,-(t.y/r-r/2),1)}getPolygonSidePoints(t){const{center:{x:e,y:r,z:n},height:s,width:a,depth:i}=t,o={x:e+a/2,y:r+s/2,z:n-i/2},c={x:e+a/2,y:r+s/2,z:n+i/2},h={x:e-a/2,y:r+s/2,z:n+i/2},l={x:e-a/2,y:r+s/2,z:n-i/2};return[o,c,h,l]}getPolygonBackPoints(t){const{center:{x:e,y:r,z:n},height:s,width:a,depth:i}=t,o={x:e-a/2,y:r+s/2,z:n+i/2},c={x:e-a/2,y:r+s/2,z:n-i/2},h={x:e-a/2,y:r-s/2,z:n-i/2},l={x:e-a/2,y:r-s/2,z:n+i/2};return[o,c,h,l]}getPolygonTopPoints(t){const{center:{x:e,y:r,z:n},height:s,width:a,depth:i}=t,o={x:e+a/2,y:r+s/2,z:n+i/2},c={x:e+a/2,y:r-s/2,z:n+i/2},h={x:e-a/2,y:r-s/2,z:n+i/2},l={x:e-a/2,y:r+s/2,z:n+i/2};return[o,c,h,l]}getModelTransformationMatrix(t){const{center:{x:e,y:r,z:n},rotation:s}=t,a=new THREE__namespace.Matrix4().makeTranslation(-e,-r,-n),i=new THREE__namespace.Matrix4().makeTranslation(e,r,n),o=new THREE__namespace.Matrix4().makeRotationZ(s);return new THREE__namespace.Matrix4().multiply(i).multiply(o).multiply(a)}getBoxSidePolygon2DCoordinate(t){return this.getBoxPolygon2DCoordinate(t,lbUtils.EPerspectiveView.Left)}getBoxBackPolygon2DCoordinate(t){return this.getBoxPolygon2DCoordinate(t,lbUtils.EPerspectiveView.Back)}boxParams2ViewPolygon(t,e){switch(e){case lbUtils.EPerspectiveView.Left:return this.getPolygonSidePoints(t);case lbUtils.EPerspectiveView.Back:return this.getPolygonBackPoints(t);default:return this.getPolygonTopPoints(t)}}getBoxPolygon2DCoordinate(t,e){const r=this.boxParams2ViewPolygon(t,e),{width:n,height:s}=t,a=new THREE__namespace.Matrix4().premultiply(this.camera.matrixWorldInverse).premultiply(this.camera.projectionMatrix),i=new THREE__namespace.Matrix4().premultiply(this.getModelTransformationMatrix(t)).premultiply(a).premultiply(this.basicCoordinate2CanvasMatrix4);this.sideMatrix=i;const o=r.map(l=>new THREE__namespace.Vector3(l.x,l.y,l.z)).map(l=>l.applyMatrix4(this.sideMatrix)),c=this.containerWidth/n,h=this.containerHeight/s;return{polygon2d:o,zoom:Math.min(c,h)/2}}getBoxTopPolygon2DCoordinate(t){const{width:e,height:r}=t,s=this.getPolygonTopPoints(t).map(o=>new THREE__namespace.Vector3(o.x,o.y,o.z)).map(o=>o.applyMatrix4(this.getModelTransformationMatrix(t))).map(o=>({x:o.y,y:o.x})).map(o=>({x:-(o.x-this.containerWidth/2),y:-(o.y-this.containerHeight/2)})),a=this.containerWidth/e,i=this.containerHeight/r;return{polygon2d:s,zoom:Math.min(a,i)/2}}getNewBoxBySideUpdate(t,e,r,n){const s=new THREE__namespace.Matrix4().makeRotationZ(n.rotation),a=new THREE__namespace.Vector3(-t.x,0,0).applyMatrix4(s);let i=n;return i.center={x:i.center.x+a.x,y:i.center.y+a.y,z:i.center.z-t.z},i=__spreadProps(__spreadValues({},i),{width:i.width+e,height:i.height,depth:i.depth+r}),{newBoxParams:i}}getNewBoxByBackUpdate(t,e,r,n){const s=new THREE__namespace.Matrix4().makeRotationZ(n.rotation),a=new THREE__namespace.Vector3(0,-t.x,0).applyMatrix4(s);let i=n;return i.center={x:i.center.x+a.x,y:i.center.y+a.y,z:i.center.z-t.z},i=__spreadProps(__spreadValues({},i),{width:i.width,height:i.height+e,depth:i.depth+r}),{newBoxParams:i}}getNewBoxBySideUpdateByPoints(t,e,r,n){var s;const a=(s=this.sideMatrix)==null?void 0:s.invert();if(!this.sideMatrix||!a){console.error("No sideMatrix");return}this.camera.zoom=1,this.camera.updateProjectionMatrix();const i=t.map(p=>new THREE__namespace.Vector3(p.x,p.y,p.z)).map(p=>p.applyMatrix4(a)),[o,c,h,l]=i,u=Math.max(Math.abs(o.x-h.x),Math.abs(o.x-c.x)),x=c.add(l).applyMatrix3(new THREE__namespace.Matrix3().set(1/2,0,0,0,1/2,0,0,0,1/2)).clone().applyMatrix3(new THREE__namespace.Matrix3().set(-1,0,0,0,-1,0,0,0,-1)).add(new THREE__namespace.Vector3(n.center.x,n.center.y,n.center.z));return{newBoxParams:__spreadProps(__spreadValues({},n),{center:{x:n.center.x-x.x,y:n.center.y-x.y,z:n.center.z-r},width:u,height:n.height,depth:n.depth+e,rotation:n.rotation})}}filterZAxisPoints(t){const e=t||this.scene.children.find(r=>r.uuid===this.pointsUuid);if(e){const{attributes:r}=e.geometry,{position:n}=r,s=[],{count:a}=n;for(let i=0;i<a;i++){const o=n.getZ(i);s.push(o>this.zAxisLimit?0:1)}e.geometry.setAttribute("visibility",new THREE__namespace.Float32BufferAttribute(s,1)),e.geometry.attributes.visibility.needsUpdate=!0}}render(){this.renderer.render(this.scene,this.camera)}}exports.createThreeMatrix4=matrix.createThreeMatrix4,exports.getCuboidFromPointCloudBox=matrix.getCuboidFromPointCloudBox,exports.lidar2image=matrix.lidar2image,exports.pointCloudLidar2image=matrix.pointCloudLidar2image,exports.rotatePoint=matrix.rotatePoint,exports.transferKitti2Matrix=matrix.transferKitti2Matrix,exports.PointCloud=PointCloud;
11
+ #include <clipping_planes_fragment>`)},this.loadPCDFile=(i,n)=>__async(this,null,function*(){this.clearPointCloud(),this.currentPCDSrc=i;const{points:c,color:h}=yield this.cacheInstance.loadPCDFile(i),l=new THREE__namespace.BufferGeometry;l.setAttribute("position",new THREE__namespace.BufferAttribute(c,3)),l.setAttribute("color",new THREE__namespace.BufferAttribute(h,3));const u=new THREE__namespace.Points(l);this.renderPointCloud(u,n)}),this.loadPCDFileByBox=(i,n,c)=>__async(this,null,function*(){const h=(g,y)=>__async(this,null,function*(){const{width:x=0,height:p=0,depth:w=0}=c!=null?c:{},m=yield this.filterPointsByBox(__spreadProps(__spreadValues({},n),{width:n.width+x,height:n.height+p,depth:n.depth+w}),g,y);if(!m){console.error("filter Error");return}this.clearPointCloud(),this.currentPCDSrc=i;const f=new THREE__namespace.Points(m.geometry);f.name=this.pointCloudObjectName,this.scene.add(f),this.render()}),{points:l,color:u}=yield this.cacheInstance.loadPCDFile(i);h(l,u)}),this.generateRange=i=>{const n=this.createRange(i);this.scene.add(n)},this.generateBoxArrow=({width:i})=>{const n=new THREE__namespace.Vector3(1,0,0),c=new THREE__namespace.Vector3(i/2,0,0),h=2,l=16776960,u=new THREE__namespace.ArrowHelper(n,c,h,l);return u.visible=this.showDirection,u},this.generateBoxTrackID=i=>{if(!i.trackID)return;const n=new THREE__namespace.Texture(this.getTextCanvas(i.trackID.toString()));n.needsUpdate=!0;const c=new THREE__namespace.SpriteMaterial({map:n,depthWrite:!1}),h=new THREE__namespace.Sprite(c);return h.scale.set(5,5,5),h.position.set(-i.width/2,0,i.depth/2+.5),h},this.applyZAxisPoints=i=>{this.zAxisLimit=i,this.filterZAxisPoints(),this.render()},this.updatePointSize=({zoomIn:i,customSize:n})=>{const c=this.scene.getObjectByName(this.pointCloudObjectName);if(!c)return;const h=c.material.size;i?c.material.size=Math.min(h*1.2,10):c.material.size=Math.max(h/1.2,1),n&&(c.material.size=n,this.pointsMaterialSize=n),this.render()},this.container=t,this.renderer=new THREE__namespace.WebGLRenderer({antialias:!0}),this.backgroundColor=s,this.config=a,r&&o?(this.isOrthographicCamera=!0,this.camera=new THREE__namespace.OrthographicCamera(o.left,o.right,o.top,o.bottom,o.near,o.far)):this.camera=new THREE__namespace.PerspectiveCamera(30,this.containerWidth/this.containerHeight,1,1e3),this.initCamera(),this.scene=new THREE__namespace.Scene,this.controls=new OrbitControls.OrbitControls(this.camera,this.renderer.domElement),this.pcdLoader=new PCDLoader.PCDLoader,this.axesHelper=new THREE__namespace.AxesHelper(1e3),this.scene.add(this.camera),e||t.appendChild(this.renderer.domElement),this.init(),this.cacheInstance=cache.PointCloudCache.getInstance()}get DEFAULT_INIT_CAMERA_POSITION(){return new THREE__namespace.Vector3(-.01,0,10)}get containerWidth(){return this.container.clientWidth}get containerHeight(){return this.container.clientHeight}setInitCameraPosition(t){this.initCameraPosition=t}setConfig(t){this.config=t}initOrthographicCamera(t){if(this.camera.type!=="OrthographicCamera")return;const{left:e,right:r,top:o,bottom:s,near:a,far:i}=t;this.camera.left=e,this.camera.right=r,this.camera.top=o,this.camera.bottom=s,this.camera.near=a,this.camera.far=i,this.camera.updateProjectionMatrix()}initPerspectiveCamera(){this.camera.type==="PerspectiveCamera"&&(this.camera.fov=30,this.camera.aspect=this.containerWidth/this.containerHeight,this.camera.near=1,this.camera.far=1e3,this.camera.updateProjectionMatrix())}initCamera(){const{camera:t}=this;if(this.isOrthographicCamera){const{x:e,y:r,z:o}=this.initCameraPosition;t.position.set(e,r,o)}else t.position.set(-1,0,500);t.up.set(0,0,1)}initControls(){const{controls:t}=this;t.addEventListener("change",()=>{this.render()}),this.setDefaultControls()}setDefaultControls(){const{controls:t}=this,e=[0,0,0];t.target=new THREE__namespace.Vector3(...e),t.addEventListener("change",()=>{this.render()}),t.maxPolarAngle=Math.PI/2,t.update()}initRenderer(){const{renderer:t}=this;t.setPixelRatio(window.devicePixelRatio),t.setSize(this.containerWidth,this.containerHeight)}init(){const{scene:t}=this;t.background=new THREE__namespace.Color(this.backgroundColor),this.initControls(),this.initRenderer()}removeObjectByName(t){const e=this.scene.getObjectByName(t);e&&e.removeFromParent()}generateBox(t,e=16777215){const r=e;this.addBoxToSense(t,r),this.render()}getAllAttributeColor(t){return t.reduce((e,r)=>(e[r.attribute]=lbUtils.toolStyleConverter.getColorFromConfig({attribute:r.attribute},__spreadProps(__spreadValues({},this.config),{attributeConfigurable:!0}),{}),e),{})}generateBoxes(t){t.forEach(e=>{this.addBoxToSense(e)}),this.render()}getOrthographicCamera(t){const{center:e,width:r,height:o}=t,s=10,a=e.x-r/2-s,i=e.x-r/2+s,n=e.y+o/2+s,c=e.y-o/2-s,h=100,l=-100,u=500/h;return{left:a,right:i,top:n,bottom:c,near:h,far:l,zoom:u}}updateCameraZoom(t){this.camera.zoom=t,this.camera.updateProjectionMatrix()}updateCameraByBox(t,e,r){const{center:o,width:s,height:a,depth:i,rotation:n}=t,c=this.getCameraVector(o,n,{width:s,height:a,depth:i},e);return r?(this.updateCamera(r,o),new THREE__namespace.Vector3(r.x,r.y,r.z)):(this.updateCamera(c,o),c)}updateOrthoCamera(t,e){const r=this.updateCameraByBox(t,e);return this.camera.zoom=1,this.camera.updateProjectionMatrix(),{cameraPositionVector:r}}updateTopCamera(){this.setInitCameraPosition(this.DEFAULT_INIT_CAMERA_POSITION),this.camera.zoom=1,this.initCamera(),this.setDefaultControls(),this.camera.updateProjectionMatrix(),this.render()}updateCamera(t,e){this.camera.position.set(t.x,t.y,t.z),this.controls.target=new THREE__namespace.Vector3(e.x,e.y,e.z),this.controls.update()}resetCamera(){this.updateCamera(this.DEFAULT_INIT_CAMERA_POSITION,{x:0,y:0,z:0})}getOrthographicCameraTarget(t){const e=new THREE__namespace.Vector3(0,0,-1).applyQuaternion(t.quaternion);return t.position.clone().add(e)}createThreeMatrix4(t){return new THREE__namespace.Matrix4().set(...t)}filterPointsByBox(t,e,r){var o,s,a;if(!e){const i=this.scene.getObjectByName(this.pointCloudObjectName);if(!i)return console.error("There is no corresponding point cloud object"),Promise.resolve(void 0);e=(a=(s=(o=i==null?void 0:i.geometry)==null?void 0:o.attributes)==null?void 0:s.position)==null?void 0:a.array}if(window.Worker){const{zMin:i,zMax:n,polygonPointList:c}=matrix.getCuboidFromPointCloudBox(t),h=e;r=r!=null?r:new Float32Array([]);const l={boxParams:t,zMin:i,zMax:n,polygonPointList:c,color:r,position:h};return new Promise(u=>{const g=new filterBoxWorker;g.postMessage(l),g.onmessage=y=>{const{color:x,position:p,num:w}=y.data,m=new THREE__namespace.BufferGeometry;m.setAttribute("position",new THREE__namespace.Float32BufferAttribute(p,3)),m.setAttribute("color",new THREE__namespace.Float32BufferAttribute(x,3)),m.computeBoundingSphere(),g.terminate(),u({geometry:m,num:w})}})}return Promise.resolve(void 0)}getCameraVector(t,e,r,o=lbUtils.EPerspectiveView.Front,s=DEFAULT_DISTANCE){let a=lbUtils.PerspectiveShiftUtils.frontViewMatrix4(s);switch(o){case lbUtils.EPerspectiveView.Front:break;case lbUtils.EPerspectiveView.Back:a=lbUtils.PerspectiveShiftUtils.backViewMatrix4(s);break;case lbUtils.EPerspectiveView.Left:a=lbUtils.PerspectiveShiftUtils.leftViewMatrix4(s);break;case lbUtils.EPerspectiveView.Right:a=lbUtils.PerspectiveShiftUtils.rightViewMatrix4(s);break;case lbUtils.EPerspectiveView.Top:a=lbUtils.PerspectiveShiftUtils.topViewMatrix4(s);break;case lbUtils.EPerspectiveView.LFT:a=lbUtils.PerspectiveShiftUtils.leftFrontTopViewMatrix4(s,r);break;case lbUtils.EPerspectiveView.RBT:a=lbUtils.PerspectiveShiftUtils.rightBackTopViewMatrix4(s,r);break}const i=this.createThreeMatrix4(a),n=new THREE__namespace.Matrix4().makeTranslation(-t.x,-t.y,-t.z),c=new THREE__namespace.Matrix4().makeTranslation(t.x,t.y,t.z),h=new THREE__namespace.Matrix4().makeRotationZ(e);return new THREE__namespace.Vector3(t.x,t.y,t.z).clone().applyMatrix4(i).applyMatrix4(n).applyMatrix4(h).applyMatrix4(c)}createRange(t){this.removeObjectByName(this.rangeObjectName);const r=new THREE__namespace.EllipseCurve(0,0,t,t,0,2*Math.PI,!1,0).getPoints(50),o=new THREE__namespace.BufferGeometry().setFromPoints(r),s=new THREE__namespace.LineBasicMaterial({color:16711680}),a=new THREE__namespace.Line(o,s);return a.name=this.rangeObjectName,a}renderPointCloud(t,e){t.name=this.pointCloudObjectName;const r=new THREE__namespace.PointsMaterial({vertexColors:!0});r.onBeforeCompile=this.overridePointShader,r.size=this.pointsMaterialSize,e&&this.generateRange(e),this.pointsUuid=t.uuid,t.material=r,this.filterZAxisPoints(t),this.scene.add(t),this.render()}clearPointCloud(){this.removeObjectByName(this.pointCloudObjectName)}clearPointCloudAndRender(){this.clearPointCloud(),this.render()}highlightOriginPointCloud(t){const e=this.scene.getObjectByName(this.pointCloudObjectName);if(!!e)return this.highlightPCDSrc=this.currentPCDSrc,new Promise((r,o)=>{if(window.Worker){const a=(t?[...t]:[]).map(c=>matrix.getCuboidFromPointCloudBox(c)),i=this.getAllAttributeColor(a),n={cuboidList:a,position:e.geometry.attributes.position.array,color:e.geometry.attributes.color.array,colorList:i};highlightWorker.postMessage(n),highlightWorker.onmessage=c=>{const{color:h}=c.data,l=new THREE__namespace.BufferAttribute(h,3);if(!this.highlightPCDSrc||this.highlightPCDSrc!==this.currentPCDSrc||e.geometry.attributes.position.array.length!==h.length){o(new Error("Error Path"));return}this.cacheInstance.updateColor(this.highlightPCDSrc,h),this.highlightPCDSrc=void 0,l.needsUpdate=!0,e.geometry.setAttribute("color",l),r(h),this.render()}}})}updateColor(t){const e=this.scene.getObjectByName(this.pointCloudObjectName);if(e){const r=new THREE__namespace.BufferAttribute(t,3);r.needsUpdate=!0,e.geometry.setAttribute("color",r),this.render()}}setShowDirection(t){this.showDirection=t,this.scene.children.forEach(e=>{e.type==="Group"&&e.children.forEach(r=>{r.type==="ArrowHelper"&&(r.visible=t)})}),this.render()}getTextCanvas(t){const e=document.createElement("canvas"),r=e.getContext("2d");return r&&(r.font=`${50}px " bold`,r.fillStyle="white",r.textAlign="center",r.textBaseline="middle",r.fillText(t,e.width/2,e.height/2)),e}getSensesPointZAxisInPolygon(t,e){const r=this.scene.children.find(n=>n.uuid===this.pointsUuid);let o=0,s=0,a=0,i=0;if(r&&(r==null?void 0:r.geometry)){const n=r==null?void 0:r.geometry.attributes.position.array;for(let c=0;c<n.length;c+=3){const h=n[c],l=n[c+1],u=n[c+2];polygonTool.isInPolygon({x:h,y:l},t)&&u&&(s=Math.max(u,s),o=Math.min(u,o),i++,e&&u>=e[0]&&u<=e[1]&&a++)}}return{maxZ:s,minZ:o,count:a,zCount:i}}getBasicCoordinate2Canvas(t){const e=this.containerWidth/2,r=this.containerHeight/2;return{x:t.x*e+e,y:t.y*r+r,z:t.z}}get basicCoordinate2CanvasMatrix4(){const t=this.containerWidth/2,e=this.containerHeight/2;return new THREE__namespace.Matrix4().set(t,0,0,t,0,e,0,e,0,0,1,0,0,0,0,1)}getCanvas2BasicCoordinate(t){const e=this.containerWidth/2,r=this.containerHeight/2;return new THREE__namespace.Vector3(t.x/e-e/2,-(t.y/r-r/2),1)}getPolygonSidePoints(t){const{center:{x:e,y:r,z:o},height:s,width:a,depth:i}=t,n={x:e+a/2,y:r+s/2,z:o-i/2},c={x:e+a/2,y:r+s/2,z:o+i/2},h={x:e-a/2,y:r+s/2,z:o+i/2},l={x:e-a/2,y:r+s/2,z:o-i/2};return[n,c,h,l]}getPolygonBackPoints(t){const{center:{x:e,y:r,z:o},height:s,width:a,depth:i}=t,n={x:e-a/2,y:r+s/2,z:o+i/2},c={x:e-a/2,y:r+s/2,z:o-i/2},h={x:e-a/2,y:r-s/2,z:o-i/2},l={x:e-a/2,y:r-s/2,z:o+i/2};return[n,c,h,l]}getPolygonTopPoints(t){const{center:{x:e,y:r,z:o},height:s,width:a,depth:i}=t,n={x:e+a/2,y:r+s/2,z:o+i/2},c={x:e+a/2,y:r-s/2,z:o+i/2},h={x:e-a/2,y:r-s/2,z:o+i/2},l={x:e-a/2,y:r+s/2,z:o+i/2};return[n,c,h,l]}getModelTransformationMatrix(t){const{center:{x:e,y:r,z:o},rotation:s}=t,a=new THREE__namespace.Matrix4().makeTranslation(-e,-r,-o),i=new THREE__namespace.Matrix4().makeTranslation(e,r,o),n=new THREE__namespace.Matrix4().makeRotationZ(s);return new THREE__namespace.Matrix4().multiply(i).multiply(n).multiply(a)}getBoxSidePolygon2DCoordinate(t){return this.getBoxPolygon2DCoordinate(t,lbUtils.EPerspectiveView.Left)}getBoxBackPolygon2DCoordinate(t){return this.getBoxPolygon2DCoordinate(t,lbUtils.EPerspectiveView.Back)}boxParams2ViewPolygon(t,e){switch(e){case lbUtils.EPerspectiveView.Left:return this.getPolygonSidePoints(t);case lbUtils.EPerspectiveView.Back:return this.getPolygonBackPoints(t);default:return this.getPolygonTopPoints(t)}}getBoxPolygon2DCoordinate(t,e){const r=this.boxParams2ViewPolygon(t,e),{width:o,height:s}=t,a=new THREE__namespace.Matrix4().premultiply(this.camera.matrixWorldInverse).premultiply(this.camera.projectionMatrix),i=new THREE__namespace.Matrix4().premultiply(this.getModelTransformationMatrix(t)).premultiply(a).premultiply(this.basicCoordinate2CanvasMatrix4);this.sideMatrix=i;const n=r.map(l=>new THREE__namespace.Vector3(l.x,l.y,l.z)).map(l=>l.applyMatrix4(this.sideMatrix)),c=this.containerWidth/o,h=this.containerHeight/s;return{polygon2d:n,zoom:Math.min(c,h)/2}}getBoxTopPolygon2DCoordinate(t){const{width:e,height:r}=t,s=this.getPolygonTopPoints(t).map(n=>new THREE__namespace.Vector3(n.x,n.y,n.z)).map(n=>n.applyMatrix4(this.getModelTransformationMatrix(t))).map(n=>({x:n.y,y:n.x})).map(n=>({x:-(n.x-this.containerWidth/2),y:-(n.y-this.containerHeight/2)})),a=this.containerWidth/e,i=this.containerHeight/r;return{polygon2d:s,zoom:Math.min(a,i)/2}}getNewBoxBySideUpdate(t,e,r,o){const s=new THREE__namespace.Matrix4().makeRotationZ(o.rotation),a=new THREE__namespace.Vector3(-t.x,0,0).applyMatrix4(s);let i=o;return i.center={x:i.center.x+a.x,y:i.center.y+a.y,z:i.center.z-t.z},i=__spreadProps(__spreadValues({},i),{width:i.width+e,height:i.height,depth:i.depth+r}),{newBoxParams:i}}getNewBoxByBackUpdate(t,e,r,o){const s=new THREE__namespace.Matrix4().makeRotationZ(o.rotation),a=new THREE__namespace.Vector3(0,-t.x,0).applyMatrix4(s);let i=o;return i.center={x:i.center.x+a.x,y:i.center.y+a.y,z:i.center.z-t.z},i=__spreadProps(__spreadValues({},i),{width:i.width,height:i.height+e,depth:i.depth+r}),{newBoxParams:i}}getNewBoxBySideUpdateByPoints(t,e,r,o){var s;const a=(s=this.sideMatrix)==null?void 0:s.invert();if(!this.sideMatrix||!a){console.error("No sideMatrix");return}this.camera.zoom=1,this.camera.updateProjectionMatrix();const i=t.map(p=>new THREE__namespace.Vector3(p.x,p.y,p.z)).map(p=>p.applyMatrix4(a)),[n,c,h,l]=i,u=Math.max(Math.abs(n.x-h.x),Math.abs(n.x-c.x)),y=c.add(l).applyMatrix3(new THREE__namespace.Matrix3().set(1/2,0,0,0,1/2,0,0,0,1/2)).clone().applyMatrix3(new THREE__namespace.Matrix3().set(-1,0,0,0,-1,0,0,0,-1)).add(new THREE__namespace.Vector3(o.center.x,o.center.y,o.center.z));return{newBoxParams:__spreadProps(__spreadValues({},o),{center:{x:o.center.x-y.x,y:o.center.y-y.y,z:o.center.z-r},width:u,height:o.height,depth:o.depth+e,rotation:o.rotation})}}filterZAxisPoints(t){const e=t||this.scene.children.find(r=>r.uuid===this.pointsUuid);if(e){const{attributes:r}=e.geometry,{position:o}=r,s=[],{count:a}=o;for(let i=0;i<a;i++){const n=o.getZ(i);s.push(n>this.zAxisLimit?0:1)}e.geometry.setAttribute("visibility",new THREE__namespace.Float32BufferAttribute(s,1)),e.geometry.attributes.visibility.needsUpdate=!0}}render(){this.renderer.render(this.scene,this.camera)}}exports.createThreeMatrix4=matrix.createThreeMatrix4,exports.getCuboidFromPointCloudBox=matrix.getCuboidFromPointCloudBox,exports.lidar2image=matrix.lidar2image,exports.pointCloudLidar2image=matrix.pointCloudLidar2image,exports.rotatePoint=matrix.rotatePoint,exports.transferKitti2Matrix=matrix.transferKitti2Matrix,exports.PointCloud=PointCloud;
@@ -48,6 +48,7 @@ export declare class PointCloud {
48
48
  private cacheInstance;
49
49
  private showDirection;
50
50
  private currentPCDSrc?;
51
+ private pointsMaterialSize;
51
52
  /**
52
53
  * Record the src of Highlight PCD.
53
54
  *
@@ -87,7 +88,7 @@ export declare class PointCloud {
87
88
  getAllAttributeColor(boxes: IPointCloudBox[]): {
88
89
  [k: string]: any;
89
90
  };
90
- AddBoxToSense: (boxParams: IPointCloudBox, color?: number) => void;
91
+ addBoxToSense: (boxParams: IPointCloudBox, color?: number) => void;
91
92
  generateBoxes(boxes: IPointCloudBox[]): void;
92
93
  /**
93
94
  * Get OrthographicCamera Params to Change
@@ -325,9 +326,13 @@ export declare class PointCloud {
325
326
  applyZAxisPoints: (zAxisLimit: number) => void;
326
327
  /**
327
328
  * Update point size
328
- * @param zoomIn
329
+ * @param param0
330
+ * @returns
329
331
  */
330
- updatePointSize: (zoomIn: boolean) => void;
332
+ updatePointSize: ({ zoomIn, customSize }: {
333
+ zoomIn?: boolean | undefined;
334
+ customSize?: number | undefined;
335
+ }) => void;
331
336
  render(): void;
332
337
  }
333
338
  export * from './matrix';
@@ -0,0 +1,12 @@
1
+ import { createBase64WorkerFactory as createBase64WorkerFactory$1 } from './_rollup-plugin-web-worker-loader__helper__node__createBase64WorkerFactory.js';
2
+ import { createBase64WorkerFactory as createBase64WorkerFactory$2 } from './_rollup-plugin-web-worker-loader__helper__browser__createBase64WorkerFactory.js';
3
+ import { isNodeJS } from './_rollup-plugin-web-worker-loader__helper__auto__isNodeJS.js';
4
+
5
+ function createBase64WorkerFactory(base64, sourcemapArg, enableUnicodeArg) {
6
+ if (isNodeJS()) {
7
+ return createBase64WorkerFactory$1(base64, sourcemapArg, enableUnicodeArg);
8
+ }
9
+ return createBase64WorkerFactory$2(base64, sourcemapArg, enableUnicodeArg);
10
+ }
11
+
12
+ export { createBase64WorkerFactory };
@@ -0,0 +1,7 @@
1
+ var kIsNodeJS = Object.prototype.toString.call(typeof process !== 'undefined' ? process : 0) === '[object process]';
2
+
3
+ function isNodeJS() {
4
+ return kIsNodeJS;
5
+ }
6
+
7
+ export { isNodeJS };
@@ -0,0 +1,11 @@
1
+ var WorkerClass = null;
2
+
3
+ try {
4
+ var WorkerThreads =
5
+ typeof module !== 'undefined' && typeof module.require === 'function' && module.require('worker_threads') ||
6
+ typeof __non_webpack_require__ === 'function' && __non_webpack_require__('worker_threads') ||
7
+ typeof require === 'function' && require('worker_threads');
8
+ WorkerClass = WorkerThreads.Worker;
9
+ } catch(e) {} // eslint-disable-line
10
+
11
+ export { WorkerClass };
@@ -0,0 +1,18 @@
1
+ import { WorkerClass } from './_rollup-plugin-web-worker-loader__helper__node__WorkerClass.js';
2
+
3
+ function decodeBase64(base64, enableUnicode) {
4
+ return Buffer.from(base64, 'base64').toString(enableUnicode ? 'utf16' : 'utf8');
5
+ }
6
+
7
+ function createBase64WorkerFactory(base64, sourcemapArg, enableUnicodeArg) {
8
+ var sourcemap = sourcemapArg === undefined ? null : sourcemapArg;
9
+ var enableUnicode = enableUnicodeArg === undefined ? false : enableUnicodeArg;
10
+ var source = decodeBase64(base64, enableUnicode);
11
+ var start = source.indexOf('\n', 10) + 1;
12
+ var body = source.substring(start) + (sourcemap ? '\/\/# sourceMappingURL=' + sourcemap : '');
13
+ return function WorkerFactory(options) {
14
+ return new WorkerClass(body, Object.assign({}, options, { eval: true }));
15
+ };
16
+ }
17
+
18
+ export { createBase64WorkerFactory };
@@ -0,0 +1,3 @@
1
+ var cuboidFAB = "<svg width=\"27\" height=\"27\" viewBox=\"0 0 27 27\" fill=\"none\" xmlns=\"http://www.w3.org/2000/svg\">\n <path\n d=\"M13.5525 3.01367C7.75439 3.01367 3.03467 7.73076 3.03467 13.5289C3.0373 19.3297 7.75439 24.0468 13.5525 24.0468C19.3507 24.0468 24.0678 19.3297 24.0678 13.5315C24.0678 7.7334 19.3507 3.01367 13.5525 3.01367ZM19.3085 15.9072V15.9521C19.3085 15.9652 19.3059 15.9784 19.3059 15.9942C19.3059 16.0021 19.3059 16.0101 19.3032 16.018C19.3032 16.0312 19.3006 16.0443 19.2979 16.0575C19.2979 16.0654 19.2953 16.076 19.2953 16.0839C19.2927 16.0944 19.2927 16.105 19.29 16.1155C19.2874 16.1261 19.2848 16.1393 19.2848 16.1498C19.2821 16.1577 19.2821 16.1656 19.2795 16.1709C19.2769 16.1867 19.2716 16.2025 19.2689 16.2184C19.2689 16.221 19.2663 16.2236 19.2663 16.2263C19.2083 16.4504 19.0923 16.664 18.9156 16.8406L15.8386 19.9177C15.3112 20.445 14.449 20.445 13.9243 19.9177C13.397 19.3903 13.397 18.5281 13.9243 18.0034L14.6863 17.2414H9.14922C8.40303 17.2414 7.79394 16.6323 7.79394 15.8861C7.79394 15.1399 8.40303 14.5309 9.14922 14.5309H17.9559C18.3039 14.5309 18.652 14.6627 18.9156 14.9264C19.1793 15.19 19.3111 15.5381 19.3111 15.8861C19.3111 15.894 19.3085 15.902 19.3085 15.9072ZM19.3111 11.1743C19.3111 11.9205 18.7021 12.5296 17.9559 12.5296H9.14922C8.80117 12.5296 8.45312 12.3978 8.18945 12.1341C7.92578 11.8704 7.79394 11.5224 7.79394 11.1743V11.1532V11.111C7.79394 11.0979 7.79658 11.082 7.79658 11.0688C7.79658 11.0609 7.79658 11.053 7.79922 11.0451C7.79922 11.0319 7.80186 11.0187 7.80449 11.0056C7.80449 10.9977 7.80713 10.9871 7.80713 10.9792C7.80977 10.9687 7.80976 10.9581 7.8124 10.9476C7.81504 10.937 7.81768 10.9238 7.81768 10.9133C7.82031 10.9054 7.82031 10.8975 7.82295 10.8922C7.82559 10.8764 7.83086 10.8605 7.8335 10.8447C7.8335 10.8421 7.83613 10.8395 7.83613 10.8368C7.89414 10.6127 8.01016 10.3991 8.18682 10.2225L11.2612 7.14805C11.7886 6.6207 12.6508 6.6207 13.1755 7.14805C13.7028 7.67539 13.7028 8.5376 13.1755 9.0623L12.4187 9.82168H17.9559C18.6994 9.82168 19.3111 10.4308 19.3111 11.1743Z\"\n fill=\"#2C7EFF\" />\n</svg>";
2
+
3
+ export { cuboidFAB as default };
@@ -0,0 +1,3 @@
1
+ var cuboidLeft = "<svg width=\"18\" height=\"18\" viewBox=\"0 0 18 18\" fill=\"none\" xmlns=\"http://www.w3.org/2000/svg\">\n <path\n d=\"M16.425 5.04961C16.35 4.82461 16.2 4.67461 15.975 4.59961L9.525 1.14961C9.225 0.999609 8.85 0.999609 8.55 1.14961L2.025 4.59961C1.725 4.74961 1.5 5.12461 1.5 5.49961V12.2496C1.5 12.6246 1.725 12.9996 2.025 13.1496L8.475 16.5996C8.7 16.6746 8.925 16.7496 9.15 16.6746C9.225 16.6746 9.375 16.5996 9.45 16.5996L15.9 13.1496C16.275 12.9996 16.5 12.6246 16.5 12.2496V5.49961C16.5 5.34961 16.425 5.19961 16.425 5.04961ZM9.15 8.87461V15.2496L9 15.3996L2.85 12.0996V5.64961L9 2.34961L15.15 5.64961L9.15 8.87461Z\"\n fill=\"#2C7EFF\" />\n <path d=\"M9 8.5V2.5L8.5 2L2.5 5.5V12.5L9 8.5Z\" fill=\"#2C7EFF\" />\n <path d=\"M15.5 6L15 5.5L14.5 6L9 8.5V15.5H9.5L15.5 12.5V6Z\" fill=\"white\" />\n</svg>";
2
+
3
+ export { cuboidLeft as default };
@@ -0,0 +1,3 @@
1
+ var cuboidMore = "<svg width=\"16\" height=\"4\" viewBox=\"0 0 16 4\" fill=\"none\" xmlns=\"http://www.w3.org/2000/svg\">\n <circle cx=\"2\" cy=\"2\" r=\"2\" fill=\"#2C7EFF\" />\n <circle cx=\"8\" cy=\"2\" r=\"2\" fill=\"#2C7EFF\" />\n <circle cx=\"14\" cy=\"2\" r=\"2\" fill=\"#2C7EFF\" />\n</svg>";
2
+
3
+ export { cuboidMore as default };
@@ -0,0 +1,3 @@
1
+ var cuboidRight = "<svg width=\"18\" height=\"18\" viewBox=\"0 0 18 18\" fill=\"none\" xmlns=\"http://www.w3.org/2000/svg\">\n <path\n d=\"M16.425 5.04961C16.35 4.82461 16.2 4.67461 15.975 4.59961L9.525 1.14961C9.225 0.999609 8.85 0.999609 8.55 1.14961L2.025 4.59961C1.725 4.74961 1.5 5.12461 1.5 5.49961V12.2496C1.5 12.6246 1.725 12.9996 2.025 13.1496L8.475 16.5996C8.7 16.6746 8.925 16.7496 9.15 16.6746C9.225 16.6746 9.375 16.5996 9.45 16.5996L15.9 13.1496C16.275 12.9996 16.5 12.6246 16.5 12.2496V5.49961C16.5 5.34961 16.425 5.19961 16.425 5.04961ZM9.15 8.87461V15.2496L9 15.3996L2.85 12.0996V5.64961L9 2.34961L15.15 5.64961L9.15 8.87461Z\"\n fill=\"#2C7EFF\" />\n</svg>";
2
+
3
+ export { cuboidRight as default };
@@ -0,0 +1,3 @@
1
+ var cuboidTop = "<svg width=\"25\" height=\"25\" viewBox=\"0 0 25 25\" fill=\"none\" xmlns=\"http://www.w3.org/2000/svg\">\n <g clip-path=\"url(#clip0_2295_37199)\">\n <path\n d=\"M5.16087 7.8398C5.00351 8.01726 4.94861 8.22216 4.99615 8.45452L5.23337 15.7654C5.25346 16.1002 5.44096 16.4249 5.72087 16.6098L11.9712 20.5356C12.2511 20.7204 12.6883 20.7277 13.0131 20.5402L18.8587 17.1652C19.1835 16.9777 19.3958 16.5954 19.3757 16.2606L19.1385 8.94971C19.0909 8.71735 19.0434 8.485 18.8659 8.32764C18.8284 8.26269 18.6885 8.17029 18.651 8.10533L12.4382 4.24447C12.1208 3.99471 11.6835 3.98735 11.3587 4.17485L5.51308 7.54985C5.38317 7.62485 5.29077 7.7648 5.16087 7.8398ZM12.1109 12.2276L17.6318 9.04014L17.8367 9.09505L18.0538 16.0711L12.468 19.2961L6.5351 15.62L6.31798 8.64399L12.1109 12.2276Z\"\n fill=\"#2C7EFF\" />\n </g>\n <defs>\n <clipPath id=\"clip0_2295_37199\">\n <rect width=\"18\" height=\"18\" fill=\"white\" transform=\"translate(9 24.5898) rotate(-120)\" />\n </clipPath>\n </defs>\n</svg>";
2
+
3
+ export { cuboidTop as default };
@@ -1,4 +1,4 @@
1
- import*as a from"three";import{toolStyleConverter as S,PerspectiveShiftUtils as w,EPerspectiveView as g}from"@labelbee/lb-utils";import k from"../../_virtual/highlightWorker.js";import V from"../../_virtual/filterBoxWorker.js";import{isInPolygon as L}from"../../utils/tool/polygonTool.js";import I from"../../utils/uuid.js";import{PCDLoader as N}from"./PCDLoader.js";import{OrbitControls as D}from"./OrbitControls.js";import{PointCloudCache as F}from"./cache.js";import{getCuboidFromPointCloudBox as B}from"./matrix.js";export{createThreeMatrix4,getCuboidFromPointCloudBox,lidar2image,pointCloudLidar2image,rotatePoint,transferKitti2Matrix}from"./matrix.js";import"../../constant/tool.js";import"../../constant/annotation.js";import"../../utils/MathUtils.js";import"@turf/turf";import"../../utils/tool/CommonToolUtils.js";import"../../utils/tool/LineToolUtils.js";import"../../utils/tool/DrawUtils.js";import"lodash";import"../../constant/keyCode.js";import"../../locales/index.js";import"../../locales/constants.js";import"../../constant/style.js";import"../../utils/tool/CanvasUtils.js";import"../../utils/tool/ZoomUtils.js";var E=Object.defineProperty,R=Object.defineProperties,U=Object.getOwnPropertyDescriptors,T=Object.getOwnPropertySymbols,W=Object.prototype.hasOwnProperty,Z=Object.prototype.propertyIsEnumerable,A=(u,t,e)=>t in u?E(u,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):u[t]=e,P=(u,t)=>{for(var e in t||(t={}))W.call(t,e)&&A(u,e,t[e]);if(T)for(var e of T(t))Z.call(t,e)&&A(u,e,t[e]);return u},M=(u,t)=>R(u,U(t)),z=(u,t,e)=>new Promise((r,n)=>{var s=o=>{try{i(e.next(o))}catch(h){n(h)}},c=o=>{try{i(e.throw(o))}catch(h){n(h)}},i=o=>o.done?r(o.value):Promise.resolve(o.value).then(s,c);i((e=e.apply(u,t)).next())});const H=30,O=new k({type:"module"});class G{constructor({container:t,noAppend:e,isOrthographicCamera:r,orthographicParams:n,backgroundColor:s="#4C4C4C",config:c}){this.zAxisLimit=10,this.initCameraPosition=this.DEFAULT_INIT_CAMERA_POSITION,this.isOrthographicCamera=!1,this.pointsUuid="",this.pointCloudObjectName="pointCloud",this.rangeObjectName="range",this.showDirection=!0,this.AddBoxToSense=(i,o=16777215)=>{var h;const l=(h=i.id)!=null?h:I();this.removeObjectByName(l);const{center:d,width:p,height:y,depth:f,rotation:C}=i,m=new a.Group,b=new a.BoxGeometry(p,y,f),x=new a.MeshBasicMaterial({color:"blue"}),v=new a.Mesh(b,x),j=new a.BoxHelper(v,o),_=this.generateBoxArrow(i);m.add(j),m.add(_),m.position.set(d.x,d.y,d.z),m.rotation.set(0,0,C),m.name=l,this.scene.add(m)},this.applyCameraTarget=i=>{if(this.camera.type==="OrthographicCamera"&&i){const o=this.getOrthographicCameraTarget(i);this.updateCameraZoom(i.zoom),this.updateCamera(i.position,o)}},this.overridePointShader=i=>{i.vertexShader=`
1
+ import*as c from"three";import{toolStyleConverter as S,PerspectiveShiftUtils as w,EPerspectiveView as g}from"@labelbee/lb-utils";import k from"../../_virtual/highlightWorker.js";import V from"../../_virtual/filterBoxWorker.js";import{isInPolygon as L}from"../../utils/tool/polygonTool.js";import D from"../../utils/uuid.js";import{PCDLoader as I}from"./PCDLoader.js";import{OrbitControls as N}from"./OrbitControls.js";import{PointCloudCache as E}from"./cache.js";import{getCuboidFromPointCloudBox as B}from"./matrix.js";export{createThreeMatrix4,getCuboidFromPointCloudBox,lidar2image,pointCloudLidar2image,rotatePoint,transferKitti2Matrix}from"./matrix.js";import"../../constant/tool.js";import"../../constant/annotation.js";import"../../utils/MathUtils.js";import"@turf/turf";import"../../utils/tool/CommonToolUtils.js";import"../../utils/tool/LineToolUtils.js";import"../../utils/tool/DrawUtils.js";import"lodash";import"../../constant/keyCode.js";import"../../locales/index.js";import"../../locales/constants.js";import"../../constant/style.js";import"../../utils/tool/CanvasUtils.js";import"../../utils/tool/ZoomUtils.js";var F=Object.defineProperty,R=Object.defineProperties,U=Object.getOwnPropertyDescriptors,T=Object.getOwnPropertySymbols,W=Object.prototype.hasOwnProperty,Z=Object.prototype.propertyIsEnumerable,O=(u,t,e)=>t in u?F(u,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):u[t]=e,P=(u,t)=>{for(var e in t||(t={}))W.call(t,e)&&O(u,e,t[e]);if(T)for(var e of T(t))Z.call(t,e)&&O(u,e,t[e]);return u},M=(u,t)=>R(u,U(t)),z=(u,t,e)=>new Promise((r,o)=>{var s=n=>{try{i(e.next(n))}catch(h){o(h)}},a=n=>{try{i(e.throw(n))}catch(h){o(h)}},i=n=>n.done?r(n.value):Promise.resolve(n.value).then(s,a);i((e=e.apply(u,t)).next())});const H=30,j=new k({type:"module"});class G{constructor({container:t,noAppend:e,isOrthographicCamera:r,orthographicParams:o,backgroundColor:s="#4C4C4C",config:a}){this.zAxisLimit=10,this.initCameraPosition=this.DEFAULT_INIT_CAMERA_POSITION,this.isOrthographicCamera=!1,this.pointsUuid="",this.pointCloudObjectName="pointCloud",this.rangeObjectName="range",this.showDirection=!0,this.pointsMaterialSize=1,this.addBoxToSense=(i,n=16777215)=>{var h;const l=(h=i.id)!=null?h:D();this.removeObjectByName(l);const{center:p,width:d,height:y,depth:f,rotation:C}=i,m=new c.Group,b=new c.BoxGeometry(d,y,f),x=new c.MeshBasicMaterial({color:"blue"}),v=new c.Mesh(b,x),A=new c.BoxHelper(v,n),_=this.generateBoxArrow(i);m.add(A),m.add(_),m.position.set(p.x,p.y,p.z),m.rotation.set(0,0,C),m.name=l,this.scene.add(m)},this.applyCameraTarget=i=>{if(this.camera.type==="OrthographicCamera"&&i){const n=this.getOrthographicCameraTarget(i);this.updateCameraZoom(i.zoom),this.updateCamera(i.position,n)}},this.overridePointShader=i=>{i.vertexShader=`
2
2
  attribute float sizes;
3
3
  attribute float visibility;
4
4
  varying float vVisible;
@@ -8,4 +8,4 @@ import*as a from"three";import{toolStyleConverter as S,PerspectiveShiftUtils as
8
8
  varying float vVisible;
9
9
  ${i.fragmentShader}`.replace("#include <clipping_planes_fragment>",`
10
10
  if (vVisible < 0.5) discard;
11
- #include <clipping_planes_fragment>`)},this.loadPCDFile=(i,o)=>z(this,null,function*(){this.clearPointCloud(),this.currentPCDSrc=i;const{points:h,color:l}=yield this.cacheInstance.loadPCDFile(i),d=new a.BufferGeometry;d.setAttribute("position",new a.BufferAttribute(h,3)),d.setAttribute("color",new a.BufferAttribute(l,3));const p=new a.Points(d);this.renderPointCloud(p,o)}),this.loadPCDFileByBox=(i,o,h)=>z(this,null,function*(){const l=(y,f)=>z(this,null,function*(){const{width:C=0,height:m=0,depth:b=0}=h!=null?h:{},x=yield this.filterPointsByBox(M(P({},o),{width:o.width+C,height:o.height+m,depth:o.depth+b}),y,f);if(!x){console.error("filter Error");return}this.clearPointCloud(),this.currentPCDSrc=i;const v=new a.Points(x.geometry);v.name=this.pointCloudObjectName,this.scene.add(v),this.render()}),{points:d,color:p}=yield this.cacheInstance.loadPCDFile(i);l(d,p)}),this.generateRange=i=>{const o=this.createRange(i);this.scene.add(o)},this.generateBoxArrow=({width:i})=>{const o=new a.Vector3(1,0,0),h=new a.Vector3(i/2,0,0),l=2,d=16776960,p=new a.ArrowHelper(o,h,l,d);return p.visible=this.showDirection,p},this.generateBoxTrackID=i=>{if(!i.trackID)return;const o=new a.Texture(this.getTextCanvas(i.trackID.toString()));o.needsUpdate=!0;const h=new a.SpriteMaterial({map:o,depthWrite:!1}),l=new a.Sprite(h);return l.scale.set(5,5,5),l.position.set(-i.width/2,0,i.depth/2+.5),l},this.applyZAxisPoints=i=>{this.zAxisLimit=i,this.filterZAxisPoints(),this.render()},this.updatePointSize=i=>{const o=this.scene.getObjectByName(this.pointCloudObjectName);if(!o)return;const h=o.material.size;i?o.material.size=Math.min(h*1.2,10):o.material.size=Math.max(h/1.2,1),this.render()},this.container=t,this.renderer=new a.WebGLRenderer({antialias:!0}),this.backgroundColor=s,this.config=c,r&&n?(this.isOrthographicCamera=!0,this.camera=new a.OrthographicCamera(n.left,n.right,n.top,n.bottom,n.near,n.far)):this.camera=new a.PerspectiveCamera(30,this.containerWidth/this.containerHeight,1,1e3),this.initCamera(),this.scene=new a.Scene,this.controls=new D(this.camera,this.renderer.domElement),this.pcdLoader=new N,this.axesHelper=new a.AxesHelper(1e3),this.scene.add(this.camera),e||t.appendChild(this.renderer.domElement),this.init(),this.cacheInstance=F.getInstance()}get DEFAULT_INIT_CAMERA_POSITION(){return new a.Vector3(-.01,0,10)}get containerWidth(){return this.container.clientWidth}get containerHeight(){return this.container.clientHeight}setInitCameraPosition(t){this.initCameraPosition=t}setConfig(t){this.config=t}initOrthographicCamera(t){if(this.camera.type!=="OrthographicCamera")return;const{left:e,right:r,top:n,bottom:s,near:c,far:i}=t;this.camera.left=e,this.camera.right=r,this.camera.top=n,this.camera.bottom=s,this.camera.near=c,this.camera.far=i,this.camera.updateProjectionMatrix()}initPerspectiveCamera(){this.camera.type==="PerspectiveCamera"&&(this.camera.fov=30,this.camera.aspect=this.containerWidth/this.containerHeight,this.camera.near=1,this.camera.far=1e3,this.camera.updateProjectionMatrix())}initCamera(){const{camera:t}=this;if(this.isOrthographicCamera){const{x:e,y:r,z:n}=this.initCameraPosition;t.position.set(e,r,n)}else t.position.set(-1,0,500);t.up.set(0,0,1)}initControls(){const{controls:t}=this;t.addEventListener("change",()=>{this.render()}),this.setDefaultControls()}setDefaultControls(){const{controls:t}=this,e=[0,0,0];t.target=new a.Vector3(...e),t.addEventListener("change",()=>{this.render()}),t.maxPolarAngle=Math.PI/2,t.update()}initRenderer(){const{renderer:t}=this;t.setPixelRatio(window.devicePixelRatio),t.setSize(this.containerWidth,this.containerHeight)}init(){const{scene:t}=this;t.background=new a.Color(this.backgroundColor),this.initControls(),this.initRenderer()}removeObjectByName(t){const e=this.scene.getObjectByName(t);e&&e.removeFromParent()}generateBox(t,e=16777215){const r=e;this.AddBoxToSense(t,r),this.render()}getAllAttributeColor(t){return t.reduce((e,r)=>(e[r.attribute]=S.getColorFromConfig({attribute:r.attribute},M(P({},this.config),{attributeConfigurable:!0}),{}),e),{})}generateBoxes(t){t.forEach(e=>{this.generateBox(e)}),this.render()}getOrthographicCamera(t){const{center:e,width:r,height:n}=t,s=10,c=e.x-r/2-s,i=e.x-r/2+s,o=e.y+n/2+s,h=e.y-n/2-s,l=100,d=-100,p=500/l;return{left:c,right:i,top:o,bottom:h,near:l,far:d,zoom:p}}updateCameraZoom(t){this.camera.zoom=t,this.camera.updateProjectionMatrix()}updateCameraByBox(t,e,r){const{center:n,width:s,height:c,depth:i,rotation:o}=t,h=this.getCameraVector(n,o,{width:s,height:c,depth:i},e);return r?(this.updateCamera(r,n),new a.Vector3(r.x,r.y,r.z)):(this.updateCamera(h,n),h)}updateOrthoCamera(t,e){const r=this.updateCameraByBox(t,e);return this.camera.zoom=1,this.camera.updateProjectionMatrix(),{cameraPositionVector:r}}updateTopCamera(){this.setInitCameraPosition(this.DEFAULT_INIT_CAMERA_POSITION),this.camera.zoom=1,this.initCamera(),this.setDefaultControls(),this.camera.updateProjectionMatrix(),this.render()}updateCamera(t,e){this.camera.position.set(t.x,t.y,t.z),this.controls.target=new a.Vector3(e.x,e.y,e.z),this.controls.update()}resetCamera(){this.updateCamera(this.DEFAULT_INIT_CAMERA_POSITION,{x:0,y:0,z:0})}getOrthographicCameraTarget(t){const e=new a.Vector3(0,0,-1).applyQuaternion(t.quaternion);return t.position.clone().add(e)}createThreeMatrix4(t){return new a.Matrix4().set(...t)}filterPointsByBox(t,e,r){var n,s,c;if(!e){const i=this.scene.getObjectByName(this.pointCloudObjectName);if(!i)return console.error("There is no corresponding point cloud object"),Promise.resolve(void 0);e=(c=(s=(n=i==null?void 0:i.geometry)==null?void 0:n.attributes)==null?void 0:s.position)==null?void 0:c.array}if(window.Worker){const{zMin:i,zMax:o,polygonPointList:h}=B(t),l=e;r=r!=null?r:new Float32Array([]);const d={boxParams:t,zMin:i,zMax:o,polygonPointList:h,color:r,position:l};return new Promise(p=>{const y=new V;y.postMessage(d),y.onmessage=f=>{const{color:C,position:m,num:b}=f.data,x=new a.BufferGeometry;x.setAttribute("position",new a.Float32BufferAttribute(m,3)),x.setAttribute("color",new a.Float32BufferAttribute(C,3)),x.computeBoundingSphere(),y.terminate(),p({geometry:x,num:b})}})}return Promise.resolve(void 0)}getCameraVector(t,e,r,n=g.Front,s=H){let c=w.frontViewMatrix4(s);switch(n){case g.Front:break;case g.Back:c=w.backViewMatrix4(s);break;case g.Left:c=w.leftViewMatrix4(s);break;case g.Right:c=w.rightViewMatrix4(s);break;case g.Top:c=w.topViewMatrix4(s);break;case g.LFT:c=w.leftFrontTopViewMatrix4(s,r);break;case g.RBT:c=w.rightBackTopViewMatrix4(s,r);break}const i=this.createThreeMatrix4(c),o=new a.Matrix4().makeTranslation(-t.x,-t.y,-t.z),h=new a.Matrix4().makeTranslation(t.x,t.y,t.z),l=new a.Matrix4().makeRotationZ(e);return new a.Vector3(t.x,t.y,t.z).clone().applyMatrix4(i).applyMatrix4(o).applyMatrix4(l).applyMatrix4(h)}createRange(t){this.removeObjectByName(this.rangeObjectName);const r=new a.EllipseCurve(0,0,t,t,0,2*Math.PI,!1,0).getPoints(50),n=new a.BufferGeometry().setFromPoints(r),s=new a.LineBasicMaterial({color:16711680}),c=new a.Line(n,s);return c.name=this.rangeObjectName,c}renderPointCloud(t,e){t.name=this.pointCloudObjectName;const r=new a.PointsMaterial({vertexColors:!0});r.onBeforeCompile=this.overridePointShader,r.size=1.2,e&&this.generateRange(e),this.pointsUuid=t.uuid,t.material=r,this.filterZAxisPoints(t),this.scene.add(t),this.render()}clearPointCloud(){this.removeObjectByName(this.pointCloudObjectName)}clearPointCloudAndRender(){this.clearPointCloud(),this.render()}highlightOriginPointCloud(t){const e=this.scene.getObjectByName(this.pointCloudObjectName);if(!!e)return this.highlightPCDSrc=this.currentPCDSrc,new Promise(r=>{if(window.Worker){const s=(t?[...t]:[]).map(o=>B(o)),c=this.getAllAttributeColor(s),i={cuboidList:s,position:e.geometry.attributes.position.array,color:e.geometry.attributes.color.array,colorList:c};O.postMessage(i),O.onmessage=o=>{const{color:h}=o.data,l=new a.BufferAttribute(h,3);this.highlightPCDSrc&&(this.cacheInstance.updateColor(this.highlightPCDSrc,h),this.highlightPCDSrc=void 0),l.needsUpdate=!0,e.geometry.setAttribute("color",l),r(h),this.render()}}})}updateColor(t){const e=this.scene.getObjectByName(this.pointCloudObjectName);if(e){const r=new a.BufferAttribute(t,3);r.needsUpdate=!0,e.geometry.setAttribute("color",r),this.render()}}setShowDirection(t){this.showDirection=t,this.scene.children.forEach(e=>{e.type==="Group"&&e.children.forEach(r=>{r.type==="ArrowHelper"&&(r.visible=t)})}),this.render()}getTextCanvas(t){const e=document.createElement("canvas"),r=e.getContext("2d");return r&&(r.font=`${50}px " bold`,r.fillStyle="white",r.textAlign="center",r.textBaseline="middle",r.fillText(t,e.width/2,e.height/2)),e}getSensesPointZAxisInPolygon(t,e){const r=this.scene.children.find(o=>o.uuid===this.pointsUuid);let n=0,s=0,c=0,i=0;if(r&&(r==null?void 0:r.geometry)){const o=r==null?void 0:r.geometry.attributes.position.array;for(let h=0;h<o.length;h+=3){const l=o[h],d=o[h+1],p=o[h+2];L({x:l,y:d},t)&&p&&(s=Math.max(p,s),n=Math.min(p,n),i++,e&&p>=e[0]&&p<=e[1]&&c++)}}return{maxZ:s,minZ:n,count:c,zCount:i}}getBasicCoordinate2Canvas(t){const e=this.containerWidth/2,r=this.containerHeight/2;return{x:t.x*e+e,y:t.y*r+r,z:t.z}}get basicCoordinate2CanvasMatrix4(){const t=this.containerWidth/2,e=this.containerHeight/2;return new a.Matrix4().set(t,0,0,t,0,e,0,e,0,0,1,0,0,0,0,1)}getCanvas2BasicCoordinate(t){const e=this.containerWidth/2,r=this.containerHeight/2;return new a.Vector3(t.x/e-e/2,-(t.y/r-r/2),1)}getPolygonSidePoints(t){const{center:{x:e,y:r,z:n},height:s,width:c,depth:i}=t,o={x:e+c/2,y:r+s/2,z:n-i/2},h={x:e+c/2,y:r+s/2,z:n+i/2},l={x:e-c/2,y:r+s/2,z:n+i/2},d={x:e-c/2,y:r+s/2,z:n-i/2};return[o,h,l,d]}getPolygonBackPoints(t){const{center:{x:e,y:r,z:n},height:s,width:c,depth:i}=t,o={x:e-c/2,y:r+s/2,z:n+i/2},h={x:e-c/2,y:r+s/2,z:n-i/2},l={x:e-c/2,y:r-s/2,z:n-i/2},d={x:e-c/2,y:r-s/2,z:n+i/2};return[o,h,l,d]}getPolygonTopPoints(t){const{center:{x:e,y:r,z:n},height:s,width:c,depth:i}=t,o={x:e+c/2,y:r+s/2,z:n+i/2},h={x:e+c/2,y:r-s/2,z:n+i/2},l={x:e-c/2,y:r-s/2,z:n+i/2},d={x:e-c/2,y:r+s/2,z:n+i/2};return[o,h,l,d]}getModelTransformationMatrix(t){const{center:{x:e,y:r,z:n},rotation:s}=t,c=new a.Matrix4().makeTranslation(-e,-r,-n),i=new a.Matrix4().makeTranslation(e,r,n),o=new a.Matrix4().makeRotationZ(s);return new a.Matrix4().multiply(i).multiply(o).multiply(c)}getBoxSidePolygon2DCoordinate(t){return this.getBoxPolygon2DCoordinate(t,g.Left)}getBoxBackPolygon2DCoordinate(t){return this.getBoxPolygon2DCoordinate(t,g.Back)}boxParams2ViewPolygon(t,e){switch(e){case g.Left:return this.getPolygonSidePoints(t);case g.Back:return this.getPolygonBackPoints(t);default:return this.getPolygonTopPoints(t)}}getBoxPolygon2DCoordinate(t,e){const r=this.boxParams2ViewPolygon(t,e),{width:n,height:s}=t,c=new a.Matrix4().premultiply(this.camera.matrixWorldInverse).premultiply(this.camera.projectionMatrix),i=new a.Matrix4().premultiply(this.getModelTransformationMatrix(t)).premultiply(c).premultiply(this.basicCoordinate2CanvasMatrix4);this.sideMatrix=i;const o=r.map(d=>new a.Vector3(d.x,d.y,d.z)).map(d=>d.applyMatrix4(this.sideMatrix)),h=this.containerWidth/n,l=this.containerHeight/s;return{polygon2d:o,zoom:Math.min(h,l)/2}}getBoxTopPolygon2DCoordinate(t){const{width:e,height:r}=t,s=this.getPolygonTopPoints(t).map(o=>new a.Vector3(o.x,o.y,o.z)).map(o=>o.applyMatrix4(this.getModelTransformationMatrix(t))).map(o=>({x:o.y,y:o.x})).map(o=>({x:-(o.x-this.containerWidth/2),y:-(o.y-this.containerHeight/2)})),c=this.containerWidth/e,i=this.containerHeight/r;return{polygon2d:s,zoom:Math.min(c,i)/2}}getNewBoxBySideUpdate(t,e,r,n){const s=new a.Matrix4().makeRotationZ(n.rotation),c=new a.Vector3(-t.x,0,0).applyMatrix4(s);let i=n;return i.center={x:i.center.x+c.x,y:i.center.y+c.y,z:i.center.z-t.z},i=M(P({},i),{width:i.width+e,height:i.height,depth:i.depth+r}),{newBoxParams:i}}getNewBoxByBackUpdate(t,e,r,n){const s=new a.Matrix4().makeRotationZ(n.rotation),c=new a.Vector3(0,-t.x,0).applyMatrix4(s);let i=n;return i.center={x:i.center.x+c.x,y:i.center.y+c.y,z:i.center.z-t.z},i=M(P({},i),{width:i.width,height:i.height+e,depth:i.depth+r}),{newBoxParams:i}}getNewBoxBySideUpdateByPoints(t,e,r,n){var s;const c=(s=this.sideMatrix)==null?void 0:s.invert();if(!this.sideMatrix||!c){console.error("No sideMatrix");return}this.camera.zoom=1,this.camera.updateProjectionMatrix();const i=t.map(m=>new a.Vector3(m.x,m.y,m.z)).map(m=>m.applyMatrix4(c)),[o,h,l,d]=i,p=Math.max(Math.abs(o.x-l.x),Math.abs(o.x-h.x)),f=h.add(d).applyMatrix3(new a.Matrix3().set(1/2,0,0,0,1/2,0,0,0,1/2)).clone().applyMatrix3(new a.Matrix3().set(-1,0,0,0,-1,0,0,0,-1)).add(new a.Vector3(n.center.x,n.center.y,n.center.z));return{newBoxParams:M(P({},n),{center:{x:n.center.x-f.x,y:n.center.y-f.y,z:n.center.z-r},width:p,height:n.height,depth:n.depth+e,rotation:n.rotation})}}filterZAxisPoints(t){const e=t||this.scene.children.find(r=>r.uuid===this.pointsUuid);if(e){const{attributes:r}=e.geometry,{position:n}=r,s=[],{count:c}=n;for(let i=0;i<c;i++){const o=n.getZ(i);s.push(o>this.zAxisLimit?0:1)}e.geometry.setAttribute("visibility",new a.Float32BufferAttribute(s,1)),e.geometry.attributes.visibility.needsUpdate=!0}}render(){this.renderer.render(this.scene,this.camera)}}export{G as PointCloud};
11
+ #include <clipping_planes_fragment>`)},this.loadPCDFile=(i,n)=>z(this,null,function*(){this.clearPointCloud(),this.currentPCDSrc=i;const{points:h,color:l}=yield this.cacheInstance.loadPCDFile(i),p=new c.BufferGeometry;p.setAttribute("position",new c.BufferAttribute(h,3)),p.setAttribute("color",new c.BufferAttribute(l,3));const d=new c.Points(p);this.renderPointCloud(d,n)}),this.loadPCDFileByBox=(i,n,h)=>z(this,null,function*(){const l=(y,f)=>z(this,null,function*(){const{width:C=0,height:m=0,depth:b=0}=h!=null?h:{},x=yield this.filterPointsByBox(M(P({},n),{width:n.width+C,height:n.height+m,depth:n.depth+b}),y,f);if(!x){console.error("filter Error");return}this.clearPointCloud(),this.currentPCDSrc=i;const v=new c.Points(x.geometry);v.name=this.pointCloudObjectName,this.scene.add(v),this.render()}),{points:p,color:d}=yield this.cacheInstance.loadPCDFile(i);l(p,d)}),this.generateRange=i=>{const n=this.createRange(i);this.scene.add(n)},this.generateBoxArrow=({width:i})=>{const n=new c.Vector3(1,0,0),h=new c.Vector3(i/2,0,0),l=2,p=16776960,d=new c.ArrowHelper(n,h,l,p);return d.visible=this.showDirection,d},this.generateBoxTrackID=i=>{if(!i.trackID)return;const n=new c.Texture(this.getTextCanvas(i.trackID.toString()));n.needsUpdate=!0;const h=new c.SpriteMaterial({map:n,depthWrite:!1}),l=new c.Sprite(h);return l.scale.set(5,5,5),l.position.set(-i.width/2,0,i.depth/2+.5),l},this.applyZAxisPoints=i=>{this.zAxisLimit=i,this.filterZAxisPoints(),this.render()},this.updatePointSize=({zoomIn:i,customSize:n})=>{const h=this.scene.getObjectByName(this.pointCloudObjectName);if(!h)return;const l=h.material.size;i?h.material.size=Math.min(l*1.2,10):h.material.size=Math.max(l/1.2,1),n&&(h.material.size=n,this.pointsMaterialSize=n),this.render()},this.container=t,this.renderer=new c.WebGLRenderer({antialias:!0}),this.backgroundColor=s,this.config=a,r&&o?(this.isOrthographicCamera=!0,this.camera=new c.OrthographicCamera(o.left,o.right,o.top,o.bottom,o.near,o.far)):this.camera=new c.PerspectiveCamera(30,this.containerWidth/this.containerHeight,1,1e3),this.initCamera(),this.scene=new c.Scene,this.controls=new N(this.camera,this.renderer.domElement),this.pcdLoader=new I,this.axesHelper=new c.AxesHelper(1e3),this.scene.add(this.camera),e||t.appendChild(this.renderer.domElement),this.init(),this.cacheInstance=E.getInstance()}get DEFAULT_INIT_CAMERA_POSITION(){return new c.Vector3(-.01,0,10)}get containerWidth(){return this.container.clientWidth}get containerHeight(){return this.container.clientHeight}setInitCameraPosition(t){this.initCameraPosition=t}setConfig(t){this.config=t}initOrthographicCamera(t){if(this.camera.type!=="OrthographicCamera")return;const{left:e,right:r,top:o,bottom:s,near:a,far:i}=t;this.camera.left=e,this.camera.right=r,this.camera.top=o,this.camera.bottom=s,this.camera.near=a,this.camera.far=i,this.camera.updateProjectionMatrix()}initPerspectiveCamera(){this.camera.type==="PerspectiveCamera"&&(this.camera.fov=30,this.camera.aspect=this.containerWidth/this.containerHeight,this.camera.near=1,this.camera.far=1e3,this.camera.updateProjectionMatrix())}initCamera(){const{camera:t}=this;if(this.isOrthographicCamera){const{x:e,y:r,z:o}=this.initCameraPosition;t.position.set(e,r,o)}else t.position.set(-1,0,500);t.up.set(0,0,1)}initControls(){const{controls:t}=this;t.addEventListener("change",()=>{this.render()}),this.setDefaultControls()}setDefaultControls(){const{controls:t}=this,e=[0,0,0];t.target=new c.Vector3(...e),t.addEventListener("change",()=>{this.render()}),t.maxPolarAngle=Math.PI/2,t.update()}initRenderer(){const{renderer:t}=this;t.setPixelRatio(window.devicePixelRatio),t.setSize(this.containerWidth,this.containerHeight)}init(){const{scene:t}=this;t.background=new c.Color(this.backgroundColor),this.initControls(),this.initRenderer()}removeObjectByName(t){const e=this.scene.getObjectByName(t);e&&e.removeFromParent()}generateBox(t,e=16777215){const r=e;this.addBoxToSense(t,r),this.render()}getAllAttributeColor(t){return t.reduce((e,r)=>(e[r.attribute]=S.getColorFromConfig({attribute:r.attribute},M(P({},this.config),{attributeConfigurable:!0}),{}),e),{})}generateBoxes(t){t.forEach(e=>{this.addBoxToSense(e)}),this.render()}getOrthographicCamera(t){const{center:e,width:r,height:o}=t,s=10,a=e.x-r/2-s,i=e.x-r/2+s,n=e.y+o/2+s,h=e.y-o/2-s,l=100,p=-100,d=500/l;return{left:a,right:i,top:n,bottom:h,near:l,far:p,zoom:d}}updateCameraZoom(t){this.camera.zoom=t,this.camera.updateProjectionMatrix()}updateCameraByBox(t,e,r){const{center:o,width:s,height:a,depth:i,rotation:n}=t,h=this.getCameraVector(o,n,{width:s,height:a,depth:i},e);return r?(this.updateCamera(r,o),new c.Vector3(r.x,r.y,r.z)):(this.updateCamera(h,o),h)}updateOrthoCamera(t,e){const r=this.updateCameraByBox(t,e);return this.camera.zoom=1,this.camera.updateProjectionMatrix(),{cameraPositionVector:r}}updateTopCamera(){this.setInitCameraPosition(this.DEFAULT_INIT_CAMERA_POSITION),this.camera.zoom=1,this.initCamera(),this.setDefaultControls(),this.camera.updateProjectionMatrix(),this.render()}updateCamera(t,e){this.camera.position.set(t.x,t.y,t.z),this.controls.target=new c.Vector3(e.x,e.y,e.z),this.controls.update()}resetCamera(){this.updateCamera(this.DEFAULT_INIT_CAMERA_POSITION,{x:0,y:0,z:0})}getOrthographicCameraTarget(t){const e=new c.Vector3(0,0,-1).applyQuaternion(t.quaternion);return t.position.clone().add(e)}createThreeMatrix4(t){return new c.Matrix4().set(...t)}filterPointsByBox(t,e,r){var o,s,a;if(!e){const i=this.scene.getObjectByName(this.pointCloudObjectName);if(!i)return console.error("There is no corresponding point cloud object"),Promise.resolve(void 0);e=(a=(s=(o=i==null?void 0:i.geometry)==null?void 0:o.attributes)==null?void 0:s.position)==null?void 0:a.array}if(window.Worker){const{zMin:i,zMax:n,polygonPointList:h}=B(t),l=e;r=r!=null?r:new Float32Array([]);const p={boxParams:t,zMin:i,zMax:n,polygonPointList:h,color:r,position:l};return new Promise(d=>{const y=new V;y.postMessage(p),y.onmessage=f=>{const{color:C,position:m,num:b}=f.data,x=new c.BufferGeometry;x.setAttribute("position",new c.Float32BufferAttribute(m,3)),x.setAttribute("color",new c.Float32BufferAttribute(C,3)),x.computeBoundingSphere(),y.terminate(),d({geometry:x,num:b})}})}return Promise.resolve(void 0)}getCameraVector(t,e,r,o=g.Front,s=H){let a=w.frontViewMatrix4(s);switch(o){case g.Front:break;case g.Back:a=w.backViewMatrix4(s);break;case g.Left:a=w.leftViewMatrix4(s);break;case g.Right:a=w.rightViewMatrix4(s);break;case g.Top:a=w.topViewMatrix4(s);break;case g.LFT:a=w.leftFrontTopViewMatrix4(s,r);break;case g.RBT:a=w.rightBackTopViewMatrix4(s,r);break}const i=this.createThreeMatrix4(a),n=new c.Matrix4().makeTranslation(-t.x,-t.y,-t.z),h=new c.Matrix4().makeTranslation(t.x,t.y,t.z),l=new c.Matrix4().makeRotationZ(e);return new c.Vector3(t.x,t.y,t.z).clone().applyMatrix4(i).applyMatrix4(n).applyMatrix4(l).applyMatrix4(h)}createRange(t){this.removeObjectByName(this.rangeObjectName);const r=new c.EllipseCurve(0,0,t,t,0,2*Math.PI,!1,0).getPoints(50),o=new c.BufferGeometry().setFromPoints(r),s=new c.LineBasicMaterial({color:16711680}),a=new c.Line(o,s);return a.name=this.rangeObjectName,a}renderPointCloud(t,e){t.name=this.pointCloudObjectName;const r=new c.PointsMaterial({vertexColors:!0});r.onBeforeCompile=this.overridePointShader,r.size=this.pointsMaterialSize,e&&this.generateRange(e),this.pointsUuid=t.uuid,t.material=r,this.filterZAxisPoints(t),this.scene.add(t),this.render()}clearPointCloud(){this.removeObjectByName(this.pointCloudObjectName)}clearPointCloudAndRender(){this.clearPointCloud(),this.render()}highlightOriginPointCloud(t){const e=this.scene.getObjectByName(this.pointCloudObjectName);if(!!e)return this.highlightPCDSrc=this.currentPCDSrc,new Promise((r,o)=>{if(window.Worker){const a=(t?[...t]:[]).map(h=>B(h)),i=this.getAllAttributeColor(a),n={cuboidList:a,position:e.geometry.attributes.position.array,color:e.geometry.attributes.color.array,colorList:i};j.postMessage(n),j.onmessage=h=>{const{color:l}=h.data,p=new c.BufferAttribute(l,3);if(!this.highlightPCDSrc||this.highlightPCDSrc!==this.currentPCDSrc||e.geometry.attributes.position.array.length!==l.length){o(new Error("Error Path"));return}this.cacheInstance.updateColor(this.highlightPCDSrc,l),this.highlightPCDSrc=void 0,p.needsUpdate=!0,e.geometry.setAttribute("color",p),r(l),this.render()}}})}updateColor(t){const e=this.scene.getObjectByName(this.pointCloudObjectName);if(e){const r=new c.BufferAttribute(t,3);r.needsUpdate=!0,e.geometry.setAttribute("color",r),this.render()}}setShowDirection(t){this.showDirection=t,this.scene.children.forEach(e=>{e.type==="Group"&&e.children.forEach(r=>{r.type==="ArrowHelper"&&(r.visible=t)})}),this.render()}getTextCanvas(t){const e=document.createElement("canvas"),r=e.getContext("2d");return r&&(r.font=`${50}px " bold`,r.fillStyle="white",r.textAlign="center",r.textBaseline="middle",r.fillText(t,e.width/2,e.height/2)),e}getSensesPointZAxisInPolygon(t,e){const r=this.scene.children.find(n=>n.uuid===this.pointsUuid);let o=0,s=0,a=0,i=0;if(r&&(r==null?void 0:r.geometry)){const n=r==null?void 0:r.geometry.attributes.position.array;for(let h=0;h<n.length;h+=3){const l=n[h],p=n[h+1],d=n[h+2];L({x:l,y:p},t)&&d&&(s=Math.max(d,s),o=Math.min(d,o),i++,e&&d>=e[0]&&d<=e[1]&&a++)}}return{maxZ:s,minZ:o,count:a,zCount:i}}getBasicCoordinate2Canvas(t){const e=this.containerWidth/2,r=this.containerHeight/2;return{x:t.x*e+e,y:t.y*r+r,z:t.z}}get basicCoordinate2CanvasMatrix4(){const t=this.containerWidth/2,e=this.containerHeight/2;return new c.Matrix4().set(t,0,0,t,0,e,0,e,0,0,1,0,0,0,0,1)}getCanvas2BasicCoordinate(t){const e=this.containerWidth/2,r=this.containerHeight/2;return new c.Vector3(t.x/e-e/2,-(t.y/r-r/2),1)}getPolygonSidePoints(t){const{center:{x:e,y:r,z:o},height:s,width:a,depth:i}=t,n={x:e+a/2,y:r+s/2,z:o-i/2},h={x:e+a/2,y:r+s/2,z:o+i/2},l={x:e-a/2,y:r+s/2,z:o+i/2},p={x:e-a/2,y:r+s/2,z:o-i/2};return[n,h,l,p]}getPolygonBackPoints(t){const{center:{x:e,y:r,z:o},height:s,width:a,depth:i}=t,n={x:e-a/2,y:r+s/2,z:o+i/2},h={x:e-a/2,y:r+s/2,z:o-i/2},l={x:e-a/2,y:r-s/2,z:o-i/2},p={x:e-a/2,y:r-s/2,z:o+i/2};return[n,h,l,p]}getPolygonTopPoints(t){const{center:{x:e,y:r,z:o},height:s,width:a,depth:i}=t,n={x:e+a/2,y:r+s/2,z:o+i/2},h={x:e+a/2,y:r-s/2,z:o+i/2},l={x:e-a/2,y:r-s/2,z:o+i/2},p={x:e-a/2,y:r+s/2,z:o+i/2};return[n,h,l,p]}getModelTransformationMatrix(t){const{center:{x:e,y:r,z:o},rotation:s}=t,a=new c.Matrix4().makeTranslation(-e,-r,-o),i=new c.Matrix4().makeTranslation(e,r,o),n=new c.Matrix4().makeRotationZ(s);return new c.Matrix4().multiply(i).multiply(n).multiply(a)}getBoxSidePolygon2DCoordinate(t){return this.getBoxPolygon2DCoordinate(t,g.Left)}getBoxBackPolygon2DCoordinate(t){return this.getBoxPolygon2DCoordinate(t,g.Back)}boxParams2ViewPolygon(t,e){switch(e){case g.Left:return this.getPolygonSidePoints(t);case g.Back:return this.getPolygonBackPoints(t);default:return this.getPolygonTopPoints(t)}}getBoxPolygon2DCoordinate(t,e){const r=this.boxParams2ViewPolygon(t,e),{width:o,height:s}=t,a=new c.Matrix4().premultiply(this.camera.matrixWorldInverse).premultiply(this.camera.projectionMatrix),i=new c.Matrix4().premultiply(this.getModelTransformationMatrix(t)).premultiply(a).premultiply(this.basicCoordinate2CanvasMatrix4);this.sideMatrix=i;const n=r.map(p=>new c.Vector3(p.x,p.y,p.z)).map(p=>p.applyMatrix4(this.sideMatrix)),h=this.containerWidth/o,l=this.containerHeight/s;return{polygon2d:n,zoom:Math.min(h,l)/2}}getBoxTopPolygon2DCoordinate(t){const{width:e,height:r}=t,s=this.getPolygonTopPoints(t).map(n=>new c.Vector3(n.x,n.y,n.z)).map(n=>n.applyMatrix4(this.getModelTransformationMatrix(t))).map(n=>({x:n.y,y:n.x})).map(n=>({x:-(n.x-this.containerWidth/2),y:-(n.y-this.containerHeight/2)})),a=this.containerWidth/e,i=this.containerHeight/r;return{polygon2d:s,zoom:Math.min(a,i)/2}}getNewBoxBySideUpdate(t,e,r,o){const s=new c.Matrix4().makeRotationZ(o.rotation),a=new c.Vector3(-t.x,0,0).applyMatrix4(s);let i=o;return i.center={x:i.center.x+a.x,y:i.center.y+a.y,z:i.center.z-t.z},i=M(P({},i),{width:i.width+e,height:i.height,depth:i.depth+r}),{newBoxParams:i}}getNewBoxByBackUpdate(t,e,r,o){const s=new c.Matrix4().makeRotationZ(o.rotation),a=new c.Vector3(0,-t.x,0).applyMatrix4(s);let i=o;return i.center={x:i.center.x+a.x,y:i.center.y+a.y,z:i.center.z-t.z},i=M(P({},i),{width:i.width,height:i.height+e,depth:i.depth+r}),{newBoxParams:i}}getNewBoxBySideUpdateByPoints(t,e,r,o){var s;const a=(s=this.sideMatrix)==null?void 0:s.invert();if(!this.sideMatrix||!a){console.error("No sideMatrix");return}this.camera.zoom=1,this.camera.updateProjectionMatrix();const i=t.map(m=>new c.Vector3(m.x,m.y,m.z)).map(m=>m.applyMatrix4(a)),[n,h,l,p]=i,d=Math.max(Math.abs(n.x-l.x),Math.abs(n.x-h.x)),f=h.add(p).applyMatrix3(new c.Matrix3().set(1/2,0,0,0,1/2,0,0,0,1/2)).clone().applyMatrix3(new c.Matrix3().set(-1,0,0,0,-1,0,0,0,-1)).add(new c.Vector3(o.center.x,o.center.y,o.center.z));return{newBoxParams:M(P({},o),{center:{x:o.center.x-f.x,y:o.center.y-f.y,z:o.center.z-r},width:d,height:o.height,depth:o.depth+e,rotation:o.rotation})}}filterZAxisPoints(t){const e=t||this.scene.children.find(r=>r.uuid===this.pointsUuid);if(e){const{attributes:r}=e.geometry,{position:o}=r,s=[],{count:a}=o;for(let i=0;i<a;i++){const n=o.getZ(i);s.push(n>this.zAxisLimit?0:1)}e.geometry.setAttribute("visibility",new c.Float32BufferAttribute(s,1)),e.geometry.attributes.visibility.needsUpdate=!0}}render(){this.renderer.render(this.scene,this.camera)}}export{G as PointCloud};
@@ -0,0 +1,131 @@
1
+ import * as THREE from 'three';
2
+ import { colorArr, toolStyleConverter } from '@labelbee/lb-utils';
3
+ import DrawUtils from '../../../utils/tool/DrawUtils.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
+ class PointCloudRender {
25
+ constructor({store, on, unbind, nextTick, config}) {
26
+ this.clearStash = () => {
27
+ var _a, _b;
28
+ const pointsGeo = this.scene.getObjectByName((_b = (_a = this.store.cacheSegData) == null ? void 0 : _a.id) != null ? _b : "");
29
+ if (pointsGeo) {
30
+ pointsGeo.removeFromParent();
31
+ this.render3d();
32
+ }
33
+ };
34
+ this.generateNewPoints = (segmentData) => {
35
+ const geometry = new THREE.BufferGeometry();
36
+ geometry.setAttribute("position", new THREE.BufferAttribute(segmentData.points, 3));
37
+ const pointsMaterial = new THREE.PointsMaterial({color: this.getCurrentColor(segmentData.attribute), size: 10});
38
+ const newPoints = new THREE.Points(geometry, pointsMaterial);
39
+ newPoints.name = segmentData.id;
40
+ this.store.scene.add(newPoints);
41
+ this.render3d();
42
+ };
43
+ this.updateNewPoints = (segmentData) => {
44
+ var _a;
45
+ const originPoints = this.store.scene.getObjectByName((_a = segmentData == null ? void 0 : segmentData.id) != null ? _a : "");
46
+ if (originPoints && segmentData) {
47
+ originPoints.geometry.setAttribute("position", new THREE.Float32BufferAttribute(segmentData.points, 3));
48
+ originPoints.material = new THREE.PointsMaterial({
49
+ color: this.getCurrentColor(segmentData.attribute),
50
+ size: 10
51
+ });
52
+ originPoints.geometry.attributes.position.needsUpdate = true;
53
+ this.render3d();
54
+ }
55
+ };
56
+ this.updatePointsColor = (segmentData = this.store.cacheSegData) => {
57
+ var _a;
58
+ const originPoints = this.store.scene.getObjectByName((_a = segmentData == null ? void 0 : segmentData.id) != null ? _a : "");
59
+ if (originPoints && segmentData) {
60
+ segmentData.attribute = this.store.currentAttribute;
61
+ originPoints.material = new THREE.PointsMaterial({
62
+ color: this.getCurrentColor(segmentData.attribute),
63
+ size: 10
64
+ });
65
+ this.render3d();
66
+ }
67
+ };
68
+ this.render3d = () => {
69
+ this.store.renderer.render(this.store.scene, this.store.camera);
70
+ };
71
+ this.store = store;
72
+ this.on = on;
73
+ this.unbind = unbind;
74
+ this.nextTick = nextTick;
75
+ this.config = config;
76
+ this.initMsg();
77
+ this.animate();
78
+ this.generateNewPoints = this.generateNewPoints.bind(this);
79
+ this.clearStash = this.clearStash.bind(this);
80
+ this.render3d = this.render3d.bind(this);
81
+ this.updateNewPoints = this.updateNewPoints.bind(this);
82
+ this.updatePointsColor = this.updatePointsColor.bind(this);
83
+ }
84
+ get scene() {
85
+ return this.store.scene;
86
+ }
87
+ getCurrentColor(attribute = this.store.currentAttribute) {
88
+ if (!attribute || !this.config) {
89
+ return colorArr[0].hexString;
90
+ }
91
+ const {fill} = toolStyleConverter.getColorFromConfig({attribute}, __spreadProps(__spreadValues({}, this.config), {attributeConfigurable: true}), {});
92
+ return fill;
93
+ }
94
+ initMsg() {
95
+ this.on("addNewPointsCloud", this.generateNewPoints);
96
+ this.on("updateNewPoints", this.updateNewPoints);
97
+ this.on("clearStashRender", this.clearStash);
98
+ this.on("reRender3d", this.render3d);
99
+ }
100
+ unbindMsg() {
101
+ this.unbind("addNewPointsCloud", this.generateNewPoints);
102
+ this.unbind("updateNewPoints", this.updateNewPoints);
103
+ this.unbind("clearStashRender", this.clearStash);
104
+ this.unbind("reRender3d", this.render3d);
105
+ }
106
+ get canvas2d() {
107
+ return this.store.canvas2d;
108
+ }
109
+ clearCanvasMouse() {
110
+ var _a, _b;
111
+ (_b = (_a = this.canvas2d) == null ? void 0 : _a.getContext("2d")) == null ? void 0 : _b.clearRect(0, 0, this.store.containerWidth, this.store.containerHeight);
112
+ }
113
+ renderCanvas2dPolygon() {
114
+ var _a;
115
+ if (((_a = this.store.polygon2d) == null ? void 0 : _a.length) > 0 && this.canvas2d) {
116
+ DrawUtils.drawPolygon(this.canvas2d, this.store.polygon2d, {
117
+ isClose: false,
118
+ color: this.getCurrentColor(),
119
+ thickness: 4
120
+ });
121
+ }
122
+ }
123
+ animate() {
124
+ requestAnimationFrame(this.animate.bind(this));
125
+ this.clearCanvasMouse();
126
+ this.renderCanvas2dPolygon();
127
+ this.nextTick();
128
+ }
129
+ }
130
+
131
+ export { PointCloudRender as default };
@@ -0,0 +1,95 @@
1
+ import { EPointCloudSegmentStatus } from '@labelbee/lb-utils';
2
+ import LassoSelector from './selector/lassoSelector.js';
3
+ import CircleSelector from './selector/circleSelector.js';
4
+
5
+ class PointCloudSegmentOperation {
6
+ constructor(props) {
7
+ this.onMouseMove = (iev) => {
8
+ if (this.store.isCheckStatus || this.store.isReadyStatus) {
9
+ this.store.updateMouse({x: iev.offsetX, y: iev.offsetY});
10
+ }
11
+ if (this.isForbid) {
12
+ return;
13
+ }
14
+ const ev = {
15
+ offsetX: iev.offsetX,
16
+ offsetY: iev.offsetY,
17
+ button: iev.buttons
18
+ };
19
+ this.currentTool.mouseMove(ev);
20
+ };
21
+ this.onMouseDown = (iev) => {
22
+ if (this.isForbid) {
23
+ return;
24
+ }
25
+ this.currentTool.mouseDown(iev);
26
+ };
27
+ this.onMouseUp = (iev) => {
28
+ if (this.isForbid || this.store.orbiting === true) {
29
+ return;
30
+ }
31
+ if (this.baseMouseDown(iev)) {
32
+ return;
33
+ }
34
+ this.currentTool.mouseUp(iev);
35
+ };
36
+ this.baseMouseDown = (e) => {
37
+ switch (e.button) {
38
+ case 0:
39
+ if (this.store.isReadyStatus || this.store.isCheckStatus) {
40
+ this.store.checkPoints();
41
+ return true;
42
+ }
43
+ break;
44
+ }
45
+ };
46
+ this._raycasting = () => {
47
+ if ([EPointCloudSegmentStatus.Ready, EPointCloudSegmentStatus.Check].includes(this.store.segmentStatus)) {
48
+ const {mouse, camera, raycaster} = this.store;
49
+ raycaster.setFromCamera(mouse, camera);
50
+ const intersects = raycaster.intersectObjects(this.store.allSegmentPoints, false);
51
+ const intersect = intersects[0];
52
+ if (intersect) {
53
+ this.store.highlightPoints(intersect.object);
54
+ } else {
55
+ this.store.resetAllSegDataSizeAndRender();
56
+ this.store.resetHoverPointsID();
57
+ }
58
+ }
59
+ };
60
+ this.dom = props.dom;
61
+ this.store = props.store;
62
+ this.lassoSelector = new LassoSelector(this.store);
63
+ this.circleSelector = new CircleSelector(this.store);
64
+ this.currentTool = this.circleSelector;
65
+ this.currentToolName = "CircleSelector";
66
+ this.dom.addEventListener("pointermove", this.onMouseMove.bind(this));
67
+ this.dom.addEventListener("pointerdown", this.onMouseDown.bind(this));
68
+ this.dom.addEventListener("pointerup", this.onMouseUp.bind(this));
69
+ this.updateSelector2Lasso = this.updateSelector2Lasso.bind(this);
70
+ this.updateSelector2Circle = this.updateSelector2Circle.bind(this);
71
+ }
72
+ getCoordinate(e) {
73
+ const bounding = this.dom.getBoundingClientRect();
74
+ return {
75
+ x: e.clientX - bounding.left,
76
+ y: e.clientY - bounding.top
77
+ };
78
+ }
79
+ get forbidOperation() {
80
+ return this.store.forbidOperation;
81
+ }
82
+ get isForbid() {
83
+ return this.forbidOperation;
84
+ }
85
+ updateSelector2Lasso() {
86
+ this.currentTool = this.lassoSelector;
87
+ this.currentToolName = "LassoSelector";
88
+ }
89
+ updateSelector2Circle() {
90
+ this.currentTool = this.circleSelector;
91
+ this.currentToolName = "CircleSelector";
92
+ }
93
+ }
94
+
95
+ export { PointCloudSegmentOperation };
@@ -0,0 +1,23 @@
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.store.getPointsInPolygon(this.polygon);
12
+ this.polygon = [];
13
+ this.scene.store.syncPolygon2d([]);
14
+ }
15
+ }
16
+ mouseDrag(ev) {
17
+ if (ev.which === 3) {
18
+ this.pushPoint(ev.offsetX, ev.offsetY);
19
+ }
20
+ }
21
+ }
22
+
23
+ export { Sse3dLassoSelector as default };
@@ -0,0 +1,15 @@
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
+ this.scene.store.syncPolygon2d(this.polygon);
9
+ }
10
+ deactivate() {
11
+ this.polygon = [];
12
+ }
13
+ }
14
+
15
+ export { Sse3dSelector as default };
@@ -0,0 +1,39 @@
1
+ import DefaultSelector from './selector.js';
2
+
3
+ class CircleSelector extends DefaultSelector {
4
+ constructor() {
5
+ super(...arguments);
6
+ this.radius = 20;
7
+ }
8
+ mouseDown(ev) {
9
+ if (ev.button === 2) {
10
+ this.pushPoint(ev.offsetX, ev.offsetY);
11
+ this.startX = ev.offsetX;
12
+ this.startY = ev.offsetY;
13
+ }
14
+ }
15
+ mouseUp(ev) {
16
+ if (ev.button === 2) {
17
+ this.store.getPointsInPolygon(this.polygon2d);
18
+ this.polygon2d.length = 0;
19
+ this.startX = this.startY = NaN;
20
+ }
21
+ }
22
+ mouseMove(ev) {
23
+ if (ev.button === 2 && this.startX && this.startY) {
24
+ this.polygon2d.length = 0;
25
+ const precision = 64;
26
+ const PI2 = Math.PI * 2;
27
+ const ox = this.startX;
28
+ const oy = this.startY;
29
+ const nx = ev.offsetX;
30
+ const ny = ev.offsetY;
31
+ const r = Math.sqrt((nx - ox) * (nx - ox) + (ny - oy) * (ny - oy));
32
+ for (let a = 0; a < PI2; a += PI2 / precision) {
33
+ this.pushPoint(ox + r * Math.cos(a), oy - r * Math.sin(a));
34
+ }
35
+ }
36
+ }
37
+ }
38
+
39
+ export { CircleSelector as default };