not promising this will work, but it gives you an idea of what it takes, you may have to modify the applyuvcurve code, it only works on straighlines at the moment.
Best,
Alex
Using Qt:
// start of main code
QList plist; // the points on the surface
plist << p1 << p2 << p3 << p4 << p5;
QList uvpoints; // to store the uv points
for(int i=0;i < plist.length();i++)
{
gp_Pnt curp = plist.at(i);
gp_Pnt2d uvpoint =Get2dPntonSurfacefromPoint(aFace,curp); // get the point on the uv
gp_Pnt uvpoint3d(uvpoint.X(),uvpoint.Y(),0);
uvpoints << uvpoint3d;
}
TopoDS_Shape 2dspline = hsf::AddNewSplineSShape(uvpoints); // build spline on the 2d points
TopoDS_Shape 3dspline = hsf::applyuvcurve(2dspline,aFace); // translate from 2d to 3d the spline
//end of main code
you will need this little utility functions i made.
******************************************************************************************
const gp_Pnt2d& HSF::Get2dPntonSurfacefromPoint(TopoDS_Shape SupportSurface, gp_Pnt point)
{
const TopoDS_Face& aFace = TopoDS::Face (SupportSurface);
Handle(Geom_Surface) aSurf = BRep_Tool::Surface(aFace);
Handle(ShapeAnalysis_Surface) aSurfAna = new ShapeAnalysis_Surface (aSurf);
gp_Pnt2d pUV = aSurfAna->ValueOfUV(point, Precision::Confusion());
return pUV;
}
const gp_Pnt& HSF::ProjectPoint(gp_Pnt p1 , TopoDS_Shape Surface)
{
gp_Pnt resultpoint;
if(Surface.ShapeType() != TopAbs_ShapeEnum::TopAbs_FACE)
{
return resultpoint;
}
TopoDS_Face aFace = TopoDS::Face(Surface);
Handle_Geom_Surface aSurf = BRep_Tool::Surface(aFace);
GeomAPI_ProjectPointOnSurf Proj (p1, aSurf);
if (Proj.NbPoints() > 0)
{
resultpoint = Proj.NearestPoint();
}
return resultpoint;
}
TopoDS_Shape HSF::AddNewSplineSShape(QList Points)
{
TColgp_Array1OfPnt arrayval (1,Points.count()); // sizing array
QListIterator iT(Points);
int count = 0;
while (iT.hasNext())
{
gp_Pnt curpoint = iT.next();
arrayval.SetValue(count+1,curpoint);
count +=1;
}
Handle(Geom_BSplineCurve) SPL1 = GeomAPI_PointsToBSpline(arrayval).Curve();
double fp,lp;
fp = SPL1->FirstParameter();
lp = SPL1->LastParameter();
TopoDS_Shape aShape = BRepBuilderAPI_MakeEdge(SPL1,fp,lp);
return aShape;
}
TopoDS_Shape HSF::applyuvcurve(TopoDS_Shape& shape2d, TopoDS_Shape& surface)
{
TopoDS_Compound multiobject;
BRep_Builder B;
B.MakeCompound(multiobject);
if (surface.IsNull()) qDebug() << "surface is null";
TopoDS_Shape surfshape = HSF::getfacefromshape(surface);
Handle(Geom_Surface) mysrf = BRep_Tool::Surface(TopoDS::Face(surfshape));
TopExp_Explorer solidExp;
for (solidExp.Init(shape2d,TopAbs_EDGE); solidExp.More(); solidExp.Next())
{
TopoDS_Shape aSolid = solidExp.Current();
TopoDS_Edge edge = TopoDS::Edge(aSolid);
TopoDS_Vertex V1, V2;
TopExp::Vertices(edge, V1, V2, Standard_True);
gp_Pnt p1 = BRep_Tool::Pnt(V1);
gp_Pnt p2 = BRep_Tool::Pnt(V2);
Standard_Real p1xd = p1.X();
Standard_Real p1yd = p1.Y();
Standard_Real p2xd = p2.X();
Standard_Real p2yd = p2.Y();
gp_Pnt2d anEllipsePnt1;
gp_Pnt2d anEllipsePnt2;
p1xd = p1xd ;
p1yd = p1yd ;
p2xd = p2xd ;
p2yd = p2yd ;
anEllipsePnt1 = gp_Pnt2d(p1xd,p1yd);
anEllipsePnt2 = gp_Pnt2d(p2xd,p2yd);
Handle(Geom2d_TrimmedCurve) aSegment = GCE2d_MakeSegment(anEllipsePnt1 , anEllipsePnt2); // replace this line with a beziercurve:
//Geom2d_BSplineCurve (const TColgp_Array1OfPnt2d &Poles, const TColStd_Array1OfReal &Knots, const TColStd_Array1OfInteger &Multiplicities, const Standard_Integer Degree, const Standard_Boolean Periodic=Standard_False)
TopoDS_Edge aEdge1OnSurf1 = BRepBuilderAPI_MakeEdge(aSegment , mysrf);
TopoDS_Wire threadingWire1 = BRepBuilderAPI_MakeWire(aEdge1OnSurf1);
BRepLib::BuildCurves3d(aEdge1OnSurf1);
TopoDS_Edge &edge3d = TopoDS::Edge(aEdge1OnSurf1);
TopoDS_Shape theShape = edge3d;
B.Add(multiobject,theShape);
}
return multiobject;
}