xl-public-utils 1.0.4 → 1.0.6

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.
@@ -0,0 +1,320 @@
1
+
2
+ import vtkInteractorStyleManipulator from "@kitware/vtk.js/Interaction/Style/InteractorStyleManipulator"
3
+ import { vec3, mat4, mat3 } from 'gl-matrix';
4
+ import vtkRenderer from "@kitware/vtk.js/Rendering/Core/Renderer";
5
+ import vtkRenderWindowInteractor from "@kitware/vtk.js/Rendering/Core/RenderWindowInteractor";
6
+ import vtkPolyData from "@kitware/vtk.js/Common/DataModel/PolyData";
7
+ /**
8
+ * 计算屏幕坐标到三维坐标
9
+ * @param {vtkRenderer} renderer vtkRenderer
10
+ * @param {number} x display x position
11
+ * @param {number} y display y position
12
+ * @param {number} z display z position
13
+ * @returns {[number, number, number]} 三维坐标
14
+ */
15
+ export function computeDisplayToWorld(renderer: vtkRenderer, x: number, y: number, z: number): [number, number, number];
16
+ /**
17
+ * 计算三维坐标到屏幕坐标
18
+ * @param {vtkRenderer} renderer vtkRenderer
19
+ * @param {number} x 三维坐标 x值
20
+ * @param {number} y 三维坐标 y值
21
+ * @param {number} z 三维坐标 z值
22
+ * @returns {[number, number, number]} 屏幕坐标
23
+ */
24
+ export function computeWorldToDisplay(renderer: vtkRenderer, x: number, y: number, z: number): [number, number, number];
25
+ /**
26
+ * 计算 w2l(word 2 local, word to local) 的变换矩阵
27
+ * @param {vec3} center 中心点
28
+ * @param {vec3} xaxis x轴
29
+ * @param {vec3} yaxis y轴
30
+ * @param {vec3} zaxis z轴
31
+ * @returns { mat4 } 变换矩阵
32
+ */
33
+ export function getW2LMatrix(center: vec3, xaxis: vec3, yaxis: vec3, zaxis: vec3): mat4;
34
+ /**
35
+ * 计算 l2w(local 2 word, local to word) 的变换矩阵
36
+ * @param {vec3} center 中心点
37
+ * @param {vec3} xaxis x轴
38
+ * @param {vec3} yaxis y轴
39
+ * @param {vec3} zaxis z轴
40
+ * @returns { mat4 } 变换矩阵
41
+ */
42
+ export function getL2WMatrix(center: vec3, xaxis: vec3, yaxis: vec3, zaxis: vec3): mat4;
43
+ /**
44
+ * 返回交互的interactorStyle
45
+ * @returns {vtkInteractorStyleManipulator} 交互的interactorStyle
46
+ */
47
+ export function make3DInteractorStyle(): vtkInteractorStyleManipulator;
48
+ /**
49
+ * 移除并返回当前renderWindow的所有鼠标交互设定
50
+ * @param {vtkRenderWindowInteractor} interactor vtkRenderWindowInteractor
51
+ * @returns {any[]} 当前鼠标的所有交互Manipulators
52
+ */
53
+ export function removeMouseInteraction(interactor: vtkRenderWindowInteractor): any[];
54
+ /**
55
+ * 给当前窗口设置交互Maintainers
56
+ * @param {vtkRenderWindowInteractor} interactor vtkRenderWindowInteractor
57
+ * @param {any[]} mm 所有的交互Maintainers
58
+ * @returns {void}
59
+ */
60
+ export function resetAllMouseMaintainers(interactor: vtkRenderWindowInteractor, mm: any[]): void;
61
+ /**
62
+ * 将点投影到平面上
63
+ * @param {vec3} point 需要投影的点
64
+ * @param {vec3} origin 平面中心点
65
+ * @param {vec3} normal 平面法向量
66
+ * @returns {vec3} 投影到平面之后的点
67
+ */
68
+ export function projectPointToPlane(point: vec3, origin: vec3, normal: vec3): vec3;
69
+ /**
70
+ * 将向量投影到面上
71
+ *
72
+ * @param {vec3} vec - The vector to project.
73
+ * @param {vec3} norm - The normal vector of the plane (assumed to be normalized).
74
+ * @returns {vec3} - The projected vector on the plane.
75
+ */
76
+ export function projectVecToPlane(vec: vec3, norm: vec3): vec3;
77
+ /**
78
+ * 将直线外一点投影到直线(两个点)上
79
+ * @param {vec3} point 直线外一点
80
+ * @param {vec3} begin 直线开始点
81
+ * @param {vec3} end 直线结束点
82
+ * @returns {vec3} 投影后的点
83
+ */
84
+ export function projectPointOnPoints(point: vec3, begin: vec3, end: vec3): vec3;
85
+ /**
86
+ * 将点投影到直线(point+dir)上
87
+ * @param {vec3} point 直线外的点
88
+ * @param {vec3} linePoint 直线任意一点
89
+ * @param {vec3} lineDir 直线方向
90
+ * @returns {vec3} 投影到直线上后的点
91
+ */
92
+ export function projectPointToLine(point: vec3, linePoint: vec3, lineDir: vec3): vec3;
93
+ /**
94
+ * 获取曲线外一点到曲线最近点的索引
95
+ * @param {vec3} point 曲线外一点
96
+ * @param {vec3[]} points 曲线
97
+ * @returns {number} 返回离点最近的曲线点索引
98
+ */
99
+ export function getPointToPointsMinIndex(point: vec3, points: vec3[]): number;
100
+ /**
101
+ * 获取点到曲线的最近距离
102
+ * @param {vec3} point 曲线外一点
103
+ * @param {vec3[]} points 曲线
104
+ * @returns {number} 返回点到曲线的最近距离
105
+ */
106
+ export function getPointToPointsMinDist(point: vec3, points: vec3[]): number;
107
+ /**
108
+ * 获取点到曲线的最近点
109
+ * @param {vec3} point 曲线外一点
110
+ * @param {vec3[]} points 曲线
111
+ * @returns {vec3} 返回点到曲线的最近点
112
+ */
113
+ export function getPointToPointsMinPoint(point: vec3, points: vec3[]): vec3;
114
+ /**
115
+ * 获取直线外一点到直线的距离
116
+ * @param {vec3} point 直线外一点
117
+ * @param {vec3} begin 直线开始点
118
+ * @param {vec3} end 直线结束点
119
+ * @returns {number} 点到直线的距离
120
+ */
121
+ export function getPointToLineDist(point: vec3, begin: vec3, end: vec3): number;
122
+ /**
123
+ * 计算点到平面的距离
124
+ * @param {vec3} point 任意一点
125
+ * @param {vec3} origin 平面上一点
126
+ * @param {vec3} normal 平面法向量,要求单位化
127
+ * @returns {number}
128
+ */
129
+ export function getPointToPlaneDist(point: vec3, origin: vec3, normal: vec3): number;
130
+ /**
131
+ * 对一个polydata应用矩阵变化,直接改变点位置
132
+ * @param {mat4} mt4 变换矩阵
133
+ * @param {vtkPolyData} data 需要应用变换的polydata
134
+ */
135
+ export function pointsApplyMat4(mt4: mat4, data: vtkPolyData): void;
136
+ /**
137
+ * 将点应用矩阵变换
138
+ * @param {vec3} point 三维点
139
+ * @param {mat4} matrix 变换矩阵
140
+ * @returns {vec3} 应用矩阵变换之后的点
141
+ */
142
+ export function pointTransformByMat4(point: vec3, matrix: mat4): vec3;
143
+ /**
144
+ * 将向量应用矩阵变换
145
+ * @param {vec3} vec 向量
146
+ * @param {mat4} matrix 变换矩阵
147
+ * @returns {vec3} 应用矩阵变换之后的向量
148
+ */
149
+ export function vecTransfromByMat4(vec: vec3, matrix: mat4): vec3;
150
+ /**
151
+ * 获取mesh的ply文件Blob
152
+ * @param {vtkPolyData} mesh 网格polydata
153
+ * @param {'ascii' | 'binary'} [format='ascii'] format 导出文件格式
154
+ * @returns {Blob} 网格的ply文件Blob
155
+ */
156
+ export function createPlyBlob(mesh: vtkPolyData, format?: "ascii" | "binary"): Blob;
157
+ /**
158
+ * 获取mesh的stl文件Blob,由于STL文件过大,只使用Binary格式
159
+ * @param {vtkPolyData} mesh 网格polydata
160
+ * @returns {Blob} 网格的BinarySTL文件Blob
161
+ */
162
+ export function createStlBlob(mesh: vtkPolyData): Blob;
163
+ /**
164
+ * 将网格压缩为drc文件,导出drc需要先加载draco_encode.js,并调用initDrcCoder初始化
165
+ * @param {vtkPolyData} mesh 网格文件
166
+ * @returns {Blob} drc文件
167
+ */
168
+ export function createDrcBlob(mesh: vtkPolyData): Blob;
169
+ /**
170
+ * 将网格输出为对应类型的Blob,均采用默认参数,导出drc需要先加载draco_encode.js,并调用initDrcCoder初始化
171
+ * @param {vtkPolyData} mesh 网格文件
172
+ * @param {'ply' | 'stl' | 'drc' } type 输出类型
173
+ * @returns {Blob} 对应类型的Blob
174
+ */
175
+ export function createMeshTypeBlob(mesh: vtkPolyData, type: "ply" | "stl" | "drc"): Blob;
176
+ /**
177
+ * 计算一组三维点的中心点
178
+ * @param {vec3[]} points 三维点数组
179
+ * @returns {vec3} 中心点
180
+ */
181
+ export function getPointsCenter(points: vec3[]): vec3;
182
+ /**
183
+ * @typedef Position
184
+ * @property {number} x 对应vtk坐标系的x值
185
+ * @property {number} y 对应vtk坐标系的y值
186
+ * @property {number} z 0
187
+ */
188
+ /**
189
+ * 计算js事件对应vtk事件的position
190
+ * @param {HTMLElement} el vtkViewDom
191
+ * @param {MouseEvent} event 二维鼠标事件
192
+ * @returns {Position} 对应vtk坐标系的xyz值
193
+ */
194
+ export function getScreenEventPositionFor(el: HTMLElement, event: MouseEvent): Position;
195
+ /**
196
+ * 将数值数组转换为vec3数组
197
+ * @param {number[] | Float32Array} dataList
198
+ * @returns {vec3[]} 格式化之后的数组
199
+ */
200
+ export function formatNumberArrayToVec3Array(dataList: number[] | Float32Array): vec3[];
201
+ /**
202
+ * 简单的数值平均插值
203
+ * @param {number} from 开始数值
204
+ * @param {number} to 结束数值
205
+ * @param {number} step 步长
206
+ * @returns {number[]} 插值的数值
207
+ */
208
+ export function calculateSimpleLerp(from: number, to: number, step: number): number[];
209
+ /**
210
+ * 将 mat3 解析为 3 个自由度的 欧拉角(Eular)(弧度)
211
+ * @param {mat3} rmat 3 * 3的矩阵
212
+ * @param {[number, number, number]} eular 输出的欧拉角度数(弧度)
213
+ * @returns {[number, number, number]} 3个自由度的欧拉角
214
+ * @example
215
+ * const mt4: mat4;
216
+ * const mt3 = mat3.fromMat4(mt3, mt4);
217
+ * mat3.transpose(mt3, mt3);
218
+ * let eular = [0, 0, 0];
219
+ * convMatrix2EularZYX(mt3, eular);
220
+ */
221
+ export function convMatrix2EularZYX(rmat: mat3, eular: [number, number, number]): [number, number, number];
222
+ /**
223
+ * 将欧拉角(Eular)转换为mat3
224
+ * @param {mat3} rmat 变换矩阵
225
+ * @param {number} xangle 对应欧拉角x 弧度
226
+ * @param {number} yangle 对应欧拉角y 弧度
227
+ * @param {number} zangle 对应欧拉加z 弧度
228
+ * @returns {mat3} 对应变换矩阵
229
+ * @example
230
+ * const rotateX = 0.5;
231
+ * const rotateY = 0.5;
232
+ * const rotateZ = 0.5;
233
+ * const mt3 = mat3.create();
234
+ * convEular2matrixZYX(mt3, [rotateX, rotateY, rotateZ])
235
+ */
236
+ export function convEular2matrixZYX(rmat: mat3, xangle: number, yangle: number, zangle: number): mat3;
237
+ /**
238
+ * 将drc
239
+ * @param {vtkPolyData} mesh 网格polyData
240
+ * @param {mat4} [matrix] 变换矩阵
241
+ * @returns {string} drc压缩之后的网格base64
242
+ */
243
+ export function enCodeMeshToBase64(mesh: vtkPolyData, matrix?: mat4): string;
244
+ /**
245
+ * 将一圈有序点按指定size进行平滑
246
+ * @param {vec3[]} points 一圈有序点
247
+ * @param {number} smaSize=3 平滑点的数量通常值为奇数
248
+ * @returns {vec3[]} 平滑之后的点
249
+ */
250
+ export function smaPoint(points: vec3[], smaSize?: number): vec3[];
251
+ /**
252
+ * 将一段有序点按指定size进行平滑
253
+ * @param {vec3[]} points 一段有序点
254
+ * @param {number} smaSize=3 平滑点的数量通常值为奇数
255
+ * @returns {vec3[]} 平滑之后的点
256
+ */
257
+ export function smaPointNotRound(points: vec3[], smaSize?: number): vec3[];
258
+ /**
259
+ * 表示一个包含三个轴向的对象
260
+ * @typedef {Object} AxisObject
261
+ * @property {vec3} x - x轴
262
+ * @property {vec3} y - y轴
263
+ * @property {vec3} z - z轴
264
+ */
265
+ /**
266
+ * 获取一个矩阵的三个轴向
267
+ * @param {mat4} matrix 4 * 4 的矩阵
268
+ * @returns {AxisObject} 三个轴向
269
+ */
270
+ export function getAxisFormMat4(matrix: mat4): AxisObject;
271
+ /**
272
+ * 计算 w2l(word 2 local, word to local) 的变换矩阵
273
+ * @param {vec3} center 中心点
274
+ * @param {vec3} xaxis x轴
275
+ * @param {vec3} yaxis y轴
276
+ * @param {vec3} zaxis z轴
277
+ * @returns { mat4 } 变换矩阵
278
+ */
279
+ export function getmatw2l(center: vec3, xaxis: vec3, yaxis: vec3, zaxis: vec3): mat4;
280
+ /**
281
+ * 计算 l2w(local 2 word, local to word) 的变换矩阵
282
+ * @param {vec3} center 中心点
283
+ * @param {vec3} xaxis x轴
284
+ * @param {vec3} yaxis y轴
285
+ * @param {vec3} zaxis z轴
286
+ * @returns { mat4 } 变换矩阵
287
+ */
288
+ export function getmatofl2w(center: vec3, xaxis: vec3, yaxis: vec3, zaxis: vec3): mat4;
289
+ export function deduplicatePolyData(data: vtkPolyData): vtkPolyData;
290
+ export type Position = {
291
+ /**
292
+ * 对应vtk坐标系的x值
293
+ */
294
+ x: number;
295
+ /**
296
+ * 对应vtk坐标系的y值
297
+ */
298
+ y: number;
299
+ /**
300
+ * 0
301
+ */
302
+ z: number;
303
+ };
304
+ /**
305
+ * 表示一个包含三个轴向的对象
306
+ */
307
+ export type AxisObject = {
308
+ /**
309
+ * - x轴
310
+ */
311
+ x: vec3;
312
+ /**
313
+ * - y轴
314
+ */
315
+ y: vec3;
316
+ /**
317
+ * - z轴
318
+ */
319
+ z: vec3;
320
+ };