Retrieve 3D location from clicked pixel / datatip position

조회 수: 5(최근 30일)
Roger Breton
Roger Breton 2022년 2월 23일
답변: Roger Breton 2022년 2월 24일
I attached a copy of my code (I did not includes the images). My question is how would I retrieve the CIE Lab color coordinates pointed to by the mouse and the datatip on the 3D graph? Not sure which function to use best? I guess I have to setup a mouseclick callback function but I don't know whether I can access the datatip properties from that function? This screen capture shows what I'm trying to do :
On the right is the RGB image displayed in its own figure and the left is the 'loRes' corresponding data, in CIE Lab. When I click on an the existing points, in the scatter3 graph, with the mouse, I get a DataTip "baloon" showing the CIE Lab value pointed to by the mouse. Those are the values that I'm trying to retrieve and use as an index on the right figure, to be able to show the xy location with a marker? All I'm trying to accomplish is to allow students to select a point in the 3D space on the left and show them what the corresponding RGB color is.
I have tons of ideas but far too little Matlab knowledge...
Any help is appreciated.
  댓글 수: 6
Roger Breton
Roger Breton 2022년 2월 23일
My latest 'attempt' involves this code :
DataCursorMode1 = datacursormode(fig_3D);
set(DataCursorMode1,'Enable','on','UpdateFcn',@displayCoordinates)
end
function txt = displayCoordinates(~, info)
txt = {sprintf('CIE L: %.0f', info.Position(3)), sprintf('CIE a: %.0f', info.Position(1)), sprintf('CIE b: %.0f', info.Position(2))};
end
At least, using this 'solution', I'm in control of the order in which the values are displayed in the datatip :
Trouble is that, now, I lose all 'default' interactivity : no more Rotate3D functionality until I click on the Rotate3D button, and then I'm automatically "out" of the datacursor mode? I have to alternate between the 'interaction mode' and 'datacursor mode', it's not possible to have the two modes simultaneously active. I understand "why", this is so. Yes, I noticed that, when the mouse hovers empty areas of the graph, that the cursor turns back into a normal mouse pointer?

댓글을 달려면 로그인하십시오.

채택된 답변

Roger Breton
Roger Breton 2022년 2월 24일
Not a "perfect" answer but I think it's 'workable'.
First, I added a pusbutton to the figure. Then I use this code, to obtain the display coordinates :
DataCursorMode1 = datacursormode(fig_3D);
set(DataCursorMode1,'Enable','on','UpdateFcn',@displayCoordinates)
Then in the callback function, I use this code :
function txt = displayCoordinates(~, info)
global clickedCIE_L clickedCIE_a clickedCIE_b;
clickedCIE_L = info.Position(3);
clickedCIE_a = info.Position(1);
clickedCIE_b = info.Position(2);
txt = {sprintf('CIE L: %.0f', info.Position(3)), sprintf('CIE a: %.0f', info.Position(1)), sprintf('CIE b: %.0f', info.Position(2))};
end
I know, "global variables"... but, have a heart. My projects will never be used for rocket launching...
This solution is not ideal but, as it stands, there is no way, with my level of (ahem!) Matlab 'mastery' to be able to intercept the datatips value when clicked with the mouse otherwise.
And I have to accept that I cannot be simultaneously in both datacursor mode and rotate3D mode. So it's a pain but, I'm satisfied that this is workable.

추가 답변(0개)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by