Home > bioelectromagnetism > gui_mesh_plot.m

gui_mesh_plot

PURPOSE ^

gui_mesh_plot - GUI for plotting meshes

SYNOPSIS ^

function [p] = gui_mesh_plot(p,mesh_plot_command,parent)

DESCRIPTION ^

 gui_mesh_plot - GUI for plotting meshes

 Usage: [p] = gui_mesh_plot(p,command,[parent])

 command   - either 'init' or 'plot'
 parent    - optional, GUI parent window

 The functionality is further described in mesh_plot

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function [p] = gui_mesh_plot(p,mesh_plot_command,parent)
0002 
0003 % gui_mesh_plot - GUI for plotting meshes
0004 %
0005 % Usage: [p] = gui_mesh_plot(p,command,[parent])
0006 %
0007 % command   - either 'init' or 'plot'
0008 % parent    - optional, GUI parent window
0009 %
0010 % The functionality is further described in mesh_plot
0011 %
0012 
0013 % $Revision: 1.1 $ $Date: 2004/11/12 01:32:35 $
0014 
0015 % Licence:  GNU GPL, no express or implied warranties
0016 % History:  02/2002, Darren.Weber_at_radiology.ucsf.edu
0017 %
0018 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0019 
0020 if ~exist('mesh_plot_command','var'),
0021   mesh_plot_command = 'init';
0022 end
0023 
0024 if ~exist('p','var'),
0025  [p] = mesh_open;
0026 elseif isempty(p),
0027  [p] = mesh_open(p);
0028 elseif isfield(p,'mesh'),
0029   if isfield(p.mesh,'data'),
0030     if isempty(p.mesh.data),
0031      [p] = mesh_open(p);
0032     end
0033   else
0034    [p] = mesh_open(p);
0035   end
0036 end
0037 
0038 
0039 switch mesh_plot_command,
0040   
0041   case 'init',
0042     
0043    [p] = mesh_plot(p);
0044     
0045     if exist('parent','var'),
0046       MESHPlot = INIT(p,parent);
0047     else
0048       MESHPlot = INIT(p);
0049     end
0050     
0051   case 'return',
0052     
0053     MESHPlot = get(gcbf,'Userdata');
0054     if isequal(get(MESHPlot.handles.Bhold,'Value'),0),
0055      [p] = gui_updateparent(MESHPlot);
0056       close gcbf;
0057     else
0058      [p] = gui_updateparent(MESHPlot,0);
0059     end
0060     fprintf('GUI_MESH_PLOT: Plot parameters returned.\n');
0061     
0062   otherwise,
0063     close(p.mesh.plot.fig);
0064     close gcbf;
0065 end
0066 
0067 return
0068 
0069 
0070 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0071 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0072 function [MESHPlot] = INIT(p,parent),
0073 
0074 % GUI General Parameters
0075 
0076 meshPlotPosition = get(p.mesh.plot.fig,'Position');
0077 
0078 GUIleft = meshPlotPosition(1) + meshPlotPosition(3) + (0.05 * meshPlotPosition(3));
0079 GUIbottom = meshPlotPosition(2);
0080 
0081 GUIwidth  = meshPlotPosition(3) / 2;
0082 GUIheight = meshPlotPosition(4);
0083 
0084 GUI = figure('Name','MESH Plot','Tag','MESH_PLOT',...
0085   'NumberTitle','off','units','pixels',...
0086   'MenuBar','none','Position',[GUIleft GUIbottom GUIwidth GUIheight]);
0087 
0088 
0089 set(GUI,'HandleVisibility','callback');
0090 
0091 MESHPlot.gui = GUI;
0092 
0093 Font.FontName   = 'Helvetica';
0094 Font.FontUnits  = 'Pixels';
0095 Font.FontSize   = 12;
0096 Font.FontWeight = 'normal';
0097 Font.FontAngle  = 'normal';
0098 
0099 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0100 % Mesh Data Selection and Parameters
0101 
0102 % Provide some GUI callbacks to change lighting...
0103 G.Fmesh = uicontrol('Parent',GUI,'Style','frame','Units','Normalized',Font, ...
0104   'Position',[.04 .62 .92 .36],...
0105   'TooltipString','Mesh Parameters',...
0106   'HorizontalAlignment','left');
0107 G.Tmesh = uicontrol('Parent',GUI,'Style','text','Units','Normalized',Font, ...
0108   'Position',[.06 .90 .4 .05],...
0109   'TooltipString','Mesh Parameters',...
0110   'String','Mesh','HorizontalAlignment','left');
0111 
0112 % Overlay checkbox
0113 G.Boverlay = uicontrol('Parent',GUI,'Style','checkbox','Units','Normalized', Font, ...
0114   'Position',[.50 .90 .4 .05],'String','Overlay','BusyAction','queue',...
0115   'TooltipString','Overlay MESH Plots',...
0116   'Value',p.mesh.plot.overlay,'HorizontalAlignment', 'center');
0117 
0118 % Mesh Type
0119 G.Title_data = uicontrol('Parent',GUI,'Style','text','Units','Normalized',Font, ...
0120   'Position',[.10 .82 .3 .05],...
0121   'String','Mesh Type:','HorizontalAlignment','left');
0122 G.PmeshType = uicontrol('Tag','PmeshType','Parent',GUI,'Style','popupmenu',...
0123   'Units','Normalized',Font,  ...
0124   'Position',[.50 .82 .4 .05],...
0125   'String',p.mesh.data.meshtype,'Value',p.mesh.current,...
0126   'TooltipString','Mesh/Tesselation Layer',...
0127   'Callback',strcat('MESHPlot = get(gcbf,''Userdata'');',...
0128   'MESHPlot.p.mesh.current = get(MESHPlot.handles.PmeshType,''Value''); ',...
0129   'MESHPlot.p.mesh.plot.overlay = get(MESHPlot.handles.Boverlay,''Value'');',...
0130   'MESHPlot.p = mesh_plot(MESHPlot.p);',...
0131   'set(gcbf,''Userdata'',MESHPlot); clear MESHPlot;'));
0132 
0133 G.Tedgecolor = uicontrol('Parent',GUI,'Style','text','Units','Normalized',Font, ...
0134   'Position',[.10 .75 .3 .05],...
0135   'TooltipString','Mesh Edge Color: 3 by 0-1 RGB float values or ''none''',...
0136   'String','Edge Color:','HorizontalAlignment','left');
0137 
0138 G.Eedgecolor = uicontrol('Parent',GUI,'Style','edit',...
0139   'Tag','p.mesh.plot.Hpatch.edgecolor','Units','Normalized',Font,  ...
0140   'Position',[.50 .75 .4 .05],...
0141   'String',p.mesh.plot.edgecolor,...
0142   'TooltipString','Mesh Edge Color: 0-1 RGB values or ''none''',...
0143   'Callback',strcat('MESHPlot = get(gcbf,''Userdata'');',...
0144   'MESHPlot.p.mesh.plot.edgecolor = get(MESHPlot.handles.Eedgecolor,''String'');',...
0145   'if findstr(MESHPlot.p.mesh.plot.edgecolor,''none''), ',...
0146   '   set(MESHPlot.p.mesh.plot.Hpatch{MESHPlot.p.mesh.current},''EdgeColor'',''none'');',...
0147   'else, ',...
0148   '   edgecolor = str2num(MESHPlot.p.mesh.plot.edgecolor); ',...
0149   '   if and(isequal(size(edgecolor,1),1),isequal(size(edgecolor,2),3)), ',...
0150   '      set(MESHPlot.p.mesh.plot.Hpatch{MESHPlot.p.mesh.current},''EdgeColor'',edgecolor);',...
0151   '   else, ',...
0152   '      msg = sprintf(''EdgeColor must be ''''none'''' or 1x3 element RGB values between 0-1\n'');',...
0153   '      warndlg(msg,''Mesh Plot Warning'');',...
0154   '   end; ',...
0155   'end; ',...
0156   'set(gcbf,''Userdata'',MESHPlot); clear edgecolor MESHPlot;'));
0157 
0158 G.Tfacecolor = uicontrol('Parent',GUI,'Style','text','Units','Normalized',Font, ...
0159   'Position',[.10 .70 .3 .05],...
0160   'TooltipString','Mesh Face Color: 3 by 0-1 RGB float values or ''none''',...
0161   'String','Face Color:','HorizontalAlignment','left');
0162 G.Efacecolor = uicontrol('Parent',GUI,'Style','edit',...
0163   'Tag','p.mesh.plot.Hpatch.facecolor','Units','Normalized',Font,  ...
0164   'Position',[.50 .70 .4 .05],...
0165   'String',sprintf('%2.1f %2.1f %2.1f',get(p.mesh.plot.Hpatch{p.mesh.current},'FaceColor')),...
0166   'TooltipString','Face Edge Color: 0-1 RGB values or ''none''',...
0167   'Callback',strcat('MESHPlot = get(gcbf,''Userdata'');',...
0168   'MESHPlot.p.mesh.plot.facecolor = get(MESHPlot.handles.Efacecolor,''String'');',...
0169   'if findstr(MESHPlot.p.mesh.plot.facecolor,''none''), ',...
0170   '   set(MESHPlot.p.mesh.plot.Hpatch{MESHPlot.p.mesh.current},''FaceColor'',''none'');',...
0171   'else, ',...
0172   '   facecolor = str2num(MESHPlot.p.mesh.plot.facecolor); ',...
0173   '   if and(isequal(size(facecolor,1),1),isequal(size(facecolor,2),3)), ',...
0174   '      set(MESHPlot.p.mesh.plot.Hpatch{MESHPlot.p.mesh.current},''FaceColor'',facecolor);',...
0175   '   else, ',...
0176   '      msg = sprintf(''FaceColor must be ''''none'''' or 1x3 element RGB values between 0-1\n'');',...
0177   '      warndlg(msg,''Mesh Plot Warning'');',...
0178   '   end; ',...
0179   'end; ',...
0180   'set(gcbf,''Userdata'',MESHPlot); clear facecolor MESHPlot;'));
0181 
0182 % Face Transparency...
0183 G.Tfacealpha = uicontrol('Parent',GUI,'Style','text','Units','Normalized',Font, ...
0184   'Position',[.10 .65 .3 .05],...
0185   'TooltipString','Face Transparency: 0 transparent, 1 opaque, 0-1 float',...
0186   'String','Face Alpha:','HorizontalAlignment','left');
0187 G.Efacealpha = uicontrol('Parent',GUI,'Style','edit',...
0188   'Tag','p.mesh.plot.Hpatch.facealpha','Units','Normalized',Font,  ...
0189   'Position',[.50 .65 .4 .05],...
0190   'String',sprintf('%2.1f',get(p.mesh.plot.Hpatch{p.mesh.current},'FaceAlpha')),...
0191   'TooltipString','Face Transparency: 0 transparent, 1 opaque, 0-1 float',...
0192   'Callback',strcat('MESHPlot = get(gcbf,''Userdata'');',...
0193   'MESHPlot.p.mesh.plot.facealpha = get(MESHPlot.handles.Efacealpha,''String'');',...
0194   'if MESHPlot.p.mesh.plot.facealpha, ',...
0195   '   facealpha = str2num(MESHPlot.p.mesh.plot.facealpha); ',...
0196   '   if isequal(size(facealpha),[1 1]), ',...
0197   '      set(MESHPlot.p.mesh.plot.Hpatch{MESHPlot.p.mesh.current},''FaceAlpha'',facealpha);',...
0198   '   else, ',...
0199   '      msg = sprintf(''FaceAlpha must be 1 element float values between 0-1\n'');',...
0200   '      warndlg(msg,''Mesh Plot Warning'');',...
0201   '   end; ',...
0202   'else, ',...
0203   '   set(MESHPlot.p.mesh.plot.Hpatch{MESHPlot.p.mesh.current},''FaceAlpha'',1);',...
0204   'end; ',...
0205   'set(gcbf,''Userdata'',MESHPlot); clear facealpha MESHPlot;'));
0206 
0207 
0208 
0209 % Provide some GUI callbacks to change lighting...
0210 G.Flight = uicontrol('Parent',GUI,'Style','frame','Units','Normalized',Font, ...
0211   'Position',[.04 .15 .92 .45],...
0212   'TooltipString','Lighting Parameters',...
0213   'HorizontalAlignment','left');
0214 G.Tlight = uicontrol('Parent',GUI,'Style','text','Units','Normalized',Font, ...
0215   'Position',[.06 .54 .45 .05],...
0216   'TooltipString','Lighting Parameters',...
0217   'String','Light','HorizontalAlignment','left');
0218 
0219 G.Tambient = uicontrol('Parent',GUI,'Style','text','Units','Normalized',Font, ...
0220   'Position',[.10 .45 .45 .05],...
0221   'TooltipString','Ambient Strength: 0-1 values',...
0222   'String','Ambient Strength:','HorizontalAlignment','left');
0223 G.Eambient = uicontrol('Parent',GUI,'Style','edit',...
0224   'Tag','p.mesh.plot.Hpatch.ambient','Units','Normalized',Font,  ...
0225   'Position',[.65 .45 .2 .05],...
0226   'String',sprintf('%2.1f',get(p.mesh.plot.Hpatch{p.mesh.current},'AmbientStrength')),...
0227   'TooltipString','Ambient Strength: 0-1 values',...
0228   'Callback',strcat('MESHPlot = get(gcbf,''Userdata'');',...
0229   'MESHPlot.p.mesh.plot.ambient = get(MESHPlot.handles.Eambient,''String'');',...
0230   'set(MESHPlot.p.mesh.plot.Hpatch{MESHPlot.p.mesh.current},''AmbientStrength'',str2num(MESHPlot.p.mesh.plot.ambient));',...
0231   'set(gcbf,''Userdata'',MESHPlot); clear MESHPlot;'));
0232 
0233 G.Tdiffuse = uicontrol('Parent',GUI,'Style','text','Units','Normalized',Font, ...
0234   'Position',[.10 .40 .45 .05],...
0235   'TooltipString','Diffuse Strength: 0-1 values',...
0236   'String','Diffuse Strength:','HorizontalAlignment','left');
0237 G.Ediffuse = uicontrol('Parent',GUI,'Style','edit',...
0238   'Tag','p.mesh.plot.Hpatch.diffuse','Units','Normalized',Font,  ...
0239   'Position',[.65 .40 .2 .05],...
0240   'String',sprintf('%2.1f',get(p.mesh.plot.Hpatch{p.mesh.current},'DiffuseStrength')),...
0241   'TooltipString','Diffuse Strength: 0-1 values',...
0242   'Callback',strcat('MESHPlot = get(gcbf,''Userdata'');',...
0243   'MESHPlot.p.mesh.plot.diffuse = get(MESHPlot.handles.Ediffuse,''String'');',...
0244   'set(MESHPlot.p.mesh.plot.Hpatch{MESHPlot.p.mesh.current},''DiffuseStrength'',str2num(MESHPlot.p.mesh.plot.diffuse));',...
0245   'set(gcbf,''Userdata'',MESHPlot); clear MESHPlot;'));
0246 
0247 G.Tspecular = uicontrol('Parent',GUI,'Style','text','Units','Normalized',Font, ...
0248   'Position',[.10 .35 .45 .05],...
0249   'TooltipString','Specular Strength: 0-1 values',...
0250   'String','Specular Strength:','HorizontalAlignment','left');
0251 G.Especular = uicontrol('Parent',GUI,'Style','edit',...
0252   'Tag','p.mesh.plot.Hpatch.specular','Units','Normalized',Font,  ...
0253   'Position',[.65 .35 .2 .05],...
0254   'String',sprintf('%2.1f',get(p.mesh.plot.Hpatch{p.mesh.current},'SpecularStrength')),...
0255   'TooltipString','Specular Strength: 0-1 values',...
0256   'Callback',strcat('MESHPlot = get(gcbf,''Userdata'');',...
0257   'MESHPlot.p.mesh.plot.specular = get(MESHPlot.handles.Especular,''String'');',...
0258   'set(MESHPlot.p.mesh.plot.Hpatch{MESHPlot.p.mesh.current},''SpecularStrength'',str2num(MESHPlot.p.mesh.plot.specular));',...
0259   'set(gcbf,''Userdata'',MESHPlot); clear MESHPlot;'));
0260 
0261 G.Tspecexp = uicontrol('Parent',GUI,'Style','text','Units','Normalized',Font, ...
0262   'Position',[.10 .30 .45 .05],...
0263   'TooltipString','Specular Exponent',...
0264   'String','Specular Exponent:','HorizontalAlignment','left');
0265 G.Especexp = uicontrol('Parent',GUI,'Style','edit',...
0266   'Tag','p.mesh.plot.Hpatch.specexp','Units','Normalized',Font,  ...
0267   'Position',[.65 .30 .2 .05],...
0268   'String',sprintf('%d',get(p.mesh.plot.Hpatch{p.mesh.current},'SpecularExponent')),...
0269   'TooltipString','Specular Exponent',...
0270   'Callback',strcat('MESHPlot = get(gcbf,''Userdata'');',...
0271   'MESHPlot.p.mesh.plot.specexp = get(MESHPlot.handles.Especexp,''String'');',...
0272   'set(MESHPlot.p.mesh.plot.Hpatch{MESHPlot.p.mesh.current},''SpecularExponent'',str2num(MESHPlot.p.mesh.plot.specexp));',...
0273   'set(gcbf,''Userdata'',MESHPlot); clear MESHPlot;'));
0274 
0275 G.Tspeccolor = uicontrol('Parent',GUI,'Style','text','Units','Normalized',Font, ...
0276   'Position',[.10 .20 .45 .08],...
0277   'TooltipString','Specular Color Reflectance: 0-1 values',...
0278   'String','Specular Color Reflectance:','HorizontalAlignment','left');
0279 G.Especcolor = uicontrol('Parent',GUI,'Style','edit',...
0280   'Tag','p.mesh.plot.Hpatch.speccolor','Units','Normalized',Font,  ...
0281   'Position',[.65 .21 .20 .07],...
0282   'String',sprintf('%2.1f',get(p.mesh.plot.Hpatch{p.mesh.current},'SpecularColorReflectance')),...
0283   'TooltipString','Specular Color Reflectance: 0-1 values',...
0284   'Callback',strcat('MESHPlot = get(gcbf,''Userdata'');',...
0285   'MESHPlot.p.mesh.plot.speccolor = get(MESHPlot.handles.Especcolor,''String'');',...
0286   'set(MESHPlot.p.mesh.plot.Hpatch{MESHPlot.p.mesh.current},''SpecularColorReflectance'',str2num(MESHPlot.p.mesh.plot.speccolor));',...
0287   'set(gcbf,''Userdata'',MESHPlot); clear MESHPlot;'));
0288 
0289 
0290 
0291 
0292 
0293 
0294 
0295 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0296 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0297 Font.FontWeight = 'bold';
0298 
0299 % RETURN, return file parameters
0300 G.Breturn = uicontrol('Parent',GUI,'Style','pushbutton','Units','Normalized', Font, ...
0301   'Position',[.05 .01 .275 .05],...
0302   'String','RETURN','BusyAction','queue',...
0303   'TooltipString','Return the plot parameters and close.',...
0304   'BackgroundColor',[0.0 0.5 0.0],...
0305   'ForegroundColor', [1 1 1], 'HorizontalAlignment', 'center',...
0306   'Callback',strcat('MESHPlot = get(gcbf,''Userdata'');',...
0307   'p = gui_mesh_plot(MESHPlot.p,''return'');',...
0308   'clear MESHPlot;'));
0309 
0310 % CANCEL, return file parameters
0311 G.Bcancel = uicontrol('Parent',GUI,'Style','pushbutton','Units','Normalized', Font, ...
0312   'Position',[.40 .01 .25 .05],...
0313   'String','CLOSE','BusyAction','queue',...
0314   'TooltipString','Close, do not return the plot parameters.',...
0315   'BackgroundColor',[0.75 0.0 0.0],...
0316   'ForegroundColor', [1 1 1], 'HorizontalAlignment', 'center',...
0317   'Callback',strcat('MESHPlot = get(gcbf,''Userdata'');',...
0318   'MESHPlot.p = gui_mesh_plot(MESHPlot.p,''close'');',...
0319   'clear MESHPlot;'));
0320 
0321 % Hold GUI Open checkbox
0322 G.Bhold = uicontrol('Parent',GUI,'Style','checkbox','Units','Normalized', Font, ...
0323   'Position',[.70 .01 .25 .05],'String','Hold','BusyAction','queue',...
0324   'TooltipString','MESH Plot GUI remains open after ''Return'' commands.',...
0325   'Value',p.hold,'HorizontalAlignment', 'center');
0326 
0327 
0328 % Store userdata
0329 if exist('parent','var'), MESHPlot.parent.gui = parent; end
0330 MESHPlot.handles = G;
0331 MESHPlot.p = p;
0332 set(GUI,'Userdata',MESHPlot);
0333 figure(MESHPlot.gui);
0334 
0335 return

Generated on Mon 15-Aug-2005 15:36:19 by m2html © 2003