copper3d 1.15.23 → 2.0.2

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.
Files changed (94) hide show
  1. package/README.md +2 -2
  2. package/dist/Loader/copperNrrdLoader.d.ts +1 -1
  3. package/dist/Renderer/baseRenderer.d.ts +2 -2
  4. package/dist/Renderer/baseRenderer.js +2 -2
  5. package/dist/Renderer/baseRenderer.js.map +1 -1
  6. package/dist/Renderer/copperMSceneRenderer.d.ts +2 -2
  7. package/dist/Renderer/copperMSceneRenderer.js +2 -2
  8. package/dist/Renderer/copperMSceneRenderer.js.map +1 -1
  9. package/dist/Renderer/copperRenderer.d.ts +4 -4
  10. package/dist/Renderer/copperRenderer.js +3 -3
  11. package/dist/Renderer/copperRenderer.js.map +1 -1
  12. package/dist/Renderer/copperRendererOnDemond.d.ts +4 -5
  13. package/dist/Renderer/copperRendererOnDemond.js +3 -3
  14. package/dist/Renderer/copperRendererOnDemond.js.map +1 -1
  15. package/dist/Scene/baseScene.d.ts +2 -2
  16. package/dist/Scene/baseScene.js +2 -2
  17. package/dist/Scene/baseScene.js.map +1 -1
  18. package/dist/Scene/commonSceneMethod.d.ts +1 -1
  19. package/dist/Scene/commonSceneMethod.js +1 -1
  20. package/dist/Scene/commonSceneMethod.js.map +1 -1
  21. package/dist/Scene/copperMScene.d.ts +2 -2
  22. package/dist/Scene/copperMScene.js +2 -2
  23. package/dist/Scene/copperMScene.js.map +1 -1
  24. package/dist/Scene/copperScene.d.ts +2 -2
  25. package/dist/Scene/copperScene.js +2 -2
  26. package/dist/Scene/copperScene.js.map +1 -1
  27. package/dist/Scene/copperSceneOnDemond.d.ts +2 -2
  28. package/dist/Scene/copperSceneOnDemond.js +2 -2
  29. package/dist/Scene/copperSceneOnDemond.js.map +1 -1
  30. package/dist/Utils/add3DLabel.d.ts +2 -2
  31. package/dist/Utils/segmentation/CommToolsData.d.ts +71 -0
  32. package/dist/Utils/segmentation/CommToolsData.js +267 -0
  33. package/dist/Utils/segmentation/CommToolsData.js.map +1 -0
  34. package/dist/Utils/segmentation/DragOperator.d.ts +30 -0
  35. package/dist/Utils/segmentation/DragOperator.js +243 -0
  36. package/dist/Utils/segmentation/DragOperator.js.map +1 -0
  37. package/dist/Utils/segmentation/DrawToolCore.d.ts +78 -0
  38. package/dist/Utils/segmentation/DrawToolCore.js +1083 -0
  39. package/dist/Utils/segmentation/DrawToolCore.js.map +1 -0
  40. package/dist/Utils/segmentation/NrrdTools.d.ts +178 -0
  41. package/dist/Utils/segmentation/NrrdTools.js +965 -0
  42. package/dist/Utils/segmentation/NrrdTools.js.map +1 -0
  43. package/dist/Utils/segmentation/coreTools/archive.d.ts +1 -0
  44. package/dist/Utils/segmentation/coreTools/archive.js +23 -0
  45. package/dist/Utils/segmentation/coreTools/archive.js.map +1 -0
  46. package/dist/Utils/segmentation/coreTools/coreType.d.ts +206 -0
  47. package/dist/Utils/segmentation/coreTools/coreType.js +2 -0
  48. package/dist/Utils/segmentation/coreTools/coreType.js.map +1 -0
  49. package/dist/Utils/segmentation/coreTools/divControlTools.d.ts +19 -0
  50. package/dist/Utils/segmentation/coreTools/divControlTools.js +48 -0
  51. package/dist/Utils/segmentation/coreTools/divControlTools.js.map +1 -0
  52. package/dist/Utils/segmentation/coreTools/gui.d.ts +123 -0
  53. package/dist/Utils/segmentation/coreTools/gui.js +307 -0
  54. package/dist/Utils/segmentation/coreTools/gui.js.map +1 -0
  55. package/dist/Utils/utils.d.ts +1 -1
  56. package/dist/Utils/utils.js +25 -10
  57. package/dist/Utils/utils.js.map +1 -1
  58. package/dist/Utils/workers/reformatSaveDataWorker.d.ts +3 -3
  59. package/dist/Utils/workers/reformatSaveDataWorker.js.map +1 -1
  60. package/dist/bundle.esm.js +2577 -2228
  61. package/dist/bundle.umd.js +2578 -2228
  62. package/dist/css/style.css +2 -18
  63. package/dist/index.d.ts +13 -11
  64. package/dist/index.js +11 -10
  65. package/dist/index.js.map +1 -1
  66. package/dist/types/Loader/copperNrrdLoader.d.ts +1 -1
  67. package/dist/types/Renderer/baseRenderer.d.ts +2 -2
  68. package/dist/types/Renderer/copperMSceneRenderer.d.ts +2 -2
  69. package/dist/types/Renderer/copperRenderer.d.ts +4 -4
  70. package/dist/types/Renderer/copperRendererOnDemond.d.ts +4 -5
  71. package/dist/types/Scene/baseScene.d.ts +2 -2
  72. package/dist/types/Scene/commonSceneMethod.d.ts +1 -1
  73. package/dist/types/Scene/copperMScene.d.ts +2 -2
  74. package/dist/types/Scene/copperScene.d.ts +2 -2
  75. package/dist/types/Scene/copperSceneOnDemond.d.ts +2 -2
  76. package/dist/types/Utils/add3DLabel.d.ts +2 -2
  77. package/dist/types/Utils/segmentation/CommToolsData.d.ts +71 -0
  78. package/dist/types/Utils/segmentation/DragOperator.d.ts +30 -0
  79. package/dist/types/Utils/segmentation/DrawToolCore.d.ts +78 -0
  80. package/dist/types/Utils/segmentation/NrrdTools.d.ts +178 -0
  81. package/dist/types/Utils/segmentation/coreTools/archive.d.ts +1 -0
  82. package/dist/types/Utils/segmentation/coreTools/coreType.d.ts +206 -0
  83. package/dist/types/Utils/segmentation/coreTools/divControlTools.d.ts +19 -0
  84. package/dist/types/Utils/segmentation/coreTools/gui.d.ts +123 -0
  85. package/dist/types/Utils/utils.d.ts +1 -1
  86. package/dist/types/Utils/workers/reformatSaveDataWorker.d.ts +3 -3
  87. package/dist/types/index.d.ts +13 -11
  88. package/dist/types/types/types.d.ts +4 -38
  89. package/dist/types/types.d.ts +4 -38
  90. package/package.json +1 -1
  91. package/dist/Utils/nrrd_tool.d.ts +0 -269
  92. package/dist/Utils/nrrd_tool.js +0 -2480
  93. package/dist/Utils/nrrd_tool.js.map +0 -1
  94. package/dist/types/Utils/nrrd_tool.d.ts +0 -269
@@ -1,2480 +0,0 @@
1
- import * as THREE from "three";
2
- import { throttle } from "./utils";
3
- import { switchEraserSize, switchPencilIcon } from "./utils";
4
- import { saveFileAsJson } from "./download";
5
- import { restructData, convertReformatDataToBlob, } from "./workers/reformatSaveDataWorker";
6
- export class nrrd_tools {
7
- constructor(container) {
8
- // used to store one label all marks
9
- this.paintImagesLabel1 = { x: [], y: [], z: [] };
10
- this.paintImagesLabel2 = { x: [], y: [], z: [] };
11
- this.paintImagesLabel3 = { x: [], y: [], z: [] };
12
- this.storedPaintImages = {
13
- label1: this.paintImagesLabel1,
14
- label2: this.paintImagesLabel2,
15
- label3: this.paintImagesLabel3,
16
- };
17
- // used to store display marks with multiple labels
18
- this.paintImages = { x: [], y: [], z: [] };
19
- // store all contrast slices, include x, y, z orientation
20
- this.allSlicesArray = [];
21
- // to store all display slices, only include one orientation (e.g, x,y,z) for all contrast slices.
22
- this.displaySlices = [];
23
- // Designed for reload displaySlices Array, only one orientation!
24
- this.backUpDisplaySlices = [];
25
- this.skipSlicesDic = {};
26
- // The default axis for all contrast slice is set to "z" orientation.
27
- // If we want to switch different orientation, we can set the axis outside.
28
- this.axis = "z";
29
- // A base conatainer to append displayCanvas and drawingCanvas
30
- this.mainAreaContainer = document.createElement("div");
31
- this.showDragNumberDiv = document.createElement("div");
32
- this.drawingCanvas = document.createElement("canvas");
33
- this.displayCanvas = document.createElement("canvas");
34
- this.downloadCanvas = document.createElement("canvas");
35
- this.drawingSphereCanvas = document.createElement("canvas");
36
- // use to convert the store image with original size in storeAllImages function!
37
- this.emptyCanvas = document.createElement("canvas");
38
- this.downloadImage = document.createElement("a");
39
- this.drawingCanvasLayerMaster = document.createElement("canvas");
40
- this.drawingCanvasLayerOne = document.createElement("canvas");
41
- this.drawingCanvasLayerTwo = document.createElement("canvas");
42
- this.drawingCanvasLayerThree = document.createElement("canvas");
43
- this.Is_Shift_Pressed = false;
44
- this.Is_Draw = false;
45
- this.sensitiveArray = [];
46
- this.start = () => { };
47
- this.undoArray = [];
48
- this.initState = true;
49
- this.eraserUrls = [];
50
- this.pencilUrls = [];
51
- this.nrrd_states = {
52
- originWidth: 0,
53
- originHeight: 0,
54
- nrrd_x_mm: 0,
55
- nrrd_y_mm: 0,
56
- nrrd_z_mm: 0,
57
- nrrd_x_pixel: 0,
58
- nrrd_y_pixel: 0,
59
- nrrd_z_pixel: 0,
60
- changedWidth: 0,
61
- changedHeight: 0,
62
- oldIndex: 0,
63
- currentIndex: 0,
64
- maxIndex: 0,
65
- minIndex: 0,
66
- RSARatio: 0,
67
- voxelSpacing: [],
68
- spaceOrigin: [],
69
- dimensions: [],
70
- loadMaskJson: false,
71
- ratios: { x: 1, y: 1, z: 1 },
72
- sharedPlace: { x: [-1], y: [-1], z: [-1] },
73
- latestNotEmptyImg: new Image(),
74
- contrastNum: 0,
75
- Max_sensitive: 100,
76
- readyToUpdate: true,
77
- showContrast: false,
78
- enableCursorChoose: false,
79
- isCursorSelect: false,
80
- cursorPageX: 0,
81
- cursorPageY: 0,
82
- // x: [cursorX, cursorY, sliceIndex]
83
- sphereOrigin: { x: [0, 0, 0], y: [0, 0, 0], z: [0, 0, 0] },
84
- spherePlanB: true,
85
- sphereRadius: 10,
86
- Mouse_Over_x: 0,
87
- Mouse_Over_y: 0,
88
- Mouse_Over: false,
89
- stepClear: 1,
90
- sizeFoctor: 1,
91
- clearAllFlag: false,
92
- previousPanelL: -99999,
93
- previousPanelT: -99999,
94
- switchSliceFlag: false,
95
- labels: ["label1", "label2", "label3"],
96
- getMask: (mask, sliceId, label, width, height, clearAllFlag) => { },
97
- getSphere: (sphereOrigin, sphereRadius) => { },
98
- defaultPaintCursor: switchPencilIcon("dot"),
99
- drawStartPos: new THREE.Vector2(1, 1),
100
- };
101
- this.cursorPage = {
102
- x: {
103
- cursorPageX: 0,
104
- cursorPageY: 0,
105
- index: 0,
106
- updated: false,
107
- },
108
- y: {
109
- cursorPageX: 0,
110
- cursorPageY: 0,
111
- index: 0,
112
- updated: false,
113
- },
114
- z: {
115
- cursorPageX: 0,
116
- cursorPageY: 0,
117
- index: 0,
118
- updated: false,
119
- },
120
- };
121
- this.gui_states = {
122
- mainAreaSize: 1,
123
- dragSensitivity: 75,
124
- Eraser: false,
125
- globalAlpha: 0.7,
126
- lineWidth: 2,
127
- color: "#f50a33",
128
- segmentation: true,
129
- fillColor: "#00ff00",
130
- brushColor: "#00ff00",
131
- brushAndEraserSize: 15,
132
- cursor: "dot",
133
- label: "label1",
134
- sphere: false,
135
- // EraserSize: 25,
136
- clear: () => {
137
- this.clearPaint();
138
- },
139
- clearAll: () => {
140
- const text = "Are you sure remove annotations on All slice?";
141
- if (confirm(text) === true) {
142
- this.nrrd_states.clearAllFlag = true;
143
- this.clearPaint();
144
- this.clearStoreImages();
145
- }
146
- this.nrrd_states.clearAllFlag = false;
147
- },
148
- undo: () => {
149
- this.undoLastPainting();
150
- },
151
- downloadCurrentMask: () => {
152
- this.enableDownload();
153
- },
154
- resetZoom: () => {
155
- this.nrrd_states.sizeFoctor = 1;
156
- this.resizePaintArea(1);
157
- this.resetPaintArea();
158
- },
159
- subView: false,
160
- subViewScale: 1.0,
161
- resetView: () => {
162
- var _a;
163
- (_a = this.sceneIn) === null || _a === void 0 ? void 0 : _a.resetView();
164
- },
165
- exportMarks: () => {
166
- // const a = [1, 2, 3, 4];
167
- this.exportData();
168
- },
169
- };
170
- this.dragPrameters = {
171
- move: 0,
172
- y: 0,
173
- h: 0,
174
- sensivity: 1,
175
- handleOnDragMouseUp: (ev) => { },
176
- handleOnDragMouseDown: (ev) => { },
177
- handleOnDragMouseMove: (ev) => { },
178
- };
179
- this.drawingPrameters = {
180
- handleOnDrawingMouseDown: (ev) => { },
181
- handleOnDrawingMouseMove: (ev) => { },
182
- handleOnPanMouseMove: (ev) => { },
183
- handleOnDrawingMouseUp: (ev) => { },
184
- handleOnDrawingMouseLeave: (ev) => { },
185
- handleOnDrawingBrushCricleMove: (ev) => { },
186
- handleZoomWheel: (e) => { },
187
- handleSphereWheel: (e) => { },
188
- };
189
- this.configDragMode = () => {
190
- this.container.style.cursor = "pointer";
191
- this.container.addEventListener("pointerdown", this.dragPrameters.handleOnDragMouseDown, true);
192
- this.container.addEventListener("pointerup", this.dragPrameters.handleOnDragMouseUp, true);
193
- };
194
- this.removeDragMode = () => {
195
- this.container.style.cursor = "";
196
- this.container.removeEventListener("pointerdown", this.dragPrameters.handleOnDragMouseDown, true);
197
- this.container.removeEventListener("pointerup", this.dragPrameters.handleOnDragMouseUp, true);
198
- this.setIsDrawFalse(1000);
199
- };
200
- this.drawLine = (x1, y1, x2, y2) => {
201
- this.drawingCtx.beginPath();
202
- this.drawingCtx.moveTo(x1, y1);
203
- this.drawingCtx.lineTo(x2, y2);
204
- this.drawingCtx.strokeStyle = this.gui_states.color;
205
- this.drawingCtx.stroke();
206
- };
207
- this.container = container;
208
- this.displayCtx = this.displayCanvas.getContext("2d");
209
- this.drawingCtx = this.drawingCanvas.getContext("2d");
210
- this.emptyCtx = this.emptyCanvas.getContext("2d");
211
- this.drawingSphereCtx = this.drawingSphereCanvas.getContext("2d");
212
- this.drawingLayerMasterCtx = this.drawingCanvasLayerMaster.getContext("2d");
213
- this.drawingLayerOneCtx = this.drawingCanvasLayerOne.getContext("2d");
214
- this.drawingLayerTwoCtx = this.drawingCanvasLayerTwo.getContext("2d");
215
- this.drawingLayerThreeCtx = this.drawingCanvasLayerThree.getContext("2d");
216
- this.previousDrawingImage = this.emptyCtx.createImageData(1, 1);
217
- this.init();
218
- }
219
- /**
220
- * A initialise function for nrrd_tools
221
- */
222
- init() {
223
- this.showDragNumberDiv = this.createShowSliceNumberDiv();
224
- this.mainAreaContainer.classList.add("copper3D_drawingCanvasContainer");
225
- this.container.appendChild(this.mainAreaContainer);
226
- this.autoFocusDiv(this.container);
227
- this.downloadImage.href = "";
228
- this.downloadImage.target = "_blank";
229
- for (let i = 0; i < this.nrrd_states.Max_sensitive; i++) {
230
- this.sensitiveArray.push((i + 1) / 20);
231
- }
232
- this.container.addEventListener("keydown", (ev) => {
233
- if (ev.key === "Shift" && !this.gui_states.sphere) {
234
- this.Is_Shift_Pressed = true;
235
- this.nrrd_states.enableCursorChoose = false;
236
- }
237
- if (ev.key === "s") {
238
- this.Is_Draw = false;
239
- this.nrrd_states.enableCursorChoose =
240
- !this.nrrd_states.enableCursorChoose;
241
- }
242
- });
243
- this.container.addEventListener("keyup", (ev) => {
244
- if (ev.key === "Shift") {
245
- this.Is_Shift_Pressed = false;
246
- }
247
- });
248
- }
249
- /**
250
- *
251
- * entry function
252
- *
253
- * @param allSlices - all nrrd contrast slices
254
- * {
255
- * x:slice,
256
- * y:slice,
257
- * z:slice
258
- * }
259
- */
260
- setAllSlices(allSlices) {
261
- this.allSlicesArray = [...allSlices];
262
- this.nrrd_states.nrrd_x_mm = this.allSlicesArray[0].z.canvas.width;
263
- this.nrrd_states.nrrd_y_mm = this.allSlicesArray[0].z.canvas.height;
264
- this.nrrd_states.nrrd_z_mm = this.allSlicesArray[0].x.canvas.width;
265
- this.nrrd_states.nrrd_x_pixel =
266
- this.allSlicesArray[0].x.volume.dimensions[0];
267
- this.nrrd_states.nrrd_y_pixel =
268
- this.allSlicesArray[0].x.volume.dimensions[1];
269
- this.nrrd_states.nrrd_z_pixel =
270
- this.allSlicesArray[0].x.volume.dimensions[2];
271
- this.nrrd_states.voxelSpacing = this.allSlicesArray[0].x.volume.spacing;
272
- this.nrrd_states.ratios.x = this.allSlicesArray[0].x.volume.spacing[0];
273
- this.nrrd_states.ratios.y = this.allSlicesArray[0].x.volume.spacing[1];
274
- this.nrrd_states.ratios.z = this.allSlicesArray[0].x.volume.spacing[2];
275
- this.nrrd_states.dimensions = this.allSlicesArray[0].x.volume.dimensions;
276
- this.allSlicesArray.forEach((item, index) => {
277
- item.x.contrastOrder = index;
278
- item.y.contrastOrder = index;
279
- item.z.contrastOrder = index;
280
- });
281
- this.nrrd_states.spaceOrigin = this.allSlicesArray[0].x.volume.header.space_origin.map((item) => {
282
- return item * 1;
283
- });
284
- this.nrrd_states.sharedPlace.x = this.getSharedPlace(this.nrrd_states.dimensions[0], this.nrrd_states.ratios.x);
285
- this.nrrd_states.sharedPlace.y = this.getSharedPlace(this.nrrd_states.dimensions[1], this.nrrd_states.ratios.y);
286
- this.nrrd_states.sharedPlace.z = this.getSharedPlace(this.nrrd_states.dimensions[2], this.nrrd_states.ratios.z);
287
- // init paintImages array
288
- this.initPaintImages(this.nrrd_states.dimensions);
289
- // init displayslices array, the axis default is "z"
290
- this.setDisplaySlicesBaseOnAxis();
291
- this.afterLoadSlice();
292
- }
293
- loadingMaskByLabel(masks, index, imageData) {
294
- let imageDataLable = this.emptyCtx.createImageData(this.nrrd_states.nrrd_x_pixel, this.nrrd_states.nrrd_y_pixel);
295
- this.setEmptyCanvasSize();
296
- for (let j = 0; j < masks[index].data.length; j++) {
297
- imageDataLable.data[j] = masks[index].data[j];
298
- imageData.data[j] += masks[index].data[j];
299
- }
300
- return imageDataLable;
301
- }
302
- setMasksData(masksData, loadingBar) {
303
- if (!!masksData) {
304
- this.nrrd_states.loadMaskJson = true;
305
- if (loadingBar) {
306
- let { loadingContainer, progress } = loadingBar;
307
- loadingContainer.style.display = "flex";
308
- progress.innerText = "Loading masks data......";
309
- }
310
- this.setEmptyCanvasSize();
311
- const len = masksData["label1"].length;
312
- for (let i = 0; i < len; i++) {
313
- let imageData = this.emptyCtx.createImageData(this.nrrd_states.nrrd_x_pixel, this.nrrd_states.nrrd_y_pixel);
314
- let imageDataLabel1, imageDataLabel2, imageDataLabel3;
315
- if (masksData["label1"][i].data.length > 0) {
316
- this.setEmptyCanvasSize();
317
- imageDataLabel1 = this.loadingMaskByLabel(masksData["label1"], i, imageData);
318
- this.emptyCtx.putImageData(imageDataLabel1, 0, 0);
319
- this.storeEachLayerImage(i, "label1");
320
- }
321
- if (masksData["label2"][i].data.length > 0) {
322
- this.setEmptyCanvasSize();
323
- imageDataLabel2 = this.loadingMaskByLabel(masksData["label2"], i, imageData);
324
- this.emptyCtx.putImageData(imageDataLabel2, 0, 0);
325
- this.storeEachLayerImage(i, "label2");
326
- }
327
- if (masksData["label3"][i].data.length > 0) {
328
- this.setEmptyCanvasSize();
329
- imageDataLabel3 = this.loadingMaskByLabel(masksData["label3"], i, imageData);
330
- this.emptyCtx.putImageData(imageDataLabel3, 0, 0);
331
- this.storeEachLayerImage(i, "label3");
332
- }
333
- this.setEmptyCanvasSize();
334
- this.emptyCtx.putImageData(imageData, 0, 0);
335
- this.storeAllImages(i, "default");
336
- }
337
- this.nrrd_states.loadMaskJson = false;
338
- this.gui_states.resetZoom();
339
- if (loadingBar) {
340
- loadingBar.loadingContainer.style.display = "none";
341
- }
342
- }
343
- }
344
- setEraserUrls(urls) {
345
- this.eraserUrls = urls;
346
- }
347
- setPencilIconUrls(urls) {
348
- this.pencilUrls = urls;
349
- this.nrrd_states.defaultPaintCursor = switchPencilIcon("dot", this.pencilUrls);
350
- this.drawingCanvas.style.cursor = this.nrrd_states.defaultPaintCursor;
351
- }
352
- getCurrentImageDimension() {
353
- return this.nrrd_states.dimensions;
354
- }
355
- getVoxelSpacing() {
356
- return this.nrrd_states.voxelSpacing;
357
- }
358
- getSpaceOrigin() {
359
- return this.nrrd_states.spaceOrigin;
360
- }
361
- getSharedPlace(len, ratio) {
362
- let old = -1;
363
- let same = [];
364
- let temp = new Set();
365
- for (let i = 0; i < len; i++) {
366
- const index = Math.floor(i * ratio);
367
- if (index === old) {
368
- temp.add(i - 1);
369
- temp.add(i);
370
- }
371
- else {
372
- old = index;
373
- }
374
- }
375
- temp.forEach((value) => {
376
- same.push(value);
377
- });
378
- return same;
379
- }
380
- /**
381
- * init all painted images for store images
382
- * @param dimensions
383
- */
384
- initPaintImages(dimensions) {
385
- this.createEmptyPaintImage(dimensions, this.paintImages);
386
- this.createEmptyPaintImage(dimensions, this.paintImagesLabel1);
387
- this.createEmptyPaintImage(dimensions, this.paintImagesLabel2);
388
- this.createEmptyPaintImage(dimensions, this.paintImagesLabel3);
389
- }
390
- createEmptyPaintImage(dimensions, paintImages) {
391
- for (let i = 0; i < dimensions[0]; i++) {
392
- const markImage_x = this.emptyCtx.createImageData(this.nrrd_states.nrrd_z_pixel, this.nrrd_states.nrrd_y_pixel);
393
- const initMark_x = {
394
- index: i,
395
- image: markImage_x,
396
- };
397
- paintImages.x.push(initMark_x);
398
- }
399
- // for y slices' marks
400
- for (let i = 0; i < dimensions[1]; i++) {
401
- const markImage_y = this.emptyCtx.createImageData(this.nrrd_states.nrrd_x_pixel, this.nrrd_states.nrrd_z_pixel);
402
- const initMark_y = {
403
- index: i,
404
- image: markImage_y,
405
- };
406
- paintImages.y.push(initMark_y);
407
- }
408
- // for z slices' marks
409
- for (let i = 0; i < dimensions[2]; i++) {
410
- const markImage_z = this.emptyCtx.createImageData(this.nrrd_states.nrrd_x_pixel, this.nrrd_states.nrrd_y_pixel);
411
- const initMark_z = {
412
- index: i,
413
- image: markImage_z,
414
- };
415
- paintImages.z.push(initMark_z);
416
- }
417
- }
418
- convertCursorPoint(from, to, cursorNumX, cursorNumY, currentSliceIndex) {
419
- const nrrd = this.nrrd_states;
420
- const dimensions = nrrd.dimensions;
421
- const ratios = nrrd.ratios;
422
- const { nrrd_x_mm, nrrd_y_mm, nrrd_z_mm } = nrrd;
423
- let currentIndex = 0;
424
- let oldIndex = 0;
425
- let convertCursorNumX = 0;
426
- let convertCursorNumY = 0;
427
- const convertIndex = {
428
- x: {
429
- y: (val) => Math.ceil((val / nrrd_x_mm) * dimensions[0]),
430
- z: (val) => Math.ceil((val / nrrd_z_mm) * dimensions[2]),
431
- },
432
- y: {
433
- x: (val) => Math.ceil((val / nrrd_y_mm) * dimensions[1]),
434
- z: (val) => Math.ceil((val / nrrd_z_mm) * dimensions[2]),
435
- },
436
- z: {
437
- x: (val) => Math.ceil((val / nrrd_x_mm) * dimensions[0]),
438
- y: (val) => Math.ceil((val / nrrd_y_mm) * dimensions[1]),
439
- },
440
- };
441
- const convertCursor = {
442
- x: {
443
- y: (sliceIndex) => Math.ceil((sliceIndex / dimensions[0]) * nrrd_x_mm),
444
- z: (sliceIndex) => Math.ceil((sliceIndex / dimensions[0]) * nrrd_x_mm),
445
- },
446
- y: {
447
- x: (sliceIndex) => Math.ceil((sliceIndex / dimensions[1]) * nrrd_y_mm),
448
- z: (sliceIndex) => Math.ceil((sliceIndex / dimensions[1]) * nrrd_y_mm),
449
- },
450
- z: {
451
- x: (sliceIndex) => Math.ceil((sliceIndex / dimensions[2]) * nrrd_z_mm),
452
- y: (sliceIndex) => Math.ceil((sliceIndex / dimensions[2]) * nrrd_z_mm),
453
- },
454
- };
455
- if (from === to) {
456
- return;
457
- }
458
- if (from === "z" && to === "x") {
459
- currentIndex = convertIndex[from][to](cursorNumX);
460
- oldIndex = currentIndex * ratios[to];
461
- convertCursorNumX = convertCursor[from][to](currentSliceIndex);
462
- convertCursorNumY = cursorNumY;
463
- }
464
- else if (from === "y" && to === "x") {
465
- currentIndex = convertIndex[from][to](cursorNumX);
466
- oldIndex = currentIndex * ratios.x;
467
- convertCursorNumY = convertCursor[from][to](currentSliceIndex);
468
- convertCursorNumX = cursorNumY;
469
- }
470
- else if (from === "z" && to === "y") {
471
- currentIndex = convertIndex[from][to](cursorNumY);
472
- oldIndex = currentIndex * ratios[to];
473
- convertCursorNumY = convertCursor[from][to](currentSliceIndex);
474
- convertCursorNumX = cursorNumX;
475
- }
476
- else if (from === "x" && to === "y") {
477
- currentIndex = convertIndex[from][to](cursorNumY);
478
- oldIndex = currentIndex * ratios[to];
479
- convertCursorNumX = convertCursor[from][to](currentSliceIndex);
480
- convertCursorNumY = cursorNumX;
481
- }
482
- else if (from === "x" && to === "z") {
483
- currentIndex = convertIndex[from][to](cursorNumX);
484
- oldIndex = currentIndex * ratios[to];
485
- convertCursorNumX = convertCursor[from][to](currentSliceIndex);
486
- convertCursorNumY = cursorNumY;
487
- }
488
- else if (from === "y" && to === "z") {
489
- currentIndex = convertIndex[from][to](cursorNumY);
490
- oldIndex = currentIndex * ratios.z;
491
- convertCursorNumY = convertCursor[from][to](currentSliceIndex);
492
- convertCursorNumX = cursorNumX;
493
- }
494
- else {
495
- return;
496
- }
497
- return { currentIndex, oldIndex, convertCursorNumX, convertCursorNumY };
498
- }
499
- /**
500
- * Switch all contrast slices' orientation
501
- * @param {string} aixs:"x" | "y" | "z"
502
- * */
503
- setSliceOrientation(axisTo) {
504
- let convetObj;
505
- if (this.nrrd_states.enableCursorChoose || this.gui_states.sphere) {
506
- if (this.axis === "z") {
507
- this.cursorPage.z.index = this.nrrd_states.currentIndex;
508
- this.cursorPage.z.cursorPageX = this.nrrd_states.cursorPageX;
509
- this.cursorPage.z.cursorPageY = this.nrrd_states.cursorPageY;
510
- }
511
- else if (this.axis === "x") {
512
- this.cursorPage.x.index = this.nrrd_states.currentIndex;
513
- this.cursorPage.x.cursorPageX = this.nrrd_states.cursorPageX;
514
- this.cursorPage.x.cursorPageY = this.nrrd_states.cursorPageY;
515
- }
516
- else if (this.axis === "y") {
517
- this.cursorPage.y.index = this.nrrd_states.currentIndex;
518
- this.cursorPage.y.cursorPageX = this.nrrd_states.cursorPageX;
519
- this.cursorPage.y.cursorPageY = this.nrrd_states.cursorPageY;
520
- }
521
- if (axisTo === "z") {
522
- if (this.nrrd_states.isCursorSelect && !this.cursorPage.z.updated) {
523
- if (this.axis === "x") {
524
- // convert x to z
525
- convetObj = this.convertCursorPoint("x", "z", this.cursorPage.x.cursorPageX, this.cursorPage.x.cursorPageY, this.cursorPage.x.index);
526
- }
527
- if (this.axis === "y") {
528
- // convert y to z
529
- convetObj = this.convertCursorPoint("y", "z", this.cursorPage.y.cursorPageX, this.cursorPage.y.cursorPageY, this.cursorPage.y.index);
530
- }
531
- }
532
- else {
533
- // not cursor select, freedom to switch x -> z or y -> z and z -> x or z -> y
534
- this.nrrd_states.currentIndex = this.cursorPage.z.index;
535
- this.nrrd_states.oldIndex =
536
- this.cursorPage.z.index * this.nrrd_states.ratios.z;
537
- this.nrrd_states.cursorPageX = this.cursorPage.z.cursorPageX;
538
- this.nrrd_states.cursorPageY = this.cursorPage.z.cursorPageY;
539
- }
540
- }
541
- else if (axisTo === "x") {
542
- if (this.nrrd_states.isCursorSelect && !this.cursorPage.x.updated) {
543
- if (this.axis === "z") {
544
- // convert z to x
545
- convetObj = this.convertCursorPoint("z", "x", this.cursorPage.z.cursorPageX, this.cursorPage.z.cursorPageY, this.cursorPage.z.index);
546
- }
547
- if (this.axis === "y") {
548
- // convert y to x
549
- convetObj = this.convertCursorPoint("y", "x", this.cursorPage.y.cursorPageX, this.cursorPage.y.cursorPageY, this.cursorPage.y.index);
550
- }
551
- }
552
- else {
553
- // not cursor select, freedom to switch z -> x or y -> x and x -> z or x -> y
554
- this.nrrd_states.currentIndex = this.cursorPage.x.index;
555
- this.nrrd_states.oldIndex =
556
- this.cursorPage.x.index * this.nrrd_states.ratios.x;
557
- this.nrrd_states.cursorPageX = this.cursorPage.x.cursorPageX;
558
- this.nrrd_states.cursorPageY = this.cursorPage.x.cursorPageY;
559
- }
560
- }
561
- else if (axisTo === "y") {
562
- if (this.nrrd_states.isCursorSelect && !this.cursorPage.y.updated) {
563
- if (this.axis === "z") {
564
- // convert z to y
565
- convetObj = this.convertCursorPoint("z", "y", this.cursorPage.z.cursorPageX, this.cursorPage.z.cursorPageY, this.cursorPage.z.index);
566
- }
567
- if (this.axis === "x") {
568
- // convert x to y
569
- convetObj = this.convertCursorPoint("x", "y", this.cursorPage.x.cursorPageX, this.cursorPage.x.cursorPageY, this.cursorPage.x.index);
570
- }
571
- }
572
- else {
573
- // not cursor select, freedom to switch z -> y or x -> y and y -> z or y -> x
574
- this.nrrd_states.currentIndex = this.cursorPage.y.index;
575
- this.nrrd_states.oldIndex =
576
- this.cursorPage.y.index * this.nrrd_states.ratios.y;
577
- this.nrrd_states.cursorPageX = this.cursorPage.y.cursorPageX;
578
- this.nrrd_states.cursorPageY = this.cursorPage.y.cursorPageY;
579
- }
580
- }
581
- if (convetObj) {
582
- // update convert cursor point, when cursor select
583
- this.nrrd_states.currentIndex = convetObj.currentIndex;
584
- this.nrrd_states.oldIndex = convetObj.oldIndex;
585
- this.nrrd_states.cursorPageX = convetObj.convertCursorNumX;
586
- this.nrrd_states.cursorPageY = convetObj.convertCursorNumY;
587
- convetObj = undefined;
588
- switch (axisTo) {
589
- case "x":
590
- this.cursorPage.x.updated = true;
591
- break;
592
- case "y":
593
- this.cursorPage.y.updated = true;
594
- break;
595
- case "z":
596
- this.cursorPage.z.updated = true;
597
- break;
598
- }
599
- }
600
- if (this.cursorPage.x.updated &&
601
- this.cursorPage.y.updated &&
602
- this.cursorPage.z.updated) {
603
- // one point convert to all axis, reset all updated status
604
- this.nrrd_states.isCursorSelect = false;
605
- }
606
- }
607
- this.axis = axisTo;
608
- this.resetDisplaySlicesStatus();
609
- // for sphere plan a
610
- if (this.gui_states.sphere && !this.nrrd_states.spherePlanB) {
611
- this.drawSphere(this.nrrd_states.sphereOrigin[axisTo][0], this.nrrd_states.sphereOrigin[axisTo][1], this.nrrd_states.sphereRadius);
612
- }
613
- }
614
- addSkip(index) {
615
- this.skipSlicesDic[index] = this.backUpDisplaySlices[index];
616
- if (index >= this.displaySlices.length) {
617
- this.nrrd_states.contrastNum = this.displaySlices.length;
618
- }
619
- else {
620
- this.nrrd_states.contrastNum = index;
621
- }
622
- this.resetDisplaySlicesStatus();
623
- }
624
- removeSkip(index) {
625
- this.skipSlicesDic[index] = undefined;
626
- this.nrrd_states.contrastNum = 0;
627
- this.resetDisplaySlicesStatus();
628
- }
629
- clear() {
630
- // To effectively reduce the js memory garbage
631
- this.allSlicesArray.length = 0;
632
- this.displaySlices.length = 0;
633
- this.undoArray.length = 0;
634
- this.paintImages.x.length = 0;
635
- this.paintImages.y.length = 0;
636
- this.paintImages.z.length = 0;
637
- this.paintImagesLabel1.x.length = 0;
638
- this.paintImagesLabel1.y.length = 0;
639
- this.paintImagesLabel1.z.length = 0;
640
- this.paintImagesLabel2.x.length = 0;
641
- this.paintImagesLabel2.y.length = 0;
642
- this.paintImagesLabel2.z.length = 0;
643
- this.paintImagesLabel3.x.length = 0;
644
- this.paintImagesLabel3.y.length = 0;
645
- this.paintImagesLabel3.z.length = 0;
646
- this.clearDictionary(this.skipSlicesDic);
647
- // this.nrrd_states.previousPanelL = this.nrrd_states.previousPanelT = -99999;
648
- this.displayCanvas.style.left = this.drawingCanvas.style.left = "";
649
- this.displayCanvas.style.top = this.drawingCanvas.style.top = "";
650
- this.backUpDisplaySlices.length = 0;
651
- this.mainPreSlice = undefined;
652
- this.currentShowingSlice = undefined;
653
- this.previousDrawingImage = this.emptyCtx.createImageData(1, 1);
654
- this.initState = true;
655
- this.axis = "z";
656
- this.nrrd_states.sizeFoctor = 1;
657
- this.resetLayerCanvas();
658
- this.drawingCanvas.width = this.drawingCanvas.width;
659
- this.displayCanvas.width = this.displayCanvas.width;
660
- }
661
- setSliceMoving(step) {
662
- if (this.mainPreSlice) {
663
- this.Is_Draw = true;
664
- this.setSyncsliceNum();
665
- this.updateIndex(step);
666
- this.setIsDrawFalse(1000);
667
- }
668
- }
669
- setShowInMainArea(isShowContrast) {
670
- this.nrrd_states.showContrast = isShowContrast;
671
- this.nrrd_states.contrastNum = 0;
672
- if (this.mainPreSlice) {
673
- this.redrawMianPreOnDisplayCanvas();
674
- this.updateShowNumDiv(this.nrrd_states.contrastNum);
675
- }
676
- }
677
- setMainAreaSize(factor) {
678
- this.nrrd_states.sizeFoctor += factor;
679
- if (this.nrrd_states.sizeFoctor >= 8) {
680
- this.nrrd_states.sizeFoctor = 8;
681
- }
682
- else if (this.nrrd_states.sizeFoctor <= 1) {
683
- this.nrrd_states.sizeFoctor = 1;
684
- }
685
- this.resizePaintArea(this.nrrd_states.sizeFoctor);
686
- this.resetPaintArea();
687
- this.setIsDrawFalse(1000);
688
- }
689
- getContainer() {
690
- return this.mainAreaContainer;
691
- }
692
- getDrawingCanvas() {
693
- return this.drawingCanvas;
694
- }
695
- getNrrdToolsSettings() {
696
- return this.nrrd_states;
697
- }
698
- getMaxSliceNum() {
699
- if (this.nrrd_states.showContrast) {
700
- return [
701
- this.nrrd_states.maxIndex,
702
- this.nrrd_states.maxIndex * this.displaySlices.length,
703
- ];
704
- }
705
- else {
706
- return [this.nrrd_states.maxIndex];
707
- }
708
- }
709
- getCurrentSlicesNumAndContrastNum() {
710
- return {
711
- currentIndex: this.nrrd_states.currentIndex,
712
- contrastIndex: this.nrrd_states.contrastNum,
713
- };
714
- }
715
- getCurrentSliceIndex() {
716
- return Math.ceil(this.mainPreSlice.index / this.nrrd_states.RSARatio);
717
- }
718
- getIsShowContrastState() {
719
- return this.nrrd_states.showContrast;
720
- }
721
- setIsDrawFalse(target) {
722
- this.preTimer = setTimeout(() => {
723
- this.Is_Draw = false;
724
- if (this.preTimer) {
725
- window.clearTimeout(this.preTimer);
726
- this.preTimer = undefined;
727
- }
728
- }, target);
729
- }
730
- setDisplaySlicesBaseOnAxis() {
731
- this.displaySlices.length = 0;
732
- this.backUpDisplaySlices.length = 0;
733
- this.allSlicesArray.forEach((slices) => {
734
- this.backUpDisplaySlices.push(slices[this.axis]);
735
- });
736
- this.loadDisplaySlicesArray();
737
- }
738
- loadDisplaySlicesArray() {
739
- const remainSlices = Object.values(this.skipSlicesDic);
740
- if (remainSlices.length === 0) {
741
- // load all display slices
742
- this.backUpDisplaySlices.forEach((slice, index) => {
743
- this.skipSlicesDic[index] = slice;
744
- this.displaySlices.push(slice);
745
- });
746
- }
747
- else {
748
- remainSlices.forEach((slice, index) => {
749
- if (!!slice) {
750
- this.displaySlices.push(this.backUpDisplaySlices[index]);
751
- this.skipSlicesDic[index] = this.backUpDisplaySlices[index];
752
- }
753
- });
754
- }
755
- }
756
- switchAllSlicesArrayData(allSlices) {
757
- this.allSlicesArray.length = 0;
758
- this.allSlicesArray = [...allSlices];
759
- this.resetDisplaySlicesStatus();
760
- }
761
- resetDisplaySlicesStatus() {
762
- // reload slice data
763
- this.setDisplaySlicesBaseOnAxis();
764
- // reset canvas attribute for drag and draw
765
- this.setupConfigs();
766
- }
767
- setupConfigs() {
768
- // reset main slice
769
- this.setMainPreSlice();
770
- // update the max index for drag and slider
771
- this.updateMaxIndex();
772
- // reset origin canvas and the nrrd_states origin Width/height
773
- // reset the current index
774
- this.setOriginCanvasAndPre();
775
- // update the show number div on top area
776
- this.updateShowNumDiv(this.nrrd_states.contrastNum);
777
- // repaint all contrast images
778
- this.repraintCurrentContrastSlice();
779
- // resize the draw/drawOutLayer/display canvas size
780
- this.resizePaintArea(this.nrrd_states.sizeFoctor);
781
- this.resetPaintArea();
782
- }
783
- setMainPreSlice() {
784
- this.mainPreSlice = this.displaySlices[0];
785
- if (this.mainPreSlice) {
786
- this.nrrd_states.RSARatio = this.mainPreSlice.RSARatio;
787
- }
788
- }
789
- setOriginCanvasAndPre() {
790
- if (this.mainPreSlice) {
791
- if (this.nrrd_states.oldIndex > this.nrrd_states.maxIndex)
792
- this.nrrd_states.oldIndex = this.nrrd_states.maxIndex;
793
- if (this.initState) {
794
- this.nrrd_states.oldIndex =
795
- this.mainPreSlice.initIndex * this.nrrd_states.RSARatio;
796
- this.nrrd_states.currentIndex = this.mainPreSlice.initIndex;
797
- }
798
- else {
799
- // !need to change
800
- // todo
801
- this.mainPreSlice.index = this.nrrd_states.oldIndex;
802
- }
803
- this.originCanvas = this.mainPreSlice.canvas;
804
- this.updateOriginAndChangedWH();
805
- }
806
- }
807
- afterLoadSlice() {
808
- this.setMainPreSlice();
809
- this.setOriginCanvasAndPre();
810
- this.currentShowingSlice = this.mainPreSlice;
811
- this.nrrd_states.oldIndex =
812
- this.mainPreSlice.initIndex * this.nrrd_states.RSARatio;
813
- this.nrrd_states.currentIndex = this.mainPreSlice.initIndex;
814
- this.undoArray = [
815
- {
816
- sliceIndex: this.nrrd_states.currentIndex,
817
- layers: { label1: [], label2: [], label3: [] },
818
- },
819
- ];
820
- // compute max index
821
- this.updateMaxIndex();
822
- this.updateShowNumDiv(this.nrrd_states.contrastNum);
823
- this.initState = false;
824
- }
825
- updateMaxIndex() {
826
- if (this.mainPreSlice) {
827
- this.nrrd_states.maxIndex = this.mainPreSlice.MaxIndex;
828
- }
829
- }
830
- updateCurrentContrastSlice() {
831
- this.currentShowingSlice = this.displaySlices[this.nrrd_states.contrastNum];
832
- return this.currentShowingSlice;
833
- }
834
- createShowSliceNumberDiv() {
835
- const sliceNumberDiv = document.createElement("div");
836
- sliceNumberDiv.className = "copper3d_sliceNumber";
837
- sliceNumberDiv.style.position = "absolute";
838
- sliceNumberDiv.style.zIndex = "100";
839
- sliceNumberDiv.style.top = "20px";
840
- sliceNumberDiv.style.left = "100px";
841
- return sliceNumberDiv;
842
- }
843
- updateOriginAndChangedWH() {
844
- this.nrrd_states.originWidth = this.originCanvas.width;
845
- this.nrrd_states.originHeight = this.originCanvas.height;
846
- this.nrrd_states.changedWidth =
847
- this.nrrd_states.originWidth * Number(this.gui_states.mainAreaSize);
848
- this.nrrd_states.changedHeight =
849
- this.nrrd_states.originWidth * Number(this.gui_states.mainAreaSize);
850
- this.resizePaintArea(1);
851
- this.resetPaintArea();
852
- }
853
- initAllCanvas() {
854
- /**
855
- * display canvas
856
- */
857
- this.displayCanvas.style.position = "absolute";
858
- this.displayCanvas.style.zIndex = "9";
859
- this.displayCanvas.width = this.nrrd_states.changedWidth;
860
- this.displayCanvas.height = this.nrrd_states.changedHeight;
861
- /**
862
- * drawing canvas
863
- */
864
- this.drawingCanvas.style.zIndex = "10";
865
- this.drawingCanvas.style.position = "absolute";
866
- this.drawingCanvas.width = this.nrrd_states.changedWidth;
867
- this.drawingCanvas.height = this.nrrd_states.changedHeight;
868
- this.drawingCanvas.style.cursor = this.nrrd_states.defaultPaintCursor;
869
- this.drawingCanvas.oncontextmenu = () => false;
870
- /**
871
- * layer1
872
- * it should be hide, so we don't need to add it to mainAreaContainer
873
- */
874
- this.drawingCanvasLayerMaster.width =
875
- this.drawingCanvasLayerOne.width =
876
- this.drawingCanvasLayerTwo.width =
877
- this.drawingCanvasLayerThree.width =
878
- this.nrrd_states.changedWidth;
879
- this.drawingCanvasLayerMaster.height =
880
- this.drawingCanvasLayerOne.height =
881
- this.drawingCanvasLayerTwo.height =
882
- this.drawingCanvasLayerThree.height =
883
- this.nrrd_states.changedHeight;
884
- /**
885
- * display and drawing canvas container
886
- */
887
- // this.mainAreaContainer.style.width = this.nrrd_states.changedWidth + "px";
888
- // this.mainAreaContainer.style.height = this.nrrd_states.changedHeight + "px";
889
- this.mainAreaContainer.style.width =
890
- this.nrrd_states.originWidth * 8 + "px";
891
- this.mainAreaContainer.style.height =
892
- this.nrrd_states.originHeight * 8 + "px";
893
- this.mainAreaContainer.appendChild(this.displayCanvas);
894
- this.mainAreaContainer.appendChild(this.drawingCanvas);
895
- }
896
- autoFocusDiv(container) {
897
- container.tabIndex = 10;
898
- container.addEventListener("mouseover", () => {
899
- container.focus();
900
- });
901
- container.style.outline = "none";
902
- }
903
- setSyncsliceNum() {
904
- this.displaySlices.forEach((slice, index) => {
905
- if (index !== 0) {
906
- slice.index = this.mainPreSlice.index;
907
- }
908
- });
909
- }
910
- repraintCurrentContrastSlice() {
911
- this.setSyncsliceNum();
912
- this.displaySlices.forEach((slice, index) => {
913
- slice.repaint.call(slice);
914
- });
915
- }
916
- repraintAllContrastSlices() {
917
- this.displaySlices.forEach((slice, index) => {
918
- slice.volume.repaintAllSlices();
919
- });
920
- }
921
- updateShowNumDiv(contrastNum) {
922
- if (this.mainPreSlice) {
923
- if (this.nrrd_states.currentIndex > this.nrrd_states.maxIndex) {
924
- this.nrrd_states.currentIndex = this.nrrd_states.maxIndex;
925
- }
926
- if (this.nrrd_states.showContrast) {
927
- this.showDragNumberDiv.innerHTML = `ContrastNum: ${contrastNum}/${this.displaySlices.length - 1} SliceNum: ${this.nrrd_states.currentIndex}/${this.nrrd_states.maxIndex}`;
928
- }
929
- else {
930
- this.showDragNumberDiv.innerHTML = `SliceNum: ${this.nrrd_states.currentIndex}/${this.nrrd_states.maxIndex}`;
931
- }
932
- }
933
- }
934
- appendLoadingbar(loadingbar) {
935
- this.mainAreaContainer.appendChild(loadingbar);
936
- }
937
- drag(opts) {
938
- this.dragPrameters.h = this.container.offsetHeight;
939
- this.sensitiveArray.reverse();
940
- if (opts === null || opts === void 0 ? void 0 : opts.showNumber) {
941
- this.container.appendChild(this.showDragNumberDiv);
942
- }
943
- this.dragPrameters.handleOnDragMouseDown = (ev) => {
944
- // before start drag event, remove wheel event.
945
- this.drawingCanvas.removeEventListener("wheel", this.drawingPrameters.handleZoomWheel);
946
- if (ev.button === 0) {
947
- // this.setSyncsliceNum();
948
- this.dragPrameters.y = ev.offsetY / this.dragPrameters.h;
949
- this.container.addEventListener("pointermove", this.dragPrameters.handleOnDragMouseMove, false);
950
- this.dragPrameters.sensivity =
951
- this.sensitiveArray[this.gui_states.dragSensitivity - 1];
952
- }
953
- };
954
- this.dragPrameters.handleOnDragMouseMove = throttle((ev) => {
955
- if (this.dragPrameters.y - ev.offsetY / this.dragPrameters.h >= 0) {
956
- this.dragPrameters.move = -Math.ceil(((this.dragPrameters.y - ev.offsetY / this.dragPrameters.h) * 10) /
957
- this.dragPrameters.sensivity);
958
- }
959
- else {
960
- this.dragPrameters.move = -Math.floor(((this.dragPrameters.y - ev.offsetY / this.dragPrameters.h) * 10) /
961
- this.dragPrameters.sensivity);
962
- }
963
- this.updateIndex(this.dragPrameters.move);
964
- (opts === null || opts === void 0 ? void 0 : opts.getSliceNum) &&
965
- opts.getSliceNum(this.nrrd_states.currentIndex, this.nrrd_states.contrastNum);
966
- this.dragPrameters.y = ev.offsetY / this.dragPrameters.h;
967
- }, this.dragPrameters.sensivity * 200);
968
- this.dragPrameters.handleOnDragMouseUp = (ev) => {
969
- // after drag, add the wheel event
970
- this.drawingCanvas.addEventListener("wheel", this.drawingPrameters.handleZoomWheel);
971
- this.setSyncsliceNum();
972
- this.container.removeEventListener("pointermove", this.dragPrameters.handleOnDragMouseMove, false);
973
- };
974
- this.configDragMode();
975
- this.container.addEventListener("keydown", (ev) => {
976
- if (ev.key === "Shift") {
977
- this.removeDragMode();
978
- }
979
- });
980
- this.container.addEventListener("keyup", (ev) => {
981
- if (ev.key === "Shift" && !this.gui_states.sphere) {
982
- this.configDragMode();
983
- }
984
- });
985
- }
986
- updateIndex(move) {
987
- let sliceModifyNum = 0;
988
- let contrastModifyNum = 0;
989
- if (this.nrrd_states.showContrast) {
990
- contrastModifyNum = move % this.displaySlices.length;
991
- this.nrrd_states.contrastNum += contrastModifyNum;
992
- if (move > 0) {
993
- // move forward
994
- if (this.nrrd_states.currentIndex <= this.nrrd_states.maxIndex) {
995
- sliceModifyNum = Math.floor(move / this.displaySlices.length);
996
- if (this.nrrd_states.contrastNum > this.displaySlices.length - 1) {
997
- sliceModifyNum += 1;
998
- this.nrrd_states.contrastNum -= this.displaySlices.length;
999
- }
1000
- }
1001
- else {
1002
- sliceModifyNum = 0;
1003
- }
1004
- }
1005
- else {
1006
- // move back
1007
- sliceModifyNum = Math.ceil(move / this.displaySlices.length);
1008
- if (this.nrrd_states.contrastNum < 0) {
1009
- this.nrrd_states.contrastNum += this.displaySlices.length;
1010
- sliceModifyNum -= 1;
1011
- }
1012
- }
1013
- }
1014
- else {
1015
- sliceModifyNum = move;
1016
- }
1017
- // let newIndex = this.nrrd_states.oldIndex + sliceModifyNum;
1018
- let newIndex = this.nrrd_states.currentIndex + sliceModifyNum;
1019
- if (newIndex != this.nrrd_states.currentIndex ||
1020
- this.nrrd_states.showContrast) {
1021
- if (newIndex > this.nrrd_states.maxIndex) {
1022
- newIndex = this.nrrd_states.maxIndex;
1023
- this.nrrd_states.contrastNum = this.displaySlices.length - 1;
1024
- }
1025
- else if (newIndex < this.nrrd_states.minIndex) {
1026
- newIndex = this.nrrd_states.minIndex;
1027
- this.nrrd_states.contrastNum = 0;
1028
- }
1029
- else {
1030
- this.mainPreSlice.index = newIndex * this.nrrd_states.RSARatio;
1031
- // clear drawing canvas, and display next slicez
1032
- this.setSyncsliceNum();
1033
- if (newIndex != this.nrrd_states.currentIndex) {
1034
- this.nrrd_states.switchSliceFlag = true;
1035
- this.drawingCanvasLayerMaster.width =
1036
- this.drawingCanvasLayerMaster.width;
1037
- this.drawingCanvasLayerOne.width = this.drawingCanvasLayerOne.width;
1038
- this.drawingCanvasLayerTwo.width = this.drawingCanvasLayerTwo.width;
1039
- this.drawingCanvasLayerThree.width =
1040
- this.drawingCanvasLayerThree.width;
1041
- }
1042
- this.displayCanvas.width = this.displayCanvas.width;
1043
- if (this.nrrd_states.changedWidth === 0) {
1044
- this.nrrd_states.changedWidth = this.nrrd_states.originWidth;
1045
- this.nrrd_states.changedHeight = this.nrrd_states.originHeight;
1046
- }
1047
- // get the slice that need to be updated on displayCanvas
1048
- let needToUpdateSlice = this.updateCurrentContrastSlice();
1049
- needToUpdateSlice.repaint.call(needToUpdateSlice);
1050
- this.nrrd_states.currentIndex = newIndex;
1051
- this.drawDragSlice(needToUpdateSlice.canvas);
1052
- }
1053
- this.nrrd_states.oldIndex = newIndex * this.nrrd_states.RSARatio;
1054
- this.updateShowNumDiv(this.nrrd_states.contrastNum);
1055
- }
1056
- }
1057
- drawDragSlice(canvas) {
1058
- this.displayCtx.save();
1059
- // flip images
1060
- this.flipDisplayImageByAxis();
1061
- this.displayCtx.drawImage(canvas, 0, 0, this.nrrd_states.changedWidth, this.nrrd_states.changedHeight);
1062
- this.displayCtx.restore();
1063
- if (this.paintImages.x.length > 0 ||
1064
- this.paintImages.y.length > 0 ||
1065
- this.paintImages.z.length > 0) {
1066
- if (this.nrrd_states.switchSliceFlag) {
1067
- this.paintedImage = this.filterDrawedImage(this.axis, this.nrrd_states.currentIndex, this.paintImages);
1068
- this.drawMaskToLabelCtx(this.paintImages, this.drawingLayerMasterCtx);
1069
- this.drawMaskToLabelCtx(this.paintImagesLabel1, this.drawingLayerOneCtx);
1070
- this.drawMaskToLabelCtx(this.paintImagesLabel2, this.drawingLayerTwoCtx);
1071
- this.drawMaskToLabelCtx(this.paintImagesLabel3, this.drawingLayerThreeCtx);
1072
- this.nrrd_states.switchSliceFlag = false;
1073
- }
1074
- }
1075
- }
1076
- drawMaskToLabelCtx(paintedImages, ctx) {
1077
- const paintedImage = this.filterDrawedImage(this.axis, this.nrrd_states.currentIndex, paintedImages);
1078
- if (paintedImage === null || paintedImage === void 0 ? void 0 : paintedImage.image) {
1079
- // redraw the stored data to empty point 2
1080
- this.setEmptyCanvasSize();
1081
- this.emptyCtx.putImageData(paintedImage.image, 0, 0);
1082
- ctx.drawImage(this.emptyCanvas, 0, 0, this.nrrd_states.changedWidth, this.nrrd_states.changedHeight);
1083
- }
1084
- }
1085
- draw(sceneIn, gui, opts) {
1086
- let modeFolder;
1087
- let subViewFolder;
1088
- if (!!opts) {
1089
- this.nrrd_states.getMask = opts === null || opts === void 0 ? void 0 : opts.getMaskData;
1090
- this.nrrd_states.getSphere = opts === null || opts === void 0 ? void 0 : opts.getSphereData;
1091
- }
1092
- this.sceneIn = sceneIn;
1093
- sceneIn.controls.enabled = false;
1094
- if (this.gui_states.subView === false) {
1095
- sceneIn.subDiv && (sceneIn.subDiv.style.display = "none");
1096
- }
1097
- /**
1098
- * GUI
1099
- */
1100
- modeFolder = gui.addFolder("Mode Parameters");
1101
- if (sceneIn.subDiv) {
1102
- subViewFolder = gui.addFolder("Sub View");
1103
- subViewFolder.add(this.gui_states, "resetView");
1104
- subViewFolder.add(this.gui_states, "subView").onChange((value) => {
1105
- if (value) {
1106
- sceneIn.controls.enabled = true;
1107
- sceneIn.subDiv && (sceneIn.subDiv.style.display = "block");
1108
- }
1109
- else {
1110
- sceneIn.subDiv && (sceneIn.subDiv.style.display = "none");
1111
- sceneIn.controls.enabled = false;
1112
- }
1113
- });
1114
- subViewFolder
1115
- .add(this.gui_states, "subViewScale")
1116
- .min(0.25)
1117
- .max(2)
1118
- .step(0.01)
1119
- .onFinishChange((value) => {
1120
- sceneIn.subDiv && (sceneIn.subDiv.style.width = 200 * value + "px");
1121
- sceneIn.subDiv && (sceneIn.subDiv.style.height = 200 * value + "px");
1122
- });
1123
- }
1124
- this.paintOnCanvas(modeFolder);
1125
- }
1126
- paintOnCanvas(modeFolder) {
1127
- var _a, _b, _c, _d;
1128
- /**
1129
- * drag paint panel
1130
- */
1131
- let leftclicked = false;
1132
- let rightclicked = false;
1133
- let panelMoveInnerX = 0;
1134
- let panelMoveInnerY = 0;
1135
- // todo
1136
- // let currentSliceIndex = this.mainPreSlice.index;
1137
- let currentSliceIndex = this.mainPreSlice.index;
1138
- // draw lines starts position
1139
- let Is_Painting = false;
1140
- let lines = [];
1141
- const clearArc = this.useEraser();
1142
- this.updateOriginAndChangedWH();
1143
- this.initAllCanvas();
1144
- this.configGui(modeFolder);
1145
- (_a = this.displayCtx) === null || _a === void 0 ? void 0 : _a.save();
1146
- this.flipDisplayImageByAxis();
1147
- (_b = this.displayCtx) === null || _b === void 0 ? void 0 : _b.drawImage(this.originCanvas, 0, 0, this.nrrd_states.changedWidth, this.nrrd_states.changedHeight);
1148
- (_c = this.displayCtx) === null || _c === void 0 ? void 0 : _c.restore();
1149
- this.previousDrawingImage = this.drawingCtx.getImageData(0, 0, this.drawingCanvas.width, this.drawingCanvas.height);
1150
- // let a global variable to store the wheel move event
1151
- this.drawingPrameters.handleZoomWheel = this.configMouseZoomWheel((_d = this.sceneIn) === null || _d === void 0 ? void 0 : _d.controls);
1152
- // init to add it
1153
- this.drawingCanvas.addEventListener("wheel", this.drawingPrameters.handleZoomWheel, {
1154
- passive: false,
1155
- });
1156
- // sphere Wheel
1157
- this.drawingPrameters.handleSphereWheel = this.configMouseSphereWheel();
1158
- // pan move
1159
- this.drawingPrameters.handleOnPanMouseMove = (e) => {
1160
- this.drawingCanvas.style.cursor = "grabbing";
1161
- this.nrrd_states.previousPanelL = e.clientX - panelMoveInnerX;
1162
- this.nrrd_states.previousPanelT = e.clientY - panelMoveInnerY;
1163
- this.displayCanvas.style.left = this.drawingCanvas.style.left =
1164
- this.nrrd_states.previousPanelL + "px";
1165
- this.displayCanvas.style.top = this.drawingCanvas.style.top =
1166
- this.nrrd_states.previousPanelT + "px";
1167
- };
1168
- // brush circle move
1169
- this.drawingPrameters.handleOnDrawingBrushCricleMove = (e) => {
1170
- e.preventDefault();
1171
- this.nrrd_states.Mouse_Over_x = e.offsetX;
1172
- this.nrrd_states.Mouse_Over_y = e.offsetY;
1173
- if (this.nrrd_states.Mouse_Over_x === undefined) {
1174
- this.nrrd_states.Mouse_Over_x = e.clientX;
1175
- this.nrrd_states.Mouse_Over_y = e.clientY;
1176
- }
1177
- if (e.type === "mouseout") {
1178
- this.nrrd_states.Mouse_Over = false;
1179
- this.drawingCanvas.removeEventListener("mousemove", this.drawingPrameters.handleOnDrawingBrushCricleMove);
1180
- }
1181
- else if (e.type === "mouseover") {
1182
- this.nrrd_states.Mouse_Over = true;
1183
- this.drawingCanvas.addEventListener("mousemove", this.drawingPrameters.handleOnDrawingBrushCricleMove);
1184
- }
1185
- };
1186
- // drawing move
1187
- this.drawingPrameters.handleOnDrawingMouseMove = (e) => {
1188
- this.Is_Draw = true;
1189
- if (Is_Painting) {
1190
- if (this.gui_states.Eraser) {
1191
- this.nrrd_states.stepClear = 1;
1192
- // drawingCtx.clearRect(e.offsetX - 5, e.offsetY - 5, 25, 25);
1193
- clearArc(e.offsetX, e.offsetY, this.gui_states.brushAndEraserSize);
1194
- }
1195
- else {
1196
- lines.push({ x: e.offsetX, y: e.offsetY });
1197
- this.paintOnCanvasLayer(e.offsetX, e.offsetY);
1198
- }
1199
- }
1200
- };
1201
- this.drawingPrameters.handleOnDrawingMouseDown = (e) => {
1202
- if (leftclicked || rightclicked) {
1203
- this.drawingCanvas.removeEventListener("pointerup", this.drawingPrameters.handleOnDrawingMouseUp);
1204
- this.drawingLayerMasterCtx.closePath();
1205
- return;
1206
- }
1207
- // when switch slice, clear previousDrawingImage
1208
- // todo
1209
- if (currentSliceIndex !== this.mainPreSlice.index) {
1210
- this.previousDrawingImage = this.emptyCtx.createImageData(1, 1);
1211
- currentSliceIndex = this.mainPreSlice.index;
1212
- }
1213
- // remove it when mouse click down
1214
- this.drawingCanvas.removeEventListener("wheel", this.drawingPrameters.handleZoomWheel);
1215
- if (e.button === 0) {
1216
- if (this.Is_Shift_Pressed) {
1217
- leftclicked = true;
1218
- lines = [];
1219
- Is_Painting = true;
1220
- this.Is_Draw = true;
1221
- if (this.gui_states.Eraser) {
1222
- // this.drawingCanvas.style.cursor =
1223
- // "url(https://raw.githubusercontent.com/LinkunGao/copper3d-datasets/main/icons/eraser/circular-cursor_48.png) 48 48, crosshair";
1224
- this.eraserUrls.length > 0
1225
- ? (this.drawingCanvas.style.cursor = switchEraserSize(this.gui_states.brushAndEraserSize, this.eraserUrls))
1226
- : (this.drawingCanvas.style.cursor = switchEraserSize(this.gui_states.brushAndEraserSize));
1227
- }
1228
- else {
1229
- this.drawingCanvas.style.cursor =
1230
- this.nrrd_states.defaultPaintCursor;
1231
- }
1232
- this.nrrd_states.drawStartPos.set(e.offsetX, e.offsetY);
1233
- // this.drawingLayerMasterCtx.beginPath();
1234
- this.drawingCanvas.addEventListener("pointerup", this.drawingPrameters.handleOnDrawingMouseUp);
1235
- this.drawingCanvas.addEventListener("pointermove", this.drawingPrameters.handleOnDrawingMouseMove);
1236
- }
1237
- else if (this.nrrd_states.enableCursorChoose) {
1238
- this.nrrd_states.cursorPageX =
1239
- e.offsetX / this.nrrd_states.sizeFoctor;
1240
- this.nrrd_states.cursorPageY =
1241
- e.offsetY / this.nrrd_states.sizeFoctor;
1242
- this.enableCrosshair();
1243
- }
1244
- else if (this.gui_states.sphere) {
1245
- let mouseX = e.offsetX;
1246
- let mouseY = e.offsetY;
1247
- // record mouseX,Y, and enable crosshair function
1248
- this.nrrd_states.sphereOrigin[this.axis] = [
1249
- mouseX,
1250
- mouseY,
1251
- this.nrrd_states.currentIndex,
1252
- ];
1253
- this.setUpSphereOrigins(mouseX, mouseY);
1254
- this.nrrd_states.cursorPageX = mouseX;
1255
- this.nrrd_states.cursorPageY = mouseY;
1256
- this.enableCrosshair();
1257
- // draw circle setup width/height for sphere canvas
1258
- this.drawSphere(mouseX, mouseY, this.nrrd_states.sphereRadius);
1259
- this.drawingCanvas.addEventListener("wheel", this.drawingPrameters.handleSphereWheel, true);
1260
- this.drawingCanvas.addEventListener("pointerup", this.drawingPrameters.handleOnDrawingMouseUp);
1261
- }
1262
- }
1263
- else if (e.button === 2) {
1264
- rightclicked = true;
1265
- // let offsetX = parseInt(this.drawingCanvas.style.left);
1266
- // let offsetY = parseInt(this.drawingCanvas.style.top);
1267
- let offsetX = this.drawingCanvas.offsetLeft;
1268
- let offsetY = this.drawingCanvas.offsetTop;
1269
- panelMoveInnerX = e.clientX - offsetX;
1270
- panelMoveInnerY = e.clientY - offsetY;
1271
- this.drawingCanvas.style.cursor = "grab";
1272
- this.drawingCanvas.addEventListener("pointerup", this.drawingPrameters.handleOnDrawingMouseUp);
1273
- this.drawingCanvas.addEventListener("pointermove", this.drawingPrameters.handleOnPanMouseMove);
1274
- }
1275
- else {
1276
- return;
1277
- }
1278
- };
1279
- // disable browser right click menu
1280
- this.drawingCanvas.addEventListener("pointerdown", this.drawingPrameters.handleOnDrawingMouseDown, true);
1281
- const redrawPreviousImageToLabelCtx = (ctx, label = "default") => {
1282
- var _a;
1283
- let paintImages;
1284
- switch (label) {
1285
- case "label1":
1286
- paintImages = this.paintImagesLabel1;
1287
- break;
1288
- case "label2":
1289
- paintImages = this.paintImagesLabel2;
1290
- break;
1291
- case "label3":
1292
- paintImages = this.paintImagesLabel3;
1293
- break;
1294
- default:
1295
- paintImages = this.paintImages;
1296
- break;
1297
- }
1298
- const tempPreImg = (_a = this.filterDrawedImage(this.axis, this.nrrd_states.currentIndex, paintImages)) === null || _a === void 0 ? void 0 : _a.image;
1299
- this.emptyCanvas.width = this.emptyCanvas.width;
1300
- if (tempPreImg && label == "default") {
1301
- this.previousDrawingImage = tempPreImg;
1302
- }
1303
- this.emptyCtx.putImageData(tempPreImg, 0, 0);
1304
- // draw privous image
1305
- ctx.drawImage(this.emptyCanvas, 0, 0, this.nrrd_states.changedWidth, this.nrrd_states.changedHeight);
1306
- };
1307
- this.drawingPrameters.handleOnDrawingMouseUp = (e) => {
1308
- if (e.button === 0) {
1309
- if (this.Is_Shift_Pressed || Is_Painting) {
1310
- leftclicked = false;
1311
- let { ctx, canvas } = this.setCurrentLayer();
1312
- ctx.closePath();
1313
- this.drawingCanvas.removeEventListener("pointermove", this.drawingPrameters.handleOnDrawingMouseMove);
1314
- if (!this.gui_states.Eraser) {
1315
- if (this.gui_states.segmentation) {
1316
- this.drawingCanvasLayerMaster.width =
1317
- this.drawingCanvasLayerMaster.width;
1318
- canvas.width = canvas.width;
1319
- redrawPreviousImageToLabelCtx(this.drawingLayerMasterCtx);
1320
- redrawPreviousImageToLabelCtx(ctx, this.gui_states.label);
1321
- // draw new drawings
1322
- ctx.beginPath();
1323
- ctx.moveTo(lines[0].x, lines[0].y);
1324
- for (let i = 1; i < lines.length; i++) {
1325
- ctx.lineTo(lines[i].x, lines[i].y);
1326
- }
1327
- ctx.closePath();
1328
- ctx.lineWidth = 1;
1329
- ctx.fillStyle = this.gui_states.fillColor;
1330
- ctx.fill();
1331
- // draw layer to master layer
1332
- this.drawingLayerMasterCtx.drawImage(canvas, 0, 0, this.nrrd_states.changedWidth, this.nrrd_states.changedHeight);
1333
- }
1334
- }
1335
- this.previousDrawingImage = this.drawingLayerMasterCtx.getImageData(0, 0, this.drawingCanvasLayerMaster.width, this.drawingCanvasLayerMaster.height);
1336
- this.storeAllImages(this.nrrd_states.currentIndex, this.gui_states.label);
1337
- if (this.gui_states.Eraser) {
1338
- const restLabels = this.getRestLabel();
1339
- this.storeEachLayerImage(this.nrrd_states.currentIndex, restLabels[0]);
1340
- this.storeEachLayerImage(this.nrrd_states.currentIndex, restLabels[1]);
1341
- }
1342
- Is_Painting = false;
1343
- /**
1344
- * store undo array
1345
- */
1346
- const currentUndoObj = this.getCurrentUndo();
1347
- const src = this.drawingCanvasLayerMaster.toDataURL();
1348
- const image = new Image();
1349
- image.src = src;
1350
- if (currentUndoObj.length > 0) {
1351
- currentUndoObj[0].layers[this.gui_states.label].push(image);
1352
- }
1353
- else {
1354
- const undoObj = {
1355
- sliceIndex: this.nrrd_states.currentIndex,
1356
- layers: { label1: [], label2: [], label3: [] },
1357
- };
1358
- undoObj.layers[this.gui_states.label].push(image);
1359
- this.undoArray.push(undoObj);
1360
- }
1361
- // add wheel after pointer up
1362
- this.drawingCanvas.addEventListener("wheel", this.drawingPrameters.handleZoomWheel, {
1363
- passive: false,
1364
- });
1365
- }
1366
- else if (this.gui_states.sphere &&
1367
- !this.nrrd_states.enableCursorChoose) {
1368
- // let { ctx, canvas } = this.setCurrentLayer();
1369
- // let mouseX = e.offsetX;
1370
- // let mouseY = e.offsetY;
1371
- // plan B
1372
- // findout all index in the sphere radius range in Axial view
1373
- if (this.nrrd_states.spherePlanB) {
1374
- // clear stroe images
1375
- this.clearStoreImages();
1376
- for (let i = 0; i < this.nrrd_states.sphereRadius; i++) {
1377
- this.drawSphereOnEachViews(i, "x");
1378
- this.drawSphereOnEachViews(i, "y");
1379
- this.drawSphereOnEachViews(i, "z");
1380
- }
1381
- }
1382
- !!this.nrrd_states.getSphere && this.nrrd_states.getSphere(this.nrrd_states.sphereOrigin.z, this.nrrd_states.sphereRadius);
1383
- this.drawingCanvas.removeEventListener("wheel", this.drawingPrameters.handleSphereWheel, true);
1384
- }
1385
- }
1386
- else if (e.button === 2) {
1387
- rightclicked = false;
1388
- this.drawingCanvas.style.cursor = "grab";
1389
- this.drawingCanvas.removeEventListener("pointermove", this.drawingPrameters.handleOnPanMouseMove);
1390
- }
1391
- else {
1392
- return;
1393
- }
1394
- if (!this.gui_states.segmentation) {
1395
- this.setIsDrawFalse(100);
1396
- }
1397
- };
1398
- this.drawingCanvas.addEventListener("pointerleave", (e) => {
1399
- Is_Painting = false;
1400
- // (this.sceneIn as copperScene).controls.enabled = true;
1401
- if (leftclicked) {
1402
- leftclicked = false;
1403
- this.drawingLayerMasterCtx.closePath();
1404
- this.drawingCanvas.removeEventListener("pointermove", this.drawingPrameters.handleOnDrawingMouseMove);
1405
- this.drawingCanvas.removeEventListener("wheel", this.drawingPrameters.handleSphereWheel, true);
1406
- }
1407
- if (rightclicked) {
1408
- rightclicked = false;
1409
- this.drawingCanvas.style.cursor = "grab";
1410
- this.drawingCanvas.removeEventListener("pointermove", this.drawingPrameters.handleOnPanMouseMove);
1411
- }
1412
- this.setIsDrawFalse(100);
1413
- if (this.gui_states.segmentation) {
1414
- this.setIsDrawFalse(1000);
1415
- }
1416
- });
1417
- this.start = () => {
1418
- if (this.nrrd_states.readyToUpdate) {
1419
- this.drawingCtx.clearRect(0, 0, this.nrrd_states.changedWidth, this.nrrd_states.changedHeight);
1420
- this.drawingCtx.globalAlpha = this.gui_states.globalAlpha;
1421
- if (this.Is_Draw) {
1422
- this.drawingLayerMasterCtx.lineCap = "round";
1423
- this.drawingLayerMasterCtx.globalAlpha = 1;
1424
- this.drawingLayerOneCtx.lineCap = "round";
1425
- this.drawingLayerOneCtx.globalAlpha = 1;
1426
- this.drawingLayerTwoCtx.lineCap = "round";
1427
- this.drawingLayerTwoCtx.globalAlpha = 1;
1428
- this.drawingLayerThreeCtx.lineCap = "round";
1429
- this.drawingLayerThreeCtx.globalAlpha = 1;
1430
- }
1431
- else {
1432
- if (this.Is_Shift_Pressed) {
1433
- if (!this.gui_states.segmentation &&
1434
- !this.gui_states.Eraser &&
1435
- this.nrrd_states.Mouse_Over) {
1436
- this.drawingCtx.clearRect(0, 0, this.nrrd_states.changedWidth, this.nrrd_states.changedHeight);
1437
- this.drawingCtx.fillStyle = this.gui_states.brushColor;
1438
- this.drawingCtx.beginPath();
1439
- this.drawingCtx.arc(this.nrrd_states.Mouse_Over_x, this.nrrd_states.Mouse_Over_y, this.gui_states.brushAndEraserSize / 2 + 1, 0, Math.PI * 2);
1440
- // this.drawingCtx.fill();
1441
- this.drawingCtx.strokeStyle = this.gui_states.brushColor;
1442
- this.drawingCtx.stroke();
1443
- }
1444
- }
1445
- if (this.nrrd_states.enableCursorChoose) {
1446
- this.drawingCtx.clearRect(0, 0, this.nrrd_states.changedWidth, this.nrrd_states.changedHeight);
1447
- const ex = this.nrrd_states.cursorPageX * this.nrrd_states.sizeFoctor;
1448
- const ey = this.nrrd_states.cursorPageY * this.nrrd_states.sizeFoctor;
1449
- this.drawLine(ex, 0, ex, this.drawingCanvas.height);
1450
- this.drawLine(0, ey, this.drawingCanvas.width, ey);
1451
- }
1452
- }
1453
- this.drawingCtx.drawImage(this.drawingCanvasLayerMaster, 0, 0);
1454
- }
1455
- else {
1456
- this.redrawDisplayCanvas();
1457
- }
1458
- };
1459
- document.addEventListener("keydown", (e) => {
1460
- if ((e.ctrlKey || e.metaKey) && e.code === "KeyZ") {
1461
- this.undoLastPainting();
1462
- }
1463
- });
1464
- }
1465
- enableCrosshair() {
1466
- this.nrrd_states.isCursorSelect = true;
1467
- switch (this.axis) {
1468
- case "x":
1469
- this.cursorPage.x.updated = true;
1470
- this.cursorPage.y.updated = false;
1471
- this.cursorPage.z.updated = false;
1472
- break;
1473
- case "y":
1474
- this.cursorPage.x.updated = false;
1475
- this.cursorPage.y.updated = true;
1476
- this.cursorPage.z.updated = false;
1477
- break;
1478
- case "z":
1479
- this.cursorPage.x.updated = false;
1480
- this.cursorPage.y.updated = false;
1481
- this.cursorPage.z.updated = true;
1482
- break;
1483
- }
1484
- }
1485
- setUpSphereOrigins(mouseX, mouseY) {
1486
- const convertCursor = (from, to) => {
1487
- const convertObj = this.convertCursorPoint(from, to, mouseX, mouseY, this.nrrd_states.currentIndex);
1488
- return {
1489
- convertCursorNumX: convertObj === null || convertObj === void 0 ? void 0 : convertObj.convertCursorNumX,
1490
- convertCursorNumY: convertObj === null || convertObj === void 0 ? void 0 : convertObj.convertCursorNumY,
1491
- currentIndex: convertObj === null || convertObj === void 0 ? void 0 : convertObj.currentIndex,
1492
- };
1493
- };
1494
- const axisConversions = {
1495
- x: { axisTo1: "y", axisTo2: "z" },
1496
- y: { axisTo1: "z", axisTo2: "x" },
1497
- z: { axisTo1: "x", axisTo2: "y" },
1498
- };
1499
- const { axisTo1, axisTo2 } = axisConversions[this.axis];
1500
- this.nrrd_states.sphereOrigin[axisTo1] = [
1501
- convertCursor(this.axis, axisTo1).convertCursorNumX,
1502
- convertCursor(this.axis, axisTo1).convertCursorNumY,
1503
- convertCursor(this.axis, axisTo1).currentIndex,
1504
- ];
1505
- this.nrrd_states.sphereOrigin[axisTo2] = [
1506
- convertCursor(this.axis, axisTo2).convertCursorNumX,
1507
- convertCursor(this.axis, axisTo2).convertCursorNumY,
1508
- convertCursor(this.axis, axisTo2).currentIndex,
1509
- ];
1510
- }
1511
- // for sphere
1512
- drawSphereOnEachViews(decay, axis) {
1513
- // init sphere canvas width and height
1514
- this.setSphereCanvasSize(axis);
1515
- const mouseX = this.nrrd_states.sphereOrigin[axis][0];
1516
- const mouseY = this.nrrd_states.sphereOrigin[axis][1];
1517
- const originIndex = this.nrrd_states.sphereOrigin[axis][2];
1518
- const preIndex = originIndex - decay;
1519
- const nextIndex = originIndex + decay;
1520
- const ctx = this.drawingSphereCtx;
1521
- const canvas = this.drawingSphereCanvas;
1522
- // if (
1523
- // preIndex < this.nrrd_states.minIndex ||
1524
- // nextIndex > this.nrrd_states.maxIndex
1525
- // )
1526
- // return;
1527
- if (preIndex === nextIndex) {
1528
- this.drawSphereCore(ctx, mouseX, mouseY, this.nrrd_states.sphereRadius);
1529
- this.storeSphereImages(preIndex, axis);
1530
- }
1531
- else {
1532
- this.drawSphereCore(ctx, mouseX, mouseY, this.nrrd_states.sphereRadius - decay);
1533
- this.drawImageOnEmptyImage(canvas);
1534
- this.storeSphereImages(preIndex, axis);
1535
- this.storeSphereImages(nextIndex, axis);
1536
- }
1537
- ctx.clearRect(0, 0, canvas.width, canvas.height);
1538
- }
1539
- drawSphereCore(ctx, x, y, radius) {
1540
- ctx.beginPath();
1541
- ctx.arc(x, y, radius * this.nrrd_states.sizeFoctor, 0, 2 * Math.PI);
1542
- ctx.fillStyle = this.gui_states.fillColor;
1543
- ctx.fill();
1544
- ctx.closePath();
1545
- }
1546
- drawSphere(mouseX, mouseY, radius) {
1547
- // clear canvas
1548
- this.drawingSphereCanvas.width = this.drawingCanvasLayerMaster.width;
1549
- this.drawingSphereCanvas.height = this.drawingCanvasLayerMaster.height;
1550
- const canvas = this.drawingSphereCanvas;
1551
- const ctx = this.drawingSphereCtx;
1552
- this.drawingLayerMasterCtx.clearRect(0, 0, canvas.width, canvas.height);
1553
- this.drawSphereCore(ctx, mouseX, mouseY, radius);
1554
- this.drawingLayerMasterCtx.drawImage(canvas, 0, 0, this.nrrd_states.changedWidth, this.nrrd_states.changedHeight);
1555
- }
1556
- // need to update
1557
- undoLastPainting() {
1558
- let { ctx, canvas } = this.setCurrentLayer();
1559
- this.Is_Draw = true;
1560
- this.drawingCanvasLayerMaster.width = this.drawingCanvasLayerMaster.width;
1561
- canvas.width = canvas.width;
1562
- this.mainPreSlice.repaint.call(this.mainPreSlice);
1563
- const currentUndoObj = this.getCurrentUndo();
1564
- if (currentUndoObj.length > 0) {
1565
- const undo = currentUndoObj[0];
1566
- const layerUndos = undo.layers[this.gui_states.label];
1567
- const layerLen = layerUndos.length;
1568
- // if (layerLen === 0) return;
1569
- layerUndos.pop();
1570
- if (layerLen > 0) {
1571
- // const imageSrc = undo.undos[undo.undos.length - 1];
1572
- const image = layerUndos[layerLen - 1];
1573
- if (!!image) {
1574
- ctx.drawImage(image, 0, 0, this.nrrd_states.changedWidth, this.nrrd_states.changedHeight);
1575
- }
1576
- }
1577
- if (undo.layers.label1.length > 0) {
1578
- const image = undo.layers.label1[undo.layers.label1.length - 1];
1579
- this.drawingLayerMasterCtx.drawImage(image, 0, 0, this.nrrd_states.changedWidth, this.nrrd_states.changedHeight);
1580
- }
1581
- if (undo.layers.label2.length > 0) {
1582
- const image = undo.layers.label2[undo.layers.label2.length - 1];
1583
- this.drawingLayerMasterCtx.drawImage(image, 0, 0, this.nrrd_states.changedWidth, this.nrrd_states.changedHeight);
1584
- }
1585
- if (undo.layers.label3.length > 0) {
1586
- const image = undo.layers.label3[undo.layers.label3.length - 1];
1587
- this.drawingLayerMasterCtx.drawImage(image, 0, 0, this.nrrd_states.changedWidth, this.nrrd_states.changedHeight);
1588
- }
1589
- this.previousDrawingImage = this.drawingLayerMasterCtx.getImageData(0, 0, this.drawingCanvasLayerMaster.width, this.drawingCanvasLayerMaster.height);
1590
- this.storeAllImages(this.nrrd_states.currentIndex, this.gui_states.label);
1591
- this.setIsDrawFalse(1000);
1592
- }
1593
- }
1594
- getCurrentUndo() {
1595
- return this.undoArray.filter((item) => {
1596
- return item.sliceIndex === this.nrrd_states.currentIndex;
1597
- });
1598
- }
1599
- // drawing canvas mouse shpere wheel
1600
- configMouseSphereWheel() {
1601
- const sphereEvent = (e) => {
1602
- e.preventDefault();
1603
- if (e.deltaY < 0) {
1604
- this.nrrd_states.sphereRadius += 1;
1605
- }
1606
- else {
1607
- this.nrrd_states.sphereRadius -= 1;
1608
- }
1609
- // limited the radius max and min
1610
- this.nrrd_states.sphereRadius = Math.max(1, Math.min(this.nrrd_states.sphereRadius, 50));
1611
- // get mouse position
1612
- const mouseX = this.nrrd_states.sphereOrigin[this.axis][0];
1613
- const mouseY = this.nrrd_states.sphereOrigin[this.axis][1];
1614
- this.drawSphere(mouseX, mouseY, this.nrrd_states.sphereRadius);
1615
- };
1616
- return sphereEvent;
1617
- }
1618
- // drawing canvas mouse zoom wheel
1619
- configMouseZoomWheel(controls) {
1620
- let moveDistance = 1;
1621
- const handleZoomWheelMove = (e) => {
1622
- if (this.Is_Shift_Pressed) {
1623
- return;
1624
- }
1625
- e.preventDefault();
1626
- // this.nrrd_states.originWidth;
1627
- const delta = e.detail ? e.detail > 0 : e.wheelDelta < 0;
1628
- this.Is_Draw = true;
1629
- const ratioL = (e.clientX -
1630
- this.mainAreaContainer.offsetLeft -
1631
- this.drawingCanvas.offsetLeft) /
1632
- this.drawingCanvas.offsetWidth;
1633
- const ratioT = (e.clientY -
1634
- this.mainAreaContainer.offsetTop -
1635
- this.drawingCanvas.offsetTop) /
1636
- this.drawingCanvas.offsetHeight;
1637
- const ratioDelta = !delta ? 1 + 0.1 : 1 - 0.1;
1638
- const w = this.drawingCanvas.offsetWidth * ratioDelta;
1639
- const h = this.drawingCanvas.offsetHeight * ratioDelta;
1640
- const l = Math.round(e.clientX - this.mainAreaContainer.offsetLeft - w * ratioL);
1641
- const t = Math.round(e.clientY - this.mainAreaContainer.offsetTop - h * ratioT);
1642
- moveDistance = w / this.nrrd_states.originWidth;
1643
- if (moveDistance > 8) {
1644
- moveDistance = 8;
1645
- }
1646
- else if (moveDistance < 1) {
1647
- moveDistance = 1;
1648
- }
1649
- else {
1650
- this.resizePaintArea(moveDistance);
1651
- this.resetPaintArea(l, t);
1652
- controls && (controls.enabled = false);
1653
- this.setIsDrawFalse(1000);
1654
- }
1655
- this.nrrd_states.sizeFoctor = moveDistance;
1656
- };
1657
- return handleZoomWheelMove;
1658
- }
1659
- useEraser() {
1660
- const clearArc = (x, y, radius) => {
1661
- var calcWidth = radius - this.nrrd_states.stepClear;
1662
- var calcHeight = Math.sqrt(radius * radius - calcWidth * calcWidth);
1663
- var posX = x - calcWidth;
1664
- var posY = y - calcHeight;
1665
- var widthX = 2 * calcWidth;
1666
- var heightY = 2 * calcHeight;
1667
- if (this.nrrd_states.stepClear <= radius) {
1668
- this.drawingLayerMasterCtx.clearRect(posX, posY, widthX, heightY);
1669
- this.drawingLayerOneCtx.clearRect(posX, posY, widthX, heightY);
1670
- this.drawingLayerTwoCtx.clearRect(posX, posY, widthX, heightY);
1671
- this.drawingLayerThreeCtx.clearRect(posX, posY, widthX, heightY);
1672
- this.nrrd_states.stepClear += 1;
1673
- clearArc(x, y, radius);
1674
- }
1675
- };
1676
- return clearArc;
1677
- }
1678
- clearPaint() {
1679
- this.Is_Draw = true;
1680
- this.resetLayerCanvas();
1681
- this.originCanvas.width = this.originCanvas.width;
1682
- this.mainPreSlice.repaint.call(this.mainPreSlice);
1683
- this.previousDrawingImage = this.emptyCtx.createImageData(1, 1);
1684
- this.storeAllImages(this.nrrd_states.currentIndex, this.gui_states.label);
1685
- const restLabels = this.getRestLabel();
1686
- this.storeEachLayerImage(this.nrrd_states.currentIndex, restLabels[0]);
1687
- this.storeEachLayerImage(this.nrrd_states.currentIndex, restLabels[1]);
1688
- this.setIsDrawFalse(1000);
1689
- }
1690
- getRestLabel() {
1691
- const labels = this.nrrd_states.labels;
1692
- const restLabel = labels.filter((item) => {
1693
- return item !== this.gui_states.label;
1694
- });
1695
- return restLabel;
1696
- }
1697
- clearStoreImages() {
1698
- this.paintImages.x.length = 0;
1699
- this.paintImages.y.length = 0;
1700
- this.paintImages.z.length = 0;
1701
- this.paintImagesLabel1.x.length = 0;
1702
- this.paintImagesLabel1.y.length = 0;
1703
- this.paintImagesLabel1.z.length = 0;
1704
- this.paintImagesLabel2.x.length = 0;
1705
- this.paintImagesLabel2.y.length = 0;
1706
- this.paintImagesLabel2.z.length = 0;
1707
- this.paintImagesLabel3.x.length = 0;
1708
- this.paintImagesLabel3.y.length = 0;
1709
- this.paintImagesLabel3.z.length = 0;
1710
- this.initPaintImages(this.nrrd_states.dimensions);
1711
- }
1712
- enableDownload() {
1713
- this.downloadImage.download = `slice_${this.axis}_#${this.nrrd_states.currentIndex}`;
1714
- const downloadCtx = this.downloadCanvas.getContext("2d");
1715
- this.downloadCanvas.width = this.nrrd_states.originWidth;
1716
- this.downloadCanvas.height = this.nrrd_states.originHeight;
1717
- downloadCtx.drawImage(this.drawingCanvas, 0, 0, this.nrrd_states.originWidth, this.nrrd_states.originHeight);
1718
- this.downloadImage.href = this.downloadCanvas.toDataURL();
1719
- this.downloadImage.click();
1720
- }
1721
- paintOnCanvasLayer(x, y) {
1722
- let { ctx, canvas } = this.setCurrentLayer();
1723
- this.drawLinesOnLayer(ctx, x, y);
1724
- this.drawLinesOnLayer(this.drawingLayerMasterCtx, x, y);
1725
- // reset drawing start position to current position.
1726
- this.nrrd_states.drawStartPos.set(x, y);
1727
- // need to flag the map as needing updating.
1728
- this.mainPreSlice.mesh.material.map.needsUpdate = true;
1729
- }
1730
- drawLinesOnLayer(ctx, x, y) {
1731
- ctx.beginPath();
1732
- ctx.moveTo(this.nrrd_states.drawStartPos.x, this.nrrd_states.drawStartPos.y);
1733
- if (this.gui_states.segmentation) {
1734
- ctx.strokeStyle = this.gui_states.color;
1735
- ctx.lineWidth = this.gui_states.lineWidth;
1736
- }
1737
- else {
1738
- ctx.strokeStyle = this.gui_states.brushColor;
1739
- ctx.lineWidth = this.gui_states.brushAndEraserSize;
1740
- }
1741
- ctx.lineTo(x, y);
1742
- ctx.stroke();
1743
- ctx.closePath();
1744
- }
1745
- setCurrentLayer() {
1746
- let ctx;
1747
- let canvas;
1748
- switch (this.gui_states.label) {
1749
- case "label1":
1750
- ctx = this.drawingLayerOneCtx;
1751
- canvas = this.drawingCanvasLayerOne;
1752
- break;
1753
- case "label2":
1754
- ctx = this.drawingLayerTwoCtx;
1755
- canvas = this.drawingCanvasLayerTwo;
1756
- break;
1757
- case "label3":
1758
- ctx = this.drawingLayerThreeCtx;
1759
- canvas = this.drawingCanvasLayerThree;
1760
- break;
1761
- default:
1762
- ctx = this.drawingLayerOneCtx;
1763
- canvas = this.drawingCanvasLayerOne;
1764
- break;
1765
- }
1766
- return { ctx, canvas };
1767
- }
1768
- updateSlicesContrast(value, flag) {
1769
- switch (flag) {
1770
- case "lowerThreshold":
1771
- this.displaySlices.forEach((slice, index) => {
1772
- slice.volume.lowerThreshold = value;
1773
- });
1774
- break;
1775
- case "upperThreshold":
1776
- this.displaySlices.forEach((slice, index) => {
1777
- slice.volume.upperThreshold = value;
1778
- });
1779
- break;
1780
- case "windowLow":
1781
- this.displaySlices.forEach((slice, index) => {
1782
- slice.volume.windowLow = value;
1783
- });
1784
- break;
1785
- case "windowHigh":
1786
- this.displaySlices.forEach((slice, index) => {
1787
- slice.volume.windowHigh = value;
1788
- });
1789
- break;
1790
- }
1791
- this.repraintCurrentContrastSlice();
1792
- }
1793
- resetPaintArea(l, t) {
1794
- if (l && t) {
1795
- this.displayCanvas.style.left = this.drawingCanvas.style.left = l + "px";
1796
- this.displayCanvas.style.top = this.drawingCanvas.style.top = t + "px";
1797
- }
1798
- else {
1799
- this.mainAreaContainer.style.justifyContent = "center";
1800
- this.mainAreaContainer.style.alignItems = "center";
1801
- }
1802
- }
1803
- resetLayerCanvas() {
1804
- this.drawingCanvasLayerMaster.width = this.drawingCanvasLayerMaster.width;
1805
- this.drawingCanvasLayerOne.width = this.drawingCanvasLayerOne.width;
1806
- this.drawingCanvasLayerTwo.width = this.drawingCanvasLayerTwo.width;
1807
- this.drawingCanvasLayerThree.width = this.drawingCanvasLayerThree.width;
1808
- }
1809
- redrawDisplayCanvas() {
1810
- var _a, _b, _c;
1811
- this.updateCurrentContrastSlice();
1812
- this.displayCanvas.width = this.displayCanvas.width;
1813
- this.displayCanvas.height = this.displayCanvas.height;
1814
- this.originCanvas.width = this.originCanvas.width;
1815
- if (this.currentShowingSlice) {
1816
- this.currentShowingSlice.repaint.call(this.currentShowingSlice);
1817
- (_a = this.displayCtx) === null || _a === void 0 ? void 0 : _a.save();
1818
- this.flipDisplayImageByAxis();
1819
- (_b = this.displayCtx) === null || _b === void 0 ? void 0 : _b.drawImage(this.currentShowingSlice.canvas, 0, 0, this.nrrd_states.changedWidth, this.nrrd_states.changedHeight);
1820
- (_c = this.displayCtx) === null || _c === void 0 ? void 0 : _c.restore();
1821
- }
1822
- }
1823
- redrawMianPreOnDisplayCanvas() {
1824
- var _a;
1825
- this.displayCanvas.width = this.displayCanvas.width;
1826
- this.displayCanvas.height = this.displayCanvas.height;
1827
- this.originCanvas.width = this.originCanvas.width;
1828
- if (this.mainPreSlice) {
1829
- this.mainPreSlice.repaint.call(this.mainPreSlice);
1830
- this.flipDisplayImageByAxis();
1831
- (_a = this.displayCtx) === null || _a === void 0 ? void 0 : _a.drawImage(this.originCanvas, 0, 0, this.nrrd_states.changedWidth, this.nrrd_states.changedHeight);
1832
- this.resizePaintArea(this.nrrd_states.sizeFoctor);
1833
- }
1834
- }
1835
- resizePaintArea(factor) {
1836
- /**
1837
- * clear canvas
1838
- */
1839
- this.originCanvas.width = this.originCanvas.width;
1840
- this.displayCanvas.width = this.displayCanvas.width;
1841
- this.drawingCanvas.width = this.drawingCanvas.width;
1842
- this.resetLayerCanvas();
1843
- this.nrrd_states.changedWidth = this.nrrd_states.originWidth * factor;
1844
- this.nrrd_states.changedHeight = this.nrrd_states.originHeight * factor;
1845
- /**
1846
- * resize canvas
1847
- */
1848
- this.displayCanvas.width = this.nrrd_states.changedWidth;
1849
- this.displayCanvas.height = this.nrrd_states.changedHeight;
1850
- this.drawingCanvas.width = this.nrrd_states.changedWidth;
1851
- this.drawingCanvas.height = this.nrrd_states.changedHeight;
1852
- this.drawingCanvasLayerMaster.width = this.nrrd_states.changedWidth;
1853
- this.drawingCanvasLayerMaster.height = this.nrrd_states.changedHeight;
1854
- this.drawingCanvasLayerOne.width = this.nrrd_states.changedWidth;
1855
- this.drawingCanvasLayerOne.height = this.nrrd_states.changedHeight;
1856
- this.drawingCanvasLayerTwo.width = this.nrrd_states.changedWidth;
1857
- this.drawingCanvasLayerTwo.height = this.nrrd_states.changedHeight;
1858
- this.drawingCanvasLayerThree.width = this.nrrd_states.changedWidth;
1859
- this.drawingCanvasLayerThree.height = this.nrrd_states.changedHeight;
1860
- this.redrawDisplayCanvas();
1861
- this.reloadMaskToLabel(this.paintImages, this.drawingLayerMasterCtx);
1862
- this.reloadMaskToLabel(this.paintImagesLabel1, this.drawingLayerOneCtx);
1863
- this.reloadMaskToLabel(this.paintImagesLabel2, this.drawingLayerTwoCtx);
1864
- this.reloadMaskToLabel(this.paintImagesLabel3, this.drawingLayerTwoCtx);
1865
- }
1866
- /**
1867
- * Used to init the mask on each label and reload
1868
- * @param paintImages
1869
- * @param ctx
1870
- */
1871
- reloadMaskToLabel(paintImages, ctx) {
1872
- let paintedImage;
1873
- switch (this.axis) {
1874
- case "x":
1875
- if (paintImages.x.length > 0) {
1876
- paintedImage = this.filterDrawedImage("x", this.nrrd_states.currentIndex, paintImages);
1877
- }
1878
- else {
1879
- paintedImage = undefined;
1880
- }
1881
- break;
1882
- case "y":
1883
- if (paintImages.y.length > 0) {
1884
- paintedImage = this.filterDrawedImage("y", this.nrrd_states.currentIndex, paintImages);
1885
- }
1886
- else {
1887
- paintedImage = undefined;
1888
- }
1889
- break;
1890
- case "z":
1891
- if (paintImages.z.length > 0) {
1892
- paintedImage = this.filterDrawedImage("z", this.nrrd_states.currentIndex, paintImages);
1893
- }
1894
- else {
1895
- paintedImage = undefined;
1896
- }
1897
- break;
1898
- }
1899
- if (paintedImage === null || paintedImage === void 0 ? void 0 : paintedImage.image) {
1900
- // redraw the stored data to empty point 1
1901
- this.setEmptyCanvasSize();
1902
- this.emptyCtx.putImageData(paintedImage.image, 0, 0);
1903
- ctx === null || ctx === void 0 ? void 0 : ctx.drawImage(this.emptyCanvas, 0, 0, this.nrrd_states.changedWidth, this.nrrd_states.changedHeight);
1904
- }
1905
- }
1906
- flipDisplayImageByAxis() {
1907
- var _a, _b, _c, _d;
1908
- if (this.axis === "x") {
1909
- (_a = this.displayCtx) === null || _a === void 0 ? void 0 : _a.scale(-1, -1);
1910
- (_b = this.displayCtx) === null || _b === void 0 ? void 0 : _b.translate(-this.nrrd_states.changedWidth, -this.nrrd_states.changedHeight);
1911
- }
1912
- else if (this.axis === "z") {
1913
- (_c = this.displayCtx) === null || _c === void 0 ? void 0 : _c.scale(1, -1);
1914
- (_d = this.displayCtx) === null || _d === void 0 ? void 0 : _d.translate(0, -this.nrrd_states.changedHeight);
1915
- }
1916
- // this.displayCtx?.scale(1, -1);
1917
- // this.displayCtx?.translate(0, -this.nrrd_states.changedHeight);
1918
- }
1919
- filterDrawedImage(axis, sliceIndex, paintedImages) {
1920
- return paintedImages[axis].filter((item) => {
1921
- return item.index === sliceIndex;
1922
- })[0];
1923
- }
1924
- // remove all folders gui controllers
1925
- removeGuiFolderChilden(modeFolder) {
1926
- const subControllers = modeFolder.__controllers;
1927
- if (subControllers.length > 0)
1928
- subControllers.forEach((c) => {
1929
- setTimeout(() => {
1930
- modeFolder.remove(c);
1931
- }, 100);
1932
- });
1933
- }
1934
- // Not use this function now!!!
1935
- verifyCanvasIsEmpty(canvas) {
1936
- this.emptyCanvas.width = canvas.width;
1937
- this.emptyCanvas.height = canvas.height;
1938
- const validation = canvas.toDataURL() === this.emptyCanvas.toDataURL();
1939
- return validation;
1940
- }
1941
- clearDictionary(dic) {
1942
- for (var key in dic) {
1943
- delete dic[key];
1944
- }
1945
- }
1946
- drawImageOnEmptyImage(canvas) {
1947
- this.emptyCtx.drawImage(canvas, 0, 0, this.emptyCanvas.width, this.emptyCanvas.height);
1948
- }
1949
- storeSphereImages(index, axis) {
1950
- this.setEmptyCanvasSize(axis);
1951
- this.drawImageOnEmptyImage(this.drawingSphereCanvas);
1952
- let imageData = this.emptyCtx.getImageData(0, 0, this.emptyCanvas.width, this.emptyCanvas.height);
1953
- this.storeImageToAxis(index, this.paintImages, imageData, axis);
1954
- }
1955
- storeAllImages(index, label) {
1956
- // const image: HTMLImageElement = new Image();
1957
- // resize the drawing image data
1958
- if (!this.nrrd_states.loadMaskJson && !this.gui_states.sphere) {
1959
- this.setEmptyCanvasSize();
1960
- this.drawImageOnEmptyImage(this.drawingCanvasLayerMaster);
1961
- }
1962
- let imageData = this.emptyCtx.getImageData(0, 0, this.emptyCanvas.width, this.emptyCanvas.height);
1963
- // 1.12.23
1964
- switch (this.axis) {
1965
- case "x":
1966
- const maskData_x = this.checkSharedPlaceSlice(this.nrrd_states.nrrd_x_pixel, this.nrrd_states.nrrd_y_pixel, imageData);
1967
- const marked_a_x = this.sliceArrayV(maskData_x, this.nrrd_states.nrrd_y_pixel, this.nrrd_states.nrrd_z_pixel);
1968
- const marked_b_x = this.sliceArrayH(maskData_x, this.nrrd_states.nrrd_y_pixel, this.nrrd_states.nrrd_z_pixel);
1969
- // const ratio_a_x =
1970
- // this.nrrd_states.nrrd_z / this.nrrd_states.dimensions[2];
1971
- // const ratio_b_x =
1972
- // this.nrrd_states.nrrd_y / this.nrrd_states.dimensions[1];
1973
- const convertXIndex = index;
1974
- // from x the target z will replace the col pixel
1975
- this.replaceVerticalColPixels(this.paintImages.z, this.nrrd_states.dimensions[2],
1976
- // this.nrrd_states.ratios.z,
1977
- 1, marked_a_x, this.nrrd_states.nrrd_x_pixel, convertXIndex);
1978
- // from x the target y will replace the col pixel
1979
- this.replaceVerticalColPixels(this.paintImages.y, this.nrrd_states.dimensions[1],
1980
- // this.nrrd_states.ratios.y,
1981
- 1, marked_b_x, this.nrrd_states.nrrd_x_pixel, convertXIndex);
1982
- break;
1983
- case "y":
1984
- const maskData_y = this.checkSharedPlaceSlice(this.nrrd_states.nrrd_x_pixel, this.nrrd_states.nrrd_y_pixel, imageData);
1985
- const marked_a_y = this.sliceArrayV(maskData_y, this.nrrd_states.nrrd_z_pixel, this.nrrd_states.nrrd_x_pixel);
1986
- const marked_b_y = this.sliceArrayH(maskData_y, this.nrrd_states.nrrd_z_pixel, this.nrrd_states.nrrd_x_pixel);
1987
- // const ratio_a_y =
1988
- // this.nrrd_states.nrrd_x / this.nrrd_states.dimensions[0];
1989
- // const ratio_b_y =
1990
- // this.nrrd_states.nrrd_z / this.nrrd_states.dimensions[2];
1991
- const convertYIndex = index;
1992
- this.replaceHorizontalRowPixels(this.paintImages.x, this.nrrd_states.dimensions[0],
1993
- // this.nrrd_states.ratios.x,
1994
- 1, marked_a_y, this.nrrd_states.nrrd_z_pixel, convertYIndex);
1995
- this.replaceHorizontalRowPixels(this.paintImages.z, this.nrrd_states.dimensions[2],
1996
- // this.nrrd_states.ratios.z,
1997
- 1, marked_b_y, this.nrrd_states.nrrd_x_pixel, convertYIndex);
1998
- break;
1999
- case "z":
2000
- // for x slices get cols' pixels
2001
- // for y slices get rows' pixels
2002
- // 1. slice z 的 y轴对应了slice y的index,所以我们可以通过slice z 确定在y轴上那些行是有pixels的,我们就可以将它的y坐标(或者是行号)对应到slice y的index,并将该index下的marked image提取出来。
2003
- // 2. 接着我们可以通过当前slice z 的index,来确定marked image 需要替换或重组的 行 pixel array。
2004
- const maskData_z = this.checkSharedPlaceSlice(this.nrrd_states.nrrd_x_pixel, this.nrrd_states.nrrd_y_pixel, imageData);
2005
- // 1. get slice z's each row's and col's pixel as a 2d array.
2006
- // 1.1 get the cols' 2d array for slice x
2007
- const marked_a_z = this.sliceArrayV(maskData_z, this.nrrd_states.nrrd_y_pixel, this.nrrd_states.nrrd_x_pixel);
2008
- // 1.2 get the rows' 2d array for slice y
2009
- const marked_b_z = this.sliceArrayH(maskData_z, this.nrrd_states.nrrd_y_pixel, this.nrrd_states.nrrd_x_pixel);
2010
- // 1.3 get x axis ratio for converting, to match the number slice x with the slice z's x axis pixel number.
2011
- // const ratio_a_z =
2012
- // this.nrrd_states.nrrd_x / this.nrrd_states.dimensions[0];
2013
- // // 1.4 get y axis ratio for converting
2014
- // const ratio_b_z =
2015
- // this.nrrd_states.nrrd_y / this.nrrd_states.dimensions[1];
2016
- // 1.5 To identify which row/col data should be replace
2017
- const convertZIndex = index;
2018
- // 2. Mapping coordinates
2019
- // from z the target x will replace the col pixel
2020
- this.replaceVerticalColPixels(this.paintImages.x, this.nrrd_states.dimensions[0],
2021
- // this.nrrd_states.ratios.x,
2022
- 1, marked_a_z, this.nrrd_states.nrrd_z_pixel, convertZIndex);
2023
- // from z the target y will replace row pixel
2024
- this.replaceHorizontalRowPixels(this.paintImages.y, this.nrrd_states.dimensions[1],
2025
- // this.nrrd_states.ratios.y,
2026
- 1, marked_b_z, this.nrrd_states.nrrd_x_pixel, convertZIndex);
2027
- break;
2028
- }
2029
- this.storeImageToAxis(index, this.paintImages, imageData);
2030
- if (!this.nrrd_states.loadMaskJson && !this.gui_states.sphere) {
2031
- this.storeEachLayerImage(index, label);
2032
- }
2033
- }
2034
- storeImageToAxis(index, paintedImages, imageData, axis) {
2035
- var _a, _b, _c;
2036
- let temp = {
2037
- index,
2038
- image: imageData,
2039
- };
2040
- let drawedImage;
2041
- switch (!!axis ? axis : this.axis) {
2042
- case "x":
2043
- drawedImage = this.filterDrawedImage("x", index, paintedImages);
2044
- drawedImage
2045
- ? (drawedImage.image = imageData)
2046
- : (_a = paintedImages.x) === null || _a === void 0 ? void 0 : _a.push(temp);
2047
- break;
2048
- case "y":
2049
- drawedImage = this.filterDrawedImage("y", index, paintedImages);
2050
- drawedImage
2051
- ? (drawedImage.image = imageData)
2052
- : (_b = paintedImages.y) === null || _b === void 0 ? void 0 : _b.push(temp);
2053
- break;
2054
- case "z":
2055
- drawedImage = this.filterDrawedImage("z", index, paintedImages);
2056
- drawedImage
2057
- ? (drawedImage.image = imageData)
2058
- : (_c = paintedImages.z) === null || _c === void 0 ? void 0 : _c.push(temp);
2059
- break;
2060
- }
2061
- }
2062
- storeImageToLabel(index, canvas, paintedImages) {
2063
- if (!this.nrrd_states.loadMaskJson) {
2064
- this.setEmptyCanvasSize();
2065
- this.drawImageOnEmptyImage(canvas);
2066
- }
2067
- const imageData = this.emptyCtx.getImageData(0, 0, this.emptyCanvas.width, this.emptyCanvas.height);
2068
- this.storeImageToAxis(index, paintedImages, imageData);
2069
- // this.setEmptyCanvasSize()
2070
- return imageData;
2071
- }
2072
- storeEachLayerImage(index, label) {
2073
- if (!this.nrrd_states.loadMaskJson) {
2074
- this.setEmptyCanvasSize();
2075
- }
2076
- let imageData;
2077
- switch (label) {
2078
- case "label1":
2079
- imageData = this.storeImageToLabel(index, this.drawingCanvasLayerOne, this.paintImagesLabel1);
2080
- break;
2081
- case "label2":
2082
- imageData = this.storeImageToLabel(index, this.drawingCanvasLayerTwo, this.paintImagesLabel2);
2083
- break;
2084
- case "label3":
2085
- imageData = this.storeImageToLabel(index, this.drawingCanvasLayerThree, this.paintImagesLabel3);
2086
- break;
2087
- }
2088
- // callback function to return the painted image
2089
- if (!this.nrrd_states.loadMaskJson && this.axis == "z") {
2090
- this.nrrd_states.getMask(imageData, this.nrrd_states.currentIndex, label, this.nrrd_states.nrrd_x_pixel, this.nrrd_states.nrrd_y_pixel, this.nrrd_states.clearAllFlag);
2091
- }
2092
- }
2093
- // slice array to 2d array
2094
- sliceArrayH(arr, row, col) {
2095
- const arr2D = [];
2096
- for (let i = 0; i < row; i++) {
2097
- const start = i * col * 4;
2098
- const end = (i + 1) * col * 4;
2099
- const temp = arr.slice(start, end);
2100
- arr2D.push(temp);
2101
- }
2102
- return arr2D;
2103
- }
2104
- sliceArrayV(arr, row, col) {
2105
- const arr2D = [];
2106
- const base = col * 4;
2107
- for (let i = 0; i < col; i++) {
2108
- const temp = [];
2109
- for (let j = 0; j < row; j++) {
2110
- const index = base * j + i * 4;
2111
- temp.push(arr[index]);
2112
- temp.push(arr[index + 1]);
2113
- temp.push(arr[index + 2]);
2114
- temp.push(arr[index + 3]);
2115
- }
2116
- arr2D.push(temp);
2117
- }
2118
- return arr2D;
2119
- }
2120
- /**
2121
- *
2122
- * @param paintImageArray : the target view slice's marked images array
2123
- * @param length : the target view slice's dimention (total slice index num)
2124
- * @param ratio : the target slice image's width/height ratio of its dimention length
2125
- * @param markedArr : current painted image's vertical 2d Array
2126
- * @param targetWidth : the target image width
2127
- * @param convertIndex : Mapping current image's index to target slice image's width/height pixel start point
2128
- */
2129
- replaceVerticalColPixels(paintImageArray, length, ratio, markedArr, targetWidth, convertIndex) {
2130
- for (let i = 0, len = length; i < len; i++) {
2131
- const index = Math.floor(i * ratio);
2132
- const convertImageArray = paintImageArray[i].image.data;
2133
- const mark_data = markedArr[index];
2134
- const base_a = targetWidth * 4;
2135
- for (let j = 0, len = mark_data.length; j < len; j += 4) {
2136
- const start = (j / 4) * base_a + convertIndex * 4;
2137
- convertImageArray[start] = mark_data[j];
2138
- convertImageArray[start + 1] = mark_data[j + 1];
2139
- convertImageArray[start + 2] = mark_data[j + 2];
2140
- convertImageArray[start + 3] = mark_data[j + 3];
2141
- }
2142
- }
2143
- }
2144
- /**
2145
- *
2146
- * @param paintImageArray : the target view slice's marked images array
2147
- * @param length : the target view slice's dimention (total slice index num)
2148
- * @param ratio : the target slice image's width/height ratio of its dimention length
2149
- * @param markedArr : current painted image's horizontal 2d Array
2150
- * @param targetWidth : the target image width
2151
- * @param convertIndex : Mapping current image's index to target slice image's width/height pixel start point
2152
- */
2153
- replaceHorizontalRowPixels(paintImageArray, length, ratio, markedArr, targetWidth, convertIndex) {
2154
- for (let i = 0, len = length; i < len; i++) {
2155
- const index = Math.floor(i * ratio);
2156
- const convertImageArray = paintImageArray[i].image.data;
2157
- const mark_data = markedArr[index];
2158
- const start = targetWidth * convertIndex * 4;
2159
- for (let j = 0, len = mark_data.length; j < len; j++) {
2160
- convertImageArray[start + j] = mark_data[j];
2161
- }
2162
- }
2163
- }
2164
- // set the empty canvas width and height, to reduce duplicate codes
2165
- setEmptyCanvasSize(axis) {
2166
- switch (!!axis ? axis : this.axis) {
2167
- case "x":
2168
- this.emptyCanvas.width = this.nrrd_states.nrrd_z_pixel;
2169
- this.emptyCanvas.height = this.nrrd_states.nrrd_y_pixel;
2170
- break;
2171
- case "y":
2172
- this.emptyCanvas.width = this.nrrd_states.nrrd_x_pixel;
2173
- this.emptyCanvas.height = this.nrrd_states.nrrd_z_pixel;
2174
- break;
2175
- case "z":
2176
- this.emptyCanvas.width = this.nrrd_states.nrrd_x_pixel;
2177
- this.emptyCanvas.height = this.nrrd_states.nrrd_y_pixel;
2178
- break;
2179
- }
2180
- }
2181
- setSphereCanvasSize(axis) {
2182
- switch (!!axis ? axis : this.axis) {
2183
- case "x":
2184
- this.drawingSphereCanvas.width = this.nrrd_states.nrrd_z_mm;
2185
- this.drawingSphereCanvas.height = this.nrrd_states.nrrd_y_mm;
2186
- break;
2187
- case "y":
2188
- this.drawingSphereCanvas.width = this.nrrd_states.nrrd_x_mm;
2189
- this.drawingSphereCanvas.height = this.nrrd_states.nrrd_z_mm;
2190
- break;
2191
- case "z":
2192
- this.drawingSphereCanvas.width = this.nrrd_states.nrrd_x_mm;
2193
- this.drawingSphereCanvas.height = this.nrrd_states.nrrd_y_mm;
2194
- break;
2195
- }
2196
- }
2197
- checkSharedPlaceSlice(width, height, imageData) {
2198
- let maskData = this.emptyCtx.createImageData(width, height).data;
2199
- if (this.nrrd_states.sharedPlace.z.includes(this.nrrd_states.currentIndex)) {
2200
- const sharedPlaceArr = this.findSliceInSharedPlace();
2201
- sharedPlaceArr.push(imageData);
2202
- if (sharedPlaceArr.length > 0) {
2203
- for (let i = 0; i < sharedPlaceArr.length; i++) {
2204
- this.replaceArray(maskData, sharedPlaceArr[i].data);
2205
- }
2206
- }
2207
- }
2208
- else {
2209
- maskData = imageData.data;
2210
- }
2211
- return maskData;
2212
- }
2213
- // replace Array
2214
- replaceArray(mainArr, replaceArr) {
2215
- for (let i = 0, len = replaceArr.length; i < len; i++) {
2216
- if (replaceArr[i] === 0 || mainArr[i] !== 0) {
2217
- continue;
2218
- }
2219
- else {
2220
- mainArr[i] = replaceArr[i];
2221
- }
2222
- }
2223
- }
2224
- findSliceInSharedPlace() {
2225
- const sharedPlaceImages = [];
2226
- const base = Math.floor(this.nrrd_states.currentIndex * this.nrrd_states.ratios[this.axis]);
2227
- for (let i = 1; i <= 3; i++) {
2228
- const index = this.nrrd_states.currentIndex - i;
2229
- if (index < this.nrrd_states.minIndex) {
2230
- break;
2231
- }
2232
- else {
2233
- const newIndex = Math.floor(index * this.nrrd_states.ratios[this.axis]);
2234
- if (newIndex === base) {
2235
- sharedPlaceImages.push(this.paintImages[this.axis][index].image);
2236
- }
2237
- }
2238
- }
2239
- for (let i = 1; i <= 3; i++) {
2240
- const index = this.nrrd_states.currentIndex + i;
2241
- if (index > this.nrrd_states.maxIndex) {
2242
- break;
2243
- }
2244
- else {
2245
- const newIndex = Math.floor(index * this.nrrd_states.ratios[this.axis]);
2246
- if (newIndex === base) {
2247
- sharedPlaceImages.push(this.paintImages[this.axis][index].image);
2248
- }
2249
- }
2250
- }
2251
- return sharedPlaceImages;
2252
- }
2253
- exportData() {
2254
- let exportDataFormat = { x: [], y: [], z: [] };
2255
- // exportDataFormat.x = this.restructData(
2256
- // this.paintImages.x,
2257
- // this.paintImages.x.length
2258
- // );
2259
- // exportDataFormat.y = this.restructData(
2260
- // this.paintImages.y,
2261
- // this.paintImages.y.length
2262
- // );
2263
- // const worker = new Worker(
2264
- // new URL("./workers/reformatSaveDataWorker.ts", import.meta.url),
2265
- // {
2266
- // type: "module",
2267
- // }
2268
- // );
2269
- window.alert("Export masks, starting!!!");
2270
- const masks = restructData(this.paintImages.z, this.nrrd_states.nrrd_z_pixel, this.nrrd_states.nrrd_x_pixel, this.nrrd_states.nrrd_y_pixel);
2271
- const blob = convertReformatDataToBlob(masks);
2272
- if (blob) {
2273
- saveFileAsJson(blob, "copper3D_export data_z.json");
2274
- window.alert("Export masks successfully!!!");
2275
- }
2276
- else {
2277
- window.alert("Export failed!");
2278
- }
2279
- // worker.postMessage({
2280
- // masksData: this.paintImages.z,
2281
- // len: this.paintImages.z.length,
2282
- // width: this.nrrd_states.nrrd_x_pixel,
2283
- // height: this.nrrd_states.nrrd_y_pixel,
2284
- // type: "reformat",
2285
- // });
2286
- // worker.onmessage = (ev: MessageEvent) => {
2287
- // const result = ev.data;
2288
- // if (result.type === "reformat") {
2289
- // exportDataFormat.z = result.masks;
2290
- // worker.postMessage({
2291
- // masksData: exportDataFormat.z,
2292
- // type: "saveBlob",
2293
- // });
2294
- // } else if (result.type === "saveBlob") {
2295
- // if (result.data) {
2296
- // saveFileAsJson(result.data, "copper3D_export data_z.json");
2297
- // window.alert("Export masks successfully!!!");
2298
- // } else {
2299
- // window.alert("Export failed!");
2300
- // }
2301
- // }
2302
- // };
2303
- }
2304
- configGui(modeFolder) {
2305
- if (modeFolder.__controllers.length > 0)
2306
- this.removeGuiFolderChilden(modeFolder);
2307
- modeFolder.open();
2308
- const actionsFolder = modeFolder.addFolder("DefaultActions");
2309
- actionsFolder
2310
- .add(this.gui_states, "globalAlpha")
2311
- .name("Opacity")
2312
- .min(0.1)
2313
- .max(1)
2314
- .step(0.01);
2315
- actionsFolder
2316
- .add(this.gui_states, "segmentation")
2317
- .name("Pencil")
2318
- .onChange(() => {
2319
- if (this.gui_states.segmentation) {
2320
- // add canvas brush circle move event listeners
2321
- this.drawingCanvas.removeEventListener("mouseover", this.drawingPrameters.handleOnDrawingBrushCricleMove);
2322
- this.drawingCanvas.removeEventListener("mouseout", this.drawingPrameters.handleOnDrawingBrushCricleMove);
2323
- }
2324
- else {
2325
- // add canvas brush circle move event listeners
2326
- this.drawingCanvas.addEventListener("mouseover", this.drawingPrameters.handleOnDrawingBrushCricleMove);
2327
- this.drawingCanvas.addEventListener("mouseout", this.drawingPrameters.handleOnDrawingBrushCricleMove);
2328
- }
2329
- });
2330
- actionsFolder
2331
- .add(this.gui_states, "sphere")
2332
- .name("Sphere")
2333
- .onChange(() => {
2334
- if (this.gui_states.sphere) {
2335
- this.drawingCanvas.removeEventListener("wheel", this.drawingPrameters.handleZoomWheel);
2336
- this.removeDragMode();
2337
- }
2338
- else {
2339
- this.drawingCanvas.addEventListener("wheel", this.drawingPrameters.handleZoomWheel);
2340
- this.configDragMode();
2341
- // clear canvas
2342
- this.clearPaint();
2343
- this.clearStoreImages();
2344
- }
2345
- });
2346
- actionsFolder
2347
- .add(this.gui_states, "brushAndEraserSize")
2348
- .name("BrushAndEraserSize")
2349
- .min(5)
2350
- .max(50)
2351
- .step(1)
2352
- .onChange(() => {
2353
- if (this.gui_states.Eraser) {
2354
- this.eraserUrls.length > 0
2355
- ? (this.drawingCanvas.style.cursor = switchEraserSize(this.gui_states.brushAndEraserSize, this.eraserUrls))
2356
- : (this.drawingCanvas.style.cursor = switchEraserSize(this.gui_states.brushAndEraserSize));
2357
- }
2358
- });
2359
- actionsFolder.add(this.gui_states, "Eraser").onChange((value) => {
2360
- this.gui_states.Eraser = value;
2361
- if (this.gui_states.Eraser) {
2362
- this.eraserUrls.length > 0
2363
- ? (this.drawingCanvas.style.cursor = switchEraserSize(this.gui_states.brushAndEraserSize, this.eraserUrls))
2364
- : (this.drawingCanvas.style.cursor = switchEraserSize(this.gui_states.brushAndEraserSize));
2365
- }
2366
- else {
2367
- this.drawingCanvas.style.cursor = this.nrrd_states.defaultPaintCursor;
2368
- }
2369
- });
2370
- actionsFolder.add(this.gui_states, "clear").name("Clear");
2371
- actionsFolder.add(this.gui_states, "clearAll").name("ClearAll");
2372
- actionsFolder.add(this.gui_states, "undo").name("Undo");
2373
- actionsFolder.add(this.gui_states, "resetZoom").name("ResetZoom");
2374
- actionsFolder
2375
- .add(this.mainPreSlice.volume, "windowHigh", this.mainPreSlice.volume.min, this.mainPreSlice.volume.max, 1)
2376
- .name("ImageContrast")
2377
- .onChange((value) => {
2378
- this.nrrd_states.readyToUpdate = false;
2379
- this.updateSlicesContrast(value, "windowHigh");
2380
- })
2381
- .onFinishChange(() => {
2382
- this.repraintAllContrastSlices();
2383
- this.nrrd_states.readyToUpdate = true;
2384
- });
2385
- const advanceFolder = modeFolder.addFolder("AdvanceSettings");
2386
- advanceFolder
2387
- .add(this.gui_states, "label", ["label1", "label2", "label3"])
2388
- .name("Label")
2389
- .onChange((val) => {
2390
- if (val === "label1") {
2391
- this.gui_states.fillColor = "#00ff00";
2392
- this.gui_states.brushColor = "#00ff00";
2393
- }
2394
- else if (val === "label2") {
2395
- this.gui_states.fillColor = "#ff0000";
2396
- this.gui_states.brushColor = "#ff0000";
2397
- }
2398
- else if (val === "label3") {
2399
- this.gui_states.fillColor = "#0000ff";
2400
- this.gui_states.brushColor = "#0000ff";
2401
- }
2402
- });
2403
- advanceFolder
2404
- .add(this.gui_states, "cursor", ["crosshair", "pencil", "dot"])
2405
- .name("CursorIcons")
2406
- .onChange((value) => {
2407
- this.nrrd_states.defaultPaintCursor = switchPencilIcon(value, this.pencilUrls);
2408
- this.drawingCanvas.style.cursor = this.nrrd_states.defaultPaintCursor;
2409
- });
2410
- advanceFolder
2411
- .add(this.gui_states, "mainAreaSize")
2412
- .name("Zoom")
2413
- .min(1)
2414
- .max(8)
2415
- .onFinishChange((factor) => {
2416
- this.resetPaintArea();
2417
- this.nrrd_states.sizeFoctor = factor;
2418
- this.resizePaintArea(factor);
2419
- });
2420
- advanceFolder
2421
- .add(this.gui_states, "dragSensitivity")
2422
- .name("DragSensitivity")
2423
- .min(1)
2424
- .max(this.nrrd_states.Max_sensitive)
2425
- .step(1);
2426
- const segmentationFolder = advanceFolder.addFolder("PencilSettings");
2427
- segmentationFolder
2428
- .add(this.gui_states, "lineWidth")
2429
- .name("OuterLineWidth")
2430
- .min(1.7)
2431
- .max(3)
2432
- .step(0.01);
2433
- segmentationFolder.addColor(this.gui_states, "color").name("Color");
2434
- segmentationFolder.addColor(this.gui_states, "fillColor").name("FillColor");
2435
- const bushFolder = advanceFolder.addFolder("BrushSettings");
2436
- bushFolder.addColor(this.gui_states, "brushColor").name("BrushColor");
2437
- // modeFolder.add(this.stateMode, "EraserSize").min(1).max(50).step(1);
2438
- const maskFolder = advanceFolder.addFolder("MaskDownload");
2439
- maskFolder
2440
- .add(this.gui_states, "downloadCurrentMask")
2441
- .name("DownloadCurrentMask");
2442
- maskFolder.add(this.gui_states, "exportMarks").name("ExportMask");
2443
- const contrastFolder = advanceFolder.addFolder("ContrastAdvanceSettings");
2444
- contrastFolder
2445
- .add(this.mainPreSlice.volume, "lowerThreshold", this.mainPreSlice.volume.min, this.mainPreSlice.volume.max, 1)
2446
- .name("LowerThreshold")
2447
- .onChange((value) => {
2448
- this.nrrd_states.readyToUpdate = false;
2449
- this.updateSlicesContrast(value, "lowerThreshold");
2450
- })
2451
- .onFinishChange(() => {
2452
- this.repraintAllContrastSlices();
2453
- this.nrrd_states.readyToUpdate = true;
2454
- });
2455
- contrastFolder
2456
- .add(this.mainPreSlice.volume, "upperThreshold", this.mainPreSlice.volume.min, this.mainPreSlice.volume.max, 1)
2457
- .name("UpperThreshold")
2458
- .onChange((value) => {
2459
- this.nrrd_states.readyToUpdate = false;
2460
- this.updateSlicesContrast(value, "upperThreshold");
2461
- })
2462
- .onFinishChange(() => {
2463
- this.repraintAllContrastSlices();
2464
- this.nrrd_states.readyToUpdate = true;
2465
- });
2466
- contrastFolder
2467
- .add(this.mainPreSlice.volume, "windowLow", this.mainPreSlice.volume.min, this.mainPreSlice.volume.max, 1)
2468
- .name("WindowLow")
2469
- .onChange((value) => {
2470
- this.nrrd_states.readyToUpdate = false;
2471
- this.updateSlicesContrast(value, "windowLow");
2472
- })
2473
- .onFinishChange(() => {
2474
- this.repraintAllContrastSlices();
2475
- this.nrrd_states.readyToUpdate = true;
2476
- });
2477
- actionsFolder.open();
2478
- }
2479
- }
2480
- //# sourceMappingURL=nrrd_tool.js.map