From a26210243cf3d1b3929c6c15a95406980bcf4aa8 Mon Sep 17 00:00:00 2001 From: Peter Reischig <peter.reischig@esrf.fr> Date: Wed, 14 Mar 2012 11:04:54 +0000 Subject: [PATCH] Small changes and bug fixes in matching GUI. Changes in the help but not in the code for gtFedRotationMatrixComp.m and gtMathsRotationMatrixComp.m . git-svn-id: https://svn.code.sf.net/p/dct/code/trunk@265 4c865b51-4357-4376-afb4-474e03ccb993 --- .../gtMatchCalculateProjectionPath.m | 2 +- 3_pairmatchingGUI/gtMatchFilterPairs.m | 10 +-- 3_pairmatchingGUI/gtMatchFindPairCandidates.m | 1 + 3_pairmatchingGUI/gtMatchGUIMain.m | 58 ++-------------- 3_pairmatchingGUI/gtMatchInitialize.m | 2 +- .../gtMatchInitializeGUIPairFigure.m | 52 +++++++++----- 3_pairmatchingGUI/gtMatchLoadDifspotData.m | 27 ++++++-- 3_pairmatchingGUI/gtMatchRankCandidates.m | 3 + 3_pairmatchingGUI/gtMatchRotAxisProjection.m | 4 +- 3_pairmatchingGUI/gtMatchSplitSpotData.m | 3 +- 3_pairmatchingGUI/gtMatchUpdateThetaFilter.m | 69 +++++++++++++++++++ 7_fed/geometry/gtFedRotationMatrixComp.m | 29 +++++--- zUtil_Maths/gtMathsRotationMatrixComp.m | 12 ++-- 13 files changed, 172 insertions(+), 100 deletions(-) create mode 100644 3_pairmatchingGUI/gtMatchUpdateThetaFilter.m diff --git a/3_pairmatchingGUI/gtMatchCalculateProjectionPath.m b/3_pairmatchingGUI/gtMatchCalculateProjectionPath.m index 4f348196..cf544d25 100644 --- a/3_pairmatchingGUI/gtMatchCalculateProjectionPath.m +++ b/3_pairmatchingGUI/gtMatchCalculateProjectionPath.m @@ -27,7 +27,7 @@ refreshdata(handles.Fullim_CentA,'caller'); % Points out of plane -projAmirrZ = (labAmirr-labgeo.detrefpos)*labgeo.detnorm'/labgeo.pixelsizeu; +projAmirrZ = (labAmirr-labgeo.detrefpos)*(-labgeo.detnorm')/labgeo.pixelsizeu; % Points along projection A-A'-B in 3D if ~isempty(handles.Fullim_ProjLine3D) diff --git a/3_pairmatchingGUI/gtMatchFilterPairs.m b/3_pairmatchingGUI/gtMatchFilterPairs.m index c6f59973..bb3f73d2 100644 --- a/3_pairmatchingGUI/gtMatchFilterPairs.m +++ b/3_pairmatchingGUI/gtMatchFilterPairs.m @@ -11,16 +11,18 @@ end set(handles.Text_Progress,'String','Updating...') gtMatchSetBusy(handles,'on'); -filtind = handles.pairs.error <= handles.ErrorFilter; +% Indices with an error smaller than the error filter +handles.pairs.filterr = handles.pairs.error <= handles.ErrorFilter; + +% Combine the theta and error filters +handles.pairs.filtind = (handles.pairs.filterr & handles.pairs.filttheta); -handles.pairs.filtind = filtind; % Copy all fields from pairs to pairsfilt fn = fieldnames(handles.pairs); for ii = 1:length(fn) - handles.pairsfilt.(fn{ii}) = handles.pairs.(fn{ii})(filtind,:); + handles.pairsfilt.(fn{ii}) = handles.pairs.(fn{ii})(handles.pairs.filtind,:); end -handles.pairsfilt = rmfield(handles.pairsfilt,'filtind'); % Update Eta-Theta figure in other GUI diff --git a/3_pairmatchingGUI/gtMatchFindPairCandidates.m b/3_pairmatchingGUI/gtMatchFindPairCandidates.m index d79c4863..da59f245 100644 --- a/3_pairmatchingGUI/gtMatchFindPairCandidates.m +++ b/3_pairmatchingGUI/gtMatchFindPairCandidates.m @@ -283,6 +283,7 @@ gtMatchUpdateStatistics(handles); % Display result, no. of pairs pairstext = get(handles.Text_PairsResults,'String'); +pairstext{1} = num2str(iw); pairstext{2} = num2str(length(handles.pairs.indA)); set(handles.Text_PairsResults,'String',pairstext); diff --git a/3_pairmatchingGUI/gtMatchGUIMain.m b/3_pairmatchingGUI/gtMatchGUIMain.m index 154461f1..71f529b0 100644 --- a/3_pairmatchingGUI/gtMatchGUIMain.m +++ b/3_pairmatchingGUI/gtMatchGUIMain.m @@ -253,7 +253,7 @@ histtheta = NaN; refreshdata(handles.GUIEtaTheta.HistHandle,'caller') % Reset results display -pairtext{1} = ''; +pairtext{1} = '0000'; pairtext{2} = '0000'; pairtext{3} = '0000'; set(handles.Text_PairsResults,'String',pairtext); @@ -399,21 +399,7 @@ function ThetaLims_Push_Add_Callback(hObject, eventdata, handles) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) -% Check input -if handles.ThetaLimLastLow >= handles.ThetaLimLastHigh - return -end - -% Add new values to array -handles.ThetaLimits(end+1,1:2) = [handles.ThetaLimLastLow, handles.ThetaLimLastHigh]; - -% Change string in list box -set(handles.ThetaLims_Listbox,'String',num2str(handles.ThetaLimits)); - -% Update theta limits in figure -handles = gtMatchUpdateThetaFilterDisplay(handles); - -guidata(hObject,handles); +gtMatchUpdateThetaFilter(handles,'add'); @@ -423,28 +409,7 @@ function ThetaLims_Push_Delete_Callback(hObject, eventdata, handles) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) -if isempty(handles.ThetaLimits) - return -end - -% Current index in list -ind = get(handles.ThetaLims_Listbox,'Value'); - -% Delete currently selected limits -handles.ThetaLimits(ind,:) = []; -set(handles.ThetaLims_Listbox,'Value',1); - -% Set string -if isempty(handles.ThetaLimits) - set(handles.ThetaLims_Listbox,'String','!! None !!'); -else - set(handles.ThetaLims_Listbox,'String',num2str(handles.ThetaLimits)); -end - -% Update theta limits in figure -handles = gtMatchUpdateThetaFilterDisplay(handles); - -guidata(hObject,handles); +gtMatchUpdateThetaFilter(handles,'delete'); @@ -454,22 +419,7 @@ function ThetaLims_Push_Change_Callback(hObject, eventdata, handles) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) -% Check input -if handles.ThetaLimLastLow >= handles.ThetaLimLastHigh - return -end - -% Change values in array -ind = get(handles.ThetaLims_Listbox,'Value'); % current index in list -handles.ThetaLimits(ind,1:2) = [handles.ThetaLimLastLow, handles.ThetaLimLastHigh]; - -% Change string in list box -set(handles.ThetaLims_Listbox,'String',num2str(handles.ThetaLimits)); - -% Update theta limits in figure -handles = gtMatchUpdateThetaFilterDisplay(handles); - -guidata(hObject,handles); +gtMatchUpdateThetaFilter(handles,'change'); diff --git a/3_pairmatchingGUI/gtMatchInitialize.m b/3_pairmatchingGUI/gtMatchInitialize.m index 9897113b..b5f0fbce 100644 --- a/3_pairmatchingGUI/gtMatchInitialize.m +++ b/3_pairmatchingGUI/gtMatchInitialize.m @@ -390,7 +390,7 @@ spottext{3} = handles.nof_spotsB; set(handles.Text_SpotsResults,'String',spottext); % Pair results -pairtext{1} = ''; +pairtext{1} = '0000'; pairtext{2} = '0000'; pairtext{3} = '0000'; set(handles.Text_PairsResults,'String',pairtext); diff --git a/3_pairmatchingGUI/gtMatchInitializeGUIPairFigure.m b/3_pairmatchingGUI/gtMatchInitializeGUIPairFigure.m index caeb7200..cee83545 100644 --- a/3_pairmatchingGUI/gtMatchInitializeGUIPairFigure.m +++ b/3_pairmatchingGUI/gtMatchInitializeGUIPairFigure.m @@ -185,8 +185,9 @@ set(handles.Radio_RotAxis,'Value',get(handles.Radio_RotAxis,'Max')); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Get transformation matrix lab2det -[~,labgeo.lab2det] = gtGeoLab2Det([0 0 0 ],labgeo,1); - +%[~,labgeo.lab2det] = gtGeoLab2Det([0 0 0],labgeo,1); +[origxyz,labgeo.lab2det] = gtGeoLab2Det([0 0 0],labgeo,0); + % Scaling for quivers scale = 0.5; @@ -198,14 +199,21 @@ if mainhandles.plot3D handles.rotaxisendsz,'LineStyle','-.','Color',[1 1 0],... 'Parent',handles.Axes_Full,'LineWidth',2); - % Use transformation matrix; add some Z coordinate - transmat = [labgeo.lab2det, labgeo.detnorm'/labgeo.pixelsizeu]; - - % Origin of plotted vectors - origuvz = [1 1 0]; + % Use lab2det transformation matrix to get U,V coordinates. To display + % everything relative to the image coordinate system, addition of a Z + % coordinate is needed. In order to keep this new reference right-handed, + % the Z coordinate direction is defined negative from detnorm + % and the scaling is chosen reasonably as: + transmat = [labgeo.lab2det, -labgeo.detnorm'/labgeo.pixelsizeu]; % Not that if linux (X client) font settings are not correct, some % fonts may not show up and plotting may get extremely slow. + + + % Detector orientation + + % Origin of plotted vectors + origuvz = [1 1 0]; dirvec = labgeo.detdiru*transmat; handles.Fullim_BaseVectors(1) = quiver3(origuvz(1),origuvz(2),origuvz(3),... @@ -224,9 +232,14 @@ if mainhandles.plot3D 'VerticalAlignment','Top'); - % Origin of plotted vectors - origuvz = [labgeo.detsizeu, labgeo.detsizev]/2; - origuvz(3) = labgeo.detsizeu/2; + % Origin of plotted vectors for rotdir, beamdir, Lab axes + origuvz([1 2]) = origxyz([1 2]); + origuvz(3)= ([0 0 0] - labgeo.detrefpos)*(-labgeo.detnorm')/labgeo.pixelsizeu; + + % Lab origin + handles.Fullim_BaseVectors(15) = plot3(origuvz(1),origuvz(2),origuvz(3), ... + 'mo','LineWidth',2,'Parent',handles.Axes_Full); + % Rotdir dirvec = labgeo.rotdir*transmat; @@ -247,7 +260,7 @@ if mainhandles.plot3D 'String','Beamdir','Color','r','FontSize',14,'Parent',handles.Axes_Full,... 'VerticalAlignment','Top','HorizontalAlignment','Right'); - + % Lab axes dirvec = [1 0 0]*transmat; handles.Fullim_BaseVectors(9) = quiver3(origuvz(1),origuvz(2),origuvz(3),... @@ -281,13 +294,12 @@ else % Use transformation matrix transmat = labgeo.lab2det; - + + % Detector orientation + % Origin of plotted vectors origuv = [1 1]; - % It looks like that font size 12 doesn't show up - % (problem may be related to linux settings) - dirvec = labgeo.detdiru*transmat; handles.Fullim_BaseVectors(1) = quiver(origuv(1),origuv(2),... dirvec(1),dirvec(2),... @@ -304,9 +316,13 @@ else 'String','Detdirv','Color','w','FontSize',14,'Parent',handles.Axes_Full,... 'VerticalAlignment','Top','HorizontalAlignment','Left'); - % Origin of plotted vectors - origuv = [labgeo.detsizeu, labgeo.detsizev]/2; - + % Origin of plotted vectors for rotdir, beamdir, Lab axes + origuv = origxyz([1 2]); + + % Lab origin + handles.Fullim_BaseVectors(15) = plot3(origuv(1),origuv(2), ... + 'mo','LineWidth',2,'Parent',handles.Axes_Full); + % Rotdir dirvec = labgeo.rotdir*transmat; handles.Fullim_BaseVectors(5) = quiver(origuv(1),origuv(2),... diff --git a/3_pairmatchingGUI/gtMatchLoadDifspotData.m b/3_pairmatchingGUI/gtMatchLoadDifspotData.m index 4ef17d33..38bf8349 100644 --- a/3_pairmatchingGUI/gtMatchLoadDifspotData.m +++ b/3_pairmatchingGUI/gtMatchLoadDifspotData.m @@ -63,6 +63,10 @@ allsp.pairid = NaN(length(allsp.ind),1); % Initial no. of pairs handles.nof_pairs_ini = mym(sprintf('SELECT count(*) FROM %s',handles.pairtable)); +disp('Number of Friedel pairs already present in database:') +disp(handles.nof_pairs_ini) + + % Display status if handles.nof_pairs_ini > 0 set(handles.Text_PairtableEmpty,'String','NOT EMPTY!') @@ -111,8 +115,19 @@ if handles.nof_pairs_ini > 0 handles.parameters.acq.nproj; if (ps.phasetype(ii) && ps.thetatype(ii)) - ps.hkl(ii,:) = handles.parameters.cryst(ps.phasetype(ii)).hkl(:,ps.thetatype(ii)); + + tmphkl = handles.parameters.cryst(ps.phasetype(ii)).hkl(:,ps.thetatype(ii)); + + if size(tmphkl,1)==3 + ps.hkl(ii,:) = tmphkl; + elseif size(tmphkl,1)==4 + ps.hkl(ii,:) = tmphkl([1 2 4]); + else + error('Expected format for field hkl is 3xn or 4xn.') + end + ps.hklunique(ii,1) = true; + else ps.hkl(ii,:) = [NaN NaN NaN]; ps.hklunique(ii,1) = false; @@ -127,9 +142,13 @@ if handles.nof_pairs_ini > 0 end - handles.pairs = ps; - handles.pairsfilt = ps; - + handles.pairs = ps; + handles.pairs.filttheta = true(size(handles.pairs.indA)); + handles.pairs.filterr = true(size(handles.pairs.indA)); + handles.pairs.filtind = true(size(handles.pairs.indA)); + + handles.pairsfilt = handles.pairs; + end handles.allsp = allsp; diff --git a/3_pairmatchingGUI/gtMatchRankCandidates.m b/3_pairmatchingGUI/gtMatchRankCandidates.m index 4c340d20..97c0cc82 100644 --- a/3_pairmatchingGUI/gtMatchRankCandidates.m +++ b/3_pairmatchingGUI/gtMatchRankCandidates.m @@ -166,6 +166,9 @@ handles.pairs.centAV = handles.allsp.centv(handles.pairs.indA); handles.pairs.centBU = handles.allsp.centu(handles.pairs.indB); handles.pairs.centBV = handles.allsp.centv(handles.pairs.indB); +handles.pairs.filttheta = true(size(handles.pairs.indA)); +handles.pairs.filterr = true(size(handles.pairs.indA)); +handles.pairs.filtind = true(size(handles.pairs.indA)); % Copy pairid-s into allsp: diff --git a/3_pairmatchingGUI/gtMatchRotAxisProjection.m b/3_pairmatchingGUI/gtMatchRotAxisProjection.m index 17019a00..5a02da60 100644 --- a/3_pairmatchingGUI/gtMatchRotAxisProjection.m +++ b/3_pairmatchingGUI/gtMatchRotAxisProjection.m @@ -85,8 +85,8 @@ if nargout > 1 % Note that there will be a distortion in this 3D figure compared to % reality, if the pixel sizes are different or detdiru and detdirv are % not orthogonal. It is only for plotting over the detector image. - endpointsz(1) = (end1lab - labgeo.detrefpos)*labgeo.detnorm'/labgeo.pixelsizeu; - endpointsz(2) = (end2lab - labgeo.detrefpos)*labgeo.detnorm'/labgeo.pixelsizeu; + endpointsz(1) = (end1lab - labgeo.detrefpos)*(-labgeo.detnorm')/labgeo.pixelsizeu; + endpointsz(2) = (end2lab - labgeo.detrefpos)*(-labgeo.detnorm')/labgeo.pixelsizeu; end diff --git a/3_pairmatchingGUI/gtMatchSplitSpotData.m b/3_pairmatchingGUI/gtMatchSplitSpotData.m index 6bd74bb9..d9c7c952 100644 --- a/3_pairmatchingGUI/gtMatchSplitSpotData.m +++ b/3_pairmatchingGUI/gtMatchSplitSpotData.m @@ -7,7 +7,8 @@ function handles = gtMatchSplitSpotData(handles) % analysed independently in other functions. % -rangeA = ceil(handles.matchpars.thr_max_offset); +% Image range for subgroups A: +rangeA = max(ceil(handles.matchpars.thr_max_offset),1); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% diff --git a/3_pairmatchingGUI/gtMatchUpdateThetaFilter.m b/3_pairmatchingGUI/gtMatchUpdateThetaFilter.m new file mode 100644 index 00000000..5f34ae51 --- /dev/null +++ b/3_pairmatchingGUI/gtMatchUpdateThetaFilter.m @@ -0,0 +1,69 @@ +function gtMatchUpdateThetaFilter(handles,op) + +% Updates the theta range values in handles.ThetaLimits if changed by the user +% via the GUI. Calls other functions to update the graphical display of +% the theta ranges and the pairs in the eta-theta plot that pass the filter. + + +% Check input +if handles.ThetaLimLastLow >= handles.ThetaLimLastHigh + return +end + + +switch op + + case 'add' + % Add new values to array + handles.ThetaLimits(end+1,1:2) = [handles.ThetaLimLastLow, handles.ThetaLimLastHigh]; + + case 'delete' + if isempty(handles.ThetaLimits) + return + end + % Current index in list + ind = get(handles.ThetaLims_Listbox,'Value'); + % Delete currently selected limits + handles.ThetaLimits(ind,:) = []; + set(handles.ThetaLims_Listbox,'Value',1); + + case 'change' + % Current index in list + ind = get(handles.ThetaLims_Listbox,'Value'); + % Change limits + handles.ThetaLimits(ind,1:2) = [handles.ThetaLimLastLow, handles.ThetaLimLastHigh]; + +end + + +% Change string in list box +if isempty(handles.ThetaLimits) + set(handles.ThetaLims_Listbox,'String','!! None !!'); +else + set(handles.ThetaLims_Listbox,'String',num2str(handles.ThetaLimits)); +end + + +% Update theta limits in figure +handles = gtMatchUpdateThetaFilterDisplay(handles); + + +% Apply filter to pairs +tmpfilt = false(size(handles.pairs.theta,1),size(handles.ThetaLimits,1)); +for ii = 1:size(handles.ThetaLimits,1) + tmpfilt(:,ii) = ((handles.ThetaLimits(ii,1) <= handles.pairs.theta)... + & (handles.pairs.theta <= handles.ThetaLimits(ii,2))); +end + +handles.pairs.filttheta = any(tmpfilt,2); + + +% Update eta-theta and text display +handles = gtMatchFilterPairs(handles); + + +% Update GUI data +guidata(handles.figure1,handles); + + + diff --git a/7_fed/geometry/gtFedRotationMatrixComp.m b/7_fed/geometry/gtFedRotationMatrixComp.m index df067ef1..098b6de1 100644 --- a/7_fed/geometry/gtFedRotationMatrixComp.m +++ b/7_fed/geometry/gtFedRotationMatrixComp.m @@ -1,27 +1,34 @@ function rotmatcomp = gtFedRotationMatrixComp(rotdir) % rotmatcomp = gtFedRotationMatrixComp(rotdir) % -% Gives the matrices to compose a rotation matrix according to Rodrigues' -% rotation formula: +% Given an arbitrary rotation axis in 3D space, returns the three matrices +% in Rodrigues's formula. The matrices can be used to compose the rotation +% tensor. Considers right-handed rotation for a positive angle. +% +% To be used with COLUMN VECTORS, MULTIPLY FROM THE LEFT side! +% Multiplication of row vectors from the right gives the wrong result! +% +% Rodrigues's rotation formula describes a linear combination of +% matrices with only cos(om) and only sin(om) dependent terms: % S = Sconst + Scos*cos(om) + Ssin*sin(om) -% S: rotation matrix: nlab = S*nsam +% S: rotation matrix: columnvector_rotated = S*columnvector % om: right-handed rotation angle % % INPUT -% rotdir - rotation axis direction in LAB coordinates +% rotdir - rotation axis direction in LAB coordinates (3,1) % % OUTPUT -% rotmatcomp.const = Sconst -% rotmatcomp.cos = Scos -% rotmatcomp.sin = Ssin +% rotmatcomp.const = matrix Sconst (3,3) +% rotmatcomp.cos = matrix Scos (3,3) +% rotmatcomp.sin = matrix Ssin (3,3) % if size(rotdir) ~= [3,1] - error('Input rotdir has to be a 3x1 coloumn vector.') + error('Input rotdir has to be a 3x1 column vector.') end -if rotdir == [0; 0; 0] % no rotation (polychromatic case) +if rotdir == [0; 0; 0] % no rotation (e.g. polychromatic case) rotmatcomp.const = [1 0 0; 0 1 0; 0 0 1]; rotmatcomp.cos = [0 0 0; 0 0 0; 0 0 0]; @@ -32,8 +39,8 @@ else % monochromatic case rotmatcomp.const = rotdir*rotdir'; rotmatcomp.cos = eye(3) - rotmatcomp.const; rotmatcomp.sin = [ 0 -rotdir(3) rotdir(2);... - rotdir(3) 0 -rotdir(1);... - -rotdir(2) rotdir(1) 0]; + rotdir(3) 0 -rotdir(1);... + -rotdir(2) rotdir(1) 0]; end diff --git a/zUtil_Maths/gtMathsRotationMatrixComp.m b/zUtil_Maths/gtMathsRotationMatrixComp.m index 87f345e4..726e65f2 100644 --- a/zUtil_Maths/gtMathsRotationMatrixComp.m +++ b/zUtil_Maths/gtMathsRotationMatrixComp.m @@ -5,10 +5,14 @@ % in Rodrigues's formula. The matrices can be used to compose the rotation % tensor. Considers right-handed rotation for a positive angle. % +% To be used with ROW VECTORS, MULTIPLY FROM THE RIGHT side! +% Multiplication of column vectors from the left gives the wrong result! +% % Rodrigues's rotation formula describes a linear combination of % matrices with only cos(om) and only sin(om) dependent terms: % Srot = Sconst + Scos*cos(om) + Ssin*sin(om) -% Srot: is the rotation tensor for a row vector: vec_rotated = vec*Srot +% Srot: rotation tensor for a row vector: +% rowvector_rotated = rowvector*Srot % om : rotation angle % % INPUT @@ -16,9 +20,9 @@ % rotation (1,3) % % OUTPUT -% rotmatcomp.const = Sconst matrix -% rotmatcomp.cos = Scos matrix -% rotmatcomp.sin = Ssin matrix +% rotmatcomp.const = matrix Sconst (3,3) +% rotmatcomp.cos = matrix Scos (3,3) +% rotmatcomp.sin = matrix Ssin (3,3) % function rotmatcomp = gtMathsRotationMatrixComp(rotdir) -- GitLab