From 9a084e74db6c3a33913084ca7b867840a8f8fd9a Mon Sep 17 00:00:00 2001
From: Nicola Vigano <nicola.vigano@esrf.fr>
Date: Wed, 5 Sep 2018 11:35:56 +0200
Subject: [PATCH] Diffractometer: adding sample translations on top of the
 sample tilts

Signed-off-by: Nicola Vigano <nicola.vigano@esrf.fr>
---
 zUtil_Geo/gtGeoDiffractometerTensor.m | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/zUtil_Geo/gtGeoDiffractometerTensor.m b/zUtil_Geo/gtGeoDiffractometerTensor.m
index 729dfc46..68d40514 100644
--- a/zUtil_Geo/gtGeoDiffractometerTensor.m
+++ b/zUtil_Geo/gtGeoDiffractometerTensor.m
@@ -2,7 +2,8 @@ function [t, t_sam, t_rot, t_base] = gtGeoDiffractometerTensor(diff, type, freev
     conf = struct( ...
         'angles_basetilt', 0, ...
         'angles_rotation', 0, ...
-        'angles_sam_tilt', zeros(0, 1) );
+        'angles_sam_tilt', zeros(0, 1), ...
+        'shifts_sam_stage', zeros(0, 3) );
     conf = parse_pv_pairs(conf, varargin);
 
     num_rotations = numel(conf.angles_rotation);
@@ -15,13 +16,18 @@ function [t, t_sam, t_rot, t_base] = gtGeoDiffractometerTensor(diff, type, freev
     % Whether we do a SAM->LAB or a LAB->SAM tensor
     is_sam2lab = strcmpi(type, 'sam2lab');
 
+    t_shift = eye(4);
+    if (is_sam2lab && ~isempty(conf.shifts_sam_stage))
+        t_shift(:, 4) = [conf.shifts_sam_stage'; 1];
+    end
+
     % Building sample tilt components
     if (iscell(conf.angles_sam_tilt))
         error('gtGeoDiffractometerTensor:not_implemented', 'multiple_sample tilts not implemented yet')
     elseif (isempty(conf.angles_sam_tilt) || isempty(diff.axes_sam_tilt))
-        t_sam = eye(4);
+        t_sam = t_shift;
     else
-        t_sam = eye(4);
+        t_sam = t_shift;
         if (is_sam2lab)
             axes_order = size(diff.axes_sam_tilt, 1):-1:1;
         else
@@ -36,6 +42,11 @@ function [t, t_sam, t_rot, t_base] = gtGeoDiffractometerTensor(diff, type, freev
         end
     end
 
+    if (~is_sam2lab && ~isempty(conf.shifts_sam_stage))
+        t_shift(:, 4) = [-conf.shifts_sam_stage'; 1];
+        t_sam = t_shift * t_sam;
+    end
+
     % Building rotation components
     if (isempty(conf.angles_rotation))
         t_rot = eye(4);
-- 
GitLab