source: trunk/src/set_col_vec.m @ 356

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

civ updated with new functions for opening files, consistently with uvmat
Bugs to be expected (use previous version then)

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