copper3d 1.15.10 → 1.15.12

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.
@@ -14,6 +14,7 @@ export class nrrd_tools {
14
14
  label2: this.paintImagesLabel2,
15
15
  label3: this.paintImagesLabel3,
16
16
  };
17
+ // used to store display marks with multiple labels
17
18
  this.paintImages = { x: [], y: [], z: [] };
18
19
  // store all contrast slices, include x, y, z orientation
19
20
  this.allSlicesArray = [];
@@ -41,7 +42,6 @@ export class nrrd_tools {
41
42
  this.Is_Shift_Pressed = false;
42
43
  this.Is_Draw = false;
43
44
  this.sensitiveArray = [];
44
- this.handleWheelMove = () => { };
45
45
  this.start = () => { };
46
46
  this.undoArray = [];
47
47
  this.initState = true;
@@ -77,6 +77,10 @@ export class nrrd_tools {
77
77
  isCursorSelect: false,
78
78
  cursorPageX: 0,
79
79
  cursorPageY: 0,
80
+ // x: [cursorX, cursorY, sliceIndex]
81
+ sphereOrigin: { x: [0, 0, 0], y: [0, 0, 0], z: [0, 0, 0] },
82
+ spherePlanB: false,
83
+ sphereRadius: 10,
80
84
  Mouse_Over_x: 0,
81
85
  Mouse_Over_y: 0,
82
86
  Mouse_Over: false,
@@ -126,12 +130,9 @@ export class nrrd_tools {
126
130
  brushAndEraserSize: 15,
127
131
  cursor: "dot",
128
132
  label: "label1",
133
+ sphere: false,
129
134
  // EraserSize: 25,
130
135
  clear: () => {
131
- // const text = "Are you sure remove annotations on Current slice?";
132
- // if (confirm(text) === true) {
133
- // this.clearPaint();
134
- // }
135
136
  this.clearPaint();
136
137
  },
137
138
  clearAll: () => {
@@ -165,6 +166,36 @@ export class nrrd_tools {
165
166
  this.exportData();
166
167
  },
167
168
  };
169
+ this.dragPrameters = {
170
+ move: 0,
171
+ y: 0,
172
+ h: 0,
173
+ sensivity: 1,
174
+ handleOnDragMouseUp: (ev) => { },
175
+ handleOnDragMouseDown: (ev) => { },
176
+ handleOnDragMouseMove: (ev) => { },
177
+ };
178
+ this.drawingPrameters = {
179
+ handleOnDrawingMouseDown: (ev) => { },
180
+ handleOnDrawingMouseMove: (ev) => { },
181
+ handleOnPanMouseMove: (ev) => { },
182
+ handleOnDrawingMouseUp: (ev) => { },
183
+ handleOnDrawingMouseLeave: (ev) => { },
184
+ handleOnDrawingBrushCricleMove: (ev) => { },
185
+ handleZoomWheel: (e) => { },
186
+ handleSphereWheel: (e) => { },
187
+ };
188
+ this.configDragMode = () => {
189
+ this.container.style.cursor = "pointer";
190
+ this.container.addEventListener("pointerdown", this.dragPrameters.handleOnDragMouseDown, true);
191
+ this.container.addEventListener("pointerup", this.dragPrameters.handleOnDragMouseUp, true);
192
+ };
193
+ this.removeDragMode = () => {
194
+ this.container.style.cursor = "";
195
+ this.container.removeEventListener("pointerdown", this.dragPrameters.handleOnDragMouseDown, true);
196
+ this.container.removeEventListener("pointerup", this.dragPrameters.handleOnDragMouseUp, true);
197
+ this.setIsDrawFalse(1000);
198
+ };
168
199
  this.drawLine = (x1, y1, x2, y2) => {
169
200
  this.drawingCtx.beginPath();
170
201
  this.drawingCtx.moveTo(x1, y1);
@@ -197,7 +228,7 @@ export class nrrd_tools {
197
228
  this.sensitiveArray.push((i + 1) / 20);
198
229
  }
199
230
  this.container.addEventListener("keydown", (ev) => {
200
- if (ev.key === "Shift") {
231
+ if (ev.key === "Shift" && !this.gui_states.sphere) {
201
232
  this.Is_Shift_Pressed = true;
202
233
  this.nrrd_states.enableCursorChoose = false;
203
234
  }
@@ -377,12 +408,94 @@ export class nrrd_tools {
377
408
  paintImages.z.push(initMark_z);
378
409
  }
379
410
  }
411
+ convertCursorPoint(from, to, cursorNumX, cursorNumY, currentSliceIndex) {
412
+ const nrrd = this.nrrd_states;
413
+ const dimensions = nrrd.dimensions;
414
+ const ratios = nrrd.ratios;
415
+ const { nrrd_x_mm, nrrd_y_mm, nrrd_z_mm } = nrrd;
416
+ let currentIndex = 0;
417
+ let oldIndex = 0;
418
+ let convertCursorNumX = 0;
419
+ let convertCursorNumY = 0;
420
+ const convertIndex = {
421
+ x: {
422
+ y: (val) => Math.ceil((val / nrrd_x_mm) * dimensions[0]),
423
+ z: (val) => Math.ceil((val / nrrd_z_mm) * dimensions[2]),
424
+ },
425
+ y: {
426
+ x: (val) => Math.ceil((val / nrrd_y_mm) * dimensions[1]),
427
+ z: (val) => Math.ceil((val / nrrd_z_mm) * dimensions[2]),
428
+ },
429
+ z: {
430
+ x: (val) => Math.ceil((val / nrrd_x_mm) * dimensions[0]),
431
+ y: (val) => Math.ceil((val / nrrd_y_mm) * dimensions[1]),
432
+ },
433
+ };
434
+ const convertCursor = {
435
+ x: {
436
+ y: (sliceIndex) => Math.ceil((sliceIndex / dimensions[0]) * nrrd_x_mm),
437
+ z: (sliceIndex) => Math.ceil((sliceIndex / dimensions[0]) * nrrd_x_mm),
438
+ },
439
+ y: {
440
+ x: (sliceIndex) => Math.ceil((sliceIndex / dimensions[1]) * nrrd_y_mm),
441
+ z: (sliceIndex) => Math.ceil((sliceIndex / dimensions[1]) * nrrd_y_mm),
442
+ },
443
+ z: {
444
+ x: (sliceIndex) => Math.ceil((sliceIndex / dimensions[2]) * nrrd_z_mm),
445
+ y: (sliceIndex) => Math.ceil((sliceIndex / dimensions[2]) * nrrd_z_mm),
446
+ },
447
+ };
448
+ if (from === to) {
449
+ return;
450
+ }
451
+ if (from === "z" && to === "x") {
452
+ currentIndex = convertIndex[from][to](cursorNumX);
453
+ oldIndex = currentIndex * ratios[to];
454
+ convertCursorNumX = convertCursor[from][to](currentSliceIndex);
455
+ convertCursorNumY = cursorNumY;
456
+ }
457
+ else if (from === "y" && to === "x") {
458
+ currentIndex = convertIndex[from][to](cursorNumX);
459
+ oldIndex = currentIndex * ratios.x;
460
+ convertCursorNumY = convertCursor[from][to](currentSliceIndex);
461
+ convertCursorNumX = cursorNumY;
462
+ }
463
+ else if (from === "z" && to === "y") {
464
+ currentIndex = convertIndex[from][to](cursorNumY);
465
+ oldIndex = currentIndex * ratios[to];
466
+ convertCursorNumY = convertCursor[from][to](currentSliceIndex);
467
+ convertCursorNumX = cursorNumX;
468
+ }
469
+ else if (from === "x" && to === "y") {
470
+ currentIndex = convertIndex[from][to](cursorNumY);
471
+ oldIndex = currentIndex * ratios[to];
472
+ convertCursorNumX = convertCursor[from][to](currentSliceIndex);
473
+ convertCursorNumY = cursorNumX;
474
+ }
475
+ else if (from === "x" && to === "z") {
476
+ currentIndex = convertIndex[from][to](cursorNumX);
477
+ oldIndex = currentIndex * ratios[to];
478
+ convertCursorNumX = convertCursor[from][to](currentSliceIndex);
479
+ convertCursorNumY = cursorNumY;
480
+ }
481
+ else if (from === "y" && to === "z") {
482
+ currentIndex = convertIndex[from][to](cursorNumY);
483
+ oldIndex = currentIndex * ratios.z;
484
+ convertCursorNumY = convertCursor[from][to](currentSliceIndex);
485
+ convertCursorNumX = cursorNumX;
486
+ }
487
+ else {
488
+ return;
489
+ }
490
+ return { currentIndex, oldIndex, convertCursorNumX, convertCursorNumY };
491
+ }
380
492
  /**
381
493
  * Switch all contrast slices' orientation
382
494
  * @param {string} aixs:"x" | "y" | "z"
383
495
  * */
384
- setSliceOrientation(axis) {
385
- if (this.nrrd_states.enableCursorChoose) {
496
+ setSliceOrientation(axisTo) {
497
+ let convetObj;
498
+ if (this.nrrd_states.enableCursorChoose || this.gui_states.sphere) {
386
499
  if (this.axis === "z") {
387
500
  this.cursorPage.z.index = this.nrrd_states.currentIndex;
388
501
  this.cursorPage.z.cursorPageX = this.nrrd_states.cursorPageX;
@@ -398,27 +511,19 @@ export class nrrd_tools {
398
511
  this.cursorPage.y.cursorPageX = this.nrrd_states.cursorPageX;
399
512
  this.cursorPage.y.cursorPageY = this.nrrd_states.cursorPageY;
400
513
  }
401
- if (axis === "z") {
514
+ if (axisTo === "z") {
402
515
  if (this.nrrd_states.isCursorSelect && !this.cursorPage.z.updated) {
403
516
  if (this.axis === "x") {
404
- this.nrrd_states.currentIndex = Math.ceil((this.cursorPage.x.cursorPageX / this.nrrd_states.nrrd_z_mm) *
405
- this.nrrd_states.dimensions[2]);
406
- this.nrrd_states.oldIndex =
407
- this.nrrd_states.currentIndex * this.nrrd_states.ratios.z;
408
- this.nrrd_states.cursorPageX = Math.ceil((this.cursorPage.x.index / this.nrrd_states.dimensions[0]) *
409
- this.nrrd_states.nrrd_x_mm);
517
+ // convert x to z
518
+ convetObj = this.convertCursorPoint("x", "z", this.cursorPage.x.cursorPageX, this.cursorPage.x.cursorPageY, this.cursorPage.x.index);
410
519
  }
411
520
  if (this.axis === "y") {
412
- this.nrrd_states.currentIndex = Math.ceil((this.cursorPage.y.cursorPageY / this.nrrd_states.nrrd_z_mm) *
413
- this.nrrd_states.dimensions[2]);
414
- this.nrrd_states.oldIndex =
415
- this.nrrd_states.currentIndex * this.nrrd_states.ratios.z;
416
- this.nrrd_states.cursorPageY = Math.ceil((this.cursorPage.y.index / this.nrrd_states.dimensions[1]) *
417
- this.nrrd_states.nrrd_y_mm);
521
+ // convert y to z
522
+ convetObj = this.convertCursorPoint("y", "z", this.cursorPage.y.cursorPageX, this.cursorPage.y.cursorPageY, this.cursorPage.y.index);
418
523
  }
419
- this.cursorPage.z.updated = true;
420
524
  }
421
525
  else {
526
+ // not cursor select, freedom to switch x -> z or y -> z and z -> x or z -> y
422
527
  this.nrrd_states.currentIndex = this.cursorPage.z.index;
423
528
  this.nrrd_states.oldIndex =
424
529
  this.cursorPage.z.index * this.nrrd_states.ratios.z;
@@ -426,28 +531,19 @@ export class nrrd_tools {
426
531
  this.nrrd_states.cursorPageY = this.cursorPage.z.cursorPageY;
427
532
  }
428
533
  }
429
- else if (axis === "x") {
534
+ else if (axisTo === "x") {
430
535
  if (this.nrrd_states.isCursorSelect && !this.cursorPage.x.updated) {
431
536
  if (this.axis === "z") {
432
- this.nrrd_states.currentIndex = Math.ceil((this.cursorPage.z.cursorPageX / this.nrrd_states.nrrd_x_mm) *
433
- this.nrrd_states.dimensions[0]);
434
- this.nrrd_states.oldIndex =
435
- this.nrrd_states.currentIndex * this.nrrd_states.ratios.x;
436
- this.nrrd_states.cursorPageX = Math.floor((this.cursorPage.z.index / this.nrrd_states.dimensions[2]) *
437
- this.nrrd_states.nrrd_z_mm);
537
+ // convert z to x
538
+ convetObj = this.convertCursorPoint("z", "x", this.cursorPage.z.cursorPageX, this.cursorPage.z.cursorPageY, this.cursorPage.z.index);
438
539
  }
439
540
  if (this.axis === "y") {
440
- this.nrrd_states.currentIndex = Math.ceil((this.cursorPage.y.cursorPageX / this.nrrd_states.nrrd_y_mm) *
441
- this.nrrd_states.dimensions[1]);
442
- this.nrrd_states.oldIndex =
443
- this.nrrd_states.currentIndex * this.nrrd_states.ratios.x;
444
- this.nrrd_states.cursorPageX = this.cursorPage.y.cursorPageY;
445
- this.nrrd_states.cursorPageY = Math.ceil((this.cursorPage.y.index / this.nrrd_states.dimensions[1]) *
446
- this.nrrd_states.nrrd_y_mm);
541
+ // convert y to x
542
+ convetObj = this.convertCursorPoint("y", "x", this.cursorPage.y.cursorPageX, this.cursorPage.y.cursorPageY, this.cursorPage.y.index);
447
543
  }
448
- this.cursorPage.x.updated = true;
449
544
  }
450
545
  else {
546
+ // not cursor select, freedom to switch z -> x or y -> x and x -> z or x -> y
451
547
  this.nrrd_states.currentIndex = this.cursorPage.x.index;
452
548
  this.nrrd_states.oldIndex =
453
549
  this.cursorPage.x.index * this.nrrd_states.ratios.x;
@@ -455,28 +551,19 @@ export class nrrd_tools {
455
551
  this.nrrd_states.cursorPageY = this.cursorPage.x.cursorPageY;
456
552
  }
457
553
  }
458
- else if (axis === "y") {
554
+ else if (axisTo === "y") {
459
555
  if (this.nrrd_states.isCursorSelect && !this.cursorPage.y.updated) {
460
556
  if (this.axis === "z") {
461
- this.nrrd_states.currentIndex = Math.ceil((this.cursorPage.z.cursorPageY / this.nrrd_states.nrrd_y_mm) *
462
- this.nrrd_states.dimensions[1]);
463
- this.nrrd_states.oldIndex =
464
- this.nrrd_states.currentIndex * this.nrrd_states.ratios.y;
465
- this.nrrd_states.cursorPageY = Math.ceil((this.cursorPage.z.index / this.nrrd_states.dimensions[2]) *
466
- this.nrrd_states.nrrd_z_mm);
557
+ // convert z to y
558
+ convetObj = this.convertCursorPoint("z", "y", this.cursorPage.z.cursorPageX, this.cursorPage.z.cursorPageY, this.cursorPage.z.index);
467
559
  }
468
560
  if (this.axis === "x") {
469
- this.nrrd_states.currentIndex = Math.ceil((this.cursorPage.x.cursorPageY / this.nrrd_states.nrrd_x_mm) *
470
- this.nrrd_states.dimensions[0]);
471
- this.nrrd_states.oldIndex =
472
- this.nrrd_states.currentIndex * this.nrrd_states.ratios.y;
473
- this.nrrd_states.cursorPageX = Math.ceil((this.cursorPage.x.index / this.nrrd_states.dimensions[0]) *
474
- this.nrrd_states.nrrd_x_mm);
475
- this.nrrd_states.cursorPageY = this.cursorPage.x.cursorPageX;
561
+ // convert x to y
562
+ convetObj = this.convertCursorPoint("x", "y", this.cursorPage.x.cursorPageX, this.cursorPage.x.cursorPageY, this.cursorPage.x.index);
476
563
  }
477
- this.cursorPage.y.updated = true;
478
564
  }
479
565
  else {
566
+ // not cursor select, freedom to switch z -> y or x -> y and y -> z or y -> x
480
567
  this.nrrd_states.currentIndex = this.cursorPage.y.index;
481
568
  this.nrrd_states.oldIndex =
482
569
  this.cursorPage.y.index * this.nrrd_states.ratios.y;
@@ -484,14 +571,38 @@ export class nrrd_tools {
484
571
  this.nrrd_states.cursorPageY = this.cursorPage.y.cursorPageY;
485
572
  }
486
573
  }
574
+ if (convetObj) {
575
+ // update convert cursor point, when cursor select
576
+ this.nrrd_states.currentIndex = convetObj.currentIndex;
577
+ this.nrrd_states.oldIndex = convetObj.oldIndex;
578
+ this.nrrd_states.cursorPageX = convetObj.convertCursorNumX;
579
+ this.nrrd_states.cursorPageY = convetObj.convertCursorNumY;
580
+ convetObj = undefined;
581
+ switch (axisTo) {
582
+ case "x":
583
+ this.cursorPage.x.updated = true;
584
+ break;
585
+ case "y":
586
+ this.cursorPage.y.updated = true;
587
+ break;
588
+ case "z":
589
+ this.cursorPage.z.updated = true;
590
+ break;
591
+ }
592
+ }
487
593
  if (this.cursorPage.x.updated &&
488
594
  this.cursorPage.y.updated &&
489
595
  this.cursorPage.z.updated) {
596
+ // one point convert to all axis, reset all updated status
490
597
  this.nrrd_states.isCursorSelect = false;
491
598
  }
492
599
  }
493
- this.axis = axis;
600
+ this.axis = axisTo;
494
601
  this.resetDisplaySlicesStatus();
602
+ // for sphere plan a
603
+ if (this.gui_states.sphere && !this.nrrd_states.spherePlanB) {
604
+ this.drawSphere(this.nrrd_states.sphereOrigin[axisTo][0], this.nrrd_states.sphereOrigin[axisTo][1], this.nrrd_states.sphereRadius);
605
+ }
495
606
  }
496
607
  addSkip(index) {
497
608
  this.skipSlicesDic[index] = this.backUpDisplaySlices[index];
@@ -568,6 +679,15 @@ export class nrrd_tools {
568
679
  this.resetPaintArea();
569
680
  this.setIsDrawFalse(1000);
570
681
  }
682
+ getContainer() {
683
+ return this.mainAreaContainer;
684
+ }
685
+ getDrawingCanvas() {
686
+ return this.drawingCanvas;
687
+ }
688
+ getNrrdToolsSettings() {
689
+ return this.nrrd_states;
690
+ }
571
691
  getMaxSliceNum() {
572
692
  if (this.nrrd_states.showContrast) {
573
693
  return [
@@ -808,62 +928,51 @@ export class nrrd_tools {
808
928
  this.mainAreaContainer.appendChild(loadingbar);
809
929
  }
810
930
  drag(opts) {
811
- let move;
812
- let y;
813
- let h = this.container.offsetHeight;
814
- let sensivity = 1;
815
- let handleOnMouseUp;
816
- let handleOnMouseDown;
817
- let handleOnMouseMove;
931
+ this.dragPrameters.h = this.container.offsetHeight;
818
932
  this.sensitiveArray.reverse();
819
933
  if (opts === null || opts === void 0 ? void 0 : opts.showNumber) {
820
934
  this.container.appendChild(this.showDragNumberDiv);
821
935
  }
822
- handleOnMouseDown = (ev) => {
936
+ this.dragPrameters.handleOnDragMouseDown = (ev) => {
823
937
  // before start drag event, remove wheel event.
824
- this.drawingCanvas.removeEventListener("wheel", this.handleWheelMove);
938
+ this.drawingCanvas.removeEventListener("wheel", this.drawingPrameters.handleZoomWheel);
825
939
  if (ev.button === 0) {
826
940
  // this.setSyncsliceNum();
827
- y = ev.offsetY / h;
828
- this.container.addEventListener("pointermove", handleOnMouseMove, false);
829
- sensivity = this.sensitiveArray[this.gui_states.dragSensitivity - 1];
941
+ this.dragPrameters.y = ev.offsetY / this.dragPrameters.h;
942
+ this.container.addEventListener("pointermove", this.dragPrameters.handleOnDragMouseMove, false);
943
+ this.dragPrameters.sensivity =
944
+ this.sensitiveArray[this.gui_states.dragSensitivity - 1];
830
945
  }
831
946
  };
832
- handleOnMouseMove = throttle((ev) => {
833
- if (y - ev.offsetY / h >= 0) {
834
- move = -Math.ceil(((y - ev.offsetY / h) * 10) / sensivity);
947
+ this.dragPrameters.handleOnDragMouseMove = throttle((ev) => {
948
+ if (this.dragPrameters.y - ev.offsetY / this.dragPrameters.h >= 0) {
949
+ this.dragPrameters.move = -Math.ceil(((this.dragPrameters.y - ev.offsetY / this.dragPrameters.h) * 10) /
950
+ this.dragPrameters.sensivity);
835
951
  }
836
952
  else {
837
- move = -Math.floor(((y - ev.offsetY / h) * 10) / sensivity);
953
+ this.dragPrameters.move = -Math.floor(((this.dragPrameters.y - ev.offsetY / this.dragPrameters.h) * 10) /
954
+ this.dragPrameters.sensivity);
838
955
  }
839
- this.updateIndex(move);
956
+ this.updateIndex(this.dragPrameters.move);
840
957
  (opts === null || opts === void 0 ? void 0 : opts.getSliceNum) &&
841
958
  opts.getSliceNum(this.nrrd_states.currentIndex, this.nrrd_states.contrastNum);
842
- y = ev.offsetY / h;
843
- }, sensivity * 200);
844
- handleOnMouseUp = (ev) => {
959
+ this.dragPrameters.y = ev.offsetY / this.dragPrameters.h;
960
+ }, this.dragPrameters.sensivity * 200);
961
+ this.dragPrameters.handleOnDragMouseUp = (ev) => {
845
962
  // after drag, add the wheel event
846
- this.drawingCanvas.addEventListener("wheel", this.handleWheelMove);
963
+ this.drawingCanvas.addEventListener("wheel", this.drawingPrameters.handleZoomWheel);
847
964
  this.setSyncsliceNum();
848
- this.container.removeEventListener("pointermove", handleOnMouseMove, false);
849
- };
850
- const configDragMode = () => {
851
- this.container.style.cursor = "pointer";
852
- this.container.addEventListener("pointerdown", handleOnMouseDown, true);
853
- this.container.addEventListener("pointerup", handleOnMouseUp, true);
965
+ this.container.removeEventListener("pointermove", this.dragPrameters.handleOnDragMouseMove, false);
854
966
  };
855
- configDragMode();
967
+ this.configDragMode();
856
968
  this.container.addEventListener("keydown", (ev) => {
857
969
  if (ev.key === "Shift") {
858
- this.container.style.cursor = "";
859
- this.container.removeEventListener("pointerdown", handleOnMouseDown, true);
860
- this.container.removeEventListener("pointerup", handleOnMouseUp, false);
861
- this.setIsDrawFalse(1000);
970
+ this.removeDragMode();
862
971
  }
863
972
  });
864
973
  this.container.addEventListener("keyup", (ev) => {
865
- if (ev.key === "Shift") {
866
- configDragMode();
974
+ if (ev.key === "Shift" && !this.gui_states.sphere) {
975
+ this.configDragMode();
867
976
  }
868
977
  });
869
978
  }
@@ -1021,6 +1130,7 @@ export class nrrd_tools {
1021
1130
  // draw lines starts position
1022
1131
  let Is_Painting = false;
1023
1132
  let lines = [];
1133
+ const clearArc = this.useEraser();
1024
1134
  this.updateOriginAndChangedWH();
1025
1135
  this.initAllCanvas();
1026
1136
  this.configGui(modeFolder);
@@ -1030,12 +1140,15 @@ export class nrrd_tools {
1030
1140
  (_c = this.displayCtx) === null || _c === void 0 ? void 0 : _c.restore();
1031
1141
  this.previousDrawingImage = this.drawingCtx.getImageData(0, 0, this.drawingCanvas.width, this.drawingCanvas.height);
1032
1142
  // let a global variable to store the wheel move event
1033
- this.handleWheelMove = this.configMouseWheel((_d = this.sceneIn) === null || _d === void 0 ? void 0 : _d.controls);
1143
+ this.drawingPrameters.handleZoomWheel = this.configMouseZoomWheel((_d = this.sceneIn) === null || _d === void 0 ? void 0 : _d.controls);
1034
1144
  // init to add it
1035
- this.drawingCanvas.addEventListener("wheel", this.handleWheelMove, {
1145
+ this.drawingCanvas.addEventListener("wheel", this.drawingPrameters.handleZoomWheel, {
1036
1146
  passive: false,
1037
1147
  });
1038
- const handleDragPaintPanel = (e) => {
1148
+ // sphere Wheel
1149
+ this.drawingPrameters.handleSphereWheel = this.configMouseSphereWheel();
1150
+ // pan move
1151
+ this.drawingPrameters.handleOnPanMouseMove = (e) => {
1039
1152
  this.drawingCanvas.style.cursor = "grabbing";
1040
1153
  this.nrrd_states.previousPanelL = e.clientX - panelMoveInnerX;
1041
1154
  this.nrrd_states.previousPanelT = e.clientY - panelMoveInnerY;
@@ -1044,8 +1157,9 @@ export class nrrd_tools {
1044
1157
  this.displayCanvas.style.top = this.drawingCanvas.style.top =
1045
1158
  this.nrrd_states.previousPanelT + "px";
1046
1159
  };
1047
- // throttle(, 80);
1048
- const handleDisplayMouseMove = (e) => {
1160
+ // brush circle move
1161
+ this.drawingPrameters.handleOnDrawingBrushCricleMove = (e) => {
1162
+ e.preventDefault();
1049
1163
  this.nrrd_states.Mouse_Over_x = e.offsetX;
1050
1164
  this.nrrd_states.Mouse_Over_y = e.offsetY;
1051
1165
  if (this.nrrd_states.Mouse_Over_x === undefined) {
@@ -1054,21 +1168,31 @@ export class nrrd_tools {
1054
1168
  }
1055
1169
  if (e.type === "mouseout") {
1056
1170
  this.nrrd_states.Mouse_Over = false;
1057
- this.drawingCanvas.removeEventListener("mousemove", handleDisplayMouseMove);
1171
+ this.drawingCanvas.removeEventListener("mousemove", this.drawingPrameters.handleOnDrawingBrushCricleMove);
1058
1172
  }
1059
1173
  else if (e.type === "mouseover") {
1060
1174
  this.nrrd_states.Mouse_Over = true;
1061
- this.drawingCanvas.addEventListener("mousemove", handleDisplayMouseMove);
1175
+ this.drawingCanvas.addEventListener("mousemove", this.drawingPrameters.handleOnDrawingBrushCricleMove);
1062
1176
  }
1063
- e.preventDefault();
1064
1177
  };
1065
- // add canvas event listeners
1066
- this.drawingCanvas.addEventListener("mouseover", handleDisplayMouseMove);
1067
- this.drawingCanvas.addEventListener("mouseout", handleDisplayMouseMove);
1068
- // disable browser right click menu
1069
- this.drawingCanvas.addEventListener("pointerdown", (e) => {
1178
+ // drawing move
1179
+ this.drawingPrameters.handleOnDrawingMouseMove = (e) => {
1180
+ this.Is_Draw = true;
1181
+ if (Is_Painting) {
1182
+ if (this.gui_states.Eraser) {
1183
+ this.nrrd_states.stepClear = 1;
1184
+ // drawingCtx.clearRect(e.offsetX - 5, e.offsetY - 5, 25, 25);
1185
+ clearArc(e.offsetX, e.offsetY, this.gui_states.brushAndEraserSize);
1186
+ }
1187
+ else {
1188
+ lines.push({ x: e.offsetX, y: e.offsetY });
1189
+ this.paintOnCanvasLayer(e.offsetX, e.offsetY);
1190
+ }
1191
+ }
1192
+ };
1193
+ this.drawingPrameters.handleOnDrawingMouseDown = (e) => {
1070
1194
  if (leftclicked || rightclicked) {
1071
- this.drawingCanvas.removeEventListener("pointerup", handlePointerUp);
1195
+ this.drawingCanvas.removeEventListener("pointerup", this.drawingPrameters.handleOnDrawingMouseUp);
1072
1196
  this.drawingLayerMasterCtx.closePath();
1073
1197
  return;
1074
1198
  }
@@ -1079,7 +1203,7 @@ export class nrrd_tools {
1079
1203
  currentSliceIndex = this.mainPreSlice.index;
1080
1204
  }
1081
1205
  // remove it when mouse click down
1082
- this.drawingCanvas.removeEventListener("wheel", this.handleWheelMove);
1206
+ this.drawingCanvas.removeEventListener("wheel", this.drawingPrameters.handleZoomWheel);
1083
1207
  if (e.button === 0) {
1084
1208
  if (this.Is_Shift_Pressed) {
1085
1209
  leftclicked = true;
@@ -1099,32 +1223,24 @@ export class nrrd_tools {
1099
1223
  }
1100
1224
  this.nrrd_states.drawStartPos.set(e.offsetX, e.offsetY);
1101
1225
  // this.drawingLayerMasterCtx.beginPath();
1102
- this.drawingCanvas.addEventListener("pointerup", handlePointerUp);
1103
- this.drawingCanvas.addEventListener("pointermove", handleOnPainterMove);
1226
+ this.drawingCanvas.addEventListener("pointerup", this.drawingPrameters.handleOnDrawingMouseUp);
1227
+ this.drawingCanvas.addEventListener("pointermove", this.drawingPrameters.handleOnDrawingMouseMove);
1104
1228
  }
1105
1229
  else if (this.nrrd_states.enableCursorChoose) {
1106
1230
  this.nrrd_states.cursorPageX =
1107
1231
  e.offsetX / this.nrrd_states.sizeFoctor;
1108
1232
  this.nrrd_states.cursorPageY =
1109
1233
  e.offsetY / this.nrrd_states.sizeFoctor;
1110
- this.nrrd_states.isCursorSelect = true;
1111
- switch (this.axis) {
1112
- case "x":
1113
- this.cursorPage.x.updated = true;
1114
- this.cursorPage.y.updated = false;
1115
- this.cursorPage.z.updated = false;
1116
- break;
1117
- case "y":
1118
- this.cursorPage.x.updated = false;
1119
- this.cursorPage.y.updated = true;
1120
- this.cursorPage.z.updated = false;
1121
- break;
1122
- case "z":
1123
- this.cursorPage.x.updated = false;
1124
- this.cursorPage.y.updated = false;
1125
- this.cursorPage.z.updated = true;
1126
- break;
1127
- }
1234
+ this.enableCrosshair();
1235
+ }
1236
+ else if (this.gui_states.sphere) {
1237
+ console.log("sphere down");
1238
+ let mouseX = e.offsetX;
1239
+ let mouseY = e.offsetY;
1240
+ // draw circle
1241
+ this.drawSphere(mouseX, mouseY, this.nrrd_states.sphereRadius);
1242
+ this.drawingCanvas.addEventListener("wheel", this.drawingPrameters.handleSphereWheel, true);
1243
+ this.drawingCanvas.addEventListener("pointerup", this.drawingPrameters.handleOnDrawingMouseUp);
1128
1244
  }
1129
1245
  }
1130
1246
  else if (e.button === 2) {
@@ -1136,28 +1252,15 @@ export class nrrd_tools {
1136
1252
  panelMoveInnerX = e.clientX - offsetX;
1137
1253
  panelMoveInnerY = e.clientY - offsetY;
1138
1254
  this.drawingCanvas.style.cursor = "grab";
1139
- this.drawingCanvas.addEventListener("pointerup", handlePointerUp);
1140
- this.drawingCanvas.addEventListener("pointermove", handleDragPaintPanel);
1255
+ this.drawingCanvas.addEventListener("pointerup", this.drawingPrameters.handleOnDrawingMouseUp);
1256
+ this.drawingCanvas.addEventListener("pointermove", this.drawingPrameters.handleOnPanMouseMove);
1141
1257
  }
1142
1258
  else {
1143
1259
  return;
1144
1260
  }
1145
- }, true);
1146
- const clearArc = this.useEraser();
1147
- const handleOnPainterMove = (e) => {
1148
- this.Is_Draw = true;
1149
- if (Is_Painting) {
1150
- if (this.gui_states.Eraser) {
1151
- this.nrrd_states.stepClear = 1;
1152
- // drawingCtx.clearRect(e.offsetX - 5, e.offsetY - 5, 25, 25);
1153
- clearArc(e.offsetX, e.offsetY, this.gui_states.brushAndEraserSize);
1154
- }
1155
- else {
1156
- lines.push({ x: e.offsetX, y: e.offsetY });
1157
- this.paintOnCanvasLayer(e.offsetX, e.offsetY);
1158
- }
1159
- }
1160
1261
  };
1262
+ // disable browser right click menu
1263
+ this.drawingCanvas.addEventListener("pointerdown", this.drawingPrameters.handleOnDrawingMouseDown, true);
1161
1264
  const redrawPreviousImageToLabelCtx = (ctx, label = "default") => {
1162
1265
  var _a;
1163
1266
  let paintImages;
@@ -1184,13 +1287,13 @@ export class nrrd_tools {
1184
1287
  // draw privous image
1185
1288
  ctx.drawImage(this.emptyCanvas, 0, 0, this.nrrd_states.changedWidth, this.nrrd_states.changedHeight);
1186
1289
  };
1187
- const handlePointerUp = (e) => {
1290
+ this.drawingPrameters.handleOnDrawingMouseUp = (e) => {
1188
1291
  if (e.button === 0) {
1189
1292
  if (this.Is_Shift_Pressed || Is_Painting) {
1190
1293
  leftclicked = false;
1191
1294
  let { ctx, canvas } = this.setCurrentLayer();
1192
1295
  ctx.closePath();
1193
- this.drawingCanvas.removeEventListener("pointermove", handleOnPainterMove);
1296
+ this.drawingCanvas.removeEventListener("pointermove", this.drawingPrameters.handleOnDrawingMouseMove);
1194
1297
  if (!this.gui_states.Eraser) {
1195
1298
  if (this.gui_states.segmentation) {
1196
1299
  this.drawingCanvasLayerMaster.width =
@@ -1238,20 +1341,66 @@ export class nrrd_tools {
1238
1341
  undoObj.layers[this.gui_states.label].push(image);
1239
1342
  this.undoArray.push(undoObj);
1240
1343
  }
1344
+ // add wheel after pointer up
1345
+ this.drawingCanvas.addEventListener("wheel", this.drawingPrameters.handleZoomWheel, {
1346
+ passive: false,
1347
+ });
1348
+ }
1349
+ else if (this.gui_states.sphere &&
1350
+ !this.nrrd_states.enableCursorChoose) {
1351
+ console.log("sphere up");
1352
+ let { ctx, canvas } = this.setCurrentLayer();
1353
+ let mouseX = e.offsetX;
1354
+ let mouseY = e.offsetY;
1355
+ this.nrrd_states.sphereOrigin[this.axis] = [
1356
+ mouseX,
1357
+ mouseY,
1358
+ this.nrrd_states.currentIndex,
1359
+ ];
1360
+ /************ */
1361
+ this.setUpSphereOrigins(mouseX, mouseY);
1362
+ console.log(this.nrrd_states.sphereOrigin);
1363
+ this.nrrd_states.cursorPageX = mouseX;
1364
+ this.nrrd_states.cursorPageY = mouseY;
1365
+ this.enableCrosshair();
1366
+ // plan B
1367
+ // findout all index in the sphere radius range in Axial view
1368
+ if (this.nrrd_states.spherePlanB) {
1369
+ // clear stroe images
1370
+ this.clearStoreImages();
1371
+ for (let i = 0; i < this.nrrd_states.sphereRadius; i++) {
1372
+ this.setEmptyCanvasSize();
1373
+ const preIndex = this.nrrd_states.currentIndex - i;
1374
+ const nextIndex = this.nrrd_states.currentIndex + i;
1375
+ if (preIndex < this.nrrd_states.minIndex ||
1376
+ nextIndex > this.nrrd_states.maxIndex)
1377
+ return;
1378
+ if (preIndex === nextIndex) {
1379
+ this.drawSphereCore(ctx, mouseX, mouseY, this.nrrd_states.sphereRadius);
1380
+ this.drawImageOnEmptyImage(canvas);
1381
+ this.storeAllImages(preIndex, "");
1382
+ }
1383
+ else {
1384
+ this.drawSphereCore(ctx, mouseX, mouseY, this.nrrd_states.sphereRadius - i);
1385
+ this.drawImageOnEmptyImage(canvas);
1386
+ this.storeAllImages(preIndex, "");
1387
+ this.storeAllImages(nextIndex, "");
1388
+ }
1389
+ ctx.clearRect(0, 0, canvas.width, canvas.height);
1390
+ }
1391
+ }
1392
+ console.log(this.nrrd_states.sphereRadius);
1393
+ this.drawingCanvas.removeEventListener("wheel", this.drawingPrameters.handleSphereWheel, true);
1241
1394
  }
1242
1395
  }
1243
1396
  else if (e.button === 2) {
1244
1397
  rightclicked = false;
1245
1398
  this.drawingCanvas.style.cursor = "grab";
1246
- this.drawingCanvas.removeEventListener("pointermove", handleDragPaintPanel);
1399
+ this.drawingCanvas.removeEventListener("pointermove", this.drawingPrameters.handleOnPanMouseMove);
1247
1400
  }
1248
1401
  else {
1249
1402
  return;
1250
1403
  }
1251
- // add wheel after pointer up
1252
- this.drawingCanvas.addEventListener("wheel", this.handleWheelMove, {
1253
- passive: false,
1254
- });
1255
1404
  if (!this.gui_states.segmentation) {
1256
1405
  this.setIsDrawFalse(100);
1257
1406
  }
@@ -1262,12 +1411,13 @@ export class nrrd_tools {
1262
1411
  if (leftclicked) {
1263
1412
  leftclicked = false;
1264
1413
  this.drawingLayerMasterCtx.closePath();
1265
- this.drawingCanvas.removeEventListener("pointermove", handleOnPainterMove);
1414
+ this.drawingCanvas.removeEventListener("pointermove", this.drawingPrameters.handleOnDrawingMouseMove);
1415
+ this.drawingCanvas.removeEventListener("wheel", this.drawingPrameters.handleSphereWheel, true);
1266
1416
  }
1267
1417
  if (rightclicked) {
1268
1418
  rightclicked = false;
1269
1419
  this.drawingCanvas.style.cursor = "grab";
1270
- this.drawingCanvas.removeEventListener("pointermove", handleDragPaintPanel);
1420
+ this.drawingCanvas.removeEventListener("pointermove", this.drawingPrameters.handleOnPanMouseMove);
1271
1421
  }
1272
1422
  this.setIsDrawFalse(100);
1273
1423
  if (this.gui_states.segmentation) {
@@ -1322,6 +1472,68 @@ export class nrrd_tools {
1322
1472
  }
1323
1473
  });
1324
1474
  }
1475
+ enableCrosshair() {
1476
+ this.nrrd_states.isCursorSelect = true;
1477
+ switch (this.axis) {
1478
+ case "x":
1479
+ this.cursorPage.x.updated = true;
1480
+ this.cursorPage.y.updated = false;
1481
+ this.cursorPage.z.updated = false;
1482
+ break;
1483
+ case "y":
1484
+ this.cursorPage.x.updated = false;
1485
+ this.cursorPage.y.updated = true;
1486
+ this.cursorPage.z.updated = false;
1487
+ break;
1488
+ case "z":
1489
+ this.cursorPage.x.updated = false;
1490
+ this.cursorPage.y.updated = false;
1491
+ this.cursorPage.z.updated = true;
1492
+ break;
1493
+ }
1494
+ }
1495
+ setUpSphereOrigins(mouseX, mouseY) {
1496
+ const convertCursor = (from, to) => {
1497
+ const convertObj = this.convertCursorPoint(from, to, mouseX, mouseY, this.nrrd_states.currentIndex);
1498
+ return {
1499
+ convertCursorNumX: convertObj === null || convertObj === void 0 ? void 0 : convertObj.convertCursorNumX,
1500
+ convertCursorNumY: convertObj === null || convertObj === void 0 ? void 0 : convertObj.convertCursorNumY,
1501
+ currentIndex: convertObj === null || convertObj === void 0 ? void 0 : convertObj.currentIndex,
1502
+ };
1503
+ };
1504
+ const axisConversions = {
1505
+ x: { axisTo1: "y", axisTo2: "z" },
1506
+ y: { axisTo1: "z", axisTo2: "x" },
1507
+ z: { axisTo1: "x", axisTo2: "y" },
1508
+ };
1509
+ const { axisTo1, axisTo2 } = axisConversions[this.axis];
1510
+ this.nrrd_states.sphereOrigin[axisTo1] = [
1511
+ convertCursor(this.axis, axisTo1).convertCursorNumX,
1512
+ convertCursor(this.axis, axisTo1).convertCursorNumY,
1513
+ convertCursor(this.axis, axisTo1).currentIndex,
1514
+ ];
1515
+ this.nrrd_states.sphereOrigin[axisTo2] = [
1516
+ convertCursor(this.axis, axisTo2).convertCursorNumX,
1517
+ convertCursor(this.axis, axisTo2).convertCursorNumY,
1518
+ convertCursor(this.axis, axisTo2).currentIndex,
1519
+ ];
1520
+ }
1521
+ // for sphere
1522
+ drawSphereCore(ctx, x, y, radius) {
1523
+ ctx.beginPath();
1524
+ ctx.arc(x, y, radius * this.nrrd_states.sizeFoctor, 0, 2 * Math.PI);
1525
+ ctx.fillStyle = this.gui_states.fillColor;
1526
+ ctx.fill();
1527
+ ctx.closePath();
1528
+ }
1529
+ drawSphere(mouseX, mouseY, radius) {
1530
+ let { ctx, canvas } = this.setCurrentLayer();
1531
+ // clear canvas
1532
+ ctx.clearRect(0, 0, canvas.width, canvas.height);
1533
+ this.drawingLayerMasterCtx.clearRect(0, 0, canvas.width, canvas.height);
1534
+ this.drawSphereCore(ctx, mouseX, mouseY, radius);
1535
+ this.drawingLayerMasterCtx.drawImage(canvas, 0, 0, this.nrrd_states.changedWidth, this.nrrd_states.changedHeight);
1536
+ }
1325
1537
  // need to update
1326
1538
  undoLastPainting() {
1327
1539
  let { ctx, canvas } = this.setCurrentLayer();
@@ -1339,7 +1551,9 @@ export class nrrd_tools {
1339
1551
  if (layerLen > 0) {
1340
1552
  // const imageSrc = undo.undos[undo.undos.length - 1];
1341
1553
  const image = layerUndos[layerLen - 1];
1342
- ctx.drawImage(image, 0, 0, this.nrrd_states.changedWidth, this.nrrd_states.changedHeight);
1554
+ if (!!image) {
1555
+ ctx.drawImage(image, 0, 0, this.nrrd_states.changedWidth, this.nrrd_states.changedHeight);
1556
+ }
1343
1557
  }
1344
1558
  if (undo.layers.label1.length > 0) {
1345
1559
  const image = undo.layers.label1[undo.layers.label1.length - 1];
@@ -1363,9 +1577,29 @@ export class nrrd_tools {
1363
1577
  return item.sliceIndex === this.nrrd_states.currentIndex;
1364
1578
  });
1365
1579
  }
1366
- configMouseWheel(controls) {
1580
+ // drawing canvas mouse shpere wheel
1581
+ configMouseSphereWheel() {
1582
+ const sphereEvent = (e) => {
1583
+ e.preventDefault();
1584
+ if (e.deltaY < 0) {
1585
+ this.nrrd_states.sphereRadius += 1;
1586
+ }
1587
+ else {
1588
+ this.nrrd_states.sphereRadius -= 1;
1589
+ }
1590
+ // limited the radius max and min
1591
+ this.nrrd_states.sphereRadius = Math.max(1, Math.min(this.nrrd_states.sphereRadius, 50));
1592
+ // get mouse position
1593
+ const mouseX = e.offsetX;
1594
+ const mouseY = e.offsetY;
1595
+ this.drawSphere(mouseX, mouseY, this.nrrd_states.sphereRadius);
1596
+ };
1597
+ return sphereEvent;
1598
+ }
1599
+ // drawing canvas mouse zoom wheel
1600
+ configMouseZoomWheel(controls) {
1367
1601
  let moveDistance = 1;
1368
- const handleWheelMove = (e) => {
1602
+ const handleZoomWheelMove = (e) => {
1369
1603
  if (this.Is_Shift_Pressed) {
1370
1604
  return;
1371
1605
  }
@@ -1401,7 +1635,7 @@ export class nrrd_tools {
1401
1635
  }
1402
1636
  this.nrrd_states.sizeFoctor = moveDistance;
1403
1637
  };
1404
- return handleWheelMove;
1638
+ return handleZoomWheelMove;
1405
1639
  }
1406
1640
  useEraser() {
1407
1641
  const clearArc = (x, y, radius) => {
@@ -1512,155 +1746,6 @@ export class nrrd_tools {
1512
1746
  }
1513
1747
  return { ctx, canvas };
1514
1748
  }
1515
- configGui(modeFolder) {
1516
- if (modeFolder.__controllers.length > 0)
1517
- this.removeGuiFolderChilden(modeFolder);
1518
- modeFolder.open();
1519
- const actionsFolder = modeFolder.addFolder("Default Actions");
1520
- actionsFolder
1521
- .add(this.gui_states, "label", ["label1", "label2", "label3"])
1522
- .onChange((val) => {
1523
- if (val === "label1") {
1524
- this.gui_states.fillColor = "#00ff00";
1525
- this.gui_states.brushColor = "#00ff00";
1526
- }
1527
- else if (val === "label2") {
1528
- this.gui_states.fillColor = "#ff0000";
1529
- this.gui_states.brushColor = "#ff0000";
1530
- }
1531
- else if (val === "label3") {
1532
- this.gui_states.fillColor = "#0000ff";
1533
- this.gui_states.brushColor = "#0000ff";
1534
- }
1535
- });
1536
- actionsFolder
1537
- .add(this.gui_states, "cursor", ["crosshair", "pencil", "dot"])
1538
- .name("cursor icons")
1539
- .onChange((value) => {
1540
- if (value === "crosshair") {
1541
- this.nrrd_states.defaultPaintCursor = "crosshair";
1542
- }
1543
- if (value === "pencil") {
1544
- this.nrrd_states.defaultPaintCursor =
1545
- "url(https://raw.githubusercontent.com/LinkunGao/copper3d_icons/main/icons/pencil-black.svg), auto";
1546
- }
1547
- if (value === "dot") {
1548
- this.nrrd_states.defaultPaintCursor =
1549
- "url(https://raw.githubusercontent.com/LinkunGao/copper3d-datasets/main/icons/dot.svg) 12 12,auto";
1550
- }
1551
- this.drawingCanvas.style.cursor = this.nrrd_states.defaultPaintCursor;
1552
- });
1553
- actionsFolder
1554
- .add(this.gui_states, "mainAreaSize")
1555
- .name("zoom")
1556
- .min(1)
1557
- .max(8)
1558
- .onFinishChange((factor) => {
1559
- this.resetPaintArea();
1560
- this.nrrd_states.sizeFoctor = factor;
1561
- this.resizePaintArea(factor);
1562
- });
1563
- actionsFolder.add(this.gui_states, "resetZoom");
1564
- actionsFolder
1565
- .add(this.gui_states, "globalAlpha")
1566
- .name("opacity")
1567
- .min(0.1)
1568
- .max(1)
1569
- .step(0.01);
1570
- actionsFolder.add(this.gui_states, "segmentation").name("Pencil");
1571
- actionsFolder
1572
- .add(this.gui_states, "brushAndEraserSize")
1573
- .min(5)
1574
- .max(50)
1575
- .step(1)
1576
- .onChange(() => {
1577
- if (this.gui_states.Eraser) {
1578
- this.eraserUrls.length > 0
1579
- ? (this.drawingCanvas.style.cursor = switchEraserSize(this.gui_states.brushAndEraserSize, this.eraserUrls))
1580
- : (this.drawingCanvas.style.cursor = switchEraserSize(this.gui_states.brushAndEraserSize));
1581
- }
1582
- });
1583
- actionsFolder.add(this.gui_states, "Eraser").onChange((value) => {
1584
- this.gui_states.Eraser = value;
1585
- if (this.gui_states.Eraser) {
1586
- this.eraserUrls.length > 0
1587
- ? (this.drawingCanvas.style.cursor = switchEraserSize(this.gui_states.brushAndEraserSize, this.eraserUrls))
1588
- : (this.drawingCanvas.style.cursor = switchEraserSize(this.gui_states.brushAndEraserSize));
1589
- }
1590
- else {
1591
- this.drawingCanvas.style.cursor = this.nrrd_states.defaultPaintCursor;
1592
- }
1593
- });
1594
- actionsFolder.add(this.gui_states, "clear");
1595
- actionsFolder.add(this.gui_states, "clearAll");
1596
- actionsFolder.add(this.gui_states, "undo");
1597
- actionsFolder
1598
- .add(this.mainPreSlice.volume, "windowHigh", this.mainPreSlice.volume.min, this.mainPreSlice.volume.max, 1)
1599
- .name("Image contrast")
1600
- .onChange((value) => {
1601
- this.nrrd_states.readyToUpdate = false;
1602
- this.updateSlicesContrast(value, "windowHigh");
1603
- })
1604
- .onFinishChange(() => {
1605
- this.repraintAllContrastSlices();
1606
- this.nrrd_states.readyToUpdate = true;
1607
- });
1608
- actionsFolder.add(this.gui_states, "exportMarks");
1609
- const advanceFolder = modeFolder.addFolder("Advance settings");
1610
- advanceFolder
1611
- .add(this.gui_states, "dragSensitivity")
1612
- .min(1)
1613
- .max(this.nrrd_states.Max_sensitive)
1614
- .step(1);
1615
- const segmentationFolder = advanceFolder.addFolder("Pencil settings");
1616
- segmentationFolder
1617
- .add(this.gui_states, "lineWidth")
1618
- .name("outerLineWidth")
1619
- .min(1.7)
1620
- .max(3)
1621
- .step(0.01);
1622
- segmentationFolder.addColor(this.gui_states, "color");
1623
- segmentationFolder.addColor(this.gui_states, "fillColor");
1624
- const bushFolder = advanceFolder.addFolder("Brush settings");
1625
- bushFolder.addColor(this.gui_states, "brushColor");
1626
- // modeFolder.add(this.stateMode, "EraserSize").min(1).max(50).step(1);
1627
- advanceFolder.add(this.gui_states, "downloadCurrentMask");
1628
- const contrastFolder = advanceFolder.addFolder("contrast advance settings");
1629
- contrastFolder
1630
- .add(this.mainPreSlice.volume, "lowerThreshold", this.mainPreSlice.volume.min, this.mainPreSlice.volume.max, 1)
1631
- .name("Lower Threshold")
1632
- .onChange((value) => {
1633
- this.nrrd_states.readyToUpdate = false;
1634
- this.updateSlicesContrast(value, "lowerThreshold");
1635
- })
1636
- .onFinishChange(() => {
1637
- this.repraintAllContrastSlices();
1638
- this.nrrd_states.readyToUpdate = true;
1639
- });
1640
- contrastFolder
1641
- .add(this.mainPreSlice.volume, "upperThreshold", this.mainPreSlice.volume.min, this.mainPreSlice.volume.max, 1)
1642
- .name("Upper Threshold")
1643
- .onChange((value) => {
1644
- this.nrrd_states.readyToUpdate = false;
1645
- this.updateSlicesContrast(value, "upperThreshold");
1646
- })
1647
- .onFinishChange(() => {
1648
- this.repraintAllContrastSlices();
1649
- this.nrrd_states.readyToUpdate = true;
1650
- });
1651
- contrastFolder
1652
- .add(this.mainPreSlice.volume, "windowLow", this.mainPreSlice.volume.min, this.mainPreSlice.volume.max, 1)
1653
- .name("Window Low")
1654
- .onChange((value) => {
1655
- this.nrrd_states.readyToUpdate = false;
1656
- this.updateSlicesContrast(value, "windowLow");
1657
- })
1658
- .onFinishChange(() => {
1659
- this.repraintAllContrastSlices();
1660
- this.nrrd_states.readyToUpdate = true;
1661
- });
1662
- actionsFolder.open();
1663
- }
1664
1749
  updateSlicesContrast(value, flag) {
1665
1750
  switch (flag) {
1666
1751
  case "lowerThreshold":
@@ -1839,12 +1924,15 @@ export class nrrd_tools {
1839
1924
  delete dic[key];
1840
1925
  }
1841
1926
  }
1927
+ drawImageOnEmptyImage(canvas) {
1928
+ this.emptyCtx.drawImage(canvas, 0, 0, this.emptyCanvas.width, this.emptyCanvas.height);
1929
+ }
1842
1930
  storeAllImages(index, label) {
1843
1931
  // const image: HTMLImageElement = new Image();
1844
1932
  // resize the drawing image data
1845
- if (!this.nrrd_states.loadMaskJson) {
1933
+ if (!this.nrrd_states.loadMaskJson && !this.gui_states.sphere) {
1846
1934
  this.setEmptyCanvasSize();
1847
- this.emptyCtx.drawImage(this.drawingCanvasLayerMaster, 0, 0, this.emptyCanvas.width, this.emptyCanvas.height);
1935
+ this.drawImageOnEmptyImage(this.drawingCanvasLayerMaster);
1848
1936
  }
1849
1937
  let imageData = this.emptyCtx.getImageData(0, 0, this.emptyCanvas.width, this.emptyCanvas.height);
1850
1938
  // 1.12.23
@@ -1914,7 +2002,7 @@ export class nrrd_tools {
1914
2002
  break;
1915
2003
  }
1916
2004
  this.storeImageToAxis(index, this.paintImages, imageData);
1917
- if (!this.nrrd_states.loadMaskJson) {
2005
+ if (!this.nrrd_states.loadMaskJson && !this.gui_states.sphere) {
1918
2006
  this.storeEachLayerImage(index, label);
1919
2007
  }
1920
2008
  }
@@ -1949,7 +2037,7 @@ export class nrrd_tools {
1949
2037
  storeImageToLabel(index, canvas, paintedImages) {
1950
2038
  if (!this.nrrd_states.loadMaskJson) {
1951
2039
  this.setEmptyCanvasSize();
1952
- this.emptyCtx.drawImage(canvas, 0, 0, this.emptyCanvas.width, this.emptyCanvas.height);
2040
+ this.drawImageOnEmptyImage(canvas);
1953
2041
  }
1954
2042
  const imageData = this.emptyCtx.getImageData(0, 0, this.emptyCanvas.width, this.emptyCanvas.height);
1955
2043
  this.storeImageToAxis(index, paintedImages, imageData);
@@ -2172,5 +2260,181 @@ export class nrrd_tools {
2172
2260
  // }
2173
2261
  // };
2174
2262
  }
2263
+ configGui(modeFolder) {
2264
+ if (modeFolder.__controllers.length > 0)
2265
+ this.removeGuiFolderChilden(modeFolder);
2266
+ modeFolder.open();
2267
+ const actionsFolder = modeFolder.addFolder("Default Actions");
2268
+ actionsFolder
2269
+ .add(this.gui_states, "label", ["label1", "label2", "label3"])
2270
+ .onChange((val) => {
2271
+ if (val === "label1") {
2272
+ this.gui_states.fillColor = "#00ff00";
2273
+ this.gui_states.brushColor = "#00ff00";
2274
+ }
2275
+ else if (val === "label2") {
2276
+ this.gui_states.fillColor = "#ff0000";
2277
+ this.gui_states.brushColor = "#ff0000";
2278
+ }
2279
+ else if (val === "label3") {
2280
+ this.gui_states.fillColor = "#0000ff";
2281
+ this.gui_states.brushColor = "#0000ff";
2282
+ }
2283
+ });
2284
+ actionsFolder
2285
+ .add(this.gui_states, "cursor", ["crosshair", "pencil", "dot"])
2286
+ .name("cursor icons")
2287
+ .onChange((value) => {
2288
+ if (value === "crosshair") {
2289
+ this.nrrd_states.defaultPaintCursor = "crosshair";
2290
+ }
2291
+ if (value === "pencil") {
2292
+ this.nrrd_states.defaultPaintCursor =
2293
+ "url(https://raw.githubusercontent.com/LinkunGao/copper3d_icons/main/icons/pencil-black.svg), auto";
2294
+ }
2295
+ if (value === "dot") {
2296
+ this.nrrd_states.defaultPaintCursor =
2297
+ "url(https://raw.githubusercontent.com/LinkunGao/copper3d-datasets/main/icons/dot.svg) 12 12,auto";
2298
+ }
2299
+ this.drawingCanvas.style.cursor = this.nrrd_states.defaultPaintCursor;
2300
+ });
2301
+ actionsFolder
2302
+ .add(this.gui_states, "mainAreaSize")
2303
+ .name("zoom")
2304
+ .min(1)
2305
+ .max(8)
2306
+ .onFinishChange((factor) => {
2307
+ this.resetPaintArea();
2308
+ this.nrrd_states.sizeFoctor = factor;
2309
+ this.resizePaintArea(factor);
2310
+ });
2311
+ actionsFolder.add(this.gui_states, "resetZoom");
2312
+ actionsFolder
2313
+ .add(this.gui_states, "globalAlpha")
2314
+ .name("opacity")
2315
+ .min(0.1)
2316
+ .max(1)
2317
+ .step(0.01);
2318
+ actionsFolder
2319
+ .add(this.gui_states, "segmentation")
2320
+ .name("Pencil")
2321
+ .onChange(() => {
2322
+ if (this.gui_states.segmentation) {
2323
+ // add canvas brush circle move event listeners
2324
+ this.drawingCanvas.removeEventListener("mouseover", this.drawingPrameters.handleOnDrawingBrushCricleMove);
2325
+ this.drawingCanvas.removeEventListener("mouseout", this.drawingPrameters.handleOnDrawingBrushCricleMove);
2326
+ }
2327
+ else {
2328
+ // add canvas brush circle move event listeners
2329
+ this.drawingCanvas.addEventListener("mouseover", this.drawingPrameters.handleOnDrawingBrushCricleMove);
2330
+ this.drawingCanvas.addEventListener("mouseout", this.drawingPrameters.handleOnDrawingBrushCricleMove);
2331
+ }
2332
+ });
2333
+ actionsFolder
2334
+ .add(this.gui_states, "sphere")
2335
+ .name("Sphere")
2336
+ .onChange(() => {
2337
+ if (this.gui_states.sphere) {
2338
+ this.drawingCanvas.removeEventListener("wheel", this.drawingPrameters.handleZoomWheel);
2339
+ this.removeDragMode();
2340
+ }
2341
+ else {
2342
+ this.drawingCanvas.addEventListener("wheel", this.drawingPrameters.handleZoomWheel);
2343
+ this.configDragMode();
2344
+ }
2345
+ });
2346
+ actionsFolder
2347
+ .add(this.gui_states, "brushAndEraserSize")
2348
+ .min(5)
2349
+ .max(50)
2350
+ .step(1)
2351
+ .onChange(() => {
2352
+ if (this.gui_states.Eraser) {
2353
+ this.eraserUrls.length > 0
2354
+ ? (this.drawingCanvas.style.cursor = switchEraserSize(this.gui_states.brushAndEraserSize, this.eraserUrls))
2355
+ : (this.drawingCanvas.style.cursor = switchEraserSize(this.gui_states.brushAndEraserSize));
2356
+ }
2357
+ });
2358
+ actionsFolder.add(this.gui_states, "Eraser").onChange((value) => {
2359
+ this.gui_states.Eraser = value;
2360
+ if (this.gui_states.Eraser) {
2361
+ this.eraserUrls.length > 0
2362
+ ? (this.drawingCanvas.style.cursor = switchEraserSize(this.gui_states.brushAndEraserSize, this.eraserUrls))
2363
+ : (this.drawingCanvas.style.cursor = switchEraserSize(this.gui_states.brushAndEraserSize));
2364
+ }
2365
+ else {
2366
+ this.drawingCanvas.style.cursor = this.nrrd_states.defaultPaintCursor;
2367
+ }
2368
+ });
2369
+ actionsFolder.add(this.gui_states, "clear");
2370
+ actionsFolder.add(this.gui_states, "clearAll");
2371
+ actionsFolder.add(this.gui_states, "undo");
2372
+ actionsFolder
2373
+ .add(this.mainPreSlice.volume, "windowHigh", this.mainPreSlice.volume.min, this.mainPreSlice.volume.max, 1)
2374
+ .name("Image contrast")
2375
+ .onChange((value) => {
2376
+ this.nrrd_states.readyToUpdate = false;
2377
+ this.updateSlicesContrast(value, "windowHigh");
2378
+ })
2379
+ .onFinishChange(() => {
2380
+ this.repraintAllContrastSlices();
2381
+ this.nrrd_states.readyToUpdate = true;
2382
+ });
2383
+ actionsFolder.add(this.gui_states, "exportMarks");
2384
+ const advanceFolder = modeFolder.addFolder("Advance settings");
2385
+ advanceFolder
2386
+ .add(this.gui_states, "dragSensitivity")
2387
+ .min(1)
2388
+ .max(this.nrrd_states.Max_sensitive)
2389
+ .step(1);
2390
+ const segmentationFolder = advanceFolder.addFolder("Pencil settings");
2391
+ segmentationFolder
2392
+ .add(this.gui_states, "lineWidth")
2393
+ .name("outerLineWidth")
2394
+ .min(1.7)
2395
+ .max(3)
2396
+ .step(0.01);
2397
+ segmentationFolder.addColor(this.gui_states, "color");
2398
+ segmentationFolder.addColor(this.gui_states, "fillColor");
2399
+ const bushFolder = advanceFolder.addFolder("Brush settings");
2400
+ bushFolder.addColor(this.gui_states, "brushColor");
2401
+ // modeFolder.add(this.stateMode, "EraserSize").min(1).max(50).step(1);
2402
+ advanceFolder.add(this.gui_states, "downloadCurrentMask");
2403
+ const contrastFolder = advanceFolder.addFolder("contrast advance settings");
2404
+ contrastFolder
2405
+ .add(this.mainPreSlice.volume, "lowerThreshold", this.mainPreSlice.volume.min, this.mainPreSlice.volume.max, 1)
2406
+ .name("Lower Threshold")
2407
+ .onChange((value) => {
2408
+ this.nrrd_states.readyToUpdate = false;
2409
+ this.updateSlicesContrast(value, "lowerThreshold");
2410
+ })
2411
+ .onFinishChange(() => {
2412
+ this.repraintAllContrastSlices();
2413
+ this.nrrd_states.readyToUpdate = true;
2414
+ });
2415
+ contrastFolder
2416
+ .add(this.mainPreSlice.volume, "upperThreshold", this.mainPreSlice.volume.min, this.mainPreSlice.volume.max, 1)
2417
+ .name("Upper Threshold")
2418
+ .onChange((value) => {
2419
+ this.nrrd_states.readyToUpdate = false;
2420
+ this.updateSlicesContrast(value, "upperThreshold");
2421
+ })
2422
+ .onFinishChange(() => {
2423
+ this.repraintAllContrastSlices();
2424
+ this.nrrd_states.readyToUpdate = true;
2425
+ });
2426
+ contrastFolder
2427
+ .add(this.mainPreSlice.volume, "windowLow", this.mainPreSlice.volume.min, this.mainPreSlice.volume.max, 1)
2428
+ .name("Window Low")
2429
+ .onChange((value) => {
2430
+ this.nrrd_states.readyToUpdate = false;
2431
+ this.updateSlicesContrast(value, "windowLow");
2432
+ })
2433
+ .onFinishChange(() => {
2434
+ this.repraintAllContrastSlices();
2435
+ this.nrrd_states.readyToUpdate = true;
2436
+ });
2437
+ actionsFolder.open();
2438
+ }
2175
2439
  }
2176
2440
  //# sourceMappingURL=nrrd_tool.js.map