Skip to content

Commit d895986

Browse files
authored
Merge pull request #295 from LinkunGao/feat/v2.0.6
Feat/v2.0.6
2 parents a9c5767 + 549a4bc commit d895986

File tree

8 files changed

+180
-143
lines changed

8 files changed

+180
-143
lines changed

docs/source/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
# The full version, including alpha/beta/rc tags
2525

26-
release = 'v2.0.5'
26+
release = 'v2.0.6'
2727

2828

2929

docs/source/release/release.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1933,3 +1933,17 @@ Huge update:
19331933
## Release v2.0.2
19341934

19351935
Fixed cursor not switch issue when user click eraser and pencil buttons.
1936+
1937+
## Release v2.0.5
1938+
1939+
- fix sphere function bugs
1940+
- solve the zoom function bugs
1941+
1942+
## Release v2.0.6
1943+
1944+
- fix Zoom affect sphere origin functions
1945+
- update sphere origin and radius export
1946+
- sphere origin and radius exports are based on sizeFactor:1.
1947+
- Fix sphere and crosshair function
1948+
- all based on sizeFactor:1
1949+
- after zoom, scale them.

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "copper3d",
33
"description": "A 3d visualisation package base on threejs provides multiple scenes and Nrrd image load funtion.",
4-
"version": "2.0.5",
4+
"version": "2.0.6",
55
"main": "dist/bundle.umd.js",
66
"moudle": "dist/bundle.esm.js",
77
"types": "dist/types/index.d.ts",

src/Utils/segmentation/DrawToolCore.ts

Lines changed: 146 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -273,10 +273,16 @@ export class DrawToolCore extends CommToolsData {
273273
e.offsetX / this.nrrd_states.sizeFoctor;
274274
this.nrrd_states.cursorPageY =
275275
e.offsetY / this.nrrd_states.sizeFoctor;
276+
276277
this.enableCrosshair();
277-
} else if (this.gui_states.sphere) {
278-
let mouseX = e.offsetX;
279-
let mouseY = e.offsetY;
278+
279+
} else if (this.gui_states.sphere && !this.nrrd_states.enableCursorChoose) {
280+
this.protectedData.canvases.drawingCanvas.removeEventListener(
281+
"wheel",
282+
this.drawingPrameters.handleZoomWheel
283+
);
284+
let mouseX = e.offsetX / this.nrrd_states.sizeFoctor;
285+
let mouseY = e.offsetY / this.nrrd_states.sizeFoctor;
280286

281287
// record mouseX,Y, and enable crosshair function
282288
this.nrrd_states.sphereOrigin[this.protectedData.axis] = [
@@ -290,7 +296,7 @@ export class DrawToolCore extends CommToolsData {
290296
this.enableCrosshair();
291297

292298
// draw circle setup width/height for sphere canvas
293-
this.drawSphere(mouseX, mouseY, this.nrrd_states.sphereRadius);
299+
this.drawSphere(e.offsetX , e.offsetY, this.nrrd_states.sphereRadius);
294300
this.protectedData.canvases.drawingCanvas.addEventListener(
295301
"wheel",
296302
this.drawingPrameters.handleSphereWheel,
@@ -485,17 +491,28 @@ export class DrawToolCore extends CommToolsData {
485491
}
486492

487493
!!this.nrrd_states.getSphere &&
488-
this.nrrd_states.getSphere(
489-
this.nrrd_states.sphereOrigin.z,
490-
this.nrrd_states.sphereRadius
491-
);
494+
this.nrrd_states.getSphere(
495+
this.nrrd_states.sphereOrigin.z,
496+
this.nrrd_states.sphereRadius / this.nrrd_states.sizeFoctor
497+
);
498+
499+
this.protectedData.canvases.drawingCanvas.addEventListener(
500+
"wheel",
501+
this.drawingPrameters.handleZoomWheel
502+
);
492503

493504
this.protectedData.canvases.drawingCanvas.removeEventListener(
494505
"wheel",
495506
this.drawingPrameters.handleSphereWheel,
496507
true
497508
);
498-
}
509+
} else if(this.gui_states.sphere &&
510+
this.nrrd_states.enableCursorChoose){
511+
this.protectedData.canvases.drawingCanvas.addEventListener(
512+
"wheel",
513+
this.drawingPrameters.handleZoomWheel
514+
);
515+
}
499516
} else if (e.button === 2) {
500517
rightclicked = false;
501518
this.protectedData.canvases.drawingCanvas.style.cursor = "grab";
@@ -891,25 +908,22 @@ export class DrawToolCore extends CommToolsData {
891908

892909
const mouseX = this.nrrd_states.sphereOrigin[axis][0];
893910
const mouseY = this.nrrd_states.sphereOrigin[axis][1];
911+
894912
const originIndex = this.nrrd_states.sphereOrigin[axis][2];
895913
const preIndex = originIndex - decay;
896914
const nextIndex = originIndex + decay;
897915
const ctx = this.protectedData.ctxes.drawingSphereCtx;
898916
const canvas = this.protectedData.canvases.drawingSphereCanvas;
899-
// if (
900-
// preIndex < this.nrrd_states.minIndex ||
901-
// nextIndex > this.nrrd_states.maxIndex
902-
// )
903-
// return;
917+
904918
if (preIndex === nextIndex) {
905-
this.drawSphereCore(ctx, mouseX, mouseY, this.nrrd_states.sphereRadius);
919+
this.drawSphereCore(ctx, mouseX, mouseY, this.nrrd_states.sphereRadius / this.nrrd_states.sizeFoctor);
906920
this.storeSphereImages(preIndex, axis);
907921
} else {
908922
this.drawSphereCore(
909923
ctx,
910924
mouseX,
911925
mouseY,
912-
this.nrrd_states.sphereRadius - decay
926+
(this.nrrd_states.sphereRadius - decay) / this.nrrd_states.sizeFoctor
913927
);
914928
this.drawImageOnEmptyImage(canvas);
915929
this.storeSphereImages(preIndex, axis);
@@ -925,7 +939,7 @@ export class DrawToolCore extends CommToolsData {
925939
radius: number
926940
) {
927941
ctx.beginPath();
928-
ctx.arc(x, y, radius * this.nrrd_states.sizeFoctor, 0, 2 * Math.PI);
942+
ctx.arc(x, y, radius, 0, 2 * Math.PI);
929943
ctx.fillStyle = this.gui_states.fillColor;
930944
ctx.fill();
931945
ctx.closePath();
@@ -969,8 +983,8 @@ export class DrawToolCore extends CommToolsData {
969983
Math.min(this.nrrd_states.sphereRadius, 50)
970984
);
971985
// get mouse position
972-
const mouseX = this.nrrd_states.sphereOrigin[this.protectedData.axis][0];
973-
const mouseY = this.nrrd_states.sphereOrigin[this.protectedData.axis][1];
986+
const mouseX = this.nrrd_states.sphereOrigin[this.protectedData.axis][0] * this.nrrd_states.sizeFoctor;
987+
const mouseY = this.nrrd_states.sphereOrigin[this.protectedData.axis][1] * this.nrrd_states.sizeFoctor;
974988
this.drawSphere(mouseX, mouseY, this.nrrd_states.sphereRadius);
975989
};
976990
return sphereEvent;
@@ -1000,7 +1014,118 @@ export class DrawToolCore extends CommToolsData {
10001014
);
10011015
}
10021016

1017+
/**
1018+
* We generate the MRI slice from threejs based on mm, but when we display it is based on pixel size/distance.
1019+
* So, the index munber on each axis (sagittal, axial, coronal) is the slice's depth in mm distance. And the width and height displayed on screen is the slice's width and height in pixel distance.
1020+
*
1021+
* When we switch into different axis' views, we need to convert current view's the depth to the pixel distance in other views width or height, and convert the current view's width or height from pixel distance to mm distance as other views' depth (slice index) in general.
1022+
*
1023+
* Then as for the crosshair (Cursor Inspector), we also need to convert the cursor point (x, y, z) to other views' (x, y, z).
1024+
*
1025+
* @param from "x" | "y" | "z", current view axis, "x: sagittle, y: coronal, z: axial".
1026+
* @param to "x" | "y" | "z", target view axis (where you want jump to), "x: sagittle, y: coronal, z: axial".
1027+
* @param cursorNumX number, cursor point x on current axis's slice. (pixel distance)
1028+
* @param cursorNumY number, cursor point y on current axis's slice. (pixel distance)
1029+
* @param currentSliceIndex number, current axis's slice's index/depth. (mm distance)
1030+
* @returns
1031+
*/
1032+
convertCursorPoint(
1033+
from: "x" | "y" | "z",
1034+
to: "x" | "y" | "z",
1035+
cursorNumX: number,
1036+
cursorNumY: number,
1037+
currentSliceIndex: number
1038+
) {
1039+
1040+
const nrrd = this.nrrd_states;
1041+
const dimensions = nrrd.dimensions;
1042+
const ratios = nrrd.ratios;
1043+
const { nrrd_x_mm, nrrd_y_mm, nrrd_z_mm } = nrrd;
1044+
1045+
let currentIndex = 0;
1046+
let oldIndex = 0;
1047+
let convertCursorNumX = 0;
1048+
let convertCursorNumY = 0;
1049+
1050+
const convertIndex = {
1051+
x: {
1052+
y: (val: number) => Math.ceil((val / nrrd_x_mm) * dimensions[0]),
1053+
z: (val: number) => Math.ceil((val / nrrd_z_mm) * dimensions[2]),
1054+
},
1055+
y: {
1056+
x: (val: number) => Math.ceil((val / nrrd_y_mm) * dimensions[1]),
1057+
z: (val: number) => Math.ceil((val / nrrd_z_mm) * dimensions[2]),
1058+
},
1059+
z: {
1060+
x: (val: number) => Math.ceil((val / nrrd_x_mm) * dimensions[0]),
1061+
y: (val: number) => Math.ceil((val / nrrd_y_mm) * dimensions[1]),
1062+
},
1063+
};
1064+
1065+
1066+
const convertCursor = {
1067+
x: {
1068+
y: (sliceIndex: number) =>
1069+
Math.ceil((sliceIndex / dimensions[0]) * nrrd_x_mm),
1070+
z: (sliceIndex: number) =>
1071+
Math.ceil((sliceIndex / dimensions[0]) * nrrd_x_mm),
1072+
},
1073+
y: {
1074+
x: (sliceIndex: number) =>
1075+
Math.ceil((sliceIndex / dimensions[1]) * nrrd_y_mm),
1076+
z: (sliceIndex: number) =>
1077+
Math.ceil((sliceIndex / dimensions[1]) * nrrd_y_mm),
1078+
},
1079+
z: {
1080+
x: (sliceIndex: number) =>
1081+
Math.ceil((sliceIndex / dimensions[2]) * nrrd_z_mm),
1082+
y: (sliceIndex: number) =>
1083+
Math.ceil((sliceIndex / dimensions[2]) * nrrd_z_mm),
1084+
},
1085+
};
1086+
1087+
if (from === to) {
1088+
return;
1089+
}
1090+
if (from === "z" && to === "x") {
1091+
currentIndex = convertIndex[from][to](cursorNumX);
1092+
oldIndex = currentIndex * ratios[to];
1093+
convertCursorNumX = convertCursor[from][to](currentSliceIndex);
1094+
convertCursorNumY = cursorNumY;
1095+
} else if (from === "y" && to === "x") {
1096+
currentIndex = convertIndex[from][to](cursorNumX);
1097+
oldIndex = currentIndex * ratios.x;
1098+
convertCursorNumY = convertCursor[from][to](currentSliceIndex);
1099+
convertCursorNumX = cursorNumY;
1100+
} else if (from === "z" && to === "y") {
1101+
currentIndex = convertIndex[from][to](cursorNumY);
1102+
oldIndex = currentIndex * ratios[to];
1103+
convertCursorNumY = convertCursor[from][to](currentSliceIndex);
1104+
convertCursorNumX = cursorNumX;
1105+
} else if (from === "x" && to === "y") {
1106+
currentIndex = convertIndex[from][to](cursorNumY);
1107+
oldIndex = currentIndex * ratios[to];
1108+
convertCursorNumX = convertCursor[from][to](currentSliceIndex);
1109+
convertCursorNumY = cursorNumX;
1110+
} else if (from === "x" && to === "z") {
1111+
currentIndex = convertIndex[from][to](cursorNumX);
1112+
oldIndex = currentIndex * ratios[to];
1113+
convertCursorNumX = convertCursor[from][to](currentSliceIndex);
1114+
convertCursorNumY = cursorNumY;
1115+
} else if (from === "y" && to === "z") {
1116+
currentIndex = convertIndex[from][to](cursorNumY);
1117+
oldIndex = currentIndex * ratios.z;
1118+
convertCursorNumY = convertCursor[from][to](currentSliceIndex);
1119+
convertCursorNumX = cursorNumX;
1120+
} else {
1121+
return;
1122+
}
1123+
1124+
return { currentIndex, oldIndex, convertCursorNumX, convertCursorNumY };
1125+
}
1126+
10031127
private setUpSphereOrigins(mouseX: number, mouseY: number) {
1128+
10041129
const convertCursor = (from: "x" | "y" | "z", to: "x" | "y" | "z") => {
10051130
const convertObj = this.convertCursorPoint(
10061131
from,
@@ -1009,6 +1134,7 @@ export class DrawToolCore extends CommToolsData {
10091134
mouseY,
10101135
this.nrrd_states.currentIndex
10111136
) as IConvertObjType;
1137+
10121138
return {
10131139
convertCursorNumX: convertObj?.convertCursorNumX,
10141140
convertCursorNumY: convertObj?.convertCursorNumY,
@@ -1026,6 +1152,7 @@ export class DrawToolCore extends CommToolsData {
10261152
axisTo1: "x" | "y" | "z";
10271153
axisTo2: "x" | "y" | "z";
10281154
};
1155+
10291156
this.nrrd_states.sphereOrigin[axisTo1] = [
10301157
convertCursor(this.protectedData.axis, axisTo1).convertCursorNumX,
10311158
convertCursor(this.protectedData.axis, axisTo1).convertCursorNumY,

0 commit comments

Comments
 (0)