source: trunk/src/set_col_vec.m @ 364

Last change on this file since 364 was 356, checked in by sommeria, 12 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
RevLine 
[356]1%'set_col_vec': % sets the color code for vectors depending on a scalar and input parameters (used for plot_field)
2%-----------------------------------------------------------------------
[313]3%function [colorlist,col_vec,minC,ColCode1,ColCode2,maxC]=colvec(colcode,vec_C)
[356]4%-----------------------------------------------------------------------
[8]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
[313]9%ColCode1, ColCode2: absolute threshold in vec_C corresponding to colcode.ColCode1 and colcode.ColCode2
[8]10%INPUT
11% colcode: struture setting the colorcode for vectors
12            % colcode.CName: 'ima_cor','black','white',...
[313]13            % colcode.ListColorCode ='black', 'white', 'rgb','brg', '64 colors'
[315]14            % colcode.CheckFixVecColor =0; thresholds scaling relative to min and max, =1 fixed thresholds
15            % colcode.MinVec; min
16            % colcode.MaxVec; max
[313]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
[8]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 
[102]27    col_vec=ones(size(vec_C));
[8]28    return
29end
[313]30if (isfield(colcode,'CheckFixVecColor') && isequal(colcode.CheckFixVecColor,1))
31    minC=colcode.MinVec;
32    maxC=colcode.MaxVec;
[8]33else
34    minC=min(vec_C);
35    maxC=max(vec_C);
36end
37
38%default input parameters
39if ~isstruct(colcode),colcode=[];end;
[313]40if ~isfield(colcode,'ListColorCode') || isempty(colcode.ListColorCode)
[8]41    colorlist=[0 0 1]; %blue 
[102]42    col_vec=ones(size(vec_C));
[8]43    return
44end
[313]45if  isfield(colcode,'ColCode1')
46    ColCode1=minC+colcode.ColCode1*(maxC-minC);
[8]47else
[313]48    ColCode1=minC+(maxC-minC)/3;%default
[8]49end
[313]50if isfield(colcode,'ColCode2')
51    ColCode2=minC+colcode.ColCode2*(maxC-minC);
[8]52else
[313]53    ColCode2=minC+2*(maxC-minC)/3;%default
[8]54end
55colcode_out.MinC=minC;
56colcode_out.MaxC=maxC;
[313]57if strcmp(colcode.ListColorCode,'black')
[8]58    colorlist(1,:)=[0 0 0];%black
59    col_vec=ones(size(vec_C));%all vectors at color#1
[313]60elseif strcmp(colcode.ListColorCode,'white')
[8]61    colorlist(1,:)=[1 1 1];%white
62    col_vec=ones(size(vec_C));%all vectors at color#1
[313]63elseif strcmp(colcode.ListColorCode,'rgb')|| strcmp(colcode.ListColorCode,'bgr')% 3 color representation
[315]64%    ind1=find(vec_C < ColCode1); % =1 for red vectors
[313]65    ind_green=find((vec_C >= ColCode1) & (vec_C < ColCode2));% =1 for green vectors
[315]66%     ind3=find(vec_C >= ColCode2);% =1 for blue vectors
[8]67    colorlist(2,:)=[0 1 0];%green
[315]68    col_vec(vec_C < ColCode1)=1;
[8]69    col_vec(ind_green)=2;
[315]70    col_vec(vec_C >= ColCode2)=3;
[313]71    if strcmp(colcode.ListColorCode,'rgb')
[8]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.