Skip to content
Snippets Groups Projects
Commit 14465a06 authored by Laura Nervo's avatar Laura Nervo Committed by Nicola Vigano
Browse files

gtPlotHexagon : introduced varargin for more options


Signed-off-by: default avatarLaura Nervo <laura.nervo@esrf.fr>

git-svn-id: https://svn.code.sf.net/p/dct/code/trunk@1005 4c865b51-4357-4376-afb4-474e03ccb993
parent 945c1a4c
No related branches found
No related tags found
No related merge requests found
function hf = gtPlotHexagon(grains, r_vectors, angle, cmap, hf)
% hf = gtPlotHexagon(grains, r_vectors, angle, cmap, hf)
% ------------------------------------------------------
function hf = gtPlotHexagon(grains, r_vectors, varargin)
% hf = gtPlotHexagon(grains, r_vectors, varargin)
% -----------------------------------------------
% Makes a figure containing subplots of the unit cells of the selected grains
%
% INPUT:
% grains = IDs of grains of interest <double 1xN>
% grains = IDs of grains of interest <double 1xM>
% r_vectors = orientations for all the grains <double Nx4>
% angle = rotation around z-axis to visualize orientations from the
% section plane as defined in gtShowSampleSurface
% cmap = colour map for all the grains (rgb) <double N+1x3>
% hf = figure handle
%
% OPTIONAL INPUT (varargin):
% cmap = colour map for all the grains (rgb) <double N+1x3> {[1 0 0]}
% angle = rotation around z-axis to visualize orientations from the
% section plane as defined in gtShowSampleSurface {0}
% hf = figure handle if already existing []
% tomo_setup = flag to match tomo reference system: x-->y y-->x z-->-z
% {false}
% reference = flag to plot the reference unit cell for each grain orientation
% {false}
% section = flag to draw a section on the yz-plane to follow
% gtShowSampleSurface {false}
% overlap = flag to overlap the first grainID in the list to all the
% other grains {true}
%
% OUTPUT:
% hf = figure handle
......@@ -20,70 +30,126 @@ function hf = gtPlotHexagon(grains, r_vectors, angle, cmap, hf)
% instruments, x//y instrument.
%
% Reference hexagon coordinates see gtHexagonalUnitCell
%
%
% Version 003 16-01-2013 by LNervo
if ~exist('angle','var') || isempty(angle)
angle = 0;
end
if ~exist('cmap', 'var') || isempty(cmap)
app.cmap = [];
app.angle = 0;
app.hf = [];
app.tomo_setup = false;
app.reference = false;
app.section = false;
app.overlap = true;
app = parse_pv_pairs(app,varargin);
if isempty(app.cmap)
%if no colourmap passed in, use red
cmap = zeros(size(r_vectors, 1), 3);
cmap(:,1) = 1;
app.cmap = zeros(size(r_vectors, 1), 3);
app.cmap(:,1) = 1;
%if overlapping,use different colour
if app.overlap
app.cmap(1,:) = [0 1 0];
end
end
if ~exist('hf','var') || isempty(hf)
hf = figure;
if isempty(app.hf)
app.hf = figure();
end
% keep info on grainID in the first column
if size(r_vectors,2) == 3
r_vectors(:,2:4) = r_vectors;
r_vectors(:,1) = (1:length(r_vectors))';
end
% patch object hexagonal prism
data = gtHexagonalUnitCell('ratio',2,'draw',false);
corners3 = data.vertices(1:12,:);
corners3 = data.vertices(1:12,:);
rec_faces = data.faces_sides;
hex_faces = data.faces_end;
vertices = zeros(12,3,length(r_vectors));
% find grid size
if length(grains) > 5
xdim = 5;
ydim = ceil(length(grains)/xdim);
else
xdim = length(grains);
ydim = 1;
end
set(app.hf, 'Position', [1 250*ydim 200*xdim 250*ydim])
% apply the R-vector
for i=1:length(grains)
for ii=1:length(grains)
grainID = grains(i);
grainID = grains(ii);
% takes the R_vector
R = r_vectors(find(r_vectors(:,1)==grainID),2:4);
% crystal to sample rotation matrix == g^-1
g = Rod2g(R);
corners3a = (g*corners3')';
% allow for the two coordinate systems. Transform from instrument to
% reconstructed tomo coordinates: x-->y y-->x z-->-z
% corners3a=[corners3a(:,2) corners3a(:,1) -corners3a(:,3)];
if app.tomo_setup
corners3a=[corners3a(:,2) corners3a(:,1) -corners3a(:,3)];
end
% do the rotate to follow the section plane
corners3b = ([cosd(angle) sind(angle) 0; -sind(angle) cosd(angle) 0;0 0 1]*corners3a')';
subplot(1, length(grains), i);
corners3b = ([ cosd(app.angle) sind(app.angle) 0; ...
-sind(app.angle) cosd(app.angle) 0; ...
0 0 1]*corners3a')';
% store info on vertices
vertices(:,:,grainID) = corners3b;
%subplot(ceil(ii,xdim), mod(ii,xdim), ii);
subplot(ydim, xdim, ii);
% reference hex
patch('Vertices', corners3, 'Faces', hex_faces, 'FaceColor', 'b', 'FaceAlpha', 0.4)
patch('Vertices', corners3, 'Faces', rec_faces, 'FaceColor', 'b', 'FaceAlpha', 0.4)
if app.reference && ~app.overlap
patch('Vertices', corners3, 'Faces', hex_faces, 'FaceColor', 'b', 'FaceAlpha', 0.4)
patch('Vertices', corners3, 'Faces', rec_faces, 'FaceColor', 'b', 'FaceAlpha', 0.4)
end
% if overlap the first grain is used as reference for the others
if app.overlap && grains(1) ~= grainID
overlapID = grains(1);
corners3a = (Rod2g( r_vectors(find(r_vectors(:,1)==overlapID),2:4) )*corners3')';
patch('Vertices', corners3a, 'Faces', hex_faces, 'FaceColor', app.cmap(overlapID+1,:), 'FaceAlpha', 0.4)
patch('Vertices', corners3a, 'Faces', rec_faces, 'FaceColor', app.cmap(overlapID+1,:), 'FaceAlpha', 0.4)
end
% reference background like the section plane
xpos=min(mean(corners3b(hex_faces(1,:), 1)), mean(corners3b(hex_faces(2,:), 1)));
section_plane_vertices=[xpos 1 1; xpos 1 -1; xpos -1 1; xpos -1 -1];
section_plane_face=[1 2 4 3];
patch('Vertices', section_plane_vertices, 'Faces', section_plane_face, 'FaceColor', 'k', 'FaceAlpha', 0.4)
if app.section
pos=min(mean(corners3b(hex_faces(1,:), 1)), mean(corners3b(hex_faces(2,:), 1)));
section_plane_vertices=[pos 1 1; pos 1 -1; pos -1 1; pos -1 -1];
section_plane_face=[1 2 4 3];
patch('Vertices', section_plane_vertices, 'Faces', section_plane_face, 'FaceColor', 'k', 'FaceAlpha', 0.4)
end
% including the rotation for sectioning
patch('Vertices', corners3b, 'Faces', hex_faces, 'FaceColor', cmap(grainID+1,:), 'FaceAlpha', 1)
patch('Vertices', corners3b, 'Faces', rec_faces, 'FaceColor', cmap(grainID+1,:), 'FaceAlpha', 1)
patch('Vertices', corners3b, 'Faces', hex_faces, 'FaceColor', app.cmap(grainID+1,:), 'FaceAlpha', 1)
patch('Vertices', corners3b, 'Faces', rec_faces, 'FaceColor', app.cmap(grainID+1,:), 'FaceAlpha', 1)
% a bit of labeling
set(get(get(gcf, 'CurrentAxes'), 'Title'), 'String', sprintf('grain %d unit cell', grainID))
set(get(get(gcf, 'CurrentAxes'), 'xLabel'),'String', 'x axis')
set(get(get(gcf, 'CurrentAxes'), 'yLabel'),'String', 'y axis')
set(get(get(gcf, 'CurrentAxes'), 'zLabel'),'String', 'z axis')
% need to mirror twice to stay consistant with tomo
% yz-plane view
set(get(gcf, 'CurrentAxes'), 'view', [90 0])
axis tight
axis equal
axis square
axis vis3d
end
axis tight;
axis square;
axis vis3d;
axis equal;
% activate rotating option
h = rotate3d(gcf);
set(h,'Enable','on');
end % end for grains
set(gcf,'UserData',vertices)
hf=gcf;
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