@labelbee/lb-annotation 1.14.0-alpha.2 → 1.14.0-alpha.3
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/_virtual/MathUtilsWorker.js +8 -1
- package/dist/_virtual/_rollup-plugin-web-worker-loader__helper__browser__createBase64WorkerFactory.js +35 -2
- package/dist/_virtual/filterBoxWorker.js +8 -1
- package/dist/_virtual/highlightWorker.js +8 -1
- package/dist/assets/attributeIcon/icon_canvasEdit0.svg.js +5 -1
- package/dist/assets/attributeIcon/icon_canvasEdit1.svg.js +5 -1
- package/dist/assets/attributeIcon/icon_canvasEdit2.svg.js +5 -1
- package/dist/assets/attributeIcon/icon_canvasEdit3.svg.js +5 -1
- package/dist/assets/attributeIcon/icon_canvasEdit4.svg.js +5 -1
- package/dist/assets/attributeIcon/icon_canvasEdit5.svg.js +5 -1
- package/dist/assets/attributeIcon/icon_canvasEdit6.svg.js +5 -1
- package/dist/assets/attributeIcon/icon_canvasEdit7.svg.js +5 -1
- package/dist/assets/attributeIcon/icon_canvasEdit8.svg.js +5 -1
- package/dist/assets/attributeIcon/icon_canvasEdit_miss.svg.js +5 -1
- package/dist/assets/attributeIcon/icon_cuboidFAB.svg.js +5 -5
- package/dist/assets/attributeIcon/icon_cuboidLeft.svg.js +5 -7
- package/dist/assets/attributeIcon/icon_cuboidMore.svg.js +5 -5
- package/dist/assets/attributeIcon/icon_cuboidRight.svg.js +5 -5
- package/dist/assets/attributeIcon/icon_cuboidTop.svg.js +5 -12
- package/dist/assets/attributeIcon/icon_editFEN.svg.js +5 -1
- package/dist/assets/attributeIcon/icon_editHUANG.svg.js +5 -1
- package/dist/assets/attributeIcon/icon_editLAN.svg.js +5 -1
- package/dist/assets/attributeIcon/icon_editLV.svg.js +5 -1
- package/dist/assets/attributeIcon/icon_editQING.svg.js +5 -1
- package/dist/constant/annotation.js +127 -1
- package/dist/constant/annotationTask.js +30 -1
- package/dist/constant/defaultConfig.js +266 -1
- package/dist/constant/keyCode.js +38 -1
- package/dist/constant/style.js +98 -1
- package/dist/constant/tool.js +236 -1
- package/dist/core/index.js +150 -1
- package/dist/core/pointCloud/OrbitControls.js +665 -1
- package/dist/core/pointCloud/PCDLoader.js +260 -2
- package/dist/core/pointCloud/annotation.js +215 -1
- package/dist/core/pointCloud/cache.js +53 -1
- package/dist/core/pointCloud/index.js +991 -5
- package/dist/core/pointCloud/matrix.js +138 -1
- package/dist/core/pointCloud/segmentation.js +144 -0
- package/dist/core/pointCloud/selector/Sse3dLassoSelector.js +26 -0
- package/dist/core/pointCloud/selector/Sse3dSelector.js +16 -0
- package/dist/core/scheduler.js +233 -1
- package/dist/core/toolOperation/LineToolOperation.js +1434 -1
- package/dist/core/toolOperation/ScribbleTool.js +292 -1
- package/dist/core/toolOperation/TextToolOperation.js +131 -1
- package/dist/core/toolOperation/ViewOperation.js +556 -1
- package/dist/core/toolOperation/basicToolOperation.js +881 -1
- package/dist/core/toolOperation/checkOperation.js +208 -1
- package/dist/core/toolOperation/cuboidOperation.js +754 -1
- package/dist/core/toolOperation/cuboidToggleButtonClass.js +152 -7
- package/dist/core/toolOperation/eventListener.js +37 -1
- package/dist/core/toolOperation/measureOperation.js +41 -1
- package/dist/core/toolOperation/pointCloud2dOperation.js +365 -1
- package/dist/core/toolOperation/pointOperation.js +696 -1
- package/dist/core/toolOperation/polygonOperation.js +1251 -1
- package/dist/core/toolOperation/rectOperation.js +1233 -1
- package/dist/core/toolOperation/segmentByRect.js +174 -1
- package/dist/core/toolOperation/tagOperation.js +201 -3
- package/dist/core/toolOperation/textAttributeClass.js +182 -16
- package/dist/index.js +185 -1
- package/dist/locales/constants.js +24 -1
- package/dist/locales/en_US/message.js +25 -1
- package/dist/locales/index.js +19 -1
- package/dist/locales/zh_CN/message.js +25 -1
- package/dist/newCore/CanvasScheduler.js +35 -1
- package/dist/types/core/pointCloud/segmentation.d.ts +0 -0
- package/dist/types/core/pointCloud/selector/Sse3dLassoSelector.d.ts +0 -0
- package/dist/types/core/pointCloud/selector/Sse3dSelector.d.ts +0 -0
- package/dist/utils/ActionsHistory.js +84 -1
- package/dist/utils/ImgUtils.js +23 -1
- package/dist/utils/MathUtils.js +385 -2
- package/dist/utils/VectorUtils.js +25 -1
- package/dist/utils/tool/AttributeUtils.js +218 -1
- package/dist/utils/tool/AxisUtils.js +340 -1
- package/dist/utils/tool/CanvasUtils.js +62 -1
- package/dist/utils/tool/CommonToolUtils.js +174 -1
- package/dist/utils/tool/CuboidUtils.js +704 -1
- package/dist/utils/tool/DblClickEventListener.js +102 -1
- package/dist/utils/tool/DrawUtils.js +492 -3
- package/dist/utils/tool/EnhanceCommonToolUtils.js +53 -1
- package/dist/utils/tool/ImgPosUtils.js +58 -1
- package/dist/utils/tool/LineToolUtils.js +261 -1
- package/dist/utils/tool/MarkerUtils.js +56 -1
- package/dist/utils/tool/PolygonUtils.js +460 -1
- package/dist/utils/tool/RectUtils.js +155 -1
- package/dist/utils/tool/RenderDomClass.js +57 -7
- package/dist/utils/tool/RenderDomUtils.js +21 -4
- package/dist/utils/tool/StyleUtils.js +31 -1
- package/dist/utils/tool/TagUtils.js +129 -1
- package/dist/utils/tool/UnitUtils.js +12 -1
- package/dist/utils/tool/ZoomUtils.js +72 -1
- package/dist/utils/tool/polygonTool.js +133 -1
- package/dist/utils/uuid.js +26 -1
- package/es/_virtual/MathUtilsWorker.js +6 -1
- package/es/_virtual/_rollup-plugin-web-worker-loader__helper__auto__createBase64WorkerFactory.js +12 -0
- package/es/_virtual/_rollup-plugin-web-worker-loader__helper__auto__isNodeJS.js +7 -0
- package/es/_virtual/_rollup-plugin-web-worker-loader__helper__browser__createBase64WorkerFactory.js +31 -2
- package/es/_virtual/_rollup-plugin-web-worker-loader__helper__node__WorkerClass.js +11 -0
- package/es/_virtual/_rollup-plugin-web-worker-loader__helper__node__createBase64WorkerFactory.js +18 -0
- package/es/_virtual/filterBoxWorker.js +6 -1
- package/es/_virtual/highlightWorker.js +6 -1
- package/es/assets/attributeIcon/icon_canvasEdit0.svg.js +3 -1
- package/es/assets/attributeIcon/icon_canvasEdit1.svg.js +3 -1
- package/es/assets/attributeIcon/icon_canvasEdit2.svg.js +3 -1
- package/es/assets/attributeIcon/icon_canvasEdit3.svg.js +3 -1
- package/es/assets/attributeIcon/icon_canvasEdit4.svg.js +3 -1
- package/es/assets/attributeIcon/icon_canvasEdit5.svg.js +3 -1
- package/es/assets/attributeIcon/icon_canvasEdit6.svg.js +3 -1
- package/es/assets/attributeIcon/icon_canvasEdit7.svg.js +3 -1
- package/es/assets/attributeIcon/icon_canvasEdit8.svg.js +3 -1
- package/es/assets/attributeIcon/icon_canvasEdit_miss.svg.js +3 -1
- package/es/assets/attributeIcon/icon_cuboidFAB.svg.js +3 -5
- package/es/assets/attributeIcon/icon_cuboidLeft.svg.js +3 -7
- package/es/assets/attributeIcon/icon_cuboidMore.svg.js +3 -5
- package/es/assets/attributeIcon/icon_cuboidRight.svg.js +3 -5
- package/es/assets/attributeIcon/icon_cuboidTop.svg.js +3 -12
- package/es/assets/attributeIcon/icon_editFEN.svg.js +3 -1
- package/es/assets/attributeIcon/icon_editHUANG.svg.js +3 -1
- package/es/assets/attributeIcon/icon_editLAN.svg.js +3 -1
- package/es/assets/attributeIcon/icon_editLV.svg.js +3 -1
- package/es/assets/attributeIcon/icon_editQING.svg.js +3 -1
- package/es/constant/annotation.js +113 -1
- package/es/constant/annotationTask.js +25 -1
- package/es/constant/defaultConfig.js +260 -1
- package/es/constant/keyCode.js +36 -1
- package/es/constant/style.js +74 -1
- package/es/constant/tool.js +220 -1
- package/es/core/index.js +148 -1
- package/es/core/pointCloud/OrbitControls.js +661 -1
- package/es/core/pointCloud/PCDLoader.js +256 -2
- package/es/core/pointCloud/annotation.js +211 -1
- package/es/core/pointCloud/cache.js +49 -1
- package/es/core/pointCloud/index.js +962 -5
- package/es/core/pointCloud/matrix.js +109 -1
- package/es/core/pointCloud/segmentation.js +120 -0
- package/es/core/pointCloud/selector/Sse3dLassoSelector.js +24 -0
- package/es/core/pointCloud/selector/Sse3dSelector.js +14 -0
- package/es/core/scheduler.js +228 -1
- package/es/core/toolOperation/LineToolOperation.js +1421 -1
- package/es/core/toolOperation/ScribbleTool.js +290 -1
- package/es/core/toolOperation/TextToolOperation.js +129 -1
- package/es/core/toolOperation/ViewOperation.js +549 -1
- package/es/core/toolOperation/basicToolOperation.js +877 -1
- package/es/core/toolOperation/checkOperation.js +206 -1
- package/es/core/toolOperation/cuboidOperation.js +752 -1
- package/es/core/toolOperation/cuboidToggleButtonClass.js +150 -7
- package/es/core/toolOperation/eventListener.js +35 -1
- package/es/core/toolOperation/measureOperation.js +39 -1
- package/es/core/toolOperation/pointCloud2dOperation.js +359 -1
- package/es/core/toolOperation/pointOperation.js +690 -1
- package/es/core/toolOperation/polygonOperation.js +1245 -1
- package/es/core/toolOperation/rectOperation.js +1228 -1
- package/es/core/toolOperation/scribbleTool2.js +249 -0
- package/es/core/toolOperation/segmentByRect.js +172 -1
- package/es/core/toolOperation/tagOperation.js +199 -3
- package/es/core/toolOperation/textAttributeClass.js +180 -16
- package/es/index.js +46 -1
- package/es/locales/constants.js +22 -1
- package/es/locales/en_US/message.js +23 -1
- package/es/locales/index.js +17 -1
- package/es/locales/zh_CN/message.js +23 -1
- package/es/newCore/CanvasScheduler.js +31 -1
- package/es/utils/ActionsHistory.js +78 -1
- package/es/utils/ImgUtils.js +21 -1
- package/es/utils/MathUtils.js +380 -2
- package/es/utils/VectorUtils.js +23 -1
- package/es/utils/tool/AttributeUtils.js +212 -1
- package/es/utils/tool/AxisUtils.js +335 -1
- package/es/utils/tool/CanvasUtils.js +60 -1
- package/es/utils/tool/CommonToolUtils.js +172 -1
- package/es/utils/tool/CuboidUtils.js +680 -1
- package/es/utils/tool/DblClickEventListener.js +100 -1
- package/es/utils/tool/DrawUtils.js +490 -3
- package/es/utils/tool/EnhanceCommonToolUtils.js +48 -1
- package/es/utils/tool/ImgPosUtils.js +56 -1
- package/es/utils/tool/LineToolUtils.js +255 -1
- package/es/utils/tool/MarkerUtils.js +54 -1
- package/es/utils/tool/PolygonUtils.js +458 -1
- package/es/utils/tool/RectUtils.js +153 -1
- package/es/utils/tool/RenderDomClass.js +55 -7
- package/es/utils/tool/RenderDomUtils.js +19 -4
- package/es/utils/tool/StyleUtils.js +29 -1
- package/es/utils/tool/TagUtils.js +127 -1
- package/es/utils/tool/UnitUtils.js +10 -1
- package/es/utils/tool/ZoomUtils.js +70 -1
- package/es/utils/tool/polygonTool.js +126 -1
- package/es/utils/uuid.js +24 -1
- package/package.json +7 -5
|
@@ -1 +1,549 @@
|
|
|
1
|
-
import M from"lodash";import E from"color-rgba";import h from"../../utils/tool/DrawUtils.js";import b from"../../utils/tool/AxisUtils.js";import Z from"../../utils/tool/RectUtils.js";import $ from"../../utils/tool/PolygonUtils.js";import C from"../../utils/MathUtils.js";import W from"../../utils/tool/RenderDomClass.js";import{ELineTypes as L,DEFAULT_FONT as j,SEGMENT_NUMBER as F}from"../../constant/tool.js";import{DEFAULT_TEXT_OFFSET as B,TEXT_ATTRIBUTE_OFFSET as A,DEFAULT_TEXT_SHADOW as H}from"../../constant/annotation.js";import N from"../../utils/tool/ImgPosUtils.js";import{BasicToolOperation as K}from"./basicToolOperation.js";import{pointCloudLidar2image as V}from"../pointCloud/matrix.js";var X=Object.defineProperty,G=Object.defineProperties,Y=Object.getOwnPropertyDescriptors,U=Object.getOwnPropertySymbols,q=Object.prototype.hasOwnProperty,J=Object.prototype.propertyIsEnumerable,z=(P,t,e)=>t in P?X(P,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):P[t]=e,p=(P,t)=>{for(var e in t||(t={}))q.call(t,e)&&z(P,e,t[e]);if(U)for(var e of U(t))J.call(t,e)&&z(P,e,t[e]);return P},_=(P,t)=>G(P,Y(t));const Q=3,tt=3,I="#6371FF";class et extends K{constructor(t){super(_(p({},t),{showDefaultCursor:!0}));this.style={},this.annotations=[],this.connectionPoints=[],this.getHoverRectID=o=>{var i,r;const c=this.getCoordinateUnderZoom(o),n=b.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 d="",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 u=a.annotation;if(Z.isInRect(c,u,Q,this.zoom)){const f=u.width*u.height;f<s&&(d=u.id,s=f)}break}case"polygon":{const u=a.annotation;if($.isInPolygon(n,u.pointList)){const f=$.getPolygonArea(u.pointList);f<s&&(d=u.id,s=f)}break}}}return d};var e;this.style=(e=t.style)!=null?e:{stroke:I,thickness:3},this.annotations=t.annotations,this.loading=!1,this.renderDomInstance=new W({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}=C.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=M.pick(t,["stroke","thickness","fill","radius"]),o=p(p({},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 _(p({},H),{color:e.stroke,font:`normal normal 600 ${r}px ${c}`})}appendOffset({x:t,y:e}){return{x:t+B.offsetX,y:e+B.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=C.calcViewportBoundaries(t),o={x:e.left,y:e.top,width:e.right-e.left,height:e.bottom-e.top},i=N.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(_(p({},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=b.changePointByZoom(t,this.zoom,this.currentPos);h.drawCircleWithFill(this.canvas,e,4,{color:"#fff"}),h.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:d=L.Line}=n,s=b.changePointListByZoom((o=n==null?void 0:n.pointList)!=null?o:[],this.zoom,this.currentPos),l=_(p(p({},r),this.getReferenceOptions(n==null?void 0:n.isReference)),{lineType:d,strokeColor:r.stroke});let a=[];if(n.showKeyPoint?a=h.drawPolygonWithKeyPoint(this.canvas,s,l):a=h.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 v=s[0],m=C.getLineCenterPoint([s[0],s[1]]);if(d===L.Curve){const g=Math.floor(F/2);v=a[g],m=a[g+1]}h.drawArrowByCanvas(this.canvas,v,m,{color:r.stroke,thickness:r.thickness}),h.drawCircle(this.canvas,s[0],r.thickness+6,{color:r.stroke,thickness:r.thickness})}const{headerText:f,bottomText:y}=this.getRenderText(n,n==null?void 0:n.hiddenText);if(f&&h.drawText(this.canvas,this.appendOffset(s[0]),f,c),y){const v=s[s.length-1];h.drawText(this.canvas,this.appendOffset({x:v.x+A.x,y:v.y+A.y}),y,c)}}renderPolygon(t){var e,o,i,r,c;if(t.type!=="polygon")return;const{style:n,fontStyle:d}=this.getRenderStyle(t),s=t.annotation;if(!(((e=s==null?void 0:s.pointList)==null?void 0:e.length)>=3))return;const{lineType:l=L.Line}=s,a=b.changePointListByZoom((o=s==null?void 0:s.pointList)!=null?o:[],this.zoom,this.currentPos);if(s.id===this.mouseHoverID||n.fill){const g=E((r=(i=n==null?void 0:n.fill)!=null?i:n==null?void 0:n.stroke)!=null?r:I),x=`rgba(${g[0]}, ${g[1]}, ${g[2]},${g[3]*.8})`;h.drawPolygonWithFill(this.canvas,a,{color:x,lineType:l})}const u=_(p(_(p({},n),{isClose:!0}),this.getReferenceOptions(s==null?void 0:s.isReference)),{lineType:l,strokeColor:n.stroke});let f=[];if(s.showKeyPoint?f=h.drawPolygonWithKeyPoint(this.canvas,a,u):f=h.drawPolygon(this.canvas,a,u),(s==null?void 0:s.showDirection)===!0&&((c=s==null?void 0:s.pointList)==null?void 0:c.length)>=2){let g=a[0],x=C.getLineCenterPoint([a[0],a[1]]);if(l===L.Curve){const w=Math.floor(F/2);g=f[w],x=f[w+1]}h.drawArrowByCanvas(this.canvas,g,x,{color:n.stroke,thickness:n.thickness}),h.drawCircle(this.canvas,a[0],n.thickness+6,{color:n.stroke,thickness:n.thickness})}const{headerText:v,bottomText:m}=this.getRenderText(s,s==null?void 0:s.hiddenText);if(v&&h.drawText(this.canvas,this.appendOffset(a[0]),v,d),m){const g=a[a.length-1];h.drawText(this.canvas,this.appendOffset({x:g.x+A.x,y:g.y+A.y}),m,d)}}renderSingleCuboid(t){var e,o;const{style:i}=this.getRenderStyle(t),r=t.annotation,c=E((o=(e=i==null?void 0:i.fill)!=null?e:i==null?void 0:i.stroke)!=null?o:I),n=`rgba(${c[0]}, ${c[1]}, ${c[2]},${c[3]*.8})`,d=i.stroke,s=b.changeCuboidByZoom(r,this.zoom,this.currentPos),{headerText:l,bottomText:a}=this.getRenderText(r,r==null?void 0:r.hiddenText);h.drawCuboidWithText(this.canvas,s,{strokeColor:d,fillColor:n,thickness:i.thickness},{config:this.config,hiddenText:r==null?void 0:r.hiddenText,headerText:l,bottomText:a})}renderBox3d(t){if(t.type!=="box3d")return;const e=t.annotation,o=V(e,e.calib),i={fill:"transparent"},r=M.pick(e,["stroke","thickness"]);o.forEach((c,n)=>{const d=p(_(p({},r),{id:`${t.annotation.id}-${n}`,pointList:c.pointList}),i);switch(c.type){case"line":this.renderLine({type:"line",annotation:d});break;case"polygon":this.renderPolygon({type:"polygon",annotation:d});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 d=this.getSpecificStyle(e.annotation),s=this.getFontStyle(e.annotation,d);switch(e.type){case"rect":{const l=e.annotation,{hiddenText:a=!1,isReference:u,hiddenRectSize:f=!1}=l,{zoom:y}=this,v=b.changeRectByZoom(l,this.zoom,this.currentPos),{x:m,y:g,width:x,height:w}=v;if(l.id===this.mouseHoverID||d.fill){const T=E((i=(o=d==null?void 0:d.fill)!=null?o:d==null?void 0:d.stroke)!=null?i:I),D=`rgba(${T[0]}, ${T[1]}, ${T[2]},${T[3]*.8})`;h.drawRectWithFill(this.canvas,v,{color:D})}h.drawRect(this.canvas,v,p(_(p({},d),{hiddenText:!0}),this.getReferenceOptions(u)));const{headerText:S,bottomText:R}=this.getRenderText(l,l==null?void 0:l.hiddenText);S&&h.drawText(this.canvas,{x:m,y:g-6},S,p({textMaxWidth:300},s));const k=`${Math.round(x/y)} * ${Math.round(w/y)}`,O=k.length*7;if(!a&&!f&&h.drawText(this.canvas,{x:m+x-O,y:g+w+15},k,s),R){const T=20,D=Math.max(20,x-O);h.drawText(this.canvas,{x:m,y:g+w+T},l.textAttribute,p({textMaxWidth:D},s))}break}case"polygon":{this.renderPolygon(e);break}case"line":{this.renderLine(e);break}case"point":{const l=e.annotation,a=b.changePointByZoom(l,this.zoom,this.currentPos),u=(r=d.radius)!=null?r:tt;h.drawCircle(this.canvas,a,u,d);const{headerText:f,bottomText:y}=this.getRenderText(l,l==null?void 0:l.hiddenText);f&&h.drawText(this.canvas,{x:a.x+u/2,y:a.y-u-4},f,p({textAlign:"center"},s)),y&&h.drawText(this.canvas,this.appendOffset({x:a.x+u,y:a.y+u+24}),y,s);break}case"text":{const l=e.annotation,{text:a,x:u,y:f,textMaxWidth:y,color:v="white",background:m="rgba(0, 0, 0, 0.6)",lineHeight:g=25,font:x=j,position:w}=l,S=10,R=10,k=b.changePointByZoom({x:u,y:f},this.zoom,this.currentPos),{width:O,height:T,fontHeight:D=0}=C.getTextArea(this.canvas,l.text,y,x,g);if(w==="rt")break;h.drawRectWithFill(this.canvas,{x:k.x,y:k.y,width:O+R*2,height:T+S*2,id:"",sourceID:"",valid:!0,textAttribute:"",attribute:""},{color:m}),h.drawText(this.canvas,{x:k.x+R,y:k.y+D+S},a,{color:v,lineHeight:g,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)}}}export{et as default};
|
|
1
|
+
import _ from 'lodash';
|
|
2
|
+
import rgba from 'color-rgba';
|
|
3
|
+
import DrawUtils from '../../utils/tool/DrawUtils.js';
|
|
4
|
+
import AxisUtils from '../../utils/tool/AxisUtils.js';
|
|
5
|
+
import RectUtils from '../../utils/tool/RectUtils.js';
|
|
6
|
+
import PolygonUtils from '../../utils/tool/PolygonUtils.js';
|
|
7
|
+
import MathUtils from '../../utils/MathUtils.js';
|
|
8
|
+
import RenderDomClass from '../../utils/tool/RenderDomClass.js';
|
|
9
|
+
import { ELineTypes, DEFAULT_FONT, SEGMENT_NUMBER } from '../../constant/tool.js';
|
|
10
|
+
import { DEFAULT_TEXT_OFFSET, TEXT_ATTRIBUTE_OFFSET, DEFAULT_TEXT_SHADOW } from '../../constant/annotation.js';
|
|
11
|
+
import ImgPosUtils from '../../utils/tool/ImgPosUtils.js';
|
|
12
|
+
import { BasicToolOperation } from './basicToolOperation.js';
|
|
13
|
+
import { pointCloudLidar2image } from '../pointCloud/matrix.js';
|
|
14
|
+
|
|
15
|
+
var __defProp = Object.defineProperty;
|
|
16
|
+
var __defProps = Object.defineProperties;
|
|
17
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
18
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
19
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
20
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
21
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, {enumerable: true, configurable: true, writable: true, value}) : obj[key] = value;
|
|
22
|
+
var __spreadValues = (a, b) => {
|
|
23
|
+
for (var prop in b || (b = {}))
|
|
24
|
+
if (__hasOwnProp.call(b, prop))
|
|
25
|
+
__defNormalProp(a, prop, b[prop]);
|
|
26
|
+
if (__getOwnPropSymbols)
|
|
27
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
28
|
+
if (__propIsEnum.call(b, prop))
|
|
29
|
+
__defNormalProp(a, prop, b[prop]);
|
|
30
|
+
}
|
|
31
|
+
return a;
|
|
32
|
+
};
|
|
33
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
34
|
+
const newScope = 3;
|
|
35
|
+
const DEFAULT_RADIUS = 3;
|
|
36
|
+
const DEFAULT_STROKE_COLOR = "#6371FF";
|
|
37
|
+
class ViewOperation extends BasicToolOperation {
|
|
38
|
+
constructor(props) {
|
|
39
|
+
super(__spreadProps(__spreadValues({}, props), {showDefaultCursor: true}));
|
|
40
|
+
this.style = {};
|
|
41
|
+
this.annotations = [];
|
|
42
|
+
this.connectionPoints = [];
|
|
43
|
+
this.getHoverRectID = (e) => {
|
|
44
|
+
var _a, _b;
|
|
45
|
+
const coordinate = this.getCoordinateUnderZoom(e);
|
|
46
|
+
const originCoordinate = AxisUtils.changePointByZoom(coordinate, 1 / this.zoom);
|
|
47
|
+
if (((_a = this.annotations) == null ? void 0 : _a.length) <= 0 || !((_b = this.annotations) == null ? void 0 : _b.length)) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
let id = "";
|
|
51
|
+
let minArea = Number.MAX_SAFE_INTEGER;
|
|
52
|
+
for (let i = 0; i < this.annotations.length; i++) {
|
|
53
|
+
const annotation = this.annotations[i];
|
|
54
|
+
switch (annotation.type) {
|
|
55
|
+
case "rect": {
|
|
56
|
+
const rect = annotation.annotation;
|
|
57
|
+
if (RectUtils.isInRect(coordinate, rect, newScope, this.zoom)) {
|
|
58
|
+
const area = rect.width * rect.height;
|
|
59
|
+
if (area < minArea) {
|
|
60
|
+
id = rect.id;
|
|
61
|
+
minArea = area;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
break;
|
|
65
|
+
}
|
|
66
|
+
case "polygon": {
|
|
67
|
+
const polygon = annotation.annotation;
|
|
68
|
+
if (PolygonUtils.isInPolygon(originCoordinate, polygon.pointList)) {
|
|
69
|
+
const area = PolygonUtils.getPolygonArea(polygon.pointList);
|
|
70
|
+
if (area < minArea) {
|
|
71
|
+
id = polygon.id;
|
|
72
|
+
minArea = area;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
break;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return id;
|
|
80
|
+
};
|
|
81
|
+
var _a;
|
|
82
|
+
this.style = (_a = props.style) != null ? _a : {stroke: DEFAULT_STROKE_COLOR, thickness: 3};
|
|
83
|
+
this.annotations = props.annotations;
|
|
84
|
+
this.loading = false;
|
|
85
|
+
this.renderDomInstance = new RenderDomClass({
|
|
86
|
+
container: this.container,
|
|
87
|
+
height: this.canvas.height
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
clearConnectionPoints() {
|
|
91
|
+
this.connectionPoints = [];
|
|
92
|
+
this.render();
|
|
93
|
+
}
|
|
94
|
+
checkConnectionPoints(newAnnotations = this.annotations) {
|
|
95
|
+
var _a, _b;
|
|
96
|
+
if (this.connectPointsStatus) {
|
|
97
|
+
(_b = (_a = this.connectPointsStatus).close) == null ? void 0 : _b.call(_a);
|
|
98
|
+
}
|
|
99
|
+
this.emit("connectionPointsStatusUpdate", () => {
|
|
100
|
+
return new Promise((resolve) => {
|
|
101
|
+
const {promise, close} = MathUtils.getCollectionPointByAnnotationDataPromise(newAnnotations);
|
|
102
|
+
this.connectPointsStatus = {
|
|
103
|
+
close
|
|
104
|
+
};
|
|
105
|
+
promise.then((res) => {
|
|
106
|
+
this.connectionPoints = res.connectionPoints;
|
|
107
|
+
this.render();
|
|
108
|
+
this.connectPointsStatus = void 0;
|
|
109
|
+
resolve({connectionPoints: res.connectionPoints});
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
setLoading(loading) {
|
|
115
|
+
this.loading = loading;
|
|
116
|
+
this.render();
|
|
117
|
+
}
|
|
118
|
+
onMouseLeave() {
|
|
119
|
+
super.onMouseLeave();
|
|
120
|
+
this.mouseHoverID = void 0;
|
|
121
|
+
this.emit("onChange", "hover", []);
|
|
122
|
+
}
|
|
123
|
+
onMouseDown(e) {
|
|
124
|
+
if (super.onMouseDown(e) || this.forbidMouseOperation || !this.imgInfo) {
|
|
125
|
+
return true;
|
|
126
|
+
}
|
|
127
|
+
const newMouseSelectedID = this.mouseHoverID;
|
|
128
|
+
if (e.button === 0) {
|
|
129
|
+
let selectedID = [];
|
|
130
|
+
if (newMouseSelectedID) {
|
|
131
|
+
selectedID = [newMouseSelectedID];
|
|
132
|
+
}
|
|
133
|
+
this.emit("onChange", "selected", selectedID);
|
|
134
|
+
this.render();
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
onMouseMove(e) {
|
|
138
|
+
if (super.onMouseMove(e) || this.forbidMouseOperation || !this.imgInfo) {
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
const oldMouseHoverID = this.mouseHoverID;
|
|
142
|
+
const newMouseHoverID = this.getHoverRectID(e);
|
|
143
|
+
if (oldMouseHoverID !== newMouseHoverID) {
|
|
144
|
+
this.mouseHoverID = newMouseHoverID;
|
|
145
|
+
let hoverID = [];
|
|
146
|
+
if (newMouseHoverID) {
|
|
147
|
+
hoverID = [newMouseHoverID];
|
|
148
|
+
}
|
|
149
|
+
this.emit("onChange", "hover", hoverID);
|
|
150
|
+
this.render();
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
updateData(annotations) {
|
|
154
|
+
this.annotations = annotations;
|
|
155
|
+
this.render();
|
|
156
|
+
}
|
|
157
|
+
getSpecificStyle(obj) {
|
|
158
|
+
const specificStyle = _.pick(obj, ["stroke", "thickness", "fill", "radius"]);
|
|
159
|
+
const newStyle = __spreadValues(__spreadValues({}, this.style), specificStyle);
|
|
160
|
+
if (newStyle.stroke) {
|
|
161
|
+
Object.assign(newStyle, {
|
|
162
|
+
color: newStyle.stroke
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
return newStyle;
|
|
166
|
+
}
|
|
167
|
+
getFontStyle(obj, style) {
|
|
168
|
+
var _a, _b;
|
|
169
|
+
const fontSize = (_a = obj == null ? void 0 : obj.fontSize) != null ? _a : 14;
|
|
170
|
+
const fontFamily = (_b = obj == null ? void 0 : obj.fontFamily) != null ? _b : "Arial";
|
|
171
|
+
return __spreadProps(__spreadValues({}, DEFAULT_TEXT_SHADOW), {
|
|
172
|
+
color: style.stroke,
|
|
173
|
+
font: `normal normal 600 ${fontSize}px ${fontFamily}`
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
appendOffset({x, y}) {
|
|
177
|
+
return {x: x + DEFAULT_TEXT_OFFSET.offsetX, y: y + DEFAULT_TEXT_OFFSET.offsetY};
|
|
178
|
+
}
|
|
179
|
+
getRenderText(result, hiddenText = false) {
|
|
180
|
+
let headerText = "";
|
|
181
|
+
let bottomText = "";
|
|
182
|
+
if (!result || hiddenText === true) {
|
|
183
|
+
return {headerText, bottomText};
|
|
184
|
+
}
|
|
185
|
+
if (result == null ? void 0 : result.order) {
|
|
186
|
+
headerText = `${result.order}`;
|
|
187
|
+
}
|
|
188
|
+
if (result == null ? void 0 : result.label) {
|
|
189
|
+
if (headerText) {
|
|
190
|
+
headerText = `${headerText}_${result.label}`;
|
|
191
|
+
} else {
|
|
192
|
+
headerText = `${result.label}`;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
if (result == null ? void 0 : result.attribute) {
|
|
196
|
+
if (headerText) {
|
|
197
|
+
headerText = `${headerText} ${result.attribute}`;
|
|
198
|
+
} else {
|
|
199
|
+
headerText = `${result.attribute}`;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
if (result == null ? void 0 : result.textAttribute) {
|
|
203
|
+
bottomText = result == null ? void 0 : result.textAttribute;
|
|
204
|
+
}
|
|
205
|
+
return {headerText, bottomText};
|
|
206
|
+
}
|
|
207
|
+
getReferenceOptions(isReference) {
|
|
208
|
+
return isReference ? {lineCap: "butt", lineDash: [20, 20]} : {};
|
|
209
|
+
}
|
|
210
|
+
focusPositionByPointList(pointList) {
|
|
211
|
+
const basicZone = MathUtils.calcViewportBoundaries(pointList);
|
|
212
|
+
const newBoundary = {
|
|
213
|
+
x: basicZone.left,
|
|
214
|
+
y: basicZone.top,
|
|
215
|
+
width: basicZone.right - basicZone.left,
|
|
216
|
+
height: basicZone.bottom - basicZone.top
|
|
217
|
+
};
|
|
218
|
+
const pos = ImgPosUtils.getBasicRecPos(this.imgNode, newBoundary, this.size, 0.5);
|
|
219
|
+
if (pos) {
|
|
220
|
+
this.setCurrentPos(pos.currentPos);
|
|
221
|
+
this.setCurrentPosStorage(pos.currentPos);
|
|
222
|
+
const {imgInfo} = this;
|
|
223
|
+
const {innerZoom} = this.innerPosAndZoom;
|
|
224
|
+
if (imgInfo) {
|
|
225
|
+
this.setImgInfo(__spreadProps(__spreadValues({}, imgInfo), {
|
|
226
|
+
width: imgInfo.width / innerZoom * pos.innerZoom,
|
|
227
|
+
height: imgInfo.height / innerZoom * pos.innerZoom
|
|
228
|
+
}));
|
|
229
|
+
}
|
|
230
|
+
this.setZoom(pos.innerZoom);
|
|
231
|
+
this.render();
|
|
232
|
+
this.renderBasicCanvas();
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
renderConnectionPoints() {
|
|
236
|
+
this.connectionPoints.forEach((point) => {
|
|
237
|
+
const renderPoint = AxisUtils.changePointByZoom(point, this.zoom, this.currentPos);
|
|
238
|
+
DrawUtils.drawCircleWithFill(this.canvas, renderPoint, 4, {color: "#fff"});
|
|
239
|
+
DrawUtils.drawCircleWithFill(this.canvas, renderPoint, 2, {color: "#000"});
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
getRenderStyle(annotation) {
|
|
243
|
+
const style = this.getSpecificStyle(annotation.annotation);
|
|
244
|
+
const fontStyle = this.getFontStyle(annotation.annotation, style);
|
|
245
|
+
return {
|
|
246
|
+
style,
|
|
247
|
+
fontStyle
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
renderLine(annotation) {
|
|
251
|
+
var _a, _b, _c;
|
|
252
|
+
if (annotation.type !== "line") {
|
|
253
|
+
return;
|
|
254
|
+
}
|
|
255
|
+
const {style, fontStyle} = this.getRenderStyle(annotation);
|
|
256
|
+
const line = annotation.annotation;
|
|
257
|
+
if (!(((_a = line == null ? void 0 : line.pointList) == null ? void 0 : _a.length) >= 2)) {
|
|
258
|
+
return;
|
|
259
|
+
}
|
|
260
|
+
const {lineType = ELineTypes.Line} = line;
|
|
261
|
+
const renderLineWithZoom = AxisUtils.changePointListByZoom((_b = line == null ? void 0 : line.pointList) != null ? _b : [], this.zoom, this.currentPos);
|
|
262
|
+
const lineRenderOptions = __spreadProps(__spreadValues(__spreadValues({}, style), this.getReferenceOptions(line == null ? void 0 : line.isReference)), {
|
|
263
|
+
lineType,
|
|
264
|
+
strokeColor: style.stroke
|
|
265
|
+
});
|
|
266
|
+
let newPointList = [];
|
|
267
|
+
if (line.showKeyPoint) {
|
|
268
|
+
newPointList = DrawUtils.drawPolygonWithKeyPoint(this.canvas, renderLineWithZoom, lineRenderOptions);
|
|
269
|
+
} else {
|
|
270
|
+
newPointList = DrawUtils.drawPolygon(this.canvas, renderLineWithZoom, lineRenderOptions);
|
|
271
|
+
}
|
|
272
|
+
const isShowDirection = (line == null ? void 0 : line.showDirection) === true && ((_c = line == null ? void 0 : line.pointList) == null ? void 0 : _c.length) >= 2;
|
|
273
|
+
if (isShowDirection) {
|
|
274
|
+
let startPoint = renderLineWithZoom[0];
|
|
275
|
+
let endPoint = MathUtils.getLineCenterPoint([renderLineWithZoom[0], renderLineWithZoom[1]]);
|
|
276
|
+
if (lineType === ELineTypes.Curve) {
|
|
277
|
+
const pos = Math.floor(SEGMENT_NUMBER / 2);
|
|
278
|
+
startPoint = newPointList[pos];
|
|
279
|
+
endPoint = newPointList[pos + 1];
|
|
280
|
+
}
|
|
281
|
+
DrawUtils.drawArrowByCanvas(this.canvas, startPoint, endPoint, {
|
|
282
|
+
color: style.stroke,
|
|
283
|
+
thickness: style.thickness
|
|
284
|
+
});
|
|
285
|
+
DrawUtils.drawCircle(this.canvas, renderLineWithZoom[0], style.thickness + 6, {
|
|
286
|
+
color: style.stroke,
|
|
287
|
+
thickness: style.thickness
|
|
288
|
+
});
|
|
289
|
+
}
|
|
290
|
+
const {headerText, bottomText} = this.getRenderText(line, line == null ? void 0 : line.hiddenText);
|
|
291
|
+
if (headerText) {
|
|
292
|
+
DrawUtils.drawText(this.canvas, this.appendOffset(renderLineWithZoom[0]), headerText, fontStyle);
|
|
293
|
+
}
|
|
294
|
+
if (bottomText) {
|
|
295
|
+
const endPoint = renderLineWithZoom[renderLineWithZoom.length - 1];
|
|
296
|
+
DrawUtils.drawText(this.canvas, this.appendOffset({x: endPoint.x + TEXT_ATTRIBUTE_OFFSET.x, y: endPoint.y + TEXT_ATTRIBUTE_OFFSET.y}), bottomText, fontStyle);
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
renderPolygon(annotation) {
|
|
300
|
+
var _a, _b, _c, _d, _e;
|
|
301
|
+
if (annotation.type !== "polygon") {
|
|
302
|
+
return;
|
|
303
|
+
}
|
|
304
|
+
const {style, fontStyle} = this.getRenderStyle(annotation);
|
|
305
|
+
const polygon = annotation.annotation;
|
|
306
|
+
if (!(((_a = polygon == null ? void 0 : polygon.pointList) == null ? void 0 : _a.length) >= 3)) {
|
|
307
|
+
return;
|
|
308
|
+
}
|
|
309
|
+
const {lineType = ELineTypes.Line} = polygon;
|
|
310
|
+
const renderPolygon = AxisUtils.changePointListByZoom((_b = polygon == null ? void 0 : polygon.pointList) != null ? _b : [], this.zoom, this.currentPos);
|
|
311
|
+
if (polygon.id === this.mouseHoverID || style.fill) {
|
|
312
|
+
const fillArr = rgba((_d = (_c = style == null ? void 0 : style.fill) != null ? _c : style == null ? void 0 : style.stroke) != null ? _d : DEFAULT_STROKE_COLOR);
|
|
313
|
+
const fill = `rgba(${fillArr[0]}, ${fillArr[1]}, ${fillArr[2]},${fillArr[3] * 0.8})`;
|
|
314
|
+
DrawUtils.drawPolygonWithFill(this.canvas, renderPolygon, {color: fill, lineType});
|
|
315
|
+
}
|
|
316
|
+
const polygonRenderOptions = __spreadProps(__spreadValues(__spreadProps(__spreadValues({}, style), {
|
|
317
|
+
isClose: true
|
|
318
|
+
}), this.getReferenceOptions(polygon == null ? void 0 : polygon.isReference)), {
|
|
319
|
+
lineType,
|
|
320
|
+
strokeColor: style.stroke
|
|
321
|
+
});
|
|
322
|
+
let newPointList = [];
|
|
323
|
+
if (polygon.showKeyPoint) {
|
|
324
|
+
newPointList = DrawUtils.drawPolygonWithKeyPoint(this.canvas, renderPolygon, polygonRenderOptions);
|
|
325
|
+
} else {
|
|
326
|
+
newPointList = DrawUtils.drawPolygon(this.canvas, renderPolygon, polygonRenderOptions);
|
|
327
|
+
}
|
|
328
|
+
const isShowDirection = (polygon == null ? void 0 : polygon.showDirection) === true && ((_e = polygon == null ? void 0 : polygon.pointList) == null ? void 0 : _e.length) >= 2;
|
|
329
|
+
if (isShowDirection) {
|
|
330
|
+
let startPoint = renderPolygon[0];
|
|
331
|
+
let endPoint = MathUtils.getLineCenterPoint([renderPolygon[0], renderPolygon[1]]);
|
|
332
|
+
if (lineType === ELineTypes.Curve) {
|
|
333
|
+
const pos = Math.floor(SEGMENT_NUMBER / 2);
|
|
334
|
+
startPoint = newPointList[pos];
|
|
335
|
+
endPoint = newPointList[pos + 1];
|
|
336
|
+
}
|
|
337
|
+
DrawUtils.drawArrowByCanvas(this.canvas, startPoint, endPoint, {
|
|
338
|
+
color: style.stroke,
|
|
339
|
+
thickness: style.thickness
|
|
340
|
+
});
|
|
341
|
+
DrawUtils.drawCircle(this.canvas, renderPolygon[0], style.thickness + 6, {
|
|
342
|
+
color: style.stroke,
|
|
343
|
+
thickness: style.thickness
|
|
344
|
+
});
|
|
345
|
+
}
|
|
346
|
+
const {headerText, bottomText} = this.getRenderText(polygon, polygon == null ? void 0 : polygon.hiddenText);
|
|
347
|
+
if (headerText) {
|
|
348
|
+
DrawUtils.drawText(this.canvas, this.appendOffset(renderPolygon[0]), headerText, fontStyle);
|
|
349
|
+
}
|
|
350
|
+
if (bottomText) {
|
|
351
|
+
const endPoint = renderPolygon[renderPolygon.length - 1];
|
|
352
|
+
DrawUtils.drawText(this.canvas, this.appendOffset({x: endPoint.x + TEXT_ATTRIBUTE_OFFSET.x, y: endPoint.y + TEXT_ATTRIBUTE_OFFSET.y}), bottomText, fontStyle);
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
renderSingleCuboid(annotation) {
|
|
356
|
+
var _a, _b;
|
|
357
|
+
const {style} = this.getRenderStyle(annotation);
|
|
358
|
+
const cuboid = annotation.annotation;
|
|
359
|
+
const fillArr = rgba((_b = (_a = style == null ? void 0 : style.fill) != null ? _a : style == null ? void 0 : style.stroke) != null ? _b : DEFAULT_STROKE_COLOR);
|
|
360
|
+
const fillColor = `rgba(${fillArr[0]}, ${fillArr[1]}, ${fillArr[2]},${fillArr[3] * 0.8})`;
|
|
361
|
+
const strokeColor = style.stroke;
|
|
362
|
+
const transformCuboid = AxisUtils.changeCuboidByZoom(cuboid, this.zoom, this.currentPos);
|
|
363
|
+
const {headerText, bottomText} = this.getRenderText(cuboid, cuboid == null ? void 0 : cuboid.hiddenText);
|
|
364
|
+
DrawUtils.drawCuboidWithText(this.canvas, transformCuboid, {strokeColor, fillColor, thickness: style.thickness}, {
|
|
365
|
+
config: this.config,
|
|
366
|
+
hiddenText: cuboid == null ? void 0 : cuboid.hiddenText,
|
|
367
|
+
headerText,
|
|
368
|
+
bottomText
|
|
369
|
+
});
|
|
370
|
+
}
|
|
371
|
+
renderBox3d(annotation) {
|
|
372
|
+
if (annotation.type !== "box3d") {
|
|
373
|
+
return;
|
|
374
|
+
}
|
|
375
|
+
const data = annotation.annotation;
|
|
376
|
+
const viewDataPointList = pointCloudLidar2image(data, data.calib);
|
|
377
|
+
const defaultViewStyle = {
|
|
378
|
+
fill: "transparent"
|
|
379
|
+
};
|
|
380
|
+
const extraData = _.pick(data, ["stroke", "thickness"]);
|
|
381
|
+
viewDataPointList.forEach((v, i) => {
|
|
382
|
+
const newAnnotation = __spreadValues(__spreadProps(__spreadValues({}, extraData), {
|
|
383
|
+
id: `${annotation.annotation.id}-${i}`,
|
|
384
|
+
pointList: v.pointList
|
|
385
|
+
}), defaultViewStyle);
|
|
386
|
+
switch (v.type) {
|
|
387
|
+
case "line":
|
|
388
|
+
this.renderLine({
|
|
389
|
+
type: "line",
|
|
390
|
+
annotation: newAnnotation
|
|
391
|
+
});
|
|
392
|
+
break;
|
|
393
|
+
case "polygon":
|
|
394
|
+
this.renderPolygon({
|
|
395
|
+
type: "polygon",
|
|
396
|
+
annotation: newAnnotation
|
|
397
|
+
});
|
|
398
|
+
break;
|
|
399
|
+
}
|
|
400
|
+
});
|
|
401
|
+
}
|
|
402
|
+
render() {
|
|
403
|
+
try {
|
|
404
|
+
super.render();
|
|
405
|
+
if (this.loading === true) {
|
|
406
|
+
return;
|
|
407
|
+
}
|
|
408
|
+
const globalDomTextAnnotation = this.annotations.filter((v) => v.type === "text" && v.annotation.position === "rt").map((v) => v.annotation);
|
|
409
|
+
this.renderDomInstance.render(globalDomTextAnnotation);
|
|
410
|
+
this.annotations.forEach((annotation) => {
|
|
411
|
+
var _a, _b, _c, _d, _e;
|
|
412
|
+
const style = this.getSpecificStyle(annotation.annotation);
|
|
413
|
+
const fontStyle = this.getFontStyle(annotation.annotation, style);
|
|
414
|
+
switch (annotation.type) {
|
|
415
|
+
case "rect": {
|
|
416
|
+
const rect = annotation.annotation;
|
|
417
|
+
const {hiddenText = false, isReference, hiddenRectSize = false} = rect;
|
|
418
|
+
const {zoom} = this;
|
|
419
|
+
const renderRect = AxisUtils.changeRectByZoom(rect, this.zoom, this.currentPos);
|
|
420
|
+
const {x, y, width, height} = renderRect;
|
|
421
|
+
if (rect.id === this.mouseHoverID || style.fill) {
|
|
422
|
+
const fillArr = rgba((_b = (_a = style == null ? void 0 : style.fill) != null ? _a : style == null ? void 0 : style.stroke) != null ? _b : DEFAULT_STROKE_COLOR);
|
|
423
|
+
const fill = `rgba(${fillArr[0]}, ${fillArr[1]}, ${fillArr[2]},${fillArr[3] * 0.8})`;
|
|
424
|
+
DrawUtils.drawRectWithFill(this.canvas, renderRect, {color: fill});
|
|
425
|
+
}
|
|
426
|
+
DrawUtils.drawRect(this.canvas, renderRect, __spreadValues(__spreadProps(__spreadValues({}, style), {
|
|
427
|
+
hiddenText: true
|
|
428
|
+
}), this.getReferenceOptions(isReference)));
|
|
429
|
+
const {headerText, bottomText} = this.getRenderText(rect, rect == null ? void 0 : rect.hiddenText);
|
|
430
|
+
if (headerText) {
|
|
431
|
+
DrawUtils.drawText(this.canvas, {x, y: y - 6}, headerText, __spreadValues({
|
|
432
|
+
textMaxWidth: 300
|
|
433
|
+
}, fontStyle));
|
|
434
|
+
}
|
|
435
|
+
const rectSize = `${Math.round(width / zoom)} * ${Math.round(height / zoom)}`;
|
|
436
|
+
const textSizeWidth = rectSize.length * 7;
|
|
437
|
+
if (!hiddenText && !hiddenRectSize) {
|
|
438
|
+
DrawUtils.drawText(this.canvas, {x: x + width - textSizeWidth, y: y + height + 15}, rectSize, fontStyle);
|
|
439
|
+
}
|
|
440
|
+
if (bottomText) {
|
|
441
|
+
const marginTop = 20;
|
|
442
|
+
const textWidth = Math.max(20, width - textSizeWidth);
|
|
443
|
+
DrawUtils.drawText(this.canvas, {x, y: y + height + marginTop}, rect.textAttribute, __spreadValues({
|
|
444
|
+
textMaxWidth: textWidth
|
|
445
|
+
}, fontStyle));
|
|
446
|
+
}
|
|
447
|
+
break;
|
|
448
|
+
}
|
|
449
|
+
case "polygon": {
|
|
450
|
+
this.renderPolygon(annotation);
|
|
451
|
+
break;
|
|
452
|
+
}
|
|
453
|
+
case "line": {
|
|
454
|
+
this.renderLine(annotation);
|
|
455
|
+
break;
|
|
456
|
+
}
|
|
457
|
+
case "point": {
|
|
458
|
+
const point = annotation.annotation;
|
|
459
|
+
const renderPoint = AxisUtils.changePointByZoom(point, this.zoom, this.currentPos);
|
|
460
|
+
const radius = (_c = style.radius) != null ? _c : DEFAULT_RADIUS;
|
|
461
|
+
DrawUtils.drawCircle(this.canvas, renderPoint, radius, style);
|
|
462
|
+
const {headerText, bottomText} = this.getRenderText(point, point == null ? void 0 : point.hiddenText);
|
|
463
|
+
if (headerText) {
|
|
464
|
+
DrawUtils.drawText(this.canvas, {x: renderPoint.x + radius / 2, y: renderPoint.y - radius - 4}, headerText, __spreadValues({
|
|
465
|
+
textAlign: "center"
|
|
466
|
+
}, fontStyle));
|
|
467
|
+
}
|
|
468
|
+
if (bottomText) {
|
|
469
|
+
DrawUtils.drawText(this.canvas, this.appendOffset({x: renderPoint.x + radius, y: renderPoint.y + radius + 24}), bottomText, fontStyle);
|
|
470
|
+
}
|
|
471
|
+
break;
|
|
472
|
+
}
|
|
473
|
+
case "text": {
|
|
474
|
+
const textAnnotation = annotation.annotation;
|
|
475
|
+
const {
|
|
476
|
+
text,
|
|
477
|
+
x,
|
|
478
|
+
y,
|
|
479
|
+
textMaxWidth,
|
|
480
|
+
color = "white",
|
|
481
|
+
background = "rgba(0, 0, 0, 0.6)",
|
|
482
|
+
lineHeight = 25,
|
|
483
|
+
font = DEFAULT_FONT,
|
|
484
|
+
position
|
|
485
|
+
} = textAnnotation;
|
|
486
|
+
const paddingTB = 10;
|
|
487
|
+
const paddingLR = 10;
|
|
488
|
+
const renderPoint = AxisUtils.changePointByZoom({x, y}, this.zoom, this.currentPos);
|
|
489
|
+
const {
|
|
490
|
+
width,
|
|
491
|
+
height,
|
|
492
|
+
fontHeight = 0
|
|
493
|
+
} = MathUtils.getTextArea(this.canvas, textAnnotation.text, textMaxWidth, font, lineHeight);
|
|
494
|
+
if (position === "rt") {
|
|
495
|
+
break;
|
|
496
|
+
}
|
|
497
|
+
DrawUtils.drawRectWithFill(this.canvas, {
|
|
498
|
+
x: renderPoint.x,
|
|
499
|
+
y: renderPoint.y,
|
|
500
|
+
width: width + paddingLR * 2,
|
|
501
|
+
height: height + paddingTB * 2,
|
|
502
|
+
id: "",
|
|
503
|
+
sourceID: "",
|
|
504
|
+
valid: true,
|
|
505
|
+
textAttribute: "",
|
|
506
|
+
attribute: ""
|
|
507
|
+
}, {
|
|
508
|
+
color: background
|
|
509
|
+
});
|
|
510
|
+
DrawUtils.drawText(this.canvas, {
|
|
511
|
+
x: renderPoint.x + paddingLR,
|
|
512
|
+
y: renderPoint.y + fontHeight + paddingTB
|
|
513
|
+
}, text, {
|
|
514
|
+
color,
|
|
515
|
+
lineHeight,
|
|
516
|
+
font,
|
|
517
|
+
textMaxWidth
|
|
518
|
+
});
|
|
519
|
+
break;
|
|
520
|
+
}
|
|
521
|
+
case "box3d": {
|
|
522
|
+
this.renderBox3d(annotation);
|
|
523
|
+
break;
|
|
524
|
+
}
|
|
525
|
+
case "cuboid": {
|
|
526
|
+
this.renderSingleCuboid(annotation);
|
|
527
|
+
break;
|
|
528
|
+
}
|
|
529
|
+
default: {
|
|
530
|
+
break;
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
(_e = (_d = annotation.annotation) == null ? void 0 : _d.renderEnhance) == null ? void 0 : _e.call(_d, {
|
|
534
|
+
ctx: this.ctx,
|
|
535
|
+
canvas: this.canvas,
|
|
536
|
+
currentPos: this.currentPos,
|
|
537
|
+
zoom: this.zoom,
|
|
538
|
+
data: annotation,
|
|
539
|
+
toolInstance: this
|
|
540
|
+
});
|
|
541
|
+
});
|
|
542
|
+
this.renderConnectionPoints();
|
|
543
|
+
} catch (e) {
|
|
544
|
+
console.error("ViewOperation Render Error", e);
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
export { ViewOperation as default };
|