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

Added function to plot hexagonal prism instead of cube for hexagonal materials.


     gtINDEXDrawGrainUnitCells(grain, parameters, phaseid,  type, numbered, hlight, strainscale)
     -------------------------------------------------------------------------------------------

     Draws a figure representing grain size, location and orientation by
     cubes or hexagonal prismes based on the their Rodrigues vectors.

     INPUT:
       grains      = grain structure from indexing
       parameters  = as in parameters file (required field: labgeo)
       phaseid     = phase number <int> {1}
       type        = cell type {'cubic'} / 'hexagonal'
       numbered    = if true, the grain id-s for each grain are shown
       hlight      = grain id-s to be highlighted
       strainscale = a multiplicative factor for the strain components
                     for better visibility (if strain data available)

     Version 001 28-06-2012 by LNervo
       Modified gtINDEXDrawGrainCubes : cubes or hexagons can be drawn

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

git-svn-id: https://svn.code.sf.net/p/dct/code/trunk@578 4c865b51-4357-4376-afb4-474e03ccb993
parent 8082cdfe
No related branches found
No related tags found
No related merge requests found
function vertices = hexagon(a,c,draw)
% create a hexagonal grid (radius <r>)
% apothem = c2 = r*sqrt(3)/2
cx=a*sqrt(3);
c2=cx/2;
v=0:60:360;
cv=a*cosd(v);
sv=a*sind(v);
x0 = 0*cx+cv;
y0 = 0*cx+sv;
z0 = repmat(-c/2,1,length(v));
z1 = repmat(+c/2,1,length(v));
vertices = [[x0;y0;z0],[x0;y0;z1]]';
vertices(7,:)=[];
vertices(end,:)=[];
if draw
figure;
line(x0,y0,z0);
line(x0,y0,z1);
hold on;
plot3(x0,y0,z0,'r*')
plot3(x0(1),y0(1),z0(1),'b*')
axis equal;
xlabel('x (100)')
ylabel('y (010)')
zlabel('z (001)')
end
%
%
% % hexagon made of hexagons
% figure;
% axis equal;
% for f=[1,2] % we test <f>!
% for a=0:60:360
% line(f*cx*cosd(a)+cv,f*cx*sind(a)+sv);
% end
% if f==2
% for a=30:60:360
% line(c2*cx*cosd(a)+cv,c2*cx*sind(a)+sv);
% end
% end
% end
%
% xy=unique([x,y],'rows')
%
% x=xy(:,1);
% y=xy(:,2);
% xx=[];
% yy=[];
% for i=1:3
% p=convhull(x,y);
% xx=[xx;x(p)]; % quick and dirty!
% yy=[yy;y(p)];
% x(p)=[];
% y(p)=[];
% end
% at=atan2(xx,yy);
% [ax,ax]=sort(at);
% xx=xx(ax);
% yy=yy(ax);
% line(xx,yy,...
% 'marker','s',...
% 'color',[0,0,0]);
% % test some data points
% px=20*rand(500,1)-10;
% py=20*rand(500,1)-10;
% line(px,py,...
% 'marker','.',...
% 'markersize',4,...
% 'linestyle','none');
% ix=inpolygon(px,py,xx,yy);
% line(px(ix),py(ix),...
% 'marker','.',...
% 'linestyle','none',...
% 'color',[1,0,0]);
end
\ No newline at end of file
function gtINDEXDrawGrainUnitCells(grains, parameters, phaseid, type, numbered, hlight, strainscale)
% gtINDEXDrawGrainUnitCells(grains, parameters, phaseid, type, numbered, hlight, strainscale)
% -------------------------------------------------------------------------------------------
%
% Draws a figure representing grain size, location and orientation by
% cubes or hexagonal prismes based on the their Rodrigues vectors.
%
% INPUT:
% grains = grain structure from indexing
% parameters = as in parameters file (required field: labgeo)
% phaseid = phase number <int> {1}
% type = cell type {'cubic'} / 'hexagonal'
% numbered = if true, the grain id-s for each grain are shown
% hlight = grain id-s to be highlighted
% strainscale = a multiplicative factor for the strain components
% for better visibility (if strain data available)
%
% Version 001 28-06-2012 by LNervo
% Modified gtINDEXDrawGrainCubes : cubes or hexagons can be drawn
if ~exist('grains','var') || isempty(grains)
disp('Loading grain data from 4_grains/phase_01/index.mat ...')
tmp = load('4_grains/phase_01/index.mat','grain');
grains = tmp.grain;
end
if ~exist('parameters','var') || isempty(parameters)
disp('Loading parameters from parameters.mat ...')
load('parameters.mat');
end
if ~exist('phaseid','var') || isempty(phaseid)
phaseid = 1;
end
if ~exist('type','var') || isempty(type)
type = 'cubic';
end
if ~exist('hlight','var') || isempty(hlight)
hlight = [];
end
if ~exist('numbered','var') || isempty(numbered)
numbered = [];
end
if ~exist('strainscale','var') || isempty(strainscale)
strainscale = 50;
end
sample.rad = parameters.labgeo.samenvrad;
sample.bot = parameters.labgeo.samenvbot;
sample.top = parameters.labgeo.samenvtop;
nof_grains = length(grains);
fs = 20;
samradmargin = 0.05;
samtopmargin = 0.2;
pixelsize = (parameters.labgeo.pixelsizeu + parameters.labgeo.pixelsizev)/2;
figure();
colormap(jet(1000))
caxis([-0.01 0.01])
cb = colorbar('FontSize', fs, 'ytick', -0.01:0.005:0.01);
%cb=colorbar('ytick',-0.01:0.002:0.01);
%cbpos=get(cb,'Position');
cbpos = [0.01 0.2 0.025 0.6];
set(cb,'Position',cbpos);
set(gca,'xtick',[],'xcolor','w')
set(gca,'ytick',[],'ycolor','w')
set(gca,'ztick',[],'zcolor','w')
%set(gca,'Position',[0.1 0 0.9 1])
set(gca,'Position',[0 0 1 1])
view(3);
axhor = 0.01*floor((sample.rad*(1+samradmargin))/0.01);
axver = 0.01*floor((max(abs(sample.top),abs(sample.bot))*(1+samtopmargin))/0.01);
%axis([-axhor axhor -axhor axhor -axver axver])
%xlabel('X')
%ylabel('Y')
%zlabel('Z')
hold on
get(gca,'CameraPosition');
get(gca,'CameraViewAngle');
t = 1:360;
circx = cosd(t)*sample.rad;
circy = sind(t)*sample.rad;
circbotz(1:360) = sample.bot;
circtopz(1:360) = sample.top;
plot3(circx, circy, circbotz, 'k-', 'Linewidth', 1);
plot3(circx, circy, circtopz, 'k-', 'Linewidth', 1);
plot3([0 0],[0 0],[sample.bot sample.top],'k.-.','Linewidth',1);
plot3([-sample.rad -sample.rad],[0 0],[sample.bot sample.top],'k.-','Linewidth',1);
plot3([0 0],[-sample.rad -sample.rad],[sample.bot sample.top],'k.-','Linewidth',1);
plot3([sample.rad sample.rad],[0 0],[sample.bot sample.top],'k.-','Linewidth',1);
plot3([0 0],[sample.rad sample.rad],[sample.bot sample.top],'k.-','Linewidth',1);
% beam direction:
% plot3([-170 170],[0 0],[0 0],'r-','Linewidth',2)
vertices = [];
faces_sides = [];
faces_end = [];
hkl = [];
if ~strcmpi(type, 'hexagonal')
vertices = [0 0 0; 1 0 0; 1 1 0; 0 1 0; 0 0 1; 1 0 1; 1 1 1; 0 1 1] - ...
0.5*repmat([1 1 1],8,1);
% Cubed face directions
% +yz -yz -xz +xz +xy -xy
% +x -x -y +y +z -z
faces_sides = [2 3 7 6; 4 1 5 8; 1 2 6 5; 3 4 8 7];
faces_end = [5 6 7 8; 1 2 3 4];
hkl = [1 0 0; -1 0 0; 0 -1 0; 0 1 0; ...
0 0 1; 0 0 -1]';
else
a = parameters.cryst(phaseid).latticepar(1);
c = parameters.cryst(phaseid).latticepar(3);
maxx = max(a,c);
% normalize the biggest axis to 1
vertices = gtHexagonalUnitCell(a/maxx,c/maxx,false);
% hexagon face directions
% +yz -yz -xz +xz +xy -xy
% +x -x -y +y +z -z
faces_sides = [1 2 8 7; 4 5 11 10; 5 6 12 11; 2 3 9 8; 3 4 10 9; 6 1 7 12];
faces_end = [1 2 3 4 5 6; 7 8 9 10 11 12];
hkl = [1 0 -1 0; -1 0 -1 0; 0 -1 1 0; 0 1 -1 0; -1 1 0 0; 1 -1 0 0; ...
0 0 0 1; 0 0 0 -1]'; % column vectors
end
Bmat = gtCrystHKL2CartesianMatrix(parameters.cryst(phaseid).latticepar);
pl_cryst = gtCrystHKL2Cartesian(hkl, Bmat); % hkl plane normals in cryst reference
for ii = 1:nof_grains
if ismember(ii,hlight)
hl = true;
else
hl = false;
end
sfPlotGrainCell(grains{ii}, vertices, faces_sides, hl, strainscale, pixelsize);
sfPlotGrainCell(grains{ii}, vertices, faces_end, hl, strainscale, pixelsize);
if numbered
text(grains{ii}.center(1), -axhor,grains{ii}.center(3), num2str(ii), 'Color','c');
text(axhor, grains{ii}.center(2), grains{ii}.center(3), num2str(ii), 'Color','c');
end
end
axis equal
axis([-axhor axhor -axhor axhor -axver axver]);
end % of main function
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% SUB-FUNCTIONS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function sfPlotGrainCell(grain, vertices, faces, hl, strainscale, pixelsize)
ga = 0.5*pixelsize*(grain.stat.bbxsmean + grain.stat.bbysmean)/2;
if isfield(grain,'centre')
gc = grain.centre;
else
gc = grain.center;
end
g_grain = Rod2g(grain.R_vector);
grain_vertices = ga*vertices*g_grain';
grain_vertices_st = repmat(gc,size(vertices,1),1) + (eye(3)*grain_vertices')';
if isfield(grain,'strain') && ~any(isnan(grain.strain.ST(:)))
grain_vertices_st = grain_vertices_st + (grain.strain.ST*strainscale*grain_vertices')';
facecolor = grain.strain.ST(3,3);
else
facecolor = 0;
end
facecolor = repmat(facecolor,size(faces,1),1);
if hl
patch('Vertices', grain_vertices_st, 'Faces', faces , ...
'FaceVertexCData', facecolor, 'FaceColor', 'flat','EdgeColor','r','LineWidth',2);
else
patch('Vertices', grain_vertices_st, 'Faces', faces , ...
'FaceVertexCData', facecolor, 'FaceColor', 'flat');
end
end % of sfPlotGrainCell
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