source: trunk/src/set_col_vec.m @ 329

Last change on this file since 329 was 315, checked in by sommeria, 12 years ago

many corrections, use of the new GUI civ with mask, grid and the new matlab civ1 and fix
pivlab now included in civ_matlab which contains all matlab subfunctions for 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.CheckFixVecColor =0; thresholds scaling relative to min and max, =1 fixed thresholds
13            % colcode.MinVec; min
14            % colcode.MaxVec; 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)
21col_vec=[];
22colcode_out=colcode;%default
23if isempty(vec_C) || ~isnumeric(vec_C)
24    colorlist=[0 0 1]; %blue 
25    col_vec=ones(size(vec_C));
26    return
27end
28if (isfield(colcode,'CheckFixVecColor') && isequal(colcode.CheckFixVecColor,1))
29    minC=colcode.MinVec;
30    maxC=colcode.MaxVec;
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,'ListColorCode') || isempty(colcode.ListColorCode)
39    colorlist=[0 0 1]; %blue 
40    col_vec=ones(size(vec_C));
41    return
42end
43if  isfield(colcode,'ColCode1')
44    ColCode1=minC+colcode.ColCode1*(maxC-minC);
45else
46    ColCode1=minC+(maxC-minC)/3;%default
47end
48if isfield(colcode,'ColCode2')
49    ColCode2=minC+colcode.ColCode2*(maxC-minC);
50else
51    ColCode2=minC+2*(maxC-minC)/3;%default
52end
53colcode_out.MinC=minC;
54colcode_out.MaxC=maxC;
55if strcmp(colcode.ListColorCode,'black')
56    colorlist(1,:)=[0 0 0];%black
57    col_vec=ones(size(vec_C));%all vectors at color#1
58elseif strcmp(colcode.ListColorCode,'white')
59    colorlist(1,:)=[1 1 1];%white
60    col_vec=ones(size(vec_C));%all vectors at color#1
61elseif strcmp(colcode.ListColorCode,'rgb')|| strcmp(colcode.ListColorCode,'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(vec_C < ColCode1)=1;
67    col_vec(ind_green)=2;
68    col_vec(vec_C >= ColCode2)=3;
69    if strcmp(colcode.ListColorCode,'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.