0001 function mouse_rotate(command,H)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034 if ~exist('command','var'), command = 'init'; end
0035
0036
0037 command = lower(command);
0038
0039 switch command,
0040
0041 case 'init',
0042
0043 if exist('H','var'),
0044 if ~isempty(H),
0045 H = INIT(H);
0046 end
0047 else
0048 H = get(gcbf,'userdata');
0049 H = INIT(H);
0050 end
0051
0052 case 'up',
0053
0054 if ~exist('H','var'), H = get(gcbf,'userdata'); end
0055 if isempty(H), H = get(gcbf,'userdata'); end
0056 if isempty(H), H = get(gcf, 'userdata'); end
0057
0058
0059
0060
0061 if isempty(get(H.gui,'WindowButtonMotionFcn')),
0062 set(H.gui,'WindowButtonMotionFcn','mouse_rotate(''rotate'');');
0063
0064
0065 else
0066 H.pos.current = get(H.axis,'View');
0067
0068 set(H.gui,'WindowButtonMotionFcn',[]);
0069
0070
0071 end
0072
0073 case 'rotate',
0074
0075 if ~exist('H','var'), H = get(gcbf,'userdata'); end
0076 if isempty(H), H = get(gcbf,'userdata'); end
0077 if isempty(H), H = get(gcf, 'userdata'); end
0078
0079
0080
0081
0082 H.pos.fig = get(H.gui,'position');
0083 H.pos.mouse = get(0,'pointerlocation');
0084 H.pos.relative = -1 * (((H.pos.mouse(1:2) - H.pos.fig(1:2))./ H.pos.fig(3:4))-.5).*[360,190];
0085 set(H.axis,'View',H.pos.relative);
0086 if ishandle(H.Az), set(H.Az,'String',sprintf('Az = %4.0f',H.pos.relative(1))); end
0087 if ishandle(H.El), set(H.El,'String',sprintf('El = %4.0f',H.pos.relative(2))); end
0088
0089
0090 if isfield(H,'light'),
0091 if ishandle(H.light), delete(H.light); end
0092 H.light = camlight('headlight','infinite');
0093 set(H.light,'color',[1 1 1]/length(H.light)/1.2);
0094 end
0095
0096
0097
0098
0099
0100 set(H.gui,'userdata',H);
0101
0102 case 'view',
0103
0104 if ~exist('H','var'), H = get(gcbf,'userdata'); end
0105 if isempty(H), H = get(gcbf,'userdata'); end
0106 if isempty(H), H = get(gcf, 'userdata'); end
0107
0108 v = get(H.View,'Value');
0109 set(H.axis,'View',H.data.view(v,:));
0110 set(H.Az,'String',sprintf('Az = %4.0f',H.data.view(v,1)));
0111 set(H.El,'String',sprintf('El = %4.0f',H.data.view(v,2)));
0112
0113
0114 AC = get(H.axis,'Children');
0115 for c = 1:length(AC),
0116 ctype = get(AC(c),'type');
0117 if isequal(ctype,'light'),
0118 delete(AC(c));
0119 end
0120 end
0121
0122
0123 H.light = camlight('headlight','infinite');
0124 set(H.light,'color',[1 1 1]/length(H.light)/1.2);
0125
0126 set(H.gui,'userdata',H);
0127
0128
0129 otherwise,
0130
0131 end
0132
0133 return
0134
0135
0136
0137
0138
0139
0140
0141 function [H] = INIT(H),
0142
0143
0144
0145
0146 if isfield(H,'El'),
0147 if ~isempty(H.El),
0148 return;
0149 end
0150 end
0151
0152 H.gui = gcf;
0153 H.axis = gca;
0154
0155 set(H.gui,'DoubleBuffer','on','WindowButtonDownFcn','mouse_rotate(''up''); ');
0156
0157
0158 menu=uicontextmenu;
0159 a=uimenu(menu,'Label','Rotate','Callback','mouse_rotate; ');
0160 if isempty(get(H.gui,'uicontextmenu')),
0161 set(H.gui,'uicontextmenu',menu);
0162 end
0163 if isempty(get(H.axis,'uicontextmenu')),
0164 set(H.axis,'uicontextmenu',menu);
0165 axsibs = get(H.axis,'Children');
0166 for i=1:length(axsibs),
0167 type = get(axsibs(i),'Type');
0168 if isequal(type,'patch'),
0169 if isempty(get(axsibs(i),'uicontextmenu')),
0170 set(axsibs(i),'uicontextmenu',menu);
0171 end
0172 end
0173 end
0174 end
0175
0176
0177 bgcolor = get(H.gui,'Color');
0178
0179 black = find(bgcolor <= .6);
0180 fgcolor = [0 0 0];
0181 if length(black)>2, fgcolor = [1 1 1]; end
0182
0183 Font.FontName = 'Helvetica';
0184 Font.FontUnits = 'Pixels';
0185 Font.FontSize = 12;
0186 Font.FontWeight = 'bold';
0187 Font.FontAngle = 'normal';
0188
0189 H.Az = uicontrol('Parent',H.gui,'Style','text',Font,...
0190 'Units','Normalized','Position',[.05 .0 .1 .05],...
0191 'BackGroundColor',bgcolor,...
0192 'ForeGroundColor',fgcolor,...
0193 'String','','TooltipString','Azimuth','HorizontalAlignment','left');
0194 H.El = uicontrol('Parent',H.gui,'Style','text',Font,...
0195 'Units','Normalized','Position',[.15 .0 .1 .05],...
0196 'BackGroundColor',bgcolor,...
0197 'ForeGroundColor',fgcolor,...
0198 'String','','TooltipString','Elevation','HorizontalAlignment','left');
0199
0200 H.Info = uicontrol('Parent',H.gui,'Style','radiobutton',Font,...
0201 'Units','Normalized','Position',[.65 .0 .1 .05],...
0202 'HorizontalAlignment','left',...
0203 'BackGroundColor',bgcolor,...
0204 'ForeGroundColor',fgcolor,...
0205 'String','Rotate','Value',1,...
0206 'TooltipString','When on, click in figure to switch on/off 3D rotation.',...
0207 'Callback',strcat('H = get(gcbf,''userdata''); ',...
0208 'rotate = get(H.Info,''Value''); ',...
0209 'if rotate, ',...
0210 'set(H.gui,''WindowButtonDownFcn'',''mouse_rotate(''''up'''');''); ',...
0211 'else, ',...
0212 'set(H.gui,''WindowButtonDownFcn'',[]); ',...
0213 'set(H.gui,''WindowButtonMotionFcn'',[]); ',...
0214 'end; ',...
0215 'clear H rotate;'));
0216
0217 H.data.viewstr = {'2D' '3D' 'Top' 'Bottom' 'Front' 'Back' 'Left' 'Right'};
0218 H.data.view = [ 0 90; -37.5 30; 0 90; 0 -90; 180 0; 0 0; -90 0; 90 0 ];
0219
0220 H.View = uicontrol('Parent',H.gui,'Style','Popup',...
0221 'Units','Normalized','Position',[.78 .0 .1 .05],...
0222 'Tag','VIEW','BackGroundColor','w',...
0223 'TooltipString','Select view.',...
0224 'String',H.data.viewstr,...
0225 'CallBack','mouse_rotate(''view'');');
0226
0227 H.RClose = uicontrol('Parent',H.gui,'Style','pushbutton',...
0228 'Units','Normalized','Position',[.9 .0 .1 .05],...
0229 'String','Close','Value',0,...
0230 'TooltipString','Use right click context menu after ''Close'' to get 3D rotation back.',...
0231 'Callback',strcat('H = get(gcbf,''userdata''); ',...
0232 'delete(H.RClose); delete(H.Info); ',...
0233 'delete(H.El); delete(H.Az); ',...
0234 'delete(H.View); ',...
0235 'fields = fieldnames(H); ',...
0236 'trashfields(1) = strmatch(''El'', fields,''exact''); ',...
0237 'trashfields(2) = strmatch(''Az'', fields,''exact''); ',...
0238 'trashfields(3) = strmatch(''Info'', fields,''exact''); ',...
0239 'trashfields(4) = strmatch(''View'', fields,''exact''); ',...
0240 'trashfields(5) = strmatch(''RClose'',fields,''exact''); ',...
0241 'trashfields(6) = strmatch(''pos'',fields,''exact''); ',...
0242 'H = setfield(H,char(fields(trashfields(1))),[]); ',...
0243 'H = setfield(H,char(fields(trashfields(2))),[]); ',...
0244 'H = setfield(H,char(fields(trashfields(3))),[]); ',...
0245 'H = setfield(H,char(fields(trashfields(4))),[]); ',...
0246 'H = setfield(H,char(fields(trashfields(5))),[]); ',...
0247 'H = setfield(H,char(fields(trashfields(6))),[]); ',...
0248 'H.data = setfield(H.data,''view'',[]); ',...
0249 'H.data = setfield(H.data,''viewstr'',[]); ',...
0250 'set(H.gui,''WindowButtonMotionFcn'',[]); ',...
0251 'set(H.gui,''WindowButtonDownFcn'',[]); ',...
0252 'set(H.gui,''WindowButtonUpFcn'',[]); ',...
0253 'set(H.gui,''userdata'',H); clear H trashfields fields; '));
0254
0255 H.pos.current = get(H.axis,'View');
0256 set(H.Az,'String',sprintf('Az = %4.0f',H.pos.current(1)));
0257 set(H.El,'String',sprintf('El = %4.0f',H.pos.current(2)));
0258
0259 set(H.gui,'userdata',H);
0260 return