Skip to content
Snippets Groups Projects
Commit ffdf6bf2 authored by Yoann Guilhem's avatar Yoann Guilhem Committed by Nicola Vigano
Browse files

Update colormap and lookup table functions.

parent aac264c1
No related branches found
No related tags found
No related merge requests found
function c_map = gtRandCmap(maxval)
% GTRANDCMAP(maxnum) Creates a random colourmap of 'maxval' random colours
% Returns a [maxval+1 by 3] 2D matrix (first line is black)
function [cmap, cmap2] = gtRandCmap(maxval, bgcolor)
% GTRANDCMAP Creates a random colourmap of 'maxval' random colours
%
% cmap = gtRandCmap(maxval[, bgcolor])
% --------------------------------------------------------------------------
%
% INPUT:
% maxval = <uint> Maximal value of the color map
% bgcolor = <double> RGB color code for background color {[0 0 0]}
% <string> Can also be 'black' or 'white'
%
% OUTPUT:
% cmap = <double> Color map 2D matrix [maxval+1 by 3]
% (first line is background color)
if ~exist('bgcolor', 'var') || isempty(bgcolor)
bg = [0 0 0]; % black background
elseif ischar(bgcolor)
if strcmpi(bgcolor, 'black')
bg = [0 0 0];
elseif strcmpi(bgcolor, 'white')
bg = [1 1 1];
else
gtError('gtRandCmap:wrong_background_color_value', ...
['Unsupported background color value: ' bgcolor]);
end
elseif (isfloat(bgcolor) && size(bgcolor, 1) == 1 && size(bgcolor, 2) == 3)
if between(bgcolor, [0 0 0], [1 1 1])
bg = bgcolor;
else
gtError('gtRandCmap:wrong_background_color_value', ...
'Background RGB values should be set in [0 , 1]!');
end
else
gtError('gtRandCmap:wrong_background_color_value', ...
['Unsupported background color value: ' bgcolor]);
end
background = [0 0 0]; %black background
%background = [1 1 1]; %white background
maxval = max(maxval, 1);
c_map = [background; rand(uint64(maxval), 3)]; % returns a [maxnum+1 by 3] 2D matrix
cmap = rand(uint64(maxval), 3);
% Increase brightness of dim colours
int = sum(cmap, 2);
indx = int < 1;
cmap(indx, :) = 2 * cmap(indx, :) ./ int(indx, [1 1 1]);
cmap(cmap > 1) = 1;
% Add background
cmap = [bg; cmap]
%increase brightness of dim colours
int = sum(c_map, 2);
indx = find(int < 1);
indx(find(indx == 1, 1)) = []; %don't scale the zeros!
c_map(indx, :) = 2 * c_map(indx, :) ./ repmat(int(indx), 1, 3);
c_map(c_map > 1) = 1;
end
end % end of function
function [hf, ha, hp] = gtCrystAxisCmap_key(N, XYZlabels, cardinal)
function [hf, ha, hp] = gtCrystAxisCmap_key(N, XYZlabels, cardinal, fontsize)
% GTCRYSTAXISCMAP_KEY Makes a figure showing the CaxisCmap present in
% stereographic projection
%
......@@ -56,10 +56,14 @@ if ~exist('cardinal', 'var') || isempty(cardinal)
cardinal = false;
end
if ~exist('fontsize', 'var') || isempty(fontsize)
fontsize = 18;
end
hf = figure();
%pos = get(hf, 'Position');
%po(3:4) = [500 500];
%set(hf, 'Position', pos);
pos = get(hf, 'Position');
po(3:4) = [550 500];
set(hf, 'Position', pos);
inc = pi/2/N;
Nphi = 4*N+2;
......@@ -94,23 +98,23 @@ rgb = gtVectorOrientationColor([X Y Z]);
% Draw patch
hp = patch(x, y, reshape(rgb, [1 size(rgb, 1) 3]), 'edgecolor', 'none');
d1 = 0.075;
text(1+d1, 0, XYZlabels(1), 'Color', [0 0 0], 'fontweight', 'bold', ...
'VerticalAlignment', 'middle', 'HorizontalAlignment', 'center');
text(0, 1+d1, XYZlabels(2), 'Color', [0 0 0], 'fontweight', 'bold', ...
'VerticalAlignment', 'top', 'HorizontalAlignment', 'center');
text(0, 0, XYZlabels(3), 'Color', [0 0 0], 'fontweight', 'bold', ...
d1 = 0.04;
text(1+d1, 0, XYZlabels(1), 'Color', [0 0 0], 'fontsize', fontsize, 'fontweight', 'bold', ...
'VerticalAlignment', 'middle', 'HorizontalAlignment', 'left');
text(0, 1+d1, XYZlabels(2), 'Color', [0 0 0], 'fontsize', fontsize, 'fontweight', 'bold', ...
'VerticalAlignment', 'bottom', 'HorizontalAlignment', 'center');
text(0, 0, XYZlabels(3), 'Color', [0 0 0], 'fontsize', fontsize, 'fontweight', 'bold', ...
'VerticalAlignment', 'middle', 'HorizontalAlignment', 'center');
if cardinal
d2 = 0.175;
text(1+d2, 0, 'E', 'Color', [0 0 0], ...
text(1+d2, 0, 'E', 'Color', [0 0 0], 'fontsize', fontsize, ...
'VerticalAlignment', 'middle', 'HorizontalAlignment', 'center');
text(0, 1+d2, 'N', 'Color', [0 0 0], ...
text(0, 1+d2, 'N', 'Color', [0 0 0], 'fontsize', fontsize, ...
'VerticalAlignment', 'top', 'HorizontalAlignment', 'center');
text(-1-d2, 0, 'W', 'Color', [0 0 0], ...
text(-1-d2, 0, 'W', 'Color', [0 0 0], 'fontsize', fontsize, ...
'VerticalAlignment', 'middle', 'HorizontalAlignment', 'center');
text(0, -1-d2, 'S', 'Color', [0 0 0], ...
text(0, -1-d2, 'S', 'Color', [0 0 0], 'fontsize', fontsize, ...
'VerticalAlignment', 'bottom', 'HorizontalAlignment', 'center');
end
......
function hf = gtIPFCmapCubicKey(N, saturate, label)
function hf = gtIPFCmapCubicKey(N, saturate, label, fontsize)
% GTIPFCMAPCUBICKEY Show inverse pole figure color space in the cubic SST
%
% hf = gtIPFCmapCubicKey([N, saturate, label])
% hf = gtIPFCmapCubicKey([N, saturate, label, fontsize])
% -------------------------------------------------------------------------
%
% OPTIONAL INPUT:
% N = <int> Number of angular steps (quality of the plot) {30}
% saturate = <logical> Saturate or not the color in the SST
% label = <logical> Draw poles label
% fontsize = <int> Font size for labels {18}
%
% OUTPUT:
% hf = <handle> Resulting figure handle
......@@ -28,6 +29,10 @@ if ~exist('label', 'var') || isempty(label)
label = false;
end
if ~exist('fontsize', 'var') || isempty(fontsize)
fontsize = 18;
end
hf = figure();
hold on;
......@@ -59,7 +64,7 @@ for phi=phimin:inc:(phimax-inc) % Rotation around z-axis
red = ratioR;
green = (1 - ratioR) * (1 - ratioB);
blue = (1 - ratioR) * ratioB;
blue = (1 - ratioR) * ratioB;
rgb = [red green blue];
% Ensure that we stay in [0 1]
......@@ -118,13 +123,13 @@ patch(xp, yp, 'w', 'EdgeColor', 'none');
% Add labels for the 3 corners poles
plot(0, 0, 'k*');
text(0, 0, '[001]', 'fontsize', 18, 'fontweight', 'bold', ...
text(0, 0, '[001]', 'fontsize', fontsize, 'fontweight', 'bold', ...
'HorizontalAlignment', 'left', 'VerticalAlignment',' top');
plot(0.4142, 0, 'k*');
text(0.4142, 0, '[101]', 'fontsize', 18, 'fontweight', 'bold', ...
text(0.4142, 0, '[101]', 'fontsize', fontsize, 'fontweight', 'bold', ...
'HorizontalAlignment', 'right', 'VerticalAlignment', 'top');
plot(0.366, 0.366, 'k*');
text(0.366, 0.366, '[111]', 'fontsize', 18, 'fontweight', 'bold', ...
text(0.366, 0.366, '[111]', 'fontsize', fontsize, 'fontweight', 'bold', ...
'HorizontalAlignment', 'left', 'VerticalAlignment', 'bottom');
%poles_phi = [0 0 phimax];
%poles_chi = [0 chimax chimax];
......@@ -132,15 +137,14 @@ text(0.366, 0.366, '[111]', 'fontsize', 18, 'fontweight', 'bold', ...
%poles_r = tan(poles_psi/2);
%[poles_x, poles_y] = sph2cart(poles_phi, poles_r);
%plot(poles_x, poles_y, 'k*');
%text(poles_x(1), poles_y(1), '[001]', 'fontsize', 18, 'fontweight', 'bold', ...
%text(poles_x(1), poles_y(1), '[001]', 'fontsize', fontsize, 'fontweight', 'bold', ...
% 'HorizontalAlignment', 'left', 'VerticalAlignment',' top');
%text(poles_x(2), poles_y(2), '[101]', 'fontsize', 18, 'fontweight', 'bold', ...
%text(poles_x(2), poles_y(2), '[101]', 'fontsize', fontsize, 'fontweight', 'bold', ...
% 'HorizontalAlignment', 'right', 'VerticalAlignment', 'top');
%text(poles_x(3), poles_y(3), '[111]', 'fontsize', 18, 'fontweight', 'bold', ...
%text(poles_x(3), poles_y(3), '[111]', 'fontsize', fontsize, 'fontweight', 'bold', ...
% 'HorizontalAlignment', 'right', 'VerticalAlignment', 'middle');
if label
uvw_poles(1).n = '[102]'; uvw_poles(1).x = 0.236; uvw_poles(1).y = 0; % 102
uvw_poles(2).n = '[112]'; uvw_poles(2).x = 0.2247; uvw_poles(2).y = 0.2247; % 112
uvw_poles(3).n = '[213]'; uvw_poles(3).x = 0.3; uvw_poles(3).y = 0.153; % 213
......@@ -150,7 +154,7 @@ if label
plot([uvw_poles.x], [uvw_poles.y], 'k*');
for ii=1:length(uvw_poles)
text(uvw_poles(ii).x, uvw_poles(ii).y, uvw_poles(ii).n, ...
'fontsize', 18, 'fontweight', 'bold', ...
'fontsize', fontsize, 'fontweight', 'bold', ...
'HorizontalAlignment','left', 'VerticalAlignment','top');
end
......
function sigma_map = gtMakeSigmaCmap(vol_bounds, boundaries_structure)
%rather than make a volume labelled by sigma, make a single (large)
%colourmap to give the right colours to boundaries.
%save the output, so that it only has to be run once.
sigma_map=zeros(max(vol_bounds(:))+1, 3);
% gtMakeSigmaCmap Creates a colormap to give the right colors to boundaries.
%
% sigma_map = gtMakeSigmaCmap(vol_bounds, boundaries_structure)
% --------------------------------------------------------------
%
% Note:
% rather than make a volume labelled by sigma, make a single (large)
% colormap to give the right colours to boundaries.
% Save the output, so that it only has to be run once.
sigma_map = zeros(max(vol_bounds(:))+1, 3);
% non-special boundaries are grey
sigma_map(2:end, :)=0.7;
sigma_map(2:end, :) = 0.7;
% prepare the key for colouring the rest
colour_key(1,:) =[1 1 1 0]; % sigma 1, yellow
......@@ -35,11 +39,12 @@ colour_key(21,:)=[29.1 1 0 1]; % sigma 29a pink/purple
colour_key(22,:)=[29.2 1 0 1]; % sigma 29b pink/purple
%loop through boundaries structure
for i=1:length(boundaries_structure)
if ~isempty(boundaries_structure(i).sigma)
sigma_map(i+1,:) = colour_key(find(colour_key(:,1)==boundaries_structure(i).sigma), 2:4);
end
for ii = 1:length(boundaries_structure)
if ~isempty(boundaries_structure(ii).sigma)
sigma_map(ii+1, :) = colour_key(find(colour_key(:,1)==boundaries_structure(ii).sigma), 2:4);
end
end
save sigma_map sigma_map
save sigma_map sigma_map;
end % end of function
% simple function to write a colour look up table for VGStudio
% note - VGStudio sometimes seems to do funny things with the colour limits
% / colour range. So be careful, what works in matlab might not work
% correctly in VGS... Consider yourselves warned!
% first argument is the matlab colourmap
% second (option) is the .lut filename
function gtVGStudioLUT(map, filename)
% GTVGSTUDIOLUT Function to write a colour look up table for VGStudio
%
% gtVGStudioLUT(map, varargin)
% ---------------------------------------------------------------------
%
% INPUT:
% map = <double> Color map to write
%
% OPTIONAL INPUT:
% filename = <string> Path to the output file {'VGStudio.lut'}
%
% Note:
% VGStudio sometimes seems to do funny things with the colour limits
% / colour range. So be careful, what works in matlab might not work
% correctly in VGS... Consider yourselves warned!
%
% Andy King, 11/2009
function gtVGStudioLUT(map, varargin)
if ~isempty(varargin)
filename=varargin{1};
if ~exits('filename', 'var') || isempty(filename)
filename = 'VGStudio.lut';
else
filename='VGStudio.lut';
[~, ~, fext] = fileparts(filename);
if ~strcmp(fext, '.lut')
warning('gtVGStudioLUT:wrong_file_extension', ...
'VGStudio lookuptable file extension should be ''.lut''!');
end
end
fid=fopen(filename,'wt');
fid = fopen(filename, 'wt');
fprintf(fid,'; Color look up table\n\n');
taille=size(map,1);
amap=(255*map)+0.5;
N = size(map, 1);
index = ([1:N] - 0.5)/10
amap = ((255*map) + 0.5)';
;for i=1:taille
fprintf(fid,'%f %f %f %f\n',(i-0.5)/taille,amap(i,1),amap(i,2),amap(i,3));
end
output = [index ; amap];
fprintf(fid, '%f %f %f %f\n', output);
fclose(fid);
fclose(fid);
\ No newline at end of file
end % end of function
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment