[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


[809]  12  % colcode.CName: 'ima_cor','black','white',...


 13  % colcode.ColorCode ='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


[8]  21  % vec_C: matlab vector representing the scalar setting the color


[809]  22 


 23  %=======================================================================


[977]  24  % Copyright 20082017, LEGI UMR 5519 / CNRS UGA GINP, Grenoble, France


[809]  25  % http://www.legi.grenobleinp.fr


 26  % Joel.Sommeria  Joel.Sommeria (A) legi.cnrs.fr


 27  %


 28  % This file is part of the toolbox UVMAT.


 29  %


 30  % UVMAT is free software; you can redistribute it and/or modify


 31  % it under the terms of the GNU General Public License as published


 32  % by the Free Software Foundation; either version 2 of the license,


 33  % or (at your option) any later version.


 34  %


 35  % UVMAT is distributed in the hope that it will be useful,


 36  % but WITHOUT ANY WARRANTY; without even the implied warranty of


 37  % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the


 38  % GNU General Public License (see LICENSE.txt) for more details.


 39  %=======================================================================


 40 


[8]  41  function [colorlist,col_vec,colcode_out]=set_col_vec(colcode,vec_C)


[517]  42  col_vec=ones(size(vec_C));%all vectors at color#1 by default


 43 


[405]  44  if ~isstruct(colcode),colcode=[];end;


[8]  45  colcode_out=colcode;%default


 46  if isempty(vec_C)  ~isnumeric(vec_C)


[405]  47  colorlist=[0 0 1]; %blue


[8]  48  return


 49  end


 50 


[405]  51  %% uniform color plot


 52  check_multicolors=0;


[8]  53  %default input parameters


[405]  54  if ~isfield(colcode,'ColorCode')  isempty(colcode.ColorCode)


 55  colorlist=[0 0 1]; %blue


[8]  56  else


[405]  57  if strcmp(colcode.ColorCode,'black')


 58  colorlist(1,:)=[0 0 0];%black


 59  elseif strcmp(colcode.ColorCode,'white')


 60  colorlist(1,:)=[1 1 1];%white


 61  else


 62  check_multicolors=1;


 63  end


[8]  64  end


[405]  65 


 66  if check_multicolors


 67  if (isfield(colcode,'CheckFixVecColor') && isequal(colcode.CheckFixVecColor,1))


 68  minC=colcode.MinVec;


 69  maxC=colcode.MaxVec;


[8]  70  else


[405]  71  minC=min(vec_C);


 72  maxC=max(vec_C);


[8]  73  end


[654]  74  colcode_out.MinVec=minC;


 75  colcode_out.MaxVec=maxC;


[405]  76  if strcmp(colcode.ColorCode,'rgb') strcmp(colcode.ColorCode,'bgr')% 3 color representation


 77  if isfield(colcode,'ColCode1')


 78  colcode_out.ColCode1=colcode.ColCode1;


 79  else


 80  colcode_out.ColCode1=minC+(maxCminC)/3;%default


 81  end


 82  if isfield(colcode,'ColCode2')


 83  colcode_out.ColCode2=colcode.ColCode2;


 84  else


 85  colcode_out.ColCode2=minC+2*(maxCminC)/3;%default


 86  end


 87  colorlist(2,:)=[0 1 0];%green


 88  col_vec(vec_C < colcode_out.ColCode1)=1;% vectors with vec_C smaller than ColCode1 set to the first color (r or b)


 89  col_vec((vec_C >= colcode_out.ColCode1) & (vec_C < colcode_out.ColCode2))=2;% select green vectors


 90  col_vec(vec_C >= colcode_out.ColCode2)=3;


 91  if strcmp(colcode.ColorCode,'rgb')


 92  colorlist(1,:)=[1 0 0];%red


 93  colorlist(3,:)=[0 0 1];%blue


 94  else


 95  colorlist(1,:)=[0 0 1];%blue


 96  colorlist(3,:)=[1 0 0];%red


 97  end


 98  else


 99  colorjet=jet;% ususal colormap from blue to red


 100  sizlist=size(colorjet);


 101  indsel=ceil((sizlist(1)/64)*(1:64));


 102  colorlist(:,1)=colorjet(indsel,1);


 103  colorlist(:,2)=colorjet(indsel,2);


 104  colorlist(:,3)=colorjet(indsel,3);


 105  sizlist=size(colorlist);


 106  nblevel=sizlist(1);


 107  col2_1=maxCminC;


 108  col_vec=1+floor(nblevel*(vec_CminC)/col2_1);


 109  col_vec=col_vec.*(col_vec<= nblevel)+nblevel*(col_vec >nblevel);% take color #nblevel at saturation


 110  col_vec=col_vec.*(col_vec>= 1)+ (col_vec <1);% take color #1 for values below 1


 111  end


[8]  112  end

