From e920d9fce954781bf1d86e8131581f779fa1fadb Mon Sep 17 00:00:00 2001
From: preischig <preischig@gmail.com>
Date: Tue, 13 Jan 2015 14:13:12 +0100
Subject: [PATCH] gtGeoLabDefaultParameters: added detrefpos Y,Z computation
 here, instead of being at the spot matching stage; changed order of code.

Signed-off-by: preischig <preischig@gmail.com>
---
 zUtil_Geo/gtGeoLabDefaultParameters.m | 69 +++++++++++++++++----------
 1 file changed, 45 insertions(+), 24 deletions(-)

diff --git a/zUtil_Geo/gtGeoLabDefaultParameters.m b/zUtil_Geo/gtGeoLabDefaultParameters.m
index cba0c45b..8424749b 100644
--- a/zUtil_Geo/gtGeoLabDefaultParameters.m
+++ b/zUtil_Geo/gtGeoLabDefaultParameters.m
@@ -9,6 +9,29 @@ function par_labgeo = gtGeoLabDefaultParameters(acq)
 
 par_labgeo = [];
 
+% Pixel and detector size
+par_labgeo.pixelsizeu = acq.pixelsize;
+par_labgeo.pixelsizev = acq.pixelsize;
+par_labgeo.detsizeu   = acq.xdet; % number of pixels along the u direction
+par_labgeo.detsizev   = acq.ydet; % number of pixels along the v direction
+
+% Beam direction, rot. axis position and detector properties
+par_labgeo.beamdir = [1 0 0];
+par_labgeo.rotpos  = [0 0 0];
+par_labgeo.detrefu = (par_labgeo.detsizeu/2) + 0.5;
+par_labgeo.detrefv = (par_labgeo.detsizev/2) + 0.5;
+
+% Coordinate axes definition and Lab unit (for records only)
+par_labgeo.deflabX = 'Along the beam direction.';
+par_labgeo.deflabY = 'Right-handed from Y=cross(Z,X).';
+par_labgeo.deflabZ = 'Along rotation axis. Positive away from sample stage.';
+par_labgeo.labunit = 'mm';
+
+% Detector angular coverage limits (2theta) for entire sample volume
+par_labgeo.detanglemin = 0;
+par_labgeo.detanglemax = 45;
+
+% Rotation axis direction
 switch (acq.rotation_name)
     case 'pmo'
         par_labgeo.rotdir = [0 0 -1];
@@ -48,6 +71,7 @@ if (acq.no_direct_beam && strcmp(acq.detector_definition, 'vertical'))
     par_labgeo.samenvtop = [];
     par_labgeo.samenvbot = [];
     par_labgeo.samenvrad = [];
+	
 elseif (~acq.no_direct_beam)
     % inline detector HR camera - suppose it on x-axis
     disp('High resolution direct beam scan...')
@@ -64,11 +88,13 @@ elseif (~acq.no_direct_beam)
     % exists, otherwise in gtPreprocessing
     if (isfield(acq, 'bb') && ~isempty(acq.bb))
         par_labgeo = gtGeoSamEnvFromAcq(par_labgeo, acq);
+		par_labgeo.detrefpos(2:3) = sfDetrefpos(acq.bb, par_labgeo);
     else
         par_labgeo.samenvtop = [];
         par_labgeo.samenvbot = [];
         par_labgeo.samenvrad = [];
-    end
+	end
+	
 elseif (acq.no_direct_beam && strcmp(acq.detector_definition, 'inline'))
     % inline detector - suppose it on x-axis
     % taper scan (far field)
@@ -83,36 +109,31 @@ elseif (acq.no_direct_beam && strcmp(acq.detector_definition, 'inline'))
         % guess a sample bounding box
         acq.bb = [acq.xdet/2-50 acq.ydet/2-50 100 100];
     end
+    if (isfield(acq,'bb') && ~isempty(acq.bb))
+        par_labgeo.detrefpos(2:3) = sfDetrefpos(acq.bb, par_labgeo);
+    end
     par_labgeo = gtGeoSamEnvFromAcq(par_labgeo, acq);
     disp('Choose a squared sample bounding box in the center of the image...')
 end
 
-par_labgeo.pixelsizeu = acq.pixelsize;
-par_labgeo.pixelsizev = acq.pixelsize;
-par_labgeo.detsizeu   = acq.xdet; % number of pixels along the u direction
-par_labgeo.detsizev   = acq.ydet; % number of pixels along the v direction
 
-% Beam direction, rot. axis position and detector properties
-par_labgeo.beamdir = [1 0 0];
-par_labgeo.rotpos  = [0 0 0];
-par_labgeo.detrefu = (par_labgeo.detsizeu/2) + 0.5;
-par_labgeo.detrefv = (par_labgeo.detsizev/2) + 0.5;
+end % end of function
 
-% Coordinate axes definition and Lab unit (for records only)
-par_labgeo.deflabX = 'Along the beam direction.';
-par_labgeo.deflabY = 'Right-handed from Y=cross(Z,X).';
-par_labgeo.deflabZ = 'Along rotation axis. Positive away from sample stage.';
-par_labgeo.labunit = 'mm';
 
-% Correct for sample bounding box position - 07-01-2014 by LNervo
-if ~isempty(acq.bb)
-    par_labgeo.detrefpos(3) = ((acq.bb(2) + acq.bb(4)/2) - par_labgeo.detsizev/2) * par_labgeo.pixelsizev;
-    par_labgeo.detrefpos(2) = -((acq.bb(1) + acq.bb(3)/2) - par_labgeo.detsizeu/2) * par_labgeo.pixelsizeu;
-end
+%%%%%%%%%%%%%%%%%%%%%
+% SUB-FUNCTIONS
+%%%%%%%%%%%%%%%%%%%%%
 
-% Detector angular coverage limits (2theta) for entire sample volume
-par_labgeo.detanglemin = 0;
-par_labgeo.detanglemax = 45;
+function [dy, dz] = sfDetrefpos(acq_bb, par_labgeo)
+% Returns the detector lateral (Y) and vertical (Z) positions which approximately
+% account for an offset of the sample bounding box position:
+%   Y lateral: It assumes that the projection of the rotation axis is at the
+%   center of the sample bounding box.
+%   Z vertical: set in a way that the vertical center of the sample bounding
+%   box will have coordinate Z=0.
+% It assumes rotpos = [0 0 0] and view into the beam.
 
+dy = -((acq_bb(1) + acq_bb(3)/2) - par_labgeo.detrefu) * par_labgeo.pixelsizeu;
+dz =  ((acq_bb(2) + acq_bb(4)/2) - par_labgeo.detrefv) * par_labgeo.pixelsizev;
 
-end % end of function
+end
\ No newline at end of file
-- 
GitLab