Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to get the center point of the bounding box of all elements? #441

Closed
uyoufu opened this issue Sep 13, 2022 · 4 comments
Closed

How to get the center point of the bounding box of all elements? #441

uyoufu opened this issue Sep 13, 2022 · 4 comments

Comments

@uyoufu
Copy link

uyoufu commented Sep 13, 2022

Hello,xBIM team!
Is there a way to calculate the bounding box of all elements and get the center point of them?

@martin1cerny
Copy link
Member

martin1cerny commented Sep 13, 2022

Yes, this is possible. You need to use our geometry engine (Xbim.Geometry nuget package) to process all the geometry. Then you will be able to get all the bounding boxes of all elements.

@uyoufu
Copy link
Author

uyoufu commented Sep 13, 2022

@martin1cerny Thanks! I have isntalled the package but I can't find a document to Introduce how to use,could you show me a example code?

@martin1cerny
Copy link
Member

You can start with this code:

Xbim3DModelContext context = new Xbim3DModelContext(model);
context.CreateContext();

var elements = model.Instances.OfType<IIfcElement>();
foreach (var element in elements)
{
    var productShapes = context.ShapeInstancesOf(element);
    var bBox = productShapes
        .Select(s => XbimRect3D.TransformBy(s.BoundingBox, s.Transformation))
        .Aggregate(XbimRect3D.Empty, (last, current) => { 
            last.Union(current); 
            return last; 
        });
}

@uyoufu
Copy link
Author

uyoufu commented Sep 14, 2022

@martin1cerny Wow, it works! Thanks very much!
The type of BoundingBox is XbimRect3D , and the method Centroid() in XbimRect3D is just what I need.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants