home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / l / l460 / 2.ddi / COLOR.DI$ / SHADING.M < prev    next >
Encoding:
Text File  |  1993-03-07  |  2.9 KB  |  84 lines

  1. function ret_type = shading(type)
  2. %SHADING Color shading mode.
  3. %    SHADING controls the color shading of SURFACE and PATCH objects.
  4. %    SURFACE and PATCH objects are created by the functions SURF, MESH,
  5. %    PCOLOR, FILL, and FILL3. 
  6. %
  7. %    SHADING FLAT sets the shading of the current graph to flat.
  8. %    SHADING INTERP sets the shading to interpolated.
  9. %    SHADING FACETED sets the shading to faceted, which is the default.
  10. %
  11. %    Flat shading is piecewise constant; each mesh line segment or
  12. %    surface patch has a constant color determined by the color value
  13. %    at the end point of the segment or the corner of the patch which
  14. %    has the smallest index or indices.
  15. %
  16. %    Interpolated shading, which is also known as Gouraud shading, is
  17. %    piecewise bilinear; the color in each segment or patch varies linearly
  18. %    and interpolates the end or corner values.
  19. %
  20. %    Faceted shading is flat shading with superimposed black mesh lines.
  21. %    This is often the most effective and is the default.
  22. %
  23. %    SHADING is an M-file that sets the EdgeColor and FaceColor properties
  24. %    of all SURFACE objects in the current axes. It sets them to the
  25. %    correct values that depend upon whether the SURFACE objects are
  26. %    representing meshes or surfaces.
  27. %
  28. %    See also SURF, MESH, PCOLOR, FILL, FILL3, SURFACE, PATCH.
  29.  
  30. %    Copyright (c) 1984-93 by The MathWorks, Inc.
  31.  
  32. ax = gca;
  33. kids = get(ax,'Children');
  34. fc = get(ax,'color');
  35. if strcmp(lower(fc),'none')
  36.     fc = get(gcf,'color');
  37. end
  38. imesh = [];
  39. isurf = [];
  40. itext = [];
  41. for i = 1:max(size(kids))
  42.     if(strcmp(lower(get(kids(i),'Type')), 'surface'))
  43.         face = lower(get(kids(i),'facecolor'));
  44.         if strcmp(face,'none')
  45.             imesh = [imesh ; kids(i)];
  46.         elseif strcmp(face,'texturemap')
  47.             itext = [itext; kids(i)];
  48.                 elseif ~isstr(face)
  49.                         if (all(face == fc)) 
  50.                 imesh = [imesh ; kids(i)];
  51.             else
  52.                 isurf = [isurf; kids(i)];
  53.             end
  54.         else
  55.             isurf = [isurf; kids(i)];
  56.         end
  57.     end
  58. end
  59.  
  60. if(nargin == 0)
  61.     ret_type = get(ax,'DefaultSurfaceFaceColor');
  62.     if(strcmp(ret_type, 'flat'))
  63.         if(strcmp(get(ax,'DefaultSurfaceEdgeColor'),'black'))
  64.             ret_type = 'faceted';
  65.         end
  66.     end
  67. else
  68.     if(strcmp(type, 'flat'))
  69.         if ~isempty(isurf),set(isurf,'facecolor','flat','edgecolor','none');end
  70.         if ~isempty(imesh),set(imesh,'facecolor',fc,'edgecolor','flat');end
  71.         if ~isempty(itext),set(itext,'edgecolor','none');end
  72.     elseif(strcmp(type, 'interp'))
  73.         if ~isempty(isurf),set(isurf,'facecolor','interp','edgecolor','none');end
  74.         if ~isempty(imesh),set(imesh,'facecolor',fc,'edgecolor','interp');end
  75.         if ~isempty(itext),set(itext,'edgecolor','interp');end
  76.     elseif(strcmp(type,'faceted'))
  77.         if ~isempty(isurf),set(isurf,'facecolor','flat','edgecolor','black');end
  78.         if ~isempty(imesh),set(imesh,'facecolor',fc,'edgecolor','flat');end
  79.         if ~isempty(itext),set(itext,'edgecolor','black');end
  80.     else
  81.         error('Shading methods are flat, faceted, and interp.');
  82.     end
  83. end
  84.