error in calculating the shape volume

I used the below code to get the shape volume:

GProp_GProps volumeProps;
BRepGProp::VolumeProperties(m_shape, volumeProps);
Standard_Real v = volumeProps.Mass();

However, the result is a minus, "-1306".

I guess it's due to the "m_shape" I input, but I don't know what's wrong with it.

Can anyone help me out how to fix it?

Thanks very much.

Dmitrii Pasukhin's picture

Hello, the reason can be negative scale factor. For analyzing we need to have model to check.

Best regards, Dmitrii.

Boqing Dong's picture

Dear Dmitrii,

I'm afraid I cannot provide you the model file, as the model in question was built out of a filed model.

The reason of rebuilding it myself is that I want a closed shape (which is more suitable for volume calculation) and the code is here:
=================================================================
BRepBuilderAPI_Sewing sewing;
sewing.SetTolerance(1e-3);
sewing.Add(shape);
sewing.Perform();
TopoDS_Shape sewedShape = sewing.SewedShape();

BRepBuilderAPI_MakeSolid makeSolid;
for (TopExp_Explorer ex(sewedShape, TopAbs_SHELL); ex.More(); ex.Next()) {
TopoDS_Shell shell = TopoDS::Shell(ex.Current());
makeSolid.Add(shell);
}

if (!makeSolid.IsDone()) {
// Failed to make a solid
std::cout << "Failed to make a solid." << std::endl;
return false;
}

TopoDS_Shape m_shape = makeSolid.Shape();
=================================================================

So when I used m_shape for volume calculation, I got a minus value.

Boqing Dong's picture

Dear Dmitrii,

Something relevant to add here.

I also tried to write the m_shape to a .STP file and then read the m_shape again from the file.
To my surprise, this time the newly-loaded m_shape yielded a positive value, with the same absolute value as the minus one.

This could be a workaround but it's unacceptable, as the writing and the re-loading is very time-consuming.

Is it possible to figure out what's wrong with my building the shape?

Thanks.

Dmitrii Pasukhin's picture

Probably Export helps to avoid some problems.

Yes, there is way to check model and Shape fix. I will write a sample a little later. But it is not guarantee to help in your case. Could you share additional occt version?

Best regards, Dmitrii.

Boqing Dong's picture

Dear Dmitrii,

Thank you very much.

The version of OCCT is OpenCASCADE-7.7.0-vc14-64.

And I also attached the original model file for your reference, which is an IGS file.

Attachments: