How to respond when negative area is acquired

Shoko

CAD practitioner
Hello.
This is my first time submitting a form. This website has always helped me.
I am a beginner in working with OpenCascade.

I used BRepGProp::SurfaceProperties to get the area of a shape, but I got negative area values.
When I get the area for each Face of the shape in TopExp_Explorer, I found that some of the areas are negative. The face direction of this face was TopAbs_FORWARD.
My question is, what is the best way to get positive values for negative areas? I would also like to know why the area is negative. Can you help me solve this problem?

Thank you in advance.
 

calciffer

Active CAD practitioner
Hi, Shoko

I'm not entirely sure what the problem might be, but it could be related to improper TopoDS_Shape modeling.
Could you please share your model and testing data with me? Additionally, it would be great if you could provide the version information for the OpenCASCADE library that you are using.

Hope we learn from each other.
 

Quaoar

Administrator
Staff member
Negative areas of faces often indicate validity problems such as improper imbrication of contours into each other. Feel free to attach an example where you encounter such an issue and we will have a look together.
 

Shoko

CAD practitioner
Thanks calciffer and Quaoar for your replies.

I apologize for the inconvenience. I can't attach the test data as I can't externalize it. I do appreciate your kind words, and I will keep them in mind.

The loaded model is a JT file, but when I checked it in the OpenCascade view, it looked like part of the Face was broken.
Does this mean that if we can fix the Face we may get the correct value for the negative area, or would you please let us know if you know how to fix the Face?
I would like to give it a try.

I am using OpenCascade version 7.6.0.
 

Quaoar

Administrator
Staff member
In Analysis Situs, try `repair` command in the Active Script window. In OpenCascade, try `ShapeFix_Shape` (you should be able to find many examples of its usage in the sources).
 

Shoko

CAD practitioner
Hello

Even using healing tools such as ShapeFix could not prevent the negative area.
Therefore, I gave up on getting the area with BRepGProp::SurfaceProperties and decided to get the area by triangulating each face and calculating the sum of the areas of the triangular elements.

I was able to create a mesh with BrepTool::Triangulation(), but I don't know how to get the node of each element. If anyone knows, please let me know.

Thank you for your reply.
 

JSlyadne

Administrator
Staff member
Hello

Even using healing tools such as ShapeFix could not prevent the negative area.
Therefore, I gave up on getting the area with BRepGProp::SurfaceProperties and decided to get the area by triangulating each face and calculating the sum of the areas of the triangular elements.

I was able to create a mesh with BrepTool::Triangulation(), but I don't know how to get the node of each element. If anyone knows, please let me know.

Thank you for your reply.
Hello Shoko,

Here it is

Code:
Handle(Poly_HArray1OfTriangle) triangles = triangulation->MapTriangleArray();
Handle(TColgp_HArray1OfPnt)    nodes     = triangulation->MapNodeArray();

for ( int elemId = triangles->Lower(); elemId <= triangles->Upper(); ++elemId )
{
    const Poly_Triangle& tri = triangles->Value(elemId);

    int n1, n2, n3;
    tri.Get(n1, n2, n3);

    gp_Pnt p1 = nodes->Value(n1);
    gp_Pnt p2 = nodes->Value(n2);
    gp_Pnt p3 = nodes->Value(n3);
    
    ...
 

Quaoar

Administrator
Staff member
Even using healing tools such as ShapeFix could not prevent the negative area.
Can you please post here an example where ShapeFix is not effective? One thing about "triangulation approach" is that potentially the triangulation algorithm might also fail on invalid faces, so it's a bit risky to rely on it.
 
Top