Create Torus surface from Geom_ToroidalSurface

Hello,
I'm building a torus surface from a Geom_ToroidalSurface. but the result is not what i want.
what i want is 0

Here is my code.
I thanks any help.

static TopoDS_Solid TestCreateTorus()
{
BRep_Builder aBuilder;

gp_Pnt origin(0.0 , 0.0 , 0.0);
gp_Dir dir(0.0 , 0.0 , 1.0);
Standard_Real dTorusRadius = 20.0 , dTubeRadius = 5.0;

Handle(Geom_ToroidalSurface) aCSurf = new Geom_ToroidalSurface(gp_Ax3(origin , dir) , dTorusRadius , dTubeRadius);

//vertices
TopoDS_Vertex aAVertex;
aBuilder.MakeVertex (aAVertex, gp_Pnt(25.0 , 0.0 , 0.0) , Precision::Confusion());
TopoDS_Vertex aBVertex;
aBuilder.MakeVertex (aBVertex, gp_Pnt(0.0 , 25.0 , 0.0), Precision::Confusion());
TopoDS_Vertex aCVertex;
aBuilder.MakeVertex (aCVertex, gp_Pnt(25.0 , 0.0 , 0.0), Precision::Confusion());

TopoDS_Vertex aDVertex1;
aBuilder.MakeVertex (aDVertex1, gp_Pnt(15.0 , 0.0 , 0.0), Precision::Confusion());
TopoDS_Vertex aDVertex2;
aBuilder.MakeVertex (aDVertex2, gp_Pnt(0.0 , 15.0 , 0.0), Precision::Confusion());

//3D curves
//axis placements
gp_Ax2 aAAx(gp_Pnt(20, 0, 0) , gp::DY() , gp::DX());
gp_Ax2 aBAx(gp_Pnt(0, 20, 0) , gp::DX() , gp::DY());

Handle(Geom_Circle) aACirc = new Geom_Circle (aAAx, dTubeRadius);
Handle(Geom_Circle) aBCirc = new Geom_Circle (aBAx, dTubeRadius);
Handle(Geom_Circle) aCCirc = new Geom_Circle (gp_Ax2(gp_Pnt(0,0,0) , gp::DZ() , gp::DX()) , dTorusRadius + dTubeRadius);
Handle(Geom_Circle) aDCirc = new Geom_Circle (gp_Ax2(gp_Pnt(0,0,0) , gp::DZ() , gp::DX()) , dTorusRadius - dTubeRadius);

TopoDS_Edge aAEdge = BRepBuilderAPI_MakeEdge (aACirc, aAVertex , TopoDS::Vertex(aAVertex.Reversed()));
TopoDS_Edge aBEdge = BRepBuilderAPI_MakeEdge (aBCirc, aBVertex , TopoDS::Vertex (aBVertex.Reversed()));
TopoDS_Edge aCEdge = BRepBuilderAPI_MakeEdge (aCCirc, aCVertex , aBVertex);
TopoDS_Edge aDEdge = BRepBuilderAPI_MakeEdge (aDCirc, aDVertex1, aDVertex2);

//wires
TopoDS_Wire aCWire;
aBuilder.MakeWire(aCWire);
aBuilder.Add (aCWire, aAEdge);
aBuilder.Add (aCWire, aBEdge);
aBuilder.Add (aCWire, aCEdge);
aBuilder.Add (aCWire, aDEdge);

TopoDS_Face aCFace;
aBuilder.MakeFace (aCFace, aCSurf, Precision::Confusion());
aBuilder.Add (aCFace, aCWire);

/// set pcurve on edge
Handle(Geom2d_Line) aCLineA = new Geom2d_Line (gp_Pnt2d (0 , 0), gp::DY2d());
aBuilder.UpdateEdge (aAEdge , aCLineA , aCFace, BRep_Tool::Tolerance (aAEdge));

Handle(Geom2d_Line) aCLineB = new Geom2d_Line (gp_Pnt2d (0.5*PI , 0), gp::DY2d());
aBuilder.UpdateEdge (aBEdge , aCLineB , aCFace, BRep_Tool::Tolerance (aBEdge));

Handle(Geom2d_Line) aCLineC = new Geom2d_Line (gp_Pnt2d (0 , 0), gp::DX2d());
aBuilder.UpdateEdge (aCEdge , aCLineC , aCFace, BRep_Tool::Tolerance (aCEdge));

Handle(Geom2d_Line) aCLineD = new Geom2d_Line (gp_Pnt2d (0.5*PI , 0), gp::DX2d().Reversed());
aBuilder.UpdateEdge (aDEdge , aCLineD , aCFace, BRep_Tool::Tolerance (aDEdge));

//shell
TopoDS_Shell aShell;
aBuilder.MakeShell (aShell);
aBuilder.Add (aShell, aCFace);

//solid
TopoDS_Solid aSolid = BRepBuilderAPI_MakeSolid(aShell);

return aSolid;
}

Attachments: 
Sharjith Naramparambath's picture

If you want to create an angle delimited torus and get only the toroidal surface, I would suggest you to do it top-down instead of the bottup-up way you are trying to do. By that I mean, instead of creating the angle delimited Geom_ToroidalSurface and building a Topological face, create the angle delimited Topological Torus and extract only the Toroidal surface from it.

BRepPrimAPI_MakeTorus MkTor(axis, majRad, minRad, angVMin, angVMax, angUMax);

// Add only toroidal surface
Handle(Geom_Surface) aSurf;
TopoDS_Shell aShell;
BRep_Builder B;
B.MakeShell(aShell);
for(TopExp_Explorer ex(MkTor.Shape(),TopAbs_FACE); ex.More(); ex.Next())
{
TopoDS_Face Face =TopoDS::Face(ex.Current());
aSurf = BRep_Tool::Surface(Face);
if(aSurf->IsKind(STANDARD_TYPE (Geom_ToroidalSurface)))
{
B.Add(aShell, Face);
}
}
// use the shell to display
Handle(AIS_Shape) aShape = new AIS_Shape(aShell);

Sharjith Naramparambath's picture

Shapshot of the code shown above

Attachments: 
zbaekhk's picture

hi Sharjith,
thanks for your reply.

i am trying to import ACIS-SAT file which has surface and severial boundary curves(edge).
previous post was my first step to extract toroidal face bounded by several boundary curves(edge).
i am struggling to create pcurve corresponding to edge.

have you any experience about it?

zbaekhk's picture

in this case, what i know is toroidal surface and two ellipses bounding toroidal surface.