Connecting faces: How declaring shared edges?

Hello, I have a question how to create a valid shell from triangle faces. I produce the triangles with BRepBuilderAPI_MakePolygon triangleMaker and add vertex. My shell is a strip of triangles (each triangle after the first shares an edge with the preceding triangle).

Then I use BRep_Builder shellMaker.Add(casShell,casTriangle) to add the triangles faces to the shell. But is this correct? Because I wonder if the shared edge is recognized as this? Do I have to make a sewing also?

And how can I check that my produced trianglestrip is like I want it to be, especially that is a strip and not something other. I would like to check the number of shared edges, because I know by the number of triangles how many shared edges the strip must have. Can anybody tell me how I can check for shared edges?

Sorry for so many questions!
Regard Simon

samscore's picture

I tried the BRepOffsetAPI_MakeFilling fillingMaker;

TopoDS_Edge edge12 = BRepBuilderAPI_MakeEdge(gp_Pnt(10,10,0),gp_Pnt(10,20,0));
TopoDS_Edge edge23 = BRepBuilderAPI_MakeEdge(gp_Pnt(10,20,0),gp_Pnt(20,20,0));
TopoDS_Edge edge36 = BRepBuilderAPI_MakeEdge(gp_Pnt(20,20,0),gp_Pnt(20,10,0));
TopoDS_Edge edge34 = BRepBuilderAPI_MakeEdge(gp_Pnt(20,20,0),gp_Pnt(40,25,10));
TopoDS_Edge edge45 = BRepBuilderAPI_MakeEdge(gp_Pnt(40,25,10),gp_Pnt(40,15,10));
TopoDS_Edge edge56 = BRepBuilderAPI_MakeEdge(gp_Pnt(40,15,10),gp_Pnt(20,10,0));
TopoDS_Edge edge61 = BRepBuilderAPI_MakeEdge(gp_Pnt(20,10,0),gp_Pnt(10,10,0));


But the produces face (I want a shell) is not what I want->

I need a simple planar surface. Can anybody tell my how I can produce a flat surface with these edges?


Paul Jimenez's picture

To have more control, you should use the BRepBuilderAPI_Make* family to create the Vertices, Edges, Wires and Faces. Just be sure to use the same Vertices and Edges when they are indeed, well, the same. Then, you can put all Faces together to form a Shell using BRep_Builder. Sewing is another way to achieve it, but I prefer to have more control on the whole process.

samscore's picture

I tried to model my shell from ground up by producing vertices, edges and faces. But if I understand your post, my failure was to not save the shared edges and use them again when I produce the next face?

Thanks a lot!

Paul Jimenez's picture

Yup. If a Vertex or Edge is in the same position as another one, then you should use the previously created one, otherwise you will obtain Vertices and Edges which are in the same place, yet they are different instances. For them to be shared, they must be the same instance.

samscore's picture

Hello Paul!
Thanks for your advice. I have successfully created my desired shell.
And if I call BRepAlgo::IsValid(casShell) is returns true. Very nice.

If I use ShapeAnalysis_Shell to get the free edges 4 edges are displayed (see image). On the other hand, I get strange values from ShapeAnalysis_ShapeContents: NbEdges = 6, NbFreeEdges = 0 ?, NbSharedEdges = 5 ? I expected 4 free edges and 2 shared?

my code:

gp_Pnt pointA(100,200,0);
gp_Pnt pointB(200,600,0);
gp_Pnt pointC(200,200,0);
gp_Pnt pointD(300,600,0);

TopoDS_Vertex vertexA = BRepBuilderAPI_MakeVertex(pointA);
TopoDS_Vertex vertexB = BRepBuilderAPI_MakeVertex(pointB);
TopoDS_Vertex vertexC = BRepBuilderAPI_MakeVertex(pointC);
TopoDS_Vertex vertexD = BRepBuilderAPI_MakeVertex(pointD);

TopoDS_Edge edgeAB = BRepBuilderAPI_MakeEdge(vertexA,vertexB);
TopoDS_Edge edgeBC = BRepBuilderAPI_MakeEdge(vertexB,vertexC);
TopoDS_Edge edgeCA = BRepBuilderAPI_MakeEdge(vertexC,vertexA);

TopoDS_Edge edgeBD = BRepBuilderAPI_MakeEdge(vertexB,vertexD);
TopoDS_Edge edgeDC = BRepBuilderAPI_MakeEdge(vertexD,vertexC);

BRepBuilderAPI_MakeWire wireMaker1;


TopoDS_Wire wire1 = wireMaker1.Wire();
TopoDS_Face casFace1 = BRepBuilderAPI_MakeFace(wire1,Standard_True);

BRepBuilderAPI_MakeWire wireMaker2;


TopoDS_Wire wire2 = wireMaker2.Wire();
TopoDS_Face casFace2 = BRepBuilderAPI_MakeFace(wire2,Standard_False);

BRep_Builder shellMaker;
TopoDS_Shell casShell;


Standard_Boolean isShapeValid = BRepAlgo::IsValid(casShell); // returns true

TopoDS_Compound freeEdges;
ShapeAnalysis_Shell sas;

if(sas.HasBadEdges()) {
TopoDS_Compound badEdges = sas.BadEdges();
if(sas.HasFreeEdges()) {
freeEdges = sas.FreeEdges(); //see image 1, the outer 4 edges (ok)

ShapeAnalysis_ShapeContents safc;
int edgeCount = safc.NbEdges(); //6
int freeEdgeCount = safc.NbFreeEdges(); // 0 ?
int sharedEdgeCount = safc.NbSharedEdges(); 5 ?
int sfEdgeCount = safc.NbSharedFreeEdges(); 0

Paul Jimenez's picture

I have no idea what kind of information ShapeAnalysis_ShapeContents actually gathers. There is no documentation about it either. Maybe it's not doing what you expect.

To get information about shared edges I use plain old TopExp::MapShapesAndAncestors. Mapping Edges to Faces is a common choice for me. If you iterate over the container and check the Extent of each list of Faces, you should get the information you want (number of Faces that contain the current Edge).

samscore's picture

I will try TopExp::MapShapesAndAncestors. Thanks a lot for your assistance - now I can work on another area of my construction site...