Question

I have to extract the geometry of a ifc file in JAVA. My problem is, that i don't know how to do it.

I tried to use openifctools but the documentation is really bad. For now i have the ifc file loaded, but i cannot get the geometry out of the model.

Does anyone have experience with ifc model loading?

Thanks in advance.

EDIT: This is what I've done so far

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();
}

This correctly loads the ifc file. But I don't know what to do with this information.

I also tried to use IfcOpenShell but the provided jar container hadn't worked either. At the moment I try to build IfcOpenShell by myself.

I'm kinda desperate because everything is very undocumented and I really need to load and parse the ifc geometry.

Was it helpful?

Solution

Depending on what you want to do with the geometry, how deep you want to delve into the IFC standard and what performance you need for your solution you have two different options:

  1. Extract the implicit geometry on your own
  2. Use an external geometry engine

If you go for the first option, you'd have to study the IFC schema intensively. You would only be interested in IFCProducts, because only those can have geometry. Using OpenIfcTools you could do something like:

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();
            }
        }
    }
}

However, there are a lot of different GeometryRepresentations, which you'd have to cover, probably doing triangulation and stuff on your own. I've shown one special case and made a lot of assertions. And you'd have to fiddle with coordinate transformations, because these may be nested recursively.

If you go for the second option the geometry engines I know are all written in C/C++ (Ifcopenshell, RDF IfcEngine), so you'd have to cope with native library integration. The jar package provided with IFCOpenshell is intended to be used as a Bimserver plugin. Those you can't use it without the respective dependencies. However you can grab the native binaries from this package. In order to use the engine you can draw some inspiration from the Bimserver plugin source. The key native methods you're gonna use are

  • boolean setIfcData(byte[] ifc) to parse the ifc data
  • IfcGeomObject getGeometry() to access the extracted geometry successively.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top