Calculate X,Y,Z,Area,Volume
Hello All I'm using c# console app to generate wexbim and in the same time, it create some "props" file, extracting properties etc. into that txt file. Now I have idea to generate also X,Y,Z,Area and Volume for each object. Is there ready solution for this? Here is very simple example which does not work 100% correctly, because it should convert units etc.
if (!processedProductLabels.Contains(product.EntityLabel))
{
var context = new Xbim3DModelContext(model);
var shapeInstances = context.ShapeInstances().Where(s => s.IfcProductLabel == product.EntityLabel);
var boundingBox = shapeInstances.Select(s => s.BoundingBox).FirstOrDefault();
if (!boundingBox.IsEmpty)
{
var sizeX = boundingBox.SizeX;
var sizeY = boundingBox.SizeY;
var sizeZ = boundingBox.SizeZ;
var volume = sizeX * sizeY * sizeZ;
var surfaceArea = 2 * (sizeX * sizeY + sizeX * sizeZ + sizeY * sizeZ);
propertyFile.WriteLine($"#{product.EntityLabel} = DIMENSIONS|");
propertyFile.WriteLine($"#{product.EntityLabel} = |Length = {sizeX:F2} m|Width = {sizeY:F2} m|Height = {sizeZ:F2} m|Volume = {volume:F2} m3|Area = {surfaceArea:F2} m2|");
}
processedProductLabels.Add(product.EntityLabel);
}
Thanks
The Geometry Engine supports calculating volumes from closed solid objects. But things like dimensions and Areas are actually pretty complex to calculate reliably since they can be subjective / arbitrary, especially when deriving the information from Geometry. It's really why we have property sets and things like IfcDoorPanelProperties
Worth noting your code above is using the BoundingBox dimensions of the first shape representing the product. This is clearly a simplification of what may be a complex object (consider what the bounding box of a pitched roof or a complex object like a light fixture may look like when converted to a cube) - but also this first shape may not be anything like representative of the whole object's size. (Example: something like a Door is often composed of many shapes. The first shape of an IfcDoor's representation might be a glazing pane/window, or the door's lock set, rather than the panel or frame.) You need to consider the union of all shapes really.
Equally on dimensions, the X dimension of a door may not be guaranteed to be it's width. It could just as well be it's depth or even height. Bottom line - it's not easy to do this generically with a reliable outcome.
I see. With the other words, mission impossible 😒
I would say it's all possible at some level of fidelity but likely to be near impossible to get right perfectly all the time for all inputs. You can probably get a decent set of results once you've handled some edge cases.