Error displaying custom Data Tips

9 Ansichten (letzte 30 Tage)
Veronica Taurino
Veronica Taurino am 16 Mär. 2021
Bearbeitet: Veronica Taurino am 23 Mär. 2021
I've created a callback to displaying Data Tips on a pointcloud (pcshow) after the space bar is pressed. The flow is:
  • Press on the space bar
  • click on a point
  • custom data tips appear
At first, the DataTip shows an error message, but if I click on the data tip or in general over the figure, the correct data tip appears and the error message does not show again. How can I avoid the appearence of that message? Where should I look for the problem?
Error message: unable to update data tip using custom update function.
Thank you.
  3 Kommentare
Veronica Taurino
Veronica Taurino am 19 Mär. 2021
Bearbeitet: Veronica Taurino am 23 Mär. 2021
Thank you for your reply. It's not (yet) a neat and efficent code, don't judge me please ahah
I create a tab panel with 3 figures (pcshow function, they are point clouds). When the user clicks the space bar on a figure, 3d rotation mode has to quit and the ''datatip'' mode starts, so that when the user clicks on a point over the point clouds, datatips are added to the figure. Then, when the user pushes the space bar again, the datatips are hidden and 3D rotation mode starts again.
Please note that to allow the callback during the 3D rotation mode, I used this undocumented Matlab code:
https://undocumentedmatlab.com/articles/enabling-user-callbacks-during-zoom-pan
function [hTabGroup] = PlotInTab(path_pc)
ptCloud = plyread(path_pc);
struct_data={'1','2','3'; ptCloud.vertex.one, ptCloud.vertex.two , ptCloud.vertex.three};
hTabGroup = uitabgroup;
drawnow;
% Plot
for iFig = 1:3
tab = uitab(hTabGroup, 'title',struct_data{1,iFig});
tab_all{iFig}=tab;
a = axes('parent', tab_all{iFig});
pc(iFig)=pcshow([ptCloud.vertex.x ptCloud.vertex.y ptCloud.vertex.z], struct_data{2,iFig},'Parent',axes_all{iFig});
%[...Stuff - custom colorbar, colormap, colorbar tick...]
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% https://undocumentedmatlab.com/articles/enabling-user-callbacks-during-zoom-pan
hFig=pc(iFig).Parent.Parent.Parent;
hManager = uigetmodemanager(hFig);
try
set(hManager.WindowListenerHandles, 'Enable', 'off'); % HG1
catch
[hManager.WindowListenerHandles.Enabled] = deal(false); % HG2
end
set(hFig, 'WindowKeyPressFcn', []);
set(hFig, 'KeyPressFcn', @isspace); % callback 2
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
set(gcf, 'MenuBar', 'none');
set(gcf, 'ToolBar', 'none');
axis 'equal'
axis 'tight'
axis 'off'
end
% Global variables - callback
setGlobalx(0)
end
%% 1. Callback: Display DataTips %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function txt = displayCoordinates(hObject,info)
hObject.Parent.Children.DataTipTemplate.DataTipRows(1).Label='X';
hObject.Parent.Children.DataTipTemplate.DataTipRows(2).Label='Y';
hObject.Parent.Children.DataTipTemplate.DataTipRows(3).Label='Height';
% Add Value row to the datatips:
hObject.Parent.Children.DataTipTemplate.DataTipRows(4).Label='Value';
hObject.Parent.Children.DataTipTemplate.DataTipRows(4).Value='CData';
end
%% 2. Callback: When space bar is pushed, starts "datatips" mode %%%%%%%%%%%%%%%%%%
function isspace(hObject,~)
% check state space bar button: 0 - show datatips, 1: hide datatips
check_state=getGlobalx(1);
setGlobalx(1,check_state+1);
if check_state==0 % If global variable is 0, shows DataTips
dcm = datacursormode;
dcm.Enable = 'on';
dcm.UpdateFcn = @displayCoordinates; % per le coordinate
if isempty(hObject.Children(end).SelectedTab.Children(end).Children.Children)
waitforbuttonpress(); %to avoid errors ?
end
hObject.Children(end).SelectedTab.Children(end).Children.Children.Visible='on' ;
pause(0.01); drawnow;
else % If global variable is 1, hide DataTips
dcm = datacursormode;
dcm.Enable = 'off';
hObject.Children(end).SelectedTab.Children(end).Children.Children.Visible='off' ;
rotate3d on
pause(0.01); drawnow;
setGlobalx(1,0);
end
%%%
hManager = uigetmodemanager(hFig);
try
set(hManager.WindowListenerHandles, 'Enable', 'off'); % HG1
catch
[hManager.WindowListenerHandles.Enabled] = deal(false); % HG2
end
set(hFig, 'WindowKeyPressFcn', []);
set(hFig, 'KeyPressFcn', @isspace);
end
Asvin Kumar
Asvin Kumar am 22 Mär. 2021
Hey, this is going to be hard to debug. I'm out of bandwidth at the moment and won't be able to look into it immediately.
A few suggestions to make it easier for others in the community:
  1. Provide a way to reproduce the behaviour. Maybe provide some code which people can quickly execute and start tinkering with.
  2. Or, if possible, come up with a short demo of your problem by just using scatter plot like in this example.
  3. Provide more details on waitforbuttonpress() because it seems like you've added that to work around your problem. What does it do? Does it work?

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Mehr zu Interactive Control and Callbacks finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by