source: trunk/src/set_col_vec.m @ 412

Last change on this file since 412 was 405, checked in by sommeria, 12 years ago

many bugs corrected: composition of 2 input fields, arrow colors from different scalar fields...

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