@labelbee/lb-annotation 1.13.0-alpha.5 → 1.13.0-alpha.6
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 +1 -1
- package/dist/types/constant/tool.d.ts +1 -1
- package/dist/types/core/pointCloud/index.d.ts +2 -1
- package/dist/types/core/scheduler.d.ts +1 -1
- package/dist/types/core/toolOperation/ViewOperation.d.ts +1 -1
- package/dist/types/core/toolOperation/segmentByRect.d.ts +1 -1
- package/dist/types/utils/tool/CommonToolUtils.d.ts +1 -1
- package/es/core/pointCloud/index.js +2 -2
- package/package.json +2 -2
- package/es/_virtual/_rollup-plugin-web-worker-loader__helper__auto__createBase64WorkerFactory.js +0 -12
- package/es/_virtual/_rollup-plugin-web-worker-loader__helper__auto__isNodeJS.js +0 -7
- package/es/_virtual/_rollup-plugin-web-worker-loader__helper__node__WorkerClass.js +0 -11
- package/es/_virtual/_rollup-plugin-web-worker-loader__helper__node__createBase64WorkerFactory.js +0 -18
- package/es/core/toolOperation/MultipleSelect.js +0 -73
- package/es/core/toolOperation/Selection.js +0 -98
|
@@ -8,4 +8,4 @@
|
|
|
8
8
|
varying float vVisible;
|
|
9
9
|
${i.fragmentShader}`.replace("#include <clipping_planes_fragment>",`
|
|
10
10
|
if (vVisible < 0.5) discard;
|
|
11
|
-
#include <clipping_planes_fragment>`)},this.loadPCDFile=(i,o)=>__async(this,null,function*(){this.clearPointCloud(),this.currentPCDSrc=i;const{points:c,color:h}=yield this.cacheInstance.loadPCDFile(i),l=new THREE__namespace.BufferGeometry;l.setAttribute("position",new THREE__namespace.BufferAttribute(c,3)),l.setAttribute("color",new THREE__namespace.BufferAttribute(h,3));const u=new THREE__namespace.Points(l);this.renderPointCloud(u,o)}),this.loadPCDFileByBox=(i,o,c)=>__async(this,null,function*(){const h=(m,x)=>__async(this,null,function*(){const{width:y=0,height:p=0,depth:w=0}=c!=null?c:{},g=yield this.filterPointsByBox(__spreadProps(__spreadValues({},o),{width:o.width+y,height:o.height+p,depth:o.depth+w}),m,x);if(!g){console.error("filter Error");return}this.clearPointCloud(),this.currentPCDSrc=i;const f=new THREE__namespace.Points(g.geometry);f.name=this.pointCloudObjectName,this.scene.add(f),this.render()}),{points:l,color:u}=yield this.cacheInstance.loadPCDFile(i);h(l,u)}),this.generateRange=i=>{const o=this.createRange(i);this.scene.add(o)},this.generateBoxArrow=({width:i})=>{const o=new THREE__namespace.Vector3(1,0,0),c=new THREE__namespace.Vector3(i/2,0,0),h=2,l=16776960,u=new THREE__namespace.ArrowHelper(o,c,h,l);return u.visible=this.showDirection,u},this.generateBoxTrackID=i=>{if(!i.trackID)return;const o=new THREE__namespace.Texture(this.getTextCanvas(i.trackID.toString()));o.needsUpdate=!0;const c=new THREE__namespace.SpriteMaterial({map:o,depthWrite:!1}),h=new THREE__namespace.Sprite(c);return h.scale.set(5,5,5),h.position.set(-i.width/2,0,i.depth/2+.5),h},this.applyZAxisPoints=i=>{this.zAxisLimit=i,this.filterZAxisPoints(),this.render()},this.updatePointSize=i=>{const o=this.scene.getObjectByName(this.pointCloudObjectName);if(!o)return;const c=o.material.size;i?o.material.size=Math.min(c*1.2,10):o.material.size=Math.max(c/1.2,1),this.render()},this.container=t,this.renderer=new THREE__namespace.WebGLRenderer({antialias:!0}),this.backgroundColor=s,this.config=a,r&&n?(this.isOrthographicCamera=!0,this.camera=new THREE__namespace.OrthographicCamera(n.left,n.right,n.top,n.bottom,n.near,n.far)):this.camera=new THREE__namespace.PerspectiveCamera(30,this.containerWidth/this.containerHeight,1,1e3),this.initCamera(),this.scene=new THREE__namespace.Scene,this.controls=new OrbitControls.OrbitControls(this.camera,this.renderer.domElement),this.pcdLoader=new PCDLoader.PCDLoader,this.axesHelper=new THREE__namespace.AxesHelper(1e3),this.scene.add(this.camera),e||t.appendChild(this.renderer.domElement),this.init(),this.cacheInstance=cache.PointCloudCache.getInstance()}get DEFAULT_INIT_CAMERA_POSITION(){return new THREE__namespace.Vector3(-.01,0,10)}get containerWidth(){return this.container.clientWidth}get containerHeight(){return this.container.clientHeight}setInitCameraPosition(t){this.initCameraPosition=t}setConfig(t){this.config=t}initOrthographicCamera(t){if(this.camera.type!=="OrthographicCamera")return;const{left:e,right:r,top:n,bottom:s,near:a,far:i}=t;this.camera.left=e,this.camera.right=r,this.camera.top=n,this.camera.bottom=s,this.camera.near=a,this.camera.far=i,this.camera.updateProjectionMatrix()}initPerspectiveCamera(){this.camera.type==="PerspectiveCamera"&&(this.camera.fov=30,this.camera.aspect=this.containerWidth/this.containerHeight,this.camera.near=1,this.camera.far=1e3,this.camera.updateProjectionMatrix())}initCamera(){const{camera:t}=this;if(this.isOrthographicCamera){const{x:e,y:r,z:n}=this.initCameraPosition;t.position.set(e,r,n)}else t.position.set(-1,0,500);t.up.set(0,0,1)}initControls(){const{controls:t}=this;t.addEventListener("change",()=>{this.render()}),this.setDefaultControls()}setDefaultControls(){const{controls:t}=this,e=[0,0,0];t.target=new THREE__namespace.Vector3(...e),t.addEventListener("change",()=>{this.render()}),t.maxPolarAngle=Math.PI/2,t.update()}initRenderer(){const{renderer:t}=this;t.setPixelRatio(window.devicePixelRatio),t.setSize(this.containerWidth,this.containerHeight)}init(){const{scene:t}=this;t.background=new THREE__namespace.Color(this.backgroundColor),this.initControls(),this.initRenderer()}removeObjectByName(t){const e=this.scene.getObjectByName(t);e&&e.removeFromParent()}generateBox(t,e=16777215){const r=e;this.AddBoxToSense(t,r),this.render()}getAllAttributeColor(t){return t.reduce((e,r)=>(e[r.attribute]=lbUtils.toolStyleConverter.getColorFromConfig({attribute:r.attribute},__spreadProps(__spreadValues({},this.config),{attributeConfigurable:!0}),{}),e),{})}generateBoxes(t){t.forEach(e=>{this.generateBox(e)}),this.render()}getOrthographicCamera(t){const{center:e,width:r,height:n}=t,s=10,a=e.x-r/2-s,i=e.x-r/2+s,o=e.y+n/2+s,c=e.y-n/2-s,h=100,l=-100,u=500/h;return{left:a,right:i,top:o,bottom:c,near:h,far:l,zoom:u}}updateCameraZoom(t){this.camera.zoom=t,this.camera.updateProjectionMatrix()}updateCameraByBox(t,e){const{center:r,width:n,height:s,depth:a,rotation:i}=t,o=this.getCameraVector(r,i,{width:n,height:s,depth:a},e);return this.updateCamera(o,r),o}updateOrthoCamera(t,e){const r=this.updateCameraByBox(t,e);return this.camera.zoom=1,this.camera.updateProjectionMatrix(),{cameraPositionVector:r}}updateTopCamera(){this.setInitCameraPosition(this.DEFAULT_INIT_CAMERA_POSITION),this.camera.zoom=1,this.initCamera(),this.setDefaultControls(),this.camera.updateProjectionMatrix(),this.render()}updateCamera(t,e){this.camera.position.set(t.x,t.y,t.z),this.controls.target=new THREE__namespace.Vector3(e.x,e.y,e.z),this.controls.update()}resetCamera(){this.updateCamera(this.DEFAULT_INIT_CAMERA_POSITION,{x:0,y:0,z:0})}getOrthographicCameraTarget(t){const e=new THREE__namespace.Vector3(0,0,-1).applyQuaternion(t.quaternion);return t.position.clone().add(e)}createThreeMatrix4(t){return new THREE__namespace.Matrix4().set(...t)}filterPointsByBox(t,e,r){var n,s,a;if(!e){const i=this.scene.getObjectByName(this.pointCloudObjectName);if(!i)return console.error("There is no corresponding point cloud object"),Promise.resolve(void 0);e=(a=(s=(n=i==null?void 0:i.geometry)==null?void 0:n.attributes)==null?void 0:s.position)==null?void 0:a.array}if(window.Worker){const{zMin:i,zMax:o,polygonPointList:c}=matrix.getCuboidFromPointCloudBox(t),h=e;r=r!=null?r:new Float32Array([]);const l={boxParams:t,zMin:i,zMax:o,polygonPointList:c,color:r,position:h};return new Promise(u=>{const m=new filterBoxWorker;m.postMessage(l),m.onmessage=x=>{const{color:y,position:p,num:w}=x.data,g=new THREE__namespace.BufferGeometry;g.setAttribute("position",new THREE__namespace.Float32BufferAttribute(p,3)),g.setAttribute("color",new THREE__namespace.Float32BufferAttribute(y,3)),g.computeBoundingSphere(),m.terminate(),u({geometry:g,num:w})}})}return Promise.resolve(void 0)}getCameraVector(t,e,r,n=lbUtils.EPerspectiveView.Front,s=DEFAULT_DISTANCE){let a=lbUtils.PerspectiveShiftUtils.frontViewMatrix4(s);switch(n){case lbUtils.EPerspectiveView.Front:break;case lbUtils.EPerspectiveView.Back:a=lbUtils.PerspectiveShiftUtils.backViewMatrix4(s);break;case lbUtils.EPerspectiveView.Left:a=lbUtils.PerspectiveShiftUtils.leftViewMatrix4(s);break;case lbUtils.EPerspectiveView.Right:a=lbUtils.PerspectiveShiftUtils.rightViewMatrix4(s);break;case lbUtils.EPerspectiveView.Top:a=lbUtils.PerspectiveShiftUtils.topViewMatrix4(s);break;case lbUtils.EPerspectiveView.LFT:a=lbUtils.PerspectiveShiftUtils.leftFrontTopViewMatrix4(s,r);break;case lbUtils.EPerspectiveView.RBT:a=lbUtils.PerspectiveShiftUtils.rightBackTopViewMatrix4(s,r);break}const i=this.createThreeMatrix4(a),o=new THREE__namespace.Matrix4().makeTranslation(-t.x,-t.y,-t.z),c=new THREE__namespace.Matrix4().makeTranslation(t.x,t.y,t.z),h=new THREE__namespace.Matrix4().makeRotationZ(e);return new THREE__namespace.Vector3(t.x,t.y,t.z).clone().applyMatrix4(i).applyMatrix4(o).applyMatrix4(h).applyMatrix4(c)}createRange(t){this.removeObjectByName(this.rangeObjectName);const r=new THREE__namespace.EllipseCurve(0,0,t,t,0,2*Math.PI,!1,0).getPoints(50),n=new THREE__namespace.BufferGeometry().setFromPoints(r),s=new THREE__namespace.LineBasicMaterial({color:16711680}),a=new THREE__namespace.Line(n,s);return a.name=this.rangeObjectName,a}renderPointCloud(t,e){t.name=this.pointCloudObjectName;const r=new THREE__namespace.PointsMaterial({vertexColors:!0});r.onBeforeCompile=this.overridePointShader,r.size=1.2,e&&this.generateRange(e),this.pointsUuid=t.uuid,t.material=r,this.filterZAxisPoints(t),this.scene.add(t),this.render()}clearPointCloud(){this.removeObjectByName(this.pointCloudObjectName)}clearPointCloudAndRender(){this.clearPointCloud(),this.render()}highlightOriginPointCloud(t){const e=this.scene.getObjectByName(this.pointCloudObjectName);if(!!e)return this.highlightPCDSrc=this.currentPCDSrc,new Promise(r=>{if(window.Worker){const s=(t?[...t]:[]).map(o=>matrix.getCuboidFromPointCloudBox(o)),a=this.getAllAttributeColor(s),i={cuboidList:s,position:e.geometry.attributes.position.array,color:e.geometry.attributes.color.array,colorList:a};highlightWorker.postMessage(i),highlightWorker.onmessage=o=>{const{color:c}=o.data,h=new THREE__namespace.BufferAttribute(c,3);this.highlightPCDSrc&&(this.cacheInstance.updateColor(this.highlightPCDSrc,c),this.highlightPCDSrc=void 0),h.needsUpdate=!0,e.geometry.setAttribute("color",h),r(c),this.render()}}})}updateColor(t){const e=this.scene.getObjectByName(this.pointCloudObjectName);if(e){const r=new THREE__namespace.BufferAttribute(t,3);r.needsUpdate=!0,e.geometry.setAttribute("color",r),this.render()}}setShowDirection(t){this.showDirection=t,this.scene.children.forEach(e=>{e.type==="Group"&&e.children.forEach(r=>{r.type==="ArrowHelper"&&(r.visible=t)})}),this.render()}getTextCanvas(t){const e=document.createElement("canvas"),r=e.getContext("2d");return r&&(r.font=`${50}px " bold`,r.fillStyle="white",r.textAlign="center",r.textBaseline="middle",r.fillText(t,e.width/2,e.height/2)),e}getSensesPointZAxisInPolygon(t,e){const r=this.scene.children.find(o=>o.uuid===this.pointsUuid);let n=0,s=0,a=0,i=0;if(r&&(r==null?void 0:r.geometry)){const o=r==null?void 0:r.geometry.attributes.position.array;for(let c=0;c<o.length;c+=3){const h=o[c],l=o[c+1],u=o[c+2];polygonTool.isInPolygon({x:h,y:l},t)&&u&&(s=Math.max(u,s),n=Math.min(u,n),i++,e&&u>=e[0]&&u<=e[1]&&a++)}}return{maxZ:s,minZ:n,count:a,zCount:i}}getBasicCoordinate2Canvas(t){const e=this.containerWidth/2,r=this.containerHeight/2;return{x:t.x*e+e,y:t.y*r+r,z:t.z}}get basicCoordinate2CanvasMatrix4(){const t=this.containerWidth/2,e=this.containerHeight/2;return new THREE__namespace.Matrix4().set(t,0,0,t,0,e,0,e,0,0,1,0,0,0,0,1)}getCanvas2BasicCoordinate(t){const e=this.containerWidth/2,r=this.containerHeight/2;return new THREE__namespace.Vector3(t.x/e-e/2,-(t.y/r-r/2),1)}getPolygonSidePoints(t){const{center:{x:e,y:r,z:n},height:s,width:a,depth:i}=t,o={x:e+a/2,y:r+s/2,z:n-i/2},c={x:e+a/2,y:r+s/2,z:n+i/2},h={x:e-a/2,y:r+s/2,z:n+i/2},l={x:e-a/2,y:r+s/2,z:n-i/2};return[o,c,h,l]}getPolygonBackPoints(t){const{center:{x:e,y:r,z:n},height:s,width:a,depth:i}=t,o={x:e-a/2,y:r+s/2,z:n+i/2},c={x:e-a/2,y:r+s/2,z:n-i/2},h={x:e-a/2,y:r-s/2,z:n-i/2},l={x:e-a/2,y:r-s/2,z:n+i/2};return[o,c,h,l]}getPolygonTopPoints(t){const{center:{x:e,y:r,z:n},height:s,width:a,depth:i}=t,o={x:e+a/2,y:r+s/2,z:n+i/2},c={x:e+a/2,y:r-s/2,z:n+i/2},h={x:e-a/2,y:r-s/2,z:n+i/2},l={x:e-a/2,y:r+s/2,z:n+i/2};return[o,c,h,l]}getModelTransformationMatrix(t){const{center:{x:e,y:r,z:n},rotation:s}=t,a=new THREE__namespace.Matrix4().makeTranslation(-e,-r,-n),i=new THREE__namespace.Matrix4().makeTranslation(e,r,n),o=new THREE__namespace.Matrix4().makeRotationZ(s);return new THREE__namespace.Matrix4().multiply(i).multiply(o).multiply(a)}getBoxSidePolygon2DCoordinate(t){return this.getBoxPolygon2DCoordinate(t,lbUtils.EPerspectiveView.Left)}getBoxBackPolygon2DCoordinate(t){return this.getBoxPolygon2DCoordinate(t,lbUtils.EPerspectiveView.Back)}boxParams2ViewPolygon(t,e){switch(e){case lbUtils.EPerspectiveView.Left:return this.getPolygonSidePoints(t);case lbUtils.EPerspectiveView.Back:return this.getPolygonBackPoints(t);default:return this.getPolygonTopPoints(t)}}getBoxPolygon2DCoordinate(t,e){const r=this.boxParams2ViewPolygon(t,e),{width:n,height:s}=t,a=new THREE__namespace.Matrix4().premultiply(this.camera.matrixWorldInverse).premultiply(this.camera.projectionMatrix),i=new THREE__namespace.Matrix4().premultiply(this.getModelTransformationMatrix(t)).premultiply(a).premultiply(this.basicCoordinate2CanvasMatrix4);this.sideMatrix=i;const o=r.map(l=>new THREE__namespace.Vector3(l.x,l.y,l.z)).map(l=>l.applyMatrix4(this.sideMatrix)),c=this.containerWidth/n,h=this.containerHeight/s;return{polygon2d:o,zoom:Math.min(c,h)/2}}getBoxTopPolygon2DCoordinate(t){const{width:e,height:r}=t,s=this.getPolygonTopPoints(t).map(o=>new THREE__namespace.Vector3(o.x,o.y,o.z)).map(o=>o.applyMatrix4(this.getModelTransformationMatrix(t))).map(o=>({x:o.y,y:o.x})).map(o=>({x:-(o.x-this.containerWidth/2),y:-(o.y-this.containerHeight/2)})),a=this.containerWidth/e,i=this.containerHeight/r;return{polygon2d:s,zoom:Math.min(a,i)/2}}getNewBoxBySideUpdate(t,e,r,n){const s=new THREE__namespace.Matrix4().makeRotationZ(n.rotation),a=new THREE__namespace.Vector3(-t.x,0,0).applyMatrix4(s);let i=n;return i.center={x:i.center.x+a.x,y:i.center.y+a.y,z:i.center.z-t.z},i=__spreadProps(__spreadValues({},i),{width:i.width+e,height:i.height,depth:i.depth+r}),{newBoxParams:i}}getNewBoxByBackUpdate(t,e,r,n){const s=new THREE__namespace.Matrix4().makeRotationZ(n.rotation),a=new THREE__namespace.Vector3(0,-t.x,0).applyMatrix4(s);let i=n;return i.center={x:i.center.x+a.x,y:i.center.y+a.y,z:i.center.z-t.z},i=__spreadProps(__spreadValues({},i),{width:i.width,height:i.height+e,depth:i.depth+r}),{newBoxParams:i}}getNewBoxBySideUpdateByPoints(t,e,r,n){var s;const a=(s=this.sideMatrix)==null?void 0:s.invert();if(!this.sideMatrix||!a){console.error("No sideMatrix");return}this.camera.zoom=1,this.camera.updateProjectionMatrix();const i=t.map(p=>new THREE__namespace.Vector3(p.x,p.y,p.z)).map(p=>p.applyMatrix4(a)),[o,c,h,l]=i,u=Math.max(Math.abs(o.x-h.x),Math.abs(o.x-c.x)),x=c.add(l).applyMatrix3(new THREE__namespace.Matrix3().set(1/2,0,0,0,1/2,0,0,0,1/2)).clone().applyMatrix3(new THREE__namespace.Matrix3().set(-1,0,0,0,-1,0,0,0,-1)).add(new THREE__namespace.Vector3(n.center.x,n.center.y,n.center.z));return{newBoxParams:__spreadProps(__spreadValues({},n),{center:{x:n.center.x-x.x,y:n.center.y-x.y,z:n.center.z-r},width:u,height:n.height,depth:n.depth+e,rotation:n.rotation})}}filterZAxisPoints(t){const e=t||this.scene.children.find(r=>r.uuid===this.pointsUuid);if(e){const{attributes:r}=e.geometry,{position:n}=r,s=[],{count:a}=n;for(let i=0;i<a;i++){const o=n.getZ(i);s.push(o>this.zAxisLimit?0:1)}e.geometry.setAttribute("visibility",new THREE__namespace.Float32BufferAttribute(s,1)),e.geometry.attributes.visibility.needsUpdate=!0}}render(){this.renderer.render(this.scene,this.camera)}}exports.createThreeMatrix4=matrix.createThreeMatrix4,exports.getCuboidFromPointCloudBox=matrix.getCuboidFromPointCloudBox,exports.lidar2image=matrix.lidar2image,exports.pointCloudLidar2image=matrix.pointCloudLidar2image,exports.rotatePoint=matrix.rotatePoint,exports.transferKitti2Matrix=matrix.transferKitti2Matrix,exports.PointCloud=PointCloud;
|
|
11
|
+
#include <clipping_planes_fragment>`)},this.loadPCDFile=(i,o)=>__async(this,null,function*(){this.clearPointCloud(),this.currentPCDSrc=i;const{points:c,color:h}=yield this.cacheInstance.loadPCDFile(i),l=new THREE__namespace.BufferGeometry;l.setAttribute("position",new THREE__namespace.BufferAttribute(c,3)),l.setAttribute("color",new THREE__namespace.BufferAttribute(h,3));const u=new THREE__namespace.Points(l);this.renderPointCloud(u,o)}),this.loadPCDFileByBox=(i,o,c)=>__async(this,null,function*(){const h=(m,x)=>__async(this,null,function*(){const{width:y=0,height:p=0,depth:w=0}=c!=null?c:{},g=yield this.filterPointsByBox(__spreadProps(__spreadValues({},o),{width:o.width+y,height:o.height+p,depth:o.depth+w}),m,x);if(!g){console.error("filter Error");return}this.clearPointCloud(),this.currentPCDSrc=i;const f=new THREE__namespace.Points(g.geometry);f.name=this.pointCloudObjectName,this.scene.add(f),this.render()}),{points:l,color:u}=yield this.cacheInstance.loadPCDFile(i);h(l,u)}),this.generateRange=i=>{const o=this.createRange(i);this.scene.add(o)},this.generateBoxArrow=({width:i})=>{const o=new THREE__namespace.Vector3(1,0,0),c=new THREE__namespace.Vector3(i/2,0,0),h=2,l=16776960,u=new THREE__namespace.ArrowHelper(o,c,h,l);return u.visible=this.showDirection,u},this.generateBoxTrackID=i=>{if(!i.trackID)return;const o=new THREE__namespace.Texture(this.getTextCanvas(i.trackID.toString()));o.needsUpdate=!0;const c=new THREE__namespace.SpriteMaterial({map:o,depthWrite:!1}),h=new THREE__namespace.Sprite(c);return h.scale.set(5,5,5),h.position.set(-i.width/2,0,i.depth/2+.5),h},this.applyZAxisPoints=i=>{this.zAxisLimit=i,this.filterZAxisPoints(),this.render()},this.updatePointSize=i=>{const o=this.scene.getObjectByName(this.pointCloudObjectName);if(!o)return;const c=o.material.size;i?o.material.size=Math.min(c*1.2,10):o.material.size=Math.max(c/1.2,1),this.render()},this.container=t,this.renderer=new THREE__namespace.WebGLRenderer({antialias:!0}),this.backgroundColor=s,this.config=a,r&&n?(this.isOrthographicCamera=!0,this.camera=new THREE__namespace.OrthographicCamera(n.left,n.right,n.top,n.bottom,n.near,n.far)):this.camera=new THREE__namespace.PerspectiveCamera(30,this.containerWidth/this.containerHeight,1,1e3),this.initCamera(),this.scene=new THREE__namespace.Scene,this.controls=new OrbitControls.OrbitControls(this.camera,this.renderer.domElement),this.pcdLoader=new PCDLoader.PCDLoader,this.axesHelper=new THREE__namespace.AxesHelper(1e3),this.scene.add(this.camera),e||t.appendChild(this.renderer.domElement),this.init(),this.cacheInstance=cache.PointCloudCache.getInstance()}get DEFAULT_INIT_CAMERA_POSITION(){return new THREE__namespace.Vector3(-.01,0,10)}get containerWidth(){return this.container.clientWidth}get containerHeight(){return this.container.clientHeight}setInitCameraPosition(t){this.initCameraPosition=t}setConfig(t){this.config=t}initOrthographicCamera(t){if(this.camera.type!=="OrthographicCamera")return;const{left:e,right:r,top:n,bottom:s,near:a,far:i}=t;this.camera.left=e,this.camera.right=r,this.camera.top=n,this.camera.bottom=s,this.camera.near=a,this.camera.far=i,this.camera.updateProjectionMatrix()}initPerspectiveCamera(){this.camera.type==="PerspectiveCamera"&&(this.camera.fov=30,this.camera.aspect=this.containerWidth/this.containerHeight,this.camera.near=1,this.camera.far=1e3,this.camera.updateProjectionMatrix())}initCamera(){const{camera:t}=this;if(this.isOrthographicCamera){const{x:e,y:r,z:n}=this.initCameraPosition;t.position.set(e,r,n)}else t.position.set(-1,0,500);t.up.set(0,0,1)}initControls(){const{controls:t}=this;t.addEventListener("change",()=>{this.render()}),this.setDefaultControls()}setDefaultControls(){const{controls:t}=this,e=[0,0,0];t.target=new THREE__namespace.Vector3(...e),t.addEventListener("change",()=>{this.render()}),t.maxPolarAngle=Math.PI/2,t.update()}initRenderer(){const{renderer:t}=this;t.setPixelRatio(window.devicePixelRatio),t.setSize(this.containerWidth,this.containerHeight)}init(){const{scene:t}=this;t.background=new THREE__namespace.Color(this.backgroundColor),this.initControls(),this.initRenderer()}removeObjectByName(t){const e=this.scene.getObjectByName(t);e&&e.removeFromParent()}generateBox(t,e=16777215){const r=e;this.AddBoxToSense(t,r),this.render()}getAllAttributeColor(t){return t.reduce((e,r)=>(e[r.attribute]=lbUtils.toolStyleConverter.getColorFromConfig({attribute:r.attribute},__spreadProps(__spreadValues({},this.config),{attributeConfigurable:!0}),{}),e),{})}generateBoxes(t){t.forEach(e=>{this.generateBox(e)}),this.render()}getOrthographicCamera(t){const{center:e,width:r,height:n}=t,s=10,a=e.x-r/2-s,i=e.x-r/2+s,o=e.y+n/2+s,c=e.y-n/2-s,h=100,l=-100,u=500/h;return{left:a,right:i,top:o,bottom:c,near:h,far:l,zoom:u}}updateCameraZoom(t){this.camera.zoom=t,this.camera.updateProjectionMatrix()}updateCameraByBox(t,e,r){const{center:n,width:s,height:a,depth:i,rotation:o}=t,c=this.getCameraVector(n,o,{width:s,height:a,depth:i},e);return r?(this.updateCamera(r,n),new THREE__namespace.Vector3(r.x,r.y,r.z)):(this.updateCamera(c,n),c)}updateOrthoCamera(t,e){const r=this.updateCameraByBox(t,e);return this.camera.zoom=1,this.camera.updateProjectionMatrix(),{cameraPositionVector:r}}updateTopCamera(){this.setInitCameraPosition(this.DEFAULT_INIT_CAMERA_POSITION),this.camera.zoom=1,this.initCamera(),this.setDefaultControls(),this.camera.updateProjectionMatrix(),this.render()}updateCamera(t,e){this.camera.position.set(t.x,t.y,t.z),this.controls.target=new THREE__namespace.Vector3(e.x,e.y,e.z),this.controls.update()}resetCamera(){this.updateCamera(this.DEFAULT_INIT_CAMERA_POSITION,{x:0,y:0,z:0})}getOrthographicCameraTarget(t){const e=new THREE__namespace.Vector3(0,0,-1).applyQuaternion(t.quaternion);return t.position.clone().add(e)}createThreeMatrix4(t){return new THREE__namespace.Matrix4().set(...t)}filterPointsByBox(t,e,r){var n,s,a;if(!e){const i=this.scene.getObjectByName(this.pointCloudObjectName);if(!i)return console.error("There is no corresponding point cloud object"),Promise.resolve(void 0);e=(a=(s=(n=i==null?void 0:i.geometry)==null?void 0:n.attributes)==null?void 0:s.position)==null?void 0:a.array}if(window.Worker){const{zMin:i,zMax:o,polygonPointList:c}=matrix.getCuboidFromPointCloudBox(t),h=e;r=r!=null?r:new Float32Array([]);const l={boxParams:t,zMin:i,zMax:o,polygonPointList:c,color:r,position:h};return new Promise(u=>{const m=new filterBoxWorker;m.postMessage(l),m.onmessage=x=>{const{color:y,position:p,num:w}=x.data,g=new THREE__namespace.BufferGeometry;g.setAttribute("position",new THREE__namespace.Float32BufferAttribute(p,3)),g.setAttribute("color",new THREE__namespace.Float32BufferAttribute(y,3)),g.computeBoundingSphere(),m.terminate(),u({geometry:g,num:w})}})}return Promise.resolve(void 0)}getCameraVector(t,e,r,n=lbUtils.EPerspectiveView.Front,s=DEFAULT_DISTANCE){let a=lbUtils.PerspectiveShiftUtils.frontViewMatrix4(s);switch(n){case lbUtils.EPerspectiveView.Front:break;case lbUtils.EPerspectiveView.Back:a=lbUtils.PerspectiveShiftUtils.backViewMatrix4(s);break;case lbUtils.EPerspectiveView.Left:a=lbUtils.PerspectiveShiftUtils.leftViewMatrix4(s);break;case lbUtils.EPerspectiveView.Right:a=lbUtils.PerspectiveShiftUtils.rightViewMatrix4(s);break;case lbUtils.EPerspectiveView.Top:a=lbUtils.PerspectiveShiftUtils.topViewMatrix4(s);break;case lbUtils.EPerspectiveView.LFT:a=lbUtils.PerspectiveShiftUtils.leftFrontTopViewMatrix4(s,r);break;case lbUtils.EPerspectiveView.RBT:a=lbUtils.PerspectiveShiftUtils.rightBackTopViewMatrix4(s,r);break}const i=this.createThreeMatrix4(a),o=new THREE__namespace.Matrix4().makeTranslation(-t.x,-t.y,-t.z),c=new THREE__namespace.Matrix4().makeTranslation(t.x,t.y,t.z),h=new THREE__namespace.Matrix4().makeRotationZ(e);return new THREE__namespace.Vector3(t.x,t.y,t.z).clone().applyMatrix4(i).applyMatrix4(o).applyMatrix4(h).applyMatrix4(c)}createRange(t){this.removeObjectByName(this.rangeObjectName);const r=new THREE__namespace.EllipseCurve(0,0,t,t,0,2*Math.PI,!1,0).getPoints(50),n=new THREE__namespace.BufferGeometry().setFromPoints(r),s=new THREE__namespace.LineBasicMaterial({color:16711680}),a=new THREE__namespace.Line(n,s);return a.name=this.rangeObjectName,a}renderPointCloud(t,e){t.name=this.pointCloudObjectName;const r=new THREE__namespace.PointsMaterial({vertexColors:!0});r.onBeforeCompile=this.overridePointShader,r.size=1.2,e&&this.generateRange(e),this.pointsUuid=t.uuid,t.material=r,this.filterZAxisPoints(t),this.scene.add(t),this.render()}clearPointCloud(){this.removeObjectByName(this.pointCloudObjectName)}clearPointCloudAndRender(){this.clearPointCloud(),this.render()}highlightOriginPointCloud(t){const e=this.scene.getObjectByName(this.pointCloudObjectName);if(!!e)return this.highlightPCDSrc=this.currentPCDSrc,new Promise(r=>{if(window.Worker){const s=(t?[...t]:[]).map(o=>matrix.getCuboidFromPointCloudBox(o)),a=this.getAllAttributeColor(s),i={cuboidList:s,position:e.geometry.attributes.position.array,color:e.geometry.attributes.color.array,colorList:a};highlightWorker.postMessage(i),highlightWorker.onmessage=o=>{const{color:c}=o.data,h=new THREE__namespace.BufferAttribute(c,3);this.highlightPCDSrc&&(this.cacheInstance.updateColor(this.highlightPCDSrc,c),this.highlightPCDSrc=void 0),h.needsUpdate=!0,e.geometry.setAttribute("color",h),r(c),this.render()}}})}updateColor(t){const e=this.scene.getObjectByName(this.pointCloudObjectName);if(e){const r=new THREE__namespace.BufferAttribute(t,3);r.needsUpdate=!0,e.geometry.setAttribute("color",r),this.render()}}setShowDirection(t){this.showDirection=t,this.scene.children.forEach(e=>{e.type==="Group"&&e.children.forEach(r=>{r.type==="ArrowHelper"&&(r.visible=t)})}),this.render()}getTextCanvas(t){const e=document.createElement("canvas"),r=e.getContext("2d");return r&&(r.font=`${50}px " bold`,r.fillStyle="white",r.textAlign="center",r.textBaseline="middle",r.fillText(t,e.width/2,e.height/2)),e}getSensesPointZAxisInPolygon(t,e){const r=this.scene.children.find(o=>o.uuid===this.pointsUuid);let n=0,s=0,a=0,i=0;if(r&&(r==null?void 0:r.geometry)){const o=r==null?void 0:r.geometry.attributes.position.array;for(let c=0;c<o.length;c+=3){const h=o[c],l=o[c+1],u=o[c+2];polygonTool.isInPolygon({x:h,y:l},t)&&u&&(s=Math.max(u,s),n=Math.min(u,n),i++,e&&u>=e[0]&&u<=e[1]&&a++)}}return{maxZ:s,minZ:n,count:a,zCount:i}}getBasicCoordinate2Canvas(t){const e=this.containerWidth/2,r=this.containerHeight/2;return{x:t.x*e+e,y:t.y*r+r,z:t.z}}get basicCoordinate2CanvasMatrix4(){const t=this.containerWidth/2,e=this.containerHeight/2;return new THREE__namespace.Matrix4().set(t,0,0,t,0,e,0,e,0,0,1,0,0,0,0,1)}getCanvas2BasicCoordinate(t){const e=this.containerWidth/2,r=this.containerHeight/2;return new THREE__namespace.Vector3(t.x/e-e/2,-(t.y/r-r/2),1)}getPolygonSidePoints(t){const{center:{x:e,y:r,z:n},height:s,width:a,depth:i}=t,o={x:e+a/2,y:r+s/2,z:n-i/2},c={x:e+a/2,y:r+s/2,z:n+i/2},h={x:e-a/2,y:r+s/2,z:n+i/2},l={x:e-a/2,y:r+s/2,z:n-i/2};return[o,c,h,l]}getPolygonBackPoints(t){const{center:{x:e,y:r,z:n},height:s,width:a,depth:i}=t,o={x:e-a/2,y:r+s/2,z:n+i/2},c={x:e-a/2,y:r+s/2,z:n-i/2},h={x:e-a/2,y:r-s/2,z:n-i/2},l={x:e-a/2,y:r-s/2,z:n+i/2};return[o,c,h,l]}getPolygonTopPoints(t){const{center:{x:e,y:r,z:n},height:s,width:a,depth:i}=t,o={x:e+a/2,y:r+s/2,z:n+i/2},c={x:e+a/2,y:r-s/2,z:n+i/2},h={x:e-a/2,y:r-s/2,z:n+i/2},l={x:e-a/2,y:r+s/2,z:n+i/2};return[o,c,h,l]}getModelTransformationMatrix(t){const{center:{x:e,y:r,z:n},rotation:s}=t,a=new THREE__namespace.Matrix4().makeTranslation(-e,-r,-n),i=new THREE__namespace.Matrix4().makeTranslation(e,r,n),o=new THREE__namespace.Matrix4().makeRotationZ(s);return new THREE__namespace.Matrix4().multiply(i).multiply(o).multiply(a)}getBoxSidePolygon2DCoordinate(t){return this.getBoxPolygon2DCoordinate(t,lbUtils.EPerspectiveView.Left)}getBoxBackPolygon2DCoordinate(t){return this.getBoxPolygon2DCoordinate(t,lbUtils.EPerspectiveView.Back)}boxParams2ViewPolygon(t,e){switch(e){case lbUtils.EPerspectiveView.Left:return this.getPolygonSidePoints(t);case lbUtils.EPerspectiveView.Back:return this.getPolygonBackPoints(t);default:return this.getPolygonTopPoints(t)}}getBoxPolygon2DCoordinate(t,e){const r=this.boxParams2ViewPolygon(t,e),{width:n,height:s}=t,a=new THREE__namespace.Matrix4().premultiply(this.camera.matrixWorldInverse).premultiply(this.camera.projectionMatrix),i=new THREE__namespace.Matrix4().premultiply(this.getModelTransformationMatrix(t)).premultiply(a).premultiply(this.basicCoordinate2CanvasMatrix4);this.sideMatrix=i;const o=r.map(l=>new THREE__namespace.Vector3(l.x,l.y,l.z)).map(l=>l.applyMatrix4(this.sideMatrix)),c=this.containerWidth/n,h=this.containerHeight/s;return{polygon2d:o,zoom:Math.min(c,h)/2}}getBoxTopPolygon2DCoordinate(t){const{width:e,height:r}=t,s=this.getPolygonTopPoints(t).map(o=>new THREE__namespace.Vector3(o.x,o.y,o.z)).map(o=>o.applyMatrix4(this.getModelTransformationMatrix(t))).map(o=>({x:o.y,y:o.x})).map(o=>({x:-(o.x-this.containerWidth/2),y:-(o.y-this.containerHeight/2)})),a=this.containerWidth/e,i=this.containerHeight/r;return{polygon2d:s,zoom:Math.min(a,i)/2}}getNewBoxBySideUpdate(t,e,r,n){const s=new THREE__namespace.Matrix4().makeRotationZ(n.rotation),a=new THREE__namespace.Vector3(-t.x,0,0).applyMatrix4(s);let i=n;return i.center={x:i.center.x+a.x,y:i.center.y+a.y,z:i.center.z-t.z},i=__spreadProps(__spreadValues({},i),{width:i.width+e,height:i.height,depth:i.depth+r}),{newBoxParams:i}}getNewBoxByBackUpdate(t,e,r,n){const s=new THREE__namespace.Matrix4().makeRotationZ(n.rotation),a=new THREE__namespace.Vector3(0,-t.x,0).applyMatrix4(s);let i=n;return i.center={x:i.center.x+a.x,y:i.center.y+a.y,z:i.center.z-t.z},i=__spreadProps(__spreadValues({},i),{width:i.width,height:i.height+e,depth:i.depth+r}),{newBoxParams:i}}getNewBoxBySideUpdateByPoints(t,e,r,n){var s;const a=(s=this.sideMatrix)==null?void 0:s.invert();if(!this.sideMatrix||!a){console.error("No sideMatrix");return}this.camera.zoom=1,this.camera.updateProjectionMatrix();const i=t.map(p=>new THREE__namespace.Vector3(p.x,p.y,p.z)).map(p=>p.applyMatrix4(a)),[o,c,h,l]=i,u=Math.max(Math.abs(o.x-h.x),Math.abs(o.x-c.x)),x=c.add(l).applyMatrix3(new THREE__namespace.Matrix3().set(1/2,0,0,0,1/2,0,0,0,1/2)).clone().applyMatrix3(new THREE__namespace.Matrix3().set(-1,0,0,0,-1,0,0,0,-1)).add(new THREE__namespace.Vector3(n.center.x,n.center.y,n.center.z));return{newBoxParams:__spreadProps(__spreadValues({},n),{center:{x:n.center.x-x.x,y:n.center.y-x.y,z:n.center.z-r},width:u,height:n.height,depth:n.depth+e,rotation:n.rotation})}}filterZAxisPoints(t){const e=t||this.scene.children.find(r=>r.uuid===this.pointsUuid);if(e){const{attributes:r}=e.geometry,{position:n}=r,s=[],{count:a}=n;for(let i=0;i<a;i++){const o=n.getZ(i);s.push(o>this.zAxisLimit?0:1)}e.geometry.setAttribute("visibility",new THREE__namespace.Float32BufferAttribute(s,1)),e.geometry.attributes.visibility.needsUpdate=!0}}render(){this.renderer.render(this.scene,this.camera)}}exports.createThreeMatrix4=matrix.createThreeMatrix4,exports.getCuboidFromPointCloudBox=matrix.getCuboidFromPointCloudBox,exports.lidar2image=matrix.lidar2image,exports.pointCloudLidar2image=matrix.pointCloudLidar2image,exports.rotatePoint=matrix.rotatePoint,exports.transferKitti2Matrix=matrix.transferKitti2Matrix,exports.PointCloud=PointCloud;
|
|
@@ -62,7 +62,7 @@ export declare enum ERectPattern {
|
|
|
62
62
|
'RectBG' = 1,
|
|
63
63
|
'showOrder' = 2
|
|
64
64
|
}
|
|
65
|
-
export
|
|
65
|
+
export type ToolName = EToolName | EVideoToolName | EPointCloudName;
|
|
66
66
|
export declare const TOOL_NAME: {
|
|
67
67
|
[a: string]: string;
|
|
68
68
|
};
|
|
@@ -107,8 +107,9 @@ export declare class PointCloud {
|
|
|
107
107
|
* Update Camera position & target
|
|
108
108
|
* @param boxParams
|
|
109
109
|
* @param perspectiveView
|
|
110
|
+
* @param customCameraVector Provide a custom way.
|
|
110
111
|
*/
|
|
111
|
-
updateCameraByBox(boxParams: IPointCloudBox, perspectiveView: EPerspectiveView): THREE.Vector3;
|
|
112
|
+
updateCameraByBox(boxParams: IPointCloudBox, perspectiveView: EPerspectiveView, customCameraVector?: I3DSpaceCoord): THREE.Vector3;
|
|
112
113
|
updateOrthoCamera(boxParams: IPointCloudBox, perspectiveView: EPerspectiveView): {
|
|
113
114
|
cameraPositionVector: THREE.Vector3;
|
|
114
115
|
};
|
|
@@ -7,7 +7,7 @@ import { EToolName } from '@/constant/tool';
|
|
|
7
7
|
import { RectOperation } from './toolOperation/rectOperation';
|
|
8
8
|
import PolygonOperation from './toolOperation/polygonOperation';
|
|
9
9
|
import SegmentByRect from './toolOperation/segmentByRect';
|
|
10
|
-
export
|
|
10
|
+
export type THybridToolName = EToolName | Array<EToolName>;
|
|
11
11
|
interface IToolSchedulerOperation {
|
|
12
12
|
}
|
|
13
13
|
interface IToolSchedulerProps {
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { TAnnotationViewData, TAnnotationViewLine, TAnnotationViewPolygon, TAnnotationViewBox3d, IBasicStyle } from '@labelbee/lb-utils';
|
|
5
5
|
import { BasicToolOperation, IBasicToolOperationProps } from './basicToolOperation';
|
|
6
|
-
|
|
6
|
+
type IViewOperationProps = {
|
|
7
7
|
style: IBasicStyle;
|
|
8
8
|
annotations: TAnnotationViewData[];
|
|
9
9
|
} & IBasicToolOperationProps;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import*as
|
|
1
|
+
import*as a from"three";import{toolStyleConverter as S,PerspectiveShiftUtils as w,EPerspectiveView as g}from"@labelbee/lb-utils";import k from"../../_virtual/highlightWorker.js";import V from"../../_virtual/filterBoxWorker.js";import{isInPolygon as L}from"../../utils/tool/polygonTool.js";import I from"../../utils/uuid.js";import{PCDLoader as N}from"./PCDLoader.js";import{OrbitControls as D}from"./OrbitControls.js";import{PointCloudCache as F}from"./cache.js";import{getCuboidFromPointCloudBox as B}from"./matrix.js";export{createThreeMatrix4,getCuboidFromPointCloudBox,lidar2image,pointCloudLidar2image,rotatePoint,transferKitti2Matrix}from"./matrix.js";import"../../constant/tool.js";import"../../constant/annotation.js";import"../../utils/MathUtils.js";import"@turf/turf";import"../../utils/tool/CommonToolUtils.js";import"../../utils/tool/LineToolUtils.js";import"../../utils/tool/DrawUtils.js";import"lodash";import"../../constant/keyCode.js";import"../../locales/index.js";import"../../locales/constants.js";import"../../constant/style.js";import"../../utils/tool/CanvasUtils.js";import"../../utils/tool/ZoomUtils.js";var E=Object.defineProperty,R=Object.defineProperties,U=Object.getOwnPropertyDescriptors,T=Object.getOwnPropertySymbols,W=Object.prototype.hasOwnProperty,Z=Object.prototype.propertyIsEnumerable,A=(u,t,e)=>t in u?E(u,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):u[t]=e,P=(u,t)=>{for(var e in t||(t={}))W.call(t,e)&&A(u,e,t[e]);if(T)for(var e of T(t))Z.call(t,e)&&A(u,e,t[e]);return u},M=(u,t)=>R(u,U(t)),z=(u,t,e)=>new Promise((r,n)=>{var s=o=>{try{i(e.next(o))}catch(h){n(h)}},c=o=>{try{i(e.throw(o))}catch(h){n(h)}},i=o=>o.done?r(o.value):Promise.resolve(o.value).then(s,c);i((e=e.apply(u,t)).next())});const H=30,O=new k({type:"module"});class G{constructor({container:t,noAppend:e,isOrthographicCamera:r,orthographicParams:n,backgroundColor:s="black",config:c}){this.zAxisLimit=10,this.initCameraPosition=this.DEFAULT_INIT_CAMERA_POSITION,this.isOrthographicCamera=!1,this.pointsUuid="",this.pointCloudObjectName="pointCloud",this.rangeObjectName="range",this.showDirection=!0,this.AddBoxToSense=(i,o=16777215)=>{var h;const l=(h=i.id)!=null?h:I();this.removeObjectByName(l);const{center:d,width:p,height:y,depth:f,rotation:C}=i,m=new a.Group,b=new a.BoxGeometry(p,y,f),x=new a.MeshBasicMaterial({color:"blue"}),v=new a.Mesh(b,x),j=new a.BoxHelper(v,o),_=this.generateBoxArrow(i);m.add(j),m.add(_),m.position.set(d.x,d.y,d.z),m.rotation.set(0,0,C),m.name=l,this.scene.add(m)},this.applyCameraTarget=i=>{if(this.camera.type==="OrthographicCamera"&&i){const o=this.getOrthographicCameraTarget(i);this.updateCameraZoom(i.zoom),this.updateCamera(i.position,o)}},this.overridePointShader=i=>{i.vertexShader=`
|
|
2
2
|
attribute float sizes;
|
|
3
3
|
attribute float visibility;
|
|
4
4
|
varying float vVisible;
|
|
@@ -8,4 +8,4 @@ import*as c from"three";import{toolStyleConverter as V,PerspectiveShiftUtils as
|
|
|
8
8
|
varying float vVisible;
|
|
9
9
|
${i.fragmentShader}`.replace("#include <clipping_planes_fragment>",`
|
|
10
10
|
if (vVisible < 0.5) discard;
|
|
11
|
-
#include <clipping_planes_fragment>`)},this.loadPCDFile=(i,o)=>B(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,o)}),this.loadPCDFileByBox=(i,o,h)=>B(this,null,function*(){const l=(y,f)=>B(this,null,function*(){const{width:C=0,height:m=0,depth:b=0}=h!=null?h:{},x=yield this.filterPointsByBox(M(P({},o),{width:o.width+C,height:o.height+m,depth:o.depth+b}),y,f);if(!x){console.error("filter Error");return}this.clearPointCloud(),this.currentPCDSrc=i;const v=new c.Points(x.geometry);v.name=this.pointCloudObjectName,this.scene.add(v),this.render()}),{points:d,color:p}=yield this.cacheInstance.loadPCDFile(i);l(d,p)}),this.generateRange=i=>{const o=this.createRange(i);this.scene.add(o)},this.generateBoxArrow=({width:i})=>{const o=new c.Vector3(1,0,0),h=new c.Vector3(i/2,0,0),l=2,d=16776960,p=new c.ArrowHelper(o,h,l,d);return p.visible=this.showDirection,p},this.generateBoxTrackID=i=>{if(!i.trackID)return;const o=new c.Texture(this.getTextCanvas(i.trackID.toString()));o.needsUpdate=!0;const h=new c.SpriteMaterial({map:o,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=i=>{const o=this.scene.getObjectByName(this.pointCloudObjectName);if(!o)return;const h=o.material.size;i?o.material.size=Math.min(h*1.2,10):o.material.size=Math.max(h/1.2,1),this.render()},this.container=t,this.renderer=new c.WebGLRenderer({antialias:!0}),this.backgroundColor=s,this.config=a,r&&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 D(this.camera,this.renderer.domElement),this.pcdLoader=new N,this.axesHelper=new c.AxesHelper(1e3),this.scene.add(this.camera),e||t.appendChild(this.renderer.domElement),this.init(),this.cacheInstance=F.getInstance()}get DEFAULT_INIT_CAMERA_POSITION(){return new 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:n,bottom:s,near:a,far:i}=t;this.camera.left=e,this.camera.right=r,this.camera.top=n,this.camera.bottom=s,this.camera.near=a,this.camera.far=i,this.camera.updateProjectionMatrix()}initPerspectiveCamera(){this.camera.type==="PerspectiveCamera"&&(this.camera.fov=30,this.camera.aspect=this.containerWidth/this.containerHeight,this.camera.near=1,this.camera.far=1e3,this.camera.updateProjectionMatrix())}initCamera(){const{camera:t}=this;if(this.isOrthographicCamera){const{x:e,y:r,z:n}=this.initCameraPosition;t.position.set(e,r,n)}else t.position.set(-1,0,500);t.up.set(0,0,1)}initControls(){const{controls:t}=this;t.addEventListener("change",()=>{this.render()}),this.setDefaultControls()}setDefaultControls(){const{controls:t}=this,e=[0,0,0];t.target=new 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]=V.getColorFromConfig({attribute:r.attribute},M(P({},this.config),{attributeConfigurable:!0}),{}),e),{})}generateBoxes(t){t.forEach(e=>{this.generateBox(e)}),this.render()}getOrthographicCamera(t){const{center:e,width:r,height:n}=t,s=10,a=e.x-r/2-s,i=e.x-r/2+s,o=e.y+n/2+s,h=e.y-n/2-s,l=100,d=-100,p=500/l;return{left:a,right:i,top:o,bottom:h,near:l,far:d,zoom:p}}updateCameraZoom(t){this.camera.zoom=t,this.camera.updateProjectionMatrix()}updateCameraByBox(t,e){const{center:r,width:n,height:s,depth:a,rotation:i}=t,o=this.getCameraVector(r,i,{width:n,height:s,depth:a},e);return this.updateCamera(o,r),o}updateOrthoCamera(t,e){const r=this.updateCameraByBox(t,e);return this.camera.zoom=1,this.camera.updateProjectionMatrix(),{cameraPositionVector:r}}updateTopCamera(){this.setInitCameraPosition(this.DEFAULT_INIT_CAMERA_POSITION),this.camera.zoom=1,this.initCamera(),this.setDefaultControls(),this.camera.updateProjectionMatrix(),this.render()}updateCamera(t,e){this.camera.position.set(t.x,t.y,t.z),this.controls.target=new c.Vector3(e.x,e.y,e.z),this.controls.update()}resetCamera(){this.updateCamera(this.DEFAULT_INIT_CAMERA_POSITION,{x:0,y:0,z:0})}getOrthographicCameraTarget(t){const e=new c.Vector3(0,0,-1).applyQuaternion(t.quaternion);return t.position.clone().add(e)}createThreeMatrix4(t){return new c.Matrix4().set(...t)}filterPointsByBox(t,e,r){var n,s,a;if(!e){const i=this.scene.getObjectByName(this.pointCloudObjectName);if(!i)return console.error("There is no corresponding point cloud object"),Promise.resolve(void 0);e=(a=(s=(n=i==null?void 0:i.geometry)==null?void 0:n.attributes)==null?void 0:s.position)==null?void 0:a.array}if(window.Worker){const{zMin:i,zMax:o,polygonPointList:h}=z(t),l=e;r=r!=null?r:new Float32Array([]);const d={boxParams:t,zMin:i,zMax:o,polygonPointList:h,color:r,position:l};return new Promise(p=>{const y=new k;y.postMessage(d),y.onmessage=f=>{const{color:C,position:m,num:b}=f.data,x=new c.BufferGeometry;x.setAttribute("position",new c.Float32BufferAttribute(m,3)),x.setAttribute("color",new c.Float32BufferAttribute(C,3)),x.computeBoundingSphere(),y.terminate(),p({geometry:x,num:b})}})}return Promise.resolve(void 0)}getCameraVector(t,e,r,n=g.Front,s=H){let a=w.frontViewMatrix4(s);switch(n){case g.Front:break;case g.Back:a=w.backViewMatrix4(s);break;case g.Left:a=w.leftViewMatrix4(s);break;case g.Right:a=w.rightViewMatrix4(s);break;case g.Top:a=w.topViewMatrix4(s);break;case g.LFT:a=w.leftFrontTopViewMatrix4(s,r);break;case g.RBT:a=w.rightBackTopViewMatrix4(s,r);break}const i=this.createThreeMatrix4(a),o=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(o).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),n=new c.BufferGeometry().setFromPoints(r),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 r=new c.PointsMaterial({vertexColors:!0});r.onBeforeCompile=this.overridePointShader,r.size=1.2,e&&this.generateRange(e),this.pointsUuid=t.uuid,t.material=r,this.filterZAxisPoints(t),this.scene.add(t),this.render()}clearPointCloud(){this.removeObjectByName(this.pointCloudObjectName)}clearPointCloudAndRender(){this.clearPointCloud(),this.render()}highlightOriginPointCloud(t){const e=this.scene.getObjectByName(this.pointCloudObjectName);if(!!e)return this.highlightPCDSrc=this.currentPCDSrc,new Promise(r=>{if(window.Worker){const s=(t?[...t]:[]).map(o=>z(o)),a=this.getAllAttributeColor(s),i={cuboidList:s,position:e.geometry.attributes.position.array,color:e.geometry.attributes.color.array,colorList:a};O.postMessage(i),O.onmessage=o=>{const{color:h}=o.data,l=new c.BufferAttribute(h,3);this.highlightPCDSrc&&(this.cacheInstance.updateColor(this.highlightPCDSrc,h),this.highlightPCDSrc=void 0),l.needsUpdate=!0,e.geometry.setAttribute("color",l),r(h),this.render()}}})}updateColor(t){const e=this.scene.getObjectByName(this.pointCloudObjectName);if(e){const r=new c.BufferAttribute(t,3);r.needsUpdate=!0,e.geometry.setAttribute("color",r),this.render()}}setShowDirection(t){this.showDirection=t,this.scene.children.forEach(e=>{e.type==="Group"&&e.children.forEach(r=>{r.type==="ArrowHelper"&&(r.visible=t)})}),this.render()}getTextCanvas(t){const e=document.createElement("canvas"),r=e.getContext("2d");return r&&(r.font=`${50}px " bold`,r.fillStyle="white",r.textAlign="center",r.textBaseline="middle",r.fillText(t,e.width/2,e.height/2)),e}getSensesPointZAxisInPolygon(t,e){const r=this.scene.children.find(o=>o.uuid===this.pointsUuid);let n=0,s=0,a=0,i=0;if(r&&(r==null?void 0:r.geometry)){const o=r==null?void 0:r.geometry.attributes.position.array;for(let h=0;h<o.length;h+=3){const l=o[h],d=o[h+1],p=o[h+2];L({x:l,y:d},t)&&p&&(s=Math.max(p,s),n=Math.min(p,n),i++,e&&p>=e[0]&&p<=e[1]&&a++)}}return{maxZ:s,minZ:n,count:a,zCount:i}}getBasicCoordinate2Canvas(t){const e=this.containerWidth/2,r=this.containerHeight/2;return{x:t.x*e+e,y:t.y*r+r,z:t.z}}get basicCoordinate2CanvasMatrix4(){const t=this.containerWidth/2,e=this.containerHeight/2;return new 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:n},height:s,width:a,depth:i}=t,o={x:e+a/2,y:r+s/2,z:n-i/2},h={x:e+a/2,y:r+s/2,z:n+i/2},l={x:e-a/2,y:r+s/2,z:n+i/2},d={x:e-a/2,y:r+s/2,z:n-i/2};return[o,h,l,d]}getPolygonBackPoints(t){const{center:{x:e,y:r,z:n},height:s,width:a,depth:i}=t,o={x:e-a/2,y:r+s/2,z:n+i/2},h={x:e-a/2,y:r+s/2,z:n-i/2},l={x:e-a/2,y:r-s/2,z:n-i/2},d={x:e-a/2,y:r-s/2,z:n+i/2};return[o,h,l,d]}getPolygonTopPoints(t){const{center:{x:e,y:r,z:n},height:s,width:a,depth:i}=t,o={x:e+a/2,y:r+s/2,z:n+i/2},h={x:e+a/2,y:r-s/2,z:n+i/2},l={x:e-a/2,y:r-s/2,z:n+i/2},d={x:e-a/2,y:r+s/2,z:n+i/2};return[o,h,l,d]}getModelTransformationMatrix(t){const{center:{x:e,y:r,z:n},rotation:s}=t,a=new c.Matrix4().makeTranslation(-e,-r,-n),i=new c.Matrix4().makeTranslation(e,r,n),o=new c.Matrix4().makeRotationZ(s);return new c.Matrix4().multiply(i).multiply(o).multiply(a)}getBoxSidePolygon2DCoordinate(t){return this.getBoxPolygon2DCoordinate(t,g.Left)}getBoxBackPolygon2DCoordinate(t){return this.getBoxPolygon2DCoordinate(t,g.Back)}boxParams2ViewPolygon(t,e){switch(e){case g.Left:return this.getPolygonSidePoints(t);case g.Back:return this.getPolygonBackPoints(t);default:return this.getPolygonTopPoints(t)}}getBoxPolygon2DCoordinate(t,e){const r=this.boxParams2ViewPolygon(t,e),{width:n,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 o=r.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:o,zoom:Math.min(h,l)/2}}getBoxTopPolygon2DCoordinate(t){const{width:e,height:r}=t,s=this.getPolygonTopPoints(t).map(o=>new c.Vector3(o.x,o.y,o.z)).map(o=>o.applyMatrix4(this.getModelTransformationMatrix(t))).map(o=>({x:o.y,y:o.x})).map(o=>({x:-(o.x-this.containerWidth/2),y:-(o.y-this.containerHeight/2)})),a=this.containerWidth/e,i=this.containerHeight/r;return{polygon2d:s,zoom:Math.min(a,i)/2}}getNewBoxBySideUpdate(t,e,r,n){const s=new c.Matrix4().makeRotationZ(n.rotation),a=new c.Vector3(-t.x,0,0).applyMatrix4(s);let i=n;return i.center={x:i.center.x+a.x,y:i.center.y+a.y,z:i.center.z-t.z},i=M(P({},i),{width:i.width+e,height:i.height,depth:i.depth+r}),{newBoxParams:i}}getNewBoxByBackUpdate(t,e,r,n){const s=new c.Matrix4().makeRotationZ(n.rotation),a=new c.Vector3(0,-t.x,0).applyMatrix4(s);let i=n;return i.center={x:i.center.x+a.x,y:i.center.y+a.y,z:i.center.z-t.z},i=M(P({},i),{width:i.width,height:i.height+e,depth:i.depth+r}),{newBoxParams:i}}getNewBoxBySideUpdateByPoints(t,e,r,n){var s;const a=(s=this.sideMatrix)==null?void 0:s.invert();if(!this.sideMatrix||!a){console.error("No sideMatrix");return}this.camera.zoom=1,this.camera.updateProjectionMatrix();const i=t.map(m=>new c.Vector3(m.x,m.y,m.z)).map(m=>m.applyMatrix4(a)),[o,h,l,d]=i,p=Math.max(Math.abs(o.x-l.x),Math.abs(o.x-h.x)),f=h.add(d).applyMatrix3(new 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(P({},n),{center:{x:n.center.x-f.x,y:n.center.y-f.y,z:n.center.z-r},width:p,height:n.height,depth:n.depth+e,rotation:n.rotation})}}filterZAxisPoints(t){const e=t||this.scene.children.find(r=>r.uuid===this.pointsUuid);if(e){const{attributes:r}=e.geometry,{position:n}=r,s=[],{count:a}=n;for(let i=0;i<a;i++){const o=n.getZ(i);s.push(o>this.zAxisLimit?0:1)}e.geometry.setAttribute("visibility",new c.Float32BufferAttribute(s,1)),e.geometry.attributes.visibility.needsUpdate=!0}}render(){this.renderer.render(this.scene,this.camera)}}export{G as PointCloud};
|
|
11
|
+
#include <clipping_planes_fragment>`)},this.loadPCDFile=(i,o)=>z(this,null,function*(){this.clearPointCloud(),this.currentPCDSrc=i;const{points:h,color:l}=yield this.cacheInstance.loadPCDFile(i),d=new a.BufferGeometry;d.setAttribute("position",new a.BufferAttribute(h,3)),d.setAttribute("color",new a.BufferAttribute(l,3));const p=new a.Points(d);this.renderPointCloud(p,o)}),this.loadPCDFileByBox=(i,o,h)=>z(this,null,function*(){const l=(y,f)=>z(this,null,function*(){const{width:C=0,height:m=0,depth:b=0}=h!=null?h:{},x=yield this.filterPointsByBox(M(P({},o),{width:o.width+C,height:o.height+m,depth:o.depth+b}),y,f);if(!x){console.error("filter Error");return}this.clearPointCloud(),this.currentPCDSrc=i;const v=new a.Points(x.geometry);v.name=this.pointCloudObjectName,this.scene.add(v),this.render()}),{points:d,color:p}=yield this.cacheInstance.loadPCDFile(i);l(d,p)}),this.generateRange=i=>{const o=this.createRange(i);this.scene.add(o)},this.generateBoxArrow=({width:i})=>{const o=new a.Vector3(1,0,0),h=new a.Vector3(i/2,0,0),l=2,d=16776960,p=new a.ArrowHelper(o,h,l,d);return p.visible=this.showDirection,p},this.generateBoxTrackID=i=>{if(!i.trackID)return;const o=new a.Texture(this.getTextCanvas(i.trackID.toString()));o.needsUpdate=!0;const h=new a.SpriteMaterial({map:o,depthWrite:!1}),l=new a.Sprite(h);return l.scale.set(5,5,5),l.position.set(-i.width/2,0,i.depth/2+.5),l},this.applyZAxisPoints=i=>{this.zAxisLimit=i,this.filterZAxisPoints(),this.render()},this.updatePointSize=i=>{const o=this.scene.getObjectByName(this.pointCloudObjectName);if(!o)return;const h=o.material.size;i?o.material.size=Math.min(h*1.2,10):o.material.size=Math.max(h/1.2,1),this.render()},this.container=t,this.renderer=new a.WebGLRenderer({antialias:!0}),this.backgroundColor=s,this.config=c,r&&n?(this.isOrthographicCamera=!0,this.camera=new a.OrthographicCamera(n.left,n.right,n.top,n.bottom,n.near,n.far)):this.camera=new a.PerspectiveCamera(30,this.containerWidth/this.containerHeight,1,1e3),this.initCamera(),this.scene=new a.Scene,this.controls=new D(this.camera,this.renderer.domElement),this.pcdLoader=new N,this.axesHelper=new a.AxesHelper(1e3),this.scene.add(this.camera),e||t.appendChild(this.renderer.domElement),this.init(),this.cacheInstance=F.getInstance()}get DEFAULT_INIT_CAMERA_POSITION(){return new a.Vector3(-.01,0,10)}get containerWidth(){return this.container.clientWidth}get containerHeight(){return this.container.clientHeight}setInitCameraPosition(t){this.initCameraPosition=t}setConfig(t){this.config=t}initOrthographicCamera(t){if(this.camera.type!=="OrthographicCamera")return;const{left:e,right:r,top:n,bottom:s,near:c,far:i}=t;this.camera.left=e,this.camera.right=r,this.camera.top=n,this.camera.bottom=s,this.camera.near=c,this.camera.far=i,this.camera.updateProjectionMatrix()}initPerspectiveCamera(){this.camera.type==="PerspectiveCamera"&&(this.camera.fov=30,this.camera.aspect=this.containerWidth/this.containerHeight,this.camera.near=1,this.camera.far=1e3,this.camera.updateProjectionMatrix())}initCamera(){const{camera:t}=this;if(this.isOrthographicCamera){const{x:e,y:r,z:n}=this.initCameraPosition;t.position.set(e,r,n)}else t.position.set(-1,0,500);t.up.set(0,0,1)}initControls(){const{controls:t}=this;t.addEventListener("change",()=>{this.render()}),this.setDefaultControls()}setDefaultControls(){const{controls:t}=this,e=[0,0,0];t.target=new a.Vector3(...e),t.addEventListener("change",()=>{this.render()}),t.maxPolarAngle=Math.PI/2,t.update()}initRenderer(){const{renderer:t}=this;t.setPixelRatio(window.devicePixelRatio),t.setSize(this.containerWidth,this.containerHeight)}init(){const{scene:t}=this;t.background=new a.Color(this.backgroundColor),this.initControls(),this.initRenderer()}removeObjectByName(t){const e=this.scene.getObjectByName(t);e&&e.removeFromParent()}generateBox(t,e=16777215){const r=e;this.AddBoxToSense(t,r),this.render()}getAllAttributeColor(t){return t.reduce((e,r)=>(e[r.attribute]=S.getColorFromConfig({attribute:r.attribute},M(P({},this.config),{attributeConfigurable:!0}),{}),e),{})}generateBoxes(t){t.forEach(e=>{this.generateBox(e)}),this.render()}getOrthographicCamera(t){const{center:e,width:r,height:n}=t,s=10,c=e.x-r/2-s,i=e.x-r/2+s,o=e.y+n/2+s,h=e.y-n/2-s,l=100,d=-100,p=500/l;return{left:c,right:i,top:o,bottom:h,near:l,far:d,zoom:p}}updateCameraZoom(t){this.camera.zoom=t,this.camera.updateProjectionMatrix()}updateCameraByBox(t,e,r){const{center:n,width:s,height:c,depth:i,rotation:o}=t,h=this.getCameraVector(n,o,{width:s,height:c,depth:i},e);return r?(this.updateCamera(r,n),new a.Vector3(r.x,r.y,r.z)):(this.updateCamera(h,n),h)}updateOrthoCamera(t,e){const r=this.updateCameraByBox(t,e);return this.camera.zoom=1,this.camera.updateProjectionMatrix(),{cameraPositionVector:r}}updateTopCamera(){this.setInitCameraPosition(this.DEFAULT_INIT_CAMERA_POSITION),this.camera.zoom=1,this.initCamera(),this.setDefaultControls(),this.camera.updateProjectionMatrix(),this.render()}updateCamera(t,e){this.camera.position.set(t.x,t.y,t.z),this.controls.target=new a.Vector3(e.x,e.y,e.z),this.controls.update()}resetCamera(){this.updateCamera(this.DEFAULT_INIT_CAMERA_POSITION,{x:0,y:0,z:0})}getOrthographicCameraTarget(t){const e=new a.Vector3(0,0,-1).applyQuaternion(t.quaternion);return t.position.clone().add(e)}createThreeMatrix4(t){return new a.Matrix4().set(...t)}filterPointsByBox(t,e,r){var n,s,c;if(!e){const i=this.scene.getObjectByName(this.pointCloudObjectName);if(!i)return console.error("There is no corresponding point cloud object"),Promise.resolve(void 0);e=(c=(s=(n=i==null?void 0:i.geometry)==null?void 0:n.attributes)==null?void 0:s.position)==null?void 0:c.array}if(window.Worker){const{zMin:i,zMax:o,polygonPointList:h}=B(t),l=e;r=r!=null?r:new Float32Array([]);const d={boxParams:t,zMin:i,zMax:o,polygonPointList:h,color:r,position:l};return new Promise(p=>{const y=new V;y.postMessage(d),y.onmessage=f=>{const{color:C,position:m,num:b}=f.data,x=new a.BufferGeometry;x.setAttribute("position",new a.Float32BufferAttribute(m,3)),x.setAttribute("color",new a.Float32BufferAttribute(C,3)),x.computeBoundingSphere(),y.terminate(),p({geometry:x,num:b})}})}return Promise.resolve(void 0)}getCameraVector(t,e,r,n=g.Front,s=H){let c=w.frontViewMatrix4(s);switch(n){case g.Front:break;case g.Back:c=w.backViewMatrix4(s);break;case g.Left:c=w.leftViewMatrix4(s);break;case g.Right:c=w.rightViewMatrix4(s);break;case g.Top:c=w.topViewMatrix4(s);break;case g.LFT:c=w.leftFrontTopViewMatrix4(s,r);break;case g.RBT:c=w.rightBackTopViewMatrix4(s,r);break}const i=this.createThreeMatrix4(c),o=new a.Matrix4().makeTranslation(-t.x,-t.y,-t.z),h=new a.Matrix4().makeTranslation(t.x,t.y,t.z),l=new a.Matrix4().makeRotationZ(e);return new a.Vector3(t.x,t.y,t.z).clone().applyMatrix4(i).applyMatrix4(o).applyMatrix4(l).applyMatrix4(h)}createRange(t){this.removeObjectByName(this.rangeObjectName);const r=new a.EllipseCurve(0,0,t,t,0,2*Math.PI,!1,0).getPoints(50),n=new a.BufferGeometry().setFromPoints(r),s=new a.LineBasicMaterial({color:16711680}),c=new a.Line(n,s);return c.name=this.rangeObjectName,c}renderPointCloud(t,e){t.name=this.pointCloudObjectName;const r=new a.PointsMaterial({vertexColors:!0});r.onBeforeCompile=this.overridePointShader,r.size=1.2,e&&this.generateRange(e),this.pointsUuid=t.uuid,t.material=r,this.filterZAxisPoints(t),this.scene.add(t),this.render()}clearPointCloud(){this.removeObjectByName(this.pointCloudObjectName)}clearPointCloudAndRender(){this.clearPointCloud(),this.render()}highlightOriginPointCloud(t){const e=this.scene.getObjectByName(this.pointCloudObjectName);if(!!e)return this.highlightPCDSrc=this.currentPCDSrc,new Promise(r=>{if(window.Worker){const s=(t?[...t]:[]).map(o=>B(o)),c=this.getAllAttributeColor(s),i={cuboidList:s,position:e.geometry.attributes.position.array,color:e.geometry.attributes.color.array,colorList:c};O.postMessage(i),O.onmessage=o=>{const{color:h}=o.data,l=new a.BufferAttribute(h,3);this.highlightPCDSrc&&(this.cacheInstance.updateColor(this.highlightPCDSrc,h),this.highlightPCDSrc=void 0),l.needsUpdate=!0,e.geometry.setAttribute("color",l),r(h),this.render()}}})}updateColor(t){const e=this.scene.getObjectByName(this.pointCloudObjectName);if(e){const r=new a.BufferAttribute(t,3);r.needsUpdate=!0,e.geometry.setAttribute("color",r),this.render()}}setShowDirection(t){this.showDirection=t,this.scene.children.forEach(e=>{e.type==="Group"&&e.children.forEach(r=>{r.type==="ArrowHelper"&&(r.visible=t)})}),this.render()}getTextCanvas(t){const e=document.createElement("canvas"),r=e.getContext("2d");return r&&(r.font=`${50}px " bold`,r.fillStyle="white",r.textAlign="center",r.textBaseline="middle",r.fillText(t,e.width/2,e.height/2)),e}getSensesPointZAxisInPolygon(t,e){const r=this.scene.children.find(o=>o.uuid===this.pointsUuid);let n=0,s=0,c=0,i=0;if(r&&(r==null?void 0:r.geometry)){const o=r==null?void 0:r.geometry.attributes.position.array;for(let h=0;h<o.length;h+=3){const l=o[h],d=o[h+1],p=o[h+2];L({x:l,y:d},t)&&p&&(s=Math.max(p,s),n=Math.min(p,n),i++,e&&p>=e[0]&&p<=e[1]&&c++)}}return{maxZ:s,minZ:n,count:c,zCount:i}}getBasicCoordinate2Canvas(t){const e=this.containerWidth/2,r=this.containerHeight/2;return{x:t.x*e+e,y:t.y*r+r,z:t.z}}get basicCoordinate2CanvasMatrix4(){const t=this.containerWidth/2,e=this.containerHeight/2;return new a.Matrix4().set(t,0,0,t,0,e,0,e,0,0,1,0,0,0,0,1)}getCanvas2BasicCoordinate(t){const e=this.containerWidth/2,r=this.containerHeight/2;return new a.Vector3(t.x/e-e/2,-(t.y/r-r/2),1)}getPolygonSidePoints(t){const{center:{x:e,y:r,z:n},height:s,width:c,depth:i}=t,o={x:e+c/2,y:r+s/2,z:n-i/2},h={x:e+c/2,y:r+s/2,z:n+i/2},l={x:e-c/2,y:r+s/2,z:n+i/2},d={x:e-c/2,y:r+s/2,z:n-i/2};return[o,h,l,d]}getPolygonBackPoints(t){const{center:{x:e,y:r,z:n},height:s,width:c,depth:i}=t,o={x:e-c/2,y:r+s/2,z:n+i/2},h={x:e-c/2,y:r+s/2,z:n-i/2},l={x:e-c/2,y:r-s/2,z:n-i/2},d={x:e-c/2,y:r-s/2,z:n+i/2};return[o,h,l,d]}getPolygonTopPoints(t){const{center:{x:e,y:r,z:n},height:s,width:c,depth:i}=t,o={x:e+c/2,y:r+s/2,z:n+i/2},h={x:e+c/2,y:r-s/2,z:n+i/2},l={x:e-c/2,y:r-s/2,z:n+i/2},d={x:e-c/2,y:r+s/2,z:n+i/2};return[o,h,l,d]}getModelTransformationMatrix(t){const{center:{x:e,y:r,z:n},rotation:s}=t,c=new a.Matrix4().makeTranslation(-e,-r,-n),i=new a.Matrix4().makeTranslation(e,r,n),o=new a.Matrix4().makeRotationZ(s);return new a.Matrix4().multiply(i).multiply(o).multiply(c)}getBoxSidePolygon2DCoordinate(t){return this.getBoxPolygon2DCoordinate(t,g.Left)}getBoxBackPolygon2DCoordinate(t){return this.getBoxPolygon2DCoordinate(t,g.Back)}boxParams2ViewPolygon(t,e){switch(e){case g.Left:return this.getPolygonSidePoints(t);case g.Back:return this.getPolygonBackPoints(t);default:return this.getPolygonTopPoints(t)}}getBoxPolygon2DCoordinate(t,e){const r=this.boxParams2ViewPolygon(t,e),{width:n,height:s}=t,c=new a.Matrix4().premultiply(this.camera.matrixWorldInverse).premultiply(this.camera.projectionMatrix),i=new a.Matrix4().premultiply(this.getModelTransformationMatrix(t)).premultiply(c).premultiply(this.basicCoordinate2CanvasMatrix4);this.sideMatrix=i;const o=r.map(d=>new a.Vector3(d.x,d.y,d.z)).map(d=>d.applyMatrix4(this.sideMatrix)),h=this.containerWidth/n,l=this.containerHeight/s;return{polygon2d:o,zoom:Math.min(h,l)/2}}getBoxTopPolygon2DCoordinate(t){const{width:e,height:r}=t,s=this.getPolygonTopPoints(t).map(o=>new a.Vector3(o.x,o.y,o.z)).map(o=>o.applyMatrix4(this.getModelTransformationMatrix(t))).map(o=>({x:o.y,y:o.x})).map(o=>({x:-(o.x-this.containerWidth/2),y:-(o.y-this.containerHeight/2)})),c=this.containerWidth/e,i=this.containerHeight/r;return{polygon2d:s,zoom:Math.min(c,i)/2}}getNewBoxBySideUpdate(t,e,r,n){const s=new a.Matrix4().makeRotationZ(n.rotation),c=new a.Vector3(-t.x,0,0).applyMatrix4(s);let i=n;return i.center={x:i.center.x+c.x,y:i.center.y+c.y,z:i.center.z-t.z},i=M(P({},i),{width:i.width+e,height:i.height,depth:i.depth+r}),{newBoxParams:i}}getNewBoxByBackUpdate(t,e,r,n){const s=new a.Matrix4().makeRotationZ(n.rotation),c=new a.Vector3(0,-t.x,0).applyMatrix4(s);let i=n;return i.center={x:i.center.x+c.x,y:i.center.y+c.y,z:i.center.z-t.z},i=M(P({},i),{width:i.width,height:i.height+e,depth:i.depth+r}),{newBoxParams:i}}getNewBoxBySideUpdateByPoints(t,e,r,n){var s;const c=(s=this.sideMatrix)==null?void 0:s.invert();if(!this.sideMatrix||!c){console.error("No sideMatrix");return}this.camera.zoom=1,this.camera.updateProjectionMatrix();const i=t.map(m=>new a.Vector3(m.x,m.y,m.z)).map(m=>m.applyMatrix4(c)),[o,h,l,d]=i,p=Math.max(Math.abs(o.x-l.x),Math.abs(o.x-h.x)),f=h.add(d).applyMatrix3(new a.Matrix3().set(1/2,0,0,0,1/2,0,0,0,1/2)).clone().applyMatrix3(new a.Matrix3().set(-1,0,0,0,-1,0,0,0,-1)).add(new a.Vector3(n.center.x,n.center.y,n.center.z));return{newBoxParams:M(P({},n),{center:{x:n.center.x-f.x,y:n.center.y-f.y,z:n.center.z-r},width:p,height:n.height,depth:n.depth+e,rotation:n.rotation})}}filterZAxisPoints(t){const e=t||this.scene.children.find(r=>r.uuid===this.pointsUuid);if(e){const{attributes:r}=e.geometry,{position:n}=r,s=[],{count:c}=n;for(let i=0;i<c;i++){const o=n.getZ(i);s.push(o>this.zAxisLimit?0:1)}e.geometry.setAttribute("visibility",new a.Float32BufferAttribute(s,1)),e.geometry.attributes.visibility.needsUpdate=!0}}render(){this.renderer.render(this.scene,this.camera)}}export{G as PointCloud};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@labelbee/lb-annotation",
|
|
3
|
-
"version": "1.13.0-alpha.
|
|
3
|
+
"version": "1.13.0-alpha.6",
|
|
4
4
|
"description": "Annotation tool collection",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"annotation",
|
|
@@ -98,5 +98,5 @@
|
|
|
98
98
|
"lodash": "^4.17.20",
|
|
99
99
|
"three": ">=0.141.0"
|
|
100
100
|
},
|
|
101
|
-
"gitHead": "
|
|
101
|
+
"gitHead": "5fa52aaa658d7268a62fc0ba4ca7304c8a57958d"
|
|
102
102
|
}
|
package/es/_virtual/_rollup-plugin-web-worker-loader__helper__auto__createBase64WorkerFactory.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { createBase64WorkerFactory as createBase64WorkerFactory$1 } from './_rollup-plugin-web-worker-loader__helper__node__createBase64WorkerFactory.js';
|
|
2
|
-
import { createBase64WorkerFactory as createBase64WorkerFactory$2 } from './_rollup-plugin-web-worker-loader__helper__browser__createBase64WorkerFactory.js';
|
|
3
|
-
import { isNodeJS } from './_rollup-plugin-web-worker-loader__helper__auto__isNodeJS.js';
|
|
4
|
-
|
|
5
|
-
function createBase64WorkerFactory(base64, sourcemapArg, enableUnicodeArg) {
|
|
6
|
-
if (isNodeJS()) {
|
|
7
|
-
return createBase64WorkerFactory$1(base64, sourcemapArg, enableUnicodeArg);
|
|
8
|
-
}
|
|
9
|
-
return createBase64WorkerFactory$2(base64, sourcemapArg, enableUnicodeArg);
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export { createBase64WorkerFactory };
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
var WorkerClass = null;
|
|
2
|
-
|
|
3
|
-
try {
|
|
4
|
-
var WorkerThreads =
|
|
5
|
-
typeof module !== 'undefined' && typeof module.require === 'function' && module.require('worker_threads') ||
|
|
6
|
-
typeof __non_webpack_require__ === 'function' && __non_webpack_require__('worker_threads') ||
|
|
7
|
-
typeof require === 'function' && require('worker_threads');
|
|
8
|
-
WorkerClass = WorkerThreads.Worker;
|
|
9
|
-
} catch(e) {} // eslint-disable-line
|
|
10
|
-
|
|
11
|
-
export { WorkerClass };
|
package/es/_virtual/_rollup-plugin-web-worker-loader__helper__node__createBase64WorkerFactory.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { WorkerClass } from './_rollup-plugin-web-worker-loader__helper__node__WorkerClass.js';
|
|
2
|
-
|
|
3
|
-
function decodeBase64(base64, enableUnicode) {
|
|
4
|
-
return Buffer.from(base64, 'base64').toString(enableUnicode ? 'utf16' : 'utf8');
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
function createBase64WorkerFactory(base64, sourcemapArg, enableUnicodeArg) {
|
|
8
|
-
var sourcemap = sourcemapArg === undefined ? null : sourcemapArg;
|
|
9
|
-
var enableUnicode = enableUnicodeArg === undefined ? false : enableUnicodeArg;
|
|
10
|
-
var source = decodeBase64(base64, enableUnicode);
|
|
11
|
-
var start = source.indexOf('\n', 10) + 1;
|
|
12
|
-
var body = source.substring(start) + (sourcemap ? '\/\/# sourceMappingURL=' + sourcemap : '');
|
|
13
|
-
return function WorkerFactory(options) {
|
|
14
|
-
return new WorkerClass(body, Object.assign({}, options, { eval: true }));
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export { createBase64WorkerFactory };
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import _ from 'lodash';
|
|
2
|
-
import CommonToolUtils from '../../utils/tool/CommonToolUtils.js';
|
|
3
|
-
|
|
4
|
-
class Selection {
|
|
5
|
-
constructor(toolInstance) {
|
|
6
|
-
if (!toolInstance) {
|
|
7
|
-
console.error("MultipleSelect is require an tool instance");
|
|
8
|
-
}
|
|
9
|
-
this._selectedIDs = [];
|
|
10
|
-
this.toolInstance = toolInstance;
|
|
11
|
-
}
|
|
12
|
-
get selectedIDs() {
|
|
13
|
-
return this._selectedIDs;
|
|
14
|
-
}
|
|
15
|
-
set selectedIDs(selectedIDs) {
|
|
16
|
-
this._selectedIDs = selectedIDs;
|
|
17
|
-
this.toolInstance.render();
|
|
18
|
-
}
|
|
19
|
-
get visibleDataList() {
|
|
20
|
-
const {dataList, attributeLockList, basicResult} = this.toolInstance;
|
|
21
|
-
const [showingDataList] = CommonToolUtils.getRenderResultList(dataList, CommonToolUtils.getSourceID(basicResult), attributeLockList);
|
|
22
|
-
return showingDataList;
|
|
23
|
-
}
|
|
24
|
-
get dataList() {
|
|
25
|
-
return this.toolInstance.dataList;
|
|
26
|
-
}
|
|
27
|
-
updateSelectedIDs(selectedID) {
|
|
28
|
-
if (this.selectedIDs.includes(selectedID)) {
|
|
29
|
-
this.selectedIDs = this.selectedIDs.filter((id) => id !== selectedID);
|
|
30
|
-
} else {
|
|
31
|
-
this.selectedIDs = [...this.selectedIDs, selectedID];
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
updateSelectedGraphProps(updateList) {
|
|
35
|
-
const updatedDataList = _.cloneDeep(this.dataList).map((i) => {
|
|
36
|
-
const updatedData = updateList.find((s) => s.id === i.id);
|
|
37
|
-
if (updatedData) {
|
|
38
|
-
return _.merge(i, updatedData);
|
|
39
|
-
}
|
|
40
|
-
return i;
|
|
41
|
-
});
|
|
42
|
-
this.setResultAndRender(updatedDataList);
|
|
43
|
-
}
|
|
44
|
-
selectAll() {
|
|
45
|
-
this.selectedIDs = this.visibleDataList.map((i) => i.id);
|
|
46
|
-
this.toolInstance.render();
|
|
47
|
-
}
|
|
48
|
-
toStashDataList() {
|
|
49
|
-
if (this.selectedIDs.length > 0) {
|
|
50
|
-
this.stashDataList = _.cloneDeep(this.dataList.filter((i) => this.selectedIDs.includes(i.id)));
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
toUnStashDataList() {
|
|
54
|
-
if (this.stashDataList) {
|
|
55
|
-
const _stashDataList = this.stashDataList;
|
|
56
|
-
this.stashDataList = [];
|
|
57
|
-
return _stashDataList;
|
|
58
|
-
}
|
|
59
|
-
return void 0;
|
|
60
|
-
}
|
|
61
|
-
mergeStashData() {
|
|
62
|
-
const stashList = this.toUnStashDataList();
|
|
63
|
-
const mergedDataList = _(this.dataList).keyBy("id").merge(_.keyBy(stashList, "id")).values().value();
|
|
64
|
-
this.setResultAndRender(mergedDataList);
|
|
65
|
-
}
|
|
66
|
-
setResultAndRender(dataList) {
|
|
67
|
-
}
|
|
68
|
-
isSelectedID(id) {
|
|
69
|
-
return this.selectedIDs.includes(id);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
export { Selection as default };
|
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
import _ from 'lodash';
|
|
2
|
-
import CommonToolUtils from '../../utils/tool/CommonToolUtils.js';
|
|
3
|
-
|
|
4
|
-
class Selection {
|
|
5
|
-
constructor(toolInstance) {
|
|
6
|
-
if (!toolInstance) {
|
|
7
|
-
console.error("MultipleSelect is require a tool instance");
|
|
8
|
-
}
|
|
9
|
-
this._selectedIDs = [];
|
|
10
|
-
this.toolInstance = toolInstance;
|
|
11
|
-
}
|
|
12
|
-
get selectedIDs() {
|
|
13
|
-
return this._selectedIDs;
|
|
14
|
-
}
|
|
15
|
-
get selectedID() {
|
|
16
|
-
return this._selectedIDs.length === 1 ? this._selectedIDs[0] : void 0;
|
|
17
|
-
}
|
|
18
|
-
get visibleDataList() {
|
|
19
|
-
const {dataList, attributeLockList, basicResult} = this.toolInstance;
|
|
20
|
-
const [showingDataList] = CommonToolUtils.getRenderResultList(dataList, CommonToolUtils.getSourceID(basicResult), attributeLockList);
|
|
21
|
-
return showingDataList;
|
|
22
|
-
}
|
|
23
|
-
get dataList() {
|
|
24
|
-
return this.toolInstance.dataList;
|
|
25
|
-
}
|
|
26
|
-
set selectedIDs(selectedIDs) {
|
|
27
|
-
var _a;
|
|
28
|
-
(_a = this.toolInstance._textAttributeInstance) == null ? void 0 : _a.selectedIDsChanged(this.selectedIDs, selectedIDs);
|
|
29
|
-
this._selectedIDs = selectedIDs;
|
|
30
|
-
this.toolInstance.render();
|
|
31
|
-
}
|
|
32
|
-
updateSelectedIDs(selectedID) {
|
|
33
|
-
if (!selectedID) {
|
|
34
|
-
this._selectedIDs = [];
|
|
35
|
-
return;
|
|
36
|
-
}
|
|
37
|
-
if (this.selectedIDs.includes(selectedID)) {
|
|
38
|
-
this.selectedIDs = this.selectedIDs.filter((id) => id !== selectedID);
|
|
39
|
-
} else {
|
|
40
|
-
this.selectedIDs = [...this.selectedIDs, selectedID];
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
setSelectedIDs(id, isAppend = false) {
|
|
44
|
-
if (isAppend) {
|
|
45
|
-
this.updateSelectedIDs(id);
|
|
46
|
-
} else {
|
|
47
|
-
this.selectedIDs = id ? [id] : [];
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
selectAll() {
|
|
51
|
-
this.selectedIDs = this.visibleDataList.map((i) => i.id);
|
|
52
|
-
this.toolInstance.render();
|
|
53
|
-
}
|
|
54
|
-
toStashDataList() {
|
|
55
|
-
if (this.selectedIDs.length > 0) {
|
|
56
|
-
this.stashDataList = _.cloneDeep(this.dataList.filter((i) => this.selectedIDs.includes(i.id)));
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
toUnStashDataList() {
|
|
60
|
-
if (this.stashDataList) {
|
|
61
|
-
const _stashDataList = this.stashDataList;
|
|
62
|
-
this.stashDataList = void 0;
|
|
63
|
-
return _stashDataList;
|
|
64
|
-
}
|
|
65
|
-
return void 0;
|
|
66
|
-
}
|
|
67
|
-
mergeStashData(setDataList) {
|
|
68
|
-
const stashList = this.toUnStashDataList();
|
|
69
|
-
if (!stashList) {
|
|
70
|
-
return;
|
|
71
|
-
}
|
|
72
|
-
const mergedDataList = _(this.dataList).keyBy("id").merge(_.keyBy(stashList, "id")).values().value();
|
|
73
|
-
setDataList(mergedDataList);
|
|
74
|
-
this.toolInstance.render();
|
|
75
|
-
}
|
|
76
|
-
isIdSelected(id) {
|
|
77
|
-
return this.selectedIDs.includes(id);
|
|
78
|
-
}
|
|
79
|
-
triggerKeyboardEvent(e, setDataList) {
|
|
80
|
-
if (e.ctrlKey) {
|
|
81
|
-
if (e.key === "v") {
|
|
82
|
-
this.mergeStashData(setDataList);
|
|
83
|
-
return true;
|
|
84
|
-
}
|
|
85
|
-
if (e.key === "a") {
|
|
86
|
-
this.selectAll();
|
|
87
|
-
return true;
|
|
88
|
-
}
|
|
89
|
-
if (e.key === "c") {
|
|
90
|
-
this.toStashDataList();
|
|
91
|
-
return true;
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
return false;
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
export { Selection as default };
|