Calculating Volume Properties of 3D Models with OpenCASCADE
Imagine you have a solid shape and you want to calculate the volume of that shape. If you are already familiar with the Open Cascade you might know the correct approach. If you are new, don’t worry! In this article, you will find out the correct approach. I hope everyone can learn simple new things from this article.
If you follow me or have read my previous articles, you may know what is Open Cascade. Hence, I am not going to discuss that here.
The motivation behind this topic comes from a question asked in the Open Cascade forum. The question is as follows.
o, there are two different functions to calculate the volume properties in the given class and that person wants to know what is the difference between those two.
Calculate volume properties
Users can use a simple code snippet to calculate the volume of the given shape. In the previous image, that is already shown.
GProp_GProps props;
BRepGProp::VolumeProperties(shape, props, tolerance, skipShared, isTriangulation);
double mass = props.Mass();
The other function is “VolumePropertiesGK”. The usage of this function is as same as the previous one.
GProp_GProps props;
BRepGProp::VolumePropertiesGK(shape, props, tolerance, isUsespan, CCGFlag, IFlag, skipShared);
double mass = props.Mass();
The major difference between these two functions is the algorithm behind them. If you are curious about that, you can dig into this. You can easily download the source code of Open Cascade. Yes, that is free!
领英推荐
This is the file path for a given file. %source%\occt\src\BRepGProp
You can define the shape, the property holder, and the tolerance value. Basically, those are the most needed parameters. Apart from that, skipShared flag and useTriangulation flag can be enabled. If the skipShared flag is enabled the sub-shapes where the same shape is shared more than once are omitted and only consider once. If the isTriangulation flag is enabled, the triangulated shape is considered to calculate the volume properties. Otherwise, the original shape is considered. You can experiment on your own with them. But if triangulation is enabled, the calculated value has deviated from the original value.
GProp_GProps props;
BRepGProp::VolumePropertiesGK(shape, props, tolerance, isUseSpan, CGFlag, IFlag, skipShared);
double mass = props.Mass();
Here, isUseSpan flag is only valid for BSpline faces. Here the span of the surface is determined if we enabled that flag. CGFlag and IFlag are required to calculate the global properties of a solid or 3D closed region of space. Here Gauss-Kronrod integration of the double integral is used.
Suggestions
Both these functions have their own advantages and disadvantages. Based on my usage, “volumeProperties” without triangulation gives more accurate results but it takes more time than with a triangulation flag.
Similarly “VolumePropertiesGK” gives more accurate results. But I did not see much usage of that function yet. So I do not have much experience with this function. But my colleagues are using that function and according to their experience, this function gives better results than the previous one.
If you want to know more about those, you can research by yourself. Also, this is free. So you can get the source code and try to understand the implementation deeply.