Changeset 822 for trunk/src/plot_field.m


Ignore:
Timestamp:
Oct 10, 2014, 10:11:30 AM (10 years ago)
Author:
sommeria
Message:

various

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/plot_field.m

    r811 r822  
    1414% function [PlotType,PlotParamOut,haxes]= plot_field(Data,haxes,PlotParam,PosColorbar)
    1515%
    16 % OUTPUT:
     16% OUPUT:
    1717% PlotType: type of plot: 'text','line'(curve plot),'plane':2D view,'volume'
    1818% PlotParamOut: structure, representing the updated  plotting parameters, in case of automatic scaling
    1919% haxes: handle of the plotting axis, when a new figure is created.
    2020%
    21 % INPUT:
     21%INPUT
    2222%    Data:   structure describing the field to plot
    2323%         (optional) .ListGlobalAttribute: cell listing the names of the global attributes
     
    8181%                expressed in figure relative unit (ex [0.821 0.471 0.019 0.445])
    8282
    83 %=======================================================================
    84 % Copyright 2008-2014, LEGI UMR 5519 / CNRS UJF G-INP, Grenoble, France
    85 %   http://www.legi.grenoble-inp.fr
    86 %   Joel.Sommeria - Joel.Sommeria (A) legi.cnrs.fr
    87 %
     83%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
     84%  Copyright 2008-2014, LEGI / CNRS UJF G-INP, Joel.Sommeria@legi.grenoble-inp.fr
     85%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
    8886%     This file is part of the toolbox UVMAT.
    89 %
     87% 
    9088%     UVMAT is free software; you can redistribute it and/or modify
    91 %     it under the terms of the GNU General Public License as published
    92 %     by the Free Software Foundation; either version 2 of the license,
    93 %     or (at your option) any later version.
    94 %
     89%     it under the terms of the GNU General Public License as published by
     90%     the Free Software Foundation; either version 2 of the License, or
     91%     (at your option) any later version.
     92% 
    9593%     UVMAT is distributed in the hope that it will be useful,
    9694%     but WITHOUT ANY WARRANTY; without even the implied warranty of
    9795%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    98 %     GNU General Public License (see LICENSE.txt) for more details.
    99 %=======================================================================
     96%     GNU General Public License (file UVMAT/COPYING.txt) for more details.
     97%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
    10098
    10199function [PlotType,PlotParamOut,haxes]= plot_field(Data,haxes,PlotParam)
     
    779777%%   image or scalar plot %%%%%%%%%%%%%%%%%%%%%%%%%%
    780778if test_ima
    781    
    782779    % distinguish B/W and color images
    783780    np=size(A);%size of image
     
    798795    end
    799796   
    800     %set the color map
     797    %set for grey scale setting
    801798    if isfield(PlotParam.Scalar,'CheckBW') && ~isempty(PlotParam.Scalar.CheckBW)
    802799        BW=PlotParam.Scalar.CheckBW; %BW=0 color imposed, else gray scale imposed.
     
    806803    end
    807804   
    808             % determine the plot option 'image' or 'contours'
     805    % determine the plot option 'image' or 'contours'
     806    CheckContour=0; %default
    809807    if isfield(PlotParam.Scalar,'ListContour')
    810808        CheckContour=strcmp(PlotParam.Scalar.ListContour,'contours');% =1 for contour plot option
    811     else
    812         CheckContour=0; %default
    813809    end
    814810   
    815811    %case of grey level images or contour plot
    816     if siz==2
    817         if ~isfield(PlotParam.Scalar,'CheckFixScalar')
    818             PlotParam.Scalar.CheckFixScalar=0;% free scalar threshold value scale (from min to max) by default
    819         end
    820         if ~isfield(PlotParam.Scalar,'MinA')
    821             PlotParam.Scalar.MinA=[];%no min scalar threshold value set
    822         end
    823         if ~isfield(PlotParam.Scalar,'MaxA')
    824             PlotParam.Scalar.MaxA=[];%no max scalar threshold value set
     812    if ~isfield(PlotParam.Scalar,'CheckFixScalar')
     813        PlotParam.Scalar.CheckFixScalar=0;% free scalar threshold value scale (from min to max) by default
     814    end
     815    if ~isfield(PlotParam.Scalar,'MinA')
     816        PlotParam.Scalar.MinA=[];%no min scalar threshold value set
     817    end
     818    if ~isfield(PlotParam.Scalar,'MaxA')
     819        PlotParam.Scalar.MaxA=[];%no max scalar threshold value set
     820    end
     821   
     822    % determine the min scalar value
     823    if PlotParam.Scalar.CheckFixScalar && ~isempty(PlotParam.Scalar.MinA) && isnumeric(PlotParam.Scalar.MinA)
     824        MinA=double(PlotParam.Scalar.MinA); % min value set as input
     825    else
     826        MinA=double(min(min(min(A)))); % min value set as min of non NaN scalar values
     827    end
     828   
     829    % error if the input scalar is NaN everywhere
     830    if isnan(MinA)
     831        errormsg='NaN input scalar or image in plot_field';
     832        return
     833    end
     834   
     835    % determine the max scalar value
     836    CheckFixScalar=0;
     837    if PlotParam.Scalar.CheckFixScalar && ~isempty(PlotParam.Scalar.MaxA) && isnumeric(PlotParam.Scalar.MaxA)
     838        MaxA=double(PlotParam.Scalar.MaxA); % max value set as input
     839        CheckFixScalar=1;
     840    else
     841        MaxA=double(max(max(max(A)))); % max value set as min of non NaN scalar values
     842    end
     843   
     844    PlotParamOut.Scalar.MinA=MinA;
     845    PlotParamOut.Scalar.MaxA=MaxA;
     846    PlotParamOut.Scalar.Npx=size(A,2);
     847    PlotParamOut.Scalar.Npy=size(A,1);
     848    %     if siz==2
     849    % case of contour plot
     850    if CheckContour
     851        if ~isempty(hima) && ishandle(hima)
     852            delete(hima) % delete existing image
    825853        end
    826854       
    827         % determine the min scalar value
    828         if PlotParam.Scalar.CheckFixScalar && ~isempty(PlotParam.Scalar.MinA) && isnumeric(PlotParam.Scalar.MinA) 
    829             MinA=double(PlotParam.Scalar.MinA); % min value set as input
    830         else
    831             MinA=double(min(min(A))); % min value set as min of non NaN scalar values
    832         end
     855        % set the contour values
     856        if ~isfield(PlotParam.Scalar,'IncrA')
     857            PlotParam.Scalar.IncrA=[];% automatic contour interval
     858        end
     859        if ~isempty(PlotParam.Scalar.IncrA) && isnumeric(PlotParam.Scalar.IncrA)
     860            interval=PlotParam.Scalar.IncrA;
     861        else % automatic contour interval
     862            cont=colbartick(MinA,MaxA);
     863            interval=cont(2)-cont(1);%default
     864            PlotParamOut.Scalar.IncrA=interval;% set the interval as output for display on the GUI
     865        end
     866        abscontmin=interval*floor(MinA/interval);
     867        abscontmax=interval*ceil(MaxA/interval);
     868        contmin=interval*floor(min(min(A))/interval);
     869        contmax=interval*ceil(max(max(A))/interval);
     870        cont_pos_plus=0:interval:contmax;% zero and positive contour values (plotted as solid lines)
     871        cont_pos_min=double(contmin):interval:-interval;% negative contour values (plotted as dashed lines)
     872        cont_pos=[cont_pos_min cont_pos_plus];% set of all contour values
    833873       
    834         % error if the input scalar is NaN everywhere
    835         if isnan(MinA)
    836                 errormsg='NaN input scalar or image in plot_field';
    837                 return
    838         end
     874        sizpx=(Coord_x(end)-Coord_x(1))/(np(2)-1);
     875        sizpy=(Coord_y(1)-Coord_y(end))/(np(1)-1);
     876        x_cont=Coord_x(1):sizpx:Coord_x(end); % pixel x coordinates for image display
     877        y_cont=Coord_y(1):-sizpy:Coord_y(end); % pixel x coordinates for image display
    839878       
    840         % determine the max scalar value
    841         if PlotParam.Scalar.CheckFixScalar && ~isempty(PlotParam.Scalar.MaxA) && isnumeric(PlotParam.Scalar.MaxA) 
    842             MaxA=double(PlotParam.Scalar.MaxA); % max value set as input
    843         else
    844             MaxA=double(max(max(A))); % max value set as min of non NaN scalar values
    845         end
     879        %axes(haxes)% set the input axes handle as current axis
    846880       
    847         PlotParamOut.Scalar.MinA=MinA;
    848         PlotParamOut.Scalar.MaxA=MaxA;
    849         PlotParamOut.Scalar.Npx=size(A,2);
    850         PlotParamOut.Scalar.Npy=size(A,1);
     881        % colormap(map);
     882        tag_axes=get(haxes,'Tag');% axes tag
     883        Opacity=1;
     884        if isfield(PlotParam.Scalar,'Opacity')&&~isempty(PlotParam.Scalar.Opacity)
     885            Opacity=PlotParam.Scalar.Opacity;
     886        end
     887        % fill the space between contours if opacity is undefined or =1
     888        if isequal(Opacity,1)
     889            [var,hcontour]=contour(haxes,x_cont,y_cont,A,cont_pos);% determine all contours
     890            set(hcontour,'Fill','on')% fill the space between contours
     891            set(hcontour,'LineStyle','none')
     892            hold on
     893        end
     894        [var_p,hcontour_p]=contour(haxes,x_cont,y_cont,A,cont_pos_plus,'k-');% draw the contours for positive values as solid lines
     895        hold on
     896        [var_m,hcontour_m]=contour(haxes,x_cont,y_cont,A,cont_pos_min,'--');% draw the contours for negative values as dashed lines
     897        if isequal(Opacity,1)
     898            set(hcontour_m,'LineColor',[1 1 1])% draw negative contours in white (better visibility in dark background)
     899        end
     900        set(haxes,'Tag',tag_axes);% restore axes tag (removed by the matlab fct contour !)
     901        hold off
    851902       
    852         % case of contour plot
    853         if CheckContour
    854             if ~isempty(hima) && ishandle(hima)
    855                 delete(hima) % delete existing image
    856             end
    857            
    858             % set the contour values
    859             if ~isfield(PlotParam.Scalar,'IncrA')
    860                 PlotParam.Scalar.IncrA=[];% automatic contour interval
    861             end
    862             if ~isempty(PlotParam.Scalar.IncrA) && isnumeric(PlotParam.Scalar.IncrA)
    863                 interval=PlotParam.Scalar.IncrA;
    864             else % automatic contour interval
    865                 cont=colbartick(MinA,MaxA);
    866                 interval=cont(2)-cont(1);%default
    867                 PlotParamOut.Scalar.IncrA=interval;% set the interval as output for display on the GUI
    868             end
    869             %B=A;
    870             abscontmin=interval*floor(MinA/interval);
    871             abscontmax=interval*ceil(MaxA/interval);
    872             contmin=interval*floor(min(min(A))/interval);
    873             contmax=interval*ceil(max(max(A))/interval);
    874             cont_pos_plus=0:interval:contmax;% zero and positive contour values (plotted as solid lines)
    875             cont_pos_min=double(contmin):interval:-interval;% negative contour values (plotted as dashed lines)
    876             cont_pos=[cont_pos_min cont_pos_plus];% set of all contour values
    877            
    878             sizpx=(Coord_x(end)-Coord_x(1))/(np(2)-1);
    879             sizpy=(Coord_y(1)-Coord_y(end))/(np(1)-1);
    880             x_cont=Coord_x(1):sizpx:Coord_x(end); % pixel x coordinates for image display
    881             y_cont=Coord_y(1):-sizpy:Coord_y(end); % pixel x coordinates for image display
    882            
    883             %axes(haxes)% set the input axes handle as current axis
    884 
    885            % colormap(map);
    886            tag_axes=get(haxes,'Tag');% axes tag
    887            Opacity=1;
    888            if isfield(PlotParam.Scalar,'Opacity')&&~isempty(PlotParam.Scalar.Opacity)
    889                Opacity=PlotParam.Scalar.Opacity;
    890            end
    891            % fill the space between contours if opacity is undefined or =1
    892            if isequal(Opacity,1)
    893                [var,hcontour]=contour(haxes,x_cont,y_cont,A,cont_pos);% determine all contours
    894                set(hcontour,'Fill','on')% fill the space between contours
    895                set(hcontour,'LineStyle','none')
    896                hold on
    897            end
    898            [var_p,hcontour_p]=contour(haxes,x_cont,y_cont,A,cont_pos_plus,'k-');% draw the contours for positive values as solid lines
    899            hold on
    900            [var_m,hcontour_m]=contour(haxes,x_cont,y_cont,A,cont_pos_min,'--');% draw the contours for negative values as dashed lines
    901            if isequal(Opacity,1)
    902                set(hcontour_m,'LineColor',[1 1 1])% draw negative contours in white (better visibility in dark background)
    903            end
    904            set(haxes,'Tag',tag_axes);% restore axes tag (removed by the matlab fct contour !)
    905            hold off
    906            
    907             %determine the color scale and map
    908             caxis([abscontmin abscontmax])
    909             if BW
    910                 vec=linspace(0,1,(abscontmax-abscontmin)/interval);%define a greyscale colormap with steps interval
    911                 map=[vec' vec' vec'];
    912                 colormap(map);
     903        %determine the color scale and map
     904        caxis([abscontmin abscontmax])
     905        if BW
     906            vec=linspace(0,1,(abscontmax-abscontmin)/interval);%define a greyscale colormap with steps interval
     907            map=[vec' vec' vec'];
     908            colormap(map);
     909        else
     910            colormap('default'); % default matlab colormap ('jet')
     911        end
     912       
     913        if isfield(PlotParam.Axes,'CheckFixAspectRatio') && isequal(PlotParam.Axes.CheckFixAspectRatio,1)
     914            set(haxes,'DataAspectRatioMode','manual')
     915            if isfield(PlotParam.Axes,'AspectRatio')
     916                set(haxes,'DataAspectRatio',[PlotParam.Axes.AspectRatio 1 1])
    913917            else
    914                 colormap('default'); % default matlab colormap ('jet')
    915             end
    916            
    917             if isfield(PlotParam.Axes,'CheckFixAspectRatio') && isequal(PlotParam.Axes.CheckFixAspectRatio,1)
    918                 set(haxes,'DataAspectRatioMode','manual')
    919                 if isfield(PlotParam.Axes,'AspectRatio')
    920                     set(haxes,'DataAspectRatio',[PlotParam.Axes.AspectRatio 1 1])
    921                 else
    922                     set(haxes,'DataAspectRatio',[1 1 1])
    923                 end
    924             end
    925         else     
     918                set(haxes,'DataAspectRatio',[1 1 1])
     919            end
     920        end
     921    else %usual images (no contour)
    926922        % set  colormap for  image display
    927             % rescale the grey levels with min and max, put a grey scale colorbar
    928 %             B=A;
    929             if BW
    930                 vec=linspace(0,1,255);%define a linear greyscale colormap
    931                 map=[vec' vec' vec'];
    932                 colormap(map);  %grey scale color map
    933             else
    934                 colormap('default'); % standard false colors for div, vort , scalar fields
    935             end
     923        if BW
     924            vec=linspace(0,1,255);%define a linear greyscale colormap
     925            map=[vec' vec' vec'];
     926            colormap(map);  %grey scale color map
     927            if siz==3% true color images visualized in BW
     928                A=uint16(sum(A,3));%sum the three color components for color images displayed with BW option
     929            end
     930        else
     931            if siz==3 && CheckFixScalar % true color images rescaled by MaxA
     932                  A=uint8(255*double(A)/double(MaxA));
     933            end
     934            colormap('default'); % standard false colors for div, vort , scalar fields
    936935        end
    937936       
    938         % case of color images
    939     else
    940         if BW
    941             A=uint16(sum(A,3));
    942         else
    943             A=uint8(A);
    944         end
    945         MinA=0;
    946         MaxA=255;
    947     end
    948    
    949     % display usual image
    950     if ~CheckContour
    951937        % interpolate field to increase resolution of image display
    952938        test_interp=0;
    953         if size(A,3)==1 % scalar of B/W image
     939        if size(A,3)==1 % scalar or B/W image
    954940            test_interp=1;
    955941            if max(np) <= 64
     
    10141000    %display the colorbar code for B/W images if Poscolorbar not empty
    10151001    if ~isempty(PosColorbar)
    1016         if siz==2 && exist('PosColorbar','var')
     1002        if size(A,3)==1 && exist('PosColorbar','var')
    10171003            if isempty(hcol)||~ishandle(hcol)
    10181004                hcol=colorbar;%create new colorbar
Note: See TracChangeset for help on using the changeset viewer.