@labelbee/lb-annotation 1.16.0-alpha.5 → 1.16.0-alpha.7

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"),segmentation=require("./segmentation.js"),index=require("./store/index.js"),index$1=require("./render/index.js"),eventListener=require("../toolOperation/eventListener.js");require("../../constant/tool.js"),require("../scheduler.js");function _interopNamespace(g){if(g&&g.__esModule)return g;var t=Object.create(null);return g&&Object.keys(g).forEach(function(e){if(e!=="default"){var i=Object.getOwnPropertyDescriptor(g,e);Object.defineProperty(t,e,i.get?i:{enumerable:!0,get:function(){return g[e]}})}}),t.default=g,Object.freeze(t)}var THREE__namespace=_interopNamespace(THREE),__defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnPropDescs=Object.getOwnPropertyDescriptors,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(g,t,e)=>t in g?__defProp(g,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):g[t]=e,__spreadValues=(g,t)=>{for(var e in t||(t={}))__hasOwnProp.call(t,e)&&__defNormalProp(g,e,t[e]);if(__getOwnPropSymbols)for(var e of __getOwnPropSymbols(t))__propIsEnum.call(t,e)&&__defNormalProp(g,e,t[e]);return g},__spreadProps=(g,t)=>__defProps(g,__getOwnPropDescs(t)),__async=(g,t,e)=>new Promise((i,r)=>{var s=h=>{try{n(e.next(h))}catch(o){r(o)}},a=h=>{try{n(e.throw(h))}catch(o){r(o)}},n=h=>h.done?i(h.value):Promise.resolve(h.value).then(s,a);n((e=e.apply(g,t)).next())});const DEFAULT_DISTANCE=30,highlightWorker=new highlightWorker$1({type:"module"});class PointCloud extends eventListener{constructor({container:t,noAppend:e,isOrthographicCamera:i,orthographicParams:r,backgroundColor:s="#4C4C4C",config:a,isSegment:n,checkMode:h}){super();this.zAxisLimit=10,this.initCameraPosition=this.DEFAULT_INIT_CAMERA_POSITION,this.isOrthographicCamera=!1,this.pointsUuid="",this.pointCloudObjectName="pointCloud",this.rangeObjectName="range",this.showDirection=!0,this.pointsMaterialSize=1,this.isSegment=!1,this.checkMode=!1,this.nextTick=()=>{!this.segmentOperation||this.segmentOperation._raycasting()},this.keydown=o=>{if(!!this.store)switch(o.key){case" ":this.controls.enablePan=!0,this.store.setForbidOperation(!0);break}},this.keyup=o=>{if(!!this.store)switch(o.key){case" ":this.controls.enablePan=!1,this.store.setForbidOperation(!1);break}},this.addSphereToSense=(o,c="blue")=>{var l;const d=(l=o.id)!=null?l:uuid();this.removeObjectByName(d,"sphere");const{radius:u,widthSegments:m,heightSegments:p}=lbUtils.DEFAULT_SPHERE_PARAMS,{center:f}=o,y=new THREE__namespace.Group,x=new THREE__namespace.SphereGeometry(u,m,p),C=new THREE__namespace.MeshBasicMaterial({color:c}),w=new THREE__namespace.Mesh(x,C);w.position.set(f.x,f.y,f.z),y.add(w),y.name=`sphere-${d}`,this.scene.add(y)},this.generateSphere=o=>{const{fill:c}=lbUtils.toolStyleConverter.getColorFromConfig({attribute:o.attribute},__spreadProps(__spreadValues({},this.config),{attributeConfigurable:!0}),{});this.addSphereToSense(o,c),this.render()},this.generateSpheres=o=>{o.forEach(c=>{const{fill:l}=lbUtils.toolStyleConverter.getColorFromConfig({attribute:c.attribute},__spreadProps(__spreadValues({},this.config),{attributeConfigurable:!0}),{});this.addSphereToSense(c,l)}),this.render()},this.addBoxToSense=(o,c=16777215)=>{var l;const d=(l=o.id)!=null?l:uuid();this.removeObjectByName(d,"box");const{center:u,width:m,height:p,depth:f,rotation:y}=o,x=new THREE__namespace.Group,C=new THREE__namespace.BoxGeometry(m,p,f),w=new THREE__namespace.MeshBasicMaterial({color:"blue"}),b=new THREE__namespace.Mesh(C,w),P=new THREE__namespace.BoxHelper(b,c),M=this.generateBoxArrow(o),v=this.generateBoxTrackID(o);v&&x.add(v),x.add(P),x.add(M),u&&x.position.set(u.x,u.y,u.z),y&&x.rotation.set(0,0,y),x.name=`box-${d}`,this.scene.add(x)},this.applyCameraTarget=o=>{if(this.camera.type==="OrthographicCamera"&&o){const c=this.getOrthographicCameraTarget(o);this.updateCameraZoom(o.zoom),this.updateCamera(o.position,c)}},this.initShaderMaterial=()=>({vertexShader:`
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var THREE=require("three"),lbUtils=require("@labelbee/lb-utils"),highlightWorker$1=require("../../_virtual/highlightWorker.js"),filterBoxWorker=require("../../_virtual/filterBoxWorker.js"),polygonTool=require("../../utils/tool/polygonTool.js"),uuid=require("../../utils/uuid.js"),MathUtils=require("../../utils/MathUtils.js"),PCDLoader=require("./PCDLoader.js"),OrbitControls=require("./OrbitControls.js"),cache=require("./cache.js"),matrix=require("./matrix.js"),segmentation=require("./segmentation.js"),index=require("./store/index.js"),index$1=require("./render/index.js"),eventListener=require("../toolOperation/eventListener.js");require("../../constant/tool.js"),require("../scheduler.js");function _interopNamespace(g){if(g&&g.__esModule)return g;var t=Object.create(null);return g&&Object.keys(g).forEach(function(e){if(e!=="default"){var i=Object.getOwnPropertyDescriptor(g,e);Object.defineProperty(t,e,i.get?i:{enumerable:!0,get:function(){return g[e]}})}}),t.default=g,Object.freeze(t)}var THREE__namespace=_interopNamespace(THREE),__defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnPropDescs=Object.getOwnPropertyDescriptors,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(g,t,e)=>t in g?__defProp(g,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):g[t]=e,__spreadValues=(g,t)=>{for(var e in t||(t={}))__hasOwnProp.call(t,e)&&__defNormalProp(g,e,t[e]);if(__getOwnPropSymbols)for(var e of __getOwnPropSymbols(t))__propIsEnum.call(t,e)&&__defNormalProp(g,e,t[e]);return g},__spreadProps=(g,t)=>__defProps(g,__getOwnPropDescs(t)),__async=(g,t,e)=>new Promise((i,r)=>{var s=h=>{try{n(e.next(h))}catch(o){r(o)}},a=h=>{try{n(e.throw(h))}catch(o){r(o)}},n=h=>h.done?i(h.value):Promise.resolve(h.value).then(s,a);n((e=e.apply(g,t)).next())});const DEFAULT_DISTANCE=30,highlightWorker=new highlightWorker$1({type:"module"});class PointCloud extends eventListener{constructor({container:t,noAppend:e,isOrthographicCamera:i,orthographicParams:r,backgroundColor:s="#4C4C4C",config:a,isSegment:n,checkMode:h}){super();this.zAxisLimit=10,this.initCameraPosition=this.DEFAULT_INIT_CAMERA_POSITION,this.isOrthographicCamera=!1,this.pointsUuid="",this.pointCloudObjectName="pointCloud",this.rangeObjectName="range",this.showDirection=!0,this.pointsMaterialSize=1,this.isSegment=!1,this.checkMode=!1,this.nextTick=()=>{!this.segmentOperation||this.segmentOperation._raycasting()},this.keydown=o=>{if(!!this.store)switch(o.key){case" ":this.controls.enablePan=!0,this.store.setForbidOperation(!0);break}},this.keyup=o=>{if(!!this.store)switch(o.key){case" ":this.controls.enablePan=!1,this.store.setForbidOperation(!1);break}},this.addSphereToSense=(o,c="blue")=>{var l;const d=(l=o.id)!=null?l:uuid();this.removeObjectByName(d,"sphere");const{radius:u,widthSegments:m,heightSegments:p}=lbUtils.DEFAULT_SPHERE_PARAMS,{center:f}=o,y=new THREE__namespace.Group,x=new THREE__namespace.SphereGeometry(u,m,p),C=new THREE__namespace.MeshBasicMaterial({color:c}),w=new THREE__namespace.Mesh(x,C);w.position.set(f.x,f.y,f.z),y.add(w),y.name=`sphere${d}`,this.scene.add(y)},this.generateSphere=o=>{const{fill:c}=lbUtils.toolStyleConverter.getColorFromConfig({attribute:o.attribute},__spreadProps(__spreadValues({},this.config),{attributeConfigurable:!0}),{});this.addSphereToSense(o,c),this.render()},this.generateSpheres=o=>{o.forEach(c=>{const{fill:l}=lbUtils.toolStyleConverter.getColorFromConfig({attribute:c.attribute},__spreadProps(__spreadValues({},this.config),{attributeConfigurable:!0}),{});this.addSphereToSense(c,l)}),this.render()},this.addBoxToSense=(o,c=16777215)=>{var l;const d=(l=o.id)!=null?l:uuid();this.removeObjectByName(d,"box");const{center:u,width:m,height:p,depth:f,rotation:y}=o,x=new THREE__namespace.Group,C=new THREE__namespace.BoxGeometry(m,p,f),w=new THREE__namespace.MeshBasicMaterial({color:"blue"}),b=new THREE__namespace.Mesh(C,w),P=new THREE__namespace.BoxHelper(b,c),M=this.generateBoxArrow(o),v=this.generateBoxTrackID(o);v&&x.add(v),x.add(P),x.add(M),u&&x.position.set(u.x,u.y,u.z),y&&x.rotation.set(0,0,y),x.name=`box${d}`,this.scene.add(x)},this.applyCameraTarget=o=>{if(this.camera.type==="OrthographicCamera"&&o){const c=this.getOrthographicCameraTarget(o);this.updateCameraZoom(o.zoom),this.updateCamera(o.position,c)}},this.initShaderMaterial=()=>({vertexShader:`
2
2
  attribute vec3 dimensions;
3
3
  varying vec3 vDimensions;
4
4
  uniform float pointSize;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var lbUtils=require("@labelbee/lb-utils"),lassoSelector=require("./selector/lassoSelector.js"),circleSelector=require("./selector/circleSelector.js");class PointCloudSegmentOperation{constructor(e){this.onMouseMove=t=>{if((this.store.isCheckStatus||this.store.isReadyStatus)&&this.store.updateMouse({x:t.offsetX,y:t.offsetY}),this.isForbid||this.store.checkMode)return;const s={offsetX:t.offsetX,offsetY:t.offsetY,button:t.buttons};this.currentTool.mouseMove(s)},this.onMouseDown=t=>{this.isForbid||this.store.checkMode||this.currentTool.mouseDown(t)},this.onMouseUp=t=>{this.isForbid||this.store.orbiting===!0||this.store.checkMode||this.baseMouseDown(t)||this.currentTool.mouseUp(t)},this.baseMouseDown=t=>{if(!this.store.checkMode)switch(t.button){case 0:if(this.store.isReadyStatus||this.store.isCheckStatus)return this.store.checkPoints(),!0;break}},this._raycasting=()=>{if([lbUtils.EPointCloudSegmentStatus.Ready,lbUtils.EPointCloudSegmentStatus.Check].includes(this.store.segmentStatus)){const{mouse:t,camera:s,raycaster:o}=this.store;o.setFromCamera(t,s);const r=o.intersectObjects(this.store.allSegmentPoints,!1)[0];r?this.store.highlightPoints(r.object):(this.store.resetAllSegDataSizeAndRender(),this.store.resetHoverPointsID())}},this.dom=e.dom,this.store=e.store,this.lassoSelector=new lassoSelector(this.store),this.circleSelector=new circleSelector(this.store),this.currentTool=this.circleSelector,this.currentToolName="CircleSelector",this.dom.addEventListener("pointermove",this.onMouseMove.bind(this)),this.dom.addEventListener("pointerdown",this.onMouseDown.bind(this)),this.dom.addEventListener("pointerup",this.onMouseUp.bind(this)),this.updateSelector2Lasso=this.updateSelector2Lasso.bind(this),this.updateSelector2Circle=this.updateSelector2Circle.bind(this)}getCoordinate(e){const t=this.dom.getBoundingClientRect();return{x:e.clientX-t.left,y:e.clientY-t.top}}get forbidOperation(){return this.store.forbidOperation}get isForbid(){return this.forbidOperation}updateSelector2Lasso(){this.currentTool=this.lassoSelector,this.currentToolName="LassoSelector"}updateSelector2Circle(){this.currentTool=this.circleSelector,this.currentToolName="CircleSelector"}}exports.PointCloudSegmentOperation=PointCloudSegmentOperation;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var lbUtils=require("@labelbee/lb-utils"),lassoSelector=require("./selector/lassoSelector.js"),circleSelector=require("./selector/circleSelector.js");class PointCloudSegmentOperation{constructor(e){this.onMouseMove=t=>{if((this.store.isCheckStatus||this.store.isReadyStatus)&&this.store.updateMouse({x:t.offsetX,y:t.offsetY}),this.isForbid||this.store.checkMode)return;const s={offsetX:t.offsetX,offsetY:t.offsetY,button:t.buttons};this.currentTool.mouseMove(s)},this.onMouseDown=t=>{this.isForbid||this.store.checkMode||this.currentTool.mouseDown(t)},this.onMouseUp=t=>{this.isForbid||this.store.orbiting===!0||this.store.checkMode||this.baseMouseDown(t)||this.currentTool.mouseUp(t)},this.baseMouseDown=t=>{if(!this.store.checkMode)switch(t.button){case 0:if(this.store.isReadyStatus||this.store.isCheckStatus)return this.store.checkPoints(),!0;break}},this._raycasting=()=>{if([lbUtils.EPointCloudSegmentStatus.Ready,lbUtils.EPointCloudSegmentStatus.Check].includes(this.store.segmentStatus)){const{mouse:t,camera:s,raycaster:o}=this.store;o.setFromCamera(t,s);const r=o.intersectObjects(this.store.allSegmentPoints,!1)[0];r?this.store.highlightPoints(r.object):(this.store.resetAllSegDataSizeAndRender(),this.store.resetHoverPointsID())}},this.dom=e.dom,this.store=e.store,this.lassoSelector=new lassoSelector(this.store),this.circleSelector=new circleSelector(this.store),this.currentTool=this.lassoSelector,this.currentToolName="LassoSelector",this.dom.addEventListener("pointermove",this.onMouseMove.bind(this)),this.dom.addEventListener("pointerdown",this.onMouseDown.bind(this)),this.dom.addEventListener("pointerup",this.onMouseUp.bind(this)),this.updateSelector2Lasso=this.updateSelector2Lasso.bind(this),this.updateSelector2Circle=this.updateSelector2Circle.bind(this)}getCoordinate(e){const t=this.dom.getBoundingClientRect();return{x:e.clientX-t.left,y:e.clientY-t.top}}get forbidOperation(){return this.store.forbidOperation}get isForbid(){return this.forbidOperation}updateSelector2Lasso(){this.currentTool=this.lassoSelector,this.currentToolName="LassoSelector"}updateSelector2Circle(){this.currentTool=this.circleSelector,this.currentToolName="CircleSelector"}}exports.PointCloudSegmentOperation=PointCloudSegmentOperation;
@@ -1 +1 @@
1
- "use strict";var THREE=require("three"),lbUtils=require("@labelbee/lb-utils"),polygonTool=require("../../../utils/tool/polygonTool.js"),uuid=require("../../../utils/uuid.js"),fsm=require("./fsm.js");function _interopNamespace(o){if(o&&o.__esModule)return o;var t=Object.create(null);return o&&Object.keys(o).forEach(function(e){if(e!=="default"){var i=Object.getOwnPropertyDescriptor(o,e);Object.defineProperty(t,e,i.get?i:{enumerable:!0,get:function(){return o[e]}})}}),t.default=o,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=(o,t,e)=>t in o?__defProp(o,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):o[t]=e,__spreadValues=(o,t)=>{for(var e in t||(t={}))__hasOwnProp.call(t,e)&&__defNormalProp(o,e,t[e]);if(__getOwnPropSymbols)for(var e of __getOwnPropSymbols(t))__propIsEnum.call(t,e)&&__defNormalProp(o,e,t[e]);return o},__spreadProps=(o,t)=>__defProps(o,__getOwnPropDescs(t));const DEFAULT_PREFIX="LABELBEE_CANVAS_";class PointCloudStore{constructor({container:t,scene:e,camera:i,renderer:a,emit:n,on:r,unbind:h,checkMode:m}){this.canvas2d=null,this.polygon2d=[],this.forbidOperation=!1,this.raycaster=new THREE__namespace.Raycaster,this.mouse=new THREE__namespace.Vector2,this.cloudData=new Map,this.originPoints=new Float32Array([]),this.segmentData=new Map,this.hoverPointsID="",this.segmentMode=lbUtils.EPointCloudSegmentMode.Add,this.segmentCoverMode=lbUtils.EPointCloudSegmentCoverMode.Cover,this.segmentFocusMode=lbUtils.EPointCloudSegmentFocusMode.Unfocus,this.hideSegment=!1,this.checkMode=!1,this.updatePointCloud=!1,this.addPointCloud=!1,this.orbiting=!1,this.currentAttribute="",this.highlightAttribute="",this.hiddenAttributes=[],this.pointCloudObjectName="pointCloud",this.updatePointCloudBySegment=s=>{this.segmentData.forEach((d,u)=>{var l;if(u!==((l=this.cacheSegData)==null?void 0:l.id)){const S=this.scene.getObjectByName(u);S&&S.removeFromParent()}});const c=s==null?void 0:s.filter(d=>{var u;return!this.hiddenAttributes.some(l=>l===d.attribute)&&d.id!==((u=this.cacheSegData)==null?void 0:u.id)});(c==null?void 0:c.length)!==0&&c.map(d=>(this.emit("addNewPointsCloud",d),d)),this.emit("reRender3d")},this.updateCoverPoints=(s=[])=>{this.segmentData.forEach((c,d)=>{var u;if(d!==((u=this.cacheSegData)==null?void 0:u.id)){const l=lbUtils.PointCloudUtils.splitPointsFromIndexes(c.indexes,s),S=[];l.forEach(g=>{S.push(this.originPoints[g*3],this.originPoints[g*3+1],this.originPoints[g*3+2])}),c.indexes=l,c.points=new Float32Array(S);const p=this.scene.getObjectByName(d);p&&(p.geometry.setAttribute("position",new THREE__namespace.Float32BufferAttribute(new Float32Array(S),3)),p.geometry.attributes.position.needsUpdate=!0)}}),this.syncSegmentData(),this.emit("reRender3d")},this.container=t,this.scene=e,this.camera=i,this.renderer=a,this.emit=n,this.on=r,this.unbind=h,this.checkMode=m,this.createCanvas2d(),this.clearStash=this.clearStash.bind(this),this.addStash2Store=this.addStash2Store.bind(this),this.updateCheck2Edit=this.updateCheck2Edit.bind(this),this.setAttribute=this.setAttribute.bind(this),this.setSegmentMode=this.setSegmentMode.bind(this),this.setSegmentCoverMode=this.setSegmentCoverMode.bind(this),this.setSegmentFocusMode=this.setSegmentFocusMode.bind(this),this.switchSegmentHideMode=this.switchSegmentHideMode.bind(this),this.highlightPointsByAttribute=this.highlightPointsByAttribute.bind(this),this.setHiddenAttributes=this.setHiddenAttributes.bind(this),this.clearAllSegmentData=this.clearAllSegmentData.bind(this),this.deleteSelectedSegmentData=this.deleteSelectedSegmentData.bind(this),this.initMsg(),this.setupRaycaster()}initMsg(){this.on("clearStash",this.clearStash),this.on("addStash2Store",this.addStash2Store),this.on("updateCheck2Edit",this.updateCheck2Edit),this.on("setSegmentMode",this.setSegmentMode),this.on("setSegmentCoverMode",this.setSegmentCoverMode),this.on("setSegmentFocusMode",this.setSegmentFocusMode),this.on("switchHideSegment",this.switchSegmentHideMode),this.on("clearAllSegmentData",this.clearAllSegmentData),this.on("deleteSelectedSegmentData",this.deleteSelectedSegmentData)}unbindMsg(){this.unbind("clearStash",this.clearStash),this.unbind("addStash2Store",this.addStash2Store),this.unbind("updateCheck2Edit",this.updateCheck2Edit),this.unbind("setSegmentMode",this.setSegmentMode),this.unbind("setSegmentCoverMode",this.setSegmentCoverMode),this.unbind("setSegmentFocusMode",this.setSegmentFocusMode),this.unbind("switchHideSegment",this.switchSegmentHideMode),this.unbind("clearAllSegmentData",this.clearAllSegmentData),this.unbind("deleteSelectedSegmentData",this.deleteSelectedSegmentData)}get containerWidth(){return this.container.clientWidth}get containerHeight(){return this.container.clientHeight}get allSegmentPoints(){return this.scene.children.filter(t=>t.type==="Points"&&t.name!==this.pointCloudObjectName)}get selectedSegmentPoints(){var t,e;return this.scene.getObjectByName((e=(t=this.cacheSegData)==null?void 0:t.id)!=null?e:"")}get segmentStatus(){return fsm.segmentStatus}get isReadyStatus(){return fsm.isReadyStatus}get isCheckStatus(){return fsm.isCheckStatus}get isEditStatus(){return fsm.isEditStatus}get formatData(){const t=this.segmentData.values(),e=[];for(const i of t)e.push({attribute:i.attribute,id:i.id,indexes:i.indexes});return e}get pointCloudArray(){return this.scene.getObjectByName(this.pointCloudObjectName)}clearAllSegmentData(){this.segmentData=new Map,this.syncSegmentData()}updateCurrentSegment(t){this.updatePointCloudBySegment([]),this.segmentData=new Map;const{pointCloudArray:e}=this;if(!e)return;const i=e.geometry.attributes.position.array;t.forEach(a=>{const n=[];a.indexes.forEach(h=>{n.push(i[h*3],i[h*3+1],i[h*3+2])});const r=__spreadProps(__spreadValues({},a),{points:new Float32Array(n)});this.segmentData.set(a.id,r),this.emit("addNewPointsCloud",__spreadProps(__spreadValues({},a),{points:new Float32Array(n)}))}),this.syncSegmentData()}statusToggle(){fsm.statusToggle()}updateStatus2Edit(){fsm.updateStatus2Edit()}createCanvas(t){const e=document.createElement("canvas");return e.id=t,this.updateCanvasBasicStyle(e,{width:this.containerWidth,height:this.containerHeight},10),e}createCanvas2d(){this.canvas2d=this.createCanvas(`${DEFAULT_PREFIX}2d`),this.container.appendChild(this.canvas2d)}setupRaycaster(){this.raycaster.params={Mesh:{},Line:{threshold:1},LOD:{},Points:{threshold:.2},Sprite:{}}}setHoverPointsID(t){this.hoverPointsID=t}setSegmentMode(t){this.segmentMode=t}setSegmentCoverMode(t){this.segmentCoverMode=t}setSegmentFocusMode(t){this.segmentFocusMode=t,t===lbUtils.EPointCloudSegmentFocusMode.Focus&&this.emit("clearPointCloud"),t===lbUtils.EPointCloudSegmentFocusMode.Unfocus&&this.emit("loadPCDFile"),this.emit("reRender3d"),this.updatePointCloudBySegment(t===lbUtils.EPointCloudSegmentFocusMode.Focus?[]:[...this.segmentData.values()])}switchSegmentHideMode(t){this.hideSegment=t,this.updatePointCloudBySegment(t===!0?[]:[...this.segmentData.values()])}setHiddenAttributes(t){this.hiddenAttributes=t,this.updatePointCloudBySegment([...this.segmentData.values()])}setOriginPoints(t){this.originPoints=t}updateCanvasBasicStyle(t,e,i){const a=1;t.style.position="absolute",t.width=e.width*a,t.height=e.height*a,t.style.width=`${e.width}px`,t.style.height=`${e.height}px`,t.style.left="0",t.style.top="0",t.style.zIndex=`${i} `}syncPolygon2d(t){this.polygon2d=t}getPointsInPolygon(t){if(!this.isReadyStatus&&!this.isEditStatus)return;const e=t,i=this.originPoints;if(i){const a=i.length,n=[],r=[],h=[];for(let s=0;s<a;s+=3){const c=new THREE__namespace.Vector3(i[s],i[s+1],i[s+2]);c.project(this.camera);const d={x:0,y:0};if(d.x=Math.round(c.x*this.container.clientWidth/2+this.container.clientWidth/2),d.y=Math.round(-c.y*this.container.clientHeight/2+this.container.clientHeight/2),polygonTool.isInPolygon(d,e)){const l=i[s],S=i[s+1],p=i[s+2],g=lbUtils.PointCloudUtils.getCloudKeys(l,S,p);this.segmentMode===lbUtils.EPointCloudSegmentMode.Remove&&(this.cloudData.get(g).visible=!1,n.push(i[s],i[s+1],i[s+2]),h.push(s/3)),this.segmentMode===lbUtils.EPointCloudSegmentMode.Add&&(this.segmentCoverMode===lbUtils.EPointCloudSegmentCoverMode.Cover&&(n.push(i[s],i[s+1],i[s+2]),h.push(s/3),this.cloudData.get(g).visible===!0&&r.push(s/3)),this.segmentCoverMode===lbUtils.EPointCloudSegmentCoverMode.Uncover&&this.cloudData.get(g).visible===!1&&(n.push(i[s],i[s+1],i[s+2]),h.push(s/3)),this.cloudData.get(g).visible===!1&&(this.cloudData.get(g).visible=!0))}}if(h.length===0||!this.cacheSegData&&this.segmentMode===lbUtils.EPointCloudSegmentMode.Remove)return;const m=new Float32Array(n);this.updateStatusBySelector(m,r,h)}}updateStatusBySelector(t,e,i){switch(this.segmentMode){case lbUtils.EPointCloudSegmentMode.Add:if(this.cacheSegData){const{points:a,coverPoints:n=new Float32Array([])}=this.cacheSegData,r=a.length+t.length,h=new Float32Array(r);h.set(a,0),h.set(t,a.length);const m=[...new Set([...n,...e])];this.cacheSegData=__spreadProps(__spreadValues({},this.cacheSegData),{points:h,coverPoints:m,indexes:this.cacheSegData.indexes.concat(i)}),this.emit("updateNewPoints",this.cacheSegData)}else this.cacheSegData={id:uuid(),attribute:this.currentAttribute,points:t,coverPoints:e,indexes:i},this.emit("addNewPointsCloud",this.cacheSegData);break;case lbUtils.EPointCloudSegmentMode.Remove:if(this.cacheSegData){const{points:a,indexes:n}=this.cacheSegData;this.cacheSegData=__spreadProps(__spreadValues({},this.cacheSegData),{points:lbUtils.PointCloudUtils.splitPointsFromPoints(a,t),indexes:lbUtils.PointCloudUtils.splitPointsFromIndexes(n,i)}),this.emit("updateNewPoints",this.cacheSegData)}break}this.updateStatus2Edit(),this.emit("syncPointCloudStatus",{segmentStatus:this.segmentStatus,cacheSegData:this.cacheSegData})}syncPointCloudStatus(){this.statusToggle();const{segmentStatus:t,cacheSegData:e}=this;this.emit("syncPointCloudStatus",{segmentStatus:t,cacheSegData:e})}syncSegmentData(){this.emit("syncSegmentData",this.formatData)}addStash2Store(){this.isEditStatus&&this.cacheSegData&&(this.cacheSegData.coverPoints&&this.cacheSegData.coverPoints.length!==0&&this.updateCoverPoints(this.cacheSegData.coverPoints),delete this.cacheSegData.coverPoints,this.segmentData.set(this.cacheSegData.id,this.cacheSegData),this.cacheSegData=void 0,this.syncPointCloudStatus(),this.syncSegmentData())}updateCloudDataStatus(t,e){for(let i=0;i<t.length;i+=3){const a=t[i],n=t[i+1],r=t[i+2],h=lbUtils.PointCloudUtils.getCloudKeys(a,n,r),m=this.cloudData.get(h);Object.keys(e).forEach(s=>{m[s]=e[s]})}}clearStash(){if(this.isEditStatus&&this.cacheSegData){if(this.updateCloudDataStatus(this.cacheSegData.points,{visible:!1}),this.segmentData.has(this.cacheSegData.id)){const t=this.segmentData.get(this.cacheSegData.id);t&&(this.emit("updateNewPoints",t),this.updateCloudDataStatus(t==null?void 0:t.points,{visible:!0}))}else this.emit("clearStashRender");this.syncSegmentData(),this.cacheSegData=void 0,this.syncPointCloudStatus()}}deleteSelectedSegmentData(t=""){if((this.isCheckStatus||this.isEditStatus)&&this.cacheSegData){const e=this.scene.getObjectByName(t),{indexes:i}=this.cacheSegData;if(e&&i){const a=e.geometry.attributes.position.array;for(let n=0;n<i.length;n++){const r=this.cloudData.get(lbUtils.PointCloudUtils.getCloudKeys(a[n],a[n+1],a[n+2]));r&&(r.visible=!1)}this.resetSelectedSegmentStatus()}}}resetSelectedSegmentStatus(){this.cacheSegData=void 0,fsm.updateStatus2Ready(),this.emit("syncPointCloudStatus",{segmentStatus:this.segmentStatus,cacheSegData:this.cacheSegData})}updateCheck2Edit(){this.isCheckStatus&&this.syncPointCloudStatus()}checkPoints(){if(this.isReadyStatus||this.isCheckStatus){const t=this.segmentData.get(this.hoverPointsID);t?(this.cacheSegData=__spreadProps(__spreadValues({},t),{points:new Float32Array(t.points)}),fsm.updateStatus2Check(),this.emit("syncPointCloudStatus",{segmentStatus:this.segmentStatus,cacheSegData:this.cacheSegData})):this.resetSelectedSegmentStatus()}}editPoints(){const t=this.segmentData.get(this.hoverPointsID);t&&(this.cacheSegData=__spreadProps(__spreadValues({},t),{points:new Float32Array(t.points)}),this.emit("updateNewPoints"),this.syncPointCloudStatus())}setForbidOperation(t){this.forbidOperation=t}updateMouse(t){const e=t.x/this.containerWidth*2-1,i=-(t.y/this.containerHeight)*2+1;this.mouse.setX(e),this.mouse.setY(i)}resetAllSegDataSize(){this.highlightAttribute===""&&this.allSegmentPoints.forEach(t=>{var e;((e=this.cacheSegData)==null?void 0:e.id)!==t.name&&(t.material.size=5)})}resetHoverPointsID(){this.hoverPointsID=""}resetAllSegDataSizeAndRender(){this.resetAllSegDataSize(),this.emit("reRender3d")}highlightPoints(t){!(this.isCheckStatus||this.isReadyStatus)||(this.resetAllSegDataSize(),t.material.size=10,this.hoverPointsID=t.name,this.emit("reRender3d"))}highlightPointsByAttribute(t){this.highlightAttribute=t,this.segmentData.size!==0&&(this.resetAllSegDataSize(),this.segmentData.forEach((e,i)=>{if(e.attribute===t){const a=this.scene.getObjectByName(i);a&&(a==null?void 0:a.material)&&(a.material.size=10)}}),this.emit("reRender3d"))}setAttribute(t){this.currentAttribute=t}}module.exports=PointCloudStore;
1
+ "use strict";var THREE=require("three"),lbUtils=require("@labelbee/lb-utils"),polygonTool=require("../../../utils/tool/polygonTool.js"),uuid=require("../../../utils/uuid.js"),fsm=require("./fsm.js");function _interopNamespace(h){if(h&&h.__esModule)return h;var t=Object.create(null);return h&&Object.keys(h).forEach(function(e){if(e!=="default"){var i=Object.getOwnPropertyDescriptor(h,e);Object.defineProperty(t,e,i.get?i:{enumerable:!0,get:function(){return h[e]}})}}),t.default=h,Object.freeze(t)}var THREE__namespace=_interopNamespace(THREE),__defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnPropDescs=Object.getOwnPropertyDescriptors,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(h,t,e)=>t in h?__defProp(h,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):h[t]=e,__spreadValues=(h,t)=>{for(var e in t||(t={}))__hasOwnProp.call(t,e)&&__defNormalProp(h,e,t[e]);if(__getOwnPropSymbols)for(var e of __getOwnPropSymbols(t))__propIsEnum.call(t,e)&&__defNormalProp(h,e,t[e]);return h},__spreadProps=(h,t)=>__defProps(h,__getOwnPropDescs(t));const DEFAULT_PREFIX="LABELBEE_CANVAS_";class PointCloudStore{constructor({container:t,scene:e,camera:i,renderer:a,emit:n,on:r,unbind:o,checkMode:m}){this.canvas2d=null,this.polygon2d=[],this.forbidOperation=!1,this.raycaster=new THREE__namespace.Raycaster,this.mouse=new THREE__namespace.Vector2,this.cloudData=new Map,this.originPoints=new Float32Array([]),this.segmentData=new Map,this.hoverPointsID="",this.segmentMode=lbUtils.EPointCloudSegmentMode.Add,this.segmentCoverMode=lbUtils.EPointCloudSegmentCoverMode.Cover,this.segmentFocusMode=lbUtils.EPointCloudSegmentFocusMode.Unfocus,this.hideSegment=!1,this.checkMode=!1,this.updatePointCloud=!1,this.addPointCloud=!1,this.orbiting=!1,this.currentAttribute="",this.highlightAttribute="",this.hiddenAttributes=[],this.pointCloudObjectName="pointCloud",this.updatePointCloudBySegment=s=>{this.segmentData.forEach((d,u)=>{var l;if(u!==((l=this.cacheSegData)==null?void 0:l.id)){const S=this.scene.getObjectByName(u);S&&S.removeFromParent()}});const c=s==null?void 0:s.filter(d=>{var u;return!this.hiddenAttributes.some(l=>l===d.attribute)&&d.id!==((u=this.cacheSegData)==null?void 0:u.id)});(c==null?void 0:c.length)!==0&&c.map(d=>(this.emit("addNewPointsCloud",d),d)),this.emit("reRender3d")},this.updateCoverPoints=(s=[])=>{this.segmentData.forEach((c,d)=>{var u;if(d!==((u=this.cacheSegData)==null?void 0:u.id)){const l=lbUtils.PointCloudUtils.splitPointsFromIndexes(c.indexes,s),S=[];l.forEach(g=>{S.push(this.originPoints[g*3],this.originPoints[g*3+1],this.originPoints[g*3+2])}),c.indexes=l,c.points=new Float32Array(S);const p=this.scene.getObjectByName(d);p&&(p.geometry.setAttribute("position",new THREE__namespace.Float32BufferAttribute(new Float32Array(S),3)),p.geometry.attributes.position.needsUpdate=!0)}}),this.syncSegmentData(),this.emit("reRender3d")},this.container=t,this.scene=e,this.camera=i,this.renderer=a,this.emit=n,this.on=r,this.unbind=o,this.checkMode=m,this.createCanvas2d(),this.clearStash=this.clearStash.bind(this),this.addStash2Store=this.addStash2Store.bind(this),this.updateCheck2Edit=this.updateCheck2Edit.bind(this),this.setAttribute=this.setAttribute.bind(this),this.setSegmentMode=this.setSegmentMode.bind(this),this.setSegmentCoverMode=this.setSegmentCoverMode.bind(this),this.setSegmentFocusMode=this.setSegmentFocusMode.bind(this),this.switchSegmentHideMode=this.switchSegmentHideMode.bind(this),this.highlightPointsByAttribute=this.highlightPointsByAttribute.bind(this),this.setHiddenAttributes=this.setHiddenAttributes.bind(this),this.clearAllSegmentData=this.clearAllSegmentData.bind(this),this.deleteSelectedSegmentData=this.deleteSelectedSegmentData.bind(this),this.initMsg(),this.setupRaycaster()}initMsg(){this.on("clearStash",this.clearStash),this.on("addStash2Store",this.addStash2Store),this.on("updateCheck2Edit",this.updateCheck2Edit),this.on("setSegmentMode",this.setSegmentMode),this.on("setSegmentCoverMode",this.setSegmentCoverMode),this.on("setSegmentFocusMode",this.setSegmentFocusMode),this.on("switchHideSegment",this.switchSegmentHideMode),this.on("clearAllSegmentData",this.clearAllSegmentData),this.on("deleteSelectedSegmentData",this.deleteSelectedSegmentData)}unbindMsg(){this.unbind("clearStash",this.clearStash),this.unbind("addStash2Store",this.addStash2Store),this.unbind("updateCheck2Edit",this.updateCheck2Edit),this.unbind("setSegmentMode",this.setSegmentMode),this.unbind("setSegmentCoverMode",this.setSegmentCoverMode),this.unbind("setSegmentFocusMode",this.setSegmentFocusMode),this.unbind("switchHideSegment",this.switchSegmentHideMode),this.unbind("clearAllSegmentData",this.clearAllSegmentData),this.unbind("deleteSelectedSegmentData",this.deleteSelectedSegmentData)}get containerWidth(){return this.container.clientWidth}get containerHeight(){return this.container.clientHeight}get allSegmentPoints(){return this.scene.children.filter(t=>t.type==="Points"&&t.name!==this.pointCloudObjectName)}get selectedSegmentPoints(){var t,e;return this.scene.getObjectByName((e=(t=this.cacheSegData)==null?void 0:t.id)!=null?e:"")}get segmentStatus(){return fsm.segmentStatus}get isReadyStatus(){return fsm.isReadyStatus}get isCheckStatus(){return fsm.isCheckStatus}get isEditStatus(){return fsm.isEditStatus}get formatData(){const t=this.segmentData.values(),e=[];for(const i of t)e.push({attribute:i.attribute,id:i.id,indexes:i.indexes});return e}get pointCloudArray(){return this.scene.getObjectByName(this.pointCloudObjectName)}clearAllSegmentData(){this.segmentData=new Map,this.syncSegmentData()}updateCurrentSegment(t){this.updatePointCloudBySegment([]),this.segmentData=new Map;const{pointCloudArray:e}=this;if(!e)return;const i=e.geometry.attributes.position.array;t.forEach(a=>{const n=[];a.indexes.forEach(o=>{n.push(i[o*3],i[o*3+1],i[o*3+2]),this.cloudData.set(`${i[o*3]}@${i[o*3+1]}@${i[o*3+2]}`,{visible:!0})});const r=__spreadProps(__spreadValues({},a),{points:new Float32Array(n)});this.segmentData.set(a.id,r),this.emit("addNewPointsCloud",__spreadProps(__spreadValues({},a),{points:new Float32Array(n)}))}),this.syncSegmentData()}statusToggle(){fsm.statusToggle()}updateStatus2Edit(){fsm.updateStatus2Edit()}createCanvas(t){const e=document.createElement("canvas");return e.id=t,this.updateCanvasBasicStyle(e,{width:this.containerWidth,height:this.containerHeight},10),e}createCanvas2d(){this.canvas2d=this.createCanvas(`${DEFAULT_PREFIX}2d`),this.container.appendChild(this.canvas2d)}setupRaycaster(){this.raycaster.params={Mesh:{},Line:{threshold:1},LOD:{},Points:{threshold:.2},Sprite:{}}}setHoverPointsID(t){this.hoverPointsID=t}setSegmentMode(t){this.segmentMode=t}setSegmentCoverMode(t){this.segmentCoverMode=t}setSegmentFocusMode(t){this.segmentFocusMode=t,t===lbUtils.EPointCloudSegmentFocusMode.Focus&&this.emit("clearPointCloud"),t===lbUtils.EPointCloudSegmentFocusMode.Unfocus&&this.emit("loadPCDFile"),this.emit("reRender3d"),this.updatePointCloudBySegment(t===lbUtils.EPointCloudSegmentFocusMode.Focus?[]:[...this.segmentData.values()])}switchSegmentHideMode(t){this.hideSegment=t,this.updatePointCloudBySegment(t===!0?[]:[...this.segmentData.values()])}setHiddenAttributes(t){this.hiddenAttributes=t,this.updatePointCloudBySegment([...this.segmentData.values()])}setOriginPoints(t){this.originPoints=t}updateCanvasBasicStyle(t,e,i){const a=1;t.style.position="absolute",t.width=e.width*a,t.height=e.height*a,t.style.width=`${e.width}px`,t.style.height=`${e.height}px`,t.style.left="0",t.style.top="0",t.style.zIndex=`${i} `}syncPolygon2d(t){this.polygon2d=t}getPointsInPolygon(t){if(!this.isReadyStatus&&!this.isEditStatus)return;const e=t,i=this.originPoints;if(i){const a=i.length,n=[],r=[],o=[];for(let s=0;s<a;s+=3){const c=new THREE__namespace.Vector3(i[s],i[s+1],i[s+2]);c.project(this.camera);const d={x:0,y:0};if(d.x=Math.round(c.x*this.container.clientWidth/2+this.container.clientWidth/2),d.y=Math.round(-c.y*this.container.clientHeight/2+this.container.clientHeight/2),polygonTool.isInPolygon(d,e)){const l=i[s],S=i[s+1],p=i[s+2],g=lbUtils.PointCloudUtils.getCloudKeys(l,S,p);this.segmentMode===lbUtils.EPointCloudSegmentMode.Remove&&(this.cloudData.get(g).visible=!1,n.push(i[s],i[s+1],i[s+2]),o.push(s/3)),this.segmentMode===lbUtils.EPointCloudSegmentMode.Add&&(this.segmentCoverMode===lbUtils.EPointCloudSegmentCoverMode.Cover&&(n.push(i[s],i[s+1],i[s+2]),o.push(s/3),this.cloudData.get(g).visible===!0&&r.push(s/3)),this.segmentCoverMode===lbUtils.EPointCloudSegmentCoverMode.Uncover&&this.cloudData.get(g).visible===!1&&(n.push(i[s],i[s+1],i[s+2]),o.push(s/3)),this.cloudData.get(g).visible===!1&&(this.cloudData.get(g).visible=!0))}}if(o.length===0||!this.cacheSegData&&this.segmentMode===lbUtils.EPointCloudSegmentMode.Remove)return;const m=new Float32Array(n);this.updateStatusBySelector(m,r,o)}}updateStatusBySelector(t,e,i){switch(this.segmentMode){case lbUtils.EPointCloudSegmentMode.Add:if(this.cacheSegData){const{points:a,coverPoints:n=new Float32Array([])}=this.cacheSegData,r=a.length+t.length,o=new Float32Array(r);o.set(a,0),o.set(t,a.length);const m=[...new Set([...n,...e])];this.cacheSegData=__spreadProps(__spreadValues({},this.cacheSegData),{points:o,coverPoints:m,indexes:this.cacheSegData.indexes.concat(i)}),this.emit("updateNewPoints",this.cacheSegData)}else this.cacheSegData={id:uuid(),attribute:this.currentAttribute,points:t,coverPoints:e,indexes:i},this.emit("addNewPointsCloud",this.cacheSegData);break;case lbUtils.EPointCloudSegmentMode.Remove:if(this.cacheSegData){const{points:a,indexes:n}=this.cacheSegData;this.cacheSegData=__spreadProps(__spreadValues({},this.cacheSegData),{points:lbUtils.PointCloudUtils.splitPointsFromPoints(a,t),indexes:lbUtils.PointCloudUtils.splitPointsFromIndexes(n,i)}),this.emit("updateNewPoints",this.cacheSegData)}break}this.updateStatus2Edit(),this.emit("syncPointCloudStatus",{segmentStatus:this.segmentStatus,cacheSegData:this.cacheSegData})}syncPointCloudStatus(){this.statusToggle();const{segmentStatus:t,cacheSegData:e}=this;this.emit("syncPointCloudStatus",{segmentStatus:t,cacheSegData:e})}syncSegmentData(){this.emit("syncSegmentData",this.formatData)}addStash2Store(){this.isEditStatus&&this.cacheSegData&&(this.cacheSegData.coverPoints&&this.cacheSegData.coverPoints.length!==0&&this.updateCoverPoints(this.cacheSegData.coverPoints),delete this.cacheSegData.coverPoints,this.segmentData.set(this.cacheSegData.id,this.cacheSegData),this.cacheSegData=void 0,this.syncPointCloudStatus(),this.syncSegmentData())}updateCloudDataStatus(t,e){for(let i=0;i<t.length;i+=3){const a=t[i],n=t[i+1],r=t[i+2],o=lbUtils.PointCloudUtils.getCloudKeys(a,n,r),m=this.cloudData.get(o);Object.keys(e).forEach(s=>{m[s]=e[s]})}}clearStash(){if(this.isEditStatus&&this.cacheSegData){if(this.updateCloudDataStatus(this.cacheSegData.points,{visible:!1}),this.segmentData.has(this.cacheSegData.id)){const t=this.segmentData.get(this.cacheSegData.id);t&&(this.emit("updateNewPoints",t),this.updateCloudDataStatus(t==null?void 0:t.points,{visible:!0}))}else this.emit("clearStashRender");this.syncSegmentData(),this.cacheSegData=void 0,this.syncPointCloudStatus()}}deleteSelectedSegmentData(t=""){if((this.isCheckStatus||this.isEditStatus)&&this.cacheSegData){const e=this.scene.getObjectByName(t),{indexes:i}=this.cacheSegData;if(e&&i){const a=e.geometry.attributes.position.array;for(let n=0;n<i.length;n++){const r=this.cloudData.get(lbUtils.PointCloudUtils.getCloudKeys(a[n],a[n+1],a[n+2]));r&&(r.visible=!1)}this.resetSelectedSegmentStatus()}}}resetSelectedSegmentStatus(){this.cacheSegData=void 0,fsm.updateStatus2Ready(),this.emit("syncPointCloudStatus",{segmentStatus:this.segmentStatus,cacheSegData:this.cacheSegData})}updateCheck2Edit(){this.isCheckStatus&&this.syncPointCloudStatus()}checkPoints(){if(this.isReadyStatus||this.isCheckStatus){const t=this.segmentData.get(this.hoverPointsID);t?(this.cacheSegData=__spreadProps(__spreadValues({},t),{points:new Float32Array(t.points)}),fsm.updateStatus2Check(),this.emit("syncPointCloudStatus",{segmentStatus:this.segmentStatus,cacheSegData:this.cacheSegData})):this.resetSelectedSegmentStatus()}}editPoints(){const t=this.segmentData.get(this.hoverPointsID);t&&(this.cacheSegData=__spreadProps(__spreadValues({},t),{points:new Float32Array(t.points)}),this.emit("updateNewPoints"),this.syncPointCloudStatus())}setForbidOperation(t){this.forbidOperation=t}updateMouse(t){const e=t.x/this.containerWidth*2-1,i=-(t.y/this.containerHeight)*2+1;this.mouse.setX(e),this.mouse.setY(i)}resetAllSegDataSize(){this.highlightAttribute===""&&this.allSegmentPoints.forEach(t=>{var e;((e=this.cacheSegData)==null?void 0:e.id)!==t.name&&(t.material.size=5)})}resetHoverPointsID(){this.hoverPointsID=""}resetAllSegDataSizeAndRender(){this.resetAllSegDataSize(),this.emit("reRender3d")}highlightPoints(t){!(this.isCheckStatus||this.isReadyStatus)||(this.resetAllSegDataSize(),t.material.size=10,this.hoverPointsID=t.name,this.emit("reRender3d"))}highlightPointsByAttribute(t){this.highlightAttribute=t,this.segmentData.size!==0&&(this.resetAllSegDataSize(),this.segmentData.forEach((e,i)=>{if(e.attribute===t){const a=this.scene.getObjectByName(i);a&&(a==null?void 0:a.material)&&(a.material.size=10)}}),this.emit("reRender3d"))}setAttribute(t){this.currentAttribute=t}}module.exports=PointCloudStore;
@@ -1,4 +1,4 @@
1
- import*as c from"three";import{toolStyleConverter as O,PerspectiveShiftUtils as M,EPerspectiveView as C,PointCloudUtils as N,DEFAULT_SPHERE_PARAMS as z}from"@labelbee/lb-utils";import V from"../../_virtual/highlightWorker.js";import F from"../../_virtual/filterBoxWorker.js";import{isInPolygon as R}from"../../utils/tool/polygonTool.js";import A from"../../utils/uuid.js";import W from"../../utils/MathUtils.js";import{PCDLoader as Z}from"./PCDLoader.js";import{OrbitControls as H}from"./OrbitControls.js";import{PointCloudCache as U}from"./cache.js";import{getCuboidFromPointCloudBox as k}from"./matrix.js";export{createThreeMatrix4,getCuboidFromPointCloudBox,lidar2image,pointCloudLidar2image,rotatePoint,transferKitti2Matrix}from"./matrix.js";import{PointCloudSegmentOperation as G}from"./segmentation.js";import $ from"./store/index.js";import X from"./render/index.js";import Y from"../toolOperation/eventListener.js";import"../../constant/tool.js";import"../scheduler.js";var q=Object.defineProperty,K=Object.defineProperties,Q=Object.getOwnPropertyDescriptors,_=Object.getOwnPropertySymbols,J=Object.prototype.hasOwnProperty,tt=Object.prototype.propertyIsEnumerable,j=(w,t,e)=>t in w?q(w,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):w[t]=e,b=(w,t)=>{for(var e in t||(t={}))J.call(t,e)&&j(w,e,t[e]);if(_)for(var e of _(t))tt.call(t,e)&&j(w,e,t[e]);return w},P=(w,t)=>K(w,Q(t)),T=(w,t,e)=>new Promise((i,r)=>{var s=l=>{try{n(e.next(l))}catch(o){r(o)}},a=l=>{try{n(e.throw(l))}catch(o){r(o)}},n=l=>l.done?i(l.value):Promise.resolve(l.value).then(s,a);n((e=e.apply(w,t)).next())});const et=30,L=new V({type:"module"});class it extends Y{constructor({container:t,noAppend:e,isOrthographicCamera:i,orthographicParams:r,backgroundColor:s="#4C4C4C",config:a,isSegment:n,checkMode:l}){super();this.zAxisLimit=10,this.initCameraPosition=this.DEFAULT_INIT_CAMERA_POSITION,this.isOrthographicCamera=!1,this.pointsUuid="",this.pointCloudObjectName="pointCloud",this.rangeObjectName="range",this.showDirection=!0,this.pointsMaterialSize=1,this.isSegment=!1,this.checkMode=!1,this.nextTick=()=>{!this.segmentOperation||this.segmentOperation._raycasting()},this.keydown=o=>{if(!!this.store)switch(o.key){case" ":this.controls.enablePan=!0,this.store.setForbidOperation(!0);break}},this.keyup=o=>{if(!!this.store)switch(o.key){case" ":this.controls.enablePan=!1,this.store.setForbidOperation(!1);break}},this.addSphereToSense=(o,h="blue")=>{var d;const u=(d=o.id)!=null?d:A();this.removeObjectByName(u,"sphere");const{radius:m,widthSegments:g,heightSegments:p}=z,{center:f}=o,x=new c.Group,y=new c.SphereGeometry(m,g,p),S=new c.MeshBasicMaterial({color:h}),v=new c.Mesh(y,S);v.position.set(f.x,f.y,f.z),x.add(v),x.name=`sphere-${u}`,this.scene.add(x)},this.generateSphere=o=>{const{fill:h}=O.getColorFromConfig({attribute:o.attribute},P(b({},this.config),{attributeConfigurable:!0}),{});this.addSphereToSense(o,h),this.render()},this.generateSpheres=o=>{o.forEach(h=>{const{fill:d}=O.getColorFromConfig({attribute:h.attribute},P(b({},this.config),{attributeConfigurable:!0}),{});this.addSphereToSense(h,d)}),this.render()},this.addBoxToSense=(o,h=16777215)=>{var d;const u=(d=o.id)!=null?d:A();this.removeObjectByName(u,"box");const{center:m,width:g,height:p,depth:f,rotation:x}=o,y=new c.Group,S=new c.BoxGeometry(g,p,f),v=new c.MeshBasicMaterial({color:"blue"}),B=new c.Mesh(S,v),I=new c.BoxHelper(B,h),E=this.generateBoxArrow(o),D=this.generateBoxTrackID(o);D&&y.add(D),y.add(I),y.add(E),m&&y.position.set(m.x,m.y,m.z),x&&y.rotation.set(0,0,x),y.name=`box-${u}`,this.scene.add(y)},this.applyCameraTarget=o=>{if(this.camera.type==="OrthographicCamera"&&o){const h=this.getOrthographicCameraTarget(o);this.updateCameraZoom(o.zoom),this.updateCamera(o.position,h)}},this.initShaderMaterial=()=>({vertexShader:`
1
+ import*as c from"three";import{toolStyleConverter as O,PerspectiveShiftUtils as M,EPerspectiveView as C,PointCloudUtils as N,DEFAULT_SPHERE_PARAMS as z}from"@labelbee/lb-utils";import V from"../../_virtual/highlightWorker.js";import F from"../../_virtual/filterBoxWorker.js";import{isInPolygon as R}from"../../utils/tool/polygonTool.js";import A from"../../utils/uuid.js";import W from"../../utils/MathUtils.js";import{PCDLoader as Z}from"./PCDLoader.js";import{OrbitControls as H}from"./OrbitControls.js";import{PointCloudCache as U}from"./cache.js";import{getCuboidFromPointCloudBox as k}from"./matrix.js";export{createThreeMatrix4,getCuboidFromPointCloudBox,lidar2image,pointCloudLidar2image,rotatePoint,transferKitti2Matrix}from"./matrix.js";import{PointCloudSegmentOperation as G}from"./segmentation.js";import $ from"./store/index.js";import X from"./render/index.js";import Y from"../toolOperation/eventListener.js";import"../../constant/tool.js";import"../scheduler.js";var q=Object.defineProperty,K=Object.defineProperties,Q=Object.getOwnPropertyDescriptors,_=Object.getOwnPropertySymbols,J=Object.prototype.hasOwnProperty,tt=Object.prototype.propertyIsEnumerable,j=(w,t,e)=>t in w?q(w,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):w[t]=e,b=(w,t)=>{for(var e in t||(t={}))J.call(t,e)&&j(w,e,t[e]);if(_)for(var e of _(t))tt.call(t,e)&&j(w,e,t[e]);return w},P=(w,t)=>K(w,Q(t)),T=(w,t,e)=>new Promise((i,r)=>{var s=l=>{try{n(e.next(l))}catch(o){r(o)}},a=l=>{try{n(e.throw(l))}catch(o){r(o)}},n=l=>l.done?i(l.value):Promise.resolve(l.value).then(s,a);n((e=e.apply(w,t)).next())});const et=30,L=new V({type:"module"});class it extends Y{constructor({container:t,noAppend:e,isOrthographicCamera:i,orthographicParams:r,backgroundColor:s="#4C4C4C",config:a,isSegment:n,checkMode:l}){super();this.zAxisLimit=10,this.initCameraPosition=this.DEFAULT_INIT_CAMERA_POSITION,this.isOrthographicCamera=!1,this.pointsUuid="",this.pointCloudObjectName="pointCloud",this.rangeObjectName="range",this.showDirection=!0,this.pointsMaterialSize=1,this.isSegment=!1,this.checkMode=!1,this.nextTick=()=>{!this.segmentOperation||this.segmentOperation._raycasting()},this.keydown=o=>{if(!!this.store)switch(o.key){case" ":this.controls.enablePan=!0,this.store.setForbidOperation(!0);break}},this.keyup=o=>{if(!!this.store)switch(o.key){case" ":this.controls.enablePan=!1,this.store.setForbidOperation(!1);break}},this.addSphereToSense=(o,h="blue")=>{var d;const u=(d=o.id)!=null?d:A();this.removeObjectByName(u,"sphere");const{radius:m,widthSegments:g,heightSegments:p}=z,{center:f}=o,x=new c.Group,y=new c.SphereGeometry(m,g,p),S=new c.MeshBasicMaterial({color:h}),v=new c.Mesh(y,S);v.position.set(f.x,f.y,f.z),x.add(v),x.name=`sphere${u}`,this.scene.add(x)},this.generateSphere=o=>{const{fill:h}=O.getColorFromConfig({attribute:o.attribute},P(b({},this.config),{attributeConfigurable:!0}),{});this.addSphereToSense(o,h),this.render()},this.generateSpheres=o=>{o.forEach(h=>{const{fill:d}=O.getColorFromConfig({attribute:h.attribute},P(b({},this.config),{attributeConfigurable:!0}),{});this.addSphereToSense(h,d)}),this.render()},this.addBoxToSense=(o,h=16777215)=>{var d;const u=(d=o.id)!=null?d:A();this.removeObjectByName(u,"box");const{center:m,width:g,height:p,depth:f,rotation:x}=o,y=new c.Group,S=new c.BoxGeometry(g,p,f),v=new c.MeshBasicMaterial({color:"blue"}),B=new c.Mesh(S,v),I=new c.BoxHelper(B,h),E=this.generateBoxArrow(o),D=this.generateBoxTrackID(o);D&&y.add(D),y.add(I),y.add(E),m&&y.position.set(m.x,m.y,m.z),x&&y.rotation.set(0,0,x),y.name=`box${u}`,this.scene.add(y)},this.applyCameraTarget=o=>{if(this.camera.type==="OrthographicCamera"&&o){const h=this.getOrthographicCameraTarget(o);this.updateCameraZoom(o.zoom),this.updateCamera(o.position,h)}},this.initShaderMaterial=()=>({vertexShader:`
2
2
  attribute vec3 dimensions;
3
3
  varying vec3 vDimensions;
4
4
  uniform float pointSize;
@@ -1 +1 @@
1
- import{EPointCloudSegmentStatus as r}from"@labelbee/lb-utils";import n from"./selector/lassoSelector.js";import c from"./selector/circleSelector.js";class h{constructor(e){this.onMouseMove=t=>{if((this.store.isCheckStatus||this.store.isReadyStatus)&&this.store.updateMouse({x:t.offsetX,y:t.offsetY}),this.isForbid||this.store.checkMode)return;const s={offsetX:t.offsetX,offsetY:t.offsetY,button:t.buttons};this.currentTool.mouseMove(s)},this.onMouseDown=t=>{this.isForbid||this.store.checkMode||this.currentTool.mouseDown(t)},this.onMouseUp=t=>{this.isForbid||this.store.orbiting===!0||this.store.checkMode||this.baseMouseDown(t)||this.currentTool.mouseUp(t)},this.baseMouseDown=t=>{if(!this.store.checkMode)switch(t.button){case 0:if(this.store.isReadyStatus||this.store.isCheckStatus)return this.store.checkPoints(),!0;break}},this._raycasting=()=>{if([r.Ready,r.Check].includes(this.store.segmentStatus)){const{mouse:t,camera:s,raycaster:o}=this.store;o.setFromCamera(t,s);const i=o.intersectObjects(this.store.allSegmentPoints,!1)[0];i?this.store.highlightPoints(i.object):(this.store.resetAllSegDataSizeAndRender(),this.store.resetHoverPointsID())}},this.dom=e.dom,this.store=e.store,this.lassoSelector=new n(this.store),this.circleSelector=new c(this.store),this.currentTool=this.circleSelector,this.currentToolName="CircleSelector",this.dom.addEventListener("pointermove",this.onMouseMove.bind(this)),this.dom.addEventListener("pointerdown",this.onMouseDown.bind(this)),this.dom.addEventListener("pointerup",this.onMouseUp.bind(this)),this.updateSelector2Lasso=this.updateSelector2Lasso.bind(this),this.updateSelector2Circle=this.updateSelector2Circle.bind(this)}getCoordinate(e){const t=this.dom.getBoundingClientRect();return{x:e.clientX-t.left,y:e.clientY-t.top}}get forbidOperation(){return this.store.forbidOperation}get isForbid(){return this.forbidOperation}updateSelector2Lasso(){this.currentTool=this.lassoSelector,this.currentToolName="LassoSelector"}updateSelector2Circle(){this.currentTool=this.circleSelector,this.currentToolName="CircleSelector"}}export{h as PointCloudSegmentOperation};
1
+ import{EPointCloudSegmentStatus as r}from"@labelbee/lb-utils";import n from"./selector/lassoSelector.js";import c from"./selector/circleSelector.js";class h{constructor(e){this.onMouseMove=t=>{if((this.store.isCheckStatus||this.store.isReadyStatus)&&this.store.updateMouse({x:t.offsetX,y:t.offsetY}),this.isForbid||this.store.checkMode)return;const s={offsetX:t.offsetX,offsetY:t.offsetY,button:t.buttons};this.currentTool.mouseMove(s)},this.onMouseDown=t=>{this.isForbid||this.store.checkMode||this.currentTool.mouseDown(t)},this.onMouseUp=t=>{this.isForbid||this.store.orbiting===!0||this.store.checkMode||this.baseMouseDown(t)||this.currentTool.mouseUp(t)},this.baseMouseDown=t=>{if(!this.store.checkMode)switch(t.button){case 0:if(this.store.isReadyStatus||this.store.isCheckStatus)return this.store.checkPoints(),!0;break}},this._raycasting=()=>{if([r.Ready,r.Check].includes(this.store.segmentStatus)){const{mouse:t,camera:s,raycaster:o}=this.store;o.setFromCamera(t,s);const i=o.intersectObjects(this.store.allSegmentPoints,!1)[0];i?this.store.highlightPoints(i.object):(this.store.resetAllSegDataSizeAndRender(),this.store.resetHoverPointsID())}},this.dom=e.dom,this.store=e.store,this.lassoSelector=new n(this.store),this.circleSelector=new c(this.store),this.currentTool=this.lassoSelector,this.currentToolName="LassoSelector",this.dom.addEventListener("pointermove",this.onMouseMove.bind(this)),this.dom.addEventListener("pointerdown",this.onMouseDown.bind(this)),this.dom.addEventListener("pointerup",this.onMouseUp.bind(this)),this.updateSelector2Lasso=this.updateSelector2Lasso.bind(this),this.updateSelector2Circle=this.updateSelector2Circle.bind(this)}getCoordinate(e){const t=this.dom.getBoundingClientRect();return{x:e.clientX-t.left,y:e.clientY-t.top}}get forbidOperation(){return this.store.forbidOperation}get isForbid(){return this.forbidOperation}updateSelector2Lasso(){this.currentTool=this.lassoSelector,this.currentToolName="LassoSelector"}updateSelector2Circle(){this.currentTool=this.circleSelector,this.currentToolName="CircleSelector"}}export{h as PointCloudSegmentOperation};
@@ -1 +1 @@
1
- import*as v from"three";import{EPointCloudSegmentMode as D,EPointCloudSegmentCoverMode as A,EPointCloudSegmentFocusMode as C,PointCloudUtils as y}from"@labelbee/lb-utils";import{isInPolygon as E}from"../../../utils/tool/polygonTool.js";import F from"../../../utils/uuid.js";import m from"./fsm.js";var O=Object.defineProperty,_=Object.defineProperties,R=Object.getOwnPropertyDescriptors,M=Object.getOwnPropertySymbols,x=Object.prototype.hasOwnProperty,B=Object.prototype.propertyIsEnumerable,w=(d,t,e)=>t in d?O(d,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):d[t]=e,P=(d,t)=>{for(var e in t||(t={}))x.call(t,e)&&w(d,e,t[e]);if(M)for(var e of M(t))B.call(t,e)&&w(d,e,t[e]);return d},f=(d,t)=>_(d,R(t));const k="LABELBEE_CANVAS_";class I{constructor({container:t,scene:e,camera:s,renderer:a,emit:n,on:o,unbind:h,checkMode:p}){this.canvas2d=null,this.polygon2d=[],this.forbidOperation=!1,this.raycaster=new v.Raycaster,this.mouse=new v.Vector2,this.cloudData=new Map,this.originPoints=new Float32Array([]),this.segmentData=new Map,this.hoverPointsID="",this.segmentMode=D.Add,this.segmentCoverMode=A.Cover,this.segmentFocusMode=C.Unfocus,this.hideSegment=!1,this.checkMode=!1,this.updatePointCloud=!1,this.addPointCloud=!1,this.orbiting=!1,this.currentAttribute="",this.highlightAttribute="",this.hiddenAttributes=[],this.pointCloudObjectName="pointCloud",this.updatePointCloudBySegment=i=>{this.segmentData.forEach((r,u)=>{var l;if(u!==((l=this.cacheSegData)==null?void 0:l.id)){const S=this.scene.getObjectByName(u);S&&S.removeFromParent()}});const c=i==null?void 0:i.filter(r=>{var u;return!this.hiddenAttributes.some(l=>l===r.attribute)&&r.id!==((u=this.cacheSegData)==null?void 0:u.id)});(c==null?void 0:c.length)!==0&&c.map(r=>(this.emit("addNewPointsCloud",r),r)),this.emit("reRender3d")},this.updateCoverPoints=(i=[])=>{this.segmentData.forEach((c,r)=>{var u;if(r!==((u=this.cacheSegData)==null?void 0:u.id)){const l=y.splitPointsFromIndexes(c.indexes,i),S=[];l.forEach(g=>{S.push(this.originPoints[g*3],this.originPoints[g*3+1],this.originPoints[g*3+2])}),c.indexes=l,c.points=new Float32Array(S);const b=this.scene.getObjectByName(r);b&&(b.geometry.setAttribute("position",new v.Float32BufferAttribute(new Float32Array(S),3)),b.geometry.attributes.position.needsUpdate=!0)}}),this.syncSegmentData(),this.emit("reRender3d")},this.container=t,this.scene=e,this.camera=s,this.renderer=a,this.emit=n,this.on=o,this.unbind=h,this.checkMode=p,this.createCanvas2d(),this.clearStash=this.clearStash.bind(this),this.addStash2Store=this.addStash2Store.bind(this),this.updateCheck2Edit=this.updateCheck2Edit.bind(this),this.setAttribute=this.setAttribute.bind(this),this.setSegmentMode=this.setSegmentMode.bind(this),this.setSegmentCoverMode=this.setSegmentCoverMode.bind(this),this.setSegmentFocusMode=this.setSegmentFocusMode.bind(this),this.switchSegmentHideMode=this.switchSegmentHideMode.bind(this),this.highlightPointsByAttribute=this.highlightPointsByAttribute.bind(this),this.setHiddenAttributes=this.setHiddenAttributes.bind(this),this.clearAllSegmentData=this.clearAllSegmentData.bind(this),this.deleteSelectedSegmentData=this.deleteSelectedSegmentData.bind(this),this.initMsg(),this.setupRaycaster()}initMsg(){this.on("clearStash",this.clearStash),this.on("addStash2Store",this.addStash2Store),this.on("updateCheck2Edit",this.updateCheck2Edit),this.on("setSegmentMode",this.setSegmentMode),this.on("setSegmentCoverMode",this.setSegmentCoverMode),this.on("setSegmentFocusMode",this.setSegmentFocusMode),this.on("switchHideSegment",this.switchSegmentHideMode),this.on("clearAllSegmentData",this.clearAllSegmentData),this.on("deleteSelectedSegmentData",this.deleteSelectedSegmentData)}unbindMsg(){this.unbind("clearStash",this.clearStash),this.unbind("addStash2Store",this.addStash2Store),this.unbind("updateCheck2Edit",this.updateCheck2Edit),this.unbind("setSegmentMode",this.setSegmentMode),this.unbind("setSegmentCoverMode",this.setSegmentCoverMode),this.unbind("setSegmentFocusMode",this.setSegmentFocusMode),this.unbind("switchHideSegment",this.switchSegmentHideMode),this.unbind("clearAllSegmentData",this.clearAllSegmentData),this.unbind("deleteSelectedSegmentData",this.deleteSelectedSegmentData)}get containerWidth(){return this.container.clientWidth}get containerHeight(){return this.container.clientHeight}get allSegmentPoints(){return this.scene.children.filter(t=>t.type==="Points"&&t.name!==this.pointCloudObjectName)}get selectedSegmentPoints(){var t,e;return this.scene.getObjectByName((e=(t=this.cacheSegData)==null?void 0:t.id)!=null?e:"")}get segmentStatus(){return m.segmentStatus}get isReadyStatus(){return m.isReadyStatus}get isCheckStatus(){return m.isCheckStatus}get isEditStatus(){return m.isEditStatus}get formatData(){const t=this.segmentData.values(),e=[];for(const s of t)e.push({attribute:s.attribute,id:s.id,indexes:s.indexes});return e}get pointCloudArray(){return this.scene.getObjectByName(this.pointCloudObjectName)}clearAllSegmentData(){this.segmentData=new Map,this.syncSegmentData()}updateCurrentSegment(t){this.updatePointCloudBySegment([]),this.segmentData=new Map;const{pointCloudArray:e}=this;if(!e)return;const s=e.geometry.attributes.position.array;t.forEach(a=>{const n=[];a.indexes.forEach(h=>{n.push(s[h*3],s[h*3+1],s[h*3+2])});const o=f(P({},a),{points:new Float32Array(n)});this.segmentData.set(a.id,o),this.emit("addNewPointsCloud",f(P({},a),{points:new Float32Array(n)}))}),this.syncSegmentData()}statusToggle(){m.statusToggle()}updateStatus2Edit(){m.updateStatus2Edit()}createCanvas(t){const e=document.createElement("canvas");return e.id=t,this.updateCanvasBasicStyle(e,{width:this.containerWidth,height:this.containerHeight},10),e}createCanvas2d(){this.canvas2d=this.createCanvas(`${k}2d`),this.container.appendChild(this.canvas2d)}setupRaycaster(){this.raycaster.params={Mesh:{},Line:{threshold:1},LOD:{},Points:{threshold:.2},Sprite:{}}}setHoverPointsID(t){this.hoverPointsID=t}setSegmentMode(t){this.segmentMode=t}setSegmentCoverMode(t){this.segmentCoverMode=t}setSegmentFocusMode(t){this.segmentFocusMode=t,t===C.Focus&&this.emit("clearPointCloud"),t===C.Unfocus&&this.emit("loadPCDFile"),this.emit("reRender3d"),this.updatePointCloudBySegment(t===C.Focus?[]:[...this.segmentData.values()])}switchSegmentHideMode(t){this.hideSegment=t,this.updatePointCloudBySegment(t===!0?[]:[...this.segmentData.values()])}setHiddenAttributes(t){this.hiddenAttributes=t,this.updatePointCloudBySegment([...this.segmentData.values()])}setOriginPoints(t){this.originPoints=t}updateCanvasBasicStyle(t,e,s){const a=1;t.style.position="absolute",t.width=e.width*a,t.height=e.height*a,t.style.width=`${e.width}px`,t.style.height=`${e.height}px`,t.style.left="0",t.style.top="0",t.style.zIndex=`${s} `}syncPolygon2d(t){this.polygon2d=t}getPointsInPolygon(t){if(!this.isReadyStatus&&!this.isEditStatus)return;const e=t,s=this.originPoints;if(s){const a=s.length,n=[],o=[],h=[];for(let i=0;i<a;i+=3){const c=new v.Vector3(s[i],s[i+1],s[i+2]);c.project(this.camera);const r={x:0,y:0};if(r.x=Math.round(c.x*this.container.clientWidth/2+this.container.clientWidth/2),r.y=Math.round(-c.y*this.container.clientHeight/2+this.container.clientHeight/2),E(r,e)){const l=s[i],S=s[i+1],b=s[i+2],g=y.getCloudKeys(l,S,b);this.segmentMode===D.Remove&&(this.cloudData.get(g).visible=!1,n.push(s[i],s[i+1],s[i+2]),h.push(i/3)),this.segmentMode===D.Add&&(this.segmentCoverMode===A.Cover&&(n.push(s[i],s[i+1],s[i+2]),h.push(i/3),this.cloudData.get(g).visible===!0&&o.push(i/3)),this.segmentCoverMode===A.Uncover&&this.cloudData.get(g).visible===!1&&(n.push(s[i],s[i+1],s[i+2]),h.push(i/3)),this.cloudData.get(g).visible===!1&&(this.cloudData.get(g).visible=!0))}}if(h.length===0||!this.cacheSegData&&this.segmentMode===D.Remove)return;const p=new Float32Array(n);this.updateStatusBySelector(p,o,h)}}updateStatusBySelector(t,e,s){switch(this.segmentMode){case D.Add:if(this.cacheSegData){const{points:a,coverPoints:n=new Float32Array([])}=this.cacheSegData,o=a.length+t.length,h=new Float32Array(o);h.set(a,0),h.set(t,a.length);const p=[...new Set([...n,...e])];this.cacheSegData=f(P({},this.cacheSegData),{points:h,coverPoints:p,indexes:this.cacheSegData.indexes.concat(s)}),this.emit("updateNewPoints",this.cacheSegData)}else this.cacheSegData={id:F(),attribute:this.currentAttribute,points:t,coverPoints:e,indexes:s},this.emit("addNewPointsCloud",this.cacheSegData);break;case D.Remove:if(this.cacheSegData){const{points:a,indexes:n}=this.cacheSegData;this.cacheSegData=f(P({},this.cacheSegData),{points:y.splitPointsFromPoints(a,t),indexes:y.splitPointsFromIndexes(n,s)}),this.emit("updateNewPoints",this.cacheSegData)}break}this.updateStatus2Edit(),this.emit("syncPointCloudStatus",{segmentStatus:this.segmentStatus,cacheSegData:this.cacheSegData})}syncPointCloudStatus(){this.statusToggle();const{segmentStatus:t,cacheSegData:e}=this;this.emit("syncPointCloudStatus",{segmentStatus:t,cacheSegData:e})}syncSegmentData(){this.emit("syncSegmentData",this.formatData)}addStash2Store(){this.isEditStatus&&this.cacheSegData&&(this.cacheSegData.coverPoints&&this.cacheSegData.coverPoints.length!==0&&this.updateCoverPoints(this.cacheSegData.coverPoints),delete this.cacheSegData.coverPoints,this.segmentData.set(this.cacheSegData.id,this.cacheSegData),this.cacheSegData=void 0,this.syncPointCloudStatus(),this.syncSegmentData())}updateCloudDataStatus(t,e){for(let s=0;s<t.length;s+=3){const a=t[s],n=t[s+1],o=t[s+2],h=y.getCloudKeys(a,n,o),p=this.cloudData.get(h);Object.keys(e).forEach(i=>{p[i]=e[i]})}}clearStash(){if(this.isEditStatus&&this.cacheSegData){if(this.updateCloudDataStatus(this.cacheSegData.points,{visible:!1}),this.segmentData.has(this.cacheSegData.id)){const t=this.segmentData.get(this.cacheSegData.id);t&&(this.emit("updateNewPoints",t),this.updateCloudDataStatus(t==null?void 0:t.points,{visible:!0}))}else this.emit("clearStashRender");this.syncSegmentData(),this.cacheSegData=void 0,this.syncPointCloudStatus()}}deleteSelectedSegmentData(t=""){if((this.isCheckStatus||this.isEditStatus)&&this.cacheSegData){const e=this.scene.getObjectByName(t),{indexes:s}=this.cacheSegData;if(e&&s){const a=e.geometry.attributes.position.array;for(let n=0;n<s.length;n++){const o=this.cloudData.get(y.getCloudKeys(a[n],a[n+1],a[n+2]));o&&(o.visible=!1)}this.resetSelectedSegmentStatus()}}}resetSelectedSegmentStatus(){this.cacheSegData=void 0,m.updateStatus2Ready(),this.emit("syncPointCloudStatus",{segmentStatus:this.segmentStatus,cacheSegData:this.cacheSegData})}updateCheck2Edit(){this.isCheckStatus&&this.syncPointCloudStatus()}checkPoints(){if(this.isReadyStatus||this.isCheckStatus){const t=this.segmentData.get(this.hoverPointsID);t?(this.cacheSegData=f(P({},t),{points:new Float32Array(t.points)}),m.updateStatus2Check(),this.emit("syncPointCloudStatus",{segmentStatus:this.segmentStatus,cacheSegData:this.cacheSegData})):this.resetSelectedSegmentStatus()}}editPoints(){const t=this.segmentData.get(this.hoverPointsID);t&&(this.cacheSegData=f(P({},t),{points:new Float32Array(t.points)}),this.emit("updateNewPoints"),this.syncPointCloudStatus())}setForbidOperation(t){this.forbidOperation=t}updateMouse(t){const e=t.x/this.containerWidth*2-1,s=-(t.y/this.containerHeight)*2+1;this.mouse.setX(e),this.mouse.setY(s)}resetAllSegDataSize(){this.highlightAttribute===""&&this.allSegmentPoints.forEach(t=>{var e;((e=this.cacheSegData)==null?void 0:e.id)!==t.name&&(t.material.size=5)})}resetHoverPointsID(){this.hoverPointsID=""}resetAllSegDataSizeAndRender(){this.resetAllSegDataSize(),this.emit("reRender3d")}highlightPoints(t){!(this.isCheckStatus||this.isReadyStatus)||(this.resetAllSegDataSize(),t.material.size=10,this.hoverPointsID=t.name,this.emit("reRender3d"))}highlightPointsByAttribute(t){this.highlightAttribute=t,this.segmentData.size!==0&&(this.resetAllSegDataSize(),this.segmentData.forEach((e,s)=>{if(e.attribute===t){const a=this.scene.getObjectByName(s);a&&(a==null?void 0:a.material)&&(a.material.size=10)}}),this.emit("reRender3d"))}setAttribute(t){this.currentAttribute=t}}export{I as default};
1
+ import*as v from"three";import{EPointCloudSegmentMode as D,EPointCloudSegmentCoverMode as A,EPointCloudSegmentFocusMode as C,PointCloudUtils as y}from"@labelbee/lb-utils";import{isInPolygon as E}from"../../../utils/tool/polygonTool.js";import F from"../../../utils/uuid.js";import m from"./fsm.js";var O=Object.defineProperty,_=Object.defineProperties,R=Object.getOwnPropertyDescriptors,M=Object.getOwnPropertySymbols,B=Object.prototype.hasOwnProperty,k=Object.prototype.propertyIsEnumerable,w=(d,t,e)=>t in d?O(d,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):d[t]=e,P=(d,t)=>{for(var e in t||(t={}))B.call(t,e)&&w(d,e,t[e]);if(M)for(var e of M(t))k.call(t,e)&&w(d,e,t[e]);return d},b=(d,t)=>_(d,R(t));const I="LABELBEE_CANVAS_";class j{constructor({container:t,scene:e,camera:s,renderer:a,emit:n,on:o,unbind:h,checkMode:p}){this.canvas2d=null,this.polygon2d=[],this.forbidOperation=!1,this.raycaster=new v.Raycaster,this.mouse=new v.Vector2,this.cloudData=new Map,this.originPoints=new Float32Array([]),this.segmentData=new Map,this.hoverPointsID="",this.segmentMode=D.Add,this.segmentCoverMode=A.Cover,this.segmentFocusMode=C.Unfocus,this.hideSegment=!1,this.checkMode=!1,this.updatePointCloud=!1,this.addPointCloud=!1,this.orbiting=!1,this.currentAttribute="",this.highlightAttribute="",this.hiddenAttributes=[],this.pointCloudObjectName="pointCloud",this.updatePointCloudBySegment=i=>{this.segmentData.forEach((r,u)=>{var l;if(u!==((l=this.cacheSegData)==null?void 0:l.id)){const S=this.scene.getObjectByName(u);S&&S.removeFromParent()}});const c=i==null?void 0:i.filter(r=>{var u;return!this.hiddenAttributes.some(l=>l===r.attribute)&&r.id!==((u=this.cacheSegData)==null?void 0:u.id)});(c==null?void 0:c.length)!==0&&c.map(r=>(this.emit("addNewPointsCloud",r),r)),this.emit("reRender3d")},this.updateCoverPoints=(i=[])=>{this.segmentData.forEach((c,r)=>{var u;if(r!==((u=this.cacheSegData)==null?void 0:u.id)){const l=y.splitPointsFromIndexes(c.indexes,i),S=[];l.forEach(g=>{S.push(this.originPoints[g*3],this.originPoints[g*3+1],this.originPoints[g*3+2])}),c.indexes=l,c.points=new Float32Array(S);const f=this.scene.getObjectByName(r);f&&(f.geometry.setAttribute("position",new v.Float32BufferAttribute(new Float32Array(S),3)),f.geometry.attributes.position.needsUpdate=!0)}}),this.syncSegmentData(),this.emit("reRender3d")},this.container=t,this.scene=e,this.camera=s,this.renderer=a,this.emit=n,this.on=o,this.unbind=h,this.checkMode=p,this.createCanvas2d(),this.clearStash=this.clearStash.bind(this),this.addStash2Store=this.addStash2Store.bind(this),this.updateCheck2Edit=this.updateCheck2Edit.bind(this),this.setAttribute=this.setAttribute.bind(this),this.setSegmentMode=this.setSegmentMode.bind(this),this.setSegmentCoverMode=this.setSegmentCoverMode.bind(this),this.setSegmentFocusMode=this.setSegmentFocusMode.bind(this),this.switchSegmentHideMode=this.switchSegmentHideMode.bind(this),this.highlightPointsByAttribute=this.highlightPointsByAttribute.bind(this),this.setHiddenAttributes=this.setHiddenAttributes.bind(this),this.clearAllSegmentData=this.clearAllSegmentData.bind(this),this.deleteSelectedSegmentData=this.deleteSelectedSegmentData.bind(this),this.initMsg(),this.setupRaycaster()}initMsg(){this.on("clearStash",this.clearStash),this.on("addStash2Store",this.addStash2Store),this.on("updateCheck2Edit",this.updateCheck2Edit),this.on("setSegmentMode",this.setSegmentMode),this.on("setSegmentCoverMode",this.setSegmentCoverMode),this.on("setSegmentFocusMode",this.setSegmentFocusMode),this.on("switchHideSegment",this.switchSegmentHideMode),this.on("clearAllSegmentData",this.clearAllSegmentData),this.on("deleteSelectedSegmentData",this.deleteSelectedSegmentData)}unbindMsg(){this.unbind("clearStash",this.clearStash),this.unbind("addStash2Store",this.addStash2Store),this.unbind("updateCheck2Edit",this.updateCheck2Edit),this.unbind("setSegmentMode",this.setSegmentMode),this.unbind("setSegmentCoverMode",this.setSegmentCoverMode),this.unbind("setSegmentFocusMode",this.setSegmentFocusMode),this.unbind("switchHideSegment",this.switchSegmentHideMode),this.unbind("clearAllSegmentData",this.clearAllSegmentData),this.unbind("deleteSelectedSegmentData",this.deleteSelectedSegmentData)}get containerWidth(){return this.container.clientWidth}get containerHeight(){return this.container.clientHeight}get allSegmentPoints(){return this.scene.children.filter(t=>t.type==="Points"&&t.name!==this.pointCloudObjectName)}get selectedSegmentPoints(){var t,e;return this.scene.getObjectByName((e=(t=this.cacheSegData)==null?void 0:t.id)!=null?e:"")}get segmentStatus(){return m.segmentStatus}get isReadyStatus(){return m.isReadyStatus}get isCheckStatus(){return m.isCheckStatus}get isEditStatus(){return m.isEditStatus}get formatData(){const t=this.segmentData.values(),e=[];for(const s of t)e.push({attribute:s.attribute,id:s.id,indexes:s.indexes});return e}get pointCloudArray(){return this.scene.getObjectByName(this.pointCloudObjectName)}clearAllSegmentData(){this.segmentData=new Map,this.syncSegmentData()}updateCurrentSegment(t){this.updatePointCloudBySegment([]),this.segmentData=new Map;const{pointCloudArray:e}=this;if(!e)return;const s=e.geometry.attributes.position.array;t.forEach(a=>{const n=[];a.indexes.forEach(h=>{n.push(s[h*3],s[h*3+1],s[h*3+2]),this.cloudData.set(`${s[h*3]}@${s[h*3+1]}@${s[h*3+2]}`,{visible:!0})});const o=b(P({},a),{points:new Float32Array(n)});this.segmentData.set(a.id,o),this.emit("addNewPointsCloud",b(P({},a),{points:new Float32Array(n)}))}),this.syncSegmentData()}statusToggle(){m.statusToggle()}updateStatus2Edit(){m.updateStatus2Edit()}createCanvas(t){const e=document.createElement("canvas");return e.id=t,this.updateCanvasBasicStyle(e,{width:this.containerWidth,height:this.containerHeight},10),e}createCanvas2d(){this.canvas2d=this.createCanvas(`${I}2d`),this.container.appendChild(this.canvas2d)}setupRaycaster(){this.raycaster.params={Mesh:{},Line:{threshold:1},LOD:{},Points:{threshold:.2},Sprite:{}}}setHoverPointsID(t){this.hoverPointsID=t}setSegmentMode(t){this.segmentMode=t}setSegmentCoverMode(t){this.segmentCoverMode=t}setSegmentFocusMode(t){this.segmentFocusMode=t,t===C.Focus&&this.emit("clearPointCloud"),t===C.Unfocus&&this.emit("loadPCDFile"),this.emit("reRender3d"),this.updatePointCloudBySegment(t===C.Focus?[]:[...this.segmentData.values()])}switchSegmentHideMode(t){this.hideSegment=t,this.updatePointCloudBySegment(t===!0?[]:[...this.segmentData.values()])}setHiddenAttributes(t){this.hiddenAttributes=t,this.updatePointCloudBySegment([...this.segmentData.values()])}setOriginPoints(t){this.originPoints=t}updateCanvasBasicStyle(t,e,s){const a=1;t.style.position="absolute",t.width=e.width*a,t.height=e.height*a,t.style.width=`${e.width}px`,t.style.height=`${e.height}px`,t.style.left="0",t.style.top="0",t.style.zIndex=`${s} `}syncPolygon2d(t){this.polygon2d=t}getPointsInPolygon(t){if(!this.isReadyStatus&&!this.isEditStatus)return;const e=t,s=this.originPoints;if(s){const a=s.length,n=[],o=[],h=[];for(let i=0;i<a;i+=3){const c=new v.Vector3(s[i],s[i+1],s[i+2]);c.project(this.camera);const r={x:0,y:0};if(r.x=Math.round(c.x*this.container.clientWidth/2+this.container.clientWidth/2),r.y=Math.round(-c.y*this.container.clientHeight/2+this.container.clientHeight/2),E(r,e)){const l=s[i],S=s[i+1],f=s[i+2],g=y.getCloudKeys(l,S,f);this.segmentMode===D.Remove&&(this.cloudData.get(g).visible=!1,n.push(s[i],s[i+1],s[i+2]),h.push(i/3)),this.segmentMode===D.Add&&(this.segmentCoverMode===A.Cover&&(n.push(s[i],s[i+1],s[i+2]),h.push(i/3),this.cloudData.get(g).visible===!0&&o.push(i/3)),this.segmentCoverMode===A.Uncover&&this.cloudData.get(g).visible===!1&&(n.push(s[i],s[i+1],s[i+2]),h.push(i/3)),this.cloudData.get(g).visible===!1&&(this.cloudData.get(g).visible=!0))}}if(h.length===0||!this.cacheSegData&&this.segmentMode===D.Remove)return;const p=new Float32Array(n);this.updateStatusBySelector(p,o,h)}}updateStatusBySelector(t,e,s){switch(this.segmentMode){case D.Add:if(this.cacheSegData){const{points:a,coverPoints:n=new Float32Array([])}=this.cacheSegData,o=a.length+t.length,h=new Float32Array(o);h.set(a,0),h.set(t,a.length);const p=[...new Set([...n,...e])];this.cacheSegData=b(P({},this.cacheSegData),{points:h,coverPoints:p,indexes:this.cacheSegData.indexes.concat(s)}),this.emit("updateNewPoints",this.cacheSegData)}else this.cacheSegData={id:F(),attribute:this.currentAttribute,points:t,coverPoints:e,indexes:s},this.emit("addNewPointsCloud",this.cacheSegData);break;case D.Remove:if(this.cacheSegData){const{points:a,indexes:n}=this.cacheSegData;this.cacheSegData=b(P({},this.cacheSegData),{points:y.splitPointsFromPoints(a,t),indexes:y.splitPointsFromIndexes(n,s)}),this.emit("updateNewPoints",this.cacheSegData)}break}this.updateStatus2Edit(),this.emit("syncPointCloudStatus",{segmentStatus:this.segmentStatus,cacheSegData:this.cacheSegData})}syncPointCloudStatus(){this.statusToggle();const{segmentStatus:t,cacheSegData:e}=this;this.emit("syncPointCloudStatus",{segmentStatus:t,cacheSegData:e})}syncSegmentData(){this.emit("syncSegmentData",this.formatData)}addStash2Store(){this.isEditStatus&&this.cacheSegData&&(this.cacheSegData.coverPoints&&this.cacheSegData.coverPoints.length!==0&&this.updateCoverPoints(this.cacheSegData.coverPoints),delete this.cacheSegData.coverPoints,this.segmentData.set(this.cacheSegData.id,this.cacheSegData),this.cacheSegData=void 0,this.syncPointCloudStatus(),this.syncSegmentData())}updateCloudDataStatus(t,e){for(let s=0;s<t.length;s+=3){const a=t[s],n=t[s+1],o=t[s+2],h=y.getCloudKeys(a,n,o),p=this.cloudData.get(h);Object.keys(e).forEach(i=>{p[i]=e[i]})}}clearStash(){if(this.isEditStatus&&this.cacheSegData){if(this.updateCloudDataStatus(this.cacheSegData.points,{visible:!1}),this.segmentData.has(this.cacheSegData.id)){const t=this.segmentData.get(this.cacheSegData.id);t&&(this.emit("updateNewPoints",t),this.updateCloudDataStatus(t==null?void 0:t.points,{visible:!0}))}else this.emit("clearStashRender");this.syncSegmentData(),this.cacheSegData=void 0,this.syncPointCloudStatus()}}deleteSelectedSegmentData(t=""){if((this.isCheckStatus||this.isEditStatus)&&this.cacheSegData){const e=this.scene.getObjectByName(t),{indexes:s}=this.cacheSegData;if(e&&s){const a=e.geometry.attributes.position.array;for(let n=0;n<s.length;n++){const o=this.cloudData.get(y.getCloudKeys(a[n],a[n+1],a[n+2]));o&&(o.visible=!1)}this.resetSelectedSegmentStatus()}}}resetSelectedSegmentStatus(){this.cacheSegData=void 0,m.updateStatus2Ready(),this.emit("syncPointCloudStatus",{segmentStatus:this.segmentStatus,cacheSegData:this.cacheSegData})}updateCheck2Edit(){this.isCheckStatus&&this.syncPointCloudStatus()}checkPoints(){if(this.isReadyStatus||this.isCheckStatus){const t=this.segmentData.get(this.hoverPointsID);t?(this.cacheSegData=b(P({},t),{points:new Float32Array(t.points)}),m.updateStatus2Check(),this.emit("syncPointCloudStatus",{segmentStatus:this.segmentStatus,cacheSegData:this.cacheSegData})):this.resetSelectedSegmentStatus()}}editPoints(){const t=this.segmentData.get(this.hoverPointsID);t&&(this.cacheSegData=b(P({},t),{points:new Float32Array(t.points)}),this.emit("updateNewPoints"),this.syncPointCloudStatus())}setForbidOperation(t){this.forbidOperation=t}updateMouse(t){const e=t.x/this.containerWidth*2-1,s=-(t.y/this.containerHeight)*2+1;this.mouse.setX(e),this.mouse.setY(s)}resetAllSegDataSize(){this.highlightAttribute===""&&this.allSegmentPoints.forEach(t=>{var e;((e=this.cacheSegData)==null?void 0:e.id)!==t.name&&(t.material.size=5)})}resetHoverPointsID(){this.hoverPointsID=""}resetAllSegDataSizeAndRender(){this.resetAllSegDataSize(),this.emit("reRender3d")}highlightPoints(t){!(this.isCheckStatus||this.isReadyStatus)||(this.resetAllSegDataSize(),t.material.size=10,this.hoverPointsID=t.name,this.emit("reRender3d"))}highlightPointsByAttribute(t){this.highlightAttribute=t,this.segmentData.size!==0&&(this.resetAllSegDataSize(),this.segmentData.forEach((e,s)=>{if(e.attribute===t){const a=this.scene.getObjectByName(s);a&&(a==null?void 0:a.material)&&(a.material.size=10)}}),this.emit("reRender3d"))}setAttribute(t){this.currentAttribute=t}}export{j as default};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@labelbee/lb-annotation",
3
- "version": "1.16.0-alpha.5",
3
+ "version": "1.16.0-alpha.7",
4
4
  "description": "Annotation tool collection",
5
5
  "keywords": [
6
6
  "annotation",