Changeset 688 for trunk/src/plot_field.m


Ignore:
Timestamp:
Sep 27, 2013, 11:20:34 AM (11 years ago)
Author:
sommeria
Message:

bug correction on xml time reading
some cleaning of the GUI uvmat
improvement of option 'contours' in plot_field

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/plot_field.m

    r674 r688  
    738738    end   
    739739end
     740PlotParamOut=PlotParam; % output plot parameters equal to input by default
    740741
    741742%%   image or scalar plot %%%%%%%%%%%%%%%%%%%%%%%%%%
    742 
    743 if isfield(PlotParam.Scalar,'ListContour')
    744     CheckContour=strcmp(PlotParam.Scalar.ListContour,'contours');
    745 else
    746     CheckContour=0; %default
    747 end
    748 PlotParamOut=PlotParam; %default
    749743if test_ima
     744   
    750745    % distinguish B/W and color images
    751746    np=size(A);%size of image
     
    773768        PlotParamOut.Scalar.CheckBW=BW;
    774769    end
     770   
     771            % determine the plot option 'image' or 'contours'
     772    if isfield(PlotParam.Scalar,'ListContour')
     773        CheckContour=strcmp(PlotParam.Scalar.ListContour,'contours');% =1 for contour plot option
     774    else
     775        CheckContour=0; %default
     776    end
     777   
    775778    %case of grey level images or contour plot
    776779    if siz==2
    777780        if ~isfield(PlotParam.Scalar,'CheckFixScalar')
    778             PlotParam.Scalar.CheckFixScalar=0;%default
     781            PlotParam.Scalar.CheckFixScalar=0;% free scalar threshold value scale (from min to max) by default
    779782        end
    780783        if ~isfield(PlotParam.Scalar,'MinA')
    781             PlotParam.Scalar.MinA=[];%default
     784            PlotParam.Scalar.MinA=[];%no min scalar threshold value set
    782785        end
    783786        if ~isfield(PlotParam.Scalar,'MaxA')
    784             PlotParam.Scalar.MaxA=[];%default
    785         end
    786         Aline=[];
    787         if ~PlotParam.Scalar.CheckFixScalar ||isempty(PlotParam.Scalar.MinA)||~isa(PlotParam.Scalar.MinA,'double')  %correct if there is no numerical data in edit box
    788             Aline=reshape(A,1,[]);
    789             Aline=Aline(~isnan(A));
    790             if isempty(Aline)
     787            PlotParam.Scalar.MaxA=[];%no max scalar threshold value set
     788        end
     789       
     790        % determine the min scalar value
     791        if PlotParam.Scalar.CheckFixScalar && ~isempty(PlotParam.Scalar.MinA) && isnumeric(PlotParam.Scalar.MinA) 
     792            MinA=double(PlotParam.Scalar.MinA); % min value set as input
     793        else
     794            MinA=double(nanmin(nanmin(A))); % min value set as min of non NaN scalar values
     795        end
     796       
     797        % error if the input scalar is NaN everywhere
     798        if isnan(MinA)
    791799                errormsg='NaN input scalar or image in plot_field';
    792800                return
    793             end
    794             MinA=double(min(Aline));
    795         else
    796             MinA=PlotParam.Scalar.MinA;
    797         end;
    798         if ~PlotParam.Scalar.CheckFixScalar||isempty(PlotParam.Scalar.MaxA)||~isa(PlotParam.Scalar.MaxA,'double') %correct if there is no numerical data in edit box
    799             if isempty(Aline)
    800                 Aline=reshape(A,1,[]);
    801                 Aline=Aline(~isnan(A));
    802                 if isempty(Aline)
    803                     errormsg='NaN input scalar or image in plot_field';
    804                     return
    805                 end
    806             end
    807             MaxA=double(max(Aline));
    808         else
    809             MaxA=PlotParam.Scalar.MaxA;
    810         end;
     801        end
     802       
     803        % determine the max scalar value
     804        if PlotParam.Scalar.CheckFixScalar && ~isempty(PlotParam.Scalar.MaxA) && isnumeric(PlotParam.Scalar.MaxA) 
     805            MaxA=double(PlotParam.Scalar.MaxA); % max value set as input
     806        else
     807            MaxA=double(nanmax(nanmax(A))); % max value set as min of non NaN scalar values
     808        end
     809       
    811810        PlotParamOut.Scalar.MinA=MinA;
    812811        PlotParamOut.Scalar.MaxA=MaxA;
    813812        PlotParamOut.Scalar.Npx=size(A,2);
    814813        PlotParamOut.Scalar.Npy=size(A,1);
     814       
    815815        % case of contour plot
    816816        if CheckContour
    817817            if ~isempty(hima) && ishandle(hima)
    818                 delete(hima)
    819             end
     818                delete(hima) % delete existing image
     819            end
     820           
     821            % set the contour values
    820822            if ~isfield(PlotParam.Scalar,'IncrA')
    821                 PlotParam.Scalar.IncrA=NaN;
    822             end
    823             if isempty(PlotParam.Scalar.IncrA)|| isnan(PlotParam.Scalar.IncrA)% | PlotParam.Scalar.AutoScal==0
     823                PlotParam.Scalar.IncrA=[];% automatic contour interval
     824            end
     825            if ~isempty(PlotParam.Scalar.IncrA) && isnumeric(PlotParam.Scalar.IncrA)
     826                interval=PlotParam.Scalar.IncrA;
     827            else % automatic contour interval
    824828                cont=colbartick(MinA,MaxA);
    825                 intercont=cont(2)-cont(1);%default
    826                 PlotParamOut.Scalar.IncrA=intercont;
    827             else
    828                 intercont=PlotParam.Scalar.IncrA;
    829             end
    830             B=A;
    831             abscontmin=intercont*floor(MinA/intercont);
    832             abscontmax=intercont*ceil(MaxA/intercont);
    833             contmin=intercont*floor(min(min(B))/intercont);
    834             contmax=intercont*ceil(max(max(B))/intercont);
    835             cont_pos_plus=0:intercont:contmax;
    836             cont_pos_min=double(contmin):intercont:-intercont;
    837             cont_pos=[cont_pos_min cont_pos_plus];
     829                interval=cont(2)-cont(1);%default
     830                PlotParamOut.Scalar.IncrA=interval;% set the interval as output for display on the GUI
     831            end
     832            %B=A;
     833            abscontmin=interval*floor(MinA/interval);
     834            abscontmax=interval*ceil(MaxA/interval);
     835            contmin=interval*floor(min(min(A))/interval);
     836            contmax=interval*ceil(max(max(A))/interval);
     837            cont_pos_plus=0:interval:contmax;% zero and positive contour values (plotted as solid lines)
     838            cont_pos_min=double(contmin):interval:-interval;% negative contour values (plotted as dashed lines)
     839            cont_pos=[cont_pos_min cont_pos_plus];% set of all contour values
     840           
    838841            sizpx=(AX(end)-AX(1))/(np(2)-1);
    839842            sizpy=(AY(1)-AY(end))/(np(1)-1);
    840843            x_cont=AX(1):sizpx:AX(end); % pixel x coordinates for image display
    841844            y_cont=AY(1):-sizpy:AY(end); % pixel x coordinates for image display
    842             % axes(haxes)% set the input axes handle as current axis
    843             txt=ver('MATLAB');
    844             Release=txt.Release;
    845             relnumb=str2double(Release(3:4));
    846             if relnumb >= 14
    847                 vec=linspace(0,1,(abscontmax-abscontmin)/intercont);%define a greyscale colormap with steps intercont
     845           
     846            %axes(haxes)% set the input axes handle as current axis
     847
     848           % colormap(map);
     849           tag_axes=get(haxes,'Tag');% axes tag
     850           Opacity=1;
     851           if isfield(PlotParam.Scalar,'Opacity')&&~isempty(PlotParam.Scalar.Opacity)
     852               Opacity=PlotParam.Scalar.Opacity;
     853           end
     854           % fill the space between contours if opacity is undefined or =1
     855           if isequal(Opacity,1)
     856               [var,hcontour]=contour(haxes,x_cont,y_cont,A,cont_pos);% determine all contours
     857               set(hcontour,'Fill','on')% fill the space between contours
     858               set(hcontour,'LineStyle','none')
     859               hold on
     860           end
     861           [var_p,hcontour_p]=contour(haxes,x_cont,y_cont,A,cont_pos_plus,'k-');% draw the contours for positive values as solid lines
     862           hold on
     863           [var_m,hcontour_m]=contour(haxes,x_cont,y_cont,A,cont_pos_min,'--');% draw the contours for negative values as dashed lines
     864           if isequal(Opacity,1)
     865               set(hcontour_m,'LineColor',[1 1 1])% draw negative contours in white (better visibility in dark background)
     866           end
     867           set(haxes,'Tag',tag_axes);% restore axes tag (removed by the matlab fct contour !)
     868           hold off
     869           
     870            %determine the color scale and map
     871            caxis([abscontmin abscontmax])
     872            if BW
     873                vec=linspace(0,1,(abscontmax-abscontmin)/interval);%define a greyscale colormap with steps interval
    848874                map=[vec' vec' vec'];
    849875                colormap(map);
    850                 [var,hcontour]=contour(x_cont,y_cont,B,cont_pos);
    851                 set(hcontour,'Fill','on')
    852                 set(hcontour,'LineStyle','none')
    853                 hold on
    854             end
    855             [var_p,hcontour_p]=contour(x_cont,y_cont,B,cont_pos_plus,'k-');
    856             hold on
    857             [var_m,hcontour_m]=contour(x_cont,y_cont,B,cont_pos_min,':');
    858             set(hcontour_m,'LineColor',[1 1 1])
    859             hold off
    860             caxis([abscontmin abscontmax])
    861             colormap(map);
     876            else
     877                colormap('default'); % default matlab colormap ('jet')
     878            end
     879           
    862880            if isfield(PlotParam.Coordinates,'CheckFixAspectRatio') && isequal(PlotParam.Coordinates.CheckFixAspectRatio,1)
    863881                set(haxes,'DataAspectRatioMode','manual')
     
    868886                end
    869887            end
    870         end
    871        
     888        else     
    872889        % set  colormap for  image display
    873         if ~CheckContour
    874890            % rescale the grey levels with min and max, put a grey scale colorbar
    875             B=A;
     891%             B=A;
    876892            if BW
    877893                vec=linspace(0,1,255);%define a linear greyscale colormap
     
    879895                colormap(map);  %grey scale color map
    880896            else
    881                 colormap('default'); % standard faulse colors for div, vort , scalar fields
     897                colormap('default'); % standard false colors for div, vort , scalar fields
    882898            end
    883899        end
     
    886902    else
    887903        if BW
    888             B=uint16(sum(A,3));
    889         else
    890             B=uint8(A);
     904            A=uint16(sum(A,3));
     905        else
     906            A=uint8(A);
    891907        end
    892908        MinA=0;
     
    898914        % interpolate field to increase resolution of image display
    899915        test_interp=0;
    900         if size(B,3)==1 % scalar of B/W image
     916        if size(A,3)==1 % scalar of B/W image
    901917            test_interp=1;
    902918            if max(np) <= 64
     
    917933            xi=linspace(AX(1),AX(2),npxy(2));
    918934            yi=linspace(AY(1),AY(2),npxy(1));
    919             B = interp2(X,Y,double(B),xi,yi');
     935            A = interp2(X,Y,double(A),xi,yi');
    920936        end
    921937        % create new image if there  no image handle is found
     
    923939            tag=get(haxes,'Tag');
    924940            if MinA<MaxA
    925                 hima=imagesc(AX,AY,B,[MinA MaxA]);
     941                hima=imagesc(AX,AY,A,[MinA MaxA]);
    926942            else % to deal with uniform field
    927                 hima=imagesc(AX,AY,B,[MaxA-1 MaxA]);
     943                hima=imagesc(AX,AY,A,[MaxA-1 MaxA]);
    928944            end
    929945            % the function imagesc reset the axes 'DataAspectRatioMode'='auto', change if .CheckFixAspectRatio is
     
    935951            % update an existing image
    936952        else
    937             set(hima,'CData',B);
     953            set(hima,'CData',A);
    938954            if MinA<MaxA
    939955                set(haxes,'CLim',[MinA MaxA])
Note: See TracChangeset for help on using the changeset viewer.