@labelbee/lb-annotation 1.14.0-alpha.14 → 1.14.0-alpha.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1 +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=(i,t,e)=>t in i?__defProp(i,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[t]=e,__spreadValues=(i,t)=>{for(var e in t||(t={}))__hasOwnProp.call(t,e)&&__defNormalProp(i,e,t[e]);if(__getOwnPropSymbols)for(var e of __getOwnPropSymbols(t))__propIsEnum.call(t,e)&&__defNormalProp(i,e,t[e]);return i},__spreadProps=(i,t)=>__defProps(i,__getOwnPropDescs(t));const createEmptyImage=i=>{const t=document.createElement("canvas");t.width=i.width,t.height=i.height;const e=t.getContext("2d");return e?(e.fillStyle="black",e.fillRect(0,0,i.width,i.height),t.toDataURL()):""};class PointCloudAnnotation{constructor({size:t,container:e,pcdPath:n,extraProps:P,config:f,checkMode:v,toolName:d}){this.updateLineList=a=>{this.toolScheduler.updateDataByToolName(tool.EToolName.Line,a!=null?a:[])},this.updatePolygonList=(a,l)=>{let s=a.map(o=>{var r;const{polygon2d:C}=this.pointCloudInstance.getBoxTopPolygon2DCoordinate(o);return{id:o.id,sourceID:"",pointList:C,isRect:!0,valid:(r=o.valid)!=null?r:!0,attribute:o.attribute}});l&&(s=s.concat(l.map(o=>{var r;return __spreadProps(__spreadValues({},o),{pointList:(r=o==null?void 0:o.pointList)==null?void 0:r.map(C=>lbUtils.PointCloudUtils.transferWorld2Canvas(C,this.toolInstance.size))})}))),this.toolScheduler.updateDataByToolName(tool.EToolName.PointCloudPolygon,s)},this.updatePointList=a=>{const l=a==null?void 0:a.map(s=>{var o;const{point2d:r}=this.pointCloudInstance.getSphereTopPoint2DCoordinate(s);return __spreadProps(__spreadValues({},r),{id:s.id,sourceID:"",valid:(o=s.valid)!=null?o:!0,attribute:s.attribute,textAttribute:""})});this.toolScheduler.updateDataByToolName(tool.EToolName.Point,l)};const
|
|
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=(i,t,e)=>t in i?__defProp(i,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[t]=e,__spreadValues=(i,t)=>{for(var e in t||(t={}))__hasOwnProp.call(t,e)&&__defNormalProp(i,e,t[e]);if(__getOwnPropSymbols)for(var e of __getOwnPropSymbols(t))__propIsEnum.call(t,e)&&__defNormalProp(i,e,t[e]);return i},__spreadProps=(i,t)=>__defProps(i,__getOwnPropDescs(t));const createEmptyImage=i=>{const t=document.createElement("canvas");t.width=i.width,t.height=i.height;const e=t.getContext("2d");return e?(e.fillStyle="black",e.fillRect(0,0,i.width,i.height),t.toDataURL()):""};class PointCloudAnnotation{constructor({size:t,container:e,pcdPath:n,extraProps:P,config:f,checkMode:v,toolName:d,proxyMode:I}){this.updateLineList=a=>{this.toolScheduler.updateDataByToolName(tool.EToolName.Line,a!=null?a:[])},this.updatePolygonList=(a,l)=>{let s=a.map(o=>{var r;const{polygon2d:C}=this.pointCloudInstance.getBoxTopPolygon2DCoordinate(o);return{id:o.id,sourceID:"",pointList:C,isRect:!0,valid:(r=o.valid)!=null?r:!0,attribute:o.attribute}});l&&(s=s.concat(l.map(o=>{var r;return __spreadProps(__spreadValues({},o),{pointList:(r=o==null?void 0:o.pointList)==null?void 0:r.map(C=>lbUtils.PointCloudUtils.transferWorld2Canvas(C,this.toolInstance.size))})}))),this.toolScheduler.updateDataByToolName(tool.EToolName.PointCloudPolygon,s)},this.updatePointList=a=>{const l=a==null?void 0:a.map(s=>{var o;const{point2d:r}=this.pointCloudInstance.getSphereTopPoint2DCoordinate(s);return __spreadProps(__spreadValues({},r),{id:s.id,sourceID:"",valid:(o=s.valid)!=null?o:!0,attribute:s.attribute,textAttribute:""})});this.toolScheduler.updateDataByToolName(tool.EToolName.Point,l)};const O=this.getDefaultOrthographic(t),L=createEmptyImage(t),u=new Image;u.src=L;const h=new scheduler.ToolScheduler({container:e,size:t,toolName:d,proxyMode:I}),m=new CanvasScheduler.CanvasScheduler({container:e}),p=new index.PointCloud({container:e,noAppend:!0,isOrthographicCamera:!0,orthographicParams:O});n&&p.loadPCDFile(n),m.createCanvas(p.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 s;if(a===tool.EToolName.PointCloudPolygon){const o=h.createOperation(a,u,g);o.eventBinding(),o.setPattern(tool.EPolygonPattern.Rect),this.toolInstance=o,this.toolInstance.eventBinding(),this.pointCloud2dOperation=o}else s=h.createOperation(a,u,__spreadProps(__spreadValues({},g),{textConfigurable:!1}));l===c.length-1&&(this.toolInstance||(this.toolInstance=s,this.toolInstance.eventBinding()))}),this.pointCloudInstance=p,this.canvasScheduler=m,this.toolScheduler=h,this.config=f}updateConfig(t){this.config=t}updateAttributeList(t){this.config=__spreadProps(__spreadValues({},this.config),{attributeList:t}),this.toolScheduler.syncAllAttributeListInConfig(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),n=new Image;n.src=e,n.onload=()=>{this.toolInstance.setImgNode(n),this.toolInstance.initImgPos()},this.pointCloud2dOperation.setCanvasSize(t)}addPolygonListOnTopView(t){const e=lbUtils.PointCloudUtils.getBoxParamsFromResultList(t),n=lbUtils.PointCloudUtils.getPolygonListFromResultList(t);this.updatePolygonList(e,n)}addLineListOnTopView(t){const e=lbUtils.PointCloudUtils.getLineListFromResultList(t);this.updateLineList(e)}addPointListOnTopView(t){const e=lbUtils.PointCloudUtils.getSphereParamsFromResultList(t);this.updatePointList(e)}updateData(t,e,n){!this.toolInstance||!this.pointCloudInstance||(this.pointCloudInstance.loadPCDFile(t,n==null?void 0:n.radius),this.addPolygonListOnTopView(e),this.addLineListOnTopView(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;
|
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"),__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 defaultConfig=require("../constant/defaultConfig.js"),EnhanceCommonToolUtils=require("../utils/tool/EnhanceCommonToolUtils.js"),basicToolOperation=require("./toolOperation/basicToolOperation.js"),__defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnPropDescs=Object.getOwnPropertyDescriptors,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(i,t,o)=>t in i?__defProp(i,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):i[t]=o,__spreadValues=(i,t)=>{for(var o in t||(t={}))__hasOwnProp.call(t,o)&&__defNormalProp(i,o,t[o]);if(__getOwnPropSymbols)for(var o of __getOwnPropSymbols(t))__propIsEnum.call(t,o)&&__defNormalProp(i,o,t[o]);return i},__spreadProps=(i,t)=>__defProps(i,__getOwnPropDescs(t));const createEmptyImage=i=>{const t=document.createElement("canvas");t.width=i.width,t.height=i.height;const o=t.getContext("2d");return o?(o.fillStyle="transparent",o.fillRect(0,0,i.width,i.height),t.toDataURL()):""},arraySwap=(i,t,o)=>{const e=i[t];return i[t]=i[o],i[o]=e,i},_HybridToolUtils=class{static isSingleTool(i){return!this.isHybridTool(i)}static isHybridTool(i){return Array.isArray(i)}};let HybridToolUtils=_HybridToolUtils;HybridToolUtils.getTopToolName=i=>_HybridToolUtils.isHybridTool(i)?i[i.length-1]:i;class ToolScheduler{constructor(t){this.toolOperationList=[],this.toolOperationDom=[],this.toolOperationNameList=[];var o,e;this.container=t.container,this.size=t.size,this.imgNode=t.imgNode,this.config=(o=t.config)!=null?o:JSON.stringify(defaultConfig.getConfig(HybridToolUtils.getTopToolName(t.toolName))),this.style=(e=t.style)!=null?e:defaultConfig.styleDefaultConfig,this.proxyMode=t.proxyMode,this.onWheel=this.onWheel.bind(this),this.onMouseDown=this.onMouseDown.bind(this),this.onMouseMove=this.onMouseMove.bind(this),this.onMouseUp=this.onMouseUp.bind(this),this.init()}setImgNode(t,o){this.toolOperationList.forEach(e=>{e.setImgNode(t,o)})}setImgAttribute(t){this.toolOperationList.forEach(o=>{o.setImgAttribute(t)})}syncAllAttributeListInConfig(t){this.toolOperationList.forEach(o=>{const e=__spreadProps(__spreadValues({},o.config),{attributeList:t});o.setConfig(JSON.stringify(e))})}setSize(t){this.toolOperationList.forEach(o=>{o.setSize(t)})}syncPosition(t,o,e,s){this.toolOperationList.forEach(a=>{s!==a&&(a.setCurrentPos(t),a.setZoom(o),a.setImgInfo(e),a.renderBasicCanvas(),a.render())})}get defaultSize(){var t,o;return{width:((t=this.imgNode)==null?void 0:t.width)||this.size.width,height:((o=this.imgNode)==null?void 0:o.height)||this.size.height}}createDom(){const{width:t,height:o}=this.defaultSize,e=window.document.createElement("div");e.style.position="absolute",e.style.left="0",e.style.top="0",e.style.width=`${t}px`,e.style.height=`${o}px`;const s=this.toolOperationList.length+1;return e.style.zIndex=`${s}`,e}getEmptyImage(t,o){const e=createEmptyImage({width:t,height:o}),s=new Image;return s.src=e,s}createOperation(t,o,e){var s;const{width:a,height:l}=this.defaultSize,r=this.createDom(),c=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:o||c,hiddenImg:!!t};e&&Object.assign(h,e);let n;if(!t)n=new basicToolOperation.BasicToolOperation(h),r.style.zIndex="0",n.init();else{const p=EnhanceCommonToolUtils.getCurrentOperation(t);if(!p)return;n=new p(h)}return n==null||n.init(),n.canvas.id=t!=null?t:"basicCanvas",n.on("dragMove",({currentPos:p,zoom:d,imgInfo:u})=>{this.syncPosition(p,d,u,n)}),n.on("renderZoom",(p,d,u)=>{p&&d&&this.syncPosition(d,p,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,o=t-1,e=t-2,s=this.toolOperationDom[o],a=this.toolOperationDom[e];if(!(!a||!s))return s.style.zIndex=`${o-1}`,a.style.zIndex=`${o}`,this.toolOperationList[o].clearActiveStatus(),this.toolOperationList[o].clearCursorLine(),this.toolOperationList[o].render(),this.toolOperationList=arraySwap(this.toolOperationList,o,e),this.toolOperationDom=arraySwap(this.toolOperationDom,o,e),this.toolOperationList[o]}getFirstToolOperation(){return this.toolOperationList.length>1?this.toolOperationList[1]:this.toolOperationList[0]}switchToCanvas(t){var o,e,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,c=this.toolOperationDom[l],h=this.toolOperationDom[r];if(!c||!h)return;const n=h.style.zIndex;return h.style.zIndex=`${c.style.zIndex}`,c.style.zIndex=`${n}`,(e=(o=this.toolOperationList[r]).clearActiveStatus)==null||e.call(o),(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,o){const e=this.toolOperationNameList.indexOf(t);e>=0&&this.toolOperationList[e].setResult(o)}clearStatusAndResult(){this.toolOperationList.forEach(t=>{var o;(o=t.clearActiveStatus)==null||o.call(t),t.clearResult()})}destroyAllLayer(){this.toolOperationList.forEach(t=>{t.destroyCanvas(),this.init()})}init(){this.toolOperationList=[],this.toolOperationDom=[],this.eventBinding()}destroy(){this.destroyAllLayer(),this.eventUnBinding()}eventBinding(){this.proxyMode&&(this.container.addEventListener("wheel",this.onWheel),this.container.addEventListener("mousedown",this.onMouseDown),this.container.addEventListener("mousemove",this.onMouseMove),this.container.addEventListener("mouseup",this.onMouseUp))}eventUnBinding(){this.proxyMode&&(this.container.removeEventListener("wheel",this.onWheel),this.container.removeEventListener("mousedown",this.onMouseDown),this.container.removeEventListener("mousemove",this.onMouseMove),this.container.removeEventListener("mouseup",this.onMouseUp))}onWheel(t){if(t.preventDefault(),t.stopPropagation(),this.toolOperationList.length!==0){const o=this.toolOperationDom.length-1;this.toolOperationList[o].onWheel(t)}}onMouseDown(t){if(t.preventDefault(),t.stopPropagation(),this.toolOperationList.length!==0){const o=this.toolOperationDom.length-1;this.toolOperationList[o].onMouseDown(t)}}onMouseMove(t){if(t.preventDefault(),t.stopPropagation(),this.toolOperationList.length!==0){const o=this.toolOperationDom.length-1;this.toolOperationList[o].onMouseMove(t)}}onMouseUp(t){if(t.preventDefault(),t.stopPropagation(),this.toolOperationList.length!==0){const o=this.toolOperationDom.length-1;this.toolOperationList[o].onMouseUp(t)}}getCurrentToolName(){return this.toolOperationNameList[this.toolOperationNameList.length-1]}}exports.HybridToolUtils=HybridToolUtils,exports.ToolScheduler=ToolScheduler;
|
|
@@ -22,6 +22,7 @@ interface IPointCloudAnnotationProps {
|
|
|
22
22
|
config: IPointCloudConfig;
|
|
23
23
|
checkMode?: boolean;
|
|
24
24
|
toolName: THybridToolName;
|
|
25
|
+
proxyMode?: boolean;
|
|
25
26
|
}
|
|
26
27
|
export declare class PointCloudAnnotation implements IPointCloudAnnotationOperation {
|
|
27
28
|
pointCloudInstance: PointCloud;
|
|
@@ -30,7 +31,7 @@ export declare class PointCloudAnnotation implements IPointCloudAnnotationOperat
|
|
|
30
31
|
toolScheduler: ToolScheduler;
|
|
31
32
|
toolInstance: any;
|
|
32
33
|
config: IPointCloudConfig;
|
|
33
|
-
constructor({ size, container, pcdPath, extraProps, config, checkMode, toolName }: IPointCloudAnnotationProps);
|
|
34
|
+
constructor({ size, container, pcdPath, extraProps, config, checkMode, toolName, proxyMode, }: IPointCloudAnnotationProps);
|
|
34
35
|
updateConfig(config: IPointCloudConfig): void;
|
|
35
36
|
updateAttributeList(attributeList: IInputList[]): void;
|
|
36
37
|
/**
|
|
@@ -16,6 +16,7 @@ interface IToolSchedulerProps {
|
|
|
16
16
|
imgNode?: HTMLImageElement;
|
|
17
17
|
config?: string;
|
|
18
18
|
style?: any;
|
|
19
|
+
proxyMode?: boolean;
|
|
19
20
|
}
|
|
20
21
|
export declare class HybridToolUtils {
|
|
21
22
|
static isSingleTool(toolName: THybridToolName): boolean;
|
|
@@ -31,6 +32,7 @@ export declare class ToolScheduler implements IToolSchedulerOperation {
|
|
|
31
32
|
private config;
|
|
32
33
|
private style;
|
|
33
34
|
private imgNode?;
|
|
35
|
+
private proxyMode?;
|
|
34
36
|
constructor(props: IToolSchedulerProps);
|
|
35
37
|
setImgNode(imgNode: HTMLImageElement, basicImgInfo?: Partial<{
|
|
36
38
|
valid: boolean;
|
|
@@ -89,5 +91,12 @@ export declare class ToolScheduler implements IToolSchedulerOperation {
|
|
|
89
91
|
eventBinding(): void;
|
|
90
92
|
eventUnBinding(): void;
|
|
91
93
|
onWheel(e: MouseEvent): void;
|
|
94
|
+
onMouseDown(e: MouseEvent): void;
|
|
95
|
+
onMouseMove(e: MouseEvent): void;
|
|
96
|
+
onMouseUp(e: MouseEvent): void;
|
|
97
|
+
/**
|
|
98
|
+
* Get current tool name of toolInstance
|
|
99
|
+
*/
|
|
100
|
+
getCurrentToolName(): EToolName;
|
|
92
101
|
}
|
|
93
102
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{PointCloudUtils as d}from"@labelbee/lb-utils";import{EToolName as f,EPolygonPattern as
|
|
1
|
+
import{PointCloudUtils as d}from"@labelbee/lb-utils";import{EToolName as f,EPolygonPattern as R}from"../../constant/tool.js";import{CanvasScheduler as A}from"../../newCore/CanvasScheduler.js";import{PointCloud as j}from"./index.js";import{ToolScheduler as B,HybridToolUtils as E}from"../scheduler.js";var V=Object.defineProperty,x=Object.defineProperties,F=Object.getOwnPropertyDescriptors,y=Object.getOwnPropertySymbols,N=Object.prototype.hasOwnProperty,U=Object.prototype.propertyIsEnumerable,w=(n,t,o)=>t in n?V(n,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):n[t]=o,c=(n,t)=>{for(var o in t||(t={}))N.call(t,o)&&w(n,o,t[o]);if(y)for(var o of y(t))U.call(t,o)&&w(n,o,t[o]);return n},u=(n,t)=>x(n,F(t));const S=n=>{const t=document.createElement("canvas");t.width=n.width,t.height=n.height;const o=t.getContext("2d");return o?(o.fillStyle="black",o.fillRect(0,0,n.width,n.height),t.toDataURL()):""};class H{constructor({size:t,container:o,pcdPath:i,extraProps:L,config:O,checkMode:b,toolName:p,proxyMode:_}){this.updateLineList=a=>{this.toolScheduler.updateDataByToolName(f.Line,a!=null?a:[])},this.updatePolygonList=(a,l)=>{let s=a.map(e=>{var r;const{polygon2d:I}=this.pointCloudInstance.getBoxTopPolygon2DCoordinate(e);return{id:e.id,sourceID:"",pointList:I,isRect:!0,valid:(r=e.valid)!=null?r:!0,attribute:e.attribute}});l&&(s=s.concat(l.map(e=>{var r;return u(c({},e),{pointList:(r=e==null?void 0:e.pointList)==null?void 0:r.map(I=>d.transferWorld2Canvas(I,this.toolInstance.size))})}))),this.toolScheduler.updateDataByToolName(f.PointCloudPolygon,s)},this.updatePointList=a=>{const l=a==null?void 0:a.map(s=>{var e;const{point2d:r}=this.pointCloudInstance.getSphereTopPoint2DCoordinate(s);return u(c({},r),{id:s.id,sourceID:"",valid:(e=s.valid)!=null?e:!0,attribute:s.attribute,textAttribute:""})});this.toolScheduler.updateDataByToolName(f.Point,l)};const D=this.getDefaultOrthographic(t),T=S(t),h=new Image;h.src=T;const m=new B({container:o,size:t,toolName:p,proxyMode:_}),v=new A({container:o}),C=new j({container:o,noAppend:!0,isOrthographicCamera:!0,orthographicParams:D});i&&C.loadPCDFile(i),v.createCanvas(C.renderer.domElement);const P={size:t,config:JSON.stringify(u(c({},O),{attributeConfigurable:!0,hideAttribute:!0})),imgNode:h,checkMode:b};L&&Object.assign(P,L);let g=[];E.isSingleTool(p)?g=[p]:g=p,g.forEach((a,l)=>{let s;if(a===f.PointCloudPolygon){const e=m.createOperation(a,h,P);e.eventBinding(),e.setPattern(R.Rect),this.toolInstance=e,this.toolInstance.eventBinding(),this.pointCloud2dOperation=e}else s=m.createOperation(a,h,u(c({},P),{textConfigurable:!1}));l===g.length-1&&(this.toolInstance||(this.toolInstance=s,this.toolInstance.eventBinding()))}),this.pointCloudInstance=C,this.canvasScheduler=v,this.toolScheduler=m,this.config=O}updateConfig(t){this.config=t}updateAttributeList(t){this.config=u(c({},this.config),{attributeList:t}),this.toolScheduler.syncAllAttributeListInConfig(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 o=S(t),i=new Image;i.src=o,i.onload=()=>{this.toolInstance.setImgNode(i),this.toolInstance.initImgPos()},this.pointCloud2dOperation.setCanvasSize(t)}addPolygonListOnTopView(t){const o=d.getBoxParamsFromResultList(t),i=d.getPolygonListFromResultList(t);this.updatePolygonList(o,i)}addLineListOnTopView(t){const o=d.getLineListFromResultList(t);this.updateLineList(o)}addPointListOnTopView(t){const o=d.getSphereParamsFromResultList(t);this.updatePointList(o)}updateData(t,o,i){!this.toolInstance||!this.pointCloudInstance||(this.pointCloudInstance.loadPCDFile(t,i==null?void 0:i.radius),this.addPolygonListOnTopView(o),this.addLineListOnTopView(o),this.addPointListOnTopView(o))}switchToCanvas(t){const o=this.toolScheduler.switchToCanvas(t);return o?(o.eventBinding(),this.toolInstance=o,o):this.toolInstance}initAllPosition(){this.pointCloudInstance.updateTopCamera(),this.pointCloud2dOperation.initPosition()}clearAllData(){this.pointCloudInstance.clearPointCloudAndRender(),this.pointCloud2dOperation.clearResult()}}export{H as PointCloudAnnotation};
|
package/es/core/scheduler.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{getConfig as L,styleDefaultConfig as
|
|
1
|
+
import{getConfig as L,styleDefaultConfig as y}from"../constant/defaultConfig.js";import{getCurrentOperation as D}from"../utils/tool/EnhanceCommonToolUtils.js";import{BasicToolOperation as w}from"./toolOperation/basicToolOperation.js";var I=Object.defineProperty,M=Object.defineProperties,_=Object.getOwnPropertyDescriptors,g=Object.getOwnPropertySymbols,x=Object.prototype.hasOwnProperty,b=Object.prototype.propertyIsEnumerable,f=(i,t,o)=>t in i?I(i,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):i[t]=o,E=(i,t)=>{for(var o in t||(t={}))x.call(t,o)&&f(i,o,t[o]);if(g)for(var o of g(t))b.call(t,o)&&f(i,o,t[o]);return i},N=(i,t)=>M(i,_(t));const T=i=>{const t=document.createElement("canvas");t.width=i.width,t.height=i.height;const o=t.getContext("2d");return o?(o.fillStyle="transparent",o.fillRect(0,0,i.width,i.height),t.toDataURL()):""},d=(i,t,o)=>{const e=i[t];return i[t]=i[o],i[o]=e,i},v=class{static isSingleTool(i){return!this.isHybridTool(i)}static isHybridTool(i){return Array.isArray(i)}};let m=v;m.getTopToolName=i=>v.isHybridTool(i)?i[i.length-1]:i;class S{constructor(t){this.toolOperationList=[],this.toolOperationDom=[],this.toolOperationNameList=[];var o,e;this.container=t.container,this.size=t.size,this.imgNode=t.imgNode,this.config=(o=t.config)!=null?o:JSON.stringify(L(m.getTopToolName(t.toolName))),this.style=(e=t.style)!=null?e:y,this.proxyMode=t.proxyMode,this.onWheel=this.onWheel.bind(this),this.onMouseDown=this.onMouseDown.bind(this),this.onMouseMove=this.onMouseMove.bind(this),this.onMouseUp=this.onMouseUp.bind(this),this.init()}setImgNode(t,o){this.toolOperationList.forEach(e=>{e.setImgNode(t,o)})}setImgAttribute(t){this.toolOperationList.forEach(o=>{o.setImgAttribute(t)})}syncAllAttributeListInConfig(t){this.toolOperationList.forEach(o=>{const e=N(E({},o.config),{attributeList:t});o.setConfig(JSON.stringify(e))})}setSize(t){this.toolOperationList.forEach(o=>{o.setSize(t)})}syncPosition(t,o,e,n){this.toolOperationList.forEach(a=>{n!==a&&(a.setCurrentPos(t),a.setZoom(o),a.setImgInfo(e),a.renderBasicCanvas(),a.render())})}get defaultSize(){var t,o;return{width:((t=this.imgNode)==null?void 0:t.width)||this.size.width,height:((o=this.imgNode)==null?void 0:o.height)||this.size.height}}createDom(){const{width:t,height:o}=this.defaultSize,e=window.document.createElement("div");e.style.position="absolute",e.style.left="0",e.style.top="0",e.style.width=`${t}px`,e.style.height=`${o}px`;const n=this.toolOperationList.length+1;return e.style.zIndex=`${n}`,e}getEmptyImage(t,o){const e=T({width:t,height:o}),n=new Image;return n.src=e,n}createOperation(t,o,e){var n;const{width:a,height:l}=this.defaultSize,r=this.createDom(),c=this.getEmptyImage(a,l),h={container:r,size:this.size,config:(n=this==null?void 0:this.config)!=null?n:"{}",drawOutSideTarget:!1,style:this.style,imgNode:o||c,hiddenImg:!!t};e&&Object.assign(h,e);let s;if(!t)s=new w(h),r.style.zIndex="0",s.init();else{const p=D(t);if(!p)return;s=new p(h)}return s==null||s.init(),s.canvas.id=t!=null?t:"basicCanvas",s.on("dragMove",({currentPos:p,zoom:u,imgInfo:O})=>{this.syncPosition(p,u,O,s)}),s.on("renderZoom",(p,u,O)=>{p&&u&&this.syncPosition(u,p,O,s)}),t?(this.container.appendChild(r),this.toolOperationList.push(s),this.toolOperationNameList.push(t),this.toolOperationDom.push(r),s):(this.container.insertBefore(r,this.container.childNodes[0]),this.toolOperationList.unshift(s),this.toolOperationDom.unshift(r),s)}switchLastTwoCanvas(){if(this.toolOperationDom.length<3){console.error("switchLastTwoCanvas is just used the layer which has 3 canvas");return}const t=this.toolOperationDom.length,o=t-1,e=t-2,n=this.toolOperationDom[o],a=this.toolOperationDom[e];if(!(!a||!n))return n.style.zIndex=`${o-1}`,a.style.zIndex=`${o}`,this.toolOperationList[o].clearActiveStatus(),this.toolOperationList[o].clearCursorLine(),this.toolOperationList[o].render(),this.toolOperationList=d(this.toolOperationList,o,e),this.toolOperationDom=d(this.toolOperationDom,o,e),this.toolOperationList[o]}getFirstToolOperation(){return this.toolOperationList.length>1?this.toolOperationList[1]:this.toolOperationList[0]}switchToCanvas(t){var o,e,n,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,c=this.toolOperationDom[l],h=this.toolOperationDom[r];if(!c||!h)return;const s=h.style.zIndex;return h.style.zIndex=`${c.style.zIndex}`,c.style.zIndex=`${s}`,(e=(o=this.toolOperationList[r]).clearActiveStatus)==null||e.call(o),(a=(n=this.toolOperationList[r]).clearCursorLine)==null||a.call(n),this.toolOperationList[r].render(),this.toolOperationList=d(this.toolOperationList,r,l),this.toolOperationDom=d(this.toolOperationDom,r,l),this.toolOperationNameList=d(this.toolOperationNameList,r,l),this.toolOperationList[r]}updateDataByToolName(t,o){const e=this.toolOperationNameList.indexOf(t);e>=0&&this.toolOperationList[e].setResult(o)}clearStatusAndResult(){this.toolOperationList.forEach(t=>{var o;(o=t.clearActiveStatus)==null||o.call(t),t.clearResult()})}destroyAllLayer(){this.toolOperationList.forEach(t=>{t.destroyCanvas(),this.init()})}init(){this.toolOperationList=[],this.toolOperationDom=[],this.eventBinding()}destroy(){this.destroyAllLayer(),this.eventUnBinding()}eventBinding(){this.proxyMode&&(this.container.addEventListener("wheel",this.onWheel),this.container.addEventListener("mousedown",this.onMouseDown),this.container.addEventListener("mousemove",this.onMouseMove),this.container.addEventListener("mouseup",this.onMouseUp))}eventUnBinding(){this.proxyMode&&(this.container.removeEventListener("wheel",this.onWheel),this.container.removeEventListener("mousedown",this.onMouseDown),this.container.removeEventListener("mousemove",this.onMouseMove),this.container.removeEventListener("mouseup",this.onMouseUp))}onWheel(t){if(t.preventDefault(),t.stopPropagation(),this.toolOperationList.length!==0){const o=this.toolOperationDom.length-1;this.toolOperationList[o].onWheel(t)}}onMouseDown(t){if(t.preventDefault(),t.stopPropagation(),this.toolOperationList.length!==0){const o=this.toolOperationDom.length-1;this.toolOperationList[o].onMouseDown(t)}}onMouseMove(t){if(t.preventDefault(),t.stopPropagation(),this.toolOperationList.length!==0){const o=this.toolOperationDom.length-1;this.toolOperationList[o].onMouseMove(t)}}onMouseUp(t){if(t.preventDefault(),t.stopPropagation(),this.toolOperationList.length!==0){const o=this.toolOperationDom.length-1;this.toolOperationList[o].onMouseUp(t)}}getCurrentToolName(){return this.toolOperationNameList[this.toolOperationNameList.length-1]}}export{m as HybridToolUtils,S as ToolScheduler};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@labelbee/lb-annotation",
|
|
3
|
-
"version": "1.14.0-alpha.
|
|
3
|
+
"version": "1.14.0-alpha.16",
|
|
4
4
|
"description": "Annotation tool collection",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"annotation",
|
|
@@ -94,7 +94,7 @@
|
|
|
94
94
|
"typescript": "^4.2.3"
|
|
95
95
|
},
|
|
96
96
|
"dependencies": {
|
|
97
|
-
"@labelbee/lb-utils": "1.7.0-alpha.
|
|
97
|
+
"@labelbee/lb-utils": "1.7.0-alpha.9",
|
|
98
98
|
"@turf/turf": "5.1.6",
|
|
99
99
|
"color-rgba": "^2.3.0",
|
|
100
100
|
"lodash": "^4.17.20",
|