@labelbee/lb-annotation 1.11.0-alpha.0 → 1.12.0-alpha.0

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/LICENSE ADDED
@@ -0,0 +1,203 @@
1
+ Copyright 2018-2023 OpenMMLab. All rights reserved.
2
+
3
+ Apache License
4
+ Version 2.0, January 2004
5
+ http://www.apache.org/licenses/
6
+
7
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
8
+
9
+ 1. Definitions.
10
+
11
+ "License" shall mean the terms and conditions for use, reproduction,
12
+ and distribution as defined by Sections 1 through 9 of this document.
13
+
14
+ "Licensor" shall mean the copyright owner or entity authorized by
15
+ the copyright owner that is granting the License.
16
+
17
+ "Legal Entity" shall mean the union of the acting entity and all
18
+ other entities that control, are controlled by, or are under common
19
+ control with that entity. For the purposes of this definition,
20
+ "control" means (i) the power, direct or indirect, to cause the
21
+ direction or management of such entity, whether by contract or
22
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
23
+ outstanding shares, or (iii) beneficial ownership of such entity.
24
+
25
+ "You" (or "Your") shall mean an individual or Legal Entity
26
+ exercising permissions granted by this License.
27
+
28
+ "Source" form shall mean the preferred form for making modifications,
29
+ including but not limited to software source code, documentation
30
+ source, and configuration files.
31
+
32
+ "Object" form shall mean any form resulting from mechanical
33
+ transformation or translation of a Source form, including but
34
+ not limited to compiled object code, generated documentation,
35
+ and conversions to other media types.
36
+
37
+ "Work" shall mean the work of authorship, whether in Source or
38
+ Object form, made available under the License, as indicated by a
39
+ copyright notice that is included in or attached to the work
40
+ (an example is provided in the Appendix below).
41
+
42
+ "Derivative Works" shall mean any work, whether in Source or Object
43
+ form, that is based on (or derived from) the Work and for which the
44
+ editorial revisions, annotations, elaborations, or other modifications
45
+ represent, as a whole, an original work of authorship. For the purposes
46
+ of this License, Derivative Works shall not include works that remain
47
+ separable from, or merely link (or bind by name) to the interfaces of,
48
+ the Work and Derivative Works thereof.
49
+
50
+ "Contribution" shall mean any work of authorship, including
51
+ the original version of the Work and any modifications or additions
52
+ to that Work or Derivative Works thereof, that is intentionally
53
+ submitted to Licensor for inclusion in the Work by the copyright owner
54
+ or by an individual or Legal Entity authorized to submit on behalf of
55
+ the copyright owner. For the purposes of this definition, "submitted"
56
+ means any form of electronic, verbal, or written communication sent
57
+ to the Licensor or its representatives, including but not limited to
58
+ communication on electronic mailing lists, source code control systems,
59
+ and issue tracking systems that are managed by, or on behalf of, the
60
+ Licensor for the purpose of discussing and improving the Work, but
61
+ excluding communication that is conspicuously marked or otherwise
62
+ designated in writing by the copyright owner as "Not a Contribution."
63
+
64
+ "Contributor" shall mean Licensor and any individual or Legal Entity
65
+ on behalf of whom a Contribution has been received by Licensor and
66
+ subsequently incorporated within the Work.
67
+
68
+ 2. Grant of Copyright License. Subject to the terms and conditions of
69
+ this License, each Contributor hereby grants to You a perpetual,
70
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
71
+ copyright license to reproduce, prepare Derivative Works of,
72
+ publicly display, publicly perform, sublicense, and distribute the
73
+ Work and such Derivative Works in Source or Object form.
74
+
75
+ 3. Grant of Patent License. Subject to the terms and conditions of
76
+ this License, each Contributor hereby grants to You a perpetual,
77
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
78
+ (except as stated in this section) patent license to make, have made,
79
+ use, offer to sell, sell, import, and otherwise transfer the Work,
80
+ where such license applies only to those patent claims licensable
81
+ by such Contributor that are necessarily infringed by their
82
+ Contribution(s) alone or by combination of their Contribution(s)
83
+ with the Work to which such Contribution(s) was submitted. If You
84
+ institute patent litigation against any entity (including a
85
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
86
+ or a Contribution incorporated within the Work constitutes direct
87
+ or contributory patent infringement, then any patent licenses
88
+ granted to You under this License for that Work shall terminate
89
+ as of the date such litigation is filed.
90
+
91
+ 4. Redistribution. You may reproduce and distribute copies of the
92
+ Work or Derivative Works thereof in any medium, with or without
93
+ modifications, and in Source or Object form, provided that You
94
+ meet the following conditions:
95
+
96
+ (a) You must give any other recipients of the Work or
97
+ Derivative Works a copy of this License; and
98
+
99
+ (b) You must cause any modified files to carry prominent notices
100
+ stating that You changed the files; and
101
+
102
+ (c) You must retain, in the Source form of any Derivative Works
103
+ that You distribute, all copyright, patent, trademark, and
104
+ attribution notices from the Source form of the Work,
105
+ excluding those notices that do not pertain to any part of
106
+ the Derivative Works; and
107
+
108
+ (d) If the Work includes a "NOTICE" text file as part of its
109
+ distribution, then any Derivative Works that You distribute must
110
+ include a readable copy of the attribution notices contained
111
+ within such NOTICE file, excluding those notices that do not
112
+ pertain to any part of the Derivative Works, in at least one
113
+ of the following places: within a NOTICE text file distributed
114
+ as part of the Derivative Works; within the Source form or
115
+ documentation, if provided along with the Derivative Works; or,
116
+ within a display generated by the Derivative Works, if and
117
+ wherever such third-party notices normally appear. The contents
118
+ of the NOTICE file are for informational purposes only and
119
+ do not modify the License. You may add Your own attribution
120
+ notices within Derivative Works that You distribute, alongside
121
+ or as an addendum to the NOTICE text from the Work, provided
122
+ that such additional attribution notices cannot be construed
123
+ as modifying the License.
124
+
125
+ You may add Your own copyright statement to Your modifications and
126
+ may provide additional or different license terms and conditions
127
+ for use, reproduction, or distribution of Your modifications, or
128
+ for any such Derivative Works as a whole, provided Your use,
129
+ reproduction, and distribution of the Work otherwise complies with
130
+ the conditions stated in this License.
131
+
132
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
133
+ any Contribution intentionally submitted for inclusion in the Work
134
+ by You to the Licensor shall be under the terms and conditions of
135
+ this License, without any additional terms or conditions.
136
+ Notwithstanding the above, nothing herein shall supersede or modify
137
+ the terms of any separate license agreement you may have executed
138
+ with Licensor regarding such Contributions.
139
+
140
+ 6. Trademarks. This License does not grant permission to use the trade
141
+ names, trademarks, service marks, or product names of the Licensor,
142
+ except as required for reasonable and customary use in describing the
143
+ origin of the Work and reproducing the content of the NOTICE file.
144
+
145
+ 7. Disclaimer of Warranty. Unless required by applicable law or
146
+ agreed to in writing, Licensor provides the Work (and each
147
+ Contributor provides its Contributions) on an "AS IS" BASIS,
148
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
149
+ implied, including, without limitation, any warranties or conditions
150
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
151
+ PARTICULAR PURPOSE. You are solely responsible for determining the
152
+ appropriateness of using or redistributing the Work and assume any
153
+ risks associated with Your exercise of permissions under this License.
154
+
155
+ 8. Limitation of Liability. In no event and under no legal theory,
156
+ whether in tort (including negligence), contract, or otherwise,
157
+ unless required by applicable law (such as deliberate and grossly
158
+ negligent acts) or agreed to in writing, shall any Contributor be
159
+ liable to You for damages, including any direct, indirect, special,
160
+ incidental, or consequential damages of any character arising as a
161
+ result of this License or out of the use or inability to use the
162
+ Work (including but not limited to damages for loss of goodwill,
163
+ work stoppage, computer failure or malfunction, or any and all
164
+ other commercial damages or losses), even if such Contributor
165
+ has been advised of the possibility of such damages.
166
+
167
+ 9. Accepting Warranty or Additional Liability. While redistributing
168
+ the Work or Derivative Works thereof, You may choose to offer,
169
+ and charge a fee for, acceptance of support, warranty, indemnity,
170
+ or other liability obligations and/or rights consistent with this
171
+ License. However, in accepting such obligations, You may act only
172
+ on Your own behalf and on Your sole responsibility, not on behalf
173
+ of any other Contributor, and only if You agree to indemnify,
174
+ defend, and hold each Contributor harmless for any liability
175
+ incurred by, or claims asserted against, such Contributor by reason
176
+ of your accepting any such warranty or additional liability.
177
+
178
+ END OF TERMS AND CONDITIONS
179
+
180
+ APPENDIX: How to apply the Apache License to your work.
181
+
182
+ To apply the Apache License to your work, attach the following
183
+ boilerplate notice, with the fields enclosed by brackets "[]"
184
+ replaced with your own identifying information. (Don't include
185
+ the brackets!) The text should be enclosed in the appropriate
186
+ comment syntax for the file format. We also recommend that a
187
+ file or class name and description of purpose be included on the
188
+ same "printed page" as the copyright notice for easier
189
+ identification within third-party archives.
190
+
191
+ Copyright 2018-2023 OpenMMLab.
192
+
193
+ Licensed under the Apache License, Version 2.0 (the "License");
194
+ you may not use this file except in compliance with the License.
195
+ You may obtain a copy of the License at
196
+
197
+ http://www.apache.org/licenses/LICENSE-2.0
198
+
199
+ Unless required by applicable law or agreed to in writing, software
200
+ distributed under the License is distributed on an "AS IS" BASIS,
201
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
202
+ See the License for the specific language governing permissions and
203
+ limitations under the License.
@@ -1 +1 @@
1
- "use strict";var annotation=require("../constant/annotation.js"),defaultConfig=require("../constant/defaultConfig.js"),scheduler=require("./scheduler.js"),__async=(a,t,e)=>new Promise((o,s)=>{var i=n=>{try{l(e.next(n))}catch(r){s(r)}},c=n=>{try{l(e.throw(n))}catch(r){s(r)}},l=n=>n.done?o(n.value):Promise.resolve(n.value).then(i,c);l((e=e.apply(a,t)).next())});const loadImage=a=>new Promise((t,e)=>{const o=document.createElement("img");o.crossOrigin="Anonymous",o.onerror=s=>{console.error(s),e(o)},o.src=a,o.onload=()=>{t(o)}});class AnnotationEngine{constructor(t){this.setImgSrc=s=>__async(this,null,function*(){const i=yield loadImage(s);!i||this.setImgNode(i)});var e,o;this.container=t.container,this.size=t.size,this.toolName=t.toolName,this.imgNode=t.imgNode,this.config=(e=t.config)!=null?e:JSON.stringify(defaultConfig.getConfig(scheduler.HybridToolUtils.getTopToolName(t.toolName))),this.style=(o=t.style)!=null?o:defaultConfig.styleDefaultConfig,this.toolScheduler=new scheduler.ToolScheduler(t),this.i18nLanguage="cn",this._initToolOperation()}setToolName(t,e){this.toolName=t;const o=e||JSON.stringify(defaultConfig.getConfig(scheduler.HybridToolUtils.getTopToolName(t)));this.config=o,this._initToolOperation()}setImgNode(t,e){this.toolScheduler.setImgNode(t,e),this.imgNode=t}setSize(t){this.size=t,this.toolScheduler.setSize(t)}setStyle(t){this.style=t}_initToolOperation(){this.toolScheduler.destroyAllLayer();let t=[];const e={hiddenImg:!0};scheduler.HybridToolUtils.isSingleTool(this.toolName)?(t=[this.toolName],Object.assign(e,{hiddenImg:!1})):t=this.toolName,t.length>1&&this.toolScheduler.createOperation(void 0,this.imgNode),t.forEach((o,s)=>{const i=this.toolScheduler.createOperation(o,void 0,e);s===t.length-1&&(this.toolInstance=i)}),this.setLang(this.i18nLanguage)}setBasicInfo(t,e){this.dependToolName=t,this.basicResult=e,this.toolInstance.setDependName(t),this.toolInstance.setBasicResult(e),this.toolInstance.renderBasicCanvas()}clearBasicResult(){this.setBasicInfo()}forbidOperation(){this.toolInstance.setForbidOperation(!0)}launchOperation(){this.toolInstance.setForbidOperation(!1)}setLang(t){switch(this.i18nLanguage=t,t){case"cn":this.toolInstance.setLang(annotation.ELang.Zh);break;case"en":this.toolInstance.setLang(annotation.ELang.US);break}}setDataInjectionAtCreation(t){this.toolInstance.setDataInjectionAtCreation(t)}setRenderEnhance(t){this.toolInstance.setRenderEnhance(t)}switchLastTwoCanvas(){const t=this.toolScheduler.switchLastTwoCanvas();if(t)return this.toolInstance=t,t}get firstToolInstance(){return this.toolScheduler.getFirstToolOperation()}setCustomRenderStyle(t){this.toolInstance.setCustomRenderStyle(t)}}module.exports=AnnotationEngine;
1
+ "use strict";var annotation=require("../constant/annotation.js"),defaultConfig=require("../constant/defaultConfig.js"),scheduler=require("./scheduler.js"),__async=(a,t,e)=>new Promise((o,s)=>{var i=n=>{try{l(e.next(n))}catch(r){s(r)}},c=n=>{try{l(e.throw(n))}catch(r){s(r)}},l=n=>n.done?o(n.value):Promise.resolve(n.value).then(i,c);l((e=e.apply(a,t)).next())});const loadImage=a=>new Promise((t,e)=>{const o=document.createElement("img");o.crossOrigin="Anonymous",o.onerror=s=>{console.error(s),e(o)},o.src=a,o.onload=()=>{t(o)}});class AnnotationEngine{constructor(t){this.setImgSrc=s=>__async(this,null,function*(){const i=yield loadImage(s);!i||this.setImgNode(i)});var e,o;this.container=t.container,this.size=t.size,this.toolName=t.toolName,this.imgNode=t.imgNode,this.config=(e=t.config)!=null?e:JSON.stringify(defaultConfig.getConfig(scheduler.HybridToolUtils.getTopToolName(t.toolName))),this.style=(o=t.style)!=null?o:defaultConfig.styleDefaultConfig,this.toolScheduler=new scheduler.ToolScheduler(t),this.i18nLanguage="cn",this._initToolOperation()}setToolName(t,e){this.toolName=t;const o=e||JSON.stringify(defaultConfig.getConfig(scheduler.HybridToolUtils.getTopToolName(t)));this.config=o,this._initToolOperation()}setImgNode(t,e){this.toolScheduler.setImgNode(t,e),this.imgNode=t}setImgAttribute(t){this.toolScheduler.setImgAttribute(t)}setSize(t){this.size=t,this.toolScheduler.setSize(t)}setStyle(t){this.style=t}_initToolOperation(){this.toolScheduler.destroyAllLayer();let t=[];const e={hiddenImg:!0};scheduler.HybridToolUtils.isSingleTool(this.toolName)?(t=[this.toolName],Object.assign(e,{hiddenImg:!1})):t=this.toolName,t.length>1&&this.toolScheduler.createOperation(void 0,this.imgNode),t.forEach((o,s)=>{const i=this.toolScheduler.createOperation(o,void 0,e);s===t.length-1&&(this.toolInstance=i)}),this.setLang(this.i18nLanguage)}setBasicInfo(t,e){this.dependToolName=t,this.basicResult=e,this.toolInstance.setDependName(t),this.toolInstance.setBasicResult(e),this.toolInstance.renderBasicCanvas()}clearBasicResult(){this.setBasicInfo()}forbidOperation(){this.toolInstance.setForbidOperation(!0)}launchOperation(){this.toolInstance.setForbidOperation(!1)}setLang(t){switch(this.i18nLanguage=t,t){case"cn":this.toolInstance.setLang(annotation.ELang.Zh);break;case"en":this.toolInstance.setLang(annotation.ELang.US);break}}setDataInjectionAtCreation(t){this.toolInstance.setDataInjectionAtCreation(t)}setRenderEnhance(t){this.toolInstance.setRenderEnhance(t)}switchLastTwoCanvas(){const t=this.toolScheduler.switchLastTwoCanvas();if(t)return this.toolInstance=t,t}get firstToolInstance(){return this.toolScheduler.getFirstToolOperation()}setCustomRenderStyle(t){this.toolInstance.setCustomRenderStyle(t)}}module.exports=AnnotationEngine;
@@ -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"),pointCloud2dOperation=require("../toolOperation/pointCloud2dOperation.js");const createEmptyImage=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 PointCloudAnnotation{constructor({size:t,container:o,pcdPath:e,polygonOperationProps:u,config:a}){this.updatePolygonList=(O,g)=>{let d=O.map(r=>{var m;const{polygon2d:f}=this.pointCloudInstance.getBoxTopPolygon2DCoordinate(r);return{id:r.id,sourceID:"",pointList:f,isRect:!0,valid:(m=r.valid)!=null?m:!0,attribute:r.attribute}});g&&(d=d.concat(g)),this.pointCloud2dOperation.setResult(d)};var c,p;const v=this.getDefaultOrthographic(t),P=createEmptyImage(t),h=new Image;h.src=P;const l=new CanvasScheduler.CanvasScheduler({container:o}),s=new index.PointCloud({container:o,noAppend:!0,isOrthographicCamera:!0,orthographicParams:v});e&&s.loadPCDFile(e),l.createCanvas(s.renderer.domElement);const C={container:o,size:t,config:JSON.stringify(a),imgNode:h,isAppend:!1};u&&Object.assign(C,u);const i=new pointCloud2dOperation(C);i.eventBinding(),i.setPattern(tool.EPolygonPattern.Rect),i.setDefaultAttribute((p=(c=a==null?void 0:a.attributeList)==null?void 0:c[0])==null?void 0:p.value),l.createCanvas(i.canvas,{size:t}),this.pointCloud2dOperation=i,this.pointCloudInstance=s,this.canvasScheduler=l,this.config=a}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=createEmptyImage(t),e=new Image;e.src=o,e.onload=()=>{this.pointCloud2dOperation.setImgNode(e),this.pointCloud2dOperation.setCanvasSize(t),this.pointCloud2dOperation.initImgPos()}}addPolygonListOnTopView(t){const o=lbUtils.PointCloudUtils.getBoxParamsFromResultList(t),e=lbUtils.PointCloudUtils.getPolygonListFromResultList(t);this.updatePolygonList(o,e)}updateData(t,o,e){!this.pointCloud2dOperation||!this.pointCloudInstance||(this.pointCloudInstance.loadPCDFile(t,e==null?void 0:e.radius),this.addPolygonListOnTopView(o))}initAllPosition(){this.pointCloudInstance.updateTopCamera(),this.pointCloud2dOperation.initPosition()}clearAllData(){this.pointCloudInstance.clearPointCloudAndRender(),this.pointCloud2dOperation.clearResult()}}exports.PointCloudAnnotation=PointCloudAnnotation;
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"),pointCloud2dOperation=require("../toolOperation/pointCloud2dOperation.js"),__defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnPropDescs=Object.getOwnPropertyDescriptors,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(o,t,e)=>t in o?__defProp(o,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):o[t]=e,__spreadValues=(o,t)=>{for(var e in t||(t={}))__hasOwnProp.call(t,e)&&__defNormalProp(o,e,t[e]);if(__getOwnPropSymbols)for(var e of __getOwnPropSymbols(t))__propIsEnum.call(t,e)&&__defNormalProp(o,e,t[e]);return o},__spreadProps=(o,t)=>__defProps(o,__getOwnPropDescs(t));const createEmptyImage=o=>{const t=document.createElement("canvas");t.width=o.width,t.height=o.height;const e=t.getContext("2d");return e?(e.fillStyle="black",e.fillRect(0,0,o.width,o.height),t.toDataURL()):""};class PointCloudAnnotation{constructor({size:t,container:e,pcdPath:n,polygonOperationProps:c,config:s,checkMode:P}){this.updatePolygonList=(_,v)=>{let u=_.map(i=>{var a;const{polygon2d:p}=this.pointCloudInstance.getBoxTopPolygon2DCoordinate(i);return{id:i.id,sourceID:"",pointList:p,isRect:!0,valid:(a=i.valid)!=null?a:!0,attribute:i.attribute}});v&&(u=u.concat(v.map(i=>{var a;return __spreadProps(__spreadValues({},i),{pointList:(a=i==null?void 0:i.pointList)==null?void 0:a.map(p=>lbUtils.PointCloudUtils.transferWorld2Canvas(p,this.pointCloud2dOperation.size))})}))),this.pointCloud2dOperation.setResult(u)};var h,C;const f=this.getDefaultOrthographic(t),m=createEmptyImage(t),g=new Image;g.src=m;const l=new CanvasScheduler.CanvasScheduler({container:e}),d=new index.PointCloud({container:e,noAppend:!0,isOrthographicCamera:!0,orthographicParams:f});n&&d.loadPCDFile(n),l.createCanvas(d.renderer.domElement);const O={container:e,size:t,config:JSON.stringify(s),imgNode:g,isAppend:!1,checkMode:P};c&&Object.assign(O,c);const r=new pointCloud2dOperation(O);r.eventBinding(),r.setPattern(tool.EPolygonPattern.Rect),r.setDefaultAttribute((C=(h=s==null?void 0:s.attributeList)==null?void 0:h[0])==null?void 0:C.value),l.createCanvas(r.canvas,{size:t}),this.pointCloud2dOperation=r,this.pointCloudInstance=d,this.canvasScheduler=l,this.config=s}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),n=new Image;n.src=e,n.onload=()=>{this.pointCloud2dOperation.setImgNode(n),this.pointCloud2dOperation.initImgPos()},this.pointCloud2dOperation.setCanvasSize(t)}addPolygonListOnTopView(t){const e=lbUtils.PointCloudUtils.getBoxParamsFromResultList(t),n=lbUtils.PointCloudUtils.getPolygonListFromResultList(t);this.updatePolygonList(e,n)}updateData(t,e,n){!this.pointCloud2dOperation||!this.pointCloudInstance||(this.pointCloudInstance.loadPCDFile(t,n==null?void 0:n.radius),this.addPolygonListOnTopView(e))}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=require("../../_virtual/highlightWorker.js"),filterBoxWorker=require("../../_virtual/filterBoxWorker.js"),polygonTool=require("../../utils/tool/polygonTool.js"),uuid=require("../../utils/uuid.js"),PCDLoader=require("./PCDLoader.js"),OrbitControls=require("./OrbitControls.js"),cache=require("./cache.js"),matrix=require("./matrix.js");require("../../constant/tool.js"),require("../../constant/annotation.js"),require("../../utils/MathUtils.js"),require("@turf/turf"),require("../../utils/tool/CommonToolUtils.js"),require("../../utils/tool/LineToolUtils.js"),require("../../utils/tool/DrawUtils.js"),require("../../constant/keyCode.js"),require("../../locales/index.js"),require("../../locales/constants.js"),require("lodash"),require("../../constant/style.js"),require("../../utils/tool/CanvasUtils.js"),require("../../utils/tool/ZoomUtils.js");function _interopNamespace(p){if(p&&p.__esModule)return p;var t=Object.create(null);return p&&Object.keys(p).forEach(function(e){if(e!=="default"){var r=Object.getOwnPropertyDescriptor(p,e);Object.defineProperty(t,e,r.get?r:{enumerable:!0,get:function(){return p[e]}})}}),t.default=p,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=(p,t,e)=>t in p?__defProp(p,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):p[t]=e,__spreadValues=(p,t)=>{for(var e in t||(t={}))__hasOwnProp.call(t,e)&&__defNormalProp(p,e,t[e]);if(__getOwnPropSymbols)for(var e of __getOwnPropSymbols(t))__propIsEnum.call(t,e)&&__defNormalProp(p,e,t[e]);return p},__spreadProps=(p,t)=>__defProps(p,__getOwnPropDescs(t)),__async=(p,t,e)=>new Promise((r,o)=>{var s=n=>{try{i(e.next(n))}catch(c){o(c)}},a=n=>{try{i(e.throw(n))}catch(c){o(c)}},i=n=>n.done?r(n.value):Promise.resolve(n.value).then(s,a);i((e=e.apply(p,t)).next())});const DEFAULT_DISTANCE=30;new highlightWorker;class PointCloud{constructor({container:t,noAppend:e,isOrthographicCamera:r,orthographicParams:o,backgroundColor:s="black",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.AddBoxToSense=(i,n=16777215)=>{var c;const h=(c=i.id)!=null?c:uuid();this.removeObjectByName(h);const{center:l,width:d,height:x,depth:g,rotation:m}=i,u=new THREE__namespace.Group,y=new THREE__namespace.BoxGeometry(d,x,g),w=new THREE__namespace.MeshBasicMaterial({color:"blue"}),f=new THREE__namespace.Mesh(y,w),v=new THREE__namespace.BoxHelper(f,n),P=this.generateBoxArrow(i);u.add(v),u.add(P),u.position.set(l.x,l.y,l.z),u.rotation.set(0,0,m),u.name=h,this.scene.add(u)},this.overridePointShader=i=>{i.vertexShader=`
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var THREE=require("three"),lbUtils=require("@labelbee/lb-utils"),highlightWorker=require("../../_virtual/highlightWorker.js"),filterBoxWorker=require("../../_virtual/filterBoxWorker.js"),polygonTool=require("../../utils/tool/polygonTool.js"),uuid=require("../../utils/uuid.js"),PCDLoader=require("./PCDLoader.js"),OrbitControls=require("./OrbitControls.js"),cache=require("./cache.js"),matrix=require("./matrix.js");require("../../constant/tool.js"),require("../../constant/annotation.js"),require("../../utils/MathUtils.js"),require("@turf/turf"),require("../../utils/tool/CommonToolUtils.js"),require("../../utils/tool/LineToolUtils.js"),require("../../utils/tool/DrawUtils.js"),require("../../constant/keyCode.js"),require("../../locales/index.js"),require("../../locales/constants.js"),require("lodash"),require("../../constant/style.js"),require("../../utils/tool/CanvasUtils.js"),require("../../utils/tool/ZoomUtils.js");function _interopNamespace(p){if(p&&p.__esModule)return p;var t=Object.create(null);return p&&Object.keys(p).forEach(function(e){if(e!=="default"){var r=Object.getOwnPropertyDescriptor(p,e);Object.defineProperty(t,e,r.get?r:{enumerable:!0,get:function(){return p[e]}})}}),t.default=p,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=(p,t,e)=>t in p?__defProp(p,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):p[t]=e,__spreadValues=(p,t)=>{for(var e in t||(t={}))__hasOwnProp.call(t,e)&&__defNormalProp(p,e,t[e]);if(__getOwnPropSymbols)for(var e of __getOwnPropSymbols(t))__propIsEnum.call(t,e)&&__defNormalProp(p,e,t[e]);return p},__spreadProps=(p,t)=>__defProps(p,__getOwnPropDescs(t)),__async=(p,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(p,t)).next())});const DEFAULT_DISTANCE=30;new highlightWorker;class PointCloud{constructor({container:t,noAppend:e,isOrthographicCamera:r,orthographicParams:n,backgroundColor:s="black",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.AddBoxToSense=(i,o=16777215)=>{var c;const h=(c=i.id)!=null?c:uuid();this.removeObjectByName(h);const{center:l,width:d,height:x,depth:g,rotation:m}=i,u=new THREE__namespace.Group,y=new THREE__namespace.BoxGeometry(d,x,g),w=new THREE__namespace.MeshBasicMaterial({color:"blue"}),f=new THREE__namespace.Mesh(y,w),v=new THREE__namespace.BoxHelper(f,o),P=this.generateBoxArrow(i);u.add(v),u.add(P),u.position.set(l.x,l.y,l.z),u.rotation.set(0,0,m),u.name=h,this.scene.add(u)},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,n)=>__async(this,null,function*(){this.clearPointCloud();const c=yield this.cacheInstance.loadPCDFile(i);c.name=this.pointCloudObjectName,this.renderPointCloud(c,n)}),this.loadPCDFileByBox=(i,n,c)=>__async(this,null,function*(){const h=d=>__async(this,null,function*(){const{width:x=0,height:g=0,depth:m=0}=c!=null?c:{},u=yield this.filterPointsByBox(__spreadProps(__spreadValues({},n),{width:n.width+x,height:n.height+g,depth:n.depth+m}),d);if(!u){console.error("filter Error");return}this.clearPointCloud();const y=new THREE__namespace.Points(u.geometry,d.material);y.name=this.pointCloudObjectName,this.scene.add(y),this.render()}),l=yield this.cacheInstance.loadPCDFile(i);h(l)}),this.generateBoxArrow=({width:i})=>{const n=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(n,c,h,l);return d.visible=this.showDirection,d},this.generateBoxTrackID=i=>{if(!i.trackID)return;const n=new THREE__namespace.Texture(this.getTextCanvas(i.trackID.toString()));n.needsUpdate=!0;const c=new THREE__namespace.SpriteMaterial({map:n,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 n=this.scene.getObjectByName(this.pointCloudObjectName);if(!n)return;const c=n.material.size;i?n.material.size=Math.min(c*1.2,10):n.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&&o?(this.isOrthographicCamera=!0,this.camera=new THREE__namespace.OrthographicCamera(o.left,o.right,o.top,o.bottom,o.near,o.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(-1,0,10)}get containerWidth(){return this.container.clientWidth}get containerHeight(){return this.container.clientHeight}setInitCameraPosition(t){this.initCameraPosition=t}initOrthographicCamera(t){if(this.camera.type!=="OrthographicCamera")return;const{left:e,right:r,top:o,bottom:s,near:a,far:i}=t;this.camera.left=e,this.camera.right=r,this.camera.top=o,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:o}=this.initCameraPosition;t.position.set(e,r,o)}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){var r,o,s,a,i;let n=e;((r=this.config)==null?void 0:r.attributeList)&&((s=(o=this.config)==null?void 0:o.attributeList)==null?void 0:s.length)>0&&t.attribute&&(n=(i=(a=lbUtils.toolStyleConverter.getColorFromConfig({attribute:t.attribute},__spreadProps(__spreadValues({},this.config),{attributeConfigurable:!0}),{}))==null?void 0:a.hex)!=null?i:e),this.AddBoxToSense(t,n),this.render()}generateBoxes(t){t.forEach(e=>{this.generateBox(e)}),this.render()}getOrthographicCamera(t){const{center:e,width:r,height:o}=t,s=10,a=e.x-r/2-s,i=e.x-r/2+s,n=e.y+o/2+s,c=e.y-o/2-s,h=100,l=-100,d=500/h;return{left:a,right:i,top:n,bottom:c,near:h,far:l,zoom:d}}updateCameraByBox(t,e){const{center:r,width:o,height:s,depth:a,rotation:i}=t,n=this.getCameraVector(r,i,{width:o,height:s,depth:a},e);return this.updateCamera(n,r),n}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({x:-1,y:0,z:500},{x:0,y:0,z:0})}createThreeMatrix4(t){return new THREE__namespace.Matrix4().set(...t)}filterPointsByBox(t,e){if(!e){const r=this.scene.getObjectByName(this.pointCloudObjectName);if(!r)return console.error("There is no corresponding point cloud object"),Promise.resolve(void 0);e=r}if(window.Worker){const{zMin:r,zMax:o,polygonPointList:s}=matrix.getCuboidFromPointCloudBox(t),a=e.geometry.attributes.position.array,i=e.geometry.attributes.color.array,n={boxParams:t,zMin:r,zMax:o,polygonPointList:s,color:i,position:a};return new Promise(c=>{const h=new filterBoxWorker;h.postMessage(n),h.onmessage=l=>{const{color:d,position:x,num:g}=l.data,m=new THREE__namespace.BufferGeometry;m.setAttribute("position",new THREE__namespace.Float32BufferAttribute(x,3)),m.setAttribute("color",new THREE__namespace.Float32BufferAttribute(d,3)),m.computeBoundingSphere(),h.terminate(),c({geometry:m,num:g})}})}return Promise.resolve(void 0)}getCameraVector(t,e,r,o=lbUtils.EPerspectiveView.Front,s=DEFAULT_DISTANCE){let a=lbUtils.PerspectiveShiftUtils.frontViewMatrix4(s);switch(o){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),n=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(n).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),o=new THREE__namespace.BufferGeometry().setFromPoints(r),s=new THREE__namespace.LineBasicMaterial({color:16711680}),a=new THREE__namespace.Line(o,s);return a.name=this.rangeObjectName,a}renderPointCloud(t,e){t.material.size=1,t.name=this.pointCloudObjectName;const r=new THREE__namespace.PointsMaterial({vertexColors:!0});if(r.onBeforeCompile=this.overridePointShader,e){const o=this.createRange(e);this.scene.add(o)}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){}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}getSensesPointZAxisInPolygon(t,e){const r=this.scene.children.find(n=>n.uuid===this.pointsUuid);let o=0,s=0,a=0,i=0;if(r&&(r==null?void 0:r.geometry)){const n=r==null?void 0:r.geometry.attributes.position.array;for(let c=0;c<n.length;c+=3){const h=n[c],l=n[c+1],d=n[c+2];polygonTool.isInPolygon({x:h,y:l},t)&&d&&(s=Math.max(d,s),o=Math.min(d,o),i++,e&&d>=e[0]&&d<=e[1]&&a++)}}return{maxZ:s,minZ:o,count:a,zCount:i}}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:o},height:s,width:a,depth:i}=t,n={x:e+a/2,y:r+s/2,z:o-i/2},c={x:e+a/2,y:r+s/2,z:o+i/2},h={x:e-a/2,y:r+s/2,z:o+i/2},l={x:e-a/2,y:r+s/2,z:o-i/2};return[n,c,h,l]}getPolygonBackPoints(t){const{center:{x:e,y:r,z:o},height:s,width:a,depth:i}=t,n={x:e-a/2,y:r+s/2,z:o+i/2},c={x:e-a/2,y:r+s/2,z:o-i/2},h={x:e-a/2,y:r-s/2,z:o-i/2},l={x:e-a/2,y:r-s/2,z:o+i/2};return[n,c,h,l]}getPolygonTopPoints(t){const{center:{x:e,y:r,z:o},height:s,width:a,depth:i}=t,n={x:e+a/2,y:r+s/2,z:o+i/2},c={x:e+a/2,y:r-s/2,z:o+i/2},h={x:e-a/2,y:r-s/2,z:o+i/2},l={x:e-a/2,y:r+s/2,z:o+i/2};return[n,c,h,l]}getModelTransformationMatrix(t){const{center:{x:e,y:r,z:o},rotation:s}=t,a=new THREE__namespace.Matrix4().makeTranslation(-e,-r,-o),i=new THREE__namespace.Matrix4().makeTranslation(e,r,o),n=new THREE__namespace.Matrix4().makeRotationZ(s);return new THREE__namespace.Matrix4().multiply(i).multiply(n).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:o,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 n=r.map(l=>new THREE__namespace.Vector3(l.x,l.y,l.z)).map(l=>l.applyMatrix4(this.sideMatrix)),c=this.containerWidth/o,h=this.containerHeight/s;return{polygon2d:n,zoom:Math.min(c,h)/2}}getBoxTopPolygon2DCoordinate(t){const{width:e,height:r}=t,s=this.getPolygonTopPoints(t).map(n=>new THREE__namespace.Vector3(n.x,n.y,n.z)).map(n=>n.applyMatrix4(this.getModelTransformationMatrix(t))).map(n=>({x:n.y,y:n.x})).map(n=>({x:-(n.x-this.containerWidth/2),y:-(n.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,o){const s=new THREE__namespace.Matrix4().makeRotationZ(o.rotation),a=new THREE__namespace.Vector3(-t.x,0,0).applyMatrix4(s);let i=o;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,o){const s=new THREE__namespace.Matrix4().makeRotationZ(o.rotation),a=new THREE__namespace.Vector3(0,-t.x,0).applyMatrix4(s);let i=o;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,o){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)),[n,c,h,l]=i,d=Math.max(Math.abs(n.x-h.x),Math.abs(n.x-c.x)),g=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(o.center.x,o.center.y,o.center.z));return{newBoxParams:__spreadProps(__spreadValues({},o),{center:{x:o.center.x-g.x,y:o.center.y-g.y,z:o.center.z-r},width:d,height:o.height,depth:o.depth+e,rotation:o.rotation})}}filterZAxisPoints(t){const e=t||this.scene.children.find(r=>r.uuid===this.pointsUuid);if(e){const{attributes:r}=e.geometry,{position:o}=r,s=[],{count:a}=o;for(let i=0;i<a;i++){const n=o.getZ(i);s.push(n>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();const c=yield this.cacheInstance.loadPCDFile(i);c.name=this.pointCloudObjectName,this.renderPointCloud(c,o)}),this.loadPCDFileByBox=(i,o,c)=>__async(this,null,function*(){const h=d=>__async(this,null,function*(){const{width:x=0,height:g=0,depth:m=0}=c!=null?c:{},u=yield this.filterPointsByBox(__spreadProps(__spreadValues({},o),{width:o.width+x,height:o.height+g,depth:o.depth+m}),d);if(!u){console.error("filter Error");return}this.clearPointCloud();const y=new THREE__namespace.Points(u.geometry,d.material);y.name=this.pointCloudObjectName,this.scene.add(y),this.render()}),l=yield this.cacheInstance.loadPCDFile(i);h(l)}),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(-1,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){var r,n,s,a,i;let o=e;((r=this.config)==null?void 0:r.attributeList)&&((s=(n=this.config)==null?void 0:n.attributeList)==null?void 0:s.length)>0&&t.attribute&&(o=(i=(a=lbUtils.toolStyleConverter.getColorFromConfig({attribute:t.attribute},__spreadProps(__spreadValues({},this.config),{attributeConfigurable:!0}),{}))==null?void 0:a.hex)!=null?i:e),this.AddBoxToSense(t,o),this.render()}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}}updateCameraByBox(t,e){const{center:r,width:n,height:s,depth:a,rotation:i}=t,o=this.getCameraVector(r,i,{width:n,height:s,depth:a},e);return this.updateCamera(o,r),o}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({x:-1,y:0,z:500},{x:0,y:0,z:0})}createThreeMatrix4(t){return new THREE__namespace.Matrix4().set(...t)}filterPointsByBox(t,e){if(!e){const r=this.scene.getObjectByName(this.pointCloudObjectName);if(!r)return console.error("There is no corresponding point cloud object"),Promise.resolve(void 0);e=r}if(window.Worker){const{zMin:r,zMax:n,polygonPointList:s}=matrix.getCuboidFromPointCloudBox(t),a=e.geometry.attributes.position.array,i=e.geometry.attributes.color.array,o={boxParams:t,zMin:r,zMax:n,polygonPointList:s,color:i,position:a};return new Promise(c=>{const h=new filterBoxWorker;h.postMessage(o),h.onmessage=l=>{const{color:d,position:x,num:g}=l.data,m=new THREE__namespace.BufferGeometry;m.setAttribute("position",new THREE__namespace.Float32BufferAttribute(x,3)),m.setAttribute("color",new THREE__namespace.Float32BufferAttribute(d,3)),m.computeBoundingSphere(),h.terminate(),c({geometry:m,num:g})}})}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.material.size=1,t.name=this.pointCloudObjectName;const r=new THREE__namespace.PointsMaterial({vertexColors:!0});r.onBeforeCompile=this.overridePointShader,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){}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}getSensesPointZAxisInPolygon(t,e){const r=this.scene.children.find(o=>o.uuid===this.pointsUuid);let n=0,s=0,a=0,i=0;if(r&&(r==null?void 0:r.geometry)){const o=r==null?void 0:r.geometry.attributes.position.array;for(let c=0;c<o.length;c+=3){const h=o[c],l=o[c+1],d=o[c+2];polygonTool.isInPolygon({x:h,y:l},t)&&d&&(s=Math.max(d,s),n=Math.min(d,n),i++,e&&d>=e[0]&&d<=e[1]&&a++)}}return{maxZ:s,minZ:n,count:a,zCount:i}}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)}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}}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)),g=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-g.x,y:n.center.y-g.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;
@@ -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=o=>{const t=document.createElement("canvas");t.width=o.width,t.height=o.height;const i=t.getContext("2d");return i?(i.fillStyle="transparent",i.fillRect(0,0,o.width,o.height),t.toDataURL()):""},arraySwap=(o,t,i)=>{const e=o[t];return o[t]=o[i],o[i]=e,o},_HybridToolUtils=class{static isSingleTool(o){return!this.isHybridTool(o)}static isHybridTool(o){return Array.isArray(o)}};let HybridToolUtils=_HybridToolUtils;HybridToolUtils.getTopToolName=o=>_HybridToolUtils.isHybridTool(o)?o[o.length-1]:o;class ToolScheduler{constructor(t){this.toolOperationList=[],this.toolOperationDom=[];var i,e;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=(e=t.style)!=null?e:defaultConfig.styleDefaultConfig}setImgNode(t,i){this.toolOperationList.forEach(e=>{e.setImgNode(t,i)})}setSize(t){this.toolOperationList.forEach(i=>{i.setSize(t)})}syncPosition(t,i,e,n){this.toolOperationList.forEach(r=>{n!==r&&(r.setCurrentPos(t),r.setZoom(i),r.setImgInfo(e),r.renderBasicCanvas(),r.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,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=`${i}px`;const n=this.toolOperationList.length+1;return e.style.zIndex=`${n}`,e}getEmptyImage(t,i){const e=createEmptyImage({width:t,height:i}),n=new Image;return n.src=e,n}createOperation(t,i,e){var n;const{width:r,height:u}=this.defaultSize,l=this.createDom(),g=this.getEmptyImage(r,u),c={container:l,size:this.size,config:(n=this==null?void 0:this.config)!=null?n:"{}",drawOutSideTarget:!1,style:this.style,imgNode:i||g,hiddenImg:!!t};e&&Object.assign(c,e);let s;if(!t)s=new basicToolOperation.BasicToolOperation(c),l.style.zIndex="0",s.init();else{const a=EnhanceCommonToolUtils.getCurrentOperation(t);if(!a)return;s=new a(c)}return s==null||s.init(),s.canvas.id=t!=null?t:"basicCanvas",s.on("dragMove",({currentPos:a,zoom:h,imgInfo:d})=>{this.syncPosition(a,h,d,s)}),s.on("renderZoom",(a,h,d)=>{a&&h&&this.syncPosition(h,a,d,s)}),t?(this.container.appendChild(l),this.toolOperationList.push(s),this.toolOperationDom.push(l),s):(this.container.insertBefore(l,this.container.childNodes[0]),this.toolOperationList.unshift(s),this.toolOperationDom.unshift(l),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,i=t-1,e=t-2,n=this.toolOperationDom[i],r=this.toolOperationDom[e];if(!(!r||!n))return n.style.zIndex=`${i-1}`,r.style.zIndex=`${i}`,this.toolOperationList[i].clearActiveStatus(),this.toolOperationList[i].clearCursorLine(),this.toolOperationList[i].render(),this.toolOperationList=arraySwap(this.toolOperationList,i,e),this.toolOperationDom=arraySwap(this.toolOperationDom,i,e),this.toolOperationList[i]}getFirstToolOperation(){return this.toolOperationList.length>1?this.toolOperationList[1]:this.toolOperationList[0]}destroyAllLayer(){this.toolOperationList.forEach(t=>{t.destroyCanvas(),this.init()})}init(){this.toolOperationList=[],this.toolOperationDom=[]}}exports.HybridToolUtils=HybridToolUtils,exports.ToolScheduler=ToolScheduler;
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=o=>{const t=document.createElement("canvas");t.width=o.width,t.height=o.height;const i=t.getContext("2d");return i?(i.fillStyle="transparent",i.fillRect(0,0,o.width,o.height),t.toDataURL()):""},arraySwap=(o,t,i)=>{const e=o[t];return o[t]=o[i],o[i]=e,o},_HybridToolUtils=class{static isSingleTool(o){return!this.isHybridTool(o)}static isHybridTool(o){return Array.isArray(o)}};let HybridToolUtils=_HybridToolUtils;HybridToolUtils.getTopToolName=o=>_HybridToolUtils.isHybridTool(o)?o[o.length-1]:o;class ToolScheduler{constructor(t){this.toolOperationList=[],this.toolOperationDom=[];var i,e;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=(e=t.style)!=null?e:defaultConfig.styleDefaultConfig}setImgNode(t,i){this.toolOperationList.forEach(e=>{e.setImgNode(t,i)})}setImgAttribute(t){this.toolOperationList.forEach(i=>{i.setImgAttribute(t)})}setSize(t){this.toolOperationList.forEach(i=>{i.setSize(t)})}syncPosition(t,i,e,n){this.toolOperationList.forEach(r=>{n!==r&&(r.setCurrentPos(t),r.setZoom(i),r.setImgInfo(e),r.renderBasicCanvas(),r.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,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=`${i}px`;const n=this.toolOperationList.length+1;return e.style.zIndex=`${n}`,e}getEmptyImage(t,i){const e=createEmptyImage({width:t,height:i}),n=new Image;return n.src=e,n}createOperation(t,i,e){var n;const{width:r,height:u}=this.defaultSize,l=this.createDom(),g=this.getEmptyImage(r,u),c={container:l,size:this.size,config:(n=this==null?void 0:this.config)!=null?n:"{}",drawOutSideTarget:!1,style:this.style,imgNode:i||g,hiddenImg:!!t};e&&Object.assign(c,e);let s;if(!t)s=new basicToolOperation.BasicToolOperation(c),l.style.zIndex="0",s.init();else{const a=EnhanceCommonToolUtils.getCurrentOperation(t);if(!a)return;s=new a(c)}return s==null||s.init(),s.canvas.id=t!=null?t:"basicCanvas",s.on("dragMove",({currentPos:a,zoom:h,imgInfo:d})=>{this.syncPosition(a,h,d,s)}),s.on("renderZoom",(a,h,d)=>{a&&h&&this.syncPosition(h,a,d,s)}),t?(this.container.appendChild(l),this.toolOperationList.push(s),this.toolOperationDom.push(l),s):(this.container.insertBefore(l,this.container.childNodes[0]),this.toolOperationList.unshift(s),this.toolOperationDom.unshift(l),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,i=t-1,e=t-2,n=this.toolOperationDom[i],r=this.toolOperationDom[e];if(!(!r||!n))return n.style.zIndex=`${i-1}`,r.style.zIndex=`${i}`,this.toolOperationList[i].clearActiveStatus(),this.toolOperationList[i].clearCursorLine(),this.toolOperationList[i].render(),this.toolOperationList=arraySwap(this.toolOperationList,i,e),this.toolOperationDom=arraySwap(this.toolOperationDom,i,e),this.toolOperationList[i]}getFirstToolOperation(){return this.toolOperationList.length>1?this.toolOperationList[1]:this.toolOperationList[0]}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 lbUtils=require("@labelbee/lb-utils"),annotation=require("../../constant/annotation.js"),tool=require("../../constant/tool.js"),AxisUtils=require("../../utils/tool/AxisUtils.js"),CommonToolUtils=require("../../utils/tool/CommonToolUtils.js"),DrawUtils=require("../../utils/tool/DrawUtils.js"),PolygonUtils=require("../../utils/tool/PolygonUtils.js"),defaultConfig=require("../../constant/defaultConfig.js"),polygonOperation=require("./polygonOperation.js"),__defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnPropDescs=Object.getOwnPropertyDescriptors,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(r,t,e)=>t in r?__defProp(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,__spreadValues=(r,t)=>{for(var e in t||(t={}))__hasOwnProp.call(t,e)&&__defNormalProp(r,e,t[e]);if(__getOwnPropSymbols)for(var e of __getOwnPropSymbols(t))__propIsEnum.call(t,e)&&__defNormalProp(r,e,t[e]);return r},__spreadProps=(r,t)=>__defProps(r,__getOwnPropDescs(t));class PointCloud2dOperation extends polygonOperation{constructor(t){super(t);this.selectedIDs=[],this.rightMouseUp=a=>{var s;if(this.drawingPointList.length>0){this.addDrawingPointToPolygonList();return}a.ctrlKey&&this.hoverID?this.emit("addSelectedIDs",this.hoverID):this.emit("setSelectedIDs",this.hoverID);const d=(s=this.hoverPolygon)==null?void 0:s.attribute;d&&d!==this.defaultAttribute&&this.emit("syncAttribute",d)},this.onKeyDown=()=>{},this.onKeyUp=()=>{},this.renderSingleSelectedPolygon=a=>{var s;if(this.selectedPolygons){const d=this.getPointCloudLineColor(a.attribute),c=AxisUtils.default.changePointListByZoom(a.pointList,this.zoom,this.currentPos);DrawUtils.drawSelectedPolygonWithFillAndLine(this.canvas,c,{fillColor:"transparent",strokeColor:d,pointColor:"white",thickness:2,lineCap:"round",isClose:!0,lineType:(s=this.config)==null?void 0:s.lineType}),a.isRect===!0&&this.showDirectionLine===!0&&this.renderRectPolygonDirection(c)}};var e,o,i,n,l;this.showDirectionLine=(e=t.showDirectionLine)!=null?e:!0,this.forbidAddNew=(o=t.forbidAddNew)!=null?o:!1,this.pointCloudConfig=(i=CommonToolUtils.jsonParser(t.config))!=null?i:{},this.config=__spreadProps(__spreadValues({},defaultConfig.polygonConfig),{textConfigurable:!1,attributeConfigurable:!0,attributeList:(l=(n=this.pointCloudConfig)==null?void 0:n.attributeList)!=null?l:[]})}get getSelectedIDs(){return this.selectedIDs}setSelectedIDs(t){this.selectedIDs=t,this.setSelectedID(this.selectedIDs.length===1?this.selectedIDs[0]:""),this.render()}deleteSelectedID(){super.deleteSelectedID(),this.selectedIDs=[],this.emit("deleteSelectedIDs")}get selectedPolygons(){return PolygonUtils.getPolygonByIDs(this.polygonList,this.selectedIDs)}getLineColor(){return"rgba(0, 255, 255, 0.5)"}getPointCloudLineColor(t=""){return lbUtils.toolStyleConverter.getColorFromConfig({attribute:t},__spreadProps(__spreadValues({},this.pointCloudConfig),{attributeConfigurable:!0}),{}).stroke}renderStaticPolygon(){var t;this.isHidden===!1&&((t=this.polygonList)==null||t.forEach(e=>{var o,i,n;if([...this.selectedIDs,this.editPolygonID].includes(e.id))return;const{attribute:l}=e,a=this.getPointCloudLineColor(l),s=AxisUtils.default.changePointListByZoom(e.pointList||[],this.zoom,this.currentPos);DrawUtils.drawPolygonWithFillAndLine(this.canvas,s,{fillColor:"transparent",strokeColor:a,pointColor:"white",thickness:(i=(o=this.style)==null?void 0:o.width)!=null?i:2,lineCap:"round",isClose:!0,lineType:(n=this.config)==null?void 0:n.lineType}),e.isRect===!0&&this.showDirectionLine===!0&&this.renderRectPolygonDirection(s)}))}renderSelectedPolygon(){var t;(t=this.selectedPolygons)==null||t.forEach(e=>{this.renderSingleSelectedPolygon(e)})}renderRectPolygonDirection(t){t.length<2||DrawUtils.drawLine(this.canvas,t[0],t[1],{color:"white",thickness:3,lineDash:[6]})}get currentPolygonListByPattern(){return this.polygonList.filter(t=>this.pattern===tool.EPolygonPattern.Rect?t.isRect===!0:this.pattern===tool.EPolygonPattern.Normal?t.isRect!==!0:!0)}getHoverID(t){var e;const o=this.getCoordinateUnderZoom(t),n=this.currentPolygonListByPattern.map(l=>__spreadProps(__spreadValues({},l),{pointList:AxisUtils.default.changePointListByZoom(l.pointList,this.zoom)}));return PolygonUtils.getHoverPolygonID(o,n,10,(e=this.config)==null?void 0:e.lineType)}switchToNextPolygon(t=annotation.ESortDirection.ascend){if(this.drawingPointList.length>0)return;const e=this.currentPolygonListByPattern.map(i=>{var n,l,a,s;return __spreadProps(__spreadValues({},i),{x:(l=(n=i.pointList[0])==null?void 0:n.x)!=null?l:0,y:(s=(a=i.pointList[0])==null?void 0:a.y)!=null?s:0})}),o=CommonToolUtils.getNextSelectedRectID(e,t,this.selectedID);if(o)return this.setSelectedIDs([o.id]),this.render(),[o.id]}setSelectedIdAfterAddingDrawing(t){this.drawingPointList.length!==0&&this.setSelectedID(t)}setSelectedID(t){var e,o;const i=this.selectedID;t!==i&&i&&((e=this._textAttributInstance)==null||e.changeSelected()),t||(o=this._textAttributInstance)==null||o.clearTextAttribute(),this.selectedID=t,this.selectedIDs=t?[t]:[],this.render()}addPointInDrawing(t){this.forbidAddNew||super.addPointInDrawing(t)}setCanvasSize(t){var e,o;const i=this.pixelRatio;this.size=t,this.setImgInfo(t),this.updateCanvasBasicStyle(this.basicCanvas,t,0),this.updateCanvasBasicStyle(this.canvas,t,10),(e=this.ctx)==null||e.scale(i,i),(o=this.basicCtx)==null||o.scale(i,i),this.initImgPos(),this.renderBasicCanvas(),this.render()}setPolygonValidAndRender(t,e=!1){if(e){super.setPolygonValidAndRender(t);return}this.emit("validUpdate",t)}}module.exports=PointCloud2dOperation;
1
+ "use strict";var lbUtils=require("@labelbee/lb-utils"),annotation=require("../../constant/annotation.js"),tool=require("../../constant/tool.js"),AxisUtils=require("../../utils/tool/AxisUtils.js"),CommonToolUtils=require("../../utils/tool/CommonToolUtils.js"),DrawUtils=require("../../utils/tool/DrawUtils.js"),PolygonUtils=require("../../utils/tool/PolygonUtils.js"),defaultConfig=require("../../constant/defaultConfig.js"),polygonOperation=require("./polygonOperation.js"),__defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnPropDescs=Object.getOwnPropertyDescriptors,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(r,t,e)=>t in r?__defProp(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,__spreadValues=(r,t)=>{for(var e in t||(t={}))__hasOwnProp.call(t,e)&&__defNormalProp(r,e,t[e]);if(__getOwnPropSymbols)for(var e of __getOwnPropSymbols(t))__propIsEnum.call(t,e)&&__defNormalProp(r,e,t[e]);return r},__spreadProps=(r,t)=>__defProps(r,__getOwnPropDescs(t));class PointCloud2dOperation extends polygonOperation{constructor(t){super(t);this.selectedIDs=[],this.rightMouseUp=s=>{var d;if(this.drawingPointList.length>0){this.addDrawingPointToPolygonList();return}s.ctrlKey&&this.hoverID?this.emit("addSelectedIDs",this.hoverID):this.emit("setSelectedIDs",this.hoverID);const c=(d=this.polygonList.find(h=>h.id===this.hoverID))==null?void 0:d.attribute;c&&c!==this.defaultAttribute&&this.emit("syncAttribute",c)},this.onKeyDown=()=>{},this.onKeyUp=()=>{},this.renderSingleSelectedPolygon=s=>{var d;if(this.selectedPolygons){const c=this.getPointCloudLineColor(s.attribute),h=AxisUtils.default.changePointListByZoom(s.pointList,this.zoom,this.currentPos);DrawUtils.drawSelectedPolygonWithFillAndLine(this.canvas,h,{fillColor:"transparent",strokeColor:c,pointColor:"white",thickness:2,lineCap:"round",isClose:!0,lineType:(d=this.config)==null?void 0:d.lineType}),s.isRect===!0&&this.showDirectionLine===!0&&this.renderRectPolygonDirection(h)}};var e,i,o,n,l,a;this.showDirectionLine=(e=t.showDirectionLine)!=null?e:!0,this.forbidAddNew=(i=t.forbidAddNew)!=null?i:!1,this.pointCloudConfig=(o=CommonToolUtils.jsonParser(t.config))!=null?o:{},this.checkMode=(n=t.checkMode)!=null?n:!1,this.forbidAddNew===!1&&t.checkMode===!0&&(this.forbidAddNew=!0),this.config=__spreadProps(__spreadValues({},defaultConfig.polygonConfig),{textConfigurable:!1,attributeConfigurable:!0,attributeList:(a=(l=this.pointCloudConfig)==null?void 0:l.attributeList)!=null?a:[]})}get getSelectedIDs(){return this.selectedIDs}setConfig(t){var e;const i=CommonToolUtils.jsonParser(t);this.pointCloudConfig=i,this.config=__spreadProps(__spreadValues({},this.config),{attributeList:(e=i==null?void 0:i.attributeList)!=null?e:[]})}dragMouseDown(t){this.checkMode||super.dragMouseDown(t)}deletePolygon(t){this.checkMode||super.deletePolygon(t)}deletePolygonPoint(t){this.checkMode||super.deletePolygonPoint(t)}setSelectedIDs(t){this.selectedIDs=t,this.setSelectedID(this.selectedIDs.length===1?this.selectedIDs[0]:""),this.render()}deleteSelectedID(){super.deleteSelectedID(),this.selectedIDs=[],this.emit("deleteSelectedIDs")}get selectedPolygons(){return PolygonUtils.getPolygonByIDs(this.polygonList,this.selectedIDs)}getLineColor(){return"rgba(0, 255, 255, 0.5)"}getPointCloudLineColor(t=""){return lbUtils.toolStyleConverter.getColorFromConfig({attribute:t},__spreadProps(__spreadValues({},this.pointCloudConfig),{attributeConfigurable:!0}),{}).stroke}renderStaticPolygon(){var t;this.isHidden===!1&&((t=this.polygonList)==null||t.forEach(e=>{var i,o,n;if([...this.selectedIDs,this.editPolygonID].includes(e.id))return;const{attribute:l}=e,a=this.getPointCloudLineColor(l),s=AxisUtils.default.changePointListByZoom(e.pointList||[],this.zoom,this.currentPos);DrawUtils.drawPolygonWithFillAndLine(this.canvas,s,{fillColor:"transparent",strokeColor:a,pointColor:"white",thickness:(o=(i=this.style)==null?void 0:i.width)!=null?o:2,lineCap:"round",isClose:!0,lineType:(n=this.config)==null?void 0:n.lineType}),e.isRect===!0&&this.showDirectionLine===!0&&this.renderRectPolygonDirection(s)}))}renderSelectedPolygon(){var t;(t=this.selectedPolygons)==null||t.forEach(e=>{this.renderSingleSelectedPolygon(e)})}renderRectPolygonDirection(t){t.length<2||DrawUtils.drawLine(this.canvas,t[0],t[1],{color:"white",thickness:3,lineDash:[6]})}get currentPolygonListByPattern(){return this.polygonList.filter(t=>this.pattern===tool.EPolygonPattern.Rect?t.isRect===!0:this.pattern===tool.EPolygonPattern.Normal?t.isRect!==!0:!0)}getHoverID(t){var e;const i=this.getCoordinateUnderZoom(t),n=this.currentPolygonListByPattern.map(l=>__spreadProps(__spreadValues({},l),{pointList:AxisUtils.default.changePointListByZoom(l.pointList,this.zoom)}));return PolygonUtils.getHoverPolygonID(i,n,10,(e=this.config)==null?void 0:e.lineType)}switchToNextPolygon(t=annotation.ESortDirection.ascend){if(this.drawingPointList.length>0)return;const e=this.currentPolygonListByPattern.map(o=>{var n,l,a,s;return __spreadProps(__spreadValues({},o),{x:(l=(n=o.pointList[0])==null?void 0:n.x)!=null?l:0,y:(s=(a=o.pointList[0])==null?void 0:a.y)!=null?s:0})}),i=CommonToolUtils.getNextSelectedRectID(e,t,this.selectedID);if(i)return this.setSelectedIDs([i.id]),this.render(),[i.id]}setSelectedIdAfterAddingDrawing(t){this.drawingPointList.length!==0&&this.setSelectedID(t)}setSelectedID(t){var e,i;const o=this.selectedID;t!==o&&o&&((e=this._textAttributInstance)==null||e.changeSelected()),t||(i=this._textAttributInstance)==null||i.clearTextAttribute(),this.selectedID=t,this.selectedIDs=t?[t]:[],this.render()}addPointInDrawing(t){this.forbidAddNew||super.addPointInDrawing(t)}setCanvasSize(t){var e,i;const o=this.pixelRatio;this.size=t,this.setImgInfo(t),this.updateCanvasBasicStyle(this.basicCanvas,t,0),this.updateCanvasBasicStyle(this.canvas,t,10),(e=this.ctx)==null||e.scale(o,o),(i=this.basicCtx)==null||i.scale(o,o),this.initImgPos(),this.renderBasicCanvas(),this.render()}setPolygonValidAndRender(t,e=!1){if(e){super.setPolygonValidAndRender(t);return}this.emit("validUpdate",t)}}module.exports=PointCloud2dOperation;
@@ -1 +1 @@
1
- "use strict";var lbUtils=require("@labelbee/lb-utils"),MathUtils=require("../../utils/MathUtils.js"),RectUtils=require("../../utils/tool/RectUtils.js"),annotation=require("../../constant/annotation.js"),keyCode=require("../../constant/keyCode.js"),tool=require("../../constant/tool.js"),index=require("../../locales/index.js"),constants=require("../../locales/constants.js"),ActionsHistory=require("../../utils/ActionsHistory.js"),AttributeUtils=require("../../utils/tool/AttributeUtils.js"),AxisUtils=require("../../utils/tool/AxisUtils.js"),CanvasUtils=require("../../utils/tool/CanvasUtils.js"),CommonToolUtils=require("../../utils/tool/CommonToolUtils.js"),DrawUtils=require("../../utils/tool/DrawUtils.js"),PolygonUtils=require("../../utils/tool/PolygonUtils.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,__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 TEXT_MAX_WIDTH=164;class PolygonOperation extends basicToolOperation.BasicToolOperation{constructor(t){super(t);this.isAllowDouble=e=>{const{selectedID:i}=this,s=this.getHoverID(e);return!!(i&&i===s)},this.textChange=e=>{this.config.textConfigurable===!1||!this.selectedID||(this.setPolygonList(AttributeUtils.default.textChange(e,this.selectedID,this.polygonList)),this.emit("selectedChange"),this.render())},this.config=CommonToolUtils.jsonParser(t.config),this.drawingPointList=[],this.polygonList=[],this.hoverPointIndex=-1,this.hoverEdgeIndex=-1,this.drawingHistory=new ActionsHistory,this.isCtrl=!1,this.isAlt=!1,this.isCombined=!1,this.pattern=tool.EPolygonPattern.Normal,this.getCurrentSelectedData=this.getCurrentSelectedData.bind(this),this.updateSelectedTextAttribute=this.updateSelectedTextAttribute.bind(this)}eventBinding(){super.eventBinding(),this.container.removeEventListener("mouseup",this.onMouseUp),this.container.addEventListener("mouseup",this.dragMouseUp),this.dblClickListener.addEvent(this.onMouseUp,this.onLeftDblClick,this.onRightDblClick,this.isAllowDouble)}eventUnbinding(){super.eventUnbinding(),this.container.removeEventListener("mouseup",this.dragMouseUp)}destroy(){super.destroy(),this._textAttributInstance&&this._textAttributInstance.clearTextAttribute()}get selectedPolygon(){return PolygonUtils.getPolygonByID(this.polygonList,this.selectedID)}get hoverPolygon(){return this.polygonList.find(t=>t.id===this.hoverID&&t.id!==this.selectedID)}get polygonListUnderZoom(){return this.polygonList.map(t=>__spreadProps(__spreadValues({},t),{pointList:AxisUtils.default.changePointListByZoom(t.pointList,this.zoom)}))}get selectedText(){var t;return(t=this.selectedPolygon)==null?void 0:t.textAttribute}get dataList(){return this.polygonList}setPattern(t,e=!1){var i;((i=this.drawingPointList)==null?void 0:i.length)>0&&e===!0||(this.pattern=t)}get currentShowList(){let t=[];const[e,i]=CommonToolUtils.getRenderResultList(this.polygonList,CommonToolUtils.getSourceID(this.basicResult),this.attributeLockList,this.selectedID);return t=e,this.isHidden&&(t=[]),i&&t.push(i),t}get currentPageResult(){const[t]=CommonToolUtils.getRenderResultList(this.polygonList,CommonToolUtils.getSourceID(this.basicResult),[]);return t}setResultAndSelectedID(t,e){this.setPolygonList(t),e&&(this.selectedID=e),this.render()}setResult(t){this.clearActiveStatus(),this.setPolygonList(t),this.render()}setPolygonDataByID(t,e){return this.polygonList.map(i=>i.id===e?__spreadValues(__spreadValues({},i),t):i)}rotatePolygon(t=1,e=annotation.ERotateDirection.Clockwise,i=this.selectedID){if(!i)return;const s=PolygonUtils.getPolygonByID(this.polygonList,i);if(!s)return;const o=PolygonUtils.updatePolygonByRotate(e,t,s==null?void 0:s.pointList);this.setPolygonList(this.setPolygonDataByID({pointList:o},i)),this.render()}addPointInDrawing(t){if(!this.imgInfo||this.forbidAddNewPolygonFuc&&this.forbidAddNewPolygonFuc(t))return;const{upperLimitPointNum:e,edgeAdsorption:i}=this.config;if(e&&this.drawingPointList.length>=e){this.emit("messageInfo",`${index.getMessagesByLocale(constants.EMessage.UpperLimitErrorNotice,this.lang)}${e}`);return}this.deleteSelectedID();const s=this.getCoordinateUnderZoom(t),o=AxisUtils.default.changeDrawOutsideTarget(s,{x:0,y:0},this.imgInfo,this.config.drawOutsideTarget,this.basicResult,this.zoom);if(AxisUtils.default.returnClosePointIndex(o,AxisUtils.default.changePointListByZoom(this.drawingPointList,this.zoom))===0){this.addDrawingPointToPolygonList();return}const{dropFoot:n}=PolygonUtils.getClosestPoint(o,this.polygonListUnderZoom,this.config.lineType,tool.edgeAdsorptionScope),l=AxisUtils.default.changePointByZoom(n&&t.altKey===!1&&i?n:o,1/this.zoom);if(this.pattern===tool.EPolygonPattern.Rect&&this.drawingPointList.length===2){const h=MathUtils.default.getRectangleByRightAngle(l,this.drawingPointList);if(this.drawingPointList=h,this.config.drawOutsideTarget===!1&&this.imgInfo&&this.isPolygonOutSide(this.drawingPointList)){this.emit("messageInfo",`${index.getMessagesByLocale(constants.EMessage.ForbiddenCreationOutsideBoundary,this.lang)}`),this.drawingPointList=[];return}this.addDrawingPointToPolygonList(!0);return}this.drawingPointList.push(l),this.drawingPointList.length===1?this.drawingHistory.initRecord(this.drawingPointList):this.drawingHistory.pushHistory(this.drawingPointList)}clearResult(){this.setPolygonList([]),this.deleteSelectedID(),this.render()}clearPolygonDrag(){this.drawingPointList=[],this.dragInfo=void 0,this.dragInfo=void 0,this.dragStatus=annotation.EDragStatus.Wait,this.hoverEdgeIndex=-1,this.hoverPointIndex=-1,this.hoverID=""}clearActiveStatus(){this.clearPolygonDrag(),this.deleteSelectedID()}clearDrawingStatus(){this.drawingPointList=[]}setPolygonList(t){const e=this.polygonList.length;this.polygonList=t,e!==t.length&&this.emit("updatePageNumber")}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")}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.selectedPolygon&&(this.selectedPolygon.attribute=t),this.history.pushHistory(this.polygonList),this.render()),this._textAttributInstance){if(this.attributeLockList.length>0&&!this.attributeLockList.includes(t)){this._textAttributInstance.clearTextAttribute();return}this._textAttributInstance.updateIcon(this.getTextIconSvg(t))}}}setStyle(t){var e;super.setStyle(t),this._textAttributInstance&&this.config.attributeConfigurable===!1&&((e=this._textAttributInstance)==null||e.updateIcon(this.getTextIconSvg()))}setPolygonValidAndRender(t){if(!t)return;const e=this.polygonList.map(i=>{var s;if(i.id===t){const o=(s=i==null?void 0:i.valid)!=null?s:!0;return __spreadProps(__spreadValues({},i),{valid:!o})}return i});this.setPolygonList(e),this.history.pushHistory(this.polygonList),this.render(),this.emit("updateResult")}addDrawingPointToPolygonList(t){let{lowerLimitPointNum:e=3}=this.config;e<3&&(e=3);let i;if(this.drawingPointList.length<e){this.drawingPointList=[],this.editPolygonID="";return}const s=CommonToolUtils.getSourceID(this.basicResult),o=[...this.polygonList];if(this.editPolygonID){const r=o.find(n=>n.id===this.editPolygonID);if(!r)return;r.pointList=this.drawingPointList,this.editPolygonID=""}else{const r=uuid(8,62);let n={id:r,sourceID:s,valid:!this.isCtrl,textAttribute:"",pointList:this.drawingPointList,attribute:this.defaultAttribute,order:CommonToolUtils.getMaxOrder(o.filter(l=>CommonToolUtils.isSameSourceID(l.sourceID,s)))+1};if(this.config.textConfigurable){let l="";l=AttributeUtils.default.getTextAttribute(this.polygonList.filter(h=>CommonToolUtils.isSameSourceID(h.sourceID,s)),this.config.textCheckType),n=__spreadProps(__spreadValues({},n),{textAttribute:l})}this.pattern===tool.EPolygonPattern.Rect&&t===!0&&(n=__spreadProps(__spreadValues({},n),{isRect:!0})),o.push(n),i=n,this.setSelectedIdAfterAddingDrawing(r)}this.setPolygonList(o),this.isCtrl=!1,this.drawingPointList=[],this.history.pushHistory(o),i&&this.emit("polygonCreated",i,this.zoom,this.currentPos)}setSelectedIdAfterAddingDrawing(t){this.drawingPointList.length!==0&&(this.config.textConfigurable?this.setSelectedID(t):this.deleteSelectedID())}getHoverID(t){var e;const i=this.getCoordinateUnderZoom(t),s=this.currentShowList.map(o=>__spreadProps(__spreadValues({},o),{pointList:AxisUtils.default.changePointListByZoom(o.pointList,this.zoom)}));return PolygonUtils.getHoverPolygonID(i,s,10,(e=this.config)==null?void 0:e.lineType)}getHoverEdgeIndex(t){var e;if(!this.selectedID)return-1;const i=this.selectedPolygon;if(!i)return-1;const s=this.getCoordinateUnderZoom(t),o=AxisUtils.default.changePointListByZoom(i.pointList,this.zoom);return PolygonUtils.getHoverEdgeIndex(s,o,(e=this.config)==null?void 0:e.lineType)}getHoverPointIndex(t){if(!this.selectedID)return-1;const e=this.selectedPolygon;if(!e)return-1;const i=this.getCoordinateUnderZoom(t),s=AxisUtils.default.changePointListByZoom(e.pointList,this.zoom);return AxisUtils.default.returnClosePointIndex(i,s)}deletePolygon(t){var e;if(!t)return;const i=this.polygonList.find(s=>s.id===t);this.emit("deletedObject",{deletedObject:i,id:t}),this.setPolygonList(this.polygonList.filter(s=>s.id!==t)),this.history.pushHistory(this.polygonList),(e=this._textAttributInstance)==null||e.clearTextAttribute(),this.emit("selectedChange"),this.render()}deletePolygonPoint(t){if(!this.selectedID)return;const{selectedPolygon:e}=this;if(!e)return;let{lowerLimitPointNum:i}=this.config;if(i<3&&(i=3),e.pointList.length<=i){this.emit("messageInfo",`${index.getMessagesByLocale(constants.EMessage.LowerLimitErrorNotice,this.lang)}${i}`);return}e==null||e.pointList.splice(t,1),this.history.pushHistory(this.polygonList),this.render()}spaceKeydown(){var t,e,i;if(this.selectedID){if(((t=this.selectedPolygon)==null?void 0:t.isRect)===!0){this.emit("messageInfo",`${index.getMessagesByLocale(constants.EMessage.UnableToReannotation,this.lang)}`);return}this.editPolygonID=this.selectedID,this.drawingPointList=(i=(e=this.selectedPolygon)==null?void 0:e.pointList)!=null?i:[],this.drawingHistory.empty(),this.drawingHistory.initRecord(this.drawingPointList),this.hoverID="",this.deleteSelectedID(),this.render()}}onTabKeyDown(t){t.preventDefault();let e=annotation.ESortDirection.ascend;t.shiftKey&&(e=annotation.ESortDirection.descend),this.switchToNextPolygon(e)}switchToNextPolygon(t){if(this.drawingPointList.length>0)return;const[e,i]=CommonToolUtils.getRenderResultList(this.polygonList,CommonToolUtils.getSourceID(this.basicResult),this.attributeLockList,this.selectedID);let s=[...e];i&&(s=[...s,i]);const o=CanvasUtils.getViewPort(this.canvas,this.currentPos,this.zoom),r=s.map(l=>{var h,c,d,a;return __spreadProps(__spreadValues({},l),{x:(c=(h=l.pointList[0])==null?void 0:h.x)!=null?c:0,y:(a=(d=l.pointList[0])==null?void 0:d.y)!=null?a:0})}).filter(l=>CanvasUtils.inViewPort({x:l.x,y:l.y},o)),n=CommonToolUtils.getNextSelectedRectID(r,t,this.selectedID);if(n){this.setSelectedID(n.id);const{selectedPolygon:l}=this;l&&this.setDefaultAttribute(l.attribute)}this.render()}onKeyDown(t){if(!CommonToolUtils.hotkeyFilter(t)||super.onKeyDown(t)===!1)return;const{keyCode:e}=t;switch(e){case keyCode.Space:this.spaceKeydown();break;case keyCode.Esc:this.drawingPointList=[],this.editPolygonID="";break;case keyCode.F:this.selectedID&&this.setPolygonValidAndRender(this.selectedID);break;case keyCode.Z:if(t.altKey){this.onCombinedExecute();return}this.setIsHidden(!this.isHidden),this.render();break;case keyCode.Delete:this.deletePolygon(this.selectedID),this.render();break;case keyCode.Ctrl:this.isCtrl=!0;break;case keyCode.Alt:this.isAlt===!1&&(t.preventDefault(),this.isAlt=!0,this.render());break;case keyCode.Tab:{this.onTabKeyDown(t);break}case keyCode.X:t.altKey&&this.segment();break;default:{if(this.config.attributeConfigurable){const i=AttributeUtils.default.getAttributeByKeycode(e,this.config.attributeList);i!==void 0&&this.setDefaultAttribute(i)}break}}}onKeyUp(t){switch(super.onKeyUp(t),t.keyCode){case keyCode.Ctrl:this.isCtrl=!1;break;case keyCode.Alt:{const e=this.isAlt;this.isAlt=!1,e===!0&&this.render();break}}}rightMouseUp(t){if(this.drawingPointList.length>0){this.addDrawingPointToPolygonList();return}this.setSelectedID(this.hoverID);const{selectedPolygon:e}=this;e&&this.setDefaultAttribute(e.attribute)}onLeftDblClick(t){if(this.hoverEdgeIndex>-1){const e=this.getCoordinateUnderZoom(t),{selectedPolygon:i}=this;if(!i)return;if(i.isRect===!0){this.emit("messageInfo",`${index.getMessagesByLocale(constants.EMessage.ForbidAddNewPoint,this.lang)}`),this.clearPolygonDrag();return}const{dropFoot:s}=PolygonUtils.getClosestPoint(e,this.polygonListUnderZoom,this.config.lineType,tool.edgeAdsorptionScope);if(!s)return;const{upperLimitPointNum:o}=this.config;if(o&&i.pointList.length>=o){this.emit("messageInfo",`${index.getMessagesByLocale(constants.EMessage.UpperLimitErrorNotice,this.lang)}${o}`),this.clearPolygonDrag();return}i==null||i.pointList.splice(this.hoverEdgeIndex+1,0,AxisUtils.default.changePointByZoom(s,1/this.zoom)),this.setPolygonDataByID(i,this.selectedID),this.history.pushHistory(this.polygonList),this.hoverPointIndex=-1,this.hoverEdgeIndex=-1,this.render()}this.dragInfo=void 0}onRightDblClick(t){this.dragInfo=void 0,this.clearImgDrag();const e=this.getHoverID(t),i=this.getHoverPointIndex(t);if(this.hoverPointIndex>-1&&this.hoverPointIndex===i){this.deletePolygonPoint(i),this.dragInfo=void 0,this.hoverPointIndex=-1,this.render();return}this.hoverID===this.selectedID&&this.deletePolygon(e),this.render()}onMouseDown(t){if(super.onMouseDown(t)||this.forbidMouseOperation||t.ctrlKey===!0)return;const e=this.selectedPolygon;if(!e||t.button!==0||this.getHoverID(t)!==this.selectedID)return;const s=e.pointList,o=this.getCoordinateUnderZoom(t);let r=[0],n=annotation.EDragTarget.Plane;this.dragStatus=annotation.EDragStatus.Start;const l=this.getHoverPointIndex(t),h=this.getHoverEdgeIndex(t);return l>-1?(n=annotation.EDragTarget.Point,r=[l]):h>-1&&this.hoverEdgeIndex>-1&&(n=annotation.EDragTarget.Line,r=[h,(h+1)%s.length]),this.dragInfo={dragStartCoord:o,dragTarget:n,initPointList:s,changePointIndex:r,originPolygon:this.selectedPolygon},!0}segment(){var t;if(!this.selectedID||((t=this.config)==null?void 0:t.lineType)!==tool.ELineTypes.Line)return;const e=PolygonUtils.getPolygonPointList(this.selectedID,this.currentShowList),i=this.currentShowList.filter(r=>r.id!==this.selectedID);if(i.length===0||e.length===0)return;const s=PolygonUtils.getWrapPolygonIndex(e,i);let o=[...this.polygonList];if(s===-1){const r=PolygonUtils.segmentPolygonByPolygon(e,i);if(!r)return;const n=r.shift();if(!n)return;let l="",h=!0;const c=CommonToolUtils.getSourceID(this.basicResult);let d="";o=this.polygonList.map(a=>{var u,f;return a.id===this.selectedID?(l=a.attribute,h=(u=a==null?void 0:a.valid)!=null?u:!0,d=(f=a==null?void 0:a.textAttribute)!=null?f:"",__spreadProps(__spreadValues({},a),{pointList:n})):a}),r.length>0&&r.forEach((a,u)=>{o.push({sourceID:c,id:uuid(8,62),pointList:a,valid:h,order:CommonToolUtils.getMaxOrder(this.currentShowList)+1+u,attribute:l,textAttribute:d})})}else o[s].pointList=PolygonUtils.clipPolygonFromWrapPolygon(e,o[s].pointList),o=o.filter(r=>r.id!==this.selectedID);this.setPolygonList(o),this.history.pushHistory(o),this.render()}onCombinedExecute(){if(!this.selectedID){this.emit("messageInfo",lbUtils.i18n.t("PolygonsToBeCombinedNeedToBeSelected"));return}this.isCombined=!this.isCombined}combine(t){var e;const i=this.getHoverID(t);if(!i||!this.selectedID||this.selectedID===i)return;if(((e=this.config)==null?void 0:e.lineType)!==tool.ELineTypes.Line){this.emit("messageInfo",lbUtils.i18n.t("CurveModeDoesNotSupportCutting"));return}const s=this.polygonList.find(h=>h.id===this.selectedID),o=this.currentShowList.find(h=>h.id===i);if(!o||!s)return;const r=PolygonUtils.combinePolygonWithPolygon(s,o);if(!r)return;const{newPolygon:n,unionList:l}=r;if(l.length===1&&n){const h=this.polygonList.filter(c=>!l.includes(c.id)).map(c=>c.id===this.selectedID?n:c);this.setPolygonList(h),this.history.pushHistory(h),this.render(),this.emit("messageInfo",lbUtils.i18n.t("CombineSuccess"))}else this.emit("messageInfo",lbUtils.i18n.t("CombiningFailedNotify"));this.isCombined=!1}isPolygonOutSide(t){if(this.dependToolName&&this.basicCanvas&&this.basicResult){let n=!1;switch(this.dependToolName){case tool.EToolName.Rect:{n=t.filter(l=>!RectUtils.isInRect(l,this.basicResult)).length>0;break}case tool.EToolName.Polygon:{n=PolygonUtils.isPointListOutSidePolygon(t,this.basicResult.pointList,this.config.lineType);break}}return n}if(!this.imgInfo)return!1;const{left:e,top:i,right:s,bottom:o}=MathUtils.default.calcViewportBoundaries(AxisUtils.default.changePointListByZoom(t,this.zoom)),r=1e-5;return e<0||i<0||s>this.imgInfo.width+r||o>this.imgInfo.height+r}onDragMove(t){if(!this.dragInfo||!this.selectedID)return;const{selectedPolygon:e}=this;let i=e==null?void 0:e.pointList;if(!i)return;const{initPointList:s,dragStartCoord:o,dragTarget:r,changePointIndex:n}=this.dragInfo,l=this.getCoordinateUnderZoom(t);let h={x:(l.x-o.x)/this.zoom,y:(l.y-o.y)/this.zoom};if(this.pattern===tool.EPolygonPattern.Rect&&(e==null?void 0:e.isRect)===!0&&n&&[annotation.EDragTarget.Line].includes(r)){const d=MathUtils.default.getArrayIndex(n[0]-2,4),a=MathUtils.default.getArrayIndex(n[0]-1,4),u=[s[d],s[a]];h=MathUtils.default.getRectPerpendicularOffset(o,l,u),h={x:h.x/this.zoom,y:h.y/this.zoom}}switch(this.dragStatus=annotation.EDragStatus.Move,r){case annotation.EDragTarget.Plane:i=i.map((d,a)=>__spreadProps(__spreadValues({},d),{x:s[a].x+h.x,y:s[a].y+h.y}));break;case annotation.EDragTarget.Point:case annotation.EDragTarget.Line:i=i.map((d,a)=>n&&n.includes(a)?__spreadProps(__spreadValues({},d),{x:s[a].x+h.x,y:s[a].y+h.y}):d);break}if(this.pattern===tool.EPolygonPattern.Rect&&(e==null?void 0:e.isRect)===!0&&r===annotation.EDragTarget.Point&&n&&(i=MathUtils.default.getPointListFromPointOffset(s,n[0],h)),this.config.drawOutsideTarget===!1&&this.imgInfo&&this.isPolygonOutSide(i))return;const c=this.polygonList.map(d=>{if(d.id===this.selectedID){const a=__spreadProps(__spreadValues({},d),{pointList:i});return d.isRect===!0&&this.pattern===tool.EPolygonPattern.Normal&&Object.assign(a,{isRect:!1}),a}return d});this.setPolygonList(c),this.render()}onMouseMove(t){if(super.onMouseMove(t)||this.forbidMouseOperation||!this.imgInfo)return;if(this.selectedID&&this.dragInfo){this.onDragMove(t);return}let e=-1,i=-1;const{selectedID:s}=this;if(s&&(this.hoverEdgeIndex=-1,this.hoverPointIndex=-1,e=this.getHoverPointIndex(t),e>-1?this.hoverPointIndex=e:(i=this.getHoverEdgeIndex(t),this.hoverEdgeIndex=i)),this.drawingPointList.length>0)return;const o=this.getHoverID(t);this.hoverID!==o&&(this.hoverID=o,this.render())}leftMouseUp(t){const e=this.getHoverID(t);if(this.drawingPointList.length===0&&t.ctrlKey===!0&&e){this.setPolygonValidAndRender(e);return}this.addPointInDrawing(t)}onMouseUp(t){if(this.isCombined){switch(t.button){case 0:this.combine(t);break;case 2:this.isCombined=!1;break;default:return}return}if(!(super.onMouseUp(t)||this.forbidMouseOperation||!this.imgInfo)){if(this.dragInfo&&this.dragStatus===annotation.EDragStatus.Move){const{originPolygon:e}=this.dragInfo;this.dragInfo=void 0,this.dragStatus=annotation.EDragStatus.Wait,this.history.pushHistory(this.polygonList),this.emit("updateResult"),this.emit("updatePolygonByDrag",{newPolygon:this.selectedPolygon,originPolygon:e});return}switch(t.button){case 0:{this.leftMouseUp(t);break}case 2:{this.rightMouseUp(t);break}}this.render()}}dragMouseUp(){this.dragStatus===annotation.EDragStatus.Start&&(this.dragInfo=void 0,this.dragStatus=annotation.EDragStatus.Wait)}exportData(){const{polygonList:t}=this;return[t,this.basicImgInfo]}getTextIconSvg(t=""){return AttributeUtils.default.getTextIconSvg(t,this.config.attributeList,this.config.attributeConfigurable,this.baseIcon)}getCurrentSelectedData(){const{selectedPolygon:t}=this;if(!t)return;const e=this.getColor(t.attribute),i=t.valid?e==null?void 0:e.valid.stroke:e==null?void 0:e.invalid.stroke;return{width:TEXT_MAX_WIDTH,textAttribute:t.textAttribute,color:i}}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.setPolygonList(AttributeUtils.default.textChange(e,this.selectedID,this.polygonList)),this.emit("updateTextAttribute"),this.render()}}renderTextAttribute(){var t;const{selectedPolygon:e}=this;if(!this.ctx||this.config.textConfigurable===!1||!e)return;const{pointList:i,attribute:s,valid:o,textAttribute:r}=e,{x:n,y:l}=i[i.length-1],h=TEXT_MAX_WIDTH,c=AxisUtils.default.getOffsetCoordinate({x:n,y:l},this.currentPos,this.zoom),d=this.getColor(s),a=o?d==null?void 0:d.valid.stroke:d==null?void 0:d.invalid.stroke;this._textAttributInstance||(this._textAttributInstance=new textAttributeClass({width:h,container:this.container,icon:this.getTextIconSvg(s),color:a,getCurrentSelectedData:this.getCurrentSelectedData,updateSelectedTextAttribute:this.updateSelectedTextAttribute})),this._textAttributInstance&&!((t=this._textAttributInstance)==null?void 0:t.isExit)&&this._textAttributInstance.appendToContainer(),this._textAttributInstance.update(`${r}`,{left:c.x,top:c.y,color:a,width:h})}renderStaticPolygon(){var t;this.isHidden===!1&&((t=this.polygonList)==null||t.forEach(e=>{var i,s,o,r,n;if([this.selectedID,this.editPolygonID].includes(e.id))return;const{textAttribute:l,attribute:h}=e,c=this.getColor(h),d=StyleUtils.getStrokeAndFill(c,e.valid),a=AxisUtils.default.changePointListByZoom(e.pointList||[],this.zoom,this.currentPos);DrawUtils.drawPolygonWithFillAndLine(this.canvas,a,{fillColor:d.fill,strokeColor:d.stroke,pointColor:"white",thickness:(s=(i=this.style)==null?void 0:i.width)!=null?s:2,lineCap:"round",isClose:!0,lineType:(o=this.config)==null?void 0:o.lineType});let u=`${(r=AttributeUtils.default.getAttributeShowText(h,this.config.attributeList))!=null?r:""}`;((n=this.config)==null?void 0:n.isShowOrder)&&(e==null?void 0:e.order)>0&&(u=`${e.order} ${u}`),DrawUtils.drawText(this.canvas,a[0],u,__spreadValues({color:d.stroke},annotation.DEFAULT_TEXT_OFFSET));const f=a[a.length-1];DrawUtils.drawText(this.canvas,{x:f.x+annotation.TEXT_ATTRIBUTE_OFFSET.x,y:f.y+annotation.TEXT_ATTRIBUTE_OFFSET.y},l,__spreadValues({color:d.stroke},annotation.DEFAULT_TEXT_OFFSET))}))}renderSelectedPolygon(){var t,e,i;if(this.selectedID){const s=this.selectedPolygon;if(s){const o=this.getColor(s.attribute),r=StyleUtils.getStrokeAndFill(o,s.valid,{isSelected:!0});DrawUtils.drawSelectedPolygonWithFillAndLine(this.canvas,AxisUtils.default.changePointListByZoom(s.pointList,this.zoom,this.currentPos),{fillColor:r.fill,strokeColor:r.stroke,pointColor:"white",thickness:2,lineCap:"round",isClose:!0,lineType:(t=this.config)==null?void 0:t.lineType});let n=`${(e=AttributeUtils.default.getAttributeShowText(s.attribute,this.config.attributeList))!=null?e:""}`;((i=this.config)==null?void 0:i.isShowOrder)&&(s==null?void 0:s.order)>0&&(n=`${s.order} ${n}`),DrawUtils.drawText(this.canvas,AxisUtils.default.changePointByZoom(s.pointList[0],this.zoom,this.currentPos),n,__spreadValues({color:r.stroke},annotation.DEFAULT_TEXT_OFFSET)),this.renderTextAttribute()}}}renderHoverPolygon(){var t;if(this.hoverID&&this.hoverID!==this.editPolygonID){const{hoverPolygon:e}=this;if(e){let i="";const s=this.getColor(e.attribute);e.valid?i=s.validHover.fill:i=StyleUtils.getStrokeAndFill(s,!1,{isHover:!0}).fill,DrawUtils.drawPolygonWithFill(this.canvas,AxisUtils.default.changePointListByZoom(e.pointList,this.zoom,this.currentPos),{color:i,lineType:(t=this.config)==null?void 0:t.lineType})}}}renderPolygon(){var t,e,i,s;this.renderStaticPolygon(),this.renderHoverPolygon(),this.renderSelectedPolygon();const o=this.getColor(this.defaultAttribute),r=StyleUtils.getStrokeAndFill(o,!this.isCtrl);if(((t=this.drawingPointList)==null?void 0:t.length)>0){let n=[...this.drawingPointList],l=AxisUtils.default.getOriginCoordinateWithOffsetCoordinate(this.coord,this.zoom,this.currentPos);if(this.pattern===tool.EPolygonPattern.Rect&&n.length===2)n=MathUtils.default.getRectangleByRightAngle(l,n);else{if(((e=this.config)==null?void 0:e.edgeAdsorption)&&this.isAlt===!1){const{dropFoot:h}=PolygonUtils.getClosestPoint(l,this.polygonList,(i=this.config)==null?void 0:i.lineType,tool.edgeAdsorptionScope/this.zoom);h&&(l=h)}n.push(l)}DrawUtils.drawSelectedPolygonWithFillAndLine(this.canvas,AxisUtils.default.changePointListByZoom(n,this.zoom,this.currentPos),{fillColor:r.fill,strokeColor:r.stroke,pointColor:"white",thickness:2,lineCap:"round",isClose:!1,lineType:this.config.lineType})}if(this.hoverPointIndex>-1&&this.selectedID){const n=this.selectedPolygon;if(!n)return;const l=StyleUtils.getStrokeAndFill(o,n.valid,{isSelected:!0}),h=n==null?void 0:n.pointList[this.hoverPointIndex];if(h){const{x:c,y:d}=AxisUtils.default.changePointByZoom(h,this.zoom,this.currentPos);DrawUtils.drawCircleWithFill(this.canvas,{x:c,y:d},5,{color:l.fill})}}if(this.hoverEdgeIndex>-1&&this.selectedID){const n=this.selectedPolygon;if(!n)return;const l=StyleUtils.getStrokeAndFill(o,n.valid,{isSelected:!0});DrawUtils.drawLineWithPointList(this.canvas,AxisUtils.default.changePointListByZoom(n.pointList,this.zoom,this.currentPos),{color:l.stroke,thickness:10,hoverEdgeIndex:this.hoverEdgeIndex,lineType:(s=this.config)==null?void 0:s.lineType})}}render(){!this.ctx||(super.render(),this.renderPolygon(),this.renderCursorLine(this.getLineColor(this.defaultAttribute)))}renderCursorLine(t){if(super.renderCursorLine(t),this.isCombined){const{x:e,y:i}=this.coord,s=10,o=186,r=32;DrawUtils.drawRectWithFill(this.canvas,{x:e+s,y:i-s*4-1,width:o,height:r},{color:"black"}),DrawUtils.drawText(this.canvas,{x:e,y:i},lbUtils.i18n.t("ClickAnotherPolygon"),{textAlign:"center",color:"white",offsetX:o/2+s,offsetY:-(r/2+s/2)}),DrawUtils.drawRect(this.canvas,{x:e-s,y:i-s,width:s*2,height:s*2},{lineDash:[6],color:"white"})}}undo(){if(this.drawingPointList.length>0){const e=this.drawingHistory.undo();if(!e)return;this.drawingPointList=e,this.render();return}const t=this.history.undo();t&&(t.length!==this.polygonList.length&&this.deleteSelectedID(),this.setPolygonList(t),this.render())}redo(){if(this.drawingPointList.length>0){const e=this.drawingHistory.redo();if(!e)return;this.drawingPointList=e,this.render();return}const t=this.history.redo();t&&(t.length!==this.polygonList.length&&this.deleteSelectedID(),this.setPolygonList(t),this.render())}deleteSelectedID(){this.setSelectedID("")}}module.exports=PolygonOperation;
1
+ "use strict";var lbUtils=require("@labelbee/lb-utils"),MathUtils=require("../../utils/MathUtils.js"),RectUtils=require("../../utils/tool/RectUtils.js"),annotation=require("../../constant/annotation.js"),keyCode=require("../../constant/keyCode.js"),tool=require("../../constant/tool.js"),index=require("../../locales/index.js"),constants=require("../../locales/constants.js"),ActionsHistory=require("../../utils/ActionsHistory.js"),AttributeUtils=require("../../utils/tool/AttributeUtils.js"),AxisUtils=require("../../utils/tool/AxisUtils.js"),CanvasUtils=require("../../utils/tool/CanvasUtils.js"),CommonToolUtils=require("../../utils/tool/CommonToolUtils.js"),DrawUtils=require("../../utils/tool/DrawUtils.js"),PolygonUtils=require("../../utils/tool/PolygonUtils.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,__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 TEXT_MAX_WIDTH=164;class PolygonOperation extends basicToolOperation.BasicToolOperation{constructor(t){super(t);this.isAllowDouble=e=>{const{selectedID:i}=this,s=this.getHoverID(e);return!!(i&&i===s)},this.textChange=e=>{this.config.textConfigurable===!1||!this.selectedID||(this.setPolygonList(AttributeUtils.default.textChange(e,this.selectedID,this.polygonList)),this.emit("selectedChange"),this.render())},this.config=CommonToolUtils.jsonParser(t.config),this.drawingPointList=[],this.polygonList=[],this.hoverPointIndex=-1,this.hoverEdgeIndex=-1,this.drawingHistory=new ActionsHistory,this.isCtrl=!1,this.isAlt=!1,this.isCombined=!1,this.pattern=tool.EPolygonPattern.Normal,this.getCurrentSelectedData=this.getCurrentSelectedData.bind(this),this.updateSelectedTextAttribute=this.updateSelectedTextAttribute.bind(this)}eventBinding(){super.eventBinding(),this.container.removeEventListener("mouseup",this.onMouseUp),this.container.addEventListener("mouseup",this.dragMouseUp),this.dblClickListener.addEvent(this.onMouseUp,this.onLeftDblClick,this.onRightDblClick,this.isAllowDouble)}eventUnbinding(){super.eventUnbinding(),this.container.removeEventListener("mouseup",this.dragMouseUp)}destroy(){super.destroy(),this._textAttributInstance&&this._textAttributInstance.clearTextAttribute()}get selectedPolygon(){return PolygonUtils.getPolygonByID(this.polygonList,this.selectedID)}get hoverPolygon(){return this.polygonList.find(t=>t.id===this.hoverID&&t.id!==this.selectedID)}get polygonListUnderZoom(){return this.polygonList.map(t=>__spreadProps(__spreadValues({},t),{pointList:AxisUtils.default.changePointListByZoom(t.pointList,this.zoom)}))}get selectedText(){var t;return(t=this.selectedPolygon)==null?void 0:t.textAttribute}get dataList(){return this.polygonList}setPattern(t,e=!1){var i;((i=this.drawingPointList)==null?void 0:i.length)>0&&e===!0||(this.pattern=t)}get currentShowList(){let t=[];const[e,i]=CommonToolUtils.getRenderResultList(this.polygonList,CommonToolUtils.getSourceID(this.basicResult),this.attributeLockList,this.selectedID);return t=e,this.isHidden&&(t=[]),i&&t.push(i),t}get currentPageResult(){const[t]=CommonToolUtils.getRenderResultList(this.polygonList,CommonToolUtils.getSourceID(this.basicResult),[]);return t}setResultAndSelectedID(t,e){this.setPolygonList(t),e&&(this.selectedID=e),this.render()}setResult(t){this.clearActiveStatus(),this.setPolygonList(t),this.render()}setPolygonDataByID(t,e){return this.polygonList.map(i=>i.id===e?__spreadValues(__spreadValues({},i),t):i)}rotatePolygon(t=1,e=annotation.ERotateDirection.Clockwise,i=this.selectedID){if(!i)return;const s=PolygonUtils.getPolygonByID(this.polygonList,i);if(!s)return;const o=PolygonUtils.updatePolygonByRotate(e,t,s==null?void 0:s.pointList);this.setPolygonList(this.setPolygonDataByID({pointList:o},i)),this.render()}addPointInDrawing(t){if(!this.imgInfo||this.forbidAddNewPolygonFuc&&this.forbidAddNewPolygonFuc(t))return;const{upperLimitPointNum:e,edgeAdsorption:i}=this.config;if(e&&this.drawingPointList.length>=e){this.emit("messageInfo",`${index.getMessagesByLocale(constants.EMessage.UpperLimitErrorNotice,this.lang)}${e}`);return}this.deleteSelectedID();const s=this.getCoordinateUnderZoom(t),o=AxisUtils.default.changeDrawOutsideTarget(s,{x:0,y:0},this.imgInfo,this.config.drawOutsideTarget,this.basicResult,this.zoom);if(AxisUtils.default.returnClosePointIndex(o,AxisUtils.default.changePointListByZoom(this.drawingPointList,this.zoom))===0){this.addDrawingPointToPolygonList();return}const{dropFoot:n}=PolygonUtils.getClosestPoint(o,this.polygonListUnderZoom,this.config.lineType,tool.edgeAdsorptionScope),l=AxisUtils.default.changePointByZoom(n&&t.altKey===!1&&i?n:o,1/this.zoom);if(this.pattern===tool.EPolygonPattern.Rect&&this.drawingPointList.length===2){const h=MathUtils.default.getRectangleByRightAngle(l,this.drawingPointList);if(this.drawingPointList=h,this.config.drawOutsideTarget===!1&&this.imgInfo&&this.isPolygonOutSide(this.drawingPointList)){this.emit("messageInfo",`${index.getMessagesByLocale(constants.EMessage.ForbiddenCreationOutsideBoundary,this.lang)}`),this.drawingPointList=[];return}this.addDrawingPointToPolygonList(!0);return}this.drawingPointList.push(l),this.drawingPointList.length===1?this.drawingHistory.initRecord(this.drawingPointList):this.drawingHistory.pushHistory(this.drawingPointList)}clearResult(){this.setPolygonList([]),this.deleteSelectedID(),this.render()}clearPolygonDrag(){this.drawingPointList=[],this.dragInfo=void 0,this.dragInfo=void 0,this.dragStatus=annotation.EDragStatus.Wait,this.hoverEdgeIndex=-1,this.hoverPointIndex=-1,this.hoverID=""}clearActiveStatus(){this.clearPolygonDrag(),this.deleteSelectedID()}clearDrawingStatus(){this.drawingPointList=[]}setPolygonList(t){const e=this.polygonList.length;this.polygonList=t,e!==t.length&&this.emit("updatePageNumber")}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")}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.selectedPolygon&&(this.selectedPolygon.attribute=t),this.history.pushHistory(this.polygonList),this.render()),this._textAttributInstance){if(this.attributeLockList.length>0&&!this.attributeLockList.includes(t)){this._textAttributInstance.clearTextAttribute();return}this._textAttributInstance.updateIcon(this.getTextIconSvg(t))}}}setStyle(t){var e;super.setStyle(t),this._textAttributInstance&&this.config.attributeConfigurable===!1&&((e=this._textAttributInstance)==null||e.updateIcon(this.getTextIconSvg()))}setPolygonValidAndRender(t){if(!t)return;const e=this.polygonList.map(i=>{var s;if(i.id===t){const o=(s=i==null?void 0:i.valid)!=null?s:!0;return __spreadProps(__spreadValues({},i),{valid:!o})}return i});this.setPolygonList(e),this.history.pushHistory(this.polygonList),this.render(),this.emit("updateResult")}addDrawingPointToPolygonList(t){let{lowerLimitPointNum:e=3}=this.config;e<3&&(e=3);let i;if(this.drawingPointList.length<e){this.drawingPointList=[],this.editPolygonID="";return}const s=CommonToolUtils.getSourceID(this.basicResult),o=[...this.polygonList];if(this.editPolygonID){const r=o.find(n=>n.id===this.editPolygonID);if(!r)return;r.pointList=this.drawingPointList,this.editPolygonID=""}else{const r=uuid(8,62);let n={id:r,sourceID:s,valid:!this.isCtrl,textAttribute:"",pointList:this.drawingPointList,attribute:this.defaultAttribute,order:CommonToolUtils.getMaxOrder(o.filter(l=>CommonToolUtils.isSameSourceID(l.sourceID,s)))+1};if(this.config.textConfigurable){let l="";l=AttributeUtils.default.getTextAttribute(this.polygonList.filter(h=>CommonToolUtils.isSameSourceID(h.sourceID,s)),this.config.textCheckType),n=__spreadProps(__spreadValues({},n),{textAttribute:l})}this.pattern===tool.EPolygonPattern.Rect&&t===!0&&(n=__spreadProps(__spreadValues({},n),{isRect:!0})),o.push(n),i=n,this.setSelectedIdAfterAddingDrawing(r)}this.setPolygonList(o),this.isCtrl=!1,this.drawingPointList=[],this.history.pushHistory(o),i&&this.emit("polygonCreated",i,this.zoom,this.currentPos)}setSelectedIdAfterAddingDrawing(t){this.drawingPointList.length!==0&&(this.config.textConfigurable?this.setSelectedID(t):this.deleteSelectedID())}getHoverID(t){var e;const i=this.getCoordinateUnderZoom(t),s=this.currentShowList.map(o=>__spreadProps(__spreadValues({},o),{pointList:AxisUtils.default.changePointListByZoom(o.pointList,this.zoom)}));return PolygonUtils.getHoverPolygonID(i,s,10,(e=this.config)==null?void 0:e.lineType)}getHoverEdgeIndex(t){var e;if(!this.selectedID)return-1;const i=this.selectedPolygon;if(!i)return-1;const s=this.getCoordinateUnderZoom(t),o=AxisUtils.default.changePointListByZoom(i.pointList,this.zoom);return PolygonUtils.getHoverEdgeIndex(s,o,(e=this.config)==null?void 0:e.lineType)}getHoverPointIndex(t){if(!this.selectedID)return-1;const e=this.selectedPolygon;if(!e)return-1;const i=this.getCoordinateUnderZoom(t),s=AxisUtils.default.changePointListByZoom(e.pointList,this.zoom);return AxisUtils.default.returnClosePointIndex(i,s)}deletePolygon(t){var e;if(!t)return;const i=this.polygonList.find(s=>s.id===t);this.emit("deletedObject",{deletedObject:i,id:t}),this.setPolygonList(this.polygonList.filter(s=>s.id!==t)),this.history.pushHistory(this.polygonList),(e=this._textAttributInstance)==null||e.clearTextAttribute(),this.emit("selectedChange"),this.render()}deletePolygonPoint(t){if(!this.selectedID)return;const{selectedPolygon:e}=this;if(!e)return;let{lowerLimitPointNum:i}=this.config;if(i<3&&(i=3),e.pointList.length<=i){this.emit("messageInfo",`${index.getMessagesByLocale(constants.EMessage.LowerLimitErrorNotice,this.lang)}${i}`);return}e==null||e.pointList.splice(t,1),this.history.pushHistory(this.polygonList),this.render()}spaceKeydown(){var t,e,i;if(this.selectedID){if(((t=this.selectedPolygon)==null?void 0:t.isRect)===!0){this.emit("messageInfo",`${index.getMessagesByLocale(constants.EMessage.UnableToReannotation,this.lang)}`);return}this.editPolygonID=this.selectedID,this.drawingPointList=(i=(e=this.selectedPolygon)==null?void 0:e.pointList)!=null?i:[],this.drawingHistory.empty(),this.drawingHistory.initRecord(this.drawingPointList),this.hoverID="",this.deleteSelectedID(),this.render()}}onTabKeyDown(t){t.preventDefault();let e=annotation.ESortDirection.ascend;t.shiftKey&&(e=annotation.ESortDirection.descend),this.switchToNextPolygon(e)}switchToNextPolygon(t){if(this.drawingPointList.length>0)return;const[e,i]=CommonToolUtils.getRenderResultList(this.polygonList,CommonToolUtils.getSourceID(this.basicResult),this.attributeLockList,this.selectedID);let s=[...e];i&&(s=[...s,i]);const o=CanvasUtils.getViewPort(this.canvas,this.currentPos,this.zoom),r=s.map(l=>{var h,c,d,a;return __spreadProps(__spreadValues({},l),{x:(c=(h=l.pointList[0])==null?void 0:h.x)!=null?c:0,y:(a=(d=l.pointList[0])==null?void 0:d.y)!=null?a:0})}).filter(l=>CanvasUtils.inViewPort({x:l.x,y:l.y},o)),n=CommonToolUtils.getNextSelectedRectID(r,t,this.selectedID);if(n){this.setSelectedID(n.id);const{selectedPolygon:l}=this;l&&this.setDefaultAttribute(l.attribute)}this.render()}onKeyDown(t){if(!CommonToolUtils.hotkeyFilter(t)||super.onKeyDown(t)===!1)return;const{keyCode:e}=t;switch(e){case keyCode.Space:this.spaceKeydown();break;case keyCode.Esc:this.drawingPointList=[],this.editPolygonID="";break;case keyCode.F:this.selectedID&&this.setPolygonValidAndRender(this.selectedID);break;case keyCode.Z:if(t.altKey){this.onCombinedExecute();return}this.setIsHidden(!this.isHidden),this.render();break;case keyCode.Delete:this.deletePolygon(this.selectedID),this.render();break;case keyCode.Ctrl:this.isCtrl=!0;break;case keyCode.Alt:this.isAlt===!1&&(t.preventDefault(),this.isAlt=!0,this.render());break;case keyCode.Tab:{this.onTabKeyDown(t);break}case keyCode.X:t.altKey&&this.segment();break;default:{if(this.config.attributeConfigurable){const i=AttributeUtils.default.getAttributeByKeycode(e,this.config.attributeList);i!==void 0&&this.setDefaultAttribute(i)}break}}}onKeyUp(t){switch(super.onKeyUp(t),t.keyCode){case keyCode.Ctrl:this.isCtrl=!1;break;case keyCode.Alt:{const e=this.isAlt;this.isAlt=!1,e===!0&&this.render();break}}}rightMouseUp(t){if(this.drawingPointList.length>0){this.addDrawingPointToPolygonList();return}this.setSelectedID(this.hoverID);const{selectedPolygon:e}=this;e&&this.setDefaultAttribute(e.attribute)}onLeftDblClick(t){if(this.hoverEdgeIndex>-1){const e=this.getCoordinateUnderZoom(t),{selectedPolygon:i}=this;if(!i)return;if(i.isRect===!0){this.emit("messageInfo",`${index.getMessagesByLocale(constants.EMessage.ForbidAddNewPoint,this.lang)}`),this.clearPolygonDrag();return}const{dropFoot:s}=PolygonUtils.getClosestPoint(e,this.polygonListUnderZoom,this.config.lineType,tool.edgeAdsorptionScope);if(!s)return;const{upperLimitPointNum:o}=this.config;if(o&&i.pointList.length>=o){this.emit("messageInfo",`${index.getMessagesByLocale(constants.EMessage.UpperLimitErrorNotice,this.lang)}${o}`),this.clearPolygonDrag();return}i==null||i.pointList.splice(this.hoverEdgeIndex+1,0,AxisUtils.default.changePointByZoom(s,1/this.zoom)),this.setPolygonDataByID(i,this.selectedID),this.history.pushHistory(this.polygonList),this.hoverPointIndex=-1,this.hoverEdgeIndex=-1,this.render()}this.dragInfo=void 0}onRightDblClick(t){this.dragInfo=void 0,this.clearImgDrag();const e=this.getHoverID(t),i=this.getHoverPointIndex(t);if(this.hoverPointIndex>-1&&this.hoverPointIndex===i){this.deletePolygonPoint(i),this.dragInfo=void 0,this.hoverPointIndex=-1,this.render();return}this.hoverID===this.selectedID&&this.deletePolygon(e),this.render()}onMouseDown(t){if(!(super.onMouseDown(t)||this.forbidMouseOperation||t.ctrlKey===!0))return this.dragMouseDown(t),!0}dragMouseDown(t){const e=this.selectedPolygon;if(!e||t.button!==0||this.getHoverID(t)!==this.selectedID)return;const s=e.pointList,o=this.getCoordinateUnderZoom(t);let r=[0],n=annotation.EDragTarget.Plane;this.dragStatus=annotation.EDragStatus.Start;const l=this.getHoverPointIndex(t),h=this.getHoverEdgeIndex(t);l>-1?(n=annotation.EDragTarget.Point,r=[l]):h>-1&&this.hoverEdgeIndex>-1&&(n=annotation.EDragTarget.Line,r=[h,(h+1)%s.length]),this.dragInfo={dragStartCoord:o,dragTarget:n,initPointList:s,changePointIndex:r,originPolygon:this.selectedPolygon}}segment(){var t;if(!this.selectedID||((t=this.config)==null?void 0:t.lineType)!==tool.ELineTypes.Line)return;const e=PolygonUtils.getPolygonPointList(this.selectedID,this.currentShowList),i=this.currentShowList.filter(r=>r.id!==this.selectedID);if(i.length===0||e.length===0)return;const s=PolygonUtils.getWrapPolygonIndex(e,i);let o=[...this.polygonList];if(s===-1){const r=PolygonUtils.segmentPolygonByPolygon(e,i);if(!r)return;const n=r.shift();if(!n)return;let l="",h=!0;const c=CommonToolUtils.getSourceID(this.basicResult);let d="";o=this.polygonList.map(a=>{var u,f;return a.id===this.selectedID?(l=a.attribute,h=(u=a==null?void 0:a.valid)!=null?u:!0,d=(f=a==null?void 0:a.textAttribute)!=null?f:"",__spreadProps(__spreadValues({},a),{pointList:n})):a}),r.length>0&&r.forEach((a,u)=>{o.push({sourceID:c,id:uuid(8,62),pointList:a,valid:h,order:CommonToolUtils.getMaxOrder(this.currentShowList)+1+u,attribute:l,textAttribute:d})})}else o[s].pointList=PolygonUtils.clipPolygonFromWrapPolygon(e,o[s].pointList),o=o.filter(r=>r.id!==this.selectedID);this.setPolygonList(o),this.history.pushHistory(o),this.render()}onCombinedExecute(){if(!this.selectedID){this.emit("messageInfo",lbUtils.i18n.t("PolygonsToBeCombinedNeedToBeSelected"));return}this.isCombined=!this.isCombined}combine(t){var e;const i=this.getHoverID(t);if(!i||!this.selectedID||this.selectedID===i)return;if(((e=this.config)==null?void 0:e.lineType)!==tool.ELineTypes.Line){this.emit("messageInfo",lbUtils.i18n.t("CurveModeDoesNotSupportCutting"));return}const s=this.polygonList.find(h=>h.id===this.selectedID),o=this.currentShowList.find(h=>h.id===i);if(!o||!s)return;const r=PolygonUtils.combinePolygonWithPolygon(s,o);if(!r)return;const{newPolygon:n,unionList:l}=r;if(l.length===1&&n){const h=this.polygonList.filter(c=>!l.includes(c.id)).map(c=>c.id===this.selectedID?n:c);this.setPolygonList(h),this.history.pushHistory(h),this.render(),this.emit("messageInfo",lbUtils.i18n.t("CombineSuccess"))}else this.emit("messageInfo",lbUtils.i18n.t("CombiningFailedNotify"));this.isCombined=!1}isPolygonOutSide(t){if(this.dependToolName&&this.basicCanvas&&this.basicResult){let n=!1;switch(this.dependToolName){case tool.EToolName.Rect:{n=t.filter(l=>!RectUtils.isInRect(l,this.basicResult)).length>0;break}case tool.EToolName.Polygon:{n=PolygonUtils.isPointListOutSidePolygon(t,this.basicResult.pointList,this.config.lineType);break}}return n}if(!this.imgInfo)return!1;const{left:e,top:i,right:s,bottom:o}=MathUtils.default.calcViewportBoundaries(AxisUtils.default.changePointListByZoom(t,this.zoom)),r=1e-5;return e<0||i<0||s>this.imgInfo.width+r||o>this.imgInfo.height+r}onDragMove(t){if(!this.dragInfo||!this.selectedID)return;const{selectedPolygon:e}=this;let i=e==null?void 0:e.pointList;if(!i)return;const{initPointList:s,dragStartCoord:o,dragTarget:r,changePointIndex:n}=this.dragInfo,l=this.getCoordinateUnderZoom(t);let h={x:(l.x-o.x)/this.zoom,y:(l.y-o.y)/this.zoom};if(this.pattern===tool.EPolygonPattern.Rect&&(e==null?void 0:e.isRect)===!0&&n&&[annotation.EDragTarget.Line].includes(r)){const d=MathUtils.default.getArrayIndex(n[0]-2,4),a=MathUtils.default.getArrayIndex(n[0]-1,4),u=[s[d],s[a]];h=MathUtils.default.getRectPerpendicularOffset(o,l,u),h={x:h.x/this.zoom,y:h.y/this.zoom}}switch(this.dragStatus=annotation.EDragStatus.Move,r){case annotation.EDragTarget.Plane:i=i.map((d,a)=>__spreadProps(__spreadValues({},d),{x:s[a].x+h.x,y:s[a].y+h.y}));break;case annotation.EDragTarget.Point:case annotation.EDragTarget.Line:i=i.map((d,a)=>n&&n.includes(a)?__spreadProps(__spreadValues({},d),{x:s[a].x+h.x,y:s[a].y+h.y}):d);break}if(this.pattern===tool.EPolygonPattern.Rect&&(e==null?void 0:e.isRect)===!0&&r===annotation.EDragTarget.Point&&n&&(i=MathUtils.default.getPointListFromPointOffset(s,n[0],h)),this.config.drawOutsideTarget===!1&&this.imgInfo&&this.isPolygonOutSide(i))return;const c=this.polygonList.map(d=>{if(d.id===this.selectedID){const a=__spreadProps(__spreadValues({},d),{pointList:i});return d.isRect===!0&&this.pattern===tool.EPolygonPattern.Normal&&Object.assign(a,{isRect:!1}),a}return d});this.setPolygonList(c),this.render()}onMouseMove(t){if(super.onMouseMove(t)||this.forbidMouseOperation||!this.imgInfo)return;if(this.selectedID&&this.dragInfo){this.onDragMove(t);return}let e=-1,i=-1;const{selectedID:s}=this;if(s&&(this.hoverEdgeIndex=-1,this.hoverPointIndex=-1,e=this.getHoverPointIndex(t),e>-1?this.hoverPointIndex=e:(i=this.getHoverEdgeIndex(t),this.hoverEdgeIndex=i)),this.drawingPointList.length>0)return;const o=this.getHoverID(t);this.hoverID!==o&&(this.hoverID=o,this.render())}leftMouseUp(t){const e=this.getHoverID(t);if(this.drawingPointList.length===0&&t.ctrlKey===!0&&e){this.setPolygonValidAndRender(e);return}this.addPointInDrawing(t)}onMouseUp(t){if(this.isCombined){switch(t.button){case 0:this.combine(t);break;case 2:this.isCombined=!1;break;default:return}return}if(!(super.onMouseUp(t)||this.forbidMouseOperation||!this.imgInfo)){if(this.dragInfo&&this.dragStatus===annotation.EDragStatus.Move){const{originPolygon:e}=this.dragInfo;this.dragInfo=void 0,this.dragStatus=annotation.EDragStatus.Wait,this.history.pushHistory(this.polygonList),this.emit("updateResult"),this.emit("updatePolygonByDrag",{newPolygon:this.selectedPolygon,originPolygon:e});return}switch(t.button){case 0:{this.leftMouseUp(t);break}case 2:{this.rightMouseUp(t);break}}this.render()}}dragMouseUp(){this.dragStatus===annotation.EDragStatus.Start&&(this.dragInfo=void 0,this.dragStatus=annotation.EDragStatus.Wait)}exportData(){const{polygonList:t}=this;return[t,this.basicImgInfo]}getTextIconSvg(t=""){return AttributeUtils.default.getTextIconSvg(t,this.config.attributeList,this.config.attributeConfigurable,this.baseIcon)}getCurrentSelectedData(){const{selectedPolygon:t}=this;if(!t)return;const e=this.getColor(t.attribute),i=t.valid?e==null?void 0:e.valid.stroke:e==null?void 0:e.invalid.stroke;return{width:TEXT_MAX_WIDTH,textAttribute:t.textAttribute,color:i}}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.setPolygonList(AttributeUtils.default.textChange(e,this.selectedID,this.polygonList)),this.emit("updateTextAttribute"),this.render()}}renderTextAttribute(){var t;const{selectedPolygon:e}=this;if(!this.ctx||this.config.textConfigurable===!1||!e)return;const{pointList:i,attribute:s,valid:o,textAttribute:r}=e,{x:n,y:l}=i[i.length-1],h=TEXT_MAX_WIDTH,c=AxisUtils.default.getOffsetCoordinate({x:n,y:l},this.currentPos,this.zoom),d=this.getColor(s),a=o?d==null?void 0:d.valid.stroke:d==null?void 0:d.invalid.stroke;this._textAttributInstance||(this._textAttributInstance=new textAttributeClass({width:h,container:this.container,icon:this.getTextIconSvg(s),color:a,getCurrentSelectedData:this.getCurrentSelectedData,updateSelectedTextAttribute:this.updateSelectedTextAttribute})),this._textAttributInstance&&!((t=this._textAttributInstance)==null?void 0:t.isExit)&&this._textAttributInstance.appendToContainer(),this._textAttributInstance.update(`${r}`,{left:c.x,top:c.y,color:a,width:h})}renderStaticPolygon(){var t;this.isHidden===!1&&((t=this.polygonList)==null||t.forEach(e=>{var i,s,o,r,n;if([this.selectedID,this.editPolygonID].includes(e.id))return;const{textAttribute:l,attribute:h}=e,c=this.getColor(h),d=StyleUtils.getStrokeAndFill(c,e.valid),a=AxisUtils.default.changePointListByZoom(e.pointList||[],this.zoom,this.currentPos);DrawUtils.drawPolygonWithFillAndLine(this.canvas,a,{fillColor:d.fill,strokeColor:d.stroke,pointColor:"white",thickness:(s=(i=this.style)==null?void 0:i.width)!=null?s:2,lineCap:"round",isClose:!0,lineType:(o=this.config)==null?void 0:o.lineType});let u=`${(r=AttributeUtils.default.getAttributeShowText(h,this.config.attributeList))!=null?r:""}`;((n=this.config)==null?void 0:n.isShowOrder)&&(e==null?void 0:e.order)>0&&(u=`${e.order} ${u}`),DrawUtils.drawText(this.canvas,a[0],u,__spreadValues({color:d.stroke},annotation.DEFAULT_TEXT_OFFSET));const f=a[a.length-1];DrawUtils.drawText(this.canvas,{x:f.x+annotation.TEXT_ATTRIBUTE_OFFSET.x,y:f.y+annotation.TEXT_ATTRIBUTE_OFFSET.y},l,__spreadValues({color:d.stroke},annotation.DEFAULT_TEXT_OFFSET))}))}renderSelectedPolygon(){var t,e,i;if(this.selectedID){const s=this.selectedPolygon;if(s){const o=this.getColor(s.attribute),r=StyleUtils.getStrokeAndFill(o,s.valid,{isSelected:!0});DrawUtils.drawSelectedPolygonWithFillAndLine(this.canvas,AxisUtils.default.changePointListByZoom(s.pointList,this.zoom,this.currentPos),{fillColor:r.fill,strokeColor:r.stroke,pointColor:"white",thickness:2,lineCap:"round",isClose:!0,lineType:(t=this.config)==null?void 0:t.lineType});let n=`${(e=AttributeUtils.default.getAttributeShowText(s.attribute,this.config.attributeList))!=null?e:""}`;((i=this.config)==null?void 0:i.isShowOrder)&&(s==null?void 0:s.order)>0&&(n=`${s.order} ${n}`),DrawUtils.drawText(this.canvas,AxisUtils.default.changePointByZoom(s.pointList[0],this.zoom,this.currentPos),n,__spreadValues({color:r.stroke},annotation.DEFAULT_TEXT_OFFSET)),this.renderTextAttribute()}}}renderHoverPolygon(){var t;if(this.hoverID&&this.hoverID!==this.editPolygonID){const{hoverPolygon:e}=this;if(e){let i="";const s=this.getColor(e.attribute);e.valid?i=s.validHover.fill:i=StyleUtils.getStrokeAndFill(s,!1,{isHover:!0}).fill,DrawUtils.drawPolygonWithFill(this.canvas,AxisUtils.default.changePointListByZoom(e.pointList,this.zoom,this.currentPos),{color:i,lineType:(t=this.config)==null?void 0:t.lineType})}}}renderPolygon(){var t,e,i,s;this.renderStaticPolygon(),this.renderHoverPolygon(),this.renderSelectedPolygon();const o=this.getColor(this.defaultAttribute),r=StyleUtils.getStrokeAndFill(o,!this.isCtrl);if(((t=this.drawingPointList)==null?void 0:t.length)>0){let n=[...this.drawingPointList],l=AxisUtils.default.getOriginCoordinateWithOffsetCoordinate(this.coord,this.zoom,this.currentPos);if(this.pattern===tool.EPolygonPattern.Rect&&n.length===2)n=MathUtils.default.getRectangleByRightAngle(l,n);else{if(((e=this.config)==null?void 0:e.edgeAdsorption)&&this.isAlt===!1){const{dropFoot:h}=PolygonUtils.getClosestPoint(l,this.polygonList,(i=this.config)==null?void 0:i.lineType,tool.edgeAdsorptionScope/this.zoom);h&&(l=h)}n.push(l)}DrawUtils.drawSelectedPolygonWithFillAndLine(this.canvas,AxisUtils.default.changePointListByZoom(n,this.zoom,this.currentPos),{fillColor:r.fill,strokeColor:r.stroke,pointColor:"white",thickness:2,lineCap:"round",isClose:!1,lineType:this.config.lineType})}if(this.hoverPointIndex>-1&&this.selectedID){const n=this.selectedPolygon;if(!n)return;const l=StyleUtils.getStrokeAndFill(o,n.valid,{isSelected:!0}),h=n==null?void 0:n.pointList[this.hoverPointIndex];if(h){const{x:c,y:d}=AxisUtils.default.changePointByZoom(h,this.zoom,this.currentPos);DrawUtils.drawCircleWithFill(this.canvas,{x:c,y:d},5,{color:l.fill})}}if(this.hoverEdgeIndex>-1&&this.selectedID){const n=this.selectedPolygon;if(!n)return;const l=StyleUtils.getStrokeAndFill(o,n.valid,{isSelected:!0});DrawUtils.drawLineWithPointList(this.canvas,AxisUtils.default.changePointListByZoom(n.pointList,this.zoom,this.currentPos),{color:l.stroke,thickness:10,hoverEdgeIndex:this.hoverEdgeIndex,lineType:(s=this.config)==null?void 0:s.lineType})}}render(){!this.ctx||(super.render(),this.renderPolygon(),this.renderCursorLine(this.getLineColor(this.defaultAttribute)))}renderCursorLine(t){if(super.renderCursorLine(t),this.isCombined){const{x:e,y:i}=this.coord,s=10,o=186,r=32;DrawUtils.drawRectWithFill(this.canvas,{x:e+s,y:i-s*4-1,width:o,height:r},{color:"black"}),DrawUtils.drawText(this.canvas,{x:e,y:i},lbUtils.i18n.t("ClickAnotherPolygon"),{textAlign:"center",color:"white",offsetX:o/2+s,offsetY:-(r/2+s/2)}),DrawUtils.drawRect(this.canvas,{x:e-s,y:i-s,width:s*2,height:s*2},{lineDash:[6],color:"white"})}}undo(){if(this.drawingPointList.length>0){const e=this.drawingHistory.undo();if(!e)return;this.drawingPointList=e,this.render();return}const t=this.history.undo();t&&(t.length!==this.polygonList.length&&this.deleteSelectedID(),this.setPolygonList(t),this.render())}redo(){if(this.drawingPointList.length>0){const e=this.drawingHistory.redo();if(!e)return;this.drawingPointList=e,this.render();return}const t=this.history.redo();t&&(t.length!==this.polygonList.length&&this.deleteSelectedID(),this.setPolygonList(t),this.render())}deleteSelectedID(){this.setSelectedID("")}}module.exports=PolygonOperation;
@@ -43,6 +43,7 @@ export default class AnnotationEngine {
43
43
  valid: boolean;
44
44
  rotate: number;
45
45
  }>): void;
46
+ setImgAttribute(imgAttribute: IImageAttribute): void;
46
47
  setSize(size: ISize): void;
47
48
  setStyle(style: any): void;
48
49
  /**
@@ -17,13 +17,15 @@ interface IPointCloudAnnotationProps {
17
17
  pcdPath?: string;
18
18
  polygonOperationProps?: IPointCloud2dOperationProps;
19
19
  config: IPointCloudConfig;
20
+ checkMode?: boolean;
20
21
  }
21
22
  export declare class PointCloudAnnotation implements IPointCloudAnnotationOperation {
22
23
  pointCloudInstance: PointCloud;
23
24
  pointCloud2dOperation: PointCloud2dOperation;
24
25
  canvasScheduler: CanvasScheduler;
25
26
  config: IPointCloudConfig;
26
- constructor({ size, container, pcdPath, polygonOperationProps, config }: IPointCloudAnnotationProps);
27
+ constructor({ size, container, pcdPath, polygonOperationProps, config, checkMode }: IPointCloudAnnotationProps);
28
+ updateConfig(config: IPointCloudConfig): void;
27
29
  /**
28
30
  * Get default boundary by size.
29
31
  * @param size
@@ -52,6 +52,7 @@ export declare class PointCloud {
52
52
  get containerWidth(): number;
53
53
  get containerHeight(): number;
54
54
  setInitCameraPosition(vector: THREE.Vector3): void;
55
+ setConfig(config: IPointCloudConfig): void;
55
56
  /**
56
57
  * Init OrthographicCamera to default config by size
57
58
  * @param orthographicParams
@@ -156,6 +157,7 @@ export declare class PointCloud {
156
157
  depth: number;
157
158
  }>) => Promise<void>;
158
159
  setShowDirection(showDirection: boolean): void;
160
+ generateRange: (radius: number) => void;
159
161
  generateBoxArrow: ({ width }: IPointCloudBox) => THREE.ArrowHelper;
160
162
  generateBoxTrackID: (boxParams: IPointCloudBox) => THREE.Sprite | undefined;
161
163
  getTextCanvas(text: string): HTMLCanvasElement;
@@ -36,6 +36,7 @@ export declare class ToolScheduler implements IToolSchedulerOperation {
36
36
  valid: boolean;
37
37
  rotate: number;
38
38
  }>): void;
39
+ setImgAttribute(imgAttribute: IImageAttribute): void;
39
40
  setSize(size: ISize): void;
40
41
  syncPosition(currentPos: ICoordinate, zoom: number, imgInfo: ISize, currentToolInstance: any): void;
41
42
  get defaultSize(): {
@@ -12,14 +12,20 @@ import PolygonOperation, { IPolygonOperationProps } from './polygonOperation';
12
12
  interface IPointCloud2dOperationProps {
13
13
  showDirectionLine?: boolean;
14
14
  forbidAddNew?: boolean;
15
+ checkMode?: boolean;
15
16
  }
16
17
  declare class PointCloud2dOperation extends PolygonOperation {
17
18
  showDirectionLine: boolean;
18
19
  forbidAddNew: boolean;
19
20
  pointCloudConfig: IPointCloudConfig;
21
+ private checkMode;
20
22
  private selectedIDs;
21
23
  constructor(props: IPolygonOperationProps & IPointCloud2dOperationProps);
22
24
  get getSelectedIDs(): string[];
25
+ setConfig(config: string): void;
26
+ dragMouseDown(e: MouseEvent): void;
27
+ deletePolygon(id?: string): void;
28
+ deletePolygonPoint(index: number): void;
23
29
  /**
24
30
  * Update selectedIDs and rerender
25
31
  * @param selectedIDs
@@ -122,6 +122,12 @@ declare class PolygonOperation extends BasicToolOperation {
122
122
  onLeftDblClick(e: MouseEvent): void;
123
123
  onRightDblClick(e: MouseEvent): void;
124
124
  onMouseDown(e: MouseEvent): true | undefined;
125
+ /**
126
+ * Judgment of drag information during mousedown
127
+ * @param e
128
+ * @returns
129
+ */
130
+ dragMouseDown(e: MouseEvent): void;
125
131
  segment(): void;
126
132
  onCombinedExecute(): void;
127
133
  combine(e: MouseEvent): void;
@@ -1,4 +1,4 @@
1
- "use strict";var index=require("../../locales/index.js"),constants=require("../../locales/constants.js");class RenderDomUtils{static renderInvalidPage(i,t,n){const e=document.createElement("div");return e.setAttribute("style",`
1
+ "use strict";var index=require("../../locales/index.js"),constants=require("../../locales/constants.js");const INVALID_PAGE_CLASS_NAME="bee-invalid-page";class RenderDomUtils{static renderInvalidPage(i,t,s){const e=document.createElement("div");return e.setAttribute("style",`
2
2
  position: absolute;
3
3
  left: 0px;
4
4
  top: 0px;
@@ -13,4 +13,4 @@
13
13
  font-size: 30px;
14
14
  opacity: 0.7;
15
15
  z-index: 30;
16
- `),e.innerHTML=index.getMessagesByLocale(constants.EMessage.InvalidImage,n),i.appendChild(e),e}}module.exports=RenderDomUtils;
16
+ `),e.innerHTML=index.getMessagesByLocale(constants.EMessage.InvalidImage,s),e.className=INVALID_PAGE_CLASS_NAME,i.appendChild(e),e}}module.exports=RenderDomUtils;
@@ -1 +1,12 @@
1
- import{createBase64WorkerFactory as a}from"./_rollup-plugin-web-worker-loader__helper__node__createBase64WorkerFactory.js";import{createBase64WorkerFactory as t}from"./_rollup-plugin-web-worker-loader__helper__browser__createBase64WorkerFactory.js";import{isNodeJS as _}from"./_rollup-plugin-web-worker-loader__helper__auto__isNodeJS.js";function l(r,e,o){return _()?a(r,e,o):t(r,e,o)}export{l as createBase64WorkerFactory};
1
+ import { createBase64WorkerFactory as createBase64WorkerFactory$1 } from './_rollup-plugin-web-worker-loader__helper__node__createBase64WorkerFactory.js';
2
+ import { createBase64WorkerFactory as createBase64WorkerFactory$2 } from './_rollup-plugin-web-worker-loader__helper__browser__createBase64WorkerFactory.js';
3
+ import { isNodeJS } from './_rollup-plugin-web-worker-loader__helper__auto__isNodeJS.js';
4
+
5
+ function createBase64WorkerFactory(base64, sourcemapArg, enableUnicodeArg) {
6
+ if (isNodeJS()) {
7
+ return createBase64WorkerFactory$1(base64, sourcemapArg, enableUnicodeArg);
8
+ }
9
+ return createBase64WorkerFactory$2(base64, sourcemapArg, enableUnicodeArg);
10
+ }
11
+
12
+ export { createBase64WorkerFactory };
@@ -1 +1,7 @@
1
- var e=Object.prototype.toString.call(typeof process!="undefined"?process:0)==="[object process]";function o(){return e}export{o as isNodeJS};
1
+ var kIsNodeJS = Object.prototype.toString.call(typeof process !== 'undefined' ? process : 0) === '[object process]';
2
+
3
+ function isNodeJS() {
4
+ return kIsNodeJS;
5
+ }
6
+
7
+ export { isNodeJS };
@@ -1 +1,11 @@
1
- var e=null;try{var r=typeof module!="undefined"&&typeof module.require=="function"&&module.require("worker_threads")||typeof __non_webpack_require__=="function"&&__non_webpack_require__("worker_threads")||typeof require=="function"&&require("worker_threads");e=r.Worker}catch(o){}export{e as WorkerClass};
1
+ var WorkerClass = null;
2
+
3
+ try {
4
+ var WorkerThreads =
5
+ typeof module !== 'undefined' && typeof module.require === 'function' && module.require('worker_threads') ||
6
+ typeof __non_webpack_require__ === 'function' && __non_webpack_require__('worker_threads') ||
7
+ typeof require === 'function' && require('worker_threads');
8
+ WorkerClass = WorkerThreads.Worker;
9
+ } catch(e) {} // eslint-disable-line
10
+
11
+ export { WorkerClass };
@@ -1,2 +1,18 @@
1
- import{WorkerClass as i}from"./_rollup-plugin-web-worker-loader__helper__node__WorkerClass.js";function l(e,r){return Buffer.from(e,"base64").toString(r?"utf16":"utf8")}function c(e,r,n){var o=r===void 0?null:r,a=n===void 0?!1:n,t=l(e,a),u=t.indexOf(`
2
- `,10)+1,s=t.substring(u)+(o?"//# sourceMappingURL="+o:"");return function(f){return new i(s,Object.assign({},f,{eval:!0}))}}export{c as createBase64WorkerFactory};
1
+ import { WorkerClass } from './_rollup-plugin-web-worker-loader__helper__node__WorkerClass.js';
2
+
3
+ function decodeBase64(base64, enableUnicode) {
4
+ return Buffer.from(base64, 'base64').toString(enableUnicode ? 'utf16' : 'utf8');
5
+ }
6
+
7
+ function createBase64WorkerFactory(base64, sourcemapArg, enableUnicodeArg) {
8
+ var sourcemap = sourcemapArg === undefined ? null : sourcemapArg;
9
+ var enableUnicode = enableUnicodeArg === undefined ? false : enableUnicodeArg;
10
+ var source = decodeBase64(base64, enableUnicode);
11
+ var start = source.indexOf('\n', 10) + 1;
12
+ var body = source.substring(start) + (sourcemap ? '\/\/# sourceMappingURL=' + sourcemap : '');
13
+ return function WorkerFactory(options) {
14
+ return new WorkerClass(body, Object.assign({}, options, { eval: true }));
15
+ };
16
+ }
17
+
18
+ export { createBase64WorkerFactory };
package/es/core/index.js CHANGED
@@ -1 +1 @@
1
- import{ELang as h}from"../constant/annotation.js";import{getConfig as d,styleDefaultConfig as u}from"../constant/defaultConfig.js";import{HybridToolUtils as r,ToolScheduler as m}from"./scheduler.js";var f=(a,t,e)=>new Promise((o,s)=>{var i=n=>{try{l(e.next(n))}catch(c){s(c)}},g=n=>{try{l(e.throw(n))}catch(c){s(c)}},l=n=>n.done?o(n.value):Promise.resolve(n.value).then(i,g);l((e=e.apply(a,t)).next())});const I=a=>new Promise((t,e)=>{const o=document.createElement("img");o.crossOrigin="Anonymous",o.onerror=s=>{console.error(s),e(o)},o.src=a,o.onload=()=>{t(o)}});class N{constructor(t){this.setImgSrc=s=>f(this,null,function*(){const i=yield I(s);!i||this.setImgNode(i)});var e,o;this.container=t.container,this.size=t.size,this.toolName=t.toolName,this.imgNode=t.imgNode,this.config=(e=t.config)!=null?e:JSON.stringify(d(r.getTopToolName(t.toolName))),this.style=(o=t.style)!=null?o:u,this.toolScheduler=new m(t),this.i18nLanguage="cn",this._initToolOperation()}setToolName(t,e){this.toolName=t;const o=e||JSON.stringify(d(r.getTopToolName(t)));this.config=o,this._initToolOperation()}setImgNode(t,e){this.toolScheduler.setImgNode(t,e),this.imgNode=t}setSize(t){this.size=t,this.toolScheduler.setSize(t)}setStyle(t){this.style=t}_initToolOperation(){this.toolScheduler.destroyAllLayer();let t=[];const e={hiddenImg:!0};r.isSingleTool(this.toolName)?(t=[this.toolName],Object.assign(e,{hiddenImg:!1})):t=this.toolName,t.length>1&&this.toolScheduler.createOperation(void 0,this.imgNode),t.forEach((o,s)=>{const i=this.toolScheduler.createOperation(o,void 0,e);s===t.length-1&&(this.toolInstance=i)}),this.setLang(this.i18nLanguage)}setBasicInfo(t,e){this.dependToolName=t,this.basicResult=e,this.toolInstance.setDependName(t),this.toolInstance.setBasicResult(e),this.toolInstance.renderBasicCanvas()}clearBasicResult(){this.setBasicInfo()}forbidOperation(){this.toolInstance.setForbidOperation(!0)}launchOperation(){this.toolInstance.setForbidOperation(!1)}setLang(t){switch(this.i18nLanguage=t,t){case"cn":this.toolInstance.setLang(h.Zh);break;case"en":this.toolInstance.setLang(h.US);break}}setDataInjectionAtCreation(t){this.toolInstance.setDataInjectionAtCreation(t)}setRenderEnhance(t){this.toolInstance.setRenderEnhance(t)}switchLastTwoCanvas(){const t=this.toolScheduler.switchLastTwoCanvas();if(t)return this.toolInstance=t,t}get firstToolInstance(){return this.toolScheduler.getFirstToolOperation()}setCustomRenderStyle(t){this.toolInstance.setCustomRenderStyle(t)}}export{N as default};
1
+ import{ELang as h}from"../constant/annotation.js";import{getConfig as d,styleDefaultConfig as u}from"../constant/defaultConfig.js";import{HybridToolUtils as c,ToolScheduler as m}from"./scheduler.js";var f=(a,t,e)=>new Promise((o,s)=>{var i=n=>{try{l(e.next(n))}catch(r){s(r)}},g=n=>{try{l(e.throw(n))}catch(r){s(r)}},l=n=>n.done?o(n.value):Promise.resolve(n.value).then(i,g);l((e=e.apply(a,t)).next())});const I=a=>new Promise((t,e)=>{const o=document.createElement("img");o.crossOrigin="Anonymous",o.onerror=s=>{console.error(s),e(o)},o.src=a,o.onload=()=>{t(o)}});class S{constructor(t){this.setImgSrc=s=>f(this,null,function*(){const i=yield I(s);!i||this.setImgNode(i)});var e,o;this.container=t.container,this.size=t.size,this.toolName=t.toolName,this.imgNode=t.imgNode,this.config=(e=t.config)!=null?e:JSON.stringify(d(c.getTopToolName(t.toolName))),this.style=(o=t.style)!=null?o:u,this.toolScheduler=new m(t),this.i18nLanguage="cn",this._initToolOperation()}setToolName(t,e){this.toolName=t;const o=e||JSON.stringify(d(c.getTopToolName(t)));this.config=o,this._initToolOperation()}setImgNode(t,e){this.toolScheduler.setImgNode(t,e),this.imgNode=t}setImgAttribute(t){this.toolScheduler.setImgAttribute(t)}setSize(t){this.size=t,this.toolScheduler.setSize(t)}setStyle(t){this.style=t}_initToolOperation(){this.toolScheduler.destroyAllLayer();let t=[];const e={hiddenImg:!0};c.isSingleTool(this.toolName)?(t=[this.toolName],Object.assign(e,{hiddenImg:!1})):t=this.toolName,t.length>1&&this.toolScheduler.createOperation(void 0,this.imgNode),t.forEach((o,s)=>{const i=this.toolScheduler.createOperation(o,void 0,e);s===t.length-1&&(this.toolInstance=i)}),this.setLang(this.i18nLanguage)}setBasicInfo(t,e){this.dependToolName=t,this.basicResult=e,this.toolInstance.setDependName(t),this.toolInstance.setBasicResult(e),this.toolInstance.renderBasicCanvas()}clearBasicResult(){this.setBasicInfo()}forbidOperation(){this.toolInstance.setForbidOperation(!0)}launchOperation(){this.toolInstance.setForbidOperation(!1)}setLang(t){switch(this.i18nLanguage=t,t){case"cn":this.toolInstance.setLang(h.Zh);break;case"en":this.toolInstance.setLang(h.US);break}}setDataInjectionAtCreation(t){this.toolInstance.setDataInjectionAtCreation(t)}setRenderEnhance(t){this.toolInstance.setRenderEnhance(t)}switchLastTwoCanvas(){const t=this.toolScheduler.switchLastTwoCanvas();if(t)return this.toolInstance=t,t}get firstToolInstance(){return this.toolScheduler.getFirstToolOperation()}setCustomRenderStyle(t){this.toolInstance.setCustomRenderStyle(t)}}export{S as default};
@@ -1 +1 @@
1
- import{PointCloudUtils as f}from"@labelbee/lb-utils";import{EPolygonPattern as w}from"../../constant/tool.js";import{CanvasScheduler as D}from"../../newCore/CanvasScheduler.js";import{PointCloud as L}from"./index.js";import b from"../toolOperation/pointCloud2dOperation.js";const O=i=>{const t=document.createElement("canvas");t.width=i.width,t.height=i.height;const o=t.getContext("2d");return o?(o.fillStyle="black",o.fillRect(0,0,i.width,i.height),t.toDataURL()):""};class R{constructor({size:t,container:o,pcdPath:n,polygonOperationProps:u,config:a}){this.updatePolygonList=(I,C)=>{let d=I.map(s=>{var m;const{polygon2d:y}=this.pointCloudInstance.getBoxTopPolygon2DCoordinate(s);return{id:s.id,sourceID:"",pointList:y,isRect:!0,valid:(m=s.valid)!=null?m:!0,attribute:s.attribute}});C&&(d=d.concat(C)),this.pointCloud2dOperation.setResult(d)};var p,c;const P=this.getDefaultOrthographic(t),v=O(t),h=new Image;h.src=v;const l=new D({container:o}),r=new L({container:o,noAppend:!0,isOrthographicCamera:!0,orthographicParams:P});n&&r.loadPCDFile(n),l.createCanvas(r.renderer.domElement);const g={container:o,size:t,config:JSON.stringify(a),imgNode:h,isAppend:!1};u&&Object.assign(g,u);const e=new b(g);e.eventBinding(),e.setPattern(w.Rect),e.setDefaultAttribute((c=(p=a==null?void 0:a.attributeList)==null?void 0:p[0])==null?void 0:c.value),l.createCanvas(e.canvas,{size:t}),this.pointCloud2dOperation=e,this.pointCloudInstance=r,this.canvasScheduler=l,this.config=a}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=O(t),n=new Image;n.src=o,n.onload=()=>{this.pointCloud2dOperation.setImgNode(n),this.pointCloud2dOperation.setCanvasSize(t),this.pointCloud2dOperation.initImgPos()}}addPolygonListOnTopView(t){const o=f.getBoxParamsFromResultList(t),n=f.getPolygonListFromResultList(t);this.updatePolygonList(o,n)}updateData(t,o,n){!this.pointCloud2dOperation||!this.pointCloudInstance||(this.pointCloudInstance.loadPCDFile(t,n==null?void 0:n.radius),this.addPolygonListOnTopView(o))}initAllPosition(){this.pointCloudInstance.updateTopCamera(),this.pointCloud2dOperation.initPosition()}clearAllData(){this.pointCloudInstance.clearPointCloudAndRender(),this.pointCloud2dOperation.clearResult()}}export{R as PointCloudAnnotation};
1
+ import{PointCloudUtils as c}from"@labelbee/lb-utils";import{EPolygonPattern as D}from"../../constant/tool.js";import{CanvasScheduler as L}from"../../newCore/CanvasScheduler.js";import{PointCloud as S}from"./index.js";import R from"../toolOperation/pointCloud2dOperation.js";var j=Object.defineProperty,A=Object.defineProperties,E=Object.getOwnPropertyDescriptors,P=Object.getOwnPropertySymbols,x=Object.prototype.hasOwnProperty,N=Object.prototype.propertyIsEnumerable,v=(e,t,o)=>t in e?j(e,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[t]=o,T=(e,t)=>{for(var o in t||(t={}))x.call(t,o)&&v(e,o,t[o]);if(P)for(var o of P(t))N.call(t,o)&&v(e,o,t[o]);return e},F=(e,t)=>A(e,E(t));const y=e=>{const t=document.createElement("canvas");t.width=e.width,t.height=e.height;const o=t.getContext("2d");return o?(o.fillStyle="black",o.fillRect(0,0,e.width,e.height),t.toDataURL()):""};class B{constructor({size:t,container:o,pcdPath:n,polygonOperationProps:h,config:s,checkMode:_}){this.updatePolygonList=(b,O)=>{let p=b.map(i=>{var a;const{polygon2d:u}=this.pointCloudInstance.getBoxTopPolygon2DCoordinate(i);return{id:i.id,sourceID:"",pointList:u,isRect:!0,valid:(a=i.valid)!=null?a:!0,attribute:i.attribute}});O&&(p=p.concat(O.map(i=>{var a;return F(T({},i),{pointList:(a=i==null?void 0:i.pointList)==null?void 0:a.map(u=>c.transferWorld2Canvas(u,this.pointCloud2dOperation.size))})}))),this.pointCloud2dOperation.setResult(p)};var g,C;const w=this.getDefaultOrthographic(t),I=y(t),m=new Image;m.src=I;const l=new L({container:o}),d=new S({container:o,noAppend:!0,isOrthographicCamera:!0,orthographicParams:w});n&&d.loadPCDFile(n),l.createCanvas(d.renderer.domElement);const f={container:o,size:t,config:JSON.stringify(s),imgNode:m,isAppend:!1,checkMode:_};h&&Object.assign(f,h);const r=new R(f);r.eventBinding(),r.setPattern(D.Rect),r.setDefaultAttribute((C=(g=s==null?void 0:s.attributeList)==null?void 0:g[0])==null?void 0:C.value),l.createCanvas(r.canvas,{size:t}),this.pointCloud2dOperation=r,this.pointCloudInstance=d,this.canvasScheduler=l,this.config=s}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 o=y(t),n=new Image;n.src=o,n.onload=()=>{this.pointCloud2dOperation.setImgNode(n),this.pointCloud2dOperation.initImgPos()},this.pointCloud2dOperation.setCanvasSize(t)}addPolygonListOnTopView(t){const o=c.getBoxParamsFromResultList(t),n=c.getPolygonListFromResultList(t);this.updatePolygonList(o,n)}updateData(t,o,n){!this.pointCloud2dOperation||!this.pointCloudInstance||(this.pointCloudInstance.loadPCDFile(t,n==null?void 0:n.radius),this.addPolygonListOnTopView(o))}initAllPosition(){this.pointCloudInstance.updateTopCamera(),this.pointCloud2dOperation.initPosition()}clearAllData(){this.pointCloudInstance.clearPointCloudAndRender(),this.pointCloud2dOperation.clearResult()}}export{B as PointCloudAnnotation};
@@ -1,4 +1,4 @@
1
- import*as c from"three";import{toolStyleConverter as _,PerspectiveShiftUtils as w,EPerspectiveView as g}from"@labelbee/lb-utils";import V from"../../_virtual/highlightWorker.js";import k from"../../_virtual/filterBoxWorker.js";import{isInPolygon as A}from"../../utils/tool/polygonTool.js";import L from"../../utils/uuid.js";import{PCDLoader as S}from"./PCDLoader.js";import{OrbitControls as I}from"./OrbitControls.js";import{PointCloudCache as N}from"./cache.js";import{getCuboidFromPointCloudBox as D}from"./matrix.js";export{createThreeMatrix4,getCuboidFromPointCloudBox,lidar2image,pointCloudLidar2image,rotatePoint,transferKitti2Matrix}from"./matrix.js";import"../../constant/tool.js";import"../../constant/annotation.js";import"../../utils/MathUtils.js";import"@turf/turf";import"../../utils/tool/CommonToolUtils.js";import"../../utils/tool/LineToolUtils.js";import"../../utils/tool/DrawUtils.js";import"../../constant/keyCode.js";import"../../locales/index.js";import"../../locales/constants.js";import"lodash";import"../../constant/style.js";import"../../utils/tool/CanvasUtils.js";import"../../utils/tool/ZoomUtils.js";var F=Object.defineProperty,E=Object.defineProperties,R=Object.getOwnPropertyDescriptors,P=Object.getOwnPropertySymbols,W=Object.prototype.hasOwnProperty,U=Object.prototype.propertyIsEnumerable,z=(u,t,e)=>t in u?F(u,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):u[t]=e,C=(u,t)=>{for(var e in t||(t={}))W.call(t,e)&&z(u,e,t[e]);if(P)for(var e of P(t))U.call(t,e)&&z(u,e,t[e]);return u},b=(u,t)=>E(u,R(t)),v=(u,t,e)=>new Promise((r,o)=>{var s=n=>{try{i(e.next(n))}catch(h){o(h)}},a=n=>{try{i(e.throw(n))}catch(h){o(h)}},i=n=>n.done?r(n.value):Promise.resolve(n.value).then(s,a);i((e=e.apply(u,t)).next())});const H=30;new V;class Z{constructor({container:t,noAppend:e,isOrthographicCamera:r,orthographicParams:o,backgroundColor:s="black",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.AddBoxToSense=(i,n=16777215)=>{var h;const l=(h=i.id)!=null?h:L();this.removeObjectByName(l);const{center:m,width:d,height:f,depth:y,rotation:x}=i,p=new c.Group,M=new c.BoxGeometry(d,f,y),B=new c.MeshBasicMaterial({color:"blue"}),j=new c.Mesh(M,B),T=new c.BoxHelper(j,n),O=this.generateBoxArrow(i);p.add(T),p.add(O),p.position.set(m.x,m.y,m.z),p.rotation.set(0,0,x),p.name=l,this.scene.add(p)},this.overridePointShader=i=>{i.vertexShader=`
1
+ import*as c from"three";import{toolStyleConverter as _,PerspectiveShiftUtils as w,EPerspectiveView as g}from"@labelbee/lb-utils";import V from"../../_virtual/highlightWorker.js";import k from"../../_virtual/filterBoxWorker.js";import{isInPolygon as A}from"../../utils/tool/polygonTool.js";import L from"../../utils/uuid.js";import{PCDLoader as S}from"./PCDLoader.js";import{OrbitControls as I}from"./OrbitControls.js";import{PointCloudCache as N}from"./cache.js";import{getCuboidFromPointCloudBox as D}from"./matrix.js";export{createThreeMatrix4,getCuboidFromPointCloudBox,lidar2image,pointCloudLidar2image,rotatePoint,transferKitti2Matrix}from"./matrix.js";import"../../constant/tool.js";import"../../constant/annotation.js";import"../../utils/MathUtils.js";import"@turf/turf";import"../../utils/tool/CommonToolUtils.js";import"../../utils/tool/LineToolUtils.js";import"../../utils/tool/DrawUtils.js";import"../../constant/keyCode.js";import"../../locales/index.js";import"../../locales/constants.js";import"lodash";import"../../constant/style.js";import"../../utils/tool/CanvasUtils.js";import"../../utils/tool/ZoomUtils.js";var F=Object.defineProperty,R=Object.defineProperties,E=Object.getOwnPropertyDescriptors,P=Object.getOwnPropertySymbols,W=Object.prototype.hasOwnProperty,U=Object.prototype.propertyIsEnumerable,z=(u,t,e)=>t in u?F(u,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):u[t]=e,C=(u,t)=>{for(var e in t||(t={}))W.call(t,e)&&z(u,e,t[e]);if(P)for(var e of P(t))U.call(t,e)&&z(u,e,t[e]);return u},b=(u,t)=>R(u,E(t)),v=(u,t,e)=>new Promise((r,n)=>{var s=o=>{try{i(e.next(o))}catch(h){n(h)}},a=o=>{try{i(e.throw(o))}catch(h){n(h)}},i=o=>o.done?r(o.value):Promise.resolve(o.value).then(s,a);i((e=e.apply(u,t)).next())});const H=30;new V;class Z{constructor({container:t,noAppend:e,isOrthographicCamera:r,orthographicParams:n,backgroundColor:s="black",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.AddBoxToSense=(i,o=16777215)=>{var h;const l=(h=i.id)!=null?h:L();this.removeObjectByName(l);const{center:m,width:d,height:f,depth:y,rotation:x}=i,p=new c.Group,M=new c.BoxGeometry(d,f,y),B=new c.MeshBasicMaterial({color:"blue"}),j=new c.Mesh(M,B),T=new c.BoxHelper(j,o),O=this.generateBoxArrow(i);p.add(T),p.add(O),p.position.set(m.x,m.y,m.z),p.rotation.set(0,0,x),p.name=l,this.scene.add(p)},this.overridePointShader=i=>{i.vertexShader=`
2
2
  attribute float sizes;
3
3
  attribute float visibility;
4
4
  varying float vVisible;
@@ -8,4 +8,4 @@ import*as c from"three";import{toolStyleConverter as _,PerspectiveShiftUtils as
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,n)=>v(this,null,function*(){this.clearPointCloud();const h=yield this.cacheInstance.loadPCDFile(i);h.name=this.pointCloudObjectName,this.renderPointCloud(h,n)}),this.loadPCDFileByBox=(i,n,h)=>v(this,null,function*(){const l=d=>v(this,null,function*(){const{width:f=0,height:y=0,depth:x=0}=h!=null?h:{},p=yield this.filterPointsByBox(b(C({},n),{width:n.width+f,height:n.height+y,depth:n.depth+x}),d);if(!p){console.error("filter Error");return}this.clearPointCloud();const M=new c.Points(p.geometry,d.material);M.name=this.pointCloudObjectName,this.scene.add(M),this.render()}),m=yield this.cacheInstance.loadPCDFile(i);l(m)}),this.generateBoxArrow=({width:i})=>{const n=new c.Vector3(1,0,0),h=new c.Vector3(i/2,0,0),l=2,m=16776960,d=new c.ArrowHelper(n,h,l,m);return d.visible=this.showDirection,d},this.generateBoxTrackID=i=>{if(!i.trackID)return;const n=new c.Texture(this.getTextCanvas(i.trackID.toString()));n.needsUpdate=!0;const h=new c.SpriteMaterial({map:n,depthWrite:!1}),l=new c.Sprite(h);return l.scale.set(5,5,5),l.position.set(-i.width/2,0,i.depth/2+.5),l},this.applyZAxisPoints=i=>{this.zAxisLimit=i,this.filterZAxisPoints(),this.render()},this.updatePointSize=i=>{const n=this.scene.getObjectByName(this.pointCloudObjectName);if(!n)return;const h=n.material.size;i?n.material.size=Math.min(h*1.2,10):n.material.size=Math.max(h/1.2,1),this.render()},this.container=t,this.renderer=new c.WebGLRenderer({antialias:!0}),this.backgroundColor=s,this.config=a,r&&o?(this.isOrthographicCamera=!0,this.camera=new c.OrthographicCamera(o.left,o.right,o.top,o.bottom,o.near,o.far)):this.camera=new c.PerspectiveCamera(30,this.containerWidth/this.containerHeight,1,1e3),this.initCamera(),this.scene=new c.Scene,this.controls=new I(this.camera,this.renderer.domElement),this.pcdLoader=new S,this.axesHelper=new c.AxesHelper(1e3),this.scene.add(this.camera),e||t.appendChild(this.renderer.domElement),this.init(),this.cacheInstance=N.getInstance()}get DEFAULT_INIT_CAMERA_POSITION(){return new c.Vector3(-1,0,10)}get containerWidth(){return this.container.clientWidth}get containerHeight(){return this.container.clientHeight}setInitCameraPosition(t){this.initCameraPosition=t}initOrthographicCamera(t){if(this.camera.type!=="OrthographicCamera")return;const{left:e,right:r,top:o,bottom:s,near:a,far:i}=t;this.camera.left=e,this.camera.right=r,this.camera.top=o,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:o}=this.initCameraPosition;t.position.set(e,r,o)}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 c.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 c.Color(this.backgroundColor),this.initControls(),this.initRenderer()}removeObjectByName(t){const e=this.scene.getObjectByName(t);e&&e.removeFromParent()}generateBox(t,e=16777215){var r,o,s,a,i;let n=e;((r=this.config)==null?void 0:r.attributeList)&&((s=(o=this.config)==null?void 0:o.attributeList)==null?void 0:s.length)>0&&t.attribute&&(n=(i=(a=_.getColorFromConfig({attribute:t.attribute},b(C({},this.config),{attributeConfigurable:!0}),{}))==null?void 0:a.hex)!=null?i:e),this.AddBoxToSense(t,n),this.render()}generateBoxes(t){t.forEach(e=>{this.generateBox(e)}),this.render()}getOrthographicCamera(t){const{center:e,width:r,height:o}=t,s=10,a=e.x-r/2-s,i=e.x-r/2+s,n=e.y+o/2+s,h=e.y-o/2-s,l=100,m=-100,d=500/l;return{left:a,right:i,top:n,bottom:h,near:l,far:m,zoom:d}}updateCameraByBox(t,e){const{center:r,width:o,height:s,depth:a,rotation:i}=t,n=this.getCameraVector(r,i,{width:o,height:s,depth:a},e);return this.updateCamera(n,r),n}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 c.Vector3(e.x,e.y,e.z),this.controls.update()}resetCamera(){this.updateCamera({x:-1,y:0,z:500},{x:0,y:0,z:0})}createThreeMatrix4(t){return new c.Matrix4().set(...t)}filterPointsByBox(t,e){if(!e){const r=this.scene.getObjectByName(this.pointCloudObjectName);if(!r)return console.error("There is no corresponding point cloud object"),Promise.resolve(void 0);e=r}if(window.Worker){const{zMin:r,zMax:o,polygonPointList:s}=D(t),a=e.geometry.attributes.position.array,i=e.geometry.attributes.color.array,n={boxParams:t,zMin:r,zMax:o,polygonPointList:s,color:i,position:a};return new Promise(h=>{const l=new k;l.postMessage(n),l.onmessage=m=>{const{color:d,position:f,num:y}=m.data,x=new c.BufferGeometry;x.setAttribute("position",new c.Float32BufferAttribute(f,3)),x.setAttribute("color",new c.Float32BufferAttribute(d,3)),x.computeBoundingSphere(),l.terminate(),h({geometry:x,num:y})}})}return Promise.resolve(void 0)}getCameraVector(t,e,r,o=g.Front,s=H){let a=w.frontViewMatrix4(s);switch(o){case g.Front:break;case g.Back:a=w.backViewMatrix4(s);break;case g.Left:a=w.leftViewMatrix4(s);break;case g.Right:a=w.rightViewMatrix4(s);break;case g.Top:a=w.topViewMatrix4(s);break;case g.LFT:a=w.leftFrontTopViewMatrix4(s,r);break;case g.RBT:a=w.rightBackTopViewMatrix4(s,r);break}const i=this.createThreeMatrix4(a),n=new c.Matrix4().makeTranslation(-t.x,-t.y,-t.z),h=new c.Matrix4().makeTranslation(t.x,t.y,t.z),l=new c.Matrix4().makeRotationZ(e);return new c.Vector3(t.x,t.y,t.z).clone().applyMatrix4(i).applyMatrix4(n).applyMatrix4(l).applyMatrix4(h)}createRange(t){this.removeObjectByName(this.rangeObjectName);const r=new c.EllipseCurve(0,0,t,t,0,2*Math.PI,!1,0).getPoints(50),o=new c.BufferGeometry().setFromPoints(r),s=new c.LineBasicMaterial({color:16711680}),a=new c.Line(o,s);return a.name=this.rangeObjectName,a}renderPointCloud(t,e){t.material.size=1,t.name=this.pointCloudObjectName;const r=new c.PointsMaterial({vertexColors:!0});if(r.onBeforeCompile=this.overridePointShader,e){const o=this.createRange(e);this.scene.add(o)}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){}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}getSensesPointZAxisInPolygon(t,e){const r=this.scene.children.find(n=>n.uuid===this.pointsUuid);let o=0,s=0,a=0,i=0;if(r&&(r==null?void 0:r.geometry)){const n=r==null?void 0:r.geometry.attributes.position.array;for(let h=0;h<n.length;h+=3){const l=n[h],m=n[h+1],d=n[h+2];A({x:l,y:m},t)&&d&&(s=Math.max(d,s),o=Math.min(d,o),i++,e&&d>=e[0]&&d<=e[1]&&a++)}}return{maxZ:s,minZ:o,count:a,zCount:i}}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 c.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 c.Vector3(t.x/e-e/2,-(t.y/r-r/2),1)}getPolygonSidePoints(t){const{center:{x:e,y:r,z:o},height:s,width:a,depth:i}=t,n={x:e+a/2,y:r+s/2,z:o-i/2},h={x:e+a/2,y:r+s/2,z:o+i/2},l={x:e-a/2,y:r+s/2,z:o+i/2},m={x:e-a/2,y:r+s/2,z:o-i/2};return[n,h,l,m]}getPolygonBackPoints(t){const{center:{x:e,y:r,z:o},height:s,width:a,depth:i}=t,n={x:e-a/2,y:r+s/2,z:o+i/2},h={x:e-a/2,y:r+s/2,z:o-i/2},l={x:e-a/2,y:r-s/2,z:o-i/2},m={x:e-a/2,y:r-s/2,z:o+i/2};return[n,h,l,m]}getPolygonTopPoints(t){const{center:{x:e,y:r,z:o},height:s,width:a,depth:i}=t,n={x:e+a/2,y:r+s/2,z:o+i/2},h={x:e+a/2,y:r-s/2,z:o+i/2},l={x:e-a/2,y:r-s/2,z:o+i/2},m={x:e-a/2,y:r+s/2,z:o+i/2};return[n,h,l,m]}getModelTransformationMatrix(t){const{center:{x:e,y:r,z:o},rotation:s}=t,a=new c.Matrix4().makeTranslation(-e,-r,-o),i=new c.Matrix4().makeTranslation(e,r,o),n=new c.Matrix4().makeRotationZ(s);return new c.Matrix4().multiply(i).multiply(n).multiply(a)}getBoxSidePolygon2DCoordinate(t){return this.getBoxPolygon2DCoordinate(t,g.Left)}getBoxBackPolygon2DCoordinate(t){return this.getBoxPolygon2DCoordinate(t,g.Back)}boxParams2ViewPolygon(t,e){switch(e){case g.Left:return this.getPolygonSidePoints(t);case g.Back:return this.getPolygonBackPoints(t);default:return this.getPolygonTopPoints(t)}}getBoxPolygon2DCoordinate(t,e){const r=this.boxParams2ViewPolygon(t,e),{width:o,height:s}=t,a=new c.Matrix4().premultiply(this.camera.matrixWorldInverse).premultiply(this.camera.projectionMatrix),i=new c.Matrix4().premultiply(this.getModelTransformationMatrix(t)).premultiply(a).premultiply(this.basicCoordinate2CanvasMatrix4);this.sideMatrix=i;const n=r.map(m=>new c.Vector3(m.x,m.y,m.z)).map(m=>m.applyMatrix4(this.sideMatrix)),h=this.containerWidth/o,l=this.containerHeight/s;return{polygon2d:n,zoom:Math.min(h,l)/2}}getBoxTopPolygon2DCoordinate(t){const{width:e,height:r}=t,s=this.getPolygonTopPoints(t).map(n=>new c.Vector3(n.x,n.y,n.z)).map(n=>n.applyMatrix4(this.getModelTransformationMatrix(t))).map(n=>({x:n.y,y:n.x})).map(n=>({x:-(n.x-this.containerWidth/2),y:-(n.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,o){const s=new c.Matrix4().makeRotationZ(o.rotation),a=new c.Vector3(-t.x,0,0).applyMatrix4(s);let i=o;return i.center={x:i.center.x+a.x,y:i.center.y+a.y,z:i.center.z-t.z},i=b(C({},i),{width:i.width+e,height:i.height,depth:i.depth+r}),{newBoxParams:i}}getNewBoxByBackUpdate(t,e,r,o){const s=new c.Matrix4().makeRotationZ(o.rotation),a=new c.Vector3(0,-t.x,0).applyMatrix4(s);let i=o;return i.center={x:i.center.x+a.x,y:i.center.y+a.y,z:i.center.z-t.z},i=b(C({},i),{width:i.width,height:i.height+e,depth:i.depth+r}),{newBoxParams:i}}getNewBoxBySideUpdateByPoints(t,e,r,o){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(p=>new c.Vector3(p.x,p.y,p.z)).map(p=>p.applyMatrix4(a)),[n,h,l,m]=i,d=Math.max(Math.abs(n.x-l.x),Math.abs(n.x-h.x)),y=h.add(m).applyMatrix3(new c.Matrix3().set(1/2,0,0,0,1/2,0,0,0,1/2)).clone().applyMatrix3(new c.Matrix3().set(-1,0,0,0,-1,0,0,0,-1)).add(new c.Vector3(o.center.x,o.center.y,o.center.z));return{newBoxParams:b(C({},o),{center:{x:o.center.x-y.x,y:o.center.y-y.y,z:o.center.z-r},width:d,height:o.height,depth:o.depth+e,rotation:o.rotation})}}filterZAxisPoints(t){const e=t||this.scene.children.find(r=>r.uuid===this.pointsUuid);if(e){const{attributes:r}=e.geometry,{position:o}=r,s=[],{count:a}=o;for(let i=0;i<a;i++){const n=o.getZ(i);s.push(n>this.zAxisLimit?0:1)}e.geometry.setAttribute("visibility",new c.Float32BufferAttribute(s,1)),e.geometry.attributes.visibility.needsUpdate=!0}}render(){this.renderer.render(this.scene,this.camera)}}export{Z as PointCloud};
11
+ #include <clipping_planes_fragment>`)},this.loadPCDFile=(i,o)=>v(this,null,function*(){this.clearPointCloud();const h=yield this.cacheInstance.loadPCDFile(i);h.name=this.pointCloudObjectName,this.renderPointCloud(h,o)}),this.loadPCDFileByBox=(i,o,h)=>v(this,null,function*(){const l=d=>v(this,null,function*(){const{width:f=0,height:y=0,depth:x=0}=h!=null?h:{},p=yield this.filterPointsByBox(b(C({},o),{width:o.width+f,height:o.height+y,depth:o.depth+x}),d);if(!p){console.error("filter Error");return}this.clearPointCloud();const M=new c.Points(p.geometry,d.material);M.name=this.pointCloudObjectName,this.scene.add(M),this.render()}),m=yield this.cacheInstance.loadPCDFile(i);l(m)}),this.generateRange=i=>{const o=this.createRange(i);this.scene.add(o)},this.generateBoxArrow=({width:i})=>{const o=new c.Vector3(1,0,0),h=new c.Vector3(i/2,0,0),l=2,m=16776960,d=new c.ArrowHelper(o,h,l,m);return d.visible=this.showDirection,d},this.generateBoxTrackID=i=>{if(!i.trackID)return;const o=new c.Texture(this.getTextCanvas(i.trackID.toString()));o.needsUpdate=!0;const h=new c.SpriteMaterial({map:o,depthWrite:!1}),l=new c.Sprite(h);return l.scale.set(5,5,5),l.position.set(-i.width/2,0,i.depth/2+.5),l},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 c.WebGLRenderer({antialias:!0}),this.backgroundColor=s,this.config=a,r&&n?(this.isOrthographicCamera=!0,this.camera=new c.OrthographicCamera(n.left,n.right,n.top,n.bottom,n.near,n.far)):this.camera=new c.PerspectiveCamera(30,this.containerWidth/this.containerHeight,1,1e3),this.initCamera(),this.scene=new c.Scene,this.controls=new I(this.camera,this.renderer.domElement),this.pcdLoader=new S,this.axesHelper=new c.AxesHelper(1e3),this.scene.add(this.camera),e||t.appendChild(this.renderer.domElement),this.init(),this.cacheInstance=N.getInstance()}get DEFAULT_INIT_CAMERA_POSITION(){return new c.Vector3(-1,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 c.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 c.Color(this.backgroundColor),this.initControls(),this.initRenderer()}removeObjectByName(t){const e=this.scene.getObjectByName(t);e&&e.removeFromParent()}generateBox(t,e=16777215){var r,n,s,a,i;let o=e;((r=this.config)==null?void 0:r.attributeList)&&((s=(n=this.config)==null?void 0:n.attributeList)==null?void 0:s.length)>0&&t.attribute&&(o=(i=(a=_.getColorFromConfig({attribute:t.attribute},b(C({},this.config),{attributeConfigurable:!0}),{}))==null?void 0:a.hex)!=null?i:e),this.AddBoxToSense(t,o),this.render()}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,l=100,m=-100,d=500/l;return{left:a,right:i,top:o,bottom:h,near:l,far:m,zoom:d}}updateCameraByBox(t,e){const{center:r,width:n,height:s,depth:a,rotation:i}=t,o=this.getCameraVector(r,i,{width:n,height:s,depth:a},e);return this.updateCamera(o,r),o}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 c.Vector3(e.x,e.y,e.z),this.controls.update()}resetCamera(){this.updateCamera({x:-1,y:0,z:500},{x:0,y:0,z:0})}createThreeMatrix4(t){return new c.Matrix4().set(...t)}filterPointsByBox(t,e){if(!e){const r=this.scene.getObjectByName(this.pointCloudObjectName);if(!r)return console.error("There is no corresponding point cloud object"),Promise.resolve(void 0);e=r}if(window.Worker){const{zMin:r,zMax:n,polygonPointList:s}=D(t),a=e.geometry.attributes.position.array,i=e.geometry.attributes.color.array,o={boxParams:t,zMin:r,zMax:n,polygonPointList:s,color:i,position:a};return new Promise(h=>{const l=new k;l.postMessage(o),l.onmessage=m=>{const{color:d,position:f,num:y}=m.data,x=new c.BufferGeometry;x.setAttribute("position",new c.Float32BufferAttribute(f,3)),x.setAttribute("color",new c.Float32BufferAttribute(d,3)),x.computeBoundingSphere(),l.terminate(),h({geometry:x,num:y})}})}return Promise.resolve(void 0)}getCameraVector(t,e,r,n=g.Front,s=H){let a=w.frontViewMatrix4(s);switch(n){case g.Front:break;case g.Back:a=w.backViewMatrix4(s);break;case g.Left:a=w.leftViewMatrix4(s);break;case g.Right:a=w.rightViewMatrix4(s);break;case g.Top:a=w.topViewMatrix4(s);break;case g.LFT:a=w.leftFrontTopViewMatrix4(s,r);break;case g.RBT:a=w.rightBackTopViewMatrix4(s,r);break}const i=this.createThreeMatrix4(a),o=new c.Matrix4().makeTranslation(-t.x,-t.y,-t.z),h=new c.Matrix4().makeTranslation(t.x,t.y,t.z),l=new c.Matrix4().makeRotationZ(e);return new c.Vector3(t.x,t.y,t.z).clone().applyMatrix4(i).applyMatrix4(o).applyMatrix4(l).applyMatrix4(h)}createRange(t){this.removeObjectByName(this.rangeObjectName);const r=new c.EllipseCurve(0,0,t,t,0,2*Math.PI,!1,0).getPoints(50),n=new c.BufferGeometry().setFromPoints(r),s=new c.LineBasicMaterial({color:16711680}),a=new c.Line(n,s);return a.name=this.rangeObjectName,a}renderPointCloud(t,e){t.material.size=1,t.name=this.pointCloudObjectName;const r=new c.PointsMaterial({vertexColors:!0});r.onBeforeCompile=this.overridePointShader,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){}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}getSensesPointZAxisInPolygon(t,e){const r=this.scene.children.find(o=>o.uuid===this.pointsUuid);let n=0,s=0,a=0,i=0;if(r&&(r==null?void 0:r.geometry)){const o=r==null?void 0:r.geometry.attributes.position.array;for(let h=0;h<o.length;h+=3){const l=o[h],m=o[h+1],d=o[h+2];A({x:l,y:m},t)&&d&&(s=Math.max(d,s),n=Math.min(d,n),i++,e&&d>=e[0]&&d<=e[1]&&a++)}}return{maxZ:s,minZ:n,count:a,zCount:i}}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 c.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 c.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},l={x:e-a/2,y:r+s/2,z:n+i/2},m={x:e-a/2,y:r+s/2,z:n-i/2};return[o,h,l,m]}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},l={x:e-a/2,y:r-s/2,z:n-i/2},m={x:e-a/2,y:r-s/2,z:n+i/2};return[o,h,l,m]}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},l={x:e-a/2,y:r-s/2,z:n+i/2},m={x:e-a/2,y:r+s/2,z:n+i/2};return[o,h,l,m]}getModelTransformationMatrix(t){const{center:{x:e,y:r,z:n},rotation:s}=t,a=new c.Matrix4().makeTranslation(-e,-r,-n),i=new c.Matrix4().makeTranslation(e,r,n),o=new c.Matrix4().makeRotationZ(s);return new c.Matrix4().multiply(i).multiply(o).multiply(a)}getBoxSidePolygon2DCoordinate(t){return this.getBoxPolygon2DCoordinate(t,g.Left)}getBoxBackPolygon2DCoordinate(t){return this.getBoxPolygon2DCoordinate(t,g.Back)}boxParams2ViewPolygon(t,e){switch(e){case g.Left:return this.getPolygonSidePoints(t);case g.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 c.Matrix4().premultiply(this.camera.matrixWorldInverse).premultiply(this.camera.projectionMatrix),i=new c.Matrix4().premultiply(this.getModelTransformationMatrix(t)).premultiply(a).premultiply(this.basicCoordinate2CanvasMatrix4);this.sideMatrix=i;const o=r.map(m=>new c.Vector3(m.x,m.y,m.z)).map(m=>m.applyMatrix4(this.sideMatrix)),h=this.containerWidth/n,l=this.containerHeight/s;return{polygon2d:o,zoom:Math.min(h,l)/2}}getBoxTopPolygon2DCoordinate(t){const{width:e,height:r}=t,s=this.getPolygonTopPoints(t).map(o=>new c.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 c.Matrix4().makeRotationZ(n.rotation),a=new c.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=b(C({},i),{width:i.width+e,height:i.height,depth:i.depth+r}),{newBoxParams:i}}getNewBoxByBackUpdate(t,e,r,n){const s=new c.Matrix4().makeRotationZ(n.rotation),a=new c.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=b(C({},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(p=>new c.Vector3(p.x,p.y,p.z)).map(p=>p.applyMatrix4(a)),[o,h,l,m]=i,d=Math.max(Math.abs(o.x-l.x),Math.abs(o.x-h.x)),y=h.add(m).applyMatrix3(new c.Matrix3().set(1/2,0,0,0,1/2,0,0,0,1/2)).clone().applyMatrix3(new c.Matrix3().set(-1,0,0,0,-1,0,0,0,-1)).add(new c.Vector3(n.center.x,n.center.y,n.center.z));return{newBoxParams:b(C({},n),{center:{x:n.center.x-y.x,y:n.center.y-y.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 c.Float32BufferAttribute(s,1)),e.geometry.attributes.visibility.needsUpdate=!0}}render(){this.renderer.render(this.scene,this.camera)}}export{Z as PointCloud};
@@ -1 +1 @@
1
- import{getConfig as f,styleDefaultConfig as y}from"../constant/defaultConfig.js";import{getCurrentOperation as L}from"../utils/tool/EnhanceCommonToolUtils.js";import{BasicToolOperation as w}from"./toolOperation/basicToolOperation.js";const v=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()):""},m=(e,t,i)=>{const o=e[t];return e[t]=e[i],e[i]=o,e},u=class{static isSingleTool(e){return!this.isHybridTool(e)}static isHybridTool(e){return Array.isArray(e)}};let g=u;g.getTopToolName=e=>u.isHybridTool(e)?e[e.length-1]:e;class T{constructor(t){this.toolOperationList=[],this.toolOperationDom=[];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(f(g.getTopToolName(t.toolName))),this.style=(o=t.style)!=null?o:y}setImgNode(t,i){this.toolOperationList.forEach(o=>{o.setImgNode(t,i)})}setSize(t){this.toolOperationList.forEach(i=>{i.setSize(t)})}syncPosition(t,i,o,n){this.toolOperationList.forEach(r=>{n!==r&&(r.setCurrentPos(t),r.setZoom(i),r.setImgInfo(o),r.renderBasicCanvas(),r.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 n=this.toolOperationList.length+1;return o.style.zIndex=`${n}`,o}getEmptyImage(t,i){const o=v({width:t,height:i}),n=new Image;return n.src=o,n}createOperation(t,i,o){var n;const{width:r,height:p}=this.defaultSize,l=this.createDom(),O=this.getEmptyImage(r,p),c={container:l,size:this.size,config:(n=this==null?void 0:this.config)!=null?n:"{}",drawOutSideTarget:!1,style:this.style,imgNode:i||O,hiddenImg:!!t};o&&Object.assign(c,o);let s;if(!t)s=new w(c),l.style.zIndex="0",s.init();else{const a=L(t);if(!a)return;s=new a(c)}return s==null||s.init(),s.canvas.id=t!=null?t:"basicCanvas",s.on("dragMove",({currentPos:a,zoom:h,imgInfo:d})=>{this.syncPosition(a,h,d,s)}),s.on("renderZoom",(a,h,d)=>{a&&h&&this.syncPosition(h,a,d,s)}),t?(this.container.appendChild(l),this.toolOperationList.push(s),this.toolOperationDom.push(l),s):(this.container.insertBefore(l,this.container.childNodes[0]),this.toolOperationList.unshift(s),this.toolOperationDom.unshift(l),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,i=t-1,o=t-2,n=this.toolOperationDom[i],r=this.toolOperationDom[o];if(!(!r||!n))return n.style.zIndex=`${i-1}`,r.style.zIndex=`${i}`,this.toolOperationList[i].clearActiveStatus(),this.toolOperationList[i].clearCursorLine(),this.toolOperationList[i].render(),this.toolOperationList=m(this.toolOperationList,i,o),this.toolOperationDom=m(this.toolOperationDom,i,o),this.toolOperationList[i]}getFirstToolOperation(){return this.toolOperationList.length>1?this.toolOperationList[1]:this.toolOperationList[0]}destroyAllLayer(){this.toolOperationList.forEach(t=>{t.destroyCanvas(),this.init()})}init(){this.toolOperationList=[],this.toolOperationDom=[]}}export{g as HybridToolUtils,T as ToolScheduler};
1
+ import{getConfig as f,styleDefaultConfig as y}from"../constant/defaultConfig.js";import{getCurrentOperation as L}from"../utils/tool/EnhanceCommonToolUtils.js";import{BasicToolOperation as w}from"./toolOperation/basicToolOperation.js";const v=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()):""},m=(e,t,i)=>{const o=e[t];return e[t]=e[i],e[i]=o,e},u=class{static isSingleTool(e){return!this.isHybridTool(e)}static isHybridTool(e){return Array.isArray(e)}};let g=u;g.getTopToolName=e=>u.isHybridTool(e)?e[e.length-1]:e;class T{constructor(t){this.toolOperationList=[],this.toolOperationDom=[];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(f(g.getTopToolName(t.toolName))),this.style=(o=t.style)!=null?o:y}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,n){this.toolOperationList.forEach(r=>{n!==r&&(r.setCurrentPos(t),r.setZoom(i),r.setImgInfo(o),r.renderBasicCanvas(),r.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 n=this.toolOperationList.length+1;return o.style.zIndex=`${n}`,o}getEmptyImage(t,i){const o=v({width:t,height:i}),n=new Image;return n.src=o,n}createOperation(t,i,o){var n;const{width:r,height:p}=this.defaultSize,l=this.createDom(),O=this.getEmptyImage(r,p),c={container:l,size:this.size,config:(n=this==null?void 0:this.config)!=null?n:"{}",drawOutSideTarget:!1,style:this.style,imgNode:i||O,hiddenImg:!!t};o&&Object.assign(c,o);let s;if(!t)s=new w(c),l.style.zIndex="0",s.init();else{const a=L(t);if(!a)return;s=new a(c)}return s==null||s.init(),s.canvas.id=t!=null?t:"basicCanvas",s.on("dragMove",({currentPos:a,zoom:h,imgInfo:d})=>{this.syncPosition(a,h,d,s)}),s.on("renderZoom",(a,h,d)=>{a&&h&&this.syncPosition(h,a,d,s)}),t?(this.container.appendChild(l),this.toolOperationList.push(s),this.toolOperationDom.push(l),s):(this.container.insertBefore(l,this.container.childNodes[0]),this.toolOperationList.unshift(s),this.toolOperationDom.unshift(l),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,i=t-1,o=t-2,n=this.toolOperationDom[i],r=this.toolOperationDom[o];if(!(!r||!n))return n.style.zIndex=`${i-1}`,r.style.zIndex=`${i}`,this.toolOperationList[i].clearActiveStatus(),this.toolOperationList[i].clearCursorLine(),this.toolOperationList[i].render(),this.toolOperationList=m(this.toolOperationList,i,o),this.toolOperationDom=m(this.toolOperationDom,i,o),this.toolOperationList[i]}getFirstToolOperation(){return this.toolOperationList.length>1?this.toolOperationList[1]:this.toolOperationList[0]}destroyAllLayer(){this.toolOperationList.forEach(t=>{t.destroyCanvas(),this.init()})}init(){this.toolOperationList=[],this.toolOperationDom=[]}}export{g as HybridToolUtils,T as ToolScheduler};
@@ -1 +1 @@
1
- import{toolStyleConverter as D}from"@labelbee/lb-utils";import{ESortDirection as C}from"../../constant/annotation.js";import{EPolygonPattern as p}from"../../constant/tool.js";import u from"../../utils/tool/AxisUtils.js";import P from"../../utils/tool/CommonToolUtils.js";import g from"../../utils/tool/DrawUtils.js";import y from"../../utils/tool/PolygonUtils.js";import{polygonConfig as _}from"../../constant/defaultConfig.js";import I from"./polygonOperation.js";var L=Object.defineProperty,b=Object.defineProperties,S=Object.getOwnPropertyDescriptors,v=Object.getOwnPropertySymbols,w=Object.prototype.hasOwnProperty,x=Object.prototype.propertyIsEnumerable,m=(r,t,e)=>t in r?L(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,c=(r,t)=>{for(var e in t||(t={}))w.call(t,e)&&m(r,e,t[e]);if(v)for(var e of v(t))x.call(t,e)&&m(r,e,t[e]);return r},h=(r,t)=>b(r,S(t));class A extends I{constructor(t){super(t);this.selectedIDs=[],this.rightMouseUp=a=>{var s;if(this.drawingPointList.length>0){this.addDrawingPointToPolygonList();return}a.ctrlKey&&this.hoverID?this.emit("addSelectedIDs",this.hoverID):this.emit("setSelectedIDs",this.hoverID);const d=(s=this.hoverPolygon)==null?void 0:s.attribute;d&&d!==this.defaultAttribute&&this.emit("syncAttribute",d)},this.onKeyDown=()=>{},this.onKeyUp=()=>{},this.renderSingleSelectedPolygon=a=>{var s;if(this.selectedPolygons){const d=this.getPointCloudLineColor(a.attribute),f=u.changePointListByZoom(a.pointList,this.zoom,this.currentPos);g.drawSelectedPolygonWithFillAndLine(this.canvas,f,{fillColor:"transparent",strokeColor:d,pointColor:"white",thickness:2,lineCap:"round",isClose:!0,lineType:(s=this.config)==null?void 0:s.lineType}),a.isRect===!0&&this.showDirectionLine===!0&&this.renderRectPolygonDirection(f)}};var e,o,i,n,l;this.showDirectionLine=(e=t.showDirectionLine)!=null?e:!0,this.forbidAddNew=(o=t.forbidAddNew)!=null?o:!1,this.pointCloudConfig=(i=P.jsonParser(t.config))!=null?i:{},this.config=h(c({},_),{textConfigurable:!1,attributeConfigurable:!0,attributeList:(l=(n=this.pointCloudConfig)==null?void 0:n.attributeList)!=null?l:[]})}get getSelectedIDs(){return this.selectedIDs}setSelectedIDs(t){this.selectedIDs=t,this.setSelectedID(this.selectedIDs.length===1?this.selectedIDs[0]:""),this.render()}deleteSelectedID(){super.deleteSelectedID(),this.selectedIDs=[],this.emit("deleteSelectedIDs")}get selectedPolygons(){return y.getPolygonByIDs(this.polygonList,this.selectedIDs)}getLineColor(){return"rgba(0, 255, 255, 0.5)"}getPointCloudLineColor(t=""){return D.getColorFromConfig({attribute:t},h(c({},this.pointCloudConfig),{attributeConfigurable:!0}),{}).stroke}renderStaticPolygon(){var t;this.isHidden===!1&&((t=this.polygonList)==null||t.forEach(e=>{var o,i,n;if([...this.selectedIDs,this.editPolygonID].includes(e.id))return;const{attribute:l}=e,a=this.getPointCloudLineColor(l),s=u.changePointListByZoom(e.pointList||[],this.zoom,this.currentPos);g.drawPolygonWithFillAndLine(this.canvas,s,{fillColor:"transparent",strokeColor:a,pointColor:"white",thickness:(i=(o=this.style)==null?void 0:o.width)!=null?i:2,lineCap:"round",isClose:!0,lineType:(n=this.config)==null?void 0:n.lineType}),e.isRect===!0&&this.showDirectionLine===!0&&this.renderRectPolygonDirection(s)}))}renderSelectedPolygon(){var t;(t=this.selectedPolygons)==null||t.forEach(e=>{this.renderSingleSelectedPolygon(e)})}renderRectPolygonDirection(t){t.length<2||g.drawLine(this.canvas,t[0],t[1],{color:"white",thickness:3,lineDash:[6]})}get currentPolygonListByPattern(){return this.polygonList.filter(t=>this.pattern===p.Rect?t.isRect===!0:this.pattern===p.Normal?t.isRect!==!0:!0)}getHoverID(t){var e;const o=this.getCoordinateUnderZoom(t),n=this.currentPolygonListByPattern.map(l=>h(c({},l),{pointList:u.changePointListByZoom(l.pointList,this.zoom)}));return y.getHoverPolygonID(o,n,10,(e=this.config)==null?void 0:e.lineType)}switchToNextPolygon(t=C.ascend){if(this.drawingPointList.length>0)return;const e=this.currentPolygonListByPattern.map(i=>{var n,l,a,s;return h(c({},i),{x:(l=(n=i.pointList[0])==null?void 0:n.x)!=null?l:0,y:(s=(a=i.pointList[0])==null?void 0:a.y)!=null?s:0})}),o=P.getNextSelectedRectID(e,t,this.selectedID);if(o)return this.setSelectedIDs([o.id]),this.render(),[o.id]}setSelectedIdAfterAddingDrawing(t){this.drawingPointList.length!==0&&this.setSelectedID(t)}setSelectedID(t){var e,o;const i=this.selectedID;t!==i&&i&&((e=this._textAttributInstance)==null||e.changeSelected()),t||(o=this._textAttributInstance)==null||o.clearTextAttribute(),this.selectedID=t,this.selectedIDs=t?[t]:[],this.render()}addPointInDrawing(t){this.forbidAddNew||super.addPointInDrawing(t)}setCanvasSize(t){var e,o;const i=this.pixelRatio;this.size=t,this.setImgInfo(t),this.updateCanvasBasicStyle(this.basicCanvas,t,0),this.updateCanvasBasicStyle(this.canvas,t,10),(e=this.ctx)==null||e.scale(i,i),(o=this.basicCtx)==null||o.scale(i,i),this.initImgPos(),this.renderBasicCanvas(),this.render()}setPolygonValidAndRender(t,e=!1){if(e){super.setPolygonValidAndRender(t);return}this.emit("validUpdate",t)}}export{A as default};
1
+ import{toolStyleConverter as C}from"@labelbee/lb-utils";import{ESortDirection as _}from"../../constant/annotation.js";import{EPolygonPattern as y}from"../../constant/tool.js";import f from"../../utils/tool/AxisUtils.js";import P from"../../utils/tool/CommonToolUtils.js";import p from"../../utils/tool/DrawUtils.js";import v from"../../utils/tool/PolygonUtils.js";import{polygonConfig as L}from"../../constant/defaultConfig.js";import I from"./polygonOperation.js";var b=Object.defineProperty,w=Object.defineProperties,S=Object.getOwnPropertyDescriptors,D=Object.getOwnPropertySymbols,A=Object.prototype.hasOwnProperty,x=Object.prototype.propertyIsEnumerable,m=(n,t,e)=>t in n?b(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,h=(n,t)=>{for(var e in t||(t={}))A.call(t,e)&&m(n,e,t[e]);if(D)for(var e of D(t))x.call(t,e)&&m(n,e,t[e]);return n},u=(n,t)=>w(n,S(t));class O extends I{constructor(t){super(t);this.selectedIDs=[],this.rightMouseUp=s=>{var d;if(this.drawingPointList.length>0){this.addDrawingPointToPolygonList();return}s.ctrlKey&&this.hoverID?this.emit("addSelectedIDs",this.hoverID):this.emit("setSelectedIDs",this.hoverID);const c=(d=this.polygonList.find(g=>g.id===this.hoverID))==null?void 0:d.attribute;c&&c!==this.defaultAttribute&&this.emit("syncAttribute",c)},this.onKeyDown=()=>{},this.onKeyUp=()=>{},this.renderSingleSelectedPolygon=s=>{var d;if(this.selectedPolygons){const c=this.getPointCloudLineColor(s.attribute),g=f.changePointListByZoom(s.pointList,this.zoom,this.currentPos);p.drawSelectedPolygonWithFillAndLine(this.canvas,g,{fillColor:"transparent",strokeColor:c,pointColor:"white",thickness:2,lineCap:"round",isClose:!0,lineType:(d=this.config)==null?void 0:d.lineType}),s.isRect===!0&&this.showDirectionLine===!0&&this.renderRectPolygonDirection(g)}};var e,i,o,r,l,a;this.showDirectionLine=(e=t.showDirectionLine)!=null?e:!0,this.forbidAddNew=(i=t.forbidAddNew)!=null?i:!1,this.pointCloudConfig=(o=P.jsonParser(t.config))!=null?o:{},this.checkMode=(r=t.checkMode)!=null?r:!1,this.forbidAddNew===!1&&t.checkMode===!0&&(this.forbidAddNew=!0),this.config=u(h({},L),{textConfigurable:!1,attributeConfigurable:!0,attributeList:(a=(l=this.pointCloudConfig)==null?void 0:l.attributeList)!=null?a:[]})}get getSelectedIDs(){return this.selectedIDs}setConfig(t){var e;const i=P.jsonParser(t);this.pointCloudConfig=i,this.config=u(h({},this.config),{attributeList:(e=i==null?void 0:i.attributeList)!=null?e:[]})}dragMouseDown(t){this.checkMode||super.dragMouseDown(t)}deletePolygon(t){this.checkMode||super.deletePolygon(t)}deletePolygonPoint(t){this.checkMode||super.deletePolygonPoint(t)}setSelectedIDs(t){this.selectedIDs=t,this.setSelectedID(this.selectedIDs.length===1?this.selectedIDs[0]:""),this.render()}deleteSelectedID(){super.deleteSelectedID(),this.selectedIDs=[],this.emit("deleteSelectedIDs")}get selectedPolygons(){return v.getPolygonByIDs(this.polygonList,this.selectedIDs)}getLineColor(){return"rgba(0, 255, 255, 0.5)"}getPointCloudLineColor(t=""){return C.getColorFromConfig({attribute:t},u(h({},this.pointCloudConfig),{attributeConfigurable:!0}),{}).stroke}renderStaticPolygon(){var t;this.isHidden===!1&&((t=this.polygonList)==null||t.forEach(e=>{var i,o,r;if([...this.selectedIDs,this.editPolygonID].includes(e.id))return;const{attribute:l}=e,a=this.getPointCloudLineColor(l),s=f.changePointListByZoom(e.pointList||[],this.zoom,this.currentPos);p.drawPolygonWithFillAndLine(this.canvas,s,{fillColor:"transparent",strokeColor:a,pointColor:"white",thickness:(o=(i=this.style)==null?void 0:i.width)!=null?o:2,lineCap:"round",isClose:!0,lineType:(r=this.config)==null?void 0:r.lineType}),e.isRect===!0&&this.showDirectionLine===!0&&this.renderRectPolygonDirection(s)}))}renderSelectedPolygon(){var t;(t=this.selectedPolygons)==null||t.forEach(e=>{this.renderSingleSelectedPolygon(e)})}renderRectPolygonDirection(t){t.length<2||p.drawLine(this.canvas,t[0],t[1],{color:"white",thickness:3,lineDash:[6]})}get currentPolygonListByPattern(){return this.polygonList.filter(t=>this.pattern===y.Rect?t.isRect===!0:this.pattern===y.Normal?t.isRect!==!0:!0)}getHoverID(t){var e;const i=this.getCoordinateUnderZoom(t),r=this.currentPolygonListByPattern.map(l=>u(h({},l),{pointList:f.changePointListByZoom(l.pointList,this.zoom)}));return v.getHoverPolygonID(i,r,10,(e=this.config)==null?void 0:e.lineType)}switchToNextPolygon(t=_.ascend){if(this.drawingPointList.length>0)return;const e=this.currentPolygonListByPattern.map(o=>{var r,l,a,s;return u(h({},o),{x:(l=(r=o.pointList[0])==null?void 0:r.x)!=null?l:0,y:(s=(a=o.pointList[0])==null?void 0:a.y)!=null?s:0})}),i=P.getNextSelectedRectID(e,t,this.selectedID);if(i)return this.setSelectedIDs([i.id]),this.render(),[i.id]}setSelectedIdAfterAddingDrawing(t){this.drawingPointList.length!==0&&this.setSelectedID(t)}setSelectedID(t){var e,i;const o=this.selectedID;t!==o&&o&&((e=this._textAttributInstance)==null||e.changeSelected()),t||(i=this._textAttributInstance)==null||i.clearTextAttribute(),this.selectedID=t,this.selectedIDs=t?[t]:[],this.render()}addPointInDrawing(t){this.forbidAddNew||super.addPointInDrawing(t)}setCanvasSize(t){var e,i;const o=this.pixelRatio;this.size=t,this.setImgInfo(t),this.updateCanvasBasicStyle(this.basicCanvas,t,0),this.updateCanvasBasicStyle(this.canvas,t,10),(e=this.ctx)==null||e.scale(o,o),(i=this.basicCtx)==null||i.scale(o,o),this.initImgPos(),this.renderBasicCanvas(),this.render()}setPolygonValidAndRender(t,e=!1){if(e){super.setPolygonValidAndRender(t);return}this.emit("validUpdate",t)}}export{O as default};
@@ -1 +1 @@
1
- import{i18n as _}from"@labelbee/lb-utils";import D from"../../utils/MathUtils.js";import z from"../../utils/tool/RectUtils.js";import{ERotateDirection as N,EDragStatus as x,ESortDirection as E,EDragTarget as b,TEXT_ATTRIBUTE_OFFSET as U,DEFAULT_TEXT_OFFSET as k}from"../../constant/annotation.js";import p from"../../constant/keyCode.js";import{EPolygonPattern as w,edgeAdsorptionScope as R,ELineTypes as H,EToolName as O}from"../../constant/tool.js";import C from"../../locales/index.js";import{EMessage as S}from"../../locales/constants.js";import W from"../../utils/ActionsHistory.js";import v from"../../utils/tool/AttributeUtils.js";import c from"../../utils/tool/AxisUtils.js";import B from"../../utils/tool/CanvasUtils.js";import u from"../../utils/tool/CommonToolUtils.js";import P from"../../utils/tool/DrawUtils.js";import y from"../../utils/tool/PolygonUtils.js";import A from"../../utils/tool/StyleUtils.js";import M from"../../utils/uuid.js";import{BasicToolOperation as K}from"./basicToolOperation.js";import $ from"./textAttributeClass.js";var V=Object.defineProperty,X=Object.defineProperties,Y=Object.getOwnPropertyDescriptors,Z=Object.getOwnPropertySymbols,q=Object.prototype.hasOwnProperty,G=Object.prototype.propertyIsEnumerable,F=(L,t,e)=>t in L?V(L,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):L[t]=e,f=(L,t)=>{for(var e in t||(t={}))q.call(t,e)&&F(L,e,t[e]);if(Z)for(var e of Z(t))G.call(t,e)&&F(L,e,t[e]);return L},m=(L,t)=>X(L,Y(t));const j=164;class J extends K{constructor(t){super(t);this.isAllowDouble=e=>{const{selectedID:i}=this,s=this.getHoverID(e);return!!(i&&i===s)},this.textChange=e=>{this.config.textConfigurable===!1||!this.selectedID||(this.setPolygonList(v.textChange(e,this.selectedID,this.polygonList)),this.emit("selectedChange"),this.render())},this.config=u.jsonParser(t.config),this.drawingPointList=[],this.polygonList=[],this.hoverPointIndex=-1,this.hoverEdgeIndex=-1,this.drawingHistory=new W,this.isCtrl=!1,this.isAlt=!1,this.isCombined=!1,this.pattern=w.Normal,this.getCurrentSelectedData=this.getCurrentSelectedData.bind(this),this.updateSelectedTextAttribute=this.updateSelectedTextAttribute.bind(this)}eventBinding(){super.eventBinding(),this.container.removeEventListener("mouseup",this.onMouseUp),this.container.addEventListener("mouseup",this.dragMouseUp),this.dblClickListener.addEvent(this.onMouseUp,this.onLeftDblClick,this.onRightDblClick,this.isAllowDouble)}eventUnbinding(){super.eventUnbinding(),this.container.removeEventListener("mouseup",this.dragMouseUp)}destroy(){super.destroy(),this._textAttributInstance&&this._textAttributInstance.clearTextAttribute()}get selectedPolygon(){return y.getPolygonByID(this.polygonList,this.selectedID)}get hoverPolygon(){return this.polygonList.find(t=>t.id===this.hoverID&&t.id!==this.selectedID)}get polygonListUnderZoom(){return this.polygonList.map(t=>m(f({},t),{pointList:c.changePointListByZoom(t.pointList,this.zoom)}))}get selectedText(){var t;return(t=this.selectedPolygon)==null?void 0:t.textAttribute}get dataList(){return this.polygonList}setPattern(t,e=!1){var i;((i=this.drawingPointList)==null?void 0:i.length)>0&&e===!0||(this.pattern=t)}get currentShowList(){let t=[];const[e,i]=u.getRenderResultList(this.polygonList,u.getSourceID(this.basicResult),this.attributeLockList,this.selectedID);return t=e,this.isHidden&&(t=[]),i&&t.push(i),t}get currentPageResult(){const[t]=u.getRenderResultList(this.polygonList,u.getSourceID(this.basicResult),[]);return t}setResultAndSelectedID(t,e){this.setPolygonList(t),e&&(this.selectedID=e),this.render()}setResult(t){this.clearActiveStatus(),this.setPolygonList(t),this.render()}setPolygonDataByID(t,e){return this.polygonList.map(i=>i.id===e?f(f({},i),t):i)}rotatePolygon(t=1,e=N.Clockwise,i=this.selectedID){if(!i)return;const s=y.getPolygonByID(this.polygonList,i);if(!s)return;const o=y.updatePolygonByRotate(e,t,s==null?void 0:s.pointList);this.setPolygonList(this.setPolygonDataByID({pointList:o},i)),this.render()}addPointInDrawing(t){if(!this.imgInfo||this.forbidAddNewPolygonFuc&&this.forbidAddNewPolygonFuc(t))return;const{upperLimitPointNum:e,edgeAdsorption:i}=this.config;if(e&&this.drawingPointList.length>=e){this.emit("messageInfo",`${C.getMessagesByLocale(S.UpperLimitErrorNotice,this.lang)}${e}`);return}this.deleteSelectedID();const s=this.getCoordinateUnderZoom(t),o=c.changeDrawOutsideTarget(s,{x:0,y:0},this.imgInfo,this.config.drawOutsideTarget,this.basicResult,this.zoom);if(c.returnClosePointIndex(o,c.changePointListByZoom(this.drawingPointList,this.zoom))===0){this.addDrawingPointToPolygonList();return}const{dropFoot:n}=y.getClosestPoint(o,this.polygonListUnderZoom,this.config.lineType,R),l=c.changePointByZoom(n&&t.altKey===!1&&i?n:o,1/this.zoom);if(this.pattern===w.Rect&&this.drawingPointList.length===2){const h=D.getRectangleByRightAngle(l,this.drawingPointList);if(this.drawingPointList=h,this.config.drawOutsideTarget===!1&&this.imgInfo&&this.isPolygonOutSide(this.drawingPointList)){this.emit("messageInfo",`${C.getMessagesByLocale(S.ForbiddenCreationOutsideBoundary,this.lang)}`),this.drawingPointList=[];return}this.addDrawingPointToPolygonList(!0);return}this.drawingPointList.push(l),this.drawingPointList.length===1?this.drawingHistory.initRecord(this.drawingPointList):this.drawingHistory.pushHistory(this.drawingPointList)}clearResult(){this.setPolygonList([]),this.deleteSelectedID(),this.render()}clearPolygonDrag(){this.drawingPointList=[],this.dragInfo=void 0,this.dragInfo=void 0,this.dragStatus=x.Wait,this.hoverEdgeIndex=-1,this.hoverPointIndex=-1,this.hoverID=""}clearActiveStatus(){this.clearPolygonDrag(),this.deleteSelectedID()}clearDrawingStatus(){this.drawingPointList=[]}setPolygonList(t){const e=this.polygonList.length;this.polygonList=t,e!==t.length&&this.emit("updatePageNumber")}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")}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.selectedPolygon&&(this.selectedPolygon.attribute=t),this.history.pushHistory(this.polygonList),this.render()),this._textAttributInstance){if(this.attributeLockList.length>0&&!this.attributeLockList.includes(t)){this._textAttributInstance.clearTextAttribute();return}this._textAttributInstance.updateIcon(this.getTextIconSvg(t))}}}setStyle(t){var e;super.setStyle(t),this._textAttributInstance&&this.config.attributeConfigurable===!1&&((e=this._textAttributInstance)==null||e.updateIcon(this.getTextIconSvg()))}setPolygonValidAndRender(t){if(!t)return;const e=this.polygonList.map(i=>{var s;if(i.id===t){const o=(s=i==null?void 0:i.valid)!=null?s:!0;return m(f({},i),{valid:!o})}return i});this.setPolygonList(e),this.history.pushHistory(this.polygonList),this.render(),this.emit("updateResult")}addDrawingPointToPolygonList(t){let{lowerLimitPointNum:e=3}=this.config;e<3&&(e=3);let i;if(this.drawingPointList.length<e){this.drawingPointList=[],this.editPolygonID="";return}const s=u.getSourceID(this.basicResult),o=[...this.polygonList];if(this.editPolygonID){const r=o.find(n=>n.id===this.editPolygonID);if(!r)return;r.pointList=this.drawingPointList,this.editPolygonID=""}else{const r=M(8,62);let n={id:r,sourceID:s,valid:!this.isCtrl,textAttribute:"",pointList:this.drawingPointList,attribute:this.defaultAttribute,order:u.getMaxOrder(o.filter(l=>u.isSameSourceID(l.sourceID,s)))+1};if(this.config.textConfigurable){let l="";l=v.getTextAttribute(this.polygonList.filter(h=>u.isSameSourceID(h.sourceID,s)),this.config.textCheckType),n=m(f({},n),{textAttribute:l})}this.pattern===w.Rect&&t===!0&&(n=m(f({},n),{isRect:!0})),o.push(n),i=n,this.setSelectedIdAfterAddingDrawing(r)}this.setPolygonList(o),this.isCtrl=!1,this.drawingPointList=[],this.history.pushHistory(o),i&&this.emit("polygonCreated",i,this.zoom,this.currentPos)}setSelectedIdAfterAddingDrawing(t){this.drawingPointList.length!==0&&(this.config.textConfigurable?this.setSelectedID(t):this.deleteSelectedID())}getHoverID(t){var e;const i=this.getCoordinateUnderZoom(t),s=this.currentShowList.map(o=>m(f({},o),{pointList:c.changePointListByZoom(o.pointList,this.zoom)}));return y.getHoverPolygonID(i,s,10,(e=this.config)==null?void 0:e.lineType)}getHoverEdgeIndex(t){var e;if(!this.selectedID)return-1;const i=this.selectedPolygon;if(!i)return-1;const s=this.getCoordinateUnderZoom(t),o=c.changePointListByZoom(i.pointList,this.zoom);return y.getHoverEdgeIndex(s,o,(e=this.config)==null?void 0:e.lineType)}getHoverPointIndex(t){if(!this.selectedID)return-1;const e=this.selectedPolygon;if(!e)return-1;const i=this.getCoordinateUnderZoom(t),s=c.changePointListByZoom(e.pointList,this.zoom);return c.returnClosePointIndex(i,s)}deletePolygon(t){var e;if(!t)return;const i=this.polygonList.find(s=>s.id===t);this.emit("deletedObject",{deletedObject:i,id:t}),this.setPolygonList(this.polygonList.filter(s=>s.id!==t)),this.history.pushHistory(this.polygonList),(e=this._textAttributInstance)==null||e.clearTextAttribute(),this.emit("selectedChange"),this.render()}deletePolygonPoint(t){if(!this.selectedID)return;const{selectedPolygon:e}=this;if(!e)return;let{lowerLimitPointNum:i}=this.config;if(i<3&&(i=3),e.pointList.length<=i){this.emit("messageInfo",`${C.getMessagesByLocale(S.LowerLimitErrorNotice,this.lang)}${i}`);return}e==null||e.pointList.splice(t,1),this.history.pushHistory(this.polygonList),this.render()}spaceKeydown(){var t,e,i;if(this.selectedID){if(((t=this.selectedPolygon)==null?void 0:t.isRect)===!0){this.emit("messageInfo",`${C.getMessagesByLocale(S.UnableToReannotation,this.lang)}`);return}this.editPolygonID=this.selectedID,this.drawingPointList=(i=(e=this.selectedPolygon)==null?void 0:e.pointList)!=null?i:[],this.drawingHistory.empty(),this.drawingHistory.initRecord(this.drawingPointList),this.hoverID="",this.deleteSelectedID(),this.render()}}onTabKeyDown(t){t.preventDefault();let e=E.ascend;t.shiftKey&&(e=E.descend),this.switchToNextPolygon(e)}switchToNextPolygon(t){if(this.drawingPointList.length>0)return;const[e,i]=u.getRenderResultList(this.polygonList,u.getSourceID(this.basicResult),this.attributeLockList,this.selectedID);let s=[...e];i&&(s=[...s,i]);const o=B.getViewPort(this.canvas,this.currentPos,this.zoom),r=s.map(l=>{var h,g,a,d;return m(f({},l),{x:(g=(h=l.pointList[0])==null?void 0:h.x)!=null?g:0,y:(d=(a=l.pointList[0])==null?void 0:a.y)!=null?d:0})}).filter(l=>B.inViewPort({x:l.x,y:l.y},o)),n=u.getNextSelectedRectID(r,t,this.selectedID);if(n){this.setSelectedID(n.id);const{selectedPolygon:l}=this;l&&this.setDefaultAttribute(l.attribute)}this.render()}onKeyDown(t){if(!u.hotkeyFilter(t)||super.onKeyDown(t)===!1)return;const{keyCode:e}=t;switch(e){case p.Space:this.spaceKeydown();break;case p.Esc:this.drawingPointList=[],this.editPolygonID="";break;case p.F:this.selectedID&&this.setPolygonValidAndRender(this.selectedID);break;case p.Z:if(t.altKey){this.onCombinedExecute();return}this.setIsHidden(!this.isHidden),this.render();break;case p.Delete:this.deletePolygon(this.selectedID),this.render();break;case p.Ctrl:this.isCtrl=!0;break;case p.Alt:this.isAlt===!1&&(t.preventDefault(),this.isAlt=!0,this.render());break;case p.Tab:{this.onTabKeyDown(t);break}case p.X:t.altKey&&this.segment();break;default:{if(this.config.attributeConfigurable){const i=v.getAttributeByKeycode(e,this.config.attributeList);i!==void 0&&this.setDefaultAttribute(i)}break}}}onKeyUp(t){switch(super.onKeyUp(t),t.keyCode){case p.Ctrl:this.isCtrl=!1;break;case p.Alt:{const e=this.isAlt;this.isAlt=!1,e===!0&&this.render();break}}}rightMouseUp(t){if(this.drawingPointList.length>0){this.addDrawingPointToPolygonList();return}this.setSelectedID(this.hoverID);const{selectedPolygon:e}=this;e&&this.setDefaultAttribute(e.attribute)}onLeftDblClick(t){if(this.hoverEdgeIndex>-1){const e=this.getCoordinateUnderZoom(t),{selectedPolygon:i}=this;if(!i)return;if(i.isRect===!0){this.emit("messageInfo",`${C.getMessagesByLocale(S.ForbidAddNewPoint,this.lang)}`),this.clearPolygonDrag();return}const{dropFoot:s}=y.getClosestPoint(e,this.polygonListUnderZoom,this.config.lineType,R);if(!s)return;const{upperLimitPointNum:o}=this.config;if(o&&i.pointList.length>=o){this.emit("messageInfo",`${C.getMessagesByLocale(S.UpperLimitErrorNotice,this.lang)}${o}`),this.clearPolygonDrag();return}i==null||i.pointList.splice(this.hoverEdgeIndex+1,0,c.changePointByZoom(s,1/this.zoom)),this.setPolygonDataByID(i,this.selectedID),this.history.pushHistory(this.polygonList),this.hoverPointIndex=-1,this.hoverEdgeIndex=-1,this.render()}this.dragInfo=void 0}onRightDblClick(t){this.dragInfo=void 0,this.clearImgDrag();const e=this.getHoverID(t),i=this.getHoverPointIndex(t);if(this.hoverPointIndex>-1&&this.hoverPointIndex===i){this.deletePolygonPoint(i),this.dragInfo=void 0,this.hoverPointIndex=-1,this.render();return}this.hoverID===this.selectedID&&this.deletePolygon(e),this.render()}onMouseDown(t){if(super.onMouseDown(t)||this.forbidMouseOperation||t.ctrlKey===!0)return;const e=this.selectedPolygon;if(!e||t.button!==0||this.getHoverID(t)!==this.selectedID)return;const s=e.pointList,o=this.getCoordinateUnderZoom(t);let r=[0],n=b.Plane;this.dragStatus=x.Start;const l=this.getHoverPointIndex(t),h=this.getHoverEdgeIndex(t);return l>-1?(n=b.Point,r=[l]):h>-1&&this.hoverEdgeIndex>-1&&(n=b.Line,r=[h,(h+1)%s.length]),this.dragInfo={dragStartCoord:o,dragTarget:n,initPointList:s,changePointIndex:r,originPolygon:this.selectedPolygon},!0}segment(){var t;if(!this.selectedID||((t=this.config)==null?void 0:t.lineType)!==H.Line)return;const e=y.getPolygonPointList(this.selectedID,this.currentShowList),i=this.currentShowList.filter(r=>r.id!==this.selectedID);if(i.length===0||e.length===0)return;const s=y.getWrapPolygonIndex(e,i);let o=[...this.polygonList];if(s===-1){const r=y.segmentPolygonByPolygon(e,i);if(!r)return;const n=r.shift();if(!n)return;let l="",h=!0;const g=u.getSourceID(this.basicResult);let a="";o=this.polygonList.map(d=>{var I,T;return d.id===this.selectedID?(l=d.attribute,h=(I=d==null?void 0:d.valid)!=null?I:!0,a=(T=d==null?void 0:d.textAttribute)!=null?T:"",m(f({},d),{pointList:n})):d}),r.length>0&&r.forEach((d,I)=>{o.push({sourceID:g,id:M(8,62),pointList:d,valid:h,order:u.getMaxOrder(this.currentShowList)+1+I,attribute:l,textAttribute:a})})}else o[s].pointList=y.clipPolygonFromWrapPolygon(e,o[s].pointList),o=o.filter(r=>r.id!==this.selectedID);this.setPolygonList(o),this.history.pushHistory(o),this.render()}onCombinedExecute(){if(!this.selectedID){this.emit("messageInfo",_.t("PolygonsToBeCombinedNeedToBeSelected"));return}this.isCombined=!this.isCombined}combine(t){var e;const i=this.getHoverID(t);if(!i||!this.selectedID||this.selectedID===i)return;if(((e=this.config)==null?void 0:e.lineType)!==H.Line){this.emit("messageInfo",_.t("CurveModeDoesNotSupportCutting"));return}const s=this.polygonList.find(h=>h.id===this.selectedID),o=this.currentShowList.find(h=>h.id===i);if(!o||!s)return;const r=y.combinePolygonWithPolygon(s,o);if(!r)return;const{newPolygon:n,unionList:l}=r;if(l.length===1&&n){const h=this.polygonList.filter(g=>!l.includes(g.id)).map(g=>g.id===this.selectedID?n:g);this.setPolygonList(h),this.history.pushHistory(h),this.render(),this.emit("messageInfo",_.t("CombineSuccess"))}else this.emit("messageInfo",_.t("CombiningFailedNotify"));this.isCombined=!1}isPolygonOutSide(t){if(this.dependToolName&&this.basicCanvas&&this.basicResult){let n=!1;switch(this.dependToolName){case O.Rect:{n=t.filter(l=>!z.isInRect(l,this.basicResult)).length>0;break}case O.Polygon:{n=y.isPointListOutSidePolygon(t,this.basicResult.pointList,this.config.lineType);break}}return n}if(!this.imgInfo)return!1;const{left:e,top:i,right:s,bottom:o}=D.calcViewportBoundaries(c.changePointListByZoom(t,this.zoom)),r=1e-5;return e<0||i<0||s>this.imgInfo.width+r||o>this.imgInfo.height+r}onDragMove(t){if(!this.dragInfo||!this.selectedID)return;const{selectedPolygon:e}=this;let i=e==null?void 0:e.pointList;if(!i)return;const{initPointList:s,dragStartCoord:o,dragTarget:r,changePointIndex:n}=this.dragInfo,l=this.getCoordinateUnderZoom(t);let h={x:(l.x-o.x)/this.zoom,y:(l.y-o.y)/this.zoom};if(this.pattern===w.Rect&&(e==null?void 0:e.isRect)===!0&&n&&[b.Line].includes(r)){const a=D.getArrayIndex(n[0]-2,4),d=D.getArrayIndex(n[0]-1,4),I=[s[a],s[d]];h=D.getRectPerpendicularOffset(o,l,I),h={x:h.x/this.zoom,y:h.y/this.zoom}}switch(this.dragStatus=x.Move,r){case b.Plane:i=i.map((a,d)=>m(f({},a),{x:s[d].x+h.x,y:s[d].y+h.y}));break;case b.Point:case b.Line:i=i.map((a,d)=>n&&n.includes(d)?m(f({},a),{x:s[d].x+h.x,y:s[d].y+h.y}):a);break}if(this.pattern===w.Rect&&(e==null?void 0:e.isRect)===!0&&r===b.Point&&n&&(i=D.getPointListFromPointOffset(s,n[0],h)),this.config.drawOutsideTarget===!1&&this.imgInfo&&this.isPolygonOutSide(i))return;const g=this.polygonList.map(a=>{if(a.id===this.selectedID){const d=m(f({},a),{pointList:i});return a.isRect===!0&&this.pattern===w.Normal&&Object.assign(d,{isRect:!1}),d}return a});this.setPolygonList(g),this.render()}onMouseMove(t){if(super.onMouseMove(t)||this.forbidMouseOperation||!this.imgInfo)return;if(this.selectedID&&this.dragInfo){this.onDragMove(t);return}let e=-1,i=-1;const{selectedID:s}=this;if(s&&(this.hoverEdgeIndex=-1,this.hoverPointIndex=-1,e=this.getHoverPointIndex(t),e>-1?this.hoverPointIndex=e:(i=this.getHoverEdgeIndex(t),this.hoverEdgeIndex=i)),this.drawingPointList.length>0)return;const o=this.getHoverID(t);this.hoverID!==o&&(this.hoverID=o,this.render())}leftMouseUp(t){const e=this.getHoverID(t);if(this.drawingPointList.length===0&&t.ctrlKey===!0&&e){this.setPolygonValidAndRender(e);return}this.addPointInDrawing(t)}onMouseUp(t){if(this.isCombined){switch(t.button){case 0:this.combine(t);break;case 2:this.isCombined=!1;break;default:return}return}if(!(super.onMouseUp(t)||this.forbidMouseOperation||!this.imgInfo)){if(this.dragInfo&&this.dragStatus===x.Move){const{originPolygon:e}=this.dragInfo;this.dragInfo=void 0,this.dragStatus=x.Wait,this.history.pushHistory(this.polygonList),this.emit("updateResult"),this.emit("updatePolygonByDrag",{newPolygon:this.selectedPolygon,originPolygon:e});return}switch(t.button){case 0:{this.leftMouseUp(t);break}case 2:{this.rightMouseUp(t);break}}this.render()}}dragMouseUp(){this.dragStatus===x.Start&&(this.dragInfo=void 0,this.dragStatus=x.Wait)}exportData(){const{polygonList:t}=this;return[t,this.basicImgInfo]}getTextIconSvg(t=""){return v.getTextIconSvg(t,this.config.attributeList,this.config.attributeConfigurable,this.baseIcon)}getCurrentSelectedData(){const{selectedPolygon:t}=this;if(!t)return;const e=this.getColor(t.attribute),i=t.valid?e==null?void 0:e.valid.stroke:e==null?void 0:e.invalid.stroke;return{width:j,textAttribute:t.textAttribute,color:i}}updateSelectedTextAttribute(t){if(this._textAttributInstance&&t&&this.selectedID){let e=t;v.textAttributeValidate(this.config.textCheckType,"",e)===!1&&(this.emit("messageError",v.getErrorNotice(this.config.textCheckType,this.lang)),e=""),this.setPolygonList(v.textChange(e,this.selectedID,this.polygonList)),this.emit("updateTextAttribute"),this.render()}}renderTextAttribute(){var t;const{selectedPolygon:e}=this;if(!this.ctx||this.config.textConfigurable===!1||!e)return;const{pointList:i,attribute:s,valid:o,textAttribute:r}=e,{x:n,y:l}=i[i.length-1],h=j,g=c.getOffsetCoordinate({x:n,y:l},this.currentPos,this.zoom),a=this.getColor(s),d=o?a==null?void 0:a.valid.stroke:a==null?void 0:a.invalid.stroke;this._textAttributInstance||(this._textAttributInstance=new $({width:h,container:this.container,icon:this.getTextIconSvg(s),color:d,getCurrentSelectedData:this.getCurrentSelectedData,updateSelectedTextAttribute:this.updateSelectedTextAttribute})),this._textAttributInstance&&!((t=this._textAttributInstance)==null?void 0:t.isExit)&&this._textAttributInstance.appendToContainer(),this._textAttributInstance.update(`${r}`,{left:g.x,top:g.y,color:d,width:h})}renderStaticPolygon(){var t;this.isHidden===!1&&((t=this.polygonList)==null||t.forEach(e=>{var i,s,o,r,n;if([this.selectedID,this.editPolygonID].includes(e.id))return;const{textAttribute:l,attribute:h}=e,g=this.getColor(h),a=A.getStrokeAndFill(g,e.valid),d=c.changePointListByZoom(e.pointList||[],this.zoom,this.currentPos);P.drawPolygonWithFillAndLine(this.canvas,d,{fillColor:a.fill,strokeColor:a.stroke,pointColor:"white",thickness:(s=(i=this.style)==null?void 0:i.width)!=null?s:2,lineCap:"round",isClose:!0,lineType:(o=this.config)==null?void 0:o.lineType});let I=`${(r=v.getAttributeShowText(h,this.config.attributeList))!=null?r:""}`;((n=this.config)==null?void 0:n.isShowOrder)&&(e==null?void 0:e.order)>0&&(I=`${e.order} ${I}`),P.drawText(this.canvas,d[0],I,f({color:a.stroke},k));const T=d[d.length-1];P.drawText(this.canvas,{x:T.x+U.x,y:T.y+U.y},l,f({color:a.stroke},k))}))}renderSelectedPolygon(){var t,e,i;if(this.selectedID){const s=this.selectedPolygon;if(s){const o=this.getColor(s.attribute),r=A.getStrokeAndFill(o,s.valid,{isSelected:!0});P.drawSelectedPolygonWithFillAndLine(this.canvas,c.changePointListByZoom(s.pointList,this.zoom,this.currentPos),{fillColor:r.fill,strokeColor:r.stroke,pointColor:"white",thickness:2,lineCap:"round",isClose:!0,lineType:(t=this.config)==null?void 0:t.lineType});let n=`${(e=v.getAttributeShowText(s.attribute,this.config.attributeList))!=null?e:""}`;((i=this.config)==null?void 0:i.isShowOrder)&&(s==null?void 0:s.order)>0&&(n=`${s.order} ${n}`),P.drawText(this.canvas,c.changePointByZoom(s.pointList[0],this.zoom,this.currentPos),n,f({color:r.stroke},k)),this.renderTextAttribute()}}}renderHoverPolygon(){var t;if(this.hoverID&&this.hoverID!==this.editPolygonID){const{hoverPolygon:e}=this;if(e){let i="";const s=this.getColor(e.attribute);e.valid?i=s.validHover.fill:i=A.getStrokeAndFill(s,!1,{isHover:!0}).fill,P.drawPolygonWithFill(this.canvas,c.changePointListByZoom(e.pointList,this.zoom,this.currentPos),{color:i,lineType:(t=this.config)==null?void 0:t.lineType})}}}renderPolygon(){var t,e,i,s;this.renderStaticPolygon(),this.renderHoverPolygon(),this.renderSelectedPolygon();const o=this.getColor(this.defaultAttribute),r=A.getStrokeAndFill(o,!this.isCtrl);if(((t=this.drawingPointList)==null?void 0:t.length)>0){let n=[...this.drawingPointList],l=c.getOriginCoordinateWithOffsetCoordinate(this.coord,this.zoom,this.currentPos);if(this.pattern===w.Rect&&n.length===2)n=D.getRectangleByRightAngle(l,n);else{if(((e=this.config)==null?void 0:e.edgeAdsorption)&&this.isAlt===!1){const{dropFoot:h}=y.getClosestPoint(l,this.polygonList,(i=this.config)==null?void 0:i.lineType,R/this.zoom);h&&(l=h)}n.push(l)}P.drawSelectedPolygonWithFillAndLine(this.canvas,c.changePointListByZoom(n,this.zoom,this.currentPos),{fillColor:r.fill,strokeColor:r.stroke,pointColor:"white",thickness:2,lineCap:"round",isClose:!1,lineType:this.config.lineType})}if(this.hoverPointIndex>-1&&this.selectedID){const n=this.selectedPolygon;if(!n)return;const l=A.getStrokeAndFill(o,n.valid,{isSelected:!0}),h=n==null?void 0:n.pointList[this.hoverPointIndex];if(h){const{x:g,y:a}=c.changePointByZoom(h,this.zoom,this.currentPos);P.drawCircleWithFill(this.canvas,{x:g,y:a},5,{color:l.fill})}}if(this.hoverEdgeIndex>-1&&this.selectedID){const n=this.selectedPolygon;if(!n)return;const l=A.getStrokeAndFill(o,n.valid,{isSelected:!0});P.drawLineWithPointList(this.canvas,c.changePointListByZoom(n.pointList,this.zoom,this.currentPos),{color:l.stroke,thickness:10,hoverEdgeIndex:this.hoverEdgeIndex,lineType:(s=this.config)==null?void 0:s.lineType})}}render(){!this.ctx||(super.render(),this.renderPolygon(),this.renderCursorLine(this.getLineColor(this.defaultAttribute)))}renderCursorLine(t){if(super.renderCursorLine(t),this.isCombined){const{x:e,y:i}=this.coord,s=10,o=186,r=32;P.drawRectWithFill(this.canvas,{x:e+s,y:i-s*4-1,width:o,height:r},{color:"black"}),P.drawText(this.canvas,{x:e,y:i},_.t("ClickAnotherPolygon"),{textAlign:"center",color:"white",offsetX:o/2+s,offsetY:-(r/2+s/2)}),P.drawRect(this.canvas,{x:e-s,y:i-s,width:s*2,height:s*2},{lineDash:[6],color:"white"})}}undo(){if(this.drawingPointList.length>0){const e=this.drawingHistory.undo();if(!e)return;this.drawingPointList=e,this.render();return}const t=this.history.undo();t&&(t.length!==this.polygonList.length&&this.deleteSelectedID(),this.setPolygonList(t),this.render())}redo(){if(this.drawingPointList.length>0){const e=this.drawingHistory.redo();if(!e)return;this.drawingPointList=e,this.render();return}const t=this.history.redo();t&&(t.length!==this.polygonList.length&&this.deleteSelectedID(),this.setPolygonList(t),this.render())}deleteSelectedID(){this.setSelectedID("")}}export{J as default};
1
+ import{i18n as _}from"@labelbee/lb-utils";import D from"../../utils/MathUtils.js";import z from"../../utils/tool/RectUtils.js";import{ERotateDirection as N,EDragStatus as x,ESortDirection as E,EDragTarget as b,TEXT_ATTRIBUTE_OFFSET as U,DEFAULT_TEXT_OFFSET as k}from"../../constant/annotation.js";import p from"../../constant/keyCode.js";import{EPolygonPattern as w,edgeAdsorptionScope as R,ELineTypes as H,EToolName as O}from"../../constant/tool.js";import C from"../../locales/index.js";import{EMessage as S}from"../../locales/constants.js";import W from"../../utils/ActionsHistory.js";import v from"../../utils/tool/AttributeUtils.js";import c from"../../utils/tool/AxisUtils.js";import B from"../../utils/tool/CanvasUtils.js";import u from"../../utils/tool/CommonToolUtils.js";import P from"../../utils/tool/DrawUtils.js";import y from"../../utils/tool/PolygonUtils.js";import A from"../../utils/tool/StyleUtils.js";import M from"../../utils/uuid.js";import{BasicToolOperation as K}from"./basicToolOperation.js";import $ from"./textAttributeClass.js";var V=Object.defineProperty,X=Object.defineProperties,Y=Object.getOwnPropertyDescriptors,Z=Object.getOwnPropertySymbols,q=Object.prototype.hasOwnProperty,G=Object.prototype.propertyIsEnumerable,F=(L,t,e)=>t in L?V(L,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):L[t]=e,f=(L,t)=>{for(var e in t||(t={}))q.call(t,e)&&F(L,e,t[e]);if(Z)for(var e of Z(t))G.call(t,e)&&F(L,e,t[e]);return L},m=(L,t)=>X(L,Y(t));const j=164;class J extends K{constructor(t){super(t);this.isAllowDouble=e=>{const{selectedID:i}=this,s=this.getHoverID(e);return!!(i&&i===s)},this.textChange=e=>{this.config.textConfigurable===!1||!this.selectedID||(this.setPolygonList(v.textChange(e,this.selectedID,this.polygonList)),this.emit("selectedChange"),this.render())},this.config=u.jsonParser(t.config),this.drawingPointList=[],this.polygonList=[],this.hoverPointIndex=-1,this.hoverEdgeIndex=-1,this.drawingHistory=new W,this.isCtrl=!1,this.isAlt=!1,this.isCombined=!1,this.pattern=w.Normal,this.getCurrentSelectedData=this.getCurrentSelectedData.bind(this),this.updateSelectedTextAttribute=this.updateSelectedTextAttribute.bind(this)}eventBinding(){super.eventBinding(),this.container.removeEventListener("mouseup",this.onMouseUp),this.container.addEventListener("mouseup",this.dragMouseUp),this.dblClickListener.addEvent(this.onMouseUp,this.onLeftDblClick,this.onRightDblClick,this.isAllowDouble)}eventUnbinding(){super.eventUnbinding(),this.container.removeEventListener("mouseup",this.dragMouseUp)}destroy(){super.destroy(),this._textAttributInstance&&this._textAttributInstance.clearTextAttribute()}get selectedPolygon(){return y.getPolygonByID(this.polygonList,this.selectedID)}get hoverPolygon(){return this.polygonList.find(t=>t.id===this.hoverID&&t.id!==this.selectedID)}get polygonListUnderZoom(){return this.polygonList.map(t=>m(f({},t),{pointList:c.changePointListByZoom(t.pointList,this.zoom)}))}get selectedText(){var t;return(t=this.selectedPolygon)==null?void 0:t.textAttribute}get dataList(){return this.polygonList}setPattern(t,e=!1){var i;((i=this.drawingPointList)==null?void 0:i.length)>0&&e===!0||(this.pattern=t)}get currentShowList(){let t=[];const[e,i]=u.getRenderResultList(this.polygonList,u.getSourceID(this.basicResult),this.attributeLockList,this.selectedID);return t=e,this.isHidden&&(t=[]),i&&t.push(i),t}get currentPageResult(){const[t]=u.getRenderResultList(this.polygonList,u.getSourceID(this.basicResult),[]);return t}setResultAndSelectedID(t,e){this.setPolygonList(t),e&&(this.selectedID=e),this.render()}setResult(t){this.clearActiveStatus(),this.setPolygonList(t),this.render()}setPolygonDataByID(t,e){return this.polygonList.map(i=>i.id===e?f(f({},i),t):i)}rotatePolygon(t=1,e=N.Clockwise,i=this.selectedID){if(!i)return;const s=y.getPolygonByID(this.polygonList,i);if(!s)return;const o=y.updatePolygonByRotate(e,t,s==null?void 0:s.pointList);this.setPolygonList(this.setPolygonDataByID({pointList:o},i)),this.render()}addPointInDrawing(t){if(!this.imgInfo||this.forbidAddNewPolygonFuc&&this.forbidAddNewPolygonFuc(t))return;const{upperLimitPointNum:e,edgeAdsorption:i}=this.config;if(e&&this.drawingPointList.length>=e){this.emit("messageInfo",`${C.getMessagesByLocale(S.UpperLimitErrorNotice,this.lang)}${e}`);return}this.deleteSelectedID();const s=this.getCoordinateUnderZoom(t),o=c.changeDrawOutsideTarget(s,{x:0,y:0},this.imgInfo,this.config.drawOutsideTarget,this.basicResult,this.zoom);if(c.returnClosePointIndex(o,c.changePointListByZoom(this.drawingPointList,this.zoom))===0){this.addDrawingPointToPolygonList();return}const{dropFoot:n}=y.getClosestPoint(o,this.polygonListUnderZoom,this.config.lineType,R),l=c.changePointByZoom(n&&t.altKey===!1&&i?n:o,1/this.zoom);if(this.pattern===w.Rect&&this.drawingPointList.length===2){const h=D.getRectangleByRightAngle(l,this.drawingPointList);if(this.drawingPointList=h,this.config.drawOutsideTarget===!1&&this.imgInfo&&this.isPolygonOutSide(this.drawingPointList)){this.emit("messageInfo",`${C.getMessagesByLocale(S.ForbiddenCreationOutsideBoundary,this.lang)}`),this.drawingPointList=[];return}this.addDrawingPointToPolygonList(!0);return}this.drawingPointList.push(l),this.drawingPointList.length===1?this.drawingHistory.initRecord(this.drawingPointList):this.drawingHistory.pushHistory(this.drawingPointList)}clearResult(){this.setPolygonList([]),this.deleteSelectedID(),this.render()}clearPolygonDrag(){this.drawingPointList=[],this.dragInfo=void 0,this.dragInfo=void 0,this.dragStatus=x.Wait,this.hoverEdgeIndex=-1,this.hoverPointIndex=-1,this.hoverID=""}clearActiveStatus(){this.clearPolygonDrag(),this.deleteSelectedID()}clearDrawingStatus(){this.drawingPointList=[]}setPolygonList(t){const e=this.polygonList.length;this.polygonList=t,e!==t.length&&this.emit("updatePageNumber")}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")}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.selectedPolygon&&(this.selectedPolygon.attribute=t),this.history.pushHistory(this.polygonList),this.render()),this._textAttributInstance){if(this.attributeLockList.length>0&&!this.attributeLockList.includes(t)){this._textAttributInstance.clearTextAttribute();return}this._textAttributInstance.updateIcon(this.getTextIconSvg(t))}}}setStyle(t){var e;super.setStyle(t),this._textAttributInstance&&this.config.attributeConfigurable===!1&&((e=this._textAttributInstance)==null||e.updateIcon(this.getTextIconSvg()))}setPolygonValidAndRender(t){if(!t)return;const e=this.polygonList.map(i=>{var s;if(i.id===t){const o=(s=i==null?void 0:i.valid)!=null?s:!0;return m(f({},i),{valid:!o})}return i});this.setPolygonList(e),this.history.pushHistory(this.polygonList),this.render(),this.emit("updateResult")}addDrawingPointToPolygonList(t){let{lowerLimitPointNum:e=3}=this.config;e<3&&(e=3);let i;if(this.drawingPointList.length<e){this.drawingPointList=[],this.editPolygonID="";return}const s=u.getSourceID(this.basicResult),o=[...this.polygonList];if(this.editPolygonID){const r=o.find(n=>n.id===this.editPolygonID);if(!r)return;r.pointList=this.drawingPointList,this.editPolygonID=""}else{const r=M(8,62);let n={id:r,sourceID:s,valid:!this.isCtrl,textAttribute:"",pointList:this.drawingPointList,attribute:this.defaultAttribute,order:u.getMaxOrder(o.filter(l=>u.isSameSourceID(l.sourceID,s)))+1};if(this.config.textConfigurable){let l="";l=v.getTextAttribute(this.polygonList.filter(h=>u.isSameSourceID(h.sourceID,s)),this.config.textCheckType),n=m(f({},n),{textAttribute:l})}this.pattern===w.Rect&&t===!0&&(n=m(f({},n),{isRect:!0})),o.push(n),i=n,this.setSelectedIdAfterAddingDrawing(r)}this.setPolygonList(o),this.isCtrl=!1,this.drawingPointList=[],this.history.pushHistory(o),i&&this.emit("polygonCreated",i,this.zoom,this.currentPos)}setSelectedIdAfterAddingDrawing(t){this.drawingPointList.length!==0&&(this.config.textConfigurable?this.setSelectedID(t):this.deleteSelectedID())}getHoverID(t){var e;const i=this.getCoordinateUnderZoom(t),s=this.currentShowList.map(o=>m(f({},o),{pointList:c.changePointListByZoom(o.pointList,this.zoom)}));return y.getHoverPolygonID(i,s,10,(e=this.config)==null?void 0:e.lineType)}getHoverEdgeIndex(t){var e;if(!this.selectedID)return-1;const i=this.selectedPolygon;if(!i)return-1;const s=this.getCoordinateUnderZoom(t),o=c.changePointListByZoom(i.pointList,this.zoom);return y.getHoverEdgeIndex(s,o,(e=this.config)==null?void 0:e.lineType)}getHoverPointIndex(t){if(!this.selectedID)return-1;const e=this.selectedPolygon;if(!e)return-1;const i=this.getCoordinateUnderZoom(t),s=c.changePointListByZoom(e.pointList,this.zoom);return c.returnClosePointIndex(i,s)}deletePolygon(t){var e;if(!t)return;const i=this.polygonList.find(s=>s.id===t);this.emit("deletedObject",{deletedObject:i,id:t}),this.setPolygonList(this.polygonList.filter(s=>s.id!==t)),this.history.pushHistory(this.polygonList),(e=this._textAttributInstance)==null||e.clearTextAttribute(),this.emit("selectedChange"),this.render()}deletePolygonPoint(t){if(!this.selectedID)return;const{selectedPolygon:e}=this;if(!e)return;let{lowerLimitPointNum:i}=this.config;if(i<3&&(i=3),e.pointList.length<=i){this.emit("messageInfo",`${C.getMessagesByLocale(S.LowerLimitErrorNotice,this.lang)}${i}`);return}e==null||e.pointList.splice(t,1),this.history.pushHistory(this.polygonList),this.render()}spaceKeydown(){var t,e,i;if(this.selectedID){if(((t=this.selectedPolygon)==null?void 0:t.isRect)===!0){this.emit("messageInfo",`${C.getMessagesByLocale(S.UnableToReannotation,this.lang)}`);return}this.editPolygonID=this.selectedID,this.drawingPointList=(i=(e=this.selectedPolygon)==null?void 0:e.pointList)!=null?i:[],this.drawingHistory.empty(),this.drawingHistory.initRecord(this.drawingPointList),this.hoverID="",this.deleteSelectedID(),this.render()}}onTabKeyDown(t){t.preventDefault();let e=E.ascend;t.shiftKey&&(e=E.descend),this.switchToNextPolygon(e)}switchToNextPolygon(t){if(this.drawingPointList.length>0)return;const[e,i]=u.getRenderResultList(this.polygonList,u.getSourceID(this.basicResult),this.attributeLockList,this.selectedID);let s=[...e];i&&(s=[...s,i]);const o=B.getViewPort(this.canvas,this.currentPos,this.zoom),r=s.map(l=>{var h,g,a,d;return m(f({},l),{x:(g=(h=l.pointList[0])==null?void 0:h.x)!=null?g:0,y:(d=(a=l.pointList[0])==null?void 0:a.y)!=null?d:0})}).filter(l=>B.inViewPort({x:l.x,y:l.y},o)),n=u.getNextSelectedRectID(r,t,this.selectedID);if(n){this.setSelectedID(n.id);const{selectedPolygon:l}=this;l&&this.setDefaultAttribute(l.attribute)}this.render()}onKeyDown(t){if(!u.hotkeyFilter(t)||super.onKeyDown(t)===!1)return;const{keyCode:e}=t;switch(e){case p.Space:this.spaceKeydown();break;case p.Esc:this.drawingPointList=[],this.editPolygonID="";break;case p.F:this.selectedID&&this.setPolygonValidAndRender(this.selectedID);break;case p.Z:if(t.altKey){this.onCombinedExecute();return}this.setIsHidden(!this.isHidden),this.render();break;case p.Delete:this.deletePolygon(this.selectedID),this.render();break;case p.Ctrl:this.isCtrl=!0;break;case p.Alt:this.isAlt===!1&&(t.preventDefault(),this.isAlt=!0,this.render());break;case p.Tab:{this.onTabKeyDown(t);break}case p.X:t.altKey&&this.segment();break;default:{if(this.config.attributeConfigurable){const i=v.getAttributeByKeycode(e,this.config.attributeList);i!==void 0&&this.setDefaultAttribute(i)}break}}}onKeyUp(t){switch(super.onKeyUp(t),t.keyCode){case p.Ctrl:this.isCtrl=!1;break;case p.Alt:{const e=this.isAlt;this.isAlt=!1,e===!0&&this.render();break}}}rightMouseUp(t){if(this.drawingPointList.length>0){this.addDrawingPointToPolygonList();return}this.setSelectedID(this.hoverID);const{selectedPolygon:e}=this;e&&this.setDefaultAttribute(e.attribute)}onLeftDblClick(t){if(this.hoverEdgeIndex>-1){const e=this.getCoordinateUnderZoom(t),{selectedPolygon:i}=this;if(!i)return;if(i.isRect===!0){this.emit("messageInfo",`${C.getMessagesByLocale(S.ForbidAddNewPoint,this.lang)}`),this.clearPolygonDrag();return}const{dropFoot:s}=y.getClosestPoint(e,this.polygonListUnderZoom,this.config.lineType,R);if(!s)return;const{upperLimitPointNum:o}=this.config;if(o&&i.pointList.length>=o){this.emit("messageInfo",`${C.getMessagesByLocale(S.UpperLimitErrorNotice,this.lang)}${o}`),this.clearPolygonDrag();return}i==null||i.pointList.splice(this.hoverEdgeIndex+1,0,c.changePointByZoom(s,1/this.zoom)),this.setPolygonDataByID(i,this.selectedID),this.history.pushHistory(this.polygonList),this.hoverPointIndex=-1,this.hoverEdgeIndex=-1,this.render()}this.dragInfo=void 0}onRightDblClick(t){this.dragInfo=void 0,this.clearImgDrag();const e=this.getHoverID(t),i=this.getHoverPointIndex(t);if(this.hoverPointIndex>-1&&this.hoverPointIndex===i){this.deletePolygonPoint(i),this.dragInfo=void 0,this.hoverPointIndex=-1,this.render();return}this.hoverID===this.selectedID&&this.deletePolygon(e),this.render()}onMouseDown(t){if(!(super.onMouseDown(t)||this.forbidMouseOperation||t.ctrlKey===!0))return this.dragMouseDown(t),!0}dragMouseDown(t){const e=this.selectedPolygon;if(!e||t.button!==0||this.getHoverID(t)!==this.selectedID)return;const s=e.pointList,o=this.getCoordinateUnderZoom(t);let r=[0],n=b.Plane;this.dragStatus=x.Start;const l=this.getHoverPointIndex(t),h=this.getHoverEdgeIndex(t);l>-1?(n=b.Point,r=[l]):h>-1&&this.hoverEdgeIndex>-1&&(n=b.Line,r=[h,(h+1)%s.length]),this.dragInfo={dragStartCoord:o,dragTarget:n,initPointList:s,changePointIndex:r,originPolygon:this.selectedPolygon}}segment(){var t;if(!this.selectedID||((t=this.config)==null?void 0:t.lineType)!==H.Line)return;const e=y.getPolygonPointList(this.selectedID,this.currentShowList),i=this.currentShowList.filter(r=>r.id!==this.selectedID);if(i.length===0||e.length===0)return;const s=y.getWrapPolygonIndex(e,i);let o=[...this.polygonList];if(s===-1){const r=y.segmentPolygonByPolygon(e,i);if(!r)return;const n=r.shift();if(!n)return;let l="",h=!0;const g=u.getSourceID(this.basicResult);let a="";o=this.polygonList.map(d=>{var I,T;return d.id===this.selectedID?(l=d.attribute,h=(I=d==null?void 0:d.valid)!=null?I:!0,a=(T=d==null?void 0:d.textAttribute)!=null?T:"",m(f({},d),{pointList:n})):d}),r.length>0&&r.forEach((d,I)=>{o.push({sourceID:g,id:M(8,62),pointList:d,valid:h,order:u.getMaxOrder(this.currentShowList)+1+I,attribute:l,textAttribute:a})})}else o[s].pointList=y.clipPolygonFromWrapPolygon(e,o[s].pointList),o=o.filter(r=>r.id!==this.selectedID);this.setPolygonList(o),this.history.pushHistory(o),this.render()}onCombinedExecute(){if(!this.selectedID){this.emit("messageInfo",_.t("PolygonsToBeCombinedNeedToBeSelected"));return}this.isCombined=!this.isCombined}combine(t){var e;const i=this.getHoverID(t);if(!i||!this.selectedID||this.selectedID===i)return;if(((e=this.config)==null?void 0:e.lineType)!==H.Line){this.emit("messageInfo",_.t("CurveModeDoesNotSupportCutting"));return}const s=this.polygonList.find(h=>h.id===this.selectedID),o=this.currentShowList.find(h=>h.id===i);if(!o||!s)return;const r=y.combinePolygonWithPolygon(s,o);if(!r)return;const{newPolygon:n,unionList:l}=r;if(l.length===1&&n){const h=this.polygonList.filter(g=>!l.includes(g.id)).map(g=>g.id===this.selectedID?n:g);this.setPolygonList(h),this.history.pushHistory(h),this.render(),this.emit("messageInfo",_.t("CombineSuccess"))}else this.emit("messageInfo",_.t("CombiningFailedNotify"));this.isCombined=!1}isPolygonOutSide(t){if(this.dependToolName&&this.basicCanvas&&this.basicResult){let n=!1;switch(this.dependToolName){case O.Rect:{n=t.filter(l=>!z.isInRect(l,this.basicResult)).length>0;break}case O.Polygon:{n=y.isPointListOutSidePolygon(t,this.basicResult.pointList,this.config.lineType);break}}return n}if(!this.imgInfo)return!1;const{left:e,top:i,right:s,bottom:o}=D.calcViewportBoundaries(c.changePointListByZoom(t,this.zoom)),r=1e-5;return e<0||i<0||s>this.imgInfo.width+r||o>this.imgInfo.height+r}onDragMove(t){if(!this.dragInfo||!this.selectedID)return;const{selectedPolygon:e}=this;let i=e==null?void 0:e.pointList;if(!i)return;const{initPointList:s,dragStartCoord:o,dragTarget:r,changePointIndex:n}=this.dragInfo,l=this.getCoordinateUnderZoom(t);let h={x:(l.x-o.x)/this.zoom,y:(l.y-o.y)/this.zoom};if(this.pattern===w.Rect&&(e==null?void 0:e.isRect)===!0&&n&&[b.Line].includes(r)){const a=D.getArrayIndex(n[0]-2,4),d=D.getArrayIndex(n[0]-1,4),I=[s[a],s[d]];h=D.getRectPerpendicularOffset(o,l,I),h={x:h.x/this.zoom,y:h.y/this.zoom}}switch(this.dragStatus=x.Move,r){case b.Plane:i=i.map((a,d)=>m(f({},a),{x:s[d].x+h.x,y:s[d].y+h.y}));break;case b.Point:case b.Line:i=i.map((a,d)=>n&&n.includes(d)?m(f({},a),{x:s[d].x+h.x,y:s[d].y+h.y}):a);break}if(this.pattern===w.Rect&&(e==null?void 0:e.isRect)===!0&&r===b.Point&&n&&(i=D.getPointListFromPointOffset(s,n[0],h)),this.config.drawOutsideTarget===!1&&this.imgInfo&&this.isPolygonOutSide(i))return;const g=this.polygonList.map(a=>{if(a.id===this.selectedID){const d=m(f({},a),{pointList:i});return a.isRect===!0&&this.pattern===w.Normal&&Object.assign(d,{isRect:!1}),d}return a});this.setPolygonList(g),this.render()}onMouseMove(t){if(super.onMouseMove(t)||this.forbidMouseOperation||!this.imgInfo)return;if(this.selectedID&&this.dragInfo){this.onDragMove(t);return}let e=-1,i=-1;const{selectedID:s}=this;if(s&&(this.hoverEdgeIndex=-1,this.hoverPointIndex=-1,e=this.getHoverPointIndex(t),e>-1?this.hoverPointIndex=e:(i=this.getHoverEdgeIndex(t),this.hoverEdgeIndex=i)),this.drawingPointList.length>0)return;const o=this.getHoverID(t);this.hoverID!==o&&(this.hoverID=o,this.render())}leftMouseUp(t){const e=this.getHoverID(t);if(this.drawingPointList.length===0&&t.ctrlKey===!0&&e){this.setPolygonValidAndRender(e);return}this.addPointInDrawing(t)}onMouseUp(t){if(this.isCombined){switch(t.button){case 0:this.combine(t);break;case 2:this.isCombined=!1;break;default:return}return}if(!(super.onMouseUp(t)||this.forbidMouseOperation||!this.imgInfo)){if(this.dragInfo&&this.dragStatus===x.Move){const{originPolygon:e}=this.dragInfo;this.dragInfo=void 0,this.dragStatus=x.Wait,this.history.pushHistory(this.polygonList),this.emit("updateResult"),this.emit("updatePolygonByDrag",{newPolygon:this.selectedPolygon,originPolygon:e});return}switch(t.button){case 0:{this.leftMouseUp(t);break}case 2:{this.rightMouseUp(t);break}}this.render()}}dragMouseUp(){this.dragStatus===x.Start&&(this.dragInfo=void 0,this.dragStatus=x.Wait)}exportData(){const{polygonList:t}=this;return[t,this.basicImgInfo]}getTextIconSvg(t=""){return v.getTextIconSvg(t,this.config.attributeList,this.config.attributeConfigurable,this.baseIcon)}getCurrentSelectedData(){const{selectedPolygon:t}=this;if(!t)return;const e=this.getColor(t.attribute),i=t.valid?e==null?void 0:e.valid.stroke:e==null?void 0:e.invalid.stroke;return{width:j,textAttribute:t.textAttribute,color:i}}updateSelectedTextAttribute(t){if(this._textAttributInstance&&t&&this.selectedID){let e=t;v.textAttributeValidate(this.config.textCheckType,"",e)===!1&&(this.emit("messageError",v.getErrorNotice(this.config.textCheckType,this.lang)),e=""),this.setPolygonList(v.textChange(e,this.selectedID,this.polygonList)),this.emit("updateTextAttribute"),this.render()}}renderTextAttribute(){var t;const{selectedPolygon:e}=this;if(!this.ctx||this.config.textConfigurable===!1||!e)return;const{pointList:i,attribute:s,valid:o,textAttribute:r}=e,{x:n,y:l}=i[i.length-1],h=j,g=c.getOffsetCoordinate({x:n,y:l},this.currentPos,this.zoom),a=this.getColor(s),d=o?a==null?void 0:a.valid.stroke:a==null?void 0:a.invalid.stroke;this._textAttributInstance||(this._textAttributInstance=new $({width:h,container:this.container,icon:this.getTextIconSvg(s),color:d,getCurrentSelectedData:this.getCurrentSelectedData,updateSelectedTextAttribute:this.updateSelectedTextAttribute})),this._textAttributInstance&&!((t=this._textAttributInstance)==null?void 0:t.isExit)&&this._textAttributInstance.appendToContainer(),this._textAttributInstance.update(`${r}`,{left:g.x,top:g.y,color:d,width:h})}renderStaticPolygon(){var t;this.isHidden===!1&&((t=this.polygonList)==null||t.forEach(e=>{var i,s,o,r,n;if([this.selectedID,this.editPolygonID].includes(e.id))return;const{textAttribute:l,attribute:h}=e,g=this.getColor(h),a=A.getStrokeAndFill(g,e.valid),d=c.changePointListByZoom(e.pointList||[],this.zoom,this.currentPos);P.drawPolygonWithFillAndLine(this.canvas,d,{fillColor:a.fill,strokeColor:a.stroke,pointColor:"white",thickness:(s=(i=this.style)==null?void 0:i.width)!=null?s:2,lineCap:"round",isClose:!0,lineType:(o=this.config)==null?void 0:o.lineType});let I=`${(r=v.getAttributeShowText(h,this.config.attributeList))!=null?r:""}`;((n=this.config)==null?void 0:n.isShowOrder)&&(e==null?void 0:e.order)>0&&(I=`${e.order} ${I}`),P.drawText(this.canvas,d[0],I,f({color:a.stroke},k));const T=d[d.length-1];P.drawText(this.canvas,{x:T.x+U.x,y:T.y+U.y},l,f({color:a.stroke},k))}))}renderSelectedPolygon(){var t,e,i;if(this.selectedID){const s=this.selectedPolygon;if(s){const o=this.getColor(s.attribute),r=A.getStrokeAndFill(o,s.valid,{isSelected:!0});P.drawSelectedPolygonWithFillAndLine(this.canvas,c.changePointListByZoom(s.pointList,this.zoom,this.currentPos),{fillColor:r.fill,strokeColor:r.stroke,pointColor:"white",thickness:2,lineCap:"round",isClose:!0,lineType:(t=this.config)==null?void 0:t.lineType});let n=`${(e=v.getAttributeShowText(s.attribute,this.config.attributeList))!=null?e:""}`;((i=this.config)==null?void 0:i.isShowOrder)&&(s==null?void 0:s.order)>0&&(n=`${s.order} ${n}`),P.drawText(this.canvas,c.changePointByZoom(s.pointList[0],this.zoom,this.currentPos),n,f({color:r.stroke},k)),this.renderTextAttribute()}}}renderHoverPolygon(){var t;if(this.hoverID&&this.hoverID!==this.editPolygonID){const{hoverPolygon:e}=this;if(e){let i="";const s=this.getColor(e.attribute);e.valid?i=s.validHover.fill:i=A.getStrokeAndFill(s,!1,{isHover:!0}).fill,P.drawPolygonWithFill(this.canvas,c.changePointListByZoom(e.pointList,this.zoom,this.currentPos),{color:i,lineType:(t=this.config)==null?void 0:t.lineType})}}}renderPolygon(){var t,e,i,s;this.renderStaticPolygon(),this.renderHoverPolygon(),this.renderSelectedPolygon();const o=this.getColor(this.defaultAttribute),r=A.getStrokeAndFill(o,!this.isCtrl);if(((t=this.drawingPointList)==null?void 0:t.length)>0){let n=[...this.drawingPointList],l=c.getOriginCoordinateWithOffsetCoordinate(this.coord,this.zoom,this.currentPos);if(this.pattern===w.Rect&&n.length===2)n=D.getRectangleByRightAngle(l,n);else{if(((e=this.config)==null?void 0:e.edgeAdsorption)&&this.isAlt===!1){const{dropFoot:h}=y.getClosestPoint(l,this.polygonList,(i=this.config)==null?void 0:i.lineType,R/this.zoom);h&&(l=h)}n.push(l)}P.drawSelectedPolygonWithFillAndLine(this.canvas,c.changePointListByZoom(n,this.zoom,this.currentPos),{fillColor:r.fill,strokeColor:r.stroke,pointColor:"white",thickness:2,lineCap:"round",isClose:!1,lineType:this.config.lineType})}if(this.hoverPointIndex>-1&&this.selectedID){const n=this.selectedPolygon;if(!n)return;const l=A.getStrokeAndFill(o,n.valid,{isSelected:!0}),h=n==null?void 0:n.pointList[this.hoverPointIndex];if(h){const{x:g,y:a}=c.changePointByZoom(h,this.zoom,this.currentPos);P.drawCircleWithFill(this.canvas,{x:g,y:a},5,{color:l.fill})}}if(this.hoverEdgeIndex>-1&&this.selectedID){const n=this.selectedPolygon;if(!n)return;const l=A.getStrokeAndFill(o,n.valid,{isSelected:!0});P.drawLineWithPointList(this.canvas,c.changePointListByZoom(n.pointList,this.zoom,this.currentPos),{color:l.stroke,thickness:10,hoverEdgeIndex:this.hoverEdgeIndex,lineType:(s=this.config)==null?void 0:s.lineType})}}render(){!this.ctx||(super.render(),this.renderPolygon(),this.renderCursorLine(this.getLineColor(this.defaultAttribute)))}renderCursorLine(t){if(super.renderCursorLine(t),this.isCombined){const{x:e,y:i}=this.coord,s=10,o=186,r=32;P.drawRectWithFill(this.canvas,{x:e+s,y:i-s*4-1,width:o,height:r},{color:"black"}),P.drawText(this.canvas,{x:e,y:i},_.t("ClickAnotherPolygon"),{textAlign:"center",color:"white",offsetX:o/2+s,offsetY:-(r/2+s/2)}),P.drawRect(this.canvas,{x:e-s,y:i-s,width:s*2,height:s*2},{lineDash:[6],color:"white"})}}undo(){if(this.drawingPointList.length>0){const e=this.drawingHistory.undo();if(!e)return;this.drawingPointList=e,this.render();return}const t=this.history.undo();t&&(t.length!==this.polygonList.length&&this.deleteSelectedID(),this.setPolygonList(t),this.render())}redo(){if(this.drawingPointList.length>0){const e=this.drawingHistory.redo();if(!e)return;this.drawingPointList=e,this.render();return}const t=this.history.redo();t&&(t.length!==this.polygonList.length&&this.deleteSelectedID(),this.setPolygonList(t),this.render())}deleteSelectedID(){this.setSelectedID("")}}export{J as default};
@@ -1,4 +1,4 @@
1
- import o from"../../locales/index.js";import{EMessage as a}from"../../locales/constants.js";class s{static renderInvalidPage(i,t,n){const e=document.createElement("div");return e.setAttribute("style",`
1
+ import n from"../../locales/index.js";import{EMessage as s}from"../../locales/constants.js";const o="bee-invalid-page";class l{static renderInvalidPage(i,t,a){const e=document.createElement("div");return e.setAttribute("style",`
2
2
  position: absolute;
3
3
  left: 0px;
4
4
  top: 0px;
@@ -13,4 +13,4 @@ import o from"../../locales/index.js";import{EMessage as a}from"../../locales/co
13
13
  font-size: 30px;
14
14
  opacity: 0.7;
15
15
  z-index: 30;
16
- `),e.innerHTML=o.getMessagesByLocale(a.InvalidImage,n),i.appendChild(e),e}}export{s as default};
16
+ `),e.innerHTML=n.getMessagesByLocale(s.InvalidImage,a),e.className=o,i.appendChild(e),e}}export{l as default};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@labelbee/lb-annotation",
3
- "version": "1.11.0-alpha.0",
3
+ "version": "1.12.0-alpha.0",
4
4
  "description": "Annotation tool collection",
5
5
  "keywords": [
6
6
  "annotation",
@@ -92,10 +92,11 @@
92
92
  "typescript": "^4.2.3"
93
93
  },
94
94
  "dependencies": {
95
- "@labelbee/lb-utils": "^1.4.0",
95
+ "@labelbee/lb-utils": "^1.5.0-alpha.0",
96
96
  "@turf/turf": "5.1.6",
97
97
  "color-rgba": "^2.3.0",
98
98
  "lodash": "^4.17.20",
99
99
  "three": ">=0.141.0"
100
- }
100
+ },
101
+ "gitHead": "3f9c6b095e3dfe1ccab781d0388574425ce0ae64"
101
102
  }