正交视图转3d

       mostFrequentCluster.lines.forEach(line => {const [x1, y1, x2, y2] = line;let xhat={x1,x2};let yhat={y1,y2};});

 没考虑到侧视图

   const clusters = clusterLines(inputlines, 5);const lines3d:[number,number,number,number,number,number][]=[]const { mostMinX, mostMinY } = getMostFrequentMinXY(clusters);const mostFrequentClusters = clusters.filter(cluster => {return cluster.min_x === mostMinX.value && cluster.min_y === mostMinY.value;
});
const topclusters = clusters.filter(cluster => {return cluster.min_x === mostMinX.value && cluster.min_y > mostMinY.value;
});
;
const rightclusters = clusters.filter(cluster => {return cluster.min_x > mostMinX.value && cluster.min_y === mostMinY.value;
});
const bottomclusters = clusters.filter(cluster => {return cluster.min_x === mostMinX.value && cluster.min_y < mostMinY.value;
});
const leftclusters = clusters.filter(cluster => {return cluster.min_x < mostMinX.value && cluster.min_y === mostMinY.value;
});const mostFrequentCluster= mostFrequentClusters[0];const topcluauster= topclusters[0];const rightcluster= rightclusters[0];const bottomcluster= bottomclusters[0];const leftcluster= leftclusters[0];mostFrequentCluster.lines.forEach(line => {const [x1, y1, x2, y2] = line;const seen = new Set<string>(); // 用于记录已经添加过的线段function addUniqueLine(x1: number, y1: number, z1: number, x2: number, y2: number, z2: number) {const key = `${x1},${y1},${z1},${x2},${y2},${z2}`;if (!seen.has(key)) {seen.add(key);lines3d.push([x1, y1, z1, x2, y2, z2]);}
}topcluauster.lines.forEach(line => {const [tx1, ty1, tx2, ty2] = line;const clusterminy=topcluauster.min_y;if (tx1 <x1 && tx2 > x2) {addUniqueLine(x1, y1, ty1-clusterminy, x2, y2, ty1-clusterminy);
addUniqueLine(x1, y1, ty2-clusterminy, x2, y2, ty2-clusterminy);}rightcluster.lines.forEach(line => {const [rx1, ry1, rx2, ry2] = line;const clusterminx=rightcluster.min_x;if (ry1 <y1 && ry2 > y2) {addUniqueLine(x1, y1, rx1-clusterminx, x2, y2, rx1-clusterminx);
addUniqueLine(x1, y1, rx2-clusterminx, x2, y2, rx2-clusterminx);}});});});
Logger.info(`lines3d completed with ${lines3d.length} lines3d`);lines3d.forEach(line => {PubSub.default.pub("njsgcs_makeline", line[0], line[1],  line[2], line[3], line[4], line[5],1); })

第3 视角0是在外侧

材质全是红色说明侧视图读取可有可无

           topcluauster.lines.forEach(line => {const [tx1, ty1, tx2, ty2] = line;const clusterminy=topcluauster.min_y;if (tx1 <=x1 && tx2 >= x2) {addUniqueLine(x1, y1, ty1-clusterminy, x2, y2, ty1-clusterminy,1);
addUniqueLine(x1, y1, ty2-clusterminy, x2, y2, ty2-clusterminy,1);
addUniqueLine(x1, y1, ty1-clusterminy, x2, y2, ty2-clusterminy,1);}

.............

        topcluauster.lines.forEach(line => {const [tx1, ty1, tx2, ty2] = line;const clusterminy=topcluauster.min_y;if (tx1 <=x1 && tx2 >= x2) {addUniqueLine(x1, y1, ty1-clusterminy, x2, y2, ty1-clusterminy,1);
addUniqueLine(x1, y1, ty2-clusterminy, x2, y2, ty2-clusterminy,1);
addUniqueLine(x1, y1, ty1-clusterminy, x2, y2, ty2-clusterminy,1);
addUniqueLine(x1, y1, ty2-clusterminy, x2, y2, ty1-clusterminy,1);}

               topcluauster.lines.forEach(line => {const [tx1, ty1, tx2, ty2] = line;const clusterminy=topcluauster.min_y;if (tx1 <=x1 && tx2 >= x2) {addUniqueLine(x1, y1, ty1-clusterminy, x2, y2, ty1-clusterminy,1);
addUniqueLine(x1, y1, ty2-clusterminy, x2, y2, ty2-clusterminy,1);if(ty1!=ty2){
addUniqueLine(x1, y1, ty1-clusterminy, x1, y1, ty2-clusterminy,1);
addUniqueLine(x2, y2, ty1-clusterminy, x2, y2, ty2-clusterminy,1);}

旧版本合并会吃线条,不然是可以手动转为实体的

import { Logger, PubSub } from "chili-core";
import DxfParser, { ILineEntity } from 'dxf-parser';
class Cluster {lines: [number, number, number, number][];min_x: number;max_x: number;min_y: number;max_y: number;constructor(lines: [number, number, number, number][] = []) {this.lines = [...lines];this.min_x = Infinity;this.max_x = -Infinity;this.min_y = Infinity;this.max_y = -Infinity;if (lines.length > 0) {this.updateBounds();}}updateBounds(): void {this.min_x = Math.min(...this.lines.flatMap(line => [line[0], line[2]]));this.max_x = Math.max(...this.lines.flatMap(line => [line[0], line[2]]));this.min_y = Math.min(...this.lines.flatMap(line => [line[1], line[3]]));this.max_y = Math.max(...this.lines.flatMap(line => [line[1], line[3]]));}get lengthX(): number {return parseFloat((this.max_x - this.min_x).toFixed(1));}get lengthY(): number {return parseFloat((this.max_y - this.min_y).toFixed(1));}
}
function clusterLines(lines: [number, number, number, number][], expandDistance: number = 5): Cluster[] {const clusters: Cluster[] = [];const remainingLines = [...lines];while (remainingLines.length > 0) {const seed = remainingLines.shift()!;const currentCluster = new Cluster([seed]);currentCluster.updateBounds();let changed = true;while (changed) {changed = false;const expandedMinX = currentCluster.min_x - expandDistance;const expandedMaxX = currentCluster.max_x + expandDistance;const expandedMinY = currentCluster.min_y - expandDistance;const expandedMaxY = currentCluster.max_y + expandDistance;const toAdd: [number, number, number, number][] = [];for (const line of [...remainingLines]) {const [x1, y1, x2, y2] = line;const inBound =(x1 >= expandedMinX && x1 <= expandedMaxX && y1 >= expandedMinY && y1 <= expandedMaxY) ||(x2 >= expandedMinX && x2 <= expandedMaxX && y2 >= expandedMinY && y2 <= expandedMaxY);if (inBound) {toAdd.push(line);changed = true;}}for (const line of toAdd) {currentCluster.lines.push(line);remainingLines.splice(remainingLines.indexOf(line), 1);}currentCluster.updateBounds();}// 合并完全覆盖的聚类for (let i = 0; i < clusters.length; i++) {const cluster = clusters[i];if (currentCluster.min_x <= cluster.min_x &&currentCluster.min_y <= cluster.min_y &&currentCluster.max_x >= cluster.max_x &&currentCluster.max_y >= cluster.max_y) {currentCluster.lines.push(...cluster.lines);clusters.splice(i, 1);break;}}clusters.push(currentCluster);}return clusters;
}
export function rebuild3D(document: Document) {const fileInput = document.createElement("input");fileInput.type = "file";fileInput.accept = ".dxf";fileInput.style.display = "none";fileInput.addEventListener("change", async (event) => {const target = event.target as HTMLInputElement;if (!target.files || target.files.length === 0) return;const file = target.files[0];Logger.info(`Selected file: ${file.name}`);try {const reader = new FileReader();reader.onload = () => {const dxfText = reader.result as string;const parser = new DxfParser();const dxf = parser.parseSync(dxfText);const inputlines: [number, number, number, number][] = [];if (dxf && dxf.entities) {dxf.entities.forEach(entity => {if (entity.type === 'LINE') {const lineEntity = entity as ILineEntity;const start = lineEntity.vertices[0];const end = lineEntity.vertices[1];if (start && end) {inputlines.push([start.x, start.y, end.x, end.y]);}}});}// 执行聚类const clusters = clusterLines(inputlines, 5);const lines3d:[number,number,number,number,number,number,number][]=[]const { mostMinX, mostMinY } = getMostFrequentMinXY(clusters);const mostFrequentClusters = clusters.filter(cluster => {return cluster.min_x === mostMinX.value && cluster.min_y === mostMinY.value;
});
const topclusters = clusters.filter(cluster => {return cluster.min_x === mostMinX.value && cluster.min_y > mostMinY.value;
});
;
const rightclusters = clusters.filter(cluster => {return cluster.min_x > mostMinX.value && cluster.min_y === mostMinY.value;
});
const bottomclusters = clusters.filter(cluster => {return cluster.min_x === mostMinX.value && cluster.min_y < mostMinY.value;
});
const leftclusters = clusters.filter(cluster => {return cluster.min_x < mostMinX.value && cluster.min_y === mostMinY.value;
});const mostFrequentCluster= mostFrequentClusters[0];const topcluauster= topclusters[0];const rightcluster= rightclusters[0];const bottomcluster= bottomclusters[0];const leftcluster= leftclusters[0];const seen = new Set<string>(); // 用于记录已经添加过的线段function addUniqueLine(x1: number, y1: number, z1: number, x2: number, y2: number, z2: number,color:number) {const key = `${x1},${y1},${z1},${x2},${y2},${z2}`;if (!seen.has(key)) {seen.add(key);lines3d.push([x1, y1, z1, x2, y2, z2,color]);}
} const topview3dpoints = [];mostFrequentCluster.lines.forEach(line => {const [x1, y1, x2, y2] = line;topcluauster.lines.forEach(line => {const [tx1, ty1, tx2, ty2] = line;const clusterminy=topcluauster.min_y;if (tx1 <=x1 || tx2 >= x2) {addUniqueLine(x1, y1, ty1-clusterminy, x2, y2, ty1-clusterminy,1);
addUniqueLine(x1, y1, ty2-clusterminy, x2, y2, ty2-clusterminy,1);if(ty1!=ty2){
addUniqueLine(x1, y1, ty1-clusterminy, x1, y1, ty2-clusterminy,1);
addUniqueLine(x2, y2, ty1-clusterminy, x2, y2, ty2-clusterminy,1);}}});});
Logger.info(`lines3d completed with ${lines3d.length} lines3d`);lines3d.forEach(line => {PubSub.default.pub("njsgcs_makeline", line[0], line[1],  line[2], line[3], line[4], line[5],1); })///// let i =0;// // 发送每个线段给 njsgcs_makeline// clusters.forEach(cluster => {//     i++;//     cluster.lines.forEach(line => {//         const [x1, y1, x2, y2] = line;//         PubSub.default.pub("njsgcs_makeline", x1, y1, 0, x2, y2, 0,i); // z=0 假设为俯视图//     });// });///Logger.info(`Clustering completed with ${clusters.length} clusters`);};reader.readAsText(file);} catch (error) {Logger.error("Error reading file:", error);}});fileInput.click();
}
function getMostFrequentMinXY(clusters: Cluster[]) {const minXCounts: Record<number, number> = {};const minYCounts: Record<number, number> = {};let maxXCount = 0, mostX = clusters[0]?.min_x;let maxYCount = 0, mostY = clusters[0]?.min_y;for (const cluster of clusters) {const x = cluster.min_x;const y = cluster.min_y;minXCounts[x] = (minXCounts[x] || 0) + 1;if (minXCounts[x] > maxXCount) {maxXCount = minXCounts[x];mostX = x;}minYCounts[y] = (minYCounts[y] || 0) + 1;if (minYCounts[y] > maxYCount) {maxYCount = minYCounts[y];mostY = y;}}return {mostMinX: { value: mostX, count: maxXCount },mostMinY: { value: mostY, count: maxYCount }};
}

 

 里面开槽会多线

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如若转载,请注明出处:http://www.pswp.cn/news/911864.shtml
繁体地址,请注明出处:http://hk.pswp.cn/news/911864.shtml
英文地址,请注明出处:http://en.pswp.cn/news/911864.shtml

如若内容造成侵权/违法违规/事实不符,请联系英文站点网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

【Docker基础】Docker容器生命周期管理:从创建到删除的完整指南

目录 1 容器生命周期概述 2 容器创建&#xff08;docker create&#xff09; 2.1 docker create命令详解 2.2 创建流程解析 2.3 创建与运行的区别 3 容器启动&#xff08;docker start&#xff09; 3.1 docker start命令详解 3.2 启动流程解析 3.3 启动与运行的区别 …

Docker、Docker composer与Docker desktop

文章目录 Docker、Docker composer与Docker desktop一、docker、docker composer、docker desktop1.1 Docker1.2 Docker Compose1.3 Docker Desktop1.4 三者之间的区别 二、docker desktop的安装和换源2.1 前期准备WSL2 2.1 Docker Desktop 安装下载 Docker Desktop安装 Docker…

H5录音、图文视频IndexDB储存最佳实践:用AI生成语音备忘录

引言 早在大学的时候&#xff0c;我就期望做一款属于自己的 APP&#xff0c;可惜那时不懂技术。现在有了技术&#xff0c;但却没有时间。好在 AI 的快速发展终于让我完成了这个愿望。于是&#xff0c;我用半天的时间&#xff0c;用 AI 生成了一个纯前端的 H5 程序&#xff1a;…

简述C++ nlohmann/json 库

目录 JSON概述 nlohmann/json 库的使用 创建json数组/对象 字符串解析&#xff08;parse反序列化&#xff09; 数据访问 序列化 文件读写 JSON概述 JSON(JavaScrip Object Notation)是一种轻量级、跨语言的数据交换格式。它基于 ECMAScript 子集&#xff0c;以独立于编程…

定制开发开源AI智能名片与S2B2C商城小程序的内容分发体系构建:基于“1+N“素材复用模型的创新实践

摘要&#xff1a;在数字内容爆炸式增长的当下&#xff0c;本文针对内容分发效率低下的行业痛点&#xff0c;提出基于"定制开发开源AI智能名片S2B2C商城小程序"的一体化解决方案。通过构建"1篇长文10条长视频20条短视频10个平台"的素材复用公式&#xff0c;…

c++26新功能—hive容器

一、容器的演进 科学进步的过程一般来说都是从先解决常用的、迫切的问题开始&#xff0c;然后再逐步解决一些少见不迫切的问题&#xff0c;直到最终解决到认知程度内的诸多问题。举一个网上的例子&#xff0c;以前说咱们无法生产水笔的尖头上的钢球&#xff0c;其实这对于国内…

Kafka 源码剖析:消息存储与协议实现(二)

四、协议实现机制探秘 4.1 生产者协议 4.1.1 消息发送流程 Producer 在向 Kafka 集群发送消息时&#xff0c;首先会根据分区策略选择目标分区 。常见的分区策略有轮询、按消息键的哈希值分区以及自定义分区策略 。如果生产者在发送消息时指定了分区号&#xff0c;那么消息就…

Vue.js 与 TypeScript:最佳实践

1. 引言 Vue.js 是一个渐进式、灵活的 JavaScript 框架&#xff0c;广泛用于构建用户界面和单页应用&#xff08;SPA&#xff09;。而 TypeScript 是 JavaScript 的一个超集&#xff0c;添加了静态类型和其他高级特性。将两者结合使用&#xff0c;可以帮助开发者构建更具可维护…

webpack5 css-loader:从基础到原理

webpack 处理样式 webpack本身是不能识别样式资源的&#xff0c;需要借助Loader来帮助webpack解析样式资源&#xff0c;样式资源包括但不限于css/less/sass/scss/styl 未使用样式处理加载器前 运行webpack打包命令 bash npx webpack报错信息如图&#xff0c;提示无法识别css…

【GESP】C++三级练习 luogu-B2096 直方图

GESP C三级练习&#xff0c;一维数组练习&#xff0c;难度★★☆☆☆。 题目题解详见&#xff1a;【GESP】C三级练习 luogu-B2096 直方图 | https://www.coderli.com/gesp-3-luogu-b2096/ 【GESP】C三级练习 luogu-B2096 直方图 | OneCoderGESP C三级练习&#xff0c;一维数组…

【网站内容安全检测】之2:从网站所有URL页面中提取所有外部及内部域名信息

还没写成Go的&#xff0c;用Python吧&#xff0c;稍微慢一点 依赖内容&#xff08;安装命令pip install -r requirements.txt) requirements.txt aiohttp beautifulsoup44.12.2 tqdm4.66.1 redis5.2.1 motor3.3.1 pymongo4.6.0 chardet提取域名的程序 domain_extractor.py …

【LLaMA-Factory 实战系列】四、API 篇 - 部署推理服务与批量调用实战

【LLaMA-Factory 实战系列】四、API 篇 - 部署推理服务与批量调用实战 1. 引言2. 推理后端的选择与对比3. 部署 API 推理服务3.1 创建 API 配置文件3.2 启动 API 服务3.3 探索交互式 API 文档 4. 编写 Python 脚本进行批量调用4.1 准备工作4.2 批量调用脚本4.3 运行脚本并查看结…

C++工厂模式的作用(工厂方法、Factory Method、Factory Pattern)

文章目录 代码示例工厂的作用1. 对象创建的封装 &#x1f3ed;2. 解耦客户端和具体类 &#x1f517;3. 统一的创建入口 &#x1f6aa;4. 隐藏实现细节 &#x1f3ad; 在这个项目中的具体体现总结 代码示例 https://gitee.com/arnold_s/my-learning-test/tree/master/20250610_…

9-C#修改任务管理的名称

C#修改任务管理的名称

Fisco Bcos学习 - 搭建第一个区块链网络

文章目录 一、前言二、环境准备三、安装依赖在 macOS 上安装依赖在 Ubuntu 上安装依赖在 CentOS 上安装依赖 四、创建操作目录并下载安装脚本五、搭建单群组 4 节点联盟链六、启动 FISCO BCOS 链七、检查进程八、检查日志输出 在数字化时代&#xff0c;区块链技术正逐渐成为推动…

可视化图解算法53:表达式求值

牛客网 面试笔试 TOP 101 1. 题目 描述 请写一个整数计算器&#xff0c;支持加减乘三种运算和括号。 数据范围&#xff1a;0≤∣s∣≤100&#xff0c;保证计算结果始终在整型范围内 要求&#xff1a;空间复杂度&#xff1a; O(n)&#xff0c;时间复杂度 O(n) 示例1 输入…

小白成长之路-Nginx配置(二)

文章目录 一、localtion配置1.匹配规则2.匹配优先级3.配置案例 二、rewrite1、 语法2、 可写入字段3 配置案例4 if 指令5.sutoindex6. nginx配置中的常用变量 三、配置Nginx状态统计1.下载vts模块2.编译nginx 提示&#xff1a;以下是本篇文章正文内容&#xff0c;下面案例可供参…

Qt的第一个程序

Qt的第一个程序 1.hello world2.使用图形化拖拽方式3.使用C代码的方式3.1.头文件3.2.setText3.3.对象树 4.设计MyLabel5.乱码问题 &#x1f31f;&#x1f31f;hello&#xff0c;各位读者大大们你们好呀&#x1f31f;&#x1f31f; &#x1f680;&#x1f680;系列专栏&#xff…

图书数据接口

基本说明&#xff1a; 接口地址&#xff1a;http://data.isbn.work/openApi/getInfoByIsbn?isbn{isbn}&appKey{appkey}返回格式&#xff1a;json请求方式&#xff1a;get请求示例&#xff1a;http://data.isbn.work/openApi/getInfoByIsbn?isbn9787513159074&appKey…

MongoDB原理

目录 一、概念 二、架构 2.1 逻辑结构 2.2 数据模型 2.3 存储引擎&#xff1a;WiredTiger 三、事务 一、概念 MongoDB是文档数据库&#xff0c;基本存储单元是 文档&#xff08;Document&#xff09;&#xff0c;以BSON格式&#xff08;一种类json的二进制形式&#xff…