[356] | 1 | %'set_col_vec': % sets the color code for vectors depending on a scalar and input parameters (used for plot_field)
|
---|
| 2 | %-----------------------------------------------------------------------
|
---|
[313] | 3 | %function [colorlist,col_vec,minC,ColCode1,ColCode2,maxC]=colvec(colcode,vec_C)
|
---|
[356] | 4 | %-----------------------------------------------------------------------
|
---|
[8] | 5 | %OUTPUT
|
---|
| 6 | %colorlist(nb,3); %list of nb colors
|
---|
| 7 | %col_vec, size=[length(vec_C),3)];%list of color indices corresponding to vec_C
|
---|
| 8 | %minC, maxC: min and max of vec_C
|
---|
[313] | 9 | %ColCode1, ColCode2: absolute threshold in vec_C corresponding to colcode.ColCode1 and colcode.ColCode2
|
---|
[8] | 10 | %INPUT
|
---|
| 11 | % colcode: struture setting the colorcode for vectors
|
---|
| 12 | % colcode.CName: 'ima_cor','black','white',...
|
---|
[405] | 13 | % colcode.ColorCode ='black', 'white', 'rgb','brg', '64 colors'
|
---|
[315] | 14 | % colcode.CheckFixVecColor =0; thresholds scaling relative to min and max, =1 fixed thresholds
|
---|
| 15 | % colcode.MinVec; min
|
---|
| 16 | % colcode.MaxVec; max
|
---|
[313] | 17 | % colcode.ColCode1: first threshold for rgb, relative to min (0) and max (1)
|
---|
| 18 | % colcode.ColCode2: second threshold for rgb, relative to min (0) and max (1),
|
---|
| 19 | % rmq: we need min <= ColCode1 <= ColCode2 <= max, otherwise
|
---|
| 20 | % ColCode1 and ColCode2 are adjusted to the bounds
|
---|
[8] | 21 | % vec_C: matlab vector representing the scalar setting the color
|
---|
| 22 | function [colorlist,col_vec,colcode_out]=set_col_vec(colcode,vec_C)
|
---|
[517] | 23 | col_vec=ones(size(vec_C));%all vectors at color#1 by default
|
---|
| 24 |
|
---|
[405] | 25 | if ~isstruct(colcode),colcode=[];end;
|
---|
[8] | 26 | colcode_out=colcode;%default
|
---|
| 27 | if isempty(vec_C) || ~isnumeric(vec_C)
|
---|
[405] | 28 | colorlist=[0 0 1]; %blue
|
---|
[8] | 29 | return
|
---|
| 30 | end
|
---|
| 31 |
|
---|
[405] | 32 | %% uniform color plot
|
---|
| 33 | check_multicolors=0;
|
---|
[8] | 34 | %default input parameters
|
---|
[405] | 35 | if ~isfield(colcode,'ColorCode') || isempty(colcode.ColorCode)
|
---|
| 36 | colorlist=[0 0 1]; %blue
|
---|
[8] | 37 | else
|
---|
[405] | 38 | if strcmp(colcode.ColorCode,'black')
|
---|
| 39 | colorlist(1,:)=[0 0 0];%black
|
---|
| 40 | elseif strcmp(colcode.ColorCode,'white')
|
---|
| 41 | colorlist(1,:)=[1 1 1];%white
|
---|
| 42 | else
|
---|
| 43 | check_multicolors=1;
|
---|
| 44 | end
|
---|
[8] | 45 | end
|
---|
[405] | 46 |
|
---|
| 47 | if check_multicolors
|
---|
| 48 | if (isfield(colcode,'CheckFixVecColor') && isequal(colcode.CheckFixVecColor,1))
|
---|
| 49 | minC=colcode.MinVec;
|
---|
| 50 | maxC=colcode.MaxVec;
|
---|
[8] | 51 | else
|
---|
[405] | 52 | minC=min(vec_C);
|
---|
| 53 | maxC=max(vec_C);
|
---|
[8] | 54 | end
|
---|
[405] | 55 | colcode_out.MinC=minC;
|
---|
| 56 | colcode_out.MaxC=maxC;
|
---|
| 57 | if strcmp(colcode.ColorCode,'rgb')|| strcmp(colcode.ColorCode,'bgr')% 3 color representation
|
---|
| 58 | if isfield(colcode,'ColCode1')
|
---|
| 59 | colcode_out.ColCode1=colcode.ColCode1;
|
---|
| 60 | else
|
---|
| 61 | colcode_out.ColCode1=minC+(maxC-minC)/3;%default
|
---|
| 62 | end
|
---|
| 63 | if isfield(colcode,'ColCode2')
|
---|
| 64 | colcode_out.ColCode2=colcode.ColCode2;
|
---|
| 65 | else
|
---|
| 66 | colcode_out.ColCode2=minC+2*(maxC-minC)/3;%default
|
---|
| 67 | end
|
---|
| 68 | colorlist(2,:)=[0 1 0];%green
|
---|
| 69 | col_vec(vec_C < colcode_out.ColCode1)=1;% vectors with vec_C smaller than ColCode1 set to the first color (r or b)
|
---|
| 70 | col_vec((vec_C >= colcode_out.ColCode1) & (vec_C < colcode_out.ColCode2))=2;% select green vectors
|
---|
| 71 | col_vec(vec_C >= colcode_out.ColCode2)=3;
|
---|
| 72 | if strcmp(colcode.ColorCode,'rgb')
|
---|
| 73 | colorlist(1,:)=[1 0 0];%red
|
---|
| 74 | colorlist(3,:)=[0 0 1];%blue
|
---|
| 75 | else
|
---|
| 76 | colorlist(1,:)=[0 0 1];%blue
|
---|
| 77 | colorlist(3,:)=[1 0 0];%red
|
---|
| 78 | end
|
---|
| 79 | else
|
---|
| 80 | colorjet=jet;% ususal colormap from blue to red
|
---|
| 81 | sizlist=size(colorjet);
|
---|
| 82 | indsel=ceil((sizlist(1)/64)*(1:64));
|
---|
| 83 | colorlist(:,1)=colorjet(indsel,1);
|
---|
| 84 | colorlist(:,2)=colorjet(indsel,2);
|
---|
| 85 | colorlist(:,3)=colorjet(indsel,3);
|
---|
| 86 | sizlist=size(colorlist);
|
---|
| 87 | nblevel=sizlist(1);
|
---|
| 88 | col2_1=maxC-minC;
|
---|
| 89 | col_vec=1+floor(nblevel*(vec_C-minC)/col2_1);
|
---|
| 90 | col_vec=col_vec.*(col_vec<= nblevel)+nblevel*(col_vec >nblevel);% take color #nblevel at saturation
|
---|
| 91 | col_vec=col_vec.*(col_vec>= 1)+ (col_vec <1);% take color #1 for values below 1
|
---|
| 92 | end
|
---|
[8] | 93 | end
|
---|