(GeomFill_Pipe) Geom_Surface to TopoDS_Face

Hi,
I want to create a face on a Geom_Surface by using GeomFill_Pipe. I know that you can solve this problem on topological level (BRepFill_Pipe) but I want to solve this like the cylinder example by Roman Lygin.

http://opencascade.blogspot.de/2009/03/topology-and-geometry-in-open-cas...
(March 10, 2009 at 11:57 PM)

I want to create some pipes and connecting them together. It doesnt work and I dont know what I making wrong. Please help.

//----------------------------------------------------------------------------
//Radius
const Standard_Real r = 0.2;
BRep_Builder aBuilder;

gp_Ax3 Ax0 = gp_Ax3(gp::Origin(), gp_Dir(gp_Vec(0.0, 0.0, 1.0)));
Handle(Geom_Circle) c0 = new Geom_Circle(Ax0.Ax2(), r);

//Surface
GeomFill_Pipe pipe0(splineCurve[0] /*Geom_TrimmedCurve*/, c0, GeomFill_IsCorrectedFrenet);
pipe0.Perform(Precision::Confusion(), Standard_False, GeomAbs_C1, BSplCLib::MaxDegree(), 1000);
Handle(Geom_Surface) s0 = pipe0.Surface();

//Edges
Handle(Geom2d_Line) lm0R = new Geom2d_Line(gp_Pnt2d(gp::Origin2d().X(), 2* M_PI), gp::DX2d());
Handle(Geom2d_TrimmedCurve) tm0R = GCE2d_MakeSegment(lm0R->Lin2d(), 0.0, M_PI/2);
TopoDS_Edge mEdgeR = BRepBuilderAPI_MakeEdge(tm0R, s0);
BRepLib::BuildCurve3d(mEdgeR, Precision::Confusion(), GeomAbs_C1, BSplCLib::MaxDegree(), 1000);

Handle(Geom2d_Line) lm0F = new Geom2d_Line(gp::Origin2d(), gp::DX2d());
Handle(Geom2d_TrimmedCurve) tm0F = GCE2d_MakeSegment(lm0F->Lin2d(), 0.0, M_PI/2);
TopoDS_Edge mEdgeF = BRepBuilderAPI_MakeEdge(tm0F, s0);
BRepLib::BuildCurve3d(mEdgeF, Precision::Confusion(), GeomAbs_C1, BSplCLib::MaxDegree(), 1000);

Handle(Geom2d_Line) lb0 = new Geom2d_Line(gp::Origin2d(), gp::DY2d());
Handle(Geom2d_TrimmedCurve) tb0 = GCE2d_MakeSegment(lb0->Lin2d(), 0.0, 2 * M_PI);
TopoDS_Edge bEdge = BRepBuilderAPI_MakeEdge(tb0, s0);
BRepLib::BuildCurve3d(bEdge, Precision::Confusion(), GeomAbs_C1, BSplCLib::MaxDegree(), 1000);

Handle(Geom2d_Line) lt0 = new Geom2d_Line(gp_Pnt2d(M_PI/2, gp::Origin2d().Y()), gp::DY2d());
Handle(Geom2d_TrimmedCurve) tt0 = GCE2d_MakeSegment(lt0->Lin2d(), 0.0, 2 * M_PI);
TopoDS_Edge tEdge = BRepBuilderAPI_MakeEdge(tt0, s0);
BRepLib::BuildCurve3d(tEdge, Precision::Confusion(), GeomAbs_C1, BSplCLib::MaxDegree(), 1000);

//Wire
TopoDS_Wire mWire0;
aBuilder.MakeWire(mWire0);
aBuilder.Add(mWire0, bEdge);
aBuilder.Add(mWire0, mEdgeF);
aBuilder.Add(mWire0, tEdge.Reversed());
aBuilder.Add(mWire0, mEdgeF.Reversed());

//Face
TopoDS_Face mFace0;
aBuilder.MakeFace(mFace0, s0, Precision::Confusion());
aBuilder.Add(mFace0, mWire0);

aBuilder.UpdateEdge(bEdge, tb0, mFace0, BRep_Tool::Tolerance(bEdge));
aBuilder.UpdateEdge(tEdge, tt0, mFace0, BRep_Tool::Tolerance(tEdge));
aBuilder.UpdateEdge(mEdgeF, tm0F, tm0R, mFace0, BRep_Tool::Tolerance(mEdgeF));

OutputBuilder.Add(OUTPUT, mFace0);

Attachments: 
Cauchy Ding's picture

Hi Markus,

I think your four edges' parameter 2d curves are not connected. See the end points' coordinates of the four parameter curves in the attached picture. They should be chanined sorted in theory. In you case, point (0,0) and point (1.57,0) happen three times, but point (0, 6.28) and (1.57, 6.28) happen only one time.

Ding

Attachments: 
Markus Hagemann's picture

Thanks Cauchy Ding.
I have changed it but it doesnt work. I dont know if this problem still exist because I cant find this information in my debugger. (VS2010)

TopoDS_Compound OUTPUT;
BRep_Builder aBuilder;
aBuilder.MakeCompound (OUTPUT);

//Spine
Handle(Geom_TrimmedCurve) aSpine = GC_MakeArcOfCircle(
gp_Pnt(gp::Origin().Coord()),
gp_Vec(0.0, 1.0, 0.0),
gp_Pnt(1.0, 1.0, 0.0));

TopoDS_Edge aEdgeSpine = BRepBuilderAPI_MakeEdge(aSpine);

aBuilder.Add(OUTPUT, aEdgeSpine);

const Standard_Real r = 0.2;
gp_Ax3 AxB = gp_Ax3(aSpine->StartPoint(), gp_Dir(gp_Vec(0.0, 1.0, 0.0)));
gp_Ax3 AxT = gp_Ax3(aSpine->EndPoint(), gp_Dir(gp_Vec(1.0, 0.0, 0.0)));

Handle(Geom_Plane) aPlaneB = new Geom_Plane(AxB.Ax2());
Handle(Geom_Plane) aPlaneT = new Geom_Plane(AxT.Ax2());

Handle(Geom_Circle) aCircB = new Geom_Circle(AxB.Ax2(), r);
Handle(Geom_Circle) aCircT = new Geom_Circle(AxT.Ax2(), r);

//Vertices
gp_Pnt aPointB = gp_Pnt(gp_Vec(AxB.Location().Coord()).Added(gp_Vec(AxB.YDirection()).Multiplied(-r)).XYZ());
TopoDS_Vertex aVertexB;
aBuilder.MakeVertex(aVertexB, aPointB, Precision::Confusion());

gp_Pnt aPointT = gp_Pnt(gp_Vec(AxT.Location().Coord()).Added(gp_Vec(AxT.YDirection()).Multiplied(-r)).XYZ());
TopoDS_Vertex aVertexT;
aBuilder.MakeVertex(aVertexT, aPointT, Precision::Confusion());

//Surface
GeomFill_Pipe pipe(aSpine, aCircB, GeomFill_IsCorrectedFrenet);
pipe.Perform(Precision::Confusion(), Standard_False, GeomAbs_C1, BSplCLib::MaxDegree(), 1000);
Handle(Geom_Surface) surface = pipe.Surface();

//PCurves
Standard_Real umin, umax, vmin, vmax;
surface->Bounds(umin, umax, vmin, vmax);
std::cout << "umin: " << umin << "\n";
std::cout << "umax: " << umax << "\n";
std::cout << "vmin: " << vmin << "\n";
std::cout << "vmax: " << vmax << "\n";

gp_Pnt2d Pnt2dOrigin = gp_Pnt2d(umin, vmin);
gp_Pnt2d Pnt2dXMax = gp_Pnt2d(umax, vmin);
gp_Pnt2d Pnt2dYMax = gp_Pnt2d(umin, vmax);
gp_Pnt2d Pnt2dXYMax = gp_Pnt2d(umax, vmax);

Handle(Geom2d_Line) aLineF = new Geom2d_Line(Pnt2dOrigin, gp::DX2d());
Handle(Geom2d_TrimmedCurve) aTrimF = GCE2d_MakeSegment(aLineF->Lin2d(), Pnt2dOrigin, Pnt2dXMax).Value();

Handle(Geom2d_Line) aLineR = new Geom2d_Line(Pnt2dYMax, gp::DX2d());
Handle(Geom2d_TrimmedCurve) aTrimR = GCE2d_MakeSegment(aLineR->Lin2d(), Pnt2dXYMax, Pnt2dYMax).Value();

Handle(Geom2d_Line) aLineT = new Geom2d_Line(Pnt2dXMax, gp::DY2d());
Handle(Geom2d_TrimmedCurve) aTrimT = GCE2d_MakeSegment(aLineT->Lin2d(), Pnt2dXMax, Pnt2dXYMax).Value();

Handle(Geom2d_Line) aLineB = new Geom2d_Line(Pnt2dOrigin, gp::DY2d());
Handle(Geom2d_TrimmedCurve) aTrimB = GCE2d_MakeSegment(aLineB->Lin2d(), Pnt2dOrigin, Pnt2dYMax).Value();

//Edges
Handle(Geom2d_Line) aLine = new Geom2d_Line(gp::Origin2d(), gp::DX2d());
Handle(Geom2d_TrimmedCurve) aTrim = GCE2d_MakeSegment(aLine->Lin2d(), gp::Origin2d(), gp_Pnt2d(M_PI/2, 0.0)).Value();
TopoDS_Edge aEdgeM = BRepBuilderAPI_MakeEdge(aTrim, surface, aVertexB, TopoDS::Vertex(aVertexT.Reversed()));
BRepLib::BuildCurve3d(aEdgeM, Precision::Confusion(), GeomAbs_C1, BSplCLib::MaxDegree(), 1000);
TopoDS_Edge aEdgeB = BRepBuilderAPI_MakeEdge(aCircB, aVertexB, TopoDS::Vertex(aVertexB.Reversed()));
TopoDS_Edge aEdgeT = BRepBuilderAPI_MakeEdge(aCircT, aVertexT, TopoDS::Vertex(aVertexT.Reversed()));

//Wires
TopoDS_Wire aWireT = BRepBuilderAPI_MakeWire(aEdgeT);
TopoDS_Wire aWireB = BRepBuilderAPI_MakeWire(aEdgeB);

TopoDS_Wire aWireM;
aBuilder.MakeWire(aWireM);
aBuilder.Add(aWireM, aEdgeB);
aBuilder.Add(aWireM, aEdgeM);
aBuilder.Add(aWireM, aEdgeT.Reversed());
aBuilder.Add(aWireM, aEdgeM.Reversed());

//Faces
TopoDS_Face aFaceT = BRepBuilderAPI_MakeFace(aPlaneT, aWireT);
TopoDS_Face aFaceB = BRepBuilderAPI_MakeFace(aPlaneB, aWireB);

TopoDS_Face aFaceM;
aBuilder.MakeFace(aFaceM, surface, Precision::Confusion());
aBuilder.Add(aFaceM, aWireM);

//Edges Update
aBuilder.UpdateEdge(aEdgeT, aTrimT, aFaceM, BRep_Tool::Tolerance(aEdgeT));
aBuilder.UpdateEdge(aEdgeB, aTrimB, aFaceM, BRep_Tool::Tolerance(aEdgeB));
aBuilder.UpdateEdge(aEdgeM, aTrimF, aTrimR, aFaceM, BRep_Tool::Tolerance(aEdgeM));

aBuilder.Add(OUTPUT, aFaceM);
//aBuilder.Add(OUTPUT, aFaceT);
//aBuilder.Add(OUTPUT, aFaceB);