How to get a solid by crossed faces.

Hi, I tried to write a function that makes a solid by some faces.

The faces given by user selection have the boundary edges are not connected to another face always. Often the 6 faces are cross like `#' symbol. This space bounded by the faces and it is closed, but I cannot to make a shell by BRepBuilderAPI_Sewing with these.
And it lose a correct shape when give a big tolerance value to the sewing API.
I want my function recognize to closed space by multiple faces and get a correct solid.
How can I get a solid by multiple faces?

The code is follows;

BRepBuilderAPI_Sewing cSewer;
cSewer.Init();
cSewer.SetTolerance(1.0);
// This function's task is make a solid by follows faces have not common edges.
TopoDS_Face f1 = BRepBuilderAPI_MakeFace(gce_MakePln(gp_Ax2(gp_Pnt(10, 0, 0), gp_Dir(1, 0, 0), gp_Dir(0, 1, 0))), 0.0, 15, 0.0, 15);
TopoDS_Face f2 = BRepBuilderAPI_MakeFace(gce_MakePln(gp_Ax2(gp_Pnt( 5, 0, 0), gp_Dir(1, 0, 0), gp_Dir(0, 1, 0))), 0.0, 15, 0.0, 15);
TopoDS_Face f3 = BRepBuilderAPI_MakeFace(gce_MakePln(gp_Ax2(gp_Pnt( 0,10, 0), gp_Dir(0, 1, 0), gp_Dir(0, 0, 1))), 0.0, 15, 0.0, 15);
TopoDS_Face f4 = BRepBuilderAPI_MakeFace(gce_MakePln(gp_Ax2(gp_Pnt( 0, 5, 0), gp_Dir(0, 1, 0), gp_Dir(0, 0, 1))), 0.0, 15, 0.0, 15);
TopoDS_Face f5 = BRepBuilderAPI_MakeFace(gce_MakePln(gp_Ax2(gp_Pnt( 0, 0,10), gp_Dir(0, 0, 1), gp_Dir(1, 0, 0))), 0.0, 15, 0.0, 15);
TopoDS_Face f6 = BRepBuilderAPI_MakeFace(gce_MakePln(gp_Ax2(gp_Pnt( 0, 0, 5), gp_Dir(0, 0, 1), gp_Dir(1, 0, 0))), 0.0, 15, 0.0, 15);
cSewer.Add(f1);
cSewer.Add(f2);
cSewer.Add(f3);
cSewer.Add(f4);
cSewer.Add(f5);
cSewer.Add(f6);
cSewer.Perform();
TopoDS_Shape aShape = cSewer.SewedShape(); // aShape has no shells!

BRepBuilderAPI_MakeSolid cMaker;
TopExp_Explorer ex(aShape, TopAbs_SHELL);
TopoDS_Solid solid;
for (; ex.More(); ex.Next()) {
TopoDS_Shell cShell = TopoDS::Shell(ex.Current());
cMaker.Add(cShell);
}
if (!cMaker.IsDone())
return 1;
TopoDS_Solid aSolid = cMaker.Solid(); // I got an empty solid.

Timo Roth's picture

Sewing can only create a solid if the faces are not crossed. So, you first have to cut your faces, so that their edges touch each other, and then do sewing.

tkocc's picture

My application calculates a volume from user selected faces that constitutes a compartment. If my application can even create solid, it can get the volume of the solid easily. But the selected faces are not always having common edges.

How can I recognize a not required part of the each face and cut it?

In the first, I tried get edges by intersect with the crossed faces each by other, but the edges are crossed (like `#' symbol) and not for make to wire.
My method is correct?

Timo Roth's picture

Maybe you could intersect the crossed edges and at the intersection points cut your edges.

But if your faces always look like the ones in the picture, it might be easier to create 3 solids by connecting always the 2 faces of the same color to form a solid. Then you could do 2 boolean common operations using BRepAlgoAPI_Common.

Pseudocode:
A, B, C, Result : Solid;
Result := A common B;
Result := Result common C;

In more complicated cases, boolean operations can be slow.

Does somebody have a better idea?

tkocc's picture

Thanks for your good idea.
But I face bad situation, the faces of a compartment are more than 6 planes, not so simple often. because there are by free user definitions.
I will try get more good idea.