Changeset 688


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

Location:
trunk/src
Files:
3 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])
  • trunk/src/uvmat.m

    r686 r688  
    696696
    697697if strcmp(FileType,'txt')
    698     edit(fileinput)
     698    try
     699        edit(fileinput)
     700    catch ME
     701        msgbox_uvmat('ERROR','invalid intput file')
     702    end
    699703    return
    700704elseif strcmp(FileType,'xml')
     
    922926    drawnow
    923927    [XmlDataRead,warntext]=imadoc2struct(XmlFileName);
     928    if ~isempty(warntext)
     929        msgbox_uvmat('WARNING',warntext)
     930    end
    924931    if ~isempty(XmlDataRead)
    925         ImaDoc_str=['view ' DocExt];  % DocExt= '.xml' or .civ (obsolete case)   
    926             if isfield(XmlDataRead,'TimeUnit')&& ~isempty(XmlDataRead.TimeUnit)
    927                 TimeUnit=XmlDataRead.TimeUnit;
    928             end
    929                     if isfield(XmlDataRead,'Time')&& ~isempty(XmlDataRead.Time)
    930                 XmlData.Time=XmlDataRead.TimeUnit;
    931             end
     932        ImaDoc_str=['view ' DocExt];  % DocExt= '.xml' or .civ (obsolete case)
     933        %XmlData=XmlDataRead;
     934        if isfield(XmlDataRead,'TimeUnit')&& ~isempty(XmlDataRead.TimeUnit)
     935            TimeUnit=XmlDataRead.TimeUnit;
     936        end
     937        if isfield(XmlDataRead,'Time')&& ~isempty(XmlDataRead.Time)
     938            XmlData.Time=XmlDataRead.Time;
     939        end
    932940        set(handles.view_xml,'BackgroundColor',[1 1 1])% paint back to white
    933941        drawnow
     
    937945                set (handles.slices,'String','volume')
    938946            end
    939             % check whether the GUI geometry_calib is opened 
     947            % check whether the GUI geometry_calib is opened
    940948            hgeometry_calib=findobj('tag','geometry_calib');
    941949            if ~isempty(hgeometry_calib) % check whether the display of the GUI geometry_calib is consistent with the current calib param
     
    10461054if ~isempty(TimeUnit)
    10471055    if index==2 && isfield(UvData,'TimeUnit') && ~strcmp(UvData.TimeUnit,TimeUnit)
    1048         warntext=['time unit for second file series ' TimeUnit ' inconsistent with first series'];
     1056        msgbox_uvmat('WARNING',['time unit for second file series ' TimeUnit ' inconsistent with first series'])
    10491057    else
    10501058        UvData.TimeUnit=TimeUnit;
     
    10551063
    10561064%display warning message
    1057 if ~isempty(warntext)
     1065if ~isequal(warntext,'')
    10581066    msgbox_uvmat('WARNING',warntext);
    10591067end
     
    37753783%-------------------------------------------------------------------
    37763784val=get(handles.ListContour,'Value');
    3777 if val==2
     3785if val==2% option 'contours'
    37783786    set(handles.interval_txt,'Visible','on')
    37793787    set(handles.num_IncrA,'Visible','on')
    3780 else
     3788    set(handles.num_IncrA,'String','')% refresh contour interval
     3789%     set(handles.opacity_txt,'Visible','off')
     3790%     set(handles.num_Opacity,'Visible','off')
     3791else % option 'image'
    37813792    set(handles.interval_txt,'Visible','off')
    37823793    set(handles.num_IncrA,'Visible','off')
     3794%     set(handles.opacity_txt,'Visible','on')
     3795%     set(handles.num_Opacity,'Visible','on')
    37833796end
    37843797update_plot(handles);
     
    38133826function CheckFixVectors_Callback(hObject, eventdata, handles)
    38143827%-------------------------------------------------------------------
    3815 test=get(handles.CheckFixVectors,'Value');
    3816 if test
    3817 %     set(handles.CheckFixVectors,'BackgroundColor',[1 1 0])
    3818 else
     3828if ~get(handles.CheckFixVectors,'Value')
    38193829    update_plot(handles);
    3820     %set(handles.num_VecScale,'String',num2str(ScalOut.num_VecScale,3))
    3821 %     set(handles.CheckFixVectors,'BackgroundColor',[0.7 0.7 0.7])
    38223830end
    38233831
     
    40244032function update_plot(handles)
    40254033%-------------------------------------------------------------------
     4034set(handles.run0,'BackgroundColor',[1 1 0]);% indicate plot activity by yellow color
     4035drawnow
    40264036UvData=get(handles.uvmat,'UserData');
    40274037AxeData=UvData.PlotAxes;% retrieve the current plotted data
     
    40294039[tild,PlotParamOut]= plot_field(AxeData,handles.PlotAxes,PlotParam);
    40304040errormsg=fill_GUI(PlotParamOut,handles.uvmat);
    4031 RUNColor=get(handles.run0,'BackgroundColor');%
    4032 if isequal(RUNColor,[1 0 1])% suppress magenta color (indicate that plot is  updated)
    4033     set(handles.run0,'BackgroundColor',[1 0 0]);
    4034 end
     4041if ~isempty(errormsg)
     4042    msgbox_uvmat('ERROR',errormsg)
     4043    return
     4044end
     4045% RUNColor=get(handles.run0,'BackgroundColor');%
     4046% if isequal(RUNColor,[1 0 1])% suppress magenta color (indicate that plot is  updated)
     4047%     set(handles.run0,'BackgroundColor',[1 0 0]);
     4048% end
     4049set(handles.run0,'BackgroundColor',[1 0 0]);
    40354050
    40364051%------------------------------------------------------------------------
Note: See TracChangeset for help on using the changeset viewer.