- Timestamp:
- Oct 4, 2010, 10:39:11 PM (14 years ago)
- Location:
- trunk/src
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/create_grid.m
r89 r109 136 136 zarray=T.z_0*ones(size(yarray)); 137 137 varargout{1}=[xarray yarray zarray]; 138 varargout{2}=T; 138 139 end 139 varargout{2}=T; 140 140 141 % The figure can be deleted now 141 142 delete(handles.figure1); -
trunk/src/geometry_calib.m
r108 r109 3 3 % function varargout = geometry_calib(varargin) 4 4 % 5 %A%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AA5 %A%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA 6 6 % Copyright Joel Sommeria, 2008, LEGI / CNRS-UJF-INPG, sommeria@coriolis-legi.org. 7 7 %AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA … … 43 43 % Edit the above text to modify the response to help geometry_calib 44 44 45 % Last Modified by GUIDE v2.5 25-Mar-2010 19:10:0545 % Last Modified by GUIDE v2.5 03-Oct-2010 09:34:12 46 46 47 47 % Begin initialization code - DO NOT edit … … 87 87 set(hObject,'Position',pos_gui); 88 88 end 89 90 %set menu of calibration options 91 %set(handles.calib_type,'String',{'rescale';'linear';'perspective';'normal';'tsai';'bouguet';'extrinsic'}) 92 set(handles.calib_type,'String',{'rescale';'linear';'quadr';'3D_linear';'3D_quadr';'3D_extrinsic'}) 89 93 inputxml=''; 90 94 if exist('inputfile','var')& ~isempty(inputfile) 91 % [Path,Name,ext]=fileparts(inputfile); 92 % form=imformats(ext([2:end])); 93 % if ~isempty(form)% if the input file is an image 94 struct.XmlInputfile=inputfile; 95 set(hObject,'UserData',struct) 96 [Pathsub,RootFile,field_count,str2,str_a,str_b,ext,nom_type,subdir]=name2display(inputfile); 97 inputxml=[fullfile(Pathsub,RootFile) '.xml']; 98 % end 95 struct.XmlInputfile=inputfile; 96 set(hObject,'UserData',struct) 97 [Pathsub,RootFile,field_count,str2,str_a,str_b,ext,nom_type,subdir]=name2display(inputfile); 98 inputxml=[fullfile(Pathsub,RootFile) '.xml']; 99 99 end 100 100 set(handles.ListCoord,'String',{'......'}) … … 102 102 loadfile(handles,inputxml)% load the point coordiantes existing in the xml file 103 103 end 104 105 104 set(handles.ListCoord,'KeyPressFcn',{@key_press_fcn,handles})%set keyboard action function 106 105 … … 113 112 varargout{1} = handles.output; 114 113 varargout{2}=handles; 115 116 %------------117 function Phi_Callback(hObject, eventdata, handles)118 119 %------------------------------------------------------------------------120 %read input xml file and update the edit boxes121 function loadfile(handles,fileinput)122 %------------------------------------------------------------------------123 %read the input xml file124 t=xmltree(fileinput);125 s=convert(t);%convert to matlab structure126 %read data currently displayed on the interface127 PointCoord=[];128 Coord_cell=get(handles.ListCoord,'String');129 data=read_geometry_calib(Coord_cell);130 %data=read_geometry_calib(handles);131 Coord=[]; %default132 if isfield(data,'Coord')133 Coord=data.Coord;134 end135 TabChar_0=get(handles.ListCoord,'String');136 nbcoord_0=size(TabChar_0,1);137 if isequal(get(handles.edit_append,'Value'),2) %edit mode A REVOIR138 val=get(handles.ListCoord,'Value')-1;139 else140 val=length(TabChar_0);141 end142 nbcoord=0;143 144 %case of calibration (ImaDoc) input file145 % hcalib=get(handles.calib_type,'parent');146 CalibData=get(handles.geometry_calib,'UserData');147 CalibData.XmlInput=fileinput;148 if isfield(s,'Heading')149 CalibData.Heading=s.Heading;150 end151 152 set(handles.geometry_calib,'UserData',CalibData);%store the heading in the interface 'UserData'153 if isfield(s,'GeometryCalib')154 Calib=s.GeometryCalib;155 if isfield(Calib,'CalibrationType')156 CalibrationType=Calib.CalibrationType;157 switch CalibrationType158 case 'linear'159 set(handles.calib_type,'Value',2)160 case 'tsai'161 set(handles.calib_type,'Value',3)162 case 'tsai_matlab'163 set(handles.calib_type,'Value',4)164 end165 end166 if isfield(Calib,'SourceCalib')167 if isfield(Calib.SourceCalib,'PointCoord')168 PointCoord=Calib.SourceCalib.PointCoord;169 end170 end171 nbcoord=length(PointCoord);172 if ~isfield(Calib,'ErrorRms')&~isfield(Calib,'ErrorMax') %old convention of Gauthier (cord in mm)173 for i=1:length(PointCoord)174 line=str2num(PointCoord{i});175 Coord(i+val,4:5)=line(4:5);%px x176 Coord(i+val,1:3)=line(1:3)/10;%phys x177 end178 else179 for i=1:length(PointCoord)180 line=str2num(PointCoord{i});181 Coord(i,4:5)=line(4:5);%px x182 Coord(i,1:3)=line(1:3);%phys x183 end184 end185 end186 %case of xml files of points187 if isfield(s,'Coord')188 PointCoord=s.Coord;189 nbcoord=length(PointCoord);190 %case of image coordinates191 if isfield(s,'CoordType')& isequal(s.CoordType,'px')192 for i=1:nbcoord193 line=str2num(PointCoord{i});194 Coord(i+val,4:5)=line(1:2);195 end196 %case of physical coordinates197 else198 for i=1:nbcoord199 line=str2num(PointCoord{i});200 Coord(i+val,1:3)=line(1:3);201 nbcolumn=size(Coord,2);202 if nbcolumn<5203 Coord(i+val,nbcolumn+1:5)=zeros(1,5-nbcolumn);204 end205 end206 end207 end208 CoordCell={};209 for iline=1:size(Coord,1)210 for j=1:5211 CoordCell{iline,j}=num2str(Coord(iline,j),4);212 end213 end214 % CoordCell=[CoordCell;{' ',' ',' ',' ',' '}];215 Tabchar=cell2tab(CoordCell,' | ');%transform cells into table ready for display216 Tabchar=[Tabchar;{'......'}];217 set(handles.ListCoord,'Value',1)218 set(handles.ListCoord,'String',Tabchar)219 MenuPlot_Callback(handles.geometry_calib, [], handles)220 if isempty(Coord)221 set(handles.edit_append,'Value',1)222 set(handles.edit_append,'BackgroundColor',[1 1 0])223 else224 set(handles.edit_append,'Value',0)225 set(handles.edit_append,'BackgroundColor',[0.7 0.7 0.7])226 end227 114 % 228 115 %------------------------------------------------------------------------ … … 252 139 function APPLY_Callback(hObject, eventdata, handles) 253 140 %------------------------------------------------------------------------ 254 calib_cell=get(handles.calib_type,'String'); 255 val=get(handles.calib_type,'Value'); 256 calib_type=calib_cell{val}; 141 142 %read the current calibration points 257 143 Coord_cell=get(handles.ListCoord,'String'); 258 144 Object=read_geometry_calib(Coord_cell); 259 X=Object.Coord(:,1); 260 Y=Object.Coord(:,2); 261 Z=Object.Coord(:,3); 262 if isequal(calib_type,'rescale') 263 GeometryCalib=calib_rescale(Object.Coord); 264 Z=0;%Z not taken into account 265 elseif isequal(calib_type,'linear') 266 GeometryCalib=calib_linear(Object.Coord); 267 Z=0; %Z not taken into account 268 elseif isequal(calib_type,'tsai_cpp') 269 GeometryCalib=calib_tsai(Object.Coord); 270 elseif isequal(calib_type,'tsai_matlab') 271 GeometryCalib=calib_tsai2(Object.Coord); 272 end 145 Coord=Object.Coord; 146 147 % apply the calibration, whose type is selected in handles.calib_type 148 if ~isempty(Coord) 149 calib_cell=get(handles.calib_type,'String'); 150 val=get(handles.calib_type,'Value'); 151 GeometryCalib=feval(['calib_' calib_cell{val}],Coord,handles); 152 else 153 msgbox_uvmat('ERROR','No calibration points, abort') 154 return 155 end 273 156 274 157 %check error … … 298 181 Calib.R=GeometryCalib.R; 299 182 end 300 x_ima=Object.Coord(:,4); 301 y_ima=Object.Coord(:,5); 302 [Xpoints,Ypoints]=px_XYZ(Calib,X,Y,Z); 303 GeometryCalib.ErrorRms(1)=sqrt(mean((Xpoints-x_ima).*(Xpoints-x_ima))); 304 [GeometryCalib.ErrorMax(1),index(1)]=max(abs(Xpoints-x_ima)); 305 GeometryCalib.ErrorRms(2)=sqrt(mean((Ypoints-y_ima).*(Ypoints-y_ima))); 306 [GeometryCalib.ErrorMax(2),index(2)]=max(abs(Ypoints-y_ima)); 307 [EM,ind_dim]=max(GeometryCalib.ErrorMax); 308 index=index(ind_dim); 309 183 if ~isempty(Coord) 184 X=Coord(:,1); 185 Y=Coord(:,2); 186 Z=Coord(:,3); 187 x_ima=Coord(:,4); 188 y_ima=Coord(:,5); 189 [Xpoints,Ypoints]=px_XYZ(Calib,X,Y,Z); 190 GeometryCalib.ErrorRms(1)=sqrt(mean((Xpoints-x_ima).*(Xpoints-x_ima))); 191 [GeometryCalib.ErrorMax(1),index(1)]=max(abs(Xpoints-x_ima)); 192 GeometryCalib.ErrorRms(2)=sqrt(mean((Ypoints-y_ima).*(Ypoints-y_ima))); 193 [GeometryCalib.ErrorMax(2),index(2)]=max(abs(Ypoints-y_ima)); 194 [EM,ind_dim]=max(GeometryCalib.ErrorMax); 195 index=index(ind_dim); 196 if isequal(max(Z),min(Z))%Z constant 197 GeometryCalib.NbSlice=1; 198 GeometryCalib.SliceCoord=[0 0 Z(1)]; 199 end 200 end 310 201 unitlist=get(handles.CoordUnit,'String'); 311 202 unit=unitlist{get(handles.CoordUnit,'value')}; 312 203 GeometryCalib.CoordUnit=unit; 313 GeometryCalib.SourceCalib.PointCoord=Object.Coord; 204 GeometryCalib.SourceCalib.PointCoord=Coord; 205 206 %display calibration intrinsic parameters 207 k=0; 208 if isfield(GeometryCalib,'kappa1') 209 k=GeometryCalib.kappa1 * GeometryCalib.focal*GeometryCalib.focal; 210 end 211 sx=1;dpx_dpy=[1 1]; 212 if isfield(GeometryCalib,'sx') 213 sx=GeometryCalib.sx; 214 end 215 if isfield(GeometryCalib,'dpx_dpy') 216 dpx_dpy=GeometryCalib.dpx_dpy; 217 end 218 Cx_Cy=[0 0]; 219 if isfield(GeometryCalib,'Cx_Cy') 220 Cx_Cy=GeometryCalib.Cx_Cy; 221 end 222 f1=GeometryCalib.focal*sx/dpx_dpy(1); 223 f2=GeometryCalib.focal/dpx_dpy(2); 224 Cx=Cx_Cy(1); 225 Cy=Cx_Cy(2); 226 set(handles.fx,'String',num2str(f1,4)) 227 set(handles.fy,'String',num2str(f2,4)) 228 set(handles.k,'String',num2str(k,'%1.4f')) 229 set(handles.Cx,'String',num2str(Cx,'%1.1f')) 230 set(handles.Cy,'String',num2str(Cy,'%1.1f')) 231 % Display extrinsinc parameters 232 set(handles.Tx,'String',num2str(GeometryCalib.Tx_Ty_Tz(1),4)) 233 set(handles.Ty,'String',num2str(GeometryCalib.Tx_Ty_Tz(2),4)) 234 set(handles.Tz,'String',num2str(GeometryCalib.Tx_Ty_Tz(3),4)) 235 236 % indicate the plane of the calibration grid if defined 314 237 huvmat=findobj(allchild(0),'Name','uvmat'); 315 238 hhuvmat=guidata(huvmat);%handles of elements in the GUI uvmat … … 337 260 hhh=findobj(hhuvmat.axes3,'Tag','calib_marker');% delete calib points and markers 338 261 if ~isempty(hhh) 339 delete(hhh); 262 delete(hhh); 340 263 end 341 264 hhh=findobj(hhuvmat.axes3,'Tag','calib_points'); … … 346 269 set(hhuvmat.FixedLimits,'BackgroundColor',[0.7 0.7 0.7]) 347 270 uvmat('RootPath_Callback',hObject,eventdata,hhuvmat); %file input with xml reading in uvmat 348 MenuPlot_Callback(hObject, eventdata, handles) 349 set(handles.ListCoord,'Value',index)% indicate in the list the point with max deviation (possible mistake) 350 ListCoord_Callback(hObject, eventdata, handles) 271 % if ip==0 272 MenuPlot_Callback(hObject, eventdata, handles) 273 set(handles.ListCoord,'Value',index)% indicate in the list the point with max deviation (possible mistake) 274 ListCoord_Callback(hObject, eventdata, handles) 275 % end 351 276 figure(handles.geometry_calib) 352 277 end … … 355 280 % --- Executes on button press in calibrate_lin. 356 281 function REPLICATE_Callback(hObject, eventdata, handles) 282 % %%%%%%Todo: correct on the model of APPLY_Callback%%%%%%%%%% 357 283 %------------------------------------------------------------------------ 358 284 calib_cell=get(handles.calib_type,'String'); 359 285 val=get(handles.calib_type,'Value'); 360 calib_type=calib_cell{val};361 286 Coord_cell=get(handles.ListCoord,'String'); 362 287 Object=read_geometry_calib(Coord_cell); 363 364 if isequal(calib_type,'rescale') 365 GeometryCalib=calib_rescale(Object.Coord); 366 elseif isequal(calib_type,'linear') 367 GeometryCalib=calib_linear(Object.Coord); 368 elseif isequal(calib_type,'tsai') 369 GeometryCalib=calib_tsai(Object.Coord); 370 end 288 GeometryCalib=feval(calib_cell{val},Object.Coord); 289 371 290 % %record image source 372 291 GeometryCalib.SourceCalib.PointCoord=Object.Coord; … … 424 343 %------------------------------------------------------------------------ 425 344 % determine the parameters for a calibration by an affine function (rescaling and offset, no rotation) 426 function GeometryCalib=calib_rescale(Coord) 427 %------------------------------------------------------------------------ 428 345 function GeometryCalib=calib_rescale(Coord,handles) 346 %------------------------------------------------------------------------ 429 347 X=Coord(:,1); 430 Y=Coord(:,2); 348 Y=Coord(:,2);% Z not used 431 349 x_ima=Coord(:,4); 432 350 y_ima=Coord(:,5); … … 436 354 T_y=py(2); 437 355 GeometryCalib.CalibrationType='rescale'; 438 GeometryCalib.focal=1; 356 GeometryCalib.focal=1;%default 357 GeometryCalib.sx=px(1)/py(1); 439 358 GeometryCalib.CoordUnit=[];% default value, to be updated by the calling function 440 GeometryCalib.Tx_Ty_Tz=[T_x T_y 1]; 441 GeometryCalib.R=[px(1),0,0;0,py(1),0;0,0,1]; 442 443 % %check error 444 % Calib.dpx=1; 445 % Calib.dpy=1; 446 % Calib.sx=1; 447 % Calib.Cx=0; 448 % Calib.Cy=0; 449 % Calib.Tz=1; 450 % Calib.kappa1=0; 451 % Calib.f=GeometryCalib.focal; 452 % Calib.Tx=T_x; 453 % Calib.Ty=T_y; 454 % Calib.R=GeometryCalib.R; 455 % [Xpoints,Ypoints]=px_XYZ(Calib,X,Y,0); 456 % GeometryCalib.ErrorRms(1)=sqrt(mean((Xpoints-x_ima).*(Xpoints-x_ima))); 457 % GeometryCalib.ErrorMax(1)=max(abs(Xpoints-x_ima)); 458 % GeometryCalib.ErrorRms(2)=sqrt(mean((Ypoints-y_ima).*(Ypoints-y_ima))); 459 % GeometryCalib.ErrorMax(2)=max(abs(Ypoints-y_ima)); 359 GeometryCalib.Tx_Ty_Tz=[T_x T_y GeometryCalib.focal/py(1)]; 360 GeometryCalib.R=[1,0,0;0,1,0;0,0,0]; 460 361 461 362 %------------------------------------------------------------------------ 462 363 % determine the parameters for a calibration by a linear transform matrix (rescale and rotation) 463 function GeometryCalib=calib_linear(Coord )364 function GeometryCalib=calib_linear(Coord,handles) 464 365 %------------------------------------------------------------------------ 465 366 X=Coord(:,1); 466 Y=Coord(:,2); 367 Y=Coord(:,2);% Z not used 467 368 x_ima=Coord(:,4); 468 369 y_ima=Coord(:,5); 469 370 XY_mat=[ones(size(X)) X Y]; 470 371 a_X1=XY_mat\x_ima; %transformation matrix for X 471 x1=XY_mat*a_X1;%reconstruction472 err_X1=max(abs(x1-x_ima));%error372 % x1=XY_mat*a_X1;%reconstruction 373 % err_X1=max(abs(x1-x_ima));%error 473 374 a_Y1=XY_mat\y_ima;%transformation matrix for X 474 y1=XY_mat*a_Y1; 475 err_Y1=max(abs(y1-y_ima));%error 476 T_x=a_X1(1); 477 T_y=a_Y1(1); 375 % y1=XY_mat*a_Y1; 376 % err_Y1=max(abs(y1-y_ima));%error 478 377 GeometryCalib.CalibrationType='linear'; 479 378 GeometryCalib.focal=1; 480 379 GeometryCalib.CoordUnit=[];% default value, to be updated by the calling function 481 GeometryCalib.Tx_Ty_Tz=[T_x T_y 1]; 482 GeometryCalib.R=[a_X1(2),a_X1(3),0;a_Y1(2),a_Y1(3),0;0,0,1]; 483 484 % %check error 485 % GeometryCalib.ErrorRms(1)=sqrt(mean((x1-x_ima).*(x1-x_ima))); 486 % GeometryCalib.ErrorMax(1)=max(abs(x1-x_ima)); 487 % GeometryCalib.ErrorRms(2)=sqrt(mean((y1-y_ima).*(y1-y_ima))); 488 % GeometryCalib.ErrorMax(2)=max(abs(y1-y_ima)); 489 490 %------------------------------------------------------------------------ 491 function GeometryCalib=calib_tsai2(Coord) 380 R=[a_X1(2),a_X1(3),0;a_Y1(2),a_Y1(3),0;0,0,0]; 381 norm=det(R); 382 GeometryCalib.Tx_Ty_Tz=[a_X1(1) a_Y1(1) norm]; 383 GeometryCalib.R=R/norm; 384 385 %------------------------------------------------------------------------ 386 % determine the tsai parameters for a view normal to the grid plane 387 function GeometryCalib=calib_normal(Coord,handles) 388 %------------------------------------------------------------------------ 389 Calib.f1=str2num(get(handles.fx,'String')); 390 Calib.f2=str2num(get(handles.fy,'String')); 391 Calib.k=str2num(get(handles.k,'String')); 392 Calib.Cx=str2num(get(handles.Cx,'String')); 393 Calib.Cy=str2num(get(handles.Cy,'String')); 394 %default 395 if isempty(Calib.f1) 396 Calib.f1=25/0.012; 397 end 398 if isempty(Calib.f2) 399 Calib.f2=25/0.012; 400 end 401 if isempty(Calib.k) 402 Calib.k=0; 403 end 404 if isempty(Calib.Cx)||isempty(Calib.Cy) 405 huvmat=findobj(allchild(0),'Tag','uvmat'); 406 hhuvmat=guidata(huvmat); 407 Calib.Cx=str2num(get(hhuvmat.npx,'String'))/2; 408 Calib.Cx=str2num(get(hhuvmat.npy,'String'))/2; 409 end 410 %tsai parameters 411 Calib.dpx=0.012;%arbitrary 412 Calib.dpy=0.012; 413 Calib.sx=Calib.f1*Calib.dpx/(Calib.f2*Calib.dpy); 414 Calib.f=Calib.f2*Calib.dpy; 415 Calib.kappa1=Calib.k/(Calib.f*Calib.f); 416 417 %initial guess 418 X=Coord(:,1); 419 Y=Coord(:,2); 420 Zmean=mean(Coord(:,3)); 421 x_ima=Coord(:,4)-Calib.Cx; 422 y_ima=Coord(:,5)-Calib.Cy; 423 XY_mat=[ones(size(X)) X Y]; 424 a_X1=XY_mat\x_ima; %transformation matrix for X 425 a_Y1=XY_mat\y_ima;%transformation matrix for Y 426 R=[a_X1(2),a_X1(3),0;a_Y1(2),a_Y1(3),0;0,0,-1];% rotation+ z axis reversal (upward) 427 norm=sqrt(det(-R)); 428 calib_param(1)=0;% quadratic distortion 429 calib_param(2)=a_X1(1); 430 calib_param(3)=a_Y1(1); 431 calib_param(4)=Calib.f/(norm*Calib.dpx)-R(3,3)*Zmean; 432 calib_param(5)=angle(a_X1(2)+i*a_X1(3)); 433 display(['initial guess=' num2str(calib_param)]) 434 435 %optimise the parameters: minimisation of error 436 calib_param = fminsearch(@(calib_param) error_calib(calib_param,Calib,Coord),calib_param) 437 438 GeometryCalib.CalibrationType='tsai_normal'; 439 GeometryCalib.focal=Calib.f; 440 GeometryCalib.dpx_dpy=[Calib.dpx Calib.dpy]; 441 GeometryCalib.Cx_Cy=[Calib.Cx Calib.Cy]; 442 GeometryCalib.sx=Calib.sx; 443 GeometryCalib.kappa1=calib_param(1); 444 GeometryCalib.CoordUnit=[];% default value, to be updated by the calling function 445 GeometryCalib.Tx_Ty_Tz=[calib_param(2) calib_param(3) calib_param(4)]; 446 alpha=calib_param(5); 447 GeometryCalib.R=[cos(alpha) sin(alpha) 0;-sin(alpha) cos(alpha) 0;0 0 -1]; 448 449 %------------------------------------------------------------------------ 450 function GeometryCalib=calib_3D_linear(Coord,handles) 492 451 %------------------------------------------------------------------ 493 452 path_uvmat=which('uvmat');% check the path detected for source file uvmat … … 495 454 huvmat=findobj(allchild(0),'Tag','uvmat'); 496 455 hhuvmat=guidata(huvmat); 456 x_1=Coord(:,4:5)' 457 X_1=Coord(:,1:3)' 458 n_ima=1; 459 % check_cond=0; 460 461 nx=str2num(get(hhuvmat.npx,'String')); 462 ny=str2num(get(hhuvmat.npy,'String')); 463 464 est_dist=[0;0;0;0;0]; 465 est_aspect_ratio=0; 466 est_fc=[1;1]; 467 %fc=[25;25]/0.012; 468 center_optim=0; 469 run(fullfile(path_UVMAT,'toolbox_calib','go_calib_optim')); 470 471 GeometryCalib.CalibrationType='3D_linear'; 472 GeometryCalib.focal=fc(2); 473 GeometryCalib.dpx_dpy=[1 1]; 474 GeometryCalib.Cx_Cy=cc'; 475 GeometryCalib.sx=fc(1)/fc(2); 476 GeometryCalib.kappa1=-kc(1)/fc(2)^2; 477 GeometryCalib.CoordUnit=[];% default value, to be updated by the calling function 478 GeometryCalib.Tx_Ty_Tz=Tc_1'; 479 GeometryCalib.R=Rc_1; 480 481 %------------------------------------------------------------------------ 482 function GeometryCalib=calib_3D_quadr(Coord,handles) 483 %------------------------------------------------------------------ 484 485 path_uvmat=which('uvmat');% check the path detected for source file uvmat 486 path_UVMAT=fileparts(path_uvmat); %path to UVMAT 487 huvmat=findobj(allchild(0),'Tag','uvmat'); 488 hhuvmat=guidata(huvmat); 489 % check_cond=0; 490 coord_files=get(handles.coord_files,'String'); 491 if ischar(coord_files) 492 coord_files={coord_files}; 493 end 494 if isempty(coord_files{1}) || isequal(coord_files,{''}) 495 coord_files={}; 496 end 497 498 %retrieve the calibration points stored in the files listed in the popup list coord_files 499 x_1=Coord(:,4:5)'; 500 X_1=Coord(:,1:3)'; 501 n_ima=numel(coord_files)+1; 502 if ~isempty(coord_files) 503 msgbox_uvmat('CONFIRMATION',['The xy coordinates of the calibration points in ' num2str(n_ima) ' planes will be used']) 504 for ifile=1:numel(coord_files) 505 t=xmltree(coord_files{ifile}); 506 s=convert(t);%convert to matlab structure 507 if isfield(s,'GeometryCalib') 508 if isfield(s.GeometryCalib,'SourceCalib') 509 if isfield(s.GeometryCalib.SourceCalib,'PointCoord') 510 PointCoord=s.GeometryCalib.SourceCalib.PointCoord; 511 Coord_file=[]; 512 for i=1:length(PointCoord) 513 line=str2num(PointCoord{i}); 514 Coord_file(i,4:5)=line(4:5);%px x 515 Coord_file(i,1:3)=line(1:3);%phys x 516 end 517 eval(['x_' num2str(ifile+1) '=Coord_file(:,4:5)'';']); 518 eval(['X_' num2str(ifile+1) '=Coord_file(:,1:3)'';']); 519 end 520 end 521 end 522 end 523 end 524 525 n_ima=numel(coord_files)+1; 526 whos 527 nx=str2num(get(hhuvmat.npx,'String')); 528 ny=str2num(get(hhuvmat.npy,'String')); 529 530 est_dist=[1;0;0;0;0]; 531 est_aspect_ratio=1; 532 %est_fc=[0;0]; 533 %fc=[25;25]/0.012; 534 center_optim=0; 535 run(fullfile(path_UVMAT,'toolbox_calib','go_calib_optim')); 536 537 GeometryCalib.CalibrationType='3D_quadr'; 538 GeometryCalib.focal=fc(2); 539 GeometryCalib.dpx_dpy=[1 1]; 540 GeometryCalib.Cx_Cy=cc'; 541 GeometryCalib.sx=fc(1)/fc(2); 542 GeometryCalib.kappa1=-kc(1)/fc(2)^2; 543 GeometryCalib.CoordUnit=[];% default value, to be updated by the calling function 544 GeometryCalib.Tx_Ty_Tz=Tc_1'; 545 GeometryCalib.R=Rc_1; 546 GeometryCalib.R(3,1:3)=-GeometryCalib.R(3,1:3);%inversion for z upward 547 GeometryCalib.ErrorRMS=[]; 548 GeometryCalib.ErrorMax=[]; 549 550 551 %------------------------------------------------------------------------ 552 function GeometryCalib=calib_3D_extrinsic(Coord,handles) 553 %------------------------------------------------------------------ 554 path_uvmat=which('geometry_calib');% check the path detected for source file uvmat 555 path_UVMAT=fileparts(path_uvmat); %path to UVMAT 497 556 x_1=Coord(:,4:5)'; 498 557 X_1=Coord(:,1:3)'; 499 558 n_ima=1; 500 % check_cond=0; 501 502 503 nx=str2num(get(hhuvmat.npx,'String')); 504 ny=str2num(get(hhuvmat.npy,'String')); 505 506 507 % est_kc=[1;0;0;0;0]; 508 est_fc=0; 509 est_dist=[1;0;0;0;0]; 510 run(fullfile(path_UVMAT,'toolbox_calib','go_calib_optim')); 511 512 GeometryCalib.CalibrationType='tsai_matlab'; 513 GeometryCalib.focal=f(2); 559 Calib.f1=str2num(get(handles.fx,'String')); 560 Calib.f2=str2num(get(handles.fy,'String')); 561 Calib.k=str2num(get(handles.k,'String')); 562 Calib.Cx=str2num(get(handles.Cx,'String')); 563 Calib.Cy=str2num(get(handles.Cy,'String')); 564 565 fct_path=fullfile(path_UVMAT,'toolbox_calib'); 566 addpath(fct_path) 567 % [omc1,Tc1,Rc1,H,x,ex,JJ] = compute_extrinsic(x_1,X_1,... 568 % [Calib.f Calib.f*Calib.sx]',... 569 % [Calib.Cx Calib.Cy]',... 570 % [-Calib.kappa1*Calib.f^2 0 0 0 0]); 571 [omc1,Tc1,Rc1,H,x,ex,JJ] = compute_extrinsic(x_1,X_1,... 572 [Calib.f1 Calib.f2]',... 573 [Calib.Cx Calib.Cy]',... 574 [-Calib.k 0 0 0 0]); 575 %get the euler angles ??? 576 rmpath(fct_path); 577 578 std(ex') 579 GeometryCalib.CalibrationType='3D_extrinsic'; 580 GeometryCalib.focal=Calib.f2; 514 581 GeometryCalib.dpx_dpy=[1 1]; 515 GeometryCalib.Cx_Cy= cc';516 GeometryCalib.sx= fc(1)/fc(2);517 GeometryCalib.kappa1= -k(1)/f(2)^2;582 GeometryCalib.Cx_Cy=[Calib.Cx Calib.Cy]; 583 GeometryCalib.sx=Calib.f1/Calib.f2; 584 GeometryCalib.kappa1=Calib.k/(Calib.f2*Calib.f2); 518 585 GeometryCalib.CoordUnit=[];% default value, to be updated by the calling function 519 GeometryCalib.Tx_Ty_Tz=Tc_1'; 520 GeometryCalib.R=Rc_1; 521 % Calib.dpx=GeometryCalib.dpx_dpy(1); 522 % Calib.dpy=GeometryCalib.dpx_dpy(2); 523 % Calib.sx=GeometryCalib.sx; 524 % Calib.Cx=GeometryCalib.Cx_Cy(1); 525 % Calib.Cy=GeometryCalib.Cx_Cy(2); 526 % Calib.kappa1=GeometryCalib.kappa1; 527 % Calib.f=GeometryCalib.focal; 528 % Calib.Tx=GeometryCalib.Tx_Ty_Tz(1); 529 % Calib.Ty=GeometryCalib.Tx_Ty_Tz(2); 530 % Calib.Tz=GeometryCalib.Tx_Ty_Tz(3); 531 % Calib.R=GeometryCalib.R; 532 % X=Coord(:,1); 533 % Y=Coord(:,2); 534 % Z=Coord(:,3); 535 % x_ima=Coord(:,4); 536 % y_ima=Coord(:,5); 537 % [Xpoints,Ypoints]=px_XYZ(Calib,X,Y,Z); 538 % 539 % GeometryCalib.ErrorRms(1)=sqrt(mean((Xpoints-x_ima).*(Xpoints-x_ima))); 540 % [GeometryCalib.ErrorMax(1),GeometryCalib.IndexMax(1)]=max(abs(Xpoints-x_ima)); 541 % GeometryCalib.ErrorRms(2)=sqrt(mean((Ypoints-y_ima).*(Ypoints-y_ima))); 542 % [GeometryCalib.ErrorMax(2),GeometryCalib.IndexMax(2)]=max(abs(Ypoints-y_ima)); 543 544 function GeometryCalib=calib_tsai(Coord) 586 GeometryCalib.Tx_Ty_Tz=Tc1'; 587 %inversion of z axis 588 GeometryCalib.R=Rc1; 589 %GeometryCalib.R(3,1:3)=-GeometryCalib.R(3,1:3);%inversion for z upward 590 591 592 %------------------------------------------------------------------------ 593 %function GeometryCalib=calib_tsai_heikkila(Coord) 594 % TEST: NOT IMPLEMENTED 595 %------------------------------------------------------------------ 596 % path_uvmat=which('uvmat');% check the path detected for source file uvmat 597 % path_UVMAT=fileparts(path_uvmat); %path to UVMAT 598 % path_calib=fullfile(path_UVMAT,'toolbox_calib_heikkila'); 599 % addpath(path_calib) 600 % npoints=size(Coord,1); 601 % Coord(:,1:3)=10*Coord(:,1:3); 602 % Coord=[Coord zeros(npoints,2) -ones(npoints,1)]; 603 % [par,pos,iter,res,er,C]=cacal('dalsa',Coord); 604 % GeometryCalib.CalibrationType='tsai'; 605 % GeometryCalib.focal=par(2); 606 607 608 %-------------------------------------------------------------------------- 609 function GeometryCalib=calib_tsai(Coord,handles)% old version using gauthier's bianry ccal_fo 545 610 %------------------------------------------------------------------------ 546 611 %TSAI 547 % 'calibration_lin' provides a linear transform on coordinates,548 612 path_uvmat=which('uvmat');% check the path detected for source file uvmat 549 613 path_UVMAT=fileparts(path_uvmat); %path to UVMAT 550 % if isunix 551 %fid = fopen(fullfile(path_UVMAT,'PARAM_LINUX.txt'),'r');%open the file with civ binary names 552 xmlfile=fullfile(path_UVMAT,'PARAM.xml'); 614 xmlfile=fullfile(path_UVMAT,'PARAM.xml');%name of the file containing names of binary executables 553 615 if exist(xmlfile,'file') 554 t=xmltree(xmlfile); 555 sparam=convert(t); 616 t=xmltree(xmlfile);% read the (xml) file containing names of binary executables 617 sparam=convert(t);% convert to matlab structure 556 618 end 557 619 if ~isfield(sparam,'GeometryCalibBin') … … 570 632 textcoord=num2str(Coord,4); 571 633 dlmwrite('t.txt',textcoord,''); 572 % ['!' Tsai_exe ' -f 1 0 -f2t.txt']573 634 % ['!' Tsai_exe ' -fx 0 -fy t.txt'] 635 eval(['!' Tsai_exe ' -f t.txt > tsaicalib.log']); 574 636 if ~exist('calib.dat','file') 575 637 msgbox_uvmat('ERROR','no output from calibration program Tsai_exe: possibly too few points') … … 577 639 calibdat=dlmread('calib.dat'); 578 640 delete('calib.dat') 579 delete('t.txt')641 %delete('t.txt') 580 642 GeometryCalib.CalibrationType='tsai'; 581 643 GeometryCalib.focal=calibdat(10); … … 604 666 %EN DEDUIRE MATRICE R ?? 605 667 GeometryCalib.R=[r1,r2,r3;r4,r5,r6;r7,r8,r9]; 606 %erreur a caracteriser? 607 % %check error 608 % Calib.dpx=GeometryCalib.dpx_dpy(1); 609 % Calib.dpy=GeometryCalib.dpx_dpy(2); 610 % Calib.sx=GeometryCalib.sx; 611 % Calib.Cx=GeometryCalib.Cx_Cy(1); 612 % Calib.Cy=GeometryCalib.Cx_Cy(2); 613 % Calib.kappa1=GeometryCalib.kappa1; 614 % Calib.f=GeometryCalib.focal; 615 % Calib.Tx=GeometryCalib.Tx_Ty_Tz(1); 616 % Calib.Ty=GeometryCalib.Tx_Ty_Tz(2); 617 % Calib.Tz=GeometryCalib.Tx_Ty_Tz(3); 618 % Calib.R=GeometryCalib.R; 619 % X=Coord(:,1); 620 % Y=Coord(:,2); 621 % Z=Coord(:,3); 622 % x_ima=Coord(:,4); 623 % y_ima=Coord(:,5); 624 % [Xpoints,Ypoints]=px_XYZ(Calib,X,Y,Z); 625 % 626 % GeometryCalib.ErrorRms(1)=sqrt(mean((Xpoints-x_ima).*(Xpoints-x_ima))); 627 % GeometryCalib.ErrorMax(1)=max(abs(Xpoints-x_ima)); 628 % GeometryCalib.ErrorRms(2)=sqrt(mean((Ypoints-y_ima).*(Ypoints-y_ima))); 629 % GeometryCalib.ErrorMax(2)=max(abs(Ypoints-y_ima)); 630 631 632 %------------------------------------------------------------------------ 633 % --- Executes on button press in rotation. 634 function rotation_Callback(hObject, eventdata, handles) 635 %------------------------------------------------------------------------ 636 angle_rot=(pi/180)*str2num(get(handles.Phi,'String')); 668 669 %------------------------------------------------------------------------ 670 % --- determine the rms of calibration error 671 function ErrorRms=error_calib(calib_param,Calib,Coord) 672 %calib_param: vector of free calibration parameters (to optimise) 673 %Calib: structure of the given calibration parameters 674 %Coord: list of phys coordinates (columns 1-3, and pixel coordinates (columns 4-5) 675 Calib.f=25; 676 Calib.dpx=0.012; 677 Calib.dpy=0.012; 678 Calib.sx=1; 679 Calib.Cx=512; 680 Calib.Cy=512; 681 Calib.kappa1=calib_param(1); 682 Calib.Tx=calib_param(2); 683 Calib.Ty=calib_param(3); 684 Calib.Tz=calib_param(4); 685 alpha=calib_param(5); 686 Calib.R=[cos(alpha) sin(alpha) 0;-sin(alpha) cos(alpha) 0;0 0 -1]; 687 688 X=Coord(:,1); 689 Y=Coord(:,2); 690 Z=Coord(:,3); 691 x_ima=Coord(:,4); 692 y_ima=Coord(:,5); 693 [Xpoints,Ypoints]=px_XYZ(Calib,X,Y,Z); 694 ErrorRms(1)=sqrt(mean((Xpoints-x_ima).*(Xpoints-x_ima))); 695 ErrorRms(2)=sqrt(mean((Ypoints-y_ima).*(Ypoints-y_ima))); 696 ErrorRms=mean(ErrorRms); 697 698 %------------------------------------------------------------------------ 699 function XImage_Callback(hObject, eventdata, handles) 700 %------------------------------------------------------------------------ 701 update_list(hObject, eventdata,handles) 702 703 %------------------------------------------------------------------------ 704 function YImage_Callback(hObject, eventdata, handles) 705 %------------------------------------------------------------------------ 706 update_list(hObject, eventdata,handles) 707 708 %------------------------------------------------------------------------ 709 % --- Executes on button press in STORE. 710 function STORE_Callback(hObject, eventdata, handles) 637 711 Coord_cell=get(handles.ListCoord,'String'); 638 data=read_geometry_calib(Coord_cell); 639 data.Coord(:,1)=cos(angle_rot)*data.Coord(:,1)+sin(angle_rot)*data.Coord(:,2); 640 data.Coord(:,1)=-sin(angle_rot)*data.Coord(:,1)+cos(angle_rot)*data.Coord(:,2); 641 set(handles.XObject,'String',num2str(data.Coord(:,1),4)); 642 set(handles.YObject,'String',num2str(data.Coord(:,2),4)); 643 644 %------------------------------------------------------------------------ 645 function XImage_Callback(hObject, eventdata, handles) 712 Object=read_geometry_calib(Coord_cell); 713 unitlist=get(handles.CoordUnit,'String'); 714 unit=unitlist{get(handles.CoordUnit,'value')}; 715 GeometryCalib.CoordUnit=unit; 716 GeometryCalib.SourceCalib.PointCoord=Object.Coord; 717 huvmat=findobj(allchild(0),'Name','uvmat'); 718 hhuvmat=guidata(huvmat);%handles of elements in the GUI uvmat 719 RootPath=''; 720 RootFile=''; 721 if ~isempty(hhuvmat.RootPath)& ~isempty(hhuvmat.RootFile) 722 testhandle=1; 723 RootPath=get(hhuvmat.RootPath,'String'); 724 RootFile=get(hhuvmat.RootFile,'String'); 725 filebase=fullfile(RootPath,RootFile); 726 while exist([filebase '.xml'],'file') 727 filebase=[filebase '~']; 728 end 729 outputfile=[filebase '.xml']; 730 update_imadoc(GeometryCalib,outputfile) 731 listfile=get(handles.coord_files,'string'); 732 if isequal(listfile,{''}) 733 listfile={outputfile}; 734 else 735 listfile=[listfile;{outputfile}]%update the list of coord files 736 end 737 set(handles.coord_files,'string',listfile); 738 end 739 set(handles.ListCoord,'Value',1)% refresh the display of coordinates 740 set(handles.ListCoord,'String',{'......'}) 741 742 %------------------------------------------------------------------------ 743 % --- Executes on button press in CLEAR. 744 function CLEAR_Callback(hObject, eventdata, handles) 745 %------------------------------------------------------------------------ 746 set(handles.coord_files,'Value',1) 747 set(handles.coord_files,'String',{''}) 748 749 %------------------------------------------------------------------------ 750 function XObject_Callback(hObject, eventdata, handles) 646 751 %------------------------------------------------------------------------ 647 752 update_list(hObject, eventdata,handles) 648 753 649 754 %------------------------------------------------------------------------ 650 function Y Image_Callback(hObject, eventdata, handles)755 function YObject_Callback(hObject, eventdata, handles) 651 756 %------------------------------------------------------------------------ 652 757 update_list(hObject, eventdata,handles) 653 758 654 function XObject_Callback(hObject, eventdata, handles) 655 update_list(hObject, eventdata,handles) 656 657 function YObject_Callback(hObject, eventdata, handles) 658 update_list(hObject, eventdata,handles) 659 759 %------------------------------------------------------------------------ 660 760 function ZObject_Callback(hObject, eventdata, handles) 761 %------------------------------------------------------------------------ 661 762 update_list(hObject, eventdata,handles) 662 763 … … 748 849 %------------------------------------------------------------------------ 749 850 choice=get(handles.edit_append,'Value'); 750 % if choice==1751 % Coord=get(handles.ListCoord,'String');752 % val=length(Coord);753 % if val>=1 & isequal(Coord{val},'')754 % val=val-1; %do not take into account blank755 % end756 % Coord{val+1}='';757 % set(handles.ListCoord,'String',Coord)758 % set(handles.ListCoord,'Value',val+1)759 % end760 851 if choice 761 852 set(handles.edit_append,'BackgroundColor',[1 1 0]) … … 817 908 end 818 909 819 % %------------------------------------------------------------------------820 % % --- Executes on button press in append_point.821 % function append_point_Callback(hObject, eventdata, handles)822 % %------------------------------------------------------------------------823 % Coord=get(handles.ListCoord,'String');824 % val=length(Coord);825 % if val>=1 & isequal(Coord{val},'')826 % val=val-1; %do not take into account blank827 % end828 % Coord{val+1}='';829 % set(handles.ListCoord,'String',Coord)830 % set(handles.ListCoord,'Value',val+1)831 832 %------------------------------------------------------------------------833 function MenuOpen_Callback(hObject, eventdata, handles)834 %------------------------------------------------------------------------835 %get the object file836 huvmat=findobj(allchild(0),'Name','uvmat');837 UvData=get(huvmat,'UserData');838 hchild=get(huvmat,'Children');839 hrootpath=findobj(hchild,'Tag','RootPath');840 oldfile=get(hrootpath,'String');841 if isempty(oldfile)842 oldfile='';843 end844 %[FileName,PathName] = uigetfile('*.civ','Select a .civ file',oldfile)845 [FileName, PathName, filterindex] = uigetfile( ...846 {'*.xml;*.mat', ' (*.xml,*.mat)';847 '*.xml', '.xml files '; ...848 '*.mat', '.mat matlab files '}, ...849 'Pick a file',oldfile);850 fileinput=[PathName FileName];%complete file name851 testblank=findstr(fileinput,' ');%look for blanks852 if ~isempty(testblank)853 msgbox_uvmat('ERROR','forbidden input file name or path: no blank character allowed')854 return855 end856 sizf=size(fileinput);857 if (~ischar(fileinput)|~isequal(sizf(1),1)),return;end858 loadfile(handles,fileinput)859 860 861 910 %------------------------------------------------------------------------ 862 911 function MenuPlot_Callback(hObject, eventdata, handles) … … 955 1004 grid_input=CalibData.grid;%retrieve the previously used grid 956 1005 end 957 [T,CalibData.grid]=create_grid(grid_input,'detect grid');%display the GUI create_grid, read the set of phys coordinates T 1006 [T,CalibData.grid]=create_grid(grid_input,'detect_grid');%display the GUI create_grid, read the set of phys coordinates T 1007 958 1008 set(handles.geometry_calib,'UserData',CalibData)%store the phys grid parameters for later use 959 1009 … … 988 1038 X=[CalibData.grid.x_0 CalibData.grid.x_1 CalibData.grid.x_0 CalibData.grid.x_1]';%corner absissa in the phys coordinates 989 1039 Y=[CalibData.grid.y_0 CalibData.grid.y_0 CalibData.grid.y_1 CalibData.grid.y_1]';%corner ordinates in the phys coordinates 990 %X=[CalibData.grid.x_0 CalibData.grid.x_0 CalibData.grid.x_1 CalibData.grid.x_1]';%corner absissa in the phys coordinates 991 %Y=[CalibData.grid.y_0 CalibData.grid.y_1 CalibData.grid.y_1 CalibData.grid.y_0]';%corner ordinates in the phys coordinate 992 %XY_mat=[ones(size(X)) X Y]; 993 %a_X1=XY_mat\corners_X; %transformation matrix for X 994 %x1=XY_mat*a_X1;%reconstruction 995 %err_X1=max(abs(x1-corners_X));%error 996 %a_Y1=XY_mat\corners_Y;%transformation matrix for X 997 %y1=XY_mat*a_Y1; 998 %err_Y1=max(abs(y1-corners_Y));%error 999 % figure(1) 1000 % hold off 1001 % plot([corners_X;corners_X(1)],[corners_Y;corners_Y(1)],'r') 1002 %test points along contour 1003 % u=[0:0.1:1]; 1004 % x12=u*corners_X(2)+(1-u)*corners_X(1); 1005 % x23=u*corners_X(3)+(1-u)*corners_X(2); 1006 % x34=u*corners_X(4)+(1-u)*corners_X(3); 1007 % x41=u*corners_X(1)+(1-u)*corners_X(4); 1008 % y12=u*corners_Y(2)+(1-u)*corners_Y(1); 1009 % y23=u*corners_Y(3)+(1-u)*corners_Y(2); 1010 % y34=u*corners_Y(4)+(1-u)*corners_Y(3); 1011 % y41=u*corners_Y(1)+(1-u)*corners_Y(4); 1012 % hold on 1013 % plot(x12,y12,'xr') 1014 % plot(x23,y23,'xr') 1015 % plot(x34,y34,'xr') 1016 % plot(x41,y41,'xr') 1040 1017 1041 %calculate transform matrices: 1018 1042 % reference: http://alumni.media.mit.edu/~cwren/interpolator/ by Christopher R. Wren … … 1026 1050 C = [l(7:8)' 1]; 1027 1051 1028 GeometryCalib.CalibrationType='tsai'; %'linear';1052 GeometryCalib.CalibrationType='tsai'; 1029 1053 GeometryCalib.CoordUnit=[];% default value, to be updated by the calling function 1030 1054 GeometryCalib.f=1; … … 1039 1063 GeometryCalib.Tz=1; 1040 1064 GeometryCalib.R=[Amat(1,1),Amat(1,2),0;Amat(2,1),Amat(2,2),0;C(1),C(2),0]; 1041 %montre points du pourtour transformes1042 % for ip=1:numel(u),1043 % XY12(:,ip)=Amat*[x12(ip);y12(ip);1]/(C*[x12(ip);y12(ip);1]);1044 % XY23(:,ip)=Amat*[x23(ip);y23(ip);1]/(C*[x23(ip);y23(ip);1]);1045 % XY34(:,ip)=Amat*[x34(ip);y34(ip);1]/(C*[x34(ip);y34(ip);1]);1046 % XY41(:,ip)=Amat*[x41(ip);y41(ip);1]/(C*[x41(ip);y41(ip);1]);1047 % end1048 % xphys12=u*X(2)+(1-u)*X(1);1049 % xphys23=u*X(3)+(1-u)*X(2);1050 % xphys34=u*X(4)+(1-u)*X(3);1051 % xphys41=u*X(1)+(1-u)*X(4);1052 % yphys12=u*Y(2)+(1-u)*Y(1);1053 % yphys23=u*Y(3)+(1-u)*Y(2);1054 % yphys34=u*Y(4)+(1-u)*Y(3);1055 % yphys41=u*Y(1)+(1-u)*Y(4);1056 % for ip=1:numel(u),1057 % XY12(:,ip)=Amat*[xphys12(ip);yphys12(ip);1]/(C*[xphys12(ip);yphys12(ip);1]);1058 % XY23(:,ip)=Amat*[xphys23(ip);yphys23(ip);1]/(C*[xphys23(ip);yphys23(ip);1]);1059 % XY34(:,ip)=Amat*[xphys34(ip);yphys34(ip);1]/(C*[xphys34(ip);yphys34(ip);1]);1060 % XY41(:,ip)=Amat*[xphys41(ip);yphys41(ip);1]/(C*[xphys41(ip);yphys41(ip);1]);1061 % end1062 % x12=XY12(1,:);1063 % y12=XY12(2,:);1064 % x23=XY23(1,:);1065 % y23=XY23(2,:);1066 % x34=XY34(1,:);1067 % y34=XY34(2,:);1068 % x41=XY41(1,:);1069 % y41=XY41(2,:);1070 % [x12,y12]=px_XYZ(GeometryCalib,xphys12,yphys12);1071 % [x23,y23]=px_XYZ(GeometryCalib,xphys23,yphys23);1072 % [x34,y34]=px_XYZ(GeometryCalib,xphys34,yphys34);1073 % [x41,y41]=px_XYZ(GeometryCalib,xphys41,yphys41);1074 % plot(x12,y12,'xb')1075 % plot(x23,y23,'xb')1076 % plot(x34,y34,'xb')1077 % plot(x41,y41,'xb')1078 % figure(2)1079 % hold off1080 % plot(XY12(1,:),XY12(2,:),'ob')1081 % hold on1082 % plot(XY23(1,:),XY23(2,:),'ob')1083 % plot(XY34(1,:),XY34(2,:),'ob')1084 % plot(XY41(1,:),XY41(2,:),'ob')1085 % plot(xphys12,yphys12,'ob')1086 % hold on1087 % plot(xphys23,yphys23,'ob')1088 % plot(xphys34,yphys34,'ob')1089 % plot(xphys41,yphys41,'ob')1090 1065 1091 1066 [Amod,Rangx,Rangy]=phys_Ima(A-min(min(A)),GeometryCalib,0); 1092 1067 1093 1068 Amod=double(Amod); 1094 figure(12) 1095 Amax=max(max(Amod));1096 image(Rangx,Rangy,uint8(255*Amod/Amax))1069 % figure(12) display corrected image 1070 % Amax=max(max(Amod)); 1071 % image(Rangx,Rangy,uint8(255*Amod/Amax)) 1097 1072 Dx=(Rangx(2)-Rangx(1))/(npxy(2)-1); %x mesh in real space 1098 1073 Dy=(Rangy(2)-Rangy(1))/(npxy(1)-1); %y mesh in real space … … 1103 1078 i0=1+round((T(ipoint,1)-Rangx(1))/Dx);%round(Xpx(ipoint)); 1104 1079 j0=1+round((T(ipoint,2)-Rangy(1))/Dy);%round(Xpx(ipoint)); 1105 Asub=Amod(j0-ind_range_y:j0+ind_range_y,i0-ind_range_x:i0+ind_range_x); 1080 j0min=max(j0-ind_range_y,1); 1081 j0max=min(j0+ind_range_y,size(Amod,1)); 1082 i0min=max(i0-ind_range_x,1); 1083 i0max=min(i0+ind_range_x,size(Amod,2)); 1084 Asub=Amod(j0min:j0max,i0min:i0max); 1106 1085 x_profile=sum(Asub,1); 1107 1086 y_profile=sum(Asub,2); … … 1111 1090 x_shift=0; 1112 1091 y_shift=0; 1113 if ind_x_max+2<=2*ind_range_x+1 && ind_x_max-2>=1 1092 %if ind_x_max+2<=2*ind_range_x+1 && ind_x_max-2>=1 1093 if ind_x_max+2<=numel(x_profile) && ind_x_max-2>=1 1114 1094 Atop=x_profile(ind_x_max-2:ind_x_max+2); 1115 1095 x_shift=sum(Atop.*[-2 -1 0 1 2])/sum(Atop); 1116 1096 end 1117 if ind_ y_max+2<=2*ind_range_y+1&& ind_y_max-2>=11097 if ind_x_max+2<=numel(y_profile) && ind_y_max-2>=1 1118 1098 Atop=y_profile(ind_y_max-2:ind_y_max+2); 1119 1099 y_shift=sum(Atop.*[-2 -1 0 1 2]')/sum(Atop); 1120 1100 end 1121 Delta(ipoint,1)=(x_shift+ind_x_max -ind_range_x-1)*Dx;%shift from the initial guess1122 Delta(ipoint,2)=(y_shift+ind_y_max -ind_range_y-1)*Dy;1101 Delta(ipoint,1)=(x_shift+ind_x_max+i0min-i0-1)*Dx;%shift from the initial guess 1102 Delta(ipoint,2)=(y_shift+ind_y_max+j0min-j0-1)*Dy; 1123 1103 end 1124 1104 Tmod=T(:,(1:2))+Delta; … … 1127 1107 Coord{ipoint,1}=num2str(T(ipoint,1),4);%display coordiantes with 4 digits 1128 1108 Coord{ipoint,2}=num2str(T(ipoint,2),4);%display coordiantes with 4 digits 1129 Coord{ipoint,3}= '0';1130 Coord{ipoint,4}=num2str(Xpx(ipoint),4);%display coordiantes with 4 digi 1131 Coord{ipoint,5}=num2str(Ypx(ipoint),4);%display coordiantes with 4 digi 1109 Coord{ipoint,3}=num2str(T(ipoint,3),4);%display coordiantes with 4 digits; 1110 Coord{ipoint,4}=num2str(Xpx(ipoint),4);%display coordiantes with 4 digits 1111 Coord{ipoint,5}=num2str(Ypx(ipoint),4);%display coordiantes with 4 digits 1132 1112 end 1133 1113 Tabchar=cell2tab(Coord(end:-1:1,:),' | '); … … 1209 1189 set(handles.ListCoord,'Value',1) 1210 1190 set(handles.ListCoord,'String',Tabchar) 1191 1192 1193 % %------------------------------------------------------------------------ 1194 % % --- Executes on button press in rotation. 1195 % function rotation_Callback(hObject, eventdata, handles) 1196 % %------------------------------------------------------------------------ 1197 % angle_rot=(pi/180)*str2num(get(handles.Phi,'String')); 1198 % Coord_cell=get(handles.ListCoord,'String'); 1199 % data=read_geometry_calib(Coord_cell); 1200 % data.Coord(:,1)=cos(angle_rot)*data.Coord(:,1)+sin(angle_rot)*data.Coord(:,2); 1201 % data.Coord(:,1)=-sin(angle_rot)*data.Coord(:,1)+cos(angle_rot)*data.Coord(:,2); 1202 % set(handles.XObject,'String',num2str(data.Coord(:,1),4)); 1203 % set(handles.YObject,'String',num2str(data.Coord(:,2),4)); 1204 1211 1205 1212 1206 %------------------------------------------------------------------------ … … 1287 1281 Zphys=Calib.SliceCoord(Zindex,3);%GENERALISER AUX CAS AVEC ANGLE 1288 1282 else 1289 % if exist('Z','var') 1290 % Zphys=Z; 1291 % else 1292 Zphys=0; 1293 % end 1283 Zphys=0; 1294 1284 end 1295 1285 if ~exist('X','var')||~exist('Y','var') … … 1329 1319 Yphys=(A21.*Xu+A22.*Yu+Y0)./denom; 1330 1320 end 1321 1322 1323 % -------------------------------------------------------------------- 1324 function MenuImportPoints_Callback(hObject, eventdata, handles) 1325 fileinput=browse_xml(hObject, eventdata, handles) 1326 if isempty(fileinput) 1327 return 1328 end 1329 [s,errormsg]=imadoc2struct(fileinput,'GeometryCalib'); 1330 GeometryCalib=s.GeometryCalib; 1331 GeometryCalib=load_calib(hObject, eventdata, handles) 1332 calib=reshape(GeometryCalib.PointCoord',[],1); 1333 for ilist=1:numel(calib) 1334 CoordCell{ilist}=num2str(calib(ilist)); 1335 end 1336 CoordCell=reshape(CoordCell,[],5); 1337 Tabchar=cell2tab(CoordCell,' | ');%transform cells into table ready for display 1338 Tabchar=[Tabchar;{'......'}]; 1339 set(handles.ListCoord,'Value',1) 1340 set(handles.ListCoord,'String',Tabchar) 1341 MenuPlot_Callback(handles.geometry_calib, [], handles) 1342 1343 % ----------------------------------------------------------------------- 1344 function MenuImportIntrinsic_Callback(hObject, eventdata, handles) 1345 %------------------------------------------------------------------------ 1346 fileinput=browse_xml(hObject, eventdata, handles); 1347 if isempty(fileinput) 1348 return 1349 end 1350 [s,errormsg]=imadoc2struct(fileinput,'GeometryCalib'); 1351 GeometryCalib=s.GeometryCalib; 1352 k=GeometryCalib.kappa1 * GeometryCalib.f*GeometryCalib.f; 1353 f1=GeometryCalib.f*GeometryCalib.sx/GeometryCalib.dpx; 1354 f2=GeometryCalib.f/GeometryCalib.dpy; 1355 Cx=GeometryCalib.Cx; 1356 Cy=GeometryCalib.Cy; 1357 set(handles.fx,'String',num2str(f1,'%1.1f')) 1358 set(handles.fy,'String',num2str(f2,'%1.1f')) 1359 set(handles.k,'String',num2str(k,'%1.4f')) 1360 set(handles.Cx,'String',num2str(Cx,'%1.1f')) 1361 set(handles.Cy,'String',num2str(Cy,'%1.1f')) 1362 1363 % ----------------------------------------------------------------------- 1364 function MenuImportAll_Callback(hObject, eventdata, handles) 1365 %------------------------------------------------------------------------ 1366 fileinput=browse_xml(hObject, eventdata, handles) 1367 if ~isempty(fileinput) 1368 loadfile(handles,fileinput) 1369 end 1370 1371 % ----------------------------------------------------------------------- 1372 % --- Executes on menubar option Import/Grid file: introduce previous grid files 1373 function MenuGridFile_Callback(hObject, eventdata, handles) 1374 % ----------------------------------------------------------------------- 1375 inputfile=browse_xml(hObject, eventdata, handles) 1376 listfile=get(handles.coord_files,'string'); 1377 if isequal(listfile,{''}) 1378 listfile={inputfile}; 1379 else 1380 listfile=[listfile;{inputfile}]%update the list of coord files 1381 end 1382 set(handles.coord_files,'string',listfile); 1383 1384 %------------------------------------------------------------------------ 1385 function fileinput=browse_xml(hObject, eventdata, handles) 1386 %------------------------------------------------------------------------ 1387 fileinput=[];%default 1388 oldfile=''; %default 1389 UserData=get(handles.geometry_calib,'UserData'); 1390 if isfield(UserData,'XmlInput') 1391 oldfile=UserData.XmlInput; 1392 end 1393 [FileName, PathName, filterindex] = uigetfile( ... 1394 {'*.xml;*.mat', ' (*.xml,*.mat)'; 1395 '*.xml', '.xml files '; ... 1396 '*.mat', '.mat matlab files '}, ... 1397 'Pick a file',oldfile); 1398 fileinput=[PathName FileName];%complete file name 1399 testblank=findstr(fileinput,' ');%look for blanks 1400 if ~isempty(testblank) 1401 msgbox_uvmat('ERROR','forbidden input file name or path: no blank character allowed') 1402 return 1403 end 1404 sizf=size(fileinput); 1405 if (~ischar(fileinput)||~isequal(sizf(1),1)),return;end 1406 UserData.XmlInput=fileinput; 1407 set(handles.geometry_calib,'UserData',UserData)%record current file foer further use of browser 1408 1409 % ----------------------------------------------------------------------- 1410 function loadfile(handles,fileinput) 1411 %------------------------------------------------------------------------ 1412 [s,errormsg]=imadoc2struct(fileinput,'GeometryCalib'); 1413 GeometryCalib=s.GeometryCalib; 1414 if isempty(GeometryCalib) 1415 Tabchar={}; 1416 CoordCell={}; 1417 k=0;%default 1418 f1=1000; 1419 f2=1000; 1420 hhuvmat=guidata(findobj(allchild(0),'Name','uvmat')); 1421 Cx=str2num(get(hhuvmat.npx,'String'))/2; 1422 Cy=str2num(get(hhuvmat.npy,'String'))/2; 1423 else 1424 k=GeometryCalib.kappa1 * GeometryCalib.f*GeometryCalib.f; 1425 f1=GeometryCalib.f*GeometryCalib.sx/GeometryCalib.dpx; 1426 f2=GeometryCalib.f/GeometryCalib.dpy; 1427 Cx=GeometryCalib.Cx; 1428 Cy=GeometryCalib.Cy; 1429 set(handles.fx,'String',num2str(f1,'%1.1f')) 1430 set(handles.fy,'String',num2str(f2,'%1.1f')) 1431 set(handles.k,'String',num2str(k,'%1.4f')) 1432 set(handles.Cx,'String',num2str(Cx,'%1.1f')) 1433 set(handles.Cy,'String',num2str(Cy,'%1.1f')) 1434 calib=reshape(GeometryCalib.PointCoord',[],1); 1435 for ilist=1:numel(calib) 1436 CoordCell{ilist}=num2str(calib(ilist)); 1437 end 1438 CoordCell=reshape(CoordCell,[],5); 1439 Tabchar=cell2tab(CoordCell,' | ');%transform cells into table ready for display 1440 set(handles.ListCoord,'Value',1) 1441 set(handles.ListCoord,'String',Tabchar) 1442 MenuPlot_Callback(handles.geometry_calib, [], handles) 1443 end 1444 Tabchar=[Tabchar;{'......'}]; 1445 if isempty(CoordCell)% allow mouse action by default in the absence of input points 1446 set(handles.edit_append,'Value',1) 1447 set(handles.edit_append,'BackgroundColor',[1 1 0]) 1448 else % does not allow mouse action by default in the presence of input points 1449 set(handles.edit_append,'Value',0) 1450 set(handles.edit_append,'BackgroundColor',[0.7 0.7 0.7]) 1451 end 1452 1453 1454 1455 1456 1457 % -------------------------------------------------------------------- 1458 % --- Executes on button press in CLEAR_PTS: clear the list of calibration points 1459 function CLEAR_PTS_Callback(hObject, eventdata, handles) 1460 % -------------------------------------------------------------------- 1461 set(handles.ListCoord,'Value',1)% refresh the display of coordinates 1462 set(handles.ListCoord,'String',{'......'}) 1463 -
trunk/src/imadoc2struct.m
r89 r109 1 1 %'imadoc2struct': reads the xml file for image documentation 2 2 %------------------------------------------------------------------------ 3 % function [s,errormsg]=imadoc2struct(ImaDoc )3 % function [s,errormsg]=imadoc2struct(ImaDoc,option) 4 4 % 5 5 % OUTPUT: … … 13 13 % INPUT: 14 14 % ImaDoc: full name of the xml input file with head key ImaDoc 15 16 function [s,errormsg]=imadoc2struct(ImaDoc) 17 15 % option: ='GeometryCalib': read the data of GeometryCalib, including source point coordinates 16 17 function [s,errormsg]=imadoc2struct(ImaDoc,option) 18 if ~exist('option','var') 19 option='default'; 20 end 18 21 errormsg=[];%default 19 22 s.Heading=[];%default … … 88 91 Dtj=reshape(Dtj'*ones(1,NbDtj),1,NbDtj*numel(Dtj)); %concatene Dti vector NbDti times 89 92 Dtj=[0 Dtj]; 90 % Time_val'91 % ones(1,numel(Dtj))92 % ones(numel(Time_val'),1)93 % cumsum(Dtj)94 93 Time_val=Time_val*ones(1,numel(Dtj))+ones(numel(Time_val),1)*cumsum(Dtj);% produce a time matrix with Dtj 95 94 end … … 107 106 end 108 107 end 109 % if size(s.Time,1)==1110 % s.Time=(s.Time)'; %change vector into column111 % end112 108 end 113 109 … … 210 206 end 211 207 end 208 if strcmp(option,'GeometryCalib') 209 tsai.PointCoord=get_value(subt,'/GeometryCalib/SourceCalib/PointCoord',[0 0 0 0 0]);%time in TimeUnit 210 end 212 211 s.GeometryCalib=tsai; 213 212 end … … 228 227 val_read=str2num(get(t,uid_child(icell),'value')); 229 228 if ~isempty(val_read) 230 val(icell )=val_read;229 val(icell,:)=val_read; 231 230 end 232 231 end -
trunk/src/plot_field.m
r107 r109 243 243 function hdisplay=plot_text(FieldData,hdisplay_in) 244 244 %------------------------------------------------------------------- 245 hdisplay_in246 245 if exist('hdisplay_in','var') && ~isempty(hdisplay_in) && ishandle(hdisplay_in) && isequal(get(hdisplay_in,'Type'),'uicontrol') 247 246 hdisplay=hdisplay_in; … … 687 686 end 688 687 x_label=[Data.ListVarName{ivar_X} '(' x_units ')']; 689 end 690 % if isfield(Data,'VarAttribute') 691 % VarAttribute=Data.VarAttribute; 692 % end 688 end 693 689 end 694 690 … … 704 700 siz=numel(np); 705 701 if siz>3 706 msgbox_uvmat('ERROR', 'unrecognized scalar type ')702 msgbox_uvmat('ERROR',['unrecognized scalar type: ' num2str(siz) ' dimensions']) 707 703 return 708 704 end … … 794 790 if ~isequal(PlotParam.Scalar.Contours,1) 795 791 % rescale the grey levels with min and max, put a grey scale colorbar 792 B=A; 796 793 if BW 797 B=A;798 794 vec=linspace(0,1,255);%define a linear greyscale colormap 799 795 map=[vec' vec' vec']; 800 796 colormap(map); %grey scale color map 801 797 else 802 B=A;803 798 colormap('default'); % standard faulse colors for div, vort , scalar fields 804 799 end -
trunk/src/proj_field.m
r77 r109 12 12 % .NbPix; 13 13 % .DimName= names of the matrix dimensions (matlab cell) 14 % .DimValue= values of the matricx dimensions (matlab vector, same length as .DimName);15 14 % .VarName= names of the variables [ProjData.VarName {'A','AMean','AMin','AMax'}]; 16 15 % .VarDimNameIndex= dimensions of the variables, indicated by indices in the list .DimName; … … 34 33 % .ListGlobalAttribute: cell listing the names of the global attributes 35 34 % .Att_1,Att_2... : values of the global attributes 36 % .ListDimName: cell listing the names of the array dimensions37 % .DimValue: array dimension values (Matlab vector with the same length as .ListDimName38 35 % .ListVarName: cell listing the names of the variables 39 % .VarDimIndex: cell containing the set of dimension indices (in list .ListDimName) for each variable of .ListVarName40 36 % .VarAttribute: cell of structures s containing names and values of variable attributes (s.name=value) for each variable of .ListVarName 41 37 % .Var1, .Var2....: variables (Matlab arrays) with names listed in .ListVarName … … 391 387 %A REVOIR, GENERALISER: UTILISER proj_line 392 388 ProjData.NbDim=1; 393 ProjData.ListDimName={};%name of dimension394 ProjData.DimValue=[];%values of dimension (nbre of vectors)389 %ProjData.ListDimName={};%name of dimension 390 %ProjData.DimValue=[];%values of dimension (nbre of vectors) 395 391 ProjData.ListVarName={}; 396 392 %ProjData.VarDimIndex={}; … … 966 962 DY=abs(ObjectData.DY);%mesh of interpolation points 967 963 end 968 if ~ isequal(ProjMode,'projection') & (DX==0|DY==0)964 if ~strcmp(ProjMode,'projection') && (DX==0||DY==0) 969 965 errormsg='DX or DY missing'; 970 966 display(errormsg) … … 997 993 ProjData=proj_heading(FieldData,ObjectData); 998 994 ProjData.NbDim=2; 999 ProjData.ListDimName={};%name of dimension1000 ProjData.DimValue=[];%values of dimension (nbre of vectors)1001 995 ProjData.ListVarName={}; 1002 996 ProjData.VarDimName={}; … … 1045 1039 DimCell={DimCell};%name of dimensions 1046 1040 end 1047 1041 1048 1042 %case of input fields with unstructured coordinates 1049 1043 if testX … … 1134 1128 if isequal(ObjectData.ProjMode,'projection') 1135 1129 %the list of dimension 1136 ProjData.ListDimName=[ProjData.ListDimName FieldData.VarDimName(VarIndex(1))];%add the point index to the list of dimensions 1137 ProjData.DimValue=[ProjData.DimValue length(coord_X)]; 1130 %ProjData.ListDimName=[ProjData.ListDimName FieldData.VarDimName(VarIndex(1))];%add the point index to the list of dimensions 1131 %ProjData.DimValue=[ProjData. 1132 %length(coord_X)]; 1138 1133 nbvar=0; 1139 1134 for ivar=VarIndex %transfer variables to the projection plane … … 1181 1176 testFF=0; 1182 1177 for ivar=VarIndex 1183 VarName=FieldData.ListVarName{ivar}; 1178 VarName=FieldData.ListVarName{ivar}; 1184 1179 if ~( ivar==ivar_X || ivar==ivar_Y || ivar==ivar_Z || ivar==ivar_F || ivar==ivar_FF || test_anc(ivar)==1) 1185 1180 ivar_new=ivar_new+1; … … 1220 1215 end 1221 1216 end 1222 %case of fields defined on a structured grid1217 %case of input fields defined on a structured grid 1223 1218 else 1224 AYName=FieldData.ListVarName{VarType.coord(1)}; 1225 AXName=FieldData.ListVarName{VarType.coord(2)}; 1219 AYName=FieldData.ListVarName{VarType.coord(1)};%name of input x coordinate (name preserved on projection) 1220 AXName=FieldData.ListVarName{VarType.coord(2)};%name of input y coordinate (name preserved on projection) 1226 1221 eval(['AX=FieldData.' AXName ';']) 1227 1222 eval(['AY=FieldData.' AYName ';']) 1228 VarName=FieldData.ListVarName{VarIndex(1)}; 1229 eval(['DimValue=size(FieldData.' VarName ');']) 1223 VarName=FieldData.ListVarName{VarIndex(1)};%get the first variable of the cell to get the input matrix dimensions 1224 eval(['DimValue=size(FieldData.' VarName ');'])%input matrix dimensions 1230 1225 ListDimName=FieldData.VarDimName{VarIndex(1)}; 1231 1226 ProjData.ListVarName=[{AYName} {AXName} ProjData.ListVarName]; %TODO: check if it already exists in Projdata (several cells) … … 1234 1229 for idim=1:length(ListDimName) 1235 1230 DimName=ListDimName{idim}; 1236 if isequal(DimName,'rgb')|isequal(DimName,'nb_coord')|isequal(DimName,'nb_coord_i')1231 if strcmp(DimName,'rgb')||strcmp(DimName,'nb_coord')||strcmp(DimName,'nb_coord_i') 1237 1232 nbcolor=DimValue(idim); 1238 DimIndices(idim)=[];1239 1233 DimValue(idim)=[]; 1240 1234 end 1241 1235 if isequal(DimName,'nb_coord_j')% NOTE: CASE OF TENSOR NOT TREATED 1242 DimIndices(idim)=[];1243 1236 DimValue(idim)=[]; 1244 1237 end 1245 1238 end 1246 1239 ind_1=find(DimValue==1); 1247 DimIndices(ind_1)=[]; %suppress singleton dimensions1248 % indxy=find(DimVarIndex(DimIndices));%select dimension variables (DimIndices non zero)1249 nb_dim=length(DimIndices);%number of space dimensions1250 1240 Coord_z=[]; 1251 1241 Coord_y=[]; 1252 1242 Coord_x=[]; 1253 1243 nb_dim=numel(size(DimValue)); 1254 1244 for idim=1:nb_dim %loop on space dimensions 1255 1245 test_interp(idim)=0;%test for coordiate interpolation (non regular grid), =0 by default 1256 test_coord(idim)=0;%test for defined coordinates, =0 by default 1257 ivar=DimVarIndex(DimIndices(idim));% index of the variable corresponding to the current dimension 1258 if ~isequal(ivar,0)% a variable corresponds to the current dimension 1259 eval(['Coord{idim}=FieldData.' FieldData.ListVarName{ivar} ';']) ;% position for the first index 1260 DCoord=diff(Coord{idim}); 1261 DCoord_min(idim)=min(DCoord); 1262 DCoord_max=max(DCoord); 1263 test_direct(idim)=DCoord_max>0;% =1 for increasing values, 0 otherwise 1264 test_direct_min=DCoord_min(idim)>0;% =1 for increasing values, 0 otherwise 1265 if ~isequal(test_direct(idim),test_direct_min) 1266 msgbox_uvmat('ERROR',['non monotonic dimension variable # ' num2str(idim) ' in proj_field.m']) 1246 ivar=VarType.coord(idim);% index of the variable corresponding to the current dimension 1247 if ~isequal(ivar,0)% a variable corresponds to the dimension #idim 1248 eval(['Coord{idim}=FieldData.' FieldData.ListVarName{ivar} ';']) ;% coord values for the input field 1249 if numel(Coord{idim})==2 %input array defined on a regular grid 1250 DCoord_min(idim)=(Coord{idim}(2)-Coord{idim}(1))/DimValue(idim); 1251 else 1252 DCoord=diff(Coord{idim});%array of coordinate derivatives for the input field 1253 DCoord_min(idim)=min(DCoord); 1254 DCoord_max=max(DCoord); 1255 % test_direct(idim)=DCoord_max>0;% =1 for increasing values, 0 otherwise 1256 if ~isequal(DCoord_max,DCoord_min(idim)>0) 1257 msgbox_uvmat('ERROR',['non monotonic dimension variable # ' num2str(idim) ' in proj_field.m']) 1267 1258 return 1268 end1269 test_interp(idim)=(DCoord_max-DCoord_min(idim))> 0.0001*abs(DCoord_max);% test grid regularity1270 test_coord(idim)=1;1271 1272 else % no variable associated with the first dimension, look for variable attributes Coord_1, _2 or _31259 end 1260 test_interp(idim)=(DCoord_max-DCoord_min(idim))> 0.0001*abs(DCoord_max);% test grid regularity 1261 end 1262 test_direct(idim)=(DCoord_min(idim)>0); 1263 else % no variable associated with the dimension #idim, the coordinate value is set equal to the matrix index by default 1273 1264 Coord_i_str=['Coord_' num2str(idim)]; 1274 1265 DCoord_min(idim)=1;%default … … 1277 1268 end 1278 1269 end 1279 if nb_dim==2 1280 if DY==0 1281 DY=abs(DCoord_min(1)); 1282 end 1283 npY=1+round(abs(Coord{1}(end)-Coord{1}(1))/DY);%nbre of points after interpolation 1284 npy=1+round(abs(Coord{1}(end)-Coord{1}(1))/abs(DCoord_min(1)));%nbre of points after possible interpolation on a regular grid 1285 if DX==0 1286 DX=abs(DCoord_min(2)); 1287 end 1288 npX=1+round(abs(Coord{2}(end)-Coord{2}(1))/DX);%nbre of points after interpol 1289 npx=1+round(abs(Coord{2}(end)-Coord{2}(1))/abs(DCoord_min(2)));%nbre of points after possible interpolation on a regular grid 1290 Coord_y=linspace(Coord{1}(1),Coord{1}(end),npY); 1291 test_direct_y=test_direct(1); 1292 Coord_x=linspace(Coord{2}(1),Coord{2}(end),npX); 1293 test_direct_x=test_direct(2); 1294 DAX=DCoord_min(2); 1295 DAY=DCoord_min(1); 1296 elseif nb_dim==3 1270 if DY==0 1271 DY=abs(DCoord_min(nb_dim-1)); 1272 end 1273 npY=1+round(abs(Coord{nb_dim-1}(end)-Coord{nb_dim-1}(1))/DY);%nbre of points after interpol 1274 if DX==0 1275 DX=abs(DCoord_min(nb_dim)); 1276 end 1277 npX=1+round(abs(Coord{nb_dim}(end)-Coord{nb_dim}(1))/DX);%nbre of points after interpol 1278 for idim=[1:nb_dim] 1279 if test_interp(idim) 1280 DimValue(idim)=1+round(abs(Coord{idim}(end)-Coord{idim}(1))/abs(DCoord_min(idim)));%nbre of points after possible interpolation on a regular gri 1281 end 1282 end 1283 Coord_y=linspace(Coord{nb_dim-1}(1),Coord{nb_dim-1}(end),npY); 1284 test_direct_y=test_direct(nb_dim-1); 1285 Coord_x=linspace(Coord{nb_dim}(1),Coord{nb_dim}(end),npX); 1286 test_direct_x=test_direct(nb_dim); 1287 DAX=DCoord_min(nb_dim); 1288 DAY=DCoord_min(nb_dim-1); 1289 if nb_dim==3 1297 1290 DZ=abs(DCoord_min(1)); 1298 npz=1+round(abs(Coord{1}(end)-Coord{1}(1))/DZ);%nbre of points after interpolation1299 if DY==01300 DY=abs(DCoord_min(2));1301 end1302 npY=1+round(abs(Coord{2}(end)-Coord{2}(1))/DY);%nbre of points after interpol1303 npy=1+round(abs(Coord{2}(end)-Coord{2}(1))/abs(DCoord_min(2)));%nbre of points before interpol1304 if DX==01305 DX=abs(DCoord_min(3));1306 end1307 npX=1+round(abs(Coord{3}(end)-Coord{3}(1))/DX);%nbre of points after interpol1308 npx=1+round(abs(Coord{3}(end)-Coord{3}(1))/abs(DCoord_min(3)));%nbre of points before interpol1309 1291 Coord_z=linspace(Coord{1}(1),Coord{1}(end),npz); 1310 1292 test_direct_z=test_direct(1); 1311 Coord_y=linspace(Coord{2}(1),Coord{2}(end),npY);1312 test_direct_y=test_direct(2);1313 Coord_x=linspace(Coord{3}(1),Coord{3}(end),npX);1314 test_direct_x=test_direct(3);1315 1293 end 1316 1294 minAX=min(Coord_x); … … 1334 1312 YMin=min(ycor_new); 1335 1313 end 1336 DXinit=(maxAX-minAX)/( npx-1);1337 DYinit=(maxAY-minAY)/( npy-1);1314 DXinit=(maxAX-minAX)/(DimValue(2)-1); 1315 DYinit=(maxAY-minAY)/(DimValue(1)-1); 1338 1316 if DX==0 1339 1317 DX=DXinit; … … 1343 1321 end 1344 1322 npX=floor((XMax-XMin)/DX+1); 1345 npY=floor((YMax-YMin)/DY+1); 1323 npY=floor((YMax-YMin)/DY+1); 1346 1324 if test_direct_y 1347 1325 coord_y_proj=linspace(YMin,YMax,npY);%abscissa of the new pixels along the line … … 1381 1359 min_ind1=max(min_ind1,1);% deals with margin (bound lower than the first index) 1382 1360 min_ind2=max(min_ind2,1); 1383 max_ind1=min(max_ind1, npy);1384 max_ind2=min(max_ind2, npx);1361 max_ind1=min(max_ind1,DimValue(1)); 1362 max_ind2=min(max_ind2,DimValue(2)); 1385 1363 for ivar=VarIndex 1386 1364 VarName=FieldData.ListVarName{ivar}; 1387 1365 ProjData.ListVarName=[ProjData.ListVarName VarName]; 1388 ProjData.VarDim Index=[ProjData.VarDimIndex [nb_dim-1 nb_dim]];1366 ProjData.VarDimName=[ProjData.VarDimName {DimCell}]; 1389 1367 if length(FieldData.VarAttribute)>=ivar 1390 1368 ProjData.VarAttribute{length(ProjData.ListVarName)}=FieldData.VarAttribute{ivar}; … … 1392 1370 eval(['ProjData.' VarName '=FieldData.' VarName '(min_ind1:max_ind1,min_ind2:max_ind2) ;']); 1393 1371 end 1394 else 1395 % case with rotation and/or interpolation 1372 else % case with rotation and/or interpolation 1396 1373 if isempty(Coord_z) %2D case 1397 1374 [X,Y]=meshgrid(coord_x_proj,coord_y_proj);%grid in the new coordinates … … 1402 1379 XIMA=reshape(round(XIMA),1,npX*npY);%indices reorganized in 'line' 1403 1380 YIMA=reshape(round(YIMA),1,npX*npY); 1404 flagin=XIMA>=1 & XIMA<= npx & YIMA >=1 & YIMA<=npy;%flagin=1 inside the original image1381 flagin=XIMA>=1 & XIMA<=DimValue(2) & YIMA >=1 & YIMA<=DimValue(1);%flagin=1 inside the original image 1405 1382 if isequal(ObjectData.ProjMode,'filter') 1406 1383 npx_filter=ceil(abs(DX/DAX)); … … 1411 1388 test_filter=0; 1412 1389 end 1390 eval(['ProjData.' AYName '=[coord_y_proj(1) coord_y_proj(end)];']) %record the new (projected ) y coordinates 1391 eval(['ProjData.' AXName '=[coord_x_proj(1) coord_x_proj(end)];']) %record the new (projected ) x coordinates 1413 1392 for ivar=VarIndex 1414 VarName=FieldData.ListVarName{ivar} ;1415 if test_interp(1) | test_interp(2)%interpolate on a regular grid1416 eval([' FieldData.' VarName '=interp2(Coord{2},Coord{1},FieldData.' VarName ',Coord_x,Coord_y'');']) %TO TEST1393 VarName=FieldData.ListVarName{ivar}; 1394 if test_interp(1) || test_interp(2)%interpolate on a regular grid 1395 eval(['ProjData.' VarName '=interp2(Coord{2},Coord{1},FieldData.' VarName ',Coord_x,Coord_y'');']) %TO TEST 1417 1396 end 1418 1397 %filter the field (image) if option 'filter' is used 1419 1398 if test_filter 1420 1399 Aclass=class(FieldData.A); 1421 eval([' FieldData.' VarName '=filter2(Mfilter,FieldData.' VarName ',''valid'');'])1400 eval(['ProjData.' VarName '=filter2(Mfilter,FieldData.' VarName ',''valid'');']) 1422 1401 if ~isequal(Aclass,'double') 1423 eval([' FieldData.' VarName '=' Aclass '(FieldData.' VarName ');'])%revert to integer values1402 eval(['ProjData.' VarName '=' Aclass '(FieldData.' VarName ');'])%revert to integer values 1424 1403 end 1425 1404 end 1426 eval(['vec_A=reshape(FieldData.' VarName ', npx*npy,nbcolor);'])%put the original image in line1405 eval(['vec_A=reshape(FieldData.' VarName ',[],nbcolor);'])%put the original image in line 1427 1406 ind_in=find(flagin); 1428 1407 ind_out=find(~flagin); 1429 ICOMB=(XIMA-1)* npy+YIMA;1408 ICOMB=(XIMA-1)*DimValue(1)+YIMA; 1430 1409 ICOMB=ICOMB(flagin);%index corresponding to XIMA and YIMA in the aligned original image vec_A 1431 1410 vec_B(ind_in,[1:nbcolor])=vec_A(ICOMB,:); … … 1433 1412 vec_B(ind_out,icolor)=zeros(size(ind_out)); 1434 1413 end 1435 ProjData.ListVarName=[ProjData.ListVarName VarName]; 1436 if length(FieldData.VarAttribute)>=ivar 1414 ProjData.ListVarName=[ProjData.ListVarName VarName]; 1415 ProjData.VarDimName=[ProjData.VarDimName {DimCell}]; 1416 if isfield(FieldData,'VarAttribute')&&length(FieldData.VarAttribute)>=ivar 1437 1417 ProjData.VarAttribute{length(ProjData.ListVarName)+nbcoord}=FieldData.VarAttribute{ivar}; 1438 1418 end … … 1441 1421 ProjData.FF=reshape(~flagin,npY,npX);%false flag A FAIRE: tenir compte d'un flga antérieur 1442 1422 ProjData.ListVarName=[ProjData.ListVarName 'FF']; 1423 ProjData.VarDimName=[ProjData.VarDimName {DimCell}]; 1443 1424 ProjData.VarAttribute{length(ProjData.ListVarName)}.Role='errorflag'; 1444 1425 else %3D case … … 1448 1429 iz=iz_sup(1); 1449 1430 if iz>=1 & iz<=npz 1450 ProjData.ListDimName=[ProjData.ListDimName ListDimName(2:end)];1451 ProjData.DimValue=[ProjData.DimValue npY npX];1431 %ProjData.ListDimName=[ProjData.ListDimName ListDimName(2:end)]; 1432 %ProjData.DimValue=[ProjData.DimValue npY npX]; 1452 1433 for ivar=VarIndex 1453 1434 VarName=FieldData.ListVarName{ivar}; … … 1582 1563 ProjData=proj_heading(FieldData,ObjectData); 1583 1564 ProjData.NbDim=3; 1584 ProjData.ListDimName={};%name of dimension1585 ProjData.DimValue=[];%values of dimension (nbre of vectors)1565 %ProjData.ListDimName={};%name of dimension 1566 %ProjData.DimValue=[];%values of dimension (nbre of vectors) 1586 1567 ProjData.ListVarName={}; 1587 1568 ProjData.VarDimName={}; … … 1717 1698 if isequal(ObjectData.ProjMode,'projection') 1718 1699 %the list of dimension 1719 ProjData.ListDimName=[ProjData.ListDimName FieldData.VarDimName(VarIndex(1))];%add the point index to the list of dimensions1720 ProjData.DimValue=[ProjData.DimValue length(coord_X)];1700 %ProjData.ListDimName=[ProjData.ListDimName FieldData.VarDimName(VarIndex(1))];%add the point index to the list of dimensions 1701 %ProjData.DimValue=[ProjData.DimValue length(coord_X)]; 1721 1702 nbvar=0; 1722 1703 for ivar=VarIndex %transfer variables to the projection plane … … 1843 1824 for idim=1:nb_dim %loop on space dimensions 1844 1825 test_interp(idim)=0;%test for coordiate interpolation (non regular grid), =0 by default 1845 test_coord(idim)=0;%test for defined coordinates, =0 by default1846 1826 ivar=DimVarIndex(DimIndices(idim));% index of the variable corresponding to the current dimension 1847 1827 if ~isequal(ivar,0)% a variable corresponds to the current dimension … … 1857 1837 end 1858 1838 test_interp(idim)=(DCoord_max-DCoord_min(idim))> 0.0001*abs(DCoord_max);% test grid regularity 1859 test_coord(idim)=1;1860 1861 1839 else % no variable associated with the first dimension, look for variable attributes Coord_1, _2 or _3 1862 1840 Coord_i_str=['Coord_' num2str(idim)]; … … 1871 1849 end 1872 1850 npY=1+round(abs(Coord{1}(end)-Coord{1}(1))/DY);%nbre of points after interpolation 1873 npy=1+round(abs(Coord{1}(end)-Coord{1}(1))/abs(DCoord_min(1)));%nbre of points after possible interpolation on a regular grid1851 DimValue(1)=1+round(abs(Coord{1}(end)-Coord{1}(1))/abs(DCoord_min(1)));%nbre of points after possible interpolation on a regular grid 1874 1852 if DX==0 1875 1853 DX=abs(DCoord_min(2)); 1876 1854 end 1877 1855 npX=1+round(abs(Coord{2}(end)-Coord{2}(1))/DX);%nbre of points after interpol 1878 npx=1+round(abs(Coord{2}(end)-Coord{2}(1))/abs(DCoord_min(2)));%nbre of points after possible interpolation on a regular grid1856 DimValue(2)=1+round(abs(Coord{2}(end)-Coord{2}(1))/abs(DCoord_min(2)));%nbre of points after possible interpolation on a regular grid 1879 1857 Coord_y=linspace(Coord{1}(1),Coord{1}(end),npY); 1880 1858 test_direct_y=test_direct(1); … … 1890 1868 end 1891 1869 npY=1+round(abs(Coord{2}(end)-Coord{2}(1))/DY);%nbre of points after interpol 1892 npy=1+round(abs(Coord{2}(end)-Coord{2}(1))/abs(DCoord_min(2)));%nbre of points before interpol1870 DimValue(1)=1+round(abs(Coord{2}(end)-Coord{2}(1))/abs(DCoord_min(2)));%nbre of points before interpol 1893 1871 if DX==0 1894 1872 DX=abs(DCoord_min(3)); 1895 1873 end 1896 1874 npX=1+round(abs(Coord{3}(end)-Coord{3}(1))/DX);%nbre of points after interpol 1897 npx=1+round(abs(Coord{3}(end)-Coord{3}(1))/abs(DCoord_min(3)));%nbre of points before interpol1875 DimValue(2)=1+round(abs(Coord{3}(end)-Coord{3}(1))/abs(DCoord_min(3)));%nbre of points before interpol 1898 1876 Coord_z=linspace(Coord{1}(1),Coord{1}(end),npz); 1899 1877 test_direct_z=test_direct(1); … … 1923 1901 YMin=min(ycor_new); 1924 1902 end 1925 DXinit=(maxAX-minAX)/( npx-1);1926 DYinit=(maxAY-minAY)/( npy-1);1903 DXinit=(maxAX-minAX)/(DimValue(2)-1); 1904 DYinit=(maxAY-minAY)/(DimValue(1)-1); 1927 1905 if DX==0 1928 1906 DX=DXinit; … … 1970 1948 min_ind1=max(min_ind1,1);% deals with margin (bound lower than the first index) 1971 1949 min_ind2=max(min_ind2,1); 1972 max_ind1=min(max_ind1, npy);1973 max_ind2=min(max_ind2, npx);1950 max_ind1=min(max_ind1,DimValue(1)); 1951 max_ind2=min(max_ind2,DimValue(2)); 1974 1952 for ivar=VarIndex 1975 1953 VarName=FieldData.ListVarName{ivar}; 1976 1954 ProjData.ListVarName=[ProjData.ListVarName VarName]; 1977 ProjData.VarDimIndex=[ProjData.VarDimIndex [nb_dim-1 nb_dim]];1955 %ProjData.VarDimIndex=[ProjData.VarDimIndex [nb_dim-1 nb_dim]]; 1978 1956 if length(FieldData.VarAttribute)>=ivar 1979 1957 ProjData.VarAttribute{length(ProjData.ListVarName)}=FieldData.VarAttribute{ivar}; … … 1991 1969 XIMA=reshape(round(XIMA),1,npX*npY);%indices reorganized in 'line' 1992 1970 YIMA=reshape(round(YIMA),1,npX*npY); 1993 flagin=XIMA>=1 & XIMA<= npx & YIMA >=1 & YIMA<=npy;%flagin=1 inside the original image1971 flagin=XIMA>=1 & XIMA<=DimValue(2) & YIMA >=1 & YIMA<=DimValue(1);%flagin=1 inside the original image 1994 1972 if isequal(ObjectData.ProjMode,'filter') 1995 1973 npx_filter=ceil(abs(DX/DAX)); … … 2013 1991 end 2014 1992 end 2015 eval(['vec_A=reshape(FieldData.' VarName ', npx*npy,nbcolor);'])%put the original image in line1993 eval(['vec_A=reshape(FieldData.' VarName ',[],nbcolor);'])%put the original image in line 2016 1994 ind_in=find(flagin); 2017 1995 ind_out=find(~flagin); 2018 ICOMB=(XIMA-1)* npy+YIMA;1996 ICOMB=(XIMA-1)*DimValue(1)+YIMA; 2019 1997 ICOMB=ICOMB(flagin);%index corresponding to XIMA and YIMA in the aligned original image vec_A 2020 1998 vec_B(ind_in,[1:nbcolor])=vec_A(ICOMB,:); … … 2037 2015 iz=iz_sup(1); 2038 2016 if iz>=1 & iz<=npz 2039 ProjData.ListDimName=[ProjData.ListDimName ListDimName(2:end)];2040 ProjData.DimValue=[ProjData.DimValue npY npX];2017 %ProjData.ListDimName=[ProjData.ListDimName ListDimName(2:end)]; 2018 %ProjData.DimValue=[ProjData.DimValue npY npX]; 2041 2019 for ivar=VarIndex 2042 2020 VarName=FieldData.ListVarName{ivar}; -
trunk/src/px_XYZ.m
r92 r109 1 %'px_XYZ': transform physical to image coordinates. 2 %------------------------------------------------------------------------ 3 %[X,Y]=px_XYZ(Calib,Xphys,Yphys,Zphys) 4 %------------------------------------------------------------------------ 5 % OUTPUT: 6 % [X,Y]: image coordinates(in pixels) 7 %------------------------------------------------------------------------ 8 % INPUT: 9 % Calib: structure containing calibration parameters 10 % Xphys,Yphys,Zphys; vectors of physical coordinates for a set of points 1 11 2 12 function [X,Y]=px_XYZ(Calib,Xphys,Yphys,Zphys) -
trunk/src/series/merge_proj.m
r106 r109 59 59 nbview=length(Series.RootFile);%number of views (file series to merge) 60 60 nbfield=size(num_i1{1},1)*size(num_i1{1},2);%number of fields in the time series 61 transform=Series.CoordType; % field transform function61 % transform=Series.CoordType; % field transform function 62 62 hhh=which('mmreader'); 63 63 for iview=1:nbview … … 72 72 73 73 %Calibration data and timing: read the ImaDoc files 74 mode=''; %default74 % mode=''; %default 75 75 timecell={}; 76 76 itime=0; … … 152 152 153 153 % Field and velocity type (the same for all views) 154 FieldName=''; 155 if strcmp(get(hseries.FieldMenu,'Visible'),'on') 154 156 Field_str=get(hseries.FieldMenu,'String'); 155 157 val=get(hseries.FieldMenu,'Value'); … … 163 165 hget_field=findobj(allchild(0),'Name','get_field');%find the get_field... GUI 164 166 SubField=get_field('read_get_field',hObject,eventdata,hget_field); %read the names of the variables to plot in the get_field GUI 167 end 165 168 end 166 169 %detect whether all the files are 'images' or 'netcdf' … … 238 241 if isequal(stopstate,'queue')% enable STOP command from the 'series' interface 239 242 update_waitbar(hseries.waitbar,WaitbarPos,ifile/nbfield) 240 Amerge=0;243 % Amerge=0; 241 244 242 245 %----------LOOP ON VIEWS---------------------- … … 258 261 end % TODO: introduce ListVarName 259 262 npxy=size(Field{iview}.A); 263 Field{iview}.ListVarName={'AX','AY','A'}; 264 Field{iview}.VarDimName={'AX','AY',{'AY','AX'}}; 260 265 Field{iview}.AX=[0.5 npxy(2)-0.5]; % coordinates of the first and last pixel centers 261 266 Field{iview}.AY=[npxy(1)-0.5 0.5]; 262 267 Field{iview}.CoordType='px'; 263 268 Field{iview}.AName='image'; 269 timeread(iview)=0; 264 270 else 265 271 if testcivx … … 287 293 end 288 294 if testcivx 289 295 Field{iview}=calc_field(FieldName,Field{iview}); 290 296 end 291 297 … … 393 399 return 394 400 end 395 for iview=1:nbview 396 if ~isequal(MergeData.ListDimName,Data{iview}.ListDimName) 397 error=1; 398 end 399 if ~isequal(MergeData.ListVarName,Data{iview}.ListVarName) 400 error=1; 401 end 402 end 403 if error 404 MergeData.Txt='ERROR: attempt at merging fields of incompatible type'; 405 return 406 end 407 408 409 410 401 % for iview=1:nbview 402 % if ~isequal(MergeData.ListDimName,Data{iview}.ListDimName) 403 % error=1; 404 % end 405 % if ~isequal(MergeData.ListVarName,Data{iview}.ListVarName) 406 % error=1; 407 % end 408 % end 409 % if error 410 % MergeData.Txt='ERROR: attempt at merging fields of incompatible type'; 411 % return 412 % end 413 % 411 414 %group the variables (fields of 'FieldData') in cells of variables with the same dimensions 412 415 [CellVarIndex,NbDim,VarTypeCell]=find_field_indices(Data{1}); … … 414 417 % CellVarIndex=cells of variable index arrays 415 418 ivar_new=0; % index of the current variable in the projected field 416 icoord=0;417 419 for icell=1:length(CellVarIndex) 418 420 if NbDim(icell)==1 -
trunk/src/sub_field.m
r89 r109 102 102 %check coincidence in positions 103 103 %unstructured coordinates 104 if testX 104 if testX 105 if testU % vector fields 106 U_1_Name=Field_1.ListVarName{VarType_1.vector_x}; 107 V_1_Name=Field_1.ListVarName{VarType_1.vector_y}; 108 eval(['vec_U_1=Field_1.' U_1_Name ';']) 109 eval(['vec_V_1=Field_1.' V_1_Name ';']) 110 nbpoints_x_1=size(vec_U_1,2); 111 nbpoints_y_1=size(vec_U_1,1); 112 vec_U_1=reshape(vec_U_1,nbpoints_x_1*nbpoints_y_1,1); 113 vec_V_1=reshape(vec_V_1,nbpoints_x_1*nbpoints_y_1,1); 114 if testfalse_1 115 vec_U_1=vec_U_1(indsel); 116 vec_V_1=vec_V_1(indsel); 117 end 118 else %(~testU && ~testU_1) 119 A_1_Name=Field_1.ListVarName{ivar_C_1}; 120 eval(['vec_A_1=Field_1.' A_1_Name ';']) 121 nbpoints_x_1=size(vec_A_1,2); 122 nbpoints_y_1=size(vec_A_1,1);%TODO: use a faster interpolation method for a regular grid (size(x)=2) 123 vec_A_1=reshape(vec_A_1,nbpoints_x_1*nbpoints_y_1,1); 124 if testfalse_1 125 vec_A_1=vec_A_1(indsel); 126 end 127 end 105 128 XName=Field.ListVarName{VarType.coord_x}; 106 129 YName=Field.ListVarName{VarType.coord_y}; … … 108 131 eval(['vec_Y=Field.' YName ';']) 109 132 nbpoints=numel(vec_X); 110 vec_X=reshape(vec_X, 1,nbpoints);111 vec_Y=reshape(vec_Y, 1,nbpoints);133 vec_X=reshape(vec_X,nbpoints,1); 134 vec_Y=reshape(vec_Y,nbpoints,1); 112 135 if testX_1 %unstructured coordinates for the second field 113 136 X_1_Name=Field_1.ListVarName{VarType_1.coord_x}; … … 115 138 eval(['vec_X_1=Field_1.' X_1_Name ';']) 116 139 eval(['vec_Y_1=Field_1.' Y_1_Name ';']) 117 nbpoints_1=numel(vec_X_1); 140 118 141 else %structured coordinates for the second field 119 142 y_1_Name=Field_1.ListVarName{VarType_1.coord(1)}; 120 143 x_1_Name=Field_1.ListVarName{VarType_1.coord(2)}; 121 144 eval(['y_1=Field_1.' y_1_Name ';']) 122 eval(['x_1=Field_1.' x_1_Name ';']) 123 npxy(1)=numel(y_1); 124 npxy(2)=numel(x_1); 125 nbpoints_1=npxy(1)*npxy(2); 145 eval(['x_1=Field_1.' x_1_Name ';']) 146 if isequal(numel(x_1),2) 147 x_1=linspace(x_1(1),x_1(2),nbpoints_x_1); 148 end 149 if isequal(numel(y_1),2) 150 y_1=linspace(y_1(1),y_1(2),nbpoints_y_1); 151 end 126 152 [vec_X_1,vec_Y_1]=meshgrid(x_1,y_1); 127 153 end 128 vec_X_1=reshape(vec_X_1, 1,nbpoints_1);129 vec_Y_1=reshape(vec_Y_1, 1,nbpoints_1);154 vec_X_1=reshape(vec_X_1,nbpoints_x_1*nbpoints_y_1,1); 155 vec_Y_1=reshape(vec_Y_1,nbpoints_x_1*nbpoints_y_1,1); 130 156 if testfalse_1 131 157 FFName_1=Field_1.ListVarName{VarType_1.errorflag}; 132 158 eval(['vec_FF_1=Field_1.' FFName_1 ';']) 133 vec_FF_1=reshape(vec_FF_1, 1,nbpoints_1);159 vec_FF_1=reshape(vec_FF_1,nbpoints_1,1); 134 160 indsel=find(~vec_FF_1); 135 161 vec_X_1=vec_X_1(indsel); 136 162 vec_Y_1=vec_Y_1(indsel); 137 end138 if testU % vector fields139 U_1_Name=Field_1.ListVarName{VarType_1.vector_x};140 V_1_Name=Field_1.ListVarName{VarType_1.vector_y};141 eval(['vec_U_1=Field_1.' U_1_Name ';'])142 eval(['vec_V_1=Field_1.' V_1_Name ';'])143 vec_U_1=reshape(vec_U_1,1,nbpoints_1);144 vec_V_1=reshape(vec_V_1,1,nbpoints_1);145 if testfalse_1146 vec_U_1=vec_U_1(indsel);147 vec_V_1=vec_V_1(indsel);148 end149 else150 A_1_Name=Field_1.ListVarName{ivar_C_1};151 eval(['vec_A_1=Field_1.' A_1_Name ';'])152 vec_A_1=reshape(vec_A_1,1,nbpoints_1);153 if testfalse_1154 vec_A_1=vec_A_1(indsel);155 end156 163 end 157 164 if ~isequal(vec_X_1,vec_X) && ~isequal(vec_Y_1,vec_Y) % if the unstructured positions are not the same … … 160 167 vec_V_1=griddata_uvmat(vec_X_1,vec_Y_1,vec_V_1,vec_X,vec_Y); %interpolate vectors in the second field 161 168 else 162 vec_A_1=griddata_uvmat(vec_X_1,vec_Y_1, vec_A_1,vec_X,vec_Y); %interpolate vectors in the second field169 vec_A_1=griddata_uvmat(vec_X_1,vec_Y_1,double(vec_A_1),vec_X,vec_Y); %interpolate vectors in the second field 163 170 end 164 171 end … … 168 175 eval(['vec_U=Field.' UName ';']) 169 176 eval(['vec_V=Field.' VName ';']) 170 vec_U=reshape(vec_U, 1,numel(vec_U));171 vec_V=reshape(vec_V, 1,numel(vec_V));177 vec_U=reshape(vec_U,numel(vec_U),1); 178 vec_V=reshape(vec_V,numel(vec_V),1); 172 179 eval(['SubData.' UName '=vec_U-vec_U_1;']) 173 180 eval(['SubData.' VName '=vec_V-vec_V_1;']) 174 181 else 175 182 AName=Field.ListVarName{ivar_C}; 183 size(Field.vort) 176 184 eval(['SubData.' AName '=Field.' AName '-vec_A_1;']) 177 185 end
Note: See TracChangeset
for help on using the changeset viewer.