rm-graphical-computing-node 1.0.171 → 1.0.173

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 +155 -69
  2. package/package.json +1 -1
package/dist/index.mjs CHANGED
@@ -7772,6 +7772,29 @@ function getPolygonIntersectionRatio(polygon1, polygon2) {
7772
7772
  }
7773
7773
  return Math.max(0, Math.min(100, intersectionArea / area1 * 100));
7774
7774
  }
7775
+ var getTriangleAngles = (A, B2, C) => {
7776
+ function getAngle(v1, v2) {
7777
+ const denominator = v1.length() * v2.length();
7778
+ if (denominator === 0) return NaN;
7779
+ const cos = THREE3.MathUtils.clamp(
7780
+ v1.dot(v2) / denominator,
7781
+ -1,
7782
+ 1
7783
+ );
7784
+ return THREE3.MathUtils.radToDeg(Math.acos(cos));
7785
+ }
7786
+ const AB = new THREE3.Vector3().subVectors(B2, A);
7787
+ const AC = new THREE3.Vector3().subVectors(C, A);
7788
+ const BA = new THREE3.Vector3().subVectors(A, B2);
7789
+ const BC = new THREE3.Vector3().subVectors(C, B2);
7790
+ const CA = new THREE3.Vector3().subVectors(A, C);
7791
+ const CB = new THREE3.Vector3().subVectors(B2, C);
7792
+ return {
7793
+ angleA: getAngle(AB, AC),
7794
+ angleB: getAngle(BA, BC),
7795
+ angleC: getAngle(CA, CB)
7796
+ };
7797
+ };
7775
7798
 
7776
7799
  // src/utils/updateLine.mjs
7777
7800
  import * as THREE4 from "three";
@@ -8562,13 +8585,6 @@ var getBeamLine = async (lines, runDataList, pcdData, lineReader, lineEditor, on
8562
8585
  nearExtendDist = Infinity;
8563
8586
  indexTmp = -1;
8564
8587
  break;
8565
- } else if (!line2.isLine2 && !lines[f].isLine2) {
8566
- let minDist = Math.min(tmpDist5, tmpDist6, tmpDist7, tmpDist8);
8567
- if (minDist < 0.5) {
8568
- nearExtendDist = minDist;
8569
- indexTmp = f;
8570
- break;
8571
- }
8572
8588
  }
8573
8589
  }
8574
8590
  }
@@ -8676,13 +8692,6 @@ var getBeamLine = async (lines, runDataList, pcdData, lineReader, lineEditor, on
8676
8692
  nearExtendDist = Infinity;
8677
8693
  indexTmp = -1;
8678
8694
  break;
8679
- } else if (!line2.isLine2 && !lines[f].isLine2) {
8680
- let minDist = Math.min(tmpDist5, tmpDist6, tmpDist7, tmpDist8);
8681
- if (minDist < 0.5) {
8682
- nearExtendDist = minDist;
8683
- indexTmp = f;
8684
- break;
8685
- }
8686
8695
  }
8687
8696
  }
8688
8697
  }
@@ -8844,6 +8853,23 @@ var getBeamLine = async (lines, runDataList, pcdData, lineReader, lineEditor, on
8844
8853
  let dist33 = doorEd.distanceTo(beamSt);
8845
8854
  let dist44 = doorEd.distanceTo(beamEd);
8846
8855
  let isNear = dist11 < nearDist || dist22 < nearDist || dist33 < nearDist || dist44 < nearDist;
8856
+ let doorStExtended2 = doorSt.clone().addScaledVector(vec1, 5);
8857
+ let doorEdExtended2 = doorEd.clone().addScaledVector(vec1.clone().negate(), 5);
8858
+ let beamStExtended2 = beamSt.clone().addScaledVector(vec2, 5);
8859
+ let beamEdExtended2 = beamEd.clone().addScaledVector(vec2.clone().negate(), 5);
8860
+ let insertPt2 = segmentsIntersect2D(doorStExtended2, doorEdExtended2, beamStExtended2, beamEdExtended2);
8861
+ if (insertPt2 == null)
8862
+ continue;
8863
+ let dist55 = doorSt.distanceTo(insertPt2.point);
8864
+ let dist66 = doorEd.distanceTo(insertPt2.point);
8865
+ let dist77 = beamSt.distanceTo(insertPt2.point);
8866
+ let dist88 = beamEd.distanceTo(insertPt2.point);
8867
+ let ptAngle1 = insertPt2.point;
8868
+ let ptAngle2 = dist55 < dist66 ? doorEd.clone() : doorSt.clone();
8869
+ let ptAngle3 = dist77 < dist88 ? beamEd.clone() : beamSt.clone();
8870
+ let triangleAngle = getTriangleAngles(ptAngle1, ptAngle2, ptAngle3);
8871
+ if (triangleAngle.angleA > 100 || triangleAngle.angleB > 100 || triangleAngle.angleC > 100)
8872
+ continue;
8847
8873
  if ((isNear || insertPt) && bIsTrue) {
8848
8874
  if (doorAndDoorFrameDatas[n].category == "door frame") {
8849
8875
  findDoorFrame = true;
@@ -9377,6 +9403,14 @@ var getBeamLine = async (lines, runDataList, pcdData, lineReader, lineEditor, on
9377
9403
  nearBeamEd = tmpDoorBeamData.beamEnd.clone();
9378
9404
  nearLineIndex = doorBeamDataIndex[w2].linesIndex;
9379
9405
  nearDoorIndex = doorBeamDataIndex[w2].doorIndex;
9406
+ if (!doorAndBeamDataObj.isExtend) {
9407
+ if (!isPointOnLine2(line2.start, line2.end, doorAndBeamDataObj.doorStart, 1e-4, true) || !isPointOnLine2(line2.start, line2.end, doorAndBeamDataObj.doorEnd, 1e-4, true))
9408
+ doorAndBeamDataObj.isExtend = true;
9409
+ }
9410
+ if (!tmpDoorBeamData.isExtend) {
9411
+ if (!isPointOnLine2(lines[doorBeamDataIndex[w2].linesIndex].start, lines[doorBeamDataIndex[w2].linesIndex].end, tmpDoorBeamData.doorStart, 1e-4, true) || !isPointOnLine2(lines[doorBeamDataIndex[w2].linesIndex].start, lines[doorBeamDataIndex[w2].linesIndex].end, tmpDoorBeamData.doorEnd, 1e-4, true))
9412
+ tmpDoorBeamData.isExtend = true;
9413
+ }
9380
9414
  break;
9381
9415
  }
9382
9416
  }
@@ -14128,7 +14162,7 @@ var drawStaircase = (pcdPointsArr, scene) => {
14128
14162
  }
14129
14163
  return pointCloudGroup;
14130
14164
  };
14131
- var getMergeMeaning = (allProjectionResults, wallLines, wallVerifyType, averagePz2, pointCloudCluster = null, tolerancePointCloudCluster = 0.1, wallLinesDelPs = 0.2) => {
14165
+ var getMergeMeaning = (allProjectionResults, wallLines, wallVerifyType, averagePz2, pointCloudCluster = null, tolerancePointCloudCluster = 0.2, wallLinesDelPs = 0.2) => {
14132
14166
  if (allProjectionResults.length == 0) return [];
14133
14167
  if (!averagePz2) averagePz2 = allProjectionResults[0].averagePz;
14134
14168
  const pcdPointsArr = [];
@@ -14136,6 +14170,7 @@ var getMergeMeaning = (allProjectionResults, wallLines, wallVerifyType, averageP
14136
14170
  const CELL = 0.1;
14137
14171
  const grid = /* @__PURE__ */ new Map();
14138
14172
  const rectRegions = [];
14173
+ let isTrueType = ["floor", "Staircase", "window", "metal framing of interior glass partitions", "door", "balcony railing"];
14139
14174
  if (wallLines) {
14140
14175
  for (const line2 of wallLines) {
14141
14176
  for (const p2 of line2.originalPoints) {
@@ -14180,12 +14215,14 @@ var getMergeMeaning = (allProjectionResults, wallLines, wallVerifyType, averageP
14180
14215
  let threePoints = [];
14181
14216
  let threePointsStr = [];
14182
14217
  for (let u4 = 0; u4 < allProjectionResults[i].points.length; u4++) {
14183
- threePoints.push(new THREE8.Vector3(
14184
- allProjectionResults[i].points[u4].x,
14185
- allProjectionResults[i].points[u4].y,
14186
- allProjectionResults[i].points[u4].z
14187
- ));
14188
- threePointsStr.push(`${allProjectionResults[i].points[u4].x},${allProjectionResults[i].points[u4].y},${allProjectionResults[i].points[u4].z}`);
14218
+ if (allProjectionResults[i].points[u4].z > averagePz2 && allProjectionResults[i].points[u4].z - averagePz2 > 0.1 || isTrueType.includes(word)) {
14219
+ threePoints.push(new THREE8.Vector3(
14220
+ allProjectionResults[i].points[u4].x,
14221
+ allProjectionResults[i].points[u4].y,
14222
+ allProjectionResults[i].points[u4].z
14223
+ ));
14224
+ threePointsStr.push(`${allProjectionResults[i].points[u4].x},${allProjectionResults[i].points[u4].y},${allProjectionResults[i].points[u4].z}`);
14225
+ }
14189
14226
  }
14190
14227
  if (wallLines) {
14191
14228
  if (wallVerifyType.type1 && wallVerifyType.type1.length && wallVerifyType.type1.includes(word)) {
@@ -14293,6 +14330,72 @@ var getMergeMeaning = (allProjectionResults, wallLines, wallVerifyType, averageP
14293
14330
  }
14294
14331
  }
14295
14332
  }
14333
+ if (pointCloudCluster != null) {
14334
+ for (let i = 0; i < pcdPointsArr.length; i++) {
14335
+ let type = pcdPointsArr[i].type;
14336
+ if (type != "window") continue;
14337
+ let array = pcdPointsArr[i].array;
14338
+ let delArray = /* @__PURE__ */ new Set();
14339
+ let newArray = [];
14340
+ for (let j = 0; j < array.length; j++) {
14341
+ if (delArray.has(j)) continue;
14342
+ let points = array[j].points;
14343
+ let obj_id = array[j].obj_id;
14344
+ let type2 = array[j].type;
14345
+ let averagePz3 = array[j].averagePz;
14346
+ let positionArr = array[j].positionArr;
14347
+ let isStaircaseBalconyRailing = array[j].isStaircaseBalconyRailing;
14348
+ if (points.length < 50)
14349
+ continue;
14350
+ let clusterResult = pointCloudCluster([points], {
14351
+ tolerance: tolerancePointCloudCluster,
14352
+ minClusterSize: 20,
14353
+ maxClusterSize: 1e7,
14354
+ threadCount: 1
14355
+ });
14356
+ let beforeLength = newArray.length;
14357
+ if (clusterResult.length > 0 && clusterResult[0].length > 1) {
14358
+ let add = 1;
14359
+ for (const cluster of clusterResult[0]) {
14360
+ if (cluster.length < 50) continue;
14361
+ const newOriginalPoints = cluster.map((i2) => points[i2]);
14362
+ const centerData = getCenterAndPointHeight(newOriginalPoints);
14363
+ let pathPoints = newOriginalPoints.map((p) => [p.x, p.y]);
14364
+ const data = {
14365
+ points: newOriginalPoints,
14366
+ path: computeContour(pathPoints),
14367
+ h: centerData.h,
14368
+ minz: centerData.minz,
14369
+ maxz: centerData.maxz,
14370
+ center: { x: centerData.x, y: centerData.y, z: centerData.z },
14371
+ type: type2,
14372
+ averagePz: averagePz3,
14373
+ obb: null,
14374
+ obj_id: obj_id + `_${add}`,
14375
+ positionArr,
14376
+ isStaircaseBalconyRailing,
14377
+ mapPosition: array[j]?.mapPosition
14378
+ };
14379
+ data.obb = getObb(data.path, data.center, data.h, (data.maxz + data.minz) / 2);
14380
+ if (data.obb == null) continue;
14381
+ newArray.push(data);
14382
+ add++;
14383
+ }
14384
+ }
14385
+ if (newArray.length != beforeLength) {
14386
+ delArray.add(j);
14387
+ }
14388
+ }
14389
+ if (delArray.size > 0) {
14390
+ for (let j = 0; j < array.length; j++) {
14391
+ if (!delArray.has(j)) {
14392
+ newArray.push(array[j]);
14393
+ }
14394
+ }
14395
+ pcdPointsArr[i].array = newArray;
14396
+ }
14397
+ }
14398
+ }
14296
14399
  function appendPcdObj(targetType, sourceType) {
14297
14400
  const targetData = pcdPointsArr.find((item) => item.type == targetType);
14298
14401
  const sourceData = pcdPointsArr.find((item) => item.type == sourceType);
@@ -14453,9 +14556,8 @@ var getMergeMeaning = (allProjectionResults, wallLines, wallVerifyType, averageP
14453
14556
  delData.add(k);
14454
14557
  let threePoints = [];
14455
14558
  let threePointsStr = [];
14456
- let isTrueType = cloneData.type == "floor" || cloneData.type == "Staircase" || cloneData.type == "window" || cloneData.type == "metal framing of interior glass partitions" || cloneData.type == "door" || cloneData.type == "balcony railing";
14457
14559
  for (let m = 0; m < array[k].points.length; m++) {
14458
- if (array[k].points[m].z > averagePz2 && array[k].points[m].z - averagePz2 > 0.1 || isTrueType) {
14560
+ if (array[k].points[m].z > averagePz2 && array[k].points[m].z - averagePz2 > 0.1 || isTrueType.includes(cloneData.type)) {
14459
14561
  cloneData.points.push(array[k].points[m]);
14460
14562
  threePoints.push(array[k].points[m]);
14461
14563
  threePointsStr.push(`${array[k].points[m].x},${array[k].points[m].y},${array[k].points[m].z}`);
@@ -14682,7 +14784,7 @@ var getMergeMeaning = (allProjectionResults, wallLines, wallVerifyType, averageP
14682
14784
  for (let k = 0; k < newnewData.length; k++) {
14683
14785
  if (newnewData[k].obb == null || delData.has(k) || j == k)
14684
14786
  continue;
14685
- let tol = 0.5;
14787
+ let tol = 0.35;
14686
14788
  let boxVecK = getObbLongSideDirection(newnewData[k].obb);
14687
14789
  let obbPointsClone = getOBBPoints(cloneData.obb);
14688
14790
  let polygonK = newnewData[k].path.map((point2) => new THREE8.Vector3(point2[0], point2[1], 0));
@@ -17901,13 +18003,6 @@ var getWindowData = (lines, pcdData, lineReader) => {
17901
18003
  if (!line2.mergeCheckRegion || line2.mergeCheckRegion.length == 0)
17902
18004
  continue;
17903
18005
  line2.completePointAreaPercentage = -1;
17904
- let box = new THREE10.Box3();
17905
- box.setFromPoints(line2.originalPoints);
17906
- let maxZ = box.max.z;
17907
- let minZ = box.min.z;
17908
- const lineStart = new THREE10.Vector3(line2.start.x, line2.start.y, line2.start.z);
17909
- const lineEnd = new THREE10.Vector3(line2.end.x, line2.end.y, line2.end.z);
17910
- let floorHeightTmp = line2.rooftopPz - line2.start.z;
17911
18006
  let totalArea = 0;
17912
18007
  for (const region of line2.mergeCheckRegion) {
17913
18008
  const facePoints = region.facePoints;
@@ -18462,11 +18557,6 @@ var getWindowData = (lines, pcdData, lineReader) => {
18462
18557
  lines[findDoorIndexs[j]].windowData = savedata2;
18463
18558
  }
18464
18559
  }
18465
- for (let i = 0; i < lines.length; i++) {
18466
- const line2 = lines[i];
18467
- line2.originalPoints = lineReader.getOriginalPointsById(line2.id);
18468
- line2.checkResults = lineReader.getLineCheckReultsById(line2.id);
18469
- }
18470
18560
  return { lines, pcdData };
18471
18561
  };
18472
18562
  var checkWindowAndDoorIsTrue = async (lines, runDataList, collectDataPath, pointCloudCluster = null) => {
@@ -19489,51 +19579,47 @@ function rdp(points, epsilon3) {
19489
19579
  if (typeof module !== "undefined" && module.exports) {
19490
19580
  module.exports = { fitPolyline, rdp };
19491
19581
  }
19492
- function smoothPolyline(vertices, samplesPerSegment = 40) {
19493
- if (!Number.isInteger(samplesPerSegment) || samplesPerSegment < 1) {
19494
- throw new Error("samplesPerSegment \u5FC5\u987B\u4E3A\u6B63\u6574\u6570");
19582
+ function smoothPolyline(vertices, samplesPerSegment = 40, rounds = 3) {
19583
+ if (!Array.isArray(vertices)) {
19584
+ throw new Error("vertices \u5FC5\u987B\u4E3A\u6570\u7EC4");
19495
19585
  }
19496
- if (!Array.isArray(vertices) || vertices.some(
19586
+ if (!Number.isInteger(rounds) || rounds < 0 || rounds > 8) {
19587
+ throw new Error("rounds \u5FC5\u987B\u4E3A 0~8 \u7684\u6574\u6570");
19588
+ }
19589
+ if (vertices.some(
19497
19590
  (p) => !p || !Number.isFinite(p.x) || !Number.isFinite(p.y)
19498
19591
  )) {
19499
19592
  throw new Error("vertices \u5FC5\u987B\u4E3A\u6709\u6548 XY \u70B9\u6570\u7EC4");
19500
19593
  }
19501
- const points = [];
19594
+ let points = [];
19502
19595
  for (const p of vertices) {
19503
19596
  const last = points[points.length - 1];
19504
19597
  if (!last || Math.hypot(p.x - last.x, p.y - last.y) > 1e-12) {
19505
19598
  points.push({ x: p.x, y: p.y });
19506
19599
  }
19507
19600
  }
19508
- if (points.length < 2) return points;
19509
- const dt = (a, b) => Math.sqrt(Math.hypot(b.x - a.x, b.y - a.y));
19510
- const extrapolate = (a, b) => ({ x: 2 * a.x - b.x, y: 2 * a.y - b.y });
19511
- const blend = (a, b, ta, tb, t) => {
19512
- const w = (t - ta) / (tb - ta);
19513
- return { x: a.x * (1 - w) + b.x * w, y: a.y * (1 - w) + b.y * w };
19514
- };
19515
- const result = [{ ...points[0] }];
19516
- for (let i = 0; i < points.length - 1; i++) {
19517
- const p1 = points[i], p2 = points[i + 1];
19518
- const p0 = i > 0 ? points[i - 1] : extrapolate(p1, p2);
19519
- const p3 = i + 2 < points.length ? points[i + 2] : extrapolate(p2, p1);
19520
- const t0 = 0, t1 = dt(p0, p1);
19521
- const t2 = t1 + dt(p1, p2), t3 = t2 + dt(p2, p3);
19522
- for (let j = 1; j <= samplesPerSegment; j++) {
19523
- if (j === samplesPerSegment) {
19524
- result.push({ ...p2 });
19525
- continue;
19526
- }
19527
- const t = t1 + (t2 - t1) * j / samplesPerSegment;
19528
- const a1 = blend(p0, p1, t0, t1, t);
19529
- const a2 = blend(p1, p2, t1, t2, t);
19530
- const a3 = blend(p2, p3, t2, t3, t);
19531
- const b1 = blend(a1, a2, t0, t2, t);
19532
- const b2 = blend(a2, a3, t1, t3, t);
19533
- result.push(blend(b1, b2, t1, t2, t));
19601
+ if (points.length < 3 || rounds === 0) {
19602
+ return points;
19603
+ }
19604
+ for (let r = 0; r < rounds; r++) {
19605
+ const result = [points[0]];
19606
+ for (let i = 0; i < points.length - 1; i++) {
19607
+ const p0 = points[i];
19608
+ const p1 = points[i + 1];
19609
+ const q = {
19610
+ x: p0.x * 0.75 + p1.x * 0.25,
19611
+ y: p0.y * 0.75 + p1.y * 0.25
19612
+ };
19613
+ const r2 = {
19614
+ x: p0.x * 0.25 + p1.x * 0.75,
19615
+ y: p0.y * 0.25 + p1.y * 0.75
19616
+ };
19617
+ result.push(q, r2);
19534
19618
  }
19619
+ result.push(points[points.length - 1]);
19620
+ points = result;
19535
19621
  }
19536
- return result;
19622
+ return points;
19537
19623
  }
19538
19624
  if (typeof module !== "undefined" && module.exports) {
19539
19625
  module.exports.smoothPolyline = smoothPolyline;
@@ -20673,7 +20759,7 @@ var getArcWallLine = (lines) => {
20673
20759
  }
20674
20760
  const polyline = fitPolyline(pts, 5e-3, 32);
20675
20761
  const curve = resampleByLength(
20676
- smoothPolyline(polyline, 200),
20762
+ smoothPolyline(polyline, 200, 3),
20677
20763
  161
20678
20764
  );
20679
20765
  const threeData = curve.map((p) => new THREE12.Vector3(p.x, p.y, 0));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rm-graphical-computing-node",
3
- "version": "1.0.171",
3
+ "version": "1.0.173",
4
4
  "description": "墙体/梁线/点云语义计算库(依赖 Python 与 three.js)",
5
5
  "type": "module",
6
6
  "main": "dist/index.mjs",