0

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.

enter image description here 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?

Paramar
  • 287
  • 1
  • 5
  • 22
  • [`nargin`](https://mathworks.com/help/matlab/ref/nargin.html) could help you remove the error for your second attempt ... but I don't see any benefit in placing the callback with the `CreateFcn` event ... – Hoki Dec 10 '18 at 16:26
  • This does not help in getting closer to the solution, I am sorry – Paramar Dec 10 '18 at 16:32
  • Apparently you successfully managed to "select points with the mouse" ... your problem in attempt 1 is that you are not able to rotate the figure at the same time. This is because each of the zoom/pan/rotate/datacursor/brush function of a figure will replace/modify the various `keypressfcn\buttondownfcn\etc...` for the figure. These do not co-exist hapilly with user defined callbacks trying to use these same events. – Hoki Dec 10 '18 at 16:46
  • Have a read at: [Enabling user callbacks during zoom/pan](https://undocumentedmatlab.com/blog/enabling-user-callbacks-during-zoom-pan). It's a bit technical and undocumented but you need to understand what is going on behind the scene if you want to implement your own callback co-existing with one of these figure `mode` (`Rotate 3D` in your case ...) – Hoki Dec 10 '18 at 16:47
  • This is above my understanding. I found another way around – Paramar Dec 11 '18 at 12:27
  • Great if you found a way around. Don't hesitate to post it here as an answer if it works – Hoki Dec 11 '18 at 14:30

0 Answers0