@labelbee/lb-annotation 1.14.0-alpha.0 → 1.14.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/core/pointCloud/annotation.js +1 -1
- package/dist/core/pointCloud/index.js +2 -2
- package/dist/core/scheduler.js +1 -1
- package/dist/core/toolOperation/ViewOperation.js +1 -1
- package/dist/core/toolOperation/cuboidOperation.js +1 -1
- package/dist/core/toolOperation/pointOperation.js +1 -1
- package/dist/index.js +1 -1
- package/dist/types/core/pointCloud/annotation.d.ts +6 -3
- package/dist/types/core/pointCloud/index.d.ts +34 -4
- package/dist/types/core/pointCloud/matrix.d.ts +1 -1
- package/dist/types/core/scheduler.d.ts +12 -1
- package/dist/types/core/toolOperation/cuboidOperation.d.ts +21 -2
- package/dist/types/core/toolOperation/pointOperation.d.ts +6 -1
- package/dist/types/core/toolOperation/textAttributeClass.d.ts +9 -0
- package/dist/types/index.d.ts +2 -1
- package/dist/types/utils/tool/CuboidUtils.d.ts +1 -1
- package/dist/types/utils/tool/DrawUtils.d.ts +21 -1
- package/dist/utils/tool/AxisUtils.js +1 -1
- package/dist/utils/tool/CuboidUtils.js +1 -1
- package/dist/utils/tool/DrawUtils.js +3 -3
- package/es/core/pointCloud/annotation.js +1 -1
- package/es/core/pointCloud/index.js +2 -2
- package/es/core/scheduler.js +1 -1
- package/es/core/toolOperation/ViewOperation.js +1 -1
- package/es/core/toolOperation/cuboidOperation.js +1 -1
- package/es/core/toolOperation/pointOperation.js +1 -1
- package/es/index.js +1 -1
- package/es/utils/tool/AttributeUtils.js +1 -1
- package/es/utils/tool/AxisUtils.js +1 -1
- package/es/utils/tool/CuboidUtils.js +1 -1
- package/es/utils/tool/DrawUtils.js +3 -3
- package/package.json +3 -3
- package/dist/types/core/pointCloud/segmentation.d.ts +0 -0
- package/es/_virtual/_rollup-plugin-web-worker-loader__helper__auto__createBase64WorkerFactory.js +0 -12
- package/es/_virtual/_rollup-plugin-web-worker-loader__helper__auto__isNodeJS.js +0 -7
- package/es/_virtual/_rollup-plugin-web-worker-loader__helper__node__WorkerClass.js +0 -11
- package/es/_virtual/_rollup-plugin-web-worker-loader__helper__node__createBase64WorkerFactory.js +0 -18
- package/es/core/pointCloud/segmentation.js +0 -50
- package/es/core/toolOperation/scribbleTool2.js +0 -249
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var lbUtils=require("@labelbee/lb-utils"),tool=require("../../constant/tool.js"),CanvasScheduler=require("../../newCore/CanvasScheduler.js"),index=require("./index.js"),scheduler=require("../scheduler.js"),__defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnPropDescs=Object.getOwnPropertyDescriptors,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var lbUtils=require("@labelbee/lb-utils"),tool=require("../../constant/tool.js"),CanvasScheduler=require("../../newCore/CanvasScheduler.js"),index=require("./index.js"),scheduler=require("../scheduler.js"),__defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnPropDescs=Object.getOwnPropertyDescriptors,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(n,t,e)=>t in n?__defProp(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,__spreadValues=(n,t)=>{for(var e in t||(t={}))__hasOwnProp.call(t,e)&&__defNormalProp(n,e,t[e]);if(__getOwnPropSymbols)for(var e of __getOwnPropSymbols(t))__propIsEnum.call(t,e)&&__defNormalProp(n,e,t[e]);return n},__spreadProps=(n,t)=>__defProps(n,__getOwnPropDescs(t));const createEmptyImage=n=>{const t=document.createElement("canvas");t.width=n.width,t.height=n.height;const e=t.getContext("2d");return e?(e.fillStyle="black",e.fillRect(0,0,n.width,n.height),t.toDataURL()):""};class PointCloudAnnotation{constructor({size:t,container:e,pcdPath:i,extraProps:P,config:f,checkMode:v,toolName:d}){this.updatePolygonList=(a,l)=>{let r=a.map(o=>{var s;const{polygon2d:C}=this.pointCloudInstance.getBoxTopPolygon2DCoordinate(o);return{id:o.id,sourceID:"",pointList:C,isRect:!0,valid:(s=o.valid)!=null?s:!0,attribute:o.attribute}});l&&(r=r.concat(l.map(o=>{var s;return __spreadProps(__spreadValues({},o),{pointList:(s=o==null?void 0:o.pointList)==null?void 0:s.map(C=>lbUtils.PointCloudUtils.transferWorld2Canvas(C,this.pointCloud2dOperation.size))})}))),this.toolScheduler.updateDataByToolName(tool.EToolName.PointCloudPolygon,r)},this.updatePointList=a=>{const l=a==null?void 0:a.map(r=>{var o;const{point2d:s}=this.pointCloudInstance.getSphereTopPoint2DCoordinate(r);return __spreadProps(__spreadValues({},s),{id:r.id,sourceID:"",valid:(o=r.valid)!=null?o:!0,attribute:r.attribute,textAttribute:""})});this.toolScheduler.updateDataByToolName(tool.EToolName.Point,l)};const O=this.getDefaultOrthographic(t),I=createEmptyImage(t),u=new Image;u.src=I;const p=new scheduler.ToolScheduler({container:e,size:t,toolName:d}),m=new CanvasScheduler.CanvasScheduler({container:e}),h=new index.PointCloud({container:e,noAppend:!0,isOrthographicCamera:!0,orthographicParams:O});i&&h.loadPCDFile(i),m.createCanvas(h.renderer.domElement);const g={size:t,config:JSON.stringify(__spreadProps(__spreadValues({},f),{attributeConfigurable:!0,hideAttribute:!0})),imgNode:u,checkMode:v};P&&Object.assign(g,P);let c=[];scheduler.HybridToolUtils.isSingleTool(d)?c=[d]:c=d,c.forEach((a,l)=>{let r;if(a===tool.EToolName.PointCloudPolygon){const o=p.createOperation(a,u,g);o.eventBinding(),o.setPattern(tool.EPolygonPattern.Rect),this.toolInstance=o,this.toolInstance.eventBinding(),this.pointCloud2dOperation=o}else r=p.createOperation(a,u,g);l===c.length-1&&(this.toolInstance||(this.toolInstance=r,this.toolInstance.eventBinding()))}),this.pointCloudInstance=h,this.canvasScheduler=m,this.toolScheduler=p,this.config=f}updateConfig(t){this.config=t,this.pointCloud2dOperation.setConfig(JSON.stringify(t))}getDefaultOrthographic(t){return{left:-t.width/2,right:t.width/2,top:t.height/2,bottom:-t.height/2,near:100,far:-100}}initSize(t){this.pointCloudInstance.updateTopCamera(),this.pointCloudInstance.setDefaultControls(),this.pointCloudInstance.initRenderer(),this.pointCloudInstance.initOrthographicCamera(this.getDefaultOrthographic(t)),this.pointCloudInstance.render();const e=createEmptyImage(t),i=new Image;i.src=e,i.onload=()=>{this.toolInstance.setImgNode(i),this.toolInstance.initImgPos()},this.pointCloud2dOperation.setCanvasSize(t)}addPolygonListOnTopView(t){const e=lbUtils.PointCloudUtils.getBoxParamsFromResultList(t),i=lbUtils.PointCloudUtils.getPolygonListFromResultList(t);this.updatePolygonList(e,i)}addPointListOnTopView(t){const e=lbUtils.PointCloudUtils.getSphereParamsFromResultList(t);this.updatePointList(e)}updateData(t,e,i){!this.toolInstance||!this.pointCloudInstance||(this.pointCloudInstance.loadPCDFile(t,i==null?void 0:i.radius),this.addPolygonListOnTopView(e),this.addPointListOnTopView(e))}switchToCanvas(t){const e=this.toolScheduler.switchToCanvas(t);return e?(e.eventBinding(),this.toolInstance=e,e):this.toolInstance}initAllPosition(){this.pointCloudInstance.updateTopCamera(),this.pointCloud2dOperation.initPosition()}clearAllData(){this.pointCloudInstance.clearPointCloudAndRender(),this.pointCloud2dOperation.clearResult()}}exports.PointCloudAnnotation=PointCloudAnnotation;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var THREE=require("three"),lbUtils=require("@labelbee/lb-utils"),highlightWorker$1=require("../../_virtual/highlightWorker.js"),filterBoxWorker=require("../../_virtual/filterBoxWorker.js"),polygonTool=require("../../utils/tool/polygonTool.js"),uuid=require("../../utils/uuid.js"),MathUtils=require("../../utils/MathUtils.js"),PCDLoader=require("./PCDLoader.js"),OrbitControls=require("./OrbitControls.js"),cache=require("./cache.js"),matrix=require("./matrix.js");require("../../constant/tool.js"),require("../scheduler.js");function _interopNamespace(
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var THREE=require("three"),lbUtils=require("@labelbee/lb-utils"),highlightWorker$1=require("../../_virtual/highlightWorker.js"),filterBoxWorker=require("../../_virtual/filterBoxWorker.js"),polygonTool=require("../../utils/tool/polygonTool.js"),uuid=require("../../utils/uuid.js"),MathUtils=require("../../utils/MathUtils.js"),PCDLoader=require("./PCDLoader.js"),OrbitControls=require("./OrbitControls.js"),cache=require("./cache.js"),matrix=require("./matrix.js");require("../../constant/tool.js"),require("../scheduler.js");function _interopNamespace(m){if(m&&m.__esModule)return m;var t=Object.create(null);return m&&Object.keys(m).forEach(function(e){if(e!=="default"){var r=Object.getOwnPropertyDescriptor(m,e);Object.defineProperty(t,e,r.get?r:{enumerable:!0,get:function(){return m[e]}})}}),t.default=m,Object.freeze(t)}var THREE__namespace=_interopNamespace(THREE),__defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnPropDescs=Object.getOwnPropertyDescriptors,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(m,t,e)=>t in m?__defProp(m,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):m[t]=e,__spreadValues=(m,t)=>{for(var e in t||(t={}))__hasOwnProp.call(t,e)&&__defNormalProp(m,e,t[e]);if(__getOwnPropSymbols)for(var e of __getOwnPropSymbols(t))__propIsEnum.call(t,e)&&__defNormalProp(m,e,t[e]);return m},__spreadProps=(m,t)=>__defProps(m,__getOwnPropDescs(t)),__async=(m,t,e)=>new Promise((r,n)=>{var s=o=>{try{i(e.next(o))}catch(c){n(c)}},a=o=>{try{i(e.throw(o))}catch(c){n(c)}},i=o=>o.done?r(o.value):Promise.resolve(o.value).then(s,a);i((e=e.apply(m,t)).next())});const DEFAULT_DISTANCE=30,highlightWorker=new highlightWorker$1({type:"module"});class PointCloud{constructor({container:t,noAppend:e,isOrthographicCamera:r,orthographicParams:n,backgroundColor:s="#4C4C4C",config:a}){this.zAxisLimit=10,this.initCameraPosition=this.DEFAULT_INIT_CAMERA_POSITION,this.isOrthographicCamera=!1,this.pointsUuid="",this.pointCloudObjectName="pointCloud",this.rangeObjectName="range",this.showDirection=!0,this.addSphereToSense=(i,o="blue")=>{var c;const h=(c=i.id)!=null?c:uuid();this.removeObjectByName(h);const{radius:l,widthSegments:d,heightSegments:g}=lbUtils.DEFAULT_SPHERE_PARAMS,{center:x}=i,p=new THREE__namespace.Group,u=new THREE__namespace.SphereGeometry(l,d,g),f=new THREE__namespace.MeshBasicMaterial({color:o}),y=new THREE__namespace.Mesh(u,f);y.position.set(x.x,x.y,x.z),p.add(y),p.name=h,this.scene.add(p)},this.generateSphere=i=>{const{fill:o}=lbUtils.toolStyleConverter.getColorFromConfig({attribute:i.attribute},__spreadProps(__spreadValues({},this.config),{attributeConfigurable:!0}),{});this.addSphereToSense(i,o),this.render()},this.generateSpheres=i=>{i.forEach(o=>{const{fill:c}=lbUtils.toolStyleConverter.getColorFromConfig({attribute:o.attribute},__spreadProps(__spreadValues({},this.config),{attributeConfigurable:!0}),{});this.addSphereToSense(o,c)}),this.render()},this.AddBoxToSense=(i,o=16777215)=>{var c;const h=(c=i.id)!=null?c:uuid();this.removeObjectByName(h);const{center:l,width:d,height:g,depth:x,rotation:p}=i,u=new THREE__namespace.Group,f=new THREE__namespace.BoxGeometry(d,g,x),y=new THREE__namespace.MeshBasicMaterial({color:"blue"}),w=new THREE__namespace.Mesh(f,y),C=new THREE__namespace.BoxHelper(w,o),P=this.generateBoxArrow(i);u.add(C),u.add(P),u.position.set(l.x,l.y,l.z),u.rotation.set(0,0,p),u.name=h,this.scene.add(u)},this.applyCameraTarget=i=>{if(this.camera.type==="OrthographicCamera"&&i){const o=this.getOrthographicCameraTarget(i);this.updateCameraZoom(i.zoom),this.updateCamera(i.position,o)}},this.overridePointShader=i=>{i.vertexShader=`
|
|
2
2
|
attribute float sizes;
|
|
3
3
|
attribute float visibility;
|
|
4
4
|
varying float vVisible;
|
|
@@ -8,4 +8,4 @@
|
|
|
8
8
|
varying float vVisible;
|
|
9
9
|
${i.fragmentShader}`.replace("#include <clipping_planes_fragment>",`
|
|
10
10
|
if (vVisible < 0.5) discard;
|
|
11
|
-
#include <clipping_planes_fragment>`)},this.loadPCDFile=(i,o)=>__async(this,null,function*(){this.clearPointCloud(),this.currentPCDSrc=i;const{points:h,color:c}=yield this.cacheInstance.loadPCDFile(i),l=new THREE__namespace.BufferGeometry;l.setAttribute("position",new THREE__namespace.BufferAttribute(h,3)),l.setAttribute("color",new THREE__namespace.BufferAttribute(c,3));const d=new THREE__namespace.Points(l);this.renderPointCloud(d,o)}),this.loadPCDFileByBox=(i,o,h)=>__async(this,null,function*(){const c=(g,m)=>__async(this,null,function*(){const{width:x=0,height:u=0,depth:y=0}=h!=null?h:{},f=yield this.filterPointsByBox(__spreadProps(__spreadValues({},o),{width:o.width+x,height:o.height+u,depth:o.depth+y}),g,m);if(!f){console.error("filter Error");return}this.clearPointCloud(),this.currentPCDSrc=i;const w=new THREE__namespace.Points(f.geometry);w.name=this.pointCloudObjectName,this.scene.add(w),this.render()}),{points:l,color:d}=yield this.cacheInstance.loadPCDFile(i);c(l,d)}),this.generateRange=i=>{const o=this.createRange(i);this.scene.add(o)},this.generateBoxArrow=({width:i})=>{const o=new THREE__namespace.Vector3(1,0,0),h=new THREE__namespace.Vector3(i/2,0,0),c=2,l=16776960,d=new THREE__namespace.ArrowHelper(o,h,c,l);return d.visible=this.showDirection,d},this.generateBoxTrackID=i=>{if(!i.trackID)return;const o=new THREE__namespace.Texture(this.getTextCanvas(i.trackID.toString()));o.needsUpdate=!0;const h=new THREE__namespace.SpriteMaterial({map:o,depthWrite:!1}),c=new THREE__namespace.Sprite(h);return c.scale.set(5,5,5),c.position.set(-i.width/2,0,i.depth/2+.5),c},this.applyZAxisPoints=i=>{this.zAxisLimit=i,this.filterZAxisPoints(),this.render()},this.updatePointSize=i=>{const o=this.scene.getObjectByName(this.pointCloudObjectName);if(!o)return;const h=o.material.size;i?o.material.size=Math.min(h*1.2,10):o.material.size=Math.max(h/1.2,1),this.render()},this.container=t,this.renderer=new THREE__namespace.WebGLRenderer({antialias:!0}),this.backgroundColor=s,this.config=a,r&&n?(this.isOrthographicCamera=!0,this.camera=new THREE__namespace.OrthographicCamera(n.left,n.right,n.top,n.bottom,n.near,n.far)):this.camera=new THREE__namespace.PerspectiveCamera(30,this.containerWidth/this.containerHeight,1,1e3),this.initCamera(),this.scene=new THREE__namespace.Scene,this.controls=new OrbitControls.OrbitControls(this.camera,this.renderer.domElement),this.pcdLoader=new PCDLoader.PCDLoader,this.axesHelper=new THREE__namespace.AxesHelper(1e3),this.scene.add(this.camera),e||t.appendChild(this.renderer.domElement),this.init(),this.cacheInstance=cache.PointCloudCache.getInstance()}get DEFAULT_INIT_CAMERA_POSITION(){return new THREE__namespace.Vector3(-.01,0,10)}get containerWidth(){return this.container.clientWidth}get containerHeight(){return this.container.clientHeight}setInitCameraPosition(t){this.initCameraPosition=t}setConfig(t){this.config=t}initOrthographicCamera(t){if(this.camera.type!=="OrthographicCamera")return;const{left:e,right:r,top:n,bottom:s,near:a,far:i}=t;this.camera.left=e,this.camera.right=r,this.camera.top=n,this.camera.bottom=s,this.camera.near=a,this.camera.far=i,this.camera.updateProjectionMatrix()}initPerspectiveCamera(){this.camera.type==="PerspectiveCamera"&&(this.camera.fov=30,this.camera.aspect=this.containerWidth/this.containerHeight,this.camera.near=1,this.camera.far=1e3,this.camera.updateProjectionMatrix())}initCamera(){const{camera:t}=this;if(this.isOrthographicCamera){const{x:e,y:r,z:n}=this.initCameraPosition;t.position.set(e,r,n)}else t.position.set(-1,0,500);t.up.set(0,0,1)}initControls(){const{controls:t}=this;t.addEventListener("change",()=>{this.render()}),this.setDefaultControls()}setDefaultControls(){const{controls:t}=this,e=[0,0,0];t.target=new THREE__namespace.Vector3(...e),t.addEventListener("change",()=>{this.render()}),t.maxPolarAngle=Math.PI/2,t.update()}initRenderer(){const{renderer:t}=this;t.setPixelRatio(window.devicePixelRatio),t.setSize(this.containerWidth,this.containerHeight)}init(){const{scene:t}=this;t.background=new THREE__namespace.Color(this.backgroundColor),this.initControls(),this.initRenderer()}removeObjectByName(t){const e=this.scene.getObjectByName(t);e&&e.removeFromParent()}generateBox(t,e=16777215){const r=e;this.AddBoxToSense(t,r),this.render()}getAllAttributeColor(t){return t.reduce((e,r)=>(e[r.attribute]=lbUtils.toolStyleConverter.getColorFromConfig({attribute:r.attribute},__spreadProps(__spreadValues({},this.config),{attributeConfigurable:!0}),{}),e),{})}generateBoxes(t){t.forEach(e=>{this.generateBox(e)}),this.render()}getOrthographicCamera(t){const{center:e,width:r,height:n}=t,s=10,a=e.x-r/2-s,i=e.x-r/2+s,o=e.y+n/2+s,h=e.y-n/2-s,c=100,l=-100,d=500/c;return{left:a,right:i,top:o,bottom:h,near:c,far:l,zoom:d}}updateCameraZoom(t){this.camera.zoom=t,this.camera.updateProjectionMatrix()}updateCameraByBox(t,e,r){const{center:n,width:s,height:a,depth:i,rotation:o}=t,h=this.getCameraVector(n,o,{width:s,height:a,depth:i},e);return r?(this.updateCamera(r,n),new THREE__namespace.Vector3(r.x,r.y,r.z)):(this.updateCamera(h,n),h)}updateOrthoCamera(t,e){const r=this.updateCameraByBox(t,e);return this.camera.zoom=1,this.camera.updateProjectionMatrix(),{cameraPositionVector:r}}updateTopCamera(){this.setInitCameraPosition(this.DEFAULT_INIT_CAMERA_POSITION),this.camera.zoom=1,this.initCamera(),this.setDefaultControls(),this.camera.updateProjectionMatrix(),this.render()}updateCamera(t,e){this.camera.position.set(t.x,t.y,t.z),this.controls.target=new THREE__namespace.Vector3(e.x,e.y,e.z),this.controls.update()}resetCamera(){this.updateCamera(this.DEFAULT_INIT_CAMERA_POSITION,{x:0,y:0,z:0})}getOrthographicCameraTarget(t){const e=new THREE__namespace.Vector3(0,0,-1).applyQuaternion(t.quaternion);return t.position.clone().add(e)}createThreeMatrix4(t){return new THREE__namespace.Matrix4().set(...t)}filterPointsByBox(t,e,r){var n,s,a;if(!e){const i=this.scene.getObjectByName(this.pointCloudObjectName);if(!i)return console.error("There is no corresponding point cloud object"),Promise.resolve(void 0);e=(a=(s=(n=i==null?void 0:i.geometry)==null?void 0:n.attributes)==null?void 0:s.position)==null?void 0:a.array}if(window.Worker){const{zMin:i,zMax:o,polygonPointList:h}=matrix.getCuboidFromPointCloudBox(t),c=e;r=r!=null?r:new Float32Array([]);const l={boxParams:t,zMin:i,zMax:o,polygonPointList:h,color:r,position:c};return new Promise(d=>{const g=new filterBoxWorker;g.postMessage(l),g.onmessage=m=>{const{color:x,position:u,num:y}=m.data,f=new THREE__namespace.BufferGeometry;f.setAttribute("position",new THREE__namespace.Float32BufferAttribute(u,3)),f.setAttribute("color",new THREE__namespace.Float32BufferAttribute(x,3)),f.computeBoundingSphere(),g.terminate(),d({geometry:f,num:y})}})}return Promise.resolve(void 0)}getCameraVector(t,e,r,n=lbUtils.EPerspectiveView.Front,s=DEFAULT_DISTANCE){let a=lbUtils.PerspectiveShiftUtils.frontViewMatrix4(s);switch(n){case lbUtils.EPerspectiveView.Front:break;case lbUtils.EPerspectiveView.Back:a=lbUtils.PerspectiveShiftUtils.backViewMatrix4(s);break;case lbUtils.EPerspectiveView.Left:a=lbUtils.PerspectiveShiftUtils.leftViewMatrix4(s);break;case lbUtils.EPerspectiveView.Right:a=lbUtils.PerspectiveShiftUtils.rightViewMatrix4(s);break;case lbUtils.EPerspectiveView.Top:a=lbUtils.PerspectiveShiftUtils.topViewMatrix4(s);break;case lbUtils.EPerspectiveView.LFT:a=lbUtils.PerspectiveShiftUtils.leftFrontTopViewMatrix4(s,r);break;case lbUtils.EPerspectiveView.RBT:a=lbUtils.PerspectiveShiftUtils.rightBackTopViewMatrix4(s,r);break}const i=this.createThreeMatrix4(a),o=new THREE__namespace.Matrix4().makeTranslation(-t.x,-t.y,-t.z),h=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(i).applyMatrix4(o).applyMatrix4(c).applyMatrix4(h)}createRange(t){this.removeObjectByName(this.rangeObjectName);const r=new THREE__namespace.EllipseCurve(0,0,t,t,0,2*Math.PI,!1,0).getPoints(50),n=new THREE__namespace.BufferGeometry().setFromPoints(r),s=new THREE__namespace.LineBasicMaterial({color:16711680}),a=new THREE__namespace.Line(n,s);return a.name=this.rangeObjectName,a}renderPointCloud(t,e){t.name=this.pointCloudObjectName;const r=new THREE__namespace.PointsMaterial({vertexColors:!0});r.onBeforeCompile=this.overridePointShader,r.size=1.2,e&&this.generateRange(e),this.pointsUuid=t.uuid,t.material=r,this.filterZAxisPoints(t),this.scene.add(t),this.render()}clearPointCloud(){this.removeObjectByName(this.pointCloudObjectName)}clearPointCloudAndRender(){this.clearPointCloud(),this.render()}highlightOriginPointCloud(t){const e=this.scene.getObjectByName(this.pointCloudObjectName);if(!!e)return this.highlightPCDSrc=this.currentPCDSrc,new Promise(r=>{if(window.Worker){const s=(t?[...t]:[]).map(o=>matrix.getCuboidFromPointCloudBox(o)),a=this.getAllAttributeColor(s),i={cuboidList:s,position:e.geometry.attributes.position.array,color:e.geometry.attributes.color.array,colorList:a};highlightWorker.postMessage(i),highlightWorker.onmessage=o=>{const{color:h}=o.data,c=new THREE__namespace.BufferAttribute(h,3);this.highlightPCDSrc&&(this.cacheInstance.updateColor(this.highlightPCDSrc,h),this.highlightPCDSrc=void 0),c.needsUpdate=!0,e.geometry.setAttribute("color",c),r(h),this.render()}}})}updateColor(t){const e=this.scene.getObjectByName(this.pointCloudObjectName);if(e){const r=new THREE__namespace.BufferAttribute(t,3);r.needsUpdate=!0,e.geometry.setAttribute("color",r),this.render()}}setShowDirection(t){this.showDirection=t,this.scene.children.forEach(e=>{e.type==="Group"&&e.children.forEach(r=>{r.type==="ArrowHelper"&&(r.visible=t)})}),this.render()}getTextCanvas(t){const e=document.createElement("canvas"),r=e.getContext("2d");return r&&(r.font=`${50}px " bold`,r.fillStyle="white",r.textAlign="center",r.textBaseline="middle",r.fillText(t,e.width/2,e.height/2)),e}filterNoise(t){let e=[...t];e.sort((l,d)=>l.z-d.z);const r=Math.floor(e.length*.05),n=e[r];e=e.filter(({z:l})=>l>n.z+.1);const s=.005,a=Math.floor(e.length*(1-s));e=e.slice(0,a),e.sort((l,d)=>l.x-d.x);const i=Math.floor(e.length*s),o=Math.floor(e.length*(1-s));e=e.slice(i,o),e.sort((l,d)=>l.y-d.y);const h=Math.floor(e.length*s),c=Math.floor(e.length*(1-s));return e=e.slice(h,c),e.length>100?e:t}getFittedCoordinates(t,e){const r=[];let n=[...t,t[0]];e.forEach(({x:i,y:o})=>{t.forEach((h,c)=>{const l=n[c+1],d=MathUtils.default.getFootOfPerpendicular({x:i,y:o},h,l,!1,!0).length;(!r[c]||d<r[c].distance)&&(r[c]={distance:d,point:{x:i,y:o}})})}),n=[t[t.length-1],...t,t[0]];const s=[r[r.length-1],...r];return t.map((i,o)=>{const h=n[o],c=n[o+1],l=n[o+2];return lbUtils.PointCloudUtils.getIntersectionBySlope({p1:s[o].point,k1:(h.y-c.y)/(h.x-c.x),p2:s[o+1].point,k2:(c.y-l.y)/(c.x-l.x)})})}getSensesPointZAxisInPolygon(t,e,r){const n=this.scene.children.find(d=>d.uuid===this.pointsUuid);let s=0,a=0,i=0,o=0,h=[],c=[];if(!(n==null?void 0:n.geometry))return{maxZ:a,minZ:s,count:i,zCount:o,fittedCoordinates:[]};const l=n==null?void 0:n.geometry.attributes.position.array;for(let d=0;d<l.length;d+=3){const g=l[d],m=l[d+1],x=l[d+2];polygonTool.isInPolygon({x:g,y:m},t)&&(x||x===0)&&c.push({x:g,y:m,z:x})}return r&&(c=this.filterNoise(c),h=this.getFittedCoordinates(t,c)),c.sort((d,g)=>d.z-g.z),s=c[0].z-.01,a=c[c.length-1].z+.01,o=c.length,e&&(i=c.filter(({z:d})=>d>=e[0]&&d<=e[1]).length),{maxZ:a,minZ:s,count:i,zCount:o,fittedCoordinates:h}}getBasicCoordinate2Canvas(t){const e=this.containerWidth/2,r=this.containerHeight/2;return{x:t.x*e+e,y:t.y*r+r,z:t.z}}get basicCoordinate2CanvasMatrix4(){const t=this.containerWidth/2,e=this.containerHeight/2;return new THREE__namespace.Matrix4().set(t,0,0,t,0,e,0,e,0,0,1,0,0,0,0,1)}getCanvas2BasicCoordinate(t){const e=this.containerWidth/2,r=this.containerHeight/2;return new THREE__namespace.Vector3(t.x/e-e/2,-(t.y/r-r/2),1)}getPolygonSidePoints(t){const{center:{x:e,y:r,z:n},height:s,width:a,depth:i}=t,o={x:e+a/2,y:r+s/2,z:n-i/2},h={x:e+a/2,y:r+s/2,z:n+i/2},c={x:e-a/2,y:r+s/2,z:n+i/2},l={x:e-a/2,y:r+s/2,z:n-i/2};return[o,h,c,l]}getPolygonBackPoints(t){const{center:{x:e,y:r,z:n},height:s,width:a,depth:i}=t,o={x:e-a/2,y:r+s/2,z:n+i/2},h={x:e-a/2,y:r+s/2,z:n-i/2},c={x:e-a/2,y:r-s/2,z:n-i/2},l={x:e-a/2,y:r-s/2,z:n+i/2};return[o,h,c,l]}getPolygonTopPoints(t){const{center:{x:e,y:r,z:n},height:s,width:a,depth:i}=t,o={x:e+a/2,y:r+s/2,z:n+i/2},h={x:e+a/2,y:r-s/2,z:n+i/2},c={x:e-a/2,y:r-s/2,z:n+i/2},l={x:e-a/2,y:r+s/2,z:n+i/2};return[o,h,c,l]}getModelTransformationMatrix(t){const{center:{x:e,y:r,z:n},rotation:s}=t,a=new THREE__namespace.Matrix4().makeTranslation(-e,-r,-n),i=new THREE__namespace.Matrix4().makeTranslation(e,r,n),o=new THREE__namespace.Matrix4().makeRotationZ(s);return new THREE__namespace.Matrix4().multiply(i).multiply(o).multiply(a)}getBoxSidePolygon2DCoordinate(t){return this.getBoxPolygon2DCoordinate(t,lbUtils.EPerspectiveView.Left)}getBoxBackPolygon2DCoordinate(t){return this.getBoxPolygon2DCoordinate(t,lbUtils.EPerspectiveView.Back)}boxParams2ViewPolygon(t,e){switch(e){case lbUtils.EPerspectiveView.Left:return this.getPolygonSidePoints(t);case lbUtils.EPerspectiveView.Back:return this.getPolygonBackPoints(t);default:return this.getPolygonTopPoints(t)}}getBoxPolygon2DCoordinate(t,e){const r=this.boxParams2ViewPolygon(t,e),{width:n,height:s}=t,a=new THREE__namespace.Matrix4().premultiply(this.camera.matrixWorldInverse).premultiply(this.camera.projectionMatrix),i=new THREE__namespace.Matrix4().premultiply(this.getModelTransformationMatrix(t)).premultiply(a).premultiply(this.basicCoordinate2CanvasMatrix4);this.sideMatrix=i;const o=r.map(l=>new THREE__namespace.Vector3(l.x,l.y,l.z)).map(l=>l.applyMatrix4(this.sideMatrix)),h=this.containerWidth/n,c=this.containerHeight/s;return{polygon2d:o,zoom:Math.min(h,c)/2}}getBoxTopPolygon2DCoordinate(t){const{width:e,height:r}=t,s=this.getPolygonTopPoints(t).map(o=>new THREE__namespace.Vector3(o.x,o.y,o.z)).map(o=>o.applyMatrix4(this.getModelTransformationMatrix(t))).map(o=>({x:o.y,y:o.x})).map(o=>({x:-(o.x-this.containerWidth/2),y:-(o.y-this.containerHeight/2)})),a=this.containerWidth/e,i=this.containerHeight/r;return{polygon2d:s,zoom:Math.min(a,i)/2}}getNewBoxBySideUpdate(t,e,r,n){const s=new THREE__namespace.Matrix4().makeRotationZ(n.rotation),a=new THREE__namespace.Vector3(-t.x,0,0).applyMatrix4(s);let i=n;return i.center={x:i.center.x+a.x,y:i.center.y+a.y,z:i.center.z-t.z},i=__spreadProps(__spreadValues({},i),{width:i.width+e,height:i.height,depth:i.depth+r}),{newBoxParams:i}}getNewBoxByBackUpdate(t,e,r,n){const s=new THREE__namespace.Matrix4().makeRotationZ(n.rotation),a=new THREE__namespace.Vector3(0,-t.x,0).applyMatrix4(s);let i=n;return i.center={x:i.center.x+a.x,y:i.center.y+a.y,z:i.center.z-t.z},i=__spreadProps(__spreadValues({},i),{width:i.width,height:i.height+e,depth:i.depth+r}),{newBoxParams:i}}getNewBoxBySideUpdateByPoints(t,e,r,n){var s;const a=(s=this.sideMatrix)==null?void 0:s.invert();if(!this.sideMatrix||!a){console.error("No sideMatrix");return}this.camera.zoom=1,this.camera.updateProjectionMatrix();const i=t.map(u=>new THREE__namespace.Vector3(u.x,u.y,u.z)).map(u=>u.applyMatrix4(a)),[o,h,c,l]=i,d=Math.max(Math.abs(o.x-c.x),Math.abs(o.x-h.x)),m=h.add(l).applyMatrix3(new THREE__namespace.Matrix3().set(1/2,0,0,0,1/2,0,0,0,1/2)).clone().applyMatrix3(new THREE__namespace.Matrix3().set(-1,0,0,0,-1,0,0,0,-1)).add(new THREE__namespace.Vector3(n.center.x,n.center.y,n.center.z));return{newBoxParams:__spreadProps(__spreadValues({},n),{center:{x:n.center.x-m.x,y:n.center.y-m.y,z:n.center.z-r},width:d,height:n.height,depth:n.depth+e,rotation:n.rotation})}}filterZAxisPoints(t){const e=t||this.scene.children.find(r=>r.uuid===this.pointsUuid);if(e){const{attributes:r}=e.geometry,{position:n}=r,s=[],{count:a}=n;for(let i=0;i<a;i++){const o=n.getZ(i);s.push(o>this.zAxisLimit?0:1)}e.geometry.setAttribute("visibility",new THREE__namespace.Float32BufferAttribute(s,1)),e.geometry.attributes.visibility.needsUpdate=!0}}render(){this.renderer.render(this.scene,this.camera)}}exports.createThreeMatrix4=matrix.createThreeMatrix4,exports.getCuboidFromPointCloudBox=matrix.getCuboidFromPointCloudBox,exports.lidar2image=matrix.lidar2image,exports.pointCloudLidar2image=matrix.pointCloudLidar2image,exports.rotatePoint=matrix.rotatePoint,exports.transferKitti2Matrix=matrix.transferKitti2Matrix,exports.PointCloud=PointCloud;
|
|
11
|
+
#include <clipping_planes_fragment>`)},this.loadPCDFile=(i,o)=>__async(this,null,function*(){this.clearPointCloud(),this.currentPCDSrc=i;const{points:c,color:h}=yield this.cacheInstance.loadPCDFile(i),l=new THREE__namespace.BufferGeometry;l.setAttribute("position",new THREE__namespace.BufferAttribute(c,3)),l.setAttribute("color",new THREE__namespace.BufferAttribute(h,3));const d=new THREE__namespace.Points(l);this.renderPointCloud(d,o)}),this.loadPCDFileByBox=(i,o,c)=>__async(this,null,function*(){const h=(g,x)=>__async(this,null,function*(){const{width:p=0,height:u=0,depth:f=0}=c!=null?c:{},y=yield this.filterPointsByBox(__spreadProps(__spreadValues({},o),{width:o.width+p,height:o.height+u,depth:o.depth+f}),g,x);if(!y){console.error("filter Error");return}this.clearPointCloud(),this.currentPCDSrc=i;const w=new THREE__namespace.Points(y.geometry);w.name=this.pointCloudObjectName,this.scene.add(w),this.render()}),{points:l,color:d}=yield this.cacheInstance.loadPCDFile(i);h(l,d)}),this.generateRange=i=>{const o=this.createRange(i);this.scene.add(o)},this.generateBoxArrow=({width:i})=>{const o=new THREE__namespace.Vector3(1,0,0),c=new THREE__namespace.Vector3(i/2,0,0),h=2,l=16776960,d=new THREE__namespace.ArrowHelper(o,c,h,l);return d.visible=this.showDirection,d},this.generateBoxTrackID=i=>{if(!i.trackID)return;const o=new THREE__namespace.Texture(this.getTextCanvas(i.trackID.toString()));o.needsUpdate=!0;const c=new THREE__namespace.SpriteMaterial({map:o,depthWrite:!1}),h=new THREE__namespace.Sprite(c);return h.scale.set(5,5,5),h.position.set(-i.width/2,0,i.depth/2+.5),h},this.applyZAxisPoints=i=>{this.zAxisLimit=i,this.filterZAxisPoints(),this.render()},this.updatePointSize=i=>{const o=this.scene.getObjectByName(this.pointCloudObjectName);if(!o)return;const c=o.material.size;i?o.material.size=Math.min(c*1.2,10):o.material.size=Math.max(c/1.2,1),this.render()},this.container=t,this.renderer=new THREE__namespace.WebGLRenderer({antialias:!0}),this.backgroundColor=s,this.config=a,r&&n?(this.isOrthographicCamera=!0,this.camera=new THREE__namespace.OrthographicCamera(n.left,n.right,n.top,n.bottom,n.near,n.far)):this.camera=new THREE__namespace.PerspectiveCamera(30,this.containerWidth/this.containerHeight,1,1e3),this.initCamera(),this.scene=new THREE__namespace.Scene,this.controls=new OrbitControls.OrbitControls(this.camera,this.renderer.domElement),this.pcdLoader=new PCDLoader.PCDLoader,this.axesHelper=new THREE__namespace.AxesHelper(1e3),this.scene.add(this.camera),e||t.appendChild(this.renderer.domElement),this.init(),this.cacheInstance=cache.PointCloudCache.getInstance()}get DEFAULT_INIT_CAMERA_POSITION(){return new THREE__namespace.Vector3(-.01,0,10)}get containerWidth(){return this.container.clientWidth}get containerHeight(){return this.container.clientHeight}setInitCameraPosition(t){this.initCameraPosition=t}setConfig(t){this.config=t}initOrthographicCamera(t){if(this.camera.type!=="OrthographicCamera")return;const{left:e,right:r,top:n,bottom:s,near:a,far:i}=t;this.camera.left=e,this.camera.right=r,this.camera.top=n,this.camera.bottom=s,this.camera.near=a,this.camera.far=i,this.camera.updateProjectionMatrix()}initPerspectiveCamera(){this.camera.type==="PerspectiveCamera"&&(this.camera.fov=30,this.camera.aspect=this.containerWidth/this.containerHeight,this.camera.near=1,this.camera.far=1e3,this.camera.updateProjectionMatrix())}initCamera(){const{camera:t}=this;if(this.isOrthographicCamera){const{x:e,y:r,z:n}=this.initCameraPosition;t.position.set(e,r,n)}else t.position.set(-1,0,500);t.up.set(0,0,1)}initControls(){const{controls:t}=this;t.addEventListener("change",()=>{this.render()}),this.setDefaultControls()}setDefaultControls(){const{controls:t}=this,e=[0,0,0];t.target=new THREE__namespace.Vector3(...e),t.addEventListener("change",()=>{this.render()}),t.maxPolarAngle=Math.PI/2,t.update()}initRenderer(){const{renderer:t}=this;t.setPixelRatio(window.devicePixelRatio),t.setSize(this.containerWidth,this.containerHeight)}init(){const{scene:t}=this;t.background=new THREE__namespace.Color(this.backgroundColor),this.initControls(),this.initRenderer()}removeObjectByName(t){const e=this.scene.getObjectByName(t);e&&e.removeFromParent()}generateBox(t,e=16777215){const r=e;this.AddBoxToSense(t,r),this.render()}getAllAttributeColor(t){return t.reduce((e,r)=>(e[r.attribute]=lbUtils.toolStyleConverter.getColorFromConfig({attribute:r.attribute},__spreadProps(__spreadValues({},this.config),{attributeConfigurable:!0}),{}),e),{})}generateBoxes(t){t.forEach(e=>{this.generateBox(e)}),this.render()}getOrthographicCamera(t){const{center:e,width:r,height:n}=t,s=10,a=e.x-r/2-s,i=e.x-r/2+s,o=e.y+n/2+s,c=e.y-n/2-s,h=100,l=-100,d=500/h;return{left:a,right:i,top:o,bottom:c,near:h,far:l,zoom:d}}updateCameraZoom(t){this.camera.zoom=t,this.camera.updateProjectionMatrix()}updateCameraByBox(t,e,r){const{center:n,width:s,height:a,depth:i,rotation:o}=t,c=this.getCameraVector(n,o,{width:s,height:a,depth:i},e);return r?(this.updateCamera(r,n),new THREE__namespace.Vector3(r.x,r.y,r.z)):(this.updateCamera(c,n),c)}updateCameraBySphere(t,e){const{center:r}=t,{radius:n}=lbUtils.DEFAULT_SPHERE_PARAMS,s=this.getCameraVector(r,0,{width:n*2,height:n*2,depth:n*2},e);return this.updateCamera(s,r),s}updateOrthoCamera(t,e){const r=this.updateCameraByBox(t,e);return this.camera.zoom=1,this.camera.updateProjectionMatrix(),{cameraPositionVector:r}}updateOrthoCameraBySphere(t,e){const r=this.updateCameraBySphere(t,e);return this.camera.zoom=1,this.camera.updateProjectionMatrix(),{cameraPositionVector:r}}updateTopCamera(){this.setInitCameraPosition(this.DEFAULT_INIT_CAMERA_POSITION),this.camera.zoom=1,this.initCamera(),this.setDefaultControls(),this.camera.updateProjectionMatrix(),this.render()}updateCamera(t,e){this.camera.position.set(t.x,t.y,t.z),this.controls.target=new THREE__namespace.Vector3(e.x,e.y,e.z),this.controls.update()}resetCamera(){this.updateCamera(this.DEFAULT_INIT_CAMERA_POSITION,{x:0,y:0,z:0})}getOrthographicCameraTarget(t){const e=new THREE__namespace.Vector3(0,0,-1).applyQuaternion(t.quaternion);return t.position.clone().add(e)}createThreeMatrix4(t){return new THREE__namespace.Matrix4().set(...t)}filterPointsByBox(t,e,r){var n,s,a;if(!e){const i=this.scene.getObjectByName(this.pointCloudObjectName);if(!i)return console.error("There is no corresponding point cloud object"),Promise.resolve(void 0);e=(a=(s=(n=i==null?void 0:i.geometry)==null?void 0:n.attributes)==null?void 0:s.position)==null?void 0:a.array}if(window.Worker){const{zMin:i,zMax:o,polygonPointList:c}=matrix.getCuboidFromPointCloudBox(t),h=e;r=r!=null?r:new Float32Array([]);const l={boxParams:t,zMin:i,zMax:o,polygonPointList:c,color:r,position:h};return new Promise(d=>{const g=new filterBoxWorker;g.postMessage(l),g.onmessage=x=>{const{color:p,position:u,num:f}=x.data,y=new THREE__namespace.BufferGeometry;y.setAttribute("position",new THREE__namespace.Float32BufferAttribute(u,3)),y.setAttribute("color",new THREE__namespace.Float32BufferAttribute(p,3)),y.computeBoundingSphere(),g.terminate(),d({geometry:y,num:f})}})}return Promise.resolve(void 0)}getCameraVector(t,e,r,n=lbUtils.EPerspectiveView.Front,s=DEFAULT_DISTANCE){let a=lbUtils.PerspectiveShiftUtils.frontViewMatrix4(s);switch(n){case lbUtils.EPerspectiveView.Front:break;case lbUtils.EPerspectiveView.Back:a=lbUtils.PerspectiveShiftUtils.backViewMatrix4(s);break;case lbUtils.EPerspectiveView.Left:a=lbUtils.PerspectiveShiftUtils.leftViewMatrix4(s);break;case lbUtils.EPerspectiveView.Right:a=lbUtils.PerspectiveShiftUtils.rightViewMatrix4(s);break;case lbUtils.EPerspectiveView.Top:a=lbUtils.PerspectiveShiftUtils.topViewMatrix4(s);break;case lbUtils.EPerspectiveView.LFT:a=lbUtils.PerspectiveShiftUtils.leftFrontTopViewMatrix4(s,r);break;case lbUtils.EPerspectiveView.RBT:a=lbUtils.PerspectiveShiftUtils.rightBackTopViewMatrix4(s,r);break}const i=this.createThreeMatrix4(a),o=new THREE__namespace.Matrix4().makeTranslation(-t.x,-t.y,-t.z),c=new THREE__namespace.Matrix4().makeTranslation(t.x,t.y,t.z),h=new THREE__namespace.Matrix4().makeRotationZ(e);return new THREE__namespace.Vector3(t.x,t.y,t.z).clone().applyMatrix4(i).applyMatrix4(o).applyMatrix4(h).applyMatrix4(c)}createRange(t){this.removeObjectByName(this.rangeObjectName);const r=new THREE__namespace.EllipseCurve(0,0,t,t,0,2*Math.PI,!1,0).getPoints(50),n=new THREE__namespace.BufferGeometry().setFromPoints(r),s=new THREE__namespace.LineBasicMaterial({color:16711680}),a=new THREE__namespace.Line(n,s);return a.name=this.rangeObjectName,a}renderPointCloud(t,e){t.name=this.pointCloudObjectName;const r=new THREE__namespace.PointsMaterial({vertexColors:!0});r.onBeforeCompile=this.overridePointShader,r.size=1.2,e&&this.generateRange(e),this.pointsUuid=t.uuid,t.material=r,this.filterZAxisPoints(t),this.scene.add(t),this.render()}clearPointCloud(){this.removeObjectByName(this.pointCloudObjectName)}clearPointCloudAndRender(){this.clearPointCloud(),this.render()}highlightOriginPointCloud(t){const e=this.scene.getObjectByName(this.pointCloudObjectName);if(!!e)return this.highlightPCDSrc=this.currentPCDSrc,new Promise(r=>{if(window.Worker){const s=(t?[...t]:[]).map(o=>matrix.getCuboidFromPointCloudBox(o)),a=this.getAllAttributeColor(s),i={cuboidList:s,position:e.geometry.attributes.position.array,color:e.geometry.attributes.color.array,colorList:a};highlightWorker.postMessage(i),highlightWorker.onmessage=o=>{const{color:c}=o.data,h=new THREE__namespace.BufferAttribute(c,3);this.highlightPCDSrc&&(this.cacheInstance.updateColor(this.highlightPCDSrc,c),this.highlightPCDSrc=void 0),h.needsUpdate=!0,e.geometry.setAttribute("color",h),r(c),this.render()}}})}updateColor(t){const e=this.scene.getObjectByName(this.pointCloudObjectName);if(e){const r=new THREE__namespace.BufferAttribute(t,3);r.needsUpdate=!0,e.geometry.setAttribute("color",r),this.render()}}setShowDirection(t){this.showDirection=t,this.scene.children.forEach(e=>{e.type==="Group"&&e.children.forEach(r=>{r.type==="ArrowHelper"&&(r.visible=t)})}),this.render()}getTextCanvas(t){const e=document.createElement("canvas"),r=e.getContext("2d");return r&&(r.font=`${50}px " bold`,r.fillStyle="white",r.textAlign="center",r.textBaseline="middle",r.fillText(t,e.width/2,e.height/2)),e}filterNoise(t){let e=[...t];e.sort((l,d)=>l.z-d.z);const r=Math.floor(e.length*.05),n=e[r];e=e.filter(({z:l})=>l>n.z+.1);const s=.005,a=Math.floor(e.length*(1-s));e=e.slice(0,a),e.sort((l,d)=>l.x-d.x);const i=Math.floor(e.length*s),o=Math.floor(e.length*(1-s));e=e.slice(i,o),e.sort((l,d)=>l.y-d.y);const c=Math.floor(e.length*s),h=Math.floor(e.length*(1-s));return e=e.slice(c,h),e.length>100?e:t}getFittedCoordinates(t,e){const r=[];let n=[...t,t[0]];e.forEach(({x:i,y:o})=>{t.forEach((c,h)=>{const l=n[h+1],d=MathUtils.default.getFootOfPerpendicular({x:i,y:o},c,l,!1,!0).length;(!r[h]||d<r[h].distance)&&(r[h]={distance:d,point:{x:i,y:o}})})}),n=[t[t.length-1],...t,t[0]];const s=[r[r.length-1],...r];return t.map((i,o)=>{const c=n[o],h=n[o+1],l=n[o+2];return lbUtils.PointCloudUtils.getIntersectionBySlope({p1:s[o].point,k1:(c.y-h.y)/(c.x-h.x),p2:s[o+1].point,k2:(h.y-l.y)/(h.x-l.x)})})}getSensesPointZAxisInPolygon(t,e,r){var n,s,a;const i=this.scene.children.find(p=>p.uuid===this.pointsUuid);let o=0,c=0,h=0,l=0,d=[],g=[];const x=((a=(s=(n=i==null?void 0:i.geometry)==null?void 0:n.attributes)==null?void 0:s.position)==null?void 0:a.array)||[];for(let p=0;p<x.length;p+=3){const u=x[p],f=x[p+1],y=x[p+2];polygonTool.isInPolygon({x:u,y:f},t)&&(y||y===0)&&g.push({x:u,y:f,z:y})}return g.length?(r&&(g=this.filterNoise(g),d=this.getFittedCoordinates(t,g)),g.sort((p,u)=>p.z-u.z),o=g[0].z-.01,c=g[g.length-1].z+.01,l=g.length,e&&(h=g.filter(({z:p})=>p>=e[0]&&p<=e[1]).length),{maxZ:c,minZ:o,count:h,zCount:l,fittedCoordinates:d}):{maxZ:c,minZ:o,count:h,zCount:l,fittedCoordinates:d}}getBasicCoordinate2Canvas(t){const e=this.containerWidth/2,r=this.containerHeight/2;return{x:t.x*e+e,y:t.y*r+r,z:t.z}}get basicCoordinate2CanvasMatrix4(){const t=this.containerWidth/2,e=this.containerHeight/2;return new THREE__namespace.Matrix4().set(t,0,0,t,0,e,0,e,0,0,1,0,0,0,0,1)}getCanvas2BasicCoordinate(t){const e=this.containerWidth/2,r=this.containerHeight/2;return new THREE__namespace.Vector3(t.x/e-e/2,-(t.y/r-r/2),1)}getPolygonSidePoints(t){const{center:{x:e,y:r,z:n},height:s,width:a,depth:i}=t,o={x:e+a/2,y:r+s/2,z:n-i/2},c={x:e+a/2,y:r+s/2,z:n+i/2},h={x:e-a/2,y:r+s/2,z:n+i/2},l={x:e-a/2,y:r+s/2,z:n-i/2};return[o,c,h,l]}getPolygonBackPoints(t){const{center:{x:e,y:r,z:n},height:s,width:a,depth:i}=t,o={x:e-a/2,y:r+s/2,z:n+i/2},c={x:e-a/2,y:r+s/2,z:n-i/2},h={x:e-a/2,y:r-s/2,z:n-i/2},l={x:e-a/2,y:r-s/2,z:n+i/2};return[o,c,h,l]}getPolygonTopPoints(t){const{center:{x:e,y:r,z:n},height:s,width:a,depth:i}=t,o={x:e+a/2,y:r+s/2,z:n+i/2},c={x:e+a/2,y:r-s/2,z:n+i/2},h={x:e-a/2,y:r-s/2,z:n+i/2},l={x:e-a/2,y:r+s/2,z:n+i/2};return[o,c,h,l]}getModelTransformationMatrix(t){const{center:{x:e,y:r,z:n},rotation:s}=t,a=new THREE__namespace.Matrix4().makeTranslation(-e,-r,-n),i=new THREE__namespace.Matrix4().makeTranslation(e,r,n),o=new THREE__namespace.Matrix4().makeRotationZ(s);return new THREE__namespace.Matrix4().multiply(i).multiply(o).multiply(a)}getBoxSidePolygon2DCoordinate(t){return this.getBoxPolygon2DCoordinate(t,lbUtils.EPerspectiveView.Left)}getBoxBackPolygon2DCoordinate(t){return this.getBoxPolygon2DCoordinate(t,lbUtils.EPerspectiveView.Back)}getSphereSidePoint2DCoordinate(t){return this.getSpherePoint2DCoordinate(t)}getSphereBackPoint2DCoordinate(t){return this.getSpherePoint2DCoordinate(t)}boxParams2ViewPolygon(t,e){switch(e){case lbUtils.EPerspectiveView.Left:return this.getPolygonSidePoints(t);case lbUtils.EPerspectiveView.Back:return this.getPolygonBackPoints(t);default:return this.getPolygonTopPoints(t)}}getBoxPolygon2DCoordinate(t,e){const r=this.boxParams2ViewPolygon(t,e),{width:n,height:s}=t,a=new THREE__namespace.Matrix4().premultiply(this.camera.matrixWorldInverse).premultiply(this.camera.projectionMatrix),i=new THREE__namespace.Matrix4().premultiply(this.getModelTransformationMatrix(t)).premultiply(a).premultiply(this.basicCoordinate2CanvasMatrix4);this.sideMatrix=i;const o=r.map(l=>new THREE__namespace.Vector3(l.x,l.y,l.z)).map(l=>l.applyMatrix4(this.sideMatrix)),c=this.containerWidth/n,h=this.containerHeight/s;return{polygon2d:o,zoom:Math.min(c,h)/2}}getSpherePoint2DCoordinate(t){const{center:e,attribute:r,id:n,valid:s}=t,{radius:a}=lbUtils.DEFAULT_SPHERE_PARAMS,i={center:e,attribute:r,id:n,valid:s,width:a*2,height:a*2,depth:a*2,rotation:0},o=new THREE__namespace.Matrix4().premultiply(this.camera.matrixWorldInverse).premultiply(this.camera.projectionMatrix),c=new THREE__namespace.Matrix4().premultiply(this.getModelTransformationMatrix(i)).premultiply(o).premultiply(this.basicCoordinate2CanvasMatrix4);this.sideMatrix=c;const h=new THREE__namespace.Vector3(e.x,e.y,e.z).applyMatrix4(this.sideMatrix),l=this.containerWidth/(a*2),d=this.containerHeight/(a*2);return{point2d:h,zoom:Math.min(l,d)/2}}getSphereTopPoint2DCoordinate(t){const{center:e}=t,{radius:r}=lbUtils.DEFAULT_SPHERE_PARAMS,n={x:-(e.y-this.containerWidth/2),y:-(e.x-this.containerHeight/2)},s=this.containerWidth/(r*2),a=this.containerHeight/(r*2);return{point2d:n,zoom:Math.min(s,a)/2}}getBoxTopPolygon2DCoordinate(t){const{width:e,height:r}=t,s=this.getPolygonTopPoints(t).map(o=>new THREE__namespace.Vector3(o.x,o.y,o.z)).map(o=>o.applyMatrix4(this.getModelTransformationMatrix(t))).map(o=>({x:o.y,y:o.x})).map(o=>({x:-(o.x-this.containerWidth/2),y:-(o.y-this.containerHeight/2)})),a=this.containerWidth/e,i=this.containerHeight/r;return{polygon2d:s,zoom:Math.min(a,i)/2}}getNewBoxBySideUpdate(t,e,r,n){const s=new THREE__namespace.Matrix4().makeRotationZ(n.rotation),a=new THREE__namespace.Vector3(-t.x,0,0).applyMatrix4(s);let i=n;return i.center={x:i.center.x+a.x,y:i.center.y+a.y,z:i.center.z-t.z},i=__spreadProps(__spreadValues({},i),{width:i.width+e,height:i.height,depth:i.depth+r}),{newBoxParams:i}}getNewBoxByBackUpdate(t,e,r,n){const s=new THREE__namespace.Matrix4().makeRotationZ(n.rotation),a=new THREE__namespace.Vector3(0,-t.x,0).applyMatrix4(s);let i=n;return i.center={x:i.center.x+a.x,y:i.center.y+a.y,z:i.center.z-t.z},i=__spreadProps(__spreadValues({},i),{width:i.width,height:i.height+e,depth:i.depth+r}),{newBoxParams:i}}getNewBoxBySideUpdateByPoints(t,e,r,n){var s;const a=(s=this.sideMatrix)==null?void 0:s.invert();if(!this.sideMatrix||!a){console.error("No sideMatrix");return}this.camera.zoom=1,this.camera.updateProjectionMatrix();const i=t.map(u=>new THREE__namespace.Vector3(u.x,u.y,u.z)).map(u=>u.applyMatrix4(a)),[o,c,h,l]=i,d=Math.max(Math.abs(o.x-h.x),Math.abs(o.x-c.x)),x=c.add(l).applyMatrix3(new THREE__namespace.Matrix3().set(1/2,0,0,0,1/2,0,0,0,1/2)).clone().applyMatrix3(new THREE__namespace.Matrix3().set(-1,0,0,0,-1,0,0,0,-1)).add(new THREE__namespace.Vector3(n.center.x,n.center.y,n.center.z));return{newBoxParams:__spreadProps(__spreadValues({},n),{center:{x:n.center.x-x.x,y:n.center.y-x.y,z:n.center.z-r},width:d,height:n.height,depth:n.depth+e,rotation:n.rotation})}}filterZAxisPoints(t){const e=t||this.scene.children.find(r=>r.uuid===this.pointsUuid);if(e){const{attributes:r}=e.geometry,{position:n}=r,s=[],{count:a}=n;for(let i=0;i<a;i++){const o=n.getZ(i);s.push(o>this.zAxisLimit?0:1)}e.geometry.setAttribute("visibility",new THREE__namespace.Float32BufferAttribute(s,1)),e.geometry.attributes.visibility.needsUpdate=!0}}render(){this.renderer.render(this.scene,this.camera)}}exports.createThreeMatrix4=matrix.createThreeMatrix4,exports.getCuboidFromPointCloudBox=matrix.getCuboidFromPointCloudBox,exports.lidar2image=matrix.lidar2image,exports.pointCloudLidar2image=matrix.pointCloudLidar2image,exports.rotatePoint=matrix.rotatePoint,exports.transferKitti2Matrix=matrix.transferKitti2Matrix,exports.PointCloud=PointCloud;
|
package/dist/core/scheduler.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var defaultConfig=require("../constant/defaultConfig.js"),EnhanceCommonToolUtils=require("../utils/tool/EnhanceCommonToolUtils.js"),basicToolOperation=require("./toolOperation/basicToolOperation.js");const createEmptyImage=e=>{const t=document.createElement("canvas");t.width=e.width,t.height=e.height;const i=t.getContext("2d");return i?(i.fillStyle="transparent",i.fillRect(0,0,e.width,e.height),t.toDataURL()):""},arraySwap=(e,t,i)=>{const o=e[t];return e[t]=e[i],e[i]=o,e},_HybridToolUtils=class{static isSingleTool(e){return!this.isHybridTool(e)}static isHybridTool(e){return Array.isArray(e)}};let HybridToolUtils=_HybridToolUtils;HybridToolUtils.getTopToolName=e=>_HybridToolUtils.isHybridTool(e)?e[e.length-1]:e;class ToolScheduler{constructor(t){this.toolOperationList=[],this.toolOperationDom=[],this.toolOperationNameList=[];var i,o;this.init(),this.container=t.container,this.size=t.size,this.imgNode=t.imgNode,this.config=(i=t.config)!=null?i:JSON.stringify(defaultConfig.getConfig(HybridToolUtils.getTopToolName(t.toolName))),this.style=(o=t.style)!=null?o:defaultConfig.styleDefaultConfig}setImgNode(t,i){this.toolOperationList.forEach(o=>{o.setImgNode(t,i)})}setImgAttribute(t){this.toolOperationList.forEach(i=>{i.setImgAttribute(t)})}setSize(t){this.toolOperationList.forEach(i=>{i.setSize(t)})}syncPosition(t,i,o,
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var defaultConfig=require("../constant/defaultConfig.js"),EnhanceCommonToolUtils=require("../utils/tool/EnhanceCommonToolUtils.js"),basicToolOperation=require("./toolOperation/basicToolOperation.js");const createEmptyImage=e=>{const t=document.createElement("canvas");t.width=e.width,t.height=e.height;const i=t.getContext("2d");return i?(i.fillStyle="transparent",i.fillRect(0,0,e.width,e.height),t.toDataURL()):""},arraySwap=(e,t,i)=>{const o=e[t];return e[t]=e[i],e[i]=o,e},_HybridToolUtils=class{static isSingleTool(e){return!this.isHybridTool(e)}static isHybridTool(e){return Array.isArray(e)}};let HybridToolUtils=_HybridToolUtils;HybridToolUtils.getTopToolName=e=>_HybridToolUtils.isHybridTool(e)?e[e.length-1]:e;class ToolScheduler{constructor(t){this.toolOperationList=[],this.toolOperationDom=[],this.toolOperationNameList=[];var i,o;this.init(),this.container=t.container,this.size=t.size,this.imgNode=t.imgNode,this.config=(i=t.config)!=null?i:JSON.stringify(defaultConfig.getConfig(HybridToolUtils.getTopToolName(t.toolName))),this.style=(o=t.style)!=null?o:defaultConfig.styleDefaultConfig}setImgNode(t,i){this.toolOperationList.forEach(o=>{o.setImgNode(t,i)})}setImgAttribute(t){this.toolOperationList.forEach(i=>{i.setImgAttribute(t)})}setSize(t){this.toolOperationList.forEach(i=>{i.setSize(t)})}syncPosition(t,i,o,s){this.toolOperationList.forEach(a=>{s!==a&&(a.setCurrentPos(t),a.setZoom(i),a.setImgInfo(o),a.renderBasicCanvas(),a.render())})}get defaultSize(){var t,i;return{width:((t=this.imgNode)==null?void 0:t.width)||this.size.width,height:((i=this.imgNode)==null?void 0:i.height)||this.size.height}}createDom(){const{width:t,height:i}=this.defaultSize,o=window.document.createElement("div");o.style.position="absolute",o.style.left="0",o.style.top="0",o.style.width=`${t}px`,o.style.height=`${i}px`;const s=this.toolOperationList.length+1;return o.style.zIndex=`${s}`,o}getEmptyImage(t,i){const o=createEmptyImage({width:t,height:i}),s=new Image;return s.src=o,s}createOperation(t,i,o){var s;const{width:a,height:l}=this.defaultSize,r=this.createDom(),d=this.getEmptyImage(a,l),h={container:r,size:this.size,config:(s=this==null?void 0:this.config)!=null?s:"{}",drawOutSideTarget:!1,style:this.style,imgNode:i||d,hiddenImg:!!t};o&&Object.assign(h,o);let n;if(!t)n=new basicToolOperation.BasicToolOperation(h),r.style.zIndex="0",n.init();else{const c=EnhanceCommonToolUtils.getCurrentOperation(t);if(!c)return;n=new c(h)}return n==null||n.init(),n.canvas.id=t!=null?t:"basicCanvas",n.on("dragMove",({currentPos:c,zoom:p,imgInfo:u})=>{this.syncPosition(c,p,u,n)}),n.on("renderZoom",(c,p,u)=>{c&&p&&this.syncPosition(p,c,u,n)}),t?(this.container.appendChild(r),this.toolOperationList.push(n),this.toolOperationNameList.push(t),this.toolOperationDom.push(r),n):(this.container.insertBefore(r,this.container.childNodes[0]),this.toolOperationList.unshift(n),this.toolOperationDom.unshift(r),n)}switchLastTwoCanvas(){if(this.toolOperationDom.length<3){console.error("switchLastTwoCanvas is just used the layer which has 3 canvas");return}const t=this.toolOperationDom.length,i=t-1,o=t-2,s=this.toolOperationDom[i],a=this.toolOperationDom[o];if(!(!a||!s))return s.style.zIndex=`${i-1}`,a.style.zIndex=`${i}`,this.toolOperationList[i].clearActiveStatus(),this.toolOperationList[i].clearCursorLine(),this.toolOperationList[i].render(),this.toolOperationList=arraySwap(this.toolOperationList,i,o),this.toolOperationDom=arraySwap(this.toolOperationDom,i,o),this.toolOperationList[i]}getFirstToolOperation(){return this.toolOperationList.length>1?this.toolOperationList[1]:this.toolOperationList[0]}switchToCanvas(t){var i,o,s,a;const l=this.toolOperationNameList.indexOf(t);if(l<0||this.toolOperationList.length<1||l>this.toolOperationDom.length-1)return;const r=this.toolOperationDom.length-1,d=this.toolOperationDom[l],h=this.toolOperationDom[r];if(!d||!h)return;const n=h.style.zIndex;return h.style.zIndex=`${d.style.zIndex}`,d.style.zIndex=`${n}`,(o=(i=this.toolOperationList[r]).clearActiveStatus)==null||o.call(i),(a=(s=this.toolOperationList[r]).clearCursorLine)==null||a.call(s),this.toolOperationList[r].render(),this.toolOperationList=arraySwap(this.toolOperationList,r,l),this.toolOperationDom=arraySwap(this.toolOperationDom,r,l),this.toolOperationNameList=arraySwap(this.toolOperationNameList,r,l),this.toolOperationList[r]}updateDataByToolName(t,i){const o=this.toolOperationNameList.indexOf(t);o>=0&&this.toolOperationList[o].setResult(i)}clearStatusAndResult(){this.toolOperationList.forEach(t=>{var i;(i=t.clearActiveStatus)==null||i.call(t),t.clearResult()})}destroyAllLayer(){this.toolOperationList.forEach(t=>{t.destroyCanvas(),this.init()})}init(){this.toolOperationList=[],this.toolOperationDom=[]}}exports.HybridToolUtils=HybridToolUtils,exports.ToolScheduler=ToolScheduler;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var _=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"),ImgPosUtils=require("../../utils/tool/ImgPosUtils.js"),basicToolOperation=require("./basicToolOperation.js"),matrix=require("../pointCloud/matrix.js"),AttributeUtils=require("../../utils/tool/AttributeUtils.js"),CuboidUtils=require("../../utils/tool/CuboidUtils.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));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=o=>{var r,a;const c=this.getCoordinateUnderZoom(o),n=AxisUtils.default.changePointByZoom(c,1/this.zoom);if(((r=this.annotations)==null?void 0:r.length)<=0||!((a=this.annotations)==null?void 0:a.length))return;let h="",i=Number.MAX_SAFE_INTEGER;for(let l=0;l<this.annotations.length;l++){const s=this.annotations[l];switch(s.type){case"rect":{const d=s.annotation;if(RectUtils.isInRect(c,d,newScope,this.zoom)){const u=d.width*d.height;u<i&&(h=d.id,i=u)}break}case"polygon":{const d=s.annotation;if(PolygonUtils.isInPolygon(n,d.pointList)){const u=PolygonUtils.getPolygonArea(d.pointList);u<i&&(h=d.id,i=u)}break}}}return h};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,o;this.connectPointsStatus&&((o=(e=this.connectPointsStatus).close)==null||o.call(e)),this.emit("connectionPointsStatusUpdate",()=>new Promise(r=>{const{promise:a,close:c}=MathUtils.default.getCollectionPointByAnnotationDataPromise(t);this.connectPointsStatus={close:c},a.then(n=>{this.connectionPoints=n.connectionPoints,this.render(),this.connectPointsStatus=void 0,r({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 o=[];e&&(o=[e]),this.emit("onChange","selected",o),this.render()}}onMouseMove(t){if(super.onMouseMove(t)||this.forbidMouseOperation||!this.imgInfo)return;const e=this.mouseHoverID,o=this.getHoverRectID(t);if(e!==o){this.mouseHoverID=o;let r=[];o&&(r=[o]),this.emit("onChange","hover",r),this.render()}}updateData(t){this.annotations=t,this.render()}getSpecificStyle(t){const e=___default.default.pick(t,["stroke","thickness","fill","radius"]),o=__spreadValues(__spreadValues({},this.style),e);return o.stroke&&Object.assign(o,{color:o.stroke}),o}getFontStyle(t,e){var o,r;const a=(o=t==null?void 0:t.fontSize)!=null?o:14,c=(r=t==null?void 0:t.fontFamily)!=null?r:"Arial";return __spreadProps(__spreadValues({},annotation.DEFAULT_TEXT_SHADOW),{color:e.stroke,font:`normal normal 600 ${a}px ${c}`})}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 o="",r="";return!t||e===!0?{headerText:o,bottomText:r}:((t==null?void 0:t.order)&&(o=`${t.order}`),(t==null?void 0:t.label)&&(o?o=`${o}_${t.label}`:o=`${t.label}`),(t==null?void 0:t.attribute)&&(o?o=`${o} ${t.attribute}`:o=`${t.attribute}`),(t==null?void 0:t.textAttribute)&&(r=t==null?void 0:t.textAttribute),{headerText:o,bottomText:r})}getReferenceOptions(t){return t?{lineCap:"butt",lineDash:[20,20]}:{}}focusPositionByPointList(t){const e=MathUtils.default.calcViewportBoundaries(t),o={x:e.left,y:e.top,width:e.right-e.left,height:e.bottom-e.top},r=ImgPosUtils.getBasicRecPos(this.imgNode,o,this.size,.5);if(r){this.setCurrentPos(r.currentPos),this.setCurrentPosStorage(r.currentPos);const{imgInfo:a}=this,{innerZoom:c}=this.innerPosAndZoom;a&&this.setImgInfo(__spreadProps(__spreadValues({},a),{width:a.width/c*r.innerZoom,height:a.height/c*r.innerZoom})),this.setZoom(r.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),o=this.getFontStyle(t.annotation,e);return{style:e,fontStyle:o}}renderLine(t){var e,o,r;if(t.type!=="line")return;const{style:a,fontStyle:c}=this.getRenderStyle(t),n=t.annotation;if(!(((e=n==null?void 0:n.pointList)==null?void 0:e.length)>=2))return;const{lineType:h=tool.ELineTypes.Line}=n,i=AxisUtils.default.changePointListByZoom((o=n==null?void 0:n.pointList)!=null?o:[],this.zoom,this.currentPos),l=__spreadProps(__spreadValues(__spreadValues({},a),this.getReferenceOptions(n==null?void 0:n.isReference)),{lineType:h,strokeColor:a.stroke});let s=[];if(n.showKeyPoint?s=DrawUtils.drawPolygonWithKeyPoint(this.canvas,i,l):s=DrawUtils.drawPolygon(this.canvas,i,l),(n==null?void 0:n.showDirection)===!0&&((r=n==null?void 0:n.pointList)==null?void 0:r.length)>=2){let v=i[0],p=MathUtils.default.getLineCenterPoint([i[0],i[1]]);if(h===tool.ELineTypes.Curve){const f=Math.floor(tool.SEGMENT_NUMBER/2);v=s[f],p=s[f+1]}DrawUtils.drawArrowByCanvas(this.canvas,v,p,{color:a.stroke,thickness:a.thickness}),DrawUtils.drawCircle(this.canvas,i[0],a.thickness+6,{color:a.stroke,thickness:a.thickness})}const{headerText:u,bottomText:y}=this.getRenderText(n,n==null?void 0:n.hiddenText);if(u&&DrawUtils.drawText(this.canvas,this.appendOffset(i[0]),u,c),y){const v=i[i.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,c)}}renderPolygon(t){var e,o,r,a,c;if(t.type!=="polygon")return;const{style:n,fontStyle:h}=this.getRenderStyle(t),i=t.annotation;if(!(((e=i==null?void 0:i.pointList)==null?void 0:e.length)>=3))return;const{lineType:l=tool.ELineTypes.Line}=i,s=AxisUtils.default.changePointListByZoom((o=i==null?void 0:i.pointList)!=null?o:[],this.zoom,this.currentPos);if(i.id===this.mouseHoverID||n.fill){const f=rgba__default.default((a=(r=n==null?void 0:n.fill)!=null?r:n==null?void 0:n.stroke)!=null?a:DEFAULT_STROKE_COLOR),x=`rgba(${f[0]}, ${f[1]}, ${f[2]},${f[3]*.8})`;DrawUtils.drawPolygonWithFill(this.canvas,s,{color:x,lineType:l})}const d=__spreadProps(__spreadValues(__spreadProps(__spreadValues({},n),{isClose:!0}),this.getReferenceOptions(i==null?void 0:i.isReference)),{lineType:l,strokeColor:n.stroke});let u=[];if(i.showKeyPoint?u=DrawUtils.drawPolygonWithKeyPoint(this.canvas,s,d):u=DrawUtils.drawPolygon(this.canvas,s,d),(i==null?void 0:i.showDirection)===!0&&((c=i==null?void 0:i.pointList)==null?void 0:c.length)>=2){let f=s[0],x=MathUtils.default.getLineCenterPoint([s[0],s[1]]);if(l===tool.ELineTypes.Curve){const T=Math.floor(tool.SEGMENT_NUMBER/2);f=u[T],x=u[T+1]}DrawUtils.drawArrowByCanvas(this.canvas,f,x,{color:n.stroke,thickness:n.thickness}),DrawUtils.drawCircle(this.canvas,s[0],n.thickness+6,{color:n.stroke,thickness:n.thickness})}const{headerText:v,bottomText:p}=this.getRenderText(i,i==null?void 0:i.hiddenText);if(v&&DrawUtils.drawText(this.canvas,this.appendOffset(s[0]),v,h),p){const f=s[s.length-1];DrawUtils.drawText(this.canvas,this.appendOffset({x:f.x+annotation.TEXT_ATTRIBUTE_OFFSET.x,y:f.y+annotation.TEXT_ATTRIBUTE_OFFSET.y}),p,h)}}renderSingleCuboid(t){var e,o,r,a;const{style:c}=this.getRenderStyle(t),n=t.annotation,h=rgba__default.default((o=(e=c==null?void 0:c.fill)!=null?e:c==null?void 0:c.stroke)!=null?o:DEFAULT_STROKE_COLOR),i=`rgba(${h[0]}, ${h[1]}, ${h[2]},${h[3]*.8})`,l=c.stroke,s=AxisUtils.default.changeCuboidByZoom(n,this.zoom,this.currentPos),d=l,{headerText:u,bottomText:y}=this.getRenderText(n,n==null?void 0:n.hiddenText),{backPoints:v,frontPoints:p,textAttribute:f}=s,x=p.br.x-p.bl.x;DrawUtils.drawCuboid(this.canvas,s,{strokeColor:l,fillColor:i,thickness:c.thickness});let T="";((r=this.config)==null?void 0:r.isShowOrder)&&s.order&&(s==null?void 0:s.order)>0&&(T=`${s.order}`),s.attribute&&(T=`${T} ${AttributeUtils.default.getAttributeShowText(s.attribute,(a=this.config)==null?void 0:a.attributeList)}`),u&&v&&DrawUtils.drawText(this.canvas,{x:v.tl.x,y:v.tl.y-5},T,{color:l,textMaxWidth:300});const P=CuboidUtils.getCuboidTextAttributeOffset({cuboid:n,currentPos:this.currentPos,zoom:this.zoom,topOffset:16,leftOffset:0});if(y){const w=Math.max(20,x*.8);DrawUtils.drawText(this.canvas,{x:P.left,y:P.top},f,{color:d,textMaxWidth:w})}}renderBox3d(t){if(t.type!=="box3d")return;const e=t.annotation,o=matrix.pointCloudLidar2image(e,e.calib),r={fill:"transparent"},a=___default.default.pick(e,["stroke","thickness"]);o.forEach((c,n)=>{const h=__spreadValues(__spreadProps(__spreadValues({},a),{id:`${t.annotation.id}-${n}`,pointList:c.pointList}),r);switch(c.type){case"line":this.renderLine({type:"line",annotation:h});break;case"polygon":this.renderPolygon({type:"polygon",annotation:h});break}})}render(){try{if(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 o,r,a,c,n;const h=this.getSpecificStyle(e.annotation),i=this.getFontStyle(e.annotation,h);switch(e.type){case"rect":{const l=e.annotation,{hiddenText:s=!1,isReference:d,hiddenRectSize:u=!1}=l,{zoom:y}=this,v=AxisUtils.default.changeRectByZoom(l,this.zoom,this.currentPos),{x:p,y:f,width:x,height:T}=v;if(l.id===this.mouseHoverID||h.fill){const m=rgba__default.default((r=(o=h==null?void 0:h.fill)!=null?o:h==null?void 0:h.stroke)!=null?r:DEFAULT_STROKE_COLOR),S=`rgba(${m[0]}, ${m[1]}, ${m[2]},${m[3]*.8})`;DrawUtils.drawRectWithFill(this.canvas,v,{color:S})}DrawUtils.drawRect(this.canvas,v,__spreadValues(__spreadProps(__spreadValues({},h),{hiddenText:!0}),this.getReferenceOptions(d)));const{headerText:P,bottomText:w}=this.getRenderText(l,l==null?void 0:l.hiddenText);P&&DrawUtils.drawText(this.canvas,{x:p,y:f-6},P,__spreadValues({textMaxWidth:300},i));const b=`${Math.round(x/y)} * ${Math.round(T/y)}`,k=b.length*7;if(!s&&!u&&DrawUtils.drawText(this.canvas,{x:p+x-k,y:f+T+15},b,i),w){const m=20,S=Math.max(20,x-k);DrawUtils.drawText(this.canvas,{x:p,y:f+T+m},l.textAttribute,__spreadValues({textMaxWidth:S},i))}break}case"polygon":{this.renderPolygon(e);break}case"line":{this.renderLine(e);break}case"point":{const l=e.annotation,s=AxisUtils.default.changePointByZoom(l,this.zoom,this.currentPos),d=(a=h.radius)!=null?a:DEFAULT_RADIUS;DrawUtils.drawCircle(this.canvas,s,d,h);const{headerText:u,bottomText:y}=this.getRenderText(l,l==null?void 0:l.hiddenText);u&&DrawUtils.drawText(this.canvas,{x:s.x+d/2,y:s.y-d-4},u,__spreadValues({textAlign:"center"},i)),y&&DrawUtils.drawText(this.canvas,this.appendOffset({x:s.x+d,y:s.y+d+24}),y,i);break}case"text":{const l=e.annotation,{text:s,x:d,y:u,textMaxWidth:y,color:v="white",background:p="rgba(0, 0, 0, 0.6)",lineHeight:f=25,font:x=tool.DEFAULT_FONT,position:T}=l,P=10,w=10,b=AxisUtils.default.changePointByZoom({x:d,y:u},this.zoom,this.currentPos),{width:k,height:m,fontHeight:S=0}=MathUtils.default.getTextArea(this.canvas,l.text,y,x,f);if(T==="rt")break;DrawUtils.drawRectWithFill(this.canvas,{x:b.x,y:b.y,width:k+w*2,height:m+P*2,id:"",sourceID:"",valid:!0,textAttribute:"",attribute:""},{color:p}),DrawUtils.drawText(this.canvas,{x:b.x+w,y:b.y+S+P},s,{color:v,lineHeight:f,font:x,textMaxWidth:y});break}case"box3d":{this.renderBox3d(e);break}case"cuboid":{this.renderSingleCuboid(e);break}default:break}(n=(c=e.annotation)==null?void 0:c.renderEnhance)==null||n.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 _=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"),ImgPosUtils=require("../../utils/tool/ImgPosUtils.js"),basicToolOperation=require("./basicToolOperation.js"),matrix=require("../pointCloud/matrix.js");function _interopDefaultLegacy(v){return v&&typeof v=="object"&&"default"in v?v:{default:v}}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=(v,t,e)=>t in v?__defProp(v,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):v[t]=e,__spreadValues=(v,t)=>{for(var e in t||(t={}))__hasOwnProp.call(t,e)&&__defNormalProp(v,e,t[e]);if(__getOwnPropSymbols)for(var e of __getOwnPropSymbols(t))__propIsEnum.call(t,e)&&__defNormalProp(v,e,t[e]);return v},__spreadProps=(v,t)=>__defProps(v,__getOwnPropDescs(t));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=o=>{var i,r;const c=this.getCoordinateUnderZoom(o),n=AxisUtils.default.changePointByZoom(c,1/this.zoom);if(((i=this.annotations)==null?void 0:i.length)<=0||!((r=this.annotations)==null?void 0:r.length))return;let h="",s=Number.MAX_SAFE_INTEGER;for(let l=0;l<this.annotations.length;l++){const a=this.annotations[l];switch(a.type){case"rect":{const d=a.annotation;if(RectUtils.isInRect(c,d,newScope,this.zoom)){const u=d.width*d.height;u<s&&(h=d.id,s=u)}break}case"polygon":{const d=a.annotation;if(PolygonUtils.isInPolygon(n,d.pointList)){const u=PolygonUtils.getPolygonArea(d.pointList);u<s&&(h=d.id,s=u)}break}}}return h};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,o;this.connectPointsStatus&&((o=(e=this.connectPointsStatus).close)==null||o.call(e)),this.emit("connectionPointsStatusUpdate",()=>new Promise(i=>{const{promise:r,close:c}=MathUtils.default.getCollectionPointByAnnotationDataPromise(t);this.connectPointsStatus={close:c},r.then(n=>{this.connectionPoints=n.connectionPoints,this.render(),this.connectPointsStatus=void 0,i({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 o=[];e&&(o=[e]),this.emit("onChange","selected",o),this.render()}}onMouseMove(t){if(super.onMouseMove(t)||this.forbidMouseOperation||!this.imgInfo)return;const e=this.mouseHoverID,o=this.getHoverRectID(t);if(e!==o){this.mouseHoverID=o;let i=[];o&&(i=[o]),this.emit("onChange","hover",i),this.render()}}updateData(t){this.annotations=t,this.render()}getSpecificStyle(t){const e=___default.default.pick(t,["stroke","thickness","fill","radius"]),o=__spreadValues(__spreadValues({},this.style),e);return o.stroke&&Object.assign(o,{color:o.stroke}),o}getFontStyle(t,e){var o,i;const r=(o=t==null?void 0:t.fontSize)!=null?o:14,c=(i=t==null?void 0:t.fontFamily)!=null?i:"Arial";return __spreadProps(__spreadValues({},annotation.DEFAULT_TEXT_SHADOW),{color:e.stroke,font:`normal normal 600 ${r}px ${c}`})}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 o="",i="";return!t||e===!0?{headerText:o,bottomText:i}:((t==null?void 0:t.order)&&(o=`${t.order}`),(t==null?void 0:t.label)&&(o?o=`${o}_${t.label}`:o=`${t.label}`),(t==null?void 0:t.attribute)&&(o?o=`${o} ${t.attribute}`:o=`${t.attribute}`),(t==null?void 0:t.textAttribute)&&(i=t==null?void 0:t.textAttribute),{headerText:o,bottomText:i})}getReferenceOptions(t){return t?{lineCap:"butt",lineDash:[20,20]}:{}}focusPositionByPointList(t){const e=MathUtils.default.calcViewportBoundaries(t),o={x:e.left,y:e.top,width:e.right-e.left,height:e.bottom-e.top},i=ImgPosUtils.getBasicRecPos(this.imgNode,o,this.size,.5);if(i){this.setCurrentPos(i.currentPos),this.setCurrentPosStorage(i.currentPos);const{imgInfo:r}=this,{innerZoom:c}=this.innerPosAndZoom;r&&this.setImgInfo(__spreadProps(__spreadValues({},r),{width:r.width/c*i.innerZoom,height:r.height/c*i.innerZoom})),this.setZoom(i.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),o=this.getFontStyle(t.annotation,e);return{style:e,fontStyle:o}}renderLine(t){var e,o,i;if(t.type!=="line")return;const{style:r,fontStyle:c}=this.getRenderStyle(t),n=t.annotation;if(!(((e=n==null?void 0:n.pointList)==null?void 0:e.length)>=2))return;const{lineType:h=tool.ELineTypes.Line}=n,s=AxisUtils.default.changePointListByZoom((o=n==null?void 0:n.pointList)!=null?o:[],this.zoom,this.currentPos),l=__spreadProps(__spreadValues(__spreadValues({},r),this.getReferenceOptions(n==null?void 0:n.isReference)),{lineType:h,strokeColor:r.stroke});let a=[];if(n.showKeyPoint?a=DrawUtils.drawPolygonWithKeyPoint(this.canvas,s,l):a=DrawUtils.drawPolygon(this.canvas,s,l),(n==null?void 0:n.showDirection)===!0&&((i=n==null?void 0:n.pointList)==null?void 0:i.length)>=2){let g=s[0],y=MathUtils.default.getLineCenterPoint([s[0],s[1]]);if(h===tool.ELineTypes.Curve){const f=Math.floor(tool.SEGMENT_NUMBER/2);g=a[f],y=a[f+1]}DrawUtils.drawArrowByCanvas(this.canvas,g,y,{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:p}=this.getRenderText(n,n==null?void 0:n.hiddenText);if(u&&DrawUtils.drawText(this.canvas,this.appendOffset(s[0]),u,c),p){const g=s[s.length-1];DrawUtils.drawText(this.canvas,this.appendOffset({x:g.x+annotation.TEXT_ATTRIBUTE_OFFSET.x,y:g.y+annotation.TEXT_ATTRIBUTE_OFFSET.y}),p,c)}}renderPolygon(t){var e,o,i,r,c;if(t.type!=="polygon")return;const{style:n,fontStyle:h}=this.getRenderStyle(t),s=t.annotation;if(!(((e=s==null?void 0:s.pointList)==null?void 0:e.length)>=3))return;const{lineType:l=tool.ELineTypes.Line}=s,a=AxisUtils.default.changePointListByZoom((o=s==null?void 0:s.pointList)!=null?o:[],this.zoom,this.currentPos);if(s.id===this.mouseHoverID||n.fill){const f=rgba__default.default((r=(i=n==null?void 0:n.fill)!=null?i:n==null?void 0:n.stroke)!=null?r:DEFAULT_STROKE_COLOR),T=`rgba(${f[0]}, ${f[1]}, ${f[2]},${f[3]*.8})`;DrawUtils.drawPolygonWithFill(this.canvas,a,{color:T,lineType:l})}const d=__spreadProps(__spreadValues(__spreadProps(__spreadValues({},n),{isClose:!0}),this.getReferenceOptions(s==null?void 0:s.isReference)),{lineType:l,strokeColor:n.stroke});let u=[];if(s.showKeyPoint?u=DrawUtils.drawPolygonWithKeyPoint(this.canvas,a,d):u=DrawUtils.drawPolygon(this.canvas,a,d),(s==null?void 0:s.showDirection)===!0&&((c=s==null?void 0:s.pointList)==null?void 0:c.length)>=2){let f=a[0],T=MathUtils.default.getLineCenterPoint([a[0],a[1]]);if(l===tool.ELineTypes.Curve){const x=Math.floor(tool.SEGMENT_NUMBER/2);f=u[x],T=u[x+1]}DrawUtils.drawArrowByCanvas(this.canvas,f,T,{color:n.stroke,thickness:n.thickness}),DrawUtils.drawCircle(this.canvas,a[0],n.thickness+6,{color:n.stroke,thickness:n.thickness})}const{headerText:g,bottomText:y}=this.getRenderText(s,s==null?void 0:s.hiddenText);if(g&&DrawUtils.drawText(this.canvas,this.appendOffset(a[0]),g,h),y){const f=a[a.length-1];DrawUtils.drawText(this.canvas,this.appendOffset({x:f.x+annotation.TEXT_ATTRIBUTE_OFFSET.x,y:f.y+annotation.TEXT_ATTRIBUTE_OFFSET.y}),y,h)}}renderSingleCuboid(t){var e,o;const{style:i}=this.getRenderStyle(t),r=t.annotation,c=rgba__default.default((o=(e=i==null?void 0:i.fill)!=null?e:i==null?void 0:i.stroke)!=null?o:DEFAULT_STROKE_COLOR),n=`rgba(${c[0]}, ${c[1]}, ${c[2]},${c[3]*.8})`,h=i.stroke,s=AxisUtils.default.changeCuboidByZoom(r,this.zoom,this.currentPos),{headerText:l,bottomText:a}=this.getRenderText(r,r==null?void 0:r.hiddenText);DrawUtils.drawCuboidWithText(this.canvas,s,{strokeColor:h,fillColor:n,thickness:i.thickness},{config:this.config,hiddenText:r==null?void 0:r.hiddenText,currentPos:this.currentPos,zoom:this.zoom,headerText:l,bottomText:a})}renderBox3d(t){if(t.type!=="box3d")return;const e=t.annotation,o=matrix.pointCloudLidar2image(e,e.calib),i={fill:"transparent"},r=___default.default.pick(e,["stroke","thickness"]);o.forEach((c,n)=>{const h=__spreadValues(__spreadProps(__spreadValues({},r),{id:`${t.annotation.id}-${n}`,pointList:c.pointList}),i);switch(c.type){case"line":this.renderLine({type:"line",annotation:h});break;case"polygon":this.renderPolygon({type:"polygon",annotation:h});break}})}render(){try{if(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 o,i,r,c,n;const h=this.getSpecificStyle(e.annotation),s=this.getFontStyle(e.annotation,h);switch(e.type){case"rect":{const l=e.annotation,{hiddenText:a=!1,isReference:d,hiddenRectSize:u=!1}=l,{zoom:p}=this,g=AxisUtils.default.changeRectByZoom(l,this.zoom,this.currentPos),{x:y,y:f,width:T,height:x}=g;if(l.id===this.mouseHoverID||h.fill){const P=rgba__default.default((i=(o=h==null?void 0:h.fill)!=null?o:h==null?void 0:h.stroke)!=null?i:DEFAULT_STROKE_COLOR),b=`rgba(${P[0]}, ${P[1]}, ${P[2]},${P[3]*.8})`;DrawUtils.drawRectWithFill(this.canvas,g,{color:b})}DrawUtils.drawRect(this.canvas,g,__spreadValues(__spreadProps(__spreadValues({},h),{hiddenText:!0}),this.getReferenceOptions(d)));const{headerText:w,bottomText:S}=this.getRenderText(l,l==null?void 0:l.hiddenText);w&&DrawUtils.drawText(this.canvas,{x:y,y:f-6},w,__spreadValues({textMaxWidth:300},s));const m=`${Math.round(T/p)} * ${Math.round(x/p)}`,k=m.length*7;if(!a&&!u&&DrawUtils.drawText(this.canvas,{x:y+T-k,y:f+x+15},m,s),S){const P=20,b=Math.max(20,T-k);DrawUtils.drawText(this.canvas,{x:y,y:f+x+P},l.textAttribute,__spreadValues({textMaxWidth:b},s))}break}case"polygon":{this.renderPolygon(e);break}case"line":{this.renderLine(e);break}case"point":{const l=e.annotation,a=AxisUtils.default.changePointByZoom(l,this.zoom,this.currentPos),d=(r=h.radius)!=null?r:DEFAULT_RADIUS;DrawUtils.drawCircle(this.canvas,a,d,h);const{headerText:u,bottomText:p}=this.getRenderText(l,l==null?void 0:l.hiddenText);u&&DrawUtils.drawText(this.canvas,{x:a.x+d/2,y:a.y-d-4},u,__spreadValues({textAlign:"center"},s)),p&&DrawUtils.drawText(this.canvas,this.appendOffset({x:a.x+d,y:a.y+d+24}),p,s);break}case"text":{const l=e.annotation,{text:a,x:d,y:u,textMaxWidth:p,color:g="white",background:y="rgba(0, 0, 0, 0.6)",lineHeight:f=25,font:T=tool.DEFAULT_FONT,position:x}=l,w=10,S=10,m=AxisUtils.default.changePointByZoom({x:d,y:u},this.zoom,this.currentPos),{width:k,height:P,fontHeight:b=0}=MathUtils.default.getTextArea(this.canvas,l.text,p,T,f);if(x==="rt")break;DrawUtils.drawRectWithFill(this.canvas,{x:m.x,y:m.y,width:k+S*2,height:P+w*2,id:"",sourceID:"",valid:!0,textAttribute:"",attribute:""},{color:y}),DrawUtils.drawText(this.canvas,{x:m.x+S,y:m.y+b+w},a,{color:g,lineHeight:f,font:T,textMaxWidth:p});break}case"box3d":{this.renderBox3d(e);break}case"cuboid":{this.renderSingleCuboid(e);break}default:break}(n=(c=e.annotation)==null?void 0:c.renderEnhance)==null||n.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 +1 @@
|
|
|
1
|
-
"use strict";var CommonToolUtils=require("../../utils/tool/CommonToolUtils.js"),AxisUtils=require("../../utils/tool/AxisUtils.js"),uuid=require("../../utils/uuid.js"),CuboidUtils=require("../../utils/tool/CuboidUtils.js"),PolygonUtils=require("../../utils/tool/PolygonUtils.js"),annotation=require("../../constant/annotation.js"),AttributeUtils=require("../../utils/tool/AttributeUtils.js"),tool=require("../../constant/tool.js"),keyCode=require("../../constant/keyCode.js"),basicToolOperation=require("./basicToolOperation.js"),DrawUtils=require("../../utils/tool/DrawUtils.js"),cuboidToggleButtonClass=require("./cuboidToggleButtonClass.js"),textAttributeClass=require("./textAttributeClass.js"),index=require("../../locales/index.js"),constants=require("../../locales/constants.js"),__defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnPropDescs=Object.getOwnPropertyDescriptors,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(n,t,i)=>t in n?__defProp(n,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):n[t]=i,__spreadValues=(n,t)=>{for(var i in t||(t={}))__hasOwnProp.call(t,i)&&__defNormalProp(n,i,t[i]);if(__getOwnPropSymbols)for(var i of __getOwnPropSymbols(t))__propIsEnum.call(t,i)&&__defNormalProp(n,i,t[i]);return n},__spreadProps=(n,t)=>__defProps(n,__getOwnPropDescs(t)),EDrawingStatus;(function(n){n[n.Ready=1]="Ready",n[n.FirstPoint=2]="FirstPoint",n[n.Cuboid=3]="Cuboid"})(EDrawingStatus||(EDrawingStatus={}));const TEXT_MAX_WIDTH=164;class CuboidOperation extends basicToolOperation.BasicToolOperation{constructor(t){super(t);this.drawingStatus=1,this.cuboidList=[],this.hoverID="",this.getHoverData=i=>{const e=this.getCoordinateUnderZoom(i),{currentShowList:o}=this;if((o==null?void 0:o.length)>0){const r=o.map(d=>({id:d.id,pointList:AxisUtils.default.changePointListByZoom(CuboidUtils.getCuboidHoverRange(d),this.zoom)})),s=PolygonUtils.getHoverPolygonID(e,r);if(s)return{hoverID:s,hoverCuboid:o.find(d=>d.id===s)}}return{}},this.textChange=i=>{this.config.textConfigurable===!1||!this.selectedID||(this.setCuboidList(AttributeUtils.default.textChange(i,this.selectedID,this.cuboidList)),this.emit("selectedChange"),this.render())},this.config=CommonToolUtils.jsonParser(t.config),this.getCurrentSelectedData=this.getCurrentSelectedData.bind(this),this.updateSelectedTextAttribute=this.updateSelectedTextAttribute.bind(this)}destroy(){super.destroy(),this._textAttributeInstance&&this._textAttributeInstance.clearTextAttribute()}get currentShowList(){let t=[];const[i,e]=CommonToolUtils.getRenderResultList(this.cuboidList,CommonToolUtils.getSourceID(this.basicResult),this.attributeLockList,this.selectedID);return t=i,this.isHidden&&(t=[]),e&&t.push(e),t}get selectedCuboid(){return this.cuboidList.find(t=>t.id===this.selectedID)}get dataList(){return this.cuboidList}get isNeedCheckCuboidSize(){var t,i;return((t=this.config)==null?void 0:t.minWidth)>=0&&((i=this.config)==null?void 0:i.minHeight)>=0}getIsHoverSelectedCuboid(t){const i=this.getCoordinateUnderZoom(t),{selectedCuboid:e}=this;return e&&AxisUtils.default.isCloseCuboid(i,AxisUtils.default.changeCuboidByZoom(e,this.zoom))}isForbiddenMove(t,i){return this.getCoordinateInOrigin(t).y>i.frontPoints.br.y}updateSelectedCuboid(t){this.cuboidList=this.cuboidList.map(i=>i.id===this.selectedID?t:i)}getColorToRender(t,i){const e=this.getColor(t),o=i?e==null?void 0:e.valid.stroke:e==null?void 0:e.invalid.stroke,r=i?e==null?void 0:e.valid.fill:e==null?void 0:e.invalid.fill;return{strokeColor:o,toolColor:e,fillColor:r}}getCurrentSelectedData(){const{selectedCuboid:t}=this;if(!t)return;const{strokeColor:i}=this.getColorToRender(t.attribute,t.valid);return{width:TEXT_MAX_WIDTH,textAttribute:t.textAttribute,color:i}}updateSelectedTextAttribute(t){if(this._textAttributeInstance&&t&&this.selectedID){let i=t;AttributeUtils.default.textAttributeValidate(this.config.textCheckType,"",i)===!1&&(this.emit("messageError",AttributeUtils.default.getErrorNotice(this.config.textCheckType,this.lang)),i=""),this.setCuboidList(AttributeUtils.default.textChange(i,this.selectedID,this.cuboidList)),this.history.pushHistory(this.cuboidList),this.emit("updateTextAttribute"),this.render()}}setResult(t){this.clearDrawingStatus(),this.setCuboidList(t),this.render()}get currentPageResult(){return this.cuboidList}clearResult(){this.setCuboidList([],!0),this.setSelectedID(void 0)}exportData(){const{cuboidList:t}=this;return[t,this.basicImgInfo]}setSelectedID(t){var i,e;const o=this.selectedID;t!==o&&o&&((i=this._textAttributeInstance)==null||i.changeSelected()),t||(e=this._textAttributeInstance)==null||e.clearTextAttribute(),this.selectedID=t,this.emit("selectedChange")}setSelectedIDAndRender(t){this.setSelectedID(t),this.render()}setCuboidValidAndRender(t){if(!t)return;const i=this.cuboidList.map(e=>e.id===t?__spreadProps(__spreadValues({},e),{valid:!e.valid}):e);this.setCuboidList(i,!0),this.history.pushHistory(this.cuboidList),this.render()}onRightDblClick(t){super.onRightDblClick(t);const{hoverID:i}=this.getHoverData(t);this.selectedID&&this.selectedID===i&&this.deleteCuboid(i)}setCuboidList(t,i=!1){const e=this.cuboidList.length;this.cuboidList=t,e!==t.length&&this.emit("updatePageNumber"),i&&this.emit("updateResult")}deleteCuboid(t){var i;!t||(this.setCuboidList(this.cuboidList.filter(e=>e.id!==t)),this.history.pushHistory(this.cuboidList),this.setSelectedID(""),(i=this._textAttributeInstance)==null||i.clearTextAttribute(),this.render())}onKeyDown(t){if(!CommonToolUtils.hotkeyFilter(t)||super.onKeyDown(t)===!1)return;const{keyCode:i}=t;switch(i){case keyCode.Ctrl:this.drawingCuboid&&(this.drawingCuboid=__spreadProps(__spreadValues({},this.drawingCuboid),{valid:!1}),this.render());break;case keyCode.F:this.selectedID&&this.setCuboidValidAndRender(this.selectedID);break;default:if(this.config.attributeConfigurable){const e=AttributeUtils.default.getAttributeByKeycode(i,this.config.attributeList);e!==void 0&&this.setDefaultAttribute(e)}}}onKeyUp(t){switch(super.onKeyUp(t),t.keyCode){case keyCode.Ctrl:this.drawingCuboid&&(this.drawingCuboid=__spreadProps(__spreadValues({},this.drawingCuboid),{valid:!0}),this.render());break}}onMouseDown(t){if(super.onMouseDown(t)||this.forbidMouseOperation||t.ctrlKey===!0)return;const{selectedCuboid:i}=this;if(!i||t.button===2||t.button===0&&this.isSpaceKey===!0||!this.getIsHoverSelectedCuboid(t))return;this.dragStatus=annotation.EDragStatus.Start;const e=this.getCoordinateUnderZoom(t),o={initCuboid:i,dragStartCoord:e},r=AxisUtils.default.returnClosePointOrLineInCuboid(e,AxisUtils.default.changeCuboidByZoom(i,this.zoom)),s=r==null?void 0:r[0];switch(s==null?void 0:s.type){case"point":this.dragInfo=__spreadProps(__spreadValues({},o),{dragTarget:annotation.EDragTarget.Point,positions:s.positions});break;case"line":this.dragInfo=__spreadProps(__spreadValues({},o),{dragTarget:annotation.EDragTarget.Line,positions:s.positions});break;default:this.dragInfo=__spreadProps(__spreadValues({},o),{dragTarget:annotation.EDragTarget.Cuboid})}}onMouseUp(t){if(super.onMouseUp(t)||this.forbidMouseOperation||!this.imgInfo)return;if(this.dragInfo&&this.dragStatus===annotation.EDragStatus.Move){this.dragInfo=void 0,this.dragStatus=annotation.EDragStatus.Wait,this.history.pushHistory(this.cuboidList),this.emit("updateResult");return}const i=CommonToolUtils.getSourceID(this.basicResult);if(t.button===0){if(this.hoverID&&t.ctrlKey&&!this.drawingCuboid){this.setCuboidValidAndRender(this.hoverID);return}if(!this.drawingCuboid){this.createNewDrawingCuboid(t,i);return}if(this.drawingCuboid)switch(this.drawingStatus){case 2:this.closeNewDrawingFrontPlane();break;case 3:this.closeAndCreateNewCuboid();break}}t.button===2&&this.rightMouseUp(t)}onMouseMove(t){var i;if(!(super.onMouseMove(t)||this.forbidMouseOperation||!this.imgInfo)){if(this.selectedID&&this.dragInfo){this.onDragMove(t);return}if(this.drawingCuboid){if(this.drawingFrontPlanesMove(t))return;this.drawingBackPlaneMove(t);return}this.hoverID=(i=this.getHoverData(t).hoverID)!=null?i:"",this.onHoverMove(t)}}drawingFrontPlanesMove(t){if(this.drawingCuboid&&this.firstClickCoord&&this.drawingStatus===2){const i=this.getCoordinateInOrigin(t);return this.drawingCuboid=__spreadProps(__spreadValues({},this.drawingCuboid),{frontPoints:CuboidUtils.getPlainPointsByDiagonalPoints(this.firstClickCoord,i)}),this.render(),!0}}drawingBackPlaneMove(t){if(this.drawingCuboid&&this.firstClickCoord&&this.drawingStatus===3){const i=this.getCoordinateInOrigin(t);if(this.isForbiddenMove(t,this.drawingCuboid))return;this.drawingCuboid=__spreadProps(__spreadValues({},this.drawingCuboid),{backPoints:CuboidUtils.getPointsByBottomRightPoint({coord:i,points:this.drawingCuboid.frontPoints})}),this.render()}}onDragMove(t){if(!this.dragInfo||!this.selectedID)return;const{dragTarget:i,initCuboid:e,dragStartCoord:o,positions:r}=this.dragInfo,s=this.getCoordinateUnderZoom(t),d={x:(s.x-o.x)/this.zoom,y:(s.y-o.y)/this.zoom};this.dragStatus=annotation.EDragStatus.Move;const u=CuboidUtils.getCuboidDragMove({offset:d,cuboid:e,dragTarget:i,positions:r});(u==null?void 0:u.backPoints)&&(u==null?void 0:u.backPoints.br.y)>(u==null?void 0:u.frontPoints.br.y)||(u&&this.updateSelectedCuboid(u),this.render())}onHoverMove(t){const{selectedCuboid:i}=this;if(i){const e=this.getCoordinateUnderZoom(t),o=AxisUtils.default.returnClosePointOrLineInCuboid(e,AxisUtils.default.changeCuboidByZoom(i,this.zoom),{zoom:1/this.zoom,scope:5});this.highlightInfo=o,this.render()}}createNewDrawingCuboid(t,i){if(!this.imgInfo)return;const e=this.getCoordinateInOrigin(t);this.drawingCuboid={attribute:this.defaultAttribute,direction:annotation.ECuboidDirection.Front,valid:!t.ctrlKey,id:uuid(8,62),sourceID:i,textAttribute:"",order:CommonToolUtils.getMaxOrder(this.cuboidList.filter(o=>CommonToolUtils.isSameSourceID(o.sourceID,i)))+1,frontPoints:{tl:e,bl:e,tr:e,br:e}},this.firstClickCoord=__spreadValues({},e),this.drawingStatus=2}closeNewDrawingFrontPlane(){this.drawingStatus=3}closeAndCreateNewCuboid(){var t,i;!((t=this.drawingCuboid)==null?void 0:t.frontPoints)||!this.drawingCuboid.backPoints||(this.isNeedCheckCuboidSize&&CuboidUtils.isCuboidWithInLimits({cuboid:this.drawingCuboid,config:this.config})===!1?this.emit("messageInfo",index.getMessagesByLocale(constants.EMessage.RectErrorSizeNotice,this.lang)):(this.setCuboidList([...this.cuboidList,this.drawingCuboid]),this.setSelectedID((i=this.drawingCuboid)==null?void 0:i.id),this.history.pushHistory(this.cuboidList)),this.clearDrawingStatus(),this.render())}clearDrawingStatus(){this.drawingCuboid&&(this.drawingCuboid=void 0,this.drawingStatus=1)}rightMouseUp(t){const{hoverID:i,hoverCuboid:e}=this.getHoverData(t);this.setSelectedID(i),e&&this.setDefaultAttribute(e.attribute),this.drawingCuboid&&this.clearDrawingStatus(),this.render()}renderSingleCuboid(t){var i,e,o,r;const s=AxisUtils.default.changeCuboidByZoom(t,this.zoom,this.currentPos),d=s.id===this.hoverID,u=s.id===this.selectedID,{strokeColor:a,fillColor:I}=this.getColorToRender(s.attribute,s.valid),w=a,g=(e=(i=this.style)==null?void 0:i.width)!=null?e:2,{hiddenText:f=!1}=this.style,D={color:a,thickness:g},{backPoints:c,frontPoints:C,textAttribute:v}=s,x=C.br.x-C.bl.x;if(DrawUtils.drawCuboid(this.canvas,s,{strokeColor:a,fillColor:I,thickness:g}),d||u){const l=CuboidUtils.getHighlightPoints(s);l.forEach(b=>{DrawUtils.drawCircleWithFill(this.canvas,b.point,5,__spreadValues({},D))}),u&&l.forEach(b=>{DrawUtils.drawCircleWithFill(this.canvas,b.point,3,{color:"white"})})}let h="";((o=this.config)==null?void 0:o.isShowOrder)&&s.order&&(s==null?void 0:s.order)>0&&(h=`${s.order}`),s.attribute&&(h=`${h} ${AttributeUtils.default.getAttributeShowText(s.attribute,(r=this.config)==null?void 0:r.attributeList)}`),!f&&c&&DrawUtils.drawText(this.canvas,{x:c.tl.x,y:c.tl.y-5},h,{color:a,textMaxWidth:300});const p=CuboidUtils.getCuboidTextAttributeOffset({cuboid:t,currentPos:this.currentPos,zoom:this.zoom,topOffset:16,leftOffset:0});if(!f&&v&&t.id!==this.selectedID){const l=Math.max(20,x*.8);DrawUtils.drawText(this.canvas,{x:p.left,y:p.top},v,{color:w,textMaxWidth:l})}this.renderTextAttribute()}setDefaultAttribute(t){const i=this.defaultAttribute;if(this.defaultAttribute=t!=null?t:"",i!==t){this.changeStyle(t),this.emit("changeAttributeSidebar");const{selectedCuboid:e}=this;if(e&&(this.setCuboidList(this.cuboidList.map(o=>o.id===this.selectedID?__spreadProps(__spreadValues({},o),{attribute:this.defaultAttribute}):o)),this.history.pushHistory(this.cuboidList),this.render()),this.drawingCuboid&&(this.drawingCuboid=__spreadProps(__spreadValues({},this.drawingCuboid),{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))}}}renderToggleButton(){const{selectedCuboid:t}=this;if(!this.ctx||this.config.textConfigurable!==!0||!t)return;const{attribute:i,valid:e}=t,{strokeColor:o}=this.getColorToRender(i,e);this.toggleButtonInstance||(this.toggleButtonInstance=new cuboidToggleButtonClass({container:this.container,cuboidButtonMove:s=>this.updateMouseOperation(s),toggleDirection:s=>this.toggleDirection(s)}));const r=CuboidUtils.getToggleDirectionButtonOffset({cuboid:t,zoom:this.zoom,currentPos:this.currentPos});this.toggleButtonInstance.update({left:r.left,top:r.top,color:o})}renderTextAttribute(){var t;const{selectedCuboid:i}=this;if(!this.ctx||this.config.textConfigurable===!1||!i)return;const{strokeColor:e}=this.getColorToRender(i.attribute,i.valid),{attribute:o,textAttribute:r,frontPoints:s}=i,d=CuboidUtils.getCuboidTextAttributeOffset({cuboid:i,currentPos:this.currentPos,zoom:this.zoom}),u=(s.br.x-s.bl.x)*this.zoom*.8;this._textAttributeInstance||(this._textAttributeInstance=new textAttributeClass({width:tool.DEFAULT_TEXT_MAX_WIDTH,container:this.container,icon:this.getTextIconSvg(o),color:e,getCurrentSelectedData:this.getCurrentSelectedData,updateSelectedTextAttribute:this.updateSelectedTextAttribute})),this._textAttributeInstance&&!((t=this._textAttributeInstance)==null?void 0:t.isExit)&&this._textAttributeInstance.appendToContainer(),this._textAttributeInstance.update(`${r}`,{left:d.left,top:d.top,color:e,width:u})}renderDrawing(){this.drawingCuboid&&this.renderSingleCuboid(this.drawingCuboid)}renderStatic(){this.cuboidList.forEach(t=>this.renderSingleCuboid(t))}renderSelected(){var t;const{selectedCuboid:i}=this;i?(this.renderSingleCuboid(i),this.renderToggleButton()):((t=this.toggleButtonInstance)==null||t.clearCuboidButtonDOM(),this.toggleButtonInstance=void 0)}updateMouseOperation(t){t==="in"?(this.setForbidCursorLine(!0),this.setForbidOperation(!0),this.setShowDefaultCursor(!0)):(this.setForbidCursorLine(!1),this.setShowDefaultCursor(!1),this.setForbidOperation(!1))}toggleDirection(t){this.cuboidList&&this.selectedCuboid&&(this.setCuboidList(this.cuboidList.map(i=>{var e;return i.id===((e=this.selectedCuboid)==null?void 0:e.id)?__spreadProps(__spreadValues({},i),{direction:t}):i})),this.history.pushHistory(this.cuboidList),this.render())}renderHover(){var t;this.dragInfo||(t=this.highlightInfo)==null||t.forEach(i=>{var e,o;const{strokeColor:r}=this.getColorToRender(i.originCuboid.attribute,i.originCuboid.valid),s=8;switch(i.type){case"point":(e=i.points)==null||e.forEach(d=>{DrawUtils.drawCircleWithFill(this.canvas,AxisUtils.default.changePointByZoom(d,this.zoom,this.currentPos),s,{color:r})});break;case"line":{const d=(o=i.points)==null?void 0:o.map(u=>AxisUtils.default.changePointByZoom(u,this.zoom,this.currentPos));d&&DrawUtils.drawLineWithPointList(this.canvas,d,{color:r,thickness:s});break}}})}renderCuboid(){this.renderStatic(),this.renderDrawing(),this.renderSelected(),this.renderHover()}render(){!this.ctx||(super.render(),this.renderCuboid(),this.renderCursorLine(this.getLineColor(this.defaultAttribute)))}undo(){const t=this.history.undo();t&&(t.length!==this.cuboidList.length&&this.setSelectedID(""),this.setCuboidList(t,!0),this.render())}redo(){const t=this.history.redo();t&&(t.length!==this.cuboidList.length&&this.setSelectedID(""),this.setCuboidList(t,!0),this.render())}}module.exports=CuboidOperation;
|
|
1
|
+
"use strict";var CommonToolUtils=require("../../utils/tool/CommonToolUtils.js"),AxisUtils=require("../../utils/tool/AxisUtils.js"),uuid=require("../../utils/uuid.js"),CuboidUtils=require("../../utils/tool/CuboidUtils.js"),PolygonUtils=require("../../utils/tool/PolygonUtils.js"),annotation=require("../../constant/annotation.js"),AttributeUtils=require("../../utils/tool/AttributeUtils.js"),tool=require("../../constant/tool.js"),keyCode=require("../../constant/keyCode.js"),basicToolOperation=require("./basicToolOperation.js"),DrawUtils=require("../../utils/tool/DrawUtils.js"),cuboidToggleButtonClass=require("./cuboidToggleButtonClass.js"),textAttributeClass=require("./textAttributeClass.js"),index=require("../../locales/index.js"),constants=require("../../locales/constants.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)),EDrawingStatus;(function(u){u[u.Ready=1]="Ready",u[u.FirstPoint=2]="FirstPoint",u[u.Cuboid=3]="Cuboid"})(EDrawingStatus||(EDrawingStatus={}));const TEXT_MAX_WIDTH=164;class CuboidOperation extends basicToolOperation.BasicToolOperation{constructor(t){super(t);this.drawingStatus=1,this.cuboidList=[],this.hoverID="",this.getHoverData=i=>{const e=this.getCoordinateUnderZoom(i),{currentShowList:s}=this;if((s==null?void 0:s.length)>0){const o=s.map(n=>({id:n.id,pointList:AxisUtils.default.changePointListByZoom(CuboidUtils.getCuboidHoverRange(n),this.zoom)})),r=PolygonUtils.getHoverPolygonID(e,o);if(r)return{hoverID:r,hoverCuboid:s.find(n=>n.id===r)}}return{}},this.textChange=i=>{this.config.textConfigurable===!1||!this.selectedID||(this.setCuboidList(AttributeUtils.default.textChange(i,this.selectedID,this.cuboidList)),this.emit("selectedChange"),this.render())},this.config=CommonToolUtils.jsonParser(t.config),this.getCurrentSelectedData=this.getCurrentSelectedData.bind(this),this.updateSelectedTextAttribute=this.updateSelectedTextAttribute.bind(this)}get selectedText(){var t,i;return(i=(t=this.selectedCuboid)==null?void 0:t.textAttribute)!=null?i:""}destroy(){super.destroy(),this._textAttributeInstance&&this._textAttributeInstance.clearTextAttribute()}get currentShowList(){let t=[];const[i,e]=CommonToolUtils.getRenderResultList(this.cuboidList,CommonToolUtils.getSourceID(this.basicResult),this.attributeLockList,this.selectedID);return t=i,this.isHidden&&(t=[]),e&&t.push(e),t}get selectedCuboid(){return this.cuboidList.find(t=>t.id===this.selectedID)}get dataList(){return this.cuboidList}get isNeedCheckCuboidSize(){var t,i;return((t=this.config)==null?void 0:t.minWidth)>=0&&((i=this.config)==null?void 0:i.minHeight)>=0}getIsHoverSelectedCuboid(t){const i=this.getCoordinateUnderZoom(t),{selectedCuboid:e}=this;return e&&AxisUtils.default.isCloseCuboid(i,AxisUtils.default.changeCuboidByZoom(e,this.zoom))}isForbiddenMove(t,i){return this.getCoordinateInOrigin(t).y>i.frontPoints.br.y}updateSelectedCuboid(t){this.cuboidList=this.cuboidList.map(i=>i.id===this.selectedID?t:i)}getStylesToRender(t,i){var e,s;const o=this.getColor(t),r=i?o==null?void 0:o.valid.stroke:o==null?void 0:o.invalid.stroke,n=i?o==null?void 0:o.valid.fill:o==null?void 0:o.invalid.fill,d=(s=(e=this.style)==null?void 0:e.width)!=null?s:2;return{strokeColor:r,toolColor:o,fillColor:n,lineWidth:d}}getCurrentSelectedData(){const{selectedCuboid:t}=this;if(!t)return;const{strokeColor:i}=this.getStylesToRender(t.attribute,t.valid);return{width:TEXT_MAX_WIDTH,textAttribute:t.textAttribute,color:i}}updateSelectedTextAttribute(t){if(this._textAttributeInstance&&t&&this.selectedID){let i=t;AttributeUtils.default.textAttributeValidate(this.config.textCheckType,"",i)===!1&&(this.emit("messageError",AttributeUtils.default.getErrorNotice(this.config.textCheckType,this.lang)),i=""),this.setCuboidList(AttributeUtils.default.textChange(i,this.selectedID,this.cuboidList)),this.history.pushHistory(this.cuboidList),this.emit("updateTextAttribute"),this.render()}}setResult(t){this.clearActiveStatus(),this.setCuboidList(t),this.render()}get currentPageResult(){return this.cuboidList}clearResult(){this.setCuboidList([],!0),this.deleteSelectedID(),this.render()}exportData(){const{cuboidList:t}=this;return[t,this.basicImgInfo]}setSelectedID(t){var i,e;const s=this.selectedID;t!==s&&s&&((i=this._textAttributeInstance)==null||i.changeSelected()),t||(e=this._textAttributeInstance)==null||e.clearTextAttribute(),this.selectedID=t,this.emit("selectedChange")}setSelectedIDAndRender(t){this.setSelectedID(t),this.render()}setCuboidValidAndRender(t){if(!t)return;const i=this.cuboidList.map(e=>e.id===t?__spreadProps(__spreadValues({},e),{valid:!e.valid}):e);this.setCuboidList(i,!0),this.history.pushHistory(this.cuboidList),this.render()}onRightDblClick(t){super.onRightDblClick(t);const{hoverID:i}=this.getHoverData(t);this.selectedID&&this.selectedID===i&&this.deleteCuboid(i)}setCuboidList(t,i=!1){const e=this.cuboidList.length;this.cuboidList=t,e!==t.length&&this.emit("updatePageNumber"),i&&this.emit("updateResult")}deleteCuboid(t){var i;!t||(this.setCuboidList(this.cuboidList.filter(e=>e.id!==t)),this.history.pushHistory(this.cuboidList),this.setSelectedID(""),(i=this._textAttributeInstance)==null||i.clearTextAttribute(),this.render())}onKeyDown(t){if(!CommonToolUtils.hotkeyFilter(t)||super.onKeyDown(t)===!1)return;const{keyCode:i}=t;switch(i){case keyCode.Ctrl:this.drawingCuboid&&(this.drawingCuboid=__spreadProps(__spreadValues({},this.drawingCuboid),{valid:!1}),this.render());break;case keyCode.Delete:this.selectedID&&this.deleteCuboid(this.selectedID);break;case keyCode.Z:this.setIsHidden(!this.isHidden),this.render();break;case keyCode.F:this.selectedID&&this.setCuboidValidAndRender(this.selectedID);break;default:if(this.config.attributeConfigurable){const e=AttributeUtils.default.getAttributeByKeycode(i,this.config.attributeList);e!==void 0&&this.setDefaultAttribute(e)}}}onKeyUp(t){switch(super.onKeyUp(t),t.keyCode){case keyCode.Ctrl:this.drawingCuboid&&(this.drawingCuboid=__spreadProps(__spreadValues({},this.drawingCuboid),{valid:!0}),this.render());break}}onMouseDown(t){if(super.onMouseDown(t)||this.forbidMouseOperation||t.ctrlKey===!0)return;const{selectedCuboid:i}=this;if(!i||t.button===2||t.button===0&&this.isSpaceKey===!0||!this.getIsHoverSelectedCuboid(t))return;this.dragStatus=annotation.EDragStatus.Start;const e=this.getCoordinateUnderZoom(t),s={initCuboid:i,dragStartCoord:e},o=AxisUtils.default.returnClosePointOrLineInCuboid(e,AxisUtils.default.changeCuboidByZoom(i,this.zoom)),r=o==null?void 0:o[0];switch(r==null?void 0:r.type){case"point":this.dragInfo=__spreadProps(__spreadValues({},s),{dragTarget:annotation.EDragTarget.Point,positions:r.positions});break;case"line":this.dragInfo=__spreadProps(__spreadValues({},s),{dragTarget:annotation.EDragTarget.Line,positions:r.positions});break;default:this.dragInfo=__spreadProps(__spreadValues({},s),{dragTarget:annotation.EDragTarget.Cuboid})}}onMouseUp(t){if(super.onMouseUp(t)||this.forbidMouseOperation||!this.imgInfo)return;if(this.dragInfo&&this.dragStatus===annotation.EDragStatus.Move){this.dragInfo=void 0,this.dragStatus=annotation.EDragStatus.Wait,this.history.pushHistory(this.cuboidList),this.emit("updateResult");return}const i=CommonToolUtils.getSourceID(this.basicResult);if(t.button===0){if(this.hoverID&&t.ctrlKey&&!this.drawingCuboid){this.setCuboidValidAndRender(this.hoverID);return}if(!this.drawingCuboid){this.createNewDrawingCuboid(t,i);return}if(this.drawingCuboid)switch(this.drawingStatus){case 2:this.closeNewDrawingFrontPlane();break;case 3:this.closeAndCreateNewCuboid();break}}t.button===2&&this.rightMouseUp(t)}onMouseMove(t){var i;if(!(super.onMouseMove(t)||this.forbidMouseOperation||!this.imgInfo)){if(this.selectedID&&this.dragInfo){this.onDragMove(t);return}if(this.drawingCuboid){if(this.drawingFrontPlanesMove(t))return;this.drawingBackPlaneMove(t);return}this.hoverID=(i=this.getHoverData(t).hoverID)!=null?i:"",this.onHoverMove(t)}}drawingFrontPlanesMove(t){if(this.drawingCuboid&&this.firstClickCoord&&this.drawingStatus===2){const i=this.getCoordinateInOrigin(t);return this.drawingCuboid=__spreadProps(__spreadValues({},this.drawingCuboid),{frontPoints:CuboidUtils.getPlainPointsByDiagonalPoints(this.firstClickCoord,i)}),this.render(),!0}}drawingBackPlaneMove(t){if(this.drawingCuboid&&this.firstClickCoord&&this.drawingStatus===3){const i=this.getCoordinateInOrigin(t);if(this.isForbiddenMove(t,this.drawingCuboid))return;this.drawingCuboid=__spreadProps(__spreadValues({},this.drawingCuboid),{backPoints:CuboidUtils.getPointsByBottomRightPoint({coord:i,points:this.drawingCuboid.frontPoints})}),this.render()}}onDragMove(t){if(!this.dragInfo||!this.selectedID)return;const{dragTarget:i,initCuboid:e,dragStartCoord:s,positions:o}=this.dragInfo,r=this.getCoordinateUnderZoom(t),n={x:(r.x-s.x)/this.zoom,y:(r.y-s.y)/this.zoom};this.dragStatus=annotation.EDragStatus.Move;const d=CuboidUtils.getCuboidDragMove({offset:n,cuboid:e,dragTarget:i,positions:o});(d==null?void 0:d.backPoints)&&(d==null?void 0:d.backPoints.br.y)>(d==null?void 0:d.frontPoints.br.y)||(d&&this.updateSelectedCuboid(d),this.render())}onHoverMove(t){const{selectedCuboid:i}=this;if(i){const e=this.getCoordinateUnderZoom(t),s=AxisUtils.default.returnClosePointOrLineInCuboid(e,AxisUtils.default.changeCuboidByZoom(i,this.zoom),{zoom:1/this.zoom,scope:5});this.highlightInfo=s,this.render()}}createNewDrawingCuboid(t,i){if(!this.imgInfo)return;const e=this.getCoordinateInOrigin(t);if(this.drawingCuboid={attribute:this.defaultAttribute,direction:annotation.ECuboidDirection.Front,valid:!t.ctrlKey,id:uuid(8,62),sourceID:i,textAttribute:"",order:CommonToolUtils.getMaxOrder(this.cuboidList.filter(s=>CommonToolUtils.isSameSourceID(s.sourceID,i)))+1,frontPoints:{tl:e,bl:e,tr:e,br:e}},this.firstClickCoord=__spreadValues({},e),this.drawingStatus=2,this.config.textConfigurable){let s="";s=AttributeUtils.default.getTextAttribute(this.cuboidList.filter(o=>CommonToolUtils.isSameSourceID(o.sourceID,i)),this.config.textCheckType),this.drawingCuboid=__spreadProps(__spreadValues({},this.drawingCuboid),{textAttribute:s})}}closeNewDrawingFrontPlane(){this.drawingStatus=3}closeAndCreateNewCuboid(){var t,i;!((t=this.drawingCuboid)==null?void 0:t.frontPoints)||!this.drawingCuboid.backPoints||(this.isNeedCheckCuboidSize&&CuboidUtils.isCuboidWithInLimits({cuboid:this.drawingCuboid,config:this.config})===!1?this.emit("messageInfo",index.getMessagesByLocale(constants.EMessage.RectErrorSizeNotice,this.lang)):(this.setCuboidList([...this.cuboidList,this.drawingCuboid]),this.setSelectedID((i=this.drawingCuboid)==null?void 0:i.id),this.history.pushHistory(this.cuboidList)),this.clearDrawingStatus(),this.render())}deleteSelectedID(){this.setSelectedID("")}clearDrawingStatus(){this.drawingCuboid&&(this.drawingCuboid=void 0,this.drawingStatus=1)}clearActiveStatus(){this.clearDrawingStatus(),this.deleteSelectedID()}rightMouseUp(t){const{hoverID:i,hoverCuboid:e}=this.getHoverData(t);this.setSelectedID(i),e&&this.setDefaultAttribute(e.attribute),this.drawingCuboid&&this.clearDrawingStatus(),this.render()}renderHighlightCuboidCom(t){const i=AxisUtils.default.changeCuboidByZoom(t,this.zoom,this.currentPos),e=i.id===this.hoverID,s=i.id===this.selectedID,{strokeColor:o,lineWidth:r}=this.getStylesToRender(i.attribute,i.valid),n={color:o,thickness:r};if(e||s){const d=CuboidUtils.getHighlightPoints(i);d.forEach(a=>{DrawUtils.drawCircleWithFill(this.canvas,a.point,5,__spreadValues({},n))}),s&&(CuboidUtils.getHighlightLines(i).forEach(h=>{DrawUtils.drawLine(this.canvas,h.p1,h.p2,{color:o,thickness:r+2})}),d.forEach(h=>{DrawUtils.drawCircleWithFill(this.canvas,h.point,3,{color:"white"})}))}}renderSingleCuboid(t){var i,e;const s=AxisUtils.default.changeCuboidByZoom(t,this.zoom,this.currentPos),{strokeColor:o,fillColor:r}=this.getStylesToRender(s.attribute,s.valid),n=(e=(i=this.style)==null?void 0:i.width)!=null?e:2,{hiddenText:d=!1}=this.style;DrawUtils.drawCuboidWithText(this.canvas,s,{strokeColor:o,fillColor:r,thickness:n},{config:this.config,hiddenText:d,currentPos:this.currentPos,zoom:this.zoom,selectedID:this.selectedID}),this.renderTextAttribute()}setDefaultAttribute(t){const i=this.defaultAttribute;if(this.defaultAttribute=t!=null?t:"",i!==t){this.changeStyle(t),this.emit("changeAttributeSidebar");const{selectedCuboid:e}=this;if(this._textAttributeInstance&&(this.attributeLockList.length>0&&!this.attributeLockList.includes(this.defaultAttribute)?this._textAttributeInstance.clearTextAttribute():this._textAttributeInstance.updateIcon(this.getTextIconSvg(t))),e){this.setCuboidList(this.cuboidList.map(s=>s.id===this.selectedID?__spreadProps(__spreadValues({},s),{attribute:this.defaultAttribute}):s)),this.history.pushHistory(this.cuboidList),this.render();return}this.drawingCuboid&&(this.drawingCuboid=__spreadProps(__spreadValues({},this.drawingCuboid),{attribute:this.defaultAttribute}),this.render())}}renderToggleButton(){const{selectedCuboid:t}=this;if(!this.ctx||!t)return;const{attribute:i,valid:e}=t,{strokeColor:s}=this.getStylesToRender(i,e);this.toggleButtonInstance||(this.toggleButtonInstance=new cuboidToggleButtonClass({container:this.container,cuboidButtonMove:r=>this.updateMouseOperation(r),toggleDirection:r=>this.toggleDirection(r)}));const o=CuboidUtils.getToggleDirectionButtonOffset({cuboid:t,zoom:this.zoom,currentPos:this.currentPos});this.toggleButtonInstance.update({left:o.left,top:o.top,color:s})}renderTextAttribute(){var t;const{selectedCuboid:i}=this;if(!this.ctx||this.config.textConfigurable===!1||!i)return;const{strokeColor:e}=this.getStylesToRender(i.attribute,i.valid),{attribute:s,textAttribute:o,frontPoints:r}=i,n=CuboidUtils.getCuboidTextAttributeOffset({cuboid:i,currentPos:this.currentPos,zoom:this.zoom}),d=(r.br.x-r.bl.x)*this.zoom*.8;this._textAttributeInstance||(this._textAttributeInstance=new textAttributeClass({width:tool.DEFAULT_TEXT_MAX_WIDTH,container:this.container,icon:this.getTextIconSvg(s),color:e,getCurrentSelectedData:this.getCurrentSelectedData,updateSelectedTextAttribute:this.updateSelectedTextAttribute})),this._textAttributeInstance&&!((t=this._textAttributeInstance)==null?void 0:t.isExit)&&this._textAttributeInstance.appendToContainer(),this._textAttributeInstance.update(`${o}`,{left:n.left,top:n.top,color:e,width:d})}renderDrawing(){this.drawingCuboid&&this.renderSingleCuboid(this.drawingCuboid)}renderStatic(){this.isHidden||this.currentShowList.forEach(t=>this.renderSingleCuboid(t))}renderSelected(){var t;const{selectedCuboid:i}=this;i?(this.renderSingleCuboid(i),this.renderHighlightCuboidCom(i),this.renderToggleButton()):((t=this.toggleButtonInstance)==null||t.clearCuboidButtonDOM(),this.toggleButtonInstance=void 0)}updateMouseOperation(t){t==="in"?(this.setForbidCursorLine(!0),this.setForbidOperation(!0),this.setShowDefaultCursor(!0)):(this.setForbidCursorLine(!1),this.setShowDefaultCursor(!1),this.setForbidOperation(!1))}toggleDirection(t){this.cuboidList&&this.selectedCuboid&&(this.setCuboidList(this.cuboidList.map(i=>{var e;return i.id===((e=this.selectedCuboid)==null?void 0:e.id)?__spreadProps(__spreadValues({},i),{direction:t}):i})),this.history.pushHistory(this.cuboidList),this.render())}renderHover(){var t;this.dragInfo||(t=this.highlightInfo)==null||t.forEach(i=>{var e,s;const{strokeColor:o}=this.getStylesToRender(i.originCuboid.attribute,i.originCuboid.valid),r=8;switch(i.type){case"point":(e=i.points)==null||e.forEach(n=>{DrawUtils.drawCircleWithFill(this.canvas,AxisUtils.default.changePointByZoom(n,this.zoom,this.currentPos),r,{color:o})});break;case"line":{const n=(s=i.points)==null?void 0:s.map(d=>AxisUtils.default.changePointByZoom(d,this.zoom,this.currentPos));n&&DrawUtils.drawLineWithPointList(this.canvas,n,{color:o,thickness:r});break}}})}renderCuboid(){this.renderStatic(),this.renderDrawing(),this.renderSelected(),this.renderHover()}render(){!this.ctx||(super.render(),this.renderCuboid(),this.renderCursorLine(this.getLineColor(this.defaultAttribute)))}undo(){const t=this.history.undo();t&&(t.length!==this.cuboidList.length&&this.setSelectedID(""),this.setCuboidList(t,!0),this.render())}redo(){const t=this.history.redo();t&&(t.length!==this.cuboidList.length&&this.setSelectedID(""),this.setCuboidList(t,!0),this.render())}}module.exports=CuboidOperation;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var tool=require("../../constant/tool.js"),RectUtils=require("../../utils/tool/RectUtils.js"),PolygonUtils=require("../../utils/tool/PolygonUtils.js"),MarkerUtils=require("../../utils/tool/MarkerUtils.js"),MathUtils=require("../../utils/MathUtils.js"),annotation=require("../../constant/annotation.js"),keyCode=require("../../constant/keyCode.js"),index=require("../../locales/index.js"),constants=require("../../locales/constants.js"),AttributeUtils=require("../../utils/tool/AttributeUtils.js"),AxisUtils=require("../../utils/tool/AxisUtils.js"),CommonToolUtils=require("../../utils/tool/CommonToolUtils.js"),DrawUtils=require("../../utils/tool/DrawUtils.js"),StyleUtils=require("../../utils/tool/StyleUtils.js"),uuid=require("../../utils/uuid.js"),basicToolOperation=require("./basicToolOperation.js"),textAttributeClass=require("./textAttributeClass.js"),__defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnPropDescs=Object.getOwnPropertyDescriptors,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__pow=Math.pow,__defNormalProp=(c,t,e)=>t in c?__defProp(c,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):c[t]=e,__spreadValues=(c,t)=>{for(var e in t||(t={}))__hasOwnProp.call(t,e)&&__defNormalProp(c,e,t[e]);if(__getOwnPropSymbols)for(var e of __getOwnPropSymbols(t))__propIsEnum.call(t,e)&&__defNormalProp(c,e,t[e]);return c},__spreadProps=(c,t)=>__defProps(c,__getOwnPropDescs(t));const TEXTAREA_WIDTH=200;class PointOperation extends basicToolOperation.BasicToolOperation{constructor(t){super(t);this.setMarkerIndex=e=>{this.markerIndex=e},this.setMarkerIndexAndSelect=e=>{if(!this.config.markerList)return;this.markerIndex=e;const i=this.config.markerList[e].value,s=this.currentPageResult.find(r=>r.label===i);s&&(this.setSelectedID(s.id),this.config.attributeConfigurable===!0&&this.setDefaultAttribute(s.attribute)),this.emit("markIndexChange")},this.textChange=e=>{this.config.textConfigurable!==!0||!this.selectedID||(this.setPointList(AttributeUtils.default.textChange(e,this.selectedID,this.pointList)),this.emit("selectedChange"),this.render())},this.isMinDistance=e=>{const i=AxisUtils.default.changePointByZoom(e,this.zoom);return this.pointList.some(s=>{const r=AxisUtils.default.changePointByZoom(s,this.zoom);return MathUtils.default.getLineLength(r,i)<.2})},this.config=CommonToolUtils.jsonParser(t.config),this.pointList=[],this.markerIndex=0,this.setStyle(t.style),this.createPoint=this.createPoint.bind(this),this.getCurrentSelectedData=this.getCurrentSelectedData.bind(this),this.updateSelectedTextAttribute=this.updateSelectedTextAttribute.bind(this),this.setSelectedID=this.setSelectedID.bind(this)}get dataList(){return this.pointList}get drawOutsideTarget(){var t;return(t=this.config.drawOutsideTarget)!=null?t:this.config.drawPointOut}setNextMarker(t=this.pointList){if(this.hasMarkerConfig){const e=CommonToolUtils.getNextMarker(this.getCurrentPageResult(t),this.config.markerList);e&&this.setMarkerIndexAndSelect(e.index)}}setResult(t){this.clearActiveStatus(),this.setPointList(t),this.setNextMarker(t),this.recoverOperationMode(),this.render()}setPointList(t,e=!1){const i=this.pointList.length;this.pointList=t,i!==t.length&&this.emit("updatePageNumber"),e&&this.emit("updateResult")}setConfig(t,e=!1){this.config=CommonToolUtils.jsonParser(t),e===!0&&this.clearResult()}clearResult(){this.setPointList([]),this.setSelectedID(void 0),this.history.pushHistory([]),this.hoverID="",this.render()}setDefaultAttribute(t=""){const e=this.defaultAttribute;if(this.defaultAttribute=t,e!==t){this.changeStyle(t),this.emit("changeAttributeSidebar");const{selectedID:i}=this;if(i&&(this.pointList.forEach(s=>{s.id===i&&(s.attribute=t)}),this.history.pushHistory(this.pointList),this.render()),this._textAttributInstance){if(this.attributeLockList.length>0&&!this.attributeLockList.includes(t)){this._textAttributInstance.clearTextAttribute();return}this._textAttributInstance.updateIcon(this.getTextIconSvg(t))}}}get selectedText(){var t;return(t=this.pointList.find(e=>e.id===this.selectedID))==null?void 0:t.textAttribute}setStyle(t){var e;super.setStyle(t),this._textAttributInstance&&this.config.attributeConfigurable===!1&&((e=this._textAttributInstance)==null||e.updateIcon(this.getTextIconSvg()))}setSelectedID(t){var e,i;const s=this.selectedID;t!==s&&s&&((e=this._textAttributInstance)==null||e.changeSelected()),t||(i=this._textAttributInstance)==null||i.clearTextAttribute(),this.selectedID=t,this.render(),this.emit("selectedChange")}getTextIconSvg(t=""){return AttributeUtils.default.getTextIconSvg(t,this.config.attributeList,this.config.attributeConfigurable,this.baseIcon)}clearActiveStatus(){this.hoverID=void 0,this.dragStatus=annotation.EDragStatus.Wait,this.setSelectedID(void 0)}setBasicResult(t){super.setBasicResult(t),this.setNextMarker(),this.clearActiveStatus()}onDragMoveAll(t){var e,i;!((i=(e=this.dragInfo)==null?void 0:e.originPointList)==null?void 0:i.length)||(this.setPointList(this.dragInfo.originPointList.map(s=>__spreadProps(__spreadValues({},s),{x:s.x+t.x/this.zoom,y:s.y+t.y/this.zoom}))),this.render())}onMouseDown(t){if(!(super.onMouseDown(t)||this.forbidMouseOperation)){if(t.button===0&&!this.hoverID){this.recoverOperationMode(),this.createPoint(t),this.render();return}if((this.hoverID===this.selectedID||this.isMultiMoveMode&&this.hoverID)&&t.button===0){this.dragStatus=annotation.EDragStatus.Start,this.isMultiMoveMode&&(this.dragInfo={dragStartCoord:this.getCoordinateUnderZoom(t),originPointList:this.pointList});return}return this.render(),!0}}onMouseMove(t){super.onMouseMove(t)||this.forbidMouseOperation||!this.imgInfo||(this.hoverID=this.getHoverId(),(this.dragStatus===annotation.EDragStatus.Start||this.dragStatus===annotation.EDragStatus.Move)&&this.onDragMove(t),this.hoverID&&this.render())}onMouseUp(t){if(super.onMouseUp(t)||this.forbidMouseOperation||!this.imgInfo)return!0;t.button===2&&this.rightMouseUp(),this.dragStatus===annotation.EDragStatus.Move&&(this.history.pushHistory(this.pointList),this.dragInfo=void 0),this.dragStatus=annotation.EDragStatus.Wait,this.render()}onDragMove(t){var e,i;if(!this.imgInfo)return;this.dragStatus=annotation.EDragStatus.Move;const s=this.getCoordinateUnderZoom(t);if(this.isMultiMoveMode&&this.dragInfo){const n={x:s.x-this.dragInfo.dragStartCoord.x,y:s.y-this.dragInfo.dragStartCoord.y};this.onDragMoveAll(n);return}const r=AxisUtils.default.changeDrawOutsideTarget(s,{x:0,y:0},this.imgInfo,this.drawOutsideTarget,this.basicResult,this.zoom),h=this.drawOutsideTarget?AxisUtils.default.getOriginCoordinateWithOffsetCoordinate(this.coord,this.zoom,this.currentPos):AxisUtils.default.changePointByZoom(r,1/this.zoom);this.drawOutsideTarget===!1&&this.dependToolName===tool.EToolName.Polygon&&((i=(e=this.basicResult)==null?void 0:e.pointList)==null?void 0:i.length)>0&&!PolygonUtils.isInPolygon(h,this.basicResult.pointList)||(this.pointList.forEach(n=>{n.id===this.selectedID&&(n.x=h.x,n.y=h.y)}),this.render())}onKeyDown(t){if(!CommonToolUtils.hotkeyFilter(t)||super.onKeyDown(t)===!1)return;const{keyCode:e}=t;switch(e){case keyCode.Delete:this.deletePoint();break;case keyCode.Tab:{this.onTabKeyDown(t);break}case keyCode.Z:this.setIsHidden(!this.isHidden),this.render();break;default:{if(this.config.attributeConfigurable){const i=AttributeUtils.default.getAttributeByKeycode(e,this.config.attributeList);i!==void 0&&this.setDefaultAttribute(i)}break}}}createPoint(t){var e,i,s,r;if(!this.imgInfo)return;const{upperLimit:h}=this.config;if(h&&this.currentPageResult.length>=h){this.emit("messageInfo",`${index.getMessagesByLocale(constants.EMessage.LowerLimitPoint,this.lang)}`);return}const n=CommonToolUtils.getSourceID(this.basicResult),d=this.getCoordinateUnderZoom(t);let l=AxisUtils.default.getOriginCoordinateWithOffsetCoordinate(this.coord,this.zoom,this.currentPos);if(this.config.edgeAdsorption&&this.referenceData&&[tool.EToolName.Polygon,tool.EToolName.Line].includes((e=this.referenceData)==null?void 0:e.toolName)){const g=((i=this.referenceData)==null?void 0:i.toolName)===tool.EToolName.Polygon,{dropFoot:f,hasClosed:v}=PolygonUtils.getClosestPoint(l,this.referenceData.result,(r=(s=this.referenceData.config)==null?void 0:s.lineType)!=null?r:tool.ELineTypes.Line,tool.edgeAdsorptionScope/this.zoom,{isClose:g});f&&(l=f),v&&this.emit("messageSuccess",`${index.getMessagesByLocale(constants.EMessage.SuccessfulEdgeAdsorption,this.lang)}`)}if(this.drawOutsideTarget===!1){if(this.dependToolName&&this.basicCanvas){let a=!1;switch(this.dependToolName){case tool.EToolName.Rect:{a=!RectUtils.isInRect(l,this.basicResult);break}case tool.EToolName.Polygon:{a=!PolygonUtils.isInPolygon(l,this.basicResult.pointList);break}}if(a)return}if(d.x<0||d.y<0||d.x>this.imgInfo.width||d.y>this.imgInfo.height)return}if(this.isMinDistance(l))return;let o=__spreadProps(__spreadValues({},l),{attribute:this.defaultAttribute,valid:!t.ctrlKey,id:uuid(8,62),sourceID:n,textAttribute:"",order:CommonToolUtils.getMaxOrder(this.pointList.filter(a=>CommonToolUtils.isSameSourceID(a.sourceID,n)))+1});if(this.config.textConfigurable){let a="";a=AttributeUtils.default.getTextAttribute(this.pointList.filter(g=>CommonToolUtils.isSameSourceID(g.sourceID,n)),this.config.textCheckType),o=__spreadProps(__spreadValues({},o),{textAttribute:a})}if(this.hasMarkerConfig){const a=CommonToolUtils.getNextMarker(this.currentPageResult,this.config.markerList,this.markerIndex);if(a)o=__spreadProps(__spreadValues({},o),{label:a.label}),this.markerIndex=a.index,this.emit("markIndexChange");else{this.emit("messageInfo",index.getMessagesByLocale(constants.EMessage.MarkerFinish,this.lang));return}}this.hoverID=o.id;const u=[...this.pointList,o];this.setPointList(u),this.history.pushHistory(u),this.setSelectedID(o.id)}isInPoint(t,e,i=this.zoom){return(this.style.width+2)/i>=Math.sqrt(__pow(t.x-e.x,2)+__pow(t.y-e.y,2))}getHoverId(){var t;const e=AxisUtils.default.getOriginCoordinateWithOffsetCoordinate(this.coord,this.zoom,this.currentPos),i=(t=this.pointList)==null?void 0:t.find(s=>this.isInPoint(e,s));return i==null?void 0:i.id}rightMouseUp(){if(this.recoverOperationMode(),this.selectedID===this.hoverID){const e=this.pointList.filter(i=>i.id!==this.selectedID);this.setPointList(e),this.history.pushHistory(e),this.setSelectedID(""),this.hoverID="";return}const t=this.pointList.find(e=>e.id===this.hoverID);if(this.setSelectedID(this.hoverID),this.setDefaultAttribute(t==null?void 0:t.attribute),(t==null?void 0:t.label)&&this.hasMarkerConfig){const e=CommonToolUtils.getCurrentMarkerIndex(t.label,this.config.markerList);e>=0&&(this.setMarkerIndex(e),this.emit("markIndexChange"))}}onTabKeyDown(t){if(t.preventDefault(),this.dragStatus===annotation.EDragStatus.Move||this.dragStatus===annotation.EDragStatus.Start)return;let e=annotation.ESortDirection.ascend;t.shiftKey&&(e=annotation.ESortDirection.descend);const[i,s]=CommonToolUtils.getRenderResultList(this.pointList,CommonToolUtils.getSourceID(this.basicResult),this.attributeLockList,this.selectedID);let r=[...i];s&&(r=[...r,s]);const h=CommonToolUtils.getNextSelectedRectID(r,e,this.selectedID);h&&this.setSelectedID(h.id)}get currentPageResult(){const[t]=CommonToolUtils.getRenderResultList(this.pointList,CommonToolUtils.getSourceID(this.basicResult),[]);return t}getCurrentPageResult(t){const[e]=CommonToolUtils.getRenderResultList(t,CommonToolUtils.getSourceID(this.basicResult),[]);return e}exportData(){const{pointList:t}=this;return[t,this.basicImgInfo]}deletePoint(){var t;this.selectedID&&(this.setPointList(this.pointList.filter(e=>e.id!==this.selectedID)),this.history.pushHistory(this.pointList),(t=this._textAttributInstance)==null||t.clearTextAttribute(),this.emit("selectedChange"),this.render())}undoAndRedo(t){var e,i;if(this.dragStatus===annotation.EDragStatus.Move||this.dragStatus===annotation.EDragStatus.Start)return;const s=(i=(e=this.history)[t])==null?void 0:i.call(e);(s==null?void 0:s.some(r=>r.id===this.selectedID))||this.setSelectedID(""),s&&(this.setPointList(s,!0),this.render())}undo(){this.undoAndRedo("undo")}redo(){this.undoAndRedo("redo")}getCurrentSelectedData(){var t;if(!this.selectedID)return;const e=(t=this.pointList)==null?void 0:t.find(r=>r.id===this.selectedID),i=this.getColor(e==null?void 0:e.attribute),s=(e==null?void 0:e.valid)?i==null?void 0:i.valid.stroke:i==null?void 0:i.invalid.stroke;return this.dragStatus=annotation.EDragStatus.Wait,{width:TEXTAREA_WIDTH*this.zoom*.6,textAttribute:(e==null?void 0:e.textAttribute)||"",color:s}}updateSelectedTextAttribute(t){if(this._textAttributInstance&&t&&this.selectedID){let e=t;AttributeUtils.default.textAttributeValidate(this.config.textCheckType,"",e)===!1&&(this.emit("messageError",AttributeUtils.default.getErrorNotice(this.config.textCheckType,this.lang)),e=""),this.setPointList(AttributeUtils.default.textChange(e,this.selectedID,this.pointList)),this.emit("updateTextAttribute"),this.render()}}renderTextAttribute(){var t,e;const i=(t=this.pointList)==null?void 0:t.find(g=>g.id===this.selectedID);if(!this.ctx||this.config.textConfigurable!==!0||!i)return;const{x:s,y:r,attribute:h,valid:n}=i,d=TEXTAREA_WIDTH*this.zoom*.6,l=AxisUtils.default.getOffsetCoordinate({x:s,y:r},this.currentPos,this.zoom),o=this.getColor(h),u=n?o==null?void 0:o.valid.stroke:o==null?void 0:o.invalid.stroke,a=4;this._textAttributInstance||(this._textAttributInstance=new textAttributeClass({width:d,container:this.container,icon:this.getTextIconSvg(h),color:u,getCurrentSelectedData:this.getCurrentSelectedData,updateSelectedTextAttribute:this.updateSelectedTextAttribute})),this._textAttributInstance&&!((e=this._textAttributInstance)==null?void 0:e.isExit)&&this._textAttributInstance.appendToContainer(),this._textAttributInstance.update(`${i.textAttribute}`,{left:l.x,top:l.y+a,color:u,width:d})}renderPoint(t,e=!1){var i,s,r;const{textAttribute:h="",attribute:n}=t,d=e||t.id===this.selectedID,l=this.getColor(n),o=AxisUtils.default.changePointByZoom(t,this.zoom,this.currentPos),{width:u=2,hiddenText:a=!1}=this.style,g=StyleUtils.getStrokeAndFill(l,t.valid,{isSelected:d||t.id===this.hoverID});DrawUtils.drawCircle(this.canvas,o,u,{startAngleDeg:0,endAngleDeg:360,thickness:1,color:g.stroke,fill:g.fill});let f="";(((i=this.config)==null?void 0:i.isShowOrder)||((s=this.config)==null?void 0:s.showOrder))&&t.order&&(t==null?void 0:t.order)>0&&(f=`${t.order}`),t.label&&this.hasMarkerConfig&&(f=`${CommonToolUtils.getCurrentMarkerIndex(t.label,this.config.markerList)+1}_${MarkerUtils.getMarkerShowText(t.label,this.config.markerList)}`),t.attribute&&(f=`${f} ${AttributeUtils.default.getAttributeShowText(t.attribute,(r=this.config)==null?void 0:r.attributeList)}`),a||DrawUtils.drawText(this.canvas,{x:o.x+u/2,y:o.y-u-4},f,{textAlign:"center",color:g.stroke}),d?this.renderTextAttribute():a||DrawUtils.drawText(this.canvas,{x:o.x+u,y:o.y+u+24},h,__spreadValues({color:g.stroke},annotation.DEFAULT_TEXT_OFFSET))}renderMultiSelectedPoint(){!this.isMultiMoveMode||this.pointList.forEach(t=>{this.renderPoint(t,!0)})}renderPointList(){switch(this.operationMode){case tool.EOperationMode.MultiMove:this.renderMultiSelectedPoint();break;default:{const[t,e]=CommonToolUtils.getRenderResultList(this.pointList,CommonToolUtils.getSourceID(this.basicResult),this.attributeLockList,this.selectedID);this.isHidden||t.forEach(i=>{this.renderPoint(i)}),e&&this.renderPoint(e)}}}renderAuxiliaryLine(){var t;if(!this.config.markerConfigurable||!((t=this.config.markerList)==null?void 0:t.length))return;const[e,i]=CommonToolUtils.getRenderResultList(this.pointList,CommonToolUtils.getSourceID(this.basicResult),this.attributeLockList,this.selectedID),s=e;if(i&&s.push(i),s.length<2)return;const r=MarkerUtils.getAuxiliaryLineByMarkerList(this.config.markerList,"value");MarkerUtils.getAuxiliaryLineCoord(r,s).forEach(n=>{const{start:d,end:l}=n,o=AxisUtils.default.changePointListByZoom([d,l],this.zoom,this.currentPos);DrawUtils.drawLine(this.canvas,o[0],o[1],{color:"#C5C5C5"})})}renderTop(){var t,e,i;const s=this.getLineColor(this.defaultAttribute);if(this.renderCursorLine(s),this.config.edgeAdsorption&&this.referenceData){let r=AxisUtils.default.getOriginCoordinateWithOffsetCoordinate(this.coord,this.zoom,this.currentPos);const h=((t=this.referenceData)==null?void 0:t.toolName)===tool.EToolName.Polygon,{dropFoot:n}=PolygonUtils.getClosestPoint(r,this.referenceData.result,(i=(e=this.referenceData.config)==null?void 0:e.lineType)!=null?i:tool.ELineTypes.Line,tool.edgeAdsorptionScope/this.zoom,{isClose:h});n&&r!==n&&r!==n&&(r=n,DrawUtils.drawCircle(this.canvas,AxisUtils.default.changePointByZoom(r,this.zoom,this.currentPos),5,{color:"white",fill:"white"}),DrawUtils.drawCircle(this.canvas,AxisUtils.default.changePointByZoom(r,this.zoom,this.currentPos),3,{fill:s,color:s}))}}render(){!this.ctx||(super.render(),this.renderAuxiliaryLine(),this.renderPointList(),this.renderTop())}}module.exports=PointOperation;
|
|
1
|
+
"use strict";var tool=require("../../constant/tool.js"),RectUtils=require("../../utils/tool/RectUtils.js"),PolygonUtils=require("../../utils/tool/PolygonUtils.js"),MarkerUtils=require("../../utils/tool/MarkerUtils.js"),MathUtils=require("../../utils/MathUtils.js"),_=require("lodash"),annotation=require("../../constant/annotation.js"),keyCode=require("../../constant/keyCode.js"),index=require("../../locales/index.js"),constants=require("../../locales/constants.js"),AttributeUtils=require("../../utils/tool/AttributeUtils.js"),AxisUtils=require("../../utils/tool/AxisUtils.js"),CommonToolUtils=require("../../utils/tool/CommonToolUtils.js"),DrawUtils=require("../../utils/tool/DrawUtils.js"),StyleUtils=require("../../utils/tool/StyleUtils.js"),uuid=require("../../utils/uuid.js"),basicToolOperation=require("./basicToolOperation.js"),textAttributeClass=require("./textAttributeClass.js");function _interopDefaultLegacy(l){return l&&typeof l=="object"&&"default"in l?l:{default:l}}var ___default=_interopDefaultLegacy(_),__defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnPropDescs=Object.getOwnPropertyDescriptors,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__pow=Math.pow,__defNormalProp=(l,t,e)=>t in l?__defProp(l,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):l[t]=e,__spreadValues=(l,t)=>{for(var e in t||(t={}))__hasOwnProp.call(t,e)&&__defNormalProp(l,e,t[e]);if(__getOwnPropSymbols)for(var e of __getOwnPropSymbols(t))__propIsEnum.call(t,e)&&__defNormalProp(l,e,t[e]);return l},__spreadProps=(l,t)=>__defProps(l,__getOwnPropDescs(t));const TEXTAREA_WIDTH=200;class PointOperation extends basicToolOperation.BasicToolOperation{constructor(t){super(t);this.setMarkerIndex=s=>{this.markerIndex=s},this.setMarkerIndexAndSelect=s=>{if(!this.config.markerList)return;this.markerIndex=s;const r=this.config.markerList[s].value,n=this.currentPageResult.find(o=>o.label===r);n&&(this.setSelectedID(n.id),this.config.attributeConfigurable===!0&&this.setDefaultAttribute(n.attribute)),this.emit("markIndexChange")},this.textChange=s=>{this.config.textConfigurable!==!0||!this.selectedID||(this.setPointList(AttributeUtils.default.textChange(s,this.selectedID,this.pointList)),this.emit("selectedChange"),this.render())},this.isMinDistance=s=>{const r=AxisUtils.default.changePointByZoom(s,this.zoom);return this.pointList.some(n=>{const o=AxisUtils.default.changePointByZoom(n,this.zoom);return MathUtils.default.getLineLength(o,r)<.2})};var e,i;this.config=CommonToolUtils.jsonParser(t.config),this.pointList=[],this.markerIndex=0,this.setStyle(t.style),this.createPoint=this.createPoint.bind(this),this.getCurrentSelectedData=this.getCurrentSelectedData.bind(this),this.updateSelectedTextAttribute=this.updateSelectedTextAttribute.bind(this),this.setSelectedID=this.setSelectedID.bind(this),this.forbidAddNew=(e=t.forbidAddNew)!=null?e:!1,this.forbidDelete=(i=t.forbidDelete)!=null?i:!1}get dataList(){return this.pointList}get drawOutsideTarget(){var t;return(t=this.config.drawOutsideTarget)!=null?t:this.config.drawPointOut}setNextMarker(t=this.pointList){if(this.hasMarkerConfig){const e=CommonToolUtils.getNextMarker(this.getCurrentPageResult(t),this.config.markerList);e&&this.setMarkerIndexAndSelect(e.index)}}setResult(t){this.clearActiveStatus(),this.setPointList(t),this.setNextMarker(t),this.recoverOperationMode(),this.render()}setPointList(t,e=!1){const i=this.pointList.length;this.pointList=t,i!==t.length&&this.emit("updatePageNumber"),e&&this.emit("updateResult")}setConfig(t,e=!1){this.config=CommonToolUtils.jsonParser(t),e===!0&&this.clearResult()}clearResult(){this.setPointList([]),this.setSelectedID(void 0),this.history.pushHistory([]),this.hoverID="",this.render()}setDefaultAttribute(t=""){const e=this.defaultAttribute;if(this.defaultAttribute=t,e!==t){this.changeStyle(t),this.emit("changeAttributeSidebar");const{selectedID:i}=this;if(i&&(this.pointList.forEach(s=>{s.id===i&&(s.attribute=t)}),this.history.pushHistory(this.pointList),this.render()),this._textAttributInstance){if(this.attributeLockList.length>0&&!this.attributeLockList.includes(t)){this._textAttributInstance.clearTextAttribute();return}this._textAttributInstance.updateIcon(this.getTextIconSvg(t))}}}get selectedText(){var t;return(t=this.pointList.find(e=>e.id===this.selectedID))==null?void 0:t.textAttribute}setStyle(t){var e;super.setStyle(t),this._textAttributInstance&&this.config.attributeConfigurable===!1&&((e=this._textAttributInstance)==null||e.updateIcon(this.getTextIconSvg()))}setSelectedID(t){var e,i;const s=this.selectedID;t!==s&&s&&((e=this._textAttributInstance)==null||e.changeSelected()),t||(i=this._textAttributInstance)==null||i.clearTextAttribute(),this.selectedID=t,this.render(),this.emit("selectedChange")}getTextIconSvg(t=""){return AttributeUtils.default.getTextIconSvg(t,this.config.attributeList,this.config.attributeConfigurable,this.baseIcon)}clearActiveStatus(){this.hoverID=void 0,this.dragStatus=annotation.EDragStatus.Wait,this.setSelectedID(void 0)}setBasicResult(t){super.setBasicResult(t),this.setNextMarker(),this.clearActiveStatus()}onDragMoveAll(t){var e,i;!((i=(e=this.dragInfo)==null?void 0:e.originPointList)==null?void 0:i.length)||(this.setPointList(this.dragInfo.originPointList.map(s=>__spreadProps(__spreadValues({},s),{x:s.x+t.x/this.zoom,y:s.y+t.y/this.zoom}))),this.render())}onMouseDown(t){if(!(super.onMouseDown(t)||this.forbidMouseOperation)){if(t.button===0&&!this.hoverID){this.recoverOperationMode(),this.createPoint(t),this.render();return}if((this.hoverID===this.selectedID||this.isMultiMoveMode&&this.hoverID)&&t.button===0){this.dragStatus=annotation.EDragStatus.Start,this.dragInfo={dragStartCoord:this.getCoordinateUnderZoom(t),originPointList:___default.default.cloneDeep(this.pointList)};return}return this.render(),!0}}onMouseMove(t){super.onMouseMove(t)||this.forbidMouseOperation||!this.imgInfo||(this.hoverID=this.getHoverId(),(this.dragStatus===annotation.EDragStatus.Start||this.dragStatus===annotation.EDragStatus.Move)&&this.onDragMove(t),this.hoverID&&this.render())}onMouseUp(t){var e;if(super.onMouseUp(t)||this.forbidMouseOperation||!this.imgInfo)return!0;t.button===2&&this.rightMouseUp(),this.dragStatus===annotation.EDragStatus.Move&&(this.history.pushHistory(this.pointList),this.emit("updatePointByDrag",this.pointList.find(i=>(i==null?void 0:i.id)===this.selectedID),(e=this.dragInfo)==null?void 0:e.originPointList),this.dragInfo=void 0),this.dragStatus=annotation.EDragStatus.Wait,this.render()}onDragMove(t){var e,i;if(!this.imgInfo)return;this.dragStatus=annotation.EDragStatus.Move;const s=this.getCoordinateUnderZoom(t);if(this.isMultiMoveMode&&this.dragInfo){const o={x:s.x-this.dragInfo.dragStartCoord.x,y:s.y-this.dragInfo.dragStartCoord.y};this.onDragMoveAll(o);return}const r=AxisUtils.default.changeDrawOutsideTarget(s,{x:0,y:0},this.imgInfo,this.drawOutsideTarget,this.basicResult,this.zoom),n=this.drawOutsideTarget?AxisUtils.default.getOriginCoordinateWithOffsetCoordinate(this.coord,this.zoom,this.currentPos):AxisUtils.default.changePointByZoom(r,1/this.zoom);this.drawOutsideTarget===!1&&this.dependToolName===tool.EToolName.Polygon&&((i=(e=this.basicResult)==null?void 0:e.pointList)==null?void 0:i.length)>0&&!PolygonUtils.isInPolygon(n,this.basicResult.pointList)||(this.pointList.forEach(o=>{o.id===this.selectedID&&(o.x=n.x,o.y=n.y)}),this.render())}onKeyDown(t){if(!CommonToolUtils.hotkeyFilter(t)||super.onKeyDown(t)===!1)return;const{keyCode:e}=t;switch(e){case keyCode.Delete:this.deletePoint();break;case keyCode.Tab:{this.onTabKeyDown(t);break}case keyCode.Z:this.setIsHidden(!this.isHidden),this.render();break;default:{if(this.config.attributeConfigurable){const i=AttributeUtils.default.getAttributeByKeycode(e,this.config.attributeList);i!==void 0&&this.setDefaultAttribute(i)}break}}}createPoint(t){var e,i,s,r;if(!this.imgInfo||this.forbidAddNew)return;const{upperLimit:n}=this.config;if(n&&this.currentPageResult.length>=n){this.emit("messageInfo",`${index.getMessagesByLocale(constants.EMessage.LowerLimitPoint,this.lang)}`);return}const o=CommonToolUtils.getSourceID(this.basicResult),u=this.getCoordinateUnderZoom(t);let d=AxisUtils.default.getOriginCoordinateWithOffsetCoordinate(this.coord,this.zoom,this.currentPos);if(this.config.edgeAdsorption&&this.referenceData&&[tool.EToolName.Polygon,tool.EToolName.Line].includes((e=this.referenceData)==null?void 0:e.toolName)){const f=((i=this.referenceData)==null?void 0:i.toolName)===tool.EToolName.Polygon,{dropFoot:g,hasClosed:v}=PolygonUtils.getClosestPoint(d,this.referenceData.result,(r=(s=this.referenceData.config)==null?void 0:s.lineType)!=null?r:tool.ELineTypes.Line,tool.edgeAdsorptionScope/this.zoom,{isClose:f});g&&(d=g),v&&this.emit("messageSuccess",`${index.getMessagesByLocale(constants.EMessage.SuccessfulEdgeAdsorption,this.lang)}`)}if(this.drawOutsideTarget===!1){if(this.dependToolName&&this.basicCanvas){let h=!1;switch(this.dependToolName){case tool.EToolName.Rect:{h=!RectUtils.isInRect(d,this.basicResult);break}case tool.EToolName.Polygon:{h=!PolygonUtils.isInPolygon(d,this.basicResult.pointList);break}}if(h)return}if(u.x<0||u.y<0||u.x>this.imgInfo.width||u.y>this.imgInfo.height)return}if(this.isMinDistance(d))return;let a=__spreadProps(__spreadValues({},d),{attribute:this.defaultAttribute,valid:!t.ctrlKey,id:uuid(8,62),sourceID:o,textAttribute:"",order:CommonToolUtils.getMaxOrder(this.pointList.filter(h=>CommonToolUtils.isSameSourceID(h.sourceID,o)))+1});if(this.config.textConfigurable){let h="";h=AttributeUtils.default.getTextAttribute(this.pointList.filter(f=>CommonToolUtils.isSameSourceID(f.sourceID,o)),this.config.textCheckType),a=__spreadProps(__spreadValues({},a),{textAttribute:h})}if(this.hasMarkerConfig){const h=CommonToolUtils.getNextMarker(this.currentPageResult,this.config.markerList,this.markerIndex);if(h)a=__spreadProps(__spreadValues({},a),{label:h.label}),this.markerIndex=h.index,this.emit("markIndexChange");else{this.emit("messageInfo",index.getMessagesByLocale(constants.EMessage.MarkerFinish,this.lang));return}}this.hoverID=a.id;const c=[...this.pointList,a];this.setPointList(c),this.emit("pointCreated",a,this.zoom),this.history.pushHistory(c),this.setSelectedID(a.id)}isInPoint(t,e,i=this.zoom){return(this.style.width+2)/i>=Math.sqrt(__pow(t.x-e.x,2)+__pow(t.y-e.y,2))}getHoverId(){var t;const e=AxisUtils.default.getOriginCoordinateWithOffsetCoordinate(this.coord,this.zoom,this.currentPos),i=(t=this.pointList)==null?void 0:t.find(s=>this.isInPoint(e,s));return i==null?void 0:i.id}get selectedPoint(){return this.pointList.find(t=>t.id===this.selectedID)}rightMouseUp(){if(this.recoverOperationMode(),this.selectedID===this.hoverID){if(this.forbidDelete)return;const e=this.pointList.filter(i=>i.id!==this.selectedID);this.setPointList(e),this.history.pushHistory(e),this.emit("pointDeleted",this.selectedID),this.setSelectedID(""),this.hoverID="";return}const t=this.pointList.find(e=>e.id===this.hoverID);if(this.setSelectedID(this.hoverID),this.emit("pointSelected",this.hoverID),this.setDefaultAttribute(t==null?void 0:t.attribute),(t==null?void 0:t.label)&&this.hasMarkerConfig){const e=CommonToolUtils.getCurrentMarkerIndex(t.label,this.config.markerList);e>=0&&(this.setMarkerIndex(e),this.emit("markIndexChange"))}}onTabKeyDown(t){if(t.preventDefault(),this.dragStatus===annotation.EDragStatus.Move||this.dragStatus===annotation.EDragStatus.Start)return;let e=annotation.ESortDirection.ascend;t.shiftKey&&(e=annotation.ESortDirection.descend);const[i,s]=CommonToolUtils.getRenderResultList(this.pointList,CommonToolUtils.getSourceID(this.basicResult),this.attributeLockList,this.selectedID);let r=[...i];s&&(r=[...r,s]);const n=CommonToolUtils.getNextSelectedRectID(r,e,this.selectedID);n&&this.setSelectedID(n.id)}get currentPageResult(){const[t]=CommonToolUtils.getRenderResultList(this.pointList,CommonToolUtils.getSourceID(this.basicResult),[]);return t}getCurrentPageResult(t){const[e]=CommonToolUtils.getRenderResultList(t,CommonToolUtils.getSourceID(this.basicResult),[]);return e}exportData(){const{pointList:t}=this;return[t,this.basicImgInfo]}deletePoint(){var t;this.selectedID&&(this.setPointList(this.pointList.filter(e=>e.id!==this.selectedID)),this.history.pushHistory(this.pointList),(t=this._textAttributInstance)==null||t.clearTextAttribute(),this.emit("selectedChange"),this.emit("pointDeleted",this.selectedID),this.render())}undoAndRedo(t){var e,i;if(this.dragStatus===annotation.EDragStatus.Move||this.dragStatus===annotation.EDragStatus.Start)return;const s=(i=(e=this.history)[t])==null?void 0:i.call(e);(s==null?void 0:s.some(r=>r.id===this.selectedID))||this.setSelectedID(""),s&&(this.setPointList(s,!0),this.render())}undo(){this.undoAndRedo("undo")}redo(){this.undoAndRedo("redo")}getCurrentSelectedData(){var t;if(!this.selectedID)return;const e=(t=this.pointList)==null?void 0:t.find(r=>r.id===this.selectedID),i=this.getColor(e==null?void 0:e.attribute),s=(e==null?void 0:e.valid)?i==null?void 0:i.valid.stroke:i==null?void 0:i.invalid.stroke;return this.dragStatus=annotation.EDragStatus.Wait,{width:TEXTAREA_WIDTH*this.zoom*.6,textAttribute:(e==null?void 0:e.textAttribute)||"",color:s}}updateSelectedTextAttribute(t){if(this._textAttributInstance&&t&&this.selectedID){let e=t;AttributeUtils.default.textAttributeValidate(this.config.textCheckType,"",e)===!1&&(this.emit("messageError",AttributeUtils.default.getErrorNotice(this.config.textCheckType,this.lang)),e=""),this.setPointList(AttributeUtils.default.textChange(e,this.selectedID,this.pointList)),this.emit("updateTextAttribute"),this.render()}}renderTextAttribute(){var t,e;const i=(t=this.pointList)==null?void 0:t.find(f=>f.id===this.selectedID);if(!this.ctx||this.config.textConfigurable!==!0||!i)return;const{x:s,y:r,attribute:n,valid:o}=i,u=TEXTAREA_WIDTH*this.zoom*.6,d=AxisUtils.default.getOffsetCoordinate({x:s,y:r},this.currentPos,this.zoom),a=this.getColor(n),c=o?a==null?void 0:a.valid.stroke:a==null?void 0:a.invalid.stroke,h=4;this._textAttributInstance||(this._textAttributInstance=new textAttributeClass({width:u,container:this.container,icon:this.getTextIconSvg(n),color:c,getCurrentSelectedData:this.getCurrentSelectedData,updateSelectedTextAttribute:this.updateSelectedTextAttribute})),this._textAttributInstance&&!((e=this._textAttributInstance)==null?void 0:e.isExit)&&this._textAttributInstance.appendToContainer(),this._textAttributInstance.update(`${i.textAttribute}`,{left:d.x,top:d.y+h,color:c,width:u})}renderPoint(t,e=!1){var i,s,r;const{textAttribute:n="",attribute:o}=t,u=e||t.id===this.selectedID,d=this.getColor(o),a=AxisUtils.default.changePointByZoom(t,this.zoom,this.currentPos),{width:c=2,hiddenText:h=!1}=this.style,f=StyleUtils.getStrokeAndFill(d,t.valid,{isSelected:u||t.id===this.hoverID});DrawUtils.drawCircle(this.canvas,a,c,{startAngleDeg:0,endAngleDeg:360,thickness:1,color:f.stroke,fill:f.fill});let g="";(((i=this.config)==null?void 0:i.isShowOrder)||((s=this.config)==null?void 0:s.showOrder))&&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&&!this.config.hideAttribute&&(g=`${g} ${AttributeUtils.default.getAttributeShowText(t.attribute,(r=this.config)==null?void 0:r.attributeList)}`),h||DrawUtils.drawText(this.canvas,{x:a.x+c/2,y:a.y-c-4},g,{textAlign:"center",color:f.stroke}),u?this.renderTextAttribute():h||DrawUtils.drawText(this.canvas,{x:a.x+c,y:a.y+c+24},n,__spreadValues({color:f.stroke},annotation.DEFAULT_TEXT_OFFSET))}renderMultiSelectedPoint(){!this.isMultiMoveMode||this.pointList.forEach(t=>{this.renderPoint(t,!0)})}renderPointList(){switch(this.operationMode){case tool.EOperationMode.MultiMove:this.renderMultiSelectedPoint();break;default:{const[t,e]=CommonToolUtils.getRenderResultList(this.pointList,CommonToolUtils.getSourceID(this.basicResult),this.attributeLockList,this.selectedID);this.isHidden||t.forEach(i=>{this.renderPoint(i)}),e&&this.renderPoint(e)}}}renderAuxiliaryLine(){var t;if(!this.config.markerConfigurable||!((t=this.config.markerList)==null?void 0:t.length))return;const[e,i]=CommonToolUtils.getRenderResultList(this.pointList,CommonToolUtils.getSourceID(this.basicResult),this.attributeLockList,this.selectedID),s=e;if(i&&s.push(i),s.length<2)return;const r=MarkerUtils.getAuxiliaryLineByMarkerList(this.config.markerList,"value");MarkerUtils.getAuxiliaryLineCoord(r,s).forEach(o=>{const{start:u,end:d}=o,a=AxisUtils.default.changePointListByZoom([u,d],this.zoom,this.currentPos);DrawUtils.drawLine(this.canvas,a[0],a[1],{color:"#C5C5C5"})})}renderTop(){var t,e,i;const s=this.getLineColor(this.defaultAttribute);if(this.renderCursorLine(s),this.config.edgeAdsorption&&this.referenceData){let r=AxisUtils.default.getOriginCoordinateWithOffsetCoordinate(this.coord,this.zoom,this.currentPos);const n=((t=this.referenceData)==null?void 0:t.toolName)===tool.EToolName.Polygon,{dropFoot:o}=PolygonUtils.getClosestPoint(r,this.referenceData.result,(i=(e=this.referenceData.config)==null?void 0:e.lineType)!=null?i:tool.ELineTypes.Line,tool.edgeAdsorptionScope/this.zoom,{isClose:n});o&&r!==o&&r!==o&&(r=o,DrawUtils.drawCircle(this.canvas,AxisUtils.default.changePointByZoom(r,this.zoom,this.currentPos),5,{color:"white",fill:"white"}),DrawUtils.drawCircle(this.canvas,AxisUtils.default.changePointByZoom(r,this.zoom,this.currentPos),3,{fill:s,color:s}))}}render(){!this.ctx||(super.render(),this.renderAuxiliaryLine(),this.renderPointList(),this.renderTop())}}module.exports=PointOperation;
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var rectOperation=require("./core/toolOperation/rectOperation.js"),tagOperation=require("./core/toolOperation/tagOperation.js"),pointOperation=require("./core/toolOperation/pointOperation.js"),LineToolOperation=require("./core/toolOperation/LineToolOperation.js"),TextToolOperation=require("./core/toolOperation/TextToolOperation.js"),polygonOperation=require("./core/toolOperation/polygonOperation.js"),measureOperation=require("./core/toolOperation/measureOperation.js"),basicToolOperation=require("./core/toolOperation/basicToolOperation.js"),ViewOperation=require("./core/toolOperation/ViewOperation.js"),ScribbleTool=require("./core/toolOperation/ScribbleTool.js"),pointCloud2dOperation=require("./core/toolOperation/pointCloud2dOperation.js"),annotation=require("./constant/annotation.js"),annotationTask=require("./constant/annotationTask.js"),keyCode=require("./constant/keyCode.js"),style=require("./constant/style.js"),tool=require("./constant/tool.js"),TagUtils=require("./utils/tool/TagUtils.js"),uuid=require("./utils/uuid.js"),EnhanceCommonToolUtils=require("./utils/tool/EnhanceCommonToolUtils.js"),MarkerUtils=require("./utils/tool/MarkerUtils.js"),RectUtils=require("./utils/tool/RectUtils.js"),AxisUtils=require("./utils/tool/AxisUtils.js"),DrawUtils=require("./utils/tool/DrawUtils.js"),ImgUtils=require("./utils/ImgUtils.js"),MathUtils=require("./utils/MathUtils.js"),AttributeUtils=require("./utils/tool/AttributeUtils.js"),ActionsHistory=require("./utils/ActionsHistory.js"),DblClickEventListener=require("./utils/tool/DblClickEventListener.js"),index=require("./core/index.js"),UnitUtils=require("./utils/tool/UnitUtils.js"),CanvasScheduler=require("./newCore/CanvasScheduler.js"),index$1=require("./core/pointCloud/index.js"),matrix=require("./core/pointCloud/matrix.js"),annotation$1=require("./core/pointCloud/annotation.js");function _interopNamespaceDefaultOnly(e){return Object.freeze({__proto__:null,default:e})}var keyCode__namespace=_interopNamespaceDefaultOnly(keyCode);const CommonToolUtils=EnhanceCommonToolUtils.default,toolUtils=EnhanceCommonToolUtils.default;exports.RectOperation=rectOperation.RectOperation,exports.TagOperation=tagOperation,exports.PointOperation=pointOperation,exports.LineToolOperation=LineToolOperation.default,exports.TextToolOperation=TextToolOperation,exports.PolygonOperation=polygonOperation,exports.MeasureOperation=measureOperation,exports.BasicToolOperation=basicToolOperation.BasicToolOperation,exports.ViewOperation=ViewOperation,exports.ScribbleTool=ScribbleTool,exports.PointCloud2dOperation=pointCloud2dOperation,exports.cAnnotation=annotation,exports.cAnnotationTask=annotationTask,exports.cKeyCode=keyCode__namespace,exports.cStyle=style,exports.CLIENT_TOOL_HEAD_TYPE=tool.CLIENT_TOOL_HEAD_TYPE,exports.CLIENT_TOOL_NAME=tool.CLIENT_TOOL_NAME,exports.DEFAULT_FONT=tool.DEFAULT_FONT,exports.DEFAULT_TEXT_MAX_WIDTH=tool.DEFAULT_TEXT_MAX_WIDTH,Object.defineProperty(exports,"EAnnotationMode",{enumerable:!0,get:function(){return tool.EAnnotationMode}}),Object.defineProperty(exports,"EAuditStatus",{enumerable:!0,get:function(){return tool.EAuditStatus}}),Object.defineProperty(exports,"ECheckModel",{enumerable:!0,get:function(){return tool.ECheckModel}}),Object.defineProperty(exports,"EDependPattern",{enumerable:!0,get:function(){return tool.EDependPattern}}),Object.defineProperty(exports,"EDragTarget",{enumerable:!0,get:function(){return tool.EDragTarget}}),Object.defineProperty(exports,"EDrawPointPattern",{enumerable:!0,get:function(){return tool.EDrawPointPattern}}),Object.defineProperty(exports,"EFilterToolOperation",{enumerable:!0,get:function(){return tool.EFilterToolOperation}}),Object.defineProperty(exports,"ELineColor",{enumerable:!0,get:function(){return tool.ELineColor}}),Object.defineProperty(exports,"ELineTypes",{enumerable:!0,get:function(){return tool.ELineTypes}}),Object.defineProperty(exports,"EOperationMode",{enumerable:!0,get:function(){return tool.EOperationMode}}),Object.defineProperty(exports,"EPageOperator",{enumerable:!0,get:function(){return tool.EPageOperator}}),Object.defineProperty(exports,"EPointCloudName",{enumerable:!0,get:function(){return tool.EPointCloudName}}),Object.defineProperty(exports,"EPolygonPattern",{enumerable:!0,get:function(){return tool.EPolygonPattern}}),Object.defineProperty(exports,"ERectPattern",{enumerable:!0,get:function(){return tool.ERectPattern}}),Object.defineProperty(exports,"EScribblePattern",{enumerable:!0,get:function(){return tool.EScribblePattern}}),Object.defineProperty(exports,"ESelectedType",{enumerable:!0,get:function(){return tool.ESelectedType}}),Object.defineProperty(exports,"ETextType",{enumerable:!0,get:function(){return tool.ETextType}}),Object.defineProperty(exports,"EThumbnailOption",{enumerable:!0,get:function(){return tool.EThumbnailOption}}),Object.defineProperty(exports,"EToolName",{enumerable:!0,get:function(){return tool.EToolName}}),Object.defineProperty(exports,"EToolType",{enumerable:!0,get:function(){return tool.EToolType}}),Object.defineProperty(exports,"EVideoToolName",{enumerable:!0,get:function(){return tool.EVideoToolName}}),exports.OPERATION_LIST=tool.OPERATION_LIST,exports.SEGMENT_NUMBER=tool.SEGMENT_NUMBER,exports.TEXT_ATTRIBUTE_LINE_HEIGHT=tool.TEXT_ATTRIBUTE_LINE_HEIGHT,exports.TEXT_ATTRIBUTE_MAX_LENGTH=tool.TEXT_ATTRIBUTE_MAX_LENGTH,exports.TEXT_TYPE=tool.TEXT_TYPE,exports.TOOL_NAME=tool.TOOL_NAME,exports.TOOL_NAME_EN=tool.TOOL_NAME_EN,exports.cTool=tool,exports.edgeAdsorptionScope=tool.edgeAdsorptionScope,exports.editStepWidth=tool.editStepWidth,exports.TagUtils=TagUtils,exports.uuid=uuid,exports.MarkerUtils=MarkerUtils,exports.RectUtils=RectUtils,exports.AxisUtils=AxisUtils.default,exports.DrawUtils=DrawUtils,exports.ImgUtils=ImgUtils,exports.MathUtils=MathUtils.default,exports.AttributeUtils=AttributeUtils.default,exports.ActionsHistory=ActionsHistory,exports.DblClickEventListener=DblClickEventListener,exports.AnnotationEngine=index,exports.UnitUtils=UnitUtils,exports.CanvasScheduler=CanvasScheduler.CanvasScheduler,exports.PointCloud=index$1.PointCloud,exports.createThreeMatrix4=matrix.createThreeMatrix4,exports.getCuboidFromPointCloudBox=matrix.getCuboidFromPointCloudBox,exports.lidar2image=matrix.lidar2image,exports.pointCloudLidar2image=matrix.pointCloudLidar2image,exports.rotatePoint=matrix.rotatePoint,exports.transferKitti2Matrix=matrix.transferKitti2Matrix,exports.PointCloudAnnotation=annotation$1.PointCloudAnnotation,exports.CommonToolUtils=CommonToolUtils,exports.toolUtils=toolUtils;
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var rectOperation=require("./core/toolOperation/rectOperation.js"),tagOperation=require("./core/toolOperation/tagOperation.js"),pointOperation=require("./core/toolOperation/pointOperation.js"),LineToolOperation=require("./core/toolOperation/LineToolOperation.js"),TextToolOperation=require("./core/toolOperation/TextToolOperation.js"),polygonOperation=require("./core/toolOperation/polygonOperation.js"),measureOperation=require("./core/toolOperation/measureOperation.js"),basicToolOperation=require("./core/toolOperation/basicToolOperation.js"),ViewOperation=require("./core/toolOperation/ViewOperation.js"),ScribbleTool=require("./core/toolOperation/ScribbleTool.js"),pointCloud2dOperation=require("./core/toolOperation/pointCloud2dOperation.js"),annotation=require("./constant/annotation.js"),annotationTask=require("./constant/annotationTask.js"),keyCode=require("./constant/keyCode.js"),style=require("./constant/style.js"),tool=require("./constant/tool.js"),TagUtils=require("./utils/tool/TagUtils.js"),uuid=require("./utils/uuid.js"),EnhanceCommonToolUtils=require("./utils/tool/EnhanceCommonToolUtils.js"),MarkerUtils=require("./utils/tool/MarkerUtils.js"),RectUtils=require("./utils/tool/RectUtils.js"),AxisUtils=require("./utils/tool/AxisUtils.js"),DrawUtils=require("./utils/tool/DrawUtils.js"),ImgUtils=require("./utils/ImgUtils.js"),MathUtils=require("./utils/MathUtils.js"),AttributeUtils=require("./utils/tool/AttributeUtils.js"),ActionsHistory=require("./utils/ActionsHistory.js"),DblClickEventListener=require("./utils/tool/DblClickEventListener.js"),index=require("./core/index.js"),UnitUtils=require("./utils/tool/UnitUtils.js"),StyleUtils=require("./utils/tool/StyleUtils.js"),CanvasScheduler=require("./newCore/CanvasScheduler.js"),index$1=require("./core/pointCloud/index.js"),matrix=require("./core/pointCloud/matrix.js"),annotation$1=require("./core/pointCloud/annotation.js");function _interopNamespaceDefaultOnly(e){return Object.freeze({__proto__:null,default:e})}var keyCode__namespace=_interopNamespaceDefaultOnly(keyCode);const CommonToolUtils=EnhanceCommonToolUtils.default,toolUtils=EnhanceCommonToolUtils.default;exports.RectOperation=rectOperation.RectOperation,exports.TagOperation=tagOperation,exports.PointOperation=pointOperation,exports.LineToolOperation=LineToolOperation.default,exports.TextToolOperation=TextToolOperation,exports.PolygonOperation=polygonOperation,exports.MeasureOperation=measureOperation,exports.BasicToolOperation=basicToolOperation.BasicToolOperation,exports.ViewOperation=ViewOperation,exports.ScribbleTool=ScribbleTool,exports.PointCloud2dOperation=pointCloud2dOperation,exports.cAnnotation=annotation,exports.cAnnotationTask=annotationTask,exports.cKeyCode=keyCode__namespace,exports.cStyle=style,exports.CLIENT_TOOL_HEAD_TYPE=tool.CLIENT_TOOL_HEAD_TYPE,exports.CLIENT_TOOL_NAME=tool.CLIENT_TOOL_NAME,exports.DEFAULT_FONT=tool.DEFAULT_FONT,exports.DEFAULT_TEXT_MAX_WIDTH=tool.DEFAULT_TEXT_MAX_WIDTH,Object.defineProperty(exports,"EAnnotationMode",{enumerable:!0,get:function(){return tool.EAnnotationMode}}),Object.defineProperty(exports,"EAuditStatus",{enumerable:!0,get:function(){return tool.EAuditStatus}}),Object.defineProperty(exports,"ECheckModel",{enumerable:!0,get:function(){return tool.ECheckModel}}),Object.defineProperty(exports,"EDependPattern",{enumerable:!0,get:function(){return tool.EDependPattern}}),Object.defineProperty(exports,"EDragTarget",{enumerable:!0,get:function(){return tool.EDragTarget}}),Object.defineProperty(exports,"EDrawPointPattern",{enumerable:!0,get:function(){return tool.EDrawPointPattern}}),Object.defineProperty(exports,"EFilterToolOperation",{enumerable:!0,get:function(){return tool.EFilterToolOperation}}),Object.defineProperty(exports,"ELineColor",{enumerable:!0,get:function(){return tool.ELineColor}}),Object.defineProperty(exports,"ELineTypes",{enumerable:!0,get:function(){return tool.ELineTypes}}),Object.defineProperty(exports,"EOperationMode",{enumerable:!0,get:function(){return tool.EOperationMode}}),Object.defineProperty(exports,"EPageOperator",{enumerable:!0,get:function(){return tool.EPageOperator}}),Object.defineProperty(exports,"EPointCloudName",{enumerable:!0,get:function(){return tool.EPointCloudName}}),Object.defineProperty(exports,"EPolygonPattern",{enumerable:!0,get:function(){return tool.EPolygonPattern}}),Object.defineProperty(exports,"ERectPattern",{enumerable:!0,get:function(){return tool.ERectPattern}}),Object.defineProperty(exports,"EScribblePattern",{enumerable:!0,get:function(){return tool.EScribblePattern}}),Object.defineProperty(exports,"ESelectedType",{enumerable:!0,get:function(){return tool.ESelectedType}}),Object.defineProperty(exports,"ETextType",{enumerable:!0,get:function(){return tool.ETextType}}),Object.defineProperty(exports,"EThumbnailOption",{enumerable:!0,get:function(){return tool.EThumbnailOption}}),Object.defineProperty(exports,"EToolName",{enumerable:!0,get:function(){return tool.EToolName}}),Object.defineProperty(exports,"EToolType",{enumerable:!0,get:function(){return tool.EToolType}}),Object.defineProperty(exports,"EVideoToolName",{enumerable:!0,get:function(){return tool.EVideoToolName}}),exports.OPERATION_LIST=tool.OPERATION_LIST,exports.SEGMENT_NUMBER=tool.SEGMENT_NUMBER,exports.TEXT_ATTRIBUTE_LINE_HEIGHT=tool.TEXT_ATTRIBUTE_LINE_HEIGHT,exports.TEXT_ATTRIBUTE_MAX_LENGTH=tool.TEXT_ATTRIBUTE_MAX_LENGTH,exports.TEXT_TYPE=tool.TEXT_TYPE,exports.TOOL_NAME=tool.TOOL_NAME,exports.TOOL_NAME_EN=tool.TOOL_NAME_EN,exports.cTool=tool,exports.edgeAdsorptionScope=tool.edgeAdsorptionScope,exports.editStepWidth=tool.editStepWidth,exports.TagUtils=TagUtils,exports.uuid=uuid,exports.MarkerUtils=MarkerUtils,exports.RectUtils=RectUtils,exports.AxisUtils=AxisUtils.default,exports.DrawUtils=DrawUtils,exports.ImgUtils=ImgUtils,exports.MathUtils=MathUtils.default,exports.AttributeUtils=AttributeUtils.default,exports.ActionsHistory=ActionsHistory,exports.DblClickEventListener=DblClickEventListener,exports.AnnotationEngine=index,exports.UnitUtils=UnitUtils,exports.StyleUtils=StyleUtils,exports.CanvasScheduler=CanvasScheduler.CanvasScheduler,exports.PointCloud=index$1.PointCloud,exports.createThreeMatrix4=matrix.createThreeMatrix4,exports.getCuboidFromPointCloudBox=matrix.getCuboidFromPointCloudBox,exports.lidar2image=matrix.lidar2image,exports.pointCloudLidar2image=matrix.pointCloudLidar2image,exports.rotatePoint=matrix.rotatePoint,exports.transferKitti2Matrix=matrix.transferKitti2Matrix,exports.PointCloudAnnotation=annotation$1.PointCloudAnnotation,exports.CommonToolUtils=CommonToolUtils,exports.toolUtils=toolUtils;
|
|
@@ -3,12 +3,13 @@
|
|
|
3
3
|
* @createDate 2022-07-18
|
|
4
4
|
* @author Ron <ron.f.luo@gmail.com>
|
|
5
5
|
*/
|
|
6
|
-
import { IPointCloudBox, IPointCloudConfig } from '@labelbee/lb-utils';
|
|
6
|
+
import { IPointCloudBox, IPointCloudSphere, IPointCloudConfig } from '@labelbee/lb-utils';
|
|
7
7
|
import { EToolName, THybridToolName } from '@/constant/tool';
|
|
8
8
|
import { CanvasScheduler } from '@/newCore';
|
|
9
9
|
import { IPolygonData } from '@/types/tool/polygon';
|
|
10
10
|
import { PointCloud } from '.';
|
|
11
11
|
import PointCloud2dOperation, { IPointCloud2dOperationProps } from '../toolOperation/pointCloud2dOperation';
|
|
12
|
+
import { IPointOperationProps } from '../toolOperation/pointOperation';
|
|
12
13
|
import { ToolScheduler } from '../scheduler';
|
|
13
14
|
interface IPointCloudAnnotationOperation {
|
|
14
15
|
updateData: (pcdPath: string, result: string) => void;
|
|
@@ -17,7 +18,7 @@ interface IPointCloudAnnotationProps {
|
|
|
17
18
|
container: HTMLElement;
|
|
18
19
|
size: ISize;
|
|
19
20
|
pcdPath?: string;
|
|
20
|
-
|
|
21
|
+
extraProps?: IPointCloud2dOperationProps | IPointOperationProps;
|
|
21
22
|
config: IPointCloudConfig;
|
|
22
23
|
checkMode?: boolean;
|
|
23
24
|
toolName: THybridToolName;
|
|
@@ -29,7 +30,7 @@ export declare class PointCloudAnnotation implements IPointCloudAnnotationOperat
|
|
|
29
30
|
toolScheduler: ToolScheduler;
|
|
30
31
|
toolInstance: any;
|
|
31
32
|
config: IPointCloudConfig;
|
|
32
|
-
constructor({ size, container, pcdPath,
|
|
33
|
+
constructor({ size, container, pcdPath, extraProps, config, checkMode, toolName }: IPointCloudAnnotationProps);
|
|
33
34
|
updateConfig(config: IPointCloudConfig): void;
|
|
34
35
|
/**
|
|
35
36
|
* Get default boundary by size.
|
|
@@ -50,7 +51,9 @@ export declare class PointCloudAnnotation implements IPointCloudAnnotationOperat
|
|
|
50
51
|
*/
|
|
51
52
|
initSize(size: ISize): void;
|
|
52
53
|
addPolygonListOnTopView(result: string): void;
|
|
54
|
+
addPointListOnTopView(result: string): void;
|
|
53
55
|
updatePolygonList: (pointCloudDataList: IPointCloudBox[], extraList?: IPolygonData[]) => void;
|
|
56
|
+
updatePointList: (sphereList: IPointCloudSphere[]) => void;
|
|
54
57
|
/**
|
|
55
58
|
* Init or Update PointCloud Data
|
|
56
59
|
* @param pcdPath
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* @author Ron <ron.f.luo@gmail.com>
|
|
5
5
|
*/
|
|
6
6
|
import * as THREE from 'three';
|
|
7
|
-
import { TMatrix4Tuple, EPerspectiveView, IVolume, IPointCloudBox, I3DSpaceCoord, IPointCloudConfig } from '@labelbee/lb-utils';
|
|
7
|
+
import { TMatrix4Tuple, EPerspectiveView, IVolume, IPointCloudBox, IPointCloudSphere, I3DSpaceCoord, IPointCloudConfig } from '@labelbee/lb-utils';
|
|
8
8
|
import { OrthographicCamera, PerspectiveCamera, Shader } from 'three';
|
|
9
9
|
import { IPolygonPoint } from '@/types/tool/polygon';
|
|
10
10
|
import { PCDLoader } from './PCDLoader';
|
|
@@ -87,6 +87,13 @@ export declare class PointCloud {
|
|
|
87
87
|
getAllAttributeColor(boxes: IPointCloudBox[]): {
|
|
88
88
|
[k: string]: any;
|
|
89
89
|
};
|
|
90
|
+
/**
|
|
91
|
+
* add new sphere just like adding new box
|
|
92
|
+
* @param sphereParams
|
|
93
|
+
*/
|
|
94
|
+
addSphereToSense: (sphereParams: IPointCloudSphere, color?: string) => void;
|
|
95
|
+
generateSphere: (sphereParams: IPointCloudSphere) => void;
|
|
96
|
+
generateSpheres: (spheres: IPointCloudSphere[]) => void;
|
|
90
97
|
AddBoxToSense: (boxParams: IPointCloudBox, color?: number) => void;
|
|
91
98
|
generateBoxes(boxes: IPointCloudBox[]): void;
|
|
92
99
|
/**
|
|
@@ -111,9 +118,13 @@ export declare class PointCloud {
|
|
|
111
118
|
* @param customCameraVector Provide a custom way.
|
|
112
119
|
*/
|
|
113
120
|
updateCameraByBox(boxParams: IPointCloudBox, perspectiveView: EPerspectiveView, customCameraVector?: I3DSpaceCoord): THREE.Vector3;
|
|
121
|
+
updateCameraBySphere(sphereParams: IPointCloudSphere, perspectiveView: EPerspectiveView): THREE.Vector3;
|
|
114
122
|
updateOrthoCamera(boxParams: IPointCloudBox, perspectiveView: EPerspectiveView): {
|
|
115
123
|
cameraPositionVector: THREE.Vector3;
|
|
116
124
|
};
|
|
125
|
+
updateOrthoCameraBySphere(sphereParams: IPointCloudSphere, perspectiveView: EPerspectiveView): {
|
|
126
|
+
cameraPositionVector: THREE.Vector3;
|
|
127
|
+
};
|
|
117
128
|
/**
|
|
118
129
|
* Initialize the camera to the initial position
|
|
119
130
|
*/
|
|
@@ -188,8 +199,8 @@ export declare class PointCloud {
|
|
|
188
199
|
* 2. Filter out points 10cm above the road surface.
|
|
189
200
|
* 3. Filter out the first 0.5% of noise points in other directions
|
|
190
201
|
*/
|
|
191
|
-
filterNoise(
|
|
192
|
-
getFittedCoordinates(polygon: IPolygonPoint[], innerPointList: ICoordinate[]): import("@labelbee/lb-utils
|
|
202
|
+
filterNoise(innerPointList: I3DSpaceCoord[]): I3DSpaceCoord[];
|
|
203
|
+
getFittedCoordinates(polygon: IPolygonPoint[], innerPointList: ICoordinate[]): import("@labelbee/lb-utils").ICoordinate[];
|
|
193
204
|
getSensesPointZAxisInPolygon(polygon: IPolygonPoint[], zScope?: [number, number], intelligentFit?: boolean): {
|
|
194
205
|
maxZ: number;
|
|
195
206
|
minZ: number;
|
|
@@ -252,6 +263,14 @@ export declare class PointCloud {
|
|
|
252
263
|
polygon2d: THREE.Vector3[];
|
|
253
264
|
zoom: number;
|
|
254
265
|
};
|
|
266
|
+
getSphereSidePoint2DCoordinate(sphereParams: IPointCloudSphere): {
|
|
267
|
+
point2d: THREE.Vector3;
|
|
268
|
+
zoom: number;
|
|
269
|
+
};
|
|
270
|
+
getSphereBackPoint2DCoordinate(sphereParams: IPointCloudSphere): {
|
|
271
|
+
point2d: THREE.Vector3;
|
|
272
|
+
zoom: number;
|
|
273
|
+
};
|
|
255
274
|
boxParams2ViewPolygon(boxParams: IPointCloudBox, perspectiveView: EPerspectiveView): {
|
|
256
275
|
x: number;
|
|
257
276
|
y: number;
|
|
@@ -275,6 +294,17 @@ export declare class PointCloud {
|
|
|
275
294
|
polygon2d: THREE.Vector3[];
|
|
276
295
|
zoom: number;
|
|
277
296
|
};
|
|
297
|
+
getSpherePoint2DCoordinate(sphereParams: IPointCloudSphere): {
|
|
298
|
+
point2d: THREE.Vector3;
|
|
299
|
+
zoom: number;
|
|
300
|
+
};
|
|
301
|
+
getSphereTopPoint2DCoordinate(sphereParams: IPointCloudSphere): {
|
|
302
|
+
point2d: {
|
|
303
|
+
x: number;
|
|
304
|
+
y: number;
|
|
305
|
+
};
|
|
306
|
+
zoom: number;
|
|
307
|
+
};
|
|
278
308
|
getBoxTopPolygon2DCoordinate(boxParams: IPointCloudBox): {
|
|
279
309
|
polygon2d: {
|
|
280
310
|
x: number;
|
|
@@ -325,7 +355,7 @@ export declare class PointCloud {
|
|
|
325
355
|
[k: string]: string;
|
|
326
356
|
} | undefined;
|
|
327
357
|
count?: number | undefined;
|
|
328
|
-
newPointList?: import("@labelbee/lb-utils
|
|
358
|
+
newPointList?: import("@labelbee/lb-utils").ICoordinate[] | undefined;
|
|
329
359
|
};
|
|
330
360
|
} | undefined;
|
|
331
361
|
/**
|
|
@@ -44,7 +44,7 @@ export declare function getCuboidFromPointCloudBox(boxParams: IPointCloudBox): {
|
|
|
44
44
|
[k: string]: string;
|
|
45
45
|
} | undefined;
|
|
46
46
|
count?: number | undefined;
|
|
47
|
-
newPointList?: import("@labelbee/lb-utils
|
|
47
|
+
newPointList?: import("@labelbee/lb-utils").ICoordinate[] | undefined;
|
|
48
48
|
width: number;
|
|
49
49
|
height: number;
|
|
50
50
|
depth: number;
|