From e19425fe7a403c66ef97a030a2f7a023bedbbe10 Mon Sep 17 00:00:00 2001
From: Nicola Vigano <nicola.vigano@esrf.fr>
Date: Fri, 22 May 2015 15:48:41 +0200
Subject: [PATCH] Read CTF files from Channel 5

Signed-off-by: Nicola Vigano <nicola.vigano@esrf.fr>
---
 zUtil_Deformation/gtReadEBSDMapEulerCTFFile.m | 86 +++++++++++++++++++
 1 file changed, 86 insertions(+)
 create mode 100644 zUtil_Deformation/gtReadEBSDMapEulerCTFFile.m

diff --git a/zUtil_Deformation/gtReadEBSDMapEulerCTFFile.m b/zUtil_Deformation/gtReadEBSDMapEulerCTFFile.m
new file mode 100644
index 00000000..af30d14c
--- /dev/null
+++ b/zUtil_Deformation/gtReadEBSDMapEulerCTFFile.m
@@ -0,0 +1,86 @@
+function [EBSD_e_map, EBSD_r_map, mask] = gtReadEBSDMapEulerCTFFile(filename, axes_perm, permute_maps)
+% function [EBSD_e_map, EBSD_r_map] = gtReadEBSDMapEulerCSVFile(filename, axes_perm, permute_maps)
+%   Axes permutation allows to easily deal with different reference
+%   systems, like for instance:
+%       DCT Axes <-> EBSD Axes ([x y z] <-> [x'y'z'])
+%           x     =     -y'
+%           y     =      z'
+%           z     =     -x'
+%   Translates to: axes_perm = [-2 3 -1]
+%
+%   NOTE: Only the Rodrigues vector map has the axes changed!
+%
+
+    if (~exist('axes_perm', 'var'))
+        axes_perm = 1:3;
+    end
+
+    if (~exist('permute_maps', 'var'))
+        permute_maps = true;
+    end
+
+    c = tic();
+    fprintf('Reading from file: "%s"..', filename);
+
+    fid = fopen(filename);
+    fgetl(fid);
+    fgetl(fid);
+    fgetl(fid);
+    fgetl(fid);
+    dims = fscanf(fid, 'XCells\t%d\nYCells\t%d\nXStep\t%f\nYStep\t%f\n');
+    fscanf(fid, 'AcqE1\t%d\nAcqE2\t%d\nAcqE3\t%d\n'); % Unknown parameters
+    fgetl(fid);
+    fgetl(fid);
+    fgetl(fid);
+    fgetl(fid);
+    input = fscanf(fid, '%d\t%f\t%f\t%d\t%d\t%f\t%f\t%f\t%f\t%d\t%d');
+    fclose(fid);
+
+    fprintf('\b\b, Done in %f seconds.\n', toc(c));
+    c = tic();
+    fprintf('Converting to Euler and Rodriguez maps..');
+
+    input = reshape(input, 11, [])';
+
+%     scales = dims(3:4);
+%
+%     xx = (input(:, 2) ./ scales(1)) + 1;
+%     yy = (input(:, 3) ./ scales(2)) + 1;
+
+    ea1 = input(:, 6);
+    ea2 = input(:, 7);
+    ea3 = input(:, 8);
+
+    sizes = dims(1:2)';
+    EBSD_e_map = cat(3, reshape(ea1, sizes), reshape(ea2, sizes), reshape(ea3, sizes));
+%     EBSD_e_map = zeros([sizes 3], 'single');
+%     ii = sub2ind([sizes, 3], yy, xx, 1 * ones(size(xx)));
+%     EBSD_e_map(ii) = ea1;
+%     ii = sub2ind([sizes, 3], yy, xx, 2 * ones(size(xx)));
+%     EBSD_e_map(ii) = ea2;
+%     ii = sub2ind([sizes, 3], yy, xx, 3 * ones(size(xx)));
+%     EBSD_e_map(ii) = ea3;
+
+%     EBSD_e_map = EBSD_e_map * 180 / pi;
+
+    dmvol_EBSD_e_map = permute(EBSD_e_map, [1 2 4 3]);
+    [gvdm_EBSD_e_map, size_dmvol_EBSD_map] = gtDefDmvol2Gvdm(dmvol_EBSD_e_map);
+    gvdm_EBSD_r_map = gtMathsEuler2Rod(gvdm_EBSD_e_map);
+    dmvol_EBSD_r_map = gtDefGvdm2Dmvol(gvdm_EBSD_r_map, size_dmvol_EBSD_map);
+    EBSD_r_map = reshape(dmvol_EBSD_r_map, [sizes 3]);
+
+    EBSD_r_map = EBSD_r_map(:, :, abs(axes_perm));
+    negative = axes_perm < 0;
+    EBSD_r_map(:, :, negative) = - EBSD_r_map(:, :, negative);
+
+    mask = input(:, 1);
+    mask = reshape(mask, sizes);
+
+    if (permute_maps)
+        EBSD_e_map = permute(EBSD_e_map, [2 1 3]);
+        EBSD_r_map = permute(EBSD_r_map, [2 1 3]);
+        mask = mask';
+    end
+
+    fprintf('\b\b, Done in %f seconds.\n', toc(c));
+end
-- 
GitLab