Problem with surface sampling

Technical discussions
Post Reply
Lois Qing
Posts: 1
Joined: Thu May 06, 2021 5:21 am

Problem with surface sampling

Post by Lois Qing »

Hello
I need help.
I wrote a program which reads step file. I need to display it.
I tried to sample points from a selected surface.

Code: Select all

IUVSurface_DG surface;
//.....
double minU,maxU,minV,maxV;
surface.GetParameterRange(true, out minU, out maxU);
surface.GetParameterRange(false, out minV, out maxV);

double u = minU;
double v = minV;
double du = (maxU-minU)/10;
double dv = (maxV-minV)/20;

for(int i=0;i<10; i++ ) {
for(int j=0;j<20; j++)  {
PointDg pnt = surface.GetPoint(new Dg_2D(u, v));
IEntity_DG ent = myModel.AddNewBRepShape(ShapeType_DG.eShTypeVertexDG);
IBRepGeometry_DG geo = (IBRepGeometry_DG)ent.GetGeometry();
IBRepVertex_DG vert = (IBRepVertex_DG)geo.GetShape();
vert.SetPosition1(pnt);
v += dv;
}
u += du; v = minV;
}
I see the points, but they are in wrong place.
What is wrong?
Thank you

Alfred R
Posts: 1
Joined: Mon Oct 17, 2016 5:48 am

Re: Problem with surface sampling

Post by Alfred R »

Hello

There are two issues to check.

If a subset of the points partially lies OK on the surface than you just need to take in consideration the trimming curves of the edge. The actual face uses only part of the parameters range rectangle. The easier way is to do in 2d uv space. You need to check if a uv point lies inside the curved polygon of pcurves. See the IBRepEdge_DG.aspx#GetPCurve(). I do not know a general method for doing this. It might be easier if you know the type of the curves

If points are out of the face completely you are probably missing conversion to global coordinates. surface.GetPoint() returns coordinates relative to the local frame of the entity.

Code: Select all

IEntity_DG entityOfTheSurface = ...;
IFrame_DG fr = entityOfTheSurface.GetLocation();
And in your loop:

Code: Select all

//...
PointDg pnt = surface.GetPoint(new Dg_2D(u, v));
pnt = iFrame.ToGlobal(pnt);
//...

Post Reply