Skip to content
Snippets Groups Projects
gtReadBoundariesStructure.m 5.73 KiB
Newer Older
function [output, output2] = gtReadBoundariesStructure(boundaries_structure, vThr, DoSym)
Andrew King's avatar
Andrew King committed


%boundaries_structure is a .mat file used to store boundary data.
%it contains: boundaries_structure(i).
% grain1
% grain2
% count
% crack1_count
% crack2_count
% crack5_count
% gb_norm
% gb_norm_confidence
% gb_centre
% misorientation_angle
% misorientation_axis
% gb_norm_grain1
% gb_norm_grain2
% sigma
% grain1_R_vector
% grain2_R_vector

%therefore, can pull out the poles for a pole figure according to different
Yoann Guilhem's avatar
Yoann Guilhem committed
%criteria, as well as producing symmetry equivalent (for xtallographic
Andrew King's avatar
Andrew King committed
%things) if required.

% add - in a crude way - the stuff to read from the the
% boundaries_structure_test - the pole figure density for each boundary
% after dealing with curved boundaries.

%output is either poles or density - either way then used in gtMakePoleFigure
%output2 is valid poles weight, not used for poles case
%should be able to combine boundaries_structure and
%boundaries_structure_test.  Keep separate for the moment while testing.

poles=[];
Andrew King's avatar
Andrew King committed
count=1;
parameters=[];
load('parameters.mat');
Andrew King's avatar
Andrew King committed

symm = gtCrystGetSymmetryOperators([], spacegroup);
if size(hkl, 2) == 4
    symm = {symm.g};
elseif size(hkl, 2) == 3
    symm = {symm.g3};
Andrew King's avatar
Andrew King committed
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if 1 % if using boundaries_structure
    %loop through structure
    for i=1:length(boundaries_structure)
        
        if 1
            %for i=bridges
            %criteria
            if  boundaries_structure(i).grain1~=0 && boundaries_structure(i).grain2~=0 && ~isempty(boundaries_structure(i).gb_norm)
                
                
                %      if  boundaries_structure(i).grain1<500 && boundaries_structure(i).grain2<500 && boundaries_structure(i).count>200
                if  boundaries_structure(i).count>vThr %& boundaries_structure(i).count<4000
                    % if (boundaries_structure(i).gb_centre(1)<150 || boundaries_structure(i).gb_centre(1)>350) && (boundaries_structure(i).gb_centre(2)<150 || boundaries_structure(i).gb_centre(2)>350)
                    % if 1 %no test
                    %    if boundaries_structure(i).crack5_count>100
                    %  if isempty(boundaries_structure(i).sigma) || boundaries_structure(i).sigma~=3
                    %    if isempty(boundaries_structure(i).sigma)
                    %  if boundaries_structure(i).sigma==3
                    %    poles(end+1,:)=boundaries_structure(i).gb_norm;
                    %
                    if 1
                        poles(end+1,:)=boundaries_structure(i).gb_norm_grain1;
                        poles(end+1,:)=boundaries_structure(i).gb_norm_grain2;
                        weights(end+1)=boundaries_structure(i).count;
                        weights(end+1)=boundaries_structure(i).count;
                        
                    end   % criteria 2
                end%criteria
            end
        end
        
        if 0
            % alternative structure for specific grain poles
            for a=1:20
                if  boundaries_structure(i).grain1==a && boundaries_structure(i).grain2~=0
                    poles(end+1,:)=boundaries_structure(i).gb_norm_grain1;
                end
                if  boundaries_structure(i).grain2==a && boundaries_structure(i).grain1~=0
                    poles(end+1,:)=boundaries_structure(i).gb_norm_grain2;
                end
            end
        end
        
    end%loop
        % Apply the symmetry operators
        poles2 = [];
        for ii=1:length(symm)
            poles2 = [poles2; poles*symm(ii)];
        poles = poles2;
        weights = repmat(weights', length(symm), 1);
    %add this to correspond to line in gtMakePoleFigure
    poles=[poles; -poles];
    weights=[weights; weights];
    output=poles;
    output2=weights;
    
    save poles poles
    save weights weights
Andrew King's avatar
Andrew King committed
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Andrew King's avatar
Andrew King committed
    %find a non-empty density map to preallocate
    i=1;
    density=[];
    count=0;
    vpw=0;%valid poles_weight for normalising
    while isempty(density)
        density=zeros(size(boundaries_structure_test(i).grain1_pole_density));
        i=i+1;
    end
Andrew King's avatar
Andrew King committed
    %for i=1:length(boundaries_structure_test)
Andrew King's avatar
Andrew King committed
        %criteria
        %if  boundaries_structure(i).grain1~=0 && boundaries_structure(i).grain2~=0 && ~isempty(boundaries_structure(i).gb_norm)
        
Andrew King's avatar
Andrew King committed
        if 1 %no test
            %    if boundaries_structure(i).crack5_count>100
            %        if isempty(boundaries_structure(i).sigma) || boundaries_structure(i).sigma~=3
            %if (isempty(boundaries_structure(i).sigma) || boundaries_structure(i).sigma~=3) && boundaries_structure(i).grain1~=0 && boundaries_structure(i).grain2~=0
            %  if isempty(boundaries_structure(i).sigma)
            %  if boundaries_structure(i).sigma==3
            %     if boundaries_structure(i).sigma==9
            %  if boundaries_structure(i).misorientation_angle>15
            %
Andrew King's avatar
Andrew King committed
            if ~isempty(boundaries_structure_test(i).grain1_pole_density)
                density=density+boundaries_structure_test(i).grain1_pole_density;
                vpw=vpw+boundaries_structure_test(i).grain1_valid_poles_weight;
Andrew King's avatar
Andrew King committed
            end
            if ~isempty(boundaries_structure_test(i).grain2_pole_density)
                density=density+boundaries_structure_test(i).grain2_pole_density;
                vpw=vpw+boundaries_structure_test(i).grain2_valid_poles_weight;
Andrew King's avatar
Andrew King committed
            end
Andrew King's avatar
Andrew King committed
        end%criteria
    end%loop
    output=density;
    output2=vpw;
    count
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%