how to create Curves on surface

Dear every one.i got a problem which seems to be a little complicated
in my projects i collect several points on a surface(or face),now i want to create a curves on the given face.
any body knows how to do it?
best regards.
in order to describe my problem .i make a picture which draw in rhino.simliar to the curve.is there any way to realize in opencascade??

Attachments: 
jelle's picture

If your interested in making this face than used use BRepFill_Filling or make a plate Geom_Plate with your curves.
If your interested in extracting the iso curve than get a BRepAdaptor from the face, and if I recall well, call the UIso or VIso method.

take care,

-jf

zhushunlai2012's picture

thank you jelle very much .it really give me some tip.

AP's picture

Zhushunlai

theres 2 ways of tackling your problem, the first questions are, how do did you locate the points on the surface to begin with.

so you have a list of points on a surface, ideally they are ordered so that if you connect them with a spline theres no self intersection.

the algorithim looks in pseudo code something like:

create an uv value array

for each point in the list
project the point on the surface
get the uv value of the point on the surface
add the uv value to the uv value array

create a 2d spline passing through the uv points
take that 2d spline and map-it from 2d to the 3d space of the surface.

the second way:

you build a 3d spline that connects the dots of your points, then you project it to the face.

Best,

Alex

AP's picture

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;

}

zhushunlai2012's picture

waaoo!!!it is so amazed,thank you AlexP with my best.
i will try to go in this wat ...3Q AGAIN