@labelbee/lb-annotation 1.15.0 → 1.16.0-alpha.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.
- package/dist/core/pointCloud/index.js +5 -5
- package/dist/core/pointCloud/render/index.js +1 -0
- package/dist/core/pointCloud/segmentation.js +1 -0
- package/dist/core/pointCloud/selector/circleSelector.js +1 -0
- package/dist/core/pointCloud/selector/lassoSelector.js +1 -0
- package/dist/core/pointCloud/selector/selector.js +1 -0
- package/dist/core/pointCloud/store/fsm.js +1 -0
- package/dist/core/pointCloud/store/index.js +1 -0
- package/dist/types/core/pointCloud/index.d.ts +46 -3
- package/dist/types/core/pointCloud/render/index.d.ts +39 -0
- package/dist/types/core/pointCloud/segmentation.d.ts +35 -0
- package/dist/types/core/pointCloud/selector/circleSelector.d.ts +9 -0
- package/dist/types/core/pointCloud/selector/lassoSelector.d.ts +6 -0
- package/dist/types/core/pointCloud/selector/selector.d.ts +21 -0
- package/dist/types/core/pointCloud/store/fsm.d.ts +21 -0
- package/dist/types/core/pointCloud/store/index.d.ts +110 -0
- package/es/core/pointCloud/index.js +5 -5
- package/es/core/pointCloud/render/index.js +1 -0
- package/es/core/pointCloud/segmentation.js +1 -0
- package/es/core/pointCloud/selector/circleSelector.js +1 -0
- package/es/core/pointCloud/selector/lassoSelector.js +1 -0
- package/es/core/pointCloud/selector/selector.js +1 -0
- package/es/core/pointCloud/store/fsm.js +1 -0
- package/es/core/pointCloud/store/index.js +1 -0
- package/package.json +2 -2
|
@@ -1,11 +1,11 @@
|
|
|
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"),MathUtils=require("../../utils/MathUtils.js"),PCDLoader=require("./PCDLoader.js"),OrbitControls=require("./OrbitControls.js"),cache=require("./cache.js"),matrix=require("./matrix.js");require("../../constant/tool.js"),require("../scheduler.js");function _interopNamespace(
|
|
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"),MathUtils=require("../../utils/MathUtils.js"),PCDLoader=require("./PCDLoader.js"),OrbitControls=require("./OrbitControls.js"),cache=require("./cache.js"),matrix=require("./matrix.js"),segmentation=require("./segmentation.js"),index=require("./store/index.js"),index$1=require("./render/index.js"),eventListener=require("../toolOperation/eventListener.js");require("../../constant/tool.js"),require("../scheduler.js");function _interopNamespace(g){if(g&&g.__esModule)return g;var t=Object.create(null);return g&&Object.keys(g).forEach(function(e){if(e!=="default"){var i=Object.getOwnPropertyDescriptor(g,e);Object.defineProperty(t,e,i.get?i:{enumerable:!0,get:function(){return g[e]}})}}),t.default=g,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=(g,t,e)=>t in g?__defProp(g,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):g[t]=e,__spreadValues=(g,t)=>{for(var e in t||(t={}))__hasOwnProp.call(t,e)&&__defNormalProp(g,e,t[e]);if(__getOwnPropSymbols)for(var e of __getOwnPropSymbols(t))__propIsEnum.call(t,e)&&__defNormalProp(g,e,t[e]);return g},__spreadProps=(g,t)=>__defProps(g,__getOwnPropDescs(t)),__async=(g,t,e)=>new Promise((i,n)=>{var s=r=>{try{o(e.next(r))}catch(c){n(c)}},a=r=>{try{o(e.throw(r))}catch(c){n(c)}},o=r=>r.done?i(r.value):Promise.resolve(r.value).then(s,a);o((e=e.apply(g,t)).next())});const DEFAULT_DISTANCE=30,highlightWorker=new highlightWorker$1({type:"module"});class PointCloud extends eventListener{constructor({container:t,noAppend:e,isOrthographicCamera:i,orthographicParams:n,backgroundColor:s="#4C4C4C",config:a,isSegment:o}){super();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.nextTick=()=>{!this.segmentOperation||this.segmentOperation._raycasting()},this.keydown=r=>{if(!!this.store)switch(r.key){case" ":this.controls.enablePan=!0,this.store.setForbidOperation(!0);break}},this.keyup=r=>{if(!!this.store)switch(r.key){case" ":this.controls.enablePan=!1,this.store.setForbidOperation(!1);break}},this.addSphereToSense=(r,c="blue")=>{var h;const l=(h=r.id)!=null?h:uuid();this.removeObjectByName(l);const{radius:d,widthSegments:u,heightSegments:f}=lbUtils.DEFAULT_SPHERE_PARAMS,{center:p}=r,m=new THREE__namespace.Group,x=new THREE__namespace.SphereGeometry(d,u,f),y=new THREE__namespace.MeshBasicMaterial({color:c}),w=new THREE__namespace.Mesh(x,y);w.position.set(p.x,p.y,p.z),m.add(w),m.name=l,this.scene.add(m)},this.generateSphere=r=>{const{fill:c}=lbUtils.toolStyleConverter.getColorFromConfig({attribute:r.attribute},__spreadProps(__spreadValues({},this.config),{attributeConfigurable:!0}),{});this.addSphereToSense(r,c),this.render()},this.generateSpheres=r=>{r.forEach(c=>{const{fill:h}=lbUtils.toolStyleConverter.getColorFromConfig({attribute:c.attribute},__spreadProps(__spreadValues({},this.config),{attributeConfigurable:!0}),{});this.addSphereToSense(c,h)}),this.render()},this.addBoxToSense=(r,c=16777215)=>{var h;const l=(h=r.id)!=null?h:uuid();this.removeObjectByName(l);const{center:d,width:u,height:f,depth:p,rotation:m}=r,x=new THREE__namespace.Group,y=new THREE__namespace.BoxGeometry(u,f,p),w=new THREE__namespace.MeshBasicMaterial({color:"blue"}),C=new THREE__namespace.Mesh(y,w),P=new THREE__namespace.BoxHelper(C,c),v=this.generateBoxArrow(r),b=this.generateBoxTrackID(r);b&&x.add(b),x.add(P),x.add(v),d&&x.position.set(d.x,d.y,d.z),m&&x.rotation.set(0,0,m),x.name=l,this.scene.add(x)},this.applyCameraTarget=r=>{if(this.camera.type==="OrthographicCamera"&&r){const c=this.getOrthographicCameraTarget(r);this.updateCameraZoom(r.zoom),this.updateCamera(r.position,c)}},this.overridePointShader=r=>{r.vertexShader=`
|
|
2
2
|
attribute float sizes;
|
|
3
3
|
attribute float visibility;
|
|
4
4
|
varying float vVisible;
|
|
5
|
-
${
|
|
5
|
+
${r.vertexShader}`.replace("gl_PointSize = size;",`gl_PointSize = size;
|
|
6
6
|
vVisible = visibility;
|
|
7
|
-
`),
|
|
7
|
+
`),r.fragmentShader=`
|
|
8
8
|
varying float vVisible;
|
|
9
|
-
${
|
|
9
|
+
${r.fragmentShader}`.replace("#include <clipping_planes_fragment>",`
|
|
10
10
|
if (vVisible < 0.5) discard;
|
|
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 d=new THREE__namespace.Points(l);this.renderPointCloud(d,n)}),this.loadPCDFileByBox=(i,n,c)=>__async(this,null,function*(){const h=(g,x)=>__async(this,null,function*(){const{width:p=0,height:u=0,depth:y=0}=c!=null?c:{},f=yield this.filterPointsByBox(__spreadProps(__spreadValues({},n),{width:n.width+p,height:n.height+u,depth:n.depth+y}),g,x);if(!f){console.error("filter Error");return}this.clearPointCloud(),this.currentPCDSrc=i;const w=new THREE__namespace.Points(f.geometry);w.name=this.pointCloudObjectName,this.scene.add(w),this.render()}),{points:l,color:d}=yield this.cacheInstance.loadPCDFile(i);h(l,d)}),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,d=new THREE__namespace.ArrowHelper(n,c,h,l);return d.visible=this.showDirection,d},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,d=500/h;return{left:a,right:i,top:n,bottom:c,near:h,far:l,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,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)}updateCameraBySphere(t,e){const{center:r}=t,{radius:o}=lbUtils.DEFAULT_SPHERE_PARAMS,s=this.getCameraVector(r,0,{width:o*2,height:o*2,depth:o*2},e);return this.updateCamera(s,r),s}updateOrthoCamera(t,e){const r=this.updateCameraByBox(t,e);return this.camera.zoom=1,this.camera.updateProjectionMatrix(),{cameraPositionVector:r}}updateOrthoCameraBySphere(t,e){const r=this.updateCameraBySphere(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(d=>{const g=new filterBoxWorker;g.postMessage(l),g.onmessage=x=>{const{color:p,position:u,num:y}=x.data,f=new THREE__namespace.BufferGeometry;f.setAttribute("position",new THREE__namespace.Float32BufferAttribute(u,3)),f.setAttribute("color",new THREE__namespace.Float32BufferAttribute(p,3)),f.computeBoundingSphere(),g.terminate(),d({geometry:f,num:y})}})}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}filterNoise(t){let e=[...t];e.sort((l,d)=>l.z-d.z);const r=Math.floor(e.length*.05),o=e[r];e=e.filter(({z:l})=>l>o.z+.1);const s=.005,a=Math.floor(e.length*(1-s));e=e.slice(0,a),e.sort((l,d)=>l.x-d.x);const i=Math.floor(e.length*s),n=Math.floor(e.length*(1-s));e=e.slice(i,n),e.sort((l,d)=>l.y-d.y);const c=Math.floor(e.length*s),h=Math.floor(e.length*(1-s));return e=e.slice(c,h),e.length>100?e:t}getFittedCoordinates(t,e){const r=[];let o=[...t,t[0]];e.forEach(({x:i,y:n})=>{t.forEach((c,h)=>{const l=o[h+1],d=MathUtils.default.getFootOfPerpendicular({x:i,y:n},c,l,!1,!0).length;(!r[h]||d<r[h].distance)&&(r[h]={distance:d,point:{x:i,y:n}})})}),o=[t[t.length-1],...t,t[0]];const s=[r[r.length-1],...r];return t.map((i,n)=>{const c=o[n],h=o[n+1],l=o[n+2];return lbUtils.PointCloudUtils.getIntersectionBySlope({p1:s[n].point,line1:[c,h],p2:s[n+1].point,line2:[h,l]})})}getSensesPointZAxisInPolygon(t,e,r){var o,s,a;const i=this.scene.children.find(p=>p.uuid===this.pointsUuid);let n=0,c=0,h=0,l=0,d=[],g=[];const x=((a=(s=(o=i==null?void 0:i.geometry)==null?void 0:o.attributes)==null?void 0:s.position)==null?void 0:a.array)||[];for(let p=0;p<x.length;p+=3){const u=x[p],y=x[p+1],f=x[p+2];polygonTool.isInPolygon({x:u,y},t)&&(f||f===0)&&g.push({x:u,y,z:f})}return g.length?(r&&(g=this.filterNoise(g),d=this.getFittedCoordinates(t,g)),g.sort((p,u)=>p.z-u.z),n=g[0].z-.01,c=g[g.length-1].z+.01,l=g.length,e&&(h=g.filter(({z:p})=>p>=e[0]&&p<=e[1]).length),{maxZ:c,minZ:n,count:h,zCount:l,fittedCoordinates:d}):{maxZ:c,minZ:n,count:h,zCount:l,fittedCoordinates:d}}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)}getSphereSidePoint2DCoordinate(t){return this.getSpherePoint2DCoordinate(t)}getSphereBackPoint2DCoordinate(t){return this.getSpherePoint2DCoordinate(t)}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}}getSpherePoint2DCoordinate(t){const{center:e,attribute:r,id:o,valid:s}=t,{radius:a}=lbUtils.DEFAULT_SPHERE_PARAMS,i={center:e,attribute:r,id:o,valid:s,width:a*2,height:a*2,depth:a*2,rotation:0},n=new THREE__namespace.Matrix4().premultiply(this.camera.matrixWorldInverse).premultiply(this.camera.projectionMatrix),c=new THREE__namespace.Matrix4().premultiply(this.getModelTransformationMatrix(i)).premultiply(n).premultiply(this.basicCoordinate2CanvasMatrix4);this.sideMatrix=c;const h=new THREE__namespace.Vector3(e.x,e.y,e.z).applyMatrix4(this.sideMatrix),l=this.containerWidth/(a*2),d=this.containerHeight/(a*2);return{point2d:h,zoom:Math.min(l,d)/2}}getSphereTopPoint2DCoordinate(t){const{center:e}=t,{radius:r}=lbUtils.DEFAULT_SPHERE_PARAMS,o={x:-(e.y-this.containerWidth/2),y:-(e.x-this.containerHeight/2)},s=this.containerWidth/(r*2),a=this.containerHeight/(r*2);return{point2d:o,zoom:Math.min(s,a)/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(u=>new THREE__namespace.Vector3(u.x,u.y,u.z)).map(u=>u.applyMatrix4(a)),[n,c,h,l]=i,d=Math.max(Math.abs(n.x-h.x),Math.abs(n.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(o.center.x,o.center.y,o.center.z));return{newBoxParams:__spreadProps(__spreadValues({},o),{center:{x:o.center.x-x.x,y:o.center.y-x.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 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=(...r)=>__async(this,[...r],function*(c=this.currentPCDSrc,h){if(!c)return;this.clearPointCloud(),this.currentPCDSrc=c;const{points:l,color:d}=yield this.cacheInstance.loadPCDFile(c),u=new THREE__namespace.BufferGeometry;u.setAttribute("position",new THREE__namespace.BufferAttribute(l,3)),u.setAttribute("color",new THREE__namespace.BufferAttribute(d,3)),this.initCloudData(l);const f=new THREE__namespace.Points(u);this.renderPointCloud(f,h)}),this.loadPCDFileByBox=(r,c,h)=>__async(this,null,function*(){const l=(f,p)=>__async(this,null,function*(){const{width:m=0,height:x=0,depth:y=0}=h!=null?h:{},w=yield this.filterPointsByBox(__spreadProps(__spreadValues({},c),{width:c.width+m,height:c.height+x,depth:c.depth+y}),f,p);if(!w){console.error("filter Error");return}this.clearPointCloud(),this.currentPCDSrc=r;const C=new THREE__namespace.Points(w.geometry);C.name=this.pointCloudObjectName,this.scene.add(C),this.render()}),{points:d,color:u}=yield this.cacheInstance.loadPCDFile(r);l(d,u)}),this.generateRange=r=>{const c=this.createRange(r);this.scene.add(c)},this.generateBoxArrow=({width:r})=>{const c=new THREE__namespace.Vector3(1,0,0),h=new THREE__namespace.Vector3(r/2,0,0),l=2,d=16776960,u=new THREE__namespace.ArrowHelper(c,h,l,d);return u.visible=this.showDirection,u},this.generateBoxTrackID=r=>{if(!r.trackID)return;const c=new THREE__namespace.Texture(this.getTextCanvas(r.trackID.toString()));c.needsUpdate=!0;const h=new THREE__namespace.SpriteMaterial({map:c,depthWrite:!1}),l=new THREE__namespace.Sprite(h);return l.scale.set(5,5,5),l.position.set(-r.width/2,0,r.depth/2+.5),l},this.applyZAxisPoints=r=>{this.zAxisLimit=r,this.filterZAxisPoints(),this.render()},this.updatePointSize=({zoomIn:r,customSize:c})=>{const h=this.scene.getObjectByName(this.pointCloudObjectName);if(!h)return;const l=h.material.size;r?h.material.size=Math.min(l*1.2,10):h.material.size=Math.max(l/1.2,1),c&&(h.material.size=c,this.pointsMaterialSize=c),this.render()},this.container=t,this.renderer=new THREE__namespace.WebGLRenderer({antialias:!0}),this.backgroundColor=s,this.config=a,i&&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,o?this.container:this.renderer.domElement),this.pcdLoader=new PCDLoader.PCDLoader,this.axesHelper=new THREE__namespace.AxesHelper(1e3),this.scene.add(this.axesHelper),this.scene.add(this.camera),e||t.appendChild(this.renderer.domElement),this.init(),this.cacheInstance=cache.PointCloudCache.getInstance(),o===!0&&this.initSegment()}initSegment(){this.store=new index(this.pointCloudDelegate),this.controls.enablePan=!1,this.controls.addEventListener("start",this.orbiterStart.bind(this)),this.controls.addEventListener("change",this.orbiterChange.bind(this)),this.controls.addEventListener("end",this.orbiterEnd.bind(this)),this.segmentOperation=new segmentation.PointCloudSegmentOperation({dom:this.container,store:this.store}),this.pointCloudRender=new index$1(__spreadProps(__spreadValues({store:this.store},this.eventBus),{nextTick:this.nextTick,config:this.config})),this.initMsg(),document.addEventListener("keydown",this.keydown),document.addEventListener("keyup",this.keyup)}orbiterStart(){}orbiterChange(){!this.store||(this.store.orbiting=!0)}orbiterEnd(){!this.store||(this.store.orbiting=!1)}get currentSegmentTool(){var t;return(t=this.segmentOperation)==null?void 0:t.currentToolName}initMsg(){!this.segmentOperation||(this.on("CircleSelector",this.segmentOperation.updateSelector2Circle.bind(this.segmentOperation)),this.on("LassoSelector",this.segmentOperation.updateSelector2Lasso.bind(this.segmentOperation)),this.on("clearPointCloud",this.clearPointCloud.bind(this)),this.on("loadPCDFile",this.loadPCDFile.bind(this)))}unbindMsg(){!this.segmentOperation||(this.unbind("CircleSelector",this.segmentOperation.updateSelector2Circle.bind(this.segmentOperation)),this.unbind("LassoSelector",this.segmentOperation.updateSelector2Lasso.bind(this.segmentOperation)),this.unbind("clearPointCloud",this.clearPointCloud.bind(this)),this.unbind("loadPCDFile",this.loadPCDFile.bind(this)))}get eventBus(){return{on:this.on.bind(this),emit:this.emit.bind(this),unbind:this.unbind.bind(this)}}get pointCloudDelegate(){return __spreadValues({container:this.container,scene:this.scene,camera:this.camera,renderer:this.renderer},this.eventBus)}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:i,top:n,bottom:s,near:a,far:o}=t;this.camera.left=e,this.camera.right=i,this.camera.top=n,this.camera.bottom=s,this.camera.near=a,this.camera.far=o,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:i,z:n}=this.initCameraPosition;t.position.set(e,i,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 i=e;this.addBoxToSense(t,i),this.render()}getAllAttributeColor(t){return t.reduce((e,i)=>(e[i.attribute]=lbUtils.toolStyleConverter.getColorFromConfig({attribute:i.attribute},__spreadProps(__spreadValues({},this.config),{attributeConfigurable:!0}),{}),e),{})}generateBoxes(t){t.forEach(e=>{this.addBoxToSense(e)}),this.render()}getOrthographicCamera(t){const{center:e,width:i,height:n}=t,s=10,a=e.x-i/2-s,o=e.x-i/2+s,r=e.y+n/2+s,c=e.y-n/2-s,h=100,l=-100,d=500/h;return{left:a,right:o,top:r,bottom:c,near:h,far:l,zoom:d}}updateCameraZoom(t){this.camera.zoom=t,this.camera.updateProjectionMatrix()}updateCameraByBox(t,e,i){const{center:n,width:s,height:a,depth:o,rotation:r}=t,c=this.getCameraVector(n,r,{width:s,height:a,depth:o},e);return i?(this.updateCamera(i,n),new THREE__namespace.Vector3(i.x,i.y,i.z)):(this.updateCamera(c,n),c)}updateCameraBySphere(t,e){const{center:i}=t,{radius:n}=lbUtils.DEFAULT_SPHERE_PARAMS,s=this.getCameraVector(i,0,{width:n*2,height:n*2,depth:n*2},e);return this.updateCamera(s,i),s}updateOrthoCamera(t,e){const i=this.updateCameraByBox(t,e);return this.camera.zoom=1,this.camera.updateProjectionMatrix(),{cameraPositionVector:i}}updateOrthoCameraBySphere(t,e){const i=this.updateCameraBySphere(t,e);return this.camera.zoom=1,this.camera.updateProjectionMatrix(),{cameraPositionVector:i}}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,i){var n,s,a;if(!e){const o=this.scene.getObjectByName(this.pointCloudObjectName);if(!o)return console.error("There is no corresponding point cloud object"),Promise.resolve(void 0);e=(a=(s=(n=o==null?void 0:o.geometry)==null?void 0:n.attributes)==null?void 0:s.position)==null?void 0:a.array}if(window.Worker){const{zMin:o,zMax:r,polygonPointList:c}=matrix.getCuboidFromPointCloudBox(t),h=e;i=i!=null?i:new Float32Array([]);const l={boxParams:t,zMin:o,zMax:r,polygonPointList:c,color:i,position:h};return new Promise(d=>{const u=new filterBoxWorker;u.postMessage(l),u.onmessage=f=>{const{color:p,position:m,num:x}=f.data,y=new THREE__namespace.BufferGeometry;y.setAttribute("position",new THREE__namespace.Float32BufferAttribute(m,3)),y.setAttribute("color",new THREE__namespace.Float32BufferAttribute(p,3)),y.computeBoundingSphere(),u.terminate(),d({geometry:y,num:x})}})}return Promise.resolve(void 0)}getCameraVector(t,e,i,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,i);break;case lbUtils.EPerspectiveView.RBT:a=lbUtils.PerspectiveShiftUtils.rightBackTopViewMatrix4(s,i);break}const o=this.createThreeMatrix4(a),r=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(o).applyMatrix4(r).applyMatrix4(h).applyMatrix4(c)}createRange(t){this.removeObjectByName(this.rangeObjectName);const i=new THREE__namespace.EllipseCurve(0,0,t,t,0,2*Math.PI,!1,0).getPoints(50),n=new THREE__namespace.BufferGeometry().setFromPoints(i),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 i=new THREE__namespace.PointsMaterial({vertexColors:!0});i.onBeforeCompile=this.overridePointShader,i.size=this.pointsMaterialSize,e&&this.generateRange(e),this.pointsUuid=t.uuid,this.filterZAxisPoints(t),this.scene.add(t),this.render()}clearPointCloud(){this.removeObjectByName(this.pointCloudObjectName)}clearPointCloudAndRender(){this.clearPointCloud(),this.render()}initCloudData(t){if(!!this.store)for(let e=0;e<t.length;e+=3){const i=t[e],n=t[e+1],s=t[e+2];this.store.cloudData.set(`${i}@${n}@${s}`,{visible:!1})}}highlightOriginPointCloud(t){const e=this.scene.getObjectByName(this.pointCloudObjectName);if(!!e)return this.highlightPCDSrc=this.currentPCDSrc,new Promise((i,n)=>{if(window.Worker){const a=(t?[...t]:[]).map(c=>matrix.getCuboidFromPointCloudBox(c)),o=this.getAllAttributeColor(a),r={cuboidList:a,position:e.geometry.attributes.position.array,color:e.geometry.attributes.color.array,colorList:o};highlightWorker.postMessage(r),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){n(new Error("Error Path"));return}this.cacheInstance.updateColor(this.highlightPCDSrc,h),this.highlightPCDSrc=void 0,l.needsUpdate=!0,e.geometry.setAttribute("color",l),i(h),this.render()}}})}updateColor(t){const e=this.scene.getObjectByName(this.pointCloudObjectName);if(e){const i=new THREE__namespace.BufferAttribute(t,3);i.needsUpdate=!0,e.geometry.setAttribute("color",i),this.render()}}setShowDirection(t){this.showDirection=t,this.scene.children.forEach(e=>{e.type==="Group"&&e.children.forEach(i=>{i.type==="ArrowHelper"&&(i.visible=t)})}),this.render()}getTextCanvas(t){const e=document.createElement("canvas"),i=e.getContext("2d");return i&&(i.font=`${50}px " bold`,i.fillStyle="white",i.textAlign="center",i.textBaseline="middle",i.fillText(t,e.width/2,e.height/2)),e}filterNoise(t){let e=[...t];e.sort((l,d)=>l.z-d.z);const i=Math.floor(e.length*.05),n=e[i];e=e.filter(({z:l})=>l>n.z+.1);const s=.005,a=Math.floor(e.length*(1-s));e=e.slice(0,a),e.sort((l,d)=>l.x-d.x);const o=Math.floor(e.length*s),r=Math.floor(e.length*(1-s));e=e.slice(o,r),e.sort((l,d)=>l.y-d.y);const c=Math.floor(e.length*s),h=Math.floor(e.length*(1-s));return e=e.slice(c,h),e.length>100?e:t}getFittedCoordinates(t,e){const i=[];let n=[...t,t[0]];e.forEach(({x:o,y:r})=>{t.forEach((c,h)=>{const l=n[h+1],d=MathUtils.default.getFootOfPerpendicular({x:o,y:r},c,l,!1,!0).length;(!i[h]||d<i[h].distance)&&(i[h]={distance:d,point:{x:o,y:r}})})}),n=[t[t.length-1],...t,t[0]];const s=[i[i.length-1],...i];return t.map((o,r)=>{const c=n[r],h=n[r+1],l=n[r+2];return lbUtils.PointCloudUtils.getIntersectionBySlope({p1:s[r].point,line1:[c,h],p2:s[r+1].point,line2:[h,l]})})}getSensesPointZAxisInPolygon(t,e,i){var n,s,a;const o=this.scene.children.find(p=>p.uuid===this.pointsUuid);let r=0,c=0,h=0,l=0,d=[],u=[];const f=((a=(s=(n=o==null?void 0:o.geometry)==null?void 0:n.attributes)==null?void 0:s.position)==null?void 0:a.array)||[];for(let p=0;p<f.length;p+=3){const m=f[p],x=f[p+1],y=f[p+2];polygonTool.isInPolygon({x:m,y:x},t)&&(y||y===0)&&u.push({x:m,y:x,z:y})}return u.length?(i&&(u=this.filterNoise(u),d=this.getFittedCoordinates(t,u)),u.sort((p,m)=>p.z-m.z),r=u[0].z-.01,c=u[u.length-1].z+.01,l=u.length,e&&(h=u.filter(({z:p})=>p>=e[0]&&p<=e[1]).length),{maxZ:c,minZ:r,count:h,zCount:l,fittedCoordinates:d}):{maxZ:c,minZ:r,count:h,zCount:l,fittedCoordinates:d}}getBasicCoordinate2Canvas(t){const e=this.containerWidth/2,i=this.containerHeight/2;return{x:t.x*e+e,y:t.y*i+i,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,i=this.containerHeight/2;return new THREE__namespace.Vector3(t.x/e-e/2,-(t.y/i-i/2),1)}getPolygonSidePoints(t){const{center:{x:e,y:i,z:n},height:s,width:a,depth:o}=t,r={x:e+a/2,y:i+s/2,z:n-o/2},c={x:e+a/2,y:i+s/2,z:n+o/2},h={x:e-a/2,y:i+s/2,z:n+o/2},l={x:e-a/2,y:i+s/2,z:n-o/2};return[r,c,h,l]}getPolygonBackPoints(t){const{center:{x:e,y:i,z:n},height:s,width:a,depth:o}=t,r={x:e-a/2,y:i+s/2,z:n+o/2},c={x:e-a/2,y:i+s/2,z:n-o/2},h={x:e-a/2,y:i-s/2,z:n-o/2},l={x:e-a/2,y:i-s/2,z:n+o/2};return[r,c,h,l]}getPolygonTopPoints(t){const{center:{x:e,y:i,z:n},height:s,width:a,depth:o}=t,r={x:e+a/2,y:i+s/2,z:n+o/2},c={x:e+a/2,y:i-s/2,z:n+o/2},h={x:e-a/2,y:i-s/2,z:n+o/2},l={x:e-a/2,y:i+s/2,z:n+o/2};return[r,c,h,l]}getModelTransformationMatrix(t){const{center:{x:e,y:i,z:n},rotation:s}=t,a=new THREE__namespace.Matrix4().makeTranslation(-e,-i,-n),o=new THREE__namespace.Matrix4().makeTranslation(e,i,n),r=new THREE__namespace.Matrix4().makeRotationZ(s);return new THREE__namespace.Matrix4().multiply(o).multiply(r).multiply(a)}getBoxSidePolygon2DCoordinate(t){return this.getBoxPolygon2DCoordinate(t,lbUtils.EPerspectiveView.Left)}getBoxBackPolygon2DCoordinate(t){return this.getBoxPolygon2DCoordinate(t,lbUtils.EPerspectiveView.Back)}getSphereSidePoint2DCoordinate(t){return this.getSpherePoint2DCoordinate(t)}getSphereBackPoint2DCoordinate(t){return this.getSpherePoint2DCoordinate(t)}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 i=this.boxParams2ViewPolygon(t,e),{width:n,height:s}=t,a=new THREE__namespace.Matrix4().premultiply(this.camera.matrixWorldInverse).premultiply(this.camera.projectionMatrix),o=new THREE__namespace.Matrix4().premultiply(this.getModelTransformationMatrix(t)).premultiply(a).premultiply(this.basicCoordinate2CanvasMatrix4);this.sideMatrix=o;const r=i.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:r,zoom:Math.min(c,h)/2}}getSpherePoint2DCoordinate(t){const{center:e,attribute:i,id:n,valid:s}=t,{radius:a}=lbUtils.DEFAULT_SPHERE_PARAMS,o={center:e,attribute:i,id:n,valid:s,width:a*2,height:a*2,depth:a*2,rotation:0},r=new THREE__namespace.Matrix4().premultiply(this.camera.matrixWorldInverse).premultiply(this.camera.projectionMatrix),c=new THREE__namespace.Matrix4().premultiply(this.getModelTransformationMatrix(o)).premultiply(r).premultiply(this.basicCoordinate2CanvasMatrix4);this.sideMatrix=c;const h=new THREE__namespace.Vector3(e.x,e.y,e.z).applyMatrix4(this.sideMatrix),l=this.containerWidth/(a*2),d=this.containerHeight/(a*2);return{point2d:h,zoom:Math.min(l,d)/2}}getSphereTopPoint2DCoordinate(t){const{center:e}=t,{radius:i}=lbUtils.DEFAULT_SPHERE_PARAMS,n={x:-(e.y-this.containerWidth/2),y:-(e.x-this.containerHeight/2)},s=this.containerWidth/(i*2),a=this.containerHeight/(i*2);return{point2d:n,zoom:Math.min(s,a)/2}}getBoxTopPolygon2DCoordinate(t){const{width:e,height:i}=t,s=this.getPolygonTopPoints(t).map(r=>new THREE__namespace.Vector3(r.x,r.y,r.z)).map(r=>r.applyMatrix4(this.getModelTransformationMatrix(t))).map(r=>({x:r.y,y:r.x})).map(r=>({x:-(r.x-this.containerWidth/2),y:-(r.y-this.containerHeight/2)})),a=this.containerWidth/e,o=this.containerHeight/i;return{polygon2d:s,zoom:Math.min(a,o)/2}}getNewBoxBySideUpdate(t,e,i,n){const s=new THREE__namespace.Matrix4().makeRotationZ(n.rotation),a=new THREE__namespace.Vector3(-t.x,0,0).applyMatrix4(s);let o=n;return o.center={x:o.center.x+a.x,y:o.center.y+a.y,z:o.center.z-t.z},o=__spreadProps(__spreadValues({},o),{width:o.width+e,height:o.height,depth:o.depth+i}),{newBoxParams:o}}getNewBoxByBackUpdate(t,e,i,n){const s=new THREE__namespace.Matrix4().makeRotationZ(n.rotation),a=new THREE__namespace.Vector3(0,-t.x,0).applyMatrix4(s);let o=n;return o.center={x:o.center.x+a.x,y:o.center.y+a.y,z:o.center.z-t.z},o=__spreadProps(__spreadValues({},o),{width:o.width,height:o.height+e,depth:o.depth+i}),{newBoxParams:o}}getNewBoxBySideUpdateByPoints(t,e,i,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 o=t.map(m=>new THREE__namespace.Vector3(m.x,m.y,m.z)).map(m=>m.applyMatrix4(a)),[r,c,h,l]=o,d=Math.max(Math.abs(r.x-h.x),Math.abs(r.x-c.x)),f=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-f.x,y:n.center.y-f.y,z:n.center.z-i},width:d,height:n.height,depth:n.depth+e,rotation:n.rotation})}}filterZAxisPoints(t){const e=t||this.scene.children.find(i=>i.uuid===this.pointsUuid);if(e){const{attributes:i}=e.geometry,{position:n}=i,s=[],{count:a}=n;for(let o=0;o<a;o++){const r=n.getZ(o);s.push(r>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;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var THREE=require("three"),lbUtils=require("@labelbee/lb-utils"),DrawUtils=require("../../../utils/tool/DrawUtils.js");function _interopNamespace(r){if(r&&r.__esModule)return r;var e=Object.create(null);return r&&Object.keys(r).forEach(function(t){if(t!=="default"){var o=Object.getOwnPropertyDescriptor(r,t);Object.defineProperty(e,t,o.get?o:{enumerable:!0,get:function(){return r[t]}})}}),e.default=r,Object.freeze(e)}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=(r,e,t)=>e in r?__defProp(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,__spreadValues=(r,e)=>{for(var t in e||(e={}))__hasOwnProp.call(e,t)&&__defNormalProp(r,t,e[t]);if(__getOwnPropSymbols)for(var t of __getOwnPropSymbols(e))__propIsEnum.call(e,t)&&__defNormalProp(r,t,e[t]);return r},__spreadProps=(r,e)=>__defProps(r,__getOwnPropDescs(e));class PointCloudRender{constructor({store:e,on:t,unbind:o,nextTick:l,config:d}){this.clearStash=()=>{var i,s;const n=this.scene.getObjectByName((s=(i=this.store.cacheSegData)==null?void 0:i.id)!=null?s:"");n&&(n.removeFromParent(),this.render3d())},this.generateNewPoints=i=>{const s=new THREE__namespace.BufferGeometry;s.setAttribute("position",new THREE__namespace.BufferAttribute(i.points,3));const n=new THREE__namespace.PointsMaterial({color:this.getCurrentColor(i.attribute),size:10}),a=new THREE__namespace.Points(s,n);a.name=i.id,this.store.scene.add(a),this.render3d()},this.updateNewPoints=i=>{var s;const n=this.store.scene.getObjectByName((s=i==null?void 0:i.id)!=null?s:"");n&&i&&(n.geometry.setAttribute("position",new THREE__namespace.Float32BufferAttribute(i.points,3)),n.material=new THREE__namespace.PointsMaterial({color:this.getCurrentColor(i.attribute),size:10}),n.geometry.attributes.position.needsUpdate=!0,n.geometry.computeBoundingSphere(),this.render3d())},this.updatePointsColor=(i=this.store.cacheSegData)=>{var s;const n=this.store.scene.getObjectByName((s=i==null?void 0:i.id)!=null?s:"");n&&i&&(i.attribute=this.store.currentAttribute,n.material=new THREE__namespace.PointsMaterial({color:this.getCurrentColor(i.attribute),size:10}),this.render3d())},this.render3d=()=>{this.store.renderer.render(this.store.scene,this.store.camera)},this.store=e,this.on=t,this.unbind=o,this.nextTick=l,this.config=d,this.generateNewPoints=this.generateNewPoints.bind(this),this.clearStash=this.clearStash.bind(this),this.render3d=this.render3d.bind(this),this.updateNewPoints=this.updateNewPoints.bind(this),this.updatePointsColor=this.updatePointsColor.bind(this),this.clearAllSegmentData=this.clearAllSegmentData.bind(this),this.clearSelectedSegmentRender=this.clearSelectedSegmentRender.bind(this),this.initMsg(),this.animate()}get scene(){return this.store.scene}getCurrentColor(e=this.store.currentAttribute){if(!e||!this.config)return lbUtils.colorArr[0].hexString;const{fill:t}=lbUtils.toolStyleConverter.getColorFromConfig({attribute:e},__spreadProps(__spreadValues({},this.config),{attributeConfigurable:!0}),{});return t}initMsg(){this.on("addNewPointsCloud",this.generateNewPoints),this.on("updateNewPoints",this.updateNewPoints),this.on("clearStashRender",this.clearStash),this.on("clearAllSegmentData",this.clearAllSegmentData),this.on("reRender3d",this.render3d),this.on("clearSelectedSegmentData",this.clearSelectedSegmentRender)}unbindMsg(){this.unbind("addNewPointsCloud",this.generateNewPoints),this.unbind("updateNewPoints",this.updateNewPoints),this.unbind("clearStashRender",this.clearStash),this.unbind("clearAllSegmentData",this.clearAllSegmentData),this.unbind("reRender3d",this.render3d),this.unbind("clearSelectedSegmentData",this.clearSelectedSegmentRender)}get canvas2d(){return this.store.canvas2d}clearCanvasMouse(){var e,t;(t=(e=this.canvas2d)==null?void 0:e.getContext("2d"))==null||t.clearRect(0,0,this.store.containerWidth,this.store.containerHeight)}renderCanvas2dPolygon(){var e;((e=this.store.polygon2d)==null?void 0:e.length)>0&&this.canvas2d&&DrawUtils.drawPolygon(this.canvas2d,this.store.polygon2d,{isClose:!1,color:this.getCurrentColor(),thickness:4})}clearAllSegmentData(){const e=this.scene.children.length;for(let t=e-1;t>=0;t--){const o=this.scene.children[t];o.type==="Points"&&o.name!==this.store.pointCloudObjectName&&o.removeFromParent()}this.render3d()}clearSelectedSegmentRender(e=""){const t=this.scene.getObjectByName(e);t&&(t.removeFromParent(),this.render3d())}animate(){requestAnimationFrame(this.animate.bind(this)),this.clearCanvasMouse(),this.renderCanvas2dPolygon(),this.nextTick()}}module.exports=PointCloudRender;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var lbUtils=require("@labelbee/lb-utils"),lassoSelector=require("./selector/lassoSelector.js"),circleSelector=require("./selector/circleSelector.js");class PointCloudSegmentOperation{constructor(e){this.onMouseMove=t=>{if((this.store.isCheckStatus||this.store.isReadyStatus)&&this.store.updateMouse({x:t.offsetX,y:t.offsetY}),this.isForbid)return;const s={offsetX:t.offsetX,offsetY:t.offsetY,button:t.buttons};this.currentTool.mouseMove(s)},this.onMouseDown=t=>{this.isForbid||this.currentTool.mouseDown(t)},this.onMouseUp=t=>{this.isForbid||this.store.orbiting===!0||this.baseMouseDown(t)||this.currentTool.mouseUp(t)},this.baseMouseDown=t=>{switch(t.button){case 0:if(this.store.isReadyStatus||this.store.isCheckStatus)return this.store.checkPoints(),!0;break}},this._raycasting=()=>{if([lbUtils.EPointCloudSegmentStatus.Ready,lbUtils.EPointCloudSegmentStatus.Check].includes(this.store.segmentStatus)){const{mouse:t,camera:s,raycaster:o}=this.store;o.setFromCamera(t,s);const i=o.intersectObjects(this.store.allSegmentPoints,!1)[0];i?this.store.highlightPoints(i.object):(this.store.resetAllSegDataSizeAndRender(),this.store.resetHoverPointsID())}},this.dom=e.dom,this.store=e.store,this.lassoSelector=new lassoSelector(this.store),this.circleSelector=new circleSelector(this.store),this.currentTool=this.circleSelector,this.currentToolName="CircleSelector",this.dom.addEventListener("pointermove",this.onMouseMove.bind(this)),this.dom.addEventListener("pointerdown",this.onMouseDown.bind(this)),this.dom.addEventListener("pointerup",this.onMouseUp.bind(this)),this.updateSelector2Lasso=this.updateSelector2Lasso.bind(this),this.updateSelector2Circle=this.updateSelector2Circle.bind(this)}getCoordinate(e){const t=this.dom.getBoundingClientRect();return{x:e.clientX-t.left,y:e.clientY-t.top}}get forbidOperation(){return this.store.forbidOperation}get isForbid(){return this.forbidOperation}updateSelector2Lasso(){this.currentTool=this.lassoSelector,this.currentToolName="LassoSelector"}updateSelector2Circle(){this.currentTool=this.circleSelector,this.currentToolName="CircleSelector"}}exports.PointCloudSegmentOperation=PointCloudSegmentOperation;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var selector=require("./selector.js");class CircleSelector extends selector{constructor(){super(...arguments);this.radius=20}mouseDown(t){t.button===2&&(this.pushPoint(t.offsetX,t.offsetY),this.startX=t.offsetX,this.startY=t.offsetY)}mouseUp(t){t.button===2&&(this.store.getPointsInPolygon(this.polygon2d),this.polygon2d.length=0,this.startX=this.startY=NaN)}mouseMove(t){if(t.button===2&&this.startX&&this.startY){this.polygon2d.length=0;const a=64,n=Math.PI*2,o=this.startX,i=this.startY,r=t.offsetX,e=t.offsetY,h=Math.sqrt((r-o)*(r-o)+(e-i)*(e-i));for(let s=0;s<n;s+=n/a)this.pushPoint(o+h*Math.cos(s),i-h*Math.sin(s))}}}module.exports=CircleSelector;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var selector=require("./selector.js");class LassoSelector extends selector{mouseDown(o){o.button===2&&this.pushPoint(o.offsetX,o.offsetY)}mouseUp(o){o.button===2&&(this.store.getPointsInPolygon(this.polygon2d),this.updatePolygon2d([]))}mouseMove(o){o.button===2&&this.pushPoint(o.offsetX,o.offsetY)}}module.exports=LassoSelector;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";class DefaultSelector{constructor(o){this.store=o,this.polygon2d=[]}pushPoint(o,s){this.polygon2d.push({x:o,y:s}),this.store.syncPolygon2d(this.polygon2d)}updatePolygon2d(o){this.polygon2d=o,this.store.syncPolygon2d(this.polygon2d)}}module.exports=DefaultSelector;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var lbUtils=require("@labelbee/lb-utils");class PointCloudFSM{constructor(){this.segmentStatus=lbUtils.EPointCloudSegmentStatus.Ready}statusToggle(){switch(this.segmentStatus){case lbUtils.EPointCloudSegmentStatus.Ready:this.segmentStatus=lbUtils.EPointCloudSegmentStatus.Check;break;case lbUtils.EPointCloudSegmentStatus.Check:this.segmentStatus=lbUtils.EPointCloudSegmentStatus.Edit;break;case lbUtils.EPointCloudSegmentStatus.Edit:this.segmentStatus=lbUtils.EPointCloudSegmentStatus.Ready;break;default:console.error("Error Status in PointCloudSegmentFSM")}}updateStatus2Edit(){this.segmentStatus=lbUtils.EPointCloudSegmentStatus.Edit}updateStatus2Check(){this.segmentStatus=lbUtils.EPointCloudSegmentStatus.Check}updateStatus2Ready(){this.segmentStatus=lbUtils.EPointCloudSegmentStatus.Ready}get isReadyStatus(){return this.segmentStatus===lbUtils.EPointCloudSegmentStatus.Ready}get isCheckStatus(){return this.segmentStatus===lbUtils.EPointCloudSegmentStatus.Check}get isEditStatus(){return this.segmentStatus===lbUtils.EPointCloudSegmentStatus.Edit}}const instance=new PointCloudFSM;module.exports=instance;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var THREE=require("three"),lbUtils=require("@labelbee/lb-utils"),polygonTool=require("../../../utils/tool/polygonTool.js"),uuid=require("../../../utils/uuid.js"),fsm=require("./fsm.js");function _interopNamespace(h){if(h&&h.__esModule)return h;var t=Object.create(null);return h&&Object.keys(h).forEach(function(e){if(e!=="default"){var i=Object.getOwnPropertyDescriptor(h,e);Object.defineProperty(t,e,i.get?i:{enumerable:!0,get:function(){return h[e]}})}}),t.default=h,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=(h,t,e)=>t in h?__defProp(h,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):h[t]=e,__spreadValues=(h,t)=>{for(var e in t||(t={}))__hasOwnProp.call(t,e)&&__defNormalProp(h,e,t[e]);if(__getOwnPropSymbols)for(var e of __getOwnPropSymbols(t))__propIsEnum.call(t,e)&&__defNormalProp(h,e,t[e]);return h},__spreadProps=(h,t)=>__defProps(h,__getOwnPropDescs(t));const DEFAULT_PREFIX="LABELBEE_CANVAS_";class PointCloudStore{constructor({container:t,scene:e,camera:i,renderer:a,emit:o,on:d,unbind:s}){this.canvas2d=null,this.polygon2d=[],this.forbidOperation=!1,this.raycaster=new THREE__namespace.Raycaster,this.mouse=new THREE__namespace.Vector2,this.cloudData=new Map,this.segmentData=new Map,this.hoverPointsID="",this.segmentMode=lbUtils.EPointCloudSegmentMode.Add,this.segmentCoverMode=lbUtils.EPointCloudSegmentCoverMode.Cover,this.segmentFocusMode=lbUtils.EPointCloudSegmentFocusMode.Unfocus,this.hideSegment=!1,this.updatePointCloud=!1,this.addPointCloud=!1,this.orbiting=!1,this.currentAttribute="",this.highlightAttribute="",this.hiddenAttributes=[],this.pointCloudObjectName="pointCloud",this.updatePointCloudBySegment=l=>{this.segmentData.forEach((u,c)=>{var g;if(c!==((g=this.cacheSegData)==null?void 0:g.id)){const S=this.scene.getObjectByName(c);S&&S.removeFromParent()}});const r=l==null?void 0:l.filter(u=>{var c;return!this.hiddenAttributes.some(g=>g===u.attribute)&&u.id!==((c=this.cacheSegData)==null?void 0:c.id)});(r==null?void 0:r.length)!==0&&r.map(u=>(this.emit("addNewPointsCloud",u),u)),this.emit("reRender3d")},this.updateCoverPoints=(l=new Float32Array([]))=>{this.segmentData.forEach((r,u)=>{var c;if(u!==((c=this.cacheSegData)==null?void 0:c.id)){const g=lbUtils.PointCloudUtils.splitPointsFromPoints(r.points,l);r.points=g;const S=this.scene.getObjectByName(u);S&&(S.geometry.setAttribute("position",new THREE__namespace.Float32BufferAttribute(g,3)),S.geometry.attributes.position.needsUpdate=!0)}}),this.syncSegmentData(),this.emit("reRender3d")},this.container=t,this.scene=e,this.camera=i,this.renderer=a,this.emit=o,this.on=d,this.unbind=s,this.createCanvas2d(),this.clearStash=this.clearStash.bind(this),this.addStash2Store=this.addStash2Store.bind(this),this.updateCheck2Edit=this.updateCheck2Edit.bind(this),this.setAttribute=this.setAttribute.bind(this),this.setSegmentMode=this.setSegmentMode.bind(this),this.setSegmentCoverMode=this.setSegmentCoverMode.bind(this),this.setSegmentFocusMode=this.setSegmentFocusMode.bind(this),this.switchSegmentHideMode=this.switchSegmentHideMode.bind(this),this.highlightPointsByAttribute=this.highlightPointsByAttribute.bind(this),this.setHiddenAttributes=this.setHiddenAttributes.bind(this),this.clearAllSegmentData=this.clearAllSegmentData.bind(this),this.clearSelectedSegmentData=this.clearSelectedSegmentData.bind(this),this.initMsg(),this.setupRaycaster()}initMsg(){this.on("clearStash",this.clearStash),this.on("addStash2Store",this.addStash2Store),this.on("updateCheck2Edit",this.updateCheck2Edit),this.on("setSegmentMode",this.setSegmentMode),this.on("setSegmentCoverMode",this.setSegmentCoverMode),this.on("setSegmentFocusMode",this.setSegmentFocusMode),this.on("switchHideSegment",this.switchSegmentHideMode),this.on("clearAllSegmentData",this.clearAllSegmentData),this.on("clearSelectedSegmentData",this.clearSelectedSegmentData)}unbindMsg(){this.unbind("clearStash",this.clearStash),this.unbind("addStash2Store",this.addStash2Store),this.unbind("updateCheck2Edit",this.updateCheck2Edit),this.unbind("setSegmentMode",this.setSegmentMode),this.unbind("setSegmentCoverMode",this.setSegmentCoverMode),this.unbind("setSegmentFocusMode",this.setSegmentFocusMode),this.unbind("switchHideSegment",this.switchSegmentHideMode),this.unbind("clearAllSegmentData",this.clearAllSegmentData),this.unbind("clearSelectedSegmentData",this.clearSelectedSegmentData)}get containerWidth(){return this.container.clientWidth}get containerHeight(){return this.container.clientHeight}get allSegmentPoints(){return this.scene.children.filter(t=>t.type==="Points"&&t.name!==this.pointCloudObjectName)}get selectedSegmentPoints(){var t,e;return this.scene.getObjectByName((e=(t=this.cacheSegData)==null?void 0:t.id)!=null?e:"")}get segmentStatus(){return fsm.segmentStatus}get isReadyStatus(){return fsm.isReadyStatus}get isCheckStatus(){return fsm.isCheckStatus}get isEditStatus(){return fsm.isEditStatus}get formatData(){const t=this.segmentData.values(),e=[];for(const i of t)e.push({attribute:i.attribute,id:i.id,indexes:i.indexes});return e}get pointCloudArray(){return this.scene.getObjectByName(this.pointCloudObjectName)}clearAllSegmentData(){this.segmentData=new Map,this.syncSegmentData()}updateCurrentSegment(t){this.updatePointCloudBySegment([]),this.segmentData=new Map;const{pointCloudArray:e}=this;if(!e)return;const i=e.geometry.attributes.position.array;t.forEach(a=>{const o=[];a.indexes.forEach(s=>{o.push(i[s*3],i[s*3+1],i[s*3+2])});const d=__spreadProps(__spreadValues({},a),{points:new Float32Array(o)});this.segmentData.set(a.id,d),this.emit("addNewPointsCloud",__spreadProps(__spreadValues({},a),{points:new Float32Array(o)}))}),this.syncSegmentData()}statusToggle(){fsm.statusToggle()}updateStatus2Edit(){fsm.updateStatus2Edit()}createCanvas(t){const e=document.createElement("canvas");return e.id=t,this.updateCanvasBasicStyle(e,{width:this.containerWidth,height:this.containerHeight},10),e}createCanvas2d(){this.canvas2d=this.createCanvas(`${DEFAULT_PREFIX}2d`),this.container.appendChild(this.canvas2d)}setupRaycaster(){this.raycaster.params={Mesh:{},Line:{threshold:1},LOD:{},Points:{threshold:.2},Sprite:{}}}setHoverPointsID(t){this.hoverPointsID=t}setSegmentMode(t){this.segmentMode=t}setSegmentCoverMode(t){this.segmentCoverMode=t}setSegmentFocusMode(t){this.segmentFocusMode=t,t===lbUtils.EPointCloudSegmentFocusMode.Focus&&this.emit("clearPointCloud"),t===lbUtils.EPointCloudSegmentFocusMode.Unfocus&&this.emit("loadPCDFile"),this.emit("reRender3d"),this.updatePointCloudBySegment(t===lbUtils.EPointCloudSegmentFocusMode.Focus?[]:[...this.segmentData.values()])}switchSegmentHideMode(t){this.hideSegment=t,this.updatePointCloudBySegment(t===!0?[]:[...this.segmentData.values()])}setHiddenAttributes(t){this.hiddenAttributes=t,this.updatePointCloudBySegment([...this.segmentData.values()])}updateCanvasBasicStyle(t,e,i){const a=1;t.style.position="absolute",t.width=e.width*a,t.height=e.height*a,t.style.width=`${e.width}px`,t.style.height=`${e.height}px`,t.style.left="0",t.style.top="0",t.style.zIndex=`${i} `}syncPolygon2d(t){this.polygon2d=t}getPointsInPolygon(t){var e,i,a;if(!this.isReadyStatus&&!this.isEditStatus)return;const o=t,d=this.scene.getObjectByName(this.pointCloudObjectName),s=(a=(i=(e=d==null?void 0:d.geometry)==null?void 0:e.attributes)==null?void 0:i.position)==null?void 0:a.array;if(s){const l=s.length,r=[],u=[],c=[];for(let n=0;n<l;n+=3){const p=new THREE__namespace.Vector3(s[n],s[n+1],s[n+2]);p.project(this.camera);const D={x:0,y:0};if(D.x=Math.round(p.x*this.container.clientWidth/2+this.container.clientWidth/2),D.y=Math.round(-p.y*this.container.clientHeight/2+this.container.clientHeight/2),polygonTool.isInPolygon(D,o)){const y=s[n],P=s[n+1],b=s[n+2],m=lbUtils.PointCloudUtils.getCloudKeys(y,P,b);this.segmentMode===lbUtils.EPointCloudSegmentMode.Remove&&(this.cloudData.get(m).visible=!1,r.push(s[n],s[n+1],s[n+2]),c.push(n/3)),this.segmentMode===lbUtils.EPointCloudSegmentMode.Add&&(this.segmentCoverMode===lbUtils.EPointCloudSegmentCoverMode.Cover&&(r.push(s[n],s[n+1],s[n+2]),c.push(n/3),this.cloudData.get(m).visible===!0&&u.push(s[n],s[n+1],s[n+2])),this.segmentCoverMode===lbUtils.EPointCloudSegmentCoverMode.Uncover&&this.cloudData.get(m).visible===!1&&(r.push(s[n],s[n+1],s[n+2]),c.push(n/3)),this.cloudData.get(m).visible===!1&&(this.cloudData.get(m).visible=!0))}}if(c.length===0||!this.cacheSegData&&this.segmentMode===lbUtils.EPointCloudSegmentMode.Remove)return;const g=new Float32Array(r),S=new Float32Array(u);this.updateStatusBySelector(g,S,c)}}updateStatusBySelector(t,e,i){switch(this.segmentMode){case lbUtils.EPointCloudSegmentMode.Add:if(this.cacheSegData){const{points:a,coverPoints:o=new Float32Array([])}=this.cacheSegData,d=a.length+t.length,s=new Float32Array(d);s.set(a,0),s.set(t,a.length);const l=o.length+e.length,r=new Float32Array(l);r.set(o,0),r.set(e,o.length),this.cacheSegData=__spreadProps(__spreadValues({},this.cacheSegData),{points:s,coverPoints:r,indexes:this.cacheSegData.indexes.concat(i)}),this.emit("updateNewPoints",this.cacheSegData)}else this.cacheSegData={id:uuid(),attribute:this.currentAttribute,points:t,coverPoints:e,indexes:i},this.emit("addNewPointsCloud",this.cacheSegData);break;case lbUtils.EPointCloudSegmentMode.Remove:if(this.cacheSegData){const{points:a,indexes:o}=this.cacheSegData;this.cacheSegData=__spreadProps(__spreadValues({},this.cacheSegData),{points:lbUtils.PointCloudUtils.splitPointsFromPoints(a,t),indexes:lbUtils.PointCloudUtils.splitPointsFromIndexes(o,i)}),this.emit("updateNewPoints",this.cacheSegData)}break}this.updateStatus2Edit(),this.emit("syncPointCloudStatus",{segmentStatus:this.segmentStatus,cacheSegData:this.cacheSegData})}syncPointCloudStatus(){this.statusToggle();const{segmentStatus:t,cacheSegData:e}=this;this.emit("syncPointCloudStatus",{segmentStatus:t,cacheSegData:e})}syncSegmentData(){this.emit("syncSegmentData",this.formatData)}addStash2Store(){this.isEditStatus&&this.cacheSegData&&(this.cacheSegData.coverPoints&&this.cacheSegData.coverPoints.length!==0&&this.updateCoverPoints(this.cacheSegData.coverPoints),delete this.cacheSegData.coverPoints,this.segmentData.set(this.cacheSegData.id,this.cacheSegData),this.cacheSegData=void 0,this.syncPointCloudStatus(),this.syncSegmentData())}updateCloudDataStatus(t,e){for(let i=0;i<t.length;i+=3){const a=t[i],o=t[i+1],d=t[i+2],s=lbUtils.PointCloudUtils.getCloudKeys(a,o,d),l=this.cloudData.get(s);Object.keys(e).forEach(r=>{l[r]=e[r]})}}clearStash(){if(this.isEditStatus&&this.cacheSegData){if(this.updateCloudDataStatus(this.cacheSegData.points,{visible:!1}),this.segmentData.has(this.cacheSegData.id)){const t=this.segmentData.get(this.cacheSegData.id);t&&(this.emit("updateNewPoints",t),this.updateCloudDataStatus(t==null?void 0:t.points,{visible:!0}))}else this.emit("clearStashRender");this.syncSegmentData(),this.cacheSegData=void 0,this.syncPointCloudStatus()}}clearSelectedSegmentData(t=""){if((this.isCheckStatus||this.isEditStatus)&&this.cacheSegData){const e=this.scene.getObjectByName(t),{indexes:i}=this.cacheSegData;if(e&&i){const a=e.geometry.attributes.position.array;for(let o=0;o<i.length;o++){const d=this.cloudData.get(lbUtils.PointCloudUtils.getCloudKeys(a[o],a[o+1],a[o+2]));d&&(d.visible=!1)}this.cacheSegData=void 0,fsm.updateStatus2Ready(),this.emit("syncPointCloudStatus",{segmentStatus:this.segmentStatus,cacheSegData:this.cacheSegData})}}}updateCheck2Edit(){this.isCheckStatus&&this.syncPointCloudStatus()}checkPoints(){const t=this.segmentData.get(this.hoverPointsID);t&&(this.cacheSegData=__spreadProps(__spreadValues({},t),{points:new Float32Array(t.points)}),fsm.updateStatus2Check(),this.emit("syncPointCloudStatus",{segmentStatus:this.segmentStatus,cacheSegData:this.cacheSegData}))}editPoints(){const t=this.segmentData.get(this.hoverPointsID);t&&(this.cacheSegData=__spreadProps(__spreadValues({},t),{points:new Float32Array(t.points)}),this.emit("updateNewPoints"),this.syncPointCloudStatus())}setForbidOperation(t){this.forbidOperation=t}updateMouse(t){const e=t.x/this.containerWidth*2-1,i=-(t.y/this.containerHeight)*2+1;this.mouse.setX(e),this.mouse.setY(i)}resetAllSegDataSize(){this.highlightAttribute===""&&this.allSegmentPoints.forEach(t=>{var e;((e=this.cacheSegData)==null?void 0:e.id)!==t.name&&(t.material.size=5)})}resetHoverPointsID(){this.hoverPointsID=""}resetAllSegDataSizeAndRender(){this.resetAllSegDataSize(),this.emit("reRender3d")}highlightPoints(t){!(this.isCheckStatus||this.isReadyStatus)||(this.resetAllSegDataSize(),t.material.size=10,this.hoverPointsID=t.name,this.emit("reRender3d"))}highlightPointsByAttribute(t){this.highlightAttribute=t,this.segmentData.size!==0&&(this.resetAllSegDataSize(),this.segmentData.forEach((e,i)=>{if(e.attribute===t){const a=this.scene.getObjectByName(i);a&&(a==null?void 0:a.material)&&(a.material.size=10)}}),this.emit("reRender3d"))}setAttribute(t){this.currentAttribute=t}}module.exports=PointCloudStore;
|
|
@@ -9,6 +9,9 @@ import { OrthographicCamera, PerspectiveCamera, Shader } from 'three';
|
|
|
9
9
|
import { IPolygonPoint } from '@/types/tool/polygon';
|
|
10
10
|
import { PCDLoader } from './PCDLoader';
|
|
11
11
|
import { OrbitControls } from './OrbitControls';
|
|
12
|
+
import PointCloudStore from './store';
|
|
13
|
+
import PointCloudRender from './render';
|
|
14
|
+
import EventListener from '../toolOperation/eventListener';
|
|
12
15
|
interface IOrthographicCamera {
|
|
13
16
|
left: number;
|
|
14
17
|
right: number;
|
|
@@ -24,8 +27,20 @@ interface IProps {
|
|
|
24
27
|
orthographicParams?: IOrthographicCamera;
|
|
25
28
|
backgroundColor?: string;
|
|
26
29
|
config?: IPointCloudConfig;
|
|
30
|
+
isSegment?: boolean;
|
|
27
31
|
}
|
|
28
|
-
export
|
|
32
|
+
export interface IEventBus {
|
|
33
|
+
on: EventListener['on'];
|
|
34
|
+
emit: EventListener['emit'];
|
|
35
|
+
unbind: EventListener['unbind'];
|
|
36
|
+
}
|
|
37
|
+
export interface IPointCloudDelegate extends IEventBus {
|
|
38
|
+
renderer: THREE.WebGLRenderer;
|
|
39
|
+
scene: THREE.Scene;
|
|
40
|
+
camera: THREE.OrthographicCamera | THREE.PerspectiveCamera;
|
|
41
|
+
container: HTMLElement;
|
|
42
|
+
}
|
|
43
|
+
export declare class PointCloud extends EventListener {
|
|
29
44
|
renderer: THREE.WebGLRenderer;
|
|
30
45
|
scene: THREE.Scene;
|
|
31
46
|
camera: THREE.OrthographicCamera | THREE.PerspectiveCamera;
|
|
@@ -33,6 +48,8 @@ export declare class PointCloud {
|
|
|
33
48
|
axesHelper: THREE.AxesHelper;
|
|
34
49
|
pcdLoader: PCDLoader;
|
|
35
50
|
config?: IPointCloudConfig;
|
|
51
|
+
store?: PointCloudStore;
|
|
52
|
+
pointCloudRender?: PointCloudRender;
|
|
36
53
|
/**
|
|
37
54
|
* zAxis Limit for filter point over a value
|
|
38
55
|
*/
|
|
@@ -55,8 +72,33 @@ export declare class PointCloud {
|
|
|
55
72
|
* Avoiding src error problems caused by asynchronous
|
|
56
73
|
*/
|
|
57
74
|
private highlightPCDSrc?;
|
|
75
|
+
private segmentOperation?;
|
|
58
76
|
constructor({ container, noAppend, isOrthographicCamera, orthographicParams, backgroundColor, // GRAY_BACKGROUND
|
|
59
|
-
config, }: IProps);
|
|
77
|
+
config, isSegment, }: IProps);
|
|
78
|
+
initSegment(): void;
|
|
79
|
+
orbiterStart(): void;
|
|
80
|
+
orbiterChange(): void;
|
|
81
|
+
orbiterEnd(): void;
|
|
82
|
+
get currentSegmentTool(): "LassoSelector" | "CircleSelector" | undefined;
|
|
83
|
+
initMsg(): void;
|
|
84
|
+
unbindMsg(): void;
|
|
85
|
+
nextTick: () => void;
|
|
86
|
+
keydown: (e: KeyboardEvent) => void;
|
|
87
|
+
keyup: (e: KeyboardEvent) => void;
|
|
88
|
+
get eventBus(): {
|
|
89
|
+
on: (eventName: string, callback: (...args: any[]) => void) => void;
|
|
90
|
+
emit: (eventName: string, ...args: any[]) => void;
|
|
91
|
+
unbind: (eventName: string, callback: (...params: any[]) => void) => void;
|
|
92
|
+
};
|
|
93
|
+
get pointCloudDelegate(): {
|
|
94
|
+
on: (eventName: string, callback: (...args: any[]) => void) => void;
|
|
95
|
+
emit: (eventName: string, ...args: any[]) => void;
|
|
96
|
+
unbind: (eventName: string, callback: (...params: any[]) => void) => void;
|
|
97
|
+
container: HTMLElement;
|
|
98
|
+
scene: THREE.Scene;
|
|
99
|
+
camera: THREE.OrthographicCamera | THREE.PerspectiveCamera;
|
|
100
|
+
renderer: THREE.WebGLRenderer;
|
|
101
|
+
};
|
|
60
102
|
get DEFAULT_INIT_CAMERA_POSITION(): THREE.Vector3;
|
|
61
103
|
get containerWidth(): number;
|
|
62
104
|
get containerHeight(): number;
|
|
@@ -165,12 +207,13 @@ export declare class PointCloud {
|
|
|
165
207
|
renderPointCloud(points: THREE.Points, radius?: number): void;
|
|
166
208
|
clearPointCloud(): void;
|
|
167
209
|
clearPointCloudAndRender(): void;
|
|
210
|
+
initCloudData(points: Float32Array): void;
|
|
168
211
|
/**
|
|
169
212
|
*
|
|
170
213
|
* @param src
|
|
171
214
|
* @param radius Render the range of circle
|
|
172
215
|
*/
|
|
173
|
-
loadPCDFile: (src
|
|
216
|
+
loadPCDFile: (src?: string | undefined, radius?: number) => Promise<void>;
|
|
174
217
|
/**
|
|
175
218
|
* It needs to be updated after load PointCloud's data.
|
|
176
219
|
* @param boxParams
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file The set of pointCloud Render.
|
|
3
|
+
* @author Laoluo <ron.f.luo@gmail.com>
|
|
4
|
+
* @createdate 2023-05-05
|
|
5
|
+
*/
|
|
6
|
+
import * as THREE from 'three';
|
|
7
|
+
import { IPointCloudConfig, IPointCloudSegmentation } from '@labelbee/lb-utils';
|
|
8
|
+
import EventListener from '@/core/toolOperation/eventListener';
|
|
9
|
+
import PointCloudStore from '../store';
|
|
10
|
+
import { IEventBus } from '..';
|
|
11
|
+
interface IPointCloudRenderProps extends IEventBus {
|
|
12
|
+
store: PointCloudStore;
|
|
13
|
+
nextTick: () => void;
|
|
14
|
+
config?: IPointCloudConfig;
|
|
15
|
+
}
|
|
16
|
+
declare class PointCloudRender {
|
|
17
|
+
store: PointCloudStore;
|
|
18
|
+
nextTick: () => void;
|
|
19
|
+
on: EventListener['on'];
|
|
20
|
+
unbind: EventListener['unbind'];
|
|
21
|
+
config?: IPointCloudConfig;
|
|
22
|
+
constructor({ store, on, unbind, nextTick, config }: IPointCloudRenderProps);
|
|
23
|
+
get scene(): THREE.Scene;
|
|
24
|
+
getCurrentColor(attribute?: string): string;
|
|
25
|
+
initMsg(): void;
|
|
26
|
+
unbindMsg(): void;
|
|
27
|
+
get canvas2d(): HTMLCanvasElement | null;
|
|
28
|
+
clearCanvasMouse(): void;
|
|
29
|
+
renderCanvas2dPolygon(): void;
|
|
30
|
+
clearStash: () => void;
|
|
31
|
+
clearAllSegmentData(): void;
|
|
32
|
+
clearSelectedSegmentRender(id?: string): void;
|
|
33
|
+
generateNewPoints: (segmentData: IPointCloudSegmentation) => void;
|
|
34
|
+
updateNewPoints: (segmentData: IPointCloudSegmentation) => void;
|
|
35
|
+
updatePointsColor: (segmentData?: IPointCloudSegmentation | undefined) => void;
|
|
36
|
+
render3d: () => void;
|
|
37
|
+
animate(): void;
|
|
38
|
+
}
|
|
39
|
+
export default PointCloudRender;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file PointCloud Segmentation Operation
|
|
3
|
+
* @author Laoluo <ron.f.luo@gmail.com>
|
|
4
|
+
* @createdate 2023-05-05
|
|
5
|
+
*/
|
|
6
|
+
import LassoSelector from './selector/lassoSelector';
|
|
7
|
+
import PointCloudStore from './store';
|
|
8
|
+
import CircleSelector from './selector/circleSelector';
|
|
9
|
+
interface IProps {
|
|
10
|
+
dom: HTMLElement;
|
|
11
|
+
store: PointCloudStore;
|
|
12
|
+
}
|
|
13
|
+
declare class PointCloudSegmentOperation {
|
|
14
|
+
private dom;
|
|
15
|
+
currentTool: LassoSelector | CircleSelector;
|
|
16
|
+
currentToolName: 'LassoSelector' | 'CircleSelector';
|
|
17
|
+
store: PointCloudStore;
|
|
18
|
+
lassoSelector: LassoSelector;
|
|
19
|
+
circleSelector: CircleSelector;
|
|
20
|
+
constructor(props: IProps);
|
|
21
|
+
getCoordinate(e: MouseEvent): {
|
|
22
|
+
x: number;
|
|
23
|
+
y: number;
|
|
24
|
+
};
|
|
25
|
+
get forbidOperation(): boolean;
|
|
26
|
+
get isForbid(): boolean;
|
|
27
|
+
updateSelector2Lasso(): void;
|
|
28
|
+
updateSelector2Circle(): void;
|
|
29
|
+
onMouseMove: (iev: MouseEvent) => void;
|
|
30
|
+
onMouseDown: (iev: MouseEvent) => void;
|
|
31
|
+
onMouseUp: (iev: MouseEvent) => void;
|
|
32
|
+
baseMouseDown: (e: MouseEvent) => true | undefined;
|
|
33
|
+
_raycasting: () => void;
|
|
34
|
+
}
|
|
35
|
+
export { PointCloudSegmentOperation };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import DefaultSelector, { ISelectorOperation } from './selector';
|
|
2
|
+
export default class CircleSelector extends DefaultSelector implements ISelectorOperation {
|
|
3
|
+
radius: number;
|
|
4
|
+
startX?: number;
|
|
5
|
+
startY?: number;
|
|
6
|
+
mouseDown(ev: MouseEvent): void;
|
|
7
|
+
mouseUp(ev: MouseEvent): void;
|
|
8
|
+
mouseMove(ev: MouseEvent): void;
|
|
9
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import PointCloudStore from '../store';
|
|
2
|
+
export interface ISelectorOperation {
|
|
3
|
+
mouseDown(ev: MouseEvent): void;
|
|
4
|
+
mouseUp(ev: MouseEvent): void;
|
|
5
|
+
mouseMove(ev: MouseEvent): void;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Unify all operation.
|
|
9
|
+
*/
|
|
10
|
+
export interface ISelectorEvent {
|
|
11
|
+
which: number;
|
|
12
|
+
offsetX: number;
|
|
13
|
+
offsetY: number;
|
|
14
|
+
}
|
|
15
|
+
export default class DefaultSelector {
|
|
16
|
+
store: PointCloudStore;
|
|
17
|
+
polygon2d: ICoordinate[];
|
|
18
|
+
constructor(store: PointCloudStore);
|
|
19
|
+
pushPoint(x: number, y: number): void;
|
|
20
|
+
updatePolygon2d(polygon2d: ICoordinate[]): void;
|
|
21
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file PointCloud FSM.
|
|
3
|
+
* @createdate 2023-05-16
|
|
4
|
+
* @author Ron <ron.f.luo@gmail.com>
|
|
5
|
+
*/
|
|
6
|
+
import { EPointCloudSegmentStatus } from '@labelbee/lb-utils';
|
|
7
|
+
declare class PointCloudFSM {
|
|
8
|
+
segmentStatus: EPointCloudSegmentStatus;
|
|
9
|
+
/**
|
|
10
|
+
* Toggle status to next status.
|
|
11
|
+
*/
|
|
12
|
+
statusToggle(): void;
|
|
13
|
+
updateStatus2Edit(): void;
|
|
14
|
+
updateStatus2Check(): void;
|
|
15
|
+
updateStatus2Ready(): void;
|
|
16
|
+
get isReadyStatus(): boolean;
|
|
17
|
+
get isCheckStatus(): boolean;
|
|
18
|
+
get isEditStatus(): boolean;
|
|
19
|
+
}
|
|
20
|
+
declare const instance: PointCloudFSM;
|
|
21
|
+
export default instance;
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file PointCloud Store.
|
|
3
|
+
* @author Laoluo <ron.f.luo@gmail.com>
|
|
4
|
+
* @createdate 2023-05-05
|
|
5
|
+
*/
|
|
6
|
+
import * as THREE from 'three';
|
|
7
|
+
import { EPointCloudSegmentCoverMode, EPointCloudSegmentFocusMode, EPointCloudSegmentMode, IPointCloudSegmentation } from '@labelbee/lb-utils';
|
|
8
|
+
import { IPointCloudDelegate } from '..';
|
|
9
|
+
export type ThreePoints = THREE.Points<THREE.BufferGeometry, THREE.PointsMaterial>;
|
|
10
|
+
/**
|
|
11
|
+
* TODO:
|
|
12
|
+
* Need to think about store:
|
|
13
|
+
* 1. The definition of points in IPointCloudSegmentation is Float32Array ?
|
|
14
|
+
* 2. CloudData store the status ?
|
|
15
|
+
*/
|
|
16
|
+
declare class PointCloudStore {
|
|
17
|
+
canvas2d: HTMLCanvasElement | null;
|
|
18
|
+
private container;
|
|
19
|
+
renderer: THREE.WebGLRenderer;
|
|
20
|
+
scene: THREE.Scene;
|
|
21
|
+
camera: THREE.OrthographicCamera | THREE.PerspectiveCamera;
|
|
22
|
+
polygon2d: ICoordinate[];
|
|
23
|
+
forbidOperation: boolean;
|
|
24
|
+
raycaster: THREE.Raycaster;
|
|
25
|
+
/** Mouse Data */
|
|
26
|
+
mouse: THREE.Vector2;
|
|
27
|
+
/** Data Store */
|
|
28
|
+
cloudData: Map<any, any>;
|
|
29
|
+
segmentData: Map<string, IPointCloudSegmentation>;
|
|
30
|
+
cacheSegData?: IPointCloudSegmentation;
|
|
31
|
+
/** Raycaster Hover PointsID */
|
|
32
|
+
hoverPointsID: string;
|
|
33
|
+
/** Render Status */
|
|
34
|
+
segmentMode: EPointCloudSegmentMode;
|
|
35
|
+
segmentCoverMode: EPointCloudSegmentCoverMode;
|
|
36
|
+
segmentFocusMode: EPointCloudSegmentFocusMode;
|
|
37
|
+
hideSegment: boolean;
|
|
38
|
+
updatePointCloud: boolean;
|
|
39
|
+
addPointCloud: boolean;
|
|
40
|
+
orbiting: boolean;
|
|
41
|
+
currentAttribute: string;
|
|
42
|
+
highlightAttribute: string;
|
|
43
|
+
hiddenAttributes: string[];
|
|
44
|
+
pointCloudObjectName: string;
|
|
45
|
+
private emit;
|
|
46
|
+
private on;
|
|
47
|
+
private unbind;
|
|
48
|
+
constructor({ container, scene, camera, renderer, emit, on, unbind }: IPointCloudDelegate);
|
|
49
|
+
initMsg(): void;
|
|
50
|
+
unbindMsg(): void;
|
|
51
|
+
get containerWidth(): number;
|
|
52
|
+
get containerHeight(): number;
|
|
53
|
+
get allSegmentPoints(): ThreePoints[];
|
|
54
|
+
get selectedSegmentPoints(): THREE.Object3D<THREE.Event> | undefined;
|
|
55
|
+
get segmentStatus(): import("@labelbee/lb-utils").EPointCloudSegmentStatus;
|
|
56
|
+
get isReadyStatus(): boolean;
|
|
57
|
+
get isCheckStatus(): boolean;
|
|
58
|
+
get isEditStatus(): boolean;
|
|
59
|
+
/**
|
|
60
|
+
* Need to update the name.
|
|
61
|
+
*/
|
|
62
|
+
get formatData(): {
|
|
63
|
+
attribute: string;
|
|
64
|
+
id: string;
|
|
65
|
+
indexes: number[];
|
|
66
|
+
}[];
|
|
67
|
+
get pointCloudArray(): THREE.Points<THREE.BufferGeometry, THREE.Material | THREE.Material[]>;
|
|
68
|
+
clearAllSegmentData(): void;
|
|
69
|
+
updateCurrentSegment(segmentData: IPointCloudSegmentation[]): void;
|
|
70
|
+
statusToggle(): void;
|
|
71
|
+
updateStatus2Edit(): void;
|
|
72
|
+
createCanvas(id: string): HTMLCanvasElement;
|
|
73
|
+
createCanvas2d(): void;
|
|
74
|
+
setupRaycaster(): void;
|
|
75
|
+
setHoverPointsID(id: string): void;
|
|
76
|
+
setSegmentMode(mode: EPointCloudSegmentMode): void;
|
|
77
|
+
setSegmentCoverMode(coverMode: EPointCloudSegmentCoverMode): void;
|
|
78
|
+
setSegmentFocusMode(focusMode: EPointCloudSegmentFocusMode): void;
|
|
79
|
+
switchSegmentHideMode(hideSegment: boolean): void;
|
|
80
|
+
setHiddenAttributes(attributes: string[]): void;
|
|
81
|
+
updateCanvasBasicStyle(canvas: HTMLCanvasElement, size: ISize, zIndex: number): void;
|
|
82
|
+
syncPolygon2d(polygon2d: ICoordinate[]): void;
|
|
83
|
+
getPointsInPolygon(originPolygon: ICoordinate[]): void;
|
|
84
|
+
updateStatusBySelector(verticesArray: Float32Array, coversArray: Float32Array, indexes: number[]): void;
|
|
85
|
+
syncPointCloudStatus(): void;
|
|
86
|
+
syncSegmentData(): void;
|
|
87
|
+
addStash2Store(): void;
|
|
88
|
+
updatePointCloudBySegment: (segArr: IPointCloudSegmentation[]) => void;
|
|
89
|
+
updateCoverPoints: (coverPoints?: Float32Array) => void;
|
|
90
|
+
updateCloudDataStatus(points: Float32Array, status: {
|
|
91
|
+
[key: string]: any;
|
|
92
|
+
}): void;
|
|
93
|
+
clearStash(): void;
|
|
94
|
+
clearSelectedSegmentData(id?: string): void;
|
|
95
|
+
updateCheck2Edit(): void;
|
|
96
|
+
checkPoints(): void;
|
|
97
|
+
/**
|
|
98
|
+
* Change CheckInstance to EditInstance.
|
|
99
|
+
*/
|
|
100
|
+
editPoints(): void;
|
|
101
|
+
setForbidOperation(forbidOperation: boolean): void;
|
|
102
|
+
updateMouse(offset: ICoordinate): void;
|
|
103
|
+
resetAllSegDataSize(): void;
|
|
104
|
+
resetHoverPointsID(): void;
|
|
105
|
+
resetAllSegDataSizeAndRender(): void;
|
|
106
|
+
highlightPoints(newPoints: ThreePoints): void;
|
|
107
|
+
highlightPointsByAttribute(attribute: string): void;
|
|
108
|
+
setAttribute(attribute: string): void;
|
|
109
|
+
}
|
|
110
|
+
export default PointCloudStore;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import*as c from"three";import{toolStyleConverter as B,PerspectiveShiftUtils as
|
|
1
|
+
import*as c from"three";import{toolStyleConverter as B,PerspectiveShiftUtils as v,EPerspectiveView as C,PointCloudUtils as V,DEFAULT_SPHERE_PARAMS as z}from"@labelbee/lb-utils";import E from"../../_virtual/highlightWorker.js";import F from"../../_virtual/filterBoxWorker.js";import{isInPolygon as N}from"../../utils/tool/polygonTool.js";import _ from"../../utils/uuid.js";import R from"../../utils/MathUtils.js";import{PCDLoader as W}from"./PCDLoader.js";import{OrbitControls as Z}from"./OrbitControls.js";import{PointCloudCache as H}from"./cache.js";import{getCuboidFromPointCloudBox as A}from"./matrix.js";export{createThreeMatrix4,getCuboidFromPointCloudBox,lidar2image,pointCloudLidar2image,rotatePoint,transferKitti2Matrix}from"./matrix.js";import{PointCloudSegmentOperation as U}from"./segmentation.js";import G from"./store/index.js";import $ from"./render/index.js";import X from"../toolOperation/eventListener.js";import"../../constant/tool.js";import"../scheduler.js";var Y=Object.defineProperty,q=Object.defineProperties,K=Object.getOwnPropertyDescriptors,D=Object.getOwnPropertySymbols,Q=Object.prototype.hasOwnProperty,J=Object.prototype.propertyIsEnumerable,k=(w,t,e)=>t in w?Y(w,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):w[t]=e,b=(w,t)=>{for(var e in t||(t={}))Q.call(t,e)&&k(w,e,t[e]);if(D)for(var e of D(t))J.call(t,e)&&k(w,e,t[e]);return w},M=(w,t)=>q(w,K(t)),O=(w,t,e)=>new Promise((i,n)=>{var s=r=>{try{o(e.next(r))}catch(h){n(h)}},a=r=>{try{o(e.throw(r))}catch(h){n(h)}},o=r=>r.done?i(r.value):Promise.resolve(r.value).then(s,a);o((e=e.apply(w,t)).next())});const tt=30,j=new E({type:"module"});class et extends X{constructor({container:t,noAppend:e,isOrthographicCamera:i,orthographicParams:n,backgroundColor:s="#4C4C4C",config:a,isSegment:o}){super();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.nextTick=()=>{!this.segmentOperation||this.segmentOperation._raycasting()},this.keydown=r=>{if(!!this.store)switch(r.key){case" ":this.controls.enablePan=!0,this.store.setForbidOperation(!0);break}},this.keyup=r=>{if(!!this.store)switch(r.key){case" ":this.controls.enablePan=!1,this.store.setForbidOperation(!1);break}},this.addSphereToSense=(r,h="blue")=>{var l;const d=(l=r.id)!=null?l:_();this.removeObjectByName(d);const{radius:p,widthSegments:u,heightSegments:f}=z,{center:m}=r,g=new c.Group,y=new c.SphereGeometry(p,u,f),x=new c.MeshBasicMaterial({color:h}),P=new c.Mesh(y,x);P.position.set(m.x,m.y,m.z),g.add(P),g.name=d,this.scene.add(g)},this.generateSphere=r=>{const{fill:h}=B.getColorFromConfig({attribute:r.attribute},M(b({},this.config),{attributeConfigurable:!0}),{});this.addSphereToSense(r,h),this.render()},this.generateSpheres=r=>{r.forEach(h=>{const{fill:l}=B.getColorFromConfig({attribute:h.attribute},M(b({},this.config),{attributeConfigurable:!0}),{});this.addSphereToSense(h,l)}),this.render()},this.addBoxToSense=(r,h=16777215)=>{var l;const d=(l=r.id)!=null?l:_();this.removeObjectByName(d);const{center:p,width:u,height:f,depth:m,rotation:g}=r,y=new c.Group,x=new c.BoxGeometry(u,f,m),P=new c.MeshBasicMaterial({color:"blue"}),S=new c.Mesh(x,P),L=new c.BoxHelper(S,h),I=this.generateBoxArrow(r),T=this.generateBoxTrackID(r);T&&y.add(T),y.add(L),y.add(I),p&&y.position.set(p.x,p.y,p.z),g&&y.rotation.set(0,0,g),y.name=d,this.scene.add(y)},this.applyCameraTarget=r=>{if(this.camera.type==="OrthographicCamera"&&r){const h=this.getOrthographicCameraTarget(r);this.updateCameraZoom(r.zoom),this.updateCamera(r.position,h)}},this.overridePointShader=r=>{r.vertexShader=`
|
|
2
2
|
attribute float sizes;
|
|
3
3
|
attribute float visibility;
|
|
4
4
|
varying float vVisible;
|
|
5
|
-
${
|
|
5
|
+
${r.vertexShader}`.replace("gl_PointSize = size;",`gl_PointSize = size;
|
|
6
6
|
vVisible = visibility;
|
|
7
|
-
`),
|
|
7
|
+
`),r.fragmentShader=`
|
|
8
8
|
varying float vVisible;
|
|
9
|
-
${
|
|
9
|
+
${r.fragmentShader}`.replace("#include <clipping_planes_fragment>",`
|
|
10
10
|
if (vVisible < 0.5) discard;
|
|
11
|
-
#include <clipping_planes_fragment>`)},this.loadPCDFile=(i,n)=>S(this,null,function*(){this.clearPointCloud(),this.currentPCDSrc=i;const{points:h,color:l}=yield this.cacheInstance.loadPCDFile(i),d=new c.BufferGeometry;d.setAttribute("position",new c.BufferAttribute(h,3)),d.setAttribute("color",new c.BufferAttribute(l,3));const p=new c.Points(d);this.renderPointCloud(p,n)}),this.loadPCDFileByBox=(i,n,h)=>S(this,null,function*(){const l=(g,x)=>S(this,null,function*(){const{width:u=0,height:m=0,depth:C=0}=h!=null?h:{},y=yield this.filterPointsByBox(P(M({},n),{width:n.width+u,height:n.height+m,depth:n.depth+C}),g,x);if(!y){console.error("filter Error");return}this.clearPointCloud(),this.currentPCDSrc=i;const v=new c.Points(y.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 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,d=16776960,p=new c.ArrowHelper(n,h,l,d);return p.visible=this.showDirection,p},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 W(this.camera,this.renderer.domElement),this.pcdLoader=new R,this.axesHelper=new c.AxesHelper(1e3),this.scene.add(this.camera),e||t.appendChild(this.renderer.domElement),this.init(),this.cacheInstance=Z.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]=B.getColorFromConfig({attribute:r.attribute},P(M({},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,d=-100,p=500/l;return{left:a,right:i,top:n,bottom:h,near:l,far:d,zoom:p}}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)}updateCameraBySphere(t,e){const{center:r}=t,{radius:o}=z,s=this.getCameraVector(r,0,{width:o*2,height:o*2,depth:o*2},e);return this.updateCamera(s,r),s}updateOrthoCamera(t,e){const r=this.updateCameraByBox(t,e);return this.camera.zoom=1,this.camera.updateProjectionMatrix(),{cameraPositionVector:r}}updateOrthoCameraBySphere(t,e){const r=this.updateCameraBySphere(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}=A(t),l=e;r=r!=null?r:new Float32Array([]);const d={boxParams:t,zMin:i,zMax:n,polygonPointList:h,color:r,position:l};return new Promise(p=>{const g=new N;g.postMessage(d),g.onmessage=x=>{const{color:u,position:m,num:C}=x.data,y=new c.BufferGeometry;y.setAttribute("position",new c.Float32BufferAttribute(m,3)),y.setAttribute("color",new c.Float32BufferAttribute(u,3)),y.computeBoundingSphere(),g.terminate(),p({geometry:y,num:C})}})}return Promise.resolve(void 0)}getCameraVector(t,e,r,o=w.Front,s=Y){let a=b.frontViewMatrix4(s);switch(o){case w.Front:break;case w.Back:a=b.backViewMatrix4(s);break;case w.Left:a=b.leftViewMatrix4(s);break;case w.Right:a=b.rightViewMatrix4(s);break;case w.Top:a=b.topViewMatrix4(s);break;case w.LFT:a=b.leftFrontTopViewMatrix4(s,r);break;case w.RBT:a=b.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=>A(h)),i=this.getAllAttributeColor(a),n={cuboidList:a,position:e.geometry.attributes.position.array,color:e.geometry.attributes.color.array,colorList:i};D.postMessage(n),D.onmessage=h=>{const{color:l}=h.data,d=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,d.needsUpdate=!0,e.geometry.setAttribute("color",d),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}filterNoise(t){let e=[...t];e.sort((d,p)=>d.z-p.z);const r=Math.floor(e.length*.05),o=e[r];e=e.filter(({z:d})=>d>o.z+.1);const s=.005,a=Math.floor(e.length*(1-s));e=e.slice(0,a),e.sort((d,p)=>d.x-p.x);const i=Math.floor(e.length*s),n=Math.floor(e.length*(1-s));e=e.slice(i,n),e.sort((d,p)=>d.y-p.y);const h=Math.floor(e.length*s),l=Math.floor(e.length*(1-s));return e=e.slice(h,l),e.length>100?e:t}getFittedCoordinates(t,e){const r=[];let o=[...t,t[0]];e.forEach(({x:i,y:n})=>{t.forEach((h,l)=>{const d=o[l+1],p=F.getFootOfPerpendicular({x:i,y:n},h,d,!1,!0).length;(!r[l]||p<r[l].distance)&&(r[l]={distance:p,point:{x:i,y:n}})})}),o=[t[t.length-1],...t,t[0]];const s=[r[r.length-1],...r];return t.map((i,n)=>{const h=o[n],l=o[n+1],d=o[n+2];return k.getIntersectionBySlope({p1:s[n].point,line1:[h,l],p2:s[n+1].point,line2:[l,d]})})}getSensesPointZAxisInPolygon(t,e,r){var o,s,a;const i=this.scene.children.find(u=>u.uuid===this.pointsUuid);let n=0,h=0,l=0,d=0,p=[],g=[];const x=((a=(s=(o=i==null?void 0:i.geometry)==null?void 0:o.attributes)==null?void 0:s.position)==null?void 0:a.array)||[];for(let u=0;u<x.length;u+=3){const m=x[u],C=x[u+1],y=x[u+2];E({x:m,y:C},t)&&(y||y===0)&&g.push({x:m,y:C,z:y})}return g.length?(r&&(g=this.filterNoise(g),p=this.getFittedCoordinates(t,g)),g.sort((u,m)=>u.z-m.z),n=g[0].z-.01,h=g[g.length-1].z+.01,d=g.length,e&&(l=g.filter(({z:u})=>u>=e[0]&&u<=e[1]).length),{maxZ:h,minZ:n,count:l,zCount:d,fittedCoordinates:p}):{maxZ:h,minZ:n,count:l,zCount:d,fittedCoordinates:p}}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},d={x:e-a/2,y:r+s/2,z:o-i/2};return[n,h,l,d]}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},d={x:e-a/2,y:r-s/2,z:o+i/2};return[n,h,l,d]}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},d={x:e-a/2,y:r+s/2,z:o+i/2};return[n,h,l,d]}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,w.Left)}getBoxBackPolygon2DCoordinate(t){return this.getBoxPolygon2DCoordinate(t,w.Back)}getSphereSidePoint2DCoordinate(t){return this.getSpherePoint2DCoordinate(t)}getSphereBackPoint2DCoordinate(t){return this.getSpherePoint2DCoordinate(t)}boxParams2ViewPolygon(t,e){switch(e){case w.Left:return this.getPolygonSidePoints(t);case w.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(d=>new c.Vector3(d.x,d.y,d.z)).map(d=>d.applyMatrix4(this.sideMatrix)),h=this.containerWidth/o,l=this.containerHeight/s;return{polygon2d:n,zoom:Math.min(h,l)/2}}getSpherePoint2DCoordinate(t){const{center:e,attribute:r,id:o,valid:s}=t,{radius:a}=z,i={center:e,attribute:r,id:o,valid:s,width:a*2,height:a*2,depth:a*2,rotation:0},n=new c.Matrix4().premultiply(this.camera.matrixWorldInverse).premultiply(this.camera.projectionMatrix),h=new c.Matrix4().premultiply(this.getModelTransformationMatrix(i)).premultiply(n).premultiply(this.basicCoordinate2CanvasMatrix4);this.sideMatrix=h;const l=new c.Vector3(e.x,e.y,e.z).applyMatrix4(this.sideMatrix),d=this.containerWidth/(a*2),p=this.containerHeight/(a*2);return{point2d:l,zoom:Math.min(d,p)/2}}getSphereTopPoint2DCoordinate(t){const{center:e}=t,{radius:r}=z,o={x:-(e.y-this.containerWidth/2),y:-(e.x-this.containerHeight/2)},s=this.containerWidth/(r*2),a=this.containerHeight/(r*2);return{point2d:o,zoom:Math.min(s,a)/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=P(M({},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=P(M({},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,d]=i,p=Math.max(Math.abs(n.x-l.x),Math.abs(n.x-h.x)),x=h.add(d).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:P(M({},o),{center:{x:o.center.x-x.x,y:o.center.y-x.y,z:o.center.z-r},width:p,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{q as PointCloud};
|
|
11
|
+
#include <clipping_planes_fragment>`)},this.loadPCDFile=(...r)=>O(this,[...r],function*(h=this.currentPCDSrc,l){if(!h)return;this.clearPointCloud(),this.currentPCDSrc=h;const{points:d,color:p}=yield this.cacheInstance.loadPCDFile(h),u=new c.BufferGeometry;u.setAttribute("position",new c.BufferAttribute(d,3)),u.setAttribute("color",new c.BufferAttribute(p,3)),this.initCloudData(d);const f=new c.Points(u);this.renderPointCloud(f,l)}),this.loadPCDFileByBox=(r,h,l)=>O(this,null,function*(){const d=(f,m)=>O(this,null,function*(){const{width:g=0,height:y=0,depth:x=0}=l!=null?l:{},P=yield this.filterPointsByBox(M(b({},h),{width:h.width+g,height:h.height+y,depth:h.depth+x}),f,m);if(!P){console.error("filter Error");return}this.clearPointCloud(),this.currentPCDSrc=r;const S=new c.Points(P.geometry);S.name=this.pointCloudObjectName,this.scene.add(S),this.render()}),{points:p,color:u}=yield this.cacheInstance.loadPCDFile(r);d(p,u)}),this.generateRange=r=>{const h=this.createRange(r);this.scene.add(h)},this.generateBoxArrow=({width:r})=>{const h=new c.Vector3(1,0,0),l=new c.Vector3(r/2,0,0),d=2,p=16776960,u=new c.ArrowHelper(h,l,d,p);return u.visible=this.showDirection,u},this.generateBoxTrackID=r=>{if(!r.trackID)return;const h=new c.Texture(this.getTextCanvas(r.trackID.toString()));h.needsUpdate=!0;const l=new c.SpriteMaterial({map:h,depthWrite:!1}),d=new c.Sprite(l);return d.scale.set(5,5,5),d.position.set(-r.width/2,0,r.depth/2+.5),d},this.applyZAxisPoints=r=>{this.zAxisLimit=r,this.filterZAxisPoints(),this.render()},this.updatePointSize=({zoomIn:r,customSize:h})=>{const l=this.scene.getObjectByName(this.pointCloudObjectName);if(!l)return;const d=l.material.size;r?l.material.size=Math.min(d*1.2,10):l.material.size=Math.max(d/1.2,1),h&&(l.material.size=h,this.pointsMaterialSize=h),this.render()},this.container=t,this.renderer=new c.WebGLRenderer({antialias:!0}),this.backgroundColor=s,this.config=a,i&&n?(this.isOrthographicCamera=!0,this.camera=new c.OrthographicCamera(n.left,n.right,n.top,n.bottom,n.near,n.far)):this.camera=new c.PerspectiveCamera(30,this.containerWidth/this.containerHeight,1,1e3),this.initCamera(),this.scene=new c.Scene,this.controls=new Z(this.camera,o?this.container:this.renderer.domElement),this.pcdLoader=new W,this.axesHelper=new c.AxesHelper(1e3),this.scene.add(this.axesHelper),this.scene.add(this.camera),e||t.appendChild(this.renderer.domElement),this.init(),this.cacheInstance=H.getInstance(),o===!0&&this.initSegment()}initSegment(){this.store=new G(this.pointCloudDelegate),this.controls.enablePan=!1,this.controls.addEventListener("start",this.orbiterStart.bind(this)),this.controls.addEventListener("change",this.orbiterChange.bind(this)),this.controls.addEventListener("end",this.orbiterEnd.bind(this)),this.segmentOperation=new U({dom:this.container,store:this.store}),this.pointCloudRender=new $(M(b({store:this.store},this.eventBus),{nextTick:this.nextTick,config:this.config})),this.initMsg(),document.addEventListener("keydown",this.keydown),document.addEventListener("keyup",this.keyup)}orbiterStart(){}orbiterChange(){!this.store||(this.store.orbiting=!0)}orbiterEnd(){!this.store||(this.store.orbiting=!1)}get currentSegmentTool(){var t;return(t=this.segmentOperation)==null?void 0:t.currentToolName}initMsg(){!this.segmentOperation||(this.on("CircleSelector",this.segmentOperation.updateSelector2Circle.bind(this.segmentOperation)),this.on("LassoSelector",this.segmentOperation.updateSelector2Lasso.bind(this.segmentOperation)),this.on("clearPointCloud",this.clearPointCloud.bind(this)),this.on("loadPCDFile",this.loadPCDFile.bind(this)))}unbindMsg(){!this.segmentOperation||(this.unbind("CircleSelector",this.segmentOperation.updateSelector2Circle.bind(this.segmentOperation)),this.unbind("LassoSelector",this.segmentOperation.updateSelector2Lasso.bind(this.segmentOperation)),this.unbind("clearPointCloud",this.clearPointCloud.bind(this)),this.unbind("loadPCDFile",this.loadPCDFile.bind(this)))}get eventBus(){return{on:this.on.bind(this),emit:this.emit.bind(this),unbind:this.unbind.bind(this)}}get pointCloudDelegate(){return b({container:this.container,scene:this.scene,camera:this.camera,renderer:this.renderer},this.eventBus)}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:i,top:n,bottom:s,near:a,far:o}=t;this.camera.left=e,this.camera.right=i,this.camera.top=n,this.camera.bottom=s,this.camera.near=a,this.camera.far=o,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:i,z:n}=this.initCameraPosition;t.position.set(e,i,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 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 i=e;this.addBoxToSense(t,i),this.render()}getAllAttributeColor(t){return t.reduce((e,i)=>(e[i.attribute]=B.getColorFromConfig({attribute:i.attribute},M(b({},this.config),{attributeConfigurable:!0}),{}),e),{})}generateBoxes(t){t.forEach(e=>{this.addBoxToSense(e)}),this.render()}getOrthographicCamera(t){const{center:e,width:i,height:n}=t,s=10,a=e.x-i/2-s,o=e.x-i/2+s,r=e.y+n/2+s,h=e.y-n/2-s,l=100,d=-100,p=500/l;return{left:a,right:o,top:r,bottom:h,near:l,far:d,zoom:p}}updateCameraZoom(t){this.camera.zoom=t,this.camera.updateProjectionMatrix()}updateCameraByBox(t,e,i){const{center:n,width:s,height:a,depth:o,rotation:r}=t,h=this.getCameraVector(n,r,{width:s,height:a,depth:o},e);return i?(this.updateCamera(i,n),new c.Vector3(i.x,i.y,i.z)):(this.updateCamera(h,n),h)}updateCameraBySphere(t,e){const{center:i}=t,{radius:n}=z,s=this.getCameraVector(i,0,{width:n*2,height:n*2,depth:n*2},e);return this.updateCamera(s,i),s}updateOrthoCamera(t,e){const i=this.updateCameraByBox(t,e);return this.camera.zoom=1,this.camera.updateProjectionMatrix(),{cameraPositionVector:i}}updateOrthoCameraBySphere(t,e){const i=this.updateCameraBySphere(t,e);return this.camera.zoom=1,this.camera.updateProjectionMatrix(),{cameraPositionVector:i}}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,i){var n,s,a;if(!e){const o=this.scene.getObjectByName(this.pointCloudObjectName);if(!o)return console.error("There is no corresponding point cloud object"),Promise.resolve(void 0);e=(a=(s=(n=o==null?void 0:o.geometry)==null?void 0:n.attributes)==null?void 0:s.position)==null?void 0:a.array}if(window.Worker){const{zMin:o,zMax:r,polygonPointList:h}=A(t),l=e;i=i!=null?i:new Float32Array([]);const d={boxParams:t,zMin:o,zMax:r,polygonPointList:h,color:i,position:l};return new Promise(p=>{const u=new F;u.postMessage(d),u.onmessage=f=>{const{color:m,position:g,num:y}=f.data,x=new c.BufferGeometry;x.setAttribute("position",new c.Float32BufferAttribute(g,3)),x.setAttribute("color",new c.Float32BufferAttribute(m,3)),x.computeBoundingSphere(),u.terminate(),p({geometry:x,num:y})}})}return Promise.resolve(void 0)}getCameraVector(t,e,i,n=C.Front,s=tt){let a=v.frontViewMatrix4(s);switch(n){case C.Front:break;case C.Back:a=v.backViewMatrix4(s);break;case C.Left:a=v.leftViewMatrix4(s);break;case C.Right:a=v.rightViewMatrix4(s);break;case C.Top:a=v.topViewMatrix4(s);break;case C.LFT:a=v.leftFrontTopViewMatrix4(s,i);break;case C.RBT:a=v.rightBackTopViewMatrix4(s,i);break}const o=this.createThreeMatrix4(a),r=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(o).applyMatrix4(r).applyMatrix4(l).applyMatrix4(h)}createRange(t){this.removeObjectByName(this.rangeObjectName);const i=new c.EllipseCurve(0,0,t,t,0,2*Math.PI,!1,0).getPoints(50),n=new c.BufferGeometry().setFromPoints(i),s=new c.LineBasicMaterial({color:16711680}),a=new c.Line(n,s);return a.name=this.rangeObjectName,a}renderPointCloud(t,e){t.name=this.pointCloudObjectName;const i=new c.PointsMaterial({vertexColors:!0});i.onBeforeCompile=this.overridePointShader,i.size=this.pointsMaterialSize,e&&this.generateRange(e),this.pointsUuid=t.uuid,this.filterZAxisPoints(t),this.scene.add(t),this.render()}clearPointCloud(){this.removeObjectByName(this.pointCloudObjectName)}clearPointCloudAndRender(){this.clearPointCloud(),this.render()}initCloudData(t){if(!!this.store)for(let e=0;e<t.length;e+=3){const i=t[e],n=t[e+1],s=t[e+2];this.store.cloudData.set(`${i}@${n}@${s}`,{visible:!1})}}highlightOriginPointCloud(t){const e=this.scene.getObjectByName(this.pointCloudObjectName);if(!!e)return this.highlightPCDSrc=this.currentPCDSrc,new Promise((i,n)=>{if(window.Worker){const a=(t?[...t]:[]).map(h=>A(h)),o=this.getAllAttributeColor(a),r={cuboidList:a,position:e.geometry.attributes.position.array,color:e.geometry.attributes.color.array,colorList:o};j.postMessage(r),j.onmessage=h=>{const{color:l}=h.data,d=new c.BufferAttribute(l,3);if(!this.highlightPCDSrc||this.highlightPCDSrc!==this.currentPCDSrc||e.geometry.attributes.position.array.length!==l.length){n(new Error("Error Path"));return}this.cacheInstance.updateColor(this.highlightPCDSrc,l),this.highlightPCDSrc=void 0,d.needsUpdate=!0,e.geometry.setAttribute("color",d),i(l),this.render()}}})}updateColor(t){const e=this.scene.getObjectByName(this.pointCloudObjectName);if(e){const i=new c.BufferAttribute(t,3);i.needsUpdate=!0,e.geometry.setAttribute("color",i),this.render()}}setShowDirection(t){this.showDirection=t,this.scene.children.forEach(e=>{e.type==="Group"&&e.children.forEach(i=>{i.type==="ArrowHelper"&&(i.visible=t)})}),this.render()}getTextCanvas(t){const e=document.createElement("canvas"),i=e.getContext("2d");return i&&(i.font=`${50}px " bold`,i.fillStyle="white",i.textAlign="center",i.textBaseline="middle",i.fillText(t,e.width/2,e.height/2)),e}filterNoise(t){let e=[...t];e.sort((d,p)=>d.z-p.z);const i=Math.floor(e.length*.05),n=e[i];e=e.filter(({z:d})=>d>n.z+.1);const s=.005,a=Math.floor(e.length*(1-s));e=e.slice(0,a),e.sort((d,p)=>d.x-p.x);const o=Math.floor(e.length*s),r=Math.floor(e.length*(1-s));e=e.slice(o,r),e.sort((d,p)=>d.y-p.y);const h=Math.floor(e.length*s),l=Math.floor(e.length*(1-s));return e=e.slice(h,l),e.length>100?e:t}getFittedCoordinates(t,e){const i=[];let n=[...t,t[0]];e.forEach(({x:o,y:r})=>{t.forEach((h,l)=>{const d=n[l+1],p=R.getFootOfPerpendicular({x:o,y:r},h,d,!1,!0).length;(!i[l]||p<i[l].distance)&&(i[l]={distance:p,point:{x:o,y:r}})})}),n=[t[t.length-1],...t,t[0]];const s=[i[i.length-1],...i];return t.map((o,r)=>{const h=n[r],l=n[r+1],d=n[r+2];return V.getIntersectionBySlope({p1:s[r].point,line1:[h,l],p2:s[r+1].point,line2:[l,d]})})}getSensesPointZAxisInPolygon(t,e,i){var n,s,a;const o=this.scene.children.find(m=>m.uuid===this.pointsUuid);let r=0,h=0,l=0,d=0,p=[],u=[];const f=((a=(s=(n=o==null?void 0:o.geometry)==null?void 0:n.attributes)==null?void 0:s.position)==null?void 0:a.array)||[];for(let m=0;m<f.length;m+=3){const g=f[m],y=f[m+1],x=f[m+2];N({x:g,y},t)&&(x||x===0)&&u.push({x:g,y,z:x})}return u.length?(i&&(u=this.filterNoise(u),p=this.getFittedCoordinates(t,u)),u.sort((m,g)=>m.z-g.z),r=u[0].z-.01,h=u[u.length-1].z+.01,d=u.length,e&&(l=u.filter(({z:m})=>m>=e[0]&&m<=e[1]).length),{maxZ:h,minZ:r,count:l,zCount:d,fittedCoordinates:p}):{maxZ:h,minZ:r,count:l,zCount:d,fittedCoordinates:p}}getBasicCoordinate2Canvas(t){const e=this.containerWidth/2,i=this.containerHeight/2;return{x:t.x*e+e,y:t.y*i+i,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,i=this.containerHeight/2;return new c.Vector3(t.x/e-e/2,-(t.y/i-i/2),1)}getPolygonSidePoints(t){const{center:{x:e,y:i,z:n},height:s,width:a,depth:o}=t,r={x:e+a/2,y:i+s/2,z:n-o/2},h={x:e+a/2,y:i+s/2,z:n+o/2},l={x:e-a/2,y:i+s/2,z:n+o/2},d={x:e-a/2,y:i+s/2,z:n-o/2};return[r,h,l,d]}getPolygonBackPoints(t){const{center:{x:e,y:i,z:n},height:s,width:a,depth:o}=t,r={x:e-a/2,y:i+s/2,z:n+o/2},h={x:e-a/2,y:i+s/2,z:n-o/2},l={x:e-a/2,y:i-s/2,z:n-o/2},d={x:e-a/2,y:i-s/2,z:n+o/2};return[r,h,l,d]}getPolygonTopPoints(t){const{center:{x:e,y:i,z:n},height:s,width:a,depth:o}=t,r={x:e+a/2,y:i+s/2,z:n+o/2},h={x:e+a/2,y:i-s/2,z:n+o/2},l={x:e-a/2,y:i-s/2,z:n+o/2},d={x:e-a/2,y:i+s/2,z:n+o/2};return[r,h,l,d]}getModelTransformationMatrix(t){const{center:{x:e,y:i,z:n},rotation:s}=t,a=new c.Matrix4().makeTranslation(-e,-i,-n),o=new c.Matrix4().makeTranslation(e,i,n),r=new c.Matrix4().makeRotationZ(s);return new c.Matrix4().multiply(o).multiply(r).multiply(a)}getBoxSidePolygon2DCoordinate(t){return this.getBoxPolygon2DCoordinate(t,C.Left)}getBoxBackPolygon2DCoordinate(t){return this.getBoxPolygon2DCoordinate(t,C.Back)}getSphereSidePoint2DCoordinate(t){return this.getSpherePoint2DCoordinate(t)}getSphereBackPoint2DCoordinate(t){return this.getSpherePoint2DCoordinate(t)}boxParams2ViewPolygon(t,e){switch(e){case C.Left:return this.getPolygonSidePoints(t);case C.Back:return this.getPolygonBackPoints(t);default:return this.getPolygonTopPoints(t)}}getBoxPolygon2DCoordinate(t,e){const i=this.boxParams2ViewPolygon(t,e),{width:n,height:s}=t,a=new c.Matrix4().premultiply(this.camera.matrixWorldInverse).premultiply(this.camera.projectionMatrix),o=new c.Matrix4().premultiply(this.getModelTransformationMatrix(t)).premultiply(a).premultiply(this.basicCoordinate2CanvasMatrix4);this.sideMatrix=o;const r=i.map(d=>new c.Vector3(d.x,d.y,d.z)).map(d=>d.applyMatrix4(this.sideMatrix)),h=this.containerWidth/n,l=this.containerHeight/s;return{polygon2d:r,zoom:Math.min(h,l)/2}}getSpherePoint2DCoordinate(t){const{center:e,attribute:i,id:n,valid:s}=t,{radius:a}=z,o={center:e,attribute:i,id:n,valid:s,width:a*2,height:a*2,depth:a*2,rotation:0},r=new c.Matrix4().premultiply(this.camera.matrixWorldInverse).premultiply(this.camera.projectionMatrix),h=new c.Matrix4().premultiply(this.getModelTransformationMatrix(o)).premultiply(r).premultiply(this.basicCoordinate2CanvasMatrix4);this.sideMatrix=h;const l=new c.Vector3(e.x,e.y,e.z).applyMatrix4(this.sideMatrix),d=this.containerWidth/(a*2),p=this.containerHeight/(a*2);return{point2d:l,zoom:Math.min(d,p)/2}}getSphereTopPoint2DCoordinate(t){const{center:e}=t,{radius:i}=z,n={x:-(e.y-this.containerWidth/2),y:-(e.x-this.containerHeight/2)},s=this.containerWidth/(i*2),a=this.containerHeight/(i*2);return{point2d:n,zoom:Math.min(s,a)/2}}getBoxTopPolygon2DCoordinate(t){const{width:e,height:i}=t,s=this.getPolygonTopPoints(t).map(r=>new c.Vector3(r.x,r.y,r.z)).map(r=>r.applyMatrix4(this.getModelTransformationMatrix(t))).map(r=>({x:r.y,y:r.x})).map(r=>({x:-(r.x-this.containerWidth/2),y:-(r.y-this.containerHeight/2)})),a=this.containerWidth/e,o=this.containerHeight/i;return{polygon2d:s,zoom:Math.min(a,o)/2}}getNewBoxBySideUpdate(t,e,i,n){const s=new c.Matrix4().makeRotationZ(n.rotation),a=new c.Vector3(-t.x,0,0).applyMatrix4(s);let o=n;return o.center={x:o.center.x+a.x,y:o.center.y+a.y,z:o.center.z-t.z},o=M(b({},o),{width:o.width+e,height:o.height,depth:o.depth+i}),{newBoxParams:o}}getNewBoxByBackUpdate(t,e,i,n){const s=new c.Matrix4().makeRotationZ(n.rotation),a=new c.Vector3(0,-t.x,0).applyMatrix4(s);let o=n;return o.center={x:o.center.x+a.x,y:o.center.y+a.y,z:o.center.z-t.z},o=M(b({},o),{width:o.width,height:o.height+e,depth:o.depth+i}),{newBoxParams:o}}getNewBoxBySideUpdateByPoints(t,e,i,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 o=t.map(g=>new c.Vector3(g.x,g.y,g.z)).map(g=>g.applyMatrix4(a)),[r,h,l,d]=o,p=Math.max(Math.abs(r.x-l.x),Math.abs(r.x-h.x)),f=h.add(d).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(n.center.x,n.center.y,n.center.z));return{newBoxParams:M(b({},n),{center:{x:n.center.x-f.x,y:n.center.y-f.y,z:n.center.z-i},width:p,height:n.height,depth:n.depth+e,rotation:n.rotation})}}filterZAxisPoints(t){const e=t||this.scene.children.find(i=>i.uuid===this.pointsUuid);if(e){const{attributes:i}=e.geometry,{position:n}=i,s=[],{count:a}=n;for(let o=0;o<a;o++){const r=n.getZ(o);s.push(r>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{et as PointCloud};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import*as o from"three";import{colorArr as g,toolStyleConverter as p}from"@labelbee/lb-utils";import P from"../../../utils/tool/DrawUtils.js";var m=Object.defineProperty,b=Object.defineProperties,f=Object.getOwnPropertyDescriptors,h=Object.getOwnPropertySymbols,S=Object.prototype.hasOwnProperty,v=Object.prototype.propertyIsEnumerable,d=(n,e,t)=>e in n?m(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,w=(n,e)=>{for(var t in e||(e={}))S.call(e,t)&&d(n,t,e[t]);if(h)for(var t of h(e))v.call(e,t)&&d(n,t,e[t]);return n},C=(n,e)=>b(n,f(e));class _{constructor({store:e,on:t,unbind:a,nextTick:c,config:u}){this.clearStash=()=>{var r,s;const i=this.scene.getObjectByName((s=(r=this.store.cacheSegData)==null?void 0:r.id)!=null?s:"");i&&(i.removeFromParent(),this.render3d())},this.generateNewPoints=r=>{const s=new o.BufferGeometry;s.setAttribute("position",new o.BufferAttribute(r.points,3));const i=new o.PointsMaterial({color:this.getCurrentColor(r.attribute),size:10}),l=new o.Points(s,i);l.name=r.id,this.store.scene.add(l),this.render3d()},this.updateNewPoints=r=>{var s;const i=this.store.scene.getObjectByName((s=r==null?void 0:r.id)!=null?s:"");i&&r&&(i.geometry.setAttribute("position",new o.Float32BufferAttribute(r.points,3)),i.material=new o.PointsMaterial({color:this.getCurrentColor(r.attribute),size:10}),i.geometry.attributes.position.needsUpdate=!0,i.geometry.computeBoundingSphere(),this.render3d())},this.updatePointsColor=(r=this.store.cacheSegData)=>{var s;const i=this.store.scene.getObjectByName((s=r==null?void 0:r.id)!=null?s:"");i&&r&&(r.attribute=this.store.currentAttribute,i.material=new o.PointsMaterial({color:this.getCurrentColor(r.attribute),size:10}),this.render3d())},this.render3d=()=>{this.store.renderer.render(this.store.scene,this.store.camera)},this.store=e,this.on=t,this.unbind=a,this.nextTick=c,this.config=u,this.generateNewPoints=this.generateNewPoints.bind(this),this.clearStash=this.clearStash.bind(this),this.render3d=this.render3d.bind(this),this.updateNewPoints=this.updateNewPoints.bind(this),this.updatePointsColor=this.updatePointsColor.bind(this),this.clearAllSegmentData=this.clearAllSegmentData.bind(this),this.clearSelectedSegmentRender=this.clearSelectedSegmentRender.bind(this),this.initMsg(),this.animate()}get scene(){return this.store.scene}getCurrentColor(e=this.store.currentAttribute){if(!e||!this.config)return g[0].hexString;const{fill:t}=p.getColorFromConfig({attribute:e},C(w({},this.config),{attributeConfigurable:!0}),{});return t}initMsg(){this.on("addNewPointsCloud",this.generateNewPoints),this.on("updateNewPoints",this.updateNewPoints),this.on("clearStashRender",this.clearStash),this.on("clearAllSegmentData",this.clearAllSegmentData),this.on("reRender3d",this.render3d),this.on("clearSelectedSegmentData",this.clearSelectedSegmentRender)}unbindMsg(){this.unbind("addNewPointsCloud",this.generateNewPoints),this.unbind("updateNewPoints",this.updateNewPoints),this.unbind("clearStashRender",this.clearStash),this.unbind("clearAllSegmentData",this.clearAllSegmentData),this.unbind("reRender3d",this.render3d),this.unbind("clearSelectedSegmentData",this.clearSelectedSegmentRender)}get canvas2d(){return this.store.canvas2d}clearCanvasMouse(){var e,t;(t=(e=this.canvas2d)==null?void 0:e.getContext("2d"))==null||t.clearRect(0,0,this.store.containerWidth,this.store.containerHeight)}renderCanvas2dPolygon(){var e;((e=this.store.polygon2d)==null?void 0:e.length)>0&&this.canvas2d&&P.drawPolygon(this.canvas2d,this.store.polygon2d,{isClose:!1,color:this.getCurrentColor(),thickness:4})}clearAllSegmentData(){const e=this.scene.children.length;for(let t=e-1;t>=0;t--){const a=this.scene.children[t];a.type==="Points"&&a.name!==this.store.pointCloudObjectName&&a.removeFromParent()}this.render3d()}clearSelectedSegmentRender(e=""){const t=this.scene.getObjectByName(e);t&&(t.removeFromParent(),this.render3d())}animate(){requestAnimationFrame(this.animate.bind(this)),this.clearCanvasMouse(),this.renderCanvas2dPolygon(),this.nextTick()}}export{_ as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{EPointCloudSegmentStatus as r}from"@labelbee/lb-utils";import n from"./selector/lassoSelector.js";import c from"./selector/circleSelector.js";class h{constructor(e){this.onMouseMove=t=>{if((this.store.isCheckStatus||this.store.isReadyStatus)&&this.store.updateMouse({x:t.offsetX,y:t.offsetY}),this.isForbid)return;const s={offsetX:t.offsetX,offsetY:t.offsetY,button:t.buttons};this.currentTool.mouseMove(s)},this.onMouseDown=t=>{this.isForbid||this.currentTool.mouseDown(t)},this.onMouseUp=t=>{this.isForbid||this.store.orbiting===!0||this.baseMouseDown(t)||this.currentTool.mouseUp(t)},this.baseMouseDown=t=>{switch(t.button){case 0:if(this.store.isReadyStatus||this.store.isCheckStatus)return this.store.checkPoints(),!0;break}},this._raycasting=()=>{if([r.Ready,r.Check].includes(this.store.segmentStatus)){const{mouse:t,camera:s,raycaster:o}=this.store;o.setFromCamera(t,s);const i=o.intersectObjects(this.store.allSegmentPoints,!1)[0];i?this.store.highlightPoints(i.object):(this.store.resetAllSegDataSizeAndRender(),this.store.resetHoverPointsID())}},this.dom=e.dom,this.store=e.store,this.lassoSelector=new n(this.store),this.circleSelector=new c(this.store),this.currentTool=this.circleSelector,this.currentToolName="CircleSelector",this.dom.addEventListener("pointermove",this.onMouseMove.bind(this)),this.dom.addEventListener("pointerdown",this.onMouseDown.bind(this)),this.dom.addEventListener("pointerup",this.onMouseUp.bind(this)),this.updateSelector2Lasso=this.updateSelector2Lasso.bind(this),this.updateSelector2Circle=this.updateSelector2Circle.bind(this)}getCoordinate(e){const t=this.dom.getBoundingClientRect();return{x:e.clientX-t.left,y:e.clientY-t.top}}get forbidOperation(){return this.store.forbidOperation}get isForbid(){return this.forbidOperation}updateSelector2Lasso(){this.currentTool=this.lassoSelector,this.currentToolName="LassoSelector"}updateSelector2Circle(){this.currentTool=this.circleSelector,this.currentToolName="CircleSelector"}}export{h as PointCloudSegmentOperation};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import f from"./selector.js";class c extends f{constructor(){super(...arguments);this.radius=20}mouseDown(t){t.button===2&&(this.pushPoint(t.offsetX,t.offsetY),this.startX=t.offsetX,this.startY=t.offsetY)}mouseUp(t){t.button===2&&(this.store.getPointsInPolygon(this.polygon2d),this.polygon2d.length=0,this.startX=this.startY=NaN)}mouseMove(t){if(t.button===2&&this.startX&&this.startY){this.polygon2d.length=0;const a=64,i=Math.PI*2,o=this.startX,n=this.startY,r=t.offsetX,e=t.offsetY,h=Math.sqrt((r-o)*(r-o)+(e-n)*(e-n));for(let s=0;s<i;s+=i/a)this.pushPoint(o+h*Math.cos(s),n-h*Math.sin(s))}}}export{c as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import t from"./selector.js";class s extends t{mouseDown(o){o.button===2&&this.pushPoint(o.offsetX,o.offsetY)}mouseUp(o){o.button===2&&(this.store.getPointsInPolygon(this.polygon2d),this.updatePolygon2d([]))}mouseMove(o){o.button===2&&this.pushPoint(o.offsetX,o.offsetY)}}export{s as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
class t{constructor(o){this.store=o,this.polygon2d=[]}pushPoint(o,s){this.polygon2d.push({x:o,y:s}),this.store.syncPolygon2d(this.polygon2d)}updatePolygon2d(o){this.polygon2d=o,this.store.syncPolygon2d(this.polygon2d)}}export{t as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{EPointCloudSegmentStatus as t}from"@labelbee/lb-utils";class e{constructor(){this.segmentStatus=t.Ready}statusToggle(){switch(this.segmentStatus){case t.Ready:this.segmentStatus=t.Check;break;case t.Check:this.segmentStatus=t.Edit;break;case t.Edit:this.segmentStatus=t.Ready;break;default:console.error("Error Status in PointCloudSegmentFSM")}}updateStatus2Edit(){this.segmentStatus=t.Edit}updateStatus2Check(){this.segmentStatus=t.Check}updateStatus2Ready(){this.segmentStatus=t.Ready}get isReadyStatus(){return this.segmentStatus===t.Ready}get isCheckStatus(){return this.segmentStatus===t.Check}get isEditStatus(){return this.segmentStatus===t.Edit}}const s=new e;export{s as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import*as P from"three";import{EPointCloudSegmentMode as p,EPointCloudSegmentCoverMode as M,EPointCloudSegmentFocusMode as f,PointCloudUtils as D}from"@labelbee/lb-utils";import{isInPolygon as B}from"../../../utils/tool/polygonTool.js";import j from"../../../utils/uuid.js";import m from"./fsm.js";var R=Object.defineProperty,N=Object.defineProperties,x=Object.getOwnPropertyDescriptors,w=Object.getOwnPropertySymbols,H=Object.prototype.hasOwnProperty,I=Object.prototype.propertyIsEnumerable,E=(l,t,e)=>t in l?R(l,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):l[t]=e,y=(l,t)=>{for(var e in t||(t={}))H.call(t,e)&&E(l,e,t[e]);if(w)for(var e of w(t))I.call(t,e)&&E(l,e,t[e]);return l},b=(l,t)=>N(l,x(t));const k="LABELBEE_CANVAS_";class z{constructor({container:t,scene:e,camera:i,renderer:a,emit:o,on:c,unbind:s}){this.canvas2d=null,this.polygon2d=[],this.forbidOperation=!1,this.raycaster=new P.Raycaster,this.mouse=new P.Vector2,this.cloudData=new Map,this.segmentData=new Map,this.hoverPointsID="",this.segmentMode=p.Add,this.segmentCoverMode=M.Cover,this.segmentFocusMode=f.Unfocus,this.hideSegment=!1,this.updatePointCloud=!1,this.addPointCloud=!1,this.orbiting=!1,this.currentAttribute="",this.highlightAttribute="",this.hiddenAttributes=[],this.pointCloudObjectName="pointCloud",this.updatePointCloudBySegment=u=>{this.segmentData.forEach((d,r)=>{var g;if(r!==((g=this.cacheSegData)==null?void 0:g.id)){const S=this.scene.getObjectByName(r);S&&S.removeFromParent()}});const h=u==null?void 0:u.filter(d=>{var r;return!this.hiddenAttributes.some(g=>g===d.attribute)&&d.id!==((r=this.cacheSegData)==null?void 0:r.id)});(h==null?void 0:h.length)!==0&&h.map(d=>(this.emit("addNewPointsCloud",d),d)),this.emit("reRender3d")},this.updateCoverPoints=(u=new Float32Array([]))=>{this.segmentData.forEach((h,d)=>{var r;if(d!==((r=this.cacheSegData)==null?void 0:r.id)){const g=D.splitPointsFromPoints(h.points,u);h.points=g;const S=this.scene.getObjectByName(d);S&&(S.geometry.setAttribute("position",new P.Float32BufferAttribute(g,3)),S.geometry.attributes.position.needsUpdate=!0)}}),this.syncSegmentData(),this.emit("reRender3d")},this.container=t,this.scene=e,this.camera=i,this.renderer=a,this.emit=o,this.on=c,this.unbind=s,this.createCanvas2d(),this.clearStash=this.clearStash.bind(this),this.addStash2Store=this.addStash2Store.bind(this),this.updateCheck2Edit=this.updateCheck2Edit.bind(this),this.setAttribute=this.setAttribute.bind(this),this.setSegmentMode=this.setSegmentMode.bind(this),this.setSegmentCoverMode=this.setSegmentCoverMode.bind(this),this.setSegmentFocusMode=this.setSegmentFocusMode.bind(this),this.switchSegmentHideMode=this.switchSegmentHideMode.bind(this),this.highlightPointsByAttribute=this.highlightPointsByAttribute.bind(this),this.setHiddenAttributes=this.setHiddenAttributes.bind(this),this.clearAllSegmentData=this.clearAllSegmentData.bind(this),this.clearSelectedSegmentData=this.clearSelectedSegmentData.bind(this),this.initMsg(),this.setupRaycaster()}initMsg(){this.on("clearStash",this.clearStash),this.on("addStash2Store",this.addStash2Store),this.on("updateCheck2Edit",this.updateCheck2Edit),this.on("setSegmentMode",this.setSegmentMode),this.on("setSegmentCoverMode",this.setSegmentCoverMode),this.on("setSegmentFocusMode",this.setSegmentFocusMode),this.on("switchHideSegment",this.switchSegmentHideMode),this.on("clearAllSegmentData",this.clearAllSegmentData),this.on("clearSelectedSegmentData",this.clearSelectedSegmentData)}unbindMsg(){this.unbind("clearStash",this.clearStash),this.unbind("addStash2Store",this.addStash2Store),this.unbind("updateCheck2Edit",this.updateCheck2Edit),this.unbind("setSegmentMode",this.setSegmentMode),this.unbind("setSegmentCoverMode",this.setSegmentCoverMode),this.unbind("setSegmentFocusMode",this.setSegmentFocusMode),this.unbind("switchHideSegment",this.switchSegmentHideMode),this.unbind("clearAllSegmentData",this.clearAllSegmentData),this.unbind("clearSelectedSegmentData",this.clearSelectedSegmentData)}get containerWidth(){return this.container.clientWidth}get containerHeight(){return this.container.clientHeight}get allSegmentPoints(){return this.scene.children.filter(t=>t.type==="Points"&&t.name!==this.pointCloudObjectName)}get selectedSegmentPoints(){var t,e;return this.scene.getObjectByName((e=(t=this.cacheSegData)==null?void 0:t.id)!=null?e:"")}get segmentStatus(){return m.segmentStatus}get isReadyStatus(){return m.isReadyStatus}get isCheckStatus(){return m.isCheckStatus}get isEditStatus(){return m.isEditStatus}get formatData(){const t=this.segmentData.values(),e=[];for(const i of t)e.push({attribute:i.attribute,id:i.id,indexes:i.indexes});return e}get pointCloudArray(){return this.scene.getObjectByName(this.pointCloudObjectName)}clearAllSegmentData(){this.segmentData=new Map,this.syncSegmentData()}updateCurrentSegment(t){this.updatePointCloudBySegment([]),this.segmentData=new Map;const{pointCloudArray:e}=this;if(!e)return;const i=e.geometry.attributes.position.array;t.forEach(a=>{const o=[];a.indexes.forEach(s=>{o.push(i[s*3],i[s*3+1],i[s*3+2])});const c=b(y({},a),{points:new Float32Array(o)});this.segmentData.set(a.id,c),this.emit("addNewPointsCloud",b(y({},a),{points:new Float32Array(o)}))}),this.syncSegmentData()}statusToggle(){m.statusToggle()}updateStatus2Edit(){m.updateStatus2Edit()}createCanvas(t){const e=document.createElement("canvas");return e.id=t,this.updateCanvasBasicStyle(e,{width:this.containerWidth,height:this.containerHeight},10),e}createCanvas2d(){this.canvas2d=this.createCanvas(`${k}2d`),this.container.appendChild(this.canvas2d)}setupRaycaster(){this.raycaster.params={Mesh:{},Line:{threshold:1},LOD:{},Points:{threshold:.2},Sprite:{}}}setHoverPointsID(t){this.hoverPointsID=t}setSegmentMode(t){this.segmentMode=t}setSegmentCoverMode(t){this.segmentCoverMode=t}setSegmentFocusMode(t){this.segmentFocusMode=t,t===f.Focus&&this.emit("clearPointCloud"),t===f.Unfocus&&this.emit("loadPCDFile"),this.emit("reRender3d"),this.updatePointCloudBySegment(t===f.Focus?[]:[...this.segmentData.values()])}switchSegmentHideMode(t){this.hideSegment=t,this.updatePointCloudBySegment(t===!0?[]:[...this.segmentData.values()])}setHiddenAttributes(t){this.hiddenAttributes=t,this.updatePointCloudBySegment([...this.segmentData.values()])}updateCanvasBasicStyle(t,e,i){const a=1;t.style.position="absolute",t.width=e.width*a,t.height=e.height*a,t.style.width=`${e.width}px`,t.style.height=`${e.height}px`,t.style.left="0",t.style.top="0",t.style.zIndex=`${i} `}syncPolygon2d(t){this.polygon2d=t}getPointsInPolygon(t){var e,i,a;if(!this.isReadyStatus&&!this.isEditStatus)return;const o=t,c=this.scene.getObjectByName(this.pointCloudObjectName),s=(a=(i=(e=c==null?void 0:c.geometry)==null?void 0:e.attributes)==null?void 0:i.position)==null?void 0:a.array;if(s){const u=s.length,h=[],d=[],r=[];for(let n=0;n<u;n+=3){const C=new P.Vector3(s[n],s[n+1],s[n+2]);C.project(this.camera);const A={x:0,y:0};if(A.x=Math.round(C.x*this.container.clientWidth/2+this.container.clientWidth/2),A.y=Math.round(-C.y*this.container.clientHeight/2+this.container.clientHeight/2),B(A,o)){const F=s[n],_=s[n+1],O=s[n+2],v=D.getCloudKeys(F,_,O);this.segmentMode===p.Remove&&(this.cloudData.get(v).visible=!1,h.push(s[n],s[n+1],s[n+2]),r.push(n/3)),this.segmentMode===p.Add&&(this.segmentCoverMode===M.Cover&&(h.push(s[n],s[n+1],s[n+2]),r.push(n/3),this.cloudData.get(v).visible===!0&&d.push(s[n],s[n+1],s[n+2])),this.segmentCoverMode===M.Uncover&&this.cloudData.get(v).visible===!1&&(h.push(s[n],s[n+1],s[n+2]),r.push(n/3)),this.cloudData.get(v).visible===!1&&(this.cloudData.get(v).visible=!0))}}if(r.length===0||!this.cacheSegData&&this.segmentMode===p.Remove)return;const g=new Float32Array(h),S=new Float32Array(d);this.updateStatusBySelector(g,S,r)}}updateStatusBySelector(t,e,i){switch(this.segmentMode){case p.Add:if(this.cacheSegData){const{points:a,coverPoints:o=new Float32Array([])}=this.cacheSegData,c=a.length+t.length,s=new Float32Array(c);s.set(a,0),s.set(t,a.length);const u=o.length+e.length,h=new Float32Array(u);h.set(o,0),h.set(e,o.length),this.cacheSegData=b(y({},this.cacheSegData),{points:s,coverPoints:h,indexes:this.cacheSegData.indexes.concat(i)}),this.emit("updateNewPoints",this.cacheSegData)}else this.cacheSegData={id:j(),attribute:this.currentAttribute,points:t,coverPoints:e,indexes:i},this.emit("addNewPointsCloud",this.cacheSegData);break;case p.Remove:if(this.cacheSegData){const{points:a,indexes:o}=this.cacheSegData;this.cacheSegData=b(y({},this.cacheSegData),{points:D.splitPointsFromPoints(a,t),indexes:D.splitPointsFromIndexes(o,i)}),this.emit("updateNewPoints",this.cacheSegData)}break}this.updateStatus2Edit(),this.emit("syncPointCloudStatus",{segmentStatus:this.segmentStatus,cacheSegData:this.cacheSegData})}syncPointCloudStatus(){this.statusToggle();const{segmentStatus:t,cacheSegData:e}=this;this.emit("syncPointCloudStatus",{segmentStatus:t,cacheSegData:e})}syncSegmentData(){this.emit("syncSegmentData",this.formatData)}addStash2Store(){this.isEditStatus&&this.cacheSegData&&(this.cacheSegData.coverPoints&&this.cacheSegData.coverPoints.length!==0&&this.updateCoverPoints(this.cacheSegData.coverPoints),delete this.cacheSegData.coverPoints,this.segmentData.set(this.cacheSegData.id,this.cacheSegData),this.cacheSegData=void 0,this.syncPointCloudStatus(),this.syncSegmentData())}updateCloudDataStatus(t,e){for(let i=0;i<t.length;i+=3){const a=t[i],o=t[i+1],c=t[i+2],s=D.getCloudKeys(a,o,c),u=this.cloudData.get(s);Object.keys(e).forEach(h=>{u[h]=e[h]})}}clearStash(){if(this.isEditStatus&&this.cacheSegData){if(this.updateCloudDataStatus(this.cacheSegData.points,{visible:!1}),this.segmentData.has(this.cacheSegData.id)){const t=this.segmentData.get(this.cacheSegData.id);t&&(this.emit("updateNewPoints",t),this.updateCloudDataStatus(t==null?void 0:t.points,{visible:!0}))}else this.emit("clearStashRender");this.syncSegmentData(),this.cacheSegData=void 0,this.syncPointCloudStatus()}}clearSelectedSegmentData(t=""){if((this.isCheckStatus||this.isEditStatus)&&this.cacheSegData){const e=this.scene.getObjectByName(t),{indexes:i}=this.cacheSegData;if(e&&i){const a=e.geometry.attributes.position.array;for(let o=0;o<i.length;o++){const c=this.cloudData.get(D.getCloudKeys(a[o],a[o+1],a[o+2]));c&&(c.visible=!1)}this.cacheSegData=void 0,m.updateStatus2Ready(),this.emit("syncPointCloudStatus",{segmentStatus:this.segmentStatus,cacheSegData:this.cacheSegData})}}}updateCheck2Edit(){this.isCheckStatus&&this.syncPointCloudStatus()}checkPoints(){const t=this.segmentData.get(this.hoverPointsID);t&&(this.cacheSegData=b(y({},t),{points:new Float32Array(t.points)}),m.updateStatus2Check(),this.emit("syncPointCloudStatus",{segmentStatus:this.segmentStatus,cacheSegData:this.cacheSegData}))}editPoints(){const t=this.segmentData.get(this.hoverPointsID);t&&(this.cacheSegData=b(y({},t),{points:new Float32Array(t.points)}),this.emit("updateNewPoints"),this.syncPointCloudStatus())}setForbidOperation(t){this.forbidOperation=t}updateMouse(t){const e=t.x/this.containerWidth*2-1,i=-(t.y/this.containerHeight)*2+1;this.mouse.setX(e),this.mouse.setY(i)}resetAllSegDataSize(){this.highlightAttribute===""&&this.allSegmentPoints.forEach(t=>{var e;((e=this.cacheSegData)==null?void 0:e.id)!==t.name&&(t.material.size=5)})}resetHoverPointsID(){this.hoverPointsID=""}resetAllSegDataSizeAndRender(){this.resetAllSegDataSize(),this.emit("reRender3d")}highlightPoints(t){!(this.isCheckStatus||this.isReadyStatus)||(this.resetAllSegDataSize(),t.material.size=10,this.hoverPointsID=t.name,this.emit("reRender3d"))}highlightPointsByAttribute(t){this.highlightAttribute=t,this.segmentData.size!==0&&(this.resetAllSegDataSize(),this.segmentData.forEach((e,i)=>{if(e.attribute===t){const a=this.scene.getObjectByName(i);a&&(a==null?void 0:a.material)&&(a.material.size=10)}}),this.emit("reRender3d"))}setAttribute(t){this.currentAttribute=t}}export{z as default};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@labelbee/lb-annotation",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.16.0-alpha.1",
|
|
4
4
|
"description": "Annotation tool collection",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"annotation",
|
|
@@ -94,7 +94,7 @@
|
|
|
94
94
|
"typescript": "^4.2.3"
|
|
95
95
|
},
|
|
96
96
|
"dependencies": {
|
|
97
|
-
"@labelbee/lb-utils": "1.
|
|
97
|
+
"@labelbee/lb-utils": "1.8.0-alpha.2",
|
|
98
98
|
"@turf/turf": "5.1.6",
|
|
99
99
|
"color-rgba": "^2.3.0",
|
|
100
100
|
"lodash": "^4.17.20",
|