@labelbee/lb-annotation 1.14.0-alpha.19 → 1.14.0-alpha.20
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.
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var THREE=require("three"),lbUtils=require("@labelbee/lb-utils"),highlightWorker$1=require("../../_virtual/highlightWorker.js"),filterBoxWorker=require("../../_virtual/filterBoxWorker.js"),polygonTool=require("../../utils/tool/polygonTool.js"),uuid=require("../../utils/uuid.js"),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(m){if(m&&m.__esModule)return m;var t=Object.create(null);return m&&Object.keys(m).forEach(function(e){if(e!=="default"){var r=Object.getOwnPropertyDescriptor(m,e);Object.defineProperty(t,e,r.get?r:{enumerable:!0,get:function(){return m[e]}})}}),t.default=m,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=(m,t,e)=>t in m?__defProp(m,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):m[t]=e,__spreadValues=(m,t)=>{for(var e in t||(t={}))__hasOwnProp.call(t,e)&&__defNormalProp(m,e,t[e]);if(__getOwnPropSymbols)for(var e of __getOwnPropSymbols(t))__propIsEnum.call(t,e)&&__defNormalProp(m,e,t[e]);return m},__spreadProps=(m,t)=>__defProps(m,__getOwnPropDescs(t)),__async=(m,t,e)=>new Promise((r,
|
|
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(m){if(m&&m.__esModule)return m;var t=Object.create(null);return m&&Object.keys(m).forEach(function(e){if(e!=="default"){var r=Object.getOwnPropertyDescriptor(m,e);Object.defineProperty(t,e,r.get?r:{enumerable:!0,get:function(){return m[e]}})}}),t.default=m,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=(m,t,e)=>t in m?__defProp(m,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):m[t]=e,__spreadValues=(m,t)=>{for(var e in t||(t={}))__hasOwnProp.call(t,e)&&__defNormalProp(m,e,t[e]);if(__getOwnPropSymbols)for(var e of __getOwnPropSymbols(t))__propIsEnum.call(t,e)&&__defNormalProp(m,e,t[e]);return m},__spreadProps=(m,t)=>__defProps(m,__getOwnPropDescs(t)),__async=(m,t,e)=>new Promise((r,o)=>{var s=n=>{try{i(e.next(n))}catch(c){o(c)}},a=n=>{try{i(e.throw(n))}catch(c){o(c)}},i=n=>n.done?r(n.value):Promise.resolve(n.value).then(s,a);i((e=e.apply(m,t)).next())});const DEFAULT_DISTANCE=30,highlightWorker=new highlightWorker$1({type:"module"});class PointCloud{constructor({container:t,noAppend:e,isOrthographicCamera:r,orthographicParams:o,backgroundColor:s="#4C4C4C",config:a}){this.zAxisLimit=10,this.initCameraPosition=this.DEFAULT_INIT_CAMERA_POSITION,this.isOrthographicCamera=!1,this.pointsUuid="",this.pointCloudObjectName="pointCloud",this.rangeObjectName="range",this.showDirection=!0,this.pointsMaterialSize=1,this.addSphereToSense=(i,n="blue")=>{var c;const h=(c=i.id)!=null?c:uuid();this.removeObjectByName(h);const{radius:l,widthSegments:d,heightSegments:g}=lbUtils.DEFAULT_SPHERE_PARAMS,{center:x}=i,p=new THREE__namespace.Group,u=new THREE__namespace.SphereGeometry(l,d,g),y=new THREE__namespace.MeshBasicMaterial({color:n}),f=new THREE__namespace.Mesh(u,y);f.position.set(x.x,x.y,x.z),p.add(f),p.name=h,this.scene.add(p)},this.generateSphere=i=>{const{fill:n}=lbUtils.toolStyleConverter.getColorFromConfig({attribute:i.attribute},__spreadProps(__spreadValues({},this.config),{attributeConfigurable:!0}),{});this.addSphereToSense(i,n),this.render()},this.generateSpheres=i=>{i.forEach(n=>{const{fill:c}=lbUtils.toolStyleConverter.getColorFromConfig({attribute:n.attribute},__spreadProps(__spreadValues({},this.config),{attributeConfigurable:!0}),{});this.addSphereToSense(n,c)}),this.render()},this.addBoxToSense=(i,n=16777215)=>{var c;const h=(c=i.id)!=null?c:uuid();this.removeObjectByName(h);const{center:l,width:d,height:g,depth:x,rotation:p}=i,u=new THREE__namespace.Group,y=new THREE__namespace.BoxGeometry(d,g,x),f=new THREE__namespace.MeshBasicMaterial({color:"blue"}),w=new THREE__namespace.Mesh(y,f),C=new THREE__namespace.BoxHelper(w,n),P=this.generateBoxArrow(i);u.add(C),u.add(P),l&&u.position.set(l.x,l.y,l.z),p&&u.rotation.set(0,0,p),u.name=h,this.scene.add(u)},this.applyCameraTarget=i=>{if(this.camera.type==="OrthographicCamera"&&i){const n=this.getOrthographicCameraTarget(i);this.updateCameraZoom(i.zoom),this.updateCamera(i.position,n)}},this.overridePointShader=i=>{i.vertexShader=`
|
|
2
2
|
attribute float sizes;
|
|
3
3
|
attribute float visibility;
|
|
4
4
|
varying float vVisible;
|
|
@@ -8,4 +8,4 @@
|
|
|
8
8
|
varying float vVisible;
|
|
9
9
|
${i.fragmentShader}`.replace("#include <clipping_planes_fragment>",`
|
|
10
10
|
if (vVisible < 0.5) discard;
|
|
11
|
-
#include <clipping_planes_fragment>`)},this.loadPCDFile=(i,o)=>__async(this,null,function*(){this.clearPointCloud(),this.currentPCDSrc=i;const{points:c,color:h}=yield this.cacheInstance.loadPCDFile(i),l=new THREE__namespace.BufferGeometry;l.setAttribute("position",new THREE__namespace.BufferAttribute(c,3)),l.setAttribute("color",new THREE__namespace.BufferAttribute(h,3));const d=new THREE__namespace.Points(l);this.renderPointCloud(d,o)}),this.loadPCDFileByBox=(i,o,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({},o),{width:o.width+p,height:o.height+u,depth:o.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 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,d=new THREE__namespace.ArrowHelper(o,c,h,l);return d.visible=this.showDirection,d},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,d=500/h;return{left:a,right:i,top:o,bottom:c,near:h,far:l,zoom:d}}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)}updateCameraBySphere(t,e){const{center:r}=t,{radius:n}=lbUtils.DEFAULT_SPHERE_PARAMS,s=this.getCameraVector(r,0,{width:n*2,height:n*2,depth:n*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 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(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,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}filterNoise(t){let e=[...t];e.sort((l,d)=>l.z-d.z);const r=Math.floor(e.length*.05),n=e[r];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 i=Math.floor(e.length*s),o=Math.floor(e.length*(1-s));e=e.slice(i,o),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 n=[...t,t[0]];e.forEach(({x:i,y:o})=>{t.forEach((c,h)=>{const l=n[h+1],d=MathUtils.default.getFootOfPerpendicular({x:i,y:o},c,l,!1,!0).length;(!r[h]||d<r[h].distance)&&(r[h]={distance:d,point:{x:i,y:o}})})}),n=[t[t.length-1],...t,t[0]];const s=[r[r.length-1],...r];return t.map((i,o)=>{const c=n[o],h=n[o+1],l=n[o+2];return lbUtils.PointCloudUtils.getIntersectionBySlope({p1:s[o].point,line1:[c,h],p2:s[o+1].point,line2:[h,l]})})}getSensesPointZAxisInPolygon(t,e,r){var n,s,a;const i=this.scene.children.find(p=>p.uuid===this.pointsUuid);let o=0,c=0,h=0,l=0,d=[],g=[];const x=((a=(s=(n=i==null?void 0:i.geometry)==null?void 0:n.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),o=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:o,count:h,zCount:l,fittedCoordinates:d}):{maxZ:c,minZ:o,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: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)}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: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}}getSpherePoint2DCoordinate(t){const{center:e,attribute:r,id:n,valid:s}=t,{radius:a}=lbUtils.DEFAULT_SPHERE_PARAMS,i={center:e,attribute:r,id:n,valid:s,width:a*2,height:a*2,depth:a*2,rotation:0},o=new THREE__namespace.Matrix4().premultiply(this.camera.matrixWorldInverse).premultiply(this.camera.projectionMatrix),c=new THREE__namespace.Matrix4().premultiply(this.getModelTransformationMatrix(i)).premultiply(o).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,n={x:-(e.y-this.containerWidth/2),y:-(e.x-this.containerHeight/2)},s=this.containerWidth/(r*2),a=this.containerHeight/(r*2);return{point2d:n,zoom:Math.min(s,a)/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(u=>new THREE__namespace.Vector3(u.x,u.y,u.z)).map(u=>u.applyMatrix4(a)),[o,c,h,l]=i,d=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:d,height:n.height,depth:n.depth+e,rotation:n.rotation})}}filterZAxisPoints(t){const e=t||this.scene.children.find(r=>r.uuid===this.pointsUuid);if(e){const{attributes:r}=e.geometry,{position:n}=r,s=[],{count:a}=n;for(let i=0;i<a;i++){const o=n.getZ(i);s.push(o>this.zAxisLimit?0:1)}e.geometry.setAttribute("visibility",new THREE__namespace.Float32BufferAttribute(s,1)),e.geometry.attributes.visibility.needsUpdate=!0}}render(){this.renderer.render(this.scene,this.camera)}}exports.createThreeMatrix4=matrix.createThreeMatrix4,exports.getCuboidFromPointCloudBox=matrix.getCuboidFromPointCloudBox,exports.lidar2image=matrix.lidar2image,exports.pointCloudLidar2image=matrix.pointCloudLidar2image,exports.rotatePoint=matrix.rotatePoint,exports.transferKitti2Matrix=matrix.transferKitti2Matrix,exports.PointCloud=PointCloud;
|
|
11
|
+
#include <clipping_planes_fragment>`)},this.loadPCDFile=(i,n)=>__async(this,null,function*(){this.clearPointCloud(),this.currentPCDSrc=i;const{points:c,color:h}=yield this.cacheInstance.loadPCDFile(i),l=new THREE__namespace.BufferGeometry;l.setAttribute("position",new THREE__namespace.BufferAttribute(c,3)),l.setAttribute("color",new THREE__namespace.BufferAttribute(h,3));const 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;
|
|
@@ -48,6 +48,7 @@ export declare class PointCloud {
|
|
|
48
48
|
private cacheInstance;
|
|
49
49
|
private showDirection;
|
|
50
50
|
private currentPCDSrc?;
|
|
51
|
+
private pointsMaterialSize;
|
|
51
52
|
/**
|
|
52
53
|
* Record the src of Highlight PCD.
|
|
53
54
|
*
|
|
@@ -94,7 +95,7 @@ export declare class PointCloud {
|
|
|
94
95
|
addSphereToSense: (sphereParams: IPointCloudSphere, color?: string) => void;
|
|
95
96
|
generateSphere: (sphereParams: IPointCloudSphere) => void;
|
|
96
97
|
generateSpheres: (spheres: IPointCloudSphere[]) => void;
|
|
97
|
-
|
|
98
|
+
addBoxToSense: (boxParams: IPointCloudBox, color?: THREE.ColorRepresentation) => void;
|
|
98
99
|
generateBoxes(boxes: IPointCloudBox[]): void;
|
|
99
100
|
/**
|
|
100
101
|
* Get OrthographicCamera Params to Change
|
|
@@ -365,9 +366,13 @@ export declare class PointCloud {
|
|
|
365
366
|
applyZAxisPoints: (zAxisLimit: number) => void;
|
|
366
367
|
/**
|
|
367
368
|
* Update point size
|
|
368
|
-
* @param
|
|
369
|
+
* @param param0
|
|
370
|
+
* @returns
|
|
369
371
|
*/
|
|
370
|
-
updatePointSize: (zoomIn
|
|
372
|
+
updatePointSize: ({ zoomIn, customSize }: {
|
|
373
|
+
zoomIn?: boolean | undefined;
|
|
374
|
+
customSize?: number | undefined;
|
|
375
|
+
}) => void;
|
|
371
376
|
render(): void;
|
|
372
377
|
}
|
|
373
378
|
export * from './matrix';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import*as c from"three";import{toolStyleConverter as B,PerspectiveShiftUtils as b,EPerspectiveView as w,PointCloudUtils as
|
|
1
|
+
import*as c from"three";import{toolStyleConverter as B,PerspectiveShiftUtils as b,EPerspectiveView as w,PointCloudUtils as V,DEFAULT_SPHERE_PARAMS as z}from"@labelbee/lb-utils";import k from"../../_virtual/highlightWorker.js";import L from"../../_virtual/filterBoxWorker.js";import{isInPolygon as N}from"../../utils/tool/polygonTool.js";import T from"../../utils/uuid.js";import E from"../../utils/MathUtils.js";import{PCDLoader as F}from"./PCDLoader.js";import{OrbitControls as R}from"./OrbitControls.js";import{PointCloudCache as W}from"./cache.js";import{getCuboidFromPointCloudBox as O}from"./matrix.js";export{createThreeMatrix4,getCuboidFromPointCloudBox,lidar2image,pointCloudLidar2image,rotatePoint,transferKitti2Matrix}from"./matrix.js";import"../../constant/tool.js";import"../scheduler.js";var Z=Object.defineProperty,H=Object.defineProperties,U=Object.getOwnPropertyDescriptors,A=Object.getOwnPropertySymbols,G=Object.prototype.hasOwnProperty,$=Object.prototype.propertyIsEnumerable,_=(f,t,e)=>t in f?Z(f,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):f[t]=e,M=(f,t)=>{for(var e in t||(t={}))G.call(t,e)&&_(f,e,t[e]);if(A)for(var e of A(t))$.call(t,e)&&_(f,e,t[e]);return f},P=(f,t)=>H(f,U(t)),S=(f,t,e)=>new Promise((r,o)=>{var s=n=>{try{i(e.next(n))}catch(h){o(h)}},a=n=>{try{i(e.throw(n))}catch(h){o(h)}},i=n=>n.done?r(n.value):Promise.resolve(n.value).then(s,a);i((e=e.apply(f,t)).next())});const X=30,j=new k({type:"module"});class Y{constructor({container:t,noAppend:e,isOrthographicCamera:r,orthographicParams:o,backgroundColor:s="#4C4C4C",config:a}){this.zAxisLimit=10,this.initCameraPosition=this.DEFAULT_INIT_CAMERA_POSITION,this.isOrthographicCamera=!1,this.pointsUuid="",this.pointCloudObjectName="pointCloud",this.rangeObjectName="range",this.showDirection=!0,this.pointsMaterialSize=1,this.addSphereToSense=(i,n="blue")=>{var h;const l=(h=i.id)!=null?h:T();this.removeObjectByName(l);const{radius:d,widthSegments:p,heightSegments:g}=z,{center:y}=i,u=new c.Group,m=new c.SphereGeometry(d,p,g),C=new c.MeshBasicMaterial({color:n}),x=new c.Mesh(m,C);x.position.set(y.x,y.y,y.z),u.add(x),u.name=l,this.scene.add(u)},this.generateSphere=i=>{const{fill:n}=B.getColorFromConfig({attribute:i.attribute},P(M({},this.config),{attributeConfigurable:!0}),{});this.addSphereToSense(i,n),this.render()},this.generateSpheres=i=>{i.forEach(n=>{const{fill:h}=B.getColorFromConfig({attribute:n.attribute},P(M({},this.config),{attributeConfigurable:!0}),{});this.addSphereToSense(n,h)}),this.render()},this.addBoxToSense=(i,n=16777215)=>{var h;const l=(h=i.id)!=null?h:T();this.removeObjectByName(l);const{center:d,width:p,height:g,depth:y,rotation:u}=i,m=new c.Group,C=new c.BoxGeometry(p,g,y),x=new c.MeshBasicMaterial({color:"blue"}),v=new c.Mesh(C,x),D=new c.BoxHelper(v,n),I=this.generateBoxArrow(i);m.add(D),m.add(I),d&&m.position.set(d.x,d.y,d.z),u&&m.rotation.set(0,0,u),m.name=l,this.scene.add(m)},this.applyCameraTarget=i=>{if(this.camera.type==="OrthographicCamera"&&i){const n=this.getOrthographicCameraTarget(i);this.updateCameraZoom(i.zoom),this.updateCamera(i.position,n)}},this.overridePointShader=i=>{i.vertexShader=`
|
|
2
2
|
attribute float sizes;
|
|
3
3
|
attribute float visibility;
|
|
4
4
|
varying float vVisible;
|
|
@@ -8,4 +8,4 @@ import*as c from"three";import{toolStyleConverter as B,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)=>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,o)}),this.loadPCDFileByBox=(i,o,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({},o),{width:o.width+u,height:o.height+m,depth:o.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 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 R(this.camera,this.renderer.domElement),this.pcdLoader=new E,this.axesHelper=new c.AxesHelper(1e3),this.scene.add(this.camera),e||t.appendChild(this.renderer.domElement),this.init(),this.cacheInstance=W.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]=B.getColorFromConfig({attribute:r.attribute},P(M({},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,r){const{center:n,width:s,height:a,depth:i,rotation:o}=t,h=this.getCameraVector(n,o,{width:s,height:a,depth:i},e);return r?(this.updateCamera(r,n),new c.Vector3(r.x,r.y,r.z)):(this.updateCamera(h,n),h)}updateCameraBySphere(t,e){const{center:r}=t,{radius:n}=z,s=this.getCameraVector(r,0,{width:n*2,height:n*2,depth:n*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 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}=A(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 g=new L;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,n=w.Front,s=X){let a=b.frontViewMatrix4(s);switch(n){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),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=>A(o)),a=this.getAllAttributeColor(s),i={cuboidList:s,position:e.geometry.attributes.position.array,color:e.geometry.attributes.color.array,colorList:a};j.postMessage(i),j.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}filterNoise(t){let e=[...t];e.sort((d,p)=>d.z-p.z);const r=Math.floor(e.length*.05),n=e[r];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 i=Math.floor(e.length*s),o=Math.floor(e.length*(1-s));e=e.slice(i,o),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 n=[...t,t[0]];e.forEach(({x:i,y:o})=>{t.forEach((h,l)=>{const d=n[l+1],p=F.getFootOfPerpendicular({x:i,y:o},h,d,!1,!0).length;(!r[l]||p<r[l].distance)&&(r[l]={distance:p,point:{x:i,y:o}})})}),n=[t[t.length-1],...t,t[0]];const s=[r[r.length-1],...r];return t.map((i,o)=>{const h=n[o],l=n[o+1],d=n[o+2];return D.getIntersectionBySlope({p1:s[o].point,line1:[h,l],p2:s[o+1].point,line2:[l,d]})})}getSensesPointZAxisInPolygon(t,e,r){var n,s,a;const i=this.scene.children.find(u=>u.uuid===this.pointsUuid);let o=0,h=0,l=0,d=0,p=[],g=[];const x=((a=(s=(n=i==null?void 0:i.geometry)==null?void 0:n.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];N({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),o=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:o,count:l,zCount:d,fittedCoordinates:p}):{maxZ:h,minZ:o,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: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,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: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}}getSpherePoint2DCoordinate(t){const{center:e,attribute:r,id:n,valid:s}=t,{radius:a}=z,i={center:e,attribute:r,id:n,valid:s,width:a*2,height:a*2,depth:a*2,rotation:0},o=new c.Matrix4().premultiply(this.camera.matrixWorldInverse).premultiply(this.camera.projectionMatrix),h=new c.Matrix4().premultiply(this.getModelTransformationMatrix(i)).premultiply(o).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,n={x:-(e.y-this.containerWidth/2),y:-(e.x-this.containerHeight/2)},s=this.containerWidth/(r*2),a=this.containerHeight/(r*2);return{point2d:n,zoom:Math.min(s,a)/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=P(M({},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=P(M({},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)),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(n.center.x,n.center.y,n.center.z));return{newBoxParams:P(M({},n),{center:{x:n.center.x-x.x,y:n.center.y-x.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{Y as PointCloud};
|
|
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,y)=>S(this,null,function*(){const{width:u=0,height:m=0,depth:C=0}=h!=null?h:{},x=yield this.filterPointsByBox(P(M({},n),{width:n.width+u,height:n.height+m,depth:n.depth+C}),g,y);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 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 R(this.camera,this.renderer.domElement),this.pcdLoader=new F,this.axesHelper=new c.AxesHelper(1e3),this.scene.add(this.camera),e||t.appendChild(this.renderer.domElement),this.init(),this.cacheInstance=W.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}=O(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 L;g.postMessage(d),g.onmessage=y=>{const{color:u,position:m,num:C}=y.data,x=new c.BufferGeometry;x.setAttribute("position",new c.Float32BufferAttribute(m,3)),x.setAttribute("color",new c.Float32BufferAttribute(u,3)),x.computeBoundingSphere(),g.terminate(),p({geometry:x,num:C})}})}return Promise.resolve(void 0)}getCameraVector(t,e,r,o=w.Front,s=X){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=>O(h)),i=this.getAllAttributeColor(a),n={cuboidList:a,position:e.geometry.attributes.position.array,color:e.geometry.attributes.color.array,colorList:i};j.postMessage(n),j.onmessage=h=>{const{color:l}=h.data,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=E.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 V.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 y=((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<y.length;u+=3){const m=y[u],C=y[u+1],x=y[u+2];N({x:m,y:C},t)&&(x||x===0)&&g.push({x:m,y:C,z:x})}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)),y=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-y.x,y:o.center.y-y.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{Y as PointCloud};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@labelbee/lb-annotation",
|
|
3
|
-
"version": "1.14.0-alpha.
|
|
3
|
+
"version": "1.14.0-alpha.20",
|
|
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.7.0-alpha.
|
|
97
|
+
"@labelbee/lb-utils": "1.7.0-alpha.10",
|
|
98
98
|
"@turf/turf": "5.1.6",
|
|
99
99
|
"color-rgba": "^2.3.0",
|
|
100
100
|
"lodash": "^4.17.20",
|