@labelbee/lb-annotation 1.23.1-alpha.1 → 1.24.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
1
+ "use strict";var _rollupPluginWebWorkerLoader__helper__browser__createBase64WorkerFactory=require("./_rollup-plugin-web-worker-loader__helper__browser__createBase64WorkerFactory.js"),WorkerFactory=_rollupPluginWebWorkerLoader__helper__browser__createBase64WorkerFactory.createBase64WorkerFactory("Lyogcm9sbHVwLXBsdWdpbi13ZWItd29ya2VyLWxvYWRlciAqLwooZnVuY3Rpb24oKXsidXNlIHN0cmljdCI7b25tZXNzYWdlPWZ1bmN0aW9uKGkpe2NvbnN0e3BvaW50czpzfT1pLmRhdGEsZT1uZXcgTWFwO2ZvcihsZXQgdD0wO3Q8cy5sZW5ndGg7dCs9Myl7Y29uc3Qgbz1zW3RdLGM9c1t0KzFdLGE9c1t0KzJdLG49YCR7TWF0aC5jZWlsKG8pfUAke01hdGguY2VpbChjKX1AJHtNYXRoLmNlaWwoYSl9YDtlLmhhcyhuKXx8ZS5zZXQobixbXSksZS5nZXQobikucHVzaCh7eDpvLHk6Yyx6OmF9KX10aGlzLnBvc3RNZXNzYWdlKHtpbmRleE1hcDplfSl9fSkoKTsKCg==",null,!1);module.exports=WorkerFactory;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var PCDLoader=require("./PCDLoader.js");class PointCloudCache{constructor(){this.MAX_SIZE=50,this.cacheList=[],this.loadPCDFile=t=>new Promise((i,n)=>{const s=this.pointsMap.get(t),o=this.colorMap.get(t);if(s&&o){i({points:s,color:o});return}if(this.cacheList.length>this.MAX_SIZE){const e=this.cacheList.shift();e&&this.pointsMap.delete(e.src)}this.cacheList.push({src:t}),this.pcdLoader.load(t,e=>{const a=e.geometry.attributes.position.array,r=e.geometry.attributes.color.array;this.pointsMap.set(t,a),this.colorMap.set(t,r),i({points:a,color:r})},()=>{},e=>{n(e)})}),this.pcdLoader=new PCDLoader.PCDLoader,this.pointsMap=new Map,this.colorMap=new Map,this.cache2DHighlightIndex=new Map}static getInstance(){return this.instance==null&&(this.instance=new PointCloudCache),this.instance}updateColor(t,i){this.colorMap.set(t,i)}clearCache2DHighlightIndex(){this.cache2DHighlightIndex.clear()}}exports.PointCloudCache=PointCloudCache;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var generateIndexWorker=require("../../_virtual/generateIndexWorker.js"),PCDLoader=require("./PCDLoader.js"),__async=(h,e,s)=>new Promise((o,n)=>{var r=t=>{try{a(s.next(t))}catch(c){n(c)}},i=t=>{try{a(s.throw(t))}catch(c){n(c)}},a=t=>t.done?o(t.value):Promise.resolve(t.value).then(r,i);a((s=s.apply(h,e)).next())});class PointCloudCache{constructor(){this.MAX_SIZE=50,this.cacheList=[],this.loadPCDFile=e=>new Promise((s,o)=>{const n=this.pointsMap.get(e),r=this.colorMap.get(e);if(n&&r){s({points:n,color:r});return}if(this.cacheList.length>this.MAX_SIZE){const i=this.cacheList.shift();i&&this.pointsMap.delete(i.src)}this.cacheList.push({src:e}),this.pcdLoader.load(e,i=>{const a=i.geometry.attributes.position.array,t=i.geometry.attributes.color.array;this.pointsMap.set(e,a),this.colorMap.set(e,t),s({points:a,color:t})},()=>{},i=>{o(i)})}),this.loadIndexMap=(e,s)=>__async(this,null,function*(){const o=this.cacheIndexMap.get(e);return new Promise(n=>{if(o)return n(o);if(window.Worker){const r=new generateIndexWorker({type:"module"});r.postMessage({points:s}),r.onmessage=i=>{const{indexMap:a}=i.data;if(this.cacheIndexMap.set(e,a),this.cacheIndexMap.size>this.MAX_SIZE){const t=Array.from(this.cacheIndexMap.keys())[0];this.cacheIndexMap.delete(t)}n(a),r.terminate()}}})}),this.pcdLoader=new PCDLoader.PCDLoader,this.pointsMap=new Map,this.colorMap=new Map,this.cacheIndexMap=new Map,this.cache2DHighlightIndex=new Map}static getInstance(){return this.instance==null&&(this.instance=new PointCloudCache),this.instance}updateColor(e,s){this.colorMap.set(e,s)}clearCache2DHighlightIndex(){this.cache2DHighlightIndex.clear()}}exports.PointCloudCache=PointCloudCache;
@@ -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"),ImgUtils=require("../../utils/ImgUtils.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(f){if(f&&f.__esModule)return f;var t=Object.create(null);return f&&Object.keys(f).forEach(function(e){if(e!=="default"){var i=Object.getOwnPropertyDescriptor(f,e);Object.defineProperty(t,e,i.get?i:{enumerable:!0,get:function(){return f[e]}})}}),t.default=f,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=(f,t,e)=>t in f?__defProp(f,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):f[t]=e,__spreadValues=(f,t)=>{for(var e in t||(t={}))__hasOwnProp.call(t,e)&&__defNormalProp(f,e,t[e]);if(__getOwnPropSymbols)for(var e of __getOwnPropSymbols(t))__propIsEnum.call(t,e)&&__defNormalProp(f,e,t[e]);return f},__spreadProps=(f,t)=>__defProps(f,__getOwnPropDescs(t)),__async=(f,t,e)=>new Promise((i,r)=>{var s=l=>{try{o(e.next(l))}catch(n){r(n)}},a=l=>{try{o(e.throw(l))}catch(n){r(n)}},o=l=>l.done?i(l.value):Promise.resolve(l.value).then(s,a);o((e=e.apply(f,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:o,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.highlightGroupName="highlightBoxes",this.showDirection=!0,this.pointsMaterialSize=1,this.isSegment=!1,this.checkMode=!1,this.nextTick=()=>{!this.segmentOperation||this.segmentOperation._raycasting()},this.keydown=n=>{if(!!this.store)switch(n.key){case" ":this.controls.enablePan=!0,this.store.setForbidOperation(!0);break}},this.keyup=n=>{if(!!this.store)switch(n.key){case" ":this.controls.enablePan=!1,this.store.setForbidOperation(!1);break}},this.addSphereToSense=(n,c="blue")=>{var h;const d=(h=n.id)!=null?h:uuid();this.removeObjectByName(d,"sphere");const{radius:u,widthSegments:m,heightSegments:p}=lbUtils.DEFAULT_SPHERE_PARAMS,{center:g}=n,y=new THREE__namespace.Group,x=new THREE__namespace.SphereGeometry(u,m,p),w=new THREE__namespace.MeshBasicMaterial({color:c}),b=new THREE__namespace.Mesh(x,w);b.position.set(g.x,g.y,g.z),y.add(b),y.name=`sphere${d}`,this.scene.add(y)},this.generateSphere=n=>{const{fill:c}=this.getColorFromConfig(n.attribute);this.addSphereToSense(n,c),this.render()},this.generateSpheres=n=>{n.forEach(c=>{const{fill:h}=this.getColorFromConfig(c.attribute);this.addSphereToSense(c,h)}),this.render()},this.addBoxToSense=(n,c=16777215)=>{var h;const d=(h=n.id)!=null?h:uuid();this.removeObjectByName(d,"box");const{center:u,width:m,height:p,depth:g,rotation:y}=n,x=new THREE__namespace.Group,w=new THREE__namespace.BoxGeometry(m,p,g),b=new THREE__namespace.MeshBasicMaterial({color:"blue"}),C=new THREE__namespace.Mesh(w,b),P=new THREE__namespace.BoxHelper(C,c),M=this.generateBoxArrow(n),v=this.generateBoxTrackID(n);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=n=>{if(this.camera.type==="OrthographicCamera"&&n){const c=this.getOrthographicCameraTarget(n);this.updateCameraZoom(n.zoom),this.updateCamera(n.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"),ImgUtils=require("../../utils/ImgUtils.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(f){if(f&&f.__esModule)return f;var t=Object.create(null);return f&&Object.keys(f).forEach(function(e){if(e!=="default"){var i=Object.getOwnPropertyDescriptor(f,e);Object.defineProperty(t,e,i.get?i:{enumerable:!0,get:function(){return f[e]}})}}),t.default=f,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=(f,t,e)=>t in f?__defProp(f,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):f[t]=e,__spreadValues=(f,t)=>{for(var e in t||(t={}))__hasOwnProp.call(t,e)&&__defNormalProp(f,e,t[e]);if(__getOwnPropSymbols)for(var e of __getOwnPropSymbols(t))__propIsEnum.call(t,e)&&__defNormalProp(f,e,t[e]);return f},__spreadProps=(f,t)=>__defProps(f,__getOwnPropDescs(t)),__async=(f,t,e)=>new Promise((i,r)=>{var s=l=>{try{o(e.next(l))}catch(n){r(n)}},h=l=>{try{o(e.throw(l))}catch(n){r(n)}},o=l=>l.done?i(l.value):Promise.resolve(l.value).then(s,h);o((e=e.apply(f,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:h,isSegment:o,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.highlightGroupName="highlightBoxes",this.showDirection=!0,this.pointsMaterialSize=1,this.isSegment=!1,this.checkMode=!1,this.nextTick=()=>{!this.segmentOperation||this.segmentOperation._raycasting()},this.keydown=n=>{if(!!this.store)switch(n.key){case" ":this.controls.enablePan=!0,this.store.setForbidOperation(!0);break}},this.keyup=n=>{if(!!this.store)switch(n.key){case" ":this.controls.enablePan=!1,this.store.setForbidOperation(!1);break}},this.addSphereToSense=(n,c="blue")=>{var a;const d=(a=n.id)!=null?a:uuid();this.removeObjectByName(d,"sphere");const{radius:u,widthSegments:m,heightSegments:p}=lbUtils.DEFAULT_SPHERE_PARAMS,{center:g}=n,y=new THREE__namespace.Group,x=new THREE__namespace.SphereGeometry(u,m,p),w=new THREE__namespace.MeshBasicMaterial({color:c}),C=new THREE__namespace.Mesh(x,w);C.position.set(g.x,g.y,g.z),y.add(C),y.name=`sphere${d}`,this.scene.add(y)},this.generateSphere=n=>{const{fill:c}=this.getColorFromConfig(n.attribute);this.addSphereToSense(n,c),this.render()},this.generateSpheres=n=>{n.forEach(c=>{const{fill:a}=this.getColorFromConfig(c.attribute);this.addSphereToSense(c,a)}),this.render()},this.addBoxToSense=(n,c=16777215)=>{var a;const d=(a=n.id)!=null?a:uuid();this.removeObjectByName(d,"box");const{center:u,width:m,height:p,depth:g,rotation:y}=n,x=new THREE__namespace.Group,w=new THREE__namespace.BoxGeometry(m,p,g),C=new THREE__namespace.MeshBasicMaterial({color:"blue"}),b=new THREE__namespace.Mesh(w,C),P=new THREE__namespace.BoxHelper(b,c),M=this.generateBoxArrow(n),v=this.generateBoxTrackID(n);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=n=>{if(this.camera.type==="OrthographicCamera"&&n){const c=this.getOrthographicCameraTarget(n);this.updateCameraZoom(n.zoom),this.updateCamera(n.position,c)}},this.initShaderMaterial=()=>({vertexShader:`
2
2
  attribute vec3 dimensions;
3
3
  varying vec3 vDimensions;
4
4
  uniform float pointSize;
@@ -28,4 +28,4 @@
28
28
 
29
29
  // Output the final color
30
30
  gl_FragColor = vec4(color, 1.0);
31
- }`,uniforms:{pointSize:{value:this.pointsMaterialSize}}}),this.loadPCDFile=(...n)=>__async(this,[...n],function*(c=this.currentPCDSrc,h){if(!c)return;this.clearPointCloud(),this.cacheInstance.clearCache2DHighlightIndex(),this.currentPCDSrc=c;const{points:d,color:u}=yield this.cacheInstance.loadPCDFile(c),m=new THREE__namespace.BufferGeometry;m.setAttribute("position",new THREE__namespace.BufferAttribute(d,3)),this.isSegment||m.setAttribute("dimensions",new THREE__namespace.BufferAttribute(u,3)),this.initCloudData(d);const p=new THREE__namespace.Points(m);this.renderPointCloud(p,h),this.emit("loadPCDFileEnd")}),this.getHighlightIndexByMappingImgList=n=>__async(this,[n],function*({mappingImgList:c,points:h}){const d=c.length===0?[]:yield Promise.all(c.map(p=>ImgUtils.default.load(p.url))),u=c.map((p,g)=>{var y;if(this.cacheInstance.cache2DHighlightIndex.has(p.url))return(y=this.cacheInstance.cache2DHighlightIndex.get(p.url))!=null?y:[];const x=matrix.getHighlightIndexByPoints({points:h,calib:p.calib,width:d[g].width,height:d[g].height});return this.cacheInstance.cache2DHighlightIndex.set(p.url,x),x});return matrix.mergeHighlightList(u)}),this.loadPCDFileByBox=(n,c,h)=>__async(this,null,function*(){const d=(p,g)=>__async(this,null,function*(){const{width:y=0,height:x=0,depth:w=0}=h!=null?h:{},b=yield this.filterPointsByBox(__spreadProps(__spreadValues({},c),{width:c.width+y,height:c.height+x,depth:c.depth+w}),p,g);if(!b){console.error("filter Error");return}this.clearPointCloud(),this.currentPCDSrc=n;const C=new THREE__namespace.Points(b.geometry);C.name=this.pointCloudObjectName,this.scene.add(C),this.render()}),{points:u,color:m}=yield this.cacheInstance.loadPCDFile(n);d(u,m)}),this.generateRange=n=>{const c=this.createRange(n);this.scene.add(c)},this.generateBoxArrow=({width:n})=>{const c=new THREE__namespace.Vector3(1,0,0),h=new THREE__namespace.Vector3(n/2,0,0),d=2,u=16776960,m=new THREE__namespace.ArrowHelper(c,h,d,u);return m.visible=this.showDirection,m},this.generateBoxTrackID=n=>{if(!n.trackID)return;const c=new THREE__namespace.Texture(this.getTextCanvas(n.trackID.toString()));c.needsUpdate=!0;const h=new THREE__namespace.SpriteMaterial({map:c,depthWrite:!1}),d=new THREE__namespace.Sprite(h);return d.scale.set(5,5,5),d.position.set(-n.width/2,0,n.depth/2+.5),d},this.applyZAxisPoints=n=>{this.zAxisLimit=n,this.filterZAxisPoints(),this.render()},this.updatePointSize=({zoomIn:n,customSize:c})=>{const h=this.scene.getObjectByName(this.pointCloudObjectName);if(!h)return;const d=h.material.uniforms.pointSize.value;n?h.material.uniforms.pointSize.value=Math.min(d*1.2,10):h.material.uniforms.pointSize.value=Math.max(d/1.2,1),c&&(h.material.uniforms.pointSize.value=c,this.pointsMaterialSize=c),h.material.uniformsNeedUpdate=!0,this.render()},this.container=t,this.renderer=new THREE__namespace.WebGLRenderer({antialias:!0}),this.backgroundColor=s,this.config=a,this.checkMode=l!=null?l:!1,i&&r?(this.isOrthographicCamera=!0,this.camera=new THREE__namespace.OrthographicCamera(r.left,r.right,r.top,r.bottom,r.near,r.far)):this.camera=new THREE__namespace.PerspectiveCamera(30,this.containerWidth/this.containerHeight,1,1e3),this.initCamera(),this.scene=new THREE__namespace.Scene,this.controls=new OrbitControls.OrbitControls(this.camera,o?this.container:this.renderer.domElement),this.pcdLoader=new PCDLoader.PCDLoader,this.axesHelper=new THREE__namespace.AxesHelper(1e3),this.scene.add(this.camera),e||t.appendChild(this.renderer.domElement),this.init(),this.cacheInstance=cache.PointCloudCache.getInstance(),o===!0&&(this.initSegment(),this.isSegment=!0)}initSegment(){this.store=new index(this.pointCloudDelegate),this.controls.enablePan=!1,this.controls.addEventListener("start",this.orbiterStart.bind(this)),this.controls.addEventListener("change",this.orbiterChange.bind(this)),this.controls.addEventListener("end",this.orbiterEnd.bind(this)),this.segmentOperation=new segmentation.PointCloudSegmentOperation(__spreadValues({dom:this.container,store:this.store},this.eventBus)),this.pointCloudRender=new index$1(__spreadProps(__spreadValues({store:this.store},this.eventBus),{nextTick:this.nextTick})),this.initMsg(),document.addEventListener("keydown",this.keydown),document.addEventListener("keyup",this.keyup)}orbiterStart(){}orbiterChange(){!this.store||(this.store.orbiting=!0)}orbiterEnd(){!this.store||(this.store.orbiting=!1)}get currentSegmentTool(){var t;return(t=this.segmentOperation)==null?void 0:t.currentToolName}get pointCloudObject(){return this.scene.getObjectByName(this.pointCloudObjectName)}initMsg(){!this.segmentOperation||(this.on("CircleSelector",this.segmentOperation.updateSelector2Circle.bind(this.segmentOperation)),this.on("LassoSelector",this.segmentOperation.updateSelector2Lasso.bind(this.segmentOperation)),this.on("RectSelector",this.segmentOperation.updateSelector2Rect.bind(this.segmentOperation)),this.on("clearPointCloud",this.clearPointCloud.bind(this)),this.on("loadPCDFile",this.loadPCDFile.bind(this)))}unbindMsg(){!this.segmentOperation||(this.unbind("CircleSelector",this.segmentOperation.updateSelector2Circle.bind(this.segmentOperation)),this.unbind("LassoSelector",this.segmentOperation.updateSelector2Lasso.bind(this.segmentOperation)),this.unbind("RectSelector",this.segmentOperation.updateSelector2Rect.bind(this.segmentOperation)),this.unbind("clearPointCloud",this.clearPointCloud.bind(this)),this.unbind("loadPCDFile",this.loadPCDFile.bind(this)))}get eventBus(){return{on:this.on.bind(this),emit:this.emit.bind(this),unbind:this.unbind.bind(this)}}get pointCloudDelegate(){return __spreadValues({container:this.container,scene:this.scene,camera:this.camera,renderer:this.renderer,checkMode:this.checkMode,config:this.config},this.eventBus)}get DEFAULT_INIT_CAMERA_POSITION(){return new THREE__namespace.Vector3(-.01,0,1e3)}get containerWidth(){return this.container.clientWidth}get containerHeight(){return this.container.clientHeight}setInitCameraPosition(t){this.initCameraPosition=t}setConfig(t){var e;this.config=t,(e=this.store)==null||e.setConfig(t)}initOrthographicCamera(t){if(this.camera.type!=="OrthographicCamera")return;const{left:e,right:i,top:r,bottom:s,near:a,far:o}=t;this.camera.left=e,this.camera.right=i,this.camera.top=r,this.camera.bottom=s,this.camera.near=a,this.camera.far=o,this.camera.updateProjectionMatrix()}initPerspectiveCamera(){this.camera.type==="PerspectiveCamera"&&(this.camera.fov=30,this.camera.aspect=this.containerWidth/this.containerHeight,this.camera.near=1,this.camera.far=1e3,this.camera.updateProjectionMatrix())}initCamera(){const{camera:t}=this;if(this.isOrthographicCamera){const{x:e,y:i,z:r}=this.initCameraPosition;t.position.set(e,i,r)}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,e=""){const i=this.scene.getObjectByName(e+t);i&&i.removeFromParent()}getColorFromConfig(t){return lbUtils.toolStyleConverter.getColorFromConfig({attribute:t},__spreadProps(__spreadValues({},this.config),{attributeConfigurable:!0}),{})}generateBox(t,e=16777215){const i=e;this.addBoxToSense(t,i),this.render()}getAllAttributeColor(t){return t.reduce((e,i)=>(e[i.attribute]=this.getColorFromConfig(i.attribute),e),{})}generateBoxes(t){t.forEach(e=>{this.addBoxToSense(e)}),this.render()}getOrthographicCamera(t){const{center:e,width:i,height:r}=t,s=10,a=e.x-i/2-s,o=e.x-i/2+s,l=e.y+r/2+s,n=e.y-r/2-s,c=100,h=-100,d=500/c;return{left:a,right:o,top:l,bottom:n,near:c,far:h,zoom:d}}updateCameraZoom(t){this.camera.zoom=t,this.camera.updateProjectionMatrix()}updateCameraByBox(t,e,i){const{center:r,width:s,height:a,depth:o,rotation:l}=t,n=this.getCameraVector(r,l,{width:s,height:a,depth:o},e);return i?(this.updateCamera(i,r),new THREE__namespace.Vector3(i.x,i.y,i.z)):(this.updateCamera(n,r),n)}updateCameraBySphere(t,e){const{center:i}=t,{radius:r}=lbUtils.DEFAULT_SPHERE_PARAMS,s=this.getCameraVector(i,0,{width:r*2,height:r*2,depth:r*2},e);return this.updateCamera(s,i),s}updateOrthoCamera(t,e){const i=this.updateCameraByBox(t,e);return this.camera.zoom=1,this.camera.updateProjectionMatrix(),{cameraPositionVector:i}}updateOrthoCameraBySphere(t,e){const i=this.updateCameraBySphere(t,e);return this.camera.zoom=1,this.camera.updateProjectionMatrix(),{cameraPositionVector:i}}updateTopCamera(){this.setInitCameraPosition(this.DEFAULT_INIT_CAMERA_POSITION),this.camera.zoom=1,this.initCamera(),this.setDefaultControls(),this.camera.updateProjectionMatrix(),this.render()}updateCamera(t,e){this.camera.position.set(t.x,t.y,t.z),this.controls.target=new THREE__namespace.Vector3(e.x,e.y,e.z),this.controls.update()}resetCamera(){this.updateCamera(this.DEFAULT_INIT_CAMERA_POSITION,{x:0,y:0,z:0})}getOrthographicCameraTarget(t){const e=new THREE__namespace.Vector3(0,0,-1).applyQuaternion(t.quaternion);return t.position.clone().add(e)}createThreeMatrix4(t){return new THREE__namespace.Matrix4().set(...t)}filterPointsByBox(t,e,i){var r,s,a;if(!e){const o=this.scene.getObjectByName(this.pointCloudObjectName);if(!o)return console.error("There is no corresponding point cloud object"),Promise.resolve(void 0);e=(a=(s=(r=o==null?void 0:o.geometry)==null?void 0:r.attributes)==null?void 0:s.position)==null?void 0:a.array}if(window.Worker){const{zMin:o,zMax:l,polygonPointList:n}=matrix.getCuboidFromPointCloudBox(t),c=e;i=i!=null?i:new Float32Array([]);const h={boxParams:t,zMin:o,zMax:l,polygonPointList:n,color:i,position:c};return new Promise(d=>{const u=new filterBoxWorker;u.postMessage(h),u.onmessage=m=>{const{color:p,position:g,num:y}=m.data,x=new THREE__namespace.BufferGeometry;x.setAttribute("position",new THREE__namespace.Float32BufferAttribute(g,3)),x.setAttribute("color",new THREE__namespace.Float32BufferAttribute(p,3)),x.computeBoundingSphere(),u.terminate(),d({geometry:x,num:y})}})}return Promise.resolve(void 0)}getCameraVector(t,e,i,r=lbUtils.EPerspectiveView.Front,s=DEFAULT_DISTANCE){let a=lbUtils.PerspectiveShiftUtils.frontViewMatrix4(s);switch(r){case lbUtils.EPerspectiveView.Front:break;case lbUtils.EPerspectiveView.Back:a=lbUtils.PerspectiveShiftUtils.backViewMatrix4(s);break;case lbUtils.EPerspectiveView.Left:a=lbUtils.PerspectiveShiftUtils.leftViewMatrix4(s);break;case lbUtils.EPerspectiveView.Right:a=lbUtils.PerspectiveShiftUtils.rightViewMatrix4(s);break;case lbUtils.EPerspectiveView.Top:a=lbUtils.PerspectiveShiftUtils.topViewMatrix4(s);break;case lbUtils.EPerspectiveView.LFT:a=lbUtils.PerspectiveShiftUtils.leftFrontTopViewMatrix4(s,i);break;case lbUtils.EPerspectiveView.RBT:a=lbUtils.PerspectiveShiftUtils.rightBackTopViewMatrix4(s,i);break}const o=this.createThreeMatrix4(a),l=new THREE__namespace.Matrix4().makeTranslation(-t.x,-t.y,-t.z),n=new THREE__namespace.Matrix4().makeTranslation(t.x,t.y,t.z),c=new THREE__namespace.Matrix4().makeRotationZ(e);return new THREE__namespace.Vector3(t.x,t.y,t.z).clone().applyMatrix4(o).applyMatrix4(l).applyMatrix4(c).applyMatrix4(n)}createRange(t){this.removeObjectByName(this.rangeObjectName);const i=new THREE__namespace.EllipseCurve(0,0,t,t,0,2*Math.PI,!1,0).getPoints(50),r=new THREE__namespace.BufferGeometry().setFromPoints(i),s=new THREE__namespace.LineBasicMaterial({color:16711680}),a=new THREE__namespace.Line(r,s);return a.name=this.rangeObjectName,a}renderPointCloud(t,e){t.name=this.pointCloudObjectName;const i=new THREE__namespace.ShaderMaterial(this.initShaderMaterial());e&&this.generateRange(e),this.pointsUuid=t.uuid,t.material=i,this.filterZAxisPoints(t),this.scene.add(t),this.render()}clearAllBox(){this.clearAllGroupByPrefix("box")}clearAllSphere(){this.clearAllGroupByPrefix("sphere")}clearAllGroupByPrefix(t=""){const e=this.scene.children;for(let i=e.length-1;i>=0;i--){const r=e[i];r.type==="Group"&&r.name.startsWith(t)&&this.removeObjectByName(r.name)}}clearPointCloud(){this.removeObjectByName(this.pointCloudObjectName)}clearPointCloudAndRender(){this.clearPointCloud(),this.render()}initCloudData(t){if(!!this.store){for(let e=0;e<t.length;e+=3){const i=t[e],r=t[e+1],s=t[e+2];this.store.cloudData.set(`${i}@${r}@${s}`,{visible:!1})}this.store.setOriginPoints(t)}}highlightOriginPointCloud(t,e=[]){const i=this.scene.getObjectByName(this.pointCloudObjectName);if(!!i)return this.highlightPCDSrc=this.currentPCDSrc,new Promise((r,s)=>{if(window.Worker){const o=(t?[...t]:[]).map(c=>matrix.getCuboidFromPointCloudBox(c)),l=this.getAllAttributeColor(o),n={cuboidList:o,position:i.geometry.attributes.position.array,color:i.geometry.attributes.dimensions.array,colorList:l,highlightIndex:e};highlightWorker.postMessage(n),highlightWorker.onmessage=c=>{const{color:h}=c.data,d=new THREE__namespace.BufferAttribute(h,3);if(!this.highlightPCDSrc||this.highlightPCDSrc!==this.currentPCDSrc||i.geometry.attributes.position.array.length!==h.length){s(new Error("Error Path"));return}this.cacheInstance.updateColor(this.highlightPCDSrc,h),this.highlightPCDSrc=void 0,d.needsUpdate=!0,i.geometry.setAttribute("dimensions",d),i.geometry.attributes.dimensions.needsUpdate=!0,r(h),this.render()}}})}clearHighlightBoxes(){this.removeObjectByName(this.highlightGroupName)}clearHighlightBoxesAndRender(){this.clearHighlightBoxes(),this.render()}highlightBoxes(t){const e=new THREE__namespace.Group;t.forEach(i=>{const{center:{x:r,y:s,z:a},width:o,height:l,depth:n,rotation:c}=i,{fill:h}=lbUtils.toolStyleConverter.getColorFromConfig({attribute:i.attribute},__spreadProps(__spreadValues({},this.config),{attributeConfigurable:!0}),{}),d=new THREE__namespace.BoxGeometry(o,l,n),u=new THREE__namespace.MeshBasicMaterial({color:h,transparent:!0,opacity:.2,depthTest:!1});d.rotateZ(c),d.translate(r,s,a);const m=new THREE__namespace.Mesh(d,u);e.add(m);const p=new THREE__namespace.PlaneGeometry(n,l);p.rotateY(Math.PI/2),p.rotateZ(c);const g=new THREE__namespace.Vector3(o/2,0,0),y=new THREE__namespace.Matrix4().makeRotationY(Math.PI/2).makeRotationZ(c);g.applyMatrix4(y),p.translate(r+g.x,s+g.y,a+g.z);const x=new THREE__namespace.MeshBasicMaterial({color:h,side:THREE__namespace.DoubleSide,transparent:!0,opacity:.8,depthTest:!1}),w=new THREE__namespace.Mesh(p,x);e.add(w)}),e.name=this.highlightGroupName,this.scene.add(e),this.render()}updateColor(t){const e=this.scene.getObjectByName(this.pointCloudObjectName);if(e){const i=new THREE__namespace.BufferAttribute(t,3);e.geometry.setAttribute("dimensions",i),e.geometry.attributes.dimensions.needsUpdate=!0,this.render()}}setShowDirection(t){this.showDirection=t,this.scene.children.forEach(e=>{e.type==="Group"&&e.children.forEach(i=>{i.type==="ArrowHelper"&&(i.visible=t)})}),this.render()}getTextCanvas(t){const e=document.createElement("canvas"),i=e.getContext("2d");return i&&(i.font=`${50}px " bold`,i.fillStyle="white",i.textAlign="center",i.textBaseline="middle",i.fillText(t,e.width/2,e.height/2)),e}filterNoise(t){let e=[...t];e.sort((h,d)=>h.z-d.z);const i=Math.floor(e.length*.05),r=e[i];e=e.filter(({z:h})=>h>r.z+.1);const s=.005,a=Math.floor(e.length*(1-s));e=e.slice(0,a),e.sort((h,d)=>h.x-d.x);const o=Math.floor(e.length*s),l=Math.floor(e.length*(1-s));e=e.slice(o,l),e.sort((h,d)=>h.y-d.y);const n=Math.floor(e.length*s),c=Math.floor(e.length*(1-s));return e=e.slice(n,c),e.length>100?e:t}getFittedCoordinates(t,e){const i=[];let r=[...t,t[0]];e.forEach(({x:l,y:n})=>{t.forEach((c,h)=>{const d=r[h+1],u=MathUtils.default.getFootOfPerpendicular({x:l,y:n},c,d,!1,!0).length;(!i[h]||u<i[h].distance)&&(i[h]={distance:u,point:{x:l,y:n}})})}),r=[t[t.length-1],...t,t[0]];const s=[i[i.length-1],...i],a=t.map((l,n)=>{const c=r[n],h=r[n+1],d=r[n+2];return lbUtils.PointCloudUtils.getIntersectionBySlope({p1:s[n].point,line1:[c,h],p2:s[n+1].point,line2:[h,d]})});return a.some(l=>!(Number.isFinite(l.x)&&Number.isFinite(l.y)))?t:a}getSensesPointZAxisInPolygon(t,e,i){var r,s,a;const o=this.scene.children.find(p=>p.uuid===this.pointsUuid);let l=0,n=0,c=0,h=0,d=[],u=[];const m=((a=(s=(r=o==null?void 0:o.geometry)==null?void 0:r.attributes)==null?void 0:s.position)==null?void 0:a.array)||[];for(let p=0;p<m.length;p+=3){const g=m[p],y=m[p+1],x=m[p+2];polygonTool.isInPolygon({x:g,y},t)&&(x||x===0)&&u.push({x:g,y,z:x})}return u.length?(i&&(u=this.filterNoise(u),d=this.getFittedCoordinates(t,u)),u.sort((p,g)=>p.z-g.z),l=u[0].z-.01,n=u[u.length-1].z+.01,h=u.length,e&&(c=u.filter(({z:p})=>p>=e[0]&&p<=e[1]).length),{maxZ:n,minZ:l,count:c,zCount:h,fittedCoordinates:d}):{maxZ:n,minZ:l,count:c,zCount:h,fittedCoordinates:d}}getBasicCoordinate2Canvas(t){const e=this.containerWidth/2,i=this.containerHeight/2;return{x:t.x*e+e,y:t.y*i+i,z:t.z}}get basicCoordinate2CanvasMatrix4(){const t=this.containerWidth/2,e=this.containerHeight/2;return new THREE__namespace.Matrix4().set(t,0,0,t,0,e,0,e,0,0,1,0,0,0,0,1)}getCanvas2BasicCoordinate(t){const e=this.containerWidth/2,i=this.containerHeight/2;return new THREE__namespace.Vector3(t.x/e-e/2,-(t.y/i-i/2),1)}getPolygonSidePoints(t){const{center:{x:e,y:i,z:r},height:s,width:a,depth:o}=t,l={x:e+a/2,y:i+s/2,z:r-o/2},n={x:e+a/2,y:i+s/2,z:r+o/2},c={x:e-a/2,y:i+s/2,z:r+o/2},h={x:e-a/2,y:i+s/2,z:r-o/2};return[l,n,c,h]}getPolygonBackPoints(t){const{center:{x:e,y:i,z:r},height:s,width:a,depth:o}=t,l={x:e-a/2,y:i+s/2,z:r+o/2},n={x:e-a/2,y:i+s/2,z:r-o/2},c={x:e-a/2,y:i-s/2,z:r-o/2},h={x:e-a/2,y:i-s/2,z:r+o/2};return[l,n,c,h]}getPolygonTopPoints(t){const{center:{x:e,y:i,z:r},height:s,width:a,depth:o}=t,l={x:e+a/2,y:i+s/2,z:r+o/2},n={x:e+a/2,y:i-s/2,z:r+o/2},c={x:e-a/2,y:i-s/2,z:r+o/2},h={x:e-a/2,y:i+s/2,z:r+o/2};return[l,n,c,h]}getModelTransformationMatrix(t){const{center:{x:e,y:i,z:r},rotation:s}=t,a=new THREE__namespace.Matrix4().makeTranslation(-e,-i,-r),o=new THREE__namespace.Matrix4().makeTranslation(e,i,r),l=new THREE__namespace.Matrix4().makeRotationZ(s);return new THREE__namespace.Matrix4().multiply(o).multiply(l).multiply(a)}getBoxSidePolygon2DCoordinate(t){return this.getBoxPolygon2DCoordinate(t,lbUtils.EPerspectiveView.Left)}getBoxBackPolygon2DCoordinate(t){return this.getBoxPolygon2DCoordinate(t,lbUtils.EPerspectiveView.Back)}getSphereSidePoint2DCoordinate(t){return this.getSpherePoint2DCoordinate(t)}getSphereBackPoint2DCoordinate(t){return this.getSpherePoint2DCoordinate(t)}boxParams2ViewPolygon(t,e){switch(e){case lbUtils.EPerspectiveView.Left:return this.getPolygonSidePoints(t);case lbUtils.EPerspectiveView.Back:return this.getPolygonBackPoints(t);default:return this.getPolygonTopPoints(t)}}getBoxPolygon2DCoordinate(t,e){const i=this.boxParams2ViewPolygon(t,e),{width:r,height:s}=t,a=new THREE__namespace.Matrix4().premultiply(this.camera.matrixWorldInverse).premultiply(this.camera.projectionMatrix),o=new THREE__namespace.Matrix4().premultiply(this.getModelTransformationMatrix(t)).premultiply(a).premultiply(this.basicCoordinate2CanvasMatrix4);this.sideMatrix=o;const l=i.map(h=>new THREE__namespace.Vector3(h.x,h.y,h.z)).map(h=>h.applyMatrix4(this.sideMatrix)),n=this.containerWidth/r,c=this.containerHeight/s;return{polygon2d:l,zoom:Math.min(n,c)/2}}getSpherePoint2DCoordinate(t){const{center:e,attribute:i,id:r,valid:s}=t,{radius:a}=lbUtils.DEFAULT_SPHERE_PARAMS,o={center:e,attribute:i,id:r,valid:s,width:a*2,height:a*2,depth:a*2,rotation:0},l=new THREE__namespace.Matrix4().premultiply(this.camera.matrixWorldInverse).premultiply(this.camera.projectionMatrix),n=new THREE__namespace.Matrix4().premultiply(this.getModelTransformationMatrix(o)).premultiply(l).premultiply(this.basicCoordinate2CanvasMatrix4);this.sideMatrix=n;const c=new THREE__namespace.Vector3(e.x,e.y,e.z).applyMatrix4(this.sideMatrix),h=this.containerWidth/(a*2),d=this.containerHeight/(a*2);return{point2d:c,zoom:Math.min(h,d)/2}}getSphereTopPoint2DCoordinate(t){const{center:e}=t,{radius:i}=lbUtils.DEFAULT_SPHERE_PARAMS,r={x:-(e.y-this.containerWidth/2),y:-(e.x-this.containerHeight/2)},s=this.containerWidth/(i*2),a=this.containerHeight/(i*2);return{point2d:r,zoom:Math.min(s,a)/2}}getBoxTopPolygon2DCoordinate(t){const{width:e,height:i}=t,s=this.getPolygonTopPoints(t).map(l=>new THREE__namespace.Vector3(l.x,l.y,l.z)).map(l=>l.applyMatrix4(this.getModelTransformationMatrix(t))).map(l=>({x:l.y,y:l.x})).map(l=>({x:-(l.x-this.containerWidth/2),y:-(l.y-this.containerHeight/2)})),a=this.containerWidth/e,o=this.containerHeight/i;return{polygon2d:s,zoom:Math.min(a,o)/2}}getNewBoxBySideUpdate(t,e,i,r){const s=new THREE__namespace.Matrix4().makeRotationZ(r.rotation),a=new THREE__namespace.Vector3(-t.x,0,0).applyMatrix4(s);let o=r;return o.center={x:o.center.x+a.x,y:o.center.y+a.y,z:o.center.z-t.z},o=__spreadProps(__spreadValues({},o),{width:Math.abs(o.width+e),height:o.height,depth:Math.abs(o.depth+i)}),{newBoxParams:o}}getNewBoxByBackUpdate(t,e,i,r){const s=new THREE__namespace.Matrix4().makeRotationZ(r.rotation),a=new THREE__namespace.Vector3(0,-t.x,0).applyMatrix4(s);let o=r;return o.center={x:o.center.x+a.x,y:o.center.y+a.y,z:o.center.z-t.z},o=__spreadProps(__spreadValues({},o),{width:o.width,height:Math.abs(o.height+e),depth:Math.abs(o.depth+i)}),{newBoxParams:o}}getNewBoxBySideUpdateByPoints(t,e,i,r){var s;const a=(s=this.sideMatrix)==null?void 0:s.invert();if(!this.sideMatrix||!a){console.error("No sideMatrix");return}this.camera.zoom=1,this.camera.updateProjectionMatrix();const o=t.map(g=>new THREE__namespace.Vector3(g.x,g.y,g.z)).map(g=>g.applyMatrix4(a)),[l,n,c,h]=o,d=Math.max(Math.abs(l.x-c.x),Math.abs(l.x-n.x)),m=n.add(h).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(r.center.x,r.center.y,r.center.z));return{newBoxParams:__spreadProps(__spreadValues({},r),{center:{x:r.center.x-m.x,y:r.center.y-m.y,z:r.center.z-i},width:d,height:r.height,depth:r.depth+e,rotation:r.rotation})}}filterZAxisPoints(t){const e=t||this.scene.children.find(i=>i.uuid===this.pointsUuid);if(e){const{attributes:i}=e.geometry,{position:r}=i,s=[],{count:a}=r;for(let o=0;o<a;o++){const l=r.getZ(o);s.push(l>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.getHighlightIndexByPoints=matrix.getHighlightIndexByPoints,exports.isFisheyeCalibValid=matrix.isFisheyeCalibValid,exports.isInImage=matrix.isInImage,exports.isMatrixValid=matrix.isMatrixValid,exports.isMatrixValidByArr=matrix.isMatrixValidByArr,exports.lidar2FisheyeImage=matrix.lidar2FisheyeImage,exports.lidar2image=matrix.lidar2image,exports.mergeHighlightList=matrix.mergeHighlightList,exports.oCamFisheyeTransfer=matrix.oCamFisheyeTransfer,exports.point3DLidar2Image=matrix.point3DLidar2Image,exports.pointCloudLidar2image=matrix.pointCloudLidar2image,exports.pointListLidar2Img=matrix.pointListLidar2Img,exports.pointMappingLidar2image=matrix.pointMappingLidar2image,exports.rotatePoint=matrix.rotatePoint,exports.transferKitti2Matrix=matrix.transferKitti2Matrix,exports.PointCloud=PointCloud;
31
+ }`,uniforms:{pointSize:{value:this.pointsMaterialSize}}}),this.loadPCDFile=(...n)=>__async(this,[...n],function*(c=this.currentPCDSrc,a){if(!c)return;this.clearPointCloud(),this.cacheInstance.clearCache2DHighlightIndex(),this.currentPCDSrc=c;const{points:d,color:u}=yield this.cacheInstance.loadPCDFile(c),m=new THREE__namespace.BufferGeometry;m.setAttribute("position",new THREE__namespace.BufferAttribute(d,3)),this.isSegment||m.setAttribute("dimensions",new THREE__namespace.BufferAttribute(u,3)),this.initCloudData(d);const p=new THREE__namespace.Points(m);this.renderPointCloud(p,a),this.emit("loadPCDFileEnd")}),this.getHighlightIndexByMappingImgList=n=>__async(this,[n],function*({mappingImgList:c,points:a}){const d=c.length===0?[]:yield Promise.all(c.map(p=>ImgUtils.default.load(p.url))),u=c.map((p,g)=>{var y;if(this.cacheInstance.cache2DHighlightIndex.has(p.url))return(y=this.cacheInstance.cache2DHighlightIndex.get(p.url))!=null?y:[];const x=matrix.getHighlightIndexByPoints({points:a,calib:p.calib,width:d[g].width,height:d[g].height});return this.cacheInstance.cache2DHighlightIndex.set(p.url,x),x});return matrix.mergeHighlightList(u)}),this.filterPreResult=(n,c,a)=>__async(this,null,function*(){const{points:d}=yield this.cacheInstance.loadPCDFile(n),u=yield this.cacheInstance.loadIndexMap(n,d);return new Promise(m=>{const p=a.map(g=>{const y=MathUtils.default.calculatePointsInsideBox({indexMap:u,polygon:matrix.getCuboidFromPointCloudBox(g).polygonPointList,zScope:[g.center.z-g.depth/2,g.center.z+g.depth/2],box:g}),x=y>=c.lowerLimitPointsNumInBox;return __spreadProps(__spreadValues({},g),{valid:x,count:y})});m(p)})}),this.loadPCDFileByBox=(n,c,a)=>__async(this,null,function*(){const d=(p,g)=>__async(this,null,function*(){const{width:y=0,height:x=0,depth:w=0}=a!=null?a:{},C=yield this.filterPointsByBox(__spreadProps(__spreadValues({},c),{width:c.width+y,height:c.height+x,depth:c.depth+w}),p,g);if(!C){console.error("filter Error");return}this.clearPointCloud(),this.currentPCDSrc=n;const b=new THREE__namespace.Points(C.geometry);b.name=this.pointCloudObjectName,this.scene.add(b),this.render()}),{points:u,color:m}=yield this.cacheInstance.loadPCDFile(n);d(u,m)}),this.generateRange=n=>{const c=this.createRange(n);this.scene.add(c)},this.generateBoxArrow=({width:n})=>{const c=new THREE__namespace.Vector3(1,0,0),a=new THREE__namespace.Vector3(n/2,0,0),d=2,u=16776960,m=new THREE__namespace.ArrowHelper(c,a,d,u);return m.visible=this.showDirection,m},this.generateBoxTrackID=n=>{if(!n.trackID)return;const c=new THREE__namespace.Texture(this.getTextCanvas(n.trackID.toString()));c.needsUpdate=!0;const a=new THREE__namespace.SpriteMaterial({map:c,depthWrite:!1}),d=new THREE__namespace.Sprite(a);return d.scale.set(5,5,5),d.position.set(-n.width/2,0,n.depth/2+.5),d},this.applyZAxisPoints=n=>{this.zAxisLimit=n,this.filterZAxisPoints(),this.render()},this.updatePointSize=({zoomIn:n,customSize:c})=>{const a=this.scene.getObjectByName(this.pointCloudObjectName);if(!a)return;const d=a.material.uniforms.pointSize.value;n?a.material.uniforms.pointSize.value=Math.min(d*1.2,10):a.material.uniforms.pointSize.value=Math.max(d/1.2,1),c&&(a.material.uniforms.pointSize.value=c,this.pointsMaterialSize=c),a.material.uniformsNeedUpdate=!0,this.render()},this.container=t,this.renderer=new THREE__namespace.WebGLRenderer({antialias:!0}),this.backgroundColor=s,this.config=h,this.checkMode=l!=null?l:!1,i&&r?(this.isOrthographicCamera=!0,this.camera=new THREE__namespace.OrthographicCamera(r.left,r.right,r.top,r.bottom,r.near,r.far)):this.camera=new THREE__namespace.PerspectiveCamera(30,this.containerWidth/this.containerHeight,1,1e3),this.initCamera(),this.scene=new THREE__namespace.Scene,this.controls=new OrbitControls.OrbitControls(this.camera,o?this.container:this.renderer.domElement),this.pcdLoader=new PCDLoader.PCDLoader,this.axesHelper=new THREE__namespace.AxesHelper(1e3),this.scene.add(this.camera),e||t.appendChild(this.renderer.domElement),this.init(),this.cacheInstance=cache.PointCloudCache.getInstance(),o===!0&&(this.initSegment(),this.isSegment=!0)}initSegment(){this.store=new index(this.pointCloudDelegate),this.controls.enablePan=!1,this.controls.addEventListener("start",this.orbiterStart.bind(this)),this.controls.addEventListener("change",this.orbiterChange.bind(this)),this.controls.addEventListener("end",this.orbiterEnd.bind(this)),this.segmentOperation=new segmentation.PointCloudSegmentOperation(__spreadValues({dom:this.container,store:this.store},this.eventBus)),this.pointCloudRender=new index$1(__spreadProps(__spreadValues({store:this.store},this.eventBus),{nextTick:this.nextTick})),this.initMsg(),document.addEventListener("keydown",this.keydown),document.addEventListener("keyup",this.keyup)}orbiterStart(){}orbiterChange(){!this.store||(this.store.orbiting=!0)}orbiterEnd(){!this.store||(this.store.orbiting=!1)}get currentSegmentTool(){var t;return(t=this.segmentOperation)==null?void 0:t.currentToolName}get pointCloudObject(){return this.scene.getObjectByName(this.pointCloudObjectName)}initMsg(){!this.segmentOperation||(this.on("CircleSelector",this.segmentOperation.updateSelector2Circle.bind(this.segmentOperation)),this.on("LassoSelector",this.segmentOperation.updateSelector2Lasso.bind(this.segmentOperation)),this.on("RectSelector",this.segmentOperation.updateSelector2Rect.bind(this.segmentOperation)),this.on("clearPointCloud",this.clearPointCloud.bind(this)),this.on("loadPCDFile",this.loadPCDFile.bind(this)))}unbindMsg(){!this.segmentOperation||(this.unbind("CircleSelector",this.segmentOperation.updateSelector2Circle.bind(this.segmentOperation)),this.unbind("LassoSelector",this.segmentOperation.updateSelector2Lasso.bind(this.segmentOperation)),this.unbind("RectSelector",this.segmentOperation.updateSelector2Rect.bind(this.segmentOperation)),this.unbind("clearPointCloud",this.clearPointCloud.bind(this)),this.unbind("loadPCDFile",this.loadPCDFile.bind(this)))}get eventBus(){return{on:this.on.bind(this),emit:this.emit.bind(this),unbind:this.unbind.bind(this)}}get pointCloudDelegate(){return __spreadValues({container:this.container,scene:this.scene,camera:this.camera,renderer:this.renderer,checkMode:this.checkMode,config:this.config},this.eventBus)}get DEFAULT_INIT_CAMERA_POSITION(){return new THREE__namespace.Vector3(-.01,0,1e3)}get containerWidth(){return this.container.clientWidth}get containerHeight(){return this.container.clientHeight}setInitCameraPosition(t){this.initCameraPosition=t}setConfig(t){var e;this.config=t,(e=this.store)==null||e.setConfig(t)}initOrthographicCamera(t){if(this.camera.type!=="OrthographicCamera")return;const{left:e,right:i,top:r,bottom:s,near:h,far:o}=t;this.camera.left=e,this.camera.right=i,this.camera.top=r,this.camera.bottom=s,this.camera.near=h,this.camera.far=o,this.camera.updateProjectionMatrix()}initPerspectiveCamera(){this.camera.type==="PerspectiveCamera"&&(this.camera.fov=30,this.camera.aspect=this.containerWidth/this.containerHeight,this.camera.near=1,this.camera.far=1e3,this.camera.updateProjectionMatrix())}initCamera(){const{camera:t}=this;if(this.isOrthographicCamera){const{x:e,y:i,z:r}=this.initCameraPosition;t.position.set(e,i,r)}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,e=""){const i=this.scene.getObjectByName(e+t);i&&i.removeFromParent()}getColorFromConfig(t){return lbUtils.toolStyleConverter.getColorFromConfig({attribute:t},__spreadProps(__spreadValues({},this.config),{attributeConfigurable:!0}),{})}generateBox(t,e=16777215){const i=e;this.addBoxToSense(t,i),this.render()}getAllAttributeColor(t){return t.reduce((e,i)=>(e[i.attribute]=this.getColorFromConfig(i.attribute),e),{})}generateBoxes(t){t.forEach(e=>{this.addBoxToSense(e)}),this.render()}getOrthographicCamera(t){const{center:e,width:i,height:r}=t,s=10,h=e.x-i/2-s,o=e.x-i/2+s,l=e.y+r/2+s,n=e.y-r/2-s,c=100,a=-100,d=500/c;return{left:h,right:o,top:l,bottom:n,near:c,far:a,zoom:d}}updateCameraZoom(t){this.camera.zoom=t,this.camera.updateProjectionMatrix()}updateCameraByBox(t,e,i){const{center:r,width:s,height:h,depth:o,rotation:l}=t,n=this.getCameraVector(r,l,{width:s,height:h,depth:o},e);return i?(this.updateCamera(i,r),new THREE__namespace.Vector3(i.x,i.y,i.z)):(this.updateCamera(n,r),n)}updateCameraBySphere(t,e){const{center:i}=t,{radius:r}=lbUtils.DEFAULT_SPHERE_PARAMS,s=this.getCameraVector(i,0,{width:r*2,height:r*2,depth:r*2},e);return this.updateCamera(s,i),s}updateOrthoCamera(t,e){const i=this.updateCameraByBox(t,e);return this.camera.zoom=1,this.camera.updateProjectionMatrix(),{cameraPositionVector:i}}updateOrthoCameraBySphere(t,e){const i=this.updateCameraBySphere(t,e);return this.camera.zoom=1,this.camera.updateProjectionMatrix(),{cameraPositionVector:i}}updateTopCamera(){this.setInitCameraPosition(this.DEFAULT_INIT_CAMERA_POSITION),this.camera.zoom=1,this.initCamera(),this.setDefaultControls(),this.camera.updateProjectionMatrix(),this.render()}updateCamera(t,e){this.camera.position.set(t.x,t.y,t.z),this.controls.target=new THREE__namespace.Vector3(e.x,e.y,e.z),this.controls.update()}resetCamera(){this.updateCamera(this.DEFAULT_INIT_CAMERA_POSITION,{x:0,y:0,z:0})}getOrthographicCameraTarget(t){const e=new THREE__namespace.Vector3(0,0,-1).applyQuaternion(t.quaternion);return t.position.clone().add(e)}createThreeMatrix4(t){return new THREE__namespace.Matrix4().set(...t)}filterPointsByBox(t,e,i){var r,s,h;if(!e){const o=this.scene.getObjectByName(this.pointCloudObjectName);if(!o)return console.error("There is no corresponding point cloud object"),Promise.resolve(void 0);e=(h=(s=(r=o==null?void 0:o.geometry)==null?void 0:r.attributes)==null?void 0:s.position)==null?void 0:h.array}if(window.Worker){const{zMin:o,zMax:l,polygonPointList:n}=matrix.getCuboidFromPointCloudBox(t),c=e;i=i!=null?i:new Float32Array([]);const a={boxParams:t,zMin:o,zMax:l,polygonPointList:n,color:i,position:c};return new Promise(d=>{const u=new filterBoxWorker;u.postMessage(a),u.onmessage=m=>{const{color:p,position:g,num:y}=m.data,x=new THREE__namespace.BufferGeometry;x.setAttribute("position",new THREE__namespace.Float32BufferAttribute(g,3)),x.setAttribute("color",new THREE__namespace.Float32BufferAttribute(p,3)),x.computeBoundingSphere(),u.terminate(),d({geometry:x,num:y})}})}return Promise.resolve(void 0)}getCameraVector(t,e,i,r=lbUtils.EPerspectiveView.Front,s=DEFAULT_DISTANCE){let h=lbUtils.PerspectiveShiftUtils.frontViewMatrix4(s);switch(r){case lbUtils.EPerspectiveView.Front:break;case lbUtils.EPerspectiveView.Back:h=lbUtils.PerspectiveShiftUtils.backViewMatrix4(s);break;case lbUtils.EPerspectiveView.Left:h=lbUtils.PerspectiveShiftUtils.leftViewMatrix4(s);break;case lbUtils.EPerspectiveView.Right:h=lbUtils.PerspectiveShiftUtils.rightViewMatrix4(s);break;case lbUtils.EPerspectiveView.Top:h=lbUtils.PerspectiveShiftUtils.topViewMatrix4(s);break;case lbUtils.EPerspectiveView.LFT:h=lbUtils.PerspectiveShiftUtils.leftFrontTopViewMatrix4(s,i);break;case lbUtils.EPerspectiveView.RBT:h=lbUtils.PerspectiveShiftUtils.rightBackTopViewMatrix4(s,i);break}const o=this.createThreeMatrix4(h),l=new THREE__namespace.Matrix4().makeTranslation(-t.x,-t.y,-t.z),n=new THREE__namespace.Matrix4().makeTranslation(t.x,t.y,t.z),c=new THREE__namespace.Matrix4().makeRotationZ(e);return new THREE__namespace.Vector3(t.x,t.y,t.z).clone().applyMatrix4(o).applyMatrix4(l).applyMatrix4(c).applyMatrix4(n)}createRange(t){this.removeObjectByName(this.rangeObjectName);const i=new THREE__namespace.EllipseCurve(0,0,t,t,0,2*Math.PI,!1,0).getPoints(50),r=new THREE__namespace.BufferGeometry().setFromPoints(i),s=new THREE__namespace.LineBasicMaterial({color:16711680}),h=new THREE__namespace.Line(r,s);return h.name=this.rangeObjectName,h}renderPointCloud(t,e){t.name=this.pointCloudObjectName;const i=new THREE__namespace.ShaderMaterial(this.initShaderMaterial());e&&this.generateRange(e),this.pointsUuid=t.uuid,t.material=i,this.filterZAxisPoints(t),this.scene.add(t),this.render()}clearAllBox(){this.clearAllGroupByPrefix("box")}clearAllSphere(){this.clearAllGroupByPrefix("sphere")}clearAllGroupByPrefix(t=""){const e=this.scene.children;for(let i=e.length-1;i>=0;i--){const r=e[i];r.type==="Group"&&r.name.startsWith(t)&&this.removeObjectByName(r.name)}}clearPointCloud(){this.removeObjectByName(this.pointCloudObjectName)}clearPointCloudAndRender(){this.clearPointCloud(),this.render()}initCloudData(t){if(!!this.store){for(let e=0;e<t.length;e+=3){const i=t[e],r=t[e+1],s=t[e+2];this.store.cloudData.set(`${i}@${r}@${s}`,{visible:!1})}this.store.setOriginPoints(t)}}highlightOriginPointCloud(t,e=[]){const i=this.scene.getObjectByName(this.pointCloudObjectName);if(!!i)return this.highlightPCDSrc=this.currentPCDSrc,new Promise((r,s)=>{if(window.Worker){const o=(t?[...t]:[]).map(c=>matrix.getCuboidFromPointCloudBox(c)),l=this.getAllAttributeColor(o),n={cuboidList:o,position:i.geometry.attributes.position.array,color:i.geometry.attributes.dimensions.array,colorList:l,highlightIndex:e};highlightWorker.postMessage(n),highlightWorker.onmessage=c=>{const{color:a}=c.data,d=new THREE__namespace.BufferAttribute(a,3);if(!this.highlightPCDSrc||this.highlightPCDSrc!==this.currentPCDSrc||i.geometry.attributes.position.array.length!==a.length){s(new Error("Error Path"));return}this.cacheInstance.updateColor(this.highlightPCDSrc,a),this.highlightPCDSrc=void 0,d.needsUpdate=!0,i.geometry.setAttribute("dimensions",d),i.geometry.attributes.dimensions.needsUpdate=!0,r(a),this.render()}}})}clearHighlightBoxes(){this.removeObjectByName(this.highlightGroupName)}clearHighlightBoxesAndRender(){this.clearHighlightBoxes(),this.render()}highlightBoxes(t){const e=new THREE__namespace.Group;t.forEach(i=>{const{center:{x:r,y:s,z:h},width:o,height:l,depth:n,rotation:c}=i,{fill:a}=lbUtils.toolStyleConverter.getColorFromConfig({attribute:i.attribute},__spreadProps(__spreadValues({},this.config),{attributeConfigurable:!0}),{}),d=new THREE__namespace.BoxGeometry(o,l,n),u=new THREE__namespace.MeshBasicMaterial({color:a,transparent:!0,opacity:.2,depthTest:!1});d.rotateZ(c),d.translate(r,s,h);const m=new THREE__namespace.Mesh(d,u);e.add(m);const p=new THREE__namespace.PlaneGeometry(n,l);p.rotateY(Math.PI/2),p.rotateZ(c);const g=new THREE__namespace.Vector3(o/2,0,0),y=new THREE__namespace.Matrix4().makeRotationY(Math.PI/2).makeRotationZ(c);g.applyMatrix4(y),p.translate(r+g.x,s+g.y,h+g.z);const x=new THREE__namespace.MeshBasicMaterial({color:a,side:THREE__namespace.DoubleSide,transparent:!0,opacity:.8,depthTest:!1}),w=new THREE__namespace.Mesh(p,x);e.add(w)}),e.name=this.highlightGroupName,this.scene.add(e),this.render()}updateColor(t){const e=this.scene.getObjectByName(this.pointCloudObjectName);if(e){const i=new THREE__namespace.BufferAttribute(t,3);e.geometry.setAttribute("dimensions",i),e.geometry.attributes.dimensions.needsUpdate=!0,this.render()}}setShowDirection(t){this.showDirection=t,this.scene.children.forEach(e=>{e.type==="Group"&&e.children.forEach(i=>{i.type==="ArrowHelper"&&(i.visible=t)})}),this.render()}getTextCanvas(t){const e=document.createElement("canvas"),i=e.getContext("2d");return i&&(i.font=`${50}px " bold`,i.fillStyle="white",i.textAlign="center",i.textBaseline="middle",i.fillText(t,e.width/2,e.height/2)),e}filterNoise(t){let e=[...t];e.sort((a,d)=>a.z-d.z);const i=Math.floor(e.length*.05),r=e[i];e=e.filter(({z:a})=>a>r.z+.1);const s=.005,h=Math.floor(e.length*(1-s));e=e.slice(0,h),e.sort((a,d)=>a.x-d.x);const o=Math.floor(e.length*s),l=Math.floor(e.length*(1-s));e=e.slice(o,l),e.sort((a,d)=>a.y-d.y);const n=Math.floor(e.length*s),c=Math.floor(e.length*(1-s));return e=e.slice(n,c),e.length>100?e:t}getFittedCoordinates(t,e){const i=[];let r=[...t,t[0]];e.forEach(({x:l,y:n})=>{t.forEach((c,a)=>{const d=r[a+1],u=MathUtils.default.getFootOfPerpendicular({x:l,y:n},c,d,!1,!0).length;(!i[a]||u<i[a].distance)&&(i[a]={distance:u,point:{x:l,y:n}})})}),r=[t[t.length-1],...t,t[0]];const s=[i[i.length-1],...i],h=t.map((l,n)=>{const c=r[n],a=r[n+1],d=r[n+2];return lbUtils.PointCloudUtils.getIntersectionBySlope({p1:s[n].point,line1:[c,a],p2:s[n+1].point,line2:[a,d]})});return h.some(l=>!(Number.isFinite(l.x)&&Number.isFinite(l.y)))?t:h}getSensesPointZAxisInPolygon(t,e,i){var r,s,h;const o=this.scene.children.find(p=>p.uuid===this.pointsUuid);let l=0,n=0,c=0,a=0,d=[],u=[];const m=((h=(s=(r=o==null?void 0:o.geometry)==null?void 0:r.attributes)==null?void 0:s.position)==null?void 0:h.array)||[];for(let p=0;p<m.length;p+=3){const g=m[p],y=m[p+1],x=m[p+2];polygonTool.isInPolygon({x:g,y},t)&&(x||x===0)&&u.push({x:g,y,z:x})}return u.length?(i&&(u=this.filterNoise(u),d=this.getFittedCoordinates(t,u)),u.sort((p,g)=>p.z-g.z),l=u[0].z-.01,n=u[u.length-1].z+.01,a=u.length,e&&(c=u.filter(({z:p})=>p>=e[0]&&p<=e[1]).length),{maxZ:n,minZ:l,count:c,zCount:a,fittedCoordinates:d}):{maxZ:n,minZ:l,count:c,zCount:a,fittedCoordinates:d}}getBasicCoordinate2Canvas(t){const e=this.containerWidth/2,i=this.containerHeight/2;return{x:t.x*e+e,y:t.y*i+i,z:t.z}}get basicCoordinate2CanvasMatrix4(){const t=this.containerWidth/2,e=this.containerHeight/2;return new THREE__namespace.Matrix4().set(t,0,0,t,0,e,0,e,0,0,1,0,0,0,0,1)}getCanvas2BasicCoordinate(t){const e=this.containerWidth/2,i=this.containerHeight/2;return new THREE__namespace.Vector3(t.x/e-e/2,-(t.y/i-i/2),1)}getPolygonSidePoints(t){const{center:{x:e,y:i,z:r},height:s,width:h,depth:o}=t,l={x:e+h/2,y:i+s/2,z:r-o/2},n={x:e+h/2,y:i+s/2,z:r+o/2},c={x:e-h/2,y:i+s/2,z:r+o/2},a={x:e-h/2,y:i+s/2,z:r-o/2};return[l,n,c,a]}getPolygonBackPoints(t){const{center:{x:e,y:i,z:r},height:s,width:h,depth:o}=t,l={x:e-h/2,y:i+s/2,z:r+o/2},n={x:e-h/2,y:i+s/2,z:r-o/2},c={x:e-h/2,y:i-s/2,z:r-o/2},a={x:e-h/2,y:i-s/2,z:r+o/2};return[l,n,c,a]}getPolygonTopPoints(t){const{center:{x:e,y:i,z:r},height:s,width:h,depth:o}=t,l={x:e+h/2,y:i+s/2,z:r+o/2},n={x:e+h/2,y:i-s/2,z:r+o/2},c={x:e-h/2,y:i-s/2,z:r+o/2},a={x:e-h/2,y:i+s/2,z:r+o/2};return[l,n,c,a]}getModelTransformationMatrix(t){const{center:{x:e,y:i,z:r},rotation:s}=t,h=new THREE__namespace.Matrix4().makeTranslation(-e,-i,-r),o=new THREE__namespace.Matrix4().makeTranslation(e,i,r),l=new THREE__namespace.Matrix4().makeRotationZ(s);return new THREE__namespace.Matrix4().multiply(o).multiply(l).multiply(h)}getBoxSidePolygon2DCoordinate(t){return this.getBoxPolygon2DCoordinate(t,lbUtils.EPerspectiveView.Left)}getBoxBackPolygon2DCoordinate(t){return this.getBoxPolygon2DCoordinate(t,lbUtils.EPerspectiveView.Back)}getSphereSidePoint2DCoordinate(t){return this.getSpherePoint2DCoordinate(t)}getSphereBackPoint2DCoordinate(t){return this.getSpherePoint2DCoordinate(t)}boxParams2ViewPolygon(t,e){switch(e){case lbUtils.EPerspectiveView.Left:return this.getPolygonSidePoints(t);case lbUtils.EPerspectiveView.Back:return this.getPolygonBackPoints(t);default:return this.getPolygonTopPoints(t)}}getBoxPolygon2DCoordinate(t,e){const i=this.boxParams2ViewPolygon(t,e),{width:r,height:s}=t,h=new THREE__namespace.Matrix4().premultiply(this.camera.matrixWorldInverse).premultiply(this.camera.projectionMatrix),o=new THREE__namespace.Matrix4().premultiply(this.getModelTransformationMatrix(t)).premultiply(h).premultiply(this.basicCoordinate2CanvasMatrix4);this.sideMatrix=o;const l=i.map(a=>new THREE__namespace.Vector3(a.x,a.y,a.z)).map(a=>a.applyMatrix4(this.sideMatrix)),n=this.containerWidth/r,c=this.containerHeight/s;return{polygon2d:l,zoom:Math.min(n,c)/2}}getSpherePoint2DCoordinate(t){const{center:e,attribute:i,id:r,valid:s}=t,{radius:h}=lbUtils.DEFAULT_SPHERE_PARAMS,o={center:e,attribute:i,id:r,valid:s,width:h*2,height:h*2,depth:h*2,rotation:0},l=new THREE__namespace.Matrix4().premultiply(this.camera.matrixWorldInverse).premultiply(this.camera.projectionMatrix),n=new THREE__namespace.Matrix4().premultiply(this.getModelTransformationMatrix(o)).premultiply(l).premultiply(this.basicCoordinate2CanvasMatrix4);this.sideMatrix=n;const c=new THREE__namespace.Vector3(e.x,e.y,e.z).applyMatrix4(this.sideMatrix),a=this.containerWidth/(h*2),d=this.containerHeight/(h*2);return{point2d:c,zoom:Math.min(a,d)/2}}getSphereTopPoint2DCoordinate(t){const{center:e}=t,{radius:i}=lbUtils.DEFAULT_SPHERE_PARAMS,r={x:-(e.y-this.containerWidth/2),y:-(e.x-this.containerHeight/2)},s=this.containerWidth/(i*2),h=this.containerHeight/(i*2);return{point2d:r,zoom:Math.min(s,h)/2}}getBoxTopPolygon2DCoordinate(t){const{width:e,height:i}=t,s=this.getPolygonTopPoints(t).map(l=>new THREE__namespace.Vector3(l.x,l.y,l.z)).map(l=>l.applyMatrix4(this.getModelTransformationMatrix(t))).map(l=>({x:l.y,y:l.x})).map(l=>({x:-(l.x-this.containerWidth/2),y:-(l.y-this.containerHeight/2)})),h=this.containerWidth/e,o=this.containerHeight/i;return{polygon2d:s,zoom:Math.min(h,o)/2}}getNewBoxBySideUpdate(t,e,i,r){const s=new THREE__namespace.Matrix4().makeRotationZ(r.rotation),h=new THREE__namespace.Vector3(-t.x,0,0).applyMatrix4(s);let o=r;return o.center={x:o.center.x+h.x,y:o.center.y+h.y,z:o.center.z-t.z},o=__spreadProps(__spreadValues({},o),{width:Math.abs(o.width+e),height:o.height,depth:Math.abs(o.depth+i)}),{newBoxParams:o}}getNewBoxByBackUpdate(t,e,i,r){const s=new THREE__namespace.Matrix4().makeRotationZ(r.rotation),h=new THREE__namespace.Vector3(0,-t.x,0).applyMatrix4(s);let o=r;return o.center={x:o.center.x+h.x,y:o.center.y+h.y,z:o.center.z-t.z},o=__spreadProps(__spreadValues({},o),{width:o.width,height:Math.abs(o.height+e),depth:Math.abs(o.depth+i)}),{newBoxParams:o}}getNewBoxBySideUpdateByPoints(t,e,i,r){var s;const h=(s=this.sideMatrix)==null?void 0:s.invert();if(!this.sideMatrix||!h){console.error("No sideMatrix");return}this.camera.zoom=1,this.camera.updateProjectionMatrix();const o=t.map(g=>new THREE__namespace.Vector3(g.x,g.y,g.z)).map(g=>g.applyMatrix4(h)),[l,n,c,a]=o,d=Math.max(Math.abs(l.x-c.x),Math.abs(l.x-n.x)),m=n.add(a).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(r.center.x,r.center.y,r.center.z));return{newBoxParams:__spreadProps(__spreadValues({},r),{center:{x:r.center.x-m.x,y:r.center.y-m.y,z:r.center.z-i},width:d,height:r.height,depth:r.depth+e,rotation:r.rotation})}}filterZAxisPoints(t){const e=t||this.scene.children.find(i=>i.uuid===this.pointsUuid);if(e){const{attributes:i}=e.geometry,{position:r}=i,s=[],{count:h}=r;for(let o=0;o<h;o++){const l=r.getZ(o);s.push(l>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.getHighlightIndexByPoints=matrix.getHighlightIndexByPoints,exports.isFisheyeCalibValid=matrix.isFisheyeCalibValid,exports.isInImage=matrix.isInImage,exports.isMatrixValid=matrix.isMatrixValid,exports.isMatrixValidByArr=matrix.isMatrixValidByArr,exports.lidar2FisheyeImage=matrix.lidar2FisheyeImage,exports.lidar2image=matrix.lidar2image,exports.mergeHighlightList=matrix.mergeHighlightList,exports.oCamFisheyeTransfer=matrix.oCamFisheyeTransfer,exports.point3DLidar2Image=matrix.point3DLidar2Image,exports.pointCloudLidar2image=matrix.pointCloudLidar2image,exports.pointListLidar2Img=matrix.pointListLidar2Img,exports.pointMappingLidar2image=matrix.pointMappingLidar2image,exports.rotatePoint=matrix.rotatePoint,exports.transferKitti2Matrix=matrix.transferKitti2Matrix,exports.PointCloud=PointCloud;
@@ -1 +1 @@
1
- "use strict";var lbUtils=require("@labelbee/lb-utils"),AxisUtils=require("../../utils/tool/AxisUtils.js"),DrawUtils=require("../../utils/tool/DrawUtils.js"),tool=require("../../constant/tool.js"),CommonToolUtils=require("../../utils/tool/CommonToolUtils.js"),AttributeUtils=require("../../utils/tool/AttributeUtils.js"),basicToolOperation=require("./basicToolOperation.js");const DEFAULT_PEN_SIZE=20,DEFAULT_COLOR="white";class ScribbleTool extends basicToolOperation.BasicToolOperation{constructor(t){super(t);this.toolName=tool.EToolName.ScribbleTool,this.action=tool.EScribblePattern.Scribble,this.getOriginCoordinate=i=>AxisUtils.default.changePointByZoom(this.getCoordinateUnderZoomByRotate(i),1/this.zoom),this.onMouseDown=i=>{super.onMouseDown(i)||this.forbidMouseOperation||!this.imgInfo||(this.initCacheCanvas(this.imgNode),this.mouseEvents("onMouseDown").call(this,i))},this.onMouseMove=i=>{super.onMouseMove(i)||this.forbidMouseOperation||!this.imgInfo||this.mouseEvents("onMouseMove").call(this,i)},this.onMouseUp=i=>{super.onMouseUp(i)||this.forbidMouseOperation||!this.imgInfo||this.mouseEvents("onMouseUp").call(this,i)},this.mouseEvents=i=>({[tool.EScribblePattern.Scribble]:{onMouseMove:this.onScribbleMove,onMouseUp:this.onScribbleEnd,onMouseDown:this.onScribbleStart},[tool.EScribblePattern.Erase]:{onMouseMove:this.onEraseMove,onMouseUp:this.onEraseEnd,onMouseDown:this.onEraseStart}})[this.action][i],this.setPattern=i=>{switch(this.action=i,i){case tool.EScribblePattern.Erase:{this.setCustomCursor(this.cursorErase);break}default:{this.setCustomCursor("none");break}}};var e;if(this.penSize=DEFAULT_PEN_SIZE,((e=this.config.attributeList)==null?void 0:e.length)>0){const i=this.config.attributeList[0];this.setDefaultAttribute(i.value)}}get cursorErase(){const t='<?xml version="1.0" encoding="UTF-8"?><svg width="24" heighst="24" viewBox="0 0 48 48" fill="none" xmlns="http://www.w3.org/2000/svg"><g clip-path="url(#icon-65e7e1747c11bad3)"><path d="M44.7818 24.1702L31.918 7.09935L14.1348 20.5L27.5 37L30.8556 34.6643L44.7818 24.1702Z" fill="#141414" stroke="#000000" stroke-width="4" stroke-linejoin="miter"/><path d="M27.4998 37L23.6613 40.0748L13.0978 40.074L10.4973 36.6231L4.06543 28.0876L14.4998 20.2248" stroke="#000000" stroke-width="4" stroke-linejoin="miter"/><path d="M13.2056 40.072L44.5653 40.072" stroke="#000000" stroke-width="4" stroke-linecap="round"/></g><defs><clipPath id="icon-65e7e1747c11bad3"><rect width="48" height="48" fill="#df4c4c"/></clipPath></defs></svg>';return`url(${`data:image/svg+xml;base64,${window.btoa(unescape(encodeURIComponent(t)))}`}) 0 0, auto`}get defaultCursor(){return this.action===tool.EScribblePattern.Erase?this.cursorErase:this.isShowDefaultCursor?"default":"none"}get color(){var t,e;return(e=(t=this==null?void 0:this.defaultAttributeInfo)==null?void 0:t.color)!=null?e:DEFAULT_COLOR}get penSizeWithZoom(){return this.penSize/this.zoom}get cacheCanvasToDataUrl(){var t;return(t=this.cacheCanvas)==null?void 0:t.toDataURL("image/png",0)}setPenSize(t){this.penSize=t}initCacheCanvas(t){if(this.cacheCanvas||!t)return;const{canvas:e,ctx:i}=lbUtils.ImgConversionUtils.createCanvas(t);this.cacheCanvas=e,this.cacheContext=i}updateCacheCanvasSize(t){this.cacheCanvas&&(this.cacheCanvas.width=t.width,this.cacheCanvas.height=t.height)}updateUrl2CacheContext(t){lbUtils.ImgConversionUtils.createImgDom(t).then(e=>{this.cacheContext||this.initCacheCanvas(e),this.cacheContext&&(this.cacheContext.save(),this.clearCacheCanvas(),this.cacheContext.drawImage(e,0,0,e.width,e.height),this.cacheContext.restore(),this.render())})}setImgNode(t,e){super.setImgNode(t,e),this.cacheCanvas?this.updateCacheCanvasSize(t):this.initCacheCanvas(t)}setResult(t){var e,i;let{url:s}=(e=t==null?void 0:t[0])!=null?e:{};if(this.clearCacheCanvas(),s||(s=(i=this.cacheCanvasToDataUrl)!=null?i:""),this.history.initRecord([s],!0),!s){this.render();return}this.updateUrl2CacheContext(s)}onKeyDown(t){if(!CommonToolUtils.hotkeyFilter(t)||super.onKeyDown(t)===!1)return;const{keyCode:e}=t,i=AttributeUtils.default.getAttributeByKeycode(e,this.config.attributeList);i!==void 0&&this.setDefaultAttribute(i)}eventBinding(){super.eventBinding()}setDefaultAttribute(t){const e=this.config.attributeList.find(i=>i.value===t);e&&(this.defaultAttribute=e.value,this.defaultAttributeInfo=e,this.emit("changeAttributeSidebar"),this.render())}clearStatusAfterLeave(){this.onScribbleEnd(),this.startPoint=void 0}onMouseLeave(){super.onMouseLeave(),this.clearStatusAfterLeave()}onScribbleStart(t){if(!this.cacheContext)return;this.cacheContext.save(),this.cacheContext.beginPath(),this.cacheContext.strokeStyle=this.color,this.cacheContext.lineWidth=this.penSizeWithZoom,this.cacheContext.lineCap="round",this.cacheContext.lineJoin="round";const e=this.getOriginCoordinate(t);this.cacheContext.moveTo(e.x,e.y),this.startPoint=e}onScribbleMove(t){if(t.buttons===1&&this.cacheContext&&this.startPoint){const e=this.getOriginCoordinate(t);this.cacheContext.lineTo(e.x,e.y),this.cacheContext.stroke()}}onScribbleEnd(){var t,e;this.startPoint&&((t=this.cacheContext)==null||t.closePath(),(e=this.cacheContext)==null||e.restore(),this.startPoint=void 0,this.history.pushHistory(this.cacheCanvasToDataUrl))}eraseArc(t){var e;if(this.cacheContext){const i=this.getOriginCoordinate(t);this.cacheContext.save(),this.cacheContext.beginPath(),this.cacheContext.arc(i.x,i.y,this.penSizeWithZoom/2,0,Math.PI*2,!1),this.cacheContext.clip(),this.cacheContext.clearRect(0,0,this.cacheContext.canvas.width,this.cacheContext.canvas.height),(e=this.cacheContext)==null||e.restore()}}onEraseStart(t){!this.cacheContext||t.buttons!==1||this.eraseArc(t)}onEraseMove(t){!this.cacheContext||t.buttons!==1||this.eraseArc(t)}onEraseEnd(){}exportData(){const t=this.cacheCanvasToDataUrl;return[[],this.basicImgInfo,{imgBase64:t}]}clearCacheCanvas(){var t;(t=this.cacheContext)==null||t.clearRect(0,0,this.cacheContext.canvas.width,this.cacheContext.canvas.height),this.render()}clearResult(){this.clearCacheCanvas(),this.history.pushHistory(this.cacheCanvasToDataUrl)}renderPoint(t){DrawUtils.drawCircleWithFill(this.canvas,this.coord,t,{color:this.color})}renderBorderPoint(t){DrawUtils.drawCircle(this.canvas,this.coord,t,{color:"black"})}render(){if(super.render(),!this.ctx||!this.cacheCanvas||(this.ctx.save(),this.ctx.globalAlpha=.5,DrawUtils.drawImg(this.canvas,this.cacheCanvas,{zoom:this.zoom,currentPos:this.currentPos,rotate:this.rotate}),this.ctx.restore(),this.forbidOperation||this.forbidCursorLine))return;const t=this.penSize/2;this.action===tool.EScribblePattern.Erase?this.renderBorderPoint(t):this.renderPoint(t)}undo(){const t=this.history.undo();t&&this.cacheCanvas&&this.updateUrl2CacheContext(t)}redo(){const t=this.history.redo();t&&this.cacheCanvas&&this.updateUrl2CacheContext(t)}}module.exports=ScribbleTool;
1
+ "use strict";var lbUtils=require("@labelbee/lb-utils"),AxisUtils=require("../../utils/tool/AxisUtils.js"),DrawUtils=require("../../utils/tool/DrawUtils.js"),tool=require("../../constant/tool.js"),CommonToolUtils=require("../../utils/tool/CommonToolUtils.js"),AttributeUtils=require("../../utils/tool/AttributeUtils.js"),keyCode=require("../../constant/keyCode.js"),basicToolOperation=require("./basicToolOperation.js");const DEFAULT_PEN_SIZE=20,DEFAULT_COLOR="white";class ScribbleTool extends basicToolOperation.BasicToolOperation{constructor(t){super(t);this.toolName=tool.EToolName.ScribbleTool,this.action=tool.EScribblePattern.Scribble,this.getOriginCoordinate=i=>AxisUtils.default.changePointByZoom(this.getCoordinateUnderZoomByRotate(i),1/this.zoom),this.onMouseDown=i=>{super.onMouseDown(i)||this.forbidMouseOperation||!this.imgInfo||(this.initCacheCanvas(this.imgNode),this.mouseEvents("onMouseDown").call(this,i))},this.onMouseMove=i=>{super.onMouseMove(i)||this.forbidMouseOperation||!this.imgInfo||this.mouseEvents("onMouseMove").call(this,i)},this.onMouseUp=i=>{super.onMouseUp(i)||this.forbidMouseOperation||!this.imgInfo||this.mouseEvents("onMouseUp").call(this,i)},this.mouseEvents=i=>({[tool.EScribblePattern.Scribble]:{onMouseMove:this.onScribbleMove,onMouseUp:this.onScribbleEnd,onMouseDown:this.onScribbleStart},[tool.EScribblePattern.Erase]:{onMouseMove:this.onEraseMove,onMouseUp:this.onEraseEnd,onMouseDown:this.onEraseStart}})[this.action][i],this.setPattern=i=>{switch(this.action=i,i){case tool.EScribblePattern.Erase:{this.setCustomCursor(this.cursorErase);break}default:{this.setCustomCursor("none");break}}};var e;if(this.penSize=DEFAULT_PEN_SIZE,this.isHidden=!1,this.pointList=[],((e=this.config.attributeList)==null?void 0:e.length)>0){const i=this.config.attributeList[0];this.setDefaultAttribute(i.value)}}get cursorErase(){const t='<?xml version="1.0" encoding="UTF-8"?><svg width="24" heighst="24" viewBox="0 0 48 48" fill="none" xmlns="http://www.w3.org/2000/svg"><g clip-path="url(#icon-65e7e1747c11bad3)"><path d="M44.7818 24.1702L31.918 7.09935L14.1348 20.5L27.5 37L30.8556 34.6643L44.7818 24.1702Z" fill="#141414" stroke="#000000" stroke-width="4" stroke-linejoin="miter"/><path d="M27.4998 37L23.6613 40.0748L13.0978 40.074L10.4973 36.6231L4.06543 28.0876L14.4998 20.2248" stroke="#000000" stroke-width="4" stroke-linejoin="miter"/><path d="M13.2056 40.072L44.5653 40.072" stroke="#000000" stroke-width="4" stroke-linecap="round"/></g><defs><clipPath id="icon-65e7e1747c11bad3"><rect width="48" height="48" fill="#df4c4c"/></clipPath></defs></svg>';return`url(${`data:image/svg+xml;base64,${window.btoa(unescape(encodeURIComponent(t)))}`}) 0 0, auto`}get defaultCursor(){return this.action===tool.EScribblePattern.Erase?this.cursorErase:this.isShowDefaultCursor?"default":"none"}get color(){var t,e;return(e=(t=this==null?void 0:this.defaultAttributeInfo)==null?void 0:t.color)!=null?e:DEFAULT_COLOR}get penSizeWithZoom(){return this.penSize/this.zoom}get cacheCanvasToDataUrl(){var t;return(t=this.cacheCanvas)==null?void 0:t.toDataURL("image/png",0)}setPenSize(t){this.penSize=t,this.render()}initCacheCanvas(t){if(this.cacheCanvas||!t)return;const{canvas:e,ctx:i}=lbUtils.ImgConversionUtils.createCanvas(t);this.cacheCanvas=e,this.cacheContext=i}updateCacheCanvasSize(t){this.cacheCanvas&&(this.cacheCanvas.width=t.width,this.cacheCanvas.height=t.height)}updateUrl2CacheContext(t){lbUtils.ImgConversionUtils.createImgDom(t).then(e=>{this.cacheContext||this.initCacheCanvas(e),this.cacheContext&&(this.cacheContext.save(),this.clearCacheCanvas(),this.cacheContext.drawImage(e,0,0,e.width,e.height),this.cacheContext.restore(),this.render())})}setImgNode(t,e){super.setImgNode(t,e),this.cacheCanvas?this.updateCacheCanvasSize(t):this.initCacheCanvas(t)}setResult(t){var e,i;let{url:s}=(e=t==null?void 0:t[0])!=null?e:{};if(this.clearCacheCanvas(),s||(s=(i=this.cacheCanvasToDataUrl)!=null?i:""),this.history.initRecord([s],!0),!s){this.render();return}this.updateUrl2CacheContext(s)}onKeyDown(t){if(!CommonToolUtils.hotkeyFilter(t)||super.onKeyDown(t)===!1)return;const{keyCode:e}=t,i=AttributeUtils.default.getAttributeByKeycode(e,this.config.attributeList);i!==void 0&&this.setDefaultAttribute(i),e===keyCode.Z&&!t.ctrlKey&&this.toggleIsHide(),t.ctrlKey&&this.action===tool.EScribblePattern.Scribble&&(this.lineActive=!0,this.render())}onKeyUp(t){super.onKeyUp(t),t.keyCode===keyCode.Ctrl&&(this.lineActive=!1,this.pointList=[],this.render())}toggleIsHide(){this.setIsHidden(!this.isHidden),this.render()}eventBinding(){super.eventBinding()}setDefaultAttribute(t){const e=this.config.attributeList.find(i=>i.value===t);e&&(this.defaultAttribute=e.value,this.defaultAttributeInfo=e,this.emit("changeAttributeSidebar"),this.render())}clearStatusAfterLeave(){this.onScribbleEnd(),this.startPoint=void 0}onMouseLeave(){super.onMouseLeave(),this.clearStatusAfterLeave()}onScribbleStart(t){if(!this.cacheContext)return;this.cacheContext.save(),this.cacheContext.beginPath(),this.cacheContext.strokeStyle=this.color,this.cacheContext.lineWidth=this.penSizeWithZoom,this.cacheContext.lineCap="round",this.cacheContext.lineJoin="round";const e=this.getOriginCoordinate(t);this.cacheContext.moveTo(e.x,e.y),this.startPoint=e,this.lineActive&&this.scribbleOnImgByLine(e)}scribbleOnImgByLine(t){const e=this.cacheContext;!e||(this.pointList.push(t),this.pointList.length>1&&this.pointList.forEach((i,s)=>{if(e.beginPath(),s>0){const o=this.pointList[s-1];e.save(),e.moveTo(o.x,o.y),e.lineTo(i.x,i.y),e.stroke(),e.restore()}}))}onScribbleMove(t){const e=this.getOriginCoordinate(t);if(this.lineActive){this.prePoint=e;return}t.buttons===1&&this.cacheContext&&this.startPoint&&(this.cacheContext.lineTo(e.x,e.y),this.cacheContext.stroke())}onScribbleEnd(){var t,e;this.startPoint&&((t=this.cacheContext)==null||t.closePath(),(e=this.cacheContext)==null||e.restore(),this.startPoint=void 0,this.history.pushHistory(this.cacheCanvasToDataUrl))}eraseArc(t){var e;if(this.cacheContext){const i=this.getOriginCoordinate(t);this.cacheContext.save(),this.cacheContext.beginPath(),this.cacheContext.arc(i.x,i.y,this.penSizeWithZoom/2,0,Math.PI*2,!1),this.cacheContext.clip(),this.cacheContext.clearRect(0,0,this.cacheContext.canvas.width,this.cacheContext.canvas.height),(e=this.cacheContext)==null||e.restore()}}onEraseStart(t){!this.cacheContext||t.buttons!==1||this.eraseArc(t)}onEraseMove(t){!this.cacheContext||t.buttons!==1||this.eraseArc(t)}onEraseEnd(){}exportData(){const t=this.cacheCanvasToDataUrl;return[[],this.basicImgInfo,{imgBase64:t}]}clearCacheCanvas(){var t;(t=this.cacheContext)==null||t.clearRect(0,0,this.cacheContext.canvas.width,this.cacheContext.canvas.height),this.render()}clearResult(){this.clearCacheCanvas(),this.history.pushHistory(this.cacheCanvasToDataUrl)}renderPoint(t){DrawUtils.drawCircleWithFill(this.canvas,this.coord,t,{color:this.color})}renderBorderPoint(t){DrawUtils.drawCircle(this.canvas,this.coord,t,{color:"black"})}drawLineSegment(){if(this.prePoint&&this.pointList.length>0){const i=[this.pointList[this.pointList.length-1]].concat(this.prePoint).map(s=>this.getCoordinateUnderZoomByRotateFromImgPoint(s));this.drawStraightLine(i,{color:this.color,lineWidth:this.penSize,globalAlpha:.5})}}render(){if(super.render(),!this.ctx||!this.cacheCanvas||this.isHidden||(this.lineActive&&(this.renderCursorLine(this.color),this.drawLineSegment()),this.ctx.save(),this.ctx.globalAlpha=.5,DrawUtils.drawImg(this.canvas,this.cacheCanvas,{zoom:this.zoom,currentPos:this.currentPos,rotate:this.rotate}),this.ctx.restore(),this.forbidOperation||this.forbidCursorLine))return;const t=this.penSize/2;this.action===tool.EScribblePattern.Erase?this.renderBorderPoint(t):this.renderPoint(t)}undo(){const t=this.history.undo();t&&this.cacheCanvas&&this.updateUrl2CacheContext(t)}redo(){const t=this.history.redo();t&&this.cacheCanvas&&this.updateUrl2CacheContext(t)}}module.exports=ScribbleTool;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var lbUtils=require("@labelbee/lb-utils"),_=require("lodash"),tool=require("../../constant/tool.js"),MathUtils=require("../../utils/MathUtils.js"),AxisUtils=require("../../utils/tool/AxisUtils.js"),CanvasUtils=require("../../utils/tool/CanvasUtils.js"),CommonToolUtils=require("../../utils/tool/CommonToolUtils.js"),LineToolUtils=require("../../utils/tool/LineToolUtils.js"),annotation=require("../../constant/annotation.js"),keyCode=require("../../constant/keyCode.js"),style=require("../../constant/style.js"),index=require("../../locales/index.js"),constants=require("../../locales/constants.js"),ActionsHistory=require("../../utils/ActionsHistory.js"),AttributeUtils=require("../../utils/tool/AttributeUtils.js"),DblClickEventListener=require("../../utils/tool/DblClickEventListener.js"),DrawUtils=require("../../utils/tool/DrawUtils.js"),RenderDomUtils=require("../../utils/tool/RenderDomUtils.js"),ZoomUtils=require("../../utils/tool/ZoomUtils.js"),eventListener=require("./eventListener.js"),__defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnPropDescs=Object.getOwnPropertyDescriptors,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(c,t,e)=>t in c?__defProp(c,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):c[t]=e,__spreadValues=(c,t)=>{for(var e in t||(t={}))__hasOwnProp.call(t,e)&&__defNormalProp(c,e,t[e]);if(__getOwnPropSymbols)for(var e of __getOwnPropSymbols(t))__propIsEnum.call(t,e)&&__defNormalProp(c,e,t[e]);return c},__spreadProps=(c,t)=>__defProps(c,__getOwnPropDescs(t)),__async=(c,t,e)=>new Promise((i,s)=>{var o=n=>{try{r(e.next(n))}catch(a){s(a)}},h=n=>{try{r(e.throw(n))}catch(a){s(a)}},r=n=>n.done?i(n.value):Promise.resolve(n.value).then(o,h);r((e=e.apply(c,t)).next())});const LANGUAGE_MAP={[annotation.ELang.Zh]:"cn",[annotation.ELang.US]:"en"},DEFAULT_ZOOM_INFO={min:.2,max:1e3,ratio:.4};class BasicToolOperation extends eventListener{constructor(t){super();this.isDrag=!1,this.isSpaceKey=!1,this.staticMode=!1,this.operationMode=tool.EOperationMode.General,this.innerZoom=1,this.basicZoom=.01,this.isSpaceClick=!1,this.isDragStart=!1,this.startTime=0,this.zoomInfo=DEFAULT_ZOOM_INFO,this.initImgPos=()=>__async(this,null,function*(){var d,l;if(!this.imgNode)return;const u=(d=this._imgAttribute)==null?void 0:d.zoomRatio,g=(l=this._imgAttribute)==null?void 0:l.isOriginalSize,{currentPos:m,imgInfo:b,zoom:f}=lbUtils.ImgPosUtils.getInitImgPos(this.size,{width:this.imgNode.width,height:this.imgNode.height},this.rotate,u,g);this.setCurrentPos(m),this.currentPosStorage=m,this.setImgInfo(b),this.setZoom(f),this.render(),this.renderBasicCanvas(),this.emit("dependRender"),this.emit("renderZoom",f,m,b)}),this.getCurrentPos=d=>{const{_firstClickCoordinate:l,currentPosStorage:u}=this;try{let g;return l&&u?g={y:u.y+d.y-l.y,x:u.x+d.x-l.x}:g={x:0,y:0},g}catch(g){return console.error(g),{x:0,y:0}}},this.wheelChangePos=(d,l,u)=>{const{currentPos:g,imgNode:m}=this;if(!m){console.error("unable to load image");return}if(this.zoom===this.basicZoom&&l===-1)return;const b=ZoomUtils.wheelChangePos(m,d,l,g,{zoom:u||this.zoom,innerZoom:this.innerZoom,basicZoom:this.basicZoom,zoomMax:this.zoomInfo.max,rotate:this.rotate});if(!b)return;const{currentPos:f,ratio:w,zoom:y,imgInfo:P}=b;this.setZoom(y),this.setCurrentPos(f),this.currentPosStorage=f,this.setImgInfo(P),this.zoomInfo.ratio=w,this.emit("renderZoom",y,f,P)},this.zoomChanged=(d,l=annotation.EGrowthMode.Linear)=>{const u=ZoomUtils.zoomChanged(this.zoom,d,l);this.wheelChangePos(this.getGetCenterCoordinate(),u>this.zoom?1:-1,u),this.render(),this.renderBasicCanvas()},this.zoomChangeOnCenter=d=>{this.wheelChangePos(this.getGetCenterCoordinate(),0,d),this.render(),this.renderBasicCanvas()},this.drawImg=()=>{!this.imgNode||this.hiddenImg===!0||(DrawUtils.drawImg(this.basicCanvas,this.imgNode,{zoom:this.zoom,currentPos:this.currentPos,rotate:this.rotate,imgAttribute:this._imgAttribute}),this.drawStaticImg())},this.drawStaticImg=()=>{!this.staticImgNode||!this.staticMode||(this.clearCanvas(),DrawUtils.drawImg(this.canvas,this.staticImgNode,{zoom:this.zoom,currentPos:this.currentPos,rotate:this.rotate,imgAttribute:this._imgAttribute}))};var e,i,s,o,h,r,n,a,v,C,I;this.container=t.container,this.config=CommonToolUtils.jsonParser(t.config),this.showDefaultCursor=t.showDefaultCursor||!1,this.destroyCanvas(),this.createCanvas(t.size,t.isAppend),this.imgNode=t.imgNode,this.staticMode=(e=t.staticMode)!=null?e:!1,this.isImgError=!t.imgNode,this.basicImgInfo={width:(s=(i=t.imgNode)==null?void 0:i.width)!=null?s:0,height:(h=(o=t.imgNode)==null?void 0:o.height)!=null?h:0,valid:!0,rotate:0},this.forbidOperation=(r=t.forbidOperation)!=null?r:!1,this.forbidBasicResultRender=(n=t.forbidBasicResultRender)!=null?n:!1,this.size=t.size,this.currentPos={x:0,y:0},this.zoom=1,this.coord={x:-1,y:-1},this.currentPosStorage={x:0,y:0},this.isShowCursor=!1,this.attributeLockList=[],this.history=new ActionsHistory,this.style=(a=t.style)!=null?a:CommonToolUtils.jsonParser(style.styleString),this._imgAttribute=(v=t.imgAttribute)!=null?v:{},this.isHidden=!1,this.dragStatus=annotation.EDragStatus.Wait,this.defaultAttribute=(C=t==null?void 0:t.defaultAttribute)!=null?C:"",this.forbidCursorLine=!!t.forbidCursorLine,this.lang=(I=t==null?void 0:t.language)!=null?I:annotation.ELang.Zh,lbUtils.i18n.changeLanguage(LANGUAGE_MAP[this.lang]),this.onMouseDown=this.onMouseDown.bind(this),this.onMouseMove=this.onMouseMove.bind(this),this.onMouseLeave=this.onMouseLeave.bind(this),this.onMouseUp=this.onMouseUp.bind(this),this.onKeyDown=this.onKeyDown.bind(this),this.onKeyUp=this.onKeyUp.bind(this),this.onWheel=this.onWheel.bind(this),this.onLeftDblClick=this.onLeftDblClick.bind(this),this.onRightDblClick=this.onRightDblClick.bind(this),this.onClick=this.onClick.bind(this),this.clearImgDrag=this.clearImgDrag.bind(this),this.dblClickListener=new DblClickEventListener(this.container,200),this.coordUtils=new AxisUtils.CoordinateUtils(this),this.coordUtils.setBasicImgInfo(this.basicImgInfo),this.hiddenImg=t.hiddenImg||!1,t.zoomInfo&&(this.zoomInfo=t.zoomInfo)}onContextmenu(t){t.preventDefault()}get ctx(){var t;return this._ctx||((t=this.canvas)==null?void 0:t.getContext("2d"))}get basicCtx(){var t;return(t=this.basicCanvas)==null?void 0:t.getContext("2d")}get rotate(){var t,e;return(e=(t=this.basicImgInfo)==null?void 0:t.rotate)!=null?e:0}get valid(){var t,e;return(e=(t=this.basicImgInfo)==null?void 0:t.valid)!=null?e:!0}get baseIcon(){return style.BASE_ICON[this.style.color]}get defaultCursor(){return this.showDefaultCursor?"default":"none"}get dataList(){return[]}get innerPosAndZoom(){return{innerZoom:this.innerZoom,currentPosStorage:this.currentPosStorage}}get isShowDefaultCursor(){return this.showDefaultCursor}get isMultiMoveMode(){return this.operationMode===tool.EOperationMode.MultiMove}get hasMarkerConfig(){return this.config.markerConfigurable===!0&&this.config.markerList&&this.config.markerList.length>0}setZoom(t){this.zoom=t,this.innerZoom=t,this.coordUtils.setZoomAndCurrentPos(this.zoom,this.currentPos)}setCurrentPos(t){this.currentPos=t,this.coordUtils.setZoomAndCurrentPos(this.zoom,this.currentPos)}setReferenceData(t){this.referenceData=t}setImgInfo(t){this.imgInfo=t}setCurrentPosStorage(t){this.currentPosStorage=t}setOperationMode(t){this.operationMode=t}recoverOperationMode(){this.operationMode===tool.EOperationMode.MultiMove&&this.setOperationMode(tool.EOperationMode.General)}updatePosition(t){const{zoom:e,currentPos:i}=t;this.setZoom(e),this.setCurrentPos(i),this.currentPosStorage=i,this.renderBasicCanvas(),this.render()}setLang(t){this.lang=t;const e=LANGUAGE_MAP[t];lbUtils.i18n.changeLanguage(e)}setShowDefaultCursor(t){this.showDefaultCursor=t,this.container.style.cursor=this.defaultCursor}setCustomCursor(t){this.container.style.cursor=t}get forbidMouseOperation(){return this.forbidOperation||this.valid===!1}get pixelRatio(){var t;return CanvasUtils.getPixelRatio((t=this.canvas)==null?void 0:t.getContext("2d"))}init(){this.eventUnbinding(),this.initPosition(),this.eventBinding(),this.render(),this.renderBasicCanvas()}destroy(){this.destroyCanvas(),this.eventUnbinding()}updateCanvasBasicStyle(t,e,i){const s=this.pixelRatio;t.style.position="absolute",t.width=e.width*s,t.height=e.height*s,t.style.width=`${e.width}px`,t.style.height=`${e.height}px`,t.style.left="0",t.style.top="0",t.style.zIndex=`${i} `}createCanvas(t,e=!0){var i,s;const o=this.pixelRatio,h=document.createElement("canvas");this.updateCanvasBasicStyle(h,t,0),this.basicCanvas=h;const r=document.createElement("canvas");this.updateCanvasBasicStyle(r,t,10),e&&(this.container.hasChildNodes()?(this.container.insertBefore(r,this.container.childNodes[0]),this.container.insertBefore(h,this.container.childNodes[0])):(this.container.appendChild(h),this.container.appendChild(r))),this.canvas=r,this.container.style.cursor=this.defaultCursor,(i=this.ctx)==null||i.scale(o,o),(s=this.basicCtx)==null||s.scale(o,o),this.ctx&&(this.ctx.imageSmoothingEnabled=!1)}destroyCanvas(){this.canvas&&this.container.contains(this.canvas)&&this.container.removeChild(this.canvas),this.basicCanvas&&this.container.contains(this.basicCanvas)&&this.container.removeChild(this.basicCanvas),this.clearInvalidPage(),this.clearImgDrag()}setStyle(t){this.style=t,this.render()}setImgNode(t,e={}){this.imgNode=t,this.setBasicImgInfo(__spreadValues({width:t.width,height:t.height,valid:!0,rotate:0},e)),this.updateZoomInfo(),this.isImgError===!0&&(this.isImgError=!1,this.emit("changeAnnotationShow")),typeof e.valid=="boolean"&&this.setValid(e.valid),this.initImgPos(),this.render(),this.renderBasicCanvas()}updateZoomInfo(t=this.imgNode,e=this.size){var i;if(!t||!e)return;const{min:s}=lbUtils.ImgPosUtils.getMinZoomByImgAndSize({canvasSize:e,imgSize:{width:t.width,height:t.height},rotate:this.rotate,zoomRatio:(i=this._imgAttribute)==null?void 0:i.zoomRatio});this.zoomInfo=__spreadProps(__spreadValues({},this.zoomInfo),{min:s})}setErrorImg(){const t=this.isImgError;this.isImgError=!0,this.imgNode=void 0,this.setBasicImgInfo({width:0,height:0,valid:!0,rotate:0}),t===!1&&this.emit("changeAnnotationShow")}setBasicImgInfo(t){this.basicImgInfo=t,this.coordUtils.setBasicImgInfo(t)}setForbidOperation(t){this.forbidOperation=t,this.setShowDefaultCursor(t),this.render()}setForbidCursorLine(t){this.forbidCursorLine=t,this.render()}setIsHidden(t){this.isHidden=t,this.emit("hiddenChange")}setDefaultAttribute(t){this.defaultAttribute=t}getCoordinateInOrigin(t){const e=this.canvas.getBoundingClientRect();return{x:(t.clientX-e.left-this.currentPos.x)/this.zoom,y:(t.clientY-e.top-this.currentPos.y)/this.zoom}}getTextIconSvg(t=""){var e;return AttributeUtils.default.getTextIconSvg(t,(e=this.config)==null?void 0:e.attributeList,this.config.attributeConfigurable,this.baseIcon)}setIsShowOrder(t){this.config.isShowOrder=t,this.render()}getCoordinate(t){const e=this.canvas.getBoundingClientRect();return{x:t.clientX-e.left,y:t.clientY-e.top}}getCoordinateUnderZoom(t){const e=this.canvas.getBoundingClientRect();return{x:t.clientX-e.left-this.currentPos.x,y:t.clientY-e.top-this.currentPos.y}}getCoordinateUnderZoomByRotate(t){const{x:e,y:i}=this.getCoordinateUnderZoom(t);return this.basicImgInfo.rotate===90?{x:i,y:this.basicImgInfo.height*this.zoom-e}:this.basicImgInfo.rotate===180?{x:this.basicImgInfo.width*this.zoom-e,y:this.basicImgInfo.height*this.zoom-i}:this.basicImgInfo.rotate===270?{x:this.basicImgInfo.width*this.zoom-i,y:e}:{x:e,y:i}}getGetCenterCoordinate(){return{x:this.size.width/2,y:this.size.height/2}}initPosition(){if(this.basicResult&&this.imgInfo){const{basicResult:t,size:e,imgNode:i,_imgAttribute:s,imgInfo:o,dependToolName:h}=this;if(t&&i&&h){let r=t;switch(h){case tool.EToolName.Polygon:case tool.EToolName.Line:{if(t.pointList){const a=MathUtils.default.calcViewportBoundaries(t.pointList);r={x:a.left,y:a.top,width:a.right-a.left,height:a.bottom-a.top}}break}}const n=lbUtils.ImgPosUtils.getBasicRecPos(i,r,e,void 0,s==null?void 0:s.zoomRatio,s==null?void 0:s.isOriginalSize);n&&(this.setCurrentPos(n.currentPos),this.currentPosStorage=this.currentPos,this.setImgInfo(__spreadProps(__spreadValues({},o),{width:o.width/this.innerZoom*n.innerZoom,height:o.height/this.innerZoom*n.innerZoom})),this.setZoom(n.innerZoom),this.render(),this.renderBasicCanvas())}}else this.initImgPos()}undo(){this.history.undo()}redo(){this.history.redo()}clearCanvas(){var t;(t=this.ctx)==null||t.clearRect(0,0,this.size.width,this.size.height)}clearBasicCanvas(){var t;(t=this.basicCtx)==null||t.clearRect(0,0,this.size.width,this.size.height)}eventBinding(){this.dblClickListener.addEvent(()=>{},this.onLeftDblClick,this.onRightDblClick),this.container.addEventListener("mousedown",this.onMouseDown),this.container.addEventListener("mousemove",this.onMouseMove),this.container.addEventListener("mouseup",this.onMouseUp),this.container.addEventListener("mouseleave",this.onMouseLeave),this.container.addEventListener("click",this.onClick),this.container.addEventListener("wheel",this.onWheel),document.addEventListener("keydown",this.onKeyDown),document.addEventListener("keyup",this.onKeyUp),window.parent.document.addEventListener("contextmenu",this.onContextmenu,!1)}eventUnbinding(){this.container.removeEventListener("mousedown",this.onMouseDown),this.container.removeEventListener("mousemove",this.onMouseMove),this.container.removeEventListener("mouseup",this.onMouseUp),this.container.removeEventListener("mouseleave",this.onMouseLeave),this.container.removeEventListener("wheel",this.onWheel),this.container.removeEventListener("click",this.onClick),document.removeEventListener("keydown",this.onKeyDown),document.removeEventListener("keyup",this.onKeyUp),window.parent.document.removeEventListener("contextmenu",this.onContextmenu,!1),this.dblClickListener.removeEvent()}clearImgDrag(){this.isDrag=!1,this.isDragStart=!1,this.isSpaceClick=!1,this.startTime=0,this.container.style.cursor=this.defaultCursor,this.forbidCursorLine=!1}clearCursorLine(){this.coord={x:-1,y:-1}}onMouseDown(t){if(!this.canvas||this.isImgError)return!0;const e=this.getCoordinate(t);(this.isSpaceKey&&t.button===0||t.button===2)&&(t.stopPropagation(),this._firstClickCoordinate=e,this.currentPosStorage=this.currentPos,this.isSpaceClick=!0,this.isDragStart=!0,this.startTime=new Date().getTime())}onMouseMove(t){if(!this.canvas||this.isImgError)return!0;const e=this.getCoordinate(t);this.isShowCursor&&(this.coord=e);try{if(!e||!_.isNumber(e==null?void 0:e.x)||!_.isNumber(e==null?void 0:e.y))throw new Error("coord error");if(this.coord=e,(this.isSpaceClick||this.isDragStart)&&this._firstClickCoordinate){const i=this.getCurrentPos(e);this.setCurrentPos(i),this.isDrag=!0,this.container.style.cursor="grabbing",this.forbidCursorLine=!0,this.renderBasicCanvas(),this.emit("dependRender"),this.emit("dragMove",{currentPos:i,zoom:this.zoom,imgInfo:this.imgInfo})}this.render()}catch(i){console.error(i)}}onMouseUp(t){if(!this.canvas||this.isImgError)return!0;if(this.container.style.cursor=this.defaultCursor,this.forbidCursorLine=!1,this.isDrag=!1,this.isDragStart=!1,this.isSpaceClick=!1,this.startTime!==0&&this._firstClickCoordinate){const e=new Date().getTime(),i=this.getCoordinate(t);if(e-this.startTime>1e3||this.isSpaceKey===!0||LineToolUtils.default.calcTwoPointDistance(i,this._firstClickCoordinate)>10)return t.stopPropagation(),this.startTime=0,this.render(),!0}this.startTime=0,this.render()}onMouseLeave(){this.clearImgDrag()}onClick(t){}onLeftDblClick(t){}onRightDblClick(t){this.clearImgDrag()}onKeyDown(t){switch(t.keyCode===keyCode.Alt&&t.preventDefault(),t.keyCode){case keyCode.Space:this.isSpaceKey=!0,t.preventDefault();break;case keyCode.Z:if(t.ctrlKey)return t.shiftKey?this.redo():this.undo(),!1;break}return!0}onKeyUp(t){switch(t.keyCode){case keyCode.Space:this.isSpaceKey=!1;break}}exportCustomData(){return{}}onWheel(t,e=!0){if(!this.imgNode||!this.coord)return;t.preventDefault(),t.stopPropagation();const i=this.getCoordinate(t),s=t.deltaY||t.wheelDelta;let o=0;s>0&&this.zoom>this.zoomInfo.min&&(o=-1),s<0&&this.zoom<this.zoomInfo.max&&(o=1),this.wheelChangePos(i,o),this.emit("dependRender"),e&&this.render(),this.renderBasicCanvas()}renderCursorLine(t=(e=>(e=this.style.lineColor[0])!=null?e:"")()){if(!this.ctx||this.forbidCursorLine||this.forbidOperation)return;const{x:e,y:i}=this.coord;DrawUtils.drawLine(this.canvas,{x:0,y:i},{x:1e4,y:i},{color:t}),DrawUtils.drawLine(this.canvas,{x:e,y:0},{x:e,y:1e4},{color:t}),DrawUtils.drawCircleWithFill(this.canvas,{x:e,y:i},1,{color:"white"})}setSize(t){var e;this.size=t,this.updateZoomInfo(),this.container.contains(this.canvas)&&(this.destroyCanvas(),this.createCanvas(t),this.eventUnbinding(),this.init(),((e=this.basicImgInfo)==null?void 0:e.valid)===!1&&this.renderInvalidPage())}setImgAttribute(t){const e=this._imgAttribute;if(this._imgAttribute=t,(e==null?void 0:e.zoomRatio)!==t.zoomRatio||e.isOriginalSize!==t.isOriginalSize){this.initImgPos();return}this.renderBasicCanvas(),this.render()}clearResult(t){}setValid(t){this.basicImgInfo.valid=t,t===!1?(this.renderInvalidPage(),this.clearResult(!1)):this.clearInvalidPage()}setRotate(t){this.basicImgInfo.rotate=t}setBasicResult(t){this.basicResult=t,this.coordUtils.setBasicResult(t),this.initPosition(),this.emit("dependRender")}setDependName(t,e){this.dependToolName=t,this.coordUtils.setDependInfo(t,e)}setAttributeLockList(t){this.attributeLockList=t,this.render()}setConfig(t){this.config=CommonToolUtils.jsonParser(t)}setDataInjectionAtCreation(t){this.dataInjectionAtCreation=t}setRenderEnhance(t){this.renderEnhance=t}setCustomRenderStyle(t){this.customRenderStyle=t}updateRotate(){if(this.dependToolName)return this.emit("messageInfo",index.getMessagesByLocale(constants.EMessage.NoRotateInDependence,this.lang)),!1;if(this.dataList.length>0)return this.emit("messageInfo",index.getMessagesByLocale(constants.EMessage.NoRotateNotice,this.lang)),!1;const t=MathUtils.default.getRotate(this.basicImgInfo.rotate);this.basicImgInfo.rotate=t,this.initImgPos(),this.emit("updateResult")}getColor(t="",e=this.config){return lbUtils.toolStyleConverter.getColorByConfig({attribute:t,config:e,style:this.style})}getLineColor(t=""){var e,i,s,o,h,r,n,a;if(((e=this.config)==null?void 0:e.attributeConfigurable)===!0){const I=AttributeUtils.default.getAttributeIndex(t,(s=(i=this.config)==null?void 0:i.attributeList)!=null?s:[])+1;return((r=(h=(o=this.config)==null?void 0:o.attributeList)==null?void 0:h.find(l=>l.value===t))==null?void 0:r.color)?(a=(n=lbUtils.toolStyleConverter.getColorByConfig({attribute:t,config:this.config}))==null?void 0:n.valid)==null?void 0:a.stroke:this.style.attributeLineColor?this.style.attributeLineColor[I]:""}const{color:v,lineColor:C}=this.style;return v&&C?C[v]:""}clearInvalidPage(){this._invalidDOM&&this.container&&this.container.contains(this._invalidDOM)&&(this.container.removeChild(this._invalidDOM),this._invalidDOM=void 0)}renderInvalidPage(){!this.container||this._invalidDOM||(this._invalidDOM=RenderDomUtils.renderInvalidPage(this.container,this.size,this.lang))}renderBasicCanvas(){if(!this.basicCanvas)return;this.clearBasicCanvas(),this.drawImg();const t=3;if(!this.forbidBasicResultRender&&this.basicResult&&this.dependToolName)switch(this.dependToolName){case tool.EToolName.Rect:{DrawUtils.drawRect(this.basicCanvas,AxisUtils.default.changeRectByZoom(this.basicResult,this.zoom,this.currentPos),{color:"rgba(204,204,204,1.00)",thickness:t});break}case tool.EToolName.Polygon:{DrawUtils.drawPolygonWithFillAndLine(this.basicCanvas,AxisUtils.default.changePointListByZoom(this.basicResult.pointList,this.zoom,this.currentPos),{fillColor:"transparent",strokeColor:"rgba(204,204,204,1.00)",isClose:!0,thickness:t});break}case tool.EToolName.Line:{DrawUtils.drawLineWithPointList(this.basicCanvas,AxisUtils.default.changePointListByZoom(this.basicResult.pointList,this.zoom,this.currentPos),{color:"rgba(204,204,204,1.00)",thickness:t});break}}}render(){!this.canvas||!this.ctx||!this.imgNode||this.clearCanvas()}changeStyle(t=this.defaultAttribute){this.emit("changeStyle",{attribute:t})}}exports.BasicToolOperation=BasicToolOperation;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var lbUtils=require("@labelbee/lb-utils"),_=require("lodash"),tool=require("../../constant/tool.js"),MathUtils=require("../../utils/MathUtils.js"),AxisUtils=require("../../utils/tool/AxisUtils.js"),CanvasUtils=require("../../utils/tool/CanvasUtils.js"),CommonToolUtils=require("../../utils/tool/CommonToolUtils.js"),LineToolUtils=require("../../utils/tool/LineToolUtils.js"),annotation=require("../../constant/annotation.js"),keyCode=require("../../constant/keyCode.js"),style=require("../../constant/style.js"),index=require("../../locales/index.js"),constants=require("../../locales/constants.js"),ActionsHistory=require("../../utils/ActionsHistory.js"),AttributeUtils=require("../../utils/tool/AttributeUtils.js"),DblClickEventListener=require("../../utils/tool/DblClickEventListener.js"),DrawUtils=require("../../utils/tool/DrawUtils.js"),RenderDomUtils=require("../../utils/tool/RenderDomUtils.js"),ZoomUtils=require("../../utils/tool/ZoomUtils.js"),eventListener=require("./eventListener.js"),__defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnPropDescs=Object.getOwnPropertyDescriptors,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(u,t,i)=>t in u?__defProp(u,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):u[t]=i,__spreadValues=(u,t)=>{for(var i in t||(t={}))__hasOwnProp.call(t,i)&&__defNormalProp(u,i,t[i]);if(__getOwnPropSymbols)for(var i of __getOwnPropSymbols(t))__propIsEnum.call(t,i)&&__defNormalProp(u,i,t[i]);return u},__spreadProps=(u,t)=>__defProps(u,__getOwnPropDescs(t)),__async=(u,t,i)=>new Promise((e,o)=>{var r=n=>{try{a(i.next(n))}catch(l){o(l)}},c=n=>{try{a(i.throw(n))}catch(l){o(l)}},a=n=>n.done?e(n.value):Promise.resolve(n.value).then(r,c);a((i=i.apply(u,t)).next())});const LANGUAGE_MAP={[annotation.ELang.Zh]:"cn",[annotation.ELang.US]:"en"},DEFAULT_ZOOM_INFO={min:.2,max:1e3,ratio:.4};class BasicToolOperation extends eventListener{constructor(t){super();this.isDrag=!1,this.isSpaceKey=!1,this.staticMode=!1,this.operationMode=tool.EOperationMode.General,this.innerZoom=1,this.basicZoom=.01,this.isSpaceClick=!1,this.isDragStart=!1,this.startTime=0,this.zoomInfo=DEFAULT_ZOOM_INFO,this.initImgPos=()=>__async(this,null,function*(){var d,h;if(!this.imgNode)return;const s=(d=this._imgAttribute)==null?void 0:d.zoomRatio,g=(h=this._imgAttribute)==null?void 0:h.isOriginalSize,{currentPos:m,imgInfo:f,zoom:v}=lbUtils.ImgPosUtils.getInitImgPos(this.size,{width:this.imgNode.width,height:this.imgNode.height},this.rotate,s,g);this.setCurrentPos(m),this.currentPosStorage=m,this.setImgInfo(f),this.setZoom(v),this.render(),this.renderBasicCanvas(),this.emit("dependRender"),this.emit("renderZoom",v,m,f)}),this.getCurrentPos=d=>{const{_firstClickCoordinate:h,currentPosStorage:s}=this;try{let g;return h&&s?g={y:s.y+d.y-h.y,x:s.x+d.x-h.x}:g={x:0,y:0},g}catch(g){return console.error(g),{x:0,y:0}}},this.wheelChangePos=(d,h,s)=>{const{currentPos:g,imgNode:m}=this;if(!m){console.error("unable to load image");return}if(this.zoom===this.basicZoom&&h===-1)return;const f=ZoomUtils.wheelChangePos(m,d,h,g,{zoom:s||this.zoom,innerZoom:this.innerZoom,basicZoom:this.basicZoom,zoomMax:this.zoomInfo.max,rotate:this.rotate});if(!f)return;const{currentPos:v,ratio:w,zoom:y,imgInfo:P}=f;this.setZoom(y),this.setCurrentPos(v),this.currentPosStorage=v,this.setImgInfo(P),this.zoomInfo.ratio=w,this.emit("renderZoom",y,v,P)},this.zoomChanged=(d,h=annotation.EGrowthMode.Linear)=>{const s=ZoomUtils.zoomChanged(this.zoom,d,h);this.wheelChangePos(this.getGetCenterCoordinate(),s>this.zoom?1:-1,s),this.render(),this.renderBasicCanvas()},this.zoomChangeOnCenter=d=>{this.wheelChangePos(this.getGetCenterCoordinate(),0,d),this.render(),this.renderBasicCanvas()},this.drawStraightLine=(d,h)=>{const{ctx:s}=this;s&&(s.save(),s.lineCap="round",s.lineJoin="round",s.strokeStyle=h.color,s.lineWidth=h.lineWidth,s.globalAlpha=h.globalAlpha,d.forEach((g,m)=>{if(s.beginPath(),m>0){const f=d[m-1];s.save(),s.moveTo(f.x,f.y),s.lineTo(g.x,g.y),s.stroke(),s.restore()}}),s.restore())},this.drawImg=()=>{!this.imgNode||this.hiddenImg===!0||(DrawUtils.drawImg(this.basicCanvas,this.imgNode,{zoom:this.zoom,currentPos:this.currentPos,rotate:this.rotate,imgAttribute:this._imgAttribute}),this.drawStaticImg())},this.drawStaticImg=()=>{!this.staticImgNode||!this.staticMode||(this.clearCanvas(),DrawUtils.drawImg(this.canvas,this.staticImgNode,{zoom:this.zoom,currentPos:this.currentPos,rotate:this.rotate,imgAttribute:this._imgAttribute}))};var i,e,o,r,c,a,n,l,C,b,I;this.container=t.container,this.config=CommonToolUtils.jsonParser(t.config),this.showDefaultCursor=t.showDefaultCursor||!1,this.destroyCanvas(),this.createCanvas(t.size,t.isAppend),this.imgNode=t.imgNode,this.staticMode=(i=t.staticMode)!=null?i:!1,this.isImgError=!t.imgNode,this.basicImgInfo={width:(o=(e=t.imgNode)==null?void 0:e.width)!=null?o:0,height:(c=(r=t.imgNode)==null?void 0:r.height)!=null?c:0,valid:!0,rotate:0},this.forbidOperation=(a=t.forbidOperation)!=null?a:!1,this.forbidBasicResultRender=(n=t.forbidBasicResultRender)!=null?n:!1,this.size=t.size,this.currentPos={x:0,y:0},this.zoom=1,this.coord={x:-1,y:-1},this.currentPosStorage={x:0,y:0},this.isShowCursor=!1,this.attributeLockList=[],this.history=new ActionsHistory,this.style=(l=t.style)!=null?l:CommonToolUtils.jsonParser(style.styleString),this._imgAttribute=(C=t.imgAttribute)!=null?C:{},this.isHidden=!1,this.dragStatus=annotation.EDragStatus.Wait,this.defaultAttribute=(b=t==null?void 0:t.defaultAttribute)!=null?b:"",this.forbidCursorLine=!!t.forbidCursorLine,this.lang=(I=t==null?void 0:t.language)!=null?I:annotation.ELang.Zh,lbUtils.i18n.changeLanguage(LANGUAGE_MAP[this.lang]),this.onMouseDown=this.onMouseDown.bind(this),this.onMouseMove=this.onMouseMove.bind(this),this.onMouseLeave=this.onMouseLeave.bind(this),this.onMouseUp=this.onMouseUp.bind(this),this.onKeyDown=this.onKeyDown.bind(this),this.onKeyUp=this.onKeyUp.bind(this),this.onWheel=this.onWheel.bind(this),this.onLeftDblClick=this.onLeftDblClick.bind(this),this.onRightDblClick=this.onRightDblClick.bind(this),this.onClick=this.onClick.bind(this),this.clearImgDrag=this.clearImgDrag.bind(this),this.dblClickListener=new DblClickEventListener(this.container,200),this.coordUtils=new AxisUtils.CoordinateUtils(this),this.coordUtils.setBasicImgInfo(this.basicImgInfo),this.hiddenImg=t.hiddenImg||!1,t.zoomInfo&&(this.zoomInfo=t.zoomInfo)}onContextmenu(t){t.preventDefault()}get ctx(){var t;return this._ctx||((t=this.canvas)==null?void 0:t.getContext("2d"))}get basicCtx(){var t;return(t=this.basicCanvas)==null?void 0:t.getContext("2d")}get rotate(){var t,i;return(i=(t=this.basicImgInfo)==null?void 0:t.rotate)!=null?i:0}get valid(){var t,i;return(i=(t=this.basicImgInfo)==null?void 0:t.valid)!=null?i:!0}get baseIcon(){return style.BASE_ICON[this.style.color]}get defaultCursor(){return this.showDefaultCursor?"default":"none"}get dataList(){return[]}get innerPosAndZoom(){return{innerZoom:this.innerZoom,currentPosStorage:this.currentPosStorage}}get isShowDefaultCursor(){return this.showDefaultCursor}get isMultiMoveMode(){return this.operationMode===tool.EOperationMode.MultiMove}get hasMarkerConfig(){return this.config.markerConfigurable===!0&&this.config.markerList&&this.config.markerList.length>0}setZoom(t){this.zoom=t,this.innerZoom=t,this.coordUtils.setZoomAndCurrentPos(this.zoom,this.currentPos)}setCurrentPos(t){this.currentPos=t,this.coordUtils.setZoomAndCurrentPos(this.zoom,this.currentPos)}setReferenceData(t){this.referenceData=t}setImgInfo(t){this.imgInfo=t}setCurrentPosStorage(t){this.currentPosStorage=t}setOperationMode(t){this.operationMode=t}recoverOperationMode(){this.operationMode===tool.EOperationMode.MultiMove&&this.setOperationMode(tool.EOperationMode.General)}updatePosition(t){const{zoom:i,currentPos:e}=t;this.setZoom(i),this.setCurrentPos(e),this.currentPosStorage=e,this.renderBasicCanvas(),this.render()}setLang(t){this.lang=t;const i=LANGUAGE_MAP[t];lbUtils.i18n.changeLanguage(i)}setShowDefaultCursor(t){this.showDefaultCursor=t,this.container.style.cursor=this.defaultCursor}setCustomCursor(t){this.container.style.cursor=t}get forbidMouseOperation(){return this.forbidOperation||this.valid===!1}get pixelRatio(){var t;return CanvasUtils.getPixelRatio((t=this.canvas)==null?void 0:t.getContext("2d"))}init(){this.eventUnbinding(),this.initPosition(),this.eventBinding(),this.render(),this.renderBasicCanvas()}destroy(){this.destroyCanvas(),this.eventUnbinding()}updateCanvasBasicStyle(t,i,e){const o=this.pixelRatio;t.style.position="absolute",t.width=i.width*o,t.height=i.height*o,t.style.width=`${i.width}px`,t.style.height=`${i.height}px`,t.style.left="0",t.style.top="0",t.style.zIndex=`${e} `}createCanvas(t,i=!0){var e,o;const r=this.pixelRatio,c=document.createElement("canvas");this.updateCanvasBasicStyle(c,t,0),this.basicCanvas=c;const a=document.createElement("canvas");this.updateCanvasBasicStyle(a,t,10),i&&(this.container.hasChildNodes()?(this.container.insertBefore(a,this.container.childNodes[0]),this.container.insertBefore(c,this.container.childNodes[0])):(this.container.appendChild(c),this.container.appendChild(a))),this.canvas=a,this.container.style.cursor=this.defaultCursor,(e=this.ctx)==null||e.scale(r,r),(o=this.basicCtx)==null||o.scale(r,r),this.ctx&&(this.ctx.imageSmoothingEnabled=!1)}destroyCanvas(){this.canvas&&this.container.contains(this.canvas)&&this.container.removeChild(this.canvas),this.basicCanvas&&this.container.contains(this.basicCanvas)&&this.container.removeChild(this.basicCanvas),this.clearInvalidPage(),this.clearImgDrag()}setStyle(t){this.style=t,this.render()}setImgNode(t,i={}){this.imgNode=t,this.setBasicImgInfo(__spreadValues({width:t.width,height:t.height,valid:!0,rotate:0},i)),this.updateZoomInfo(),this.isImgError===!0&&(this.isImgError=!1,this.emit("changeAnnotationShow")),typeof i.valid=="boolean"&&this.setValid(i.valid),this.initImgPos(),this.render(),this.renderBasicCanvas()}updateZoomInfo(t=this.imgNode,i=this.size){var e;if(!t||!i)return;const{min:o}=lbUtils.ImgPosUtils.getMinZoomByImgAndSize({canvasSize:i,imgSize:{width:t.width,height:t.height},rotate:this.rotate,zoomRatio:(e=this._imgAttribute)==null?void 0:e.zoomRatio});this.zoomInfo=__spreadProps(__spreadValues({},this.zoomInfo),{min:o})}setErrorImg(){const t=this.isImgError;this.isImgError=!0,this.imgNode=void 0,this.setBasicImgInfo({width:0,height:0,valid:!0,rotate:0}),t===!1&&this.emit("changeAnnotationShow")}setBasicImgInfo(t){this.basicImgInfo=t,this.coordUtils.setBasicImgInfo(t)}setForbidOperation(t){this.forbidOperation=t,this.setShowDefaultCursor(t),this.render()}setForbidCursorLine(t){this.forbidCursorLine=t,this.render()}setIsHidden(t){this.isHidden=t,this.emit("hiddenChange")}setDefaultAttribute(t){this.defaultAttribute=t}getCoordinateInOrigin(t){const i=this.canvas.getBoundingClientRect();return{x:(t.clientX-i.left-this.currentPos.x)/this.zoom,y:(t.clientY-i.top-this.currentPos.y)/this.zoom}}getTextIconSvg(t=""){var i;return AttributeUtils.default.getTextIconSvg(t,(i=this.config)==null?void 0:i.attributeList,this.config.attributeConfigurable,this.baseIcon)}setIsShowOrder(t){this.config.isShowOrder=t,this.render()}getCoordinate(t){const i=this.canvas.getBoundingClientRect();return{x:t.clientX-i.left,y:t.clientY-i.top}}getCoordinateUnderZoom(t){const i=this.canvas.getBoundingClientRect();return{x:t.clientX-i.left-this.currentPos.x,y:t.clientY-i.top-this.currentPos.y}}getCoordinateUnderZoomByRotate(t){const{x:i,y:e}=this.getCoordinateUnderZoom(t);return this.basicImgInfo.rotate===90?{x:e,y:this.basicImgInfo.height*this.zoom-i}:this.basicImgInfo.rotate===180?{x:this.basicImgInfo.width*this.zoom-i,y:this.basicImgInfo.height*this.zoom-e}:this.basicImgInfo.rotate===270?{x:this.basicImgInfo.width*this.zoom-e,y:i}:{x:i,y:e}}getCoordinateUnderZoomByRotateFromImgPoint(t){const{x:i,y:e}=t;return this.basicImgInfo.rotate===90?{x:(this.basicImgInfo.height-e)*this.zoom+this.currentPos.x,y:i*this.zoom+this.currentPos.y}:this.basicImgInfo.rotate===180?{x:(this.basicImgInfo.width-i)*this.zoom+this.currentPos.x,y:(this.basicImgInfo.height-e)*this.zoom+this.currentPos.y}:this.basicImgInfo.rotate===270?{x:e*this.zoom+this.currentPos.x,y:(this.basicImgInfo.width-i)*this.zoom+this.currentPos.y}:{x:i*this.zoom+this.currentPos.x,y:e*this.zoom+this.currentPos.y}}getGetCenterCoordinate(){return{x:this.size.width/2,y:this.size.height/2}}initPosition(){if(this.basicResult&&this.imgInfo){const{basicResult:t,size:i,imgNode:e,_imgAttribute:o,imgInfo:r,dependToolName:c}=this;if(t&&e&&c){let a=t;switch(c){case tool.EToolName.Polygon:case tool.EToolName.Line:{if(t.pointList){const l=MathUtils.default.calcViewportBoundaries(t.pointList);a={x:l.left,y:l.top,width:l.right-l.left,height:l.bottom-l.top}}break}}const n=lbUtils.ImgPosUtils.getBasicRecPos(e,a,i,void 0,o==null?void 0:o.zoomRatio,o==null?void 0:o.isOriginalSize);n&&(this.setCurrentPos(n.currentPos),this.currentPosStorage=this.currentPos,this.setImgInfo(__spreadProps(__spreadValues({},r),{width:r.width/this.innerZoom*n.innerZoom,height:r.height/this.innerZoom*n.innerZoom})),this.setZoom(n.innerZoom),this.render(),this.renderBasicCanvas())}}else this.initImgPos()}undo(){this.history.undo()}redo(){this.history.redo()}clearCanvas(){var t;(t=this.ctx)==null||t.clearRect(0,0,this.size.width,this.size.height)}clearBasicCanvas(){var t;(t=this.basicCtx)==null||t.clearRect(0,0,this.size.width,this.size.height)}eventBinding(){this.dblClickListener.addEvent(()=>{},this.onLeftDblClick,this.onRightDblClick),this.container.addEventListener("mousedown",this.onMouseDown),this.container.addEventListener("mousemove",this.onMouseMove),this.container.addEventListener("mouseup",this.onMouseUp),this.container.addEventListener("mouseleave",this.onMouseLeave),this.container.addEventListener("click",this.onClick),this.container.addEventListener("wheel",this.onWheel),document.addEventListener("keydown",this.onKeyDown),document.addEventListener("keyup",this.onKeyUp),window.parent.document.addEventListener("contextmenu",this.onContextmenu,!1)}eventUnbinding(){this.container.removeEventListener("mousedown",this.onMouseDown),this.container.removeEventListener("mousemove",this.onMouseMove),this.container.removeEventListener("mouseup",this.onMouseUp),this.container.removeEventListener("mouseleave",this.onMouseLeave),this.container.removeEventListener("wheel",this.onWheel),this.container.removeEventListener("click",this.onClick),document.removeEventListener("keydown",this.onKeyDown),document.removeEventListener("keyup",this.onKeyUp),window.parent.document.removeEventListener("contextmenu",this.onContextmenu,!1),this.dblClickListener.removeEvent()}clearImgDrag(){this.isDrag=!1,this.isDragStart=!1,this.isSpaceClick=!1,this.startTime=0,this.container.style.cursor=this.defaultCursor,this.forbidCursorLine=!1}clearCursorLine(){this.coord={x:-1,y:-1}}onMouseDown(t){if(!this.canvas||this.isImgError)return!0;const i=this.getCoordinate(t);(this.isSpaceKey&&t.button===0||t.button===2)&&(t.stopPropagation(),this._firstClickCoordinate=i,this.currentPosStorage=this.currentPos,this.isSpaceClick=!0,this.isDragStart=!0,this.startTime=new Date().getTime())}onMouseMove(t){if(!this.canvas||this.isImgError)return!0;const i=this.getCoordinate(t);this.isShowCursor&&(this.coord=i);try{if(!i||!_.isNumber(i==null?void 0:i.x)||!_.isNumber(i==null?void 0:i.y))throw new Error("coord error");if(this.coord=i,(this.isSpaceClick||this.isDragStart)&&this._firstClickCoordinate){const e=this.getCurrentPos(i);this.setCurrentPos(e),this.isDrag=!0,this.container.style.cursor="grabbing",this.forbidCursorLine=!0,this.renderBasicCanvas(),this.emit("dependRender"),this.emit("dragMove",{currentPos:e,zoom:this.zoom,imgInfo:this.imgInfo})}this.render()}catch(e){console.error(e)}}onMouseUp(t){if(!this.canvas||this.isImgError)return!0;if(this.container.style.cursor=this.defaultCursor,this.forbidCursorLine=!1,this.isDrag=!1,this.isDragStart=!1,this.isSpaceClick=!1,this.startTime!==0&&this._firstClickCoordinate){const i=new Date().getTime(),e=this.getCoordinate(t);if(i-this.startTime>1e3||this.isSpaceKey===!0||LineToolUtils.default.calcTwoPointDistance(e,this._firstClickCoordinate)>10)return t.stopPropagation(),this.startTime=0,this.render(),!0}this.startTime=0,this.render()}onMouseLeave(){this.clearImgDrag()}onClick(t){}onLeftDblClick(t){}onRightDblClick(t){this.clearImgDrag()}onKeyDown(t){switch(t.keyCode===keyCode.Alt&&t.preventDefault(),t.keyCode){case keyCode.Space:this.isSpaceKey=!0,t.preventDefault();break;case keyCode.Z:if(t.ctrlKey)return t.shiftKey?this.redo():this.undo(),!1;break}return!0}onKeyUp(t){switch(t.keyCode){case keyCode.Space:this.isSpaceKey=!1;break}}exportCustomData(){return{}}onWheel(t,i=!0){if(!this.imgNode||!this.coord)return;t.preventDefault(),t.stopPropagation();const e=this.getCoordinate(t),o=t.deltaY||t.wheelDelta;let r=0;o>0&&this.zoom>this.zoomInfo.min&&(r=-1),o<0&&this.zoom<this.zoomInfo.max&&(r=1),this.wheelChangePos(e,r),this.emit("dependRender"),i&&this.render(),this.renderBasicCanvas()}renderCursorLine(t=(i=>(i=this.style.lineColor[0])!=null?i:"")()){if(!this.ctx||this.forbidCursorLine||this.forbidOperation)return;const{x:i,y:e}=this.coord;DrawUtils.drawLine(this.canvas,{x:0,y:e},{x:1e4,y:e},{color:t}),DrawUtils.drawLine(this.canvas,{x:i,y:0},{x:i,y:1e4},{color:t}),DrawUtils.drawCircleWithFill(this.canvas,{x:i,y:e},1,{color:"white"})}setSize(t){var i;this.size=t,this.updateZoomInfo(),this.container.contains(this.canvas)&&(this.destroyCanvas(),this.createCanvas(t),this.eventUnbinding(),this.init(),((i=this.basicImgInfo)==null?void 0:i.valid)===!1&&this.renderInvalidPage())}setImgAttribute(t){const i=this._imgAttribute;if(this._imgAttribute=t,(i==null?void 0:i.zoomRatio)!==t.zoomRatio||i.isOriginalSize!==t.isOriginalSize){this.initImgPos();return}this.renderBasicCanvas(),this.render()}clearResult(t){}setValid(t){this.basicImgInfo.valid=t,t===!1?(this.renderInvalidPage(),this.clearResult(!1)):this.clearInvalidPage()}setRotate(t){this.basicImgInfo.rotate=t}setBasicResult(t){this.basicResult=t,this.coordUtils.setBasicResult(t),this.initPosition(),this.emit("dependRender")}setDependName(t,i){this.dependToolName=t,this.coordUtils.setDependInfo(t,i)}setAttributeLockList(t){this.attributeLockList=t,this.render()}setConfig(t){this.config=CommonToolUtils.jsonParser(t)}setDataInjectionAtCreation(t){this.dataInjectionAtCreation=t}setRenderEnhance(t){this.renderEnhance=t}setCustomRenderStyle(t){this.customRenderStyle=t}updateRotate(){if(this.dependToolName)return this.emit("messageInfo",index.getMessagesByLocale(constants.EMessage.NoRotateInDependence,this.lang)),!1;if(this.dataList.length>0)return this.emit("messageInfo",index.getMessagesByLocale(constants.EMessage.NoRotateNotice,this.lang)),!1;const t=MathUtils.default.getRotate(this.basicImgInfo.rotate);this.basicImgInfo.rotate=t,this.initImgPos(),this.emit("updateResult")}getColor(t="",i=this.config){return lbUtils.toolStyleConverter.getColorByConfig({attribute:t,config:i,style:this.style})}getLineColor(t=""){var i,e,o,r,c,a,n,l;if(((i=this.config)==null?void 0:i.attributeConfigurable)===!0){const I=AttributeUtils.default.getAttributeIndex(t,(o=(e=this.config)==null?void 0:e.attributeList)!=null?o:[])+1;return((a=(c=(r=this.config)==null?void 0:r.attributeList)==null?void 0:c.find(h=>h.value===t))==null?void 0:a.color)?(l=(n=lbUtils.toolStyleConverter.getColorByConfig({attribute:t,config:this.config}))==null?void 0:n.valid)==null?void 0:l.stroke:this.style.attributeLineColor?this.style.attributeLineColor[I]:""}const{color:C,lineColor:b}=this.style;return C&&b?b[C]:""}clearInvalidPage(){this._invalidDOM&&this.container&&this.container.contains(this._invalidDOM)&&(this.container.removeChild(this._invalidDOM),this._invalidDOM=void 0)}renderInvalidPage(){!this.container||this._invalidDOM||(this._invalidDOM=RenderDomUtils.renderInvalidPage(this.container,this.size,this.lang))}renderBasicCanvas(){if(!this.basicCanvas)return;this.clearBasicCanvas(),this.drawImg();const t=3;if(!this.forbidBasicResultRender&&this.basicResult&&this.dependToolName)switch(this.dependToolName){case tool.EToolName.Rect:{DrawUtils.drawRect(this.basicCanvas,AxisUtils.default.changeRectByZoom(this.basicResult,this.zoom,this.currentPos),{color:"rgba(204,204,204,1.00)",thickness:t});break}case tool.EToolName.Polygon:{DrawUtils.drawPolygonWithFillAndLine(this.basicCanvas,AxisUtils.default.changePointListByZoom(this.basicResult.pointList,this.zoom,this.currentPos),{fillColor:"transparent",strokeColor:"rgba(204,204,204,1.00)",isClose:!0,thickness:t});break}case tool.EToolName.Line:{DrawUtils.drawLineWithPointList(this.basicCanvas,AxisUtils.default.changePointListByZoom(this.basicResult.pointList,this.zoom,this.currentPos),{color:"rgba(204,204,204,1.00)",thickness:t});break}}}render(){!this.canvas||!this.ctx||!this.imgNode||this.clearCanvas()}changeStyle(t=this.defaultAttribute){this.emit("changeStyle",{attribute:t})}}exports.BasicToolOperation=BasicToolOperation;
@@ -4,11 +4,17 @@
4
4
  * @author Ron <ron.f.luo@gmail.com>
5
5
  */
6
6
  import { PCDLoader } from './PCDLoader';
7
+ export type TIndexMap = Map<string, {
8
+ x: number;
9
+ y: number;
10
+ z: number;
11
+ }[]>;
7
12
  export declare class PointCloudCache {
8
13
  pcdLoader: PCDLoader;
9
14
  MAX_SIZE: number;
10
15
  private pointsMap;
11
16
  private colorMap;
17
+ private cacheIndexMap;
12
18
  private cacheList;
13
19
  private static instance;
14
20
  cache2DHighlightIndex: Map<string, number[]>;
@@ -28,4 +34,12 @@ export declare class PointCloudCache {
28
34
  * Clear all cache2dHighlightIndex.
29
35
  */
30
36
  clearCache2DHighlightIndex(): void;
37
+ /**
38
+ * Loads index map from cache or generates it in a worker.
39
+ *
40
+ * @param src The path to the source image.
41
+ * @param points The points of the source image.
42
+ * @returns A promise that resolves to the index map.
43
+ */
44
+ loadIndexMap: (src: string, points: Float32Array) => Promise<unknown>;
31
45
  }
@@ -247,6 +247,7 @@ export declare class PointCloud extends EventListener {
247
247
  }>;
248
248
  points: ArrayLike<number>;
249
249
  }) => Promise<number[]>;
250
+ filterPreResult: (src: string, config: any, boxParamsList: IPointCloudBox[]) => Promise<unknown>;
250
251
  /**
251
252
  * It needs to be updated after load PointCloud's data.
252
253
  * @param boxParams
@@ -6,11 +6,15 @@ declare class ScribbleTool extends BasicToolOperation {
6
6
  toolName: EToolName;
7
7
  defaultAttributeInfo?: IInputList;
8
8
  config: IScribbleConfig;
9
+ isHidden: boolean;
9
10
  private action;
10
11
  private cacheCanvas?;
11
12
  private cacheContext?;
12
13
  private penSize;
13
14
  private startPoint?;
15
+ private prePoint?;
16
+ private pointList;
17
+ private lineActive?;
14
18
  constructor(props: IProps);
15
19
  get cursorErase(): string;
16
20
  get defaultCursor(): string;
@@ -36,6 +40,8 @@ declare class ScribbleTool extends BasicToolOperation {
36
40
  }>): void;
37
41
  setResult(data: IScribbleData[]): void;
38
42
  onKeyDown(e: KeyboardEvent): boolean | void;
43
+ onKeyUp(e: KeyboardEvent): void;
44
+ toggleIsHide(): void;
39
45
  eventBinding(): void;
40
46
  onMouseDown: (e: MouseEvent) => undefined;
41
47
  onMouseMove: (e: MouseEvent) => undefined;
@@ -46,6 +52,7 @@ declare class ScribbleTool extends BasicToolOperation {
46
52
  clearStatusAfterLeave(): void;
47
53
  onMouseLeave(): void;
48
54
  onScribbleStart(e: MouseEvent): void;
55
+ scribbleOnImgByLine(endPoint: ICoordinate): void;
49
56
  onScribbleMove(e: MouseEvent): void;
50
57
  onScribbleEnd(): void;
51
58
  eraseArc(e: MouseEvent): void;
@@ -57,6 +64,7 @@ declare class ScribbleTool extends BasicToolOperation {
57
64
  clearResult(): void;
58
65
  renderPoint(radius: number): void;
59
66
  renderBorderPoint(radius: number): void;
67
+ drawLineSegment(): void;
60
68
  render(): void;
61
69
  /** 撤销 */
62
70
  undo(): void;
@@ -197,6 +197,13 @@ declare class BasicToolOperation extends EventListener {
197
197
  x: number;
198
198
  y: number;
199
199
  };
200
+ /**
201
+ * Get the coordinates of the outer canvas by scaling the coordinates of the relative image under rotation
202
+ */
203
+ getCoordinateUnderZoomByRotateFromImgPoint(point: ICoordinate): {
204
+ x: number;
205
+ y: number;
206
+ };
200
207
  getGetCenterCoordinate(): {
201
208
  x: number;
202
209
  y: number;
@@ -250,6 +257,11 @@ declare class BasicToolOperation extends EventListener {
250
257
  */
251
258
  zoomChangeOnCenter: (newZoom: number) => void;
252
259
  renderCursorLine(lineColor?: any): void;
260
+ drawStraightLine: (points: ICoordinate[], config: {
261
+ color: string;
262
+ lineWidth: number;
263
+ globalAlpha: number;
264
+ }) => void;
253
265
  drawImg: () => void;
254
266
  drawStaticImg: () => void;
255
267
  /**
@@ -1,8 +1,9 @@
1
1
  /**
2
2
  * 各类的数学运算
3
3
  */
4
- import { TAnnotationViewData } from '@labelbee/lb-utils';
4
+ import { I3DSpaceCoord, IPointCloudBox, TAnnotationViewData } from '@labelbee/lb-utils';
5
5
  import { IPolygonPoint } from '@/types/tool/polygon';
6
+ import { TIndexMap } from '@/core/pointCloud/cache';
6
7
  /**
7
8
  * 基础的三角运算
8
9
  */
@@ -11,6 +12,12 @@ export declare class Trigonometric {
11
12
  static sinAPlusB(sinA: number, cosA: number, sinB: number, cosB: number): number;
12
13
  static cosAPlusB(sinA: number, cosA: number, sinB: number, cosB: number): number;
13
14
  }
15
+ interface ICalculatePointsInsideBoxParams {
16
+ indexMap: TIndexMap;
17
+ polygon: IPolygonPoint[];
18
+ zScope: [number, number];
19
+ box: IPointCloudBox;
20
+ }
14
21
  export default class MathUtils {
15
22
  /**
16
23
  * 是否在指定范围内
@@ -176,4 +183,7 @@ export default class MathUtils {
176
183
  * @param newHeight
177
184
  */
178
185
  static getModifiedRectangleCoordinates(coordinates: ICoordinate[], newWidth: number, newHeight: number): ICoordinate[];
186
+ static calculatePointsInsideBox: (params: ICalculatePointsInsideBoxParams) => number;
187
+ static isPointInsideCube(point: I3DSpaceCoord, polygon: IPolygonPoint[], zScope: [number, number]): boolean;
179
188
  }
189
+ export {};
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var MathUtilsWorker=require("../_virtual/MathUtilsWorker.js"),tool=require("../constant/tool.js"),polygonTool=require("./tool/polygonTool.js"),PolygonUtils=require("./tool/PolygonUtils.js"),VectorUtils=require("./VectorUtils.js"),__defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnPropDescs=Object.getOwnPropertyDescriptors,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__pow=Math.pow,__defNormalProp=(e,t,o)=>t in e?__defProp(e,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[t]=o,__spreadValues=(e,t)=>{for(var o in t||(t={}))__hasOwnProp.call(t,o)&&__defNormalProp(e,o,t[o]);if(__getOwnPropSymbols)for(var o of __getOwnPropSymbols(t))__propIsEnum.call(t,o)&&__defNormalProp(e,o,t[o]);return e},__spreadProps=(e,t)=>__defProps(e,__getOwnPropDescs(t));class Trigonometric{static tanAPlusB(t,o){return(t+o)/(1-t*o)}static sinAPlusB(t,o,s,n){return n*t+o*s}static cosAPlusB(t,o,s,n){return o*n-t*s}}const _MathUtils=class{static getRotate(e){return e+90>=360?e+90-360:e+90}static getLineLength(e,t){return Math.sqrt(Math.pow(t.y-e.y,2)+Math.pow(t.x-e.x,2))}static getTextArea(e,t,o=tool.DEFAULT_TEXT_MAX_WIDTH,s=tool.DEFAULT_FONT,n){if(typeof t!="string")return{width:0,height:0};const i=e.getContext("2d");i.font=s;let r=0;typeof n=="undefined"&&(n=e&&parseInt(window.getComputedStyle(e).lineHeight,10)||parseInt(window.getComputedStyle(document.body).lineHeight,10));const a=e&&parseInt(window.getComputedStyle(e).fontSize,10)||parseInt(window.getComputedStyle(document.body).fontSize,10)||0,c=t.split(`
2
- `);let u=0;for(let l=0;l<c.length;l++){const f=c[l].split("");let p="";for(let h=0;h<f.length;h++){const y=p+f[h],g=i.measureText(y).width;g>o&&h>0?(p=f[h],r+=n,u=o):(p=y,g>u&&(u=g))}l!==c.length-1&&(r+=n)}return{width:u,height:r+a,lineHeight:n,fontHeight:a}}static getLineCenterPoint(e){const[t,o]=e,s=VectorUtils.getVector(t,o);return{x:t.x+s.x/2,y:t.y+s.y/2}}static getPerpendicularLine(e){if(e.length!==2)return;const[t,o]=e,s={x:o.x+o.y-t.y,y:o.y-(o.x-t.x)};return[o,s]}static getPerpendicularFootOfLine(e,t){if(e.length!==2)return e;const o=this.getPerpendicularLine(e);if(!o)return e;const[s,n]=o;return this.getFootOfPerpendicular(t,s,n).footPoint}static getQuadrangleFromTriangle(e){if(e.length!==3)return e;const[t,o,s]=e,n={x:s.x+t.x-o.x,y:s.y+t.y-o.y};return[t,o,s,n]}static getRectPerpendicularOffset(e,t,o){const[s,n]=o,i=this.getFootOfPerpendicular(e,s,n).footPoint,r=this.getFootOfPerpendicular(t,s,n).footPoint,a={x:i.x-r.x,y:i.y-r.y},c=VectorUtils.add(t,a);return VectorUtils.getVector(e,c)}static getArrayIndex(e,t){return e<0?t+e:e>=t?e-t:e}static getPointListFromPointOffset(e,t,o){const s=this.getArrayIndex(t-1,e.length),n=this.getArrayIndex(t+1,e.length),i=this.getArrayIndex(t-2,e.length),r=[...e];r[t]=VectorUtils.add(r[t],o);const a=this.getFootOfPerpendicular(r[t],r[i],r[s]).footPoint,c=this.getFootOfPerpendicular(r[t],r[n],r[i]).footPoint;return r[s]=a,r[n]=c,r}static getRectCenterPoint(e){const[t,,o]=e;return{x:(t.x+o.x)/2,y:(t.y+o.y)/2}}static rotateRectPointList(e=5,t){const o=this.getRectCenterPoint(t),{PI:s}=Math,n=Math.sin(e*s/180),i=Math.cos(e*s/180);return t.map(r=>{const a=VectorUtils.getVector(o,r),c=VectorUtils.len(a),u=a.y/c,l=a.x/c;return{x:c*Trigonometric.cosAPlusB(u,l,n,i)+o.x,y:c*Trigonometric.sinAPlusB(u,l,n,i)+o.y}})}static getRectangleByRightAngle(e,t){if(t.length!==2)return t;const o=_MathUtils.getPerpendicularFootOfLine(t,e);return _MathUtils.getQuadrangleFromTriangle([...t,o])}static getRadiusFromQuadrangle(e){const[,t,o]=e,s=o.y-t.y,n=t.x-o.x,i=this.getLineLength(t,o),r=s/i,a=Math.acos(r);return n>0?Math.PI*2-a:a}static getCollectionPointByAnnotationDataPromise(e){const t=e.filter(n=>n.type==="point").map(n=>n.annotation),o=e.filter(n=>!!["polygon","line"].includes(n.type)).map(n=>n.type==="polygon"?__spreadProps(__spreadValues({},n.annotation),{pointList:PolygonUtils.concatBeginAndEnd(n.annotation.pointList)}):n.annotation),s=new MathUtilsWorker;return{promise:new Promise(function(i){s.postMessage({points:t,backgroundList:o}),s.onmessage=r=>{i(r.data),s.terminate()}}),close:()=>{s.terminate()}}}static getCollectionPointByAnnotationData(e){const t=[],o=new Set,s=e.filter(r=>r.type==="point").map(r=>r.annotation),n=e.filter(r=>!!["polygon","line"].includes(r.type)).map(r=>r.type==="polygon"?__spreadProps(__spreadValues({},r.annotation),{pointList:PolygonUtils.concatBeginAndEnd(r.annotation.pointList)}):r.annotation),i=(r,a)=>{const{dropFoot:c}=PolygonUtils.getClosestPoint(r,a,tool.ELineTypes.Line,1,{isClose:!1});if(c!==r){const u=`${c.x} + ${c.y}`;o.has(u)||t.push(r),o.add(u)}};return s.forEach(r=>{i(r,n)}),n.forEach(r=>{let a="";a=r.id,n.forEach((c,u)=>{if(c.id===a)return;const l=[...n];l.splice(u,1),c.pointList.forEach(f=>{i(f,l)})})}),{connectionPoints:t}}static getModifiedRectangleCoordinates(e,t,o){if(e.length!==4)throw new Error("Invalid number of coordinates. Four coordinates are required.");const s=e[0],n=e[1],i=e[2],r=Math.sqrt(__pow(n.x-s.x,2)+__pow(n.y-s.y,2)),a=Math.sqrt(__pow(i.x-n.x,2)+__pow(i.y-n.y,2)),c=t/r,u=o/a,l={x:s.x+(n.x-s.x)*c,y:s.y+(n.y-s.y)*c},f={x:l.x+(i.x-n.x)*u,y:l.y+(i.y-n.y)*u},p={x:s.x+(f.x-n.x),y:s.y+(f.y-n.y)};return[s,l,f,p]}};let MathUtils=_MathUtils;MathUtils.isInRange=(e,t)=>{const o=Math.min(...t),s=Math.max(...t),n=r=>r<=s&&r>=o;return(Array.isArray(e)?e:[e]).every(r=>n(r))},MathUtils.withinRange=(e,t)=>{const o=Math.min(...t),s=Math.max(...t);return e>s?s:e<o?o:e},MathUtils.calcViewportBoundaries=(e,t=!1,o=tool.SEGMENT_NUMBER,s=1)=>{if(!e)return{top:0,bottom:0,left:0,right:0};const n=20/s,i=[],r=[];let a=e;t&&(a=polygonTool.createSmoothCurvePointsFromPointList(e,o)),a.forEach(({x:y,y:x})=>{i.push(y),r.push(x)});let c=Math.min(...i),u=Math.max(...i),l=Math.min(...r),f=Math.max(...r);const p=u-c,h=f-l;if(p<n){const y=(n-p)/2;c-=y,u+=y}if(h<n){const y=(n-h)/2;l-=y,f+=y}return{top:l,bottom:f,left:c,right:u}},MathUtils.getFootOfPerpendicular=(e,t,o,s=!1,n=!1)=>{let i={x:0,y:0};const r=t.x-o.x,a=t.y-o.y;if(Math.abs(r)<1e-8&&Math.abs(a)<1e-8)return i=t,i;let c=(e.x-t.x)*(t.x-o.x)+(e.y-t.y)*(t.y-o.y);c/=r*r+a*a,i.x=t.x+c*r,i.y=t.y+c*a;const u=_MathUtils.getLineLength(e,i),l=2,f=Math.min(t.x,o.x),p=Math.max(t.x,o.x),h=Math.min(t.y,o.y),y=Math.max(t.y,o.y),x=!(_MathUtils.isInRange(e.x,[f,p])||_MathUtils.isInRange(e.y,[h,y])),g=e.x>p+l||e.x<f-l||e.y>y+l||e.y<h-l;return!n&&(s?x:g)?{footPoint:i,length:Infinity}:{footPoint:i,length:u}};var MathUtils$1=MathUtils;exports.Trigonometric=Trigonometric,exports.default=MathUtils$1;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var MathUtilsWorker=require("../_virtual/MathUtilsWorker.js"),tool=require("../constant/tool.js"),polygonTool=require("./tool/polygonTool.js"),PolygonUtils=require("./tool/PolygonUtils.js"),VectorUtils=require("./VectorUtils.js"),__defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnPropDescs=Object.getOwnPropertyDescriptors,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__pow=Math.pow,__defNormalProp=(e,n,t)=>n in e?__defProp(e,n,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[n]=t,__spreadValues=(e,n)=>{for(var t in n||(n={}))__hasOwnProp.call(n,t)&&__defNormalProp(e,t,n[t]);if(__getOwnPropSymbols)for(var t of __getOwnPropSymbols(n))__propIsEnum.call(n,t)&&__defNormalProp(e,t,n[t]);return e},__spreadProps=(e,n)=>__defProps(e,__getOwnPropDescs(n));class Trigonometric{static tanAPlusB(n,t){return(n+t)/(1-n*t)}static sinAPlusB(n,t,i,o){return o*n+t*i}static cosAPlusB(n,t,i,o){return t*o-n*i}}var CubePosition;(function(e){e[e.Outside=0]="Outside",e[e.PartiallyInside=1]="PartiallyInside",e[e.FullyInside=2]="FullyInside"})(CubePosition||(CubePosition={}));function getCubePosition(e,n,t){const i=[{x:t.x-t.width/2,y:t.y-t.height/2,z:t.z-t.depth/2},{x:t.x+t.width/2,y:t.y-t.height/2,z:t.z-t.depth/2},{x:t.x-t.width/2,y:t.y+t.height/2,z:t.z-t.depth/2},{x:t.x+t.width/2,y:t.y+t.height/2,z:t.z-t.depth/2},{x:t.x-t.width/2,y:t.y-t.height/2,z:t.z+t.depth/2},{x:t.x+t.width/2,y:t.y-t.height/2,z:t.z+t.depth/2},{x:t.x-t.width/2,y:t.y+t.height/2,z:t.z+t.depth/2},{x:t.x+t.width/2,y:t.y+t.height/2,z:t.z+t.depth/2}];let o=0;for(let s=0;s<i.length;s++)MathUtils.isPointInsideCube(i[s],e,n)&&o++;return o===0?0:o===8?2:1}const _MathUtils=class{static getRotate(e){return e+90>=360?e+90-360:e+90}static getLineLength(e,n){return Math.sqrt(Math.pow(n.y-e.y,2)+Math.pow(n.x-e.x,2))}static getTextArea(e,n,t=tool.DEFAULT_TEXT_MAX_WIDTH,i=tool.DEFAULT_FONT,o){if(typeof n!="string")return{width:0,height:0};const s=e.getContext("2d");s.font=i;let r=0;typeof o=="undefined"&&(o=e&&parseInt(window.getComputedStyle(e).lineHeight,10)||parseInt(window.getComputedStyle(document.body).lineHeight,10));const a=e&&parseInt(window.getComputedStyle(e).fontSize,10)||parseInt(window.getComputedStyle(document.body).fontSize,10)||0,c=n.split(`
2
+ `);let y=0;for(let h=0;h<c.length;h++){const f=c[h].split("");let g="";for(let d=0;d<f.length;d++){const x=g+f[d],p=s.measureText(x).width;p>t&&d>0?(g=f[d],r+=o,y=t):(g=x,p>y&&(y=p))}h!==c.length-1&&(r+=o)}return{width:y,height:r+a,lineHeight:o,fontHeight:a}}static getLineCenterPoint(e){const[n,t]=e,i=VectorUtils.getVector(n,t);return{x:n.x+i.x/2,y:n.y+i.y/2}}static getPerpendicularLine(e){if(e.length!==2)return;const[n,t]=e,i={x:t.x+t.y-n.y,y:t.y-(t.x-n.x)};return[t,i]}static getPerpendicularFootOfLine(e,n){if(e.length!==2)return e;const t=this.getPerpendicularLine(e);if(!t)return e;const[i,o]=t;return this.getFootOfPerpendicular(n,i,o).footPoint}static getQuadrangleFromTriangle(e){if(e.length!==3)return e;const[n,t,i]=e,o={x:i.x+n.x-t.x,y:i.y+n.y-t.y};return[n,t,i,o]}static getRectPerpendicularOffset(e,n,t){const[i,o]=t,s=this.getFootOfPerpendicular(e,i,o).footPoint,r=this.getFootOfPerpendicular(n,i,o).footPoint,a={x:s.x-r.x,y:s.y-r.y},c=VectorUtils.add(n,a);return VectorUtils.getVector(e,c)}static getArrayIndex(e,n){return e<0?n+e:e>=n?e-n:e}static getPointListFromPointOffset(e,n,t){const i=this.getArrayIndex(n-1,e.length),o=this.getArrayIndex(n+1,e.length),s=this.getArrayIndex(n-2,e.length),r=[...e];r[n]=VectorUtils.add(r[n],t);const a=this.getFootOfPerpendicular(r[n],r[s],r[i]).footPoint,c=this.getFootOfPerpendicular(r[n],r[o],r[s]).footPoint;return r[i]=a,r[o]=c,r}static getRectCenterPoint(e){const[n,,t]=e;return{x:(n.x+t.x)/2,y:(n.y+t.y)/2}}static rotateRectPointList(e=5,n){const t=this.getRectCenterPoint(n),{PI:i}=Math,o=Math.sin(e*i/180),s=Math.cos(e*i/180);return n.map(r=>{const a=VectorUtils.getVector(t,r),c=VectorUtils.len(a),y=a.y/c,h=a.x/c;return{x:c*Trigonometric.cosAPlusB(y,h,o,s)+t.x,y:c*Trigonometric.sinAPlusB(y,h,o,s)+t.y}})}static getRectangleByRightAngle(e,n){if(n.length!==2)return n;const t=_MathUtils.getPerpendicularFootOfLine(n,e);return _MathUtils.getQuadrangleFromTriangle([...n,t])}static getRadiusFromQuadrangle(e){const[,n,t]=e,i=t.y-n.y,o=n.x-t.x,s=this.getLineLength(n,t),r=i/s,a=Math.acos(r);return o>0?Math.PI*2-a:a}static getCollectionPointByAnnotationDataPromise(e){const n=e.filter(o=>o.type==="point").map(o=>o.annotation),t=e.filter(o=>!!["polygon","line"].includes(o.type)).map(o=>o.type==="polygon"?__spreadProps(__spreadValues({},o.annotation),{pointList:PolygonUtils.concatBeginAndEnd(o.annotation.pointList)}):o.annotation),i=new MathUtilsWorker;return{promise:new Promise(function(s){i.postMessage({points:n,backgroundList:t}),i.onmessage=r=>{s(r.data),i.terminate()}}),close:()=>{i.terminate()}}}static getCollectionPointByAnnotationData(e){const n=[],t=new Set,i=e.filter(r=>r.type==="point").map(r=>r.annotation),o=e.filter(r=>!!["polygon","line"].includes(r.type)).map(r=>r.type==="polygon"?__spreadProps(__spreadValues({},r.annotation),{pointList:PolygonUtils.concatBeginAndEnd(r.annotation.pointList)}):r.annotation),s=(r,a)=>{const{dropFoot:c}=PolygonUtils.getClosestPoint(r,a,tool.ELineTypes.Line,1,{isClose:!1});if(c!==r){const y=`${c.x} + ${c.y}`;t.has(y)||n.push(r),t.add(y)}};return i.forEach(r=>{s(r,o)}),o.forEach(r=>{let a="";a=r.id,o.forEach((c,y)=>{if(c.id===a)return;const h=[...o];h.splice(y,1),c.pointList.forEach(f=>{s(f,h)})})}),{connectionPoints:n}}static getModifiedRectangleCoordinates(e,n,t){if(e.length!==4)throw new Error("Invalid number of coordinates. Four coordinates are required.");const i=e[0],o=e[1],s=e[2],r=Math.sqrt(__pow(o.x-i.x,2)+__pow(o.y-i.y,2)),a=Math.sqrt(__pow(s.x-o.x,2)+__pow(s.y-o.y,2)),c=n/r,y=t/a,h={x:i.x+(o.x-i.x)*c,y:i.y+(o.y-i.y)*c},f={x:h.x+(s.x-o.x)*y,y:h.y+(s.y-o.y)*y},g={x:i.x+(f.x-o.x),y:i.y+(f.y-o.y)};return[i,h,f,g]}static isPointInsideCube(e,n,t){const[i,o]=t;return!!(polygonTool.isInPolygon({x:e.x,y:e.y},n)&&e.z>=i&&e.z<=o)}};let MathUtils=_MathUtils;MathUtils.isInRange=(e,n)=>{const t=Math.min(...n),i=Math.max(...n),o=r=>r<=i&&r>=t;return(Array.isArray(e)?e:[e]).every(r=>o(r))},MathUtils.withinRange=(e,n)=>{const t=Math.min(...n),i=Math.max(...n);return e>i?i:e<t?t:e},MathUtils.calcViewportBoundaries=(e,n=!1,t=tool.SEGMENT_NUMBER,i=1)=>{if(!e)return{top:0,bottom:0,left:0,right:0};const o=20/i,s=[],r=[];let a=e;n&&(a=polygonTool.createSmoothCurvePointsFromPointList(e,t)),a.forEach(({x,y:u})=>{s.push(x),r.push(u)});let c=Math.min(...s),y=Math.max(...s),h=Math.min(...r),f=Math.max(...r);const g=y-c,d=f-h;if(g<o){const x=(o-g)/2;c-=x,y+=x}if(d<o){const x=(o-d)/2;h-=x,f+=x}return{top:h,bottom:f,left:c,right:y}},MathUtils.getFootOfPerpendicular=(e,n,t,i=!1,o=!1)=>{let s={x:0,y:0};const r=n.x-t.x,a=n.y-t.y;if(Math.abs(r)<1e-8&&Math.abs(a)<1e-8)return s=n,s;let c=(e.x-n.x)*(n.x-t.x)+(e.y-n.y)*(n.y-t.y);c/=r*r+a*a,s.x=n.x+c*r,s.y=n.y+c*a;const y=_MathUtils.getLineLength(e,s),h=2,f=Math.min(n.x,t.x),g=Math.max(n.x,t.x),d=Math.min(n.y,t.y),x=Math.max(n.y,t.y),u=!(_MathUtils.isInRange(e.x,[f,g])||_MathUtils.isInRange(e.y,[d,x])),p=e.x>g+h||e.x<f-h||e.y>x+h||e.y<d-h;return!o&&(i?u:p)?{footPoint:s,length:Infinity}:{footPoint:s,length:y}},MathUtils.calculatePointsInsideBox=e=>{const{indexMap:n,polygon:t,zScope:i,box:o}=e;let s=0;return n.forEach((r,a)=>{const c=a.split("@"),y=Number(c[0]),h=Number(c[1]),f=Number(c[2]),g={x:y-.5,y:h-.5,z:f-.5,width:1,height:1,depth:1},d=getCubePosition(t,i,g);d===2&&(s+=r.length),(d===1||d===0&&(o.width<=1||o.height<=1))&&r.forEach(x=>{_MathUtils.isPointInsideCube(x,t,i)&&s++})}),s};var MathUtils$1=MathUtils;exports.Trigonometric=Trigonometric,exports.default=MathUtils$1;
@@ -0,0 +1 @@
1
+ import{createBase64WorkerFactory as e}from"./_rollup-plugin-web-worker-loader__helper__browser__createBase64WorkerFactory.js";var l=e("Lyogcm9sbHVwLXBsdWdpbi13ZWItd29ya2VyLWxvYWRlciAqLwooZnVuY3Rpb24oKXsidXNlIHN0cmljdCI7b25tZXNzYWdlPWZ1bmN0aW9uKGkpe2NvbnN0e3BvaW50czpzfT1pLmRhdGEsZT1uZXcgTWFwO2ZvcihsZXQgdD0wO3Q8cy5sZW5ndGg7dCs9Myl7Y29uc3Qgbz1zW3RdLGM9c1t0KzFdLGE9c1t0KzJdLG49YCR7TWF0aC5jZWlsKG8pfUAke01hdGguY2VpbChjKX1AJHtNYXRoLmNlaWwoYSl9YDtlLmhhcyhuKXx8ZS5zZXQobixbXSksZS5nZXQobikucHVzaCh7eDpvLHk6Yyx6OmF9KX10aGlzLnBvc3RNZXNzYWdlKHtpbmRleE1hcDplfSl9fSkoKTsKCg==",null,!1);export{l as default};
@@ -1 +1 @@
1
- import{PCDLoader as r}from"./PCDLoader.js";class e{constructor(){this.MAX_SIZE=50,this.cacheList=[],this.loadPCDFile=t=>new Promise((s,c)=>{const o=this.pointsMap.get(t),a=this.colorMap.get(t);if(o&&a){s({points:o,color:a});return}if(this.cacheList.length>this.MAX_SIZE){const i=this.cacheList.shift();i&&this.pointsMap.delete(i.src)}this.cacheList.push({src:t}),this.pcdLoader.load(t,i=>{const h=i.geometry.attributes.position.array,n=i.geometry.attributes.color.array;this.pointsMap.set(t,h),this.colorMap.set(t,n),s({points:h,color:n})},()=>{},i=>{c(i)})}),this.pcdLoader=new r,this.pointsMap=new Map,this.colorMap=new Map,this.cache2DHighlightIndex=new Map}static getInstance(){return this.instance==null&&(this.instance=new e),this.instance}updateColor(t,s){this.colorMap.set(t,s)}clearCache2DHighlightIndex(){this.cache2DHighlightIndex.clear()}}export{e as PointCloudCache};
1
+ import l from"../../_virtual/generateIndexWorker.js";import{PCDLoader as d}from"./PCDLoader.js";var M=(p,t,i)=>new Promise((r,n)=>{var o=e=>{try{a(i.next(e))}catch(c){n(c)}},s=e=>{try{a(i.throw(e))}catch(c){n(c)}},a=e=>e.done?r(e.value):Promise.resolve(e.value).then(o,s);a((i=i.apply(p,t)).next())});class h{constructor(){this.MAX_SIZE=50,this.cacheList=[],this.loadPCDFile=t=>new Promise((i,r)=>{const n=this.pointsMap.get(t),o=this.colorMap.get(t);if(n&&o){i({points:n,color:o});return}if(this.cacheList.length>this.MAX_SIZE){const s=this.cacheList.shift();s&&this.pointsMap.delete(s.src)}this.cacheList.push({src:t}),this.pcdLoader.load(t,s=>{const a=s.geometry.attributes.position.array,e=s.geometry.attributes.color.array;this.pointsMap.set(t,a),this.colorMap.set(t,e),i({points:a,color:e})},()=>{},s=>{r(s)})}),this.loadIndexMap=(t,i)=>M(this,null,function*(){const r=this.cacheIndexMap.get(t);return new Promise(n=>{if(r)return n(r);if(window.Worker){const o=new l({type:"module"});o.postMessage({points:i}),o.onmessage=s=>{const{indexMap:a}=s.data;if(this.cacheIndexMap.set(t,a),this.cacheIndexMap.size>this.MAX_SIZE){const e=Array.from(this.cacheIndexMap.keys())[0];this.cacheIndexMap.delete(e)}n(a),o.terminate()}}})}),this.pcdLoader=new d,this.pointsMap=new Map,this.colorMap=new Map,this.cacheIndexMap=new Map,this.cache2DHighlightIndex=new Map}static getInstance(){return this.instance==null&&(this.instance=new h),this.instance}updateColor(t,i){this.colorMap.set(t,i)}clearCache2DHighlightIndex(){this.cache2DHighlightIndex.clear()}}export{h as PointCloudCache};
@@ -1,4 +1,4 @@
1
- import*as a from"three";import{toolStyleConverter as T,PerspectiveShiftUtils as v,EPerspectiveView as C,PointCloudUtils as F,DEFAULT_SPHERE_PARAMS as O}from"@labelbee/lb-utils";import E from"../../_virtual/highlightWorker.js";import V from"../../_virtual/filterBoxWorker.js";import{isInPolygon as R}from"../../utils/tool/polygonTool.js";import I from"../../utils/uuid.js";import H from"../../utils/MathUtils.js";import W from"../../utils/ImgUtils.js";import{PCDLoader as Z}from"./PCDLoader.js";import{OrbitControls as U}from"./OrbitControls.js";import{PointCloudCache as G}from"./cache.js";import{getCuboidFromPointCloudBox as A,getHighlightIndexByPoints as $,mergeHighlightList as Y}from"./matrix.js";export{createThreeMatrix4,getCuboidFromPointCloudBox,getHighlightIndexByPoints,isFisheyeCalibValid,isInImage,isMatrixValid,isMatrixValidByArr,lidar2FisheyeImage,lidar2image,mergeHighlightList,oCamFisheyeTransfer,point3DLidar2Image,pointCloudLidar2image,pointListLidar2Img,pointMappingLidar2image,rotatePoint,transferKitti2Matrix}from"./matrix.js";import{PointCloudSegmentOperation as X}from"./segmentation.js";import q from"./store/index.js";import K from"./render/index.js";import Q from"../toolOperation/eventListener.js";import"../../constant/tool.js";import"../scheduler.js";var J=Object.defineProperty,tt=Object.defineProperties,et=Object.getOwnPropertyDescriptors,j=Object.getOwnPropertySymbols,it=Object.prototype.hasOwnProperty,rt=Object.prototype.propertyIsEnumerable,L=(w,t,e)=>t in w?J(w,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):w[t]=e,b=(w,t)=>{for(var e in t||(t={}))it.call(t,e)&&L(w,e,t[e]);if(j)for(var e of j(t))rt.call(t,e)&&L(w,e,t[e]);return w},B=(w,t)=>tt(w,et(t)),z=(w,t,e)=>new Promise((i,r)=>{var s=d=>{try{o(e.next(d))}catch(n){r(n)}},h=d=>{try{o(e.throw(d))}catch(n){r(n)}},o=d=>d.done?i(d.value):Promise.resolve(d.value).then(s,h);o((e=e.apply(w,t)).next())});const nt=30,k=new E({type:"module"});class ot extends Q{constructor({container:t,noAppend:e,isOrthographicCamera:i,orthographicParams:r,backgroundColor:s="#4C4C4C",config:h,isSegment:o,checkMode:d}){super();this.zAxisLimit=10,this.initCameraPosition=this.DEFAULT_INIT_CAMERA_POSITION,this.isOrthographicCamera=!1,this.pointsUuid="",this.pointCloudObjectName="pointCloud",this.rangeObjectName="range",this.highlightGroupName="highlightBoxes",this.showDirection=!0,this.pointsMaterialSize=1,this.isSegment=!1,this.checkMode=!1,this.nextTick=()=>{!this.segmentOperation||this.segmentOperation._raycasting()},this.keydown=n=>{if(!!this.store)switch(n.key){case" ":this.controls.enablePan=!0,this.store.setForbidOperation(!0);break}},this.keyup=n=>{if(!!this.store)switch(n.key){case" ":this.controls.enablePan=!1,this.store.setForbidOperation(!1);break}},this.addSphereToSense=(n,l="blue")=>{var c;const m=(c=n.id)!=null?c:I();this.removeObjectByName(m,"sphere");const{radius:u,widthSegments:f,heightSegments:p}=O,{center:g}=n,y=new a.Group,x=new a.SphereGeometry(u,f,p),M=new a.MeshBasicMaterial({color:l}),P=new a.Mesh(x,M);P.position.set(g.x,g.y,g.z),y.add(P),y.name=`sphere${m}`,this.scene.add(y)},this.generateSphere=n=>{const{fill:l}=this.getColorFromConfig(n.attribute);this.addSphereToSense(n,l),this.render()},this.generateSpheres=n=>{n.forEach(l=>{const{fill:c}=this.getColorFromConfig(l.attribute);this.addSphereToSense(l,c)}),this.render()},this.addBoxToSense=(n,l=16777215)=>{var c;const m=(c=n.id)!=null?c:I();this.removeObjectByName(m,"box");const{center:u,width:f,height:p,depth:g,rotation:y}=n,x=new a.Group,M=new a.BoxGeometry(f,p,g),P=new a.MeshBasicMaterial({color:"blue"}),S=new a.Mesh(M,P),_=new a.BoxHelper(S,l),N=this.generateBoxArrow(n),D=this.generateBoxTrackID(n);D&&x.add(D),x.add(_),x.add(N),u&&x.position.set(u.x,u.y,u.z),y&&x.rotation.set(0,0,y),x.name=`box${m}`,this.scene.add(x)},this.applyCameraTarget=n=>{if(this.camera.type==="OrthographicCamera"&&n){const l=this.getOrthographicCameraTarget(n);this.updateCameraZoom(n.zoom),this.updateCamera(n.position,l)}},this.initShaderMaterial=()=>({vertexShader:`
1
+ import*as a from"three";import{toolStyleConverter as T,PerspectiveShiftUtils as B,EPerspectiveView as C,PointCloudUtils as E,DEFAULT_SPHERE_PARAMS as O}from"@labelbee/lb-utils";import V from"../../_virtual/highlightWorker.js";import R from"../../_virtual/filterBoxWorker.js";import{isInPolygon as H}from"../../utils/tool/polygonTool.js";import A from"../../utils/uuid.js";import L from"../../utils/MathUtils.js";import W from"../../utils/ImgUtils.js";import{PCDLoader as Z}from"./PCDLoader.js";import{OrbitControls as U}from"./OrbitControls.js";import{PointCloudCache as G}from"./cache.js";import{getCuboidFromPointCloudBox as D,getHighlightIndexByPoints as $,mergeHighlightList as Y}from"./matrix.js";export{createThreeMatrix4,getCuboidFromPointCloudBox,getHighlightIndexByPoints,isFisheyeCalibValid,isInImage,isMatrixValid,isMatrixValidByArr,lidar2FisheyeImage,lidar2image,mergeHighlightList,oCamFisheyeTransfer,point3DLidar2Image,pointCloudLidar2image,pointListLidar2Img,pointMappingLidar2image,rotatePoint,transferKitti2Matrix}from"./matrix.js";import{PointCloudSegmentOperation as X}from"./segmentation.js";import q from"./store/index.js";import K from"./render/index.js";import Q from"../toolOperation/eventListener.js";import"../../constant/tool.js";import"../scheduler.js";var J=Object.defineProperty,tt=Object.defineProperties,et=Object.getOwnPropertyDescriptors,j=Object.getOwnPropertySymbols,it=Object.prototype.hasOwnProperty,rt=Object.prototype.propertyIsEnumerable,k=(w,t,e)=>t in w?J(w,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):w[t]=e,b=(w,t)=>{for(var e in t||(t={}))it.call(t,e)&&k(w,e,t[e]);if(j)for(var e of j(t))rt.call(t,e)&&k(w,e,t[e]);return w},P=(w,t)=>tt(w,et(t)),S=(w,t,e)=>new Promise((i,r)=>{var s=d=>{try{o(e.next(d))}catch(n){r(n)}},c=d=>{try{o(e.throw(d))}catch(n){r(n)}},o=d=>d.done?i(d.value):Promise.resolve(d.value).then(s,c);o((e=e.apply(w,t)).next())});const nt=30,_=new V({type:"module"});class ot extends Q{constructor({container:t,noAppend:e,isOrthographicCamera:i,orthographicParams:r,backgroundColor:s="#4C4C4C",config:c,isSegment:o,checkMode:d}){super();this.zAxisLimit=10,this.initCameraPosition=this.DEFAULT_INIT_CAMERA_POSITION,this.isOrthographicCamera=!1,this.pointsUuid="",this.pointCloudObjectName="pointCloud",this.rangeObjectName="range",this.highlightGroupName="highlightBoxes",this.showDirection=!0,this.pointsMaterialSize=1,this.isSegment=!1,this.checkMode=!1,this.nextTick=()=>{!this.segmentOperation||this.segmentOperation._raycasting()},this.keydown=n=>{if(!!this.store)switch(n.key){case" ":this.controls.enablePan=!0,this.store.setForbidOperation(!0);break}},this.keyup=n=>{if(!!this.store)switch(n.key){case" ":this.controls.enablePan=!1,this.store.setForbidOperation(!1);break}},this.addSphereToSense=(n,l="blue")=>{var h;const u=(h=n.id)!=null?h:A();this.removeObjectByName(u,"sphere");const{radius:m,widthSegments:f,heightSegments:p}=O,{center:g}=n,x=new a.Group,y=new a.SphereGeometry(m,f,p),M=new a.MeshBasicMaterial({color:l}),v=new a.Mesh(y,M);v.position.set(g.x,g.y,g.z),x.add(v),x.name=`sphere${u}`,this.scene.add(x)},this.generateSphere=n=>{const{fill:l}=this.getColorFromConfig(n.attribute);this.addSphereToSense(n,l),this.render()},this.generateSpheres=n=>{n.forEach(l=>{const{fill:h}=this.getColorFromConfig(l.attribute);this.addSphereToSense(l,h)}),this.render()},this.addBoxToSense=(n,l=16777215)=>{var h;const u=(h=n.id)!=null?h:A();this.removeObjectByName(u,"box");const{center:m,width:f,height:p,depth:g,rotation:x}=n,y=new a.Group,M=new a.BoxGeometry(f,p,g),v=new a.MeshBasicMaterial({color:"blue"}),z=new a.Mesh(M,v),N=new a.BoxHelper(z,l),F=this.generateBoxArrow(n),I=this.generateBoxTrackID(n);I&&y.add(I),y.add(N),y.add(F),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=n=>{if(this.camera.type==="OrthographicCamera"&&n){const l=this.getOrthographicCameraTarget(n);this.updateCameraZoom(n.zoom),this.updateCamera(n.position,l)}},this.initShaderMaterial=()=>({vertexShader:`
2
2
  attribute vec3 dimensions;
3
3
  varying vec3 vDimensions;
4
4
  uniform float pointSize;
@@ -28,4 +28,4 @@ import*as a from"three";import{toolStyleConverter as T,PerspectiveShiftUtils as
28
28
 
29
29
  // Output the final color
30
30
  gl_FragColor = vec4(color, 1.0);
31
- }`,uniforms:{pointSize:{value:this.pointsMaterialSize}}}),this.loadPCDFile=(...n)=>z(this,[...n],function*(l=this.currentPCDSrc,c){if(!l)return;this.clearPointCloud(),this.cacheInstance.clearCache2DHighlightIndex(),this.currentPCDSrc=l;const{points:m,color:u}=yield this.cacheInstance.loadPCDFile(l),f=new a.BufferGeometry;f.setAttribute("position",new a.BufferAttribute(m,3)),this.isSegment||f.setAttribute("dimensions",new a.BufferAttribute(u,3)),this.initCloudData(m);const p=new a.Points(f);this.renderPointCloud(p,c),this.emit("loadPCDFileEnd")}),this.getHighlightIndexByMappingImgList=n=>z(this,[n],function*({mappingImgList:l,points:c}){const m=l.length===0?[]:yield Promise.all(l.map(p=>W.load(p.url))),u=l.map((p,g)=>{var y;if(this.cacheInstance.cache2DHighlightIndex.has(p.url))return(y=this.cacheInstance.cache2DHighlightIndex.get(p.url))!=null?y:[];const x=$({points:c,calib:p.calib,width:m[g].width,height:m[g].height});return this.cacheInstance.cache2DHighlightIndex.set(p.url,x),x});return Y(u)}),this.loadPCDFileByBox=(n,l,c)=>z(this,null,function*(){const m=(p,g)=>z(this,null,function*(){const{width:y=0,height:x=0,depth:M=0}=c!=null?c:{},P=yield this.filterPointsByBox(B(b({},l),{width:l.width+y,height:l.height+x,depth:l.depth+M}),p,g);if(!P){console.error("filter Error");return}this.clearPointCloud(),this.currentPCDSrc=n;const S=new a.Points(P.geometry);S.name=this.pointCloudObjectName,this.scene.add(S),this.render()}),{points:u,color:f}=yield this.cacheInstance.loadPCDFile(n);m(u,f)}),this.generateRange=n=>{const l=this.createRange(n);this.scene.add(l)},this.generateBoxArrow=({width:n})=>{const l=new a.Vector3(1,0,0),c=new a.Vector3(n/2,0,0),m=2,u=16776960,f=new a.ArrowHelper(l,c,m,u);return f.visible=this.showDirection,f},this.generateBoxTrackID=n=>{if(!n.trackID)return;const l=new a.Texture(this.getTextCanvas(n.trackID.toString()));l.needsUpdate=!0;const c=new a.SpriteMaterial({map:l,depthWrite:!1}),m=new a.Sprite(c);return m.scale.set(5,5,5),m.position.set(-n.width/2,0,n.depth/2+.5),m},this.applyZAxisPoints=n=>{this.zAxisLimit=n,this.filterZAxisPoints(),this.render()},this.updatePointSize=({zoomIn:n,customSize:l})=>{const c=this.scene.getObjectByName(this.pointCloudObjectName);if(!c)return;const m=c.material.uniforms.pointSize.value;n?c.material.uniforms.pointSize.value=Math.min(m*1.2,10):c.material.uniforms.pointSize.value=Math.max(m/1.2,1),l&&(c.material.uniforms.pointSize.value=l,this.pointsMaterialSize=l),c.material.uniformsNeedUpdate=!0,this.render()},this.container=t,this.renderer=new a.WebGLRenderer({antialias:!0}),this.backgroundColor=s,this.config=h,this.checkMode=d!=null?d:!1,i&&r?(this.isOrthographicCamera=!0,this.camera=new a.OrthographicCamera(r.left,r.right,r.top,r.bottom,r.near,r.far)):this.camera=new a.PerspectiveCamera(30,this.containerWidth/this.containerHeight,1,1e3),this.initCamera(),this.scene=new a.Scene,this.controls=new U(this.camera,o?this.container:this.renderer.domElement),this.pcdLoader=new Z,this.axesHelper=new a.AxesHelper(1e3),this.scene.add(this.camera),e||t.appendChild(this.renderer.domElement),this.init(),this.cacheInstance=G.getInstance(),o===!0&&(this.initSegment(),this.isSegment=!0)}initSegment(){this.store=new q(this.pointCloudDelegate),this.controls.enablePan=!1,this.controls.addEventListener("start",this.orbiterStart.bind(this)),this.controls.addEventListener("change",this.orbiterChange.bind(this)),this.controls.addEventListener("end",this.orbiterEnd.bind(this)),this.segmentOperation=new X(b({dom:this.container,store:this.store},this.eventBus)),this.pointCloudRender=new K(B(b({store:this.store},this.eventBus),{nextTick:this.nextTick})),this.initMsg(),document.addEventListener("keydown",this.keydown),document.addEventListener("keyup",this.keyup)}orbiterStart(){}orbiterChange(){!this.store||(this.store.orbiting=!0)}orbiterEnd(){!this.store||(this.store.orbiting=!1)}get currentSegmentTool(){var t;return(t=this.segmentOperation)==null?void 0:t.currentToolName}get pointCloudObject(){return this.scene.getObjectByName(this.pointCloudObjectName)}initMsg(){!this.segmentOperation||(this.on("CircleSelector",this.segmentOperation.updateSelector2Circle.bind(this.segmentOperation)),this.on("LassoSelector",this.segmentOperation.updateSelector2Lasso.bind(this.segmentOperation)),this.on("RectSelector",this.segmentOperation.updateSelector2Rect.bind(this.segmentOperation)),this.on("clearPointCloud",this.clearPointCloud.bind(this)),this.on("loadPCDFile",this.loadPCDFile.bind(this)))}unbindMsg(){!this.segmentOperation||(this.unbind("CircleSelector",this.segmentOperation.updateSelector2Circle.bind(this.segmentOperation)),this.unbind("LassoSelector",this.segmentOperation.updateSelector2Lasso.bind(this.segmentOperation)),this.unbind("RectSelector",this.segmentOperation.updateSelector2Rect.bind(this.segmentOperation)),this.unbind("clearPointCloud",this.clearPointCloud.bind(this)),this.unbind("loadPCDFile",this.loadPCDFile.bind(this)))}get eventBus(){return{on:this.on.bind(this),emit:this.emit.bind(this),unbind:this.unbind.bind(this)}}get pointCloudDelegate(){return b({container:this.container,scene:this.scene,camera:this.camera,renderer:this.renderer,checkMode:this.checkMode,config:this.config},this.eventBus)}get DEFAULT_INIT_CAMERA_POSITION(){return new a.Vector3(-.01,0,1e3)}get containerWidth(){return this.container.clientWidth}get containerHeight(){return this.container.clientHeight}setInitCameraPosition(t){this.initCameraPosition=t}setConfig(t){var e;this.config=t,(e=this.store)==null||e.setConfig(t)}initOrthographicCamera(t){if(this.camera.type!=="OrthographicCamera")return;const{left:e,right:i,top:r,bottom:s,near:h,far:o}=t;this.camera.left=e,this.camera.right=i,this.camera.top=r,this.camera.bottom=s,this.camera.near=h,this.camera.far=o,this.camera.updateProjectionMatrix()}initPerspectiveCamera(){this.camera.type==="PerspectiveCamera"&&(this.camera.fov=30,this.camera.aspect=this.containerWidth/this.containerHeight,this.camera.near=1,this.camera.far=1e3,this.camera.updateProjectionMatrix())}initCamera(){const{camera:t}=this;if(this.isOrthographicCamera){const{x:e,y:i,z:r}=this.initCameraPosition;t.position.set(e,i,r)}else t.position.set(-1,0,500);t.up.set(0,0,1)}initControls(){const{controls:t}=this;t.addEventListener("change",()=>{this.render()}),this.setDefaultControls()}setDefaultControls(){const{controls:t}=this,e=[0,0,0];t.target=new a.Vector3(...e),t.addEventListener("change",()=>{this.render()}),t.maxPolarAngle=Math.PI/2,t.update()}initRenderer(){const{renderer:t}=this;t.setPixelRatio(window.devicePixelRatio),t.setSize(this.containerWidth,this.containerHeight)}init(){const{scene:t}=this;t.background=new a.Color(this.backgroundColor),this.initControls(),this.initRenderer()}removeObjectByName(t,e=""){const i=this.scene.getObjectByName(e+t);i&&i.removeFromParent()}getColorFromConfig(t){return T.getColorFromConfig({attribute:t},B(b({},this.config),{attributeConfigurable:!0}),{})}generateBox(t,e=16777215){const i=e;this.addBoxToSense(t,i),this.render()}getAllAttributeColor(t){return t.reduce((e,i)=>(e[i.attribute]=this.getColorFromConfig(i.attribute),e),{})}generateBoxes(t){t.forEach(e=>{this.addBoxToSense(e)}),this.render()}getOrthographicCamera(t){const{center:e,width:i,height:r}=t,s=10,h=e.x-i/2-s,o=e.x-i/2+s,d=e.y+r/2+s,n=e.y-r/2-s,l=100,c=-100,m=500/l;return{left:h,right:o,top:d,bottom:n,near:l,far:c,zoom:m}}updateCameraZoom(t){this.camera.zoom=t,this.camera.updateProjectionMatrix()}updateCameraByBox(t,e,i){const{center:r,width:s,height:h,depth:o,rotation:d}=t,n=this.getCameraVector(r,d,{width:s,height:h,depth:o},e);return i?(this.updateCamera(i,r),new a.Vector3(i.x,i.y,i.z)):(this.updateCamera(n,r),n)}updateCameraBySphere(t,e){const{center:i}=t,{radius:r}=O,s=this.getCameraVector(i,0,{width:r*2,height:r*2,depth:r*2},e);return this.updateCamera(s,i),s}updateOrthoCamera(t,e){const i=this.updateCameraByBox(t,e);return this.camera.zoom=1,this.camera.updateProjectionMatrix(),{cameraPositionVector:i}}updateOrthoCameraBySphere(t,e){const i=this.updateCameraBySphere(t,e);return this.camera.zoom=1,this.camera.updateProjectionMatrix(),{cameraPositionVector:i}}updateTopCamera(){this.setInitCameraPosition(this.DEFAULT_INIT_CAMERA_POSITION),this.camera.zoom=1,this.initCamera(),this.setDefaultControls(),this.camera.updateProjectionMatrix(),this.render()}updateCamera(t,e){this.camera.position.set(t.x,t.y,t.z),this.controls.target=new a.Vector3(e.x,e.y,e.z),this.controls.update()}resetCamera(){this.updateCamera(this.DEFAULT_INIT_CAMERA_POSITION,{x:0,y:0,z:0})}getOrthographicCameraTarget(t){const e=new a.Vector3(0,0,-1).applyQuaternion(t.quaternion);return t.position.clone().add(e)}createThreeMatrix4(t){return new a.Matrix4().set(...t)}filterPointsByBox(t,e,i){var r,s,h;if(!e){const o=this.scene.getObjectByName(this.pointCloudObjectName);if(!o)return console.error("There is no corresponding point cloud object"),Promise.resolve(void 0);e=(h=(s=(r=o==null?void 0:o.geometry)==null?void 0:r.attributes)==null?void 0:s.position)==null?void 0:h.array}if(window.Worker){const{zMin:o,zMax:d,polygonPointList:n}=A(t),l=e;i=i!=null?i:new Float32Array([]);const c={boxParams:t,zMin:o,zMax:d,polygonPointList:n,color:i,position:l};return new Promise(m=>{const u=new V;u.postMessage(c),u.onmessage=f=>{const{color:p,position:g,num:y}=f.data,x=new a.BufferGeometry;x.setAttribute("position",new a.Float32BufferAttribute(g,3)),x.setAttribute("color",new a.Float32BufferAttribute(p,3)),x.computeBoundingSphere(),u.terminate(),m({geometry:x,num:y})}})}return Promise.resolve(void 0)}getCameraVector(t,e,i,r=C.Front,s=nt){let h=v.frontViewMatrix4(s);switch(r){case C.Front:break;case C.Back:h=v.backViewMatrix4(s);break;case C.Left:h=v.leftViewMatrix4(s);break;case C.Right:h=v.rightViewMatrix4(s);break;case C.Top:h=v.topViewMatrix4(s);break;case C.LFT:h=v.leftFrontTopViewMatrix4(s,i);break;case C.RBT:h=v.rightBackTopViewMatrix4(s,i);break}const o=this.createThreeMatrix4(h),d=new a.Matrix4().makeTranslation(-t.x,-t.y,-t.z),n=new a.Matrix4().makeTranslation(t.x,t.y,t.z),l=new a.Matrix4().makeRotationZ(e);return new a.Vector3(t.x,t.y,t.z).clone().applyMatrix4(o).applyMatrix4(d).applyMatrix4(l).applyMatrix4(n)}createRange(t){this.removeObjectByName(this.rangeObjectName);const i=new a.EllipseCurve(0,0,t,t,0,2*Math.PI,!1,0).getPoints(50),r=new a.BufferGeometry().setFromPoints(i),s=new a.LineBasicMaterial({color:16711680}),h=new a.Line(r,s);return h.name=this.rangeObjectName,h}renderPointCloud(t,e){t.name=this.pointCloudObjectName;const i=new a.ShaderMaterial(this.initShaderMaterial());e&&this.generateRange(e),this.pointsUuid=t.uuid,t.material=i,this.filterZAxisPoints(t),this.scene.add(t),this.render()}clearAllBox(){this.clearAllGroupByPrefix("box")}clearAllSphere(){this.clearAllGroupByPrefix("sphere")}clearAllGroupByPrefix(t=""){const e=this.scene.children;for(let i=e.length-1;i>=0;i--){const r=e[i];r.type==="Group"&&r.name.startsWith(t)&&this.removeObjectByName(r.name)}}clearPointCloud(){this.removeObjectByName(this.pointCloudObjectName)}clearPointCloudAndRender(){this.clearPointCloud(),this.render()}initCloudData(t){if(!!this.store){for(let e=0;e<t.length;e+=3){const i=t[e],r=t[e+1],s=t[e+2];this.store.cloudData.set(`${i}@${r}@${s}`,{visible:!1})}this.store.setOriginPoints(t)}}highlightOriginPointCloud(t,e=[]){const i=this.scene.getObjectByName(this.pointCloudObjectName);if(!!i)return this.highlightPCDSrc=this.currentPCDSrc,new Promise((r,s)=>{if(window.Worker){const o=(t?[...t]:[]).map(l=>A(l)),d=this.getAllAttributeColor(o),n={cuboidList:o,position:i.geometry.attributes.position.array,color:i.geometry.attributes.dimensions.array,colorList:d,highlightIndex:e};k.postMessage(n),k.onmessage=l=>{const{color:c}=l.data,m=new a.BufferAttribute(c,3);if(!this.highlightPCDSrc||this.highlightPCDSrc!==this.currentPCDSrc||i.geometry.attributes.position.array.length!==c.length){s(new Error("Error Path"));return}this.cacheInstance.updateColor(this.highlightPCDSrc,c),this.highlightPCDSrc=void 0,m.needsUpdate=!0,i.geometry.setAttribute("dimensions",m),i.geometry.attributes.dimensions.needsUpdate=!0,r(c),this.render()}}})}clearHighlightBoxes(){this.removeObjectByName(this.highlightGroupName)}clearHighlightBoxesAndRender(){this.clearHighlightBoxes(),this.render()}highlightBoxes(t){const e=new a.Group;t.forEach(i=>{const{center:{x:r,y:s,z:h},width:o,height:d,depth:n,rotation:l}=i,{fill:c}=T.getColorFromConfig({attribute:i.attribute},B(b({},this.config),{attributeConfigurable:!0}),{}),m=new a.BoxGeometry(o,d,n),u=new a.MeshBasicMaterial({color:c,transparent:!0,opacity:.2,depthTest:!1});m.rotateZ(l),m.translate(r,s,h);const f=new a.Mesh(m,u);e.add(f);const p=new a.PlaneGeometry(n,d);p.rotateY(Math.PI/2),p.rotateZ(l);const g=new a.Vector3(o/2,0,0),y=new a.Matrix4().makeRotationY(Math.PI/2).makeRotationZ(l);g.applyMatrix4(y),p.translate(r+g.x,s+g.y,h+g.z);const x=new a.MeshBasicMaterial({color:c,side:a.DoubleSide,transparent:!0,opacity:.8,depthTest:!1}),M=new a.Mesh(p,x);e.add(M)}),e.name=this.highlightGroupName,this.scene.add(e),this.render()}updateColor(t){const e=this.scene.getObjectByName(this.pointCloudObjectName);if(e){const i=new a.BufferAttribute(t,3);e.geometry.setAttribute("dimensions",i),e.geometry.attributes.dimensions.needsUpdate=!0,this.render()}}setShowDirection(t){this.showDirection=t,this.scene.children.forEach(e=>{e.type==="Group"&&e.children.forEach(i=>{i.type==="ArrowHelper"&&(i.visible=t)})}),this.render()}getTextCanvas(t){const e=document.createElement("canvas"),i=e.getContext("2d");return i&&(i.font=`${50}px " bold`,i.fillStyle="white",i.textAlign="center",i.textBaseline="middle",i.fillText(t,e.width/2,e.height/2)),e}filterNoise(t){let e=[...t];e.sort((c,m)=>c.z-m.z);const i=Math.floor(e.length*.05),r=e[i];e=e.filter(({z:c})=>c>r.z+.1);const s=.005,h=Math.floor(e.length*(1-s));e=e.slice(0,h),e.sort((c,m)=>c.x-m.x);const o=Math.floor(e.length*s),d=Math.floor(e.length*(1-s));e=e.slice(o,d),e.sort((c,m)=>c.y-m.y);const n=Math.floor(e.length*s),l=Math.floor(e.length*(1-s));return e=e.slice(n,l),e.length>100?e:t}getFittedCoordinates(t,e){const i=[];let r=[...t,t[0]];e.forEach(({x:d,y:n})=>{t.forEach((l,c)=>{const m=r[c+1],u=H.getFootOfPerpendicular({x:d,y:n},l,m,!1,!0).length;(!i[c]||u<i[c].distance)&&(i[c]={distance:u,point:{x:d,y:n}})})}),r=[t[t.length-1],...t,t[0]];const s=[i[i.length-1],...i],h=t.map((d,n)=>{const l=r[n],c=r[n+1],m=r[n+2];return F.getIntersectionBySlope({p1:s[n].point,line1:[l,c],p2:s[n+1].point,line2:[c,m]})});return h.some(d=>!(Number.isFinite(d.x)&&Number.isFinite(d.y)))?t:h}getSensesPointZAxisInPolygon(t,e,i){var r,s,h;const o=this.scene.children.find(p=>p.uuid===this.pointsUuid);let d=0,n=0,l=0,c=0,m=[],u=[];const f=((h=(s=(r=o==null?void 0:o.geometry)==null?void 0:r.attributes)==null?void 0:s.position)==null?void 0:h.array)||[];for(let p=0;p<f.length;p+=3){const g=f[p],y=f[p+1],x=f[p+2];R({x:g,y},t)&&(x||x===0)&&u.push({x:g,y,z:x})}return u.length?(i&&(u=this.filterNoise(u),m=this.getFittedCoordinates(t,u)),u.sort((p,g)=>p.z-g.z),d=u[0].z-.01,n=u[u.length-1].z+.01,c=u.length,e&&(l=u.filter(({z:p})=>p>=e[0]&&p<=e[1]).length),{maxZ:n,minZ:d,count:l,zCount:c,fittedCoordinates:m}):{maxZ:n,minZ:d,count:l,zCount:c,fittedCoordinates:m}}getBasicCoordinate2Canvas(t){const e=this.containerWidth/2,i=this.containerHeight/2;return{x:t.x*e+e,y:t.y*i+i,z:t.z}}get basicCoordinate2CanvasMatrix4(){const t=this.containerWidth/2,e=this.containerHeight/2;return new a.Matrix4().set(t,0,0,t,0,e,0,e,0,0,1,0,0,0,0,1)}getCanvas2BasicCoordinate(t){const e=this.containerWidth/2,i=this.containerHeight/2;return new a.Vector3(t.x/e-e/2,-(t.y/i-i/2),1)}getPolygonSidePoints(t){const{center:{x:e,y:i,z:r},height:s,width:h,depth:o}=t,d={x:e+h/2,y:i+s/2,z:r-o/2},n={x:e+h/2,y:i+s/2,z:r+o/2},l={x:e-h/2,y:i+s/2,z:r+o/2},c={x:e-h/2,y:i+s/2,z:r-o/2};return[d,n,l,c]}getPolygonBackPoints(t){const{center:{x:e,y:i,z:r},height:s,width:h,depth:o}=t,d={x:e-h/2,y:i+s/2,z:r+o/2},n={x:e-h/2,y:i+s/2,z:r-o/2},l={x:e-h/2,y:i-s/2,z:r-o/2},c={x:e-h/2,y:i-s/2,z:r+o/2};return[d,n,l,c]}getPolygonTopPoints(t){const{center:{x:e,y:i,z:r},height:s,width:h,depth:o}=t,d={x:e+h/2,y:i+s/2,z:r+o/2},n={x:e+h/2,y:i-s/2,z:r+o/2},l={x:e-h/2,y:i-s/2,z:r+o/2},c={x:e-h/2,y:i+s/2,z:r+o/2};return[d,n,l,c]}getModelTransformationMatrix(t){const{center:{x:e,y:i,z:r},rotation:s}=t,h=new a.Matrix4().makeTranslation(-e,-i,-r),o=new a.Matrix4().makeTranslation(e,i,r),d=new a.Matrix4().makeRotationZ(s);return new a.Matrix4().multiply(o).multiply(d).multiply(h)}getBoxSidePolygon2DCoordinate(t){return this.getBoxPolygon2DCoordinate(t,C.Left)}getBoxBackPolygon2DCoordinate(t){return this.getBoxPolygon2DCoordinate(t,C.Back)}getSphereSidePoint2DCoordinate(t){return this.getSpherePoint2DCoordinate(t)}getSphereBackPoint2DCoordinate(t){return this.getSpherePoint2DCoordinate(t)}boxParams2ViewPolygon(t,e){switch(e){case C.Left:return this.getPolygonSidePoints(t);case C.Back:return this.getPolygonBackPoints(t);default:return this.getPolygonTopPoints(t)}}getBoxPolygon2DCoordinate(t,e){const i=this.boxParams2ViewPolygon(t,e),{width:r,height:s}=t,h=new a.Matrix4().premultiply(this.camera.matrixWorldInverse).premultiply(this.camera.projectionMatrix),o=new a.Matrix4().premultiply(this.getModelTransformationMatrix(t)).premultiply(h).premultiply(this.basicCoordinate2CanvasMatrix4);this.sideMatrix=o;const d=i.map(c=>new a.Vector3(c.x,c.y,c.z)).map(c=>c.applyMatrix4(this.sideMatrix)),n=this.containerWidth/r,l=this.containerHeight/s;return{polygon2d:d,zoom:Math.min(n,l)/2}}getSpherePoint2DCoordinate(t){const{center:e,attribute:i,id:r,valid:s}=t,{radius:h}=O,o={center:e,attribute:i,id:r,valid:s,width:h*2,height:h*2,depth:h*2,rotation:0},d=new a.Matrix4().premultiply(this.camera.matrixWorldInverse).premultiply(this.camera.projectionMatrix),n=new a.Matrix4().premultiply(this.getModelTransformationMatrix(o)).premultiply(d).premultiply(this.basicCoordinate2CanvasMatrix4);this.sideMatrix=n;const l=new a.Vector3(e.x,e.y,e.z).applyMatrix4(this.sideMatrix),c=this.containerWidth/(h*2),m=this.containerHeight/(h*2);return{point2d:l,zoom:Math.min(c,m)/2}}getSphereTopPoint2DCoordinate(t){const{center:e}=t,{radius:i}=O,r={x:-(e.y-this.containerWidth/2),y:-(e.x-this.containerHeight/2)},s=this.containerWidth/(i*2),h=this.containerHeight/(i*2);return{point2d:r,zoom:Math.min(s,h)/2}}getBoxTopPolygon2DCoordinate(t){const{width:e,height:i}=t,s=this.getPolygonTopPoints(t).map(d=>new a.Vector3(d.x,d.y,d.z)).map(d=>d.applyMatrix4(this.getModelTransformationMatrix(t))).map(d=>({x:d.y,y:d.x})).map(d=>({x:-(d.x-this.containerWidth/2),y:-(d.y-this.containerHeight/2)})),h=this.containerWidth/e,o=this.containerHeight/i;return{polygon2d:s,zoom:Math.min(h,o)/2}}getNewBoxBySideUpdate(t,e,i,r){const s=new a.Matrix4().makeRotationZ(r.rotation),h=new a.Vector3(-t.x,0,0).applyMatrix4(s);let o=r;return o.center={x:o.center.x+h.x,y:o.center.y+h.y,z:o.center.z-t.z},o=B(b({},o),{width:Math.abs(o.width+e),height:o.height,depth:Math.abs(o.depth+i)}),{newBoxParams:o}}getNewBoxByBackUpdate(t,e,i,r){const s=new a.Matrix4().makeRotationZ(r.rotation),h=new a.Vector3(0,-t.x,0).applyMatrix4(s);let o=r;return o.center={x:o.center.x+h.x,y:o.center.y+h.y,z:o.center.z-t.z},o=B(b({},o),{width:o.width,height:Math.abs(o.height+e),depth:Math.abs(o.depth+i)}),{newBoxParams:o}}getNewBoxBySideUpdateByPoints(t,e,i,r){var s;const h=(s=this.sideMatrix)==null?void 0:s.invert();if(!this.sideMatrix||!h){console.error("No sideMatrix");return}this.camera.zoom=1,this.camera.updateProjectionMatrix();const o=t.map(g=>new a.Vector3(g.x,g.y,g.z)).map(g=>g.applyMatrix4(h)),[d,n,l,c]=o,m=Math.max(Math.abs(d.x-l.x),Math.abs(d.x-n.x)),f=n.add(c).applyMatrix3(new a.Matrix3().set(1/2,0,0,0,1/2,0,0,0,1/2)).clone().applyMatrix3(new a.Matrix3().set(-1,0,0,0,-1,0,0,0,-1)).add(new a.Vector3(r.center.x,r.center.y,r.center.z));return{newBoxParams:B(b({},r),{center:{x:r.center.x-f.x,y:r.center.y-f.y,z:r.center.z-i},width:m,height:r.height,depth:r.depth+e,rotation:r.rotation})}}filterZAxisPoints(t){const e=t||this.scene.children.find(i=>i.uuid===this.pointsUuid);if(e){const{attributes:i}=e.geometry,{position:r}=i,s=[],{count:h}=r;for(let o=0;o<h;o++){const d=r.getZ(o);s.push(d>this.zAxisLimit?0:1)}e.geometry.setAttribute("visibility",new a.Float32BufferAttribute(s,1)),e.geometry.attributes.visibility.needsUpdate=!0}}render(){this.renderer.render(this.scene,this.camera)}}export{ot as PointCloud};
31
+ }`,uniforms:{pointSize:{value:this.pointsMaterialSize}}}),this.loadPCDFile=(...n)=>S(this,[...n],function*(l=this.currentPCDSrc,h){if(!l)return;this.clearPointCloud(),this.cacheInstance.clearCache2DHighlightIndex(),this.currentPCDSrc=l;const{points:u,color:m}=yield this.cacheInstance.loadPCDFile(l),f=new a.BufferGeometry;f.setAttribute("position",new a.BufferAttribute(u,3)),this.isSegment||f.setAttribute("dimensions",new a.BufferAttribute(m,3)),this.initCloudData(u);const p=new a.Points(f);this.renderPointCloud(p,h),this.emit("loadPCDFileEnd")}),this.getHighlightIndexByMappingImgList=n=>S(this,[n],function*({mappingImgList:l,points:h}){const u=l.length===0?[]:yield Promise.all(l.map(p=>W.load(p.url))),m=l.map((p,g)=>{var x;if(this.cacheInstance.cache2DHighlightIndex.has(p.url))return(x=this.cacheInstance.cache2DHighlightIndex.get(p.url))!=null?x:[];const y=$({points:h,calib:p.calib,width:u[g].width,height:u[g].height});return this.cacheInstance.cache2DHighlightIndex.set(p.url,y),y});return Y(m)}),this.filterPreResult=(n,l,h)=>S(this,null,function*(){const{points:u}=yield this.cacheInstance.loadPCDFile(n),m=yield this.cacheInstance.loadIndexMap(n,u);return new Promise(f=>{const p=h.map(g=>{const x=L.calculatePointsInsideBox({indexMap:m,polygon:D(g).polygonPointList,zScope:[g.center.z-g.depth/2,g.center.z+g.depth/2],box:g}),y=x>=l.lowerLimitPointsNumInBox;return P(b({},g),{valid:y,count:x})});f(p)})}),this.loadPCDFileByBox=(n,l,h)=>S(this,null,function*(){const u=(p,g)=>S(this,null,function*(){const{width:x=0,height:y=0,depth:M=0}=h!=null?h:{},v=yield this.filterPointsByBox(P(b({},l),{width:l.width+x,height:l.height+y,depth:l.depth+M}),p,g);if(!v){console.error("filter Error");return}this.clearPointCloud(),this.currentPCDSrc=n;const z=new a.Points(v.geometry);z.name=this.pointCloudObjectName,this.scene.add(z),this.render()}),{points:m,color:f}=yield this.cacheInstance.loadPCDFile(n);u(m,f)}),this.generateRange=n=>{const l=this.createRange(n);this.scene.add(l)},this.generateBoxArrow=({width:n})=>{const l=new a.Vector3(1,0,0),h=new a.Vector3(n/2,0,0),u=2,m=16776960,f=new a.ArrowHelper(l,h,u,m);return f.visible=this.showDirection,f},this.generateBoxTrackID=n=>{if(!n.trackID)return;const l=new a.Texture(this.getTextCanvas(n.trackID.toString()));l.needsUpdate=!0;const h=new a.SpriteMaterial({map:l,depthWrite:!1}),u=new a.Sprite(h);return u.scale.set(5,5,5),u.position.set(-n.width/2,0,n.depth/2+.5),u},this.applyZAxisPoints=n=>{this.zAxisLimit=n,this.filterZAxisPoints(),this.render()},this.updatePointSize=({zoomIn:n,customSize:l})=>{const h=this.scene.getObjectByName(this.pointCloudObjectName);if(!h)return;const u=h.material.uniforms.pointSize.value;n?h.material.uniforms.pointSize.value=Math.min(u*1.2,10):h.material.uniforms.pointSize.value=Math.max(u/1.2,1),l&&(h.material.uniforms.pointSize.value=l,this.pointsMaterialSize=l),h.material.uniformsNeedUpdate=!0,this.render()},this.container=t,this.renderer=new a.WebGLRenderer({antialias:!0}),this.backgroundColor=s,this.config=c,this.checkMode=d!=null?d:!1,i&&r?(this.isOrthographicCamera=!0,this.camera=new a.OrthographicCamera(r.left,r.right,r.top,r.bottom,r.near,r.far)):this.camera=new a.PerspectiveCamera(30,this.containerWidth/this.containerHeight,1,1e3),this.initCamera(),this.scene=new a.Scene,this.controls=new U(this.camera,o?this.container:this.renderer.domElement),this.pcdLoader=new Z,this.axesHelper=new a.AxesHelper(1e3),this.scene.add(this.camera),e||t.appendChild(this.renderer.domElement),this.init(),this.cacheInstance=G.getInstance(),o===!0&&(this.initSegment(),this.isSegment=!0)}initSegment(){this.store=new q(this.pointCloudDelegate),this.controls.enablePan=!1,this.controls.addEventListener("start",this.orbiterStart.bind(this)),this.controls.addEventListener("change",this.orbiterChange.bind(this)),this.controls.addEventListener("end",this.orbiterEnd.bind(this)),this.segmentOperation=new X(b({dom:this.container,store:this.store},this.eventBus)),this.pointCloudRender=new K(P(b({store:this.store},this.eventBus),{nextTick:this.nextTick})),this.initMsg(),document.addEventListener("keydown",this.keydown),document.addEventListener("keyup",this.keyup)}orbiterStart(){}orbiterChange(){!this.store||(this.store.orbiting=!0)}orbiterEnd(){!this.store||(this.store.orbiting=!1)}get currentSegmentTool(){var t;return(t=this.segmentOperation)==null?void 0:t.currentToolName}get pointCloudObject(){return this.scene.getObjectByName(this.pointCloudObjectName)}initMsg(){!this.segmentOperation||(this.on("CircleSelector",this.segmentOperation.updateSelector2Circle.bind(this.segmentOperation)),this.on("LassoSelector",this.segmentOperation.updateSelector2Lasso.bind(this.segmentOperation)),this.on("RectSelector",this.segmentOperation.updateSelector2Rect.bind(this.segmentOperation)),this.on("clearPointCloud",this.clearPointCloud.bind(this)),this.on("loadPCDFile",this.loadPCDFile.bind(this)))}unbindMsg(){!this.segmentOperation||(this.unbind("CircleSelector",this.segmentOperation.updateSelector2Circle.bind(this.segmentOperation)),this.unbind("LassoSelector",this.segmentOperation.updateSelector2Lasso.bind(this.segmentOperation)),this.unbind("RectSelector",this.segmentOperation.updateSelector2Rect.bind(this.segmentOperation)),this.unbind("clearPointCloud",this.clearPointCloud.bind(this)),this.unbind("loadPCDFile",this.loadPCDFile.bind(this)))}get eventBus(){return{on:this.on.bind(this),emit:this.emit.bind(this),unbind:this.unbind.bind(this)}}get pointCloudDelegate(){return b({container:this.container,scene:this.scene,camera:this.camera,renderer:this.renderer,checkMode:this.checkMode,config:this.config},this.eventBus)}get DEFAULT_INIT_CAMERA_POSITION(){return new a.Vector3(-.01,0,1e3)}get containerWidth(){return this.container.clientWidth}get containerHeight(){return this.container.clientHeight}setInitCameraPosition(t){this.initCameraPosition=t}setConfig(t){var e;this.config=t,(e=this.store)==null||e.setConfig(t)}initOrthographicCamera(t){if(this.camera.type!=="OrthographicCamera")return;const{left:e,right:i,top:r,bottom:s,near:c,far:o}=t;this.camera.left=e,this.camera.right=i,this.camera.top=r,this.camera.bottom=s,this.camera.near=c,this.camera.far=o,this.camera.updateProjectionMatrix()}initPerspectiveCamera(){this.camera.type==="PerspectiveCamera"&&(this.camera.fov=30,this.camera.aspect=this.containerWidth/this.containerHeight,this.camera.near=1,this.camera.far=1e3,this.camera.updateProjectionMatrix())}initCamera(){const{camera:t}=this;if(this.isOrthographicCamera){const{x:e,y:i,z:r}=this.initCameraPosition;t.position.set(e,i,r)}else t.position.set(-1,0,500);t.up.set(0,0,1)}initControls(){const{controls:t}=this;t.addEventListener("change",()=>{this.render()}),this.setDefaultControls()}setDefaultControls(){const{controls:t}=this,e=[0,0,0];t.target=new a.Vector3(...e),t.addEventListener("change",()=>{this.render()}),t.maxPolarAngle=Math.PI/2,t.update()}initRenderer(){const{renderer:t}=this;t.setPixelRatio(window.devicePixelRatio),t.setSize(this.containerWidth,this.containerHeight)}init(){const{scene:t}=this;t.background=new a.Color(this.backgroundColor),this.initControls(),this.initRenderer()}removeObjectByName(t,e=""){const i=this.scene.getObjectByName(e+t);i&&i.removeFromParent()}getColorFromConfig(t){return T.getColorFromConfig({attribute:t},P(b({},this.config),{attributeConfigurable:!0}),{})}generateBox(t,e=16777215){const i=e;this.addBoxToSense(t,i),this.render()}getAllAttributeColor(t){return t.reduce((e,i)=>(e[i.attribute]=this.getColorFromConfig(i.attribute),e),{})}generateBoxes(t){t.forEach(e=>{this.addBoxToSense(e)}),this.render()}getOrthographicCamera(t){const{center:e,width:i,height:r}=t,s=10,c=e.x-i/2-s,o=e.x-i/2+s,d=e.y+r/2+s,n=e.y-r/2-s,l=100,h=-100,u=500/l;return{left:c,right:o,top:d,bottom:n,near:l,far:h,zoom:u}}updateCameraZoom(t){this.camera.zoom=t,this.camera.updateProjectionMatrix()}updateCameraByBox(t,e,i){const{center:r,width:s,height:c,depth:o,rotation:d}=t,n=this.getCameraVector(r,d,{width:s,height:c,depth:o},e);return i?(this.updateCamera(i,r),new a.Vector3(i.x,i.y,i.z)):(this.updateCamera(n,r),n)}updateCameraBySphere(t,e){const{center:i}=t,{radius:r}=O,s=this.getCameraVector(i,0,{width:r*2,height:r*2,depth:r*2},e);return this.updateCamera(s,i),s}updateOrthoCamera(t,e){const i=this.updateCameraByBox(t,e);return this.camera.zoom=1,this.camera.updateProjectionMatrix(),{cameraPositionVector:i}}updateOrthoCameraBySphere(t,e){const i=this.updateCameraBySphere(t,e);return this.camera.zoom=1,this.camera.updateProjectionMatrix(),{cameraPositionVector:i}}updateTopCamera(){this.setInitCameraPosition(this.DEFAULT_INIT_CAMERA_POSITION),this.camera.zoom=1,this.initCamera(),this.setDefaultControls(),this.camera.updateProjectionMatrix(),this.render()}updateCamera(t,e){this.camera.position.set(t.x,t.y,t.z),this.controls.target=new a.Vector3(e.x,e.y,e.z),this.controls.update()}resetCamera(){this.updateCamera(this.DEFAULT_INIT_CAMERA_POSITION,{x:0,y:0,z:0})}getOrthographicCameraTarget(t){const e=new a.Vector3(0,0,-1).applyQuaternion(t.quaternion);return t.position.clone().add(e)}createThreeMatrix4(t){return new a.Matrix4().set(...t)}filterPointsByBox(t,e,i){var r,s,c;if(!e){const o=this.scene.getObjectByName(this.pointCloudObjectName);if(!o)return console.error("There is no corresponding point cloud object"),Promise.resolve(void 0);e=(c=(s=(r=o==null?void 0:o.geometry)==null?void 0:r.attributes)==null?void 0:s.position)==null?void 0:c.array}if(window.Worker){const{zMin:o,zMax:d,polygonPointList:n}=D(t),l=e;i=i!=null?i:new Float32Array([]);const h={boxParams:t,zMin:o,zMax:d,polygonPointList:n,color:i,position:l};return new Promise(u=>{const m=new R;m.postMessage(h),m.onmessage=f=>{const{color:p,position:g,num:x}=f.data,y=new a.BufferGeometry;y.setAttribute("position",new a.Float32BufferAttribute(g,3)),y.setAttribute("color",new a.Float32BufferAttribute(p,3)),y.computeBoundingSphere(),m.terminate(),u({geometry:y,num:x})}})}return Promise.resolve(void 0)}getCameraVector(t,e,i,r=C.Front,s=nt){let c=B.frontViewMatrix4(s);switch(r){case C.Front:break;case C.Back:c=B.backViewMatrix4(s);break;case C.Left:c=B.leftViewMatrix4(s);break;case C.Right:c=B.rightViewMatrix4(s);break;case C.Top:c=B.topViewMatrix4(s);break;case C.LFT:c=B.leftFrontTopViewMatrix4(s,i);break;case C.RBT:c=B.rightBackTopViewMatrix4(s,i);break}const o=this.createThreeMatrix4(c),d=new a.Matrix4().makeTranslation(-t.x,-t.y,-t.z),n=new a.Matrix4().makeTranslation(t.x,t.y,t.z),l=new a.Matrix4().makeRotationZ(e);return new a.Vector3(t.x,t.y,t.z).clone().applyMatrix4(o).applyMatrix4(d).applyMatrix4(l).applyMatrix4(n)}createRange(t){this.removeObjectByName(this.rangeObjectName);const i=new a.EllipseCurve(0,0,t,t,0,2*Math.PI,!1,0).getPoints(50),r=new a.BufferGeometry().setFromPoints(i),s=new a.LineBasicMaterial({color:16711680}),c=new a.Line(r,s);return c.name=this.rangeObjectName,c}renderPointCloud(t,e){t.name=this.pointCloudObjectName;const i=new a.ShaderMaterial(this.initShaderMaterial());e&&this.generateRange(e),this.pointsUuid=t.uuid,t.material=i,this.filterZAxisPoints(t),this.scene.add(t),this.render()}clearAllBox(){this.clearAllGroupByPrefix("box")}clearAllSphere(){this.clearAllGroupByPrefix("sphere")}clearAllGroupByPrefix(t=""){const e=this.scene.children;for(let i=e.length-1;i>=0;i--){const r=e[i];r.type==="Group"&&r.name.startsWith(t)&&this.removeObjectByName(r.name)}}clearPointCloud(){this.removeObjectByName(this.pointCloudObjectName)}clearPointCloudAndRender(){this.clearPointCloud(),this.render()}initCloudData(t){if(!!this.store){for(let e=0;e<t.length;e+=3){const i=t[e],r=t[e+1],s=t[e+2];this.store.cloudData.set(`${i}@${r}@${s}`,{visible:!1})}this.store.setOriginPoints(t)}}highlightOriginPointCloud(t,e=[]){const i=this.scene.getObjectByName(this.pointCloudObjectName);if(!!i)return this.highlightPCDSrc=this.currentPCDSrc,new Promise((r,s)=>{if(window.Worker){const o=(t?[...t]:[]).map(l=>D(l)),d=this.getAllAttributeColor(o),n={cuboidList:o,position:i.geometry.attributes.position.array,color:i.geometry.attributes.dimensions.array,colorList:d,highlightIndex:e};_.postMessage(n),_.onmessage=l=>{const{color:h}=l.data,u=new a.BufferAttribute(h,3);if(!this.highlightPCDSrc||this.highlightPCDSrc!==this.currentPCDSrc||i.geometry.attributes.position.array.length!==h.length){s(new Error("Error Path"));return}this.cacheInstance.updateColor(this.highlightPCDSrc,h),this.highlightPCDSrc=void 0,u.needsUpdate=!0,i.geometry.setAttribute("dimensions",u),i.geometry.attributes.dimensions.needsUpdate=!0,r(h),this.render()}}})}clearHighlightBoxes(){this.removeObjectByName(this.highlightGroupName)}clearHighlightBoxesAndRender(){this.clearHighlightBoxes(),this.render()}highlightBoxes(t){const e=new a.Group;t.forEach(i=>{const{center:{x:r,y:s,z:c},width:o,height:d,depth:n,rotation:l}=i,{fill:h}=T.getColorFromConfig({attribute:i.attribute},P(b({},this.config),{attributeConfigurable:!0}),{}),u=new a.BoxGeometry(o,d,n),m=new a.MeshBasicMaterial({color:h,transparent:!0,opacity:.2,depthTest:!1});u.rotateZ(l),u.translate(r,s,c);const f=new a.Mesh(u,m);e.add(f);const p=new a.PlaneGeometry(n,d);p.rotateY(Math.PI/2),p.rotateZ(l);const g=new a.Vector3(o/2,0,0),x=new a.Matrix4().makeRotationY(Math.PI/2).makeRotationZ(l);g.applyMatrix4(x),p.translate(r+g.x,s+g.y,c+g.z);const y=new a.MeshBasicMaterial({color:h,side:a.DoubleSide,transparent:!0,opacity:.8,depthTest:!1}),M=new a.Mesh(p,y);e.add(M)}),e.name=this.highlightGroupName,this.scene.add(e),this.render()}updateColor(t){const e=this.scene.getObjectByName(this.pointCloudObjectName);if(e){const i=new a.BufferAttribute(t,3);e.geometry.setAttribute("dimensions",i),e.geometry.attributes.dimensions.needsUpdate=!0,this.render()}}setShowDirection(t){this.showDirection=t,this.scene.children.forEach(e=>{e.type==="Group"&&e.children.forEach(i=>{i.type==="ArrowHelper"&&(i.visible=t)})}),this.render()}getTextCanvas(t){const e=document.createElement("canvas"),i=e.getContext("2d");return i&&(i.font=`${50}px " bold`,i.fillStyle="white",i.textAlign="center",i.textBaseline="middle",i.fillText(t,e.width/2,e.height/2)),e}filterNoise(t){let e=[...t];e.sort((h,u)=>h.z-u.z);const i=Math.floor(e.length*.05),r=e[i];e=e.filter(({z:h})=>h>r.z+.1);const s=.005,c=Math.floor(e.length*(1-s));e=e.slice(0,c),e.sort((h,u)=>h.x-u.x);const o=Math.floor(e.length*s),d=Math.floor(e.length*(1-s));e=e.slice(o,d),e.sort((h,u)=>h.y-u.y);const n=Math.floor(e.length*s),l=Math.floor(e.length*(1-s));return e=e.slice(n,l),e.length>100?e:t}getFittedCoordinates(t,e){const i=[];let r=[...t,t[0]];e.forEach(({x:d,y:n})=>{t.forEach((l,h)=>{const u=r[h+1],m=L.getFootOfPerpendicular({x:d,y:n},l,u,!1,!0).length;(!i[h]||m<i[h].distance)&&(i[h]={distance:m,point:{x:d,y:n}})})}),r=[t[t.length-1],...t,t[0]];const s=[i[i.length-1],...i],c=t.map((d,n)=>{const l=r[n],h=r[n+1],u=r[n+2];return E.getIntersectionBySlope({p1:s[n].point,line1:[l,h],p2:s[n+1].point,line2:[h,u]})});return c.some(d=>!(Number.isFinite(d.x)&&Number.isFinite(d.y)))?t:c}getSensesPointZAxisInPolygon(t,e,i){var r,s,c;const o=this.scene.children.find(p=>p.uuid===this.pointsUuid);let d=0,n=0,l=0,h=0,u=[],m=[];const f=((c=(s=(r=o==null?void 0:o.geometry)==null?void 0:r.attributes)==null?void 0:s.position)==null?void 0:c.array)||[];for(let p=0;p<f.length;p+=3){const g=f[p],x=f[p+1],y=f[p+2];H({x:g,y:x},t)&&(y||y===0)&&m.push({x:g,y:x,z:y})}return m.length?(i&&(m=this.filterNoise(m),u=this.getFittedCoordinates(t,m)),m.sort((p,g)=>p.z-g.z),d=m[0].z-.01,n=m[m.length-1].z+.01,h=m.length,e&&(l=m.filter(({z:p})=>p>=e[0]&&p<=e[1]).length),{maxZ:n,minZ:d,count:l,zCount:h,fittedCoordinates:u}):{maxZ:n,minZ:d,count:l,zCount:h,fittedCoordinates:u}}getBasicCoordinate2Canvas(t){const e=this.containerWidth/2,i=this.containerHeight/2;return{x:t.x*e+e,y:t.y*i+i,z:t.z}}get basicCoordinate2CanvasMatrix4(){const t=this.containerWidth/2,e=this.containerHeight/2;return new a.Matrix4().set(t,0,0,t,0,e,0,e,0,0,1,0,0,0,0,1)}getCanvas2BasicCoordinate(t){const e=this.containerWidth/2,i=this.containerHeight/2;return new a.Vector3(t.x/e-e/2,-(t.y/i-i/2),1)}getPolygonSidePoints(t){const{center:{x:e,y:i,z:r},height:s,width:c,depth:o}=t,d={x:e+c/2,y:i+s/2,z:r-o/2},n={x:e+c/2,y:i+s/2,z:r+o/2},l={x:e-c/2,y:i+s/2,z:r+o/2},h={x:e-c/2,y:i+s/2,z:r-o/2};return[d,n,l,h]}getPolygonBackPoints(t){const{center:{x:e,y:i,z:r},height:s,width:c,depth:o}=t,d={x:e-c/2,y:i+s/2,z:r+o/2},n={x:e-c/2,y:i+s/2,z:r-o/2},l={x:e-c/2,y:i-s/2,z:r-o/2},h={x:e-c/2,y:i-s/2,z:r+o/2};return[d,n,l,h]}getPolygonTopPoints(t){const{center:{x:e,y:i,z:r},height:s,width:c,depth:o}=t,d={x:e+c/2,y:i+s/2,z:r+o/2},n={x:e+c/2,y:i-s/2,z:r+o/2},l={x:e-c/2,y:i-s/2,z:r+o/2},h={x:e-c/2,y:i+s/2,z:r+o/2};return[d,n,l,h]}getModelTransformationMatrix(t){const{center:{x:e,y:i,z:r},rotation:s}=t,c=new a.Matrix4().makeTranslation(-e,-i,-r),o=new a.Matrix4().makeTranslation(e,i,r),d=new a.Matrix4().makeRotationZ(s);return new a.Matrix4().multiply(o).multiply(d).multiply(c)}getBoxSidePolygon2DCoordinate(t){return this.getBoxPolygon2DCoordinate(t,C.Left)}getBoxBackPolygon2DCoordinate(t){return this.getBoxPolygon2DCoordinate(t,C.Back)}getSphereSidePoint2DCoordinate(t){return this.getSpherePoint2DCoordinate(t)}getSphereBackPoint2DCoordinate(t){return this.getSpherePoint2DCoordinate(t)}boxParams2ViewPolygon(t,e){switch(e){case C.Left:return this.getPolygonSidePoints(t);case C.Back:return this.getPolygonBackPoints(t);default:return this.getPolygonTopPoints(t)}}getBoxPolygon2DCoordinate(t,e){const i=this.boxParams2ViewPolygon(t,e),{width:r,height:s}=t,c=new a.Matrix4().premultiply(this.camera.matrixWorldInverse).premultiply(this.camera.projectionMatrix),o=new a.Matrix4().premultiply(this.getModelTransformationMatrix(t)).premultiply(c).premultiply(this.basicCoordinate2CanvasMatrix4);this.sideMatrix=o;const d=i.map(h=>new a.Vector3(h.x,h.y,h.z)).map(h=>h.applyMatrix4(this.sideMatrix)),n=this.containerWidth/r,l=this.containerHeight/s;return{polygon2d:d,zoom:Math.min(n,l)/2}}getSpherePoint2DCoordinate(t){const{center:e,attribute:i,id:r,valid:s}=t,{radius:c}=O,o={center:e,attribute:i,id:r,valid:s,width:c*2,height:c*2,depth:c*2,rotation:0},d=new a.Matrix4().premultiply(this.camera.matrixWorldInverse).premultiply(this.camera.projectionMatrix),n=new a.Matrix4().premultiply(this.getModelTransformationMatrix(o)).premultiply(d).premultiply(this.basicCoordinate2CanvasMatrix4);this.sideMatrix=n;const l=new a.Vector3(e.x,e.y,e.z).applyMatrix4(this.sideMatrix),h=this.containerWidth/(c*2),u=this.containerHeight/(c*2);return{point2d:l,zoom:Math.min(h,u)/2}}getSphereTopPoint2DCoordinate(t){const{center:e}=t,{radius:i}=O,r={x:-(e.y-this.containerWidth/2),y:-(e.x-this.containerHeight/2)},s=this.containerWidth/(i*2),c=this.containerHeight/(i*2);return{point2d:r,zoom:Math.min(s,c)/2}}getBoxTopPolygon2DCoordinate(t){const{width:e,height:i}=t,s=this.getPolygonTopPoints(t).map(d=>new a.Vector3(d.x,d.y,d.z)).map(d=>d.applyMatrix4(this.getModelTransformationMatrix(t))).map(d=>({x:d.y,y:d.x})).map(d=>({x:-(d.x-this.containerWidth/2),y:-(d.y-this.containerHeight/2)})),c=this.containerWidth/e,o=this.containerHeight/i;return{polygon2d:s,zoom:Math.min(c,o)/2}}getNewBoxBySideUpdate(t,e,i,r){const s=new a.Matrix4().makeRotationZ(r.rotation),c=new a.Vector3(-t.x,0,0).applyMatrix4(s);let o=r;return o.center={x:o.center.x+c.x,y:o.center.y+c.y,z:o.center.z-t.z},o=P(b({},o),{width:Math.abs(o.width+e),height:o.height,depth:Math.abs(o.depth+i)}),{newBoxParams:o}}getNewBoxByBackUpdate(t,e,i,r){const s=new a.Matrix4().makeRotationZ(r.rotation),c=new a.Vector3(0,-t.x,0).applyMatrix4(s);let o=r;return o.center={x:o.center.x+c.x,y:o.center.y+c.y,z:o.center.z-t.z},o=P(b({},o),{width:o.width,height:Math.abs(o.height+e),depth:Math.abs(o.depth+i)}),{newBoxParams:o}}getNewBoxBySideUpdateByPoints(t,e,i,r){var s;const c=(s=this.sideMatrix)==null?void 0:s.invert();if(!this.sideMatrix||!c){console.error("No sideMatrix");return}this.camera.zoom=1,this.camera.updateProjectionMatrix();const o=t.map(g=>new a.Vector3(g.x,g.y,g.z)).map(g=>g.applyMatrix4(c)),[d,n,l,h]=o,u=Math.max(Math.abs(d.x-l.x),Math.abs(d.x-n.x)),f=n.add(h).applyMatrix3(new a.Matrix3().set(1/2,0,0,0,1/2,0,0,0,1/2)).clone().applyMatrix3(new a.Matrix3().set(-1,0,0,0,-1,0,0,0,-1)).add(new a.Vector3(r.center.x,r.center.y,r.center.z));return{newBoxParams:P(b({},r),{center:{x:r.center.x-f.x,y:r.center.y-f.y,z:r.center.z-i},width:u,height:r.height,depth:r.depth+e,rotation:r.rotation})}}filterZAxisPoints(t){const e=t||this.scene.children.find(i=>i.uuid===this.pointsUuid);if(e){const{attributes:i}=e.geometry,{position:r}=i,s=[],{count:c}=r;for(let o=0;o<c;o++){const d=r.getZ(o);s.push(d>this.zAxisLimit?0:1)}e.geometry.setAttribute("visibility",new a.Float32BufferAttribute(s,1)),e.geometry.attributes.visibility.needsUpdate=!0}}render(){this.renderer.render(this.scene,this.camera)}}export{ot as PointCloud};
@@ -1 +1 @@
1
- import{ImgConversionUtils as n}from"@labelbee/lb-utils";import r from"../../utils/tool/AxisUtils.js";import a from"../../utils/tool/DrawUtils.js";import{EToolName as h,EScribblePattern as o}from"../../constant/tool.js";import c from"../../utils/tool/CommonToolUtils.js";import l from"../../utils/tool/AttributeUtils.js";import{BasicToolOperation as u}from"./basicToolOperation.js";const d=20,C="white";class v extends u{constructor(t){super(t);this.toolName=h.ScribbleTool,this.action=o.Scribble,this.getOriginCoordinate=i=>r.changePointByZoom(this.getCoordinateUnderZoomByRotate(i),1/this.zoom),this.onMouseDown=i=>{super.onMouseDown(i)||this.forbidMouseOperation||!this.imgInfo||(this.initCacheCanvas(this.imgNode),this.mouseEvents("onMouseDown").call(this,i))},this.onMouseMove=i=>{super.onMouseMove(i)||this.forbidMouseOperation||!this.imgInfo||this.mouseEvents("onMouseMove").call(this,i)},this.onMouseUp=i=>{super.onMouseUp(i)||this.forbidMouseOperation||!this.imgInfo||this.mouseEvents("onMouseUp").call(this,i)},this.mouseEvents=i=>({[o.Scribble]:{onMouseMove:this.onScribbleMove,onMouseUp:this.onScribbleEnd,onMouseDown:this.onScribbleStart},[o.Erase]:{onMouseMove:this.onEraseMove,onMouseUp:this.onEraseEnd,onMouseDown:this.onEraseStart}})[this.action][i],this.setPattern=i=>{switch(this.action=i,i){case o.Erase:{this.setCustomCursor(this.cursorErase);break}default:{this.setCustomCursor("none");break}}};var e;if(this.penSize=d,((e=this.config.attributeList)==null?void 0:e.length)>0){const i=this.config.attributeList[0];this.setDefaultAttribute(i.value)}}get cursorErase(){const t='<?xml version="1.0" encoding="UTF-8"?><svg width="24" heighst="24" viewBox="0 0 48 48" fill="none" xmlns="http://www.w3.org/2000/svg"><g clip-path="url(#icon-65e7e1747c11bad3)"><path d="M44.7818 24.1702L31.918 7.09935L14.1348 20.5L27.5 37L30.8556 34.6643L44.7818 24.1702Z" fill="#141414" stroke="#000000" stroke-width="4" stroke-linejoin="miter"/><path d="M27.4998 37L23.6613 40.0748L13.0978 40.074L10.4973 36.6231L4.06543 28.0876L14.4998 20.2248" stroke="#000000" stroke-width="4" stroke-linejoin="miter"/><path d="M13.2056 40.072L44.5653 40.072" stroke="#000000" stroke-width="4" stroke-linecap="round"/></g><defs><clipPath id="icon-65e7e1747c11bad3"><rect width="48" height="48" fill="#df4c4c"/></clipPath></defs></svg>';return`url(${`data:image/svg+xml;base64,${window.btoa(unescape(encodeURIComponent(t)))}`}) 0 0, auto`}get defaultCursor(){return this.action===o.Erase?this.cursorErase:this.isShowDefaultCursor?"default":"none"}get color(){var t,e;return(e=(t=this==null?void 0:this.defaultAttributeInfo)==null?void 0:t.color)!=null?e:C}get penSizeWithZoom(){return this.penSize/this.zoom}get cacheCanvasToDataUrl(){var t;return(t=this.cacheCanvas)==null?void 0:t.toDataURL("image/png",0)}setPenSize(t){this.penSize=t}initCacheCanvas(t){if(this.cacheCanvas||!t)return;const{canvas:e,ctx:i}=n.createCanvas(t);this.cacheCanvas=e,this.cacheContext=i}updateCacheCanvasSize(t){this.cacheCanvas&&(this.cacheCanvas.width=t.width,this.cacheCanvas.height=t.height)}updateUrl2CacheContext(t){n.createImgDom(t).then(e=>{this.cacheContext||this.initCacheCanvas(e),this.cacheContext&&(this.cacheContext.save(),this.clearCacheCanvas(),this.cacheContext.drawImage(e,0,0,e.width,e.height),this.cacheContext.restore(),this.render())})}setImgNode(t,e){super.setImgNode(t,e),this.cacheCanvas?this.updateCacheCanvasSize(t):this.initCacheCanvas(t)}setResult(t){var e,i;let{url:s}=(e=t==null?void 0:t[0])!=null?e:{};if(this.clearCacheCanvas(),s||(s=(i=this.cacheCanvasToDataUrl)!=null?i:""),this.history.initRecord([s],!0),!s){this.render();return}this.updateUrl2CacheContext(s)}onKeyDown(t){if(!c.hotkeyFilter(t)||super.onKeyDown(t)===!1)return;const{keyCode:e}=t,i=l.getAttributeByKeycode(e,this.config.attributeList);i!==void 0&&this.setDefaultAttribute(i)}eventBinding(){super.eventBinding()}setDefaultAttribute(t){const e=this.config.attributeList.find(i=>i.value===t);e&&(this.defaultAttribute=e.value,this.defaultAttributeInfo=e,this.emit("changeAttributeSidebar"),this.render())}clearStatusAfterLeave(){this.onScribbleEnd(),this.startPoint=void 0}onMouseLeave(){super.onMouseLeave(),this.clearStatusAfterLeave()}onScribbleStart(t){if(!this.cacheContext)return;this.cacheContext.save(),this.cacheContext.beginPath(),this.cacheContext.strokeStyle=this.color,this.cacheContext.lineWidth=this.penSizeWithZoom,this.cacheContext.lineCap="round",this.cacheContext.lineJoin="round";const e=this.getOriginCoordinate(t);this.cacheContext.moveTo(e.x,e.y),this.startPoint=e}onScribbleMove(t){if(t.buttons===1&&this.cacheContext&&this.startPoint){const e=this.getOriginCoordinate(t);this.cacheContext.lineTo(e.x,e.y),this.cacheContext.stroke()}}onScribbleEnd(){var t,e;this.startPoint&&((t=this.cacheContext)==null||t.closePath(),(e=this.cacheContext)==null||e.restore(),this.startPoint=void 0,this.history.pushHistory(this.cacheCanvasToDataUrl))}eraseArc(t){var e;if(this.cacheContext){const i=this.getOriginCoordinate(t);this.cacheContext.save(),this.cacheContext.beginPath(),this.cacheContext.arc(i.x,i.y,this.penSizeWithZoom/2,0,Math.PI*2,!1),this.cacheContext.clip(),this.cacheContext.clearRect(0,0,this.cacheContext.canvas.width,this.cacheContext.canvas.height),(e=this.cacheContext)==null||e.restore()}}onEraseStart(t){!this.cacheContext||t.buttons!==1||this.eraseArc(t)}onEraseMove(t){!this.cacheContext||t.buttons!==1||this.eraseArc(t)}onEraseEnd(){}exportData(){const t=this.cacheCanvasToDataUrl;return[[],this.basicImgInfo,{imgBase64:t}]}clearCacheCanvas(){var t;(t=this.cacheContext)==null||t.clearRect(0,0,this.cacheContext.canvas.width,this.cacheContext.canvas.height),this.render()}clearResult(){this.clearCacheCanvas(),this.history.pushHistory(this.cacheCanvasToDataUrl)}renderPoint(t){a.drawCircleWithFill(this.canvas,this.coord,t,{color:this.color})}renderBorderPoint(t){a.drawCircle(this.canvas,this.coord,t,{color:"black"})}render(){if(super.render(),!this.ctx||!this.cacheCanvas||(this.ctx.save(),this.ctx.globalAlpha=.5,a.drawImg(this.canvas,this.cacheCanvas,{zoom:this.zoom,currentPos:this.currentPos,rotate:this.rotate}),this.ctx.restore(),this.forbidOperation||this.forbidCursorLine))return;const t=this.penSize/2;this.action===o.Erase?this.renderBorderPoint(t):this.renderPoint(t)}undo(){const t=this.history.undo();t&&this.cacheCanvas&&this.updateUrl2CacheContext(t)}redo(){const t=this.history.redo();t&&this.cacheCanvas&&this.updateUrl2CacheContext(t)}}export{v as default};
1
+ import{ImgConversionUtils as a}from"@labelbee/lb-utils";import c from"../../utils/tool/AxisUtils.js";import n from"../../utils/tool/DrawUtils.js";import{EToolName as l,EScribblePattern as o}from"../../constant/tool.js";import u from"../../utils/tool/CommonToolUtils.js";import d from"../../utils/tool/AttributeUtils.js";import h from"../../constant/keyCode.js";import{BasicToolOperation as C}from"./basicToolOperation.js";const v=20,f="white";class p extends C{constructor(t){super(t);this.toolName=l.ScribbleTool,this.action=o.Scribble,this.getOriginCoordinate=i=>c.changePointByZoom(this.getCoordinateUnderZoomByRotate(i),1/this.zoom),this.onMouseDown=i=>{super.onMouseDown(i)||this.forbidMouseOperation||!this.imgInfo||(this.initCacheCanvas(this.imgNode),this.mouseEvents("onMouseDown").call(this,i))},this.onMouseMove=i=>{super.onMouseMove(i)||this.forbidMouseOperation||!this.imgInfo||this.mouseEvents("onMouseMove").call(this,i)},this.onMouseUp=i=>{super.onMouseUp(i)||this.forbidMouseOperation||!this.imgInfo||this.mouseEvents("onMouseUp").call(this,i)},this.mouseEvents=i=>({[o.Scribble]:{onMouseMove:this.onScribbleMove,onMouseUp:this.onScribbleEnd,onMouseDown:this.onScribbleStart},[o.Erase]:{onMouseMove:this.onEraseMove,onMouseUp:this.onEraseEnd,onMouseDown:this.onEraseStart}})[this.action][i],this.setPattern=i=>{switch(this.action=i,i){case o.Erase:{this.setCustomCursor(this.cursorErase);break}default:{this.setCustomCursor("none");break}}};var e;if(this.penSize=v,this.isHidden=!1,this.pointList=[],((e=this.config.attributeList)==null?void 0:e.length)>0){const i=this.config.attributeList[0];this.setDefaultAttribute(i.value)}}get cursorErase(){const t='<?xml version="1.0" encoding="UTF-8"?><svg width="24" heighst="24" viewBox="0 0 48 48" fill="none" xmlns="http://www.w3.org/2000/svg"><g clip-path="url(#icon-65e7e1747c11bad3)"><path d="M44.7818 24.1702L31.918 7.09935L14.1348 20.5L27.5 37L30.8556 34.6643L44.7818 24.1702Z" fill="#141414" stroke="#000000" stroke-width="4" stroke-linejoin="miter"/><path d="M27.4998 37L23.6613 40.0748L13.0978 40.074L10.4973 36.6231L4.06543 28.0876L14.4998 20.2248" stroke="#000000" stroke-width="4" stroke-linejoin="miter"/><path d="M13.2056 40.072L44.5653 40.072" stroke="#000000" stroke-width="4" stroke-linecap="round"/></g><defs><clipPath id="icon-65e7e1747c11bad3"><rect width="48" height="48" fill="#df4c4c"/></clipPath></defs></svg>';return`url(${`data:image/svg+xml;base64,${window.btoa(unescape(encodeURIComponent(t)))}`}) 0 0, auto`}get defaultCursor(){return this.action===o.Erase?this.cursorErase:this.isShowDefaultCursor?"default":"none"}get color(){var t,e;return(e=(t=this==null?void 0:this.defaultAttributeInfo)==null?void 0:t.color)!=null?e:f}get penSizeWithZoom(){return this.penSize/this.zoom}get cacheCanvasToDataUrl(){var t;return(t=this.cacheCanvas)==null?void 0:t.toDataURL("image/png",0)}setPenSize(t){this.penSize=t,this.render()}initCacheCanvas(t){if(this.cacheCanvas||!t)return;const{canvas:e,ctx:i}=a.createCanvas(t);this.cacheCanvas=e,this.cacheContext=i}updateCacheCanvasSize(t){this.cacheCanvas&&(this.cacheCanvas.width=t.width,this.cacheCanvas.height=t.height)}updateUrl2CacheContext(t){a.createImgDom(t).then(e=>{this.cacheContext||this.initCacheCanvas(e),this.cacheContext&&(this.cacheContext.save(),this.clearCacheCanvas(),this.cacheContext.drawImage(e,0,0,e.width,e.height),this.cacheContext.restore(),this.render())})}setImgNode(t,e){super.setImgNode(t,e),this.cacheCanvas?this.updateCacheCanvasSize(t):this.initCacheCanvas(t)}setResult(t){var e,i;let{url:s}=(e=t==null?void 0:t[0])!=null?e:{};if(this.clearCacheCanvas(),s||(s=(i=this.cacheCanvasToDataUrl)!=null?i:""),this.history.initRecord([s],!0),!s){this.render();return}this.updateUrl2CacheContext(s)}onKeyDown(t){if(!u.hotkeyFilter(t)||super.onKeyDown(t)===!1)return;const{keyCode:e}=t,i=d.getAttributeByKeycode(e,this.config.attributeList);i!==void 0&&this.setDefaultAttribute(i),e===h.Z&&!t.ctrlKey&&this.toggleIsHide(),t.ctrlKey&&this.action===o.Scribble&&(this.lineActive=!0,this.render())}onKeyUp(t){super.onKeyUp(t),t.keyCode===h.Ctrl&&(this.lineActive=!1,this.pointList=[],this.render())}toggleIsHide(){this.setIsHidden(!this.isHidden),this.render()}eventBinding(){super.eventBinding()}setDefaultAttribute(t){const e=this.config.attributeList.find(i=>i.value===t);e&&(this.defaultAttribute=e.value,this.defaultAttributeInfo=e,this.emit("changeAttributeSidebar"),this.render())}clearStatusAfterLeave(){this.onScribbleEnd(),this.startPoint=void 0}onMouseLeave(){super.onMouseLeave(),this.clearStatusAfterLeave()}onScribbleStart(t){if(!this.cacheContext)return;this.cacheContext.save(),this.cacheContext.beginPath(),this.cacheContext.strokeStyle=this.color,this.cacheContext.lineWidth=this.penSizeWithZoom,this.cacheContext.lineCap="round",this.cacheContext.lineJoin="round";const e=this.getOriginCoordinate(t);this.cacheContext.moveTo(e.x,e.y),this.startPoint=e,this.lineActive&&this.scribbleOnImgByLine(e)}scribbleOnImgByLine(t){const e=this.cacheContext;!e||(this.pointList.push(t),this.pointList.length>1&&this.pointList.forEach((i,s)=>{if(e.beginPath(),s>0){const r=this.pointList[s-1];e.save(),e.moveTo(r.x,r.y),e.lineTo(i.x,i.y),e.stroke(),e.restore()}}))}onScribbleMove(t){const e=this.getOriginCoordinate(t);if(this.lineActive){this.prePoint=e;return}t.buttons===1&&this.cacheContext&&this.startPoint&&(this.cacheContext.lineTo(e.x,e.y),this.cacheContext.stroke())}onScribbleEnd(){var t,e;this.startPoint&&((t=this.cacheContext)==null||t.closePath(),(e=this.cacheContext)==null||e.restore(),this.startPoint=void 0,this.history.pushHistory(this.cacheCanvasToDataUrl))}eraseArc(t){var e;if(this.cacheContext){const i=this.getOriginCoordinate(t);this.cacheContext.save(),this.cacheContext.beginPath(),this.cacheContext.arc(i.x,i.y,this.penSizeWithZoom/2,0,Math.PI*2,!1),this.cacheContext.clip(),this.cacheContext.clearRect(0,0,this.cacheContext.canvas.width,this.cacheContext.canvas.height),(e=this.cacheContext)==null||e.restore()}}onEraseStart(t){!this.cacheContext||t.buttons!==1||this.eraseArc(t)}onEraseMove(t){!this.cacheContext||t.buttons!==1||this.eraseArc(t)}onEraseEnd(){}exportData(){const t=this.cacheCanvasToDataUrl;return[[],this.basicImgInfo,{imgBase64:t}]}clearCacheCanvas(){var t;(t=this.cacheContext)==null||t.clearRect(0,0,this.cacheContext.canvas.width,this.cacheContext.canvas.height),this.render()}clearResult(){this.clearCacheCanvas(),this.history.pushHistory(this.cacheCanvasToDataUrl)}renderPoint(t){n.drawCircleWithFill(this.canvas,this.coord,t,{color:this.color})}renderBorderPoint(t){n.drawCircle(this.canvas,this.coord,t,{color:"black"})}drawLineSegment(){if(this.prePoint&&this.pointList.length>0){const i=[this.pointList[this.pointList.length-1]].concat(this.prePoint).map(s=>this.getCoordinateUnderZoomByRotateFromImgPoint(s));this.drawStraightLine(i,{color:this.color,lineWidth:this.penSize,globalAlpha:.5})}}render(){if(super.render(),!this.ctx||!this.cacheCanvas||this.isHidden||(this.lineActive&&(this.renderCursorLine(this.color),this.drawLineSegment()),this.ctx.save(),this.ctx.globalAlpha=.5,n.drawImg(this.canvas,this.cacheCanvas,{zoom:this.zoom,currentPos:this.currentPos,rotate:this.rotate}),this.ctx.restore(),this.forbidOperation||this.forbidCursorLine))return;const t=this.penSize/2;this.action===o.Erase?this.renderBorderPoint(t):this.renderPoint(t)}undo(){const t=this.history.undo();t&&this.cacheCanvas&&this.updateUrl2CacheContext(t)}redo(){const t=this.history.redo();t&&this.cacheCanvas&&this.updateUrl2CacheContext(t)}}export{p as default};
@@ -1 +1 @@
1
- import{i18n as R,ImgPosUtils as L,toolStyleConverter as k}from"@labelbee/lb-utils";import{isNumber as E}from"lodash";import{EOperationMode as w,EToolName as y}from"../../constant/tool.js";import B from"../../utils/MathUtils.js";import _,{CoordinateUtils as G}from"../../utils/tool/AxisUtils.js";import F from"../../utils/tool/CanvasUtils.js";import D from"../../utils/tool/CommonToolUtils.js";import H from"../../utils/tool/LineToolUtils.js";import{ELang as x,EGrowthMode as V,EDragStatus as Y}from"../../constant/annotation.js";import P from"../../constant/keyCode.js";import{styleString as X,BASE_ICON as $}from"../../constant/style.js";import U from"../../locales/index.js";import{EMessage as Z}from"../../locales/constants.js";import q from"../../utils/ActionsHistory.js";import O from"../../utils/tool/AttributeUtils.js";import J from"../../utils/tool/DblClickEventListener.js";import g from"../../utils/tool/DrawUtils.js";import Q from"../../utils/tool/RenderDomUtils.js";import A from"../../utils/tool/ZoomUtils.js";import tt from"./eventListener.js";var it=Object.defineProperty,et=Object.defineProperties,st=Object.getOwnPropertyDescriptors,N=Object.getOwnPropertySymbols,ot=Object.prototype.hasOwnProperty,nt=Object.prototype.propertyIsEnumerable,j=(c,t,i)=>t in c?it(c,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):c[t]=i,z=(c,t)=>{for(var i in t||(t={}))ot.call(t,i)&&j(c,i,t[i]);if(N)for(var i of N(t))nt.call(t,i)&&j(c,i,t[i]);return c},T=(c,t)=>et(c,st(t)),rt=(c,t,i)=>new Promise((e,s)=>{var o=n=>{try{r(i.next(n))}catch(a){s(a)}},h=n=>{try{r(i.throw(n))}catch(a){s(a)}},r=n=>n.done?e(n.value):Promise.resolve(n.value).then(o,h);r((i=i.apply(c,t)).next())});const K={[x.Zh]:"cn",[x.US]:"en"},at={min:.2,max:1e3,ratio:.4};class ht extends tt{constructor(t){super();this.isDrag=!1,this.isSpaceKey=!1,this.staticMode=!1,this.operationMode=w.General,this.innerZoom=1,this.basicZoom=.01,this.isSpaceClick=!1,this.isDragStart=!1,this.startTime=0,this.zoomInfo=at,this.initImgPos=()=>rt(this,null,function*(){var d,l;if(!this.imgNode)return;const u=(d=this._imgAttribute)==null?void 0:d.zoomRatio,m=(l=this._imgAttribute)==null?void 0:l.isOriginalSize,{currentPos:f,imgInfo:I,zoom:v}=L.getInitImgPos(this.size,{width:this.imgNode.width,height:this.imgNode.height},this.rotate,u,m);this.setCurrentPos(f),this.currentPosStorage=f,this.setImgInfo(I),this.setZoom(v),this.render(),this.renderBasicCanvas(),this.emit("dependRender"),this.emit("renderZoom",v,f,I)}),this.getCurrentPos=d=>{const{_firstClickCoordinate:l,currentPosStorage:u}=this;try{let m;return l&&u?m={y:u.y+d.y-l.y,x:u.x+d.x-l.x}:m={x:0,y:0},m}catch(m){return console.error(m),{x:0,y:0}}},this.wheelChangePos=(d,l,u)=>{const{currentPos:m,imgNode:f}=this;if(!f){console.error("unable to load image");return}if(this.zoom===this.basicZoom&&l===-1)return;const I=A.wheelChangePos(f,d,l,m,{zoom:u||this.zoom,innerZoom:this.innerZoom,basicZoom:this.basicZoom,zoomMax:this.zoomInfo.max,rotate:this.rotate});if(!I)return;const{currentPos:v,ratio:W,zoom:S,imgInfo:M}=I;this.setZoom(S),this.setCurrentPos(v),this.currentPosStorage=v,this.setImgInfo(M),this.zoomInfo.ratio=W,this.emit("renderZoom",S,v,M)},this.zoomChanged=(d,l=V.Linear)=>{const u=A.zoomChanged(this.zoom,d,l);this.wheelChangePos(this.getGetCenterCoordinate(),u>this.zoom?1:-1,u),this.render(),this.renderBasicCanvas()},this.zoomChangeOnCenter=d=>{this.wheelChangePos(this.getGetCenterCoordinate(),0,d),this.render(),this.renderBasicCanvas()},this.drawImg=()=>{!this.imgNode||this.hiddenImg===!0||(g.drawImg(this.basicCanvas,this.imgNode,{zoom:this.zoom,currentPos:this.currentPos,rotate:this.rotate,imgAttribute:this._imgAttribute}),this.drawStaticImg())},this.drawStaticImg=()=>{!this.staticImgNode||!this.staticMode||(this.clearCanvas(),g.drawImg(this.canvas,this.staticImgNode,{zoom:this.zoom,currentPos:this.currentPos,rotate:this.rotate,imgAttribute:this._imgAttribute}))};var i,e,s,o,h,r,n,a,C,b,p;this.container=t.container,this.config=D.jsonParser(t.config),this.showDefaultCursor=t.showDefaultCursor||!1,this.destroyCanvas(),this.createCanvas(t.size,t.isAppend),this.imgNode=t.imgNode,this.staticMode=(i=t.staticMode)!=null?i:!1,this.isImgError=!t.imgNode,this.basicImgInfo={width:(s=(e=t.imgNode)==null?void 0:e.width)!=null?s:0,height:(h=(o=t.imgNode)==null?void 0:o.height)!=null?h:0,valid:!0,rotate:0},this.forbidOperation=(r=t.forbidOperation)!=null?r:!1,this.forbidBasicResultRender=(n=t.forbidBasicResultRender)!=null?n:!1,this.size=t.size,this.currentPos={x:0,y:0},this.zoom=1,this.coord={x:-1,y:-1},this.currentPosStorage={x:0,y:0},this.isShowCursor=!1,this.attributeLockList=[],this.history=new q,this.style=(a=t.style)!=null?a:D.jsonParser(X),this._imgAttribute=(C=t.imgAttribute)!=null?C:{},this.isHidden=!1,this.dragStatus=Y.Wait,this.defaultAttribute=(b=t==null?void 0:t.defaultAttribute)!=null?b:"",this.forbidCursorLine=!!t.forbidCursorLine,this.lang=(p=t==null?void 0:t.language)!=null?p:x.Zh,R.changeLanguage(K[this.lang]),this.onMouseDown=this.onMouseDown.bind(this),this.onMouseMove=this.onMouseMove.bind(this),this.onMouseLeave=this.onMouseLeave.bind(this),this.onMouseUp=this.onMouseUp.bind(this),this.onKeyDown=this.onKeyDown.bind(this),this.onKeyUp=this.onKeyUp.bind(this),this.onWheel=this.onWheel.bind(this),this.onLeftDblClick=this.onLeftDblClick.bind(this),this.onRightDblClick=this.onRightDblClick.bind(this),this.onClick=this.onClick.bind(this),this.clearImgDrag=this.clearImgDrag.bind(this),this.dblClickListener=new J(this.container,200),this.coordUtils=new G(this),this.coordUtils.setBasicImgInfo(this.basicImgInfo),this.hiddenImg=t.hiddenImg||!1,t.zoomInfo&&(this.zoomInfo=t.zoomInfo)}onContextmenu(t){t.preventDefault()}get ctx(){var t;return this._ctx||((t=this.canvas)==null?void 0:t.getContext("2d"))}get basicCtx(){var t;return(t=this.basicCanvas)==null?void 0:t.getContext("2d")}get rotate(){var t,i;return(i=(t=this.basicImgInfo)==null?void 0:t.rotate)!=null?i:0}get valid(){var t,i;return(i=(t=this.basicImgInfo)==null?void 0:t.valid)!=null?i:!0}get baseIcon(){return $[this.style.color]}get defaultCursor(){return this.showDefaultCursor?"default":"none"}get dataList(){return[]}get innerPosAndZoom(){return{innerZoom:this.innerZoom,currentPosStorage:this.currentPosStorage}}get isShowDefaultCursor(){return this.showDefaultCursor}get isMultiMoveMode(){return this.operationMode===w.MultiMove}get hasMarkerConfig(){return this.config.markerConfigurable===!0&&this.config.markerList&&this.config.markerList.length>0}setZoom(t){this.zoom=t,this.innerZoom=t,this.coordUtils.setZoomAndCurrentPos(this.zoom,this.currentPos)}setCurrentPos(t){this.currentPos=t,this.coordUtils.setZoomAndCurrentPos(this.zoom,this.currentPos)}setReferenceData(t){this.referenceData=t}setImgInfo(t){this.imgInfo=t}setCurrentPosStorage(t){this.currentPosStorage=t}setOperationMode(t){this.operationMode=t}recoverOperationMode(){this.operationMode===w.MultiMove&&this.setOperationMode(w.General)}updatePosition(t){const{zoom:i,currentPos:e}=t;this.setZoom(i),this.setCurrentPos(e),this.currentPosStorage=e,this.renderBasicCanvas(),this.render()}setLang(t){this.lang=t;const i=K[t];R.changeLanguage(i)}setShowDefaultCursor(t){this.showDefaultCursor=t,this.container.style.cursor=this.defaultCursor}setCustomCursor(t){this.container.style.cursor=t}get forbidMouseOperation(){return this.forbidOperation||this.valid===!1}get pixelRatio(){var t;return F.getPixelRatio((t=this.canvas)==null?void 0:t.getContext("2d"))}init(){this.eventUnbinding(),this.initPosition(),this.eventBinding(),this.render(),this.renderBasicCanvas()}destroy(){this.destroyCanvas(),this.eventUnbinding()}updateCanvasBasicStyle(t,i,e){const s=this.pixelRatio;t.style.position="absolute",t.width=i.width*s,t.height=i.height*s,t.style.width=`${i.width}px`,t.style.height=`${i.height}px`,t.style.left="0",t.style.top="0",t.style.zIndex=`${e} `}createCanvas(t,i=!0){var e,s;const o=this.pixelRatio,h=document.createElement("canvas");this.updateCanvasBasicStyle(h,t,0),this.basicCanvas=h;const r=document.createElement("canvas");this.updateCanvasBasicStyle(r,t,10),i&&(this.container.hasChildNodes()?(this.container.insertBefore(r,this.container.childNodes[0]),this.container.insertBefore(h,this.container.childNodes[0])):(this.container.appendChild(h),this.container.appendChild(r))),this.canvas=r,this.container.style.cursor=this.defaultCursor,(e=this.ctx)==null||e.scale(o,o),(s=this.basicCtx)==null||s.scale(o,o),this.ctx&&(this.ctx.imageSmoothingEnabled=!1)}destroyCanvas(){this.canvas&&this.container.contains(this.canvas)&&this.container.removeChild(this.canvas),this.basicCanvas&&this.container.contains(this.basicCanvas)&&this.container.removeChild(this.basicCanvas),this.clearInvalidPage(),this.clearImgDrag()}setStyle(t){this.style=t,this.render()}setImgNode(t,i={}){this.imgNode=t,this.setBasicImgInfo(z({width:t.width,height:t.height,valid:!0,rotate:0},i)),this.updateZoomInfo(),this.isImgError===!0&&(this.isImgError=!1,this.emit("changeAnnotationShow")),typeof i.valid=="boolean"&&this.setValid(i.valid),this.initImgPos(),this.render(),this.renderBasicCanvas()}updateZoomInfo(t=this.imgNode,i=this.size){var e;if(!t||!i)return;const{min:s}=L.getMinZoomByImgAndSize({canvasSize:i,imgSize:{width:t.width,height:t.height},rotate:this.rotate,zoomRatio:(e=this._imgAttribute)==null?void 0:e.zoomRatio});this.zoomInfo=T(z({},this.zoomInfo),{min:s})}setErrorImg(){const t=this.isImgError;this.isImgError=!0,this.imgNode=void 0,this.setBasicImgInfo({width:0,height:0,valid:!0,rotate:0}),t===!1&&this.emit("changeAnnotationShow")}setBasicImgInfo(t){this.basicImgInfo=t,this.coordUtils.setBasicImgInfo(t)}setForbidOperation(t){this.forbidOperation=t,this.setShowDefaultCursor(t),this.render()}setForbidCursorLine(t){this.forbidCursorLine=t,this.render()}setIsHidden(t){this.isHidden=t,this.emit("hiddenChange")}setDefaultAttribute(t){this.defaultAttribute=t}getCoordinateInOrigin(t){const i=this.canvas.getBoundingClientRect();return{x:(t.clientX-i.left-this.currentPos.x)/this.zoom,y:(t.clientY-i.top-this.currentPos.y)/this.zoom}}getTextIconSvg(t=""){var i;return O.getTextIconSvg(t,(i=this.config)==null?void 0:i.attributeList,this.config.attributeConfigurable,this.baseIcon)}setIsShowOrder(t){this.config.isShowOrder=t,this.render()}getCoordinate(t){const i=this.canvas.getBoundingClientRect();return{x:t.clientX-i.left,y:t.clientY-i.top}}getCoordinateUnderZoom(t){const i=this.canvas.getBoundingClientRect();return{x:t.clientX-i.left-this.currentPos.x,y:t.clientY-i.top-this.currentPos.y}}getCoordinateUnderZoomByRotate(t){const{x:i,y:e}=this.getCoordinateUnderZoom(t);return this.basicImgInfo.rotate===90?{x:e,y:this.basicImgInfo.height*this.zoom-i}:this.basicImgInfo.rotate===180?{x:this.basicImgInfo.width*this.zoom-i,y:this.basicImgInfo.height*this.zoom-e}:this.basicImgInfo.rotate===270?{x:this.basicImgInfo.width*this.zoom-e,y:i}:{x:i,y:e}}getGetCenterCoordinate(){return{x:this.size.width/2,y:this.size.height/2}}initPosition(){if(this.basicResult&&this.imgInfo){const{basicResult:t,size:i,imgNode:e,_imgAttribute:s,imgInfo:o,dependToolName:h}=this;if(t&&e&&h){let r=t;switch(h){case y.Polygon:case y.Line:{if(t.pointList){const a=B.calcViewportBoundaries(t.pointList);r={x:a.left,y:a.top,width:a.right-a.left,height:a.bottom-a.top}}break}}const n=L.getBasicRecPos(e,r,i,void 0,s==null?void 0:s.zoomRatio,s==null?void 0:s.isOriginalSize);n&&(this.setCurrentPos(n.currentPos),this.currentPosStorage=this.currentPos,this.setImgInfo(T(z({},o),{width:o.width/this.innerZoom*n.innerZoom,height:o.height/this.innerZoom*n.innerZoom})),this.setZoom(n.innerZoom),this.render(),this.renderBasicCanvas())}}else this.initImgPos()}undo(){this.history.undo()}redo(){this.history.redo()}clearCanvas(){var t;(t=this.ctx)==null||t.clearRect(0,0,this.size.width,this.size.height)}clearBasicCanvas(){var t;(t=this.basicCtx)==null||t.clearRect(0,0,this.size.width,this.size.height)}eventBinding(){this.dblClickListener.addEvent(()=>{},this.onLeftDblClick,this.onRightDblClick),this.container.addEventListener("mousedown",this.onMouseDown),this.container.addEventListener("mousemove",this.onMouseMove),this.container.addEventListener("mouseup",this.onMouseUp),this.container.addEventListener("mouseleave",this.onMouseLeave),this.container.addEventListener("click",this.onClick),this.container.addEventListener("wheel",this.onWheel),document.addEventListener("keydown",this.onKeyDown),document.addEventListener("keyup",this.onKeyUp),window.parent.document.addEventListener("contextmenu",this.onContextmenu,!1)}eventUnbinding(){this.container.removeEventListener("mousedown",this.onMouseDown),this.container.removeEventListener("mousemove",this.onMouseMove),this.container.removeEventListener("mouseup",this.onMouseUp),this.container.removeEventListener("mouseleave",this.onMouseLeave),this.container.removeEventListener("wheel",this.onWheel),this.container.removeEventListener("click",this.onClick),document.removeEventListener("keydown",this.onKeyDown),document.removeEventListener("keyup",this.onKeyUp),window.parent.document.removeEventListener("contextmenu",this.onContextmenu,!1),this.dblClickListener.removeEvent()}clearImgDrag(){this.isDrag=!1,this.isDragStart=!1,this.isSpaceClick=!1,this.startTime=0,this.container.style.cursor=this.defaultCursor,this.forbidCursorLine=!1}clearCursorLine(){this.coord={x:-1,y:-1}}onMouseDown(t){if(!this.canvas||this.isImgError)return!0;const i=this.getCoordinate(t);(this.isSpaceKey&&t.button===0||t.button===2)&&(t.stopPropagation(),this._firstClickCoordinate=i,this.currentPosStorage=this.currentPos,this.isSpaceClick=!0,this.isDragStart=!0,this.startTime=new Date().getTime())}onMouseMove(t){if(!this.canvas||this.isImgError)return!0;const i=this.getCoordinate(t);this.isShowCursor&&(this.coord=i);try{if(!i||!E(i==null?void 0:i.x)||!E(i==null?void 0:i.y))throw new Error("coord error");if(this.coord=i,(this.isSpaceClick||this.isDragStart)&&this._firstClickCoordinate){const e=this.getCurrentPos(i);this.setCurrentPos(e),this.isDrag=!0,this.container.style.cursor="grabbing",this.forbidCursorLine=!0,this.renderBasicCanvas(),this.emit("dependRender"),this.emit("dragMove",{currentPos:e,zoom:this.zoom,imgInfo:this.imgInfo})}this.render()}catch(e){console.error(e)}}onMouseUp(t){if(!this.canvas||this.isImgError)return!0;if(this.container.style.cursor=this.defaultCursor,this.forbidCursorLine=!1,this.isDrag=!1,this.isDragStart=!1,this.isSpaceClick=!1,this.startTime!==0&&this._firstClickCoordinate){const i=new Date().getTime(),e=this.getCoordinate(t);if(i-this.startTime>1e3||this.isSpaceKey===!0||H.calcTwoPointDistance(e,this._firstClickCoordinate)>10)return t.stopPropagation(),this.startTime=0,this.render(),!0}this.startTime=0,this.render()}onMouseLeave(){this.clearImgDrag()}onClick(t){}onLeftDblClick(t){}onRightDblClick(t){this.clearImgDrag()}onKeyDown(t){switch(t.keyCode===P.Alt&&t.preventDefault(),t.keyCode){case P.Space:this.isSpaceKey=!0,t.preventDefault();break;case P.Z:if(t.ctrlKey)return t.shiftKey?this.redo():this.undo(),!1;break}return!0}onKeyUp(t){switch(t.keyCode){case P.Space:this.isSpaceKey=!1;break}}exportCustomData(){return{}}onWheel(t,i=!0){if(!this.imgNode||!this.coord)return;t.preventDefault(),t.stopPropagation();const e=this.getCoordinate(t),s=t.deltaY||t.wheelDelta;let o=0;s>0&&this.zoom>this.zoomInfo.min&&(o=-1),s<0&&this.zoom<this.zoomInfo.max&&(o=1),this.wheelChangePos(e,o),this.emit("dependRender"),i&&this.render(),this.renderBasicCanvas()}renderCursorLine(t=(i=>(i=this.style.lineColor[0])!=null?i:"")()){if(!this.ctx||this.forbidCursorLine||this.forbidOperation)return;const{x:i,y:e}=this.coord;g.drawLine(this.canvas,{x:0,y:e},{x:1e4,y:e},{color:t}),g.drawLine(this.canvas,{x:i,y:0},{x:i,y:1e4},{color:t}),g.drawCircleWithFill(this.canvas,{x:i,y:e},1,{color:"white"})}setSize(t){var i;this.size=t,this.updateZoomInfo(),this.container.contains(this.canvas)&&(this.destroyCanvas(),this.createCanvas(t),this.eventUnbinding(),this.init(),((i=this.basicImgInfo)==null?void 0:i.valid)===!1&&this.renderInvalidPage())}setImgAttribute(t){const i=this._imgAttribute;if(this._imgAttribute=t,(i==null?void 0:i.zoomRatio)!==t.zoomRatio||i.isOriginalSize!==t.isOriginalSize){this.initImgPos();return}this.renderBasicCanvas(),this.render()}clearResult(t){}setValid(t){this.basicImgInfo.valid=t,t===!1?(this.renderInvalidPage(),this.clearResult(!1)):this.clearInvalidPage()}setRotate(t){this.basicImgInfo.rotate=t}setBasicResult(t){this.basicResult=t,this.coordUtils.setBasicResult(t),this.initPosition(),this.emit("dependRender")}setDependName(t,i){this.dependToolName=t,this.coordUtils.setDependInfo(t,i)}setAttributeLockList(t){this.attributeLockList=t,this.render()}setConfig(t){this.config=D.jsonParser(t)}setDataInjectionAtCreation(t){this.dataInjectionAtCreation=t}setRenderEnhance(t){this.renderEnhance=t}setCustomRenderStyle(t){this.customRenderStyle=t}updateRotate(){if(this.dependToolName)return this.emit("messageInfo",U.getMessagesByLocale(Z.NoRotateInDependence,this.lang)),!1;if(this.dataList.length>0)return this.emit("messageInfo",U.getMessagesByLocale(Z.NoRotateNotice,this.lang)),!1;const t=B.getRotate(this.basicImgInfo.rotate);this.basicImgInfo.rotate=t,this.initImgPos(),this.emit("updateResult")}getColor(t="",i=this.config){return k.getColorByConfig({attribute:t,config:i,style:this.style})}getLineColor(t=""){var i,e,s,o,h,r,n,a;if(((i=this.config)==null?void 0:i.attributeConfigurable)===!0){const p=O.getAttributeIndex(t,(s=(e=this.config)==null?void 0:e.attributeList)!=null?s:[])+1;return((r=(h=(o=this.config)==null?void 0:o.attributeList)==null?void 0:h.find(l=>l.value===t))==null?void 0:r.color)?(a=(n=k.getColorByConfig({attribute:t,config:this.config}))==null?void 0:n.valid)==null?void 0:a.stroke:this.style.attributeLineColor?this.style.attributeLineColor[p]:""}const{color:C,lineColor:b}=this.style;return C&&b?b[C]:""}clearInvalidPage(){this._invalidDOM&&this.container&&this.container.contains(this._invalidDOM)&&(this.container.removeChild(this._invalidDOM),this._invalidDOM=void 0)}renderInvalidPage(){!this.container||this._invalidDOM||(this._invalidDOM=Q.renderInvalidPage(this.container,this.size,this.lang))}renderBasicCanvas(){if(!this.basicCanvas)return;this.clearBasicCanvas(),this.drawImg();const t=3;if(!this.forbidBasicResultRender&&this.basicResult&&this.dependToolName)switch(this.dependToolName){case y.Rect:{g.drawRect(this.basicCanvas,_.changeRectByZoom(this.basicResult,this.zoom,this.currentPos),{color:"rgba(204,204,204,1.00)",thickness:t});break}case y.Polygon:{g.drawPolygonWithFillAndLine(this.basicCanvas,_.changePointListByZoom(this.basicResult.pointList,this.zoom,this.currentPos),{fillColor:"transparent",strokeColor:"rgba(204,204,204,1.00)",isClose:!0,thickness:t});break}case y.Line:{g.drawLineWithPointList(this.basicCanvas,_.changePointListByZoom(this.basicResult.pointList,this.zoom,this.currentPos),{color:"rgba(204,204,204,1.00)",thickness:t});break}}}render(){!this.canvas||!this.ctx||!this.imgNode||this.clearCanvas()}changeStyle(t=this.defaultAttribute){this.emit("changeStyle",{attribute:t})}}export{ht as BasicToolOperation};
1
+ import{i18n as R,ImgPosUtils as L,toolStyleConverter as k}from"@labelbee/lb-utils";import{isNumber as E}from"lodash";import{EOperationMode as p,EToolName as y}from"../../constant/tool.js";import B from"../../utils/MathUtils.js";import _,{CoordinateUtils as G}from"../../utils/tool/AxisUtils.js";import F from"../../utils/tool/CanvasUtils.js";import x from"../../utils/tool/CommonToolUtils.js";import H from"../../utils/tool/LineToolUtils.js";import{ELang as z,EGrowthMode as V,EDragStatus as Y}from"../../constant/annotation.js";import w from"../../constant/keyCode.js";import{styleString as X,BASE_ICON as $}from"../../constant/style.js";import U from"../../locales/index.js";import{EMessage as Z}from"../../locales/constants.js";import J from"../../utils/ActionsHistory.js";import A from"../../utils/tool/AttributeUtils.js";import q from"../../utils/tool/DblClickEventListener.js";import v from"../../utils/tool/DrawUtils.js";import Q from"../../utils/tool/RenderDomUtils.js";import O from"../../utils/tool/ZoomUtils.js";import tt from"./eventListener.js";var it=Object.defineProperty,et=Object.defineProperties,st=Object.getOwnPropertyDescriptors,N=Object.getOwnPropertySymbols,ot=Object.prototype.hasOwnProperty,nt=Object.prototype.propertyIsEnumerable,j=(u,t,i)=>t in u?it(u,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):u[t]=i,D=(u,t)=>{for(var i in t||(t={}))ot.call(t,i)&&j(u,i,t[i]);if(N)for(var i of N(t))nt.call(t,i)&&j(u,i,t[i]);return u},T=(u,t)=>et(u,st(t)),rt=(u,t,i)=>new Promise((e,o)=>{var n=r=>{try{a(i.next(r))}catch(l){o(l)}},c=r=>{try{a(i.throw(r))}catch(l){o(l)}},a=r=>r.done?e(r.value):Promise.resolve(r.value).then(n,c);a((i=i.apply(u,t)).next())});const K={[z.Zh]:"cn",[z.US]:"en"},at={min:.2,max:1e3,ratio:.4};class ht extends tt{constructor(t){super();this.isDrag=!1,this.isSpaceKey=!1,this.staticMode=!1,this.operationMode=p.General,this.innerZoom=1,this.basicZoom=.01,this.isSpaceClick=!1,this.isDragStart=!1,this.startTime=0,this.zoomInfo=at,this.initImgPos=()=>rt(this,null,function*(){var d,h;if(!this.imgNode)return;const s=(d=this._imgAttribute)==null?void 0:d.zoomRatio,m=(h=this._imgAttribute)==null?void 0:h.isOriginalSize,{currentPos:g,imgInfo:f,zoom:C}=L.getInitImgPos(this.size,{width:this.imgNode.width,height:this.imgNode.height},this.rotate,s,m);this.setCurrentPos(g),this.currentPosStorage=g,this.setImgInfo(f),this.setZoom(C),this.render(),this.renderBasicCanvas(),this.emit("dependRender"),this.emit("renderZoom",C,g,f)}),this.getCurrentPos=d=>{const{_firstClickCoordinate:h,currentPosStorage:s}=this;try{let m;return h&&s?m={y:s.y+d.y-h.y,x:s.x+d.x-h.x}:m={x:0,y:0},m}catch(m){return console.error(m),{x:0,y:0}}},this.wheelChangePos=(d,h,s)=>{const{currentPos:m,imgNode:g}=this;if(!g){console.error("unable to load image");return}if(this.zoom===this.basicZoom&&h===-1)return;const f=O.wheelChangePos(g,d,h,m,{zoom:s||this.zoom,innerZoom:this.innerZoom,basicZoom:this.basicZoom,zoomMax:this.zoomInfo.max,rotate:this.rotate});if(!f)return;const{currentPos:C,ratio:W,zoom:S,imgInfo:M}=f;this.setZoom(S),this.setCurrentPos(C),this.currentPosStorage=C,this.setImgInfo(M),this.zoomInfo.ratio=W,this.emit("renderZoom",S,C,M)},this.zoomChanged=(d,h=V.Linear)=>{const s=O.zoomChanged(this.zoom,d,h);this.wheelChangePos(this.getGetCenterCoordinate(),s>this.zoom?1:-1,s),this.render(),this.renderBasicCanvas()},this.zoomChangeOnCenter=d=>{this.wheelChangePos(this.getGetCenterCoordinate(),0,d),this.render(),this.renderBasicCanvas()},this.drawStraightLine=(d,h)=>{const{ctx:s}=this;s&&(s.save(),s.lineCap="round",s.lineJoin="round",s.strokeStyle=h.color,s.lineWidth=h.lineWidth,s.globalAlpha=h.globalAlpha,d.forEach((m,g)=>{if(s.beginPath(),g>0){const f=d[g-1];s.save(),s.moveTo(f.x,f.y),s.lineTo(m.x,m.y),s.stroke(),s.restore()}}),s.restore())},this.drawImg=()=>{!this.imgNode||this.hiddenImg===!0||(v.drawImg(this.basicCanvas,this.imgNode,{zoom:this.zoom,currentPos:this.currentPos,rotate:this.rotate,imgAttribute:this._imgAttribute}),this.drawStaticImg())},this.drawStaticImg=()=>{!this.staticImgNode||!this.staticMode||(this.clearCanvas(),v.drawImg(this.canvas,this.staticImgNode,{zoom:this.zoom,currentPos:this.currentPos,rotate:this.rotate,imgAttribute:this._imgAttribute}))};var i,e,o,n,c,a,r,l,b,I,P;this.container=t.container,this.config=x.jsonParser(t.config),this.showDefaultCursor=t.showDefaultCursor||!1,this.destroyCanvas(),this.createCanvas(t.size,t.isAppend),this.imgNode=t.imgNode,this.staticMode=(i=t.staticMode)!=null?i:!1,this.isImgError=!t.imgNode,this.basicImgInfo={width:(o=(e=t.imgNode)==null?void 0:e.width)!=null?o:0,height:(c=(n=t.imgNode)==null?void 0:n.height)!=null?c:0,valid:!0,rotate:0},this.forbidOperation=(a=t.forbidOperation)!=null?a:!1,this.forbidBasicResultRender=(r=t.forbidBasicResultRender)!=null?r:!1,this.size=t.size,this.currentPos={x:0,y:0},this.zoom=1,this.coord={x:-1,y:-1},this.currentPosStorage={x:0,y:0},this.isShowCursor=!1,this.attributeLockList=[],this.history=new J,this.style=(l=t.style)!=null?l:x.jsonParser(X),this._imgAttribute=(b=t.imgAttribute)!=null?b:{},this.isHidden=!1,this.dragStatus=Y.Wait,this.defaultAttribute=(I=t==null?void 0:t.defaultAttribute)!=null?I:"",this.forbidCursorLine=!!t.forbidCursorLine,this.lang=(P=t==null?void 0:t.language)!=null?P:z.Zh,R.changeLanguage(K[this.lang]),this.onMouseDown=this.onMouseDown.bind(this),this.onMouseMove=this.onMouseMove.bind(this),this.onMouseLeave=this.onMouseLeave.bind(this),this.onMouseUp=this.onMouseUp.bind(this),this.onKeyDown=this.onKeyDown.bind(this),this.onKeyUp=this.onKeyUp.bind(this),this.onWheel=this.onWheel.bind(this),this.onLeftDblClick=this.onLeftDblClick.bind(this),this.onRightDblClick=this.onRightDblClick.bind(this),this.onClick=this.onClick.bind(this),this.clearImgDrag=this.clearImgDrag.bind(this),this.dblClickListener=new q(this.container,200),this.coordUtils=new G(this),this.coordUtils.setBasicImgInfo(this.basicImgInfo),this.hiddenImg=t.hiddenImg||!1,t.zoomInfo&&(this.zoomInfo=t.zoomInfo)}onContextmenu(t){t.preventDefault()}get ctx(){var t;return this._ctx||((t=this.canvas)==null?void 0:t.getContext("2d"))}get basicCtx(){var t;return(t=this.basicCanvas)==null?void 0:t.getContext("2d")}get rotate(){var t,i;return(i=(t=this.basicImgInfo)==null?void 0:t.rotate)!=null?i:0}get valid(){var t,i;return(i=(t=this.basicImgInfo)==null?void 0:t.valid)!=null?i:!0}get baseIcon(){return $[this.style.color]}get defaultCursor(){return this.showDefaultCursor?"default":"none"}get dataList(){return[]}get innerPosAndZoom(){return{innerZoom:this.innerZoom,currentPosStorage:this.currentPosStorage}}get isShowDefaultCursor(){return this.showDefaultCursor}get isMultiMoveMode(){return this.operationMode===p.MultiMove}get hasMarkerConfig(){return this.config.markerConfigurable===!0&&this.config.markerList&&this.config.markerList.length>0}setZoom(t){this.zoom=t,this.innerZoom=t,this.coordUtils.setZoomAndCurrentPos(this.zoom,this.currentPos)}setCurrentPos(t){this.currentPos=t,this.coordUtils.setZoomAndCurrentPos(this.zoom,this.currentPos)}setReferenceData(t){this.referenceData=t}setImgInfo(t){this.imgInfo=t}setCurrentPosStorage(t){this.currentPosStorage=t}setOperationMode(t){this.operationMode=t}recoverOperationMode(){this.operationMode===p.MultiMove&&this.setOperationMode(p.General)}updatePosition(t){const{zoom:i,currentPos:e}=t;this.setZoom(i),this.setCurrentPos(e),this.currentPosStorage=e,this.renderBasicCanvas(),this.render()}setLang(t){this.lang=t;const i=K[t];R.changeLanguage(i)}setShowDefaultCursor(t){this.showDefaultCursor=t,this.container.style.cursor=this.defaultCursor}setCustomCursor(t){this.container.style.cursor=t}get forbidMouseOperation(){return this.forbidOperation||this.valid===!1}get pixelRatio(){var t;return F.getPixelRatio((t=this.canvas)==null?void 0:t.getContext("2d"))}init(){this.eventUnbinding(),this.initPosition(),this.eventBinding(),this.render(),this.renderBasicCanvas()}destroy(){this.destroyCanvas(),this.eventUnbinding()}updateCanvasBasicStyle(t,i,e){const o=this.pixelRatio;t.style.position="absolute",t.width=i.width*o,t.height=i.height*o,t.style.width=`${i.width}px`,t.style.height=`${i.height}px`,t.style.left="0",t.style.top="0",t.style.zIndex=`${e} `}createCanvas(t,i=!0){var e,o;const n=this.pixelRatio,c=document.createElement("canvas");this.updateCanvasBasicStyle(c,t,0),this.basicCanvas=c;const a=document.createElement("canvas");this.updateCanvasBasicStyle(a,t,10),i&&(this.container.hasChildNodes()?(this.container.insertBefore(a,this.container.childNodes[0]),this.container.insertBefore(c,this.container.childNodes[0])):(this.container.appendChild(c),this.container.appendChild(a))),this.canvas=a,this.container.style.cursor=this.defaultCursor,(e=this.ctx)==null||e.scale(n,n),(o=this.basicCtx)==null||o.scale(n,n),this.ctx&&(this.ctx.imageSmoothingEnabled=!1)}destroyCanvas(){this.canvas&&this.container.contains(this.canvas)&&this.container.removeChild(this.canvas),this.basicCanvas&&this.container.contains(this.basicCanvas)&&this.container.removeChild(this.basicCanvas),this.clearInvalidPage(),this.clearImgDrag()}setStyle(t){this.style=t,this.render()}setImgNode(t,i={}){this.imgNode=t,this.setBasicImgInfo(D({width:t.width,height:t.height,valid:!0,rotate:0},i)),this.updateZoomInfo(),this.isImgError===!0&&(this.isImgError=!1,this.emit("changeAnnotationShow")),typeof i.valid=="boolean"&&this.setValid(i.valid),this.initImgPos(),this.render(),this.renderBasicCanvas()}updateZoomInfo(t=this.imgNode,i=this.size){var e;if(!t||!i)return;const{min:o}=L.getMinZoomByImgAndSize({canvasSize:i,imgSize:{width:t.width,height:t.height},rotate:this.rotate,zoomRatio:(e=this._imgAttribute)==null?void 0:e.zoomRatio});this.zoomInfo=T(D({},this.zoomInfo),{min:o})}setErrorImg(){const t=this.isImgError;this.isImgError=!0,this.imgNode=void 0,this.setBasicImgInfo({width:0,height:0,valid:!0,rotate:0}),t===!1&&this.emit("changeAnnotationShow")}setBasicImgInfo(t){this.basicImgInfo=t,this.coordUtils.setBasicImgInfo(t)}setForbidOperation(t){this.forbidOperation=t,this.setShowDefaultCursor(t),this.render()}setForbidCursorLine(t){this.forbidCursorLine=t,this.render()}setIsHidden(t){this.isHidden=t,this.emit("hiddenChange")}setDefaultAttribute(t){this.defaultAttribute=t}getCoordinateInOrigin(t){const i=this.canvas.getBoundingClientRect();return{x:(t.clientX-i.left-this.currentPos.x)/this.zoom,y:(t.clientY-i.top-this.currentPos.y)/this.zoom}}getTextIconSvg(t=""){var i;return A.getTextIconSvg(t,(i=this.config)==null?void 0:i.attributeList,this.config.attributeConfigurable,this.baseIcon)}setIsShowOrder(t){this.config.isShowOrder=t,this.render()}getCoordinate(t){const i=this.canvas.getBoundingClientRect();return{x:t.clientX-i.left,y:t.clientY-i.top}}getCoordinateUnderZoom(t){const i=this.canvas.getBoundingClientRect();return{x:t.clientX-i.left-this.currentPos.x,y:t.clientY-i.top-this.currentPos.y}}getCoordinateUnderZoomByRotate(t){const{x:i,y:e}=this.getCoordinateUnderZoom(t);return this.basicImgInfo.rotate===90?{x:e,y:this.basicImgInfo.height*this.zoom-i}:this.basicImgInfo.rotate===180?{x:this.basicImgInfo.width*this.zoom-i,y:this.basicImgInfo.height*this.zoom-e}:this.basicImgInfo.rotate===270?{x:this.basicImgInfo.width*this.zoom-e,y:i}:{x:i,y:e}}getCoordinateUnderZoomByRotateFromImgPoint(t){const{x:i,y:e}=t;return this.basicImgInfo.rotate===90?{x:(this.basicImgInfo.height-e)*this.zoom+this.currentPos.x,y:i*this.zoom+this.currentPos.y}:this.basicImgInfo.rotate===180?{x:(this.basicImgInfo.width-i)*this.zoom+this.currentPos.x,y:(this.basicImgInfo.height-e)*this.zoom+this.currentPos.y}:this.basicImgInfo.rotate===270?{x:e*this.zoom+this.currentPos.x,y:(this.basicImgInfo.width-i)*this.zoom+this.currentPos.y}:{x:i*this.zoom+this.currentPos.x,y:e*this.zoom+this.currentPos.y}}getGetCenterCoordinate(){return{x:this.size.width/2,y:this.size.height/2}}initPosition(){if(this.basicResult&&this.imgInfo){const{basicResult:t,size:i,imgNode:e,_imgAttribute:o,imgInfo:n,dependToolName:c}=this;if(t&&e&&c){let a=t;switch(c){case y.Polygon:case y.Line:{if(t.pointList){const l=B.calcViewportBoundaries(t.pointList);a={x:l.left,y:l.top,width:l.right-l.left,height:l.bottom-l.top}}break}}const r=L.getBasicRecPos(e,a,i,void 0,o==null?void 0:o.zoomRatio,o==null?void 0:o.isOriginalSize);r&&(this.setCurrentPos(r.currentPos),this.currentPosStorage=this.currentPos,this.setImgInfo(T(D({},n),{width:n.width/this.innerZoom*r.innerZoom,height:n.height/this.innerZoom*r.innerZoom})),this.setZoom(r.innerZoom),this.render(),this.renderBasicCanvas())}}else this.initImgPos()}undo(){this.history.undo()}redo(){this.history.redo()}clearCanvas(){var t;(t=this.ctx)==null||t.clearRect(0,0,this.size.width,this.size.height)}clearBasicCanvas(){var t;(t=this.basicCtx)==null||t.clearRect(0,0,this.size.width,this.size.height)}eventBinding(){this.dblClickListener.addEvent(()=>{},this.onLeftDblClick,this.onRightDblClick),this.container.addEventListener("mousedown",this.onMouseDown),this.container.addEventListener("mousemove",this.onMouseMove),this.container.addEventListener("mouseup",this.onMouseUp),this.container.addEventListener("mouseleave",this.onMouseLeave),this.container.addEventListener("click",this.onClick),this.container.addEventListener("wheel",this.onWheel),document.addEventListener("keydown",this.onKeyDown),document.addEventListener("keyup",this.onKeyUp),window.parent.document.addEventListener("contextmenu",this.onContextmenu,!1)}eventUnbinding(){this.container.removeEventListener("mousedown",this.onMouseDown),this.container.removeEventListener("mousemove",this.onMouseMove),this.container.removeEventListener("mouseup",this.onMouseUp),this.container.removeEventListener("mouseleave",this.onMouseLeave),this.container.removeEventListener("wheel",this.onWheel),this.container.removeEventListener("click",this.onClick),document.removeEventListener("keydown",this.onKeyDown),document.removeEventListener("keyup",this.onKeyUp),window.parent.document.removeEventListener("contextmenu",this.onContextmenu,!1),this.dblClickListener.removeEvent()}clearImgDrag(){this.isDrag=!1,this.isDragStart=!1,this.isSpaceClick=!1,this.startTime=0,this.container.style.cursor=this.defaultCursor,this.forbidCursorLine=!1}clearCursorLine(){this.coord={x:-1,y:-1}}onMouseDown(t){if(!this.canvas||this.isImgError)return!0;const i=this.getCoordinate(t);(this.isSpaceKey&&t.button===0||t.button===2)&&(t.stopPropagation(),this._firstClickCoordinate=i,this.currentPosStorage=this.currentPos,this.isSpaceClick=!0,this.isDragStart=!0,this.startTime=new Date().getTime())}onMouseMove(t){if(!this.canvas||this.isImgError)return!0;const i=this.getCoordinate(t);this.isShowCursor&&(this.coord=i);try{if(!i||!E(i==null?void 0:i.x)||!E(i==null?void 0:i.y))throw new Error("coord error");if(this.coord=i,(this.isSpaceClick||this.isDragStart)&&this._firstClickCoordinate){const e=this.getCurrentPos(i);this.setCurrentPos(e),this.isDrag=!0,this.container.style.cursor="grabbing",this.forbidCursorLine=!0,this.renderBasicCanvas(),this.emit("dependRender"),this.emit("dragMove",{currentPos:e,zoom:this.zoom,imgInfo:this.imgInfo})}this.render()}catch(e){console.error(e)}}onMouseUp(t){if(!this.canvas||this.isImgError)return!0;if(this.container.style.cursor=this.defaultCursor,this.forbidCursorLine=!1,this.isDrag=!1,this.isDragStart=!1,this.isSpaceClick=!1,this.startTime!==0&&this._firstClickCoordinate){const i=new Date().getTime(),e=this.getCoordinate(t);if(i-this.startTime>1e3||this.isSpaceKey===!0||H.calcTwoPointDistance(e,this._firstClickCoordinate)>10)return t.stopPropagation(),this.startTime=0,this.render(),!0}this.startTime=0,this.render()}onMouseLeave(){this.clearImgDrag()}onClick(t){}onLeftDblClick(t){}onRightDblClick(t){this.clearImgDrag()}onKeyDown(t){switch(t.keyCode===w.Alt&&t.preventDefault(),t.keyCode){case w.Space:this.isSpaceKey=!0,t.preventDefault();break;case w.Z:if(t.ctrlKey)return t.shiftKey?this.redo():this.undo(),!1;break}return!0}onKeyUp(t){switch(t.keyCode){case w.Space:this.isSpaceKey=!1;break}}exportCustomData(){return{}}onWheel(t,i=!0){if(!this.imgNode||!this.coord)return;t.preventDefault(),t.stopPropagation();const e=this.getCoordinate(t),o=t.deltaY||t.wheelDelta;let n=0;o>0&&this.zoom>this.zoomInfo.min&&(n=-1),o<0&&this.zoom<this.zoomInfo.max&&(n=1),this.wheelChangePos(e,n),this.emit("dependRender"),i&&this.render(),this.renderBasicCanvas()}renderCursorLine(t=(i=>(i=this.style.lineColor[0])!=null?i:"")()){if(!this.ctx||this.forbidCursorLine||this.forbidOperation)return;const{x:i,y:e}=this.coord;v.drawLine(this.canvas,{x:0,y:e},{x:1e4,y:e},{color:t}),v.drawLine(this.canvas,{x:i,y:0},{x:i,y:1e4},{color:t}),v.drawCircleWithFill(this.canvas,{x:i,y:e},1,{color:"white"})}setSize(t){var i;this.size=t,this.updateZoomInfo(),this.container.contains(this.canvas)&&(this.destroyCanvas(),this.createCanvas(t),this.eventUnbinding(),this.init(),((i=this.basicImgInfo)==null?void 0:i.valid)===!1&&this.renderInvalidPage())}setImgAttribute(t){const i=this._imgAttribute;if(this._imgAttribute=t,(i==null?void 0:i.zoomRatio)!==t.zoomRatio||i.isOriginalSize!==t.isOriginalSize){this.initImgPos();return}this.renderBasicCanvas(),this.render()}clearResult(t){}setValid(t){this.basicImgInfo.valid=t,t===!1?(this.renderInvalidPage(),this.clearResult(!1)):this.clearInvalidPage()}setRotate(t){this.basicImgInfo.rotate=t}setBasicResult(t){this.basicResult=t,this.coordUtils.setBasicResult(t),this.initPosition(),this.emit("dependRender")}setDependName(t,i){this.dependToolName=t,this.coordUtils.setDependInfo(t,i)}setAttributeLockList(t){this.attributeLockList=t,this.render()}setConfig(t){this.config=x.jsonParser(t)}setDataInjectionAtCreation(t){this.dataInjectionAtCreation=t}setRenderEnhance(t){this.renderEnhance=t}setCustomRenderStyle(t){this.customRenderStyle=t}updateRotate(){if(this.dependToolName)return this.emit("messageInfo",U.getMessagesByLocale(Z.NoRotateInDependence,this.lang)),!1;if(this.dataList.length>0)return this.emit("messageInfo",U.getMessagesByLocale(Z.NoRotateNotice,this.lang)),!1;const t=B.getRotate(this.basicImgInfo.rotate);this.basicImgInfo.rotate=t,this.initImgPos(),this.emit("updateResult")}getColor(t="",i=this.config){return k.getColorByConfig({attribute:t,config:i,style:this.style})}getLineColor(t=""){var i,e,o,n,c,a,r,l;if(((i=this.config)==null?void 0:i.attributeConfigurable)===!0){const P=A.getAttributeIndex(t,(o=(e=this.config)==null?void 0:e.attributeList)!=null?o:[])+1;return((a=(c=(n=this.config)==null?void 0:n.attributeList)==null?void 0:c.find(h=>h.value===t))==null?void 0:a.color)?(l=(r=k.getColorByConfig({attribute:t,config:this.config}))==null?void 0:r.valid)==null?void 0:l.stroke:this.style.attributeLineColor?this.style.attributeLineColor[P]:""}const{color:b,lineColor:I}=this.style;return b&&I?I[b]:""}clearInvalidPage(){this._invalidDOM&&this.container&&this.container.contains(this._invalidDOM)&&(this.container.removeChild(this._invalidDOM),this._invalidDOM=void 0)}renderInvalidPage(){!this.container||this._invalidDOM||(this._invalidDOM=Q.renderInvalidPage(this.container,this.size,this.lang))}renderBasicCanvas(){if(!this.basicCanvas)return;this.clearBasicCanvas(),this.drawImg();const t=3;if(!this.forbidBasicResultRender&&this.basicResult&&this.dependToolName)switch(this.dependToolName){case y.Rect:{v.drawRect(this.basicCanvas,_.changeRectByZoom(this.basicResult,this.zoom,this.currentPos),{color:"rgba(204,204,204,1.00)",thickness:t});break}case y.Polygon:{v.drawPolygonWithFillAndLine(this.basicCanvas,_.changePointListByZoom(this.basicResult.pointList,this.zoom,this.currentPos),{fillColor:"transparent",strokeColor:"rgba(204,204,204,1.00)",isClose:!0,thickness:t});break}case y.Line:{v.drawLineWithPointList(this.basicCanvas,_.changePointListByZoom(this.basicResult.pointList,this.zoom,this.currentPos),{color:"rgba(204,204,204,1.00)",thickness:t});break}}}render(){!this.canvas||!this.ctx||!this.imgNode||this.clearCanvas()}changeStyle(t=this.defaultAttribute){this.emit("changeStyle",{attribute:t})}}export{ht as BasicToolOperation};
@@ -1,2 +1,2 @@
1
- import R from"../_virtual/MathUtilsWorker.js";import{SEGMENT_NUMBER as E,DEFAULT_TEXT_MAX_WIDTH as I,DEFAULT_FONT as T,ELineTypes as S}from"../constant/tool.js";import{createSmoothCurvePointsFromPointList as v}from"./tool/polygonTool.js";import M from"./tool/PolygonUtils.js";import g from"./VectorUtils.js";var B=Object.defineProperty,C=Object.defineProperties,U=Object.getOwnPropertyDescriptors,O=Object.getOwnPropertySymbols,j=Object.prototype.hasOwnProperty,D=Object.prototype.propertyIsEnumerable,w=Math.pow,A=(e,t,o)=>t in e?B(e,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[t]=o,L=(e,t)=>{for(var o in t||(t={}))j.call(t,o)&&A(e,o,t[o]);if(O)for(var o of O(t))D.call(t,o)&&A(e,o,t[o]);return e},F=(e,t)=>C(e,U(t));class _{static tanAPlusB(t,o){return(t+o)/(1-t*o)}static sinAPlusB(t,o,s,n){return n*t+o*s}static cosAPlusB(t,o,s,n){return o*n-t*s}}const x=class{static getRotate(e){return e+90>=360?e+90-360:e+90}static getLineLength(e,t){return Math.sqrt(Math.pow(t.y-e.y,2)+Math.pow(t.x-e.x,2))}static getTextArea(e,t,o=I,s=T,n){if(typeof t!="string")return{width:0,height:0};const i=e.getContext("2d");i.font=s;let r=0;typeof n=="undefined"&&(n=e&&parseInt(window.getComputedStyle(e).lineHeight,10)||parseInt(window.getComputedStyle(document.body).lineHeight,10));const a=e&&parseInt(window.getComputedStyle(e).fontSize,10)||parseInt(window.getComputedStyle(document.body).fontSize,10)||0,c=t.split(`
2
- `);let f=0;for(let l=0;l<c.length;l++){const u=c[l].split("");let p="";for(let h=0;h<u.length;h++){const y=p+u[h],d=i.measureText(y).width;d>o&&h>0?(p=u[h],r+=n,f=o):(p=y,d>f&&(f=d))}l!==c.length-1&&(r+=n)}return{width:f,height:r+a,lineHeight:n,fontHeight:a}}static getLineCenterPoint(e){const[t,o]=e,s=g.getVector(t,o);return{x:t.x+s.x/2,y:t.y+s.y/2}}static getPerpendicularLine(e){if(e.length!==2)return;const[t,o]=e,s={x:o.x+o.y-t.y,y:o.y-(o.x-t.x)};return[o,s]}static getPerpendicularFootOfLine(e,t){if(e.length!==2)return e;const o=this.getPerpendicularLine(e);if(!o)return e;const[s,n]=o;return this.getFootOfPerpendicular(t,s,n).footPoint}static getQuadrangleFromTriangle(e){if(e.length!==3)return e;const[t,o,s]=e,n={x:s.x+t.x-o.x,y:s.y+t.y-o.y};return[t,o,s,n]}static getRectPerpendicularOffset(e,t,o){const[s,n]=o,i=this.getFootOfPerpendicular(e,s,n).footPoint,r=this.getFootOfPerpendicular(t,s,n).footPoint,a={x:i.x-r.x,y:i.y-r.y},c=g.add(t,a);return g.getVector(e,c)}static getArrayIndex(e,t){return e<0?t+e:e>=t?e-t:e}static getPointListFromPointOffset(e,t,o){const s=this.getArrayIndex(t-1,e.length),n=this.getArrayIndex(t+1,e.length),i=this.getArrayIndex(t-2,e.length),r=[...e];r[t]=g.add(r[t],o);const a=this.getFootOfPerpendicular(r[t],r[i],r[s]).footPoint,c=this.getFootOfPerpendicular(r[t],r[n],r[i]).footPoint;return r[s]=a,r[n]=c,r}static getRectCenterPoint(e){const[t,,o]=e;return{x:(t.x+o.x)/2,y:(t.y+o.y)/2}}static rotateRectPointList(e=5,t){const o=this.getRectCenterPoint(t),{PI:s}=Math,n=Math.sin(e*s/180),i=Math.cos(e*s/180);return t.map(r=>{const a=g.getVector(o,r),c=g.len(a),f=a.y/c,l=a.x/c;return{x:c*_.cosAPlusB(f,l,n,i)+o.x,y:c*_.sinAPlusB(f,l,n,i)+o.y}})}static getRectangleByRightAngle(e,t){if(t.length!==2)return t;const o=x.getPerpendicularFootOfLine(t,e);return x.getQuadrangleFromTriangle([...t,o])}static getRadiusFromQuadrangle(e){const[,t,o]=e,s=o.y-t.y,n=t.x-o.x,i=this.getLineLength(t,o),r=s/i,a=Math.acos(r);return n>0?Math.PI*2-a:a}static getCollectionPointByAnnotationDataPromise(e){const t=e.filter(n=>n.type==="point").map(n=>n.annotation),o=e.filter(n=>!!["polygon","line"].includes(n.type)).map(n=>n.type==="polygon"?F(L({},n.annotation),{pointList:M.concatBeginAndEnd(n.annotation.pointList)}):n.annotation),s=new R;return{promise:new Promise(function(i){s.postMessage({points:t,backgroundList:o}),s.onmessage=r=>{i(r.data),s.terminate()}}),close:()=>{s.terminate()}}}static getCollectionPointByAnnotationData(e){const t=[],o=new Set,s=e.filter(r=>r.type==="point").map(r=>r.annotation),n=e.filter(r=>!!["polygon","line"].includes(r.type)).map(r=>r.type==="polygon"?F(L({},r.annotation),{pointList:M.concatBeginAndEnd(r.annotation.pointList)}):r.annotation),i=(r,a)=>{const{dropFoot:c}=M.getClosestPoint(r,a,S.Line,1,{isClose:!1});if(c!==r){const f=`${c.x} + ${c.y}`;o.has(f)||t.push(r),o.add(f)}};return s.forEach(r=>{i(r,n)}),n.forEach(r=>{let a="";a=r.id,n.forEach((c,f)=>{if(c.id===a)return;const l=[...n];l.splice(f,1),c.pointList.forEach(u=>{i(u,l)})})}),{connectionPoints:t}}static getModifiedRectangleCoordinates(e,t,o){if(e.length!==4)throw new Error("Invalid number of coordinates. Four coordinates are required.");const s=e[0],n=e[1],i=e[2],r=Math.sqrt(w(n.x-s.x,2)+w(n.y-s.y,2)),a=Math.sqrt(w(i.x-n.x,2)+w(i.y-n.y,2)),c=t/r,f=o/a,l={x:s.x+(n.x-s.x)*c,y:s.y+(n.y-s.y)*c},u={x:l.x+(i.x-n.x)*f,y:l.y+(i.y-n.y)*f},p={x:s.x+(u.x-n.x),y:s.y+(u.y-n.y)};return[s,l,u,p]}};let m=x;m.isInRange=(e,t)=>{const o=Math.min(...t),s=Math.max(...t),n=r=>r<=s&&r>=o;return(Array.isArray(e)?e:[e]).every(r=>n(r))},m.withinRange=(e,t)=>{const o=Math.min(...t),s=Math.max(...t);return e>s?s:e<o?o:e},m.calcViewportBoundaries=(e,t=!1,o=E,s=1)=>{if(!e)return{top:0,bottom:0,left:0,right:0};const n=20/s,i=[],r=[];let a=e;t&&(a=v(e,o)),a.forEach(({x:y,y:P})=>{i.push(y),r.push(P)});let c=Math.min(...i),f=Math.max(...i),l=Math.min(...r),u=Math.max(...r);const p=f-c,h=u-l;if(p<n){const y=(n-p)/2;c-=y,f+=y}if(h<n){const y=(n-h)/2;l-=y,u+=y}return{top:l,bottom:u,left:c,right:f}},m.getFootOfPerpendicular=(e,t,o,s=!1,n=!1)=>{let i={x:0,y:0};const r=t.x-o.x,a=t.y-o.y;if(Math.abs(r)<1e-8&&Math.abs(a)<1e-8)return i=t,i;let c=(e.x-t.x)*(t.x-o.x)+(e.y-t.y)*(t.y-o.y);c/=r*r+a*a,i.x=t.x+c*r,i.y=t.y+c*a;const f=x.getLineLength(e,i),l=2,u=Math.min(t.x,o.x),p=Math.max(t.x,o.x),h=Math.min(t.y,o.y),y=Math.max(t.y,o.y),P=!(x.isInRange(e.x,[u,p])||x.isInRange(e.y,[h,y])),d=e.x>p+l||e.x<u-l||e.y>y+l||e.y<h-l;return!n&&(s?P:d)?{footPoint:i,length:Infinity}:{footPoint:i,length:f}};var V=m;export{_ as Trigonometric,V as default};
1
+ import z from"../_virtual/MathUtilsWorker.js";import{SEGMENT_NUMBER as E,DEFAULT_TEXT_MAX_WIDTH as R,DEFAULT_FONT as T,ELineTypes as S}from"../constant/tool.js";import{createSmoothCurvePointsFromPointList as v,isInPolygon as B}from"./tool/polygonTool.js";import O from"./tool/PolygonUtils.js";import P from"./VectorUtils.js";var U=Object.defineProperty,j=Object.defineProperties,N=Object.getOwnPropertyDescriptors,_=Object.getOwnPropertySymbols,V=Object.prototype.hasOwnProperty,X=Object.prototype.propertyIsEnumerable,M=Math.pow,I=(n,o,t)=>o in n?U(n,o,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[o]=t,A=(n,o)=>{for(var t in o||(o={}))V.call(o,t)&&I(n,t,o[t]);if(_)for(var t of _(o))X.call(o,t)&&I(n,t,o[t]);return n},F=(n,o)=>j(n,N(o));class m{static tanAPlusB(o,t){return(o+t)/(1-o*t)}static sinAPlusB(o,t,i,e){return e*o+t*i}static cosAPlusB(o,t,i,e){return t*e-o*i}}var L;(function(n){n[n.Outside=0]="Outside",n[n.PartiallyInside=1]="PartiallyInside",n[n.FullyInside=2]="FullyInside"})(L||(L={}));function D(n,o,t){const i=[{x:t.x-t.width/2,y:t.y-t.height/2,z:t.z-t.depth/2},{x:t.x+t.width/2,y:t.y-t.height/2,z:t.z-t.depth/2},{x:t.x-t.width/2,y:t.y+t.height/2,z:t.z-t.depth/2},{x:t.x+t.width/2,y:t.y+t.height/2,z:t.z-t.depth/2},{x:t.x-t.width/2,y:t.y-t.height/2,z:t.z+t.depth/2},{x:t.x+t.width/2,y:t.y-t.height/2,z:t.z+t.depth/2},{x:t.x-t.width/2,y:t.y+t.height/2,z:t.z+t.depth/2},{x:t.x+t.width/2,y:t.y+t.height/2,z:t.z+t.depth/2}];let e=0;for(let s=0;s<i.length;s++)u.isPointInsideCube(i[s],n,o)&&e++;return e===0?0:e===8?2:1}const g=class{static getRotate(n){return n+90>=360?n+90-360:n+90}static getLineLength(n,o){return Math.sqrt(Math.pow(o.y-n.y,2)+Math.pow(o.x-n.x,2))}static getTextArea(n,o,t=R,i=T,e){if(typeof o!="string")return{width:0,height:0};const s=n.getContext("2d");s.font=i;let r=0;typeof e=="undefined"&&(e=n&&parseInt(window.getComputedStyle(n).lineHeight,10)||parseInt(window.getComputedStyle(document.body).lineHeight,10));const a=n&&parseInt(window.getComputedStyle(n).fontSize,10)||parseInt(window.getComputedStyle(document.body).fontSize,10)||0,c=o.split(`
2
+ `);let y=0;for(let h=0;h<c.length;h++){const f=c[h].split("");let x="";for(let d=0;d<f.length;d++){const p=x+f[d],l=s.measureText(p).width;l>t&&d>0?(x=f[d],r+=e,y=t):(x=p,l>y&&(y=l))}h!==c.length-1&&(r+=e)}return{width:y,height:r+a,lineHeight:e,fontHeight:a}}static getLineCenterPoint(n){const[o,t]=n,i=P.getVector(o,t);return{x:o.x+i.x/2,y:o.y+i.y/2}}static getPerpendicularLine(n){if(n.length!==2)return;const[o,t]=n,i={x:t.x+t.y-o.y,y:t.y-(t.x-o.x)};return[t,i]}static getPerpendicularFootOfLine(n,o){if(n.length!==2)return n;const t=this.getPerpendicularLine(n);if(!t)return n;const[i,e]=t;return this.getFootOfPerpendicular(o,i,e).footPoint}static getQuadrangleFromTriangle(n){if(n.length!==3)return n;const[o,t,i]=n,e={x:i.x+o.x-t.x,y:i.y+o.y-t.y};return[o,t,i,e]}static getRectPerpendicularOffset(n,o,t){const[i,e]=t,s=this.getFootOfPerpendicular(n,i,e).footPoint,r=this.getFootOfPerpendicular(o,i,e).footPoint,a={x:s.x-r.x,y:s.y-r.y},c=P.add(o,a);return P.getVector(n,c)}static getArrayIndex(n,o){return n<0?o+n:n>=o?n-o:n}static getPointListFromPointOffset(n,o,t){const i=this.getArrayIndex(o-1,n.length),e=this.getArrayIndex(o+1,n.length),s=this.getArrayIndex(o-2,n.length),r=[...n];r[o]=P.add(r[o],t);const a=this.getFootOfPerpendicular(r[o],r[s],r[i]).footPoint,c=this.getFootOfPerpendicular(r[o],r[e],r[s]).footPoint;return r[i]=a,r[e]=c,r}static getRectCenterPoint(n){const[o,,t]=n;return{x:(o.x+t.x)/2,y:(o.y+t.y)/2}}static rotateRectPointList(n=5,o){const t=this.getRectCenterPoint(o),{PI:i}=Math,e=Math.sin(n*i/180),s=Math.cos(n*i/180);return o.map(r=>{const a=P.getVector(t,r),c=P.len(a),y=a.y/c,h=a.x/c;return{x:c*m.cosAPlusB(y,h,e,s)+t.x,y:c*m.sinAPlusB(y,h,e,s)+t.y}})}static getRectangleByRightAngle(n,o){if(o.length!==2)return o;const t=g.getPerpendicularFootOfLine(o,n);return g.getQuadrangleFromTriangle([...o,t])}static getRadiusFromQuadrangle(n){const[,o,t]=n,i=t.y-o.y,e=o.x-t.x,s=this.getLineLength(o,t),r=i/s,a=Math.acos(r);return e>0?Math.PI*2-a:a}static getCollectionPointByAnnotationDataPromise(n){const o=n.filter(e=>e.type==="point").map(e=>e.annotation),t=n.filter(e=>!!["polygon","line"].includes(e.type)).map(e=>e.type==="polygon"?F(A({},e.annotation),{pointList:O.concatBeginAndEnd(e.annotation.pointList)}):e.annotation),i=new z;return{promise:new Promise(function(s){i.postMessage({points:o,backgroundList:t}),i.onmessage=r=>{s(r.data),i.terminate()}}),close:()=>{i.terminate()}}}static getCollectionPointByAnnotationData(n){const o=[],t=new Set,i=n.filter(r=>r.type==="point").map(r=>r.annotation),e=n.filter(r=>!!["polygon","line"].includes(r.type)).map(r=>r.type==="polygon"?F(A({},r.annotation),{pointList:O.concatBeginAndEnd(r.annotation.pointList)}):r.annotation),s=(r,a)=>{const{dropFoot:c}=O.getClosestPoint(r,a,S.Line,1,{isClose:!1});if(c!==r){const y=`${c.x} + ${c.y}`;t.has(y)||o.push(r),t.add(y)}};return i.forEach(r=>{s(r,e)}),e.forEach(r=>{let a="";a=r.id,e.forEach((c,y)=>{if(c.id===a)return;const h=[...e];h.splice(y,1),c.pointList.forEach(f=>{s(f,h)})})}),{connectionPoints:o}}static getModifiedRectangleCoordinates(n,o,t){if(n.length!==4)throw new Error("Invalid number of coordinates. Four coordinates are required.");const i=n[0],e=n[1],s=n[2],r=Math.sqrt(M(e.x-i.x,2)+M(e.y-i.y,2)),a=Math.sqrt(M(s.x-e.x,2)+M(s.y-e.y,2)),c=o/r,y=t/a,h={x:i.x+(e.x-i.x)*c,y:i.y+(e.y-i.y)*c},f={x:h.x+(s.x-e.x)*y,y:h.y+(s.y-e.y)*y},x={x:i.x+(f.x-e.x),y:i.y+(f.y-e.y)};return[i,h,f,x]}static isPointInsideCube(n,o,t){const[i,e]=t;return!!(B({x:n.x,y:n.y},o)&&n.z>=i&&n.z<=e)}};let u=g;u.isInRange=(n,o)=>{const t=Math.min(...o),i=Math.max(...o),e=r=>r<=i&&r>=t;return(Array.isArray(n)?n:[n]).every(r=>e(r))},u.withinRange=(n,o)=>{const t=Math.min(...o),i=Math.max(...o);return n>i?i:n<t?t:n},u.calcViewportBoundaries=(n,o=!1,t=E,i=1)=>{if(!n)return{top:0,bottom:0,left:0,right:0};const e=20/i,s=[],r=[];let a=n;o&&(a=v(n,t)),a.forEach(({x:p,y:w})=>{s.push(p),r.push(w)});let c=Math.min(...s),y=Math.max(...s),h=Math.min(...r),f=Math.max(...r);const x=y-c,d=f-h;if(x<e){const p=(e-x)/2;c-=p,y+=p}if(d<e){const p=(e-d)/2;h-=p,f+=p}return{top:h,bottom:f,left:c,right:y}},u.getFootOfPerpendicular=(n,o,t,i=!1,e=!1)=>{let s={x:0,y:0};const r=o.x-t.x,a=o.y-t.y;if(Math.abs(r)<1e-8&&Math.abs(a)<1e-8)return s=o,s;let c=(n.x-o.x)*(o.x-t.x)+(n.y-o.y)*(o.y-t.y);c/=r*r+a*a,s.x=o.x+c*r,s.y=o.y+c*a;const y=g.getLineLength(n,s),h=2,f=Math.min(o.x,t.x),x=Math.max(o.x,t.x),d=Math.min(o.y,t.y),p=Math.max(o.y,t.y),w=!(g.isInRange(n.x,[f,x])||g.isInRange(n.y,[d,p])),l=n.x>x+h||n.x<f-h||n.y>p+h||n.y<d-h;return!e&&(i?w:l)?{footPoint:s,length:Infinity}:{footPoint:s,length:y}},u.calculatePointsInsideBox=n=>{const{indexMap:o,polygon:t,zScope:i,box:e}=n;let s=0;return o.forEach((r,a)=>{const c=a.split("@"),y=Number(c[0]),h=Number(c[1]),f=Number(c[2]),x={x:y-.5,y:h-.5,z:f-.5,width:1,height:1,depth:1},d=D(t,i,x);d===2&&(s+=r.length),(d===1||d===0&&(e.width<=1||e.height<=1))&&r.forEach(p=>{g.isPointInsideCube(p,t,i)&&s++})}),s};var W=u;export{m as Trigonometric,W as default};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@labelbee/lb-annotation",
3
- "version": "1.23.1-alpha.1",
3
+ "version": "1.24.0-alpha.1",
4
4
  "description": "Annotation tool collection",
5
5
  "keywords": [
6
6
  "annotation",
@@ -94,7 +94,7 @@
94
94
  "typescript": "^4.2.3"
95
95
  },
96
96
  "dependencies": {
97
- "@labelbee/lb-utils": "1.15.1-alpha.1",
97
+ "@labelbee/lb-utils": "1.16.0-alpha.1",
98
98
  "@turf/turf": "5.1.6",
99
99
  "color-rgba": "^2.3.0",
100
100
  "lodash": "^4.17.20",