Creating a cylinder topology

Hi,

I tried to build a cylinder by its topological hierachy.

This is the code:

//The builder
BRep_Builder B;

// Build the vertices
TopoDS_Vertex V1, V2;
B.MakeVertex(V1, gp_Pnt(1, 0, 2), precision);
B.MakeVertex(V2, gp_Pnt(1, 0, 0), precision);

//Build the edges
TopoDS_Edge C1, C2, L1;
Handle (Geom_Line) L;
Handle (Geom_Circle) C;

// C1
C = new Geom_Circle(gp_Ax2(gp_Pnt(0,0,2),gp_Dir(0,0,1),gp_Dir(1,0,0)),1);
B.MakeEdge(C1, C, precision);
V1.Orientation(TopAbs_FORWARD);
B.Add(C1,V1);
V1.Orientation(TopAbs_REVERSED);
B.Add(C1,V1);
//Parameters
B.UpdateVertex(V1,0,C1,precision);
B.UpdateVertex(V1,2*PI,C1,precision);

// L1
L = new Geom_Line(gp_Pnt(1, 0, 0), gp_Dir(0, 0, 1));
B.MakeEdge(L1, L, precision);
V1.Orientation(TopAbs_REVERSED);
V2.Orientation(TopAbs_FORWARD);
B.Add(L1, V1);
B.Add(L1, V2);
B.UpdateVertex(V1, 2, L1, precision);
B.UpdateVertex(V2, 0, L1, precision);

// C2
C = new Geom_Circle(gp_Ax2(gp_Pnt(0,0,0),gp_Dir(0,0,1),gp_Dir(1,0,0)),1);
B.MakeEdge(C2, C, precision);
V2.Orientation(TopAbs_FORWARD);
B.Add(C2,V2);
V2.Orientation(TopAbs_REVERSED);
B.Add(C2,V2);
//Parameters
B.UpdateVertex(V2,0,C2,precision);
B.UpdateVertex(V2,2*PI,C2,precision);

// Build the wires
TopoDS_Wire W1, W2, W3;
B.MakeWire(W1);
C1.Orientation(TopAbs_REVERSED);
B.Add(W1, C1);
L1.Orientation(TopAbs_REVERSED);
B.Add(W1, L1);
C2.Orientation(TopAbs_FORWARD);
B.Add(W1, C2);
L1.Orientation(TopAbs_FORWARD);
B.Add(W1, L1);

// Build faces
TopoDS_Face CYL;

Handle (Geom_CylindricalSurface) S;
Handle (Geom2d_Line) L2d, L2d2;

//CYL
S = new Geom_CylindricalSurface(gp_Ax3(gp_Pnt(0,0,0),gp_Dir(0,0,1),gp_Dir(1,0,0)),1);
B.MakeFace(CYL,S,precision);
W1.Orientation(TopAbs_FORWARD);
L2d = new Geom2d_Line(gp_Pnt2d(0,2),gp_Dir2d(1,0));
B.UpdateEdge(C1, L2d, CYL, precision);
B.UpdateVertex(V1, 0, C1, CYL, precision);
B.UpdateVertex(V1, 2 * PI, C1, CYL, precision);

L2d = new Geom2d_Line(gp_Pnt2d(0,0),gp_Dir2d(0,1));
L2d2 = new Geom2d_Line(gp_Pnt2d(2*PI,0),gp_Dir2d(0,1));
B.UpdateEdge(L1, L2d, L2d2, CYL, precision);

L2d = new Geom2d_Line(gp_Pnt2d(0,0),gp_Dir2d(1,0));
B.UpdateEdge(C2, L2d, CYL, precision);
B.UpdateVertex(V2, 2 * PI, C1, CYL, precision);
B.UpdateVertex(V2, 0, C1, CYL, precision);

L2d = new Geom2d_Line(gp_Pnt2d(0,0),gp_Dir2d(0,1));
B.UpdateEdge(L1, L2d, CYL, precision);

B.Add(CYL, W1);

//ShapeFix_Wire sfw(W1, CYL, precision);
//sfw.FixEdgeCurves();

//Shell
TopoDS_Shell Sh;
B.MakeShell(Sh);
B.Add(Sh,CYL);

When I proof validity of the resulting shape, I got an error of the wire that is Not_Closed.
What have i done wrong or what is missing? I don't want to do the shape fix, because it is
to expensive for my task.
As you see, I also set two curves for linear edge of the cylinder.

Rob Bachrach's picture

I don't think you are bounding the cylindrical surface properly. It needs to be bound with the two straight lines and the two circles (top and bottom). Your best bet to get the proper topological structure is to use the DRAWEXE program to see what is created normally. Try the following after starting DRAWEXE:

pload
pcylinder c 1 2
dump c

You will see the required face, wire, edge, surface, and curve definitions. You can then reproduce this manually.

slips's picture

As you see in the dump there are two circles and one line. So my topology seems to be right.