function varargout = register(varargin)

% REGISTER: callback functions for AART GUI
% REGISTER is an M-file for register.fig
%      REGISTER, by itself, creates a new REGISTER or raises the existing
%      singleton*.
%
%      H = REGISTER returns the handle to a new REGISTER or the handle to
%      the existing singleton*.
%
%      REGISTER('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in REGISTER.M with the given input arguments.
%
%      REGISTER('Property','Value',...) creates a new REGISTER or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before register_OpeningFunction gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to register_OpeningFcn via varargin.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
%      instance to run (singleton)".
%
% Code construction assisted by GUIDE
%
%    GENERAL
%
%      varargout = register(varargin)
%
%    INPUT/S
%
%      -Currently not applicable
%          
%           
%    OUTPUT/S
%
%      -Not used at present
%
%    PENDING WORK
%
%      -The function will be extended to have more callbacks. Shifting of
%      certain sub-routines outside might be possible in the future,
%      provided that objects in the GUI need not be passed.
%
%    KNOWN BUG/S
%
%      -February: Some callbacks such as MDL are not yet implemnented and a
%      sensible message box appears.
%
%    COMMENT/S
%
%      -
%
%    RELATED FUNCTION/S
%
%      
%
%    ABOUT
%
%      -Created:     January 2004
%      -Last update: February 13th, 2004
%      -Revision:    0.6.9
%      -Author:      R. S. Schestowitz, University of Manchester
% ==============================================================

% Edit the above text to modify the response to help_button register

% Last Modified by GUIDE v2.5 24-Mar-2004 17:39:06

% Begin initialization code - DO NOT EDIT
gui_Singleton = 0;
gui_State = struct('gui_Name',       mfilename, ...
    'gui_Singleton',  gui_Singleton, ...
    'gui_OpeningFcn', @register_OpeningFcn, ...
    'gui_OutputFcn',  @register_OutputFcn, ...
    'gui_LayoutFcn',  [] , ...
    'gui_Callback',   []);
if nargin & isstr(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

% ==================================================================== %  

% --- Executes just before register is made visible.
function register_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 register (see VARARGIN)

% Choose default command line output for register
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

if strcmp(get(hObject,'Visible'),'off')
    initialize_gui(hObject, handles);
end


  set(handles.resume, 'cdata', playbutton);
  set(handles.pause, 'cdata', stopbutton);
  set(handles.register_1d, 'cdata', registerbutton);
  set(handles.help_button, 'cdata', helpbutton);
  set(handles.abort, 'cdata', abortbutton);
  set(handles.reset, 'cdata', resetbutton);
  
% ==================================================================== %  

% --- Outputs from this function are returned to the command line.
function varargout = register_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;

% ==================================================================== %  

function register = registerbutton

register = iconize(imread('reg.jpg'));
register(register>240) = .69*255;

% ==================================================================== %  

function stop = stopbutton

stop = iconize(imread('stop.jpg'));
stop(stop>240) = .69*255;

% ==================================================================== %   

function play = playbutton

play = iconize(imread('play.jpg'));
play(play>240) = .69*255;

% ==================================================================== %   

function abort = abortbutton

abort = iconize(imread('abort.jpg'));
abort(abort>240) = .69*255;

% ==================================================================== %   

function reset = resetbutton

reset = iconize(imread('reset.jpg'));
reset(reset>240) = .69*255;

% ==================================================================== %     

function help = helpbutton

help = iconize(imread('help.jpg'));
help(help>240) = .69*255;

% ==================================================================== %  

% --- Hand-written callback 
% --- Used to create icon data from an image

function out = iconize(a)

% Find the size of the acquired image and determine how much data will need
% to be lost in order to form a 18x18 icon
[r,c,d] = size(a);
r_skip = ceil(r/25);
c_skip = ceil(c/25);

% Create the 25x25 icon (RGB data)
out = a(1:r_skip:end,1:c_skip:end,:);

% ==================================================================== %     

function register_1d_Callback(hObject, eventdata, handles)

% getappdata(0, 'exit_handle') This is how advanced menu values are
% obtained

if ((str2num(get(handles.save_pixels, 'String')) == 0)...
        & (get(handles.save_video_option, 'Value') == 1) ),
    set(handles.show_pixels_throughout_option, 'Value', 1);
    set(handles.show_pixels, 'String', '1');
    % force figure to be shown for video capture
end

if ((str2num(get(handles.save_pixels, 'String')) == 3)...
        & (get(handles.save_video_option, 'Value') == 1) ),
    set(handles.repeatedly_show_model_option, 'Value', 1);
    set(handles.repeatedly_show_model, 'String', '1');
    % force figure to be shown for video capture of model
end


if ((str2num(get(handles.save_pixels, 'String')) == 1)...
        & (str2num(get(handles.save_video, 'String')) == 1)),
    set(handles.show_plots_throughout_option, 'Value', 1);
    set(handles.show_plot, 'String', '1');
    % bring up display if video of plots needs to be captured
end

if ((str2num(get(handles.save_pixels, 'String')) == 2)...
        & (str2num(get(handles.save_video, 'String')) == 1)),
    set(handles.show_mesh_throughout_option, 'Value', 1);
    set(handles.show_mesh, 'String', '1');
    % bring up display if video of plots needs to be captured
end


if ((str2num(get(handles.overlap_scores, 'String')) == 1)...
        & (str2num(get(handles.all_objective_functions, 'String')) == 1)),
    set(handles.always_score_by_model_option, 'Value', 1);   
    set(handles.show_score_vs_iteration_option, 'Value', 1);
    set(handles.always_score_by_model, 'String', 1);   
    set(handles.show_score_vs_iteration, 'String', 1);
      % show the required results if overlapping scores are displayed
end


if (str2num(get(handles.use_filename, 'String')) == 0),
    movie_name_to_pass = 'Undefined.avi';
    % can generate sensible name as done by default in
    % build_1d_bump_model, but currently uses a default name
else
    movie_name_to_pass = get(handles.file_for_video_box, 'String');
end

original_base_handle = get(handles.filename_handle, 'String');

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% This is where registration actually starts

range_minimum = str2num(getappdata(0,'minimum_value'));
range_maximum = str2num(getappdata(0,'maximum_value'));
range_step = str2num(getappdata(0,'step_size'));
automation_type = getappdata(0, 'automation_type');

% check for some exceptions

if (range_minimum > range_maximum),
    error('Minimum cannot be greater than maximum.');
% elseif (range_maximum - range_minimum < range_step)
%    error('Step size does not fit within range defined.');
end


for i = range_minimum:range_step:range_maximum,
    
	if (strcmp(automation_type, 'None')),
        % do nothing, also means that same experiments can be performed
        % over and over again with new sets. Alternatively there is a sets
        % option built-in to build_1d_bump_model but it appears less
        % reliable. It was used mainly by Kate for statistics in the far
        % past.
	elseif (strcmp(automation_type, 'Number of Knot-points')),
        set(handles.knot_points, 'String', num2str(i));
        set(handles.filename_handle, 'String', [[original_base_handle], ['-'], [num2str(i)]]);     
	elseif (strcmp(automation_type, 'Number of Modes')),
        set(handles.number_of_modes_display, 'String', num2str(i));
        set(handles.filename_handle, 'String', [[original_base_handle], ['-'], [num2str(i)]]);    
	elseif (strcmp(automation_type, 'Model Weight')),
        set(handles.model_weight_constant_value, 'String', num2str(i));
        set(handles.filename_handle, 'String', [[original_base_handle], ['-'], [num2str(i)]]);   
	elseif (strcmp(automation_type, 'Smoothing')),
        set(handles.window, 'String', num2str(i));
        set(handles.filename_handle, 'String', [[original_base_handle], ['-'], [num2str(i)]]); 
    elseif (strcmp(automation_type, 'Perturbation')),
        setappdata(0, 'perturbation_offset', num2str(i));
        set(handles.filename_handle, 'String', [[original_base_handle], ['-'], [num2str(i)]]);     
	end
    
    if (strcmp(which([[get(handles.filename_handle, 'String')],['.mat']]), '') == 0),
        % check if handle exists already
        set(handles.filename_handle, 'String',[[get(handles.filename_handle, 'String')],['-'], num2str(ceil(rand * 999))]);
        % append extra numbers
    end
    
    if (strcmp(get(handles.filename_handle, 'String'), '')),
        % check if handle is empty
        set(handles.filename_handle, 'String', [['Undefined'],['-'], num2str(ceil(rand * 999))]);
        % append extra numbers to the 'Undefined' string
    end
    
	set(handles.status_bar, 'String', 'Registration in progress...');
       % indicate status in the status bar
	
	set(handles.pause, 'Enable', 'on');
	set(handles.resume, 'Enable', 'off');
        % enable the buttons that control tehe state of the process (will
        % currently work only if drawing is involved
	
	[status] = build_1d_bump_model(get(handles.spline_type_display, 'String')...
        , get(handles.placement_method_display, 'String')...
        , get(handles.objective_function_display, 'String')...
        , str2num(get(handles.apply_corrective_offset, 'String'))...
        , str2num(get(handles.save_video, 'String'))...
        , str2num(get(handles.show_plot, 'String'))...   
        , str2num(get(handles.save_pixels, 'String'))...
        , str2num(get(handles.hierarchical_text, 'String'))...
        , str2num(get(handles.use_defaults, 'String'))...
        , str2num(get(handles.show_statistics, 'String'))...
        , str2num(get(handles.repeatedly_show_model, 'String'))...
        , str2num(get(handles.show_pixels, 'String'))...
        , str2num(get(handles.show_score_vs_iteration, 'String'))...
        , str2num(get(handles.show_final_model, 'String'))...
        , str2num(get(handles.find_specificity, 'String'))...
        , str2num(get(handles.show_score_while_optimising, 'String'))...
        , movie_name_to_pass...
        , str2num(get(handles.window, 'String'))...
        , str2num(get(handles.average_smoothing, 'String'))...
        , str2num(get(handles.gaussian_smoothing, 'String'))...
        , str2num(get(handles.bump_width, 'String'))...
        , str2num(get(handles.bump_width_variation, 'String'))...
        , str2num(get(handles.bump_height, 'String'))...
        , str2num(get(handles.bump_height_variation, 'String'))...
        , str2num(get(handles.bump_position_freedom, 'String'))...
        , str2num(get(handles.initial_diminish_factor, 'String'))...
        , str2num(get(handles.smoothness_factor, 'String'))...
        , str2num(get(handles.plot_before_and_after, 'String'))...
        , str2num(get(handles.number_of_bins, 'String'))...
        , str2num(get(handles.determinant, 'String'))...
        , str2num(get(handles.always_score_by_model, 'String'))...
        , get(handles.filename_handle, 'String')...
        , str2num(get(handles.number_of_modes_display, 'String'))... 
        , (str2num(get(handles.model_weight_constant_value, 'String')) / 100)...
        , get(handles.text108, 'String') ...
        , (str2num(get(handles.variatyion_kept_display, 'String')) / 100)...
        , str2num(get(handles.all_objective_functions, 'String'))...
        , get(handles.pdf, 'String')...
        , str2num(get(handles.save_data, 'String'))...
        , str2num(get(handles.load_data, 'String'))...
        , str2num(get(handles.save_bumps_flag, 'String'))...
        , str2num(get(handles.draw_warp_curve, 'String'))...
        , str2num(get(handles.overlap_scores, 'String'))...
        , str2num(get(handles.show_target, 'String'))...
        , get(handles.format, 'String')...
        , get(handles.filter_type, 'String')...
        , str2num(get(handles.level, 'String'))...
        , get(handles.model_score_type, 'String')...
        , str2num(get(handles.gen_iters, 'String'))...
        , str2num(get(handles.spec_iters, 'String'))...
        , str2num(get(handles.draw_curve_by_images, 'String'))...
        , str2num(get(handles.show_mesh, 'String'))...
        , get(handles.mesh_type, 'String')...
        , str2num(getappdata(0, 'exit_handle'))...
        , str2num(getappdata(0, 'show_score_figures'))...
        , str2num(getappdata(0, 'close_handle'))...
        , str2num(get(handles.frames_per_second, 'String'))...
        , str2num(getappdata(0, 'show_score_bar'))...
        , str2num(get(handles.knot_points, 'String'))...
        , str2num(get(handles.show_warp_targets, 'String'))...
        , str2num(get(handles.show_registration_target_flag, 'String'))...
        , str2num(get(handles.produce_record, 'String'))...
        , str2num(get(handles.initialise_warps_close_to_target, 'String'))...
        , str2num(get(handles.save_in_log, 'String'))...
        , getappdata(0, 'perturbation_method')...
        , str2num(getappdata(0, 'perturbation_offset'))...
        , str2num(get(handles.force_reference, 'String'))...
        , str2num(get(handles.cycle, 'String')) ...
        , get(handles.verbose_optimiser_flag, 'String') ...
        , str2num(get(handles.save_stats, 'String')) ...
        , str2num(getappdata(0, 'number_of_modes')) ...
        , str2num(getappdata(0, 'std')) ...
        , str2num(get(handles.show_warps_while_optimising_flag, 'String')) ...
        , get(handles.description, 'String') ...
        , str2num(getappdata(0, 'find_perfect_warp')) ...
        , str2num(getappdata(0, 'force_first_reference')) ...
        , str2num(getappdata(0, 'display_shape_model')) ...
        , str2num(getappdata(0, 'display_intensity_model')) ...
        , str2num(getappdata(0, 'plot_alignment')) ...
        , getappdata(0, 'error_verbosity') ...
        , str2num(getappdata(0, 'precision_required'))...
        , str2num(getappdata(0, 'background_colour_red'))...
        , str2num(getappdata(0, 'background_colour_green'))...
        , str2num(getappdata(0, 'background_colour_blue'))...
        , str2num(getappdata(0, 'dynamic_precision'))...
        , getappdata(0, 'automatic_precision_type')...
        , str2num(getappdata(0, 'rotate_surface')) ...
        , str2num(getappdata(0, 'draw_final_warps')) ...
        , getappdata(0, 'distance_type') ...
        , str2num(getappdata(0, 'retain_original_peak')) ...
        , getappdata(0, 'peak_type') ...
        , str2num(getappdata(0, 'add_points')) ...
        , str2num(getappdata(0, 'add_points_cycle')) ...
        , str2num(getappdata(0, 'stamp_images')) ...
        , get(handles.auto_weighting_menu, 'Checked') ...
        , getappdata(0, 'automatic_weighting_type') ...
        , get(handles.show_inverse_projection, 'Checked') ...
        , get(handles.show_model_reconstruction_for_warped_images, 'Checked') ...
        , getappdata(0, 'point_insertion_position') ...
  );
	
	% call the main function to carry out registration and fetch all the
	% arguments to be passed from the GUI
	
	set(handles.pause, 'Enable', 'off');
	set(handles.resume, 'Enable', 'off');
	% disable these buttons as they are not applicable when the application
	% does not run
	set(handles.status_bar, 'String', status);
	% get status returned from the function at the end of exectution and
	% display it in the status bar

end

%% Registration ends
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% ==================================================================== %     

function initialize_gui(fig_handle, handles)

% this function will be called at the start and every time 'reset' is
% pressed

% The main routines will set values and strings, but some will shade
% sections in the GUI and initialise some button states and menus

% organisation and ordering of the statements might be useful.

% set the title

if (strcmp(getenv('OS'), 'Linux')),
  set(handles.Main_window, 'Name', [[get_package], [get_month], ' ', [get_year], ' - Version ', [get_version], ' - ', [getenv('OS')], ' on ', [get_host], '@ ', [get_domain]]);
       % if on Linux, display machine identifier
else
  set(handles.Main_window, 'Name', [[get_package], [get_month], ' ', [get_year], ' - Version ', [get_version], ' - ', [getenv('OS')]]);
end






% now draw the logo

background = imread('backgroundlarge.jpg');

axes(handles.background);
axis off;
imshow(background,[0,255]);

axes(handles.isbe_logo);
isbe = imread('isbe.tif');

%        The lines below give a binary option for black/white with a
%        threshold. It was disabled in January 2004.
%
% for i=1:size(isbe,1),
%     for j=1:size(isbe,2),
%         if (isbe(i,j) > 150)
%             isbe(i,j) = 180;
%         else
%             isbe(i,j) = 0;
%         end
%     end
% end

imshow(isbe,[0,255]);

% The standard procedure is to read the data, set the apppropriate region
% in the UI, and then display that image (logo) in that region.

axes(handles.aart_logo);
isbe = imread('aartsm.tif');
imshow(isbe,[0,255]);

samples = imread('samples.tif');

axes(handles.samples);
axis off;
imshow(samples,[0,255]);



% NOTE: by removing the two (last) lines above (axis and imshow) linkage can work.
% Pending solution (March 2004) as axis must be void for ButtonDownFcn to
% be a valid callback. 3 pseudo-hyperlink callbacks are obsolete.





% image references parameters

set(handles.force_reference , 'String', '1');
set(handles.force_reference_button, 'Value', 1);
setappdata(0, 'force_first_reference', '2');

set(handles.random_reference_menu, 'Checked', 'off'); 
set(handles.first_reference_menu, 'Checked', 'off'); 
set(handles.second_reference_menu, 'Checked', 'off'); 
set(handles.reference_nearest_to_average_menu, 'Checked', 'on');
set(handles.lowest_reference_menu, 'Checked', 'off'); 
set(handles.highest_reference_menu, 'Checked', 'off');


% log parameters

set(handles.save_in_log_button, 'Value', 1);
set(handles.save_in_log, 'String', '1');
setappdata(0, 'stamp_images', '0');
set(handles.stamp_images_menu, 'Checked', 'off');

% set the sliders to initial values

set(handles.frames_per_second_slider, 'Value', 15);
set(handles.smoothing_slider, 'Value', 0);
set(handles.spec_slider, 'Value', 25);
set(handles.gen_slider, 'Value', 25);
set(handles.knotpoints_slider, 'Value', 5);

% set the sliders of the bump properties

set(handles.base_height_slider, 'Value', 0.2);
set(handles.base_width_slider, 'Value', 0.5);
set(handles.height_variation_slider, 'Value', 0.7);
set(handles.width_variation_slider, 'Value', 0.2);
set(handles.position_freedom_slider, 'Value', 0.9);
set(handles.smoothness_slider, 'Value', 17);
set(handles.cycle_slider, 'Value', 1);

% bump properties

set(handles.samples_flag, 'String', '1');
set(handles.bump_width, 'String', '0.5');
set(handles.bump_width_variation, 'String', '0.2');
set(handles.bump_height, 'String', '0.2');
set(handles.bump_height_variation, 'String', '0.7');
set(handles.bump_position_freedom, 'String', '0.9');
set(handles.initial_diminish_factor, 'String', '1');
set(handles.smoothness_factor, 'String', '17');


% bump generation sliders section

set(handles.base_height_slider, 'Enable', 'off');
set(handles.position_freedom_slider, 'Enable', 'off');
set(handles.height_variation_slider, 'Enable', 'off');
set(handles.width_variation_slider, 'Enable', 'off');
set(handles.base_width_slider, 'Enable', 'off');
set(handles.smoothness_slider, 'Enable', 'off');

% bump attributes - extra options

set(handles.default_attributes, 'Value', 1);
set(handles.specify_attributes, 'Value', 0);


set(handles.base_height_text, 'Enable', 'off');
set(handles.width_variation_text, 'Enable', 'off');
set(handles.height_variation_text, 'Enable', 'off');

set(handles.base_width_text, 'Enable', 'off');
set(handles.position_freedom_text, 'Enable', 'off');
set(handles.smoothness_text, 'Enable', 'off');

set(handles.attr_height, 'Enable', 'off');
set(handles.attr_low_var, 'Enable', 'off');
set(handles.attr_typical, 'Enable', 'off');

% show/hide samples

set(handles.enable_samples, 'Checked', 'on');
set(handles.disable_samples, 'Checked', 'off');

% set mesh/surface properties

set(handles.file_for_video_box, 'String', 'Default.avi');
set(handles.mesh_type, 'String', 'Illuminated Surface');

set(handles.rotate_surface, 'Value', 0);
setappdata(0, 'rotate_surface', '0');

set(handles.show_mesh, 'String', '0');
set(handles.rotate_surface, 'Enable', 'on');

% dynamic precision option

set(handles.dynamic_precision, 'Checked', 'off');
setappdata(0, 'dynamic_precision', '0');

% warping and warp options section

setappdata(0, 'draw_final_warps', '0');

setappdata(0, 'find_perfect_warp', '1');
set(handles.find_perfect_warp_menu, 'Checked', 'on');

set(handles.show_warps_while_optimising_flag, 'String', '0');
set(handles.show_warps_while_optimising, 'Checked', 'off');

% ways of measuring distance from the mean

setappdata(0, 'distance_type', 'sum_of_squared_distances');
set(handles.Sum_of_Squared_Distances, 'Checked', 'on');
set(handles.Absolute_Distances, 'Checked', 'off');

% options for peaks being retained

setappdata(0, 'retain_original_peak', '0');
set(handles.retain_original_peak_menu, 'Checked', 'off');

setappdata(0, 'peak_type', 'average_position');

set(handles.peak_type_average_menu, 'Checked', 'on');
set(handles.peak_type_initial_menu, 'Checked', 'off');

% Advanced options handles

setappdata(0, 'close_handle', '0');
setappdata(0, 'exit_handle', '0');
setappdata(0, 'show_score_figures', '0');
setappdata(0, 'show_score_bar', '0');


% Perturbation options handles

setappdata(0, 'perturbation_offset', '0');

setappdata(0, 'number_of_modes', '2');
setappdata(0, 'std', '2');

setappdata(0, 'perturbation_method', 'random noise');

% automation options

setappdata(0, 'automation_type', 'None');
setappdata(0, 'minimum_value', '1');
setappdata(0, 'maximum_value', '1');
setappdata(0, 'step_size', '1');

% precision menus

setappdata(0, 'precision_required', '1e - 7');

set(handles.precision_5, 'Checked', 'off');
set(handles.precision_6, 'Checked', 'off');
set(handles.precision_7, 'Checked', 'on');
set(handles.precision_8, 'Checked', 'off');
set(handles.precision_9, 'Checked', 'off');
set(handles.precision_10, 'Checked', 'off');
set(handles.precision_12, 'Checked', 'off');
set(handles.precision_15, 'Checked', 'off');
set(handles.precision_3, 'Checked', 'off');
set(handles.precision_4, 'Checked', 'off');

setappdata(0, 'automatic_precision_type', 'default');

set(handles.default_auto, 'Checked', 'on');
set(handles.smart_auto, 'Checked', 'off');

% optimiser and verbosity

setappdata(0, 'error_verbosity', 'normal');
set(handles.verbosity_low, 'Checked', 'off');
set(handles.verbosity_normal, 'Checked', 'on');
set(handles.verbosity_high, 'Checked', 'off');

set(handles.verbose_disabled, 'Checked', 'on');
set(handles.verbose_iteration, 'Checked', 'off');
set(handles.verbose_notify, 'Checked', 'off');
set(handles.verbose_final, 'Checked', 'off');

% icons visibility menu options

set(handles.show_icons, 'Checked', 'on');
set(handles.hide_icons, 'Checked', 'off');

% model display options

setappdata(0, 'display_shape_model', '0');
set(handles.display_shape_model_menu, 'Checked', 'off');

setappdata(0, 'display_intensity_model', '0');
set(handles.display_intensity_model_menu, 'Checked', 'off');

% point stuffing options

setappdata(0, 'add_points', '0');
set(handles.add_points_menu, 'Checked', 'off');

setappdata(0, 'add_points_cycle', '1');

set(handles.point_stuffing_cycle_1, 'Checked', 'on');
set(handles.point_stuffing_cycle_10, 'Checked', 'off');
set(handles.point_stuffing_cycle_100, 'Checked', 'off');


setappdata(0, 'plot_alignment', '0');


set(handles.save_model_option, 'Value', 0); 
set(handles.save_model_option, 'Enable', 'off'); 

set(handles.score_model_by_menu, 'Enable', 'off');

% calculation cycle for display of score

set(handles.cycle, 'String', '1');
set(handles.cycle, 'Enable', 'off');

set(handles.cycle_slider, 'Enable', 'off');
set(handles.cycle_label, 'Enable', 'off');



set(handles.save_stats, 'String', '1');
set(handles.save_stats_menu, 'Checked', 'on');

set(handles.show_target, 'String', '0');
set(handles.show_target_option, 'Enable', 'off');

% knot-point placement methods

set(handles.spline_type_display, 'String', 'single_point');
set(handles.placement_method_display, 'String', 'random_and_scale');

set(handles.single_point_option, 'Value', 1);
set(handles.multi_point_option, 'Value', 0);
set(handles.random_option, 'Value', 0);
set(handles.edges_option, 'Value', 0);
set(handles.grid_option, 'Value', 0);
set(handles.alternating_grid_option, 'Value', 0);
set(handles.random_and_Scale_option, 'Value', 1);
set(handles.overlap_grid_option, 'Value', 0);
set(handles.edges_and_scale_option, 'Value', 0);

set(handles.apply_corrective_offset_option, 'Value', 0);

set(handles.knot_points, 'String', '5');

set(handles.random_option, 'Enable', 'off');
set(handles.edges_option, 'Enable', 'off');
set(handles.grid_option, 'Enable', 'off');
set(handles.alternating_grid_option, 'Enable', 'off');
set(handles.random_and_Scale_option, 'Enable', 'on');
set(handles.overlap_grid_option, 'Enable', 'on');
set(handles.edges_and_scale_option, 'Enable', 'on');

% data display options

set(handles.show_plots_throughout_option, 'Value', 0);
set(handles.show_pixels_throughout_option, 'Value', 0);
set(handles.show_mesh_throughout_option, 'Value', 0);

% saving options (for videos)

set(handles.save_plots_option, 'Value', 0);
set(handles.save_pixels_option, 'Value', 1);
set(handles.save_mesh_option, 'Value', 0);
set(handles.save_video_option, 'Value', 0);


set(handles.find_specificity_option, 'Value', 0);
set(handles.repeatedly_show_model_option, 'Value', 0);




set(handles.show_target_option, 'Value', 0);



set(handles.show_statistics_option, 'Value', 0);

% smoothing options

set(handles.smoothing_disabled_option, 'Value', 1);
set(handles.gaussian_smoothing_option, 'Value', 0);
set(handles.average_smoothing_option, 'Value', 0);

set(handles.gaussian_smoothing, 'String', '0');
set(handles.average_smoothing, 'String', '0');

set(handles.window, 'String', '');
set(handles.window_size, 'String', '');
set(handles.smoothing_slider, 'Enable', 'off');

% objective function buttons

set(handles.sequential_msd_option, 'Value', 0);
set(handles.sequential_model_option, 'Value', 0);
set(handles.joint_msd_option, 'Value', 0);
set(handles.joint_model_option, 'Value', 1);
set(handles.show_final_model_option, 'Value', 0);
set(handles.show_score_vs_iteration_option, 'Value', 0);
set(handles.show_score_while_optimising_option, 'Value', 0);
set(handles.sequential_mi_option, 'Value', 0);
set(handles.sequential_nmi_option, 'Value', 0);
set(handles.joint_mi_option, 'Value', 0);
set(handles.joint_nmi_option, 'Value', 0);
set(handles.mixed_msd_model_option, 'Value', 0);
set(handles.model_post_msd_option, 'Value', 0);
set(handles.tfceccv, 'Value', 0);

% objective function menu        
        
set(handles.objective_function_display, 'String', 'model_opt_together');

set(handles.sequential_mi_option_menu, 'Checked', 'off');
set(handles.sequential_nmi_option_menu, 'Checked', 'off');
set(handles.joint_msd_option_menu, 'Checked', 'off');
set(handles.joint_model_option_menu, 'Checked', 'on');
set(handles.sequential_msd_option_menu, 'Checked', 'off');
set(handles.sequential_model_option_menu, 'Checked', 'off');
set(handles.mixed_msd_model_option_menu, 'Checked', 'off');
set(handles.model_post_msd_option_menu, 'Checked', 'off');
set(handles.joint_mi_option_menu, 'Checked', 'off');
set(handles.joint_nmi_option_menu, 'Checked', 'off');
set(handles.button_all_objective_functions_menu, 'Checked', 'off');
set(handles.tfceccv_menu, 'Checked', 'off');
set(handles.wavelet_option_menu, 'Checked', 'off');
set(handles.model_pairs_menu, 'Checked', 'off');
set(handles.seq_model_pairs_menu, 'Checked', 'off');


% data save options

set(handles.filename_option, 'Value', 0);

set(handles.export_default, 'Checked', 'off');
set(handles.disable_save, 'Checked', 'off');
set(handles.save_handle, 'Checked', 'on');

set(handles.save_bumps_flag, 'String', '0');
set(handles.save_bumps, 'Checked', 'off');
set(handles.save_data, 'String', '1');

set(handles.save_mesh_option, 'Enable', 'off');
set(handles.save_plots_option, 'Enable', 'off');
set(handles.save_pixels_option, 'Enable', 'off');



set(handles.determinant, 'String', '1');


set(handles.wavelet_option, 'Value', 0);


% automatic weighting term

set(handles.smart_weighting_type, 'Checked', 'off');
set(handles.default_weighting_type, 'Checked', 'on');
set(handles.auto_weighting_menu, 'Checked', 'off');
setappdata(0, 'automatic_weighting_type', 'default');


% file formats section

set(handles.format, 'String', 'png');

set(handles.png, 'Checked', 'on');
set(handles.bmp, 'Checked', 'off');
set(handles.tiff, 'Checked', 'off');
set(handles.jpeg, 'Checked', 'off');
set(handles.hdf, 'Checked', 'off');
set(handles.pcx, 'Checked', 'off');
set(handles.xwd, 'Checked', 'off');
set(handles.ras, 'Checked', 'off');
set(handles.pbm, 'Checked', 'off');
set(handles.pgm, 'Checked', 'off');
set(handles.ppm, 'Checked', 'off');
set(handles.pnm, 'Checked', 'off');

        % check only png, all other must be unchecked


        
% wavelets section

set(handles.compression_type_title, 'Enable', 'off');
set(handles.compression_level_title, 'Enable', 'off');
set(handles.compression, 'Enable', 'off');
set(handles.compression_level, 'Enable', 'off');


set(handles.overlap_scores_option, 'Enable', 'off');

% main controls

set(handles.pause, 'Enable', 'off');
set(handles.resume, 'Enable', 'off');
% PDF options

set(handles.PDF, 'Enable', 'off');
set(handles.Kernel_title, 'Enable', 'off');

% schemes

set(handles.large_test, 'Checked', 'off');
set(handles.large_set, 'Checked', 'off');

% progress indicator modes

set(handles.progress_bar_menu, 'Checked', 'on');
set(handles.hierarchical_text_menu, 'Checked', 'off');
set(handles.quiet_menu, 'Checked', 'off');





% Menu OPEN section

set(handles.load_data, 'String', '6');

set(handles.open_flat, 'Checked', 'off');
set(handles.open_disable, 'Checked', 'off');
set(handles.handle_open, 'Checked', 'off');
set(handles.open_default, 'Checked', 'off');
set(handles.ellipse, 'Checked', 'on');
set(handles.open_default, 'Checked', 'off');
set(handles.open_plain, 'Checked', 'off');
set(handles.open_plainran, 'Checked', 'off');
set(handles.generate_simple_bump, 'Checked', 'off');

set(handles.verbose_optimiser_flag, 'String', 'off');



set(handles.produce_record_button, 'Value', 0);

set(handles.draw_warp_curve, 'String', '0');
set(handles.show_warp_targets, 'String', '0');

set(handles.overlap_scores, 'String', '0');
set(handles.overlap_scores_option, 'Value', 0);

set(handles.spec_iters, 'String', '25');
set(handles.gen_iters, 'String', '25');

% alignment and perturbation

set(handles.initialise_warps_close_to_target, 'String', '0');
set(handles.initialise_warps_close_to_target_button, 'Value', 0);

set(handles.perturb_option_button, 'Enable', 'off');
set(handles.perturb_option_menuentry, 'Enable', 'off');







set(handles.frames_per_second, 'String', '15');

set(handles.plot_alignment_button, 'Value', 0);

 
set(handles.model_score_type, 'String', 'Default');
set(handles.use_filename, 'String', '0');

set(handles.produce_record, 'String', '0');
set(handles.show_statistics, 'String', '0');

set(handles.draw_curve_by_images, 'String', '0');
set(handles.apply_corrective_offset, 'String', '0');

set(handles.show_plot, 'String', '0');
set(handles.show_pixels, 'String', '0');

set(handles.show_registration_target_flag, 'String', '0');
set(handles.show_registration_target, 'Enable', 'off');
set(handles.show_registration_target, 'value', 0);

set(handles.save_pixels, 'String', '0');
set(handles.save_video, 'String', '0');

set(handles.find_specificity, 'String', '0');
set(handles.repeatedly_show_model, 'String', '0');

set(handles.show_final_model, 'String', '0');
set(handles.show_score_vs_iteration, 'String', '0');
set(handles.show_score_while_optimising, 'String', '0');



set(handles.use_defaults, 'String', '1');

set(handles.hierarchical_text, 'String', '1');

set(handles.plot_before_and_after, 'String', '0');
set(handles.always_score_by_model, 'String', '0');

% Ws Weighting

set(handles.constant, 'Value', 1);
set(handles.edge, 'Value', 0);
set(handles.variance, 'Value', 0);
set(handles.text108, 'String', 'constant');
set(handles.model_weight_constant_value, 'String', '0');
set(handles.model_weight_constant_value, 'Enable', 'on');
set(handles.constant_value_text, 'Enable', 'on');

set(handles.model_weight_slider, 'Value', 0);
set(handles.model_weight_slider, 'Enable', 'on');

% set default background colours to required colour

setappdata(0, 'background_colour_red', '0.84');
setappdata(0, 'background_colour_green', '0.84');
setappdata(0, 'background_colour_blue', '1');


% bins options

set(handles.number_of_bins_text, 'Enable', 'off');
set(handles.number_of_bins_slider, 'Enable', 'off');

set(handles.number_of_bins, 'Enable', 'off');
set(handles.number_of_bins_slider, 'Value', 50);

set(handles.number_of_bins, 'String', '50');



set(handles.number_of_modes_slider, 'Value', 20);


set(handles.variation_kept_slider, 'Value', 98);
set(handles.button_all_objective_functions, 'Value', 0);






% misc.

setappdata(0, 'point_insertion_position', 'highest_model_discrepancy');

set(handles.steepest_warp_menu, 'Checked', 'off');
set(handles.highest_model_discrepancy_menu, 'Checked', 'on');


set(handles.show_model_reconstruction_for_warped_images, 'Checked', 'off');

set(handles.show_inverse_projection, 'Checked', 'off');

set(handles.all_objective_functions, 'String', '0');

set(handles.file_for_video_box, 'Enable', 'off');

set(handles.filename_option, 'Enable', 'off');

set(handles.show_plots_at_end_option, 'Value', 0);
set(handles.always_score_by_model_option, 'Value', 0);

set(handles.filename_handle, 'String', 'Default');
set(handles.description, 'String', 'Default');

% paramaters choice

set(handles.overnight1, 'Checked', 'off');
set(handles.overnight2, 'Checked', 'off');
set(handles.overnight3, 'Checked', 'off');

set(handles.normal_test, 'Checked', 'off')
set(handles.max_test, 'Checked', 'off')
set(handles.user_menus, 'Checked', 'on');
set(handles.default_parameters, 'Checked', 'off');

 

% set accelerators

set(handles.Register, 'Accelerator', 'R');
set(handles.Reset, 'Accelerator', 'E');
set(handles.Exit, 'Accelerator', 'Q');
set(handles.Quit_MATLAB, 'Accelerator', 'Z');
set(handles.clear_status_bar, 'Accelerator', 'T');
set(handles.show_warps_while_optimising, 'Accelerator', 'D');

set(handles.display_shape_model_menu, 'Accelerator', 'G');
set(handles.display_intensity_model_menu, 'Accelerator', 'I');
set(handles.user_menus, 'Accelerator', '1');
set(handles.default_parameters, 'Accelerator', '2');
set(handles.normal_test, 'Accelerator', '3');
set(handles.large_test, 'Accelerator', '4');
set(handles.max_test, 'Accelerator', '5');
set(handles.large_set, 'Accelerator', '6');
set(handles.overnight1, 'Accelerator', '7');
set(handles.overnight2, 'Accelerator', '8');
set(handles.overnight3, 'Accelerator', '9');

set(handles.find_perfect_warp_menu, 'Accelerator', 'F');
set(handles.save_stats_menu, 'Accelerator', 'M');
set(handles.perturb_option_menuentry, 'Accelerator', 'B');
set(handles.automation_menu, 'Accelerator', 'A');
set(handles.advanced, 'Accelerator', 'K');
set(handles.bug, 'Accelerator', 'U');
set(handles.aart_on_line, 'Accelerator', 'N');
set(handles.Using_AART, 'Accelerator', 'H');



% set message in the status bar

message = [['Autonomous Appearance-based Registration Test-bed  '];
    ['                                                   '];
    ['Imaging Science and Biomedical Engineering         '];
    ['                                                   '];          
    ['Victoria University of Manchester                  ']];

% set up a preliminary message to be sent to the status bar. please note
% that the message (matrix) must be rectangular.

set(handles.status_bar, 'String', message);

% set the status bar to display a welcoming message

% ==================================================================== %     

% The following are schemes, i.e. settings that are useful to carry out
% specific types of experiments. Note that these will need to be modified
% with the functions they reference. Some buttons will be controlled not
% only by the callback and the initialisation, but also all schemes.

function scheme_20_set_experiment_Callback(hObject, eventdata, handles)

    set(handles.determinant, 'String', '2');
    set(handles.show_target_option, 'Enable', 'on');
    set(handles.show_registration_target, 'Enable', 'on');
    
    set(handles.show_registration_target, 'Value', 1);
    set(handles.show_registration_target_flag, 'String', '1'); 
    
    set(handles.show_score_vs_iteration_option, 'Value', 1);
    set(handles.show_score_vs_iteration, 'String', '1');
    
    set(handles.show_plots_at_end_option, 'Value', 1);
    set(handles.plot_before_and_after, 'String', '1');
    
    set(handles.overnight1, 'Checked', 'on');
    set(handles.overnight2, 'Checked', 'off');
    set(handles.overnight3, 'Checked', 'off');
	set(handles.user_menus, 'Checked', 'off');
	set(handles.default_parameters, 'Checked', 'off');
	set(handles.max_test, 'Checked', 'off');
	set(handles.normal_test, 'Checked', 'off');
	set(handles.large_test, 'Checked', 'off');
	set(handles.large_set, 'Checked', 'off');
	set(handles.use_defaults, 'String', '6');

% ==================================================================== %         

function scheme_regular_set_auto_Callback(hObject, eventdata, handles)

    set(handles.determinant, 'String', '2');
    set(handles.show_target_option, 'Enable', 'on');
    set(handles.show_registration_target, 'Enable', 'on');
    
    set(handles.show_registration_target, 'Value', 1);
    set(handles.show_registration_target_flag, 'String', '1'); 
    
    set(handles.show_score_vs_iteration_option, 'Value', 1);
    set(handles.show_score_vs_iteration, 'String', '1');
    
    set(handles.show_plots_at_end_option, 'Value', 1);
    set(handles.plot_before_and_after, 'String', '1');
    
    set(handles.overnight1, 'Checked', 'off');
    set(handles.overnight2, 'Checked', 'on');
    set(handles.overnight3, 'Checked', 'off');
	set(handles.user_menus, 'Checked', 'off');
	set(handles.default_parameters, 'Checked', 'off');
	set(handles.max_test, 'Checked', 'off');
	set(handles.normal_test, 'Checked', 'off');
	set(handles.large_test, 'Checked', 'off');
	set(handles.large_set, 'Checked', 'off');
	set(handles.use_defaults, 'String', '7');
    
    set(handles.dynamic_precision, 'Checked', 'on');
    setappdata(0, 'dynamic_precision', '1');

% ==================================================================== %     
    
% The following function draws the data samples in the appropriate frame.
% It is called from various functions when the samples need to be redrawn.

function draw_data(hObject, eventdata, handles)

if (str2num(get(handles.samples_flag, 'String')) == 1),
    n_examples = 6;
    resolution = 50;
    
    % the resultion is the number of pixels (horizontal) used to create the
    % bump and n_examples defines the number of plots to be generated.
    
    
    [imagelist, images, points] = make_1d_bump(n_examples, resolution, str2num(get(handles.bump_width, 'String')),...
        str2num(get(handles.bump_width_variation, 'String')), str2num(get(handles.bump_height, 'String')),...
        str2num(get(handles.bump_height_variation, 'String')), str2num(get(handles.bump_position_freedom, 'String')),...
        str2num(get(handles.initial_diminish_factor, 'String'))...
        , str2num(get(handles.smoothness_factor, 'String')), 0, get(handles.format, 'String')); % 0 means do not save images
    
    colour = [0.2,0.2,0.2]; 
    % a cycle of colours is defined here so that at each 
    % iteration a different colour is picked
    axes(handles.samples);
    plot([0]);
    hold on;
    for i=1:n_examples,
        if (colour ==[0.2,0.2,0.2]),
            colour = [0.4,0.4,0.4];
        elseif (colour ==[0.4,0.4,0.4]),
            colour = [0.6,0.6,0.6];
        else
            colour = [0.2,0.2,0.2];
        end 
        plot(images(:,i),'color', colour);
    end
    axis off;
    % do not display the clutter around the drawing region
    axis([0 resolution 0 1]); % set the size of the plot
    hold off;
end

% ==================================================================== % 

function random_option_Callback(hObject, eventdata, handles)

set(handles.random_option, 'Value', 1);
set(handles.edges_option, 'Value', 0);
set(handles.grid_option, 'Value', 0);
set(handles.random_and_Scale_option, 'Value', 0);
set(handles.overlap_grid_option, 'Value', 0);
set(handles.edges_and_scale_option, 'Value', 0);
set(handles.alternating_grid_option, 'Value', 0);

set(handles.placement_method_display, 'String', 'random');

% ==================================================================== % 

function edges_option_Callback(hObject, eventdata, handles)

set(handles.random_option, 'Value', 0);
set(handles.edges_option, 'Value', 1);
set(handles.grid_option, 'Value', 0);
set(handles.random_and_Scale_option, 'Value', 0);
set(handles.overlap_grid_option, 'Value', 0);
set(handles.edges_and_scale_option, 'Value', 0);
set(handles.alternating_grid_option, 'Value', 0);

set(handles.placement_method_display, 'String', 'edge');

% ==================================================================== % 

function grid_option_Callback(hObject, eventdata, handles)

set(handles.random_option, 'Value', 0);
set(handles.edges_option, 'Value', 0);
set(handles.grid_option, 'Value', 1);
set(handles.random_and_Scale_option, 'Value', 0);
set(handles.overlap_grid_option, 'Value', 0);
set(handles.edges_and_scale_option, 'Value', 0);
set(handles.alternating_grid_option, 'Value', 0);

set(handles.placement_method_display, 'String', 'grid');

% ==================================================================== % 

function random_and_Scale_option_Callback(hObject, eventdata, handles)

set(handles.random_option, 'Value', 0);
set(handles.edges_option, 'Value', 0);
set(handles.grid_option, 'Value', 0);
set(handles.random_and_Scale_option, 'Value', 1);
set(handles.overlap_grid_option, 'Value', 0);
set(handles.edges_and_scale_option, 'Value', 0);
set(handles.alternating_grid_option, 'Value', 0);

set(handles.placement_method_display, 'String', 'random_and_scale');

% ==================================================================== % 

function alternating_grid_option_Callback(hObject, eventdata, handles)

set(handles.random_option, 'Value', 0);
set(handles.edges_option, 'Value', 0);
set(handles.grid_option, 'Value', 0);
set(handles.random_and_Scale_option, 'Value', 0);
set(handles.overlap_grid_option, 'Value', 0);
set(handles.edges_and_scale_option, 'Value', 0);
set(handles.alternating_grid_option, 'Value', 1);

set(handles.placement_method_display, 'String', 'alternating_grid');

% ==================================================================== % 

function single_point_option_Callback(hObject, eventdata, handles)

set(handles.single_point_option, 'Value', 1);
set(handles.multi_point_option, 'Value', 0);

set(handles.random_option, 'Enable', 'off');
set(handles.edges_option, 'Enable', 'off');
set(handles.grid_option, 'Enable', 'off');
set(handles.alternating_grid_option, 'Enable', 'off');

set(handles.random_and_Scale_option, 'Enable', 'on');
set(handles.overlap_grid_option, 'Enable', 'on');
set(handles.edges_and_scale_option, 'Enable', 'on');

set(handles.random_and_Scale_option, 'Value', 1);
set(handles.random_option, 'Value', 0);
set(handles.edges_option, 'Value', 0);
set(handles.grid_option, 'Value', 0);
set(handles.overlap_grid_option, 'Value', 0);
set(handles.edges_and_scale_option, 'Value', 0);
set(handles.alternating_grid_option, 'Value', 0);
set(handles.placement_method_display, 'String', 'random_and_scale');
set(handles.spline_type_display, 'String', 'single_point');

% ==================================================================== % 

function multi_point_option_Callback(hObject, eventdata, handles)

set(handles.single_point_option, 'Value', 0);
set(handles.multi_point_option, 'Value', 1);
set(handles.spline_type_display, 'String', 'multi_point');
set(handles.random_option, 'Enable', 'on');
set(handles.edges_option, 'Enable', 'on');
set(handles.grid_option, 'Enable', 'on');
set(handles.random_and_Scale_option, 'Enable', 'off');
set(handles.overlap_grid_option, 'Enable', 'off');
set(handles.edges_and_scale_option, 'Enable', 'off');
set(handles.alternating_grid_option, 'Enable', 'on');
set(handles.random_and_Scale_option, 'Value', 0);
set(handles.random_option, 'Value', 1);
set(handles.edges_option, 'Value', 0);
set(handles.grid_option, 'Value', 0);
set(handles.overlap_grid_option, 'Value', 0);
set(handles.edges_and_scale_option, 'Value', 0);
set(handles.alternating_grid_option, 'Value', 0);
set(handles.placement_method_display, 'String', 'random');

% ==================================================================== % 

function overlap_grid_option_Callback(hObject, eventdata, handles)

set(handles.random_option, 'Value', 0);
set(handles.edges_option, 'Value', 0);
set(handles.grid_option, 'Value', 0);
set(handles.random_and_Scale_option, 'Value', 0);
set(handles.overlap_grid_option, 'Value', 1);
set(handles.edges_and_scale_option, 'Value', 0);
set(handles.alternating_grid_option, 'Value', 0);

set(handles.placement_method_display, 'String', 'overlap_grid');

% ==================================================================== % 

function edges_and_scale_option_Callback(hObject, eventdata, handles)

set(handles.random_option, 'Value', 0);
set(handles.edges_option, 'Value', 0);
set(handles.grid_option, 'Value', 0);
set(handles.random_and_Scale_option, 'Value', 0);
set(handles.overlap_grid_option, 'Value', 0);
set(handles.edges_and_scale_option, 'Value', 1);
set(handles.alternating_grid_option, 'Value', 0);

set(handles.placement_method_display, 'String', 'edge_and_scale');

% ==================================================================== % 

function apply_corrective_offset_option_Callback(hObject, eventdata, handles)

if (get(handles.apply_corrective_offset_option,'Value') == 0),
    set(handles.apply_corrective_offset_option, 'Value', 0);
    set(handles.apply_corrective_offset, 'String', '0');
else
    set(handles.apply_corrective_offset_option, 'Value', 1);
    set(handles.apply_corrective_offset, 'String', '1');  
end    

% ==================================================================== % 

function show_plots_throughout_option_Callback(hObject, eventdata, handles)

if (get(handles.show_plots_throughout_option,'Value') == 0),
    set(handles.show_plots_throughout_option, 'Value', 0);
    set(handles.show_plot, 'String', '0');
else
    set(handles.show_plots_throughout_option, 'Value', 1);
    set(handles.show_plot, 'String', '1');  
end    

% ==================================================================== % 

function show_pixels_throughout_option_Callback(hObject, eventdata, handles)

if (get(handles.show_pixels_throughout_option,'Value') == 0),
    set(handles.show_pixels_throughout_option, 'Value', 0);
    set(handles.show_pixels, 'String', '0');
else
    set(handles.show_pixels_throughout_option, 'Value', 1);
    set(handles.show_pixels, 'String', '1');
end    

% ==================================================================== % 

function save_video_option_Callback(hObject, eventdata, handles)

if (get(handles.save_video_option,'Value') == 0),
    set(handles.save_video_option, 'Value', 0);
    set(handles.save_video, 'String', '0');  
    set(handles.save_plots_option, 'Enable', 'off');
    set(handles.save_pixels_option, 'Enable', 'off');
    set(handles.save_mesh_option, 'Enable', 'off');
    set(handles.save_model_option, 'Enable', 'off');    
    set(handles.filename_option, 'Enable', 'off');
else
    set(handles.save_video_option, 'Value', 1);
    set(handles.save_video, 'String', '1'); 
    set(handles.save_plots_option, 'Enable', 'on');
    set(handles.save_model_option, 'Enable', 'on');    
     set(handles.save_mesh_option, 'Enable', 'on');
    set(handles.save_pixels_option, 'Enable', 'on');
    set(handles.filename_option, 'Enable', 'on');
end

if (get(handles.filename_option,'Value') == 0),
    set(handles.file_for_video_box, 'Enable', 'off');
else
    set(handles.file_for_video_box, 'Enable', 'on'); 
end

% ==================================================================== % 

function find_specificity_option_Callback(hObject, eventdata, handles)

if (get(handles.find_specificity_option,'Value') == 0),
    set(handles.find_specificity_option, 'Value', 0);
    set(handles.find_specificity, 'String', '0');
else
    set(handles.find_specificity_option, 'Value', 1);
    set(handles.find_specificity, 'String', '1');  
end    

% ==================================================================== % 

function repeatedly_show_model_option_Callback(hObject, eventdata, handles)

if (get(handles.repeatedly_show_model_option,'Value') == 0),
    set(handles.repeatedly_show_model_option, 'Value', 0);
    set(handles.repeatedly_show_model, 'String', '0');
else
    set(handles.repeatedly_show_model_option, 'Value', 1);
    set(handles.repeatedly_show_model, 'String', '1');  
end    

% ==================================================================== % 

function show_final_model_option_Callback(hObject, eventdata, handles)

if (get(handles.show_final_model_option,'Value') == 0),
    set(handles.show_final_model_option, 'Value', 0);
    set(handles.show_final_model, 'String', '0');
else
    set(handles.show_final_model_option, 'Value', 1);
    set(handles.show_final_model, 'String', '1');  
end    

% ==================================================================== % 

function show_score_vs_iteration_option_Callback(hObject, eventdata, handles)

if (get(handles.show_score_vs_iteration_option,'Value') == 0),
    set(handles.show_score_vs_iteration_option, 'Value', 0);
    set(handles.show_score_vs_iteration, 'String', '0');
else
    set(handles.show_score_vs_iteration_option, 'Value', 1);
    set(handles.show_score_vs_iteration, 'String', '1');  
end   

% ==================================================================== % 

function show_score_while_optimising_option_Callback(hObject, eventdata, handles)

if (get(handles.show_score_while_optimising_option,'Value') == 0),
    set(handles.show_score_while_optimising_option, 'Value', 0);
    set(handles.show_score_while_optimising, 'String', '0');
else
    set(handles.show_score_while_optimising_option, 'Value', 1);
    set(handles.show_score_while_optimising, 'String', '1');  
end

% ==================================================================== % 

function show_statistics_option_Callback(hObject, eventdata, handles)

if (get(handles.show_statistics_option,'Value') == 0),
    set(handles.show_statistics_option, 'Value', 0);
    set(handles.show_statistics, 'String', '0');
else
    set(handles.show_statistics_option, 'Value', 1);
    set(handles.show_statistics, 'String', '1');  
end    

% ==================================================================== % 

function save_plots_option_Callback(hObject, eventdata, handles)

set(handles.save_plots_option, 'Value', 1);
set(handles.save_pixels_option, 'Value', 0);
set(handles.save_mesh_option, 'Value', 0);
set(handles.save_model_option, 'Value', 0);

set(handles.save_pixels, 'String', '1');

% ==================================================================== % 

function save_pixels_option_Callback(hObject, eventdata, handles)

set(handles.save_plots_option, 'Value', 0);
set(handles.save_pixels_option, 'Value', 1);
set(handles.save_mesh_option, 'Value', 0);
set(handles.save_model_option, 'Value', 0);

set(handles.save_pixels, 'String', '0');

% ==================================================================== % 

function Help_Callback(hObject, eventdata, handles)

% ==================================================================== % 

function File_Callback(hObject, eventdata, handles)

% ==================================================================== % 

function Exit_Callback(hObject, eventdata, handles)

close;

% ==================================================================== % 

function About_Callback(hObject, eventdata, handles)

about;

% ==================================================================== % 

function reset_Callback(hObject, eventdata, handles)

% reset invocation should result in the application returning to its
% starting state

initialize_gui(hObject, handles);

% ==================================================================== % 

function Matlab_Help_Callback(hObject, eventdata, handles)

% the internal helpdesk for MATLAB

helpdesk;

% ==================================================================== % 

function filename_option_Callback(hObject, eventdata, handles)

if (get(handles.filename_option,'Value') == 0),
    set(handles.filename_option, 'Value', 0);
    set(handles.use_filename, 'String', '0');
    set(handles.file_for_video_box, 'Enable', 'off');
else
    set(handles.filename_option, 'Value', 1);
    set(handles.use_filename, 'String', '1'); 
    set(handles.file_for_video_box, 'Enable', 'on');
end  

% ==================================================================== % 

function file_for_video_box_CreateFcn(hObject, eventdata, handles)

if ispc
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end

% ==================================================================== % 

function file_for_video_box_Callback(hObject, eventdata, handles)

% ==================================================================== % 

function smoothing_disabled_option_Callback(hObject, eventdata, handles)

set(handles.smoothing_disabled_option, 'Value', 1);
set(handles.gaussian_smoothing_option, 'Value', 0);
set(handles.average_smoothing_option, 'Value', 0);
set(handles.gaussian_smoothing, 'String', '0');
set(handles.average_smoothing, 'String', '0');
set(handles.smoothing_slider, 'Enable', 'off');
set(handles.window_size, 'String', '');
set(handles.window, 'String', '');

% ==================================================================== % 

function gaussian_smoothing_option_Callback(hObject, eventdata, handles)

set(handles.smoothing_disabled_option, 'Value', 0);
set(handles.gaussian_smoothing_option, 'Value', 1);
set(handles.average_smoothing_option, 'Value', 0);
set(handles.gaussian_smoothing, 'String', '1');
set(handles.average_smoothing, 'String', '0');
set(handles.smoothing_slider, 'Enable', 'on');
set(handles.window, 'String', num2str(ceil(get(handles.smoothing_slider, 'Value'))));
set(handles.window_size, 'String', 'Sigma:');

% ==================================================================== % 

function average_smoothing_option_Callback(hObject, eventdata, handles)

set(handles.smoothing_disabled_option, 'Value', 0);
set(handles.gaussian_smoothing_option, 'Value', 0);
set(handles.average_smoothing_option, 'Value', 1);
set(handles.average_smoothing, 'String', '1');
set(handles.gaussian_smoothing, 'String', '0');
set(handles.smoothing_slider, 'Enable', 'on');
set(handles.window, 'String', num2str(ceil(get(handles.smoothing_slider, 'Value'))));
set(handles.window_size, 'String', 'Window size:');

% ==================================================================== % 

function smoothing_slider_CreateFcn(hObject, eventdata, handles)

usewhitebg = 1;
if usewhitebg
    set(hObject,'BackgroundColor',[.9 .9 .9]);
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end

% ==================================================================== % 

function smoothing_slider_Callback(hObject, eventdata, handles)

set(handles.window, 'String', num2str(ceil(get(handles.smoothing_slider, 'Value'))));

% ==================================================================== % 

function status_bar_CreateFcn(hObject, eventdata, handles)


if ispc
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end

% ==================================================================== % 

function status_bar_Callback(hObject, eventdata, handles)

% ==================================================================== % 

function popupmenu2_CreateFcn(hObject, eventdata, handles)

if ispc
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end

% ==================================================================== % 

function popupmenu2_Callback(hObject, eventdata, handles)

% ==================================================================== % 

function popupmenu3_CreateFcn(hObject, eventdata, handles)

if ispc
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end

% ==================================================================== % 

function popupmenu3_Callback(hObject, eventdata, handles)

% ==================================================================== % 

function default_attributes_Callback(hObject, eventdata, handles)

% disable all the bars and set values to defaults before re-drawing 

set(handles.default_attributes, 'Value', 1);
set(handles.specify_attributes, 'Value', 0);

set(handles.attr_height, 'Enable', 'off');
set(handles.attr_low_var, 'Enable', 'off');
set(handles.attr_typical, 'Enable', 'off');

set(handles.base_height_slider, 'Enable', 'off');
set(handles.position_freedom_slider, 'Enable', 'off');
set(handles.height_variation_slider, 'Enable', 'off');
set(handles.width_variation_slider, 'Enable', 'off');
set(handles.base_width_slider, 'Enable', 'off');
set(handles.smoothness_slider, 'Enable', 'off');
set(handles.base_height_text, 'Enable', 'off');
set(handles.width_variation_text, 'Enable', 'off');
set(handles.height_variation_text, 'Enable', 'off');
set(handles.base_width_text, 'Enable', 'off');
set(handles.position_freedom_text, 'Enable', 'off');
set(handles.smoothness_text, 'Enable', 'off');

set(handles.bump_width, 'String', '0.5');
set(handles.bump_width_variation, 'String', '0.2');
set(handles.bump_height, 'String', '0.2');
set(handles.bump_height_variation, 'String', '0.7');
set(handles.bump_position_freedom, 'String', '0.9');
set(handles.initial_diminish_factor, 'String', '1');
set(handles.smoothness_factor, 'String', '17');

draw_data(hObject, eventdata, handles);

% ==================================================================== % 

function specify_attributes_Callback(hObject, eventdata, handles)

set(handles.default_attributes, 'Value', 0);
set(handles.specify_attributes, 'Value', 1);
set(handles.base_height_text, 'Enable', 'on');
set(handles.width_variation_text, 'Enable', 'on');
set(handles.height_variation_text, 'Enable', 'on');
set(handles.base_width_text, 'Enable', 'on');
set(handles.position_freedom_text, 'Enable', 'on');
set(handles.smoothness_text, 'Enable', 'on');
set(handles.base_height_slider, 'Enable', 'on');
set(handles.position_freedom_slider, 'Enable', 'on');
set(handles.height_variation_slider, 'Enable', 'on');
set(handles.width_variation_slider, 'Enable', 'on');
set(handles.base_width_slider, 'Enable', 'on');
set(handles.smoothness_slider, 'Enable', 'on');

set(handles.attr_height, 'Enable', 'on');
set(handles.attr_low_var, 'Enable', 'on');
set(handles.attr_typical, 'Enable', 'on');

set(handles.bump_height, 'String', num2str(get(handles.base_height_slider, 'Value')));
set(handles.bump_position_freedom, 'String', num2str(get(handles.position_freedom_slider, 'Value')));
set(handles.bump_height_variation, 'String', num2str(get(handles.height_variation_slider, 'Value')));
set(handles.bump_width_variation, 'String', num2str(get(handles.width_variation_slider, 'Value')));
set(handles.bump_width, 'String', num2str(get(handles.base_width_slider, 'Value')));
set(handles.smoothness_factor, 'String', num2str(get(handles.smoothness_slider, 'Value')));

draw_data(hObject, eventdata, handles);

% ==================================================================== % 

function popupmenu4_CreateFcn(hObject, eventdata, handles)

if ispc
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end

% ==================================================================== % 

function radiobutton44_Callback(hObject, eventdata, handles)

% ==================================================================== % 

function radiobutton45_Callback(hObject, eventdata, handles)

% ==================================================================== % 

function base_height_slider_CreateFcn(hObject, eventdata, handles)

usewhitebg = 1;
if usewhitebg
    set(hObject,'BackgroundColor',[.9 .9 .9]);
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end

% ==================================================================== % 

function base_height_slider_Callback(hObject, eventdata, handles)

set(handles.bump_height, 'String', num2str(get(handles.base_height_slider, 'Value')));
draw_data(hObject, eventdata, handles);

% ==================================================================== % 

function position_freedom_slider_CreateFcn(hObject, eventdata, handles)

usewhitebg = 1;
if usewhitebg
    set(hObject,'BackgroundColor',[.9 .9 .9]);
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end

% ==================================================================== % 

function position_freedom_slider_Callback(hObject, eventdata, handles)

set(handles.bump_position_freedom, 'String', num2str(get(handles.position_freedom_slider, 'Value')));
draw_data(hObject, eventdata, handles);

% ==================================================================== % 

function height_variation_slider_CreateFcn(hObject, eventdata, handles)

usewhitebg = 1;
if usewhitebg
    set(hObject,'BackgroundColor',[.9 .9 .9]);
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end

% ==================================================================== % 

function height_variation_slider_Callback(hObject, eventdata, handles)

set(handles.bump_height_variation, 'String', num2str(get(handles.height_variation_slider, 'Value')));
draw_data(hObject, eventdata, handles);

% ==================================================================== % 

function width_variation_slider_CreateFcn(hObject, eventdata, handles)

usewhitebg = 1;
if usewhitebg
    set(hObject,'BackgroundColor',[.9 .9 .9]);
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end

% ==================================================================== % 

function width_variation_slider_Callback(hObject, eventdata, handles)

set(handles.bump_width_variation, 'String', num2str(get(handles.width_variation_slider, 'Value')));
draw_data(hObject, eventdata, handles);

% ==================================================================== % 

function base_width_slider_CreateFcn(hObject, eventdata, handles)

usewhitebg = 1;
if usewhitebg
    set(hObject,'BackgroundColor',[.9 .9 .9]);
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end

% ==================================================================== % 

function base_width_slider_Callback(hObject, eventdata, handles)

set(handles.bump_width, 'String', num2str(get(handles.base_width_slider, 'Value')));
draw_data(hObject, eventdata, handles);

% ==================================================================== % 

function Using_AART_Callback(hObject, eventdata, handles)

web http://www.danielsorogon.com/Webmaster/Projects/AART/help.htm

% ==================================================================== % 

function Quit_MATLAB_Callback(hObject, eventdata, handles)

exit;

% ==================================================================== % 

function bug_Callback(hObject, eventdata, handles)

web http://www.danielsorogon.com/Webmaster/Feedback

% ==================================================================== % 

function view_Callback(hObject, eventdata, handles)

% ==================================================================== % 

function tools_Callback(hObject, eventdata, handles)

% ==================================================================== % 

function smoothness_slider_CreateFcn(hObject, eventdata, handles)

usewhitebg = 1;
if usewhitebg
    set(hObject,'BackgroundColor',[.9 .9 .9]);
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end

% ==================================================================== % 

function smoothness_slider_Callback(hObject, eventdata, handles)

set(handles.smoothness_factor, 'String', num2str(get(handles.smoothness_slider, 'Value')));
draw_data(hObject, eventdata, handles);

% ==================================================================== % 

function exit_button_Callback(hObject, eventdata, handles)

close;

% ==================================================================== % 

function show_plots_at_end_option_Callback(hObject, eventdata, handles)

if (get(handles.show_plots_at_end_option,'Value') == 0),
    set(handles.show_plots_at_end_option, 'Value', 0);
    set(handles.plot_before_and_after, 'String', '0');
else
    set(handles.show_plots_at_end_option, 'Value', 1);
    set(handles.plot_before_and_after, 'String', '1');  
end

% ==================================================================== % 

function aart_on_line_Callback(hObject, eventdata, handles)

web http://www.danielsorogon.com/Webmaster/Projects/AART

% ==================================================================== % 

function number_of_bins_slider_CreateFcn(hObject, eventdata, handles)

usewhitebg = 1;
if usewhitebg
    set(hObject,'BackgroundColor',[.9 .9 .9]);
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end

% ==================================================================== % 

function number_of_bins_slider_Callback(hObject, eventdata, handles)

set(handles.number_of_bins, 'String', num2str(ceil(get(handles.number_of_bins_slider, 'Value'))));

% ==================================================================== %

function always_score_by_model_option_Callback(hObject, eventdata, handles)

set(handles.always_score_by_model, 'String', '0');
if (get(handles.always_score_by_model_option,'Value') == 0),
    set(handles.always_score_by_model_option, 'Value', 0);
    set(handles.always_score_by_model, 'String', '0');
    set(handles.score_model_by_menu, 'Enable', 'off');
    set(handles.cycle, 'Enable', 'off');
    set(handles.cycle_slider, 'Enable', 'off');
    set(handles.cycle_label, 'Enable', 'off');
else
    set(handles.always_score_by_model_option, 'Value', 1);
    set(handles.always_score_by_model, 'String', '1');
    set(handles.score_model_by_menu, 'Enable', 'on');
    set(handles.cycle, 'Enable', 'on');
    set(handles.cycle_slider, 'Enable', 'on');
    set(handles.cycle_label, 'Enable', 'on');
end

% ==================================================================== % 

function filename_handle_CreateFcn(hObject, eventdata, handles)

if ispc
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end

% ==================================================================== % 

function filename_handle_Callback(hObject, eventdata, handles)

% ==================================================================== % 

function pause_Callback(hObject, eventdata, handles)

set(handles.pause, 'Enable', 'off');
set(handles.resume, 'Enable', 'on');
set(handles.status_bar, 'String', 'Registration paused');
uiwait;

% ==================================================================== % 

function resume_Callback(hObject, eventdata, handles)

set(handles.pause, 'Enable', 'on');
set(handles.resume, 'Enable', 'off');
uiresume;
set(handles.status_bar, 'String', 'Registration in progress...');

% ==================================================================== % 

function help_button_Callback(hObject, eventdata, handles)

web http://www.danielsorogon.com/Webmaster/Projects/AART/help.htm

% ==================================================================== % 

function constant_Callback(hObject, eventdata, handles)

set(handles.constant, 'Value', 1);
set(handles.edge, 'Value', 0);
set(handles.variance, 'Value', 0);
set(handles.text108, 'String', 'constant');
set(handles.model_weight_slider, 'Enable', 'on');

set(handles.model_weight_constant_value, 'Enable', 'on');
set(handles.constant_value_text, 'Enable', 'on');

% ==================================================================== % 

function edge_Callback(hObject, eventdata, handles)

set(handles.constant, 'Value', 0);
set(handles.edge, 'Value', 1);
set(handles.variance, 'Value', 0);
set(handles.text108, 'String', 'edge');
set(handles.model_weight_slider, 'Enable', 'off');
set(handles.model_weight_constant_value, 'Enable', 'off');
set(handles.constant_value_text, 'Enable', 'off');

% ==================================================================== % 

function variance_Callback(hObject, eventdata, handles)

set(handles.constant, 'Value', 0);
set(handles.edge, 'Value', 0);
set(handles.variance, 'Value', 1);
set(handles.text108, 'String', 'variance');
set(handles.model_weight_slider, 'Enable', 'off');

set(handles.model_weight_constant_value, 'Enable', 'off');
set(handles.constant_value_text, 'Enable', 'off');

% ==================================================================== % 

function number_of_modes_slider_CreateFcn(hObject, eventdata, handles)

usewhitebg = 1;
if usewhitebg
    set(hObject,'BackgroundColor',[.9 .9 .9]);
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end

% ==================================================================== % 

function number_of_modes_slider_Callback(hObject, eventdata, handles)

set(handles.number_of_modes_display, 'String', num2str(ceil(get(handles.number_of_modes_slider, 'Value'))));

% ==================================================================== % 

function model_weight_slider_CreateFcn(hObject, eventdata, handles)

usewhitebg = 1;
if usewhitebg
    set(hObject,'BackgroundColor',[.9 .9 .9]);
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end

% ==================================================================== % 

function model_weight_slider_Callback(hObject, eventdata, handles)

set(handles.model_weight_constant_value, 'String', num2str(get(handles.model_weight_slider, 'Value')));


% ==================================================================== % 

function variation_kept_slider_CreateFcn(hObject, eventdata, handles)

usewhitebg = 1;
if usewhitebg
    set(hObject,'BackgroundColor',[.9 .9 .9]);
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end

% ==================================================================== % 

function variation_kept_slider_Callback(hObject, eventdata, handles)

set(handles.variatyion_kept_display, 'String', num2str(get(handles.variation_kept_slider, 'Value')));

% ==================================================================== % 

function data_samples_Callback(hObject, eventdata, handles)

% ==================================================================== % 

function disable_samples_Callback(hObject, eventdata, handles)

set(handles.samples_flag, 'String', '0');
set(handles.enable_samples, 'Checked', 'off');
set(handles.disable_samples, 'Checked', 'on');
samples = imread('samples.tif');
axes(handles.samples);
axis off;
imshow(samples,[0,255]);

% ==================================================================== % 

function enable_samples_Callback(hObject, eventdata, handles)

set(handles.samples_flag, 'String', '1');
draw_data(hObject, eventdata, handles);

set(handles.enable_samples, 'Checked', 'on');
set(handles.disable_samples, 'Checked', 'off');

% ==================================================================== % 

function Evaluation_menu_CreateFcn(hObject, eventdata, handles)

if ispc
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end

% ==================================================================== % 

function Evaluation_menu_Callback(hObject, eventdata, handles)

contents = get(hObject,'String');
if (strcmp(contents{get(hObject,'Value')},'Determinant')),
    set(handles.show_target_option, 'Enable', 'off');
    set(handles.show_registration_target, 'Enable', 'off');
    set(handles.show_registration_target, 'Value', 0);
    set(handles.show_target_option, 'Value', 0);
    set(handles.show_target, 'String', '0');
    set(handles.show_registration_target_flag, 'String', '0');
    set(handles.determinant, 'String', '1');
elseif (strcmp(contents{get(hObject,'Value')},'MDL')),
    set(handles.show_target_option, 'Enable', 'off');
    set(handles.show_registration_target, 'Enable', 'off');
    set(handles.show_registration_target, 'Value', 0);
    set(handles.show_target_option, 'Value', 0);
    set(handles.show_target, 'String', '0');
    set(handles.show_registration_target_flag, 'String', '0');
    set(handles.determinant, 'String', '0');
elseif (strcmp(contents{get(hObject,'Value')},'Sum Log Eigenvalues')),
    set(handles.determinant, 'String', '2');
    set(handles.show_target_option, 'Enable', 'on');
    set(handles.show_registration_target, 'Enable', 'on');
elseif (strcmp(contents{get(hObject,'Value')},'Specificity')),
    set(handles.show_target_option, 'Enable', 'off');
    set(handles.show_registration_target, 'Enable', 'off');
    set(handles.show_registration_target, 'Value', 0);
    set(handles.show_target_option, 'Value', 0);
    set(handles.show_target, 'String', '0');
    set(handles.show_registration_target_flag, 'String', '0');
    set(handles.determinant, 'String', '3');
elseif (strcmp(contents{get(hObject,'Value')},'Generalisability')),
    set(handles.show_target_option, 'Enable', 'off');
    set(handles.show_registration_target, 'Enable', 'off');
    set(handles.show_registration_target, 'Value', 0);
    set(handles.show_target_option, 'Value', 0);
    set(handles.show_target, 'String', '0');
    set(handles.show_registration_target_flag, 'String', '0');
    set(handles.determinant, 'String', '4');      
else
    msgbox('Error with menu callback');
end

% ==================================================================== % 

function PDF_CreateFcn(hObject, eventdata, handles)

if ispc
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end

% ==================================================================== % 

function PDF_Callback(hObject, eventdata, handles)

contents = get(hObject,'String');

if (strcmp(contents{get(hObject,'Value')},'Exponential')),
    set(handles.pdf, 'String', 'Exponential');
elseif (strcmp(contents{get(hObject,'Value')},'Poisson')),
    set(handles.pdf, 'String', 'Poisson');
elseif (strcmp(contents{get(hObject,'Value')},'Normal')),
    set(handles.pdf, 'String', 'Normal');
elseif (strcmp(contents{get(hObject,'Value')},'Beta')),
    set(handles.pdf, 'String', 'Beta');
elseif (strcmp(contents{get(hObject,'Value')},'Binomial')),
    set(handles.pdf, 'String', 'Binomial');
elseif (strcmp(contents{get(hObject,'Value')},'Chisquare')),
    set(handles.pdf, 'String', 'Chisquare');
elseif (strcmp(contents{get(hObject,'Value')},'F')),
    set(handles.pdf, 'String', 'F');
elseif (strcmp(contents{get(hObject,'Value')},'Gamma')),
    set(handles.pdf, 'String', 'Gamma');
elseif (strcmp(contents{get(hObject,'Value')},'Geometric')),
    set(handles.pdf, 'String', 'Geometric');
elseif (strcmp(contents{get(hObject,'Value')},'Hypergeometric')),
    set(handles.pdf, 'String', 'Hypergeometric');
elseif (strcmp(contents{get(hObject,'Value')},'Lognormal')),
    set(handles.pdf, 'String', 'Lognormal');   
elseif (strcmp(contents{get(hObject,'Value')},'Negative Binomial')),
    set(handles.pdf, 'String', 'Negative Binomial');    
elseif (strcmp(contents{get(hObject,'Value')},'Noncentral F')),
    set(handles.pdf, 'String', 'Noncentral F');    
elseif (strcmp(contents{get(hObject,'Value')},'Noncentral t')),
    set(handles.pdf, 'String', 'Noncentral t');      
elseif (strcmp(contents{get(hObject,'Value')},'Noncentral Chi-square')),
    set(handles.pdf, 'String', 'Noncentral Chi-square');    
elseif (strcmp(contents{get(hObject,'Value')},'Rayleigh')),
    set(handles.pdf, 'String', 'Rayleigh');    
elseif (strcmp(contents{get(hObject,'Value')},'T')),
    set(handles.pdf, 'String', 'T');    
elseif (strcmp(contents{get(hObject,'Value')},'Uniform')),
    set(handles.pdf, 'String', 'Uniform');        
elseif (strcmp(contents{get(hObject,'Value')},'Discrete Uniform')),
    set(handles.pdf, 'String', 'Discrete Uniform'); 
elseif (strcmp(contents{get(hObject,'Value')},'Weibull')),
    set(handles.pdf, 'String', 'Weibull'); 
else
    msgbox('Error with menu callback. Parameter passed is not recognised.');
end

% ==================================================================== % 

function Save_Callback(hObject, eventdata, handles)

% ==================================================================== % 

function save_handle_Callback(hObject, eventdata, handles)

set(handles.save_data, 'String', '1');
set(handles.save_handle, 'Checked', 'on');
set(handles.disable_save, 'Checked', 'off');
set(handles.export_default, 'Checked', 'off');

% ==================================================================== % 

function disable_save_Callback(hObject, eventdata, handles)

set(handles.save_data, 'String', '0');
set(handles.disable_save, 'Checked', 'on');
set(handles.save_handle, 'Checked', 'off');
set(handles.export_default, 'Checked', 'off');

% ==================================================================== % 

function advanced_Callback(hObject, eventdata, handles)

advanced;

% ==================================================================== % 

% Menu OPEN section

function open_Callback(hObject, eventdata, handles)

% ==================================================================== % 

function generate_simple_bump_Callback(hObject, eventdata, handles)

set(handles.open_flat, 'Checked', 'off');
set(handles.open_disable, 'Checked', 'off');
set(handles.handle_open, 'Checked', 'off');
set(handles.open_default, 'Checked', 'off');
set(handles.open_plain, 'Checked', 'off');
set(handles.open_plainran, 'Checked', 'off');
set(handles.ellipse, 'Checked', 'off');
set(handles.generate_simple_bump, 'Checked', 'on');
set(handles.load_data, 'String', '7');

% ==================================================================== % 

function ellipse_Callback(hObject, eventdata, handles)

set(handles.open_flat, 'Checked', 'off');
set(handles.open_disable, 'Checked', 'off');
set(handles.handle_open, 'Checked', 'off');
set(handles.open_default, 'Checked', 'off');
set(handles.open_plain, 'Checked', 'off');
set(handles.open_plainran, 'Checked', 'off');
set(handles.ellipse, 'Checked', 'on');
set(handles.generate_simple_bump, 'Checked', 'off');
set(handles.load_data, 'String', '6');

% ==================================================================== % 

function open_flat_Callback(hObject, eventdata, handles)

set(handles.open_flat, 'Checked', 'on');
set(handles.open_disable, 'Checked', 'off');
set(handles.handle_open, 'Checked', 'off');
set(handles.open_default, 'Checked', 'off');
set(handles.open_plain, 'Checked', 'off');
set(handles.open_plainran, 'Checked', 'off');
set(handles.ellipse, 'Checked', 'off');
set(handles.generate_simple_bump, 'Checked', 'off');
set(handles.load_data, 'String', '3');

% ==================================================================== % 

function open_default_Callback(hObject, eventdata, handles)

set(handles.load_data, 'String', '2');
set(handles.handle_open, 'Checked', 'off');
set(handles.open_disable, 'Checked', 'off');
set(handles.open_default, 'Checked', 'on');
set(handles.open_plain, 'Checked', 'off');
set(handles.open_plainran, 'Checked', 'off');
set(handles.ellipse, 'Checked', 'off');
set(handles.generate_simple_bump, 'Checked', 'off');
set(handles.open_flat, 'Checked', 'off');

% ==================================================================== % 

function open_disable_Callback(hObject, eventdata, handles)

set(handles.load_data, 'String', '0');
set(handles.open_disable, 'Checked', 'on');
set(handles.handle_open, 'Checked', 'off');
set(handles.generate_simple_bump, 'Checked', 'off');
set(handles.open_default, 'Checked', 'off');
set(handles.open_plain, 'Checked', 'off');
set(handles.open_plainran, 'Checked', 'off');
set(handles.ellipse, 'Checked', 'off');
set(handles.open_flat, 'Checked', 'off');

% ==================================================================== % 

function handle_open_Callback(hObject, eventdata, handles)

set(handles.load_data, 'String', '1');
set(handles.handle_open, 'Checked', 'on');
set(handles.open_disable, 'Checked', 'off');
set(handles.open_default, 'Checked', 'off');
set(handles.open_plain, 'Checked', 'off');
set(handles.open_plainran, 'Checked', 'off');
set(handles.generate_simple_bump, 'Checked', 'off');
set(handles.ellipse, 'Checked', 'off');
set(handles.open_flat, 'Checked', 'off');

% ==================================================================== % 

function open_plain_Callback(hObject, eventdata, handles)

set(handles.load_data, 'String', '4');
set(handles.handle_open, 'Checked', 'off');
set(handles.open_disable, 'Checked', 'off');
set(handles.open_default, 'Checked', 'off');
set(handles.open_plain, 'Checked', 'on');
set(handles.open_plainran, 'Checked', 'off');
set(handles.generate_simple_bump, 'Checked', 'off');
set(handles.open_flat, 'Checked', 'off');

% ==================================================================== % 

function open_plainran_Callback(hObject, eventdata, handles)

set(handles.load_data, 'String', '5');
set(handles.handle_open, 'Checked', 'off');
set(handles.open_disable, 'Checked', 'off');
set(handles.open_default, 'Checked', 'off');
set(handles.open_plain, 'Checked', 'off');
set(handles.open_plainran, 'Checked', 'on');
set(handles.generate_simple_bump, 'Checked', 'off');
set(handles.ellipse, 'Checked', 'off');
set(handles.open_flat, 'Checked', 'off');

% ==================================================================== % 

function save_bumps_Callback(hObject, eventdata, handles)
if (str2num(get(handles.save_bumps_flag, 'String')) == 0),
    set(handles.save_bumps_flag, 'String', '1');
    set(handles.save_bumps, 'Checked', 'on');
else
    set(handles.save_bumps_flag, 'String', '0');
    set(handles.save_bumps, 'Checked', 'off');   
end

% ==================================================================== % 

function overlap_scores_option_Callback(hObject, eventdata, handles)


if (get(handles.overlap_scores_option,'Value') == 0),
    set(handles.overlap_scores_option, 'Value', 0);
    set(handles.overlap_scores, 'String', '0');
else
    set(handles.overlap_scores_option, 'Value', 1);
    set(handles.overlap_scores, 'String', '1'); 
end

% ==================================================================== % 

function show_target_option_Callback(hObject, eventdata, handles)

if (get(handles.show_target_option,'Value') == 0),
    set(handles.show_target_option, 'Value', 0);
    set(handles.show_target, 'String', '0');
else
    set(handles.show_target_option, 'Value', 1);
    set(handles.show_target, 'String', '1'); 
end  

% ==================================================================== % 

function export_Callback(hObject, eventdata, handles)

% ==================================================================== % 

function format_selection_Callback(hObject, eventdata, handles)

% ==================================================================== % 

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% The file formats callbacks

function png_Callback(hObject, eventdata, handles)

set(handles.format, 'String', 'png');

set(handles.png, 'Checked', 'on');
set(handles.bmp, 'Checked', 'off');
set(handles.tiff, 'Checked', 'off');
set(handles.jpeg, 'Checked', 'off');
set(handles.hdf, 'Checked', 'off');
set(handles.pcx, 'Checked', 'off');
set(handles.xwd, 'Checked', 'off');
set(handles.ras, 'Checked', 'off');
set(handles.pbm, 'Checked', 'off');
set(handles.pgm, 'Checked', 'off');
set(handles.ppm, 'Checked', 'off');
set(handles.pnm, 'Checked', 'off');

% ==================================================================== % 

function bmp_Callback(hObject, eventdata, handles)

set(handles.format, 'String', 'bmp');

set(handles.png, 'Checked', 'off');
set(handles.bmp, 'Checked', 'on');
set(handles.tiff, 'Checked', 'off');
set(handles.jpeg, 'Checked', 'off');
set(handles.hdf, 'Checked', 'off');
set(handles.pcx, 'Checked', 'off');
set(handles.xwd, 'Checked', 'off');
set(handles.ras, 'Checked', 'off');
set(handles.pbm, 'Checked', 'off');
set(handles.pgm, 'Checked', 'off');
set(handles.ppm, 'Checked', 'off');
set(handles.pnm, 'Checked', 'off');

% ==================================================================== % 

function tiff_Callback(hObject, eventdata, handles)

set(handles.format, 'String', 'tiff');

set(handles.png, 'Checked', 'off');
set(handles.bmp, 'Checked', 'off');
set(handles.tiff, 'Checked', 'on');
set(handles.jpeg, 'Checked', 'off');
set(handles.hdf, 'Checked', 'off');
set(handles.pcx, 'Checked', 'off');
set(handles.xwd, 'Checked', 'off');
set(handles.ras, 'Checked', 'off');
set(handles.pbm, 'Checked', 'off');
set(handles.pgm, 'Checked', 'off');
set(handles.ppm, 'Checked', 'off');
set(handles.pnm, 'Checked', 'off');

% ==================================================================== % 

function jpeg_Callback(hObject, eventdata, handles)

set(handles.format, 'String', 'jpeg');

set(handles.png, 'Checked', 'off');
set(handles.bmp, 'Checked', 'off');
set(handles.tiff, 'Checked', 'off');
set(handles.jpeg, 'Checked', 'on');
set(handles.hdf, 'Checked', 'off');
set(handles.pcx, 'Checked', 'off');
set(handles.xwd, 'Checked', 'off');
set(handles.ras, 'Checked', 'off');
set(handles.pbm, 'Checked', 'off');
set(handles.pgm, 'Checked', 'off');
set(handles.ppm, 'Checked', 'off');
set(handles.pnm, 'Checked', 'off');

% ==================================================================== % 

function hdf_Callback(hObject, eventdata, handles)

set(handles.format, 'String', 'hdf');

set(handles.png, 'Checked', 'off');
set(handles.bmp, 'Checked', 'off');
set(handles.tiff, 'Checked', 'off');
set(handles.jpeg, 'Checked', 'off');
set(handles.hdf, 'Checked', 'on');
set(handles.pcx, 'Checked', 'off');
set(handles.xwd, 'Checked', 'off');
set(handles.ras, 'Checked', 'off');
set(handles.pbm, 'Checked', 'off');
set(handles.pgm, 'Checked', 'off');
set(handles.ppm, 'Checked', 'off');
set(handles.pnm, 'Checked', 'off');

% ==================================================================== % 

function pcx_Callback(hObject, eventdata, handles)

set(handles.format, 'String', 'pcx');

set(handles.png, 'Checked', 'off');
set(handles.bmp, 'Checked', 'off');
set(handles.tiff, 'Checked', 'off');
set(handles.jpeg, 'Checked', 'off');
set(handles.hdf, 'Checked', 'off');
set(handles.pcx, 'Checked', 'on');
set(handles.xwd, 'Checked', 'off');
set(handles.ras, 'Checked', 'off');
set(handles.pbm, 'Checked', 'off');
set(handles.pgm, 'Checked', 'off');
set(handles.ppm, 'Checked', 'off');
set(handles.pnm, 'Checked', 'off');

% ==================================================================== % 

function xwd_Callback(hObject, eventdata, handles)

set(handles.format, 'String', 'xwd');

set(handles.png, 'Checked', 'off');
set(handles.bmp, 'Checked', 'off');
set(handles.tiff, 'Checked', 'off');
set(handles.jpeg, 'Checked', 'off');
set(handles.hdf, 'Checked', 'off');
set(handles.pcx, 'Checked', 'off');
set(handles.xwd, 'Checked', 'on');
set(handles.ras, 'Checked', 'off');
set(handles.pbm, 'Checked', 'off');
set(handles.pgm, 'Checked', 'off');
set(handles.ppm, 'Checked', 'off');
set(handles.pnm, 'Checked', 'off');

% ==================================================================== % 

function ras_Callback(hObject, eventdata, handles)

set(handles.format, 'String', 'ras');

set(handles.png, 'Checked', 'off');
set(handles.bmp, 'Checked', 'off');
set(handles.tiff, 'Checked', 'off');
set(handles.jpeg, 'Checked', 'off');
set(handles.hdf, 'Checked', 'off');
set(handles.pcx, 'Checked', 'off');
set(handles.xwd, 'Checked', 'off');
set(handles.ras, 'Checked', 'on');
set(handles.pbm, 'Checked', 'off');
set(handles.pgm, 'Checked', 'off');
set(handles.ppm, 'Checked', 'off');
set(handles.pnm, 'Checked', 'off');

% ==================================================================== % 

function pbm_Callback(hObject, eventdata, handles)

set(handles.format, 'String', 'pbm');

set(handles.png, 'Checked', 'off');
set(handles.bmp, 'Checked', 'off');
set(handles.tiff, 'Checked', 'off');
set(handles.jpeg, 'Checked', 'off');
set(handles.hdf, 'Checked', 'off');
set(handles.pcx, 'Checked', 'off');
set(handles.xwd, 'Checked', 'off');
set(handles.ras, 'Checked', 'off');
set(handles.pbm, 'Checked', 'on');
set(handles.pgm, 'Checked', 'off');
set(handles.ppm, 'Checked', 'off');
set(handles.pnm, 'Checked', 'off');

% ==================================================================== % 

function pgm_Callback(hObject, eventdata, handles)

set(handles.format, 'String', 'pgm');

set(handles.png, 'Checked', 'off');
set(handles.bmp, 'Checked', 'off');
set(handles.tiff, 'Checked', 'off');
set(handles.jpeg, 'Checked', 'off');
set(handles.hdf, 'Checked', 'off');
set(handles.pcx, 'Checked', 'off');
set(handles.xwd, 'Checked', 'off');
set(handles.ras, 'Checked', 'off');
set(handles.pbm, 'Checked', 'off');
set(handles.pgm, 'Checked', 'on');
set(handles.ppm, 'Checked', 'off');
set(handles.pnm, 'Checked', 'off');


% ==================================================================== % 

function ppm_Callback(hObject, eventdata, handles)

set(handles.format, 'String', 'ppm');

set(handles.png, 'Checked', 'off');
set(handles.bmp, 'Checked', 'off');
set(handles.tiff, 'Checked', 'off');
set(handles.jpeg, 'Checked', 'off');
set(handles.hdf, 'Checked', 'off');
set(handles.pcx, 'Checked', 'off');
set(handles.xwd, 'Checked', 'off');
set(handles.ras, 'Checked', 'off');
set(handles.pbm, 'Checked', 'off');
set(handles.pgm, 'Checked', 'off');
set(handles.ppm, 'Checked', 'on');
set(handles.pnm, 'Checked', 'off');

% ==================================================================== % 

function pnm_Callback(hObject, eventdata, handles)

set(handles.format, 'String', 'pnm');

set(handles.png, 'Checked', 'off');
set(handles.bmp, 'Checked', 'off');
set(handles.tiff, 'Checked', 'off');
set(handles.jpeg, 'Checked', 'off');
set(handles.hdf, 'Checked', 'off');
set(handles.pcx, 'Checked', 'off');
set(handles.xwd, 'Checked', 'off');
set(handles.ras, 'Checked', 'off');
set(handles.pbm, 'Checked', 'off');
set(handles.pgm, 'Checked', 'off');
set(handles.ppm, 'Checked', 'off');
set(handles.pnm, 'Checked', 'on');

% ==================================================================== % 

function compression_CreateFcn(hObject, eventdata, handles)

if ispc
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end

% ==================================================================== % 

function compression_Callback(hObject, eventdata, handles)

contents = get(hObject,'String');

if (strcmp(contents{get(hObject,'Value')},'Daubechy')),
    set(handles.filter_type, 'String', 'db1');
elseif (strcmp(contents{get(hObject,'Value')},'Haar')),
    set(handles.filter_type, 'String', 'haar');
elseif (strcmp(contents{get(hObject,'Value')},'Coiflet')),
    set(handles.filter_type, 'String', 'coif1');    
elseif (strcmp(contents{get(hObject,'Value')},'Symlet')),
    set(handles.filter_type, 'String', 'sym2');   
elseif (strcmp(contents{get(hObject,'Value')},'Meyer')),
    set(handles.filter_type, 'String', 'dmey');    
elseif (strcmp(contents{get(hObject,'Value')},'Biorthogonal')),
    set(handles.filter_type, 'String', 'bior1.1');   
elseif (strcmp(contents{get(hObject,'Value')},'Reverse Biorthogonal')),
    set(handles.filter_type, 'String', 'rbio1.1');     
else
    msgbox('Error with menu callback. Parameter passed is not recognised.');
end

% ==================================================================== % 

function compression_level_CreateFcn(hObject, eventdata, handles)

if ispc
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end

% ==================================================================== % 

function compression_level_Callback(hObject, eventdata, handles)


contents = get(hObject,'String');

if (strcmp(contents{get(hObject,'Value')},'1')),
    set(handles.level, 'String', '1');
elseif (strcmp(contents{get(hObject,'Value')},'2')),
    set(handles.level, 'String', '2');
elseif (strcmp(contents{get(hObject,'Value')},'3')),
    set(handles.level, 'String', '3');    
elseif (strcmp(contents{get(hObject,'Value')},'4')),
    set(handles.level, 'String', '4');    
elseif (strcmp(contents{get(hObject,'Value')},'5')),
    set(handles.level, 'String', '5');    
elseif (strcmp(contents{get(hObject,'Value')},'6')),
    set(handles.level, 'String', '6');    
elseif (strcmp(contents{get(hObject,'Value')},'7')),
    set(handles.level, 'String', '7');    
elseif (strcmp(contents{get(hObject,'Value')},'8')),
    set(handles.level, 'String', '8');   
elseif (strcmp(contents{get(hObject,'Value')},'9')),
    set(handles.level, 'String', '9');
elseif (strcmp(contents{get(hObject,'Value')},'10')),
    set(handles.level, 'String', '10'); 
else
    msgbox('Error with menu callback. Parameter passed is not recognised.');
end

% ==================================================================== % 

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% The objective functions callbacks


function joint_msd_option_Callback(hObject, eventdata, handles)

set(handles.sequential_mi_option_menu, 'Checked', 'off');
set(handles.sequential_nmi_option_menu, 'Checked', 'off');
set(handles.joint_msd_option_menu, 'Checked', 'on');
set(handles.joint_model_option_menu, 'Checked', 'off');
set(handles.sequential_msd_option_menu, 'Checked', 'off');
set(handles.sequential_model_option_menu, 'Checked', 'off');
set(handles.mixed_msd_model_option_menu, 'Checked', 'off');
set(handles.model_post_msd_option_menu, 'Checked', 'off');
set(handles.joint_mi_option_menu, 'Checked', 'off');
set(handles.joint_nmi_option_menu, 'Checked', 'off');
set(handles.button_all_objective_functions_menu, 'Checked', 'off');
set(handles.tfceccv_menu, 'Checked', 'off');
set(handles.wavelet_option_menu, 'Checked', 'off');
set(handles.model_pairs_menu, 'Checked', 'off');
set(handles.seq_model_pairs_menu, 'Checked', 'off');

set(handles.sequential_mi_option, 'Value', 0);
set(handles.sequential_nmi_option, 'Value', 0);
set(handles.joint_msd_option, 'Value', 1);
set(handles.joint_model_option, 'Value', 0);
set(handles.sequential_msd_option, 'Value', 0);
set(handles.sequential_model_option, 'Value', 0);
set(handles.mixed_msd_model_option, 'Value', 0);
set(handles.model_post_msd_option, 'Value', 0);
set(handles.joint_mi_option, 'Value', 0);
set(handles.joint_nmi_option, 'Value', 0);
set(handles.button_all_objective_functions, 'Value', 0);
set(handles.tfceccv, 'Value', 0);
set(handles.wavelet_option, 'Value', 0);

set(handles.all_objective_functions, 'String', '0');
set(handles.objective_function_display, 'String', 'msd_opt_together');

set(handles.PDF, 'Enable', 'off');
set(handles.Kernel_title, 'Enable', 'off');

set(handles.overlap_scores_option, 'Enable', 'off');

set(handles.number_of_bins_text, 'Enable', 'off');
set(handles.number_of_bins_slider, 'Enable', 'off');
set(handles.number_of_bins, 'Enable', 'off');

set(handles.compression_type_title, 'Enable', 'off');
set(handles.compression_level_title, 'Enable', 'off');
set(handles.compression, 'Enable', 'off');
set(handles.compression_level, 'Enable', 'off');

% unset forced reference

set(handles.force_reference, 'String', '0');
set(handles.force_reference_button, 'Value', 0);


% ==================================================================== % 

function joint_model_option_Callback(hObject, eventdata, handles)

set(handles.sequential_mi_option_menu, 'Checked', 'off');
set(handles.sequential_nmi_option_menu, 'Checked', 'off');
set(handles.joint_msd_option_menu, 'Checked', 'off');
set(handles.joint_model_option_menu, 'Checked', 'on');
set(handles.sequential_msd_option_menu, 'Checked', 'off');
set(handles.sequential_model_option_menu, 'Checked', 'off');
set(handles.mixed_msd_model_option_menu, 'Checked', 'off');
set(handles.model_post_msd_option_menu, 'Checked', 'off');
set(handles.joint_mi_option_menu, 'Checked', 'off');
set(handles.joint_nmi_option_menu, 'Checked', 'off');
set(handles.button_all_objective_functions_menu, 'Checked', 'off');
set(handles.tfceccv_menu, 'Checked', 'off');
set(handles.wavelet_option_menu, 'Checked', 'off');
set(handles.model_pairs_menu, 'Checked', 'off');
set(handles.seq_model_pairs_menu, 'Checked', 'off');


set(handles.sequential_mi_option, 'Value', 0);
set(handles.sequential_nmi_option, 'Value', 0);
set(handles.mixed_msd_model_option, 'Value', 0);
set(handles.model_post_msd_option, 'Value', 0);
set(handles.joint_msd_option, 'Value', 0);
set(handles.joint_model_option, 'Value', 1);
set(handles.sequential_msd_option, 'Value', 0);
set(handles.sequential_model_option, 'Value', 0);
set(handles.joint_mi_option, 'Value', 0);
set(handles.joint_nmi_option, 'Value', 0);
set(handles.button_all_objective_functions, 'Value', 0);
set(handles.tfceccv, 'Value', 0);
set(handles.wavelet_option, 'Value', 0);

set(handles.all_objective_functions, 'String', '0');
set(handles.objective_function_display, 'String', 'model_opt_together');

set(handles.PDF, 'Enable', 'off');
set(handles.Kernel_title, 'Enable', 'off');

set(handles.overlap_scores_option, 'Enable', 'off');

set(handles.number_of_bins_text, 'Enable', 'off');
set(handles.number_of_bins_slider, 'Enable', 'off');
set(handles.number_of_bins, 'Enable', 'off');

set(handles.compression_type_title, 'Enable', 'off');
set(handles.compression_level_title, 'Enable', 'off');
set(handles.compression, 'Enable', 'off');
set(handles.compression_level, 'Enable', 'off');

% set forced reference

set(handles.force_reference, 'String', '1');
set(handles.force_reference_button, 'Value', 1);

% ==================================================================== % 

function sequential_msd_option_Callback(hObject, eventdata, handles)

set(handles.sequential_mi_option_menu, 'Checked', 'off');
set(handles.sequential_nmi_option_menu, 'Checked', 'off');
set(handles.joint_msd_option_menu, 'Checked', 'off');
set(handles.joint_model_option_menu, 'Checked', 'off');
set(handles.sequential_msd_option_menu, 'Checked', 'on');
set(handles.sequential_model_option_menu, 'Checked', 'off');
set(handles.mixed_msd_model_option_menu, 'Checked', 'off');
set(handles.model_post_msd_option_menu, 'Checked', 'off');
set(handles.joint_mi_option_menu, 'Checked', 'off');
set(handles.joint_nmi_option_menu, 'Checked', 'off');
set(handles.button_all_objective_functions_menu, 'Checked', 'off');
set(handles.tfceccv_menu, 'Checked', 'off');
set(handles.wavelet_option_menu, 'Checked', 'off');
set(handles.model_pairs_menu, 'Checked', 'off');
set(handles.seq_model_pairs_menu, 'Checked', 'off');


set(handles.mixed_msd_model_option, 'Value', 0);
set(handles.model_post_msd_option, 'Value', 0);
set(handles.joint_msd_option, 'Value', 0);
set(handles.joint_model_option, 'Value', 0);
set(handles.sequential_msd_option, 'Value', 1);
set(handles.sequential_model_option, 'Value', 0);
set(handles.sequential_mi_option, 'Value', 0);
set(handles.sequential_nmi_option, 'Value', 0);
set(handles.joint_mi_option, 'Value', 0);
set(handles.joint_nmi_option, 'Value', 0);
set(handles.tfceccv, 'Value', 0);
set(handles.wavelet_option, 'Value', 0);
set(handles.button_all_objective_functions, 'Value', 0);

set(handles.PDF, 'Enable', 'off');
set(handles.Kernel_title, 'Enable', 'off');

set(handles.number_of_bins_text, 'Enable', 'off');
set(handles.number_of_bins_slider, 'Enable', 'off');
set(handles.number_of_bins, 'Enable', 'off');

set(handles.all_objective_functions, 'String', '0');
set(handles.objective_function_display, 'String', 'msd_opt_separate');

set(handles.overlap_scores_option, 'Enable', 'off');

set(handles.compression_type_title, 'Enable', 'off');
set(handles.compression_level_title, 'Enable', 'off');
set(handles.compression, 'Enable', 'off');
set(handles.compression_level, 'Enable', 'off');

% unset forced reference

set(handles.force_reference, 'String', '0');
set(handles.force_reference_button, 'Value', 0);

% ==================================================================== % 

function sequential_model_option_Callback(hObject, eventdata, handles)

set(handles.sequential_mi_option_menu, 'Checked', 'off');
set(handles.sequential_nmi_option_menu, 'Checked', 'off');
set(handles.joint_msd_option_menu, 'Checked', 'off');
set(handles.joint_model_option_menu, 'Checked', 'off');
set(handles.sequential_msd_option_menu, 'Checked', 'off');
set(handles.sequential_model_option_menu, 'Checked', 'on');
set(handles.mixed_msd_model_option_menu, 'Checked', 'off');
set(handles.model_post_msd_option_menu, 'Checked', 'off');
set(handles.joint_mi_option_menu, 'Checked', 'off');
set(handles.joint_nmi_option_menu, 'Checked', 'off');
set(handles.button_all_objective_functions_menu, 'Checked', 'off');
set(handles.tfceccv_menu, 'Checked', 'off');
set(handles.wavelet_option_menu, 'Checked', 'off');
set(handles.model_pairs_menu, 'Checked', 'off');
set(handles.seq_model_pairs_menu, 'Checked', 'off');


set(handles.mixed_msd_model_option, 'Value', 0);
set(handles.model_post_msd_option, 'Value', 0);
set(handles.joint_msd_option, 'Value', 0);
set(handles.joint_model_option, 'Value', 0);
set(handles.sequential_msd_option, 'Value', 0);
set(handles.sequential_model_option, 'Value', 1);
set(handles.sequential_mi_option, 'Value', 0);
set(handles.sequential_nmi_option, 'Value', 0);
set(handles.joint_mi_option, 'Value', 0);
set(handles.joint_nmi_option, 'Value', 0);
set(handles.tfceccv, 'Value', 0);
set(handles.wavelet_option, 'Value', 0);
set(handles.button_all_objective_functions, 'Value', 0);

set(handles.PDF, 'Enable', 'off');
set(handles.Kernel_title, 'Enable', 'off');

set(handles.number_of_bins_text, 'Enable', 'off');
set(handles.number_of_bins_slider, 'Enable', 'off');
set(handles.number_of_bins, 'Enable', 'off');

set(handles.all_objective_functions, 'String', '0');
set(handles.objective_function_display, 'String', 'model_opt_separate');
set(handles.overlap_scores_option, 'Enable', 'off');

set(handles.compression_type_title, 'Enable', 'off');
set(handles.compression_level_title, 'Enable', 'off');
set(handles.compression, 'Enable', 'off');
set(handles.compression_level, 'Enable', 'off');

% set forced reference

set(handles.force_reference, 'String', '1');
set(handles.force_reference_button, 'Value', 1);

% ==================================================================== % 

function mixed_msd_model_option_Callback(hObject, eventdata, handles)

set(handles.sequential_mi_option_menu, 'Checked', 'off');
set(handles.sequential_nmi_option_menu, 'Checked', 'off');
set(handles.joint_msd_option_menu, 'Checked', 'off');
set(handles.joint_model_option_menu, 'Checked', 'off');
set(handles.sequential_msd_option_menu, 'Checked', 'off');
set(handles.sequential_model_option_menu, 'Checked', 'off');
set(handles.mixed_msd_model_option_menu, 'Checked', 'on');
set(handles.model_post_msd_option_menu, 'Checked', 'off');
set(handles.joint_mi_option_menu, 'Checked', 'off');
set(handles.joint_nmi_option_menu, 'Checked', 'off');
set(handles.button_all_objective_functions_menu, 'Checked', 'off');
set(handles.tfceccv_menu, 'Checked', 'off');
set(handles.wavelet_option_menu, 'Checked', 'off');
set(handles.model_pairs_menu, 'Checked', 'off');
set(handles.seq_model_pairs_menu, 'Checked', 'off');


set(handles.sequential_mi_option, 'Value', 0);
set(handles.sequential_nmi_option, 'Value', 0);
set(handles.joint_msd_option, 'Value', 0);
set(handles.joint_model_option, 'Value', 0);
set(handles.sequential_msd_option, 'Value', 0);
set(handles.sequential_model_option, 'Value', 0);
set(handles.mixed_msd_model_option, 'Value', 1);
set(handles.model_post_msd_option, 'Value', 0);
set(handles.joint_mi_option, 'Value', 0);
set(handles.joint_nmi_option, 'Value', 0);
set(handles.tfceccv, 'Value', 0);
set(handles.wavelet_option, 'Value', 0);
set(handles.button_all_objective_functions, 'Value', 0);

set(handles.PDF, 'Enable', 'off');
set(handles.Kernel_title, 'Enable', 'off');

set(handles.all_objective_functions, 'String', '0');

set(handles.objective_function_display, 'String', 'mixed_msd_model');

set(handles.overlap_scores_option, 'Enable', 'off');

set(handles.number_of_bins_text, 'Enable', 'off');
set(handles.number_of_bins_slider, 'Enable', 'off');
set(handles.number_of_bins, 'Enable', 'off');

set(handles.compression_type_title, 'Enable', 'off');
set(handles.compression_level_title, 'Enable', 'off');
set(handles.compression, 'Enable', 'off');
set(handles.compression_level, 'Enable', 'off');

% unset forced reference

set(handles.force_reference, 'String', '0');
set(handles.force_reference_button, 'Value', 0);

% ==================================================================== % 

function model_post_msd_option_Callback(hObject, eventdata, handles)

set(handles.sequential_mi_option_menu, 'Checked', 'off');
set(handles.sequential_nmi_option_menu, 'Checked', 'off');
set(handles.joint_msd_option_menu, 'Checked', 'off');
set(handles.joint_model_option_menu, 'Checked', 'off');
set(handles.sequential_msd_option_menu, 'Checked', 'off');
set(handles.sequential_model_option_menu, 'Checked', 'off');
set(handles.mixed_msd_model_option_menu, 'Checked', 'off');
set(handles.model_post_msd_option_menu, 'Checked', 'on');
set(handles.joint_mi_option_menu, 'Checked', 'off');
set(handles.joint_nmi_option_menu, 'Checked', 'off');
set(handles.button_all_objective_functions_menu, 'Checked', 'off');
set(handles.tfceccv_menu, 'Checked', 'off');
set(handles.wavelet_option_menu, 'Checked', 'off');
set(handles.model_pairs_menu, 'Checked', 'off');
set(handles.seq_model_pairs_menu, 'Checked', 'off');


set(handles.sequential_mi_option, 'Value', 0);
set(handles.sequential_nmi_option, 'Value', 0);
set(handles.joint_msd_option, 'Value', 0);
set(handles.joint_model_option, 'Value', 0);
set(handles.sequential_msd_option, 'Value', 0);
set(handles.sequential_model_option, 'Value', 0);
set(handles.mixed_msd_model_option, 'Value', 0);
set(handles.model_post_msd_option, 'Value', 1);
set(handles.joint_mi_option, 'Value', 0);
set(handles.joint_nmi_option, 'Value', 0);
set(handles.tfceccv, 'Value', 0);
set(handles.wavelet_option, 'Value', 0);

set(handles.button_all_objective_functions, 'Value', 0);

set(handles.all_objective_functions, 'String', '0');

set(handles.objective_function_display, 'String', 'model_post_msd');

set(handles.PDF, 'Enable', 'off');
set(handles.Kernel_title, 'Enable', 'off');

set(handles.overlap_scores_option, 'Enable', 'off');

set(handles.number_of_bins_text, 'Enable', 'off');
set(handles.number_of_bins_slider, 'Enable', 'off');
set(handles.number_of_bins, 'Enable', 'off');

set(handles.compression_type_title, 'Enable', 'off');
set(handles.compression_level_title, 'Enable', 'off');
set(handles.compression, 'Enable', 'off');
set(handles.compression_level, 'Enable', 'off');

% unset forced reference

set(handles.force_reference, 'String', '0');
set(handles.force_reference_button, 'Value', 0);

% ==================================================================== % 

function joint_mi_option_Callback(hObject, eventdata, handles)

set(handles.sequential_mi_option_menu, 'Checked', 'off');
set(handles.sequential_nmi_option_menu, 'Checked', 'off');
set(handles.joint_msd_option_menu, 'Checked', 'off');
set(handles.joint_model_option_menu, 'Checked', 'off');
set(handles.sequential_msd_option_menu, 'Checked', 'off');
set(handles.sequential_model_option_menu, 'Checked', 'off');
set(handles.mixed_msd_model_option_menu, 'Checked', 'off');
set(handles.model_post_msd_option_menu, 'Checked', 'off');
set(handles.joint_mi_option_menu, 'Checked', 'on');
set(handles.joint_nmi_option_menu, 'Checked', 'off');
set(handles.button_all_objective_functions_menu, 'Checked', 'off');
set(handles.tfceccv_menu, 'Checked', 'off');
set(handles.wavelet_option_menu, 'Checked', 'off');
set(handles.model_pairs_menu, 'Checked', 'off');
set(handles.seq_model_pairs_menu, 'Checked', 'off');


set(handles.sequential_mi_option, 'Value', 0);
set(handles.sequential_nmi_option, 'Value', 0);
set(handles.joint_msd_option, 'Value', 0);
set(handles.joint_model_option, 'Value', 0);
set(handles.sequential_msd_option, 'Value', 0);
set(handles.sequential_model_option, 'Value', 0);
set(handles.mixed_msd_model_option, 'Value', 0);
set(handles.model_post_msd_option, 'Value', 0);
set(handles.joint_mi_option, 'Value', 1);
set(handles.joint_nmi_option, 'Value', 0);
set(handles.tfceccv, 'Value', 0);
set(handles.wavelet_option, 'Value', 0);
set(handles.button_all_objective_functions, 'Value', 0);

set(handles.all_objective_functions, 'String', '0');

set(handles.number_of_bins_text, 'Enable', 'on');
set(handles.number_of_bins_slider, 'Enable', 'on');
set(handles.number_of_bins, 'Enable', 'on');

set(handles.PDF, 'Enable', 'off');
set(handles.Kernel_title, 'Enable', 'off');

set(handles.objective_function_display, 'String', 'mi_opt_together');

set(handles.overlap_scores_option, 'Enable', 'off');

set(handles.compression_type_title, 'Enable', 'off');
set(handles.compression_level_title, 'Enable', 'off');
set(handles.compression, 'Enable', 'off');
set(handles.compression_level, 'Enable', 'off');

% unset forced reference

set(handles.force_reference, 'String', '0');
set(handles.force_reference_button, 'Value', 0);

% ==================================================================== % 

function joint_nmi_option_Callback(hObject, eventdata, handles)

set(handles.sequential_mi_option_menu, 'Checked', 'off');
set(handles.sequential_nmi_option_menu, 'Checked', 'off');
set(handles.joint_msd_option_menu, 'Checked', 'off');
set(handles.joint_model_option_menu, 'Checked', 'off');
set(handles.sequential_msd_option_menu, 'Checked', 'off');
set(handles.sequential_model_option_menu, 'Checked', 'off');
set(handles.mixed_msd_model_option_menu, 'Checked', 'off');
set(handles.model_post_msd_option_menu, 'Checked', 'off');
set(handles.joint_mi_option_menu, 'Checked', 'off');
set(handles.joint_nmi_option_menu, 'Checked', 'on');
set(handles.button_all_objective_functions_menu, 'Checked', 'off');
set(handles.tfceccv_menu, 'Checked', 'off');
set(handles.wavelet_option_menu, 'Checked', 'off');
set(handles.model_pairs_menu, 'Checked', 'off');
set(handles.seq_model_pairs_menu, 'Checked', 'off');


set(handles.sequential_mi_option, 'Value', 0);
set(handles.sequential_nmi_option, 'Value', 0);
set(handles.joint_msd_option, 'Value', 0);
set(handles.joint_model_option, 'Value', 0);
set(handles.sequential_msd_option, 'Value', 0);
set(handles.sequential_model_option, 'Value', 0);
set(handles.mixed_msd_model_option, 'Value', 0);
set(handles.model_post_msd_option, 'Value', 0);
set(handles.joint_mi_option, 'Value', 0);
set(handles.joint_nmi_option, 'Value', 1);
set(handles.tfceccv, 'Value', 0);
set(handles.wavelet_option, 'Value', 0);
set(handles.button_all_objective_functions, 'Value', 0);

set(handles.all_objective_functions, 'String', '0');

set(handles.PDF, 'Enable', 'off');
set(handles.Kernel_title, 'Enable', 'off');

set(handles.objective_function_display, 'String', 'nmi_opt_together');

set(handles.overlap_scores_option, 'Enable', 'off');

set(handles.number_of_bins_text, 'Enable', 'on');
set(handles.number_of_bins_slider, 'Enable', 'on');
set(handles.number_of_bins, 'Enable', 'on');

set(handles.compression_type_title, 'Enable', 'off');
set(handles.compression_level_title, 'Enable', 'off');
set(handles.compression, 'Enable', 'off');
set(handles.compression_level, 'Enable', 'off');

% unset forced reference

set(handles.force_reference, 'String', '0');
set(handles.force_reference_button, 'Value', 0);

% ==================================================================== % 

function tfceccv_Callback(hObject, eventdata, handles)

set(handles.sequential_mi_option_menu, 'Checked', 'off');
set(handles.sequential_nmi_option_menu, 'Checked', 'off');
set(handles.joint_msd_option_menu, 'Checked', 'off');
set(handles.joint_model_option_menu, 'Checked', 'off');
set(handles.sequential_msd_option_menu, 'Checked', 'off');
set(handles.sequential_model_option_menu, 'Checked', 'off');
set(handles.mixed_msd_model_option_menu, 'Checked', 'off');
set(handles.model_post_msd_option_menu, 'Checked', 'off');
set(handles.joint_mi_option_menu, 'Checked', 'off');
set(handles.joint_nmi_option_menu, 'Checked', 'off');
set(handles.button_all_objective_functions_menu, 'Checked', 'off');
set(handles.tfceccv_menu, 'Checked', 'on');
set(handles.wavelet_option_menu, 'Checked', 'off');
set(handles.model_pairs_menu, 'Checked', 'off');
set(handles.seq_model_pairs_menu, 'Checked', 'off');


set(handles.sequential_mi_option, 'Value', 0);
set(handles.sequential_nmi_option, 'Value', 0);
set(handles.joint_msd_option, 'Value', 0);
set(handles.joint_model_option, 'Value', 0);
set(handles.sequential_msd_option, 'Value', 0);
set(handles.sequential_model_option, 'Value', 0);
set(handles.mixed_msd_model_option, 'Value', 0);
set(handles.model_post_msd_option, 'Value', 0);
set(handles.joint_mi_option, 'Value', 0);
set(handles.joint_nmi_option, 'Value', 0);
set(handles.tfceccv, 'Value', 1);
set(handles.wavelet_option, 'Value', 0);
set(handles.button_all_objective_functions, 'Value', 0);

set(handles.all_objective_functions, 'String', '0');

set(handles.objective_function_display, 'String', 'tfc_eccv');

set(handles.overlap_scores_option, 'Enable', 'off');

set(handles.PDF, 'Enable', 'on');
set(handles.Kernel_title, 'Enable', 'on');

set(handles.number_of_bins_text, 'Enable', 'off');
set(handles.number_of_bins_slider, 'Enable', 'off');
set(handles.number_of_bins, 'Enable', 'off');

set(handles.compression_type_title, 'Enable', 'off');
set(handles.compression_level_title, 'Enable', 'off');
set(handles.compression, 'Enable', 'off');
set(handles.compression_level, 'Enable', 'off');

% unset forced reference

set(handles.force_reference, 'String', '1');
set(handles.force_reference_button, 'Value', 1);

% ==================================================================== % 

function button_all_objective_functions_Callback(hObject, eventdata, handles)

set(handles.sequential_mi_option_menu, 'Checked', 'off');
set(handles.sequential_nmi_option_menu, 'Checked', 'off');
set(handles.joint_msd_option_menu, 'Checked', 'off');
set(handles.joint_model_option_menu, 'Checked', 'off');
set(handles.sequential_msd_option_menu, 'Checked', 'off');
set(handles.sequential_model_option_menu, 'Checked', 'off');
set(handles.mixed_msd_model_option_menu, 'Checked', 'off');
set(handles.model_post_msd_option_menu, 'Checked', 'off');
set(handles.joint_mi_option_menu, 'Checked', 'off');
set(handles.joint_nmi_option_menu, 'Checked', 'off');
set(handles.button_all_objective_functions_menu, 'Checked', 'on');
set(handles.tfceccv_menu, 'Checked', 'off');
set(handles.wavelet_option_menu, 'Checked', 'off');
set(handles.model_pairs_menu, 'Checked', 'off');
set(handles.seq_model_pairs_menu, 'Checked', 'off');


set(handles.sequential_mi_option, 'Value', 0);
set(handles.sequential_nmi_option, 'Value', 0);
set(handles.joint_msd_option, 'Value', 0);
set(handles.joint_model_option, 'Value', 0);
set(handles.sequential_msd_option, 'Value', 0);
set(handles.sequential_model_option, 'Value', 0);
set(handles.mixed_msd_model_option, 'Value', 0);
set(handles.model_post_msd_option, 'Value', 0);
set(handles.joint_mi_option, 'Value', 0);
set(handles.joint_nmi_option, 'Value', 0);
set(handles.tfceccv, 'Value', 0);
set(handles.wavelet_option, 'Value', 0);
set(handles.button_all_objective_functions, 'Value', 1);

set(handles.all_objective_functions, 'String', '1');
set(handles.objective_function_display, 'String', 'all');

set(handles.number_of_bins_text, 'Enable', 'off');
set(handles.number_of_bins_slider, 'Enable', 'off');
set(handles.number_of_bins, 'Enable', 'off');

set(handles.overlap_scores_option, 'Enable', 'on');

set(handles.compression_type_title, 'Enable', 'off');
set(handles.compression_level_title, 'Enable', 'off');
set(handles.compression, 'Enable', 'off');
set(handles.compression_level, 'Enable', 'off');

% unset forced reference

set(handles.force_reference, 'String', '0');
set(handles.force_reference_button, 'Value', 0);

% ==================================================================== % 

function sequential_mi_option_Callback(hObject, eventdata, handles)

set(handles.sequential_mi_option_menu, 'Checked', 'on');
set(handles.sequential_nmi_option_menu, 'Checked', 'off');
set(handles.joint_msd_option_menu, 'Checked', 'off');
set(handles.joint_model_option_menu, 'Checked', 'off');
set(handles.sequential_msd_option_menu, 'Checked', 'off');
set(handles.sequential_model_option_menu, 'Checked', 'off');
set(handles.mixed_msd_model_option_menu, 'Checked', 'off');
set(handles.model_post_msd_option_menu, 'Checked', 'off');
set(handles.joint_mi_option_menu, 'Checked', 'off');
set(handles.joint_nmi_option_menu, 'Checked', 'off');
set(handles.button_all_objective_functions_menu, 'Checked', 'off');
set(handles.tfceccv_menu, 'Checked', 'off');
set(handles.wavelet_option_menu, 'Checked', 'off');
set(handles.model_pairs_menu, 'Checked', 'off');
set(handles.seq_model_pairs_menu, 'Checked', 'off');


set(handles.sequential_mi_option, 'Value', 1);
set(handles.sequential_nmi_option, 'Value', 0);
set(handles.joint_msd_option, 'Value', 0);
set(handles.joint_model_option, 'Value', 0);
set(handles.sequential_msd_option, 'Value', 0);
set(handles.sequential_model_option, 'Value', 0);
set(handles.mixed_msd_model_option, 'Value', 0);
set(handles.model_post_msd_option, 'Value', 0);
set(handles.joint_mi_option, 'Value', 0);
set(handles.joint_nmi_option, 'Value', 0);
set(handles.tfceccv, 'Value', 0);
set(handles.wavelet_option, 'Value', 0);
set(handles.button_all_objective_functions, 'Value', 0);

set(handles.all_objective_functions, 'String', '0');

set(handles.number_of_bins_text, 'Enable', 'on');
set(handles.number_of_bins_slider, 'Enable', 'on');
set(handles.number_of_bins, 'Enable', 'on');

set(handles.objective_function_display, 'String', 'mi_opt_separate');

set(handles.PDF, 'Enable', 'off');
set(handles.Kernel_title, 'Enable', 'off');

set(handles.overlap_scores_option, 'Enable', 'off');

set(handles.compression_type_title, 'Enable', 'off');
set(handles.compression_level_title, 'Enable', 'off');
set(handles.compression, 'Enable', 'off');
set(handles.compression_level, 'Enable', 'off');

% unset forced reference

set(handles.force_reference, 'String', '0');
set(handles.force_reference_button, 'Value', 0);

% ==================================================================== % 

function sequential_nmi_option_Callback(hObject, eventdata, handles)

set(handles.sequential_mi_option_menu, 'Checked', 'off');
set(handles.sequential_nmi_option_menu, 'Checked', 'on');
set(handles.joint_msd_option_menu, 'Checked', 'off');
set(handles.joint_model_option_menu, 'Checked', 'off');
set(handles.sequential_msd_option_menu, 'Checked', 'off');
set(handles.sequential_model_option_menu, 'Checked', 'off');
set(handles.mixed_msd_model_option_menu, 'Checked', 'off');
set(handles.model_post_msd_option_menu, 'Checked', 'off');
set(handles.joint_mi_option_menu, 'Checked', 'off');
set(handles.joint_nmi_option_menu, 'Checked', 'off');
set(handles.button_all_objective_functions_menu, 'Checked', 'off');
set(handles.tfceccv_menu, 'Checked', 'off');
set(handles.wavelet_option_menu, 'Checked', 'off');
set(handles.model_pairs_menu, 'Checked', 'off');
set(handles.seq_model_pairs_menu, 'Checked', 'off');


set(handles.sequential_mi_option, 'Value', 0);
set(handles.sequential_nmi_option, 'Value', 1);
set(handles.joint_msd_option, 'Value', 0);
set(handles.joint_model_option, 'Value', 0);
set(handles.sequential_msd_option, 'Value', 0);
set(handles.sequential_model_option, 'Value', 0);
set(handles.mixed_msd_model_option, 'Value', 0);
set(handles.model_post_msd_option, 'Value', 0);
set(handles.joint_mi_option, 'Value', 0);
set(handles.joint_nmi_option, 'Value', 0);
set(handles.tfceccv, 'Value', 0);
set(handles.wavelet_option, 'Value', 0);
set(handles.button_all_objective_functions, 'Value', 0);

set(handles.objective_function_display, 'String', 'nmi_opt_separate');

set(handles.all_objective_functions, 'String', '0');

set(handles.PDF, 'Enable', 'off');
set(handles.Kernel_title, 'Enable', 'off');

set(handles.number_of_bins_text, 'Enable', 'on');
set(handles.number_of_bins_slider, 'Enable', 'on');
set(handles.number_of_bins, 'Enable', 'on');

set(handles.overlap_scores_option, 'Enable', 'off');

set(handles.compression_type_title, 'Enable', 'off');
set(handles.compression_level_title, 'Enable', 'off');
set(handles.compression, 'Enable', 'off');
set(handles.compression_level, 'Enable', 'off');

% unset forced reference

set(handles.force_reference, 'String', '0');
set(handles.force_reference_button, 'Value', 0);

% ==================================================================== % 

function wavelet_option_Callback(hObject, eventdata, handles)

set(handles.sequential_mi_option_menu, 'Checked', 'off');
set(handles.sequential_nmi_option_menu, 'Checked', 'off');
set(handles.joint_msd_option_menu, 'Checked', 'off');
set(handles.joint_model_option_menu, 'Checked', 'off');
set(handles.sequential_msd_option_menu, 'Checked', 'off');
set(handles.sequential_model_option_menu, 'Checked', 'off');
set(handles.mixed_msd_model_option_menu, 'Checked', 'off');
set(handles.model_post_msd_option_menu, 'Checked', 'off');
set(handles.joint_mi_option_menu, 'Checked', 'off');
set(handles.joint_nmi_option_menu, 'Checked', 'off');
set(handles.button_all_objective_functions_menu, 'Checked', 'off');
set(handles.tfceccv_menu, 'Checked', 'off');
set(handles.wavelet_option_menu, 'Checked', 'on');
set(handles.model_pairs_menu, 'Checked', 'off');
set(handles.seq_model_pairs_menu, 'Checked', 'off');


set(handles.sequential_mi_option, 'Value', 0);
set(handles.sequential_nmi_option, 'Value', 0);
set(handles.joint_msd_option, 'Value', 0);
set(handles.joint_model_option, 'Value', 0);
set(handles.sequential_msd_option, 'Value', 0);
set(handles.sequential_model_option, 'Value', 0);
set(handles.mixed_msd_model_option, 'Value', 0);
set(handles.model_post_msd_option, 'Value', 0);
set(handles.wavelet_option, 'Value', 1);
set(handles.joint_mi_option, 'Value', 0);
set(handles.joint_nmi_option, 'Value', 0);
set(handles.tfceccv, 'Value', 0);
set(handles.button_all_objective_functions, 'Value', 0);

set(handles.objective_function_display, 'String', 'wavelet_complexity');

set(handles.all_objective_functions, 'String', '0');

set(handles.number_of_bins_text, 'Enable', 'off');
set(handles.number_of_bins_slider, 'Enable', 'off');
set(handles.number_of_bins, 'Enable', 'off');

set(handles.PDF, 'Enable', 'off');
set(handles.Kernel_title, 'Enable', 'off');

set(handles.overlap_scores_option, 'Enable', 'off');

set(handles.compression_type_title, 'Enable', 'on');
set(handles.compression_level_title, 'Enable', 'on');
set(handles.compression, 'Enable', 'on');
set(handles.compression_level, 'Enable', 'on');


set(handles.force_reference, 'String', '1');
set(handles.force_reference_button, 'Value', 1);

% ==================================================================== % 

function model_pairs_option_Callback(hObject, eventdata, handles)

set(handles.sequential_mi_option_menu, 'Checked', 'off');
set(handles.sequential_nmi_option_menu, 'Checked', 'off');
set(handles.joint_msd_option_menu, 'Checked', 'off');
set(handles.joint_model_option_menu, 'Checked', 'off');
set(handles.sequential_msd_option_menu, 'Checked', 'off');
set(handles.sequential_model_option_menu, 'Checked', 'off');
set(handles.mixed_msd_model_option_menu, 'Checked', 'off');
set(handles.model_post_msd_option_menu, 'Checked', 'off');
set(handles.joint_mi_option_menu, 'Checked', 'off');
set(handles.joint_nmi_option_menu, 'Checked', 'off');
set(handles.button_all_objective_functions_menu, 'Checked', 'off');
set(handles.tfceccv_menu, 'Checked', 'off');
set(handles.wavelet_option_menu, 'Checked', 'off');
set(handles.model_pairs_menu, 'Checked', 'on');
set(handles.seq_model_pairs_menu, 'Checked', 'off');

set(handles.objective_function_display, 'String', 'model_pairs_together');


% unset forced reference

set(handles.force_reference, 'String', '0');
set(handles.force_reference_button, 'Value', 0);


set(handles.sequential_mi_option, 'Value', 0);
set(handles.sequential_nmi_option, 'Value', 0);
set(handles.joint_msd_option, 'Value', 0);
set(handles.joint_model_option, 'Value', 0);
set(handles.sequential_msd_option, 'Value', 0);
set(handles.sequential_model_option, 'Value', 0);
set(handles.mixed_msd_model_option, 'Value', 0);
set(handles.model_post_msd_option, 'Value', 0);
set(handles.wavelet_option, 'Value', 0);
set(handles.joint_mi_option, 'Value', 0);
set(handles.joint_nmi_option, 'Value', 0);
set(handles.tfceccv, 'Value', 0);
set(handles.button_all_objective_functions, 'Value', 0);

set(handles.all_objective_functions, 'String', '0');

set(handles.number_of_bins_text, 'Enable', 'off');
set(handles.number_of_bins_slider, 'Enable', 'off');
set(handles.number_of_bins, 'Enable', 'off');

set(handles.PDF, 'Enable', 'off');
set(handles.Kernel_title, 'Enable', 'off');

set(handles.overlap_scores_option, 'Enable', 'off');

set(handles.compression_type_title, 'Enable', 'off');
set(handles.compression_level_title, 'Enable', 'off');
set(handles.compression, 'Enable', 'off');
set(handles.compression_level, 'Enable', 'off');

% ==================================================================== % 

function seq_model_pairs_option_Callback(hObject, eventdata, handles)

set(handles.sequential_mi_option_menu, 'Checked', 'off');
set(handles.sequential_nmi_option_menu, 'Checked', 'off');
set(handles.joint_msd_option_menu, 'Checked', 'off');
set(handles.joint_model_option_menu, 'Checked', 'off');
set(handles.sequential_msd_option_menu, 'Checked', 'off');
set(handles.sequential_model_option_menu, 'Checked', 'off');
set(handles.mixed_msd_model_option_menu, 'Checked', 'off');
set(handles.model_post_msd_option_menu, 'Checked', 'off');
set(handles.joint_mi_option_menu, 'Checked', 'off');
set(handles.joint_nmi_option_menu, 'Checked', 'off');
set(handles.button_all_objective_functions_menu, 'Checked', 'off');
set(handles.tfceccv_menu, 'Checked', 'off');
set(handles.wavelet_option_menu, 'Checked', 'off');
set(handles.model_pairs_menu, 'Checked', 'off');
set(handles.seq_model_pairs_menu, 'Checked', 'on');

set(handles.objective_function_display, 'String', 'model_pairs_separate');

% unset forced reference

set(handles.force_reference, 'String', '0');
set(handles.force_reference_button, 'Value', 0);

set(handles.sequential_mi_option, 'Value', 0);
set(handles.sequential_nmi_option, 'Value', 0);
set(handles.joint_msd_option, 'Value', 0);
set(handles.joint_model_option, 'Value', 0);
set(handles.sequential_msd_option, 'Value', 0);
set(handles.sequential_model_option, 'Value', 0);
set(handles.mixed_msd_model_option, 'Value', 0);
set(handles.model_post_msd_option, 'Value', 0);
set(handles.wavelet_option, 'Value', 0);
set(handles.joint_mi_option, 'Value', 0);
set(handles.joint_nmi_option, 'Value', 0);
set(handles.tfceccv, 'Value', 0);
set(handles.button_all_objective_functions, 'Value', 0);

set(handles.all_objective_functions, 'String', '0');

set(handles.number_of_bins_text, 'Enable', 'off');
set(handles.number_of_bins_slider, 'Enable', 'off');
set(handles.number_of_bins, 'Enable', 'off');

set(handles.PDF, 'Enable', 'off');
set(handles.Kernel_title, 'Enable', 'off');

set(handles.overlap_scores_option, 'Enable', 'off');

set(handles.compression_type_title, 'Enable', 'off');
set(handles.compression_level_title, 'Enable', 'off');
set(handles.compression, 'Enable', 'off');
set(handles.compression_level, 'Enable', 'off');

% ==================================================================== % 

function status_mode_menu_Callback(hObject, eventdata, handles)

% ==================================================================== % 

function options_Callback(hObject, eventdata, handles)

% ==================================================================== % 

function parameters_menu_Callback(hObject, eventdata, handles)

% ==================================================================== % 

function hierarchical_text_menu_Callback(hObject, eventdata, handles)

set(handles.progress_bar_menu, 'Checked', 'off');
set(handles.hierarchical_text_menu, 'Checked', 'on');
set(handles.quiet_menu, 'Checked', 'off');
set(handles.console_progress_bar, 'Checked', 'off');

set(handles.hierarchical_text, 'String', '0');

% ==================================================================== % 

function progress_bar_menu_Callback(hObject, eventdata, handles)

set(handles.progress_bar_menu, 'Checked', 'on');
set(handles.hierarchical_text_menu, 'Checked', 'off');
set(handles.quiet_menu, 'Checked', 'off');
set(handles.console_progress_bar, 'Checked', 'off');

set(handles.hierarchical_text, 'String', '1');

% ==================================================================== % 

function quiet_menu_Callback(hObject, eventdata, handles)

set(handles.progress_bar_menu, 'Checked', 'off');
set(handles.hierarchical_text_menu, 'Checked', 'off');
set(handles.quiet_menu, 'Checked', 'on');
set(handles.console_progress_bar, 'Checked', 'off');

set(handles.hierarchical_text, 'String', '2');

% ==================================================================== % 

function score_by_menu_CreateFcn(hObject, eventdata, handles)

if ispc
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end

% ==================================================================== % 

function score_by_menu_Callback(hObject, eventdata, handles)

% ==================================================================== % 

function score_model_by_menu_CreateFcn(hObject, eventdata, handles)


if ispc
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end

% ==================================================================== % 

function score_model_by_menu_Callback(hObject, eventdata, handles)

contents = get(hObject,'String');

if (strcmp(contents{get(hObject,'Value')},'Model Defaults')),
    set(handles.model_score_type, 'String', 'Default');
elseif (strcmp(contents{get(hObject,'Value')},'Specificity')),
    set(handles.model_score_type, 'String', 'Specificity');
elseif (strcmp(contents{get(hObject,'Value')},'Generalisability')),
    set(handles.model_score_type, 'String', 'Generalisability');
elseif (strcmp(contents{get(hObject,'Value')},'Mean MSD')),
    set(handles.model_score_type, 'String', 'Mean MSD');    
elseif (strcmp(contents{get(hObject,'Value')},'All')),
    set(handles.model_score_type, 'String', 'All');        
else
    error('Wrong values passed from scoring method. Internal error.');
end

% ==================================================================== % 

function Technical_Callback(hObject, eventdata, handles)

technical;

% ==================================================================== % 

function gen_slider_CreateFcn(hObject, eventdata, handles)

usewhitebg = 1;
if usewhitebg
    set(hObject,'BackgroundColor',[.9 .9 .9]);
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end

% ==================================================================== % 

function gen_slider_Callback(hObject, eventdata, handles)

set(handles.gen_iters, 'String', num2str(ceil(get(handles.gen_slider, 'Value'))));

% ==================================================================== % 

function spec_slider_CreateFcn(hObject, eventdata, handles)

usewhitebg = 1;
if usewhitebg
    set(hObject,'BackgroundColor',[.9 .9 .9]);
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end

% ==================================================================== % 

function spec_slider_Callback(hObject, eventdata, handles)

set(handles.spec_iters, 'String', num2str(ceil(get(handles.spec_slider, 'Value'))));

% ==================================================================== % 

function console_progress_bar_Callback(hObject, eventdata, handles)

set(handles.progress_bar_menu, 'Checked', 'off');
set(handles.hierarchical_text_menu, 'Checked', 'off');
set(handles.quiet_menu, 'Checked', 'off');
set(handles.console_progress_bar, 'Checked', 'on');

set(handles.hierarchical_text, 'String', '3');

% ==================================================================== % 

function warp_menu_CreateFcn(hObject, eventdata, handles)

if ispc
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end

% ==================================================================== % 

function warp_menu_Callback(hObject, eventdata, handles)

contents = get(hObject,'String');

if (strcmp(contents{get(hObject,'Value')},'Overlapping Warps')),
       set(handles.draw_warp_curve, 'String', '1');
       set(handles.draw_curve_by_images, 'String', '0');
       set(handles.show_warp_targets, 'String', '0');
       setappdata(0, 'draw_final_warps', '0');
elseif (strcmp(contents{get(hObject,'Value')},'Warps Map')),
       set(handles.draw_warp_curve, 'String', '0');
       set(handles.draw_curve_by_images, 'String', '1');
       set(handles.show_warp_targets, 'String', '0');
       setappdata(0, 'draw_final_warps', '0');
elseif (strcmp(contents{get(hObject,'Value')},'None')),
       set(handles.draw_warp_curve, 'String', '0');
       set(handles.draw_curve_by_images, 'String', '0');
       set(handles.show_warp_targets, 'String', '0');
       setappdata(0, 'draw_final_warps', '0');
elseif (strcmp(contents{get(hObject,'Value')},'All')),
       set(handles.draw_warp_curve, 'String', '1');
       set(handles.draw_curve_by_images, 'String', '1');
       set(handles.show_warp_targets, 'String', '1');
       setappdata(0, 'draw_final_warps', '1');
elseif (strcmp(contents{get(hObject,'Value')},'Targets Only')),
       set(handles.draw_warp_curve, 'String', '0');
       set(handles.draw_curve_by_images, 'String', '0');
       set(handles.show_warp_targets, 'String', '1');
       setappdata(0, 'draw_final_warps', '0');
elseif (strcmp(contents{get(hObject,'Value')},'Warps Map with Targets')),
       set(handles.draw_warp_curve, 'String', '0');
       set(handles.draw_curve_by_images, 'String', '1');
       set(handles.show_warp_targets, 'String', '1');
       setappdata(0, 'draw_final_warps', '0');
elseif (strcmp(contents{get(hObject,'Value')},'Overlapping Warps with Targets')),
       set(handles.draw_warp_curve, 'String', '1');
       set(handles.draw_curve_by_images, 'String', '0');
       set(handles.show_warp_targets, 'String', '1');
       setappdata(0, 'draw_final_warps', '0');
elseif (strcmp(contents{get(hObject,'Value')},'Final Warps')),
       set(handles.draw_warp_curve, 'String', '0');
       set(handles.draw_curve_by_images, 'String', '0');
       set(handles.show_warp_targets, 'String', '0');
       setappdata(0, 'draw_final_warps', '1');       
else
    error('Wrong values passed from warps menu. Internal error.');
end

% ==================================================================== % 

function save_mesh_option_Callback(hObject, eventdata, handles)

set(handles.save_plots_option, 'Value', 0);
set(handles.save_pixels_option, 'Value', 0);
set(handles.save_mesh_option, 'Value', 1);
set(handles.save_model_option, 'Value', 0);

set(handles.save_pixels, 'String', '2');

% ==================================================================== % 

function show_mesh_throughout_option_Callback(hObject, eventdata, handles)

if (get(handles.show_mesh_throughout_option,'Value') == 0),
    set(handles.show_mesh_throughout_option, 'Value', 0);
    set(handles.show_mesh, 'String', '0');
else
    set(handles.show_mesh_throughout_option, 'Value', 1);
    set(handles.show_mesh, 'String', '1');
end   

% ==================================================================== % 

function mesh_menu_CreateFcn(hObject, eventdata, handles)

if ispc
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end

% ==================================================================== % 

function mesh_menu_Callback(hObject, eventdata, handles)

contents = get(hObject,'String');

if (strcmp(contents{get(hObject,'Value')},'Surface Red')),
       set(handles.mesh_type, 'String', 'Surface Red');
       set(handles.rotate_surface, 'Enable', 'off');
elseif (strcmp(contents{get(hObject,'Value')},'Surface Blue')),
       set(handles.mesh_type, 'String', 'Surface Blue');
       set(handles.rotate_surface, 'Enable', 'off');
elseif (strcmp(contents{get(hObject,'Value')},'Polygons')),
       set(handles.mesh_type, 'String', 'Polygons');
       set(handles.rotate_surface, 'Enable', 'off');
elseif (strcmp(contents{get(hObject,'Value')},'Illuminated Surface')),
       set(handles.mesh_type, 'String', 'Illuminated Surface');
       set(handles.rotate_surface, 'Enable', 'on');
else
    error('Wrong values passed from mesh type menu. Internal error.');
end

% ==================================================================== % 

function advanced_button_Callback(hObject, eventdata, handles)

advanced;

% ==================================================================== % 

function frames_per_second_slider_CreateFcn(hObject, eventdata, handles)

usewhitebg = 1;
if usewhitebg
    set(hObject,'BackgroundColor',[.9 .9 .9]);
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end

% ==================================================================== % 

function frames_per_second_slider_Callback(hObject, eventdata, handles)

set(handles.frames_per_second, 'String', num2str(ceil(get(handles.frames_per_second_slider, 'Value'))));

% ==================================================================== % 

% The following will only be called if the images (axes) are void

function aart_pressed()

web http://www.danielsorogon.com/Webmaster/Projects/AART/

% ==================================================================== % 

function isbe_pressed()

web http://www.isbe.man.ac.uk

% ==================================================================== % 

function samples_pressed(hObject, eventdata, handles)

draw_data(hObject, eventdata, handles);

% ==================================================================== % 

function knotpoints_slider_CreateFcn(hObject, eventdata, handles)

usewhitebg = 1;
if usewhitebg
    set(hObject,'BackgroundColor',[.9 .9 .9]);
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end

% ==================================================================== % 

function knotpoints_slider_Callback(hObject, eventdata, handles)

set(handles.knot_points, 'String', num2str(ceil(get(handles.knotpoints_slider, 'Value'))));

% ==================================================================== % 

function show_registration_target_Callback(hObject, eventdata, handles)

if (get(handles.show_registration_target,'Value') == 0),
    set(handles.show_registration_target, 'Value', 0);
    set(handles.show_registration_target_flag, 'String', '0');
else
    set(handles.show_registration_target, 'Value', 1);
    set(handles.show_registration_target_flag, 'String', '1'); 
end  

% ==================================================================== % 

function produce_record_button_Callback(hObject, eventdata, handles)

if (get(handles.produce_record_button,'Value') == 0),
    set(handles.produce_record_button, 'Value', 0);
    set(handles.produce_record, 'String', '0');
else
    set(handles.produce_record_button, 'Value', 1);
    set(handles.produce_record, 'String', '1'); 
end  

% ==================================================================== % 

function initialise_warps_close_to_target_button_Callback(hObject, eventdata, handles)


if (get(handles.initialise_warps_close_to_target_button,'Value') == 0),
    set(handles.initialise_warps_close_to_target_button, 'Value', 0);
    set(handles.initialise_warps_close_to_target, 'String', '0');
    set(handles.perturb_option_button, 'Enable', 'off');
    set(handles.perturb_option_menuentry, 'Enable', 'off');
else
    set(handles.initialise_warps_close_to_target_button, 'Value', 1);
    set(handles.initialise_warps_close_to_target, 'String', '1'); 
    set(handles.perturb_option_button, 'Enable', 'on');
    set(handles.perturb_option_menuentry, 'Enable', 'on');
end  

% ==================================================================== % 

function save_in_log_button_Callback(hObject, eventdata, handles)

if (get(handles.save_in_log_button,'Value') == 0),
    set(handles.save_in_log_button, 'Value', 0);
    set(handles.save_in_log, 'String', '0');
else
    set(handles.save_in_log_button, 'Value', 1);
    set(handles.save_in_log, 'String', '1'); 
end  

% ==================================================================== % 

function perturb_option_menuentry_Callback(hObject, eventdata, handles)

perturb;

% ==================================================================== % 

function perturb_option_button_Callback(hObject, eventdata, handles)

perturb;

% ==================================================================== % 

function force_reference_button_Callback(hObject, eventdata, handles)

if (get(handles.force_reference_button,'Value') == 0),
    set(handles.force_reference_button, 'Value', 0);
    set(handles.force_reference, 'String', '0');
else
    set(handles.force_reference_button, 'Value', 1);
    set(handles.force_reference, 'String', '1'); 
end

% ==================================================================== % 

function cycle_slider_CreateFcn(hObject, eventdata, handles)

usewhitebg = 1;
if usewhitebg
    set(hObject,'BackgroundColor',[.9 .9 .9]);
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end

% ==================================================================== % 

function cycle_slider_Callback(hObject, eventdata, handles)

set(handles.cycle, 'String', num2str(ceil(get(handles.cycle_slider, 'Value'))));

% ==================================================================== % 

% function verbose_optimiser_Callback(hObject, eventdata, handles)
% 
% if (strcmp(get(handles.verbose_optimiser_flag,'String'),'off')),
%     set(handles.verbose_optimiser_flag, 'String', 'iter');
%     set(handles.verbose_optimiser, 'Checked', 'on');
% else
%     set(handles.verbose_optimiser_flag, 'String', 'off'); % notify, final also exist
%     set(handles.verbose_optimiser, 'Checked', 'off')
% end  

% ==================================================================== % 

function save_stats_menu_Callback(hObject, eventdata, handles)

if (str2num(get(handles.save_stats,'String')) == 0),
    set(handles.save_stats, 'String', '1');
    set(handles.save_stats_menu, 'Checked', 'on');
else
    set(handles.save_stats, 'String', '0');
    set(handles.save_stats_menu, 'Checked', 'off');    
end  

% ==================================================================== % 

function attr_height_Callback(hObject, eventdata, handles)

set(handles.base_height_slider, 'Value', 0.7);
set(handles.base_width_slider, 'Value', 0.5);
set(handles.height_variation_slider, 'Value', 0);
set(handles.width_variation_slider, 'Value', 0.2);
set(handles.position_freedom_slider, 'Value', 0.9);
set(handles.smoothness_slider, 'Value', 17);

set(handles.bump_width, 'String', '0.5');
set(handles.bump_width_variation, 'String', '0.2');
set(handles.bump_height, 'String', '0.7');
set(handles.bump_height_variation, 'String', '0');
set(handles.bump_position_freedom, 'String', '0.9');
set(handles.smoothness_factor, 'String', '17');

draw_data(hObject, eventdata, handles);

% ==================================================================== % 

function attr_low_var_Callback(hObject, eventdata, handles)

set(handles.base_height_slider, 'Value', 0.2);
set(handles.base_width_slider, 'Value', 0.5);
set(handles.height_variation_slider, 'Value', 0.1);
set(handles.width_variation_slider, 'Value', 0.1);
set(handles.position_freedom_slider, 'Value', 0.7);
set(handles.smoothness_slider, 'Value', 17);

set(handles.bump_width, 'String', '0.5');
set(handles.bump_width_variation, 'String', '0.1');
set(handles.bump_height, 'String', '0.2');
set(handles.bump_height_variation, 'String', '0.1');
set(handles.bump_position_freedom, 'String', '0.7');
set(handles.smoothness_factor, 'String', '17');

draw_data(hObject, eventdata, handles);

% ==================================================================== % 

function attr_typical_Callback(hObject, eventdata, handles)


set(handles.base_height_slider, 'Value', 0.2);
set(handles.base_width_slider, 'Value', 0.5);
set(handles.height_variation_slider, 'Value', 0.7);
set(handles.width_variation_slider, 'Value', 0.2);
set(handles.position_freedom_slider, 'Value', 0.9);
set(handles.smoothness_slider, 'Value', 17);

set(handles.bump_width, 'String', '0.5');
set(handles.bump_width_variation, 'String', '0.2');
set(handles.bump_height, 'String', '0.2');
set(handles.bump_height_variation, 'String', '0.7');
set(handles.bump_position_freedom, 'String', '0.9');
set(handles.smoothness_factor, 'String', '17');

% ==================================================================== % 

function Register_Callback(hObject, eventdata, handles)

register_1d_Callback(hObject, eventdata, handles);

% ==================================================================== % 

function Reset_Callback(hObject, eventdata, handles)

initialize_gui(hObject, handles);

% ==================================================================== % 

function export_default_Callback(hObject, eventdata, handles)

set(handles.disable_save, 'Checked', 'off');
set(handles.save_handle, 'Checked', 'off');
set(handles.export_default, 'Checked', 'on');
set(handles.save_data, 'String', '2');

% ==================================================================== % 

function save_model_option_Callback(hObject, eventdata, handles)

set(handles.save_plots_option, 'Value', 0);
set(handles.save_pixels_option, 'Value', 0);
set(handles.save_mesh_option, 'Value', 0);
set(handles.save_model_option, 'Value', 1);

set(handles.save_pixels, 'String', '3');

% ==================================================================== % 

function overnight1_Callback(hObject, eventdata, handles)

set(handles.overnight1, 'Checked', 'on');
set(handles.overnight2, 'Checked', 'off');
set(handles.overnight3, 'Checked', 'off');

set(handles.user_menus, 'Checked', 'off');
set(handles.default_parameters, 'Checked', 'off');
set(handles.max_test, 'Checked', 'off');
set(handles.normal_test, 'Checked', 'off');
set(handles.large_test, 'Checked', 'off');
set(handles.large_set, 'Checked', 'off');
set(handles.use_defaults, 'String', '6');

% ==================================================================== % 

function overnight2_Callback(hObject, eventdata, handles)

set(handles.overnight1, 'Checked', 'off');
set(handles.overnight2, 'Checked', 'on');
set(handles.overnight3, 'Checked', 'off');

set(handles.user_menus, 'Checked', 'off');
set(handles.default_parameters, 'Checked', 'off');
set(handles.max_test, 'Checked', 'off');
set(handles.normal_test, 'Checked', 'off');
set(handles.large_test, 'Checked', 'off');
set(handles.large_set, 'Checked', 'off');
set(handles.use_defaults, 'String', '7');

% ==================================================================== % 

function overnight3_Callback(hObject, eventdata, handles)

set(handles.overnight1, 'Checked', 'off');
set(handles.overnight2, 'Checked', 'off');
set(handles.overnight3, 'Checked', 'on');

set(handles.user_menus, 'Checked', 'off');
set(handles.default_parameters, 'Checked', 'off');
set(handles.max_test, 'Checked', 'off');
set(handles.normal_test, 'Checked', 'off');
set(handles.large_test, 'Checked', 'off');
set(handles.large_set, 'Checked', 'off');
set(handles.use_defaults, 'String', '8');

draw_data(hObject, eventdata, handles);

% ==================================================================== % 

function large_test_Callback(hObject, eventdata, handles)

set(handles.overnight1, 'Checked', 'off');
set(handles.overnight2, 'Checked', 'off');
set(handles.overnight3, 'Checked', 'off');

set(handles.user_menus, 'Checked', 'off');
set(handles.default_parameters, 'Checked', 'off');
set(handles.max_test, 'Checked', 'off');
set(handles.normal_test, 'Checked', 'off');
set(handles.large_test, 'Checked', 'on');
set(handles.large_set, 'Checked', 'off');
set(handles.use_defaults, 'String', '4');

% ==================================================================== % 

function large_set_Callback(hObject, eventdata, handles)

set(handles.overnight1, 'Checked', 'off');
set(handles.overnight2, 'Checked', 'off');
set(handles.overnight3, 'Checked', 'off');

set(handles.user_menus, 'Checked', 'off');
set(handles.default_parameters, 'Checked', 'off');
set(handles.max_test, 'Checked', 'off');
set(handles.normal_test, 'Checked', 'off');
set(handles.large_test, 'Checked', 'off');
set(handles.large_set, 'Checked', 'on');
set(handles.use_defaults, 'String', '5');

% ==================================================================== % 

function user_menus_Callback(hObject, eventdata, handles)

set(handles.overnight1, 'Checked', 'off');
set(handles.overnight2, 'Checked', 'off');
set(handles.overnight3, 'Checked', 'off');

set(handles.user_menus, 'Checked', 'on');
set(handles.default_parameters, 'Checked', 'off');
set(handles.max_test, 'Checked', 'off');
set(handles.normal_test, 'Checked', 'off');
set(handles.large_test, 'Checked', 'off');
set(handles.large_set, 'Checked', 'off');
set(handles.use_defaults, 'String', '1');

% ==================================================================== % 

function default_parameters_Callback(hObject, eventdata, handles)

set(handles.overnight1, 'Checked', 'off');
set(handles.overnight2, 'Checked', 'off');
set(handles.overnight3, 'Checked', 'off');

set(handles.user_menus, 'Checked', 'off');
set(handles.default_parameters, 'Checked', 'on');
set(handles.max_test, 'Checked', 'off');
set(handles.normal_test, 'Checked', 'off');
set(handles.large_test, 'Checked', 'off');
set(handles.large_set, 'Checked', 'off');
set(handles.use_defaults, 'String', '0');

% ==================================================================== % 

function max_test_Callback(hObject, eventdata, handles)

set(handles.overnight1, 'Checked', 'off');
set(handles.overnight2, 'Checked', 'off');
set(handles.overnight3, 'Checked', 'off');

set(handles.user_menus, 'Checked', 'off');
set(handles.default_parameters, 'Checked', 'off');
set(handles.max_test, 'Checked', 'on');
set(handles.normal_test, 'Checked', 'off');
set(handles.large_test, 'Checked', 'off');
set(handles.large_set, 'Checked', 'off');
set(handles.use_defaults, 'String', '2');

% ==================================================================== % 

function normal_test_Callback(hObject, eventdata, handles)

set(handles.overnight1, 'Checked', 'off');
set(handles.overnight2, 'Checked', 'off');
set(handles.overnight3, 'Checked', 'off');

set(handles.user_menus, 'Checked', 'off');
set(handles.default_parameters, 'Checked', 'off');
set(handles.max_test, 'Checked', 'off');
set(handles.normal_test, 'Checked', 'on');
set(handles.large_test, 'Checked', 'off');
set(handles.large_set, 'Checked', 'off');
set(handles.use_defaults, 'String', '3');

% ==================================================================== % 

function automation_button_Callback(hObject, eventdata, handles)

automation;

% ==================================================================== % 

function automation_menu_Callback(hObject, eventdata, handles)

automation;

% ==================================================================== % 

function show_warps_while_optimising_Callback(hObject, eventdata, handles)

if (strcmp(get(handles.show_warps_while_optimising_flag,'String'),'0')),
    set(handles.show_warps_while_optimising_flag, 'String', '1');
    set(handles.show_warps_while_optimising, 'Checked', 'on');
else
    set(handles.show_warps_while_optimising_flag, 'String', '0');
    set(handles.show_warps_while_optimising, 'Checked', 'off')
end  

% ==================================================================== % 

function abort_Callback(hObject, eventdata, handles)

error('Registration Aborted');

% ==================================================================== % 

function verbose_disabled_Callback(hObject, eventdata, handles)

    set(handles.verbose_optimiser_flag, 'String', 'off');
    set(handles.verbose_disabled, 'Checked', 'on');
    set(handles.verbose_iteration, 'Checked', 'off');
    set(handles.verbose_notify, 'Checked', 'off');
    set(handles.verbose_final, 'Checked', 'off');

% ==================================================================== % 

function verbose_iterations_Callback(hObject, eventdata, handles)

    set(handles.verbose_optimiser_flag, 'String', 'iter');
    set(handles.verbose_disabled, 'Checked', 'off');
    set(handles.verbose_iteration, 'Checked', 'on');
    set(handles.verbose_notify, 'Checked', 'off');
    set(handles.verbose_final, 'Checked', 'off');

% ==================================================================== % 

function verbose_notify_Callback(hObject, eventdata, handles)

    set(handles.verbose_optimiser_flag, 'String', 'notify');
    set(handles.verbose_disabled, 'Checked', 'off');
    set(handles.verbose_iteration, 'Checked', 'off');
    set(handles.verbose_notify, 'Checked', 'on');
    set(handles.verbose_final, 'Checked', 'off');
    
% ==================================================================== % 

function verbose_final_Callback(hObject, eventdata, handles)

    set(handles.verbose_optimiser_flag, 'String', 'final');
    set(handles.verbose_disabled, 'Checked', 'off');
    set(handles.verbose_iteration, 'Checked', 'off');
    set(handles.verbose_notify, 'Checked', 'off');
    set(handles.verbose_final, 'Checked', 'on');

% ==================================================================== %     
    
function description_CreateFcn(hObject, eventdata, handles)

if ispc
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end

% ==================================================================== % 

function description_Callback(hObject, eventdata, handles)

% ==================================================================== % 

function clear_status_bar_Callback(hObject, eventdata, handles)

set(handles.status_bar, 'String', '');

% ==================================================================== % 

function handle_auto_Callback(hObject, eventdata, handles)


set(handles.filename_handle, 'String', [['Registration attempt number ']]);

% ==================================================================== % 

function desc_auto_Callback(hObject, eventdata, handles)

set(handles.description, 'String', [['Registration using '], ...
        [get(handles.objective_function_display,'String')], ...
        [' with '], [get(handles.spline_type_display,'String')], [' warps']]);

% ==================================================================== % 

function handle_clear_Callback(hObject, eventdata, handles)
set(handles.filename_handle, 'String', '');

% ==================================================================== % 

function desc_clear_Callback(hObject, eventdata, handles)
set(handles.description, 'String', '');

% ==================================================================== % 

function handle_rand_Callback(hObject, eventdata, handles)
set(handles.filename_handle, 'String', num2str(ceil(rand * 10000000)));

% ==================================================================== % 

function desc_rand_Callback(hObject, eventdata, handles)
set(handles.description, 'String', num2str(ceil(rand * 10000000)));

% ==================================================================== % 

function find_perfect_warp_menu_Callback(hObject, eventdata, handles)

if (str2num(getappdata(0, 'find_perfect_warp')) == 0),
    setappdata(0, 'find_perfect_warp', '1');
    set(handles.find_perfect_warp_menu, 'Checked', 'on');
else
    setappdata(0, 'find_perfect_warp', '0');
    set(handles.find_perfect_warp_menu, 'Checked', 'off');    
end

% ==================================================================== % 

function first_reference_menu_Callback(hObject, eventdata, handles)

setappdata(0, 'force_first_reference', '1');

set(handles.first_reference_menu, 'Checked', 'on'); 
set(handles.second_reference_menu, 'Checked', 'off'); 
set(handles.reference_nearest_to_average_menu, 'Checked', 'off'); 
set(handles.random_reference_menu, 'Checked', 'off'); 
set(handles.reference_farthest_from_average_menu, 'Checked', 'off');
set(handles.lowest_reference_menu, 'Checked', 'off'); 
set(handles.highest_reference_menu, 'Checked', 'off'); 

% ==================================================================== % 

function second_reference_menu_Callback(hObject, eventdata, handles)

setappdata(0, 'force_first_reference', '0');

set(handles.first_reference_menu, 'Checked', 'off'); 
set(handles.second_reference_menu, 'Checked', 'on'); 
set(handles.reference_nearest_to_average_menu, 'Checked', 'off'); 
set(handles.random_reference_menu, 'Checked', 'off'); 
set(handles.reference_farthest_from_average_menu, 'Checked', 'off');
set(handles.lowest_reference_menu, 'Checked', 'off'); 
set(handles.highest_reference_menu, 'Checked', 'off'); 

% ==================================================================== % 

function reference_nearest_to_average_menu_Callback(hObject, eventdata, handles)

setappdata(0, 'force_first_reference', '2');

set(handles.first_reference_menu, 'Checked', 'off'); 
set(handles.second_reference_menu, 'Checked', 'off'); 
set(handles.reference_nearest_to_average_menu, 'Checked', 'on'); 
set(handles.random_reference_menu, 'Checked', 'off');
set(handles.reference_farthest_from_average_menu, 'Checked', 'off');
set(handles.lowest_reference_menu, 'Checked', 'off'); 
set(handles.highest_reference_menu, 'Checked', 'off'); 

% ==================================================================== % 

function random_reference_menu_Callback(hObject, eventdata, handles)

setappdata(0, 'force_first_reference', '3');

set(handles.random_reference_menu, 'Checked', 'on'); 
set(handles.first_reference_menu, 'Checked', 'off'); 
set(handles.second_reference_menu, 'Checked', 'off'); 
set(handles.reference_nearest_to_average_menu, 'Checked', 'off'); 
set(handles.reference_farthest_from_average_menu, 'Checked', 'off');
set(handles.lowest_reference_menu, 'Checked', 'off'); 
set(handles.highest_reference_menu, 'Checked', 'off'); 

% ==================================================================== % 

function reference_farthest_from_average_menu_Callback(hObject, eventdata, handles)

setappdata(0, 'force_first_reference', '4');

set(handles.random_reference_menu, 'Checked', 'off'); 
set(handles.first_reference_menu, 'Checked', 'off'); 
set(handles.second_reference_menu, 'Checked', 'off'); 
set(handles.reference_nearest_to_average_menu, 'Checked', 'off'); 
set(handles.reference_farthest_from_average_menu, 'Checked', 'on'); 
set(handles.lowest_reference_menu, 'Checked', 'off'); 
set(handles.highest_reference_menu, 'Checked', 'off'); 

% ==================================================================== % 

function lowest_reference_menu_Callback(hObject, eventdata, handles)

setappdata(0, 'force_first_reference', '6');

set(handles.random_reference_menu, 'Checked', 'off'); 
set(handles.first_reference_menu, 'Checked', 'off'); 
set(handles.second_reference_menu, 'Checked', 'off'); 
set(handles.reference_nearest_to_average_menu, 'Checked', 'off'); 
set(handles.reference_farthest_from_average_menu, 'Checked', 'off'); 
set(handles.lowest_reference_menu, 'Checked', 'on'); 
set(handles.highest_reference_menu, 'Checked', 'off'); 

% ==================================================================== % 

function highest_reference_menu_Callback(hObject, eventdata, handles)

setappdata(0, 'force_first_reference', '5');

set(handles.random_reference_menu, 'Checked', 'off'); 
set(handles.first_reference_menu, 'Checked', 'off'); 
set(handles.second_reference_menu, 'Checked', 'off'); 
set(handles.reference_nearest_to_average_menu, 'Checked', 'off'); 
set(handles.reference_farthest_from_average_menu, 'Checked', 'off'); 
set(handles.lowest_reference_menu, 'Checked', 'off'); 
set(handles.highest_reference_menu, 'Checked', 'on'); 

% ==================================================================== % 

function display_shape_model_menu_Callback(hObject, eventdata, handles)

if (str2num(getappdata(0, 'display_shape_model')) == 0),
    setappdata(0, 'display_shape_model', '1');
    set(handles.display_shape_model_menu, 'Checked', 'on');
else
    setappdata(0, 'display_shape_model', '0');
    set(handles.display_shape_model_menu, 'Checked', 'off');    
end  

% ==================================================================== % 

function display_intensity_model_menu_Callback(hObject, eventdata, handles)

if (str2num(getappdata(0, 'display_intensity_model')) == 0),
    setappdata(0, 'display_intensity_model', '1');
    set(handles.display_intensity_model_menu, 'Checked', 'on');
else
    setappdata(0, 'display_intensity_model', '0');
    set(handles.display_intensity_model_menu, 'Checked', 'off');    
end  

% ==================================================================== % 

function plot_alignment_button_Callback(hObject, eventdata, handles)

if (get(handles.plot_alignment_button,'Value') == 0),
    set(handles.plot_alignment_button, 'Value', 0);
    setappdata(0, 'plot_alignment', '0');
else
    set(handles.plot_alignment_button, 'Value', 1);
    setappdata(0, 'plot_alignment', '1');
end

% ==================================================================== % 

function verbosity_normal_Callback(hObject, eventdata, handles)

setappdata(0, 'error_verbosity', 'normal');
set(handles.verbosity_low, 'Checked', 'off');
set(handles.verbosity_normal, 'Checked', 'on');
set(handles.verbosity_high, 'Checked', 'off');

% ==================================================================== % 

function verbosity_low_Callback(hObject, eventdata, handles)

setappdata(0, 'error_verbosity', 'low');
set(handles.verbosity_low, 'Checked', 'on');
set(handles.verbosity_normal, 'Checked', 'off');
set(handles.verbosity_high, 'Checked', 'off');

% ==================================================================== % 

function verbosity_high_Callback(hObject, eventdata, handles)

setappdata(0, 'error_verbosity', 'high');
set(handles.verbosity_low, 'Checked', 'off');
set(handles.verbosity_normal, 'Checked', 'off');
set(handles.verbosity_high, 'Checked', 'on');

% ==================================================================== % 

function error_verbosity_menu_Callback(hObject, eventdata, handles)

% ==================================================================== % 

function input_output_menu_Callback(hObject, eventdata, handles)

% ==================================================================== % 

function precision_9_Callback(hObject, eventdata, handles)

setappdata(0, 'precision_required', '1e-9');

set(handles.precision_5, 'Checked', 'on');
set(handles.precision_6, 'Checked', 'off');
set(handles.precision_7, 'Checked', 'off');
set(handles.precision_8, 'Checked', 'off');
set(handles.precision_9, 'Checked', 'off');
set(handles.precision_10, 'Checked', 'off');
set(handles.precision_12, 'Checked', 'off');
set(handles.precision_15, 'Checked', 'off');
set(handles.precision_3, 'Checked', 'off');
set(handles.precision_4, 'Checked', 'off');

% ==================================================================== % 

function precision_8_Callback(hObject, eventdata, handles)

setappdata(0, 'precision_required', '1e-8');
set(handles.precision_5, 'Checked', 'off');
set(handles.precision_6, 'Checked', 'off');
set(handles.precision_7, 'Checked', 'off');
set(handles.precision_8, 'Checked', 'off');
set(handles.precision_9, 'Checked', 'off');
set(handles.precision_10, 'Checked', 'off');
set(handles.precision_12, 'Checked', 'off');
set(handles.precision_15, 'Checked', 'off');
set(handles.precision_3, 'Checked', 'off');
set(handles.precision_4, 'Checked', 'off');

% ==================================================================== % 

function precision_6_Callback(hObject, eventdata, handles)

setappdata(0, 'precision_required', '1e-6');
set(handles.precision_5, 'Checked', 'off');
set(handles.precision_6, 'Checked', 'on');
set(handles.precision_7, 'Checked', 'off');
set(handles.precision_8, 'Checked', 'off');
set(handles.precision_9, 'Checked', 'off');
set(handles.precision_10, 'Checked', 'off');
set(handles.precision_12, 'Checked', 'off');
set(handles.precision_15, 'Checked', 'off');
set(handles.precision_3, 'Checked', 'off');
set(handles.precision_4, 'Checked', 'off');

% ==================================================================== % 

function precision_5_Callback(hObject, eventdata, handles)

setappdata(0, 'precision_required', '1e-5');
set(handles.precision_5, 'Checked', 'on');
set(handles.precision_6, 'Checked', 'off');
set(handles.precision_7, 'Checked', 'off');
set(handles.precision_8, 'Checked', 'off');
set(handles.precision_9, 'Checked', 'off');
set(handles.precision_10, 'Checked', 'off');
set(handles.precision_12, 'Checked', 'off');
set(handles.precision_15, 'Checked', 'off');
set(handles.precision_3, 'Checked', 'off');
set(handles.precision_4, 'Checked', 'off');

% ==================================================================== % 

function precision_7_Callback(hObject, eventdata, handles)

setappdata(0, 'precision_required', '1e-7');
set(handles.precision_5, 'Checked', 'off');
set(handles.precision_6, 'Checked', 'off');
set(handles.precision_7, 'Checked', 'on');
set(handles.precision_8, 'Checked', 'off');
set(handles.precision_9, 'Checked', 'off');
set(handles.precision_10, 'Checked', 'off');
set(handles.precision_12, 'Checked', 'off');
set(handles.precision_15, 'Checked', 'off');
set(handles.precision_3, 'Checked', 'off');
set(handles.precision_4, 'Checked', 'off');

% ==================================================================== % 

function precision_10_Callback(hObject, eventdata, handles)

setappdata(0, 'precision_required', '1e-10');
set(handles.precision_5, 'Checked', 'off');
set(handles.precision_6, 'Checked', 'off');
set(handles.precision_7, 'Checked', 'off');
set(handles.precision_8, 'Checked', 'off');
set(handles.precision_9, 'Checked', 'off');
set(handles.precision_10, 'Checked', 'on');
set(handles.precision_12, 'Checked', 'off');
set(handles.precision_15, 'Checked', 'off');
set(handles.precision_3, 'Checked', 'off');
set(handles.precision_4, 'Checked', 'off');

% ==================================================================== % 

function precision_12_Callback(hObject, eventdata, handles)

setappdata(0, 'precision_required', '1e-12');
set(handles.precision_5, 'Checked', 'off');
set(handles.precision_6, 'Checked', 'off');
set(handles.precision_7, 'Checked', 'off');
set(handles.precision_8, 'Checked', 'off');
set(handles.precision_9, 'Checked', 'off');
set(handles.precision_10, 'Checked', 'off');
set(handles.precision_12, 'Checked', 'on');
set(handles.precision_15, 'Checked', 'off');
set(handles.precision_3, 'Checked', 'off');
set(handles.precision_4, 'Checked', 'off');

% ==================================================================== % 

function precision_15_Callback(hObject, eventdata, handles)

setappdata(0, 'precision_required', '1e-15');
set(handles.precision_5, 'Checked', 'off');
set(handles.precision_6, 'Checked', 'off');
set(handles.precision_7, 'Checked', 'off');
set(handles.precision_8, 'Checked', 'off');
set(handles.precision_9, 'Checked', 'off');
set(handles.precision_10, 'Checked', 'off');
set(handles.precision_12, 'Checked', 'off');
set(handles.precision_15, 'Checked', 'on');
set(handles.precision_3, 'Checked', 'off');
set(handles.precision_4, 'Checked', 'off');

% ==================================================================== % 

function precision_4_Callback(hObject, eventdata, handles)

setappdata(0, 'precision_required', '1e-4');
set(handles.precision_5, 'Checked', 'off');
set(handles.precision_6, 'Checked', 'off');
set(handles.precision_7, 'Checked', 'off');
set(handles.precision_8, 'Checked', 'off');
set(handles.precision_9, 'Checked', 'off');
set(handles.precision_10, 'Checked', 'off');
set(handles.precision_12, 'Checked', 'off');
set(handles.precision_15, 'Checked', 'off');
set(handles.precision_3, 'Checked', 'off');
set(handles.precision_4, 'Checked', 'on');

% ==================================================================== % 

function precision_3_Callback(hObject, eventdata, handles)

setappdata(0, 'precision_required', '1e-3');
set(handles.precision_5, 'Checked', 'off');
set(handles.precision_6, 'Checked', 'off');
set(handles.precision_7, 'Checked', 'off');
set(handles.precision_8, 'Checked', 'off');
set(handles.precision_9, 'Checked', 'off');
set(handles.precision_10, 'Checked', 'off');
set(handles.precision_12, 'Checked', 'off');
set(handles.precision_15, 'Checked', 'off');
set(handles.precision_3, 'Checked', 'on');
set(handles.precision_4, 'Checked', 'off');

% ==================================================================== % 

function set_background_colour_Callback(hObject, eventdata, handles)

RGB = uisetcolor;

% open dialog to select colour for background of plots


if (size(RGB, 2) == 3),
      % just in case the dialog was closed
	setappdata(0, 'background_colour_red', num2str(RGB(1)));
	setappdata(0, 'background_colour_green', num2str(RGB(2)));
	setappdata(0, 'background_colour_blue', num2str(RGB(3)));
end    

% May 2004: yet not fully used

% ==================================================================== % 

function dynamic_precision_Callback(hObject, eventdata, handles)


if (str2num(getappdata(0, 'dynamic_precision')) == 0),
    set(handles.dynamic_precision, 'Checked', 'on');
    setappdata(0, 'dynamic_precision', '1');
else
    set(handles.dynamic_precision, 'Checked', 'off');
    setappdata(0, 'dynamic_precision', '0');
end

% ==================================================================== % 

function clone_menu_Callback(hObject, eventdata, handles)

  register;

% ==================================================================== % 

function clone_Callback(hObject, eventdata, handles)

  register;
  
% ==================================================================== % 

  function show_icons_Callback(hObject, eventdata, handles)

  set(handles.resume, 'cdata', playbutton);
  set(handles.pause, 'cdata', stopbutton);
  set(handles.register_1d, 'cdata', registerbutton);
  set(handles.help_button, 'cdata', helpbutton);
  set(handles.abort, 'cdata', abortbutton);
  set(handles.reset, 'cdata', resetbutton);
  
  set(handles.show_icons, 'Checked', 'on');
  set(handles.hide_icons, 'Checked', 'off');

% ==================================================================== % 

function hide_icons_Callback(hObject, eventdata, handles)

  set(handles.resume, 'cdata', []);
  set(handles.pause, 'cdata', []);
  set(handles.register_1d, 'cdata', []);
  set(handles.help_button, 'cdata', []);
  set(handles.abort, 'cdata', []);
  set(handles.reset, 'cdata', []);
  
  set(handles.show_icons, 'Checked', 'off');
  set(handles.hide_icons, 'Checked', 'on');
  
% ==================================================================== % 
  
function document_code_Callback(hObject, eventdata, handles)

  document_aart;
  
% ==================================================================== %  

function redefine_paths_Callback(hObject, eventdata, handles)
  
  path;
  
% ==================================================================== %

function application_editor_Callback(hObject, eventdata, handles)

  msgbox('To prevent conflicting modifications, please contact Roy Schestowitz before making any changes.','Important Notification');
  mb;
  
% ==================================================================== %
  
function default_auto_Callback(hObject, eventdata, handles)  

  setappdata(0, 'automatic_precision_type', 'default');
  set(handles.default_auto, 'Checked', 'on');
  set(handles.smart_auto, 'Checked', 'off');
  
% ==================================================================== %  

function smart_auto_Callback(hObject, eventdata, handles)  
  
  setappdata(0, 'automatic_precision_type', 'smart');
  set(handles.default_auto, 'Checked', 'off');
  set(handles.smart_auto, 'Checked', 'on');
  
% ==================================================================== %  
  
function rotate_surface_Callback(hObject, eventdata, handles)   
  if (str2num(getappdata(0, 'rotate_surface')) == 0),
    set(handles.rotate_surface, 'Value', 1);
    setappdata(0, 'rotate_surface', '1');
  else
    set(handles.rotate_surface, 'Value', 0);
    setappdata(0, 'rotate_surface', '0');
  end

% ==================================================================== %
  
function Sum_of_Squared_Distances_Callback(hObject, eventdata, handles)

  setappdata(0, 'distance_type', 'sum_of_squared_distances');  
  set(handles.Sum_of_Squared_Distances, 'Checked', 'on');
  set(handles.Absolute_Distances, 'Checked', 'off');

% ==================================================================== %

function Absolute_Distances_Callback(hObject, eventdata, handles)   

  setappdata(0, 'distance_type', 'absolute_values');
  set(handles.Sum_of_Squared_Distances, 'Checked', 'off');
  set(handles.Absolute_Distances, 'Checked', 'on');

% ==================================================================== %

function retain_original_peak_menu_Callback(hObject, eventdata, handles)    
  
if (str2num(getappdata(0, 'retain_original_peak')) == 0),  
  setappdata(0, 'retain_original_peak', '1');
  set(handles.retain_original_peak_menu, 'Checked', 'on');
else
  setappdata(0, 'retain_original_peak', '0');
  set(handles.retain_original_peak_menu, 'Checked', 'off');
end

% ==================================================================== %

function peak_type_average_menu_Callback(hObject, eventdata, handles)
  
setappdata(0, 'peak_type', 'average_position');
set(handles.peak_type_average_menu, 'Checked', 'on');
set(handles.peak_type_initial_menu, 'Checked', 'off');

% ==================================================================== %

function peak_type_initial_menu_Callback(hObject, eventdata, handles)    
  
setappdata(0, 'peak_type', 'initial_position');
set(handles.peak_type_average_menu, 'Checked', 'off');
set(handles.peak_type_initial_menu, 'Checked', 'on');

% ==================================================================== %

function add_points_menu_Callback(hObject, eventdata, handles)   
if (str2num(getappdata(0, 'add_points')) == 0),  
  setappdata(0, 'add_points', '1');
  set(handles.add_points_menu, 'Checked', 'on');
else
  setappdata(0, 'add_points', '0');
  set(handles.add_points_menu, 'Checked', 'off');
end

% ==================================================================== %

function generate_html_menu_Callback(hObject, eventdata, handles) 

aart_html;

% ==================================================================== %

function point_stuffing_cycle_1_Callback(hObject, eventdata, handles) 

setappdata(0, 'add_points_cycle', '1');

set(handles.point_stuffing_cycle_1, 'Checked', 'on');
set(handles.point_stuffing_cycle_10, 'Checked', 'off');
set(handles.point_stuffing_cycle_100, 'Checked', 'off');

% ==================================================================== %

function point_stuffing_cycle_10_Callback(hObject, eventdata, handles) 

setappdata(0, 'add_points_cycle', '10');

set(handles.point_stuffing_cycle_1, 'Checked', 'off');
set(handles.point_stuffing_cycle_10, 'Checked', 'on');
set(handles.point_stuffing_cycle_100, 'Checked', 'off');

% ==================================================================== %

function point_stuffing_cycle_100_Callback(hObject, eventdata, handles) 

setappdata(0, 'add_points_cycle', '100');

set(handles.point_stuffing_cycle_1, 'Checked', 'off');
set(handles.point_stuffing_cycle_10, 'Checked', 'off');
set(handles.point_stuffing_cycle_100, 'Checked', 'on');

% ==================================================================== %

function stamp_images_Callback(hObject, eventdata, handles)

status = add_watermarks_to_all_files;
set(handles.status_bar, 'String', status);


function stamp_images_menu_Callback(hObject, eventdata, handles)

if (str2num(getappdata(0, 'stamp_images')) == 0),  
  setappdata(0, 'stamp_images', '1');
  set(handles.stamp_images_menu, 'Checked', 'on');
else
  setappdata(0, 'stamp_images', '0');
  set(handles.stamp_images_menu, 'Checked', 'off');
end

% ==================================================================== %

function auto_weighting_menu_Callback(hObject, eventdata, handles)


if (strcmp(get(handles.auto_weighting_menu, 'Checked'), 'off')),  
  set(handles.auto_weighting_menu, 'Checked', 'on');
else
  set(handles.auto_weighting_menu, 'Checked', 'off');
end

% ==================================================================== %

function smart_weighting_type_Callback(hObject, eventdata, handles)

set(handles.smart_weighting_type, 'Checked', 'on');
set(handles.default_weighting_type, 'Checked', 'off');

setappdata(0, 'automatic_weighting_type', 'smart');
 
% ==================================================================== %

function default_weighting_type_Callback(hObject, eventdata, handles)

set(handles.smart_weighting_type, 'Checked', 'off');
set(handles.default_weighting_type, 'Checked', 'on');

setappdata(0, 'automatic_weighting_type', 'default');

% ==================================================================== %

function show_inverse_projection_Callback(hObject, eventdata, handles)


if (strcmp(get(handles.show_inverse_projection, 'Checked'), 'off')),  
  set(handles.show_inverse_projection, 'Checked', 'on');
else
  set(handles.show_inverse_projection, 'Checked', 'off');
end

% ==================================================================== %

function show_model_reconstruction_for_warped_images_Callback(hObject, eventdata, handles)


if (strcmp(get(handles.show_model_reconstruction_for_warped_images, 'Checked'), 'off')),  
  set(handles.show_model_reconstruction_for_warped_images, 'Checked', 'on');
else
  set(handles.show_model_reconstruction_for_warped_images, 'Checked', 'off');
end

% ==================================================================== %

function steepest_warp_menu_Callback(hObject, eventdata, handles)

setappdata(0, 'point_insertion_position', 'steepest warp');
set(handles.steepest_warp_menu, 'Checked', 'on');
set(handles.highest_model_discrepancy_menu, 'Checked', 'off');

% ==================================================================== %

function highest_model_discrepancy_menu_Callback(hObject, eventdata, handles)

setappdata(0, 'point_insertion_position', 'highest_model_discrepancy');
set(handles.steepest_warp_menu, 'Checked', 'off');
set(handles.highest_model_discrepancy_menu, 'Checked', 'on');