xBimTeam / XbimEssentials

A .NET library to work with data in the IFC format. This is the core component of the Xbim Toolkit
https://xbimteam.github.io/
Other
476 stars 171 forks source link

Detecting Clashes of two elements #341

Open Kilian941 opened 4 years ago

Kilian941 commented 4 years ago

Hello,

I am currently trying to compare the geometry of two objects and identify whether they overlap or not. I have not really used xBIM for processing geometry so I am not too familiar with the possibilites. Is there a method implemented that compares the shape and returns a result?

Simplified example using pseudo code

The following example illistrates what I am looking for:

using (var model = IfcStore.Open("file.ifc"))
{
    XbimShapeGeometry wall,slab;
    if(clash(wall,slab)) return true;
    return false;

}

public bool clash(XbimShapeGeometry shape1, XbimShapeGeometry shape2)
{
    // Write code here
    // I could generate TriangulatedMeshes and run inside/outside tests. But I hope there is a quicker solution on that.
}

Expected behavior:

Ideally I want to compare two elemnts. If there is a clas I aim to automatically generate a BCF issue. I have already implemented the BCF export. However, I somehow need to identify the actal clashes.

Thanks a lot for answering!

Kilian

martin1cerny commented 4 years ago

This is a non-trivial task. You can use pre-computed bounding boxes for fast filtering but than you will have to do a complete comparison on candidates. Also, don't forget to use placement transformations as well as shapes.

BalintBende commented 3 years ago

Hello @martin1cerny

Maybe a related topic, you mentioned: "You can use pre-computed bounding boxes". Is it reachable from XbimEssentials or is it part of the XbimGeometry? I'm asking this because we are using .net5 application (builded on linux) and trying to calculate the absolute coordinates of the elements, however, at some point the calculation becomes very complex. For accurate positions, the summarizing of local placements are not enough (especially member pos -> storey pos -> building pos -> site pos), and local positions of product definition shape are needed to be taken into consideration. Easier approach would be getting the element bounding boxes. Or if you had a better solution, i would be very pleased.

So now this is my solution, but it soon proved that in many cases Ifc elements' representations contain local placements as well

public Dictionary<string, double[]> getElementPlacements(){
      var result = new Dictionary<string, double[]>();
      foreach (var element in elements) {
        var globalPlacement = new double[3];
        var locPlacement = (IIfcLocalPlacement) element.ObjectPlacement;
        var relPlacement = (IIfcLocalPlacement) locPlacement.PlacementRelTo;
        while (locPlacement != null) {
          var location =
            ((IIfcPlacement) locPlacement.RelativePlacement).Location;
          globalPlacement[0] += location.X;
          globalPlacement[1] += location.Y;
          globalPlacement[2] += location.Z;
          locPlacement = relPlacement;
          if(relPlacement!=null)
            relPlacement = (IIfcLocalPlacement) relPlacement.PlacementRelTo!;
        }
        result[element.GlobalId.ToString()] = globalPlacement;
      }
      return result;
    }

Cheers, Balint

andyward commented 3 years ago

I think you'll need XbimGeometry before computing the Bounding Box as it's derived from the Representation Geometry. Appreciate that may rule out use on Linux as things stand.

If you're looking at clash detection I answered a question on SO that may help https://stackoverflow.com/a/63018278/5168875