Changeset 533 for trunk/src/proj_field.m
- Timestamp:
- Aug 31, 2012, 11:44:55 AM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/proj_field.m
r530 r533 184 184 % 185 185 % select types of variables to be projected 186 ListProj ect={'VarIndex_scalar','VarIndex_image','VarIndex_color','VarIndex_vector_x','VarIndex_vector_y'};187 check_project=false(size(VarIndex));188 for ilist=1:numel(ListProj ect)189 if isfield(CellInfo{icell},ListProj ect{ilist})190 check_proj ect(CellInfo{icell}.(ListProject{ilist}))=1;186 ListProj={'VarIndex_scalar','VarIndex_image','VarIndex_color','VarIndex_vector_x','VarIndex_vector_y'}; 187 check_proj=false(size(FieldData.ListVarName)); 188 for ilist=1:numel(ListProj) 189 if isfield(CellInfo{icell},ListProj{ilist}) 190 check_proj(CellInfo{icell}.(ListProj{ilist}))=1; 191 191 end 192 192 end 193 VarIndex=VarIndex(check_project); 194 195 % if isempty(ivar_X) 196 % test_grid=1;%test for input data on regular grid (e.g. image)coordinates 197 % else 198 % if length(ivar_X)>1 || length(ivar_Y)>1 || length(ivar_Z)>1 199 % errormsg='multiple coordinate input in proj_field.m'; 200 % return 201 % end 202 % if length(ivar_Y)~=1 203 % errormsg='y coordinate not defined in proj_field.m'; 204 % return 205 % end 206 % test_grid=0; 207 % end 193 VarIndex=find(check_proj); 208 194 ProjData.ListVarName={'Y','X','NbVal'}; 209 195 ProjData.VarDimName={'nb_points','nb_points','nb_points'}; … … 360 346 361 347 %group the variables (fields of 'FieldData') in cells of variables with the same dimensions 362 testfalse=0;363 ListIndex={};364 % DimVarIndex=0;%initilise list of indices for dimension variables365 idimvar=0;366 348 [CellInfo,NbDim,errormsg]=find_field_cells(FieldData); 367 %[CellVarIndex,NbDim,VarTypeCell,errormsg]=find_field_cells(FieldData);368 349 if ~isempty(errormsg) 369 350 errormsg=['error in proj_field/proj_patch:' errormsg]; … … 372 353 373 354 %LOOP ON GROUPS OF VARIABLES SHARING THE SAME DIMENSIONS 374 dimcounter=0;375 355 for icell=1:length(CellInfo) 376 356 testX=0; 377 357 testY=0; 378 358 test_Amat=0; 379 testfalse=0;380 VarIndex=CellInfo{icell}.VarIndex;% indices of the selected variables in the list FieldData.ListVarName381 % VarType=VarTypeCell{icell};382 % DimIndices=FieldData.VarDimIndex{VarIndex(1)};%indices of the dimensions of the first variable (common to all variables in the cell)383 359 if NbDim(icell)~=2% proj_patch acts only on fields of space dimension 2 384 360 continue 385 361 end 386 %testX=~isempty(VarType.coord_x) && ~isempty(VarType.coord_y);362 ivar_FF=[]; 387 363 testfalse=isfield(CellInfo{icell},'VarIndex_errorflag'); 388 testproj(VarIndex)=zeros(size(VarIndex));%default 364 if testfalse 365 ivar_FF=CellInfo{icell}.VarIndex_errorflag; 366 FFName=FieldData.ListVarName{ivar_FF}; 367 errorflag=FieldData.(FFName); 368 end 369 % select types of variables to be projected 370 ListProj={'VarIndex_scalar','VarIndex_image','VarIndex_color','VarIndex_vector_x','VarIndex_vector_y'}; 371 check_proj=false(size(FieldData.ListVarName)); 372 for ilist=1:numel(ListProj) 373 if isfield(CellInfo{icell},ListProj{ilist}) 374 check_proj(CellInfo{icell}.(ListProj{ilist}))=1; 375 end 376 end 377 VarIndex=find(check_proj); 378 389 379 ivar_X=CellInfo{icell}.CoordIndex(end); 390 380 ivar_Y=CellInfo{icell}.CoordIndex(end-1); 391 381 ivar_Z=[]; 392 if NbDim Array(icell)==3382 if NbDim(icell)==3 393 383 ivar_Z=CellInfo{icell}.CoordIndex(1); 394 384 end 395 ivar_rem=[];396 if isfield(CellInfo{icell},'VarIndex_ancillary')397 ivar_rem=CellInfo{icell}.VarIndex_ancillary;398 end399 if isfield(CellInfo{icell},'VarIndex_warnflag')400 ivar_rem=[ivar_rem CellInfo{icell}.VarIndex_warnflag];401 end402 if isfield(CellInfo{icell},'VarIndex_errorflag')403 ivar_rem=[ivar_rem CellInfo{icell}.VarIndex_errorflag];404 ivar_FF=CellInfo{icell}.VarIndex_errorflag;405 end406 VarIndex([ivar_X ivar_Y ivar_Z ivar_rem])=[];% not projected variables removed frlom list407 408 385 if strcmp(CellInfo{icell}.CoordType,'scattered')%case of unstructured coordinates 409 eval(['nbpoint=numel(FieldData.' FieldData.ListVarName{VarIndex(1)} ');']) 410 for ivar=[VarIndex VarType.coord_x VarType.coord_y VarType.errorflag] 411 VarName=FieldData.ListVarName{ivar}; 412 eval(['FieldData.' VarName '=reshape(FieldData.' VarName ',nbpoint,1);']) 413 end 414 XName=FieldData.ListVarName{CellInfo{icell}.CoordIndex(end)}; 415 YName=FieldData.ListVarName{CellInfo{icell}.CoordIndex(end-1)}; 416 eval(['coord_x=FieldData.' XName ';']) 417 eval(['coord_y=FieldData.' YName ';']) 418 end 419 if testfalse 420 FFName=FieldData.ListVarName{VarType.errorflag}; 421 eval(['errorflag=FieldData.' FFName ';']) 386 %nbpoint=numel(FieldData.(FieldData.ListVarName{VarIndex(1)})); 387 for ivar=[VarIndex ivar_X ivar_Y ivar_FF] 388 VarName=FieldData.ListVarName{ivar}; 389 FieldData.(VarName)=reshape(FieldData.(VarName),[],1); 390 end 391 XName=FieldData.ListVarName{ivar_X}; 392 YName=FieldData.ListVarName{ivar_Y}; 393 coord_x=FieldData.(XName); 394 coord_y=FieldData.(YName); 422 395 end 423 396 % image or 2D matrix … … 430 403 VarName=FieldData.ListVarName{VarIndex(1)}; 431 404 DimValue=size(FieldData.(VarName)); 432 if length(AX)==2 433 AX=linspace(AX(1),AX(end),DimValue(2)); 434 end 435 if length(AY)==2 436 AY=linspace(AY(1),AY(end),DimValue(1)); 437 end 438 % for idim=1:length(DimValue) 439 % Coord_i_str=['Coord_' num2str(idim)]; 440 % DCoord_min(idim)=1;%default 441 % Coord{idim}=[0.5 DimValue(idim)]; 442 % test_direct(idim)=1; 443 % end 444 % AX=linspace(Coord{2}(1),Coord{2}(2),DimValue(2)); 445 % AY=linspace(Coord{1}(1),Coord{1}(2),DimValue(1)); %TODO : 3D case 446 % testcolor=find(numel(DimValue)==3); 405 if length(AX)==2 406 AX=linspace(AX(1),AX(end),DimValue(2)); 407 end 408 if length(AY)==2 409 AY=linspace(AY(1),AY(end),DimValue(1)); 410 end 447 411 if length(DimValue)==3 448 412 testcolor=1; … … 459 423 for ivar=1:length(VarIndex) 460 424 VarName=FieldData.ListVarName{VarIndex(ivar)}; 461 FieldData.(VarName)=reshape(FieldData.(VarName),npxy(1)*npxy(2),npxy(3)); % keep only non false vectors 462 end 463 end 464 %select the indices in the range of action425 FieldData.(VarName)=reshape(FieldData.(VarName),npxy(1)*npxy(2),npxy(3)); % keep only non false vectors 426 end 427 end 428 %select the indices in the range of action 465 429 testin=[];%default 466 430 if isequal(ObjectData.Type,'rectangle') 467 % if ~isfield(ObjectData,'RangeX')|~isfield(ObjectData,'RangeY') 468 % errormsg='rectangle half sides RangeX and RangeY needed' 469 % return 470 % end 471 if testX 431 if strcmp(CellInfo{icell}.CoordType,'scattered') 472 432 distX=abs(coord_x-ObjectData.Coord(1,1)); 473 433 distY=abs(coord_y-ObjectData.Coord(1,2)); 474 434 testin=distX<widthx & distY<widthy; 475 elseif test_Amat476 distX=abs(Xi-ObjectData.Coord(1,1));477 distY=abs(Yi-ObjectData.Coord(1,2));478 testin=distX<widthx & distY<widthy;479 end435 elseif test_Amat 436 distX=abs(Xi-ObjectData.Coord(1,1)); 437 distY=abs(Yi-ObjectData.Coord(1,2)); 438 testin=distX<widthx & distY<widthy; 439 end 480 440 elseif isequal(ObjectData.Type,'polygon') 481 441 if testX 482 442 testin=inpolygon(coord_x,coord_y,ObjectData.Coord(:,1),ObjectData.Coord(:,2)); 483 443 elseif test_Amat 484 testin=inpolygon(Xi,Yi,ObjectData.Coord(:,1),ObjectData.Coord(:,2));485 else%calculate the scalar486 testin=[]; %A REVOIR487 end444 testin=inpolygon(Xi,Yi,ObjectData.Coord(:,1),ObjectData.Coord(:,2)); 445 else%calculate the scalar 446 testin=[]; %A REVOIR 447 end 488 448 elseif isequal(ObjectData.Type,'ellipse') 489 X2Max=widthx*widthx;490 Y2Max=(widthy)*(widthy);491 if testX449 X2Max=widthx*widthx; 450 Y2Max=(widthy)*(widthy); 451 if testX 492 452 distX=(coord_x-ObjectData.Coord(1,1)); 493 453 distY=(coord_y-ObjectData.Coord(1,2)); 494 454 testin=(distX.*distX/X2Max+distY.*distY/Y2Max)<1; 495 elseif test_Amat %case of usual 2x2 matrix496 distX=(Xi-ObjectData.Coord(1,1));497 distY=(Yi-ObjectData.Coord(1,2));498 testin=(distX.*distX/X2Max+distY.*distY/Y2Max)<1;499 end455 elseif test_Amat %case of usual 2x2 matrix 456 distX=(Xi-ObjectData.Coord(1,1)); 457 distY=(Yi-ObjectData.Coord(1,2)); 458 testin=(distX.*distX/X2Max+distY.*distY/Y2Max)<1; 459 end 500 460 end 501 461 %selected indices 502 462 if isequal(ObjectData.ProjMode,'outside') 503 463 testin=~testin; 504 464 end 505 465 if testfalse 506 testin=testin & (errorflag==0); % keep only non false vectors 466 testin=testin & (errorflag==0); % keep only non false vectors 507 467 end 508 468 indsel=find(testin); 509 469 for ivar=VarIndex 510 if testproj(ivar) 511 VarName=FieldData.ListVarName{ivar}; 512 ProjData.([VarName 'Mean'])=mean(double(FieldData.(VarName)(indsel,:))); % take the mean in the selected region, for each color component 513 ProjData.([VarName 'Min'])=min(double(FieldData.(VarName)(indsel,:))); % take the min in the selected region , for each color component 514 ProjData.([VarName 'Max'])=max(double(FieldData.(VarName)(indsel,:))); % take the max in the selected region , for each color component 515 if isequal(Mesh(ivar),0) 516 eval(['[ProjData.' VarName 'Histo,ProjData.' VarName ']=hist(double(FieldData.' VarName '(indsel,:,:)),100);']); % default histogram with 100 bins 517 else 518 eval(['ProjData.' VarName '=(ProjData.' VarName 'Min+Mesh(ivar)/2:Mesh(ivar):ProjData.' VarName 'Max);']); % list of bin values 519 eval(['ProjData.' VarName 'Histo=hist(double(FieldData.' VarName '(indsel,:)),ProjData.' VarName ');']); % histogram at predefined bin positions 520 end 521 ProjData.ListVarName=[ProjData.ListVarName {VarName} {[VarName 'Histo']} {[VarName 'Mean']} {[VarName 'Min']} {[VarName 'Max']}]; 522 if test_Amat && testcolor 523 ProjData.VarDimName=[ProjData.VarDimName {VarName} {{VarName,'rgb'}} {'rgb'} {'rgb'} {'rgb'}];%{{'nb_point','rgb'}}; 524 else 525 ProjData.VarDimName=[ProjData.VarDimName {VarName} {VarName} {'one'} {'one'} {'one'}]; 526 end 527 ProjData.VarAttribute=[ProjData.VarAttribute FieldData.VarAttribute{ivar} {[]} {[]} {[]} {[]}]; 528 end 529 end 530 % if test_Amat & testcolor 531 % %ProjData.ListDimName=[ProjData.ListDimName {'rgb'}]; 532 % % ProjData.DimValue=[ProjData.DimValue 3]; 533 % % ProjData.VarDimIndex={[1 2]}; 534 % ProjData.VarDimName=[ProjData.VarDimName {VarName} {VarName,'rgb'}];%{{'nb_point','rgb'}}; 535 % ProjData.VarDimName 536 % end 470 VarName=FieldData.ListVarName{ivar}; 471 ProjData.([VarName 'Mean'])=mean(double(FieldData.(VarName)(indsel,:))); % take the mean in the selected region, for each color component 472 ProjData.([VarName 'Min'])=min(double(FieldData.(VarName)(indsel,:))); % take the min in the selected region , for each color component 473 ProjData.([VarName 'Max'])=max(double(FieldData.(VarName)(indsel,:))); % take the max in the selected region , for each color component 474 if isequal(Mesh(ivar),0) 475 eval(['[ProjData.' VarName 'Histo,ProjData.' VarName ']=hist(double(FieldData.' VarName '(indsel,:,:)),100);']); % default histogram with 100 bins 476 else 477 eval(['ProjData.' VarName '=(ProjData.' VarName 'Min+Mesh(ivar)/2:Mesh(ivar):ProjData.' VarName 'Max);']); % list of bin values 478 eval(['ProjData.' VarName 'Histo=hist(double(FieldData.' VarName '(indsel,:)),ProjData.' VarName ');']); % histogram at predefined bin positions 479 end 480 ProjData.ListVarName=[ProjData.ListVarName {VarName} {[VarName 'Histo']} {[VarName 'Mean']} {[VarName 'Min']} {[VarName 'Max']}]; 481 if test_Amat && testcolor 482 ProjData.VarDimName=[ProjData.VarDimName {VarName} {{VarName,'rgb'}} {'rgb'} {'rgb'} {'rgb'}];%{{'nb_point','rgb'}}; 483 else 484 ProjData.VarDimName=[ProjData.VarDimName {VarName} {VarName} {'one'} {'one'} {'one'}]; 485 end 486 ProjData.VarAttribute=[ProjData.VarAttribute FieldData.VarAttribute{ivar} {[]} {[]} {[]} {[]}]; 487 end 537 488 end 538 489 … … 615 566 616 567 % select types of variables to be projected 617 ListProj ect={'VarIndex_scalar','VarIndex_image','VarIndex_color','VarIndex_vector_x','VarIndex_vector_y'};618 check_proj ect=false(size(FieldData.ListVarName));619 for ilist=1:numel(ListProj ect)620 if isfield(CellInfo{icell},ListProj ect{ilist})621 check_proj ect(CellInfo{icell}.(ListProject{ilist}))=1;568 ListProj={'VarIndex_scalar','VarIndex_image','VarIndex_color','VarIndex_vector_x','VarIndex_vector_y'}; 569 check_proj=false(size(FieldData.ListVarName)); 570 for ilist=1:numel(ListProj) 571 if isfield(CellInfo{icell},ListProj{ilist}) 572 check_proj(CellInfo{icell}.(ListProj{ilist}))=1; 622 573 end 623 574 end 624 VarIndex=find(check_proj ect);575 VarIndex=find(check_proj); 625 576 626 577 %identify vector components
Note: See TracChangeset
for help on using the changeset viewer.