Skip to content

Commit f5ab079

Browse files
committed
Improve the function for downloading STL models.
1 parent 7deda0e commit f5ab079

File tree

1 file changed

+38
-16
lines changed
  • bluelight/scripts/plugin

1 file changed

+38
-16
lines changed

bluelight/scripts/plugin/vr2.js

Lines changed: 38 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ endsolid name`
333333
for (var obj of VRCube.cube.ElemZs) {
334334
segList.push({
335335
pixelData: obj.imgData,
336-
PositionZ: obj.position.z
336+
PositionZ: parseInt(obj.originPositionZ)
337337
});
338338
}
339339

@@ -388,16 +388,20 @@ endsolid name`
388388

389389
//針對第一面和最後一面
390390
for (var p0 = 0; p0 < segList.length; p0++) {
391+
392+
//如果選擇空心,非0層就直接跳最後一層
393+
if (getByid("VR2_STLCheck").checked) {
394+
if (p0 != 0) p0 = segList.length - 1;
395+
}
396+
391397
var seg0 = segList[p0];
392-
//if (p0 == 0) var seg0 = segList[0];
393-
//else var seg0 = segList[segList.length - 1];
394398
var pixel = seg0.pixelData;
395399
//左到右
396400
for (var h = 1; h < height - 1; h += 1) {
397401
for (var w = 1; w < width; w++) {
398-
if (pixel[h * width + w] != 0 && pixel[h * width + w - 1] == 0) {
402+
if (pixel[h * width + w] > 0xFF000000 && pixel[h * width + w - 1] <= 0xFF000000) {
399403
for (var w2 = w; w2 < width; w2++) {
400-
if (pixel[h * width + w2] == 0 && pixel[h * width + w2 - 1] != 0) {
404+
if (pixel[h * width + w2] <= 0xFF000000 && pixel[h * width + w2 - 1] > 0xFF000000) {
401405
pushIntters(
402406
h, w, seg0.PositionZ,
403407
h + 1, w, seg0.PositionZ,
@@ -428,9 +432,9 @@ endsolid name`
428432
//上到下
429433
for (var w = 1; w < width; w += 1) {
430434
for (var h = 1; h < height; h++) {
431-
if (pixel[h * width + w] != 0 && pixel[(h - 1) * width + w] == 0) {
435+
if (pixel[h * width + w] > 0xFF000000 && pixel[(h - 1) * width + w] <= 0xFF000000) {
432436
for (var h2 = h; h2 < height; h2++) {
433-
if (pixel[h2 * width + w] == 0 && pixel[(h2 - 1) * width + w] != 0) {
437+
if (pixel[h2 * width + w] <= 0xFF000000 && pixel[(h2 - 1) * width + w] > 0xFF000000) {
434438
pushIntters(
435439
h, w, seg0.PositionZ,
436440
h, w + 1, seg0.PositionZ,
@@ -467,7 +471,7 @@ endsolid name`
467471
var pixel = seg1.pixelData;
468472
for (var h = 0; h < height; h += 5) {
469473
for (var w = 1; w < width; w++) {
470-
if (pixel[h * width + w] != 0 && pixel[h * width + w - 1] == 0) {
474+
if (pixel[h * width + w] > 0xFF000000 && pixel[h * width + w - 1] <= 0xFF000000) {
471475
pointlist1.push([h, w]);
472476
break;
473477
}
@@ -478,7 +482,7 @@ endsolid name`
478482
var pixel = seg2.pixelData;
479483
for (var h = 0; h < height; h += 5) {
480484
for (var w = 1; w < width; w++) {
481-
if (pixel[h * width + w] != 0 && pixel[h * width + w - 1] == 0) {
485+
if (pixel[h * width + w] > 0xFF000000 && pixel[h * width + w - 1] <= 0xFF000000) {
482486
pointlist2.push([h, w]);
483487
break;
484488
}
@@ -494,7 +498,7 @@ endsolid name`
494498
var pixel = seg1.pixelData;
495499
for (var h = 0; h < height; h += 5) {
496500
for (var w = width - 2; w > 0; w--) {
497-
if (pixel[h * width + w] != 0 && pixel[h * width + w + 1] == 0) {
501+
if (pixel[h * width + w] > 0xFF000000 && pixel[h * width + w + 1] <= 0xFF000000) {
498502
pointlist1.push([h, w]);
499503
break;
500504
}
@@ -505,7 +509,7 @@ endsolid name`
505509
var pixel = seg2.pixelData;
506510
for (var h = 0; h < height; h += 5) {
507511
for (var w = width - 2; w > 0; w--) {
508-
if (pixel[h * width + w] != 0 && pixel[h * width + w + 1] == 0) {
512+
if (pixel[h * width + w] > 0xFF000000 && pixel[h * width + w + 1] <= 0xFF000000) {
509513
pointlist2.push([h, w]);
510514
break;
511515
}
@@ -522,7 +526,7 @@ endsolid name`
522526
var pixel = seg1.pixelData;
523527
for (var w = 0; w < width; w += 5) {
524528
for (var h = 1; h < height; h++) {
525-
if (pixel[h * width + w] != 0 && pixel[(h - 1) * width + w] == 0) {
529+
if (pixel[h * width + w] > 0xFF000000 && pixel[(h - 1) * width + w] <= 0xFF000000) {
526530
pointlist1.push([h, w]);
527531
break;
528532
}
@@ -533,7 +537,7 @@ endsolid name`
533537
var pixel = seg2.pixelData;
534538
for (var w = 0; w < width; w += 5) {
535539
for (var h = 1; h < height; h++) {
536-
if (pixel[h * width + w] != 0 && pixel[(h - 1) * width + w] == 0) {
540+
if (pixel[h * width + w] > 0xFF000000 && pixel[(h - 1) * width + w] <= 0xFF000000) {
537541
pointlist2.push([h, w]);
538542
break;
539543
}
@@ -549,7 +553,7 @@ endsolid name`
549553
var pixel = seg1.pixelData;
550554
for (var w = 0; w < width; w += 5) {
551555
for (var h = height - 2; h > 0; h--) {
552-
if (pixel[h * width + w] != 0 && pixel[(h + 1) * width + w] == 0) {
556+
if (pixel[h * width + w] > 0xFF000000 && pixel[(h + 1) * width + w] <= 0xFF000000) {
553557
pointlist1.push([h, w]);
554558
break;
555559
}
@@ -560,7 +564,7 @@ endsolid name`
560564
var pixel = seg2.pixelData;
561565
for (var w = 0; w < width; w += 5) {
562566
for (var h = height - 2; h > 0; h--) {
563-
if (pixel[h * width + w] != 0 && pixel[(h + 1) * width + w] == 0) {
567+
if (pixel[h * width + w] > 0xFF000000 && pixel[(h + 1) * width + w] <= 0xFF000000) {
564568
pointlist2.push([h, w]);
565569
break;
566570
}
@@ -1080,7 +1084,24 @@ endsolid name`
10801084
span.appendChild(ReduceSliceLable);
10811085
userDIV.appendChild(span);
10821086

1083-
1087+
//////////STL//////////
1088+
var span = document.createElement("span");
1089+
span.style['zIndex'] = "490";
1090+
span.style['float'] = "right";
1091+
var STLLable = document.createElement("LABEL");
1092+
STLLable.innerText = "Download as hollow STL model";
1093+
STLLable.className = "VR2_Label";
1094+
STLLable.style.float = "left";
1095+
1096+
var STLCheck = document.createElement("input");
1097+
STLCheck.style = "z-index: 490;float:left";
1098+
STLCheck.type = "checkbox";
1099+
STLCheck.id = "VR2_STLCheck";
1100+
STLCheck.setAttribute("checked", "checked");
1101+
1102+
span.appendChild(STLCheck);
1103+
span.appendChild(STLLable);
1104+
userDIV.appendChild(span);
10841105
//////////Perspective//////////
10851106
var span = document.createElement("span");
10861107
span.style['zIndex'] = "490";
@@ -1263,6 +1284,7 @@ endsolid name`
12631284

12641285
NewCanvas.position = new Point3D(0, 0, 0);
12651286
NewCanvas.position.z = parseFloat(SOP.Image.data.string(Tag.ImagePositionPatient).split("\\")[2]) * (1 / (parseFloat(SOP.Image.rowPixelSpacing)));
1287+
NewCanvas.originPositionZ = NewCanvas.position.z;
12661288
NewCanvas.direction = 'z';
12671289

12681290
var Matrix = multiplyMatrices(getTranslateMatrix(0, 0, (NewCanvas.position.z / step)), [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]);

0 commit comments

Comments
 (0)