2.1 Printing Objects with Interpolated Shading

Problem

Although objects drawn with interpolated shading look good on the screen, objects which consist of a large number of interpolated patches generally take an unacceptably long time to print. This is not because the PostScript files are excessively large, but rather because most printers are overwhelmed by the computations required to determine the exact shading/coloring of each point. Unlike flat and faceted shading, in which the color of each patch is constant and specified directly in the PostScript code, the PostScript files generated for interpolated shading contain the color information of the patches' vertices. The interpolation calculations are done by the printer. This may result in extremely long print times for graphics using interpolated shading. In many cases, printers "time-out" (i.e., abort the print job) due to the long wait.

Solution

There are several possible workarounds for obtaining interpolated shaded figures:

Please note that this method may result in large PostScript files. In some UNIX environments, the default lpr command will not print files larger than 1 Mbyte. Files larger than 1 Mbyte can be printed via the lpr -s command (see the man pages for lpr).
/NI 16 def    % NI can be 4 (draft), 
8 (medium), or 16 (high-res)
Change the number to the desired resolution, save the file, and print. Below is a sample M-file to perform data interpolation.
***********************  APP_INT.M  **********************
function hfi = app_int(x,y,z,s,dc)
% This function approximates interpolated shading by 
% interpolating data and using flat shading.  The inputs
% are the data that was used to generate the original
% object, a scale factor, and a string that contains the
% drawing command. The function returns a handle to the new 
% object.
%
% Syntax 1:For just Z-Data (e.g., surf(z) => 
% app_int(z,s,dc)
% z = zdata, s = scaling factor and dc = drawing command used  
% to create the plot.
%
% Syntax 2: For x,y,z Data ( e.g., surf(x,y,z) ) => app_int
%(x,y,z,s,dc)
%
% Example 1: [x,y,z] = peaks;surf(z);shading interp
% app_int(z,3,'surf')   interpolate by a factor of 3
%
% Example 2: [x,y,z ] = peaks; surf(x,y,z); shading interp
% app_int(x,y,z,3,'surf')interpolate by a factor of 3
if ( nargin == 3 )
  dc = z;
  z = x;
  s = y;
  [m n] = size(z);
  x = 1:n; y = (1:m)';
  mscal = m*s;
  nscal = n*s;
  xi = linspace(1,n,nscal);
  yi = linspace(1,m,mscal)';
  zi = interp2(x,y,z,xi,yi);
  figure;
  cmd = ['hfi=' dc '(xi,yi,zi);'];
  eval(cmd);
  shading flat;
elseif ( nargin == 5 )
  [m n] = size(z);
  mscal = m*s;
  nscal = n*s;
  mint = min(min(x));
  maxt = max(max(x));
  xi = linspace(mint,maxt,mscal);
  mint = min(min(y));
  maxt = max(max(y));
  yi = linspace(mint,maxt,nscal)';
  zi = interp2(x,y,z,xi,yi);
  figure;
  cmd = ['hfi=' dc '(xi,yi,zi);'];
  eval(cmd);
  shading flat;
end
**********************  END OF FILE  *********************
On PC's, <ALT>+<Print Scrn> can be used to send a bitmap screen image to the clipboard. This image will include the window border. Import the image into a graphics package such as MS Paintbrush (included with MS Windows), in order to remove the window borders and print.

(c) Copyright 1994 by The MathWorks, Inc.