我必须在 JAVA 中提取 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();
}
Run Code Online (Sandbox Code Playgroud)
这正确加载了 ifc 文件。但我不知道如何处理这些信息。
我也尝试使用IfcOpenShell,但提供的 jar 容器也没有工作。目前我尝试自己构建 IfcOpenShell。
我有点绝望,因为一切都没有记录,我真的需要加载和解析 ifc 几何。
根据您想对几何体做什么、您想深入研究 IFC 标准的深度以及您的解决方案所需的性能,您有两种不同的选择:
如果您选择第一个选项,则必须深入研究IFC 模式。你只会对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();
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
但是,有很多不同的 GeometryRepresentations,您必须涵盖它们,可能需要自己进行三角测量和其他操作。我已经展示了一个特殊情况并做出了很多断言。而且您必须摆弄坐标变换,因为它们可能会递归嵌套。
如果您选择第二个选项,我所知道的几何引擎都是用 C/C++ 编写的(Ifcopenshell、RDF IfcEngine),因此您必须处理本机库集成。IFCOpenshell 提供的 jar 包旨在用作 Bimserver 插件。如果没有相应的依赖项,您就无法使用它。但是,您可以从此包中获取本机二进制文件。为了使用引擎,您可以从 Bimserver插件源中获得一些灵感。您将要使用的关键本机方法是
boolean setIfcData(byte[] ifc) 解析ifc数据IfcGeomObject getGeometry() 依次访问提取的几何图形。