How to sample points on a surface?

I writed a program to read a iges file and display it.
When I tried to sample points from my selected surface, I had some trouble.(see piture)

This is my code in sampling points:

Standard_Real umin, umax;
Standard_Real vmin, vmax;
aSurf->Bounds(umin, umax, vmin, vmax);

Standard_Real u = umin,v = vmin;
Standard_Real dv = (vmax-vmin)/30;
Standard_Real du = (umax-umin)/5;

for(int j=1;j {
for(int i=1;i {

gp_Pnt aPnt = aSurf->Value(u, v);
Handle_AIS_Shape aisbPnt = new AIS_Shape(BRepBuilderAPI_MakeVertex(aPnt));
aisbPnt->SetColor(Quantity_NOC_INDIANRED); //set color
myContext->Display(aisbPnt, Standard_True);
v=v+dv;

}
u=u+du; v=vmin;
}

Sébastien Raymond's picture

Hello, I'm not sure to understand what your problem is about.
Do you mean that you expect the red points to be on the white face?

Dante Liu's picture

yes.

Benjamin Bihler's picture

Hi!

This is indeed an interesting question. Aren't the p-curves (of faces) the bounding curves? If they are not simple, what is the meaning of u/v-bounds? For complicated faces the border cannot be described by a few parameter values, can it? I am looking forward to any answer!

But perhaps I can also offer some help to Dante Liu:

If your surface is made from a face, you can use BRepTopAdaptor_FClass2d to decide whether a point is on the face or not. Maybe Adaptor3d_TopolTool does the same for adaptors you can also create from Geom_Surface, but I have not tried that yet.

BRepTopAdaptor_FClass2d can be used like this:

gp_Pnt2d position(0.0, 1.0);
BRepTopAdaptor_FClass2d topologyChecker(face, Precision::Approximation());
TopAbs_State state = topologyChecker.Perform(position);

if(state != TopAbs_OUT)
{
std::cout << "Position is on face." << std::endl;
}

Benjamin

Dante Liu's picture

Thank you!

Sébastien Raymond's picture

So the result you get is normal, the points lie on the base surface of the face.
A face is defined by a surface and a wire boundary.
So if the boundary have more than 4 edges, uv mapping is not possible.
Maybe you could sort you points by checking the distance between the face and points.

Dante Liu's picture

Thank you!