Skip to content
Snippets Groups Projects
Commit 536cbd18 authored by Nicola Vigano's avatar Nicola Vigano
Browse files

Added editor for mat-files / initial GUI for gtSetup


Some code is already shared between gtSetup and guiGtSetup, and this will be extended as the functionality of guiGtSetup is extended

Signed-off-by: default avatarNicola Vigano <nicola.vigano@esrf.fr>

git-svn-id: https://svn.code.sf.net/p/dct/code/trunk@144 4c865b51-4357-4376-afb4-474e03ccb993
parent d22ea2bc
No related branches found
No related tags found
No related merge requests found
......@@ -74,6 +74,7 @@ pause(1);
close('all');
global GT_MATLAB_HOME
interactive = true;
parameters=[];
list=[];
......@@ -182,9 +183,6 @@ end
parameters.acq.name = tmpname;
clear tmpname
% xml file name
xmlfname=[parameters.acq.name '.xml'];
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% directory for analysis - try to make sensible defaults
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
......@@ -210,108 +208,10 @@ clear tmppwd tmpacqdir
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Parameters from .xml if possible
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% xml file name
xmlfname=[parameters.acq.name '.xml'];
% try to read the .xml file that may be present
if exist(xmlfname,'file')
disp('reading parameters from xml file');
tmpxml = xml_read(xmlfname);
tmpxml = tmpxml.acquisition;
parameters.acq.name = tmpxml.scanName; %shouldn't change!
parameters.acq.date = tmpxml.date;
parameters.acq.xdet = tmpxml.projectionSize.DIM_2;
parameters.acq.ydet = tmpxml.projectionSize.DIM_1;
parameters.acq.nproj = tmpxml.tomo_N/2;
parameters.acq.refon = tmpxml.ref_On;
parameters.acq.nref = tmpxml.ref_N;
parameters.acq.ndark = tmpxml.dark_N;
parameters.acq.pixelsize = tmpxml.pixelSize/1000;
parameters.acq.count_time = tmpxml.ccdtime;
parameters.acq.energy = tmpxml.energy;
parameters.acq.dist = tmpxml.distance; %units??
parameters.acq.sensortype = tmpxml.cameraName;
parameters.acq.type = [num2str(tmpxml.scanRange) 'degree'];
parameters.acq.orig_xdet = 2048;
parameters.acq.orig_ydet = 2048;
parameters.acq.roi_x_off = tmpxml.projectionSize.ROW_BEG;
parameters.acq.roi_y_off = tmpxml.projectionSize.COL_BEG;
else %if .xml not found
disp('No .xml file found! Are you sure you are correctly in the acquistion directory?')
check=inputwdefault('Do you want to proceed without the xml file? [y/n]', 'n');
if strcmpi(check,'y')
disp('quitting...')
return
end
% guess some default values
parameters.acq.date = date();
parameters.acq.xdet = 2048;
parameters.acq.ydet = 2048;
parameters.acq.nproj = 7200;
parameters.acq.refon = 200;
parameters.acq.nref = 5;
parameters.acq.ndark = 11;
parameters.acq.pixelsize = 0.0014;
parameters.acq.count_time = 2;
parameters.acq.energy = 20;
parameters.acq.dist = 5;
parameters.acq.sensortype = 'frelon';
parameters.acq.type = '360degree';
parameters.acq.orig_xdet = 2048;
parameters.acq.orig_ydet = 2048;
parameters.acq.roi_x_off = 0;
parameters.acq.roi_y_off = 0;
clear check
end
% interlacing parameters
% try to guess whether the scan is interlaced
if exist([parameters.acq.name '0_0000.edf'], 'file')
parameters.acq.interlaced_turns = true; % assume one extra turn is reasonable guess
disp('This looks like an interlaced scan! Doubling nproj...')
parameters.acq.nproj = parameters.acq.nproj*2;
else
parameters.acq.interlaced_turns = false;
end
% mono tuned during scan?
parameters.acq.mono_tune = false;
% if we have a horizontal rotation axis we turn the images during the copying process
parameters.acq.rotation_axis = 'vertical';
parameters.acq.distortion = 'none';
% deal with flips and rotations
% subsequently, deal with flips and rotations, scans without direct beam
parameters.acq.flip_images = false;
parameters.acq.no_direct_beam = false;
% rotate images to the gt coordinate system !!! Help !!!
parameters.acq.rotation_direction = 'clockwise';
%%% add 20-12-2011
parameters.acq.rotu = parameters.acq.xdet/2+0.5; % Images will be shifted in gtCreateFullLive to have rotation axis in center...
parameters.acq.rotx = parameters.acq.rotu;
parameters.acq.bb = [0 0 0 0];
parameters.acq.bbdir = [0 0 0 0];
parameters.acq.maxradius = max(parameters.acq.xdet,parameters.acq.ydet)/2*sqrt(2);
%%%
% if it is 360degree data, we need a pair table
if strcmpi(parameters.acq.type, '360degree')
% pair tablename can be derived from the scan name
parameters.acq.pair_tablename = [parameters.acq.name 'spotpairs'];
parameters.acq.calib_tablename = [parameters.acq.name 'paircalib'];
end
% check with user:
% header for the GUI
if exist(xmlfname,'file')
header='Check carefully that the following are correct:';
else
header='Check all values. All "(?)" should be removed:';
end
parameters.acq = gtModifyStructure(parameters.acq, list.acq(:,1:2), header);
parameters = gtLoadAcquisitionXML(parameters, list, xmlfname, interactive);
disp('Saving parameters.mat in the analysis directory...')
save(parameters_name,'parameters');
......
function params = gtLoadAcquisitionXML(parameters, list, xmlfname, interactive)
% FUNCTION gtLoadAcquisitionXML
% params = gtLoadAcquisitionXML(parameters, xmlfname, interactive)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Parameters from .xml if possible
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% try to read the .xml file that may be present
if exist(xmlfname,'file')
disp('reading parameters from xml file');
tmpxml = xml_read(xmlfname);
tmpxml = tmpxml.acquisition;
parameters.acq.name = tmpxml.scanName; %shouldn't change!
parameters.acq.date = tmpxml.date;
parameters.acq.xdet = tmpxml.projectionSize.DIM_2;
parameters.acq.ydet = tmpxml.projectionSize.DIM_1;
parameters.acq.nproj = tmpxml.tomo_N/2;
parameters.acq.refon = tmpxml.ref_On;
parameters.acq.nref = tmpxml.ref_N;
parameters.acq.ndark = tmpxml.dark_N;
parameters.acq.pixelsize = tmpxml.pixelSize/1000;
parameters.acq.count_time = tmpxml.ccdtime;
parameters.acq.energy = tmpxml.energy;
parameters.acq.dist = tmpxml.distance; %units??
parameters.acq.sensortype = tmpxml.cameraName;
parameters.acq.type = [num2str(tmpxml.scanRange) 'degree'];
parameters.acq.orig_xdet = 2048;
parameters.acq.orig_ydet = 2048;
parameters.acq.roi_x_off = tmpxml.projectionSize.ROW_BEG;
parameters.acq.roi_y_off = tmpxml.projectionSize.COL_BEG;
else %if .xml not found
if interactive
disp('No .xml file found! Are you sure you are correctly in the acquistion directory?')
check=inputwdefault('Do you want to proceed without the xml file? [y/n]', 'n');
if strcmpi(check,'y')
disp('quitting...')
return
end
end
% guess some default values
parameters.acq.date = date();
parameters.acq.xdet = 2048;
parameters.acq.ydet = 2048;
parameters.acq.nproj = 7200;
parameters.acq.refon = 200;
parameters.acq.nref = 5;
parameters.acq.ndark = 11;
parameters.acq.pixelsize = 0.0014;
parameters.acq.count_time = 2;
parameters.acq.energy = 20;
parameters.acq.dist = 5;
parameters.acq.sensortype = 'frelon';
parameters.acq.type = '360degree';
parameters.acq.orig_xdet = 2048;
parameters.acq.orig_ydet = 2048;
parameters.acq.roi_x_off = 0;
parameters.acq.roi_y_off = 0;
clear check
end
% interlacing parameters
% try to guess whether the scan is interlaced
if exist([parameters.acq.name '0_0000.edf'], 'file')
parameters.acq.interlaced_turns = true; % assume one extra turn is reasonable guess
disp('This looks like an interlaced scan! Doubling nproj...')
parameters.acq.nproj = parameters.acq.nproj*2;
else
parameters.acq.interlaced_turns = false;
end
% mono tuned during scan?
parameters.acq.mono_tune = false;
% if we have a horizontal rotation axis we turn the images during the copying process
parameters.acq.rotation_axis = 'vertical';
parameters.acq.distortion = 'none';
% deal with flips and rotations
% subsequently, deal with flips and rotations, scans without direct beam
parameters.acq.flip_images = false;
parameters.acq.no_direct_beam = false;
% rotate images to the gt coordinate system !!! Help !!!
parameters.acq.rotation_direction = 'clockwise';
%%% add 20-12-2011
parameters.acq.rotu = parameters.acq.xdet/2+0.5; % Images will be shifted in gtCreateFullLive to have rotation axis in center...
parameters.acq.rotx = parameters.acq.rotu;
parameters.acq.bb = [0 0 0 0];
parameters.acq.bbdir = [0 0 0 0];
parameters.acq.maxradius = max(parameters.acq.xdet,parameters.acq.ydet)/2*sqrt(2);
%%%
% if it is 360degree data, we need a pair table
if strcmpi(parameters.acq.type, '360degree')
% pair tablename can be derived from the scan name
parameters.acq.pair_tablename = [parameters.acq.name 'spotpairs'];
parameters.acq.calib_tablename = [parameters.acq.name 'paircalib'];
end
if interactive
% check with user:
% header for the GUI
if exist(xmlfname,'file')
header='Check carefully that the following are correct:';
else
header='Check all values. All "(?)" should be removed:';
end
parameters.acq = gtModifyStructure(parameters.acq, list.acq(:,1:2), header);
end
params = parameters;
end
......@@ -99,6 +99,7 @@ function initialise_gt()
addpath(GT_MATLAB_HOME)
addpath(fullfile(GT_MATLAB_HOME, '1_preprocessing'));
addpath(fullfile(GT_MATLAB_HOME, '1_preprocessing', 'gtSetup_Utils'));
addpath(fullfile(GT_MATLAB_HOME, '2_difspot'));
addpath(fullfile(GT_MATLAB_HOME, '3_pairmatching'));
addpath(fullfile(GT_MATLAB_HOME, '4_grains'));
......@@ -121,6 +122,7 @@ function initialise_gt()
addpath(fullfile(GT_MATLAB_HOME, 'zUtil_EDF'));
addpath(fullfile(GT_MATLAB_HOME, 'zUtil_ForwardProjection'));
addpath(fullfile(GT_MATLAB_HOME, 'zUtil_GVF'));
addpath(fullfile(GT_MATLAB_HOME, 'zUtil_GUI'));
addpath(fullfile(GT_MATLAB_HOME, 'zUtil_Help'));
addpath(fullfile(GT_MATLAB_HOME, 'zUtil_ICP'));
addpath(fullfile(GT_MATLAB_HOME, 'zUtil_Imaging'));
......
File added
function varargout = guiGtSetup(varargin)
% GUIGTSETUP MATLAB code for guiGtSetup.fig
% GUIGTSETUP, by itself, creates a new GUIGTSETUP or raises the existing
% singleton*.
%
% H = GUIGTSETUP returns the handle to a new GUIGTSETUP or the handle to
% the existing singleton*.
%
% GUIGTSETUP('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in GUIGTSETUP.M with the given input arguments.
%
% GUIGTSETUP('Property','Value',...) creates a new GUIGTSETUP or raises
% the existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before guiGtSetup_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to guiGtSetup_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help guiGtSetup
% Last Modified by GUIDE v2.5 23-Jan-2012 18:10:13
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @guiGtSetup_OpeningFcn, ...
'gui_OutputFcn', @guiGtSetup_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
end
% --- Executes just before guiGtSetup is made visible.
function guiGtSetup_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to guiGtSetup (see VARARGIN)
% Choose default command line output for guiGtSetup
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
initialize_gui(hObject, handles, false);
% UIWAIT makes guiGtSetup wait for user response (see UIRESUME)
% uiwait(handles.figure1);
end
% --- Outputs from this function are returned to the command line.
function varargout = guiGtSetup_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
end
% --------------------------------------------------------------------
function initialize_gui(fig_handle, handles, isreset)
% If the metricdata field is present and the reset flag is false, it means
% we are we are just re-initializing a GUI by calling it from the cmd line
% while it is up. So, bail out as we dont want to reset the data.
% if isfield(handles, 'metricdata') && ~isreset
% return;
% end
%
% handles.metricdata.density = 0;
% handles.metricdata.volume = 0;
%
% set(handles.density, 'String', handles.metricdata.density);
% set(handles.volume, 'String', handles.metricdata.volume);
% set(handles.mass, 'String', 0);
%
% set(handles.unitgroup, 'SelectedObject', handles.english);
%
% set(handles.text4, 'String', 'lb/cu.in');
% set(handles.text5, 'String', 'cu.in');
% set(handles.text6, 'String', 'lb');
handles.guiEditPath = setAcquisitionPath(handles.guiEditPath, pwd);
[handles.parameters, handles.list] = make_parameters(1);
updateListbox(handles.guiListbox, handles.parameters);
% Update handles structure
guidata(handles.figure1, handles);
end
function guiAcquisPathOut = setAcquisitionPath(guiAcquisitionPath, pathname)
set(guiAcquisitionPath, 'String', pathname);
guiAcquisPathOut = guiAcquisitionPath;
end
% --- Executes on selection change in guiListbox.
function guiListbox_Callback(hObject, eventdata, handles)
% hObject handle to guiListbox (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = cellstr(get(hObject,'String')) returns guiListbox contents as cell array
% contents{get(hObject,'Value')} returns selected item from guiListbox
end
% --- Executes during object creation, after setting all properties.
function guiListbox_CreateFcn(hObject, eventdata, handles)
% hObject handle to guiListbox (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: listbox controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
end
% --- Executes on button press in guiSaveButton.
function guiSaveButton_Callback(hObject, eventdata, handles)
% hObject handle to guiSaveButton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
[filename, pathname] = uiputfile('parameters.mat', 'Save Parameters as');
disp(['File: ''' filename ''' and path: ''' pathname ''''])
if filename
save(handles.parameters, fullfile(pathname, filename));
end
end
% --- Executes on button press in guiLoadButton.
function guiLoadButton_Callback(hObject, eventdata, handles)
% hObject handle to guiLoadButton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
[filename, pathname] = uigetfile('*.mat', 'Select a Parameter file');
disp(['File: ''' filename ''' and path: ''' pathname ''''])
if filename
completePath = fullfile(pathname, filename);
[handles.parameters, handles.list] = make_parameters(1);
handles.parameters = load(completePath);
% Update handles structure
guidata(handles.figure1, handles);
end
end
% --- Executes on button press in guiEditButton.
function guiEditButton_Callback(hObject, eventdata, handles)
% hObject handle to guiEditButton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
namesList = fieldnames(handles.parameters);
currentValue = get(handles.guiListbox, 'Value');
section_name = namesList(currentValue);
section_name = section_name{1};
section = getfield(handles.parameters, section_name);
section_descr = getfield(handles.list, section_name);
section = editSection(section, section_descr);
handles.parameters = setfield(handles.parameters, section_name, section);
% Update handles structure
guidata(handles.figure1, handles);
end
% --- Executes on button press in guiLoadXMLPushButton.
function guiLoadXMLPushButton_Callback(hObject, eventdata, handles)
% hObject handle to guiLoadXMLPushButton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
[xmlFilename, xmlPath] = uigetfile('*.xml', 'Select an XML file');
disp(['File: ''' xmlFilename ''' and path: ''' xmlPath ''''])
if xmlFilename
completePath = fullfile(xmlPath, xmlFilename);
[handles.parameters, handles.list] = make_parameters(1);
handles.parameters = gtLoadAcquisitionXML(handles.parameters, handles.list, completePath, false);
handles.guiEditPath = setAcquisitionPath(handles.guiEditPath, xmlPath);
% Update handles structure
guidata(handles.figure1, handles);
end
end
% --- Executes on button press in guiLaunchButton.
function guiLaunchButton_Callback(hObject, eventdata, handles)
% hObject handle to guiLaunchButton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
end
function updateListbox(listbox, paramfile)
namesList = fieldnames(paramfile);
listbox_string = '';
for k = 1:length(namesList)
listbox_string = [listbox_string namesList(k)];
end
set(listbox, 'String', listbox_string);
end
function sectionOut = editSection(section, section_descr)
header='Check carefully that the following are correct:';
sectionOut = gtModifyStructure(section, section_descr(:,1:2), header);
end
function guiEditPath_Callback(hObject, eventdata, handles)
% hObject handle to guiEditPath (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of guiEditPath as text
% str2double(get(hObject,'String')) returns contents of guiEditPath as a double
dirname = get(handles.guiEditPath, 'String');
resetAcquisitionDir(handles, dirname);
end
% --- Executes during object creation, after setting all properties.
function guiEditPath_CreateFcn(hObject, eventdata, handles)
% hObject handle to guiEditPath (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
end
% --- Executes on button press in guiChangeButton.
function guiChangeButton_Callback(hObject, eventdata, handles)
% hObject handle to guiChangeButton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
startdir = get(handles.guiEditPath, 'String');
directoryname = uigetdir(startdir, 'Select acquisition directory...');
if directoryname
resetAcquisitionDir(handles, directoryname);
end
end
function resetAcquisitionDir(handles, directoryname)
[handles.parameters, handles.list] = make_parameters(1);
% Let's find a xml file
paramsFiles = dir(fullfile(directoryname, 'parameters.mat'));
xmlFiles = dir(fullfile(directoryname, '*.xml'));
if length(paramsFiles) == 1
completePath = fullfile(directoryname, paramsFiles(1).name);
disp(['Opening file: ' completePath])
handles.parameters = load(completePath);
handles.guiEditPath = setAcquisitionPath(handles.guiEditPath, directoryname);
elseif length(xmlFiles) == 1
completePath = fullfile(directoryname, xmlFiles(1).name);
disp(['Opening file: ' completePath])
handles.parameters = gtLoadAcquisitionXML(handles.parameters, handles.list, completePath, false);
handles.guiEditPath = setAcquisitionPath(handles.guiEditPath, directoryname);
else
warnmessage = [ 'Not possible to automatically locate any ' ...
'parameters.mat or *.xml file in directory: ' ...
directoryname];
f = warndlg(warnmessage, 'Warning', 'modal');
end
% Update handles structure
guidata(handles.figure1, handles);
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment