source: trunk/src/private/set_col_vec.m @ 8

Last change on this file since 8 was 8, checked in by gostiaux, 11 years ago
File size: 3.5 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.ColorCode ='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    return
27end
28if (isfield(colcode,'FixedCbounds') && isequal(colcode.FixedCbounds,1))
29    minC=colcode.MinC;
30    maxC=colcode.MaxC;
31else
32    minC=min(vec_C);
33    maxC=max(vec_C);
34end
35
36%default input parameters
37if ~isstruct(colcode),colcode=[];end;
38if ~isfield(colcode,'ColorCode') || isempty(colcode.ColorCode)
39    colorlist=[0 0 1]; %blue 
40    return
41end
42if  isfield(colcode,'colcode1')
43    colcode1=minC+colcode.colcode1*(maxC-minC);
44else
45    colcode1=minC+(maxC-minC)/3;%default
46end
47if isfield(colcode,'colcode2')
48    colcode2=minC+colcode.colcode2*(maxC-minC);
49else
50    colcode2=minC+2*(maxC-minC)/3;%default
51end
52colcode_out.MinC=minC;
53colcode_out.MaxC=maxC;
54
55if strcmp(colcode.ColorCode,'black')
56    colorlist(1,:)=[0 0 0];%black
57    col_vec=ones(size(vec_C));%all vectors at color#1
58elseif strcmp(colcode.ColorCode,'white')
59    colorlist(1,:)=[1 1 1];%white
60    col_vec=ones(size(vec_C));%all vectors at color#1
61elseif strcmp(colcode.ColorCode,'rgb')|| strcmp(colcode.ColorCode,'bgr')% 3 color representation
62    ind1=find(vec_C < colcode1); % =1 for red vectors
63    ind_green=find((vec_C >= colcode1) & (vec_C < colcode2));% =1 for green vectors
64    ind3=find(vec_C >= colcode2);% =1 for blue vectors
65    colorlist(2,:)=[0 1 0];%green
66    col_vec(ind1)=1;
67    col_vec(ind_green)=2;
68    col_vec(ind3)=3;
69    if strcmp(colcode.ColorCode,'rgb')
70        colorlist(1,:)=[1 0 0];%red
71        colorlist(3,:)=[0 0 1];%blue
72    else
73        colorlist(1,:)=[0 0 1];%blue
74        colorlist(3,:)=[1 0 0];%red
75    end
76else
77    colorjet=jet;% ususal colormap from blue to red
78    sizlist=size(colorjet);
79    indsel=ceil((sizlist(1)/64)*(1:64));
80    colorlist(:,1)=colorjet(indsel,1);
81    colorlist(:,2)=colorjet(indsel,2);
82    colorlist(:,3)=colorjet(indsel,3);
83    sizlist=size(colorlist);
84    nblevel=sizlist(1);
85    col2_1=maxC-minC;
86    col_vec=1+floor(nblevel*(vec_C-minC)/col2_1);
87    col_vec=col_vec.*(col_vec<= nblevel)+nblevel*(col_vec >nblevel);% take color #nblevel at saturation
88    col_vec=col_vec.*(col_vec>= 1)+  (col_vec <1);% take color #1 for values below 1
89end
Note: See TracBrowser for help on using the repository browser.