Skip to content

akaiHuang/cad-intelligent-recognizer

Repository files navigation

CAD Intelligent Recognizer

Multi-Dimensional Confidence Scoring for Structural Element Recognition in CAD Files

JavaScript Three.js DXF DWG License


An intelligent CAD file parser that recognizes structural columns from DXF/DWG architectural drawings using a 6-dimension confidence scoring system. No hardcoded rules -- the recognizer adapts to different CAD standards and naming conventions.

智慧 CAD 檔案解析器 -- 從 DXF/DWG 建築圖面中識別結構柱體,採用六維度信心度評分系統。不依賴硬編碼規則,可自適應不同 CAD 標準與命名慣例。


   ┌──────────────┐         ┌──────────────┐         ┌──────────────────────────────┐
   │   DXF/DWG    │  Parse  │   Entity     │ Analyze │   6-Dimension Confidence     │
   │   CAD File   │ ──────> │   Extraction │ ──────> │   Scoring Engine             │
   │              │         │              │         │                              │
   └──────────────┘         └──────────────┘         │  ┌────────┐  ┌───────────┐  │
                                                     │  │ Layer  │  │ Size      │  │
                                                     │  │ 0.40   │  │ 0.20      │  │
                                                     │  ├────────┤  ├───────────┤  │
                                                     │  │ Shape  │  │ Closure   │  │
                                                     │  │ 0.15   │  │ 0.10      │  │
                                                     │  ├────────┤  ├───────────┤  │
                                                     │  │ Annot. │  │ Spatial   │  │
                                                     │  │ 0.30   │  │ 0.00      │  │
                                                     │  └────────┘  └───────────┘  │
                                                     └──────────────┬───────────────┘
                                                                    │
                                                     ┌──────────────▼───────────────┐
                                                     │   Classification Output      │
                                                     │                              │
                                                     │   >= 0.6  Confirmed Column   │
                                                     │   >= 0.4  Needs Review       │
                                                     │   <  0.4  Rejected           │
                                                     └──────────────────────────────┘

About

CAD Intelligent Recognizer 是一個 CAD 圖面智慧辨識引擎,針對結構元素(如柱體)提供自動識別與多維度信心分數評估。適合結構工程與建設數位化流程,用於從 DXF/DWG 圖資抽取可計算的幾何與構件資料。

About (EN)

CAD Intelligent Recognizer extracts structural elements from CAD drawings and scores recognition confidence across multiple dimensions. It is aimed at construction digitization workflows that need computable geometry from DXF/DWG assets.

📋 Quick Summary

🏗️ 這是一款智慧 CAD 建築圖面識別引擎,能從 DXF/DWG 格式的建築設計圖中自動識別結構柱體。🎯 核心技術是獨創的六維度信心度評分系統,融合圖層名稱匹配(權重 0.40)、尺寸約束驗證(0.20)、形狀特徵分析(0.15)、封閉性驗證(0.10)、文字標註匹配(0.30)和空間上下文分析,產出三級分類結果:確認、待審核、排除。🔍 最大亮點是不依賴硬編碼規則——透過 regex 模式匹配和 JSON 配置檔案,可自適應 LCz9-COLS-COL 等各種 CAD 命名慣例,輕鬆適配不同設計院標準。📐 DXF 解析器完整支援 LINE、LWPOLYLINE、POLYLINE、CIRCLE、ARC、TEXT 六種實體類型。🖥️ 附帶瀏覽器端視覺化測試介面,使用 Three.js 彩色渲染識別結果,方便即時調試。📁 內含真實建築圖面測試檔案(DXF/DWG)。適合結構工程 AI、建築資訊模型化(BIM)、CAD 自動化處理領域的開發者參考。


✨ Highlights / 技術亮點

Domain Detail
CAD File Parsing 完整 DXF 格式解析器,支援 LINE、LWPOLYLINE、POLYLINE、CIRCLE、ARC、TEXT 六種實體類型
6-Dimension Scoring 圖層名稱 (0.40) + 尺寸約束 (0.20) + 形狀特徵 (0.15) + 封閉性 (0.10) + 文字標註 (0.30) + 空間上下文 (可選)
Universal Recognition 不依賴特定圖層命名,透過 regex 模式匹配支援 LCz9-COLS-COL 等多種命名慣例
Configurable Rules JSON 配置檔案驅動所有識別規則,無需修改程式碼即可適配不同 CAD 標準
Visual Testing 瀏覽器端測試介面,彩色視覺化識別結果,即時調試與驗證
Real CAD Samples 內含真實 DXF/DWG 建築圖面測試檔案

🏗️ Architecture / 系統架構

Recognition Pipeline / 識別流程

DXF/DWG File Input
       │
       ├── DXF Parser (dwg-importer-v2.js)
       │     ├── ENTITIES section extraction        解析 ENTITIES 區段
       │     ├── Entity type classification         實體類型分類
       │     ├── Coordinate & property extraction   座標與屬性擷取
       │     ├── Layer name mapping                 圖層名稱對映
       │     └── Color index resolution             顏色索引解析
       │
       ├── Closed Shape Detection
       │     ├── LWPOLYLINE (isClosed flag)         封閉多段線
       │     ├── CIRCLE entities                    圓形實體
       │     └── LINE combination analysis          線段組合分析
       │
       ├── 6-Dimension Feature Analysis
       │     ├── [1] Layer Name Matching             圖層名稱匹配 (weight: 0.40)
       │     │        primary: LC, z9-COL, Column, COL
       │     │        secondary: S-COL, A-COL, 柱
       │     │        fallback: 0, Default
       │     │
       │     ├── [2] Size Constraints                尺寸約束驗證 (weight: 0.20)
       │     │        width/depth: 10-200mm
       │     │        area: 100-40000mm^2
       │     │        aspect ratio: square/rectangular
       │     │
       │     ├── [3] Shape Analysis                  形狀特徵分析 (weight: 0.15)
       │     │        rectangle: 4 vertices, right angles
       │     │        circle: radius 10-100mm
       │     │
       │     ├── [4] Closure Verification            封閉性驗證 (weight: 0.10)
       │     │        tolerance: 5cm
       │     │
       │     ├── [5] Annotation Matching             文字標註匹配 (weight: 0.30)
       │     │        patterns: C1, 柱-1, Column_1, KZ1
       │     │        search radius: 500cm
       │     │        size extraction: (60x60) format
       │     │
       │     └── [6] Spatial Context (optional)      空間上下文 (weight: 0.00)
       │              grid proximity, repetitive patterns
       │
       └── Confidence Classification
             ├── >= 0.6  Confirmed / 確認為柱子
             ├── >= 0.4  Uncertain / 需人工確認
             └── <  0.4  Rejected / 排除

Confidence Scoring Formula / 信心度計算公式

confidence = (layer_score    x 0.40)
           + (size_score     x 0.20)
           + (shape_score    x 0.15)
           + (closure_score  x 0.10)
           + (annotation_score x 0.30)
           + (spatial_score  x 0.00)

where each dimension_score is in [0.0, 1.0]

權重總和刻意大於 1.0,允許多維度特徵強化疊加。例如一個在柱子圖層上、尺寸符合、且有標註的元素,可以獲得極高信心度。


📁 Project Structure / 專案結構

cad-intelligent-recognizer/
├── dwg-importer-v2.js                  # DXF parser (955 lines) -- full ENTITIES section parser
├── universal-column-recognizer.js      # Recognition engine (512 lines) -- 6-dimension scoring
├── column-recognition-config.json      # Rule configuration -- all thresholds & weights
├── column-recognition-rules.md         # Rule documentation / 識別規則說明文件
├── dwg-importer.js                     # Legacy DXF parser (v1) / 舊版解析器
├── test-universal-recognition.html     # Full recognition test UI / 完整識別測試介面
├── test-simple.html                    # Simplified test page / 簡化測試頁面
├── test-color.html                     # Color rendering test / 彩色渲染測試
├── 03f-cbs.dxf                         # Sample DXF file / DXF 測試檔案
├── example.dxf                         # Example DXF file / DXF 範例檔案
├── ALL-PLAN.dwg                        # Full architectural plan (DWG) / 完整建築平面圖
├── ALL-PLAN-S.dwg                      # Structural plan (DWG) / 結構平面圖
├── 剖立面.dwg                           # Section/elevation drawing / 剖立面圖
├── DWG_IMPORT_GUIDE.md                 # DWG import guide / DWG 匯入指南
└── development-notes.md                # Development notes / 開發筆記

🛠️ Tech Stack / 技術棧

Layer Technology
CAD Parsing Custom DXF parser -- LINE, LWPOLYLINE, POLYLINE, CIRCLE, ARC, TEXT entity support
Recognition Engine Multi-feature fusion with weighted confidence scoring
Configuration JSON-driven rule system -- regex patterns, size constraints, weight tuning
Visualization Three.js -- 3D rendering of parsed CAD entities with color-coded recognition results
Testing Browser-based HTML test suites with interactive debugging
CAD Formats DXF (native parsing), DWG (with conversion pipeline)

🔑 Key Components / 核心模組詳解

DXF Parser (dwg-importer-v2.js -- 955 lines)

  • ENTITIES section parser -- 逐行解析 DXF 格式,提取 group code / value 對
  • Six entity types -- LINE (線段)、LWPOLYLINE (輕量多段線)、POLYLINE (多段線)、CIRCLE (圓)、ARC (弧)、TEXT (文字)
  • Property extraction -- 座標點、圖層名稱、顏色索引、封閉標記、半徑、文字內容
  • Robust parsing -- 自動處理 SECTION/ENDSEC 邊界、跳過未知實體類型

Universal Column Recognizer (universal-column-recognizer.js -- 512 lines)

  • Layer name matching -- 三級優先:primary (LC, COL) > secondary (S-COL, 柱) > fallback (Default),使用 regex 模式匹配
  • Size constraint validation -- 寬度/深度 10-200mm,面積 100-40000mm^2,長寬比分析(方形 0.8-1.2,矩形 1.5-3.0)
  • Shape analysis -- 矩形柱:4 頂點 + 直角檢測 + 對邊平行;圓形柱:半徑範圍驗證
  • Annotation matching -- 500cm 搜尋半徑內匹配 C1柱-1Column_1KZ1 等標註,並可提取 (60x60) 格式的尺寸資訊
  • Three-tier output -- confirmed (確認)、uncertain (待確認)、rejected (排除)

Configuration System (column-recognition-config.json)

完整可調的 JSON 配置,無需修改程式碼即可適配不同 CAD 標準:

{
  "columnRecognition": {
    "layers": {
      "primary":   { "patterns": ["^LC\\d*$", "^z9-COL$"], "weight": 0.4 },
      "secondary": { "patterns": ["^S-COL$", "^柱"],       "weight": 0.2 },
      "fallback":  { "patterns": ["^0$", "^Default$"],     "weight": 0.05 }
    },
    "sizeConstraints": { "minWidth": 10, "maxWidth": 200, "minArea": 100, "maxArea": 40000 },
    "thresholds":      { "confirmed": 0.6, "uncertain": 0.4 },
    "confidenceWeights": { "layer": 0.4, "size": 0.2, "shape": 0.15, "closure": 0.1, "annotation": 0.3 }
  }
}

🏁 Getting Started / 開始使用

Browser-Based Testing / 瀏覽器端測試

# Clone the repository
git clone <repo-url>
cd cad-intelligent-recognizer

# Open the test UI in your browser
# (Use a local server or VS Code Live Server for ES module support)
open test-universal-recognition.html

Loading CAD Files / 載入 CAD 檔案

  1. Open test-universal-recognition.html in browser
  2. Load one of the included sample files (03f-cbs.dxf, example.dxf)
  3. View recognition results with confidence scores and color-coded visualization
  4. Adjust column-recognition-config.json to tune recognition parameters

Integrating in Your Project / 整合到你的專案

import { DXFParser } from './dwg-importer-v2.js';
import { UniversalColumnRecognizer } from './universal-column-recognizer.js';
import config from './column-recognition-config.json';

// Parse DXF file
const parser = new DXFParser();
const entities = parser.parse(dxfContent);

// Recognize columns
const recognizer = new UniversalColumnRecognizer(config);
const results = recognizer.recognizeColumns(entities.entities, entities.textEntities);

console.log(`Confirmed columns: ${results.confirmed.length}`);
console.log(`Needs review: ${results.uncertain.length}`);
console.log(`Rejected: ${results.rejected.length}`);

📐 Supported CAD Elements / 支援的 CAD 元素

Entity Type Description Recognition Role
LWPOLYLINE Lightweight polyline / 輕量多段線 Primary column shape detection (矩形柱主要來源)
CIRCLE Circle entity / 圓形 Circular column detection (圓形柱識別)
LINE Single line segment / 線段 Combined closure analysis (組合封閉分析)
POLYLINE Standard polyline / 標準多段線 Complex shape detection (複雜形狀識別)
ARC Arc segment / 弧線 Curved element parsing (弧形元素解析)
TEXT Text annotation / 文字標註 Column label matching (柱號標註匹配)

🏷️ Category / 分類

Crawler & Intelligent Classification / 爬蟲與智能分類

本專案展示了結構工程 AI 的核心能力 -- 從工業標準 CAD 檔案中智慧識別結構元素。六維度信心度評分系統融合了圖層語義、幾何特徵、空間關係和文字標註,實現了不依賴硬編碼規則的通用柱體識別,可適配不同設計院和 CAD 軟體的命名慣例。


Built with JavaScript, Three.js, and Multi-Dimensional Confidence Scoring

用 JavaScript、Three.js 和多維度信心度評分打造的智慧 CAD 識別引擎

About

CAD drawing recognizer for extracting structural elements from DXF/DWG with multi-dimensional confidence scoring.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors