annotate private/EDB1makesnapshot.m @ 18:2d5f50205527 jabuilder_int tip

Escape the trailing backslash as well
author Chris Cannam
date Tue, 30 Sep 2014 16:23:00 +0100
parents 90220f7249fc
children
rev   line source
tp@0 1 function snapshot = EDB1makesnapshot(firstirfile,xvec,yvec,timestep,filtir,maxvalue,viewpoint,...
tp@0 2 outlinecorners,noutlinepoints,sourcepoint,typeofir,windowsize,ampexp)
tp@0 3 % EDB1makesnapshot - Makes a snapshot of a sound field based on IRs.
tp@0 4 %
tp@0 5 % Input parameters:
tp@0 6 % firstirfile The first of the IR files
tp@0 7 % xvec, yvec The ranges of x- and y-values of the receiver positions
tp@0 8 % timestep The time step to plot
tp@0 9 % filtir A window to filter with
tp@0 10 % maxvalue [1,2] The minimum and maximum amplitude in the plot
tp@0 11 % viewpoint The point to view from [x y z]
tp@0 12 % outlinecorners A matrix of corners which will be plotted as an outline
tp@0 13 % in the form [x1 y1;x2 y2;x3 y3;...]
tp@0 14 % If the matrix has more columns than two, each pair of
tp@0 15 % column will be plotted as a separate outline, and they
tp@0 16 % will not be tied together.
tp@0 17 % noutlinepoints A list with the number of points in each column pair.
tp@0 18 % sourcepoint The [x y z] coordinates of the source.
tp@0 19 % typeofir 't' (default), 'g' (geom), 'f' (direct sound), 'd'
tp@0 20 % (diffracted), 'c' (direct sound + geom)
tp@0 21 % windowsize 's', 'm' or 'l' or 'x'
tp@0 22 % ampexp (optional) If a value is given here, the signal will be
tp@0 23 % plotted as abs(pressure)^ampexp, so that if ampexp =
tp@0 24 % 0.5, sqrt(abs(pressure)) will be plotted. If no value
tp@0 25 % is given, or the value zero is given, the linear pressure will be plotted.
tp@0 26 %
tp@0 27 % Output parameters:
tp@0 28 % snapshot A snapshot, in the format which can be played by the
tp@0 29 % command surf(xvec,yvec,snapshot).
tp@0 30 %
tp@0 31 % Uses functions EDB1strpend
tp@0 32 %
tp@0 33 % ----------------------------------------------------------------------------------------------
tp@0 34 % This file is part of the Edge Diffraction Toolbox by Peter Svensson.
tp@0 35 %
tp@0 36 % The Edge Diffraction Toolbox is free software: you can redistribute it and/or modify
tp@0 37 % it under the terms of the GNU General Public License as published by the Free Software
tp@0 38 % Foundation, either version 3 of the License, or (at your option) any later version.
tp@0 39 %
tp@0 40 % The Edge Diffraction Toolbox is distributed in the hope that it will be useful,
tp@0 41 % but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
tp@0 42 % FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
tp@0 43 %
tp@0 44 % You should have received a copy of the GNU General Public License along with the
tp@0 45 % Edge Diffraction Toolbox. If not, see <http://www.gnu.org/licenses/>.
tp@0 46 % ----------------------------------------------------------------------------------------------
tp@0 47 % Peter Svensson (svensson@iet.ntnu.no) 20051013
tp@0 48 %
tp@0 49 % M = EDB1snapshot(firstirfile,xvec,yvec,starttimestep,ntimesteps,filtir,maxvalue,viewpoint
tp@0 50 % outlinecorners,noutlinepoints,sourcepoint,typeofir,windowsize,ampexp);
tp@0 51
tp@0 52 disp('*************************************')
tp@0 53 disp('*')
tp@0 54 disp('* Creating a snapshot....')
tp@0 55 disp(' ')
tp@0 56
tp@0 57
tp@0 58 %--------------------------------------------------------------
tp@0 59 % Extract the filename stem
tp@0 60
tp@0 61 if nargin == 0
tp@0 62 [firstirfile,irfilepath] = uigetfile('*ir.mat','Please select the first irfile');
tp@0 63 [irfilepath,temp1,temp2] = fileparts(irfilepath);
tp@0 64 if ~isstr(firstirfile) | isempty(firstirfile)
tp@0 65 return
tp@0 66 end
tp@0 67 else
tp@0 68 [irfilepath,firstirfile,fileext] = fileparts(firstirfile);
tp@0 69 irfilepath = [irfilepath,filesep];
tp@0 70 firstirfile = [firstirfile,fileext];
tp@0 71 end
tp@0 72
tp@0 73 if nargin < 11
tp@0 74 typeofir = 't';
tp@0 75 windowsize = 's';
tp@0 76 ampexp = 0;
tp@0 77 else
tp@0 78 typeofir = lower(typeofir(1));
tp@0 79 if nargin < 12
tp@0 80 windowsize = 's';
tp@0 81 ampexp = 0;
tp@0 82 else
tp@0 83 windowsize = lower(windowsize(1));
tp@0 84 if nargin < 13
tp@0 85 ampexp = 0;
tp@0 86 else
tp@0 87 if ampexp < 0
tp@0 88 error('ERROR: ampexp must be larger than, or equal to, zero')
tp@0 89 end
tp@0 90 end
tp@0 91 end
tp@0 92 end
tp@0 93
tp@0 94 filestem = EDB1strpend(firstirfile,'_ir');
tp@0 95 iv = find(filestem=='_');
tp@0 96 iv = iv(length(iv));
tp@0 97 firstnumber = str2num(filestem(iv+1:length(filestem)));
tp@0 98 filestem = filestem(1:iv);
tp@0 99
tp@0 100 nx = length(xvec);
tp@0 101 ny = length(yvec);
tp@0 102 nfiles = nx*ny;
tp@0 103
tp@0 104 loadcommandbase = ['load ',irfilepath,filestem];
tp@0 105
tp@0 106 %--------------------------------------------------------------
tp@0 107 % Read the files, filter and store
tp@0 108
tp@0 109 Bigir = zeros(nfiles,1);
tp@0 110
tp@0 111 disp(' Loading the files, starting with:')
tp@0 112 for ii = 1:nfiles
tp@0 113 eval([loadcommandbase,sprintf('%.0f',ii),'_ir.mat'])
tp@0 114 if typeofir == 'f'
tp@0 115 irtot = irdirect;
tp@0 116 elseif typeofir == 'g'
tp@0 117 irtot = irgeom;
tp@0 118 elseif typeofir == 'c'
tp@0 119 irtot = irgeom + irdirect;
tp@0 120 elseif typeofir == 'd',
tp@0 121 irtot = irdiff;
tp@0 122 end
tp@0 123
tp@0 124 if any(irtot)
tp@0 125
tp@0 126 if length(irtot) > timestep
tp@0 127 irtot = irtot(1:timestep);
tp@0 128 elseif length(irtot) < timestep
tp@0 129 irtot = [irtot;zeros(timestep-length(irtot),1)];
tp@0 130 end
tp@0 131
tp@0 132 irsamplevalue = sum(irtot([timestep:-1:timestep-length(filtir)+1]).*filtir);
tp@0 133 else
tp@0 134 irsamplevalue = 0;
tp@0 135 end
tp@0 136
tp@0 137 if ampexp == 0
tp@0 138 Bigir(ii) = irsamplevalue;
tp@0 139 else
tp@0 140 Bigir(ii) = (abs(irsamplevalue)).^ampexp;
tp@0 141 end
tp@0 142
tp@0 143 end
tp@0 144
tp@0 145 disp(' ... files are loaded.')
tp@0 146
tp@0 147
tp@0 148 if length(maxvalue) < 2
tp@0 149 maxvalue = [maxvalue(1) max(Bigir)];
tp@0 150 end
tp@0 151
tp@0 152 %--------------------------------------------------------------
tp@0 153 % Prepare the outline plotting
tp@0 154
tp@0 155 opengl neverselect
tp@0 156
tp@0 157 snapshot = reshape(Bigir,ny,nx);
tp@0 158
tp@0 159 [noutlinerows,ncolumns] = size(outlinecorners);
tp@0 160 noutlines = floor(ncolumns/2);
tp@0 161 if noutlines == 1
tp@0 162 outlinecorners = [outlinecorners;outlinecorners(1,:)];
tp@0 163 noutlinepoints = noutlinepoints+1;
tp@0 164 end
tp@0 165
tp@0 166 axisvalues = [min(xvec) max(xvec) min(yvec) max(yvec) maxvalue(1) maxvalue(2)];
tp@0 167 figure(1)
tp@0 168 clf
tp@0 169
tp@0 170 xyaspectratio = abs(max(xvec)-min(xvec))/abs(max(yvec)-min(yvec));
tp@0 171
tp@0 172 windowheight = 675;
tp@0 173 windowwidth = windowheight*xyaspectratio;
tp@0 174
tp@0 175 if windowwidth > 800
tp@0 176 scaledownfactor = windowwidth/800;
tp@0 177 windowwidth = windowwidth/scaledownfactor;
tp@0 178 windowheight = windowheight/scaledownfactor;
tp@0 179 end
tp@0 180
tp@0 181 windowpos = [380 80];
tp@0 182 if windowsize == 's'
tp@0 183 windowwidth = windowwidth/2;
tp@0 184 windowheight = windowheight/2;
tp@0 185 elseif windowsize == 'm'
tp@0 186 windowwidth = windowwidth/1.41;
tp@0 187 windowheight = windowheight/1.41;
tp@0 188 elseif windowsize == 'x'
tp@0 189 windowwidth = windowwidth*1.41;
tp@0 190 windowheight = windowheight*1.41;
tp@0 191 windowpos(1) = 100;
tp@0 192 end
tp@0 193
tp@0 194 set(1,'Position',[windowpos(1:2) windowwidth windowheight])
tp@0 195
tp@0 196 snapshot = reshape(Bigir,ny,nx);
tp@0 197 surf(xvec,yvec,snapshot);
tp@0 198
tp@0 199 shading interp
tp@0 200 colormap('jet')
tp@0 201 caxis([maxvalue(1) maxvalue(2)])
tp@0 202 axis(axisvalues);
tp@0 203 axis off
tp@0 204 view(viewpoint)
tp@0 205
tp@0 206 if noutlines > 0
tp@0 207 for kk = 1:noutlines
tp@0 208 for ll = 1:noutlinepoints(kk)-1
tp@0 209 H = line([outlinecorners(ll,(kk-1)*2+1) outlinecorners(ll+1,(kk-1)*2+1)],[outlinecorners(ll,(kk-1)*2+2) outlinecorners(ll+1,(kk-1)*2+2)],[0 0]);
tp@0 210 set(H,'LineWidth',4);
tp@0 211 set(H,'Color',[1 1 0]);
tp@0 212 H = line([outlinecorners(ll,(kk-1)*2+1) outlinecorners(ll+1,(kk-1)*2+1)],[outlinecorners(ll,(kk-1)*2+2) outlinecorners(ll+1,(kk-1)*2+2)],2*[maxvalue(2) maxvalue(2)]);
tp@0 213 set(H,'LineWidth',4);
tp@0 214 set(H,'Color',[1 1 0]);
tp@0 215 H = line([outlinecorners(ll,(kk-1)*2+1) outlinecorners(ll,(kk-1)*2+1)],[outlinecorners(ll,(kk-1)*2+2) outlinecorners(ll,(kk-1)*2+2)],[0 2*maxvalue(2)]);
tp@0 216 set(H,'LineWidth',4);
tp@0 217 set(H,'Color',[1 1 0]);
tp@0 218 end
tp@0 219 H = line([outlinecorners(ll+1,(kk-1)*2+1) outlinecorners(ll+1,(kk-1)*2+1)],[outlinecorners(ll+1,(kk-1)*2+2) outlinecorners(ll+1,(kk-1)*2+2)],[0 2*maxvalue(2)]);
tp@0 220 set(H,'LineWidth',4);
tp@0 221 set(H,'Color',[1 1 0]);
tp@0 222 end
tp@0 223 end
tp@0 224 if ~isempty(sourcepoint)
tp@0 225 H = line([sourcepoint(1)*0.95 sourcepoint(1)*1.05],[sourcepoint(2)*0.95 sourcepoint(2)*1.05],[maxvalue(2) maxvalue(2)]);
tp@0 226 set(H,'LineWidth',4);
tp@0 227 set(H,'Color',[1 0 0]);
tp@0 228 H = line([sourcepoint(1)*0.95 sourcepoint(1)*1.05],[sourcepoint(2)*1.05 sourcepoint(2)*0.95],[maxvalue(2) maxvalue(2)]);
tp@0 229 set(H,'LineWidth',4);
tp@0 230 set(H,'Color',[1 0 0]);
tp@0 231 end