annotate private/EDB1plotmodel.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 EDB1plotmodel(eddatafile,plotoptions,plotoptions2,plotoptions3)
tp@0 2 % EDB1plotmodel - Plots a model which is given in an eddatafile.
tp@0 3 %
tp@0 4 % Input parameters:
tp@0 5 % eddatafile (optional) The input file. If not specified, a file
tp@0 6 % opening window will be presented.
tp@0 7 % plotoptions (optional) An integer that can give extra options:
tp@0 8 % if bit0 = 1 (= 1) => plot sources
tp@0 9 % if bit1 = 1 (= 2) => plot receivers
tp@0 10 % if bit2 = 1 (= 4) => plot plane normal vectors
tp@0 11 % if bit3 = 1 (= 8) => print plane numbers
tp@0 12 % if bit4 = 1 (=16) => print edge numbers
tp@0 13 % if bit5 = 1 (=32) => print corner numbers
tp@0 14 % if bit6 = 1 (=64) => print plane numbers using the
tp@0 15 % CAD file numbering
tp@0 16 % if bit7 = 1 (=128)=> print corner numbers using the
tp@0 17 % CAD file numbering
tp@0 18 % if bit8 = 1 (=256) => offedges are not included
tp@0 19 % if bit9 = 1 (=512) => only offedges are included
tp@0 20 % if plotoptions == -1 => plot edge by edge
tp@0 21 % if plotoptions == -2 => plot plane by plane
tp@0 22 % Example: the integer 11 = 8+2+1
tp@0 23 % so sources, receivers, and plane numbers will be plotted.
tp@0 24 % plotoptions2 (optional) A matrix with two columns of 1 or many integers, the first
tp@0 25 % giving the source numbers to be plotted and the
tp@0 26 % second giving the receiver numbers to be
tp@0 27 % plotted. The first in the sequence will be
tp@0 28 % plotted with a black color.
tp@0 29 % Alternatively, if plotoptions = -1, then
tp@0 30 % plotoptions2 can be used to give a list of
tp@0 31 % edges to plot.
tp@0 32 % Alternatively, if plotoptions = -2, then
tp@0 33 % plotoptions2 can be used to give a list of
tp@0 34 % planes to plot.
tp@0 35 % plotoptions3 (optional) A vector with two or three values, giving the
tp@0 36 % view position for the 3D plot view.
tp@0 37 %
tp@0 38 % Sources and receivers are taken from an sdatafile and an rdatafile, the file name of
tp@0 39 % which is assumed to be similar to the eddatafile.
tp@0 40 %
tp@0 41 % Uses functions EDB1strpend, EDB1myvalueinput
tp@0 42 %
tp@0 43 % ----------------------------------------------------------------------------------------------
tp@0 44 % This file is part of the Edge Diffraction Toolbox by Peter Svensson.
tp@0 45 %
tp@0 46 % The Edge Diffraction Toolbox is free software: you can redistribute it and/or modify
tp@0 47 % it under the terms of the GNU General Public License as published by the Free Software
tp@0 48 % Foundation, either version 3 of the License, or (at your option) any later version.
tp@0 49 %
tp@0 50 % The Edge Diffraction Toolbox is distributed in the hope that it will be useful,
tp@0 51 % but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
tp@0 52 % FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
tp@0 53 %
tp@0 54 % You should have received a copy of the GNU General Public License along with the
tp@0 55 % Edge Diffraction Toolbox. If not, see <http://www.gnu.org/licenses/>.
tp@0 56 % ----------------------------------------------------------------------------------------------
tp@0 57 % Peter Svensson (svensson@iet.ntnu.no) 20110704
tp@0 58 %
tp@0 59 % EDB1plotmodel(eddatafile,plotoptions,plotoptions2,plotoptions3);
tp@0 60
tp@0 61 %--------------------------------------------------------------
tp@0 62 % Read the eddatafile
tp@0 63
tp@0 64 if nargin == 0 | (nargin >= 1 & isstr(eddatafile) ~= 1)
tp@0 65 [eddatafile,eddatafilepath] = uigetfile('*eddata.mat','Please select the eddatafile');
tp@0 66 [eddatafilepath,temp1,temp2] = fileparts(eddatafilepath);
tp@0 67 if ~isstr(eddatafile) | isempty(eddatafile)
tp@0 68 return
tp@0 69 end
tp@0 70 else
tp@0 71 [eddatafilepath,eddatafile,fileext] = fileparts(eddatafile);
tp@0 72 eddatafile = [eddatafile,fileext];
tp@0 73 end
tp@0 74 Filestem = EDB1strpend(eddatafile,'_eddata');
tp@0 75
tp@0 76 disp(['eddatafile is ',eddatafilepath,filesep,eddatafile])
tp@0 77
tp@0 78 if nargin == 1
tp@0 79 if isstr(eddatafile) ~= 1
tp@0 80 plotoptions = eddatafile;
tp@0 81 else
tp@0 82 plotoptions = 0;
tp@0 83 end
tp@0 84 plotoptions2 = [];
tp@0 85 plotoptions3 = [];
tp@0 86 elseif nargin == 0
tp@0 87 plotoptions = 0;
tp@0 88 plotoptions2 = [];
tp@0 89 plotoptions3 = [];
tp@0 90 elseif nargin == 2
tp@0 91 plotoptions2 = [];
tp@0 92 plotoptions3 = [];
tp@0 93 elseif nargin == 3
tp@0 94 nplotoptions2 = size(plotoptions2);
tp@0 95 plotoptions3 = [];
tp@0 96 else
tp@0 97 nplotoptions2 = size(plotoptions2);
tp@0 98 end
tp@0 99
tp@0 100 plotedgesequence = 0;
tp@0 101 plotplanesequence = 0;
tp@0 102 if plotoptions < 0
tp@0 103 if plotoptions == -1
tp@0 104 plotedgesequence = 1;
tp@0 105 elseif plotoptions == -2
tp@0 106 plotplanesequence = 1;
tp@0 107 end
tp@0 108 plotoptions = 0;
tp@0 109 end
tp@0 110 plotsources = bitget(plotoptions,1);
tp@0 111 plotreceivers = bitget(plotoptions,2);
tp@0 112 plotnvecs = bitget(plotoptions,3);
tp@0 113 plotplnumbers = bitget(plotoptions,4);
tp@0 114 plotednumbers = bitget(plotoptions,5);
tp@0 115 plotconumbers = bitget(plotoptions,6);
tp@0 116 plotplCADnumbers = bitget(plotoptions,7);
tp@0 117 plotcoCADnumbers = bitget(plotoptions,8);
tp@0 118 plotnooffedges = bitget(plotoptions,9);
tp@0 119 plotonlyoffedges = bitget(plotoptions,10);
tp@0 120
tp@0 121 if plotplCADnumbers, plotplnumbers = 1; end
tp@0 122 if plotcoCADnumbers, plotconumbers = 1; end
tp@0 123
tp@0 124 %--------------------------------------------------------------------------
tp@0 125 % Load the needed input files
tp@0 126
tp@0 127 if ~isempty(eddatafilepath)
tp@0 128 eval(['load ',eddatafilepath,filesep,eddatafile])
tp@0 129 else
tp@0 130 eval(['load ',eddatafile])
tp@0 131 end
tp@0 132
tp@0 133 ncornersperplanevec = double(ncornersperplanevec);
tp@0 134 if plotsources
tp@0 135 sdatafile = [eddatafilepath,filesep,Filestem,'_sdata_1.mat'];
tp@0 136 if exist(sdatafile) == 2
tp@0 137 allsources = [];
tp@0 138 sfilecounter = 1;
tp@0 139 while exist(sdatafile) == 2
tp@0 140 eval(['load ',sdatafile])
tp@0 141 allsources = [allsources;sources];
tp@0 142 sfilecounter = sfilecounter +1;
tp@0 143 sdatafile = [eddatafilepath,filesep,Filestem,'_sdata_',int2str(sfilecounter),'.mat']
tp@0 144 end
tp@0 145 sources = allsources;
tp@0 146 else
tp@0 147 sdatafile = [eddatafilepath,filesep,Filestem,'_sdata.mat'];
tp@0 148 if exist(sdatafile) == 2
tp@0 149 eval(['load ',sdatafile])
tp@0 150 else
tp@0 151 error(['ERROR: The sdata file named ',sdatafile,' could not be opened'])
tp@0 152 end
tp@0 153 end
tp@0 154 end
tp@0 155 if plotreceivers
tp@0 156 rdatafile = [eddatafilepath,filesep,Filestem,'_rdata_1.mat'];
tp@0 157 if exist(rdatafile) == 2
tp@0 158 allreceivers = [];
tp@0 159 rfilecounter = 1;
tp@0 160 while exist(rdatafile) == 2
tp@0 161 eval(['load ',rdatafile])
tp@0 162 allreceivers = [allreceivers;receivers];
tp@0 163 rfilecounter = rfilecounter +1;
tp@0 164 rdatafile = [eddatafilepath,filesep,Filestem,'_rdata_',int2str(rfilecounter),'.mat']
tp@0 165 end
tp@0 166 receivers = allreceivers;
tp@0 167 else
tp@0 168 rdatafile = [eddatafilepath,filesep,Filestem,'_rdata.mat'];
tp@0 169 if exist(rdatafile) == 2
tp@0 170 eval(['load ',rdatafile])
tp@0 171 else
tp@0 172 error(['ERROR: The rdata file named ',rdatafile,' could not be opened'])
tp@0 173 end
tp@0 174 end
tp@0 175 end
tp@0 176
tp@0 177 if plotplCADnumbers | plotcoCADnumbers
tp@0 178 cadgeofile = [eddatafilepath,Filestem,'_cadgeo.mat'];
tp@0 179 if exist(cadgeofile) == 2
tp@0 180 eval(['load ',cadgeofile])
tp@0 181 else
tp@0 182 error(['ERROR: The cadgeo file named ',cadgeofile,' could not be opened'])
tp@0 183 end
tp@0 184 end
tp@0 185
tp@0 186 %--------------------------------------------------------------
tp@0 187
tp@0 188 [ncorners,slask] = size(corners);
tp@0 189 [nedges,slask] = size(edgecorners);
tp@0 190 [nplanes,slask] = size(planenvecs);
tp@0 191
tp@0 192 planelist = 1:nplanes;
tp@0 193
tp@0 194 if isempty(plotoptions3)
tp@0 195 viewpos = EDB1myvalueinput('From which point do you want to watch the model? (x y z, or az el, with spaces inbetween) ',-1);
tp@0 196 else
tp@0 197 viewpos = plotoptions3;
tp@0 198 end
tp@0 199
tp@0 200 hold off
tp@0 201 for ii = 1:nedges
tp@0 202 co1 = edgecorners(ii,1);
tp@0 203 co2 = edgecorners(ii,2);
tp@0 204 iv = [co1;co2];
tp@0 205 plot3(corners(iv,1),corners(iv,2),corners(iv,3))
tp@0 206 if ii ==1
tp@0 207 view(viewpos)
tp@0 208 hold
tp@0 209 end
tp@0 210 end
tp@0 211
tp@0 212 if plotedgesequence
tp@0 213 for ii = 1:nedges
tp@0 214 co1 = edgecorners(ii,1);
tp@0 215 co2 = edgecorners(ii,2);
tp@0 216 iv = [co1;co2];
tp@0 217 h = plot3(corners(iv,1),corners(iv,2),corners(iv,3));
tp@0 218 set(h,'LineWidth',2)
tp@0 219 disp(['Edge no. ',int2str(ii),' Closed wedge angle: ',num2str(closwedangvec(ii)*180/pi)])
tp@0 220 pause
tp@0 221 set(h,'LineWidth',1)
tp@0 222
tp@0 223 end
tp@0 224 end
tp@0 225 if plotplanesequence
tp@0 226 if ~isempty(plotoptions2)
tp@0 227 listofplanes = plotoptions2;
tp@0 228 else
tp@0 229 listofplanes = [1:nplanes];
tp@0 230 end
tp@0 231 for jj = listofplanes
tp@0 232 edgelist = edgesatplane(jj,:);
tp@0 233 edgelist = edgelist(find(edgelist));
tp@0 234 for ii = edgelist
tp@0 235 co1 = edgecorners(ii,1);
tp@0 236 co2 = edgecorners(ii,2);
tp@0 237 iv = [co1;co2];
tp@0 238 h = plot3(corners(iv,1),corners(iv,2),corners(iv,3));
tp@0 239 set(h,'LineWidth',2)
tp@0 240 end
tp@0 241 disp(['Plane no. ',int2str(jj)])
tp@0 242 pause
tp@0 243
tp@0 244 % For some reason it doesnt work to replot the same list of edges
tp@0 245 % with a thinner linewidth; even trying out with replotting the
tp@0 246 % edges with another color just replots one of the edges??
tp@0 247 % Therefore the inelegant method of replotting the whole model.
tp@0 248 hold off
tp@0 249 for ii = 1:nedges
tp@0 250 co1 = edgecorners(ii,1);
tp@0 251 co2 = edgecorners(ii,2);
tp@0 252 iv = [co1;co2];
tp@0 253 plot3(corners(iv,1),corners(iv,2),corners(iv,3))
tp@0 254 if ii ==1
tp@0 255 view(viewpos)
tp@0 256 hold
tp@0 257 end
tp@0 258 end
tp@0 259
tp@0 260
tp@0 261
tp@0 262 end
tp@0 263 end
tp@0 264
tp@0 265 if plotnvecs
tp@0 266 for ii = 1:nplanes
tp@0 267 midpoint = mean(corners(planecorners(ii,1:(ncornersperplanevec(ii))),:));
tp@0 268
tp@0 269 endpoint = midpoint + planenvecs(ii,:);
tp@0 270 bothpoints = [midpoint;endpoint];
tp@0 271 plot3(bothpoints(:,1),bothpoints(:,2),bothpoints(:,3));
tp@0 272 plot3(midpoint(1),midpoint(2),midpoint(3),'ro');
tp@0 273 end
tp@0 274 end
tp@0 275
tp@0 276 if plotplnumbers
tp@0 277 for ii = 1:nplanes
tp@0 278 midpoint = mean(corners(planecorners(ii,1:ncornersperplanevec(ii)),:));
tp@0 279 endpoint = midpoint + planenvecs(ii,:)*0.1;
tp@0 280 if plotplCADnumbers == 1
tp@0 281 text(endpoint(1),endpoint(2),endpoint(3),int2str(planenumbers(ii)));
tp@0 282 else
tp@0 283 text(endpoint(1),endpoint(2),endpoint(3),int2str(ii));
tp@0 284 end
tp@0 285
tp@0 286 end
tp@0 287 end
tp@0 288
tp@0 289 if plotednumbers
tp@0 290 iv = [1:nedges];
tp@0 291 if plotnooffedges, iv(offedges) = []; end
tp@0 292 if plotonlyoffedges, iv = offedges; end
tp@0 293 iv = iv(:).';
tp@0 294
tp@0 295 for ii = iv
tp@0 296 midpoint = mean(corners(edgecorners(ii,1:2),:));
tp@0 297 text(midpoint(1),midpoint(2),midpoint(3),int2str(ii));
tp@0 298 end
tp@0 299 end
tp@0 300
tp@0 301 if plotconumbers
tp@0 302 for ii = 1:ncorners
tp@0 303 if plotcoCADnumbers == 1
tp@0 304 text(corners(ii,1),corners(ii,2),corners(ii,3),int2str(cornernumbers(ii)))
tp@0 305 else
tp@0 306 text(corners(ii,1),corners(ii,2),corners(ii,3),int2str(ii))
tp@0 307 end
tp@0 308 end
tp@0 309
tp@0 310 end
tp@0 311
tp@0 312 if plotsources == 1
tp@0 313 if isempty(plotoptions2)
tp@0 314 plot3(sources(:,1),sources(:,2),sources(:,3),'*');
tp@0 315 else
tp@0 316 if nplotoptions2 == 1
tp@0 317 plot3(sources(plotoptions2(1),1),sources(plotoptions2(1),2),sources(plotoptions2(1),3),'*')
tp@0 318 else
tp@0 319 plot3(sources(plotoptions2(1,1),1),sources(plotoptions2(1,1),2),sources(plotoptions2(1,1),3),'k*')
tp@0 320 plot3(sources(plotoptions2(2:nplotoptions2,1),1),sources(plotoptions2(2:nplotoptions2,1),2),sources(plotoptions2(2:nplotoptions2,1),3),'*')
tp@0 321 end
tp@0 322 end
tp@0 323 end
tp@0 324
tp@0 325 if plotreceivers == 1
tp@0 326 if isempty(plotoptions2)
tp@0 327 plot3(receivers(:,1),receivers(:,2),receivers(:,3),'ro');
tp@0 328 else
tp@0 329 if nplotoptions2 == 1
tp@0 330 plot3(receivers(plotoptions2(2),1),receivers(plotoptions2(2),2),receivers(plotoptions2(2),3),'ro');
tp@0 331 else
tp@0 332 plot3(receivers(plotoptions2(1,2),1),receivers(plotoptions2(1,2),2),receivers(plotoptions2(1,2),3),'ko');
tp@0 333 plot3(receivers(plotoptions2(2:nplotoptions2,2),1),receivers(plotoptions2(2:nplotoptions2,2),2),receivers(plotoptions2(2:nplotoptions2,2),3),'ro');
tp@0 334
tp@0 335 end
tp@0 336 end
tp@0 337 end