Home > utils > unfreezeColors.m

unfreezeColors

PURPOSE ^

unfreezeColors Restore colors of a plot to original indexed color. (v2.3)

SYNOPSIS ^

function unfreezeColors(h)

DESCRIPTION ^

 unfreezeColors  Restore colors of a plot to original indexed color. (v2.3)

   Useful if you want to apply a new colormap to plots whose
       colors were previously frozen with freezeColors.

   Usage:
       unfreezeColors          unfreezes all objects in current axis, 
       unfreezeColors(axh)     same, but works on axis axh. axh can be vector.
       unfreezeColors(figh)    same, but for all objects in figure figh.

       Has no effect on objects on which freezeColors was not already called.


   See also freezeColors, freezeColors_demo, freezeColors_pub.html.


   John Iversen (iversen@nsi.edu) 3/23/05

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function unfreezeColors(h)
0002 % unfreezeColors  Restore colors of a plot to original indexed color. (v2.3)
0003 %
0004 %   Useful if you want to apply a new colormap to plots whose
0005 %       colors were previously frozen with freezeColors.
0006 %
0007 %   Usage:
0008 %       unfreezeColors          unfreezes all objects in current axis,
0009 %       unfreezeColors(axh)     same, but works on axis axh. axh can be vector.
0010 %       unfreezeColors(figh)    same, but for all objects in figure figh.
0011 %
0012 %       Has no effect on objects on which freezeColors was not already called.
0013 %
0014 %
0015 %   See also freezeColors, freezeColors_demo, freezeColors_pub.html.
0016 %
0017 %
0018 %   John Iversen (iversen@nsi.edu) 3/23/05
0019 %
0020 
0021 %   Changes:
0022 %   JRI 9/1/06 now restores any object with frozen CData;
0023 %           can unfreeze an entire figure at once
0024 
0025 % Free for all uses, but please retain the following:
0026 %
0027 %   Original Author:
0028 %   John Iversen, 2005-7
0029 %   john_iversen@post.harvard.edu
0030 
0031 error(nargchk(0,1,nargin,'struct'))
0032 
0033 appdatacode = 'JRI__freezeColorsData';
0034 
0035 %default: operate on gca
0036 if nargin < 1,
0037     h = gca;
0038 end
0039 
0040 if ~ishandle(h),
0041      error('JRI:unfreezeColors:invalidHandle',...
0042             'The argument must be a valid graphics handle to a figure or axis')
0043 end
0044 
0045 %if h is a figure, loop on its axes
0046 if strcmp(get(h,'type'),'figure'),
0047     h = get(h,'children');
0048 end
0049 
0050 for h1 = h', %loop on axes
0051 
0052     %process all children, acting only on those with saved CData
0053     %   ( in appdata JRI__freezeColorsData)
0054     ch = findobj(h1);
0055     
0056     for hh = ch',
0057         
0058         %some object handles may be invalidated when their parent changes
0059         %   (e.g. restoring colors of a scattergroup unfortunately changes
0060         %   the handles of all its children). So, first check to make sure
0061         %   it's a valid handle
0062         if ishandle(hh)
0063             if isappdata(hh,appdatacode),
0064                 ad = getappdata(hh,appdatacode);
0065                 %get oroginal cdata
0066                 %patches have to be handled separately (see note in freezeColors)
0067                 if ~strcmp(get(hh,'type'),'patch'),
0068                     cdata = get(hh,'CData');
0069                 else
0070                     cdata = get(hh,'faceVertexCData');
0071                     cdata = permute(cdata,[1 3 2]);
0072                 end
0073                 indexed = ad{1};
0074                 scalemode = ad{2};
0075                 
0076                 %size consistency check
0077                 if all(size(indexed) == size(cdata(:,:,1))),
0078                     %ok, restore indexed cdata
0079                     if ~strcmp(get(hh,'type'),'patch'),
0080                         set(hh,'CData',indexed);
0081                     else
0082                         set(hh,'faceVertexCData',indexed);
0083                     end
0084                     %restore cdatamapping, if needed
0085                     g = get(hh);
0086                     if isfield(g,'CDataMapping'),
0087                         set(hh,'CDataMapping',scalemode);
0088                     end
0089                     %clear appdata
0090                     rmappdata(hh,appdatacode)
0091                 else
0092                     warning('JRI:unfreezeColors:internalCdataInconsistency',...
0093                         ['Could not restore indexed data: it is the wrong size. ' ...
0094                         'Were the axis contents changed since the call to freezeColors?'])
0095                 end
0096                 
0097             end %test if has our appdata
0098         end %test ishandle
0099 
0100     end %loop on children
0101 
0102 end %loop on axes
0103

Generated on Wed 20-Sep-2023 04:00:50 by m2html © 2003