Changeset 581 for trunk/src/proj_field.m


Ignore:
Timestamp:
Mar 12, 2013, 12:52:13 PM (11 years ago)
Author:
sommeria
Message:

clean the transform field functions

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/proj_field.m

    r576 r581  
    142142        return
    143143    end
    144 elseif  ~isequal(ObjectData.ProjMode,'interp')
     144elseif  ~isequal(ObjectData.ProjMode,'interp_lin')
    145145    errormsg=(['ProjMode option ' ObjectData.ProjMode ' not available in proj_field']);
    146146        return
     
    223223                    Var=FieldData.(VarName)(indsel);
    224224                    ProjData.(VarName)(ipoint,1)=mean(Var);
    225                     if isequal(ObjectData.ProjMode,'interp')
     225                    if isequal(ObjectData.ProjMode,'interp_lin')
    226226                         ProjData.(VarName)(ipoint,1)=griddata_uvmat(coord_x(indsel),coord_y(indsel),Var,Xpoint(1),Xpoint(2));
    227227                    end
     
    524524theta=angle(dlinx+1i*dliny);%angle of each segment
    525525theta(siz_line(1))=theta(siz_line(1)-1);
    526 % determine a rectangles at +-width from the line (only used for the ProjMode='projection or 'filter')
     526% determine a rectangles at +-width from the line (only used for the ProjMode='projection or 'interp_tps')
    527527xsup=zeros(1,siz_line(1)); xinf=zeros(1,siz_line(1)); ysup=zeros(1,siz_line(1)); yinf=zeros(1,siz_line(1));
    528 if isequal(ProjMode,'projection') || isequal(ProjMode,'filter')
     528if isequal(ProjMode,'projection') || isequal(ProjMode,'interp_tps')
    529529    xsup(1)=ObjectData.Coord(1,1)-width*sin(theta(1));
    530530    xinf(1)=ObjectData.Coord(1,1)+width*sin(theta(1));
     
    580580    % check needed object properties for unstructured positions (position given by the variables with role coord_x, coord_y
    581581    if strcmp(CellInfo{icell}.CoordType,'scattered')
    582         if  ~isequal(ProjMode,'interp')
     582        if  ~isequal(ProjMode,'interp_lin')
    583583            if width==0
    584584                errormsg='range of the projection object is missing';
    585585                return     
    586586            else
    587                 lambda=2/(width*width); %smoothing factor used for filter: weight exp(-2) at distance width from the line
     587                lambda=2/(width*width); %smoothing factor used for interp_tps: weight exp(-2) at distance width from the line
    588588            end
    589589        end
     
    621621                flagsel=ones(size(coord_x));
    622622            end
    623             if isequal(ProjMode,'projection') | isequal(ProjMode,'filter')
     623            if isequal(ProjMode,'projection') || isequal(ProjMode,'interp_tps')
    624624                flagsel=flagsel & ((coord_y -yinf(ip))*(xinf(ip+1)-xinf(ip))>(coord_x-xinf(ip))*(yinf(ip+1)-yinf(ip))) ...
    625625                & ((coord_y -ysup(ip))*(xsup(ip+1)-xsup(ip))<(coord_x-xsup(ip))*(ysup(ip+1)-ysup(ip))) ...
     
    649649                     end
    650650                end
    651             elseif isequal(ProjMode,'interp') %linear interpolation:
     651            elseif isequal(ProjMode,'interp_lin') %linear interpolation:
    652652                npoint=floor(linelength/DX)+1;% nbre of points in the profile (interval DX)
    653653                Xproj=linelength/(2*npoint):linelength/npoint:linelength-linelength/(2*npoint);
     
    659659                     end
    660660                end
    661             elseif isequal(ProjMode,'filter') %filtering
     661            elseif isequal(ProjMode,'interp_tps') %filtering
    662662                npoint=floor(linelength/DX)+1;% nbre of points in the profile (interval DX)
    663663                Xproj=linelength/(2*npoint):linelength/npoint:linelength-linelength/(2*npoint);
     
    983983for icell=1:numel(CellInfo)% TODO: recalculate coordinates here to get the bounds in the rotated coordinates
    984984    ProjMode{icell}=ObjectData.ProjMode;
    985     if isfield(CellInfo{icell},'FieldRequest')
    986         switch CellInfo{icell}.FieldRequest
     985    if isfield(CellInfo{icell},'ProjModeRequest')
     986        switch CellInfo{icell}.ProjModeRequest
    987987            case 'interp_lin'
    988                 ProjMode{icell}='interp';
     988                ProjMode{icell}='interp_lin';
    989989            case 'interp_tps'
    990                 ProjMode{icell}='filter';
    991         end
    992     end
    993     if strcmp(ProjMode{icell},'interp')||strcmp(ProjMode{icell},'filter')
     990                ProjMode{icell}='interp_tps';
     991        end
     992    end
     993    if strcmp(ProjMode{icell},'interp_lin')||strcmp(ProjMode{icell},'interp_tps')
    994994        check_grid=1;
    995995    end
     
    10431043        %% case of input fields with unstructured coordinates
    10441044        case 'scattered'
    1045             if strcmp(ProjMode{icell},'filter')
    1046                 continue %skip for filter (needs tps field cell)
     1045            if strcmp(ProjMode{icell},'interp_tps')
     1046                continue %skip for interp_tps (needs tps field cell)
    10471047            end
    10481048            coord_x=FieldData.(FieldData.ListVarName{CellInfo{icell}.CoordIndex(end)});% initial x coordinates
     
    11481148                        end
    11491149                    end
    1150                 case 'interp'%interpolate data on a regular grid
     1150                case 'interp_lin'%interpolate data on a regular grid
    11511151                    coord_x_proj=XMin:DX:XMax;
    11521152                    coord_y_proj=YMin:DY:YMax;
     
    12051205            end
    12061206
    1207             %% case of tps interpolation (applies only in filter mode and for spatial derivatives)
     1207            %% case of tps interpolation (applies only in interp_tps mode and for spatial derivatives)
    12081208        case 'tps'
    1209             if strcmp(ProjMode{icell},'filter')
     1209            if strcmp(ProjMode{icell},'interp_tps')
    12101210                Coord=FieldData.(FieldData.ListVarName{CellInfo{icell}.CoordIndex});
    1211                 NbSites=FieldData.(FieldData.ListVarName{CellInfo{icell}.NbSite_tps});
     1211                NbCentres=FieldData.(FieldData.ListVarName{CellInfo{icell}.NbCentres_tps});
    12121212                SubRange=FieldData.(FieldData.ListVarName{CellInfo{icell}.SubRange_tps});
    12131213                if isfield(CellInfo{icell},'VarIndex_vector_x_tps')&&isfield(CellInfo{icell},'VarIndex_vector_y_tps')
     
    12211221                XI=XI+ObjectData.Coord(1,1);
    12221222                YI=YI+ObjectData.Coord(1,2);
    1223                 [DataOut,VarAttribute,errormsg]=calc_field_tps(Coord,NbSites,SubRange,FieldVar,CellInfo{icell}.FieldName,cat(3,XI,YI));   
     1223                [DataOut,VarAttribute,errormsg]=calc_field_tps(Coord,NbCentres,SubRange,FieldVar,CellInfo{icell}.FieldName,cat(3,XI,YI));   
    12241224                ListFieldProj=(fieldnames(DataOut))';
    12251225                VarDimName=cell(size(ListFieldProj));
     
    14611461                    YIMA=reshape(round(YIMA),1,npX*npY);
    14621462                    flagin=XIMA>=1 & XIMA<=DimValue(2) & YIMA >=1 & YIMA<=DimValue(1);%flagin=1 inside the original image
    1463                     if isequal(ProjMode{icell},'filter')
    1464                         npx_filter=ceil(abs(DX/DAX));
    1465                         npy_filter=ceil(abs(DY/DAY));
    1466                         Mfilter=ones(npy_filter,npx_filter)/(npx_filter*npy_filter);
    1467                         test_filter=1;
     1463                    if isequal(ProjMode{icell},'interp_tps')
     1464                        npx_interp_tps=ceil(abs(DX/DAX));
     1465                        npy_interp_tps=ceil(abs(DY/DAY));
     1466                        Minterp_tps=ones(npy_interp_tps,npx_interp_tps)/(npx_interp_tps*npy_interp_tps);
     1467                        test_interp_tps=1;
    14681468                    else
    1469                         test_filter=0;
     1469                        test_interp_tps=0;
    14701470                    end
    14711471                    eval(['ProjData.' AYName '=[coord_y_proj(1) coord_y_proj(end)];']) %record the new (projected ) y coordinates
     
    14761476                            eval(['ProjData.' VarName '=interp2(Coord{2},Coord{1},FieldData.' VarName ',Coord_x,Coord_y'');']) %TO TEST
    14771477                        end
    1478                         %filter the field (image) if option 'filter' is used
    1479 %                         if test_filter
    1480 %                             Aclass=class(FieldData.A);
    1481 %                             eval(['ProjData.' VarName '=filter2(Mfilter,FieldData.' VarName ',''valid'');'])
    1482 %                             if ~isequal(Aclass,'double')
    1483 %                                 eval(['ProjData.' VarName '=' Aclass '(FieldData.' VarName ');'])%revert to integer values
    1484 %                             end
    1485 %                         end
    14861478                        eval(['vec_A=reshape(FieldData.' VarName ',[],nbcolor);'])%put the original image in line
    14871479                        %ind_in=find(flagin);
     
    15251517                else
    15261518                    errormsg='projection of structured coordinates on oblique plane not yet implemented';
    1527                     %TODO: use interp3
     1519                    %TODO: use interp_lin3
    15281520                    return
    15291521                end
     
    18011793                end
    18021794            end 
    1803         elseif isequal(ObjectData.ProjMode,'interp')||isequal(ObjectData.ProjMode,'filter')%interpolate data on a regular grid
     1795        elseif isequal(ObjectData.ProjMode,'interp_lin')||isequal(ObjectData.ProjMode,'interp_tps')%interpolate data on a regular grid
    18041796            coord_x_proj=XMin:DX:XMax;
    18051797            coord_y_proj=YMin:DY:YMax;
     
    20742066                YIMA=reshape(round(YIMA),1,npX*npY);
    20752067                flagin=XIMA>=1 & XIMA<=DimValue(2) & YIMA >=1 & YIMA<=DimValue(1);%flagin=1 inside the original image
    2076                 if isequal(ObjectData.ProjMode,'filter')
    2077                     npx_filter=ceil(abs(DX/DAX));
    2078                     npy_filter=ceil(abs(DY/DAY));
    2079                     Mfilter=ones(npy_filter,npx_filter)/(npx_filter*npy_filter);
    2080                     test_filter=1;
     2068                if isequal(ObjectData.ProjMode,'interp_tps')
     2069                    npx_interp_tps=ceil(abs(DX/DAX));
     2070                    npy_interp_tps=ceil(abs(DY/DAY));
     2071                    Minterp_tps=ones(npy_interp_tps,npx_interp_tps)/(npx_interp_tps*npy_interp_tps);
     2072                    test_interp_tps=1;
    20812073                else
    2082                     test_filter=0;
     2074                    test_interp_tps=0;
    20832075                end
    20842076                eval(['ProjData.' AYName '=[coord_y_proj(1) coord_y_proj(end)];']) %record the new (projected ) y coordinates
     
    20892081                          eval(['ProjData.' VarName '=interp2(Coord{2},Coord{1},FieldData.' VarName ',Coord_x,Coord_y'');']) %TO TEST
    20902082                    end
    2091                     %filter the field (image) if option 'filter' is used
    2092                     if test_filter 
     2083                    %filter the field (image) if option 'interp_tps' is used
     2084                    if test_interp_tps 
    20932085                         Aclass=class(FieldData.A);
    2094                          ProjData.(VarName)=filter2(Mfilter,FieldData.(VarName),'valid');
     2086                         ProjData.(VarName)=interp_tps2(Minterp_tps,FieldData.(VarName),'valid');
    20952087                         if ~isequal(Aclass,'double')
    20962088                             ProjData.(VarName)=Aclass(FieldData.(VarName));%revert to integer values
Note: See TracChangeset for help on using the changeset viewer.