
IfcPlusPlus 核心API速查BuildingModel、ReaderSTEP、GeometryConverter 完全清單【免費下載鏈接】ifcplusplusIfcPlusPlus is an open source C class model, as well as a reader and writer for IFC files in STEP format. Features: Easy and efficient memory management using smart pointers. Parallel reader for very fast parsing on multi-core CPUs. Additionally, theres a simple IFC viewer application, using Qt and OpenSceneGraph. It can be used as starting point for all kinds of applications around the open building model standard IFC.項目地址: https://gitcode.com/gh_mirrors/if/ifcplusplus想快速上手 IFC 建筑模型開發本文給出 IfcPlusPlusIFC核心 API 速查清單圍繞BuildingModel、ReaderSTEP、GeometryConverter三大核心類列全了關鍵方法、文件位置與調用順序。IfcPlusPlus 是開源 C 類模型與 IFCSTEP 格式文件讀取/寫入器配合智能指針管理內存、多線程并行解析是開發開放建筑模型應用的理想起點文末附示例工程路徑照做即可跑通。一、3 個核心類一眼看懂 核心類一句話職責源碼位置BuildingModel建筑模型容器存放全部 IFC 實體IfcPlusPlus/src/ifcpp/model/BuildingModel.hReaderSTEP讀取 IFC STEP 文件多核并行、速度快IfcPlusPlus/src/ifcpp/reader/ReaderSTEP.hGeometryConverter把 IFC 幾何表示轉換為 Carve 網格IfcPlusPlus/src/ifcpp/geometry/GeometryConverter.h輔助類同樣值得收藏WriterSTEP把模型寫回 IFC 文件IfcPlusPlus/src/ifcpp/writer/WriterSTEP.hStatusCallback統一的消息/進度/取消回調基類IfcPlusPlus/src/ifcpp/model/StatusCallback.h三個核心類都繼承自它GeometrySettings幾何轉換參數如圓周頂點數、布爾運算 epsilonIfcPlusPlus/src/ifcpp/geometry/GeometrySettings.h二、BuildingModel 類速查模型實體全在這BuildingModel是整個應用的數據中樞內部用std::unordered_mapint, shared_ptrBuildingEntity按 STEP tag 存放所有實體。2.1 實體增刪BuildingModel.h 第 42–47 行方法作用getMapIfcEntities()獲取實體映射表遍歷模型最快入口insertEntity(e, overwrite, warn)插入實體可覆蓋已有 tagremoveEntity(e)/removeEntity(tag)按對象或 tag 刪除實體removeUnreferencedEntities()清理無引用實體省內存getLowestUnusedEntityTagSlow()找最小可用 tag填補空隙getNextUnusedEntityTagFast()快速取下一個可用 tag2.2 模型信息與單位getIfcProject()拿到根實體 IfcProjectgetIfcSchemaVersionOfLoadedFile()已加載文件的 IFC 版本IFC2X3/IFC4/IFC4X3…getIfcSchemaVersionCurrent()庫當前實現的最高 IFC 版本getUnitConverter()單位換算器毫米/米等幾何轉換前務必確認getFileName()/getFileHeader()/getFileDescription()文件元信息2.3 加載控制resolveInverseAttributes()/unsetInverseAttributes()解析/釋放反向引用cancelLoading()/isLoadingCancelled()取消正在進行的加載配合 GUI 的取消按鈕 小技巧實體類定義在IfcPlusPlus/src/ifcpp/IFC4X3/include/下每個 IFC 實體一個頭文件如IfcWall.h、IfcProject.h屬性直接以m_Name、m_GlobalId等成員變量訪問非常直觀。三、ReaderSTEP 類速查最快讀取 IFC 文件ReaderSTEP封裝了 STEP 文件解析支持從文件或直接流讀取內部用多線程并行解析大文件也能快速完成。方法作用loadModelFromFile(filePath, model)一步到位打開文件→解析→實體填入模型最常用loadModelFromStream(content, pos, model)從內存流加載適合網絡/嵌入場景readHeader(in, model)只讀文件頭schema 版本、單位、文件名readData(in, end, model)解析實體數據段readSingleStepLine(line, obj)解析單行 STEP 語句底層接口3.1 消息回調必接一步ReaderSTEP繼承自StatusCallback調用setMessageCallBack(...)注冊回調后解析進度MESSAGE_TYPE_PROGRESS_VALUE、警告、錯誤都會推給你——這是實現進度條和錯誤日志的關鍵。四、GeometryConverter 類速查IFC 幾何轉網格GeometryConverter是模型→可渲染網格的轉換器接收BuildingModel后調用convertGeometry()內部并行處理每個 IfcProduct輸出ProductShapeData含網格、變換矩陣、子產品樹。4.1 核心方法方法作用convertGeometry()主入口多線程轉換全部幾何getShapeInputData()結果獲取GUID→ProductShapeData扁平映射setModel(model)換綁另一個模型setCsgEps(eps)設置 CSG 布爾運算容差示例常用 1.5e-9resetModel()/clearInputCache()釋放緩存、清理內存getBuildingModel()/getGeomSettings()取回模型與幾何設置4.2 內部子轉換器清單GeometryConverter組合了RepresentationConverter后者又編排了一整套子轉換器都在IfcPlusPlus/src/ifcpp/geometry/下PointConverter點坐標PointConverter.hCurveConverter曲線/樣條CurveConverter.hPlacementConverter放置與變換矩陣PlacementConverter.hFaceConverter面/殼三角化FaceConverter.hSolidModelConverter實體、布爾運算SolidModelConverter.hProfileCache輪廓緩存提升重復截面性能ProfileCache.hCSG_Adapter布爾切減如墻體開洞CSG_Adapter.h 性能調參GeometrySettings中setNumVerticesPerCircle()控制圓弧細分默認 14頂點越多越圓滑、越耗內存。五、WriterSTEP三行寫回 IFC 文件需要導出模型時WriterSTEP非常輕量shared_ptrWriterSTEP writer(new WriterSTEP()); writer-writeModelToStream(stream, ifc_model);m_writeNumberPrecision可調整輸出小數精度默認 15。六、典型調用順序4 步跑通全流程 ?建模型與讀取器new BuildingModel()new ReaderSTEP()給兩者注冊setMessageCallBack加載文件step_reader-loadModelFromFile(xx.ifc, ifc_model)轉換幾何new GeometryConverter(ifc_model)→ 配置setCsgEps→convertGeometry()取結果getShapeInputData()拿扁平網格映射或從ifc_model-getIfcProject()出發用反向屬性如m_IsDecomposedBy_inverse遍歷空間樹 完整可運行的參考實現在examples/LoadFileExample/src/main.cpp含樹遍歷與網格遍歷演示想從零創建墻體的看examples/CreateIfcWallAndWriteFile/src/main.cpp帶 QtOpenSceneGraph 的 3D 查看器示例在examples/SimpleViewerExampleQt/可直接作為你應用的起點。七、新手避坑清單單位不一致轉換前先查getUnitConverter()IFC 常用毫米幾何輸出按米縮放忘記接回調不注冊setMessageCallBack時進度與錯誤信息會丟失Debug 下打印到控制臺GUID 重復convertGeometry()會自動檢測重復 GUID 并追加后綴注意看回調里的錯誤消息大文件內存轉換完成后及時clearInputCache()可顯著降低駐留內存取消加載UI 取消時調用ifc_model-cancelLoading()讀取器會協作退出掌握這份 BuildingModel、ReaderSTEP、GeometryConverter 速查清單你就能獨立完成 IFC 文件讀取、幾何轉換與導出的全鏈路開發。動手從examples/LoadFileExample開始是最快的學習路徑【免費下載鏈接】ifcplusplusIfcPlusPlus is an open source C class model, as well as a reader and writer for IFC files in STEP format. Features: Easy and efficient memory management using smart pointers. Parallel reader for very fast parsing on multi-core CPUs. Additionally, theres a simple IFC viewer application, using Qt and OpenSceneGraph. It can be used as starting point for all kinds of applications around the open building model standard IFC.項目地址: https://gitcode.com/gh_mirrors/if/ifcplusplus創作聲明:本文部分內容由AI輔助生成(AIGC),僅供參考