source: trunk/src/set_col_vec.m @ 857

Last change on this file since 857 was 809, checked in by g7moreau, 10 years ago
  • Add license
File size: 4.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.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
21% vec_C: matlab vector representing the scalar setting the color
22
23%=======================================================================
24% Copyright 2008-2014, LEGI UMR 5519 / CNRS UJF G-INP, Grenoble, France
25%   http://www.legi.grenoble-inp.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
41function [colorlist,col_vec,colcode_out]=set_col_vec(colcode,vec_C)
42col_vec=ones(size(vec_C));%all vectors at color#1 by default
43
44if ~isstruct(colcode),colcode=[];end;
45colcode_out=colcode;%default
46if isempty(vec_C) || ~isnumeric(vec_C)
47    colorlist=[0 0 1]; %blue
48    return
49end
50
51%% uniform color plot
52check_multicolors=0;
53%default input parameters
54if ~isfield(colcode,'ColorCode') || isempty(colcode.ColorCode)
55    colorlist=[0 0 1]; %blue
56else
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
64end
65
66if check_multicolors
67    if (isfield(colcode,'CheckFixVecColor') && isequal(colcode.CheckFixVecColor,1))
68        minC=colcode.MinVec;
69        maxC=colcode.MaxVec;
70    else
71        minC=min(vec_C);
72        maxC=max(vec_C);
73    end
74    colcode_out.MinVec=minC;
75    colcode_out.MaxVec=maxC;
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+(maxC-minC)/3;%default
81        end
82        if  isfield(colcode,'ColCode2')
83            colcode_out.ColCode2=colcode.ColCode2;
84        else
85            colcode_out.ColCode2=minC+2*(maxC-minC)/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=maxC-minC;
108        col_vec=1+floor(nblevel*(vec_C-minC)/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
112end
Note: See TracBrowser for help on using the repository browser.