cili3d筆記20 正交投影3d重建筆記1

正交視圖轉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…