正交视图三维重建 笔记 2d线到3d线
这种代码怎么写好,x1==tx1 x2==tx2 x1x2在一条线上tx2和tx1在一条线上输出x1 y1 ty1,x2 y2 ty2
线过的点 的集合
俯视图找深度
测试一下
目标
四条线变一条线
复杂度贼大跑起来贼慢
加了16000条
去重
for (const [x1, y1, x2, y2, lineId, type] of frontpointlist) {for (const [x3, y3, x4, y4, lineId2, type2] of toppointlist) {if (x1 === x3 && x2 === x4) {const drawline1=[x1, y1, y3 - clusterMinY, x2, y2, y3 - clusterMinY]const drawline2=[x1, y1, y4 - clusterMinY, x2, y2, y4 - clusterMinY]const key = drawline1.map(v => v.toFixed(2)).join(',');if (!seenLinePairs.has(key)) {seenLinePairs.add(key);lines3d.push([x1, y1, y3 - clusterMinY, x2, y2, y3 - clusterMinY, lineId, type]);}const key2 = drawline2.map(v => v.toFixed(2)).join(',');if (!seenLinePairs.has(key2)) {seenLinePairs.add(key2);lines3d.push([x1, y1, y4 - clusterMinY, x2, y2, y4 - clusterMinY, lineId, type]);}}}
}
上下分离
俯视图的拉伸需要旋转
yz调换
升天
俯视图z忘记归零了
多了4条线,不过问题不大,不影响生成面,生成面是要闭合环
经典缺线
分开判断看看
多这条线是不能容忍的
飞了
取x,x不一样
这条线不存在于俯视图
按x方向投
主视图侧视图投影线需要在俯视图里
for (const [x1, y1, x2, y2,lineId] of mostFrequentCluster.lines) {for (const [x3, y3, x4, y4,lineId2,type] of mostFrequentCluster.lines) {
if(x1<=x3 && x2>=x4 && y1<=y3 && y2>=y4 )
{frontpointlist.push([x3, y3, x4, y4,lineId2,type]);
frontpointmap .set([x3, y3,x4, y4], true);}}
}
200,0
捕捉不到兀线
for (const [x1, y1, x2, y2, lineId, type] of toppointlist) {for (const [x3, y3, x4, y4, lineId2, type2] of frontpointlist){if (x1 === x3 && x2 === x4) {const drawline1=[x1, y3, y1 , x2, y3, y2];const drawline2=[x1, y4, y1 , x2, y4, y2];const key = drawline1.map(v => v.toFixed(2)).join(',');if (!seenLinePairs.has(key)) {seenLinePairs.add(key);// lines3d.push([x1, y3, y1, x2, y3, y2, lineId, type]);}const key2 = drawline2.map(v => v.toFixed(2)).join(',');if (!seenLinePairs.has(key2)) {seenLinePairs.add(key2);// lines3d.push([x1, y4, y1 , x2, y4, y2, lineId, type]);}}}}for (const [x1, y1, x2, y2, lineId, type] of rightpointlist) {for (const [x3, y3, x4, y4, lineId2, type2] of frontpointlist) {if (y1 === y3&& y2 === y4) {const drawline1=[x3, y1, x1, x3, y2, x2];const drawline2=[x4, y1, x1, x4, y2, x2];const key = drawline1.map(v => v.toFixed(2)).join(',');if (!seenLinePairs.has(key)) {seenLinePairs.add(key);lines3d.push([x3, y1, x1, x3, y2, x2 ,lineId, type]);}const key2 = drawline2.map(v => v.toFixed(2)).join(',');if (!seenLinePairs.has(key2)) {seenLinePairs.add(key2);lines3d.push([x4, y1, x1, x4, y2, x2, lineId, type]);}}}
没什么软用
for (const [x1, y1, x2, y2,lineId] of mostFrequentCluster.lines) {for (const [x3, y3, x4, y4,lineId2,type] of mostFrequentCluster.lines) {
if(x1<=x3 && x2>=x4 && y1<=y3 && y2>=y4 )
{frontpointlist.push([x3, y3, x4, y4,lineId2,type]);
frontpointmap .set(`${x3},${y3 }`, true);
frontpointmap .set( `${x4},${y4}`, true);}}
}
for (const [x1, y1, x2, y2,lineId] of topcluauster.lines) {for (const [x3, y3, x4, y4,lineId2,type] of topcluauster.lines) {if(x1<=x3 && x2>=x4 && y1<=y3 && y2>=y4 )
{toppointlist.push([x3, y3- clusterMinY, x4, y4- clusterMinY,lineId2,type]);
toppointmap .set(`${x3},${y3- clusterMinY }`, true);
toppointmap .set( `${x4},${y4- clusterMinY}`, true);
}}
}
for (const [x1, y1, x2, y2,lineId] of rightcluster.lines) {for (const [x3, y3, x4, y4,lineId2,type] of rightcluster.lines) {if(x1<=x3 && x2>=x4 && y1<=y3 && y2>=y4 )
{rightpointlist.push([x3-clusterMinx, y3, x4-clusterMinx, y4,lineId2,type]);rightpointmap .set(`${x3-clusterMinx },${y3 }`, true);rightpointmap .set( `${x4-clusterMinx },${y4}`, true);}}
}
看看别人怎么写的
for (const [fx1, fy1, fx2, fy2, lineId, type] of frontpointlist) {for (const [tx1, ty1, tx2, ty2, lineId2, type2] of toppointlist) {if (fx1 === tx1 && fx2 === tx2) {const A=[fx1, fy1, ty1];const Ahat=[fx1, fy1, ty2];const B=[fx2, fy2, ty1];const Bhat=[fx2, fy2, ty2];}}
}
好短
const seenLinePairs = new Set<string>(); // 用于记录已经添加过的 [lineId, lineId2] 对
function drawlines(x1:number, y1:number, z1:number , x2:number, y2:number, z2:number , lineId:number, type:number){if([x1, y1, z1].join(',') === [x2, y2, z2].join(','))return;const drawline2=[x1, y1, z1 , x2, y2,z2]const key2 = drawline2.map(v => v.toFixed(2)).join(',');if (!seenLinePairs.has(key2)) {seenLinePairs.add(key2);lines3d.push([x1, y1, z1, x2, y2, z2 , lineId, type]);}}
for (const [fx1, fy1, fx2, fy2, lineId, type] of frontpointlist) {for (const [tx1, ty1, tx2, ty2, lineId2, type2] of toppointlist) {if (fx1 === tx1 && fx2 === tx2) {const A=[fx1, fy1, ty1];const Ahat=[fx1, fy1, ty2];const B=[fx2, fy2, ty1];const Bhat=[fx2, fy2, ty2];drawlines(A[0], A[1], A[2], Ahat[0], Ahat[1], Ahat[2], lineId, type);drawlines(B[0], B[1], B[2], Bhat[0], Bhat[1], Bhat[2], lineId, type);drawlines(A[0], A[1], A[2], B[0], B[1], B[2], lineId, type);drawlines(Ahat[0], Ahat[1], Ahat[2], Bhat[0], Bhat[1], Bhat[2], lineId, type);}}
}
又缺线
for (const [fx1, fy1, fx2, fy2, lineId, type] of frontpointlist) {for (const [tx1, ty1, tx2, ty2, lineId2, type2] of toppointlist) {if (isLineInSet([fx1,ty1,fx2,ty1] ,toplineSet)&& isLineInSet([fx1,ty2,fx2,ty2] ,toplineSet)) {const A=[fx1, fy1, ty1];const Ahat=[fx1, fy1, ty2];const B=[fx2, fy2, ty1];const Bhat=[fx2, fy2, ty2];drawlines(A[0], A[1], A[2], Ahat[0], Ahat[1], Ahat[2], lineId, type);drawlines(B[0], B[1], B[2], Bhat[0], Bhat[1], Bhat[2], lineId, type);drawlines(A[0], A[1], A[2], B[0], B[1], B[2], lineId, type);drawlines(Ahat[0], Ahat[1], Ahat[2], Bhat[0], Bhat[1], Bhat[2], lineId, type);}}
}
明天用rbush解决兀的情况,然后前视图俯视图调换一下看看效果