Skip to content
Snippets Groups Projects
gtReadBoundaryProperties.m 6.3 KiB
Newer Older
function gtReadBoundaryProperties(phaseid, boundaries_structure, vol_out, r_vectors)
% gtReadBoundaryProperties(phaseid, boundaries_structure, vol_out, r_vectors)

disp('have changed this to axis convention matlab1 // instX , matlab2 // instY, matlab3 // instZ')
disp('AK, 11/8/2010')
pause(3)

Andrew King's avatar
Andrew King committed
%continue to add to boundaries_structure.mat - orientations,
%disorientation, r-vectors etc.
parameters=[];
load('parameters.mat');
spacegroup = parameters.cryst(phaseid).spacegroup;
Andrew King's avatar
Andrew King committed

%find the max grainID - ugly but ca va
Andrew King's avatar
Andrew King committed
maxgrain=0;
for i=1:length(boundaries_structure)
    maxgrain=max(maxgrain, boundaries_structure(i).grain1);
    maxgrain=max(maxgrain, boundaries_structure(i).grain2);
Andrew King's avatar
Andrew King committed
end

symm = gtCrystGetSymmetryOperators([], spacegroup);
symm = {symm.g3};
Andrew King's avatar
Andrew King committed

% loop through the boundaries
for ii=1:size(boundaries_structure, 2)
Andrew King's avatar
Andrew King committed

    if boundaries_structure(ii).count<4 %can still be useful to calc index planes where we have only one of the grains
        continue;
Andrew King's avatar
Andrew King committed
    else
        %Read in the r-vector data for the two grains
        grain1=boundaries_structure(ii).grain1;
        grain2=boundaries_structure(ii).grain2;

        if grain1==0
            g1=[];
            g1equiv=[];
            boundaries_structure(ii).grain1_R_vector=R1;
            g1 = gtMathsRod2RotMat(R1);
Andrew King's avatar
Andrew King committed
        end

        if grain2==0
            g2=[];
            boundaries_structure(ii).grain2_R_vector=R2;
            g2 = gtMathsRod2RotMat(R2);
Andrew King's avatar
Andrew King committed

        % calculate the misorientation angle and axis between these grains
        % TODO: replace by a MISORIENTATION function
        if ~isempty(g1) && ~isempty(g2)
            % If we have both grains
Yoann Guilhem's avatar
Yoann Guilhem committed
            % Need to search symmetry equivalents for the minimum misorientation
            rot_offset=[];
            % warning('g*symm maybe should be symm*g')
            for jj=1:length(symm)
                g1equiv = g1*symm(jj);
                rot_offset(jj) = acos((trace(netg)-1)/2);
Andrew King's avatar
Andrew King committed

            dummy = find(rot_offset ==min(rot_offset));
            g1equiv = g1*symm(dummy);
Andrew King's avatar
Andrew King committed

            misorientation_angle = acosd((trace(netg)-1)/2);
Andrew King's avatar
Andrew King committed

            [eigVec, eigVal]=eig(netg);
            for p=1:3
                if isreal(eigVec(:,p))  %find the real eigenvector - should be just one
                    misorientation_axis=eigVec(:,p);
                    boundaries_structure(ii).eigVal=eigVal(p,p);
            boundaries_structure(ii).misorientation_axis=misorientation_axis';
            boundaries_structure(ii).misorientation_angle=misorientation_angle;
            boundaries_structure(ii).misorientation_axis=[];
            boundaries_structure(ii).misorientation_angle=[];
            boundaries_structure(ii).eigVal=[];
        end

        %even if we have only one grain, can deal with the boundary plane
        [x,y,z]=ind2sub(size(test), find(test));
        [origin, a]=lsplane([x y z]);
        gb_normal=a;
        %gb_normal(3)=-gb_normal(3);
        boundaries_structure(ii).gb_norm = gb_normal';
        boundaries_structure(ii).gb_centre = origin';

        if ~isempty(g1equiv)
        elseif ~isempty(g1)
        else
            plane1=[];
        end

        if ~isempty(g2)
        else
            plane2=[];
        end

        if spacegroup==225 || spacegroup==229
            % if cubic then this is the index plane
            boundaries_structure(ii).gb_norm_grain1=plane1';
            boundaries_structure(ii).gb_norm_grain2=plane2';

        elseif spacegroup==167 || spacegroup==663 || spacegroup==194
            % if hexagonal, keep cartesian vector, but also
            % convert the cartesian plane normal to hexagonal four index notation
            % ditto for misorientation axis

            boundaries_structure(i).gb_norm_grain1=plane1';
            boundaries_structure(i).gb_norm_grain2=plane2';

            if ~isempty(plane1)
                hkl=plane1;
                hkil=[];
                hkil(1) = hkl(1) - (1/sqrt(3))*hkl(2);
                hkil(2) = (2/sqrt(3))*hkl(2);
                hkil(3) = -(hkil(1) + hkil(2));
                hkil(4) = hkl(3);
                % account for lattice vector lengths
                hkil(1:3) = hkil(1:3) / (2/(sqrt(3)*parameters.cryst.latticepar(1)));
                hkil(4)   = hkil(4) / (1/parameters.cryst.latticepar(3));
                boundaries_structure(ii).gb_norm_hex_grain1=hkil;
                boundaries_structure(ii).gb_norm_hex_grain1=[];
            end

            if ~isempty(plane2)
                hkl=plane2;

                hkil=[];
                hkil(1) = hkl(1) - (1/sqrt(3))*hkl(2);
                hkil(2) = (2/sqrt(3))*hkl(2);
                hkil(3) = -(hkil(1) + hkil(2));
                hkil(4) = hkl(3);
                % account for lattice vector lengths
                hkil(1:3) = hkil(1:3) / (2/(sqrt(3)*parameters.cryst.latticepar(1)));
                hkil(4)   = hkil(4) / (1/parameters.cryst.latticepar(3));
                boundaries_structure(ii).gb_norm_hex_grain2=hkil;
                boundaries_structure(ii).gb_norm_hex_grain2=[];
            if ~isempty(boundaries_structure(ii).misorientation_axis)
                hkl=boundaries_structure(ii).misorientation_axis';

                hkil=[];
                hkil(1) = hkl(1) - (1/sqrt(3))*hkl(2);
                hkil(2) = (2/sqrt(3))*hkl(2);
                hkil(3) = -(hkil(1) + hkil(2));
                hkil(4) = hkl(3);
                % account for lattice vector lengths
                hkil(1:3) = hkil(1:3) / (2/(sqrt(3)*parameters.cryst.latticepar(1)));
                hkil(4)   = hkil(4) / (1/parameters.cryst.latticepar(3));
                boundaries_structure(ii).misorientation_axis_hex=hkil;
        else
            disp('crystallography not supported!')
        end
    end % skip small boundaries
end

Andrew King's avatar
Andrew King committed
save('boundaries_structure.mat', 'boundaries_structure')

end % end of function