Changeset 1122 for trunk/src/series/merge_proj_volume.m
- Timestamp:
- Apr 21, 2023, 11:01:06 AM (18 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/series/merge_proj_volume.m
r1121 r1122 200 200 DataVol.Time=0; %TO UPDATE 201 201 DataVol.ListVarName={'coord_x','coord_y','coord_z','A'}; 202 DataVol.VarDimName={'coord_x','coord_y','coord_z',{'coord_ z','coord_y','coord_x'}};202 DataVol.VarDimName={'coord_x','coord_y','coord_z',{'coord_y','coord_x','coord_z'}}; 203 203 DataVol.VarAttribute{1}.Role='coord_x'; 204 204 DataVol.VarAttribute{2}.Role='coord_y'; … … 257 257 258 258 for index_i=1:NbField_i 259 AMerge=zeros(NbField_j,numel(DataVol.coord_y),numel(DataVol.coord_x));259 260 260 for index_j=1:NbField_j 261 261 index_j … … 268 268 269 269 %%%%%%%%%%%%%%%% loop on views (input lines) %%%%%%%%%%%%%%%% 270 Data=cell(1,NbView);%initiate the set Data270 271 271 timeread=zeros(1,NbView); 272 for iview=1:NbView272 % for iview=1:NbView 273 273 %% reading input file(s) 274 [Data {iview},tild,errormsg] = read_field(filecell{iview,index_j},FileType{iview},ParamIn{iview},frame_index{iview}(index_j));274 [Data,tild,errormsg] = read_field(filecell{1,index_j},FileType{1},ParamIn{1},frame_index{1}(index_j)); 275 275 if ~isempty(errormsg) 276 276 disp_uvmat('ERROR',['ERROR in merge_proj/read_field/' errormsg],checkrun) 277 277 return 278 278 end 279 ListVar=Data{iview}.ListVarName; 279 Data.A=Data.A(1:4:end,1:4:end);% reduce the mage size 280 ListVar=Data.ListVarName; 281 %reduce the image size 280 282 for ilist=1:numel(ListVar) 281 Data {iview}.(ListVar{ilist})=double(Data{iview}.(ListVar{ilist}));% transform all fields in double before all operations283 Data.(ListVar{ilist})=double(Data.(ListVar{ilist}));% transform all fields in double before all operations 282 284 end 283 285 % get the time defined in the current file if not already defined from the xml file 284 if ~isempty(time) && isfield(Data {iview},'Time')285 timeread(iview)=Data {iview}.Time;286 if ~isempty(time) && isfield(Data,'Time') 287 timeread(iview)=Data.Time; 286 288 end 287 Data{iview}.ZIndex=index_j; 288 [X,Y]=meshgrid(DataVol.coord_x,DataVol.coord_y);%grid in physical coordinates 289 Data{iview}=proj_plane(Data{iview},XmlData{iview},X,Y); %project on the common x,y plane 289 Data.ZIndex=index_j; 290 [X,Y,Z]=meshgrid(DataVol.coord_x,DataVol.coord_y,DataVol.coord_z);%grid in physical coordinates 291 %Data{iview}=proj_plane(Data{iview},XmlData{iview},X,Y); %project on the common x,y plane 292 293 if index_j==1 294 AMerge=zeros(size(Data.A,1),size(Data.A,2),NbField_j); 290 295 end 291 % merge the NbView fields only to merge views from several cameras) 292 293 % [MergeData,errormsg]=merge_field(ProjData); 294 % if ~isempty(errormsg) 295 % disp_uvmat('ERROR',errormsg,checkrun); 296 % return 297 % end 298 AMerge(index_j,:,:)=Data{iview}.A; 296 AMerge(:,:,index_j)=Data.A; 299 297 300 298 %%%%%%%%%%%%%%%% END LOOP FOR VOLUME SCAN %%%%%%%%%%%%%%%% 301 299 end 302 300 %interpolate on the vertical grid 303 Z=zeros(1,NbField_j); 304 for j_index=1:numel(DataVol.coord_y) 305 for i_index=1:numel(DataVol.coord_x) 306 for ZIndex=1:NbField_j 307 Z(ZIndex)=Zpos(XmlData{iview},ZIndex,X(j_index,i_index),Y(j_index,i_index)); 308 end 309 DataVol.A(:,j_index,i_index) = interp1(Z,AMerge(:,j_index,i_index),DataVol.coord_z); 310 end 311 end 301 DataVol.A=proj_volume(AMerge,XmlData{1},X,Y,Z); 302 % Z=zeros(1,NbField_j); 303 % for j_index=1:numel(DataVol.coord_y) 304 % for i_index=1:numel(DataVol.coord_x) 305 % for ZIndex=1:NbField_j 306 % Z(ZIndex)=Zpos(XmlData{iview},ZIndex,X(j_index,i_index),Y(j_index,i_index)); 307 % end 308 % DataVol.A(:,j_index,i_index) = interp1(Z,AMerge(:,j_index,i_index),DataVol.coord_z); 309 % end 310 % end 312 311 error=struct2nc(OutputFile,DataVol)%save result file 313 312 314 315 % if index==1316 % TimeData.ListGlobalAttribute={'Conventions','Project','CoordUnit','TimeUnit','ZPos','Time'};317 % TimeData.Conventions='uvmat';318 % TimeData.Project='2016_Circumpolar';319 % TimeData.CoordUnit='cm';320 % TimeData.TimeUnit='s';321 % % TimeData.ZPos=ZPos;322 % TimeData.ListVarName={'radius','azimuth','U','V','curl','div'};323 % TimeData.VarDimName={'radius','azimuth',{'radius','azimuth'},{'radius','azimuth'}...324 % {'radius','azimuth'},{'radius','azimuth'}};325 % TimeData.VarAttribute{1}.Role='';326 % TimeData.VarAttribute{2}.Role='';327 % TimeData.VarAttribute{3}.Role='vector_x';328 % TimeData.VarAttribute{4}.Role='vector_y';329 % TimeData.VarAttribute{5}.Role='scalar';330 % TimeData.VarAttribute{6}.Role='scalar';331 %332 % end333 %334 % %% append data to the netcdf file for next iterations335 %336 %337 % error=struct2nc(OutputFile,TimeData);%save result file338 % if isempty(error)339 % disp(['output file ' OutputFile ' written'])340 % else341 % disp(error)342 % end343 % ellapsed_time=toc(tstart);344 % disp(['ellapsed time since start ' num2str(ellapsed_time/60,2) ' minutes'])345 313 end 346 314 … … 426 394 end 427 395 396 397 function ZIndex=XYZtoIndex(XmlData,X,Y,Z)% Z positions corresponding to X,Y positions 398 Zp=Z-XmlData.Slice.SliceCoord(1,3); 399 DZ=XmlData.Slice.SliceCoord(end,3)-XmlData.Slice.SliceCoord(1,3)/(size(XmlData.Slice.SliceCoord,1)-1); 400 if DZ~=0 401 ZIndex=(Z-XmlData.Slice.SliceCoord(1,3))/DZ+1;% Z=XmlData.SliceCoord(1,3)+(ZIndex-1)*DZ 402 end 403 % effect of angular deviation 404 SliceAngleMax=XmlData.Slice.SliceAngle(end,:)-XmlData.Slice.SliceAngle(1,:); 405 normAxe=norm(SliceAngleMax); 406 if normAxe>0 % case of angle scan 407 a=-SliceAngleMax(2)/normAxe; 408 b=-SliceAngleMax(1)/normAxe; 409 c=-a*XmlData.Slice.SliceCoord(1,1)+b*XmlData.Slice.SliceCoord(1,2);%equation of the axis ax+by+c=0 410 DNormal=norm(a*X+b*Y+c); 411 Ang=atand(Zp./DNormal); 412 ZIndex=ZIndex+Ang-norm(XmlData.Slice.SliceAngle(1,:))+1; 413 end 414 415 %------------------------------------------------------------ 416 % proj_volume: poject each image on a common grid given by coord_x and coord_y 417 function A=proj_volume(AMerge,XmlData,X,Y,Z) 418 419 A=[]; %default output 420 421 %% initial image coordinates 422 [npy,npx,npz]=size(AMerge); 423 xima=0.5:npx-0.5;%image coordinates of corners 424 %yima=npy-0.5:-1:0.5; 425 yima=0.5:npy-0.5; 426 zima=0.5:npz-0.5; 427 [XIMA_init,YIMA_init,ZIMA_init]=meshgrid(xima,yima,zima);%grid of initial image in px coordinates 428 429 %% projected coordinates 430 ZIndex=XYZtoIndex(XmlData,X,Y,Z);% Z positions correspoonding to X,Y positions 431 432 %% interpolation on the new grid 433 [XIMA,YIMA]=px_XYZ(XmlData.GeometryCalib,XmlData.Slice,X,Y,Z);% image coordinates for each point in the real 434 A=interp3(XIMA_init,YIMA_init,ZIMA_init,AMerge,XIMA,YIMA,ZIndex); 435 436 437 428 438 % proj_plane: poject each image on a common grid given by coord_x and coord_y 429 439 function DataOut=proj_plane(DataIn,XmlData,X,Y)
Note: See TracChangeset
for help on using the changeset viewer.