@labelbee/lb-annotation 1.27.0-alpha.53 → 1.27.0-alpha.55
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/core/pointCloud/OrbitControls.js +1 -1
- package/dist/core/pointCloud/index.js +4 -2
- package/dist/core/toolOperation/ViewOperation.js +1 -1
- package/dist/core/toolOperation/basicToolOperation.js +1 -1
- package/dist/core/toolOperation/pointCloud2DRectOperation.js +1 -1
- package/dist/core/toolOperation/rectOperation.js +1 -1
- package/dist/types/core/pointCloud/index.d.ts +42 -2
- package/dist/types/core/toolOperation/ViewOperation.d.ts +15 -1
- package/dist/types/core/toolOperation/basicToolOperation.d.ts +1 -0
- package/dist/types/core/toolOperation/pointCloud2DRectOperation.d.ts +3 -0
- package/dist/types/core/toolOperation/rectOperation.d.ts +1 -1
- package/dist/types/utils/tool/PolygonUtils.d.ts +12 -0
- package/dist/utils/tool/PolygonUtils.js +1 -1
- package/es/core/pointCloud/OrbitControls.js +1 -1
- package/es/core/pointCloud/index.js +4 -2
- package/es/core/toolOperation/ViewOperation.js +1 -1
- package/es/core/toolOperation/basicToolOperation.js +1 -1
- package/es/core/toolOperation/pointCloud2DRectOperation.js +1 -1
- package/es/core/toolOperation/rectOperation.js +1 -1
- package/es/utils/tool/PolygonUtils.js +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var THREE=require("three"),__defProp=Object.defineProperty,__defNormalProp=(y,u,p)=>u in y?__defProp(y,u,{enumerable:!0,configurable:!0,writable:!0,value:p}):y[u]=p,__publicField=(y,u,p)=>(__defNormalProp(y,typeof u!="symbol"?u+"":u,p),p);const _changeEvent={type:"change"},_startEvent={type:"start"},_endEvent={type:"end"};class OrbitControls extends THREE.EventDispatcher{constructor(u,p){super();__publicField(this,"listenToKeyEvents",t=>{t.addEventListener("keydown",onKeyDown),this._domElementKeyEvents=t}),p===void 0&&console.warn('THREE.OrbitControls: The second parameter "domElement" is now mandatory.'),p===document&&console.error('THREE.OrbitControls: "document" should not be used as the target "domElement". Please use "renderer.domElement" instead.'),this.object=u,this.domElement=p,this.domElement.style.touchAction="none",this.enabled=!0,this.target=new THREE.Vector3,this.minDistance=0,this.maxDistance=Infinity,this.minZoom=0,this.maxZoom=Infinity,this.minPolarAngle=0,this.maxPolarAngle=Math.PI,this.minAzimuthAngle=-Infinity,this.maxAzimuthAngle=Infinity,this.enableDamping=!1,this.dampingFactor=.05,this.enableZoom=!0,this.zoomSpeed=1,this.enableRotate=!0,this.rotateSpeed=1,this.enablePan=!0,this.panSpeed=1,this.screenSpacePanning=!0,this.keyPanSpeed=7,this.autoRotate=!1,this.autoRotateSpeed=2,this.keys={LEFT:"ArrowLeft",UP:"ArrowUp",RIGHT:"ArrowRight",BOTTOM:"ArrowDown"},this.mouseButtons={LEFT:THREE.MOUSE.ROTATE,MIDDLE:THREE.MOUSE.DOLLY,RIGHT:THREE.MOUSE.PAN},this.touches={ONE:THREE.TOUCH.ROTATE,TWO:THREE.TOUCH.DOLLY_PAN},this.target0=this.target.clone(),this.position0=this.object.position.clone(),this.zoom0=this.object.zoom,this._domElementKeyEvents=null,this.getPolarAngle=function(){return s.phi},this.getAzimuthalAngle=function(){return s.theta},this.getDistance=function(){return this.object.position.distanceTo(this.target)},this.saveState=function(){e.target0.copy(e.target),e.position0.copy(e.object.position),e.zoom0=e.object.zoom},this.reset=function(){e.target.copy(e.target0),e.object.position.copy(e.position0),e.object.zoom=e.zoom0,e.object.updateProjectionMatrix(),e.dispatchEvent(_changeEvent),e.update(),i=a.NONE},this.update=function(){const t=new THREE.Vector3,n=new THREE.Quaternion().setFromUnitVectors(u.up,new THREE.Vector3(0,1,0)),r=n.clone().invert(),c=new THREE.Vector3,l=new THREE.Quaternion,L=2*Math.PI;return function(){const{position:oe}=e.object;t.copy(oe).sub(e.target),t.applyQuaternion(n),s.setFromVector3(t),e.autoRotate&&i===a.NONE&&C(ae()),e.enableDamping?(s.theta+=d.theta*e.dampingFactor,s.phi+=d.phi*e.dampingFactor):(s.theta+=d.theta,s.phi+=d.phi);let h=e.minAzimuthAngle,m=e.maxAzimuthAngle;return isFinite(h)&&isFinite(m)&&(h<-Math.PI?h+=L:h>Math.PI&&(h-=L),m<-Math.PI?m+=L:m>Math.PI&&(m-=L),h<=m?s.theta=Math.max(h,Math.min(m,s.theta)):s.theta=s.theta>(h+m)/2?Math.max(h,s.theta):Math.min(m,s.theta)),s.phi=Math.max(e.minPolarAngle,Math.min(e.maxPolarAngle,s.phi)),s.makeSafe(),s.radius*=N,s.radius=Math.max(e.minDistance,Math.min(e.maxDistance,s.radius)),e.enableDamping===!0?e.target.addScaledVector(O,e.dampingFactor):e.target.add(O),t.setFromSpherical(s),t.applyQuaternion(r),oe.copy(e.target).add(t),e.object.lookAt(e.target),e.enableDamping===!0?(d.theta*=1-e.dampingFactor,d.phi*=1-e.dampingFactor,O.multiplyScalar(1-e.dampingFactor)):(d.set(0,0,0),O.set(0,0,0)),N=1,S||c.distanceToSquared(e.object.position)>U||8*(1-l.dot(e.object.quaternion))>U?(e.dispatchEvent(_changeEvent),c.copy(e.object.position),l.copy(e.object.quaternion),S=!1,!0):!1}}(),this.dispose=function(){e.domElement.removeEventListener("contextmenu",ee),e.domElement.removeEventListener("pointerdown",Q),e.domElement.removeEventListener("pointercancel",J),e.domElement.removeEventListener("wheel",$),e.domElement.removeEventListener("pointermove",k),e.domElement.removeEventListener("pointerup",_),e._domElementKeyEvents!==null&&e._domElementKeyEvents.removeEventListener("keydown",Ee)};const e=this,a={NONE:-1,ROTATE:0,DOLLY:1,PAN:2,TOUCH_ROTATE:3,TOUCH_PAN:4,TOUCH_DOLLY_PAN:5,TOUCH_DOLLY_ROTATE:6};let i=a.NONE;const U=1e-6,s=new THREE.Spherical,d=new THREE.Spherical;let N=1;const O=new THREE.Vector3;let S=!1;const f=new THREE.Vector2,b=new THREE.Vector2,P=new THREE.Vector2,E=new THREE.Vector2,g=new THREE.Vector2,T=new THREE.Vector2,M=new THREE.Vector2,w=new THREE.Vector2,D=new THREE.Vector2,o=[],R={};function ae(){return 2*Math.PI/60/60*e.autoRotateSpeed}function j(){return Math.pow(.95,e.zoomSpeed)}function C(t){d.theta-=t}function H(t){d.phi-=t}const V=function(){const t=new THREE.Vector3;return function(r,c){t.setFromMatrixColumn(c,0),t.multiplyScalar(-r),O.add(t)}}(),v=function(){const t=new THREE.Vector3;return function(r,c){e.screenSpacePanning===!0?t.setFromMatrixColumn(c,1):(t.setFromMatrixColumn(c,0),t.crossVectors(e.object.up,t)),t.multiplyScalar(r),O.add(t)}}(),A=function(){const t=new THREE.Vector3;return function(r,c){const l=e.domElement;if(e.object.isPerspectiveCamera){const{position:L}=e.object;t.copy(L).sub(e.target);let x=t.length();x*=Math.tan(e.object.fov/2*Math.PI/180),V(2*r*x/l.clientHeight,e.object.matrix),v(2*c*x/l.clientHeight,e.object.matrix)}else e.object.isOrthographicCamera?(V(r*(e.object.right-e.object.left)/e.object.zoom/l.clientWidth,e.object.matrix),v(c*(e.object.top-e.object.bottom)/e.object.zoom/l.clientHeight,e.object.matrix)):(console.warn("WARNING: OrbitControls.js encountered an unknown camera type - pan disabled."),e.enablePan=!1)}}();function I(t){e.object.isPerspectiveCamera?N/=t:e.object.isOrthographicCamera?(e.object.zoom=Math.max(e.minZoom,Math.min(e.maxZoom,e.object.zoom*t)),e.object.updateProjectionMatrix(),S=!0):(console.warn("WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled."),e.enableZoom=!1)}function z(t){e.object.isPerspectiveCamera?N*=t:e.object.isOrthographicCamera?(e.object.zoom=Math.max(e.minZoom,Math.min(e.maxZoom,e.object.zoom/t)),e.object.updateProjectionMatrix(),S=!0):(console.warn("WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled."),e.enableZoom=!1)}function Z(t){f.set(t.clientX,t.clientY)}function ie(t){M.set(t.clientX,t.clientY)}function F(t){E.set(t.clientX,t.clientY)}function se(t){b.set(t.clientX,t.clientY),P.subVectors(b,f).multiplyScalar(e.rotateSpeed);const n=e.domElement;C(2*Math.PI*P.x/n.clientHeight),H(2*Math.PI*P.y/n.clientHeight),f.copy(b),e.update()}function re(t){w.set(t.clientX,t.clientY),D.subVectors(w,M),D.y>0?I(j()):D.y<0&&z(j()),M.copy(w),e.update()}function ce(t){g.set(t.clientX,t.clientY),T.subVectors(g,E).multiplyScalar(e.panSpeed),A(T.x,T.y),E.copy(g),e.update()}function le(t){t.deltaY<0?z(j()):t.deltaY>0&&I(j()),e.update()}function ue(t){let n=!1;switch(t.code){case e.keys.UP:A(0,e.keyPanSpeed),n=!0;break;case e.keys.BOTTOM:A(0,-e.keyPanSpeed),n=!0;break;case e.keys.LEFT:A(e.keyPanSpeed,0),n=!0;break;case e.keys.RIGHT:A(-e.keyPanSpeed,0),n=!0;break}n&&(t.preventDefault(),e.update())}function X(){if(o.length===1)f.set(o[0].pageX,o[0].pageY);else{const t=.5*(o[0].pageX+o[1].pageX),n=.5*(o[0].pageY+o[1].pageY);f.set(t,n)}}function K(){if(o.length===1)E.set(o[0].pageX,o[0].pageY);else{const t=.5*(o[0].pageX+o[1].pageX),n=.5*(o[0].pageY+o[1].pageY);E.set(t,n)}}function q(){const t=o[0].pageX-o[1].pageX,n=o[0].pageY-o[1].pageY,r=Math.sqrt(t*t+n*n);M.set(0,r)}function pe(){e.enableZoom&&q(),e.enablePan&&K()}function de(){e.enableZoom&&q(),e.enableRotate&&X()}function W(t){if(o.length==1)b.set(t.pageX,t.pageY);else{const r=Y(t),c=.5*(t.pageX+r.x),l=.5*(t.pageY+r.y);b.set(c,l)}P.subVectors(b,f).multiplyScalar(e.rotateSpeed);const n=e.domElement;C(2*Math.PI*P.x/n.clientHeight),H(2*Math.PI*P.y/n.clientHeight),f.copy(b)}function G(t){if(o.length===1)g.set(t.pageX,t.pageY);else{const n=Y(t),r=.5*(t.pageX+n.x),c=.5*(t.pageY+n.y);g.set(r,c)}T.subVectors(g,E).multiplyScalar(e.panSpeed),A(T.x,T.y),E.copy(g)}function B(t){const n=Y(t),r=t.pageX-n.x,c=t.pageY-n.y,l=Math.sqrt(r*r+c*c);w.set(0,l),D.set(0,Math.pow(w.y/M.y,e.zoomSpeed)),I(D.y),M.copy(w)}function he(t){e.enableZoom&&B(t),e.enablePan&&G(t)}function me(t){e.enableZoom&&B(t),e.enableRotate&&W(t)}function Q(t){e.enabled!==!1&&(o.length===0&&(e.domElement.setPointerCapture(t.pointerId),e.domElement.addEventListener("pointermove",k),e.domElement.addEventListener("pointerup",_)),Oe(t),t.pointerType==="touch"?ge(t):fe(t))}function k(t){e.enabled!==!1&&(t.pointerType==="touch"?ye(t):be(t))}function _(t){te(t),o.length===0&&(e.domElement.releasePointerCapture(t.pointerId),e.domElement.removeEventListener("pointermove",k),e.domElement.removeEventListener("pointerup",_)),e.dispatchEvent(_endEvent),i=a.NONE}function J(t){te(t)}function fe(t){let n;switch(t.button){case 0:n=e.mouseButtons.LEFT;break;case 1:n=e.mouseButtons.MIDDLE;break;case 2:n=e.mouseButtons.RIGHT;break;default:n=-1}switch(n){case THREE.MOUSE.DOLLY:if(e.enableZoom===!1)return;ie(t),i=a.DOLLY;break;case THREE.MOUSE.ROTATE:if(t.ctrlKey||t.metaKey||t.shiftKey){if(e.enablePan===!1)return;F(t),i=a.PAN}else{if(e.enableRotate===!1)return;Z(t),i=a.ROTATE}break;case THREE.MOUSE.PAN:if(t.ctrlKey||t.metaKey||t.shiftKey){if(e.enableRotate===!1)return;Z(t),i=a.ROTATE}else{if(e.enablePan===!1)return;F(t),i=a.PAN}break;default:i=a.NONE}i!==a.NONE&&e.dispatchEvent(_startEvent)}function be(t){if(e.enabled!==!1)switch(i){case a.ROTATE:if(e.enableRotate===!1)return;se(t);break;case a.DOLLY:if(e.enableZoom===!1)return;re(t);break;case a.PAN:if(e.enablePan===!1)return;ce(t);break}}function $(t){e.enabled===!1||e.enableZoom===!1||i!==a.NONE||(t.preventDefault(),e.dispatchEvent(_startEvent),le(t),e.dispatchEvent(_endEvent))}function Ee(t){e.enabled===!1||e.enablePan===!1||ue(t)}function ge(t){switch(ne(t),o.length){case 1:switch(e.touches.ONE){case THREE.TOUCH.ROTATE:if(e.enableRotate===!1)return;X(),i=a.TOUCH_ROTATE;break;case THREE.TOUCH.PAN:if(e.enablePan===!1)return;K(),i=a.TOUCH_PAN;break;default:i=a.NONE}break;case 2:switch(e.touches.TWO){case THREE.TOUCH.DOLLY_PAN:if(e.enableZoom===!1&&e.enablePan===!1)return;pe(),i=a.TOUCH_DOLLY_PAN;break;case THREE.TOUCH.DOLLY_ROTATE:if(e.enableZoom===!1&&e.enableRotate===!1)return;de(),i=a.TOUCH_DOLLY_ROTATE;break;default:i=a.NONE}break;default:i=a.NONE}i!==a.NONE&&e.dispatchEvent(_startEvent)}function ye(t){switch(ne(t),i){case a.TOUCH_ROTATE:if(e.enableRotate===!1)return;W(t),e.update();break;case a.TOUCH_PAN:if(e.enablePan===!1)return;G(t),e.update();break;case a.TOUCH_DOLLY_PAN:if(e.enableZoom===!1&&e.enablePan===!1)return;he(t),e.update();break;case a.TOUCH_DOLLY_ROTATE:if(e.enableZoom===!1&&e.enableRotate===!1)return;me(t),e.update();break;default:i=a.NONE}}function ee(t){e.enabled!==!1&&t.preventDefault()}function Oe(t){o.push(t)}function te(t){delete R[t.pointerId];for(let n=0;n<o.length;n++)if(o[n].pointerId==t.pointerId){o.splice(n,1);return}}function ne(t){let n=R[t.pointerId];n===void 0&&(n=new THREE.Vector2,R[t.pointerId]=n),n.set(t.pageX,t.pageY)}function Y(t){const n=t.pointerId===o[0].pointerId?o[1]:o[0];return R[n.pointerId]}e.domElement.addEventListener("contextmenu",ee),e.domElement.addEventListener("pointerdown",Q),e.domElement.addEventListener("pointercancel",J),e.domElement.addEventListener("wheel",$,{passive:!1}),this.update()}}exports.OrbitControls=OrbitControls;
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var THREE=require("three"),__defProp=Object.defineProperty,__defNormalProp=(y,u,p)=>u in y?__defProp(y,u,{enumerable:!0,configurable:!0,writable:!0,value:p}):y[u]=p,__publicField=(y,u,p)=>(__defNormalProp(y,typeof u!="symbol"?u+"":u,p),p);const _changeEvent={type:"change"},_startEvent={type:"start"},_endEvent={type:"end"};class OrbitControls extends THREE.EventDispatcher{constructor(u,p){super();__publicField(this,"listenToKeyEvents",t=>{t.addEventListener("keydown",onKeyDown),this._domElementKeyEvents=t}),p===void 0&&console.warn('THREE.OrbitControls: The second parameter "domElement" is now mandatory.'),p===document&&console.error('THREE.OrbitControls: "document" should not be used as the target "domElement". Please use "renderer.domElement" instead.'),this.object=u,this.domElement=p,this.domElement.style.touchAction="none",this.enabled=!0,this.target=new THREE.Vector3,this.minDistance=0,this.maxDistance=Infinity,this.minZoom=0,this.maxZoom=Infinity,this.minPolarAngle=0,this.maxPolarAngle=Math.PI,this.minAzimuthAngle=-Infinity,this.maxAzimuthAngle=Infinity,this.enableDamping=!1,this.dampingFactor=.05,this.enableZoom=!0,this.zoomSpeed=1,this.enableRotate=!0,this.rotateSpeed=1,this.enablePan=!0,this.panSpeed=1,this.screenSpacePanning=!0,this.keyPanSpeed=7,this.autoRotate=!1,this.autoRotateSpeed=2,this.keys={LEFT:"ArrowLeft",UP:"ArrowUp",RIGHT:"ArrowRight",BOTTOM:"ArrowDown"},this.mouseButtons={LEFT:THREE.MOUSE.ROTATE,MIDDLE:THREE.MOUSE.DOLLY,RIGHT:THREE.MOUSE.PAN},this.touches={ONE:THREE.TOUCH.ROTATE,TWO:THREE.TOUCH.DOLLY_PAN},this.target0=this.target.clone(),this.position0=this.object.position.clone(),this.zoom0=this.object.zoom,this._domElementKeyEvents=null,this.getPolarAngle=function(){return s.phi},this.getAzimuthalAngle=function(){return s.theta},this.getDistance=function(){return this.object.position.distanceTo(this.target)},this.saveState=function(){e.target0.copy(e.target),e.position0.copy(e.object.position),e.zoom0=e.object.zoom},this.reset=function(){e.target.copy(e.target0),e.object.position.copy(e.position0),e.object.zoom=e.zoom0,e.object.updateProjectionMatrix(),e.dispatchEvent(_changeEvent),e.update(),i=a.NONE},this.update=function(){const t=new THREE.Vector3,n=new THREE.Quaternion().setFromUnitVectors(u.up,new THREE.Vector3(0,1,0)),r=n.clone().invert(),c=new THREE.Vector3,l=new THREE.Quaternion,L=2*Math.PI;return function(){const{position:oe}=e.object;t.copy(oe).sub(e.target),t.applyQuaternion(n),s.setFromVector3(t),e.autoRotate&&i===a.NONE&&C(ae()),e.enableDamping?(s.theta+=h.theta*e.dampingFactor,s.phi+=h.phi*e.dampingFactor):(s.theta+=h.theta,s.phi+=h.phi);let d=e.minAzimuthAngle,m=e.maxAzimuthAngle;return isFinite(d)&&isFinite(m)&&(d<-Math.PI?d+=L:d>Math.PI&&(d-=L),m<-Math.PI?m+=L:m>Math.PI&&(m-=L),d<=m?s.theta=Math.max(d,Math.min(m,s.theta)):s.theta=s.theta>(d+m)/2?Math.max(d,s.theta):Math.min(m,s.theta)),s.phi=Math.max(e.minPolarAngle,Math.min(e.maxPolarAngle,s.phi)),s.makeSafe(),s.radius*=N,s.radius=Math.max(e.minDistance,Math.min(e.maxDistance,s.radius)),e.enableDamping===!0?e.target.addScaledVector(O,e.dampingFactor):e.target.add(O),t.setFromSpherical(s),t.applyQuaternion(r),oe.copy(e.target).add(t),e.object.lookAt(e.target),e.enableDamping===!0?(h.theta*=1-e.dampingFactor,h.phi*=1-e.dampingFactor,O.multiplyScalar(1-e.dampingFactor)):(h.set(0,0,0),O.set(0,0,0)),N=1,S||c.distanceToSquared(e.object.position)>U||8*(1-l.dot(e.object.quaternion))>U?(e.dispatchEvent(_changeEvent),c.copy(e.object.position),l.copy(e.object.quaternion),S=!1,!0):!1}}(),this.dispose=function(){e.domElement.removeEventListener("contextmenu",ee),e.domElement.removeEventListener("pointerdown",Q),e.domElement.removeEventListener("pointercancel",J),e.domElement.removeEventListener("wheel",$),e.domElement.removeEventListener("pointermove",I),e.domElement.removeEventListener("pointerup",_),e._domElementKeyEvents!==null&&e._domElementKeyEvents.removeEventListener("keydown",Ee)};const e=this,a={NONE:-1,ROTATE:0,DOLLY:1,PAN:2,TOUCH_ROTATE:3,TOUCH_PAN:4,TOUCH_DOLLY_PAN:5,TOUCH_DOLLY_ROTATE:6};let i=a.NONE;const U=1e-6,s=new THREE.Spherical,h=new THREE.Spherical;let N=1;const O=new THREE.Vector3;let S=!1;const f=new THREE.Vector2,b=new THREE.Vector2,P=new THREE.Vector2,E=new THREE.Vector2,g=new THREE.Vector2,T=new THREE.Vector2,M=new THREE.Vector2,w=new THREE.Vector2,D=new THREE.Vector2,o=[],R={};function ae(){return 2*Math.PI/60/60*e.autoRotateSpeed}function j(){return Math.pow(.95,e.zoomSpeed)}function C(t){h.theta-=t}function H(t){h.phi-=t}const V=function(){const t=new THREE.Vector3;return function(r,c){t.setFromMatrixColumn(c,0),t.multiplyScalar(-r),O.add(t)}}(),v=function(){const t=new THREE.Vector3;return function(r,c){e.screenSpacePanning===!0?t.setFromMatrixColumn(c,1):(t.setFromMatrixColumn(c,0),t.crossVectors(e.object.up,t)),t.multiplyScalar(r),O.add(t)}}(),A=function(){const t=new THREE.Vector3;return function(r,c){const l=e.domElement;if(e.object.isPerspectiveCamera){const{position:L}=e.object;t.copy(L).sub(e.target);let x=t.length();x*=Math.tan(e.object.fov/2*Math.PI/180),V(2*r*x/l.clientHeight,e.object.matrix),v(2*c*x/l.clientHeight,e.object.matrix)}else e.object.isOrthographicCamera?(V(r*(e.object.right-e.object.left)/e.object.zoom/l.clientWidth,e.object.matrix),v(c*(e.object.top-e.object.bottom)/e.object.zoom/l.clientHeight,e.object.matrix)):(console.warn("WARNING: OrbitControls.js encountered an unknown camera type - pan disabled."),e.enablePan=!1)}}();function k(t){e.object.isPerspectiveCamera?N/=t:e.object.isOrthographicCamera?(e.object.zoom=Math.max(e.minZoom,Math.min(e.maxZoom,e.object.zoom*t)),e.object.updateProjectionMatrix(),S=!0):(console.warn("WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled."),e.enableZoom=!1)}function z(t){e.object.isPerspectiveCamera?N*=t:e.object.isOrthographicCamera?(e.object.zoom=Math.max(e.minZoom,Math.min(e.maxZoom,e.object.zoom/t)),e.object.updateProjectionMatrix(),S=!0):(console.warn("WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled."),e.enableZoom=!1)}function Z(t){f.set(t.clientX,t.clientY)}function ie(t){M.set(t.clientX,t.clientY)}function F(t){E.set(t.clientX,t.clientY)}function se(t){b.set(t.clientX,t.clientY),P.subVectors(b,f).multiplyScalar(e.rotateSpeed);const n=e.domElement;C(2*Math.PI*P.x/n.clientHeight),H(2*Math.PI*P.y/n.clientHeight),f.copy(b),e.update()}function re(t){w.set(t.clientX,t.clientY),D.subVectors(w,M),D.y>0?k(j()):D.y<0&&z(j()),M.copy(w),e.update()}function ce(t){g.set(t.clientX,t.clientY),T.subVectors(g,E).multiplyScalar(e.panSpeed),A(T.x,T.y),E.copy(g),e.update()}function le(t){t.deltaY<0?z(j()):t.deltaY>0&&k(j()),e.update()}function ue(t){let n=!1;switch(t.code){case e.keys.UP:A(0,e.keyPanSpeed),n=!0;break;case e.keys.BOTTOM:A(0,-e.keyPanSpeed),n=!0;break;case e.keys.LEFT:A(e.keyPanSpeed,0),n=!0;break;case e.keys.RIGHT:A(-e.keyPanSpeed,0),n=!0;break}n&&(t.preventDefault(),e.update())}function X(){if(o.length===1)f.set(o[0].pageX,o[0].pageY);else{const t=.5*(o[0].pageX+o[1].pageX),n=.5*(o[0].pageY+o[1].pageY);f.set(t,n)}}function K(){if(o.length===1)E.set(o[0].pageX,o[0].pageY);else{const t=.5*(o[0].pageX+o[1].pageX),n=.5*(o[0].pageY+o[1].pageY);E.set(t,n)}}function q(){const t=o[0].pageX-o[1].pageX,n=o[0].pageY-o[1].pageY,r=Math.sqrt(t*t+n*n);M.set(0,r)}function pe(){e.enableZoom&&q(),e.enablePan&&K()}function he(){e.enableZoom&&q(),e.enableRotate&&X()}function W(t){if(o.length==1)b.set(t.pageX,t.pageY);else{const r=Y(t),c=.5*(t.pageX+r.x),l=.5*(t.pageY+r.y);b.set(c,l)}P.subVectors(b,f).multiplyScalar(e.rotateSpeed);const n=e.domElement;C(2*Math.PI*P.x/n.clientHeight),H(2*Math.PI*P.y/n.clientHeight),f.copy(b)}function G(t){if(o.length===1)g.set(t.pageX,t.pageY);else{const n=Y(t),r=.5*(t.pageX+n.x),c=.5*(t.pageY+n.y);g.set(r,c)}T.subVectors(g,E).multiplyScalar(e.panSpeed),A(T.x,T.y),E.copy(g)}function B(t){const n=Y(t),r=t.pageX-n.x,c=t.pageY-n.y,l=Math.sqrt(r*r+c*c);w.set(0,l),D.set(0,Math.pow(w.y/M.y,e.zoomSpeed)),k(D.y),M.copy(w)}function de(t){e.enableZoom&&B(t),e.enablePan&&G(t)}function me(t){e.enableZoom&&B(t),e.enableRotate&&W(t)}function Q(t){e.enabled!==!1&&(o.length===0&&(e.domElement.setPointerCapture(t.pointerId),e.domElement.addEventListener("pointermove",I),e.domElement.addEventListener("pointerup",_)),Oe(t),t.pointerType==="touch"?ge(t):fe(t))}function I(t){e.enabled!==!1&&(t.pointerType==="touch"?ye(t):be(t))}function _(t){te(t),o.length===0&&(e.domElement.releasePointerCapture(t.pointerId),e.domElement.removeEventListener("pointermove",I),e.domElement.removeEventListener("pointerup",_)),e.dispatchEvent(_endEvent),i=a.NONE}function J(t){te(t)}function fe(t){let n;switch(t.button){case 0:n=e.mouseButtons.LEFT;break;case 1:n=e.mouseButtons.MIDDLE;break;case 2:n=e.mouseButtons.RIGHT;break;default:n=-1}switch(n){case THREE.MOUSE.DOLLY:if(e.enableZoom===!1)return;ie(t),i=a.DOLLY;break;case THREE.MOUSE.ROTATE:if(t.ctrlKey||t.metaKey||t.shiftKey){if(e.enablePan===!1)return;F(t),i=a.PAN}else{if(e.enableRotate===!1)return;Z(t),i=a.ROTATE}break;case THREE.MOUSE.PAN:if(t.ctrlKey||t.metaKey||t.shiftKey){if(e.enableRotate===!1)return;Z(t),i=a.ROTATE}else{if(e.enablePan===!1)return;F(t),i=a.PAN}break;default:i=a.NONE}i!==a.NONE&&e.dispatchEvent(_startEvent)}function be(t){if(e.enabled!==!1)switch(i){case a.ROTATE:if(e.enableRotate===!1)return;se(t);break;case a.DOLLY:if(e.enableZoom===!1)return;re(t);break;case a.PAN:if(e.enablePan===!1)return;ce(t);break}}function $(t){e.enabled===!1||e.enableZoom===!1||i!==a.NONE||(t.preventDefault(),e.dispatchEvent(_startEvent),le(t),e.dispatchEvent(_endEvent))}function Ee(t){e.enabled===!1||e.enablePan===!1||ue(t)}function ge(t){switch(ne(t),o.length){case 1:switch(e.touches.ONE){case THREE.TOUCH.ROTATE:if(e.enableRotate===!1)return;X(),i=a.TOUCH_ROTATE;break;case THREE.TOUCH.PAN:if(e.enablePan===!1)return;K(),i=a.TOUCH_PAN;break;default:i=a.NONE}break;case 2:switch(e.touches.TWO){case THREE.TOUCH.DOLLY_PAN:if(e.enableZoom===!1&&e.enablePan===!1)return;pe(),i=a.TOUCH_DOLLY_PAN;break;case THREE.TOUCH.DOLLY_ROTATE:if(e.enableZoom===!1&&e.enableRotate===!1)return;he(),i=a.TOUCH_DOLLY_ROTATE;break;default:i=a.NONE}break;default:i=a.NONE}i!==a.NONE&&e.dispatchEvent(_startEvent)}function ye(t){switch(ne(t),i){case a.TOUCH_ROTATE:if(e.enableRotate===!1)return;W(t),e.update();break;case a.TOUCH_PAN:if(e.enablePan===!1)return;G(t),e.update();break;case a.TOUCH_DOLLY_PAN:if(e.enableZoom===!1&&e.enablePan===!1)return;de(t),e.update();break;case a.TOUCH_DOLLY_ROTATE:if(e.enableZoom===!1&&e.enableRotate===!1)return;me(t),e.update();break;default:i=a.NONE}}function ee(t){e.enabled!==!1&&(t.preventDefault(),e.dispatchEvent({type:"rightClick",originalEvent:t}))}function Oe(t){o.push(t)}function te(t){delete R[t.pointerId];for(let n=0;n<o.length;n++)if(o[n].pointerId==t.pointerId){o.splice(n,1);return}}function ne(t){let n=R[t.pointerId];n===void 0&&(n=new THREE.Vector2,R[t.pointerId]=n),n.set(t.pageX,t.pageY)}function Y(t){const n=t.pointerId===o[0].pointerId?o[1]:o[0];return R[n.pointerId]}e.domElement.addEventListener("contextmenu",ee),e.domElement.addEventListener("pointerdown",Q),e.domElement.addEventListener("pointercancel",J),e.domElement.addEventListener("wheel",$,{passive:!1}),this.update()}}exports.OrbitControls=OrbitControls;
|
|
@@ -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(
|
|
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(w){if(w&&w.__esModule)return w;var t=Object.create(null);return w&&Object.keys(w).forEach(function(e){if(e!=="default"){var i=Object.getOwnPropertyDescriptor(w,e);Object.defineProperty(t,e,i.get?i:{enumerable:!0,get:function(){return w[e]}})}}),t.default=w,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=(w,t,e)=>t in w?__defProp(w,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):w[t]=e,__spreadValues=(w,t)=>{for(var e in t||(t={}))__hasOwnProp.call(t,e)&&__defNormalProp(w,e,t[e]);if(__getOwnPropSymbols)for(var e of __getOwnPropSymbols(t))__propIsEnum.call(t,e)&&__defNormalProp(w,e,t[e]);return w},__spreadProps=(w,t)=>__defProps(w,__getOwnPropDescs(t)),__async=(w,t,e)=>new Promise((i,r)=>{var a=l=>{try{s(e.next(l))}catch(u){r(u)}},h=l=>{try{s(e.throw(l))}catch(u){r(u)}},s=l=>l.done?i(l.value):Promise.resolve(l.value).then(a,h);s((e=e.apply(w,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:a="#4C4C4C",config:h,isSegment:s,checkMode:l,hiddenText:u=!1}){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.workerLoading=!1,this.raycaster=new THREE__namespace.Raycaster,this.pointer=new THREE__namespace.Vector2,this.hiddenText=!1,this.nextTick=()=>{!this.segmentOperation||this.segmentOperation._raycasting()},this.keydown=o=>{if(!!this.store)switch(o.key){case" ":this.controls.enablePan=!0,this.store.setForbidOperation(!0);break}},this.keyup=o=>{if(!!this.store)switch(o.key){case" ":this.controls.enablePan=!1,this.store.setForbidOperation(!1);break}},this.addSphereToSense=(o,n="blue")=>{var c;const d=(c=o.id)!=null?c:uuid();this.removeObjectByName(d,"sphere");const{radius:x,widthSegments:p,heightSegments:f}=lbUtils.DEFAULT_SPHERE_PARAMS,{center:g}=o,m=new THREE__namespace.Group,y=new THREE__namespace.SphereGeometry(x,p,f),b=new THREE__namespace.MeshBasicMaterial({color:n}),C=new THREE__namespace.Mesh(y,b);C.position.set(g.x,g.y,g.z),m.add(C),m.name=`sphere${d}`,this.scene.add(m)},this.generateSphere=o=>{const{fill:n}=this.getColorFromConfig(o.attribute);this.addSphereToSense(o,n),this.render()},this.generateSpheres=o=>{o.forEach(n=>{const{fill:c}=this.getColorFromConfig(n.attribute);this.addSphereToSense(n,c)}),this.render()},this.addBoxToSense=(o,n=16777215)=>{var c;const d=(c=o.id)!=null?c:uuid();this.removeObjectByName(d,"box");const{center:x,width:p,height:f,depth:g,rotation:m}=o,y=new THREE__namespace.Group,b=new THREE__namespace.BoxGeometry(p,f,g),C=new THREE__namespace.MeshBasicMaterial({color:"blue"}),v=new THREE__namespace.Mesh(b,C),B=new THREE__namespace.BoxHelper(v,n),O=this.generateBoxArrow(o),M=this.generateBoxTrackID(o);M&&y.add(M);const P=this.generateBoxAttributeLabel(o);P&&y.add(P),y.add(B),y.add(O),x&&y.position.set(x.x,x.y,x.z),m&&y.rotation.set(0,0,m),y.name=`box${d}`;const z=new THREE__namespace.BoxGeometry(p,f,g),L=new THREE__namespace.MeshBasicMaterial({visible:!1}),S=new THREE__namespace.Mesh(z,L);S.userData={selectedID:d},y.add(S),this.scene.add(y)},this.applyCameraTarget=o=>{if(this.camera.type==="OrthographicCamera"&&o){const n=this.getOrthographicCameraTarget(o);this.updateCameraZoom(o.zoom),this.updateCamera(o.position,n)}},this.initShaderMaterial=()=>({vertexShader:`
|
|
2
2
|
attribute vec3 dimensions;
|
|
3
3
|
varying vec3 vDimensions;
|
|
4
4
|
uniform float pointSize;
|
|
@@ -28,4 +28,6 @@
|
|
|
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:p}=yield this.cacheInstance.loadPCDFile(c),x=new THREE__namespace.BufferGeometry;x.setAttribute("position",new THREE__namespace.BufferAttribute(d,3)),this.isSegment||x.setAttribute("dimensions",new THREE__namespace.BufferAttribute(p,3)),this.initCloudData(d);const g=new THREE__namespace.Points(x);this.renderPointCloud(g,h),this.emit("loadPCDFileEnd")}),this.getHighlightIndexByMappingImgList=n=>__async(this,[n],function*({mappingImgList:c,points:h}){const d=u=>__async(this,null,function*(){try{return yield ImgUtils.default.load(u)}catch(m){return console.error("Error loading image:",m),null}}),p=c.length===0?[]:(yield Promise.all(c.map(u=>__async(this,null,function*(){let m=yield d(u.url);return!m&&u.fallbackUrl&&(m=yield d(u.fallbackUrl)),m})))).filter(u=>u!==null),x=c.map((u,m)=>{var f;if(this.cacheInstance.cache2DHighlightIndex.has(u.url))return(f=this.cacheInstance.cache2DHighlightIndex.get(u.url))!=null?f:[];const w=matrix.getHighlightIndexByPoints({points:h,calib:u.calib,width:p[m].width,height:p[m].height});return this.cacheInstance.cache2DHighlightIndex.set(u.url,w),w});return matrix.mergeHighlightList(x)}),this.filterPreResult=(n,c,h)=>__async(this,null,function*(){const{points:d}=yield this.cacheInstance.loadPCDFile(n),p=yield this.cacheInstance.loadIndexMap(n,d);return new Promise(x=>{const g=h.map(u=>{const m=MathUtils.default.calculatePointsInsideBox({indexMap:p,polygon:matrix.getCuboidFromPointCloudBox(u).polygonPointList,zScope:[u.center.z-u.depth/2,u.center.z+u.depth/2],box:u}),f=m>=c.lowerLimitPointsNumInBox;return __spreadProps(__spreadValues({},u),{valid:f,count:m})});x(g)})}),this.loadPCDFileByBox=(n,c,h)=>__async(this,null,function*(){const d=(g,u)=>__async(this,null,function*(){const{width:m=0,height:f=0,depth:w=0}=h!=null?h:{},C=yield this.filterPointsByBox(__spreadProps(__spreadValues({},c),{width:c.width+m,height:c.height+f,depth:c.depth+w}),g,u);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:p,color:x}=yield this.cacheInstance.loadPCDFile(n);d(p,x)}),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,p=16776960,x=new THREE__namespace.ArrowHelper(c,h,d,p);return x.visible=this.showDirection,x},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 p=new filterBoxWorker;p.postMessage(h),p.onmessage=x=>{const{color:g,position:u,num:m}=x.data,f=new THREE__namespace.BufferGeometry;f.setAttribute("position",new THREE__namespace.Float32BufferAttribute(u,3)),f.setAttribute("color",new THREE__namespace.Float32BufferAttribute(g,3)),f.computeBoundingSphere(),p.terminate(),d({geometry:f,num:m})}})}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)}}handleWebworker(t){return __async(this,null,function*(){return new Promise((e,i)=>{if(this.workerLoading){i(new Error("highlightWorker called repeatedly, new call discarded"));return}this.workerLoading=!0,highlightWorker.postMessage(t),highlightWorker.onmessage=r=>{e(r.data),this.workerLoading=!1},highlightWorker.onerror=r=>{i(r),this.workerLoading=!1}})})}highlightOriginPointCloud(t){return __async(this,arguments,function*(e,i=[],r={modifiedBoxIds:[],resetAreas:[]}){const{modifiedBoxIds:s,resetAreas:a}=r,o=this.scene.getObjectByName(this.pointCloudObjectName);if(!!o)return this.highlightPCDSrc=this.currentPCDSrc,new Promise((l,n)=>{if(window.Worker){const h=(e?[...e]:[]).map(u=>matrix.getCuboidFromPointCloudBox(u)),d=this.getAllAttributeColor(h),p=o.geometry.attributes.position.array,x=o.geometry.attributes.dimensions.array,g={cuboidList:h,position:p,color:x,colorList:d,highlightIndex:i,modifiedBoxIds:s,resetAreas:a};this.handleWebworker(g).then(u=>{const{color:m}=u;let f=m;(s.length||a.length)&&(f=m.map((C,b)=>C===-1?x[b]:C));const w=new THREE__namespace.BufferAttribute(f,3);if(!this.highlightPCDSrc||this.highlightPCDSrc!==this.currentPCDSrc||o.geometry.attributes.position.array.length!==m.length){n(new Error("Error Path"));return}this.cacheInstance.updateColor(this.highlightPCDSrc,f),this.highlightPCDSrc=void 0,w.needsUpdate=!0,o.geometry.setAttribute("dimensions",w),o.geometry.attributes.dimensions.needsUpdate=!0,l(f),this.render()}).catch(u=>{n(u)})}})})}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),p=new THREE__namespace.MeshBasicMaterial({color:h,transparent:!0,opacity:.2,depthTest:!1});d.rotateZ(c),d.translate(r,s,a);const x=new THREE__namespace.Mesh(d,p);e.add(x);const g=new THREE__namespace.PlaneGeometry(n,l);g.rotateY(Math.PI/2),g.rotateZ(c);const u=new THREE__namespace.Vector3(o/2,0,0),m=new THREE__namespace.Matrix4().makeRotationY(Math.PI/2).makeRotationZ(c);u.applyMatrix4(m),g.translate(r+u.x,s+u.y,a+u.z);const f=new THREE__namespace.MeshBasicMaterial({color:h,side:THREE__namespace.DoubleSide,transparent:!0,opacity:.8,depthTest:!1}),w=new THREE__namespace.Mesh(g,f);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],p=MathUtils.default.getFootOfPerpendicular({x:l,y:n},c,d,!1,!0).length;(!i[h]||p<i[h].distance)&&(i[h]={distance:p,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(g=>g.uuid===this.pointsUuid);let l=0,n=0,c=0,h=0,d=[],p=[];const x=((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 g=0;g<x.length;g+=3){const u=x[g],m=x[g+1],f=x[g+2];polygonTool.isInPolygon({x:u,y:m},t)&&(f||f===0)&&p.push({x:u,y:m,z:f})}return p.length?(i&&(p=this.filterNoise(p),d=this.getFittedCoordinates(t,p)),p.sort((g,u)=>g.z-u.z),l=p[0].z-.01,n=p[p.length-1].z+.01,h=p.length,e&&(c=p.filter(({z:g})=>g>=e[0]&&g<=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(u=>new THREE__namespace.Vector3(u.x,u.y,u.z)).map(u=>u.applyMatrix4(a)),[l,n,c,h]=o,d=Math.max(Math.abs(l.x-c.x),Math.abs(l.x-n.x)),x=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-x.x,y:r.center.y-x.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.omniCamera11VTransfer=matrix.omniCamera11VTransfer,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=(...o)=>__async(this,[...o],function*(n=this.currentPCDSrc,c){if(!n)return;this.clearPointCloud(),this.cacheInstance.clearCache2DHighlightIndex(),this.currentPCDSrc=n;const{points:d,color:x}=yield this.cacheInstance.loadPCDFile(n),p=new THREE__namespace.BufferGeometry;p.setAttribute("position",new THREE__namespace.BufferAttribute(d,3)),this.isSegment||p.setAttribute("dimensions",new THREE__namespace.BufferAttribute(x,3)),this.initCloudData(d);const f=new THREE__namespace.Points(p);this.renderPointCloud(f,c),this.emit("loadPCDFileEnd")}),this.getHighlightIndexByMappingImgList=o=>__async(this,[o],function*({mappingImgList:n,points:c}){const d=g=>__async(this,null,function*(){try{return yield ImgUtils.default.load(g)}catch(m){return console.error("Error loading image:",m),null}}),x=n.length===0?[]:(yield Promise.all(n.map(g=>__async(this,null,function*(){let m=yield d(g.url);return!m&&g.fallbackUrl&&(m=yield d(g.fallbackUrl)),m})))).filter(g=>g!==null),p=n.map((g,m)=>{var y;if(this.cacheInstance.cache2DHighlightIndex.has(g.url))return(y=this.cacheInstance.cache2DHighlightIndex.get(g.url))!=null?y:[];const b=matrix.getHighlightIndexByPoints({points:c,calib:g.calib,width:x[m].width,height:x[m].height});return this.cacheInstance.cache2DHighlightIndex.set(g.url,b),b});return matrix.mergeHighlightList(p)}),this.filterPreResult=(o,n,c)=>__async(this,null,function*(){const{points:d}=yield this.cacheInstance.loadPCDFile(o),x=yield this.cacheInstance.loadIndexMap(o,d);return new Promise(p=>{const f=c.map(g=>{const m=MathUtils.default.calculatePointsInsideBox({indexMap:x,polygon:matrix.getCuboidFromPointCloudBox(g).polygonPointList,zScope:[g.center.z-g.depth/2,g.center.z+g.depth/2],box:g}),y=m>=n.lowerLimitPointsNumInBox;return __spreadProps(__spreadValues({},g),{valid:y,count:m})});p(f)})}),this.loadPCDFileByBox=(o,n,c)=>__async(this,null,function*(){const d=(f,g)=>__async(this,null,function*(){const{width:m=0,height:y=0,depth:b=0}=c!=null?c:{},C=yield this.filterPointsByBox(__spreadProps(__spreadValues({},n),{width:n.width+m,height:n.height+y,depth:n.depth+b}),f,g);if(!C){console.error("filter Error");return}this.clearPointCloud(),this.currentPCDSrc=o;const v=new THREE__namespace.Points(C.geometry);v.name=this.pointCloudObjectName,this.scene.add(v),this.render()}),{points:x,color:p}=yield this.cacheInstance.loadPCDFile(o);d(x,p)}),this.generateRange=o=>{const n=this.createRange(o);this.scene.add(n)},this.generateBoxArrow=({width:o})=>{const n=new THREE__namespace.Vector3(1,0,0),c=new THREE__namespace.Vector3(o/2,0,0),d=2,x=16776960,p=new THREE__namespace.ArrowHelper(n,c,d,x);return p.visible=this.showDirection,p},this.generateLabel=(o,n)=>{const c=this.getTextCanvas(o),d=new THREE__namespace.Texture(c);d.minFilter=THREE__namespace.LinearFilter,d.magFilter=THREE__namespace.LinearFilter,d.needsUpdate=!0;const x=c.width/window.devicePixelRatio,p=c.height/window.devicePixelRatio,f=new THREE__namespace.SpriteMaterial({map:d,depthWrite:!1}),g=new THREE__namespace.Sprite(f);return g.scale.set(x/n,p/n,1),{sprite:g,canvasWidth:x,canvasHeight:p}},this.generateBoxTrackID=o=>{if(!o.trackID)return;const{sprite:n}=this.generateLabel(o.trackID.toString(),50);return n.position.set(-o.width/2,0,o.depth/2+.5),n},this.generateBoxAttributeLabel=o=>{if(!o.attribute||this.hiddenText)return;const n=this.findSubAttributeLabel(o,this.config),c=n?`${o.attribute}
|
|
32
|
+
${n}`:`${o.attribute}`,{sprite:d,canvasWidth:x,canvasHeight:p}=this.generateLabel(c,100);return d.position.set(-o.width/2,o.height/2-x/200,-o.depth/2-p/150),d},this.applyZAxisPoints=o=>{this.zAxisLimit=o,this.filterZAxisPoints(),this.render()},this.updatePointSize=({zoomIn:o,customSize:n})=>{const c=this.scene.getObjectByName(this.pointCloudObjectName);if(!c)return;const d=c.material.uniforms.pointSize.value;o?c.material.uniforms.pointSize.value=Math.min(d*1.2,10):c.material.uniforms.pointSize.value=Math.max(d/1.2,1),n&&(c.material.uniforms.pointSize.value=n,this.pointsMaterialSize=n),c.material.uniformsNeedUpdate=!0,this.render()},this.container=t,this.renderer=new THREE__namespace.WebGLRenderer({antialias:!0}),this.backgroundColor=a,this.config=h,this.checkMode=l!=null?l:!1,this.hiddenText=u,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,s?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(),s===!0&&(this.initSegment(),this.isSegment=!0),this.controls.addEventListener("rightClick",o=>{var n,c;const d=this.renderer.domElement.getBoundingClientRect(),x=o.originalEvent.clientX-d.left,p=o.originalEvent.clientY-d.top;this.pointer.x=x/d.width*2-1,this.pointer.y=-(p/d.height)*2+1,this.raycaster.setFromCamera(this.pointer,this.camera);const f=[];this.scene.children.forEach(m=>{m instanceof THREE__namespace.Group&&m.children.forEach(y=>{y instanceof THREE__namespace.Mesh&&f.push(y)})});const g=this.raycaster.intersectObjects(f,!1);if(g.length>0){const m=g[0].object;(n=this.pipe)==null||n.setNeedUpdateCenter(!1),(c=this.pipe)==null||c.setSelectedIDs([m.userData.selectedID])}})}setHandlerPipe(t){this.pipe=t}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:a,near:h,far:s}=t;this.camera.left=e,this.camera.right=i,this.camera.top=r,this.camera.bottom=a,this.camera.near=h,this.camera.far=s,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,a=10,h=e.x-i/2-a,s=e.x-i/2+a,l=e.y+r/2+a,u=e.y-r/2-a,o=100,n=-100,c=500/o;return{left:h,right:s,top:l,bottom:u,near:o,far:n,zoom:c}}updateCameraZoom(t){this.camera.zoom=t,this.camera.updateProjectionMatrix()}updateCameraByBox(t,e,i){const{center:r,width:a,height:h,depth:s,rotation:l}=t,u=this.getCameraVector(r,l,{width:a,height:h,depth:s},e);return i?(this.updateCamera(i,r),new THREE__namespace.Vector3(i.x,i.y,i.z)):(this.updateCamera(u,r),u)}updateCameraBySphere(t,e){const{center:i}=t,{radius:r}=lbUtils.DEFAULT_SPHERE_PARAMS,a=this.getCameraVector(i,0,{width:r*2,height:r*2,depth:r*2},e);return this.updateCamera(a,i),a}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,a,h;if(!e){const s=this.scene.getObjectByName(this.pointCloudObjectName);if(!s)return console.error("There is no corresponding point cloud object"),Promise.resolve(void 0);e=(h=(a=(r=s==null?void 0:s.geometry)==null?void 0:r.attributes)==null?void 0:a.position)==null?void 0:h.array}if(window.Worker){const{zMin:s,zMax:l,polygonPointList:u}=matrix.getCuboidFromPointCloudBox(t),o=e;i=i!=null?i:new Float32Array([]);const n={boxParams:t,zMin:s,zMax:l,polygonPointList:u,color:i,position:o};return new Promise(c=>{const d=new filterBoxWorker;d.postMessage(n),d.onmessage=x=>{const{color:p,position:f,num:g}=x.data,m=new THREE__namespace.BufferGeometry;m.setAttribute("position",new THREE__namespace.Float32BufferAttribute(f,3)),m.setAttribute("color",new THREE__namespace.Float32BufferAttribute(p,3)),m.computeBoundingSphere(),d.terminate(),c({geometry:m,num:g})}})}return Promise.resolve(void 0)}getCameraVector(t,e,i,r=lbUtils.EPerspectiveView.Front,a=DEFAULT_DISTANCE){let h=lbUtils.PerspectiveShiftUtils.frontViewMatrix4(a);switch(r){case lbUtils.EPerspectiveView.Front:break;case lbUtils.EPerspectiveView.Back:h=lbUtils.PerspectiveShiftUtils.backViewMatrix4(a);break;case lbUtils.EPerspectiveView.Left:h=lbUtils.PerspectiveShiftUtils.leftViewMatrix4(a);break;case lbUtils.EPerspectiveView.Right:h=lbUtils.PerspectiveShiftUtils.rightViewMatrix4(a);break;case lbUtils.EPerspectiveView.Top:h=lbUtils.PerspectiveShiftUtils.topViewMatrix4(a);break;case lbUtils.EPerspectiveView.LFT:h=lbUtils.PerspectiveShiftUtils.leftFrontTopViewMatrix4(a,i);break;case lbUtils.EPerspectiveView.RBT:h=lbUtils.PerspectiveShiftUtils.rightBackTopViewMatrix4(a,i);break}const s=this.createThreeMatrix4(h),l=new THREE__namespace.Matrix4().makeTranslation(-t.x,-t.y,-t.z),u=new THREE__namespace.Matrix4().makeTranslation(t.x,t.y,t.z),o=new THREE__namespace.Matrix4().makeRotationZ(e);return new THREE__namespace.Vector3(t.x,t.y,t.z).clone().applyMatrix4(s).applyMatrix4(l).applyMatrix4(o).applyMatrix4(u)}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),a=new THREE__namespace.LineBasicMaterial({color:16711680}),h=new THREE__namespace.Line(r,a);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],a=t[e+2];this.store.cloudData.set(`${i}@${r}@${a}`,{visible:!1})}this.store.setOriginPoints(t)}}handleWebworker(t){return __async(this,null,function*(){return new Promise((e,i)=>{if(this.workerLoading){i(new Error("highlightWorker called repeatedly, new call discarded"));return}this.workerLoading=!0,highlightWorker.postMessage(t),highlightWorker.onmessage=r=>{e(r.data),this.workerLoading=!1},highlightWorker.onerror=r=>{i(r),this.workerLoading=!1}})})}highlightOriginPointCloud(t){return __async(this,arguments,function*(e,i=[],r={modifiedBoxIds:[],resetAreas:[]}){const{modifiedBoxIds:a,resetAreas:h}=r,s=this.scene.getObjectByName(this.pointCloudObjectName);if(!!s)return this.highlightPCDSrc=this.currentPCDSrc,new Promise((l,u)=>{if(window.Worker){const n=(e?[...e]:[]).map(f=>matrix.getCuboidFromPointCloudBox(f)),c=this.getAllAttributeColor(n),d=s.geometry.attributes.position.array,x=s.geometry.attributes.dimensions.array,p={cuboidList:n,position:d,color:x,colorList:c,highlightIndex:i,modifiedBoxIds:a,resetAreas:h};this.handleWebworker(p).then(f=>{const{color:g}=f;let m=g;(a.length||h.length)&&(m=g.map((b,C)=>b===-1?x[C]:b));const y=new THREE__namespace.BufferAttribute(m,3);if(!this.highlightPCDSrc||this.highlightPCDSrc!==this.currentPCDSrc||s.geometry.attributes.position.array.length!==g.length){u(new Error("Error Path"));return}this.cacheInstance.updateColor(this.highlightPCDSrc,m),this.highlightPCDSrc=void 0,y.needsUpdate=!0,s.geometry.setAttribute("dimensions",y),s.geometry.attributes.dimensions.needsUpdate=!0,l(m),this.render()}).catch(f=>{u(f)})}})})}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:a,z:h},width:s,height:l,depth:u,rotation:o}=i,{fill:n}=lbUtils.toolStyleConverter.getColorFromConfig({attribute:i.attribute},__spreadProps(__spreadValues({},this.config),{attributeConfigurable:!0}),{}),c=new THREE__namespace.BoxGeometry(s,l,u),d=new THREE__namespace.MeshBasicMaterial({color:n,transparent:!0,opacity:.2,depthTest:!1});c.rotateZ(o),c.translate(r,a,h);const x=new THREE__namespace.Mesh(c,d);e.add(x);const p=new THREE__namespace.PlaneGeometry(u,l);p.rotateY(Math.PI/2),p.rotateZ(o);const f=new THREE__namespace.Vector3(s/2,0,0),g=new THREE__namespace.Matrix4().makeRotationY(Math.PI/2).makeRotationZ(o);f.applyMatrix4(g),p.translate(r+f.x,a+f.y,h+f.z);const m=new THREE__namespace.MeshBasicMaterial({color:n,side:THREE__namespace.DoubleSide,transparent:!0,opacity:.8,depthTest:!1}),y=new THREE__namespace.Mesh(p,m);e.add(y)}),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()}findSubAttributeLabel(t,e){if(!(t==null?void 0:t.subAttribute)||typeof t.subAttribute!="object"||!e)return"";const{inputList:i}=e;let r="";const a=Object.keys(t.subAttribute);return a.length===0||a.forEach(h=>{const s=i.find(n=>n.value===h);if(!s||!s.subSelected)return;const{key:l,subSelected:u}=s,o=u.find(n=>{var c;return n.value===((c=t.subAttribute)==null?void 0:c[h])});o&&(r&&(r+="\u3001"),r+=`${l}:${o.key}`)}),r}getTextCanvas(t){const e=document.createElement("canvas"),i=e.getContext("2d"),r=window.devicePixelRatio||1,a=50;if(i){i.font=`${a}px bold`;const h=t.split(`
|
|
33
|
+
`),s=Math.max(...h.map(n=>i.measureText(n).width)),l=Math.ceil(s),u=a*1.5,o=u*h.length;e.width=l*r,e.height=o*r,e.style.width=`${l}px`,e.style.height=`${o}px`,i.scale(r,r),i.font=`${a}px bold`,i.fillStyle="white",i.textAlign="left",i.textBaseline="top",h.forEach((n,c)=>{i.fillText(n,0,c*u)})}return e}updateHiddenTextAndRender(t,e){this.hiddenText=t,this.generateBoxes(e)}filterNoise(t){let e=[...t];e.sort((n,c)=>n.z-c.z);const i=Math.floor(e.length*.05),r=e[i];e=e.filter(({z:n})=>n>r.z+.1);const a=.005,h=Math.floor(e.length*(1-a));e=e.slice(0,h),e.sort((n,c)=>n.x-c.x);const s=Math.floor(e.length*a),l=Math.floor(e.length*(1-a));e=e.slice(s,l),e.sort((n,c)=>n.y-c.y);const u=Math.floor(e.length*a),o=Math.floor(e.length*(1-a));return e=e.slice(u,o),e.length>100?e:t}getFittedCoordinates(t,e){const i=[];let r=[...t,t[0]];e.forEach(({x:l,y:u})=>{t.forEach((o,n)=>{const c=r[n+1],d=MathUtils.default.getFootOfPerpendicular({x:l,y:u},o,c,!1,!0).length;(!i[n]||d<i[n].distance)&&(i[n]={distance:d,point:{x:l,y:u}})})}),r=[t[t.length-1],...t,t[0]];const a=[i[i.length-1],...i],h=t.map((l,u)=>{const o=r[u],n=r[u+1],c=r[u+2];return lbUtils.PointCloudUtils.getIntersectionBySlope({p1:a[u].point,line1:[o,n],p2:a[u+1].point,line2:[n,c]})});return h.some(l=>!(Number.isFinite(l.x)&&Number.isFinite(l.y)))?t:h}getSensesPointZAxisInPolygon(t,e,i){var r,a,h;const s=this.scene.children.find(p=>p.uuid===this.pointsUuid);let l=0,u=0,o=0,n=0,c=[],d=[];const x=((h=(a=(r=s==null?void 0:s.geometry)==null?void 0:r.attributes)==null?void 0:a.position)==null?void 0:h.array)||[];for(let p=0;p<x.length;p+=3){const f=x[p],g=x[p+1],m=x[p+2];polygonTool.isInPolygon({x:f,y:g},t)&&(m||m===0)&&d.push({x:f,y:g,z:m})}return d.length?(i&&(d=this.filterNoise(d),c=this.getFittedCoordinates(t,d)),d.sort((p,f)=>p.z-f.z),l=d[0].z-.01,u=d[d.length-1].z+.01,n=d.length,e&&(o=d.filter(({z:p})=>p>=e[0]&&p<=e[1]).length),{maxZ:u,minZ:l,count:o,zCount:n,fittedCoordinates:c}):{maxZ:u,minZ:l,count:o,zCount:n,fittedCoordinates:c}}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:a,width:h,depth:s}=t,l={x:e+h/2,y:i+a/2,z:r-s/2},u={x:e+h/2,y:i+a/2,z:r+s/2},o={x:e-h/2,y:i+a/2,z:r+s/2},n={x:e-h/2,y:i+a/2,z:r-s/2};return[l,u,o,n]}getPolygonBackPoints(t){const{center:{x:e,y:i,z:r},height:a,width:h,depth:s}=t,l={x:e-h/2,y:i+a/2,z:r+s/2},u={x:e-h/2,y:i+a/2,z:r-s/2},o={x:e-h/2,y:i-a/2,z:r-s/2},n={x:e-h/2,y:i-a/2,z:r+s/2};return[l,u,o,n]}getPolygonTopPoints(t){const{center:{x:e,y:i,z:r},height:a,width:h,depth:s}=t,l={x:e+h/2,y:i+a/2,z:r+s/2},u={x:e+h/2,y:i-a/2,z:r+s/2},o={x:e-h/2,y:i-a/2,z:r+s/2},n={x:e-h/2,y:i+a/2,z:r+s/2};return[l,u,o,n]}getModelTransformationMatrix(t){const{center:{x:e,y:i,z:r},rotation:a}=t,h=new THREE__namespace.Matrix4().makeTranslation(-e,-i,-r),s=new THREE__namespace.Matrix4().makeTranslation(e,i,r),l=new THREE__namespace.Matrix4().makeRotationZ(a);return new THREE__namespace.Matrix4().multiply(s).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:a}=t,h=new THREE__namespace.Matrix4().premultiply(this.camera.matrixWorldInverse).premultiply(this.camera.projectionMatrix),s=new THREE__namespace.Matrix4().premultiply(this.getModelTransformationMatrix(t)).premultiply(h).premultiply(this.basicCoordinate2CanvasMatrix4);this.sideMatrix=s;const l=i.map(n=>new THREE__namespace.Vector3(n.x,n.y,n.z)).map(n=>n.applyMatrix4(this.sideMatrix)),u=this.containerWidth/r,o=this.containerHeight/a;return{polygon2d:l,zoom:Math.min(u,o)/2}}getSpherePoint2DCoordinate(t){const{center:e,attribute:i,id:r,valid:a}=t,{radius:h}=lbUtils.DEFAULT_SPHERE_PARAMS,s={center:e,attribute:i,id:r,valid:a,width:h*2,height:h*2,depth:h*2,rotation:0},l=new THREE__namespace.Matrix4().premultiply(this.camera.matrixWorldInverse).premultiply(this.camera.projectionMatrix),u=new THREE__namespace.Matrix4().premultiply(this.getModelTransformationMatrix(s)).premultiply(l).premultiply(this.basicCoordinate2CanvasMatrix4);this.sideMatrix=u;const o=new THREE__namespace.Vector3(e.x,e.y,e.z).applyMatrix4(this.sideMatrix),n=this.containerWidth/(h*2),c=this.containerHeight/(h*2);return{point2d:o,zoom:Math.min(n,c)/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)},a=this.containerWidth/(i*2),h=this.containerHeight/(i*2);return{point2d:r,zoom:Math.min(a,h)/2}}getBoxTopPolygon2DCoordinate(t){const{width:e,height:i}=t,a=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,s=this.containerHeight/i;return{polygon2d:a,zoom:Math.min(h,s)/2}}getNewBoxBySideUpdate(t,e,i,r){const a=new THREE__namespace.Matrix4().makeRotationZ(r.rotation),h=new THREE__namespace.Vector3(-t.x,0,0).applyMatrix4(a);let s=r;return s.center={x:s.center.x+h.x,y:s.center.y+h.y,z:s.center.z-t.z},s=__spreadProps(__spreadValues({},s),{width:Math.abs(s.width+e),height:s.height,depth:Math.abs(s.depth+i)}),{newBoxParams:s}}getNewBoxByBackUpdate(t,e,i,r){const a=new THREE__namespace.Matrix4().makeRotationZ(r.rotation),h=new THREE__namespace.Vector3(0,-t.x,0).applyMatrix4(a);let s=r;return s.center={x:s.center.x+h.x,y:s.center.y+h.y,z:s.center.z-t.z},s=__spreadProps(__spreadValues({},s),{width:s.width,height:Math.abs(s.height+e),depth:Math.abs(s.depth+i)}),{newBoxParams:s}}getNewBoxBySideUpdateByPoints(t,e,i,r){var a;const h=(a=this.sideMatrix)==null?void 0:a.invert();if(!this.sideMatrix||!h){console.error("No sideMatrix");return}this.camera.zoom=1,this.camera.updateProjectionMatrix();const s=t.map(f=>new THREE__namespace.Vector3(f.x,f.y,f.z)).map(f=>f.applyMatrix4(h)),[l,u,o,n]=s,c=Math.max(Math.abs(l.x-o.x),Math.abs(l.x-u.x)),x=u.add(n).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-x.x,y:r.center.y-x.y,z:r.center.z-i},width:c,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,a=[],{count:h}=r;for(let s=0;s<h;s++){const l=r.getZ(s);a.push(l>this.zAxisLimit?0:1)}e.geometry.setAttribute("visibility",new THREE__namespace.Float32BufferAttribute(a,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.omniCamera11VTransfer=matrix.omniCamera11VTransfer,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"),_=require("lodash"),rgba=require("color-rgba"),DrawUtils=require("../../utils/tool/DrawUtils.js"),AxisUtils=require("../../utils/tool/AxisUtils.js"),RectUtils=require("../../utils/tool/RectUtils.js"),PolygonUtils=require("../../utils/tool/PolygonUtils.js"),MathUtils=require("../../utils/MathUtils.js"),RenderDomClass=require("../../utils/tool/RenderDomClass.js"),tool=require("../../constant/tool.js"),annotation=require("../../constant/annotation.js"),ImgUtils=require("../../utils/ImgUtils.js"),CanvasUtils=require("../../utils/tool/CanvasUtils.js"),basicToolOperation=require("./basicToolOperation.js"),matrix=require("../pointCloud/matrix.js");function _interopDefaultLegacy(g){return g&&typeof g=="object"&&"default"in g?g:{default:g}}var ___default=_interopDefaultLegacy(_),rgba__default=_interopDefaultLegacy(rgba),__defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnPropDescs=Object.getOwnPropertyDescriptors,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(g,t,e)=>t in g?__defProp(g,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):g[t]=e,__spreadValues=(g,t)=>{for(var e in t||(t={}))__hasOwnProp.call(t,e)&&__defNormalProp(g,e,t[e]);if(__getOwnPropSymbols)for(var e of __getOwnPropSymbols(t))__propIsEnum.call(t,e)&&__defNormalProp(g,e,t[e]);return g},__spreadProps=(g,t)=>__defProps(g,__getOwnPropDescs(t)),__async=(g,t,e)=>new Promise((i,o)=>{var r=c=>{try{n(e.next(c))}catch(s){o(s)}},a=c=>{try{n(e.throw(c))}catch(s){o(s)}},n=c=>c.done?i(c.value):Promise.resolve(c.value).then(r,a);n((e=e.apply(g,t)).next())});const newScope=3,DEFAULT_RADIUS=3,DEFAULT_STROKE_COLOR="#6371FF";class ViewOperation extends basicToolOperation.BasicToolOperation{constructor(t){super(__spreadProps(__spreadValues({},t),{showDefaultCursor:!0}));this.style={},this.annotations=[],this.connectionPoints=[],this.getHoverRectID=i=>{var o,r;const a=this.getCoordinateUnderZoom(i),n=AxisUtils.default.changePointByZoom(a,1/this.zoom);if(((o=this.annotations)==null?void 0:o.length)<=0||!((r=this.annotations)==null?void 0:r.length))return;let c="",s=Number.MAX_SAFE_INTEGER;for(let u=0;u<this.annotations.length;u++){const h=this.annotations[u];switch(h.type){case"rect":{const l=h.annotation;if(RectUtils.isInRect(a,l,newScope,this.zoom)){const d=l.width*l.height;d<s&&(c=l.id,s=d)}break}case"polygon":{const l=h.annotation;if(PolygonUtils.isInPolygon(n,l.pointList)){const d=PolygonUtils.getPolygonArea(l.pointList);d<s&&(c=l.id,s=d)}break}}}return c};var e;this.style=(e=t.style)!=null?e:{stroke:DEFAULT_STROKE_COLOR,thickness:3},this.annotations=t.annotations,this.loading=!1,this.renderDomInstance=new RenderDomClass({container:this.container,height:this.canvas.height})}clearConnectionPoints(){this.connectionPoints=[],this.render()}checkConnectionPoints(t=this.annotations){var e,i;this.connectPointsStatus&&((i=(e=this.connectPointsStatus).close)==null||i.call(e)),this.emit("connectionPointsStatusUpdate",()=>new Promise(o=>{const{promise:r,close:a}=MathUtils.default.getCollectionPointByAnnotationDataPromise(t);this.connectPointsStatus={close:a},r.then(n=>{this.connectionPoints=n.connectionPoints,this.render(),this.connectPointsStatus=void 0,o({connectionPoints:n.connectionPoints})})}))}setLoading(t){this.loading=t,this.render()}onMouseLeave(){super.onMouseLeave(),this.mouseHoverID=void 0,this.emit("onChange","hover",[])}onMouseDown(t){if(super.onMouseDown(t)||this.forbidMouseOperation||!this.imgInfo)return!0;const e=this.mouseHoverID;if(t.button===0){let i=[];e&&(i=[e]),this.emit("onChange","selected",i),this.render()}}setImgNode(t,e={}){super.setImgNode(t,e),this.staticMode&&this.generateStaticImgNode()}generateStaticImgNode(){var t,e;const i=ImgUtils.cropAndEnlarge(this.canvas,(t=this.basicImgInfo)==null?void 0:t.width,(e=this.basicImgInfo)==null?void 0:e.height,1);ImgUtils.default.load(i).then(o=>{this.staticImgNode=o,this.drawStaticImg()})}onMouseMove(t){if(super.onMouseMove(t)||this.forbidMouseOperation||!this.imgInfo)return;const e=this.mouseHoverID,i=this.getHoverRectID(t);if(e!==i){this.mouseHoverID=i;let o=[];i&&(o=[i]),this.emit("onChange","hover",o),this.render()}}updateData(t){return __async(this,null,function*(){if(!___default.default.isEqual(this.annotations,t)&&(this.annotations=t,this.staticMode&&(this.staticImgNode=void 0),this.render(),this.staticMode)){const e=this.zoom,i=this.currentPos;this.initImgPos(),this.generateStaticImgNode();const o=this.staticImgNode;this.staticImgNode=void 0,this.updatePosition({zoom:e,currentPos:i}),this.staticImgNode=o}})}setConfig(t){this.config=t}getSpecificStyle(t){const e=___default.default.pick(t,["stroke","thickness","fill","radius"]),i=__spreadValues(__spreadValues({},this.style),e);return i.stroke&&Object.assign(i,{color:i.stroke}),i}getFontStyle(t,e){var i,o;const r=(i=t==null?void 0:t.fontSize)!=null?i:14,a=(o=t==null?void 0:t.fontFamily)!=null?o:"Arial";return __spreadProps(__spreadValues({},annotation.DEFAULT_TEXT_SHADOW),{color:e.stroke,font:`normal normal 600 ${r}px ${a}`})}appendOffset({x:t,y:e}){return{x:t+annotation.DEFAULT_TEXT_OFFSET.offsetX,y:e+annotation.DEFAULT_TEXT_OFFSET.offsetY}}getRenderText(t,e=!1){let i="",o="";return!t||e===!0?{headerText:i,bottomText:o}:((t==null?void 0:t.order)&&(i=`${t.order}`),(t==null?void 0:t.label)&&(i?i=`${i}_${t.label}`:i=`${t.label}`),(t==null?void 0:t.attribute)&&(i?i=`${i} ${t.attribute}`:i=`${t.attribute}`),(t==null?void 0:t.textAttribute)&&(o=t==null?void 0:t.textAttribute),(t==null?void 0:t.subAttributeText)&&(i+=t==null?void 0:t.subAttributeText),{headerText:i,bottomText:o})}getReferenceOptions(t){return t?{lineCap:"butt",lineDash:[20,20]}:{}}focusPositionByPointList(t){const e=MathUtils.default.calcViewportBoundaries(t),i={x:e.left,y:e.top,width:e.right-e.left,height:e.bottom-e.top},o=lbUtils.ImgPosUtils.getBasicRecPos(this.imgNode,i,this.size,.5);if(o){this.setCurrentPos(o.currentPos),this.setCurrentPosStorage(o.currentPos);const{imgInfo:r}=this,{innerZoom:a}=this.innerPosAndZoom;r&&this.setImgInfo(__spreadProps(__spreadValues({},r),{width:r.width/a*o.innerZoom,height:r.height/a*o.innerZoom})),this.setZoom(o.innerZoom),this.render(),this.renderBasicCanvas()}}renderConnectionPoints(){this.connectionPoints.forEach(t=>{const e=AxisUtils.default.changePointByZoom(t,this.zoom,this.currentPos);DrawUtils.drawCircleWithFill(this.canvas,e,4,{color:"#fff"}),DrawUtils.drawCircleWithFill(this.canvas,e,2,{color:"#000"})})}getRenderStyle(t){const e=this.getSpecificStyle(t.annotation),i=this.getFontStyle(t.annotation,e);return{style:e,fontStyle:i}}renderLine(t){var e,i,o;if(t.type!=="line")return;const{style:r,fontStyle:a}=this.getRenderStyle(t),n=t.annotation;if(!(((e=n==null?void 0:n.pointList)==null?void 0:e.length)>=2))return;const{lineType:c=tool.ELineTypes.Line}=n,s=AxisUtils.default.changePointListByZoom((i=n==null?void 0:n.pointList)!=null?i:[],this.zoom,this.currentPos),u=__spreadProps(__spreadValues(__spreadValues({},r),this.getReferenceOptions(n==null?void 0:n.isReference)),{lineType:c,strokeColor:r.stroke});let h=[];if(n.showKeyPoint?h=DrawUtils.drawPolygonWithKeyPoint(this.canvas,s,u):h=DrawUtils.drawPolygon(this.canvas,s,u),(n==null?void 0:n.showDirection)===!0&&((o=n==null?void 0:n.pointList)==null?void 0:o.length)>=2){let v=s[0],p=MathUtils.default.getLineCenterPoint([s[0],s[1]]);if(c===tool.ELineTypes.Curve){const f=Math.floor(tool.SEGMENT_NUMBER/2);v=h[f],p=h[f+1]}DrawUtils.drawArrowByCanvas(this.canvas,v,p,{color:r.stroke,thickness:r.thickness}),DrawUtils.drawCircle(this.canvas,s[0],r.thickness+6,{color:r.stroke,thickness:r.thickness})}const{headerText:d,bottomText:y}=this.getRenderText(n,n==null?void 0:n.hiddenText);if(d&&DrawUtils.drawText(this.canvas,this.appendOffset(s[0]),d,a),y){const v=s[s.length-1];DrawUtils.drawText(this.canvas,this.appendOffset({x:v.x+annotation.TEXT_ATTRIBUTE_OFFSET.x,y:v.y+annotation.TEXT_ATTRIBUTE_OFFSET.y}),y,a)}}renderPolygon(t){var e,i,o,r,a;if(t.type!=="polygon")return;const{style:n,fontStyle:c}=this.getRenderStyle(t),s=t.annotation;if(!(((e=s==null?void 0:s.pointList)==null?void 0:e.length)>=3))return;const{lineType:u=tool.ELineTypes.Line}=s,h=AxisUtils.default.changePointListByZoom((i=s==null?void 0:s.pointList)!=null?i:[],this.zoom,this.currentPos);if(s.id===this.mouseHoverID||n.fill){const f=rgba__default.default((r=(o=n==null?void 0:n.fill)!=null?o:n==null?void 0:n.stroke)!=null?r:DEFAULT_STROKE_COLOR),m=`rgba(${f[0]}, ${f[1]}, ${f[2]},${f[3]*.8})`;DrawUtils.drawPolygonWithFill(this.canvas,h,{color:m,lineType:u})}const l=__spreadProps(__spreadValues(__spreadProps(__spreadValues({},n),{isClose:!0}),this.getReferenceOptions(s==null?void 0:s.isReference)),{lineType:u,strokeColor:n.stroke});let d=[];if(s.showKeyPoint?d=DrawUtils.drawPolygonWithKeyPoint(this.canvas,h,l):d=DrawUtils.drawPolygon(this.canvas,h,l),(s==null?void 0:s.showDirection)===!0&&((a=s==null?void 0:s.pointList)==null?void 0:a.length)>=2){let f=h[0],m=MathUtils.default.getLineCenterPoint([h[0],h[1]]);if(u===tool.ELineTypes.Curve){const x=Math.floor(tool.SEGMENT_NUMBER/2);f=d[x],m=d[x+1]}DrawUtils.drawArrowByCanvas(this.canvas,f,m,{color:n.stroke,thickness:n.thickness}),DrawUtils.drawCircle(this.canvas,h[0],n.thickness+6,{color:n.stroke,thickness:n.thickness})}const{headerText:v,bottomText:p}=this.getRenderText(s,s==null?void 0:s.hiddenText);if(v&&DrawUtils.drawText(this.canvas,this.appendOffset(h[0]),v,c),p){const f=h[h.length-2];DrawUtils.drawText(this.canvas,this.appendOffset({x:f.x+annotation.TEXT_ATTRIBUTE_OFFSET.x,y:f.y+annotation.TEXT_ATTRIBUTE_OFFSET.y}),p,c)}}renderSingleCuboid(t){var e,i;const{style:o}=this.getRenderStyle(t),r=t.annotation,a=rgba__default.default((i=(e=o==null?void 0:o.fill)!=null?e:o==null?void 0:o.stroke)!=null?i:DEFAULT_STROKE_COLOR),n=`rgba(${a[0]}, ${a[1]}, ${a[2]},${a[3]*.8})`,c=o.stroke,s=AxisUtils.default.changeCuboidByZoom(r,this.zoom,this.currentPos),{headerText:u,bottomText:h}=this.getRenderText(r,r==null?void 0:r.hiddenText);DrawUtils.drawCuboidWithText(this.canvas,s,{strokeColor:c,fillColor:n,thickness:o.thickness},{config:this.config,hiddenText:r==null?void 0:r.hiddenText,headerText:u,bottomText:h})}renderBox3d(t){var e;if(t.type!=="box3d")return;const i=t.annotation,{transferViewData:o}=(e=matrix.pointCloudLidar2image(i,i.calib))!=null?e:{};if(!o)return;const r={fill:"transparent"},a=___default.default.pick(i,["stroke","thickness"]);o.forEach((n,c)=>{const s=__spreadValues(__spreadProps(__spreadValues({},a),{id:`${t.annotation.id}-${c}`,pointList:n.pointList}),r);switch(n.type){case"line":this.renderLine({type:"line",annotation:s});break;case"polygon":this.renderPolygon({type:"polygon",annotation:s});break}})}renderPixelPoints(t){var e;if(t.type!=="pixelPoints")return;const i=t.annotation;if(!this.imgNode){console.error("Need to load after imgLoaded");return}if(!(i.length>0)){console.warn("Empty pixelPoints");return}const o=this.imgNode.src+i.length+t.defaultRGBA,r=(e=this.cacheCanvas)==null?void 0:e[o];if(r){DrawUtils.drawImg(this.canvas,r,{zoom:this.zoom,currentPos:this.currentPos});return}const a={width:this.imgNode.width,height:this.imgNode.height},{ctx:n,canvas:c}=CanvasUtils.createCanvas(a),s=typeof t.pixelSize=="number"?t.pixelSize:13;n&&(i==null?void 0:i.length)>0&&(DrawUtils.drawPixel({canvas:c,points:i,size:a,defaultRGBA:t.defaultRGBA,pixelSize:s}),DrawUtils.drawImg(this.canvas,c,{zoom:this.zoom,currentPos:this.currentPos}),this.cacheCanvas={[o]:c})}render(){try{if(this.staticImgNode||(super.render(),this.loading===!0))return;const t=this.annotations.filter(e=>e.type==="text"&&e.annotation.position==="rt").map(e=>e.annotation);this.renderDomInstance.render(t),this.annotations.forEach(e=>{var i,o,r,a,n,c,s;const u=this.getSpecificStyle(e.annotation),h=this.getFontStyle(e.annotation,u);switch(e.type){case"rect":{const l=e.annotation,{hiddenText:d=!1,isReference:y,hiddenRectSize:v=!1}=l,{zoom:p}=this,f=AxisUtils.default.changeRectByZoom(l,this.zoom,this.currentPos),{x:m,y:x,width:w,height:b}=f,P=rgba__default.default((o=(i=u==null?void 0:u.fill)!=null?i:u==null?void 0:u.stroke)!=null?o:DEFAULT_STROKE_COLOR),S=`rgba(${P[0]}, ${P[1]}, ${P[2]},${P[3]*.8})`;(l.id===this.mouseHoverID||u.fill)&&DrawUtils.drawRectWithFill(this.canvas,f,{color:S}),DrawUtils.drawRect(this.canvas,f,__spreadValues(__spreadProps(__spreadValues({},u),{hiddenText:!0}),this.getReferenceOptions(y))),(l==null?void 0:l.isHighlight)&&DrawUtils.drawHighlightFlag({canvas:this.canvas,color:S,position:{x:m-16,y:x-16}});const{headerText:I,bottomText:T}=this.getRenderText(l,l==null?void 0:l.hiddenText);I&&DrawUtils.drawText(this.canvas,{x:m,y:x-6},I,__spreadValues({textMaxWidth:300},h));const k=`${Math.round(w/p)} * ${Math.round(b/p)}`,C=k.length*7;if(!d&&!v&&DrawUtils.drawText(this.canvas,{x:m+w-C,y:x+b+15},k,h),T){const E=20,R=Math.max(20,w-C);DrawUtils.drawText(this.canvas,{x:m,y:x+b+E},l.textAttribute,__spreadValues({textMaxWidth:R},h))}break}case"polygon":{this.renderPolygon(e);break}case"line":{this.renderLine(e);break}case"point":{const l=e.annotation,d=AxisUtils.default.changePointByZoom(l,this.zoom,this.currentPos),y=(r=u.radius)!=null?r:DEFAULT_RADIUS;DrawUtils.drawCircle(this.canvas,d,y,u);const{headerText:v,bottomText:p}=this.getRenderText(l,l==null?void 0:l.hiddenText);v&&DrawUtils.drawText(this.canvas,{x:d.x+y/2,y:d.y-y-4},v,__spreadValues({textAlign:"center"},h)),p&&DrawUtils.drawText(this.canvas,this.appendOffset({x:d.x+y,y:d.y+y+24}),p,h);break}case"text":{const l=e.annotation,{text:d,x:y,y:v,textMaxWidth:p,color:f="white",background:m="rgba(0, 0, 0, 0.6)",lineHeight:x=25,font:w=tool.DEFAULT_FONT,position:b,offset:P}=l,S=10,I=10,T=AxisUtils.default.changePointByZoom({x:y,y:v},this.zoom,this.currentPos);P&&(T.x+=(a=P.x)!=null?a:0,T.y+=(n=P.y)!=null?n:0);const{width:k,height:C,fontHeight:E=0}=MathUtils.default.getTextArea(this.canvas,l.text,p,w,x);if(b==="rt")break;DrawUtils.drawRectWithFill(this.canvas,{x:T.x,y:T.y,width:k+I*2,height:C+S*2,id:"",sourceID:"",valid:!0,textAttribute:"",attribute:""},{color:m}),DrawUtils.drawText(this.canvas,{x:T.x+I,y:T.y+E+S},d,{color:f,lineHeight:x,font:w,textMaxWidth:p});break}case"box3d":{this.renderBox3d(e);break}case"cuboid":{this.renderSingleCuboid(e);break}case"pixelPoints":{this.renderPixelPoints(e);break}default:break}"renderEnhance"in e.annotation&&((s=(c=e.annotation).renderEnhance)==null||s.call(c,{ctx:this.ctx,canvas:this.canvas,currentPos:this.currentPos,zoom:this.zoom,data:e,toolInstance:this}))}),this.renderConnectionPoints()}catch(t){console.error("ViewOperation Render Error",t)}}}module.exports=ViewOperation;
|
|
1
|
+
"use strict";var lbUtils=require("@labelbee/lb-utils"),_=require("lodash"),rgba=require("color-rgba"),DrawUtils=require("../../utils/tool/DrawUtils.js"),AxisUtils=require("../../utils/tool/AxisUtils.js"),RectUtils=require("../../utils/tool/RectUtils.js"),PolygonUtils=require("../../utils/tool/PolygonUtils.js"),MathUtils=require("../../utils/MathUtils.js"),RenderDomClass=require("../../utils/tool/RenderDomClass.js"),tool=require("../../constant/tool.js"),annotation=require("../../constant/annotation.js"),ImgUtils=require("../../utils/ImgUtils.js"),CanvasUtils=require("../../utils/tool/CanvasUtils.js"),basicToolOperation=require("./basicToolOperation.js"),matrix=require("../pointCloud/matrix.js");function _interopDefaultLegacy(g){return g&&typeof g=="object"&&"default"in g?g:{default:g}}var ___default=_interopDefaultLegacy(_),rgba__default=_interopDefaultLegacy(rgba),__defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnPropDescs=Object.getOwnPropertyDescriptors,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(g,t,e)=>t in g?__defProp(g,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):g[t]=e,__spreadValues=(g,t)=>{for(var e in t||(t={}))__hasOwnProp.call(t,e)&&__defNormalProp(g,e,t[e]);if(__getOwnPropSymbols)for(var e of __getOwnPropSymbols(t))__propIsEnum.call(t,e)&&__defNormalProp(g,e,t[e]);return g},__spreadProps=(g,t)=>__defProps(g,__getOwnPropDescs(t)),__async=(g,t,e)=>new Promise((i,o)=>{var r=l=>{try{n(e.next(l))}catch(s){o(s)}},a=l=>{try{n(e.throw(l))}catch(s){o(s)}},n=l=>l.done?i(l.value):Promise.resolve(l.value).then(r,a);n((e=e.apply(g,t)).next())});const newScope=3,DEFAULT_RADIUS=3,DEFAULT_STROKE_COLOR="#6371FF";class ViewOperation extends basicToolOperation.BasicToolOperation{constructor(t){super(__spreadProps(__spreadValues({},t),{showDefaultCursor:!0}));this.style={},this.annotations=[],this.connectionPoints=[],this.needUpdatePosition=!0,this.posTimer=null,this.convexHullGroup={},this.pointCloudBoxList=[],this.hiddenText=!1,this.getHoverRectID=i=>{var o,r;const a=this.getCoordinateUnderZoom(i),n=AxisUtils.default.changePointByZoom(a,1/this.zoom);if(((o=this.annotations)==null?void 0:o.length)<=0||!((r=this.annotations)==null?void 0:r.length))return;let l="",s=Number.MAX_SAFE_INTEGER;for(let d=0;d<this.annotations.length;d++){const c=this.annotations[d];switch(c.type){case"rect":{const h=c.annotation;if(RectUtils.isInRect(a,h,newScope,this.zoom)){const u=h.width*h.height;u<s&&(l=h.id,s=u)}break}case"polygon":{const h=c.annotation;if(PolygonUtils.isInPolygon(n,h.pointList)){const u=PolygonUtils.getPolygonArea(h.pointList);u<s&&(l=h.id,s=u)}break}}}return l};var e;this.style=(e=t.style)!=null?e:{stroke:DEFAULT_STROKE_COLOR,thickness:3},this.annotations=t.annotations,this.convexHullGroup=PolygonUtils.createConvexHullGroup(t.annotations),this.loading=!1,this.renderDomInstance=new RenderDomClass({container:this.container,height:this.canvas.height})}clearConnectionPoints(){this.connectionPoints=[],this.render()}checkConnectionPoints(t=this.annotations){var e,i;this.connectPointsStatus&&((i=(e=this.connectPointsStatus).close)==null||i.call(e)),this.emit("connectionPointsStatusUpdate",()=>new Promise(o=>{const{promise:r,close:a}=MathUtils.default.getCollectionPointByAnnotationDataPromise(t);this.connectPointsStatus={close:a},r.then(n=>{this.connectionPoints=n.connectionPoints,this.render(),this.connectPointsStatus=void 0,o({connectionPoints:n.connectionPoints})})}))}setLoading(t){this.loading=t,this.render()}onMouseLeave(){super.onMouseLeave(),this.mouseHoverID=void 0,this.emit("onChange","hover",[])}onMouseDown(t){if(super.onMouseDown(t)||this.forbidMouseOperation||!this.imgInfo)return!0;const e=this.mouseHoverID;if(t.button===0){let i=[];e&&(i=[e]),this.emit("onChange","selected",i),this.render()}}setImgNode(t,e={}){super.setImgNode(t,e),this.staticMode&&this.generateStaticImgNode()}generateStaticImgNode(){var t,e;const i=ImgUtils.cropAndEnlarge(this.canvas,(t=this.basicImgInfo)==null?void 0:t.width,(e=this.basicImgInfo)==null?void 0:e.height,1);ImgUtils.default.load(i).then(o=>{this.staticImgNode=o,this.drawStaticImg()})}onRightClick(t){const e=this.getClickTargetId(t);!e||(this.needUpdatePosition=!1,this.posTimer&&clearTimeout(this.posTimer),this.emit("onRightClick",{event:t,targetId:e}),this.posTimer=setTimeout(()=>{this.needUpdatePosition=!0},1e3))}onMouseMove(t){if(super.onMouseMove(t)||this.forbidMouseOperation||!this.imgInfo)return;const e=this.mouseHoverID,i=this.getHoverRectID(t);if(e!==i){this.mouseHoverID=i;let o=[];i&&(o=[i]),this.emit("onChange","hover",o),this.render()}}updateData(t){return __async(this,null,function*(){if(!___default.default.isEqual(this.annotations,t)&&(this.annotations=t,this.convexHullGroup=PolygonUtils.createConvexHullGroup(t),this.staticMode&&(this.staticImgNode=void 0),this.render(),this.staticMode)){const e=this.zoom,i=this.currentPos;this.initImgPos(),this.generateStaticImgNode();const o=this.staticImgNode;this.staticImgNode=void 0,this.updatePosition({zoom:e,currentPos:i}),this.staticImgNode=o}})}setPointCloudBoxList(t){this.pointCloudBoxList=t}setHiddenText(t){this.hiddenText=t,this.render()}setConfig(t){this.config=t}getSpecificStyle(t){const e=___default.default.pick(t,["stroke","thickness","fill","radius"]),i=__spreadValues(__spreadValues({},this.style),e);return i.stroke&&Object.assign(i,{color:i.stroke}),i}getFontStyle(t,e){var i,o;const r=(i=t==null?void 0:t.fontSize)!=null?i:14,a=(o=t==null?void 0:t.fontFamily)!=null?o:"Arial";return __spreadProps(__spreadValues({},annotation.DEFAULT_TEXT_SHADOW),{color:e.stroke,font:`normal normal 600 ${r}px ${a}`})}appendOffset({x:t,y:e}){return{x:t+annotation.DEFAULT_TEXT_OFFSET.offsetX,y:e+annotation.DEFAULT_TEXT_OFFSET.offsetY}}getRenderText(t,e=!1){let i="",o="";return!t||e===!0?{headerText:i,bottomText:o}:((t==null?void 0:t.order)&&(i=`${t.order}`),(t==null?void 0:t.label)&&(i?i=`${i}_${t.label}`:i=`${t.label}`),(t==null?void 0:t.attribute)&&(i?i=`${i} ${t.attribute}`:i=`${t.attribute}`),(t==null?void 0:t.textAttribute)&&(o=t==null?void 0:t.textAttribute),(t==null?void 0:t.subAttributeText)&&(i+=t==null?void 0:t.subAttributeText),{headerText:i,bottomText:o})}getReferenceOptions(t){return t?{lineCap:"butt",lineDash:[20,20]}:{}}focusPositionByPointList(t){if(!this.needUpdatePosition)return;const e=MathUtils.default.calcViewportBoundaries(t),i={x:e.left,y:e.top,width:e.right-e.left,height:e.bottom-e.top},o=lbUtils.ImgPosUtils.getBasicRecPos(this.imgNode,i,this.size,.5);if(o){this.setCurrentPos(o.currentPos),this.setCurrentPosStorage(o.currentPos);const{imgInfo:r}=this,{innerZoom:a}=this.innerPosAndZoom;r&&this.setImgInfo(__spreadProps(__spreadValues({},r),{width:r.width/a*o.innerZoom,height:r.height/a*o.innerZoom})),this.setZoom(o.innerZoom),this.render(),this.renderBasicCanvas()}}renderConnectionPoints(){this.connectionPoints.forEach(t=>{const e=AxisUtils.default.changePointByZoom(t,this.zoom,this.currentPos);DrawUtils.drawCircleWithFill(this.canvas,e,4,{color:"#fff"}),DrawUtils.drawCircleWithFill(this.canvas,e,2,{color:"#000"})})}renderAttribute(){___default.default.chunk(this.annotations,6).forEach(e=>{var i,o;const r=e.find(c=>c.type==="polygon");if(!r)return;const{fontStyle:a}=this.getRenderStyle(r),n=r.annotation,l=(i=this.pointCloudBoxList)==null?void 0:i.find(c=>c.id===n.id),s=this.hiddenText?"":l==null?void 0:l.attribute,d=AxisUtils.default.changePointListByZoom((o=n==null?void 0:n.pointList)!=null?o:[],this.zoom,this.currentPos);s&&DrawUtils.drawText(this.canvas,this.appendOffset(d[0]),s,a)})}getRenderStyle(t){const e=this.getSpecificStyle(t.annotation),i=this.getFontStyle(t.annotation,e);return{style:e,fontStyle:i}}renderLine(t){var e,i,o;if(t.type!=="line")return;const{style:r,fontStyle:a}=this.getRenderStyle(t),n=t.annotation;if(!(((e=n==null?void 0:n.pointList)==null?void 0:e.length)>=2))return;const{lineType:l=tool.ELineTypes.Line}=n,s=AxisUtils.default.changePointListByZoom((i=n==null?void 0:n.pointList)!=null?i:[],this.zoom,this.currentPos),d=__spreadProps(__spreadValues(__spreadValues({},r),this.getReferenceOptions(n==null?void 0:n.isReference)),{lineType:l,strokeColor:r.stroke});let c=[];if(n.showKeyPoint?c=DrawUtils.drawPolygonWithKeyPoint(this.canvas,s,d):c=DrawUtils.drawPolygon(this.canvas,s,d),(n==null?void 0:n.showDirection)===!0&&((o=n==null?void 0:n.pointList)==null?void 0:o.length)>=2){let v=s[0],p=MathUtils.default.getLineCenterPoint([s[0],s[1]]);if(l===tool.ELineTypes.Curve){const f=Math.floor(tool.SEGMENT_NUMBER/2);v=c[f],p=c[f+1]}DrawUtils.drawArrowByCanvas(this.canvas,v,p,{color:r.stroke,thickness:r.thickness}),DrawUtils.drawCircle(this.canvas,s[0],r.thickness+6,{color:r.stroke,thickness:r.thickness})}const{headerText:u,bottomText:y}=this.getRenderText(n,n==null?void 0:n.hiddenText);if(u&&DrawUtils.drawText(this.canvas,this.appendOffset(s[0]),u,a),y){const v=s[s.length-1];DrawUtils.drawText(this.canvas,this.appendOffset({x:v.x+annotation.TEXT_ATTRIBUTE_OFFSET.x,y:v.y+annotation.TEXT_ATTRIBUTE_OFFSET.y}),y,a)}}renderPolygon(t){var e,i,o,r,a;if(t.type!=="polygon")return;const{style:n,fontStyle:l}=this.getRenderStyle(t),s=t.annotation;if(!(((e=s==null?void 0:s.pointList)==null?void 0:e.length)>=3))return;const{lineType:d=tool.ELineTypes.Line}=s,c=AxisUtils.default.changePointListByZoom((i=s==null?void 0:s.pointList)!=null?i:[],this.zoom,this.currentPos);if(s.id===this.mouseHoverID||n.fill){const f=rgba__default.default((r=(o=n==null?void 0:n.fill)!=null?o:n==null?void 0:n.stroke)!=null?r:DEFAULT_STROKE_COLOR),m=`rgba(${f[0]}, ${f[1]}, ${f[2]},${f[3]*.8})`;DrawUtils.drawPolygonWithFill(this.canvas,c,{color:m,lineType:d})}const h=__spreadProps(__spreadValues(__spreadProps(__spreadValues({},n),{isClose:!0}),this.getReferenceOptions(s==null?void 0:s.isReference)),{lineType:d,strokeColor:n.stroke});let u=[];if(s.showKeyPoint?u=DrawUtils.drawPolygonWithKeyPoint(this.canvas,c,h):u=DrawUtils.drawPolygon(this.canvas,c,h),(s==null?void 0:s.showDirection)===!0&&((a=s==null?void 0:s.pointList)==null?void 0:a.length)>=2){let f=c[0],m=MathUtils.default.getLineCenterPoint([c[0],c[1]]);if(d===tool.ELineTypes.Curve){const x=Math.floor(tool.SEGMENT_NUMBER/2);f=u[x],m=u[x+1]}DrawUtils.drawArrowByCanvas(this.canvas,f,m,{color:n.stroke,thickness:n.thickness}),DrawUtils.drawCircle(this.canvas,c[0],n.thickness+6,{color:n.stroke,thickness:n.thickness})}const{headerText:v,bottomText:p}=this.getRenderText(s,s==null?void 0:s.hiddenText);if(v&&DrawUtils.drawText(this.canvas,this.appendOffset(c[0]),v,l),p){const f=c[c.length-2];DrawUtils.drawText(this.canvas,this.appendOffset({x:f.x+annotation.TEXT_ATTRIBUTE_OFFSET.x,y:f.y+annotation.TEXT_ATTRIBUTE_OFFSET.y}),p,l)}}renderSingleCuboid(t){var e,i;const{style:o}=this.getRenderStyle(t),r=t.annotation,a=rgba__default.default((i=(e=o==null?void 0:o.fill)!=null?e:o==null?void 0:o.stroke)!=null?i:DEFAULT_STROKE_COLOR),n=`rgba(${a[0]}, ${a[1]}, ${a[2]},${a[3]*.8})`,l=o.stroke,s=AxisUtils.default.changeCuboidByZoom(r,this.zoom,this.currentPos),{headerText:d,bottomText:c}=this.getRenderText(r,r==null?void 0:r.hiddenText);DrawUtils.drawCuboidWithText(this.canvas,s,{strokeColor:l,fillColor:n,thickness:o.thickness},{config:this.config,hiddenText:r==null?void 0:r.hiddenText,headerText:d,bottomText:c})}renderBox3d(t){var e;if(t.type!=="box3d")return;const i=t.annotation,{transferViewData:o}=(e=matrix.pointCloudLidar2image(i,i.calib))!=null?e:{};if(!o)return;const r={fill:"transparent"},a=___default.default.pick(i,["stroke","thickness"]);o.forEach((n,l)=>{const s=__spreadValues(__spreadProps(__spreadValues({},a),{id:`${t.annotation.id}-${l}`,pointList:n.pointList}),r);switch(n.type){case"line":this.renderLine({type:"line",annotation:s});break;case"polygon":this.renderPolygon({type:"polygon",annotation:s});break}})}renderPixelPoints(t){var e;if(t.type!=="pixelPoints")return;const i=t.annotation;if(!this.imgNode){console.error("Need to load after imgLoaded");return}if(!(i.length>0)){console.warn("Empty pixelPoints");return}const o=this.imgNode.src+i.length+t.defaultRGBA,r=(e=this.cacheCanvas)==null?void 0:e[o];if(r){DrawUtils.drawImg(this.canvas,r,{zoom:this.zoom,currentPos:this.currentPos});return}const a={width:this.imgNode.width,height:this.imgNode.height},{ctx:n,canvas:l}=CanvasUtils.createCanvas(a),s=typeof t.pixelSize=="number"?t.pixelSize:13;n&&(i==null?void 0:i.length)>0&&(DrawUtils.drawPixel({canvas:l,points:i,size:a,defaultRGBA:t.defaultRGBA,pixelSize:s}),DrawUtils.drawImg(this.canvas,l,{zoom:this.zoom,currentPos:this.currentPos}),this.cacheCanvas={[o]:l})}render(){try{if(this.staticImgNode||(super.render(),this.loading===!0))return;const t=this.annotations.filter(e=>e.type==="text"&&e.annotation.position==="rt").map(e=>e.annotation);this.renderDomInstance.render(t),this.annotations.forEach(e=>{var i,o,r,a,n,l,s;const d=this.getSpecificStyle(e.annotation),c=this.getFontStyle(e.annotation,d);switch(e.type){case"rect":{const h=e.annotation,{hiddenText:u=!1,isReference:y,hiddenRectSize:v=!1}=h,{zoom:p}=this,f=AxisUtils.default.changeRectByZoom(h,this.zoom,this.currentPos),{x:m,y:x,width:w,height:b}=f,P=rgba__default.default((o=(i=d==null?void 0:d.fill)!=null?i:d==null?void 0:d.stroke)!=null?o:DEFAULT_STROKE_COLOR),C=`rgba(${P[0]}, ${P[1]}, ${P[2]},${P[3]*.8})`;(h.id===this.mouseHoverID||d.fill)&&DrawUtils.drawRectWithFill(this.canvas,f,{color:C}),DrawUtils.drawRect(this.canvas,f,__spreadValues(__spreadProps(__spreadValues({},d),{hiddenText:!0}),this.getReferenceOptions(y))),(h==null?void 0:h.isHighlight)&&DrawUtils.drawHighlightFlag({canvas:this.canvas,color:C,position:{x:m-16,y:x-16}});const{headerText:S,bottomText:T}=this.getRenderText(h,h==null?void 0:h.hiddenText);S&&DrawUtils.drawText(this.canvas,{x:m,y:x-6},S,__spreadValues({textMaxWidth:300},c));const k=`${Math.round(w/p)} * ${Math.round(b/p)}`,I=k.length*7;if(!u&&!v&&DrawUtils.drawText(this.canvas,{x:m+w-I,y:x+b+15},k,c),T){const R=20,E=Math.max(20,w-I);DrawUtils.drawText(this.canvas,{x:m,y:x+b+R},h.textAttribute,__spreadValues({textMaxWidth:E},c))}break}case"polygon":{this.renderPolygon(e);break}case"line":{this.renderLine(e);break}case"point":{const h=e.annotation,u=AxisUtils.default.changePointByZoom(h,this.zoom,this.currentPos),y=(r=d.radius)!=null?r:DEFAULT_RADIUS;DrawUtils.drawCircle(this.canvas,u,y,d);const{headerText:v,bottomText:p}=this.getRenderText(h,h==null?void 0:h.hiddenText);v&&DrawUtils.drawText(this.canvas,{x:u.x+y/2,y:u.y-y-4},v,__spreadValues({textAlign:"center"},c)),p&&DrawUtils.drawText(this.canvas,this.appendOffset({x:u.x+y,y:u.y+y+24}),p,c);break}case"text":{const h=e.annotation,{text:u,x:y,y:v,textMaxWidth:p,color:f="white",background:m="rgba(0, 0, 0, 0.6)",lineHeight:x=25,font:w=tool.DEFAULT_FONT,position:b,offset:P}=h,C=10,S=10,T=AxisUtils.default.changePointByZoom({x:y,y:v},this.zoom,this.currentPos);P&&(T.x+=(a=P.x)!=null?a:0,T.y+=(n=P.y)!=null?n:0);const{width:k,height:I,fontHeight:R=0}=MathUtils.default.getTextArea(this.canvas,h.text,p,w,x);if(b==="rt")break;DrawUtils.drawRectWithFill(this.canvas,{x:T.x,y:T.y,width:k+S*2,height:I+C*2,id:"",sourceID:"",valid:!0,textAttribute:"",attribute:""},{color:m}),DrawUtils.drawText(this.canvas,{x:T.x+S,y:T.y+R+C},u,{color:f,lineHeight:x,font:w,textMaxWidth:p});break}case"box3d":{this.renderBox3d(e);break}case"cuboid":{this.renderSingleCuboid(e);break}case"pixelPoints":{this.renderPixelPoints(e);break}default:break}"renderEnhance"in e.annotation&&((s=(l=e.annotation).renderEnhance)==null||s.call(l,{ctx:this.ctx,canvas:this.canvas,currentPos:this.currentPos,zoom:this.zoom,data:e,toolInstance:this}))}),this.renderConnectionPoints(),this.renderAttribute()}catch(t){console.error("ViewOperation Render Error",t)}}getClickTargetId(t){const e=this.getCoordinateUnderZoom(t),i=AxisUtils.default.changePointByZoom(e,1/this.zoom);for(const o in this.convexHullGroup){if(!Object.prototype.hasOwnProperty.call(this.convexHullGroup,o))continue;const r=this.convexHullGroup[o].convexHull;if(PolygonUtils.isInPolygon(i,r))return o}}}module.exports=ViewOperation;
|
|
@@ -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=(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.keyCode===keyCode.A)&&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)}filterCacheContext(){}setAttributeLockList(t){this.attributeLockList=t,this.filterCacheContext(),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;
|
|
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 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 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,n,c,a,r,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=(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 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.onRightClick=this.onRightClick.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 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(__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:n,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 r=lbUtils.ImgPosUtils.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(__spreadProps(__spreadValues({},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),this.container.addEventListener("contextmenu",this.onRightClick),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),this.container.removeEventListener("contextmenu",this.onRightClick),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){}onRightClick(t){}onLeftDblClick(t){}onRightDblClick(t){this.clearImgDrag()}onKeyDown(t){switch((t.keyCode===keyCode.Alt||t.keyCode===keyCode.A)&&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 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;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)}filterCacheContext(){}setAttributeLockList(t){this.attributeLockList=t,this.filterCacheContext(),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,n,c,a,r,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=(n=this.config)==null?void 0:n.attributeList)==null?void 0:c.find(h=>h.value===t))==null?void 0:a.color)?(l=(r=lbUtils.toolStyleConverter.getColorByConfig({attribute:t,config:this.config}))==null?void 0:r.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;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var keyCode=require("../../constant/keyCode.js"),rectOperation=require("./rectOperation.js"),reCalcRect=require("./utils/reCalcRect.js"),__defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnPropDescs=Object.getOwnPropertyDescriptors,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(r,e,t)=>e in r?__defProp(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,__spreadValues=(r,e)=>{for(var t in e||(e={}))__hasOwnProp.call(e,t)&&__defNormalProp(r,t,e[t]);if(__getOwnPropSymbols)for(var t of __getOwnPropSymbols(e))__propIsEnum.call(e,t)&&__defNormalProp(r,t,e[t]);return r},__spreadProps=(r,e)=>__defProps(r,__getOwnPropDescs(e));class PointCloud2DRectOperation extends rectOperation.RectOperation{constructor(e){super(e);this.checkMode=e.checkMode}createNewDrawingRect(e,t){this.checkMode||super.createNewDrawingRect(e,t)}deleteSelectedRect(e){if(this.checkMode)return;const{selectedRects:t}=this;t.length&&e.stopPropagation(),this.emit("deleteSelectedRects",t)}setSelectedIdAfterAddingDrawingRect(){!this.drawingRect||(this.setSelectedRectID(this.drawingRect.id),this.emit("afterAddingDrawingRect",__spreadValues({},this.selectedRect)))}setSelectedRectID(e){this.checkMode||super.setSelectedRectID(e)}onKeyDown(e){if(this.checkMode||![keyCode.Delete,keyCode.R].includes(e.keyCode))return;super.onKeyDown(e);const{keyCode:t,ctrlKey:s,altKey:
|
|
1
|
+
"use strict";var keyCode=require("../../constant/keyCode.js"),rectOperation=require("./rectOperation.js"),reCalcRect=require("./utils/reCalcRect.js"),__defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnPropDescs=Object.getOwnPropertyDescriptors,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(r,e,t)=>e in r?__defProp(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,__spreadValues=(r,e)=>{for(var t in e||(e={}))__hasOwnProp.call(e,t)&&__defNormalProp(r,t,e[t]);if(__getOwnPropSymbols)for(var t of __getOwnPropSymbols(e))__propIsEnum.call(e,t)&&__defNormalProp(r,t,e[t]);return r},__spreadProps=(r,e)=>__defProps(r,__getOwnPropDescs(e));class PointCloud2DRectOperation extends rectOperation.RectOperation{constructor(e){super(e);this.checkMode=e.checkMode}createNewDrawingRect(e,t){this.checkMode||super.createNewDrawingRect(e,t)}deleteSelectedRect(e){if(this.checkMode)return;const{selectedRects:t}=this;t.length&&e.stopPropagation(),this.emit("deleteSelectedRects",t)}setSelectedIdAfterAddingDrawingRect(){!this.drawingRect||(this.setSelectedRectID(this.drawingRect.id),this.emit("afterAddingDrawingRect",__spreadValues({},this.selectedRect)))}setSelectedRectID(e){this.checkMode||super.setSelectedRectID(e)}onKeyDown(e){if(this.checkMode||![keyCode.Delete,keyCode.R].includes(e.keyCode))return;super.onKeyDown(e);const{keyCode:t,ctrlKey:s,altKey:i,shiftKey:c,metaKey:n}=e;switch(t){case keyCode.R:{if(s||i||c||n)return;this.resizeRect();break}}return!0}renderDrawingRect(e,t=this.zoom,s=!1){const i=(e==null?void 0:e.boxID)||(e==null?void 0:e.lineDash);super.renderDrawingRect(i?e:__spreadProps(__spreadValues({},e),{lineDash:[3]}),t,s)}resizeRect(e=100,t=100){var s;if(!this.imgNode||!((s=this.selectedRects)==null?void 0:s.length)||e<=0||t<=0||this.selectedRects[0].width<=e&&this.selectedRects[0].height<=t)return;const{width:i,height:c}=this.basicImgInfo,n={width:i,height:c,x:0,y:0},a=reCalcRect(this.selectedRects[0],n,e,t);a.noChange||(this.setRectList(this.rectList.map(o=>this.selectedIDs.includes(o.id)?__spreadValues(__spreadValues({},o),a):o),!0),this.render(),this.updateDragResult())}rightMouseUp(e){const t=super.rightMouseUp(e);return t&&this.emit("onRightClick",{event:e,targetId:t.boxID}),t}}module.exports=PointCloud2DRectOperation;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var _=require("lodash"),turf=require("@turf/turf"),MathUtils=require("../../utils/MathUtils.js"),AxisUtils=require("../../utils/tool/AxisUtils.js"),RectUtils=require("../../utils/tool/RectUtils.js"),TagUtils=require("../../utils/tool/TagUtils.js"),annotation=require("../../constant/annotation.js"),tool=require("../../constant/tool.js"),keyCode=require("../../constant/keyCode.js"),index=require("../../locales/index.js"),constants=require("../../locales/constants.js"),AttributeUtils=require("../../utils/tool/AttributeUtils.js"),CanvasUtils=require("../../utils/tool/CanvasUtils.js"),CommonToolUtils=require("../../utils/tool/CommonToolUtils.js"),DrawUtils=require("../../utils/tool/DrawUtils.js"),MarkerUtils=require("../../utils/tool/MarkerUtils.js"),polygonTool=require("../../utils/tool/polygonTool.js"),uuid=require("../../utils/uuid.js"),basicToolOperation=require("./basicToolOperation.js"),textAttributeClass=require("./textAttributeClass.js"),Selection=require("./Selection.js");function _interopDefaultLegacy(R){return R&&typeof R=="object"&&"default"in R?R:{default:R}}var ___default=_interopDefaultLegacy(_),__defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnPropDescs=Object.getOwnPropertyDescriptors,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(R,t,e)=>t in R?__defProp(R,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):R[t]=e,__spreadValues=(R,t)=>{for(var e in t||(t={}))__hasOwnProp.call(t,e)&&__defNormalProp(R,e,t[e]);if(__getOwnPropSymbols)for(var e of __getOwnPropSymbols(t))__propIsEnum.call(t,e)&&__defNormalProp(R,e,t[e]);return R},__spreadProps=(R,t)=>__defProps(R,__getOwnPropDescs(t));const scope=6;class RectOperation extends basicToolOperation.BasicToolOperation{constructor(t){super(t);this.highlightVisible=!1,this.enableAddRect=!0,this.setMarkerIndex=e=>{this.markerIndex=e},this.setMarkerIndexAndSelect=e=>{if(!this.config.markerList)return;this.markerIndex=e;const i=this.config.markerList[e].value,r=this.currentPageResult.find(n=>n.label===i);r&&(this.setSelectedRectID(r.id),this.config.attributeConfigurable===!0&&this.setDefaultAttribute(r.attribute)),this.emit("markIndexChange")},this.getHoverRectID=e=>{const i=this.getCoordinateUnderZoom(e),r=scope,{currentShowList:n}=this;if(n.length>0){if(this.selectedRectID){const{selectedRect:a}=this;if(a&&RectUtils.isInRect(i,a,r,this.zoom))return a.id}const s=n.filter(a=>RectUtils.isInRect(i,a,r,this.zoom));if(s.length===0)return"";if(s.length===1)return s[0].id;if(s.length>1)return s.map(o=>({size:o.width*o.height,id:o.id})).sort((o,h)=>o.size-h.size)[0].id}return""},this.getSelectedRectTextAttribute=e=>{if(e){const i=this.rectList.find(r=>r.id===e);return(i==null?void 0:i.textAttribute)||""}return""},this.setDefaultSubAttribute=()=>{var e,i,r,n;if(((e=this.config)==null?void 0:e.secondaryAttributeConfigurable)&&((i=this.config)==null?void 0:i.subAttributeList)){const s=TagUtils.getDefaultResultByConfig((n=(r=this.config)==null?void 0:r.subAttributeList)!=null?n:[]);this.setRectList(this.rectList.map(a=>{var o;if(a.id===this.selectedRectID){const h=(o=a==null?void 0:a.subAttribute)!=null?o:s;return __spreadProps(__spreadValues({},a),{subAttribute:h})}return a}),!0)}},this.textChange=e=>{this.config.textConfigurable!==!0||!this.selectedRectID||(this.setRectList(AttributeUtils.default.textChange(e,this.selectedRectID,this.rectList),!0),this.emit("selectedChange"),this.render())},this._drawOutSideTarget=t.drawOutSideTarget||!1,this.rectList=[],this.isFlow=!0,this.config=CommonToolUtils.jsonParser(t.config),this.hoverRectEdgeIndex=-1,this.hoverRectPointIndex=-1,this.selectedRectTextAttribute="",this.markerIndex=0,this.createNewDrawingRect=this.createNewDrawingRect.bind(this),this.getDrawingRectWithRectList=this.getDrawingRectWithRectList.bind(this),this.setSelectedIdAfterAddingDrawingRect=this.setSelectedIdAfterAddingDrawingRect.bind(this),this.getCurrentSelectedData=this.getCurrentSelectedData.bind(this),this.updateSelectedRectTextAttribute=this.updateSelectedRectTextAttribute.bind(this),this.setSelectedID=this.setSelectedID.bind(this),this.updateSelectedRectSubAttribute=this.updateSelectedRectSubAttribute.bind(this),this.selection=new Selection(this)}setResult(t){if(this.clearActiveStatus(),this.setRectList(t),this.hasMarkerConfig){const e=CommonToolUtils.getNextMarker(this.getCurrentPageResult(t),this.config.markerList);e&&this.setMarkerIndex(e.index)}this.render()}destroy(){super.destroy(),this._textAttributeInstance&&this._textAttributeInstance.clearTextAttribute()}setConfig(t,e=!1){this.config=CommonToolUtils.jsonParser(t),e===!0&&this.clearResult(!1)}setRectList(t,e=!1){const i=this.rectList.length;this.rectList=t,i!==t.length&&this.emit("updatePageNumber"),e&&this.emit("updateResult")}get selectedRectID(){return this.selectedIDs.length===1?this.selectedIDs[0]:void 0}get selectedID(){return this.selectedRectID}get drawOutSideTarget(){return this._drawOutSideTarget||this.config.drawOutsideTarget}get selectedRect(){return this.selectedRects.length===1?this.selectedRects[0]:void 0}get selectedIDs(){return this.selection.selectedIDs}get selectedRects(){return this.rectList.filter(t=>this.selectedIDs.includes(t.id))}get selectedText(){var t;return(t=this.selectedRect)==null?void 0:t.textAttribute}get dataList(){return this.rectList}get currentShowList(){let t=[];const[e,i]=CommonToolUtils.getRenderResultList(this.rectList,CommonToolUtils.getSourceID(this.basicResult),this.attributeLockList,this.selectedIDs);return t=e,this.isHidden&&(t=[]),i&&t.push(...i),t}get currentPageResult(){const[t]=CommonToolUtils.getRenderResultList(this.rectList,CommonToolUtils.getSourceID(this.basicResult),[]);return t}getCurrentPageResult(t){const[e]=CommonToolUtils.getRenderResultList(t,CommonToolUtils.getSourceID(this.basicResult),[]);return e}setSelectedID(t){this.setSelectedRectID(t)}setSelectedRectID(t,e=!1){this.selection.setSelectedIDs(t,e),this.render(),this.emit("selectedChange")}setStyle(t){var e;super.setStyle(t),this._textAttributeInstance&&this.config.attributeConfigurable===!1&&((e=this._textAttributeInstance)==null||e.updateIcon(this.getTextIconSvg()))}updateSelectedRectTextAttribute(t){if(this._textAttributeInstance&&t&&this.selectedRectID){let e=t;AttributeUtils.default.textAttributeValidate(this.config.textCheckType,"",e)===!1&&(this.emit("messageError",AttributeUtils.default.getErrorNotice(this.config.textCheckType,this.lang)),e=""),this.setRectList(this.rectList.map(i=>i.id===this.selectedRectID?__spreadProps(__spreadValues({},i),{textAttribute:e}):i),!0),this.emit("updateTextAttribute"),this.render()}}updateSelectedRectSubAttribute(t,e){e&&this.config.secondaryAttributeConfigurable===!0&&this.selectedRectID&&(this.setRectList(this.rectList.map(i=>{var r;if(i.id===this.selectedRectID){const n=(r=i==null?void 0:i.subAttribute)!=null?r:{};return __spreadProps(__spreadValues({},i),{subAttribute:__spreadProps(__spreadValues({},n),{[t]:e})})}return i}),!0),this.render())}getHoverRectPointIndex(t){return this.selectedRect?AxisUtils.default.returnClosePointIndex(this.getCoordinateUnderZoom(t),RectUtils.getRectPointList(this.selectedRect,this.zoom),scope+2):-1}getHoverRectEdgeIndex(t){if(!this.selectedRect)return-1;let e=-1;const{selectedRect:i}=this,r=RectUtils.getRectEdgeList(i,this.zoom),n=this.getCoordinateUnderZoom(t);for(let s=0;s<r.length;s++){const a=r[s],{length:o}=MathUtils.default.getFootOfPerpendicular(n,a.begin,a.end);o<scope+10&&(e=s)}return e}getTextIconSvg(t=""){return AttributeUtils.default.getTextIconSvg(t,this.config.attributeList,this.config.attributeConfigurable,this.baseIcon)}onMouseDown(t){if(super.onMouseDown(t)||this.forbidMouseOperation||t.ctrlKey===!0)return;const e=this.getCoordinateUnderZoom(t),i=this.getHoverRectID(t);if(!(t.button===2||t.button===0&&this.isSpaceKey===!0)){if(this.selectedRectID){const r=this.currentShowList.find(n=>n.id===this.selectedRectID);if(!r)return;if(this.getHoverRectPointIndex(t)>-1){const n=tool.EDragTarget.Point;this.dragInfo={dragStartCoord:e,dragTarget:n,startTime:+new Date,firstRect:r},this.dragStatus=annotation.EDragStatus.Start;return}if(this.getHoverRectEdgeIndex(t)>-1){const n=tool.EDragTarget.Line;this.dragInfo={dragStartCoord:e,dragTarget:n,startTime:+new Date,firstRect:r},this.dragStatus=annotation.EDragStatus.Start;return}}if(this.selection.isIdSelected(i)&&!this.drawingRect){const r=tool.EDragTarget.Plane;this.dragInfo={dragStartCoord:e,dragTarget:r,firstRect:this.selectedRect,startTime:+new Date,originRectList:this.selectedRects},this.dragStatus=annotation.EDragStatus.Start}}}appendOffsetRect(t,e){return __spreadProps(__spreadValues({},t),{x:t.x+e.x/this.zoom,y:t.y+e.y/this.zoom})}getRectsBoundaries(t,e){const i=t.reduce((r,n)=>r.concat(...RectUtils.getRectPointList(this.appendOffsetRect(n,e))),[]);return MathUtils.default.calcViewportBoundaries(i)}isRectsOutOfTarget(t,e){var i,r,n,s;if(this.drawOutSideTarget!==!1)return!1;const a=this.getRectsBoundaries(t,e),o={y:a.top,x:a.left,height:a.bottom-a.top,width:a.right-a.left};if(((r=(i=this.basicResult)==null?void 0:i.pointList)==null?void 0:r.length)>0)return RectUtils.isRectNotInPolygon(o,polygonTool.getPolygonPointUnderZoom(this.basicResult.pointList,this.zoom));if(this.basicResult||this.imgInfo){const h=this.basicResult?this.basicResult:{x:0,y:0,height:(n=this.imgNode)==null?void 0:n.height,width:(s=this.imgNode)==null?void 0:s.width};if(h)return[{x:a.left,y:a.top},{x:a.right,y:a.bottom}].some(d=>!RectUtils.isInRect(d,h))}return!1}moveRects(t){var e;if((e=this.dragInfo)==null?void 0:e.originRectList){let i=___default.default.cloneDeep(this.dragInfo.originRectList);if(this.isRectsOutOfTarget(i,t))return;i=this.dragInfo.originRectList.map(r=>__spreadProps(__spreadValues({},r),{x:r.x+t.x/this.zoom,y:r.y+t.y/this.zoom})),this.setRectList(this.rectList.map(r=>{const n=i.find(s=>s.id===r.id);return n||r}))}}onDragMoveAll(t){var e,i;!((i=(e=this.dragInfo)==null?void 0:e.originRectList)==null?void 0:i.length)||(this.setRectList(this.dragInfo.originRectList.map(r=>__spreadProps(__spreadValues({},r),{x:r.x+t.x/this.zoom,y:r.y+t.y/this.zoom}))),this.render())}onDragMove(t){var e,i,r,n;if(!this.dragInfo)return;const s={x:t.x-this.dragInfo.dragStartCoord.x,y:t.y-this.dragInfo.dragStartCoord.y};if(this.dragStatus=annotation.EDragStatus.Move,this.dragInfo.dragTarget===tool.EDragTarget.Plane){this.moveRects(s);return}if(!this.dragInfo.firstRect)return;const a=RectUtils.getRectUnderZoom(this.dragInfo.firstRect,this.zoom),{x:o,y:h,width:d,height:c}=a;let l=this.rectList.filter(u=>u.id===this.selectedRectID)[0];switch(this.dragInfo.dragTarget){case tool.EDragTarget.Point:{let u=o,f=h,b=d,g=c;switch(this.hoverRectPointIndex){case 0:{u=d-s.x<0?o+d:o+s.x,f=c-s.y<0?h+c:h+s.y,b=Math.abs(s.x-d),g=Math.abs(s.y-c);break}case 1:{u=d+s.x>0?o:o+d+s.x,f=c-s.y<0?h+c:h+s.y,b=Math.abs(d+s.x),g=Math.abs(c-s.y);break}case 2:{u=d+s.x>0?o:o+d+s.x,f=c+s.y>0?h:h+c+s.y,b=Math.abs(d+s.x),g=c+s.y>0?c+s.y:Math.abs(c+s.y);break}case 3:{u=d-s.x<0?o+d:o+s.x,f=c+s.y>0?h:h+c+s.y,b=Math.abs(s.x-d),g=c+s.y>0?c+s.y:Math.abs(c+s.y);break}default:return}l=__spreadProps(__spreadValues({},l),{x:u,y:f,width:b,height:g})}break;case tool.EDragTarget.Line:{let u=o,f=h,b=d,g=c;switch(this.hoverRectEdgeIndex){case 0:{f=c-s.y<0?h+c:h+s.y,g=Math.abs(s.y-c);break}case 1:{u=d+s.x>0?o:o+d+s.x,b=Math.abs(d+s.x);break}case 2:{f=c+s.y>0?h:h+c+s.y,g=c+s.y>0?c+s.y:Math.abs(c+s.y);break}case 3:{u=d-s.x<0?o+d:o+s.x,b=Math.abs(s.x-d);break}default:return}l=__spreadProps(__spreadValues({},l),{x:u,y:f,width:b,height:g});break}default:return}if(this.drawOutSideTarget===!1){if(this.basicResult){if(((i=(e=this.basicResult)==null?void 0:e.pointList)==null?void 0:i.length)>0&&RectUtils.isRectNotInPolygon(l,polygonTool.getPolygonPointUnderZoom(this.basicResult.pointList,this.zoom)))return;const u=this.basicResult.x*this.zoom,f=this.basicResult.y*this.zoom,b=this.basicResult.width*this.zoom,g=this.basicResult.height*this.zoom;if(l.x<u-.01||l.y<f-.01||l.width>u+b-l.x+.01||l.height>f+g-l.y+.01)return;if(l.x<u&&(l.x=u),l.y<f&&(l.y=f),l.width>u+b-l.x)switch(this.dragInfo.dragTarget){case tool.EDragTarget.Point:case tool.EDragTarget.Line:s.x>0&&s.y>0&&(l.width=u+b-l.x);break;default:return}if(l.height>f+g-l.y)switch(this.dragInfo.dragTarget){}}else if(l.x<0&&(l.x=0),l.y<0&&(l.y=0),this.imgInfo)switch(this.dragInfo.dragTarget){default:if(l.x+l.width>((r=this.imgInfo)==null?void 0:r.width)+.01||l.y+l.height>((n=this.imgInfo)==null?void 0:n.height)+.01)return}}this.setRectList(this.rectList.map(u=>u.id===l.id?RectUtils.getRectUnderZoom(l,1/this.zoom):u)),this.render()}onMouseMove(t){var e,i;if(super.onMouseMove(t)||this.forbidMouseOperation||!this.imgInfo)return;const r=this.getCoordinateUnderZoom(t),n=AxisUtils.default.changeDrawOutsideTarget(r,{x:0,y:0},this.imgInfo,this.drawOutSideTarget,this.basicResult,this.zoom);if(this.selectedIDs.length>0&&this.dragInfo){this.onDragMove(n);return}if(this.selectedRectID){const o=this.getHoverRectPointIndex(t);if(o!==this.hoverRectPointIndex){this.hoverRectPointIndex=o,this.hoverRectEdgeIndex=-1,this.render();return}if(this.hoverRectPointIndex===-1){const h=this.getHoverRectEdgeIndex(t);if(h!==this.hoverRectEdgeIndex){this.hoverRectEdgeIndex=h,this.render();return}}}const s=this.getHoverRectID(t),a=this.hoverRectID;if(this.hoverRectID=s,s!==a&&this.render(),this.enableAddRect&&this.drawingRect&&this.firstClickCoord){let{x:o,y:h}=this.firstClickCoord,{width:d,height:c}=this.drawingRect;if(d=Math.abs(o-n.x),c=Math.abs(h-n.y),n.x<o&&(o=n.x),n.y<h&&(h=n.y),this.drawOutSideTarget===!1){if(((i=(e=this.basicResult)==null?void 0:e.pointList)==null?void 0:i.length)>0&&RectUtils.isRectNotInPolygon(__spreadProps(__spreadValues({},this.drawingRect),{x:o,y:h,width:d,height:c}),polygonTool.getPolygonPointUnderZoom(this.basicResult.pointList,this.zoom)))return;n.x<0&&(d=Math.abs(this.firstClickCoord.x),o=0),n.y<0&&(c=Math.abs(this.firstClickCoord.y),h=0),this.imgInfo&&(o+d>this.imgInfo.width&&(d=Math.abs(this.imgInfo.width-o)),h+c>this.imgInfo.height&&(c=Math.abs(this.imgInfo.height-h)))}this.drawingRect=__spreadProps(__spreadValues({},this.drawingRect),{x:o,y:h,width:d,height:c}),this.render()}}setHighlightVisible(t){this.highlightVisible=t,this.setAttributeLockList([])}setAttributeLockList(t){this.setSelectedRectID(void 0),(t==null?void 0:t.length)&&(this.highlightVisible=!1),super.setAttributeLockList(t)}setBasicResult(t){super.setBasicResult(t),this.clearActiveStatus()}setRectValidAndRender(t){!t||(this.setRectList(this.rectList.map(e=>e.id===t?__spreadProps(__spreadValues({},e),{valid:!e.valid}):e),!0),this.render(),this.emit("updateResult"))}createNewDrawingRect(t,e){var i,r,n,s;if(!this.imgInfo)return;const a=this.getCoordinateUnderZoom(t),o=AxisUtils.default.changeDrawOutsideTarget(a,{x:0,y:0},this.imgInfo,this.drawOutSideTarget,this.basicResult,this.zoom);if(this.setSelectedRectID(""),this.hoverRectID="",this.drawOutSideTarget&&(o.x<0&&(o.x=0),o.y<0&&(o.y=0)),this.drawingRect=__spreadProps(__spreadValues({},o),{width:0,height:0,attribute:this.defaultAttribute,valid:!t.ctrlKey,id:uuid(8,62),sourceID:e,textAttribute:""}),this.hasMarkerConfig){const h=CommonToolUtils.getNextMarker(this.currentPageResult,this.config.markerList,this.markerIndex);if(h)this.drawingRect&&(this.drawingRect=__spreadProps(__spreadValues({},this.drawingRect),{label:h.label})),this.markerIndex=h.index,this.emit("markIndexChange");else{this.emit("messageInfo",index.getMessagesByLocale(constants.EMessage.MarkerFinish,this.lang)),this.drawingRect=void 0;return}}if(this.config.textConfigurable){let h="";h=AttributeUtils.default.getTextAttribute(this.rectList.filter(d=>CommonToolUtils.isSameSourceID(d.sourceID,e)),this.config.textCheckType),this.drawingRect&&(this.drawingRect=__spreadProps(__spreadValues({},this.drawingRect),{textAttribute:h}))}if(((i=this.config)==null?void 0:i.secondaryAttributeConfigurable)&&((r=this.config)==null?void 0:r.subAttributeList)){const h=TagUtils.getDefaultResultByConfig((s=(n=this.config)==null?void 0:n.subAttributeList)!=null?s:[]);this.drawingRect=__spreadProps(__spreadValues({},this.drawingRect),{subAttribute:h})}if(Object.assign(this.drawingRect,{order:CommonToolUtils.getMaxOrder(this.rectList.filter(h=>CommonToolUtils.isSameSourceID(h.sourceID,e)))+1}),this.firstClickCoord=__spreadValues({},o),this.firstCurrentPos=__spreadValues({},this.currentPos),this.dataInjectionAtCreation){const h=this.dataInjectionAtCreation(this.drawingRect);h&&Object.assign(this.drawingRect,h)}}addDrawingRectToRectList(){if(!this.drawingRect)return;let{width:t,height:e}=this.drawingRect;if(t/=this.zoom,e/=this.zoom,Math.round(t)<this.config.minWidth||Math.round(e)<this.config.minHeight){this.emit("messageInfo",index.getMessagesByLocale(constants.EMessage.RectErrorSizeNotice,this.lang)),this.clearDrawingStatus(),this.render();return}const i=this.getDrawingRectWithRectList();this.setRectList(i,!0),this.history.pushHistory(this.rectList),this.setSelectedIdAfterAddingDrawingRect(),this.clearDrawingStatus()}setSelectedIdAfterAddingDrawingRect(){!this.drawingRect||(this.config.textConfigurable?this.setSelectedRectID(this.drawingRect.id):this.setSelectedRectID())}getDrawingRectWithRectList(){if(!this.drawingRect)return this.rectList;let{x:t,y:e,width:i,height:r}=this.drawingRect;return t/=this.zoom,e/=this.zoom,i/=this.zoom,r/=this.zoom,[...this.rectList,__spreadProps(__spreadValues({},this.drawingRect),{x:t,y:e,width:i,height:r})]}rightMouseUp(t){var e,i,r,n,s;const a=this.getHoverRectID(t),o=this.rectList.find(h=>h.id===a);if(this.selectedRectTextAttribute="",this.drawingRect)this.drawingRect=void 0,this.firstClickCoord=void 0;else{if(((e=this.dragInfo)==null?void 0:e.dragStartCoord)&&turf.distance((i=this.dragInfo)==null?void 0:i.dragStartCoord,this.getCoordinateUnderZoom(t))>3&&this.dblClickListener.clearRightDblClick(),this.setSelectedRectID(a,t.ctrlKey),o&&((r=this.selectedIDs)==null?void 0:r.length)===1&&(this.selectedRectTextAttribute=this.getSelectedRectTextAttribute(a),this.setDefaultAttribute(o.attribute)),this.hoverRectID="",(o==null?void 0:o.label)&&this.hasMarkerConfig){const h=CommonToolUtils.getCurrentMarkerIndex(o.label,this.config.markerList);h>=0&&(this.setMarkerIndex(h),this.emit("markIndexChange"))}((n=this.config)==null?void 0:n.secondaryAttributeConfigurable)&&((s=this.config)==null?void 0:s.subAttributeList)&&this.setDefaultSubAttribute()}this.render()}shiftRightMouseUp(t){const e=this.getHoverRectID(t);this.emit("shiftRightMouseUp",e)}updateDragResult(){this.emit("updateDragResult",__spreadValues({},this.selectedRect))}setEnableAddRect(t){this.enableAddRect=t}onMouseUp(t){if(super.onMouseUp(t)||this.forbidMouseOperation||!this.imgInfo)return!0;if(this.dragInfo&&this.dragStatus===annotation.EDragStatus.Move){this.dragInfo=void 0,this.dragStatus=annotation.EDragStatus.Wait,this.history.pushHistory(this.rectList),this.emit("updateResult"),this.updateDragResult();return}if(t.button===2&&t.shiftKey===!0){this.shiftRightMouseUp(t);return}if(t.button===2){this.rightMouseUp(t);return}const e=CommonToolUtils.getSourceID(this.basicResult);if(this.drawingRect){this.enableAddRect?this.addDrawingRectToRectList():(this.clearDrawingStatus(),this.render());return}if(t.ctrlKey===!0&&t.button===0&&this.hoverRectID){this.setRectValidAndRender(this.hoverRectID);return}this.enableAddRect&&(this.createNewDrawingRect(t,e),this.render())}onRightDblClick(t){super.onRightDblClick(t);const e=this.getHoverRectID(t);this.selection.isIdSelected(e)&&this.deleteSelectedRect(t)}deleteSelectedRect(t){this.selectedRects.forEach(e=>{this.deleteRect(e.id)})}onKeyDown(t){if(!CommonToolUtils.hotkeyFilter(t)||super.onKeyDown(t)===!1||this.selection.triggerKeyboardEvent(t,this.setRectList.bind(this)))return;const{keyCode:e}=t;switch(e){case keyCode.Ctrl:this.drawingRect&&(this.drawingRect=__spreadProps(__spreadValues({},this.drawingRect),{valid:!t.ctrlKey}),this.render());break;case keyCode.F:this.selectedRectID&&this.setRectValidAndRender(this.selectedRectID);break;case keyCode.Z:this.setIsHidden(!this.isHidden),this.render();break;case keyCode.Delete:this.deleteSelectedRect(t);break;case keyCode.Tab:{if(t.preventDefault(),this.drawingRect)return;let i=annotation.ESortDirection.ascend;t.shiftKey&&(i=annotation.ESortDirection.descend);const[r,n]=CommonToolUtils.getRenderResultList(this.rectList,CommonToolUtils.getSourceID(this.basicResult),this.attributeLockList,this.selectedIDs);let s=[...r];n&&(s=[...s,...n]);const a=CanvasUtils.getViewPort(this.canvas,this.currentPos,this.zoom);s=s.filter(h=>CanvasUtils.inViewPort({x:h.x,y:h.y},a));const o=CommonToolUtils.getNextSelectedRectID(s,i,this.selectedRectID);o&&(this.setSelectedRectID(o.id),this.config.attributeConfigurable===!0&&this.setDefaultAttribute(o.attribute));break}default:{if(this.config.attributeConfigurable){const i=AttributeUtils.default.getAttributeByKeycode(e,this.config.attributeList);i!==void 0&&this.setDefaultAttribute(i)}break}}return!0}onKeyUp(t){switch(super.onKeyUp(t),t.keyCode){case keyCode.Ctrl:this.drawingRect&&(this.drawingRect=__spreadProps(__spreadValues({},this.drawingRect),{valid:!0}),this.render());break}}onWheel(t){const e=this.zoom;let i,r;this.drawingRect&&this.firstClickCoord&&(i=RectUtils.getRectUnderZoom(this.drawingRect,1/e),r=AxisUtils.default.changePointByZoom(this.firstClickCoord,1/e)),super.onWheel(t,!1),i&&r&&(this.drawingRect=RectUtils.getRectUnderZoom(i,this.zoom),this.firstClickCoord=AxisUtils.default.changePointByZoom(r,this.zoom)),this.render()}getCurrentSelectedData(){const{selectedRect:t}=this;if(!t)return;const e=this.getColor(t.attribute),i=t.valid?e==null?void 0:e.valid.stroke:e==null?void 0:e.invalid.stroke;return{width:t.width*this.zoom*.6,textAttribute:t.textAttribute,color:i}}getRenderStyle(t){const e=this.customRenderStyle&&this.customRenderStyle(t);if(e)return e;const i=this.getColor(t.attribute);let r,n;return t.valid===!1?(r=i==null?void 0:i.invalid.stroke,n=i==null?void 0:i.invalid.fill):(r=i==null?void 0:i.valid.stroke,n=i==null?void 0:i.valid.fill),{strokeColor:r,fillColor:n,textColor:r,toolColor:i}}renderTextAttribute(){var t;const{selectedRect:e}=this;if(!this.ctx||this.config.textConfigurable!==!0||!e)return;const{x:i,y:r,width:n,height:s,attribute:a,valid:o}=e,h=n*this.zoom*.6,d=AxisUtils.default.getOffsetCoordinate({x:i,y:r+s},this.currentPos,this.zoom),c=this.getColor(a),l=o?c==null?void 0:c.valid.stroke:c==null?void 0:c.invalid.stroke,u=4;this._textAttributeInstance||(this._textAttributeInstance=new textAttributeClass({width:h,container:this.container,icon:this.getTextIconSvg(a),color:l,getCurrentSelectedData:this.getCurrentSelectedData,updateSelectedTextAttribute:this.updateSelectedRectTextAttribute})),this._textAttributeInstance&&!((t=this._textAttributeInstance)==null?void 0:t.isExit)&&this._textAttributeInstance.appendToContainer(),this._textAttributeInstance.update(`${e.textAttribute}`,{left:d.x,top:d.y+u,color:l,width:h})}renderSelectedRect(t){if(!this.ctx||!t)return;const{ctx:e}=this;let i=10;const r=RectUtils.getRectPointList(t),n=r.length,s=this.getColor(t.attribute);r.forEach((a,o)=>{var h,d;if(e.save(),e.moveTo(a.x,a.y),e.beginPath(),this.hoverRectPointIndex===o?i=scope+6:i=scope,t.valid===!1?(e.strokeStyle=s==null?void 0:s.invalid.stroke,e.fillStyle=s==null?void 0:s.invalid.stroke):(e.strokeStyle=s==null?void 0:s.valid.stroke,e.fillStyle=s==null?void 0:s.valid.stroke),e.arc(a.x*this.zoom+this.currentPos.x,a.y*this.zoom+this.currentPos.y,i,0,2*Math.PI),e.fill(),this.hoverRectEdgeIndex===o){e.beginPath(),e.lineWidth=10;const c=this.getColor(t.attribute),l=t.valid===!1?(h=c==null?void 0:c.invalid)==null?void 0:h.stroke:(d=c==null?void 0:c.valid)==null?void 0:d.stroke;e.strokeStyle=l,e.moveTo(r[o].x*this.zoom+this.currentPos.x,r[o].y*this.zoom+this.currentPos.y),e.lineTo(r[(o+1)%n].x*this.zoom+this.currentPos.x,r[(o+1)%n].y*this.zoom+this.currentPos.y),e.stroke()}e.restore()}),this.renderTextAttribute()}renderDrawingRect(t,e=this.zoom,i=!1){var r,n,s,a,o,h;if(this.ctx&&t){const{ctx:d,style:c}=this,{hiddenText:l=!1}=c;d.save();const{strokeColor:u,fillColor:f,textColor:b}=this.getRenderStyle(t);d.font="lighter 14px Arial";let g="";((r=this.config)==null?void 0:r.isShowOrder)&&t.order&&(t==null?void 0:t.order)>0&&(g=`${t.order}`),t.label&&this.hasMarkerConfig&&(g=`${CommonToolUtils.getCurrentMarkerIndex(t.label,this.config.markerList)+1}_${MarkerUtils.getMarkerShowText(t.label,this.config.markerList)}`),t.attribute&&(g=`${g} ${AttributeUtils.default.getAttributeShowText(t.attribute,(n=this.config)==null?void 0:n.attributeList)}`,(t==null?void 0:t.subAttribute)&&((s=this.config)==null?void 0:s.secondaryAttributeConfigurable)&&((a=this.config)==null?void 0:a.subAttributeList)&&TagUtils.getTagNameList(t.subAttribute,this.config.subAttributeList).forEach(v=>{g+=`
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var _=require("lodash"),turf=require("@turf/turf"),MathUtils=require("../../utils/MathUtils.js"),AxisUtils=require("../../utils/tool/AxisUtils.js"),RectUtils=require("../../utils/tool/RectUtils.js"),TagUtils=require("../../utils/tool/TagUtils.js"),annotation=require("../../constant/annotation.js"),tool=require("../../constant/tool.js"),keyCode=require("../../constant/keyCode.js"),index=require("../../locales/index.js"),constants=require("../../locales/constants.js"),AttributeUtils=require("../../utils/tool/AttributeUtils.js"),CanvasUtils=require("../../utils/tool/CanvasUtils.js"),CommonToolUtils=require("../../utils/tool/CommonToolUtils.js"),DrawUtils=require("../../utils/tool/DrawUtils.js"),MarkerUtils=require("../../utils/tool/MarkerUtils.js"),polygonTool=require("../../utils/tool/polygonTool.js"),uuid=require("../../utils/uuid.js"),basicToolOperation=require("./basicToolOperation.js"),textAttributeClass=require("./textAttributeClass.js"),Selection=require("./Selection.js");function _interopDefaultLegacy(R){return R&&typeof R=="object"&&"default"in R?R:{default:R}}var ___default=_interopDefaultLegacy(_),__defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnPropDescs=Object.getOwnPropertyDescriptors,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(R,t,e)=>t in R?__defProp(R,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):R[t]=e,__spreadValues=(R,t)=>{for(var e in t||(t={}))__hasOwnProp.call(t,e)&&__defNormalProp(R,e,t[e]);if(__getOwnPropSymbols)for(var e of __getOwnPropSymbols(t))__propIsEnum.call(t,e)&&__defNormalProp(R,e,t[e]);return R},__spreadProps=(R,t)=>__defProps(R,__getOwnPropDescs(t));const scope=6;class RectOperation extends basicToolOperation.BasicToolOperation{constructor(t){super(t);this.highlightVisible=!1,this.enableAddRect=!0,this.setMarkerIndex=e=>{this.markerIndex=e},this.setMarkerIndexAndSelect=e=>{if(!this.config.markerList)return;this.markerIndex=e;const i=this.config.markerList[e].value,r=this.currentPageResult.find(n=>n.label===i);r&&(this.setSelectedRectID(r.id),this.config.attributeConfigurable===!0&&this.setDefaultAttribute(r.attribute)),this.emit("markIndexChange")},this.getHoverRectID=e=>{const i=this.getCoordinateUnderZoom(e),r=scope,{currentShowList:n}=this;if(n.length>0){if(this.selectedRectID){const{selectedRect:a}=this;if(a&&RectUtils.isInRect(i,a,r,this.zoom))return a.id}const s=n.filter(a=>RectUtils.isInRect(i,a,r,this.zoom));if(s.length===0)return"";if(s.length===1)return s[0].id;if(s.length>1)return s.map(o=>({size:o.width*o.height,id:o.id})).sort((o,h)=>o.size-h.size)[0].id}return""},this.getSelectedRectTextAttribute=e=>{if(e){const i=this.rectList.find(r=>r.id===e);return(i==null?void 0:i.textAttribute)||""}return""},this.setDefaultSubAttribute=()=>{var e,i,r,n;if(((e=this.config)==null?void 0:e.secondaryAttributeConfigurable)&&((i=this.config)==null?void 0:i.subAttributeList)){const s=TagUtils.getDefaultResultByConfig((n=(r=this.config)==null?void 0:r.subAttributeList)!=null?n:[]);this.setRectList(this.rectList.map(a=>{var o;if(a.id===this.selectedRectID){const h=(o=a==null?void 0:a.subAttribute)!=null?o:s;return __spreadProps(__spreadValues({},a),{subAttribute:h})}return a}),!0)}},this.textChange=e=>{this.config.textConfigurable!==!0||!this.selectedRectID||(this.setRectList(AttributeUtils.default.textChange(e,this.selectedRectID,this.rectList),!0),this.emit("selectedChange"),this.render())},this._drawOutSideTarget=t.drawOutSideTarget||!1,this.rectList=[],this.isFlow=!0,this.config=CommonToolUtils.jsonParser(t.config),this.hoverRectEdgeIndex=-1,this.hoverRectPointIndex=-1,this.selectedRectTextAttribute="",this.markerIndex=0,this.createNewDrawingRect=this.createNewDrawingRect.bind(this),this.getDrawingRectWithRectList=this.getDrawingRectWithRectList.bind(this),this.setSelectedIdAfterAddingDrawingRect=this.setSelectedIdAfterAddingDrawingRect.bind(this),this.getCurrentSelectedData=this.getCurrentSelectedData.bind(this),this.updateSelectedRectTextAttribute=this.updateSelectedRectTextAttribute.bind(this),this.setSelectedID=this.setSelectedID.bind(this),this.updateSelectedRectSubAttribute=this.updateSelectedRectSubAttribute.bind(this),this.selection=new Selection(this)}setResult(t){if(this.clearActiveStatus(),this.setRectList(t),this.hasMarkerConfig){const e=CommonToolUtils.getNextMarker(this.getCurrentPageResult(t),this.config.markerList);e&&this.setMarkerIndex(e.index)}this.render()}destroy(){super.destroy(),this._textAttributeInstance&&this._textAttributeInstance.clearTextAttribute()}setConfig(t,e=!1){this.config=CommonToolUtils.jsonParser(t),e===!0&&this.clearResult(!1)}setRectList(t,e=!1){const i=this.rectList.length;this.rectList=t,i!==t.length&&this.emit("updatePageNumber"),e&&this.emit("updateResult")}get selectedRectID(){return this.selectedIDs.length===1?this.selectedIDs[0]:void 0}get selectedID(){return this.selectedRectID}get drawOutSideTarget(){return this._drawOutSideTarget||this.config.drawOutsideTarget}get selectedRect(){return this.selectedRects.length===1?this.selectedRects[0]:void 0}get selectedIDs(){return this.selection.selectedIDs}get selectedRects(){return this.rectList.filter(t=>this.selectedIDs.includes(t.id))}get selectedText(){var t;return(t=this.selectedRect)==null?void 0:t.textAttribute}get dataList(){return this.rectList}get currentShowList(){let t=[];const[e,i]=CommonToolUtils.getRenderResultList(this.rectList,CommonToolUtils.getSourceID(this.basicResult),this.attributeLockList,this.selectedIDs);return t=e,this.isHidden&&(t=[]),i&&t.push(...i),t}get currentPageResult(){const[t]=CommonToolUtils.getRenderResultList(this.rectList,CommonToolUtils.getSourceID(this.basicResult),[]);return t}getCurrentPageResult(t){const[e]=CommonToolUtils.getRenderResultList(t,CommonToolUtils.getSourceID(this.basicResult),[]);return e}setSelectedID(t){this.setSelectedRectID(t)}setSelectedRectID(t,e=!1){this.selection.setSelectedIDs(t,e),this.render(),this.emit("selectedChange")}setStyle(t){var e;super.setStyle(t),this._textAttributeInstance&&this.config.attributeConfigurable===!1&&((e=this._textAttributeInstance)==null||e.updateIcon(this.getTextIconSvg()))}updateSelectedRectTextAttribute(t){if(this._textAttributeInstance&&t&&this.selectedRectID){let e=t;AttributeUtils.default.textAttributeValidate(this.config.textCheckType,"",e)===!1&&(this.emit("messageError",AttributeUtils.default.getErrorNotice(this.config.textCheckType,this.lang)),e=""),this.setRectList(this.rectList.map(i=>i.id===this.selectedRectID?__spreadProps(__spreadValues({},i),{textAttribute:e}):i),!0),this.emit("updateTextAttribute"),this.render()}}updateSelectedRectSubAttribute(t,e){e&&this.config.secondaryAttributeConfigurable===!0&&this.selectedRectID&&(this.setRectList(this.rectList.map(i=>{var r;if(i.id===this.selectedRectID){const n=(r=i==null?void 0:i.subAttribute)!=null?r:{};return __spreadProps(__spreadValues({},i),{subAttribute:__spreadProps(__spreadValues({},n),{[t]:e})})}return i}),!0),this.render())}getHoverRectPointIndex(t){return this.selectedRect?AxisUtils.default.returnClosePointIndex(this.getCoordinateUnderZoom(t),RectUtils.getRectPointList(this.selectedRect,this.zoom),scope+2):-1}getHoverRectEdgeIndex(t){if(!this.selectedRect)return-1;let e=-1;const{selectedRect:i}=this,r=RectUtils.getRectEdgeList(i,this.zoom),n=this.getCoordinateUnderZoom(t);for(let s=0;s<r.length;s++){const a=r[s],{length:o}=MathUtils.default.getFootOfPerpendicular(n,a.begin,a.end);o<scope+10&&(e=s)}return e}getTextIconSvg(t=""){return AttributeUtils.default.getTextIconSvg(t,this.config.attributeList,this.config.attributeConfigurable,this.baseIcon)}onMouseDown(t){if(super.onMouseDown(t)||this.forbidMouseOperation||t.ctrlKey===!0)return;const e=this.getCoordinateUnderZoom(t),i=this.getHoverRectID(t);if(!(t.button===2||t.button===0&&this.isSpaceKey===!0)){if(this.selectedRectID){const r=this.currentShowList.find(n=>n.id===this.selectedRectID);if(!r)return;if(this.getHoverRectPointIndex(t)>-1){const n=tool.EDragTarget.Point;this.dragInfo={dragStartCoord:e,dragTarget:n,startTime:+new Date,firstRect:r},this.dragStatus=annotation.EDragStatus.Start;return}if(this.getHoverRectEdgeIndex(t)>-1){const n=tool.EDragTarget.Line;this.dragInfo={dragStartCoord:e,dragTarget:n,startTime:+new Date,firstRect:r},this.dragStatus=annotation.EDragStatus.Start;return}}if(this.selection.isIdSelected(i)&&!this.drawingRect){const r=tool.EDragTarget.Plane;this.dragInfo={dragStartCoord:e,dragTarget:r,firstRect:this.selectedRect,startTime:+new Date,originRectList:this.selectedRects},this.dragStatus=annotation.EDragStatus.Start}}}appendOffsetRect(t,e){return __spreadProps(__spreadValues({},t),{x:t.x+e.x/this.zoom,y:t.y+e.y/this.zoom})}getRectsBoundaries(t,e){const i=t.reduce((r,n)=>r.concat(...RectUtils.getRectPointList(this.appendOffsetRect(n,e))),[]);return MathUtils.default.calcViewportBoundaries(i)}isRectsOutOfTarget(t,e){var i,r,n,s;if(this.drawOutSideTarget!==!1)return!1;const a=this.getRectsBoundaries(t,e),o={y:a.top,x:a.left,height:a.bottom-a.top,width:a.right-a.left};if(((r=(i=this.basicResult)==null?void 0:i.pointList)==null?void 0:r.length)>0)return RectUtils.isRectNotInPolygon(o,polygonTool.getPolygonPointUnderZoom(this.basicResult.pointList,this.zoom));if(this.basicResult||this.imgInfo){const h=this.basicResult?this.basicResult:{x:0,y:0,height:(n=this.imgNode)==null?void 0:n.height,width:(s=this.imgNode)==null?void 0:s.width};if(h)return[{x:a.left,y:a.top},{x:a.right,y:a.bottom}].some(d=>!RectUtils.isInRect(d,h))}return!1}moveRects(t){var e;if((e=this.dragInfo)==null?void 0:e.originRectList){let i=___default.default.cloneDeep(this.dragInfo.originRectList);if(this.isRectsOutOfTarget(i,t))return;i=this.dragInfo.originRectList.map(r=>__spreadProps(__spreadValues({},r),{x:r.x+t.x/this.zoom,y:r.y+t.y/this.zoom})),this.setRectList(this.rectList.map(r=>{const n=i.find(s=>s.id===r.id);return n||r}))}}onDragMoveAll(t){var e,i;!((i=(e=this.dragInfo)==null?void 0:e.originRectList)==null?void 0:i.length)||(this.setRectList(this.dragInfo.originRectList.map(r=>__spreadProps(__spreadValues({},r),{x:r.x+t.x/this.zoom,y:r.y+t.y/this.zoom}))),this.render())}onDragMove(t){var e,i,r,n;if(!this.dragInfo)return;const s={x:t.x-this.dragInfo.dragStartCoord.x,y:t.y-this.dragInfo.dragStartCoord.y};if(this.dragStatus=annotation.EDragStatus.Move,this.dragInfo.dragTarget===tool.EDragTarget.Plane){this.moveRects(s);return}if(!this.dragInfo.firstRect)return;const a=RectUtils.getRectUnderZoom(this.dragInfo.firstRect,this.zoom),{x:o,y:h,width:d,height:c}=a;let l=this.rectList.filter(u=>u.id===this.selectedRectID)[0];switch(this.dragInfo.dragTarget){case tool.EDragTarget.Point:{let u=o,f=h,b=d,g=c;switch(this.hoverRectPointIndex){case 0:{u=d-s.x<0?o+d:o+s.x,f=c-s.y<0?h+c:h+s.y,b=Math.abs(s.x-d),g=Math.abs(s.y-c);break}case 1:{u=d+s.x>0?o:o+d+s.x,f=c-s.y<0?h+c:h+s.y,b=Math.abs(d+s.x),g=Math.abs(c-s.y);break}case 2:{u=d+s.x>0?o:o+d+s.x,f=c+s.y>0?h:h+c+s.y,b=Math.abs(d+s.x),g=c+s.y>0?c+s.y:Math.abs(c+s.y);break}case 3:{u=d-s.x<0?o+d:o+s.x,f=c+s.y>0?h:h+c+s.y,b=Math.abs(s.x-d),g=c+s.y>0?c+s.y:Math.abs(c+s.y);break}default:return}l=__spreadProps(__spreadValues({},l),{x:u,y:f,width:b,height:g})}break;case tool.EDragTarget.Line:{let u=o,f=h,b=d,g=c;switch(this.hoverRectEdgeIndex){case 0:{f=c-s.y<0?h+c:h+s.y,g=Math.abs(s.y-c);break}case 1:{u=d+s.x>0?o:o+d+s.x,b=Math.abs(d+s.x);break}case 2:{f=c+s.y>0?h:h+c+s.y,g=c+s.y>0?c+s.y:Math.abs(c+s.y);break}case 3:{u=d-s.x<0?o+d:o+s.x,b=Math.abs(s.x-d);break}default:return}l=__spreadProps(__spreadValues({},l),{x:u,y:f,width:b,height:g});break}default:return}if(this.drawOutSideTarget===!1){if(this.basicResult){if(((i=(e=this.basicResult)==null?void 0:e.pointList)==null?void 0:i.length)>0&&RectUtils.isRectNotInPolygon(l,polygonTool.getPolygonPointUnderZoom(this.basicResult.pointList,this.zoom)))return;const u=this.basicResult.x*this.zoom,f=this.basicResult.y*this.zoom,b=this.basicResult.width*this.zoom,g=this.basicResult.height*this.zoom;if(l.x<u-.01||l.y<f-.01||l.width>u+b-l.x+.01||l.height>f+g-l.y+.01)return;if(l.x<u&&(l.x=u),l.y<f&&(l.y=f),l.width>u+b-l.x)switch(this.dragInfo.dragTarget){case tool.EDragTarget.Point:case tool.EDragTarget.Line:s.x>0&&s.y>0&&(l.width=u+b-l.x);break;default:return}if(l.height>f+g-l.y)switch(this.dragInfo.dragTarget){}}else if(l.x<0&&(l.x=0),l.y<0&&(l.y=0),this.imgInfo)switch(this.dragInfo.dragTarget){default:if(l.x+l.width>((r=this.imgInfo)==null?void 0:r.width)+.01||l.y+l.height>((n=this.imgInfo)==null?void 0:n.height)+.01)return}}this.setRectList(this.rectList.map(u=>u.id===l.id?RectUtils.getRectUnderZoom(l,1/this.zoom):u)),this.render()}onMouseMove(t){var e,i;if(super.onMouseMove(t)||this.forbidMouseOperation||!this.imgInfo)return;const r=this.getCoordinateUnderZoom(t),n=AxisUtils.default.changeDrawOutsideTarget(r,{x:0,y:0},this.imgInfo,this.drawOutSideTarget,this.basicResult,this.zoom);if(this.selectedIDs.length>0&&this.dragInfo){this.onDragMove(n);return}if(this.selectedRectID){const o=this.getHoverRectPointIndex(t);if(o!==this.hoverRectPointIndex){this.hoverRectPointIndex=o,this.hoverRectEdgeIndex=-1,this.render();return}if(this.hoverRectPointIndex===-1){const h=this.getHoverRectEdgeIndex(t);if(h!==this.hoverRectEdgeIndex){this.hoverRectEdgeIndex=h,this.render();return}}}const s=this.getHoverRectID(t),a=this.hoverRectID;if(this.hoverRectID=s,s!==a&&this.render(),this.enableAddRect&&this.drawingRect&&this.firstClickCoord){let{x:o,y:h}=this.firstClickCoord,{width:d,height:c}=this.drawingRect;if(d=Math.abs(o-n.x),c=Math.abs(h-n.y),n.x<o&&(o=n.x),n.y<h&&(h=n.y),this.drawOutSideTarget===!1){if(((i=(e=this.basicResult)==null?void 0:e.pointList)==null?void 0:i.length)>0&&RectUtils.isRectNotInPolygon(__spreadProps(__spreadValues({},this.drawingRect),{x:o,y:h,width:d,height:c}),polygonTool.getPolygonPointUnderZoom(this.basicResult.pointList,this.zoom)))return;n.x<0&&(d=Math.abs(this.firstClickCoord.x),o=0),n.y<0&&(c=Math.abs(this.firstClickCoord.y),h=0),this.imgInfo&&(o+d>this.imgInfo.width&&(d=Math.abs(this.imgInfo.width-o)),h+c>this.imgInfo.height&&(c=Math.abs(this.imgInfo.height-h)))}this.drawingRect=__spreadProps(__spreadValues({},this.drawingRect),{x:o,y:h,width:d,height:c}),this.render()}}setHighlightVisible(t){this.highlightVisible=t,this.setAttributeLockList([])}setAttributeLockList(t){this.setSelectedRectID(void 0),(t==null?void 0:t.length)&&(this.highlightVisible=!1),super.setAttributeLockList(t)}setBasicResult(t){super.setBasicResult(t),this.clearActiveStatus()}setRectValidAndRender(t){!t||(this.setRectList(this.rectList.map(e=>e.id===t?__spreadProps(__spreadValues({},e),{valid:!e.valid}):e),!0),this.render(),this.emit("updateResult"))}createNewDrawingRect(t,e){var i,r,n,s;if(!this.imgInfo)return;const a=this.getCoordinateUnderZoom(t),o=AxisUtils.default.changeDrawOutsideTarget(a,{x:0,y:0},this.imgInfo,this.drawOutSideTarget,this.basicResult,this.zoom);if(this.setSelectedRectID(""),this.hoverRectID="",this.drawOutSideTarget&&(o.x<0&&(o.x=0),o.y<0&&(o.y=0)),this.drawingRect=__spreadProps(__spreadValues({},o),{width:0,height:0,attribute:this.defaultAttribute,valid:!t.ctrlKey,id:uuid(8,62),sourceID:e,textAttribute:""}),this.hasMarkerConfig){const h=CommonToolUtils.getNextMarker(this.currentPageResult,this.config.markerList,this.markerIndex);if(h)this.drawingRect&&(this.drawingRect=__spreadProps(__spreadValues({},this.drawingRect),{label:h.label})),this.markerIndex=h.index,this.emit("markIndexChange");else{this.emit("messageInfo",index.getMessagesByLocale(constants.EMessage.MarkerFinish,this.lang)),this.drawingRect=void 0;return}}if(this.config.textConfigurable){let h="";h=AttributeUtils.default.getTextAttribute(this.rectList.filter(d=>CommonToolUtils.isSameSourceID(d.sourceID,e)),this.config.textCheckType),this.drawingRect&&(this.drawingRect=__spreadProps(__spreadValues({},this.drawingRect),{textAttribute:h}))}if(((i=this.config)==null?void 0:i.secondaryAttributeConfigurable)&&((r=this.config)==null?void 0:r.subAttributeList)){const h=TagUtils.getDefaultResultByConfig((s=(n=this.config)==null?void 0:n.subAttributeList)!=null?s:[]);this.drawingRect=__spreadProps(__spreadValues({},this.drawingRect),{subAttribute:h})}if(Object.assign(this.drawingRect,{order:CommonToolUtils.getMaxOrder(this.rectList.filter(h=>CommonToolUtils.isSameSourceID(h.sourceID,e)))+1}),this.firstClickCoord=__spreadValues({},o),this.firstCurrentPos=__spreadValues({},this.currentPos),this.dataInjectionAtCreation){const h=this.dataInjectionAtCreation(this.drawingRect);h&&Object.assign(this.drawingRect,h)}}addDrawingRectToRectList(){if(!this.drawingRect)return;let{width:t,height:e}=this.drawingRect;if(t/=this.zoom,e/=this.zoom,Math.round(t)<this.config.minWidth||Math.round(e)<this.config.minHeight){this.emit("messageInfo",index.getMessagesByLocale(constants.EMessage.RectErrorSizeNotice,this.lang)),this.clearDrawingStatus(),this.render();return}const i=this.getDrawingRectWithRectList();this.setRectList(i,!0),this.history.pushHistory(this.rectList),this.setSelectedIdAfterAddingDrawingRect(),this.clearDrawingStatus()}setSelectedIdAfterAddingDrawingRect(){!this.drawingRect||(this.config.textConfigurable?this.setSelectedRectID(this.drawingRect.id):this.setSelectedRectID())}getDrawingRectWithRectList(){if(!this.drawingRect)return this.rectList;let{x:t,y:e,width:i,height:r}=this.drawingRect;return t/=this.zoom,e/=this.zoom,i/=this.zoom,r/=this.zoom,[...this.rectList,__spreadProps(__spreadValues({},this.drawingRect),{x:t,y:e,width:i,height:r})]}rightMouseUp(t){var e,i,r,n,s;const a=this.getHoverRectID(t),o=this.rectList.find(h=>h.id===a);if(this.selectedRectTextAttribute="",this.drawingRect)this.drawingRect=void 0,this.firstClickCoord=void 0;else{if(((e=this.dragInfo)==null?void 0:e.dragStartCoord)&&turf.distance((i=this.dragInfo)==null?void 0:i.dragStartCoord,this.getCoordinateUnderZoom(t))>3&&this.dblClickListener.clearRightDblClick(),this.setSelectedRectID(a,t.ctrlKey),o&&((r=this.selectedIDs)==null?void 0:r.length)===1&&(this.selectedRectTextAttribute=this.getSelectedRectTextAttribute(a),this.setDefaultAttribute(o.attribute)),this.hoverRectID="",(o==null?void 0:o.label)&&this.hasMarkerConfig){const h=CommonToolUtils.getCurrentMarkerIndex(o.label,this.config.markerList);h>=0&&(this.setMarkerIndex(h),this.emit("markIndexChange"))}((n=this.config)==null?void 0:n.secondaryAttributeConfigurable)&&((s=this.config)==null?void 0:s.subAttributeList)&&this.setDefaultSubAttribute()}return this.render(),o}shiftRightMouseUp(t){const e=this.getHoverRectID(t);this.emit("shiftRightMouseUp",e)}updateDragResult(){this.emit("updateDragResult",__spreadValues({},this.selectedRect))}setEnableAddRect(t){this.enableAddRect=t}onMouseUp(t){if(super.onMouseUp(t)||this.forbidMouseOperation||!this.imgInfo)return!0;if(this.dragInfo&&this.dragStatus===annotation.EDragStatus.Move){this.dragInfo=void 0,this.dragStatus=annotation.EDragStatus.Wait,this.history.pushHistory(this.rectList),this.emit("updateResult"),this.updateDragResult();return}if(t.button===2&&t.shiftKey===!0){this.shiftRightMouseUp(t);return}if(t.button===2){this.rightMouseUp(t);return}const e=CommonToolUtils.getSourceID(this.basicResult);if(this.drawingRect){this.enableAddRect?this.addDrawingRectToRectList():(this.clearDrawingStatus(),this.render());return}if(t.ctrlKey===!0&&t.button===0&&this.hoverRectID){this.setRectValidAndRender(this.hoverRectID);return}this.enableAddRect&&(this.createNewDrawingRect(t,e),this.render())}onRightDblClick(t){super.onRightDblClick(t);const e=this.getHoverRectID(t);this.selection.isIdSelected(e)&&this.deleteSelectedRect(t)}deleteSelectedRect(t){this.selectedRects.forEach(e=>{this.deleteRect(e.id)})}onKeyDown(t){if(!CommonToolUtils.hotkeyFilter(t)||super.onKeyDown(t)===!1||this.selection.triggerKeyboardEvent(t,this.setRectList.bind(this)))return;const{keyCode:e}=t;switch(e){case keyCode.Ctrl:this.drawingRect&&(this.drawingRect=__spreadProps(__spreadValues({},this.drawingRect),{valid:!t.ctrlKey}),this.render());break;case keyCode.F:this.selectedRectID&&this.setRectValidAndRender(this.selectedRectID);break;case keyCode.Z:this.setIsHidden(!this.isHidden),this.render();break;case keyCode.Delete:this.deleteSelectedRect(t);break;case keyCode.Tab:{if(t.preventDefault(),this.drawingRect)return;let i=annotation.ESortDirection.ascend;t.shiftKey&&(i=annotation.ESortDirection.descend);const[r,n]=CommonToolUtils.getRenderResultList(this.rectList,CommonToolUtils.getSourceID(this.basicResult),this.attributeLockList,this.selectedIDs);let s=[...r];n&&(s=[...s,...n]);const a=CanvasUtils.getViewPort(this.canvas,this.currentPos,this.zoom);s=s.filter(h=>CanvasUtils.inViewPort({x:h.x,y:h.y},a));const o=CommonToolUtils.getNextSelectedRectID(s,i,this.selectedRectID);o&&(this.setSelectedRectID(o.id),this.config.attributeConfigurable===!0&&this.setDefaultAttribute(o.attribute));break}default:{if(this.config.attributeConfigurable){const i=AttributeUtils.default.getAttributeByKeycode(e,this.config.attributeList);i!==void 0&&this.setDefaultAttribute(i)}break}}return!0}onKeyUp(t){switch(super.onKeyUp(t),t.keyCode){case keyCode.Ctrl:this.drawingRect&&(this.drawingRect=__spreadProps(__spreadValues({},this.drawingRect),{valid:!0}),this.render());break}}onWheel(t){const e=this.zoom;let i,r;this.drawingRect&&this.firstClickCoord&&(i=RectUtils.getRectUnderZoom(this.drawingRect,1/e),r=AxisUtils.default.changePointByZoom(this.firstClickCoord,1/e)),super.onWheel(t,!1),i&&r&&(this.drawingRect=RectUtils.getRectUnderZoom(i,this.zoom),this.firstClickCoord=AxisUtils.default.changePointByZoom(r,this.zoom)),this.render()}getCurrentSelectedData(){const{selectedRect:t}=this;if(!t)return;const e=this.getColor(t.attribute),i=t.valid?e==null?void 0:e.valid.stroke:e==null?void 0:e.invalid.stroke;return{width:t.width*this.zoom*.6,textAttribute:t.textAttribute,color:i}}getRenderStyle(t){const e=this.customRenderStyle&&this.customRenderStyle(t);if(e)return e;const i=this.getColor(t.attribute);let r,n;return t.valid===!1?(r=i==null?void 0:i.invalid.stroke,n=i==null?void 0:i.invalid.fill):(r=i==null?void 0:i.valid.stroke,n=i==null?void 0:i.valid.fill),{strokeColor:r,fillColor:n,textColor:r,toolColor:i}}renderTextAttribute(){var t;const{selectedRect:e}=this;if(!this.ctx||this.config.textConfigurable!==!0||!e)return;const{x:i,y:r,width:n,height:s,attribute:a,valid:o}=e,h=n*this.zoom*.6,d=AxisUtils.default.getOffsetCoordinate({x:i,y:r+s},this.currentPos,this.zoom),c=this.getColor(a),l=o?c==null?void 0:c.valid.stroke:c==null?void 0:c.invalid.stroke,u=4;this._textAttributeInstance||(this._textAttributeInstance=new textAttributeClass({width:h,container:this.container,icon:this.getTextIconSvg(a),color:l,getCurrentSelectedData:this.getCurrentSelectedData,updateSelectedTextAttribute:this.updateSelectedRectTextAttribute})),this._textAttributeInstance&&!((t=this._textAttributeInstance)==null?void 0:t.isExit)&&this._textAttributeInstance.appendToContainer(),this._textAttributeInstance.update(`${e.textAttribute}`,{left:d.x,top:d.y+u,color:l,width:h})}renderSelectedRect(t){if(!this.ctx||!t)return;const{ctx:e}=this;let i=10;const r=RectUtils.getRectPointList(t),n=r.length,s=this.getColor(t.attribute);r.forEach((a,o)=>{var h,d;if(e.save(),e.moveTo(a.x,a.y),e.beginPath(),this.hoverRectPointIndex===o?i=scope+6:i=scope,t.valid===!1?(e.strokeStyle=s==null?void 0:s.invalid.stroke,e.fillStyle=s==null?void 0:s.invalid.stroke):(e.strokeStyle=s==null?void 0:s.valid.stroke,e.fillStyle=s==null?void 0:s.valid.stroke),e.arc(a.x*this.zoom+this.currentPos.x,a.y*this.zoom+this.currentPos.y,i,0,2*Math.PI),e.fill(),this.hoverRectEdgeIndex===o){e.beginPath(),e.lineWidth=10;const c=this.getColor(t.attribute),l=t.valid===!1?(h=c==null?void 0:c.invalid)==null?void 0:h.stroke:(d=c==null?void 0:c.valid)==null?void 0:d.stroke;e.strokeStyle=l,e.moveTo(r[o].x*this.zoom+this.currentPos.x,r[o].y*this.zoom+this.currentPos.y),e.lineTo(r[(o+1)%n].x*this.zoom+this.currentPos.x,r[(o+1)%n].y*this.zoom+this.currentPos.y),e.stroke()}e.restore()}),this.renderTextAttribute()}renderDrawingRect(t,e=this.zoom,i=!1){var r,n,s,a,o,h;if(this.ctx&&t){const{ctx:d,style:c}=this,{hiddenText:l=!1}=c;d.save();const{strokeColor:u,fillColor:f,textColor:b}=this.getRenderStyle(t);d.font="lighter 14px Arial";let g="";((r=this.config)==null?void 0:r.isShowOrder)&&t.order&&(t==null?void 0:t.order)>0&&(g=`${t.order}`),t.label&&this.hasMarkerConfig&&(g=`${CommonToolUtils.getCurrentMarkerIndex(t.label,this.config.markerList)+1}_${MarkerUtils.getMarkerShowText(t.label,this.config.markerList)}`),t.attribute&&(g=`${g} ${AttributeUtils.default.getAttributeShowText(t.attribute,(n=this.config)==null?void 0:n.attributeList)}`,(t==null?void 0:t.subAttribute)&&((s=this.config)==null?void 0:s.secondaryAttributeConfigurable)&&((a=this.config)==null?void 0:a.subAttributeList)&&TagUtils.getTagNameList(t.subAttribute,this.config.subAttributeList).forEach(v=>{g+=`
|
|
2
2
|
${v.keyName}: ${v.value.join("\u3001")}`}));const x=AxisUtils.default.changeRectByZoom(t,i?e:this.zoom,this.currentPos);l||DrawUtils.drawText(this.canvas,{x:x.x,y:x.y-6},g,__spreadProps(__spreadValues({color:u,font:"normal normal 900 14px SourceHanSansCN-Regular"},annotation.DEFAULT_TEXT_SHADOW),{textMaxWidth:300})),this.highlightVisible&&(t==null?void 0:t.isHighlight)&&DrawUtils.drawHighlightFlag({canvas:this.canvas,color:u,position:{x:x.x-5,y:x.y-16}});const m=(h=(o=this.style)==null?void 0:o.width)!=null?h:2,D=this.config.textConfigurable&&this.config.isHighlightSameTextAttribute&&this.selectedRectTextAttribute!==""&&t.textAttribute===this.selectedRectTextAttribute;(t.id===this.hoverRectID||D||t.id===this.selectedRectID||this.isMultiMoveMode)&&DrawUtils.drawRectWithFill(this.canvas,x,{color:f}),DrawUtils.drawRect(this.canvas,x,{color:u,thickness:m,hiddenText:!0,lineDash:t.lineDash}),d.restore();let I=`${Math.round(t.width)} * ${Math.round(t.height)}`;i===!0&&(I=`${Math.round(t.width/this.zoom)} * ${Math.round(x.height/this.zoom)}`);const y=I.length*7;if(l||DrawUtils.drawText(this.canvas,{x:x.x+x.width-y,y:x.y+x.height+15},I,__spreadValues({color:b,font:"normal normal 600 14px Arial"},annotation.DEFAULT_TEXT_SHADOW)),!l&&t.textAttribute&&t.id!==this.selectedRectID){const w=0,v=Math.max(20,x.width-y);DrawUtils.drawText(this.canvas,{x:x.x,y:x.y+x.height+20+w},t.textAttribute,__spreadValues({color:b,font:"italic normal 900 14px Arial",textMaxWidth:v},annotation.DEFAULT_TEXT_SHADOW))}}}renderStaticRect(){var t;if(!(((t=this.rectList)==null?void 0:t.length)>0&&JSON.stringify(this.rectList)))return;const{renderEnhance:e={}}=this,[i,r]=CommonToolUtils.getRenderResultList(this.rectList,CommonToolUtils.getSourceID(this.basicResult),this.attributeLockList,this.selectedIDs,this.highlightVisible);this.isHidden||i==null||i.forEach(n=>{this.renderDrawingRect(n),e.staticRender&&e.staticRender(this.canvas,AxisUtils.default.changeRectByZoom(n,this.zoom,this.currentPos),this.getRenderStyle(n))}),r&&r.forEach(n=>{this.renderDrawingRect(n),this.renderSelectedRect(n),e.selectedRender&&e.selectedRender(this.canvas,AxisUtils.default.changeRectByZoom(n,this.zoom,this.currentPos),this.getRenderStyle(n))})}renderCreatingRect(){if(!this.drawingRect)return;const{renderEnhance:t={}}=this;this.renderDrawingRect(this.drawingRect,1,!0),t.creatingRender&&t.creatingRender(this.canvas,AxisUtils.default.changeRectByZoom(this.drawingRect,1,this.currentPos),this.getRenderStyle(this.drawingRect))}renderRect(){this.renderStaticRect(),this.renderCreatingRect()}render(){!this.ctx||(super.render(),this.renderRect(),this.renderCursorLine(this.getLineColor(this.defaultAttribute)))}setDefaultAttribute(t){const e=this.defaultAttribute;if(this.defaultAttribute=t!=null?t:"",e!==t&&(this.changeStyle(t),this.emit("changeAttributeSidebar"),this.selectedRects&&(this.setRectList(this.rectList.map(i=>this.selection.isIdSelected(i.id)?__spreadProps(__spreadValues({},i),{attribute:this.defaultAttribute}):i),!0),this.history.pushHistory(this.rectList),this.render()),this.drawingRect&&(this.drawingRect=__spreadProps(__spreadValues({},this.drawingRect),{attribute:this.defaultAttribute}),this.render()),this._textAttributeInstance)){if(this.attributeLockList.length>0&&!this.attributeLockList.includes(this.defaultAttribute)){this._textAttributeInstance.clearTextAttribute();return}this._textAttributeInstance.updateIcon(this.getTextIconSvg(t))}}setValid(t){super.setValid(t),this.emit("updateResult")}clearDrawingStatus(){this.drawingRect=void 0,this.firstClickCoord=void 0,this.dragInfo=void 0,this.dragStatus=annotation.EDragStatus.Wait}clearActiveStatus(){this.clearDrawingStatus(),this.setSelectedRectID(void 0),this.setOperationMode(tool.EOperationMode.General)}clearResult(t=!0){const e=this.rectList.filter(i=>i.disableDelete===!0);e.length>0&&t&&this.emit("messageInfo",index.getMessagesByLocale(constants.EMessage.ClearPartialData,this.lang)),this.setRectList(e,!0),this.setSelectedRectID(void 0)}deleteRect(t){var e;if(!t)return;const i=this.rectList.find(r=>r.id===t);if((i==null?void 0:i.disableDelete)===!0){this.emit("messageInfo",index.getMessagesByLocale(constants.EMessage.DisableDelete,this.lang));return}this.setRectList(this.rectList.filter(r=>r.id!==t),!0),this.history.pushHistory(this.rectList),this.setSelectedRectID(void 0),(e=this._textAttributeInstance)==null||e.clearTextAttribute(),this.render()}exportData(){const{rectList:t}=this;return[t,this.basicImgInfo]}undo(){const t=this.history.undo();t&&(t.length!==this.rectList.length&&this.setSelectedRectID(""),this.setRectList(t,!0),this.render())}redo(){const t=this.history.redo();t&&(t.length!==this.rectList.length&&this.setSelectedRectID(""),this.setRectList(t,!0),this.render())}}exports.RectOperation=RectOperation,exports.default=RectOperation;
|