source: trunk/src/set_col_vec.m @ 313

Last change on this file since 313 was 313, checked in by sommeria, 9 years ago

bug reapirs in view of vector colors and grid in civ

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