rm-graphical-computing-node 1.0.68 → 1.0.70

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 (2) hide show
  1. package/dist/index.mjs +204 -10
  2. package/package.json +1 -1
package/dist/index.mjs CHANGED
@@ -10879,8 +10879,9 @@ var getSlabData = (lines, runDataList, pointCloudCluster = null, getOblique = fa
10879
10879
  flatSlabPoints.push(lines[i]);
10880
10880
  }
10881
10881
  const flatSlabDatas = getFlatSlabData(flatSlabPoints, runDataList, pointCloudCluster);
10882
+ const flatFloorDatas = getFlatFloorData(flatSlabPoints, runDataList, pointCloudCluster);
10882
10883
  const obliqueSlabDatas = getObliqueSlabData(obliqueSlabPoints, runDataList, pointCloudCluster);
10883
- return { flatSlabDatas, obliqueSlabDatas };
10884
+ return { flatSlabDatas, obliqueSlabDatas, flatFloorDatas };
10884
10885
  };
10885
10886
  var getFlatSlabData = (lines, runDataList, pointCloudCluster = null) => {
10886
10887
  if (lines.length === 0) return;
@@ -10993,6 +10994,168 @@ var getFlatSlabData = (lines, runDataList, pointCloudCluster = null) => {
10993
10994
  }
10994
10995
  return slabDatas;
10995
10996
  };
10997
+ var getFlatFloorData = (lines, runDataList, pointCloudCluster = null) => {
10998
+ if (lines.length === 0) return;
10999
+ let floorDatas = [];
11000
+ let maxHeightTrajectoryPt = new THREE9.Vector3(runDataList[0].x, runDataList[0].y, runDataList[0].z);
11001
+ let totalZ = 0;
11002
+ for (let i = 1; i < runDataList.length; i++) {
11003
+ totalZ += runDataList[i].z;
11004
+ if (runDataList[i].z > maxHeightTrajectoryPt.z) {
11005
+ maxHeightTrajectoryPt.set(runDataList[i].x, runDataList[i].y, runDataList[i].z);
11006
+ }
11007
+ }
11008
+ const averageZ = totalZ / (runDataList.length - 1);
11009
+ let maxPointsNum = 0;
11010
+ let maxPointsZ = 0;
11011
+ for (const line2 of lines) {
11012
+ let points = line2[1].points;
11013
+ if (points.length < 30) continue;
11014
+ let mapSortPoint = /* @__PURE__ */ new Map();
11015
+ for (let c = 0; c < points.length; c++) {
11016
+ let z = points[c].z;
11017
+ z = Math.floor(z * 10) / 10;
11018
+ if (mapSortPoint.has(z)) {
11019
+ const item = mapSortPoint.get(z);
11020
+ item.num += 1;
11021
+ item.points.push(points[c]);
11022
+ mapSortPoint.set(z, item);
11023
+ } else {
11024
+ mapSortPoint.set(z, { num: 1, points: [points[c]] });
11025
+ }
11026
+ }
11027
+ let mostFrequentEntry = [...mapSortPoint.entries()].reduce(
11028
+ (max2, cur) => cur[1].num > max2[1].num ? cur : max2
11029
+ );
11030
+ points = mostFrequentEntry[1].points.map((p) => new THREE9.Vector3(p.x, p.y, p.z));
11031
+ let newPoints = [];
11032
+ if (pointCloudCluster != null) {
11033
+ let clusterResult = pointCloudCluster([points], {
11034
+ tolerance: 0.1,
11035
+ minClusterSize: 30,
11036
+ maxClusterSize: 1e7,
11037
+ threadCount: 1
11038
+ });
11039
+ if (clusterResult.length > 0) {
11040
+ for (const cluster of clusterResult[0]) {
11041
+ if (cluster.length < 50) continue;
11042
+ const newOriginalPoints = cluster.map((i) => points[i]);
11043
+ newPoints.push(newOriginalPoints);
11044
+ }
11045
+ } else
11046
+ newPoints.push(points);
11047
+ } else
11048
+ newPoints.push(points);
11049
+ for (let u4 = 0; u4 < newPoints.length; u4++) {
11050
+ let { minZ, maxZ, averagePz: averagePz2 } = getPointsMinAndMax(newPoints[u4]);
11051
+ const height = maxZ - minZ;
11052
+ if (averageZ < maxZ) continue;
11053
+ let pathPoints = newPoints[u4].map((p) => [p.x, p.y]);
11054
+ let path3 = computeContour(pathPoints);
11055
+ let area3 = calculatePolygonArea(path3);
11056
+ if (area3 < 0.5) continue;
11057
+ const floorData = {
11058
+ contour: path3,
11059
+ averagePz: averagePz2,
11060
+ points: newPoints[u4]
11061
+ };
11062
+ if (newPoints[u4].length > maxPointsNum) {
11063
+ maxPointsNum = newPoints[u4].length;
11064
+ maxPointsZ = averagePz2;
11065
+ }
11066
+ floorDatas.push(floorData);
11067
+ }
11068
+ }
11069
+ const newFloorDatas = [];
11070
+ for (const floorData of floorDatas) {
11071
+ if (floorData.averagePz <= maxPointsZ || floorData.averagePz < averageZ) {
11072
+ newFloorDatas.push(floorData);
11073
+ }
11074
+ }
11075
+ let delIndex = /* @__PURE__ */ new Set();
11076
+ for (let j = 0; j < newFloorDatas.length; j++) {
11077
+ if (delIndex.has(j)) continue;
11078
+ const floorData1 = newFloorDatas[j];
11079
+ for (let k = 0; k < newFloorDatas.length; k++) {
11080
+ if (j == k || delIndex.has(k))
11081
+ continue;
11082
+ const floorData2 = newFloorDatas[k];
11083
+ if (Math.abs(floorData1.averagePz - floorData2.averagePz) > 0.05) continue;
11084
+ const isIntersect = contoursIntersect(floorData1.contour, floorData2.contour, 1e-3);
11085
+ if (isIntersect) {
11086
+ for (let b = 0; b < floorData2.points.length; b++)
11087
+ floorData1.points.push(floorData2.points[b]);
11088
+ let tmpPoints = floorData1.points.map((p) => [p.x, p.y]);
11089
+ tmpPoints = voxelDownsample2DForContour(tmpPoints, 0.1);
11090
+ let path3 = computeContour(tmpPoints);
11091
+ floorData1.contour = path3;
11092
+ delIndex.add(k);
11093
+ k = -1;
11094
+ }
11095
+ }
11096
+ }
11097
+ floorDatas = [];
11098
+ for (let j = 0; j < newFloorDatas.length; j++) {
11099
+ if (!delIndex.has(j))
11100
+ floorDatas.push({
11101
+ contour: newFloorDatas[j].contour,
11102
+ averagePz: newFloorDatas[j].averagePz,
11103
+ points: newFloorDatas[j].points
11104
+ });
11105
+ }
11106
+ let maxContourIndex = -1;
11107
+ let maxPointsLength = 0;
11108
+ let area2 = 0;
11109
+ let avaregPzs = [];
11110
+ let disIncludeIndexs = [];
11111
+ for (let i = 0; i < floorDatas.length; i++) {
11112
+ const contour = floorDatas[i].contour;
11113
+ if (contour.length) {
11114
+ const points = floorDatas[i].points;
11115
+ let avaregZ = 0;
11116
+ points.forEach((p) => {
11117
+ avaregZ += p.z;
11118
+ });
11119
+ avaregZ /= points.length;
11120
+ avaregPzs.push(avaregZ);
11121
+ if (avaregZ < averageZ) {
11122
+ const { width, height } = getOBB(contour);
11123
+ const newArea = width * height;
11124
+ if (newArea > area2) {
11125
+ if (points.length > maxPointsLength && (avaregZ < runDataList[0].z || Math.abs(avaregZ - runDataList[0].z) < 0.1)) {
11126
+ if (maxContourIndex > -1) {
11127
+ disIncludeIndexs.push(maxContourIndex);
11128
+ }
11129
+ area2 = newArea;
11130
+ maxContourIndex = i;
11131
+ maxPointsLength = points.length;
11132
+ continue;
11133
+ }
11134
+ disIncludeIndexs.push(i);
11135
+ } else {
11136
+ if (points.length > maxPointsLength && area2 - newArea < area2 / 3 && (avaregZ < runDataList[0].z || Math.abs(avaregZ - runDataList[0].z) < 0.1)) {
11137
+ if (maxContourIndex > -1) {
11138
+ disIncludeIndexs.push(maxContourIndex);
11139
+ }
11140
+ area2 = newArea;
11141
+ maxContourIndex = i;
11142
+ maxPointsLength = points.length;
11143
+ continue;
11144
+ }
11145
+ disIncludeIndexs.push(i);
11146
+ }
11147
+ }
11148
+ } else {
11149
+ console.log("\u4E0D\u5B58\u5728\uFF01");
11150
+ avaregPzs.push(1e4);
11151
+ }
11152
+ }
11153
+ return {
11154
+ contour: floorDatas[maxContourIndex].contour,
11155
+ averagePz: avaregPzs[maxContourIndex]
11156
+ /**, points: floorDatas[maxContourIndex].points */
11157
+ };
11158
+ };
10996
11159
  var getObliqueSlabData = (lines, runDataList, pointCloudCluster = null) => {
10997
11160
  if (lines.length === 0) return [];
10998
11161
  let slabDatas = [];
@@ -11168,6 +11331,46 @@ function getPathZ(path3, points) {
11168
11331
  }
11169
11332
  }
11170
11333
  }
11334
+ var getOBB = (contour) => {
11335
+ const center = [0, 0];
11336
+ for (const [x, y] of contour) {
11337
+ center[0] += x;
11338
+ center[1] += y;
11339
+ }
11340
+ center[0] /= contour.length;
11341
+ center[1] /= contour.length;
11342
+ let covXX = 0, covXY = 0, covYY = 0;
11343
+ for (const [x, y] of contour) {
11344
+ const dx = x - center[0];
11345
+ const dy = y - center[1];
11346
+ covXX += dx * dx;
11347
+ covXY += dx * dy;
11348
+ covYY += dy * dy;
11349
+ }
11350
+ covXX /= contour.length;
11351
+ covXY /= contour.length;
11352
+ covYY /= contour.length;
11353
+ const det = Math.sqrt((covXX - covYY) ** 2 + 4 * covXY ** 2);
11354
+ const eigenVal1 = (covXX + covYY + det) / 2;
11355
+ const eigenVal2 = (covXX + covYY - det) / 2;
11356
+ const angle = Math.atan2(2 * covXY, covXX - covYY) / 2;
11357
+ const rotatedPoints = contour.map((p) => {
11358
+ const x = p[0] * Math.cos(-angle) - p[1] * Math.sin(-angle);
11359
+ const y = p[0] * Math.sin(-angle) + p[1] * Math.cos(-angle);
11360
+ return [x, y];
11361
+ });
11362
+ let minX = Infinity, maxX = -Infinity;
11363
+ let minY = Infinity, maxY = -Infinity;
11364
+ for (const [x, y] of rotatedPoints) {
11365
+ minX = Math.min(minX, x);
11366
+ maxX = Math.max(maxX, x);
11367
+ minY = Math.min(minY, y);
11368
+ maxY = Math.max(maxY, y);
11369
+ }
11370
+ const width = maxX - minX;
11371
+ const height = maxY - minY;
11372
+ return { width, height };
11373
+ };
11171
11374
 
11172
11375
  // src/geometry/window.mjs
11173
11376
  import * as THREE10 from "three";
@@ -11830,15 +12033,6 @@ var getWindowData = (lines, pcdData, lineReader) => {
11830
12033
  lines[findDoorIndexs[j]].windowData = savedata2;
11831
12034
  }
11832
12035
  }
11833
- let tmpLines = [];
11834
- for (let i = 0; i < lines.length; i++) {
11835
- if (!lines[i].isLine2)
11836
- tmpLines.push(lines[i]);
11837
- if (lines[i].isLine2 && lines[i].windowData.length != 0)
11838
- tmpLines.push(lines[i]);
11839
- }
11840
- lines.length = 0;
11841
- lines.push(...tmpLines);
11842
12036
  return { lines, pcdData };
11843
12037
  };
11844
12038
  var checkWindowAndDoorIsTrue = async (lines, runDataList, collectDataPath, pointCloudCluster = null) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rm-graphical-computing-node",
3
- "version": "1.0.68",
3
+ "version": "1.0.70",
4
4
  "description": "墙体/梁线/点云语义计算库(依赖 Python 与 three.js)",
5
5
  "type": "module",
6
6
  "main": "dist/index.mjs",