Picking preciesion

I implemented my own Picking as the automatic Hilighting was not suitable for my needs.

I do something like this:

Handle(StdSelect_ViewerSelector3d) selector = myAISContext->MainSelector();

selector->Pick(x, y, theView);
if(selector->NbPicked() > 0)//selector->More())
. if(selector->OnePicked())
. {
. . . Handle(SelectMgr_SelectableObject)obj = selector->OnePicked()->Selectable();
. . . Handle(AIS_Shape)aisShp = Handle_AIS_Shape::DownCast(obj);

This works as intended (I use this to highlight a group of interactive objects at once. Grouping information is handled elsewhere)

Now, after this step, I want to calculate the point on my solids surface the mousecursor is hovering over.
I do this using a line-solid-intersection with the line constructed from the converted mouse position on the Projection plane parallel to the View-vector(from 'eye' to 'at'[works since i use orthografic projection])
This works, too.

. . . if(aisShp.Access() != UndefinedHandleAddress)
. . . {
. . . . //Calculate line-solid intersection
. . . }
. . . else
. . . {
. . . . //Do other stuff
. . . }
. . .}
. .}

My problem is: the picking does not always return a valid shape when i move the mouse over my solid. I The interactive object is returned always, but sometimes there is no shape to be read from the object.

This seems to be related to the Sensitivity of my selector, as cranking down the tolerance to let's say 0.0001 removes the issue.


I do not only have solids to be highlighted in my group. There may be lines, too. And if I set the tolerance very low, the selection of a line with the mouse becomes a game of 'nimble fingers'.

I probably could hack meself a workaround, using different tolerances for line/solid picking and 'Pick-A-Point-On-The-Solid', but I would prefer not to if there is a more elegant solution to this.

Thank you for reading this rather lengthy post up to this point.

James Blackmon's picture

Hi, Tilman:

So where to put this code? In the function to handle mouse move? or mouse click? or somewhere else?


Tilman Leune's picture

The x and y parameters passed to selector.pick are the coordinates of the current mouse position. the function this code snippet is located in is called in the mouse-move handler.