2013-02-25 292 views
2

我必須在JAVA中提取ifc文件的幾何圖形。我的問題是,我不知道該怎麼做。從IFC文件中提取幾何圖形

我試圖使用openifctools,但文檔非常糟糕。現在我已經加載了ifc文件,但是我無法從模型中獲取幾何圖形。

有沒有人有經驗與ifc模型加載?

在此先感謝。

編輯:這是我到目前爲止

try { 
    IfcModel ifcModel = new IfcModel(); 
    ifcModel.readStepFile(new File("my-project.ifc")); 
    Collection<IfcClass> ifcObjects = ifcModel.getIfcObjects(); 
    System.out.println(ifcObjects.iterator().next()); 
} catch (Exception e) { 
    e.printStackTrace(); 
} 

做這正確加載IFC文件。但我不知道如何處理這些信息。

我也試過使用IfcOpenShell,但提供的jar容器也沒有工作。目前我試圖自己構建IfcOpenShell。

我有點絕望,因爲一切都很無證,我真的需要加載和解析ifc幾何。

+0

我對IFC文件沒有任何經驗,但是如果這是一個普通的java問題,我可能會提供幫助。你能告訴我們你到目前爲止有什麼?加上你可能有的任何錯誤/輸出。 – mjshaw 2013-02-25 21:26:13

+0

java應該不是問題。無論如何,我編輯我的問題,並添加了一些代碼片段加載一個ifc文件到內存使用openifctools。 – AlmostBearded 2013-02-26 10:40:11

+0

對不起,我誤解了。要使用IfcModel和IfcClass,你確​​實需要API。如果沒有,請嘗試在提供自動完成功能的IDE中使用它,例如eclipse。它可能會讓您瞭解可用的方法,以便您可以推斷如何使用它。對不起,我沒有更多的幫助。 – mjshaw 2013-02-26 10:53:53

回答

3

根據你想用的幾何形狀,你想有多深鑽研IFC標準,你需要爲你解決怎樣的表現,你有兩種不同的選擇做什麼:

  1. 提取物對隱式幾何自己
  2. 使用外部幾何引擎

如果你去的第一個選項,你就必須學習IFC schema集中。你只會對IFCProducts感興趣,因爲只有那些可以有幾何。使用OpenIfcTools你可以這樣做:

Collection<IfcProduct> products = model.getCollection(IfcProduct.class); 
for(IfcProduct product: products){ 
    List<IfcRepresentation> representations = product.getRepresentation().getRepresentations(); 
    assert ! representations.isEmpty(); 
    assert representations.get(0) instanceof IfcShapeRepresentation: 
    Collection<IfcRepresentationItem> repr = representations.get(0).getItems(); 
    assert !repr.isEmpty(); 
    IfcRepresentationItem representationItem = repr.iterator().next(); 
    assert representationItem instanceof IfcFacetedBrep; 
    for(IfcFace face: ((IfcFacetedBrep)representationItem).getOuter().getCfsFaces()){ 
     for(IfcFaceBound faceBound: face.getBounds()){ 
      IfcLoop loop = faceBound.getBound(); 
      assert loop instanceof IfcPolyLoop; 
      for(IfcCartesianPoint point: ((IfcPolyLoop) loop).getPolygon()){ 
       point.getCoordinates(); 
      } 
     } 
    } 
} 

然而,也有很多不同的GeometryRepresentations,你不得不支付,可能做你自己的三角之類的東西。我已經展示了一個特例,並做了很多斷言。你不得不擺弄座標轉換,因爲它們可能是遞歸嵌套的。

如果你選擇第二個選項,我所知道的幾何引擎全部用C/C++編寫(Ifcopenshell,RDF IfcEngine),所以你必須應對本地庫集成。 IFCOpenshell提供的jar包旨在用作Bimserver插件。那些沒有各自的依賴關係就無法使用它。但是,您可以從該包中獲取本機二進制文件。爲了使用引擎,您可以從Bimserver plugin source中獲得靈感。你會使用的主要本地方法是

  • boolean setIfcData(byte[] ifc)解析IFC數據
  • IfcGeomObject getGeometry()依次訪問所提取的幾何形狀。