Volume

Hi all,

i import a step-file and have to compute the volume of the whole object. Can i do that with OCC ?

thanks,

best regards,

---------
Juri

Rob Bachrach's picture

Look at BRepGProp::VolumeProperties
The resulting Mass should be the volume of your shape.

juri's picture

thanks for your help. i use that code

----------------------------------------
GProp_GProps System;

myAISContext->InitCurrent();
TopoDS_Shape current_shape = myAISContext->SelectedShape();

BRepGProp::VolumeProperties(current_shape, System);
Standard_Real vol = System.Mass();

-------------------------------------------------------

but i always get the wrong value. I dont know why?

Rob Bachrach's picture

I don't know why either. Two possibilities come to mind:
1) Maybe you are just not thinking in terms of the right units.
The volume will be in mm^3.
2) Maybe your shape contains some surfaces that are visible but
are never defined to be a solid. VolumeProperties only
takes solid geometries into account.

Rob

juri's picture

If i use the function currentshape.ShapeType(), i always get TopAbs_FACE as result. But why can i compute the volume of a face???

Is that the error? Should i first constuct a solid? but how?

Rob Bachrach's picture

Cascade can compute the volume of a face, but that volume should be 0.

It is entirely possible that the system you used to produce the STEP
file only generated trimmed surfaces (which became faces) as opposed
to solids. You may want to check if there is an option to create
solids in your source system. Most 3D solid modelers used in CAD
systems allow this as an option. When importing a STEP file with
STEPControl_Reader, I use the OneShape function to get it as a single
shape. This usually gives me a single solid or a compound of solids.
My STEP files usually come from Pro/ENGINEER as solid geometry.

You can build solids from the faces by first making a shell and
then making a solid from the shell, but this can be a lot of work
(that is a little beyond me), because you would have to build the
connectivity yourself.

Good luck,
Rob