Changeset 864
- Timestamp:
- Feb 6, 2015, 7:55:10 PM (10 years ago)
- Location:
- trunk/src
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/calc_field_interp.m
r863 r864 55 55 check_skipped(ilist)=1; %variable not found 56 56 elseif isempty(find(strcmp(FieldName{ilist},InputVarList), 1));% the variable exists and has not been already selected 57 if isfield(Data.VarAttribute{ivar},'Role') &&...57 if exist('XI','var')&& isfield(Data.VarAttribute{ivar},'Role') &&... 58 58 (strcmp(Data.VarAttribute{ivar}.Role,'ancillary')||strcmp(Data.VarAttribute{ivar}.Role,'warnflag')||strcmp(Data.VarAttribute{ivar}.Role,'errorflag')) 59 59 check_interp(ilist)=0; % ancillary variable, not interpolated ????? -
trunk/src/plot_field.m
r848 r864 640 640 return 641 641 else 642 if numel(CellInfo{icell}.VarIndex_vector_x)>1 643 errormsg='error in plot_field: attempt to plot two vector fields'; 644 return 645 end 642 646 test_vec=1; 643 647 if isfield(CellInfo{icell},'VarIndex_errorflag') -
trunk/src/proj_field.m
r863 r864 961 961 if isfield(FieldData,'PlaneCoord')&&length(FieldData.PlaneCoord)==3&& isfield(ProjData,'ProjObjectCoord') 962 962 if length(ProjData.ProjObjectCoord)==3% if the projection plane has a z coordinate 963 if ~isequal(ProjData.PlaneCoord(3),ProjData.ProjObjectCoord) %check the consistency with the z coordinate of the field plane (set by calibration)963 if isfield(ProjData,'.PlaneCoord') && ~isequal(ProjData.PlaneCoord(3),ProjData.ProjObjectCoord) %check the consistency with the z coordinate of the field plane (set by calibration) 964 964 errormsg='inconsistent z position for field and projection plane'; 965 965 return -
trunk/src/series/civ2vel_3C.m
r863 r864 169 169 %% MAIN LOOP ON FIELDS 170 170 warning off 171 for index=1:NbField 171 if NbField<2 && length(filecell{:,1})>2 172 disp_uvmat('ERROR','you need at least 2 images to compute the mean position for the stereo.',checkrun) 173 return 174 end 175 for index=1:NbField-1 172 176 update_waitbar(WaitbarHandle,index/NbField) 173 177 if ~isempty(RUNHandle) && ~strcmp(get(RUNHandle,'BusyAction'),'queue') … … 179 183 Data=cell(1,NbView);%initiate the set Data 180 184 timeread=zeros(1,NbView); 181 [Data{3},tild,errormsg] = nc2struct(filecell{3,index}); 182 ZI=griddata(Data{3}.Xphys,Data{3}.Yphys,Data{3}.Zphys,XI,YI); 185 186 %get Xphys,Yphys,Zphys from 1 or 2 stereo folders. Positions are taken 187 %at the middle between to time step 188 clear ZItemp 189 ZItemp=zeros(size(XI,1),size(XI,2),2); 190 for indextemp=index:index+1; 191 if NbView==3 % if there is only 1 stereo folder, extract directly Xphys,Yphys and Zphys 192 193 [Data{3},tild,errormsg] = nc2struct(filecell{3,indextemp}); 194 195 if exist('Data{3}.Civ3_FF','var') % FF is present, remove wrong vector 196 temp=find(Data{3}.Civ3_FF==0); 197 Zphys=Data{3}.Zphys(temp); 198 Yphys=Data{3}.Yphys(temp); 199 Xphys=Data{3}.Xphys(temp); 200 else 201 Zphys=Data{3}.Zphys; 202 Yphys=Data{3}.Yphys; 203 Xphys=Data{3}.Xphys; 204 end 205 206 207 208 elseif NbView==4 % is there is 2 stereo folders, get global U and V and compute Zphys 209 210 211 %test if the seconde camera is the same for both folder 212 for i=3:4 213 indpt(i)=strfind(Param.InputTable{i,2},'.'); % indice of the "." is the folder name 1 214 indline(i)=strfind(Param.InputTable{i,2},'-'); % indice of the "-" is the folder name1 215 camname{i}=Param.InputTable{i,2}(indline(i)+1:indpt(i)-1);% extract the second camera name 216 end 217 218 if strcmp(camname{3},camname{4})==0 219 disp_uvmat('ERROR','The 2 stereo folders should have the same camera for the second position',checkrun) 220 return 221 end 222 223 [Data{3},tild,errormsg] = nc2struct(filecell{3,indextemp}); 224 if exist('Data{3}.Civ3_FF','var') % if FF is present, remove wrong vector 225 temp=find(Data{3}.Civ3_FF==0); 226 Xmid3=Data{3}.Xmid(temp); 227 Ymid3=Data{3}.Ymid(temp); 228 U3=Data{3}.Uphys(temp); 229 V3=Data{3}.Vphys(temp); 230 else 231 Xmid3=Data{3}.Xmid; 232 Ymid3=Data{3}.Ymid; 233 U3=Data{3}.Uphys; 234 V3=Data{3}.Vphys; 235 end 236 %temporary gridd of merging the 2 stereos datas 237 [xq,yq] = meshgrid(min(Xmid3+(U3)/2):(max(Xmid3+(U3)/2)-min(Xmid3+(U3)/2))/128:max(Xmid3+(U3)/2),min(Ymid3+(V3)/2):(max(Ymid3+(V3)/2)-min(Ymid3+(V3)/2))/128:max(Ymid3+(V3)/2)); 238 239 %1st folder : interpolate the first camera (Dalsa1) points on the second (common) camera 240 %(Dalsa 3) 241 x3Q=griddata(Xmid3+(U3)/2,Ymid3+(V3)/2,Xmid3-(U3)/2,xq,yq); 242 y3Q=griddata(Xmid3+(U3)/2,Ymid3+(V3)/2,Ymid3-(V3)/2,xq,yq); 243 244 245 [Data{4},tild,errormsg] = nc2struct(filecell{4,indextemp}); 246 if exist('Data{4}.Civ3_FF','var') % if FF is present, remove wrong vector 247 temp=find(Data{4}.Civ3_FF==0); 248 Xmid4=Data{4}.Xmid(temp); 249 Ymid4=Data{4}.Ymid(temp); 250 U4=Data{4}.Uphys(temp); 251 V4=Data{4}.Vphys(temp); 252 else 253 Xmid4=Data{4}.Xmid; 254 Ymid4=Data{4}.Ymid; 255 U4=Data{4}.Uphys; 256 V4=Data{4}.Vphys; 257 end 258 259 %2nd folder :interpolate the first camera (Dalsa2) points on the second (common) camera 260 %(Dalsa 3) 261 x4Q=griddata(Xmid4+(U4)/2,Ymid4+(V4)/2,Xmid4-(U4)/2,xq,yq); 262 y4Q=griddata(Xmid4+(U4)/2,Ymid4+(V4)/2,Ymid4-(V4)/2,xq,yq); 263 264 xmid=reshape((x4Q+x3Q)/2,length(xq(:,1)).*length(xq(1,:)),1); 265 ymid=reshape((y4Q+y3Q)/2,length(yq(:,1)).*length(yq(1,:)),1); 266 u=reshape(x4Q-x3Q,length(xq(:,1)).*length(xq(1,:)),1); 267 v=reshape(y4Q-y3Q,length(yq(:,1)).*length(yq(1,:)),1); 268 269 270 [Zphys,Xphys,Yphys,error]=shift2z(xmid, ymid, u, v,XmlData); %get Xphy,Yphy and Zphys 271 %remove NaN 272 tempNaN=isnan(Zphys);tempind=find(tempNaN==1); 273 Zphys(tempind)=[]; 274 Xphys(tempind)=[]; 275 Yphys(tempind)=[]; 276 error(tempind)=[]; 277 278 end 279 280 281 282 283 ZItemp(:,:,indextemp)=griddata(Xphys,Yphys,Zphys,XI,YI); %interpolation on the choosen gridd 284 285 end 286 ZI=mean(ZItemp,3); %mean between two the two time step 287 183 288 [Xa,Ya]=px_XYZ(XmlData{1}.GeometryCalib,XI,YI,ZI);% set of image coordinates on view a 184 289 [Xb,Yb]=px_XYZ(XmlData{2}.GeometryCalib,XI,YI,ZI);% set of image coordinates on view b … … 208 313 end 209 314 end 210 Ua=griddata(Data{1}.X,Data{1}.Y,Data{1}.U,Xa,Ya); 211 Va=griddata(Data{1}.X,Data{1}.Y,Data{1}.V,Xa,Ya); 315 %remove wrong vector 316 temp=find(Data{1}.FF==0); 317 X1=Data{1}.X(temp); 318 Y1=Data{1}.Y(temp); 319 U1=Data{1}.U(temp); 320 V1=Data{1}.V(temp); 321 322 Ua=griddata(X1,Y1,U1,Xa,Ya); 323 Va=griddata(X1,Y1,V1,Xa,Ya); 212 324 A=get_coeff(XmlData{1}.GeometryCalib,Xa,Ya,YI,YI,ZI); 213 325 214 Ub=griddata(Data{2}.X,Data{2}.Y,Data{1}.U,Xb,Yb); 215 Vb=griddata(Data{2}.X,Data{2}.Y,Data{2}.V,Xb,Yb); 326 327 temp=find(Data{2}.FF==0); 328 X2=Data{2}.X(temp); 329 Y2=Data{2}.Y(temp); 330 U2=Data{2}.U(temp); 331 V2=Data{2}.V(temp); 332 Ub=griddata(X2,Y2,U2,Xb,Yb); 333 Vb=griddata(X2,Y2,V2,Xb,Yb); 216 334 B=get_coeff(XmlData{2}.GeometryCalib,Xb,Yb,YI,YI,ZI); 217 335 S=ones(size(XI,1),size(XI,2),3); … … 302 420 303 421 304 305 306 422 function [z,Xphy,Yphy,error]=shift2z(xmid, ymid, u, v,XmlData) 423 z=0; 424 error=0; 425 426 427 %% first image 428 Calib_A=XmlData{1}.GeometryCalib; 429 R=(Calib_A.R)'; 430 x_a=xmid- u/2; 431 y_a=ymid- u/2; 432 z_a=R(7)*x_a+R(8)*y_a+Calib_A.Tx_Ty_Tz(1,3); 433 Xa=(R(1)*x_a+R(2)*y_a+Calib_A.Tx_Ty_Tz(1,1))./z_a; 434 Ya=(R(4)*x_a+R(5)*y_a+Calib_A.Tx_Ty_Tz(1,2))./z_a; 435 436 A_1_1=R(1)-R(7)*Xa; 437 A_1_2=R(2)-R(8)*Xa; 438 A_1_3=R(3)-R(9)*Xa; 439 A_2_1=R(4)-R(7)*Ya; 440 A_2_2=R(5)-R(8)*Ya; 441 A_2_3=R(6)-R(9)*Ya; 442 Det=A_1_1.*A_2_2-A_1_2.*A_2_1; 443 Dxa=(A_1_2.*A_2_3-A_2_2.*A_1_3)./Det; 444 Dya=(A_2_1.*A_1_3-A_1_1.*A_2_3)./Det; 445 446 %% second image 447 Calib_B=XmlData{2}.GeometryCalib; 448 R=(Calib_B.R)'; 449 x_b=xmid+ u/2; 450 y_b=ymid+ v/2; 451 z_b=R(7)*x_b+R(8)*y_b+Calib_B.Tx_Ty_Tz(1,3); 452 Xb=(R(1)*x_b+R(2)*y_b+Calib_B.Tx_Ty_Tz(1,1))./z_b; 453 Yb=(R(4)*x_b+R(5)*y_b+Calib_B.Tx_Ty_Tz(1,2))./z_b; 454 B_1_1=R(1)-R(7)*Xb; 455 B_1_2=R(2)-R(8)*Xb; 456 B_1_3=R(3)-R(9)*Xb; 457 B_2_1=R(4)-R(7)*Yb; 458 B_2_2=R(5)-R(8)*Yb; 459 B_2_3=R(6)-R(9)*Yb; 460 Det=B_1_1.*B_2_2-B_1_2.*B_2_1; 461 Dxb=(B_1_2.*B_2_3-B_2_2.*B_1_3)./Det; 462 Dyb=(B_2_1.*B_1_3-B_1_1.*B_2_3)./Det; 463 464 %% result 465 Den=(Dxb-Dxa).*(Dxb-Dxa)+(Dyb-Dya).*(Dyb-Dya); 466 error=((Dyb-Dya).*u-(Dxb-Dxa).*v)./Den; 467 468 xnew(1,:)=Dxa.*z+x_a; 469 xnew(2,:)=Dxb.*z+x_b; 470 ynew(1,:)=Dya.*z+y_a; 471 ynew(2,:)=Dyb.*z+y_b; 472 473 Xphy=mean(xnew,1); %on moyenne les 2 valeurs 474 Yphy=mean(ynew,1); 475 z=((Dxb-Dxa).*u-(Dyb-Dya).*v)./Den; 476 477 -
trunk/src/series/stereo_civ.m
r862 r864 41 41 Data=[]; 42 42 errormsg=''; 43 44 43 %% set the input elements needed on the GUI series when the action is selected in the menu ActionName or InputTable refreshed 45 44 if isstruct(Param) && isequal(Param.Action.RUN,0)% function activated from the GUI series but not RUN … … 50 49 path_series=fileparts(which('series')); 51 50 addpath(fullfile(path_series,'series')) 52 % Data=civ_input(Param);% introduce the civ parameters using the GUI civ_input 53 Data=stereo_input(Param) 51 Data=stereo_input(Param);% introduce the civ parameters using the GUI civ_input 54 52 if isempty(Data) 55 53 Data=Param;% if civ_input has been cancelled, keep previous parameters … … 263 261 end 264 262 265 263 tic 266 264 %%%%% MAIN LOOP %%%%%% 267 265 for ifield=1:NbField … … 271 269 break 272 270 end 271 % variable for light saving or not. 272 LSM=Param.ActionInput.CheckLSM; 273 273 274 Civ1Dir=OutputDir; 274 275 275 ncfile=fullfile_uvmat(RootPath_A,Civ1Dir, RootFile_A,'.nc',NomTypeNc,i2_series_Civ1(ifield),[],...276 ncfile=fullfile_uvmat(RootPath_A,Civ1Dir,[RootFile_A,'_All'],'.nc',NomTypeNc,i2_series_Civ1(ifield),[],... 276 277 j1_series_Civ1(ifield),j2_series_Civ1(ifield)); 278 279 280 ncfile2=fullfile_uvmat(RootPath_A,Civ1Dir,[RootFile_A,'_Light'],'.nc',NomTypeNc,i2_series_Civ1(ifield),[],... 281 j1_series_Civ1(ifield),j2_series_Civ1(ifield)); 282 277 283 %% Civ1 284 278 285 % if Civ1 computation is requested 279 286 if isfield (Param.ActionInput,'Civ1') … … 294 301 PhysImageA=fullfile_uvmat(RootPath_A,Civ1Dir,RootFile_A,'.png','_1a',i1_series_Civ1(ifield),[],1); 295 302 PhysImageB=fullfile_uvmat(RootPath_A,Civ1Dir,RootFile_A,'.png','_1a',i1_series_Civ1(ifield),[],2); 303 if LSM ~= 1 296 304 imwrite(A{1},PhysImageA) 297 305 imwrite(A{2},PhysImageB) 306 end 307 298 308 par_civ1.ImageA=A{1}; 299 309 par_civ1.ImageB=A{2}; … … 338 348 339 349 % calculate velocity data (y and v in indices, reverse to y component) 340 [xtable ytable utable vtable ctable F result_converrormsg] = civ (par_civ1);350 [xtable, ytable, utable, vtable, ctable, F, result_conv, errormsg] = civ (par_civ1); 341 351 Data.Civ1_X=reshape(xtable,[],1); 342 352 Data.Civ1_Y=reshape(par_civ1.ImageHeight-ytable+1,[],1); … … 346 356 Data.Civ1_C=reshape(ctable,[],1); 347 357 Data.Civ1_F=reshape(F,[],1); 348 % Data.Xphys=Rangx(1)+(Rangx(2)-Rangx(1))*(Data.Civ1_X-0.5)/(Npx-1); 349 % Data.Yphys=Rangy(1)+(Rangy(2)-Rangy(1))*(Data.Civ1_Y-0.5)/(Npy-1); 350 % 351 % U=Data.Civ1_U*(Rangx(2)-Rangx(1))/(Npx-1); 352 % V=Data.Civ1_V*(Rangy(2)-Rangy(1))/(Npy-1); 353 % [Data.Zphys,Data.Civ1_E]=shift2z(Data.Xphys,Data.Yphys,U,V,XmlData); 354 % if ~isempty(errormsg) 355 % disp_uvmat('ERROR',errormsg,checkrun) 356 % return 357 % end 358 358 359 end 359 360 … … 425 426 Data.Civ1_FF(ind_good)=FFres; 426 427 Data.CivStage=3; 428 429 430 431 432 % 433 % % get z from u and v (displacements) 434 % 435 % tempXmid=Rangx(1)+(Rangx(2)-Rangx(1))*(Data.Civ1_X-0.5)/(Npx-1);%temporary coordinate (velocity taken at the point middle from imgae 1 and 2) 436 % tempYmid=Rangy(1)+(Rangy(2)-Rangy(1))*(Data.Civ1_Y-0.5)/(Npy-1);%temporary coordinate (velocity taken at the point middle from imgae 1 and 2) 437 % tempUphys=Data.Civ1_U_smooth*(Rangx(2)-Rangx(1))/(Npx-1); 438 % tempVphys=Data.Civ1_V_smooth*(Rangy(2)-Rangy(1))/(Npy-1); 439 % [tempZphys,tempXphys,tempYphys,tempCiv3_E]=shift2z(tempXmid,tempYmid,tempUphys,tempVphys,XmlData); %Data.Xphys and Data.Xphys are real coordinate (geometric correction more accurate than xtemp/ytemp) 440 % temp=find(Data.Civ1_FF~=0); 441 % tempXmid(temp)=[]; 442 % tempYmid(temp)=[]; 443 % tempZphys(temp)=[]; 444 % 427 445 end 428 446 … … 446 464 j2=j2_series_Civ2(ifield); 447 465 end 448 par_civ2.ImageWidth=size(par_civ2.ImageA,2);%FileInfo_A.Width; 449 par_civ2.ImageHeight=size(par_civ2.ImageA,1);%FileInfo_A.Height; 466 par_civ2.ImageWidth=size(par_civ2.ImageA,2); 467 par_civ2.ImageHeight=size(par_civ2.ImageA,1); 468 450 469 if isfield(par_civ2,'Grid')% grid points set as input file 451 470 if ischar(par_civ2.Grid)%read the grid file if the input is a file name … … 461 480 par_civ2.Grid(:,1)=reshape(GridX,[],1); 462 481 par_civ2.Grid(:,2)=reshape(GridY,[],1); 482 483 463 484 end 464 485 Shiftx=zeros(size(par_civ2.Grid,1),1);% shift expected from civ1 data … … 508 529 end 509 530 % calculate velocity data (y and v in indices, reverse to y component) 510 [xtable ytable utable vtable ctableF] = civ (par_civ2);531 [xtable, ytable, utable, vtable, ctable, F] = civ (par_civ2); 511 532 list_param=(fieldnames(Param.ActionInput.Civ2))'; 512 533 Civ2_param=regexprep(list_param,'^.+','Civ2_$0');% insert 'Civ2_' before each string in list_param … … 523 544 524 545 nbvar=numel(Data.ListVarName); 525 Data.ListVarName=[Data.ListVarName {'Civ2_X','Civ2_Y','Civ2_U','Civ2_V','Civ2_F','Civ2_C' ,'Xphys','Yphys','Zphys','Civ2_E'}];% cell array containing the names of the fields to record526 Data.VarDimName=[Data.VarDimName {'nb_vec_2','nb_vec_2','nb_vec_2','nb_vec_2','nb_vec_2','nb_vec_2' ,'nb_vec_2','nb_vec_2','nb_vec_2','nb_vec_2'}];546 Data.ListVarName=[Data.ListVarName {'Civ2_X','Civ2_Y','Civ2_U','Civ2_V','Civ2_F','Civ2_C'}];% cell array containing the names of the fields to record 547 Data.VarDimName=[Data.VarDimName {'nb_vec_2','nb_vec_2','nb_vec_2','nb_vec_2','nb_vec_2','nb_vec_2'}]; 527 548 Data.VarAttribute{nbvar+1}.Role='coord_x'; 528 549 Data.VarAttribute{nbvar+2}.Role='coord_y'; … … 598 619 599 620 621 622 623 end 624 625 626 %% Civ3 627 628 if isfield (Param.ActionInput,'Civ3') 629 par_civ3=Param.ActionInput.Civ3; 630 par_civ3.ImageA=par_civ1.ImageA; 631 par_civ3.ImageB=par_civ1.ImageB; 632 % if ~isfield(Param.Civ1,'ImageA') 633 % i1=i1_series_Civ3(ifield); 634 % i2=i1; 635 % if ~isempty(i2_series_Civ3) 636 % i2=i2_series_Civ3(ifield); 637 % end 638 % j1=1; 639 % if ~isempty(j1_series_Civ3) 640 % j1=j1_series_Civ3(ifield); 641 % end 642 % j2=j1; 643 % if ~isempty(j2_series_Civ3) 644 % j2=j2_series_Civ3(ifield); 645 % end 646 par_civ3.ImageWidth=size(par_civ3.ImageA,2); 647 par_civ3.ImageHeight=size(par_civ3.ImageA,1); 648 649 if isfield(par_civ3,'Grid')% grid points set as input file 650 if ischar(par_civ3.Grid)%read the grid file if the input is a file name 651 par_civ3.Grid=dlmread(par_civ3.Grid); 652 par_civ3.Grid(1,:)=[];%the first line must be removed (heading in the grid file) 653 end 654 else% automatic grid 655 minix=floor(par_civ3.Dx/2)-0.5; 656 maxix=minix+par_civ3.Dx*floor((par_civ3.ImageWidth-1)/par_civ3.Dx); 657 miniy=floor(par_civ3.Dy/2)-0.5; 658 maxiy=minix+par_civ3.Dy*floor((par_civ3.ImageHeight-1)/par_civ3.Dy); 659 [GridX,GridY]=meshgrid(minix:par_civ3.Dx:maxix,miniy:par_civ3.Dy:maxiy); 660 par_civ3.Grid(:,1)=reshape(GridX,[],1); 661 par_civ3.Grid(:,2)=reshape(GridY,[],1); 662 663 664 end 665 Shiftx=zeros(size(par_civ3.Grid,1),1);% shift expected from civ2 data 666 Shifty=zeros(size(par_civ3.Grid,1),1); 667 nbval=zeros(size(par_civ3.Grid,1),1); 668 if par_civ3.CheckDeformation 669 DUDX=zeros(size(par_civ3.Grid,1),1); 670 DUDY=zeros(size(par_civ3.Grid,1),1); 671 DVDX=zeros(size(par_civ3.Grid,1),1); 672 DVDY=zeros(size(par_civ3.Grid,1),1); 673 end 674 NbSubDomain=size(Data.Civ2_SubRange,3); 675 % get the guess from patch2 676 for isub=1:NbSubDomain% for each sub-domain of Patch2 677 nbvec_sub=Data.Civ2_NbCentres(isub);% nbre of Civ2 vectors in the subdomain 678 ind_sel=find(par_civ3.Grid(:,1)>=Data.Civ2_SubRange(1,1,isub) & par_civ3.Grid(:,1)<=Data.Civ2_SubRange(1,2,isub) &... 679 par_civ3.Grid(:,2)>=Data.Civ2_SubRange(2,1,isub) & par_civ3.Grid(:,2)<=Data.Civ2_SubRange(2,2,isub)); 680 epoints = par_civ3.Grid(ind_sel,:);% coordinates of interpolation sites 681 ctrs=Data.Civ2_Coord_tps(1:nbvec_sub,:,isub) ;%(=initial points) ctrs 682 nbval(ind_sel)=nbval(ind_sel)+1;% records the number of values for eacn interpolation point (in case of subdomain overlap) 683 EM = tps_eval(epoints,ctrs); 684 Shiftx(ind_sel)=Shiftx(ind_sel)+EM*Data.Civ2_U_tps(1:nbvec_sub+3,isub); 685 Shifty(ind_sel)=Shifty(ind_sel)+EM*Data.Civ2_V_tps(1:nbvec_sub+3,isub); 686 if par_civ3.CheckDeformation 687 [EMDX,EMDY] = tps_eval_dxy(epoints,ctrs);%2D matrix of distances between extrapolation points epoints and spline centres (=site points) ctrs 688 DUDX(ind_sel)=DUDX(ind_sel)+EMDX*Data.Civ2_U_tps(1:nbvec_sub+3,isub); 689 DUDY(ind_sel)=DUDY(ind_sel)+EMDY*Data.Civ2_U_tps(1:nbvec_sub+3,isub); 690 DVDX(ind_sel)=DVDX(ind_sel)+EMDX*Data.Civ2_V_tps(1:nbvec_sub+3,isub); 691 DVDY(ind_sel)=DVDY(ind_sel)+EMDY*Data.Civ2_V_tps(1:nbvec_sub+3,isub); 692 end 693 end 694 mask=''; 695 if par_civ3.CheckMask&&~isempty(par_civ3.Mask)&& ~strcmp(maskname,par_civ3.Mask)% mask exist, not already read in Civ2 696 mask=imread(par_civ3.Mask); 697 end 698 ibx2=ceil(par_civ3.CorrBoxSize(1)/2); 699 iby2=ceil(par_civ3.CorrBoxSize(2)/2); 700 % par_civ3.SearchBoxSize(1)=2*ibx2+9;% search ara +-4 pixels around the guess 701 % par_civ3.SearchBoxSize(2)=2*iby2+9; 702 par_civ3.SearchBoxShift=[Shiftx(nbval>=1)./nbval(nbval>=1) Shifty(nbval>=1)./nbval(nbval>=1)]; 703 par_civ3.Grid=[par_civ3.Grid(nbval>=1,1)-par_civ3.SearchBoxShift(:,1)/2 par_civ3.Grid(nbval>=1,2)-par_civ3.SearchBoxShift(:,2)/2];% grid taken at the extrapolated origin of the displacement vectors 704 if par_civ3.CheckDeformation 705 par_civ3.DUDX=DUDX./nbval; 706 par_civ3.DUDY=DUDY./nbval; 707 par_civ3.DVDX=DVDX./nbval; 708 par_civ3.DVDY=DVDY./nbval; 709 end 710 % calculate velocity data (y and v in indices, reverse to y component) 711 [xtable, ytable, utable, vtable, ctable, F] = civ (par_civ3); 712 list_param=(fieldnames(Param.ActionInput.Civ3))'; 713 Civ3_param=regexprep(list_param,'^.+','Civ3_$0');% insert 'Civ3_' before each string in list_param 714 Civ3_param=[{'Civ3_ImageA','Civ3_ImageB','Civ3_Time','Civ3_Dt'} Civ3_param]; %insert the names of the two input images 715 %indicate the values of all the global attributes in the output data 716 Data.Civ3_ImageA=ImageName_A; 717 Data.Civ3_ImageB=ImageName_B; 718 Data.Civ3_Time=(time(i2+1,j2+1)+time(i1+1,j1+1))/2; 719 Data.Civ3_Dt=0; 720 for ilist=1:length(list_param) 721 Data.(Civ3_param{4+ilist})=Param.ActionInput.Civ3.(list_param{ilist}); 722 end 723 Data.ListGlobalAttribute=[Data.ListGlobalAttribute Civ3_param]; 724 725 nbvar=numel(Data.ListVarName); 726 Data.ListVarName=[Data.ListVarName {'Civ3_X','Civ3_Y','Civ3_U','Civ3_V','Civ3_F','Civ3_C','Xphys','Yphys','Zphys','Civ3_E'}];% cell array containing the names of the fields to record 727 Data.VarDimName=[Data.VarDimName {'nb_vec_3','nb_vec_3','nb_vec_3','nb_vec_3','nb_vec_3','nb_vec_3','nb_vec_3','nb_vec_3','nb_vec_3','nb_vec_3'}]; 728 Data.VarAttribute{nbvar+1}.Role='coord_x'; 729 Data.VarAttribute{nbvar+2}.Role='coord_y'; 730 Data.VarAttribute{nbvar+3}.Role='vector_x'; 731 Data.VarAttribute{nbvar+4}.Role='vector_y'; 732 Data.VarAttribute{nbvar+5}.Role='warnflag'; 733 Data.Civ3_X=reshape(xtable,[],1); 734 Data.Civ3_Y=reshape(size(par_civ3.ImageA,1)-ytable+1,[],1); 735 Data.Civ3_U=reshape(utable,[],1); 736 Data.Civ3_V=reshape(-vtable,[],1); 737 Data.Civ3_C=reshape(ctable,[],1); 738 Data.Civ3_F=reshape(F,[],1); 739 Data.CivStage=Data.CivStage+1; 740 end 741 742 %% Fix3 743 if isfield (Param.ActionInput,'Fix3') 744 ListFixParam=fieldnames(Param.ActionInput.Fix3); 745 for ilist=1:length(ListFixParam) 746 ParamName=ListFixParam{ilist}; 747 ListName=['Fix3_' ParamName]; 748 eval(['Data.ListGlobalAttribute=[Data.ListGlobalAttribute ''' ParamName '''];']) 749 eval(['Data.' ListName '=Param.ActionInput.Fix3.' ParamName ';']) 750 end 751 if check_civx 752 if ~isfield(Data,'fix3') 753 Data.ListGlobalAttribute=[Data.ListGlobalAttribute 'fix3']; 754 Data.fix3=1; 755 Data.ListVarName=[Data.ListVarName {'vec3_FixFlag'}]; 756 Data.VarDimName=[Data.VarDimName {'nb_vectors3'}]; 757 end 758 Data.vec_FixFlag=fix(Param.Fix3,Data.vec3_F,Data.vec3_C,Data.vec3_U,Data.vec3_V,Data.vec3_X,Data.vec3_Y); 759 else 760 Data.ListVarName=[Data.ListVarName {'Civ3_FF'}]; 761 Data.VarDimName=[Data.VarDimName {'nb_vec_3'}]; 762 nbvar=length(Data.ListVarName); 763 Data.VarAttribute{nbvar}.Role='errorflag'; 764 Data.Civ3_FF=double(fix(Param.ActionInput.Fix3,Data.Civ3_F,Data.Civ3_C,Data.Civ3_U,Data.Civ3_V)); 765 Data.CivStage=Data.CivStage+1; 766 end 767 768 end 769 770 771 %% Patch3 772 if isfield (Param.ActionInput,'Patch3') 773 Data.ListGlobalAttribute=[Data.ListGlobalAttribute {'Patch3_Rho','Patch3_Threshold','Patch3_SubDomain'}]; 774 Data.Patch3_FieldSmooth=Param.ActionInput.Patch3.FieldSmooth; 775 Data.Patch3_MaxDiff=Param.ActionInput.Patch3.MaxDiff; 776 Data.Patch3_SubDomainSize=Param.ActionInput.Patch3.SubDomainSize; 777 nbvar=length(Data.ListVarName); 778 Data.ListVarName=[Data.ListVarName {'Civ3_U_smooth','Civ3_V_smooth','Civ3_SubRange','Civ3_NbCentres','Civ3_Coord_tps','Civ3_U_tps','Civ3_V_tps','Xmid','Ymid','Uphys','Vphys'}]; 779 Data.VarDimName=[Data.VarDimName {'nb_vec_3','nb_vec_3',{'nb_coord','nb_bounds','nb_subdomain_3'},{'nb_subdomain_3'},... 780 {'nb_tps_3','nb_coord','nb_subdomain_3'},{'nb_tps_3','nb_subdomain_3'},{'nb_tps_3','nb_subdomain_3'},'nb_vec_3','nb_vec_3','nb_vec_3','nb_vec_3'}]; 781 782 Data.VarAttribute{nbvar+1}.Role='vector_x'; 783 Data.VarAttribute{nbvar+2}.Role='vector_y'; 784 Data.VarAttribute{nbvar+5}.Role='coord_tps'; 785 Data.VarAttribute{nbvar+6}.Role='vector_x'; 786 Data.VarAttribute{nbvar+7}.Role='vector_y'; 787 Data.Civ3_U_smooth=zeros(size(Data.Civ3_X)); 788 Data.Civ3_V_smooth=zeros(size(Data.Civ3_X)); 789 if isfield(Data,'Civ3_FF') 790 ind_good=find(Data.Civ3_FF==0); 791 else 792 ind_good=1:numel(Data.Civ3_X); 793 end 794 [Data.Civ3_SubRange,Data.Civ3_NbCentres,Data.Civ3_Coord_tps,Data.Civ3_U_tps,Data.Civ3_V_tps,tild,Ures, Vres,tild,FFres]=... 795 filter_tps([Data.Civ3_X(ind_good) Data.Civ3_Y(ind_good)],Data.Civ3_U(ind_good),Data.Civ3_V(ind_good),[],Data.Patch3_SubDomainSize,Data.Patch3_FieldSmooth,Data.Patch3_MaxDiff); 796 Data.Civ3_U_smooth(ind_good)=Ures; 797 Data.Civ3_V_smooth(ind_good)=Vres; 798 Data.Civ3_FF(ind_good)=FFres; 799 Data.CivStage=Data.CivStage+1; 800 801 600 802 % get z from u and v (displacements) 601 803 602 Data.X phys=Rangx(1)+(Rangx(2)-Rangx(1))*(Data.Civ2_X-0.5)/(Npx-1);603 Data.Y phys=Rangy(1)+(Rangy(2)-Rangy(1))*(Data.Civ2_Y-0.5)/(Npy-1);604 U=Data.Civ2_U_smooth*(Rangx(2)-Rangx(1))/(Npx-1);605 V=Data.Civ2_V_smooth*(Rangy(2)-Rangy(1))/(Npy-1);606 [Data.Zphys,Data. Civ2_E]=shift2z(Data.Xphys,Data.Yphys,U,V,XmlData);804 Data.Xmid=Rangx(1)+(Rangx(2)-Rangx(1))*(Data.Civ3_X-0.5)/(Npx-1);%temporary coordinate (velocity taken at the point middle from imgae 1 and 2) 805 Data.Ymid=Rangy(2)+(Rangy(1)-Rangy(2))*(Data.Civ3_Y-0.5)/(Npy-1);%temporary coordinate (velocity taken at the point middle from imgae 1 and 2) 806 Data.Uphys=Data.Civ3_U_smooth*(Rangx(2)-Rangx(1))/(Npx-1); 807 Data.Vphys=Data.Civ3_V_smooth*(Rangy(2)-Rangy(1))/(Npy-1); 808 [Data.Zphys,Data.Xphys,Data.Yphys,Data.Civ3_E]=shift2z(Data.Xmid,Data.Ymid,Data.Uphys,Data.Vphys,XmlData); %Data.Xphys and Data.Xphys are real coordinate (geometric correction more accurate than xtemp/ytemp) 607 809 if ~isempty(errormsg) 608 810 disp_uvmat('ERROR',errormsg,checkrun) … … 612 814 end 613 815 816 817 818 614 819 %% write result in a netcdf file if requested 615 if exist('ncfile','var') 616 errormsg=struct2nc(ncfile,Data); 617 if isempty(errormsg) 618 disp([ncfile ' written']) 619 else 620 disp(errormsg) 621 end 622 end 623 end 820 if LSM ~= 1 % store all data 821 if exist('ncfile','var') 822 errormsg=struct2nc(ncfile,Data); 823 if isempty(errormsg) 824 disp([ncfile ' written']) 825 else 826 disp(errormsg) 827 end 828 end 829 else 830 % store only phys data 831 Data_light.ListVarName={'Xphys','Yphys','Zphys','Civ3_C','Xmid','Ymid','Uphys','Vphys'}; 832 Data_light.VarDimName={'nb_vec_3','nb_vec_3','nb_vec_3','nb_vec_3','nb_vec_3','nb_vec_3','nb_vec_3','nb_vec_3'}; 833 temp=find(Data.Civ3_FF==0); 834 Data_light.Zphys=Data.Zphys(temp); 835 Data_light.Yphys=Data.Yphys(temp); 836 Data_light.Xphys=Data.Xphys(temp); 837 Data_light.Civ3_C=Data.Civ3_C(temp); 838 Data_light.Xmid=Data.Xmid(temp); 839 Data_light.Ymid=Data.Ymid(temp); 840 Data_light.Uphys=Data.Uphys(temp); 841 Data_light.Vphys=Data.Vphys(temp); 842 843 if exist('ncfile2','var') 844 errormsg=struct2nc(ncfile2,Data_light); 845 if isempty(errormsg) 846 disp([ncfile2 ' written']) 847 else 848 disp(errormsg) 849 end 850 end 851 852 end 853 end 854 855 toc 856 857 624 858 625 859 % 'civ': function piv.m adapted from PIVlab http://pivlab.blogspot.com/ … … 769 1003 end 770 1004 % vector=[0 0];%default 1005 771 1006 for ivec=1:nbvec 772 1007 iref=round(par_civ.Grid(ivec,1)+0.5);% xindex on the image A for the middle of the correlation box 773 1008 jref=round(par_civ.ImageHeight-par_civ.Grid(ivec,2)+0.5);% yindex on the image B for the middle of the correlation box 1009 774 1010 %if ~(checkmask && par_civ.Mask(jref,iref)<=20) %velocity not set to zero by the black mask 775 1011 % if jref-iby2<1 || jref+iby2>par_civ.ImageHeight|| iref-ibx2<1 || iref+ibx2>par_civ.ImageWidth||... … … 820 1056 image2_crop=interp2(image2_crop,xi,yi); 821 1057 end 822 sum_square=(sum(sum(image1_crop.*image1_crop)) +sum(sum(image2_crop.*image2_crop)))/2;1058 sum_square=(sum(sum(image1_crop.*image1_crop)));%+sum(sum(image2_crop.*image2_crop)))/2; 823 1059 %reference: Oliver Pust, PIV: Direct Cross-Correlation 824 1060 result_conv= conv2(image2_crop,flipdim(flipdim(image1_crop,2),1),'valid'); … … 834 1070 [vector,F(ivec)] = SUBPIX2DGAUSS (result_conv,x,y); 835 1071 end 836 837 % if isfield(par_civ,'CheckDeformation') 838 % utable(ivec)=shiftx(ivec); 839 % vtable(ivec)=shifty(ivec); 840 % else 841 utable(ivec)=vector(1)*mesh+shiftx(ivec); 1072 1073 1074 utable(ivec)=vector(1)*mesh+shiftx(ivec); 842 1075 vtable(ivec)=vector(2)*mesh+shifty(ivec); 843 % end 844 % xtable(ivec)=iref+utable(ivec)/2-0.5;% convec flow (velocity taken at the point middle from imgae 1 and 2) 845 % ytable(ivec)=jref+vtable(ivec)/2-0.5;% and position of pixel 1=0.5 (convention for image coordinates=0 at the edge) 1076 1077 1078 xtable(ivec)=iref+utable(ivec)/2-0.5;% convec flow (velocity taken at the point middle from imgae 1 and 2) 1079 ytable(ivec)=jref+vtable(ivec)/2-0.5;% and position of pixel 1=0.5 (convention for image coordinates=0 at the edge) 1080 846 1081 iref=round(xtable(ivec));% image index for the middle of the vector 847 1082 jref=round(ytable(ivec)); … … 1051 1286 % ymid+ v/2: set of apparent phys y coordinates in the ref plane, image B 1052 1287 % XmlData: content of the xml files containing geometric calibration parameters 1053 function [z, error]=shift2z(xmid, ymid, u, v,XmlData)1288 function [z,Xphy,Yphy,error]=shift2z(xmid, ymid, u, v,XmlData) 1054 1289 z=0; 1055 1290 error=0; … … 1059 1294 Calib_A=XmlData{1}.GeometryCalib; 1060 1295 R=(Calib_A.R)'; 1061 x_a=xmid ;1062 y_a=ymid ;1296 x_a=xmid- u/2; 1297 y_a=ymid- u/2; 1063 1298 z_a=R(7)*x_a+R(8)*y_a+Calib_A.Tx_Ty_Tz(1,3); 1064 1299 Xa=(R(1)*x_a+R(2)*y_a+Calib_A.Tx_Ty_Tz(1,1))./z_a; … … 1078 1313 Calib_B=XmlData{2}.GeometryCalib; 1079 1314 R=(Calib_B.R)'; 1080 x_b=xmid+ u ;1081 y_b=ymid+ v ;1315 x_b=xmid+ u/2; 1316 y_b=ymid+ v/2; 1082 1317 z_b=R(7)*x_b+R(8)*y_b+Calib_B.Tx_Ty_Tz(1,3); 1083 1318 Xb=(R(1)*x_b+R(2)*y_b+Calib_B.Tx_Ty_Tz(1,1))./z_b; … … 1096 1331 Den=(Dxb-Dxa).*(Dxb-Dxa)+(Dyb-Dya).*(Dyb-Dya); 1097 1332 error=((Dyb-Dya).*u-(Dxb-Dxa).*v)./Den; 1333 1334 xnew(1,:)=Dxa.*z+x_a; 1335 xnew(2,:)=Dxb.*z+x_b; 1336 ynew(1,:)=Dya.*z+y_a; 1337 ynew(2,:)=Dyb.*z+y_b; 1338 1339 Xphy=mean(xnew,1); %on moyenne les 2 valeurs 1340 Yphy=mean(ynew,1); 1098 1341 z=((Dxb-Dxa).*u-(Dyb-Dya).*v)./Den; 1099 1342 1343 1344 1345 -
trunk/src/set_object.m
r850 r864 326 326 set(handles.num_RangeX_2,'TooltipString',['num_RangeX_2: half length of the ' ObjectStyle]) 327 327 set(handles.num_RangeY_2,'TooltipString',['num_RangeY_2: half width of the ' ObjectStyle]) 328 % set(handles.XObject,'TooltipString',['XObject: x coordinate of the ' Type ' centre'])329 % set(handles.YObject,'TooltipString',['YObject: y coordinate of the ' Type ' centre'])330 328 case {'plane'} 331 329 set(handles.num_Angle_3,'Visible','on') … … 334 332 set(handles.num_RangeY_1,'Visible','on') 335 333 set(handles.num_RangeY_2,'Visible','on') 336 % set(handles.XObject,'TooltipString',['XObject: x coordinate of the axis origin for the ' Type])337 % set(handles.YObject,'TooltipString',['YObject: y coordinate of the axis origin for the ' Type])338 334 set(handles.num_RangeZ_2,'TooltipString','num_ZMax: range of projection normal to the plane') 339 335 if test3D … … 374 370 end 375 371 end 372 % set default values read in the plot of uvmat to initiate the mesh 373 if isequal(ProjMode,'interp_lin')|| isequal(ProjMode,'interp_tps') 374 if isempty(str2num(get(handles.num_DX,'String')))||isempty(str2num(get(handles.num_DY,'String'))); 375 huvmat=findobj('Tag','uvmat');%find the current uvmat interface handle 376 UvData=get(huvmat,'UserData');%Data associated to the current uvmat interface 377 Field=UvData.Field; 378 if isfield(UvData.Field,'CoordMesh')&&~isempty(UvData.Field.CoordMesh) 379 set(handles.num_DX,'String',num2str(UvData.Field.CoordMesh)) 380 set(handles.num_DY,'String',num2str(UvData.Field.CoordMesh)) 381 set(handles.num_RangeX_1,'String',num2str(UvData.Field.XMin)) 382 set(handles.num_RangeX_2,'String',num2str(UvData.Field.XMax)) 383 set(handles.num_RangeY_1,'String',num2str(UvData.Field.YMin)) 384 set(handles.num_RangeY_2,'String',num2str(UvData.Field.YMax)) 385 end 386 if isempty(get(handles.CoordUnit,'String')) 387 set(handles.CoordUnit,'String',Field.CoordUnit) 388 end 389 end 390 end 391 376 392 %------------------------------------------------------------------------ 377 393 -
trunk/src/sub_field.m
r862 r864 129 129 for ilist=1:numel(Field_1.ListVarName) 130 130 % case of variable with a single dimension 131 OldDimName=Field_1.VarDimName{ilist}; 132 if ischar(OldDimName), OldDimName={OldDimName}; end% transform char string to cell if relevant 133 if numel(OldDimName)==1 134 OldDim=Field_1.(Field_1.ListVarName{ilist});% get variable 135 %look for the existence of the variable OldDim in the first field Field 136 for i1=1:numel(Field.ListVarName) 137 if isequal(Field.(Field.ListVarName{i1}),OldDim) &&... 138 ((isempty(ProjModeRequest{i1}) && isempty(ProjModeRequest_1{ilist})) || strcmp(ProjModeRequest{i1},ProjModeRequest_1{ilist})) 139 ind_remove(ilist)=1; 140 NewDimName=Field.VarDimName{i1}; 141 if ischar(NewDimName), NewDimName={NewDimName}; end %transform char chain to cell if needed 142 Field_1.VarDimName=regexprep_r(Field_1.VarDimName,['^' OldDimName{1} '$'],NewDimName{1});% change the var name of Field_1 to the corresponding var name of Field 131 if ~isempty(regexp(Field_1.VarAttribute{ilist}.Role,'^coord')) 132 OldDimName=Field_1.VarDimName{ilist}; 133 if ischar(OldDimName), OldDimName={OldDimName}; end% transform char string to cell if relevant 134 if numel(OldDimName)==1 135 OldDim=Field_1.(Field_1.ListVarName{ilist});% get variable 136 %look for the existence of the variable OldDim in the first field Field 137 for i1=1:numel(Field.ListVarName) 138 if isequal(Field.(Field.ListVarName{i1}),OldDim) &&... 139 ((isempty(ProjModeRequest{i1}) && isempty(ProjModeRequest_1{ilist})) || strcmp(ProjModeRequest{i1},ProjModeRequest_1{ilist})) 140 ind_remove(ilist)=1; 141 NewDimName=Field.VarDimName{i1}; 142 if ischar(NewDimName), NewDimName={NewDimName}; end %transform char chain to cell if needed 143 Field_1.VarDimName=regexprep_r(Field_1.VarDimName,['^' OldDimName{1} '$'],NewDimName{1});% change the var name of Field_1 to the corresponding var name of Field 144 end 143 145 end 144 146 end … … 152 154 ListVarNameNew=Field_1.ListVarName; 153 155 check_rename=zeros(size(ListVarNameNew)); 156 check_remove=zeros(size(ListVarNameNew)); 154 157 for ilist=1:numel(ListVarNameNew) 155 158 VarName=Field_1.ListVarName{ilist}; 156 159 ind_prev=find(strcmp(ListVarNameNew{ilist},Field.ListVarName),1);% look for duplicated variable name 157 160 if ~isempty(ind_prev)% variable name exists in Field 158 check_rename(ilist)=1; 159 ListVarNameNew{ilist}=[ListVarNameNew{ilist} '_1']; 161 % check_rename(ilist)=0; 162 check_remove(ilist)=1; 163 if isfield(Field_1.VarAttribute{ilist},'Role')&& ismember(Field_1.VarAttribute{ilist}.Role,{'scalar','vector_x','vector_y'}) 164 ListVarNameNew{ilist}=[ListVarNameNew{ilist} '_1']; 165 check_rename(ilist)=1; 166 end 160 167 end 161 168 SubData.ListVarName=[SubData.ListVarName ListVarNameNew{ilist}]; 162 169 SubData.VarDimName=[SubData.VarDimName Field_1.VarDimName(ilist)]; 170 Field_1.VarAttribute{ilist}.CheckSub=1; 171 SubData.VarAttribute=[SubData.VarAttribute Field_1.VarAttribute{ilist}]; 163 172 SubData.(ListVarNameNew{ilist})=Field_1.(VarName);% teke the values of the old variable for the newly named one 164 173 %SubData.VarAttribute=[SubData.VarAttribute Field_1.VarDimName(ilist)]; -
trunk/src/uvmat.m
r856 r864 5528 5528 data.Type='plane'; 5529 5529 end 5530 5531 %% initiate the new projection object 5530 5532 hset_object=set_object(data,[],ZBounds); 5531 5533 set(hset_object,'name','set_object')
Note: See TracChangeset
for help on using the changeset viewer.