OCCUtils provides a convenience function to do this:
#include <occutils/Shape.hxx> using namespace OCCUtils; TopoDS_Shape myShape = /* ... */; double volume = Shape::Volume(myShape);
In case you need to do this without OCCUtils, use
GProp_GProps gprops; BRepGProp::VolumeProperties(shape, gprops); double volume = gprops.Mass();