source: trunk/src/set_col_vec.m @ 230

Last change on this file since 230 was 102, checked in by sommeria, 15 years ago

bugs corrected for projection objects

File size: 3.5 KB
RevLine 
[8]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 
[102]26    col_vec=ones(size(vec_C));
[8]27    return
28end
29if (isfield(colcode,'FixedCbounds') && isequal(colcode.FixedCbounds,1))
30    minC=colcode.MinC;
31    maxC=colcode.MaxC;
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,'ColorCode') || isempty(colcode.ColorCode)
40    colorlist=[0 0 1]; %blue 
[102]41    col_vec=ones(size(vec_C));
[8]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.ColorCode,'black')
57    colorlist(1,:)=[0 0 0];%black
58    col_vec=ones(size(vec_C));%all vectors at color#1
59elseif strcmp(colcode.ColorCode,'white')
60    colorlist(1,:)=[1 1 1];%white
61    col_vec=ones(size(vec_C));%all vectors at color#1
62elseif strcmp(colcode.ColorCode,'rgb')|| strcmp(colcode.ColorCode,'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.ColorCode,'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.