I try to select (by mouse clicking) a number of points on a 3D triangular surface mesh using matlab and save their coordinates in a matrix.
This has proved to be far more notorious than I expected.
It seems like callbacks is the right thing to do here. After experimenting a bit I ended up with:
global allPoints;
allPoints = [];
patch('Faces',T,'Vertices',V,'FaceColor','white','ButtonDownFcn',@lineCallback)
axis equal;
allPoints
function lineCallback(src,eventData)
global allPoints;
p = eventData.IntersectionPoint;
allPoints = [allPoints;p];
end
Attempt 1:
Although not elegant, the above allows the users to click on the bunny and get the points. The issue arises when I want to select a point that is not visible. In that case, for some reason the figure does not allow me to rotate the bunny. (I suppose because I already click a mouse button to do that).
Attempt 2:
When I tried to replace ButtonDownFcn with CreateFnc I get an error:
Not enough input arguments.
Error in tzs>lineCallback (line 14)
p = eventData.IntersectionPoint;
which is perfectly logical as I have not defined neither the eventdata nor the object. However, I can not find any serious example to help towards this direction. Can anybody help?