Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: Speed of patch plots
Replies: 0

 Rick Gaudette Posts: 5 Registered: 12/7/04
Speed of patch plots
Posted: Sep 18, 1996 12:31 AM

Hello,

Does anyone know how to speed up the rendering of patch objects. I am
displaying complex numbers as arrow heads created with the patch function
where the direction of the arrow represents the phase and the color of the
arrow represents the amplitude. I have toyed with setting the gca's drawmode
to fast and turned the backingstore off without much improvemnt in speed.

I am running this code on an indigo2 (200MHz MIPS R4???). Displaying a 25x21
complex matrix takes about 3-5 seconds to image (much longer than surf of the
same size). The code is included below, as can be seen I am not using any
loops, patch called only once with all of the "patches" in the 3 matrix
arguments,
rePos + reArrow', imPos + imArrow', Colors(:)'

Any help would be much appreciated.

Thanks,
Rick Gaudette
rjg@cdsp.neu.edu

%ARROWS2 Represent a complex function of 2D data.
%
% hArrs = arrows2(fZ, Colors, Length)
%
% hArrs Handles to the arrow patches.
%
% fZ The complex function to be plotted.
%
% Colors [OPTIONAL]: A real matrix the same size as fZ that specifies
% the color to use for each arrow. This is used instead of the
% amplitude of fZ.
%
% Length [OPTIONAL] : A real matrix the same size as fZ that specifies
% the length to use for each arrow. This is used instead of the
% amplitude of fZ.
%
% ARROWS2 displays a complex function of 2 dimensions using amplitude
% and phase. A triangular arrowhead for the phase of each point
% and color for the amplitude. The arrow heads are drawn using
% MATLAB's patch function. Note that the Y direction is also reversed so
% that the orientation is the same as the matrix.
%
%
% Calls: none.
%
% Bugs: kind of slow, seem to be due to MATLABs patch function.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \$Author: rjg \$
%
% \$Date: 1996/09/18 00:46:25 \$
%
% \$Revision: 1.4 \$
%
% \$Log: arrows2.m,v \$
% Revision 1.4 1996/09/18 00:46:25 rjg
% Add another argument to control the length of the arrows.
%
% Revision 1.3 1996/09/17 00:58:25 rjg
% Added a second argument to provide for a different coloring than
% the amplitude.
%
% Revision 1.2 1996/09/16 19:26:56 rjg
% Fixed row & column indexing.
% Calling convention switched to complex data.
%
% Revision 1.1 1996/09/16 15:21:38 rjg
% Initial revision
%
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function h = arrows2(fZ, Colors, Length)

%%
%%
%% Get the dimension of the functions
%%
[nImag nReal] = size(fZ);

%%
%% Generate a model arrow
%% - top row is horizontal coordinates
%% - bottom row is vertical coordinates
%% - columns is the number of points in the patch
%%
Model = [-0.5 0.5 -0.5;
-0.25 0 0.25];

[junk nModPoints] = size(Model);

%%
%% Compute the angles & magnitudes of each element of the function
%%
Angles = angle(fZ);
Mag = abs(fZ);
MagNorm = Mag ./ matmax(Mag);

if nargin < 2,
Colors = abs(fZ);
end

%%
%% Where magnitude is zero make it infinity so that it will disappear.
%%
idxZeros = find((Mag == 0));
Colors(idxZeros) = ones(size(idxZeros)) * inf - inf;

%%
%% Rotate an image of each arrow according to the phase at each sample point
%%
%% - the rational operator is reversed becuse the ydir property is reversed
%%
Angles = Angles(:);
reArrow = [cos(Angles) sin(Angles)] * Model;
imArrow = [-sin(Angles) cos(Angles)] * Model;

%%
%% If the length argument is supplied scale the arrows.
%%
if nargin > 2,
Length = Length (:) ./ matmax(abs(Length)) * ones(1, nModPoints);
reArrow = reArrow .* Length;
imArrow = imArrow .* Length;
end

%%
%% Offset each arrow according to its sample position
%%
[rePos imPos] = meshgrid([1:nReal], [1:nImag]);
rePos = ones(nModPoints, 1) * rePos(:)';
imPos = ones(nModPoints, 1) * imPos(:)';

%%
%% Draw the arrows as patch objects
%%
h = patch(rePos + reArrow', imPos + imArrow', Colors(:)');
set(gca, 'ydir', 'reverse');