Projection OnClick

Hello everybody!
I want to show the clicked point as a point projected on the plane XOY.
I have used Stephane's ConvertClickToPoint to get the clicked point and now I'm doing this:

gp_Pnt CXXXView::ProjectPointToXY(gp_Pnt clickedPoint, Handle_V3d_View aView)
{
gp_Pln PlaneOfTheProj (gp_Ax3(gp::XOY()));

//Convert to a surface
TopoDS_Face face = BRepBuilderAPI_MakeFace(PlaneOfTheProj);
BRepAdaptor_Surface surface(face);
const GeomAdaptor_Surface& geomAdapSurf = surface.Surface();
const Handle(Geom_Surface)& geomSurf = geomAdapSurf.Surface();

//Projects the point
GeomAPI_ProjectPointOnSurf prj(P,geomSurf);
Standard_Integer index=prj.NbPoints();
gp_Pnt ResultPoint = prj.Point(index);

return ResultPoint;
}

It almost work, it does the projection on XY but not on the clicked point but on a near point.
Any idea on what could happen?

Thank you very much.

P Dolbey's picture

Do you know, I developed a completely different mechanism for the project-ap-point. Well 2 actually, one as given in http://www.opencascade.org/org/forum/thread_2785/
and another based on screen interpolation. And do you know they BOTH suffered from exactly the same problem - a pixel error between the point clicked and the point displayed giving rise to a significant rounding error in the floating point transformation. It seemed as if there was a common variance between the forward and reverse projections through the projection view matrices. I spent about a month (of evenings anyway) trying to figure this one out. I did discover that by default the "privileged plane" I was using for the grid has a very small but deliberate offset from its true XOY value, but this offset can be removed through an API call.

he grid feedback mechanism doesn't appear to suffer from the same projection problem. I'd love to know to fix it as well - maybe OCC 6.2 has the asnswer...

Pete

José Manuel Domínguez Ramos's picture

Hello Pete!
I have tried your post code on that thread and it does just what I wanted to do!
OCC 6.2-I am wishing to prove the new version.
Thank you very much for your help. People like you make OCC live.

P Dolbey's picture

I'd love to take the credit for the code, but if you get the full code (look for some of the Qt4 threads). you'll see that it was down to material I kept from a training course in CAS.CADE 1.5. I'm not an OpenCASCADE employee, and this stuff is a hobby for me left over from a previous job (look for FILLCALC on the web) but if you're developing commercially its well worth considering going on a training course. I suspect there's a wealth of material that's unpublished anywhere else. Unfortunately all mine is on paper, and I'd probaly be contravening copyright by transcribing it to the web anyway.

Don't forget, you can re-align the privileged plane to any plane that can be defined by with a gp_Pln and the picking algorithm still works - you're not just constrained to XOY (and you get can a "free" grid as well). I'm still working out if I can display a grid/plane per view rather than over the global viewer

Pete