|
31 | 31 | <download-icon/> |
32 | 32 | </v-btn> |
33 | 33 | </template> |
34 | | - <span>Export</span> |
| 34 | + <span>Download Mesh</span> |
35 | 35 | </v-tooltip> |
36 | 36 | <v-tooltip top> |
37 | 37 | <template v-slot:activator="{ on }"> |
|
570 | 570 | }; |
571 | 571 | let height = this.packing.height; |
572 | 572 | let width = this.packing.width; |
573 | | - this.packing.polygons.forEach(pol => { |
574 | | - for (let i = 0; i < pol.points.length; i++) { |
575 | | - let pntA = pol.points[i]; |
576 | | - let pntB = pol.points[(i + 1) % pol.points.length]; |
577 | | -
|
578 | | - if ([pntA.x, pntA.y] in this.packing.graph && [pntB.x, pntB.y] in this.packing.graph[[pntA.x, pntA.y]]) { |
579 | | - this.packing.graph[[pntA.x, pntA.y]][[pntB.x, pntB.y]] = { |
580 | | - selected: false |
581 | | - } |
582 | | - } else if ([pntB.x, pntB.y] in this.packing.graph && [pntA.x, pntA.y] in this.packing.graph[[pntB.x, pntB.y]]) { |
583 | | - this.packing.graph[[pntB.x, pntB.y]][[pntA.x, pntA.y]] = { |
584 | | - selected: false |
| 573 | + if(this.packing.graph) { |
| 574 | + this.packing.polygons.forEach(pol => { |
| 575 | + for (let i = 0; i < pol.points.length; i++) { |
| 576 | + let pntA = pol.points[i]; |
| 577 | + let pntB = pol.points[(i + 1) % pol.points.length]; |
| 578 | +
|
| 579 | + if ([pntA.x, pntA.y] in this.packing.graph && [pntB.x, pntB.y] in this.packing.graph[[pntA.x, pntA.y]]) { |
| 580 | + this.packing.graph[[pntA.x, pntA.y]][[pntB.x, pntB.y]] = { |
| 581 | + selected: false |
| 582 | + } |
| 583 | + } else if ([pntB.x, pntB.y] in this.packing.graph && [pntA.x, pntA.y] in this.packing.graph[[pntB.x, pntB.y]]) { |
| 584 | + this.packing.graph[[pntB.x, pntB.y]][[pntA.x, pntA.y]] = { |
| 585 | + selected: false |
| 586 | + } |
585 | 587 | } |
586 | 588 | } |
587 | | - } |
588 | | - }); |
589 | | - this.packing.polygons.forEach(pol => { |
590 | | - pol.selected = this.polygonIntersection(pol, box, width, height, p); |
591 | | - for (let i = 0; i < pol.points.length; i++) { |
592 | | - let pntA = pol.points[i]; |
593 | | - let pntB = pol.points[(i + 1) % pol.points.length]; |
594 | | -
|
595 | | - if ([pntA.x, pntA.y] in this.packing.graph && [pntB.x, pntB.y] in this.packing.graph[[pntA.x, pntA.y]]) { |
596 | | - this.packing.graph[[pntA.x, pntA.y]][[pntB.x, pntB.y]] = { |
597 | | - selected: pol.selected || this.packing.graph[[pntA.x, pntA.y]][[pntB.x, pntB.y]].selected |
598 | | - } |
599 | | - } else if ([pntB.x, pntB.y] in this.packing.graph && [pntA.x, pntA.y] in this.packing.graph[[pntB.x, pntB.y]]) { |
600 | | - this.packing.graph[[pntB.x, pntB.y]][[pntA.x, pntA.y]] = { |
601 | | - selected: pol.selected || this.packing.graph[[pntB.x, pntB.y]][[pntA.x, pntA.y]].selected |
| 589 | + }); |
| 590 | + this.packing.polygons.forEach(pol => { |
| 591 | + pol.selected = this.polygonIntersection(pol, box, width, height, p); |
| 592 | + for (let i = 0; i < pol.points.length; i++) { |
| 593 | + let pntA = pol.points[i]; |
| 594 | + let pntB = pol.points[(i + 1) % pol.points.length]; |
| 595 | +
|
| 596 | + if ([pntA.x, pntA.y] in this.packing.graph && [pntB.x, pntB.y] in this.packing.graph[[pntA.x, pntA.y]]) { |
| 597 | + this.packing.graph[[pntA.x, pntA.y]][[pntB.x, pntB.y]] = { |
| 598 | + selected: pol.selected || this.packing.graph[[pntA.x, pntA.y]][[pntB.x, pntB.y]].selected |
| 599 | + } |
| 600 | + } else if ([pntB.x, pntB.y] in this.packing.graph && [pntA.x, pntA.y] in this.packing.graph[[pntB.x, pntB.y]]) { |
| 601 | + this.packing.graph[[pntB.x, pntB.y]][[pntA.x, pntA.y]] = { |
| 602 | + selected: pol.selected || this.packing.graph[[pntB.x, pntB.y]][[pntA.x, pntA.y]].selected |
| 603 | + } |
602 | 604 | } |
603 | 605 | } |
604 | | - } |
605 | | - }); |
| 606 | + }); |
| 607 | + } |
606 | 608 | dragged = false; |
607 | 609 | p.draw(); |
608 | 610 | } |
|
624 | 626 | let graph = this.packing.graph; |
625 | 627 | let height = this.packing.height; |
626 | 628 | let width = this.packing.width; |
627 | | - Object.keys(graph).forEach(function (pointA) { |
628 | | - Object.keys(graph[pointA]).forEach(function (pointB) { |
629 | | - const pntA = JSON.parse("[" + pointA + "]"); |
630 | | - const pntB = JSON.parse("[" + pointB + "]"); |
631 | | -
|
632 | | - if (graph[pointA][pointB].selected) { |
633 | | - p.stroke(189, 189, 189); |
634 | | - } else { |
635 | | - p.stroke(33, 33, 33); |
636 | | - } |
| 629 | + if(graph) { |
| 630 | + Object.keys(graph).forEach(function (pointA) { |
| 631 | + Object.keys(graph[pointA]).forEach(function (pointB) { |
| 632 | + const pntA = JSON.parse("[" + pointA + "]"); |
| 633 | + const pntB = JSON.parse("[" + pointB + "]"); |
| 634 | +
|
| 635 | + if (graph[pointA][pointB].selected) { |
| 636 | + p.stroke(189, 189, 189); |
| 637 | + } else { |
| 638 | + p.stroke(33, 33, 33); |
| 639 | + } |
637 | 640 |
|
638 | | - if (graph[pointA][pointB].selected) { |
639 | | - p.strokeWeight(4); |
640 | | - } else { |
641 | | - p.strokeWeight(3); |
642 | | - } |
| 641 | + if (graph[pointA][pointB].selected) { |
| 642 | + p.strokeWeight(4); |
| 643 | + } else { |
| 644 | + p.strokeWeight(3); |
| 645 | + } |
643 | 646 |
|
644 | | - p.line( |
645 | | - (pntA[0] / width) * p.width, |
646 | | - ((height - pntA[1]) / height) * p.height, |
647 | | - (pntB[0] / width) * p.width, |
648 | | - ((height - pntB[1]) / height) * p.height |
649 | | - ); |
| 647 | + p.line( |
| 648 | + (pntA[0] / width) * p.width, |
| 649 | + ((height - pntA[1]) / height) * p.height, |
| 650 | + (pntB[0] / width) * p.width, |
| 651 | + ((height - pntB[1]) / height) * p.height |
| 652 | + ); |
| 653 | + }); |
650 | 654 | }); |
651 | | - }); |
| 655 | + } |
652 | 656 | if (locked) { |
653 | 657 | p.strokeWeight(3); |
654 | 658 | p.stroke(239, 83, 80); |
|
776 | 780 | let points = this.packing.draw.points; |
777 | 781 | let edges = this.packing.draw.edges; |
778 | 782 | let polygons = this.packing.draw.polygons; |
| 783 | + let borderPoints = this.packing.draw.borderPoints; |
| 784 | + let borderSegments = this.packing.draw.borderSegments; |
779 | 785 |
|
780 | 786 | let sortedPoints = this.sortDictionary(points); |
781 | 787 | let sortedEdges = this.sortDictionary(edges); |
782 | 788 | let sortedPolygons = this.sortPolygons(polygons); |
783 | 789 | let properties = JSON.parse(localStorage.getItem('properties')); |
784 | 790 | let propertiesArray = Object.keys(properties); |
785 | 791 |
|
786 | | - file += Object.keys(points).length + ' ' + Object.keys(edges).length + ' ' + propertiesArray.length + ' ' + Object.keys(polygons).length + '\n'; |
| 792 | + file += Object.keys(points).length |
| 793 | + + ' ' + Object.keys(edges).length |
| 794 | + + ' ' + propertiesArray.length |
| 795 | + + ' ' + Object.keys(polygons).length |
| 796 | + + ' ' + Object.keys(borderPoints).length |
| 797 | + + ' ' + Object.keys(borderSegments).length |
| 798 | + + '\n'; |
787 | 799 |
|
788 | 800 | sortedPoints.forEach(point => { |
789 | 801 | let splitted = point[0].split(","); |
|
818 | 830 | file += '\n'; |
819 | 831 | }); |
820 | 832 |
|
| 833 | + Object.keys(borderPoints).forEach(bp => { |
| 834 | + file += (borderPoints[bp].pointIndex + ' '); |
| 835 | + file += (borderPoints[bp].polygons.length + ' '); |
| 836 | + borderPoints[bp].polygons.forEach(pol => { |
| 837 | + file += (pol + ' '); |
| 838 | + }); |
| 839 | + file = file.slice(0, -1); |
| 840 | + file += '\n'; |
| 841 | + }); |
| 842 | +
|
| 843 | + Object.keys(borderSegments).forEach(bs => { |
| 844 | + file += (borderSegments[bs].segmentIndex + ' '); |
| 845 | + file += (borderSegments[bs].polygons.length + ' '); |
| 846 | + borderSegments[bs].polygons.forEach(pol => { |
| 847 | + file += (pol + ' '); |
| 848 | + }); |
| 849 | + file = file.slice(0, -1); |
| 850 | + file += '\n'; |
| 851 | + }); |
| 852 | +
|
821 | 853 |
|
822 | 854 | let filename = 'packing.txt'; |
823 | 855 | let universalBOM = "\uFEFF"; |
|
1026 | 1058 | parseMesh(mesh) { |
1027 | 1059 | //console.log(resp); |
1028 | 1060 |
|
| 1061 | + const width = mesh.width; |
| 1062 | + const height = mesh.height; |
| 1063 | +
|
1029 | 1064 | let points = {}; |
1030 | 1065 | let edges = {}; |
1031 | 1066 | let polygons = {}; |
| 1067 | + let borderPoints = {}; |
| 1068 | + let borderSegments = {}; |
1032 | 1069 | let edgesG = {}; |
1033 | 1070 | let cEdgesG = {}; |
1034 | 1071 | let p = 1; |
1035 | 1072 | let e = 1; |
| 1073 | + let bp = 1; |
| 1074 | + let bs = 1; |
1036 | 1075 | let polCount = 1; |
1037 | 1076 |
|
| 1077 | + function checkEpsilon(value, equalValue, precision = 1e-8) { |
| 1078 | + return Math.abs(value - equalValue) < precision; |
| 1079 | + } |
| 1080 | +
|
| 1081 | + function isBorderPoint(point, minX, maxX, minY, maxY) { |
| 1082 | + if(checkEpsilon(point.x, minX) |
| 1083 | + || checkEpsilon(point.x, maxX) |
| 1084 | + || checkEpsilon(point.y, minY) |
| 1085 | + || checkEpsilon(point.y, maxY)) { |
| 1086 | + return true; |
| 1087 | + } |
| 1088 | + return false; |
| 1089 | + } |
| 1090 | +
|
| 1091 | + function checkBorderPoint(point, borderPoints, width, height, bpCount, polCount) { |
| 1092 | + let nPoint = false; |
| 1093 | + // Check if the point is on the border of the container. |
| 1094 | + if (isBorderPoint(point, 0, width, 0, height)) { |
| 1095 | +
|
| 1096 | + // Check if the point is already labeled. |
| 1097 | + if (!([point.x, point.y] in borderPoints)) { |
| 1098 | + borderPoints[[point.x, point.y]] = { |
| 1099 | + index: bpCount, |
| 1100 | + pointIndex: points[[point.x, point.y]], |
| 1101 | + polygons: [] |
| 1102 | + }; |
| 1103 | + nPoint = true; |
| 1104 | + } |
| 1105 | +
|
| 1106 | + // Add the polygon if needed. |
| 1107 | + if (!borderPoints[[point.x, point.y]].polygons.includes(polCount)) { |
| 1108 | + borderPoints[[point.x, point.y]].polygons.push(polCount); |
| 1109 | + } |
| 1110 | + } |
| 1111 | + return nPoint; |
| 1112 | + } |
| 1113 | +
|
| 1114 | + function checkBorderSegment(pointA, pointB, borderSegments, width, height, bsCount, polCount) { |
| 1115 | + let nSegment = false; |
| 1116 | + // Check if one of the points is on the border of the container. |
| 1117 | + if (isBorderPoint(pointA, 0, width, 0, height) |
| 1118 | + || isBorderPoint(pointB, 0, width, 0, height)) { |
| 1119 | +
|
| 1120 | + // Check if the segment is already labeled. |
| 1121 | + if (!([points[[pointA.x, pointA.y]], points[[pointB.x, pointB.y]]] in borderSegments)) { |
| 1122 | + borderSegments[[points[[pointA.x, pointA.y]], points[[pointB.x, pointB.y]]]] = { |
| 1123 | + index: bsCount, |
| 1124 | + segmentIndex: edges[[points[[pointA.x, pointA.y]], points[[pointB.x, pointB.y]]]], |
| 1125 | + polygons: [] |
| 1126 | + }; |
| 1127 | + nSegment = true; |
| 1128 | + } |
| 1129 | +
|
| 1130 | + // Add the polygon if needed. |
| 1131 | + if (!borderSegments[[points[[pointA.x, pointA.y]], points[[pointB.x, pointB.y]]]].polygons.includes(polCount)) { |
| 1132 | + borderSegments[[points[[pointA.x, pointA.y]], points[[pointB.x, pointB.y]]]].polygons.push(polCount); |
| 1133 | + } |
| 1134 | + } |
| 1135 | + return nSegment; |
| 1136 | + } |
| 1137 | +
|
1038 | 1138 | mesh.polygons.forEach(pol => { |
1039 | 1139 |
|
1040 | 1140 | let polygonPoints = []; |
|
1043 | 1143 |
|
1044 | 1144 | let pointA = pol.points[i]; |
1045 | 1145 | let pointB = pol.points[(i + 1) % pol.points.length]; |
| 1146 | +
|
1046 | 1147 | if (!([pointA.x, pointA.y] in points)) { |
1047 | 1148 | points[[pointA.x, pointA.y]] = p; |
1048 | 1149 | p += 1; |
|
1053 | 1154 | p += 1; |
1054 | 1155 | } |
1055 | 1156 |
|
| 1157 | + // Check if the points are on the border of the container. |
| 1158 | + if (checkBorderPoint(pointA, borderPoints, width, height, bp, polCount)) { |
| 1159 | + bp += 1 |
| 1160 | + } |
| 1161 | + if (checkBorderPoint(pointB, borderPoints, width, height, bp, polCount)) { |
| 1162 | + bp += 1 |
| 1163 | + } |
| 1164 | +
|
1056 | 1165 | if (!([points[[pointA.x, pointA.y]], points[[pointB.x, pointB.y]]] in edges)) { |
1057 | 1166 | edges[[points[[pointA.x, pointA.y]], points[[pointB.x, pointB.y]]]] = e; |
| 1167 | +
|
| 1168 | + // Check if the segment is on the border of the container. |
| 1169 | + if (checkBorderSegment(pointA, pointB, borderSegments, width, height, bs, polCount)) { |
| 1170 | + bs += 1 |
| 1171 | + } |
| 1172 | +
|
1058 | 1173 | e += 1; |
1059 | 1174 |
|
1060 | 1175 | if (!([pointA.x, pointA.y] in cEdgesG)) { |
|
1093 | 1208 | this.packing.draw.points = points; |
1094 | 1209 | this.packing.draw.edges = edges; |
1095 | 1210 | this.packing.draw.polygons = polygons; |
| 1211 | + this.packing.draw.borderPoints = borderPoints; |
| 1212 | + this.packing.draw.borderSegments = borderSegments; |
1096 | 1213 | this.packing.graph = edgesG; |
1097 | 1214 | this.packing.rGraph = cEdgesG; |
1098 | 1215 | }, |
|
0 commit comments