annotate Problems/private/thumbPlot.m @ 51:217a33ac374e

(none)
author idamnjanovic
date Mon, 14 Mar 2011 16:52:27 +0000
parents
children
rev   line source
idamnjanovic@51 1 function P = thumbPlot(P,x,y,color)
idamnjanovic@51 2
idamnjanovic@51 3 % Copyright 2008, Ewout van den Berg and Michael P. Friedlander
idamnjanovic@51 4 % http://www.cs.ubc.ca/labs/scl/sparco
idamnjanovic@51 5 % $Id: thumbPlot.m 1040 2008-06-26 20:29:02Z ewout78 $
idamnjanovic@51 6
idamnjanovic@51 7 m = size(P,1);
idamnjanovic@51 8 n = size(P,2);
idamnjanovic@51 9 if (size(P,3) == 0) & (length(color) == 3)
idamnjanovic@51 10 % Convert to gray-scale
idamnjanovic@51 11 color = 0.30*color(1) + 0.59*color(2) + 0.11*color(3);
idamnjanovic@51 12 end
idamnjanovic@51 13
idamnjanovic@51 14 mnx = min(x); % Minimum x
idamnjanovic@51 15 mxx = max(x); % Maximum x
idamnjanovic@51 16 mny = min(y); % Minimum y
idamnjanovic@51 17 mxy = max(y); % Maximum y
idamnjanovic@51 18 dy = (mxy - mny) * 0.1; % Offset on vertical axis
idamnjanovic@51 19 sx = (mxx - mnx) * 1.0; % Scale of horizontal axis
idamnjanovic@51 20 sy = (mxy - mny) * 1.2; % Scale of vertical axis
idamnjanovic@51 21
idamnjanovic@51 22 if (sx < 1e-6), sx = 1; end
idamnjanovic@51 23 if (sy < 1e-6), sy = 1; end
idamnjanovic@51 24
idamnjanovic@51 25 for i=1:length(x)-1
idamnjanovic@51 26 x0 = floor(1 + (n-1) * (x(i ) - mnx) / sx);
idamnjanovic@51 27 x1 = floor(1 + (n-1) * (x(i+1) - mnx) / sx);
idamnjanovic@51 28 y0 = floor( (n-1) * (y(i ) - mny + dy) / sy);
idamnjanovic@51 29 y1 = floor( (n-1) * (y(i+1) - mny + dy) / sy);
idamnjanovic@51 30
idamnjanovic@51 31 samples = 1+2*max(abs(x1-x0)+1,abs(y1-y0)+1);
idamnjanovic@51 32 c = linspace(0,1,samples);
idamnjanovic@51 33 idx = round((1-c)*x0 + c*x1);
idamnjanovic@51 34 idy = n - round((1-c)*y0 + c*y1);
idamnjanovic@51 35 for j=1:samples
idamnjanovic@51 36 P(idy(j),idx(j),:) = color;
idamnjanovic@51 37 end
idamnjanovic@51 38 end