diff --git a/zUtil_Indexter/gtINDEXMatchGrains.m b/zUtil_Indexter/gtINDEXMatchGrains.m index 3f5704d39bf150f6a4c5ce3015fc0ad64ca11a44..8c7217744f3bc60e6907bef146eb983e6fce855f 100644 --- a/zUtil_Indexter/gtINDEXMatchGrains.m +++ b/zUtil_Indexter/gtINDEXMatchGrains.m @@ -1,11 +1,10 @@ -function [match, dev, dcm, drotm, conflicts] = gtINDEXMatchGrains(grain1, grain2, ... - ph1, dc, drot, tol) - -% GTINDEXMATCHGRAINS Matches multiple indexed grains between two datasets; -% can also be used to find unmerged grains. +function [match, dev, dcm, drotm, conflicts, toBeChecked] = gtINDEXMatchGrains(... + grain1, grain2, ph1, dc, drot, tol) +% GTINDEXMATCHGRAINS Matches multiple indexed grains between two datasets; +% can also be used to find unmerged grains. % -% [match, dev, dcm, drotm, conflicts] = gtINDEXMatchGrains(grain1, grain2, ... -% ph1, dc, drot, tol) +% [match, dev, dcm, drotm, conflicts, toBeChecked] = gtINDEXMatchGrains(grain1, grain2, ph1, dc, drot, tol) +% -------------------------------------------------------------------------------------------------------- % % For each grain in the reference set 'grain1' it tries to find the % corresponding grain in the set 'grain2'. It uses tolerances in 'tol' @@ -47,19 +46,19 @@ function [match, dev, dcm, drotm, conflicts] = gtINDEXMatchGrains(grain1, grain2 % operators. % % -% OPTIONAL INPUT -% grain1 - indexed grain data of reference set as output from Indexter +% OPTIONAL INPUT: +% grain1 = indexed grain data of reference set as output from Indexter % {if undefined, it is loaded for the current dataset} -% grain2 - indexed grain data to be matched as output from Indexter +% grain2 = indexed grain data to be matched as output from Indexter % {if undefined, it is same as grain1} -% ph1 - phase ID in grain1 {default is 1} -% dc - global translation between datasets from a position given in +% ph1 = phase ID in grain1 {default is 1} +% dc = global translation between datasets from a position given in % grain2 to the same in grain1 {default is [0 0 0]} -% drot - global rotation around the origin of grain2; the rotation +% drot = global rotation around the origin of grain2; the rotation % matrix that transforms a position vector given in grain2 % into grain1 (size 3x3 for column vectors); {default is the % identity matrix}: p1 = drot*p2 + dc; -% tol - tolerances for finding matching grains and their default values +% tol = tolerances for finding matching grains and their default values % tol.distf = 0.5 - distance between center of mass; % mult. factor of smaller bounding box size % toldist = tol.distf * min(bbxs,bbys) @@ -69,15 +68,17 @@ function [match, dev, dcm, drotm, conflicts] = gtINDEXMatchGrains(grain1, grain2 % tol.int = 1e10 - max. intensity ratio % % -% OUTPUT -% match - array of indices of matching grains [grain_ind1 grain_ind2] -% dev - vectors of deviations of grain properties -% dcm - updated guess for dc -% drotm - updated guess for drot -% conflicts - list of conflicts found (same as printed on command line); -% conflicts{:,1}: grains from set1 for which more than one -% possible matches were found -% conflicts{:,2}: corresponding possible matches from set2 +% OUTPUT: +% match = array of indices of matching grains [grain_ind1 grain_ind2] +% dev = vectors of deviations of grain properties +% dcm = updated guess for dc +% drotm = updated guess for drot +% conflicts = list of conflicts found (same as printed on command line); +% conflicts{:,1}: grains from set1 for which more than one +% possible matches were found +% conflicts{:,2}: corresponding possible matches from set2 +% toBeChecked = conflicts list formatted to be saved as +% parameters.input.forcemerge % % USAGE EXAMPLE % Revise tolerances; then run: @@ -108,7 +109,7 @@ function [match, dev, dcm, drotm, conflicts] = gtINDEXMatchGrains(grain1, grain2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% Initialize +% Initialize %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -153,7 +154,7 @@ nof_grains2 = length(grain2); %%%%%%%%%%%%%%%%%%%%%%%%%%% -%% Prepare grain data +% Prepare grain data %%%%%%%%%%%%%%%%%%%%%%%%%%% % Sort grains by Z position and only keep one third at the center @@ -224,7 +225,7 @@ dev.rot = NaN(3,3,nof_grains1); %%%%%%%%%%%%%%%%%%%%%%%%%%% -%% Reference planes +% Reference planes %%%%%%%%%%%%%%%%%%%%%%%%%%% % Extension to Rodrigues fundamental zone @@ -279,7 +280,7 @@ end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% Grain2 grain centers +% Grain2 grain centers %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% if isempty(drot) @@ -293,7 +294,7 @@ gr2.center = gr2.center*rotmat' + dc(ones(nof_grains2,1),:); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% Grain2 Rodrigues coordinates +% Grain2 Rodrigues coordinates %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Calculate new Rodrigues lines and vectors inside the fundamental zone % for the new, rotated positions @@ -363,7 +364,7 @@ end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% Grain1 Rodrigues coordinates +% Grain1 Rodrigues coordinates %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Calculate Rodrigues lines inside the fundamental zone @@ -401,7 +402,7 @@ end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% Match grains +% Match grains %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% disp('Matching grains ...') @@ -460,6 +461,7 @@ end if isempty(conflicts) fprintf('\nNo conflicts have been found with the actual tolerances.\n') + toBeChecked = []; else if (length([conflicts{:,2}]) == length(unique([conflicts{:,2}]))) fprintf('Match conflict list is unique.\n') @@ -467,12 +469,21 @@ else fprintf('Match conflict list is NOT unique.\n') fprintf(' Some grain(s) in set2 may be assigned to more than one in set1.\n') end + tmp = cell2mat(conflicts); + pippo_cc = cell(0,2); + for ii=1:size(tmp,1) + tmp2 = tmp(ii,:); + tmp2 = unique(tmp2); + pippo_cc{ii} = tmp2; + end + tmp = cell2mat(pippo_cc'); + toBeChecked = unique(tmp, 'rows'); end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% Evalute grain match +% Evalute grain match %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% dev.xyz = NaN(nof_grains1,3); @@ -557,8 +568,9 @@ fprintf('Number of matching grains found:\n %d \n\n',sum(~isnan(match(:,2)))) end % of main function +%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% SUB-FUNCTIONS +% SUB-FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function tomatch = sfCheckMatching(act, cand, tol, fzone_acc, fzone_ext, pixsize)