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]=set_col_vec(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 | %
|
---|
11 | %INPUT
|
---|
12 | % colcode: struture setting the colorcode for vectors
|
---|
13 | % colcode.CName: 'ima_cor','black','white',...
|
---|
14 | % colcode.ColorCode ='black', 'white', 'rgb','brg', '64 colors','BuYlRd'
|
---|
15 | % colcode.CheckFixVecColor =0; thresholds scaling relative to min and max, =1 fixed thresholds
|
---|
16 | % colcode.MinVec; min
|
---|
17 | % colcode.MaxVec; max
|
---|
18 | % colcode.ColCode1: first threshold for rgb, relative to min (0) and max (1)
|
---|
19 | % colcode.ColCode2: second threshold for rgb, relative to min (0) and max (1),
|
---|
20 | % rmq: we need min <= ColCode1 <= ColCode2 <= max, otherwise
|
---|
21 | % ColCode1 and ColCode2 are adjusted to the bounds
|
---|
22 | % vec_C: matlab vector representing the scalar setting the color
|
---|
23 |
|
---|
24 | %=======================================================================
|
---|
25 | % Copyright 2008-2024, LEGI UMR 5519 / CNRS UGA G-INP, Grenoble, France
|
---|
26 | % http://www.legi.grenoble-inp.fr
|
---|
27 | % Joel.Sommeria - Joel.Sommeria (A) univ-grenoble-alpes.fr
|
---|
28 | %
|
---|
29 | % This file is part of the toolbox UVMAT.
|
---|
30 | %
|
---|
31 | % UVMAT is free software; you can redistribute it and/or modify
|
---|
32 | % it under the terms of the GNU General Public License as published
|
---|
33 | % by the Free Software Foundation; either version 2 of the license,
|
---|
34 | % or (at your option) any later version.
|
---|
35 | %
|
---|
36 | % UVMAT is distributed in the hope that it will be useful,
|
---|
37 | % but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
38 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
39 | % GNU General Public License (see LICENSE.txt) for more details.
|
---|
40 | %=======================================================================
|
---|
41 |
|
---|
42 | function [colorlist,col_vec,colcode_out]=set_col_vec(colcode,vec_C)
|
---|
43 | col_vec=ones(size(vec_C));%all vectors at color#1 by default
|
---|
44 |
|
---|
45 | if ~isstruct(colcode),colcode=[];end
|
---|
46 | colcode_out=colcode;%default
|
---|
47 | if isempty(vec_C) || ~isnumeric(vec_C)
|
---|
48 | colorlist=[0 0 1]; %blue
|
---|
49 | return
|
---|
50 | end
|
---|
51 |
|
---|
52 | %% uniform color plot
|
---|
53 | check_multicolors=0;
|
---|
54 | %default input parameters
|
---|
55 | if ~isfield(colcode,'ColorCode') || isempty(colcode.ColorCode)
|
---|
56 | colorlist=[0 0 1]; %blue
|
---|
57 | else
|
---|
58 | if strcmp(colcode.ColorCode,'black')% black vectors
|
---|
59 | colorlist(1,:)=[0 0 0];%black
|
---|
60 | elseif strcmp(colcode.ColorCode,'white')% white vectors
|
---|
61 | colorlist(1,:)=[1 1 1];%white
|
---|
62 | else
|
---|
63 | check_multicolors=1;
|
---|
64 | end
|
---|
65 | end
|
---|
66 |
|
---|
67 | %% colored vectors
|
---|
68 | if check_multicolors
|
---|
69 | if (isfield(colcode,'CheckFixVecColor') && isequal(colcode.CheckFixVecColor,1))
|
---|
70 | minC=colcode.MinVec;
|
---|
71 | maxC=colcode.MaxVec;
|
---|
72 | else
|
---|
73 | minC=min(vec_C);
|
---|
74 | maxC=max(vec_C);
|
---|
75 | end
|
---|
76 | colcode_out.MinVec=minC;
|
---|
77 | colcode_out.MaxVec=maxC;
|
---|
78 | if strcmp(colcode.ColorCode,'rgb')|| strcmp(colcode.ColorCode,'bgr')% 3 color representation
|
---|
79 | if isfield(colcode,'ColCode1')
|
---|
80 | colcode_out.ColCode1=colcode.ColCode1;
|
---|
81 | else
|
---|
82 | colcode_out.ColCode1=minC+(maxC-minC)/3;%default
|
---|
83 | end
|
---|
84 | if isfield(colcode,'ColCode2')
|
---|
85 | colcode_out.ColCode2=colcode.ColCode2;
|
---|
86 | else
|
---|
87 | colcode_out.ColCode2=minC+2*(maxC-minC)/3;%default
|
---|
88 | end
|
---|
89 | colorlist(2,:)=[0 1 0];%green
|
---|
90 | col_vec(vec_C < colcode_out.ColCode1)=1;% vectors with vec_C smaller than ColCode1 set to the first color (r or b)
|
---|
91 | col_vec((vec_C >= colcode_out.ColCode1) & (vec_C < colcode_out.ColCode2))=2;% select green vectors
|
---|
92 | col_vec(vec_C >= colcode_out.ColCode2)=3;
|
---|
93 | if strcmp(colcode.ColorCode,'rgb')
|
---|
94 | colorlist(1,:)=[1 0 0];%red
|
---|
95 | colorlist(3,:)=[0 0 1];%blue
|
---|
96 | else
|
---|
97 | colorlist(1,:)=[0 0 1];%blue
|
---|
98 | colorlist(3,:)=[1 0 0];%red
|
---|
99 | end
|
---|
100 | else
|
---|
101 | switch colcode.ColorCode
|
---|
102 | case '64 colors'
|
---|
103 | colorjet=jet;% ususal colormap from blue to red
|
---|
104 | case 'BuYlRd'
|
---|
105 | hh=load('BuYlRd.mat');
|
---|
106 | colorjet=hh.BuYlRd;
|
---|
107 | end
|
---|
108 | sizlist=size(colorjet,1);
|
---|
109 | indsel=ceil((sizlist(1)/64)*(1:64));
|
---|
110 | colorlist(:,1)=colorjet(indsel,1);
|
---|
111 | colorlist(:,2)=colorjet(indsel,2);
|
---|
112 | colorlist(:,3)=colorjet(indsel,3);
|
---|
113 | nblevel=size(colorlist,1);
|
---|
114 | col2_1=maxC-minC;
|
---|
115 | col_vec=1+floor(nblevel*(vec_C-minC)/col2_1);
|
---|
116 | col_vec=col_vec.*(col_vec<= nblevel)+nblevel*(col_vec >nblevel);% take color #nblevel at saturation
|
---|
117 | col_vec=col_vec.*(col_vec>= 1)+ (col_vec <1);% take color #1 for values below 1
|
---|
118 | end
|
---|
119 | end
|
---|