How to correctly update the pcurve curve of the seamEdge on the side face of a cylinder? In a cylindrical surface, the seamEdge consists of two topological edges that are IsSame. How should the pcurve curves of these two seamEdges be updated to ensure they are correctly projected onto the cylindrical surface? Looking forward to your reply.
void BRep_CAD_View::UpdateEdgeOnCylinderPcurve(TopoDS_Edge& newEdge, TopoDS_Edge& oldEdge, TopoDS_Face& face)
{
TopLoc_Location locF;
Handle(Geom_Surface) surf = BRep_Tool::Surface(face, locF);
if (surf.IsNull()) return;
// 1) 先从 oldSeam 上取一条 pcurve,得到它的 u0(角度参数)
Standard_Real f2dOld, l2dOld;
Handle(Geom2d_Curve) c2dOld =
BRep_Tool::CurveOnSurface(oldEdge, face, f2dOld, l2dOld);
if (c2dOld.IsNull()) return;
Standard_Real tMidOld = 0.5 * (f2dOld + l2dOld);
gp_Pnt2d uvMidOld = c2dOld->Value(tMidOld);
Standard_Real u0 = uvMidOld.X(); // 这条 seam 对应的固定 U
// 2) 取 newSeam 的两个顶点,在 surface 上求 (u,v),我们只要 v,用旧的 u0
TopoDS_Vertex v1 = TopExp::FirstVertex(newEdge, Standard_True);
TopoDS_Vertex v2 = TopExp::LastVertex(newEdge, Standard_True);
gp_Pnt P1 = BRep_Tool::Pnt(v1);
gp_Pnt P2 = BRep_Tool::Pnt(v2);
// 注意坐标系:face 可能带 Location,这里变换到曲面局部坐标系
gp_Trsf trInv = locF.Transformation().Inverted();
P1.Transform(trInv);
P2.Transform(trInv);
GeomAPI_ProjectPointOnSurf proj1(P1, surf);
GeomAPI_ProjectPointOnSurf proj2(P2, surf);
Standard_Real uu1, vv1, uu2, vv2;
proj1.LowerDistanceParameters(uu1, vv1);
proj2.LowerDistanceParameters(uu2, vv2);
// 强制使用 old seam 的 u0,v 用新端点的
gp_Pnt2d uv1(u0, vv1);
gp_Pnt2d uv2(u0, vv2);
// 3) 在 UV 平面上做一条线段当作 newSeam 的 pcurve
Handle(Geom2d_TrimmedCurve) pcNew = GCE2d_MakeSegment(uv1, uv2);
Handle(Geom2d_Curve) pcRight;
if (u0 == 0.)
{
pcRight = Handle(Geom2d_Curve)::DownCast(pcNew->Copy());
gp_Trsf2d tr2d;
tr2d.SetTranslation(gp_Vec2d(2.0 * M_PI, 0.0));
pcRight->Transform(tr2d);
}
else if (u0 == 2.0 * M_PI)
{
pcRight = Handle(Geom2d_Curve)::DownCast(pcNew->Copy());
gp_Trsf2d tr2d;
tr2d.SetTranslation(gp_Vec2d(-2.0 * M_PI, 0.0));
pcRight->Transform(tr2d);
}
BRep_Builder B;
B.UpdateEdge(newEdge, pcNew, pcRight, surf, locF, Precision::Confusion());
// 4) 更新顶点在这条 pcurve 上的参数
Geom2dAPI_ProjectPointOnCurve projPC1(uv1, pcNew);
Geom2dAPI_ProjectPointOnCurve projPC2(uv2, pcNew);
Standard_Real par1 = projPC1.LowerDistanceParameter();
Standard_Real par2 = projPC2.LowerDistanceParameter();
B.UpdateVertex(v1, par1, newEdge, surf, locF, Precision::Confusion());
B.UpdateVertex(v2, par2, newEdge, surf, locF, Precision::Confusion());
}