XbimEssentials icon indicating copy to clipboard operation
XbimEssentials copied to clipboard

Detecting Clashes of two elements

Open Kilian941 opened this issue 4 years ago • 3 comments

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

Kilian941 avatar Jun 25 '20 13:06 Kilian941

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.

martin1cerny avatar Jun 25 '20 15:06 martin1cerny

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

BalintBende avatar Apr 01 '21 10:04 BalintBende

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

andyward avatar Apr 07 '21 15:04 andyward