function varargout = Stimuli_3D(varargin)
%%%Dr. Ignacio Serrano-Pedraza 2018
%%%iserrano@ucm.es

% STIMULI_3D MATLAB code for Stimuli_3D.fig
%      STIMULI_3D, by itself, creates a new STIMULI_3D or raises the existing
%      singleton*.
%
%      H = STIMULI_3D returns the handle to a new STIMULI_3D or the handle to
%      the existing singleton*.
%
%      STIMULI_3D('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in STIMULI_3D.M with the given input arguments.
%
%      STIMULI_3D('Property','Value',...) creates a new STIMULI_3D or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before Stimuli_3D_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to Stimuli_3D_OpeningFcn via varargin.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
%      instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help Stimuli_3D

% Last Modified by GUIDE v2.5 15-Mar-2018 15:24:09

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @Stimuli_3D_OpeningFcn, ...
                   'gui_OutputFcn',  @Stimuli_3D_OutputFcn, ...
                   'gui_LayoutFcn',  [] , ...
                   'gui_Callback',   []);
if nargin && ischar(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT

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

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

% Play_sound handles structure
guidata(hObject, handles);

Plot_figure(hObject, eventdata, handles)


function Plot_figure(hObject, eventdata, handles)
expt = getexpt(handles);
for i=1:255
    r(i)=i/255;
    g(i)=i/255;
    b(i)=i/255;
end

  gray2=[r',g',b'];
  colormap(gray2); 
  map=colormap;

gradosimagenx=expt.visualangle;
gradosimageny=gradosimagenx;
TAMX=512;
TAMY=512;
gx=gradosimagenx/TAMX;%Grados de angulo visual del pixel en la direccion x
gy=gradosimageny/TAMY;%Grados de angulo visual del pixel en la direccion y

[x,y]=meshgrid(-gradosimagenx/2:(gradosimagenx/TAMX):((gradosimagenx/2)-(gradosimagenx/TAMX))...
    ,((gradosimageny/2)):-(gradosimageny/TAMY):-((gradosimageny/2)-(gradosimageny/TAMY)));


Angulo=expt.Orientation; 
xx=x.*cosd(Angulo)+y.*sind(Angulo);
yy=-x.*sind(Angulo)+y.*cosd(Angulo);


x0=0;
y0=0;
sx=expt.SizeX;
sy=expt.SizeY;


%sx=sqrt(log(2)).*(1+2.^BOCT)./(pi*sqrt(2).*u1.*(2.^BOCT-1));%%Serrano-Pedraza et al. (2007) JoV.
%sy=sqrt(log(2))/(sqrt(2)*pi*u1*tan(gradosABO/2));;%%Serrano-Pedraza et al. (2007) JoV.



Gaussiana2D=exp(-(xx-x0).^2./(2*sx^2) - (yy-y0).^2./(2*sy^2));


L0=127.5;%Mean luminance
u0=expt.Spatial_frequency;
phase=expt.PHASE;%fase

Image2D=L0*(1+1*(cos(2*pi*u0*xx+phase)).*Gaussiana2D);



axes(handles.Plot1);
cla;
image(Image2D)
colormap(gray2);
map=colormap;
set(gca,'Fontsize',11);
set(gca,'LineWidth',1);
set(gca,'xcolor','k');%Blanco es "w"
set(gca,'ycolor','k');
set(gca, 'xtickmode','manual');
set(gca, 'ytickmode','manual');
if gradosimagenx>=8
grados=round(linspace(-gradosimagenx/2,gradosimagenx/2,9));
grados2=round(linspace(-gradosimagenx/2,gradosimagenx/2,9));
else
%grados=round(linspace(-gradosimagenx/2,gradosimagenx/2,5))
%grados2=round(linspace(-gradosimagenx/2,gradosimagenx/2,5))

grados=[-gradosimagenx/2:gradosimagenx/2];
grados2=[-gradosimagenx/2:gradosimagenx/2];

end   
gradosconv=(((grados/(gradosimagenx/2))*(TAMX/4)+(TAMX/4))*2+1);
gradosconv(:,length(gradosconv))=TAMX;
set(gca,'xtick',gradosconv);
set(gca,'XTickLabel',grados);
set(gca,'ytick',gradosconv);
set(gca,'yTickLabel',grados2);
title('Disparity map')
xlabel('Postition (degrees)')
ylabel('Postition (degrees)')
axis square

 

axes(handles.Plot2);
cla;



expt.ndots=expt.numberofdots;
dotYpix = TAMY*(rand(1, expt.ndots)-0.5);
dotXpix = TAMX*(rand(1, expt.ndots)-0.5);

Angulo=-expt.Orientation*pi/180; 
xx=dotXpix.*cos(Angulo)+dotYpix.*sin(Angulo);
yy=-dotXpix.*sin(Angulo)+dotYpix.*cos(Angulo);

delta=expt.Disparity*(cos(2*pi*xx*u0*(expt.visualangle/TAMX)+phase)).*(exp(-((xx*(expt.visualangle/TAMX)).^2/(2*(sx).^2))-((yy*(expt.visualangle/TAMY)).^2/(2*(sy).^2))));  

dotXpix = TAMX/2+dotXpix;
dotYpix = TAMY/2+dotYpix;

jkeep = find((abs(dotXpix) > 10 & abs(dotXpix) < TAMX-10) & (abs(dotYpix) > 10 & abs(dotYpix) < TAMY-10));
dotXpix = dotXpix(jkeep);%-TAMX/2;
dotYpix = dotYpix(jkeep);%-TAMY/2;
delta=delta(jkeep);

dotxL = dotXpix-delta/2;
dotxR = dotXpix+delta/2;
dotyL= dotYpix;
dotyR= dotyL;


noiseL=0.*ones(TAMX,TAMY);
noiseR=0.*ones(TAMX,TAMY);

sx=1;
sy=sx;
tam=4;


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%ANTIALISNG USING GAUSSIAN DOTS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%(ISP)%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%% DRAW GAUSSIAN DOTS
NDOTS=0;
for i=1:length(dotxL)
m=255;
LL=noiseL([round(dotyL(i))-tam:round(dotyL(i))+tam],[round(dotxL(i))-tam:round(dotxL(i))+tam]);
RR=noiseR([round(dotyR(i))-tam:round(dotyR(i))+tam],[round(dotxR(i))-tam:round(dotxR(i))+tam]);
[H]=find(LL>0);
[G]=find(RR>0);
if isempty(H)==0 || isempty(G)==0 %%this eliminates overlaping of dots
else
[x,y]=meshgrid(round(dotxL(i))-tam:round(dotxL(i))+tam,round(dotyL(i))-tam:round(dotyL(i))+tam);
noiseL([round(dotyL(i))-tam:round(dotyL(i))+tam],[round(dotxL(i))-tam:round(dotxL(i))+tam])=(m*(exp(-((x-dotxL(i)).^2/(2*(sx).^2))-((y-dotyL(i)).^2/(2*(sy).^2)))));
[x,y]=meshgrid(round(dotxR(i))-tam:round(dotxR(i))+tam,round(dotyR(i))-tam:round(dotyR(i))+tam);
noiseR([round(dotyR(i))-tam:round(dotyR(i))+tam],[round(dotxR(i))-tam:round(dotxR(i))+tam])=(m*(exp(-((x-dotxR(i)).^2/(2*(sx).^2))-((y-dotyR(i)).^2/(2*(sy).^2)))));
NDOTS=NDOTS+1;
end
end



imagestereo(:,:,1)=noiseR./255;
imagestereo(:,:,3)=0*ones(TAMX,TAMY)./255;
imagestereo(:,:,2)=noiseL./255;
imagestereo=(255.*imagestereo);



image(imagestereo)
set(gca,'Fontsize',11);
set(gca,'LineWidth',1);
set(gca,'xcolor','k');%Blanco es "w"
set(gca,'ycolor','k');
set(gca, 'xtickmode','manual');
set(gca, 'ytickmode','manual');
if gradosimagenx>=8
grados=round(linspace(-gradosimagenx/2,gradosimagenx/2,9));
grados2=round(linspace(-gradosimagenx/2,gradosimagenx/2,9));
else
%grados=round(linspace(-gradosimagenx/2,gradosimagenx/2,5))
%grados2=round(linspace(-gradosimagenx/2,gradosimagenx/2,5))

grados=[-gradosimagenx/2:gradosimagenx/2];
grados2=[-gradosimagenx/2:gradosimagenx/2];

end   
gradosconv=(((grados/(gradosimagenx/2))*(TAMX/4)+(TAMX/4))*2+1);
gradosconv(:,length(gradosconv))=TAMX;
set(gca,'xtick',gradosconv);
set(gca,'XTickLabel',grados);
set(gca,'ytick',gradosconv);
set(gca,'yTickLabel',grados2);
title('Random dot stereogram')
xlabel('Postition (degrees)')
ylabel('Postition (degrees)')
axis square


axes(handles.Plot3);
cla;
mesh(Image2D)
view([50 43])
title('3D plot')

        xlabel('Postition (degrees)')
        ylabel('Postition (degrees)')
        %axis off
       % axis([0 500 0 500 0 256])
if gradosimagenx>=8
grados=round(linspace(-gradosimagenx/2,gradosimagenx/2,9));
grados2=round(linspace(-gradosimagenx/2,gradosimagenx/2,9));
else
%grados=round(linspace(-gradosimagenx/2,gradosimagenx/2,5))
%grados2=round(linspace(-gradosimagenx/2,gradosimagenx/2,5))

grados=[-gradosimagenx/2:gradosimagenx/2];
grados2=[-gradosimagenx/2:gradosimagenx/2];

end   
gradosconv=(((grados/(gradosimagenx/2))*(TAMX/4)+(TAMX/4))*2+1);
gradosconv(:,length(gradosconv))=TAMX;
set(gca,'xtick',gradosconv);
set(gca,'XTickLabel',grados);
set(gca,'ytick',gradosconv);
set(gca,'yTickLabel',grados2);
set(gca,'ztick',[0:64:256]);
set(gca,'zTickLabel',[0:64:256]);
axis([0 TAMX 0 TAMY 0 256])
%colormap(jet)
%shading interp





% --- Outputs from this function are returned to the command line.
function varargout = Stimuli_3D_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 OpenMenuItem_Callback(hObject, eventdata, handles)
% hObject    handle to OpenMenuItem (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
file = uigetfile('*.fig');
if ~isequal(file, 0)
    open(file);
end


% --- Executes during object creation, after setting all properties.
function Disparity_CreateFcn(hObject, eventdata, handles)
% hObject    handle to Disparity (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called
function Disparity_Callback(hObject, eventdata, handles)

expt = getexpt(handles);
set(handles.disparityslider,  'String', expt.Disparity);

Plot_figure(hObject, eventdata, handles)

function expt = getexpt(handles)
% Reads off key data from GUI
%expt = handles.expt;
A = get(handles.Disparity,'string');
expt.Disparity = str2double(A);
Spatial = get(handles.Spatial_frequency,'string');
expt.Spatial_frequency = str2double(Spatial);
PHASE = get(handles.Phase,'string');
expt.PHASE = str2double(PHASE);
Orientation = get(handles.Orientation,'string');
expt.Orientation = str2double(Orientation);
SizeX = get(handles.SizeX,'string');
expt.SizeX = str2double(SizeX);
SizeY = get(handles.SizeY,'string');
expt.SizeY = str2double(SizeY);
visualangle = get(handles.visualangle,'string');
expt.visualangle = str2double(visualangle);
expt.freqslider = get(handles.Freqslider,'value');
bandwidthfreq = get(handles.bandwidthfreq,'string');
expt.bandwidthfreq = str2double(bandwidthfreq);
bandwidthori = get(handles.bandwidthori,'string');
expt.bandwidthori = str2double(bandwidthori);
numberofdots = get(handles.numberofdots,'string');
expt.numberofdots = str2double(numberofdots);
expt.phaseslider = get(handles.phaseslider,'value');
expt.disparityslider = get(handles.disparityslider,'value');
expt.orientationslider = get(handles.orientationslider,'value');


function Spatial_frequency_Callback(hObject, eventdata, handles)

expt = getexpt(handles);
set(handles.Freqslider,  'Value', expt.Spatial_frequency);
BOCT=expt.bandwidthfreq;
u1=expt.Spatial_frequency;
expt.SizeX=sqrt(log(2)).*(1+2.^BOCT)./(pi*sqrt(2).*u1.*(2.^BOCT-1));%%Serrano-Pedraza et al. (2007) JoV.
set(handles.SizeX, 'String', num2str(expt.SizeX,'%10.3f'));
gradosABO=expt.bandwidthori*pi/180;
expt.SizeY=sqrt(log(2))/(sqrt(2)*pi*u1*tan(gradosABO/2));%%Serrano-Pedraza et al. (2007) JoV.
set(handles.SizeY, 'String', num2str(expt.SizeY,'%10.3f'));
Plot_figure(hObject, eventdata, handles)
% --- Executes during object creation, after setting all properties.
function Spatial_frequency_CreateFcn(hObject, eventdata, handles)
% hObject    handle to Spatial_frequency (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function Phase_Callback(hObject, eventdata, handles)
% hObject    handle to Phase (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of Phase as text
%        str2double(get(hObject,'String')) returns contents of Phase as a double
expt = getexpt(handles);
set(handles.phaseslider,  'Value', expt.PHASE);
Plot_figure(hObject, eventdata, handles)


% --- Executes during object creation, after setting all properties.
function Phase_CreateFcn(hObject, eventdata, handles)
% hObject    handle to Phase (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on button press in Plot_figure.
function Plot_figure_Callback(hObject, eventdata, handles)
% hObject    handle to Plot_figure (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

Plot_figure(hObject, eventdata, handles)



function Orientation_Callback(hObject, eventdata, handles)
% hObject    handle to Orientation (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of Orientation as text
%        str2double(get(hObject,'String')) returns contents of Orientation as a double
expt = getexpt(handles);
set(handles.orientationslider,  'Value', expt.Orientation);
Plot_figure(hObject, eventdata, handles)


% --- Executes during object creation, after setting all properties.
function Orientation_CreateFcn(hObject, eventdata, handles)
% hObject    handle to Orientation (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

function CloseMenuItem_Callback(hObject, eventdata, handles)
% hObject    handle to CloseMenuItem (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
selection = questdlg(['Close ' get(handles.axixX,'Name') '?'],...
                     ['Close ' get(handles.axixX,'Name') '...'],...
                     'Yes','No','Yes');
if strcmp(selection,'No')
    return;
end

delete(handles.axixX)
% --------------------------------------------------------------------
function PrintMenuItem_Callback(hObject, eventdata, handles)
% hObject    handle to PrintMenuItem (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
printdlg(handles.axixX)

% --------------------------------------------------------------------
function FileMenu_Callback(hObject, eventdata, handles)
% hObject    handle to FileMenu (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


% --- Executes on button press in Reset.
function Reset_Callback(hObject, eventdata, handles)
% hObject    handle to Reset (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


set(handles.Disparity, 'String', 5);
set(handles.Spatial_frequency,  'String', 0.4);
set(handles.Phase, 'String', 0);
set(handles.Orientation, 'String', 90);
set(handles.SizeX, 'String', 6.77);
set(handles.SizeY, 'String', 3.558);
set(handles.Freqslider,'Value',0.1);
set(handles.phaseslider,'Value',0);
set(handles.orientationslider,'Value',90);
set(handles.disparityslider,'Value',5);
set(handles.visualangle,'String',8);
set(handles.bandwidthfreq,'String',0.2);
set(handles.bandwidthori,'String',15);
set(handles.numberofdots,'String',2000);
Plot_figure(hObject, eventdata, handles)




% --- Executes on slider movement.
function axisX_Callback(hObject, eventdata, handles)
% hObject    handle to axisX (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
%get(hObject,'Value')
% Hints: get(hObject,'Value') returns position of slider
%        get(hObject,'Min') and get(hObject,'Max') to determine range of slider

Plot_figure(hObject, eventdata, handles)


% --- Executes during object creation, after setting all properties.
function axisX_CreateFcn(hObject, eventdata, handles)
% hObject    handle to axisX (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor',[.9 .9 .9]);
end


% --- Executes on slider movement.
function Freqslider_Callback(hObject, eventdata, handles)

expt = getexpt(handles);
set(handles.Spatial_frequency,  'String', expt.freqslider);
BOCT=expt.bandwidthfreq;
u1=expt.freqslider;
expt.SizeX=sqrt(log(2)).*(1+2.^BOCT)./(pi*sqrt(2).*u1.*(2.^BOCT-1));%%Serrano-Pedraza et al. (2007) JoV.
set(handles.SizeX, 'String', num2str(expt.SizeX,'%10.3f'));
gradosABO=expt.bandwidthori*pi/180;
expt.SizeY=sqrt(log(2))/(sqrt(2)*pi*u1*tan(gradosABO/2));%%Serrano-Pedraza et al. (2007) JoV.
set(handles.SizeY, 'String', num2str(expt.SizeY,'%10.3f'));

Plot_figure(hObject, eventdata, handles)


% --- Executes during object creation, after setting all properties.
function Freqslider_CreateFcn(hObject, eventdata, handles)
% hObject    handle to Freqslider (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor',[.9 .9 .9]);
end




function SizeX_Callback(hObject, eventdata, handles)
% hObject    handle to SizeX (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of SizeX as text
%        str2double(get(hObject,'String')) returns contents of SizeX as a double
expt = getexpt(handles);
u1=expt.Spatial_frequency;
BOCT=real(log2((u1*pi*expt.SizeX*sqrt(2)+sqrt(log(2)))/(u1*pi*expt.SizeX*sqrt(2)-sqrt(log(2)))));
set(handles.bandwidthfreq, 'String', num2str(BOCT,'%10.3f'));
Plot_figure(hObject, eventdata, handles)

% --- Executes during object creation, after setting all properties.
function SizeX_CreateFcn(hObject, eventdata, handles)
% hObject    handle to SizeX (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function SizeY_Callback(hObject, eventdata, handles)
% hObject    handle to SizeY (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of SizeY as text
%        str2double(get(hObject,'String')) returns contents of SizeY as a double
expt = getexpt(handles);
u1=expt.Spatial_frequency;
gradosABO=2*atand(sqrt(log(2))/(sqrt(2)*pi*u1*expt.SizeY));
set(handles.bandwidthori, 'String', num2str(gradosABO,'%10.3f'));
Plot_figure(hObject, eventdata, handles)

% --- Executes during object creation, after setting all properties.
function SizeY_CreateFcn(hObject, eventdata, handles)
% hObject    handle to SizeY (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on button press in logvaluesbutton.
function logvaluesbutton_Callback(hObject, eventdata, handles)
% hObject    handle to logvaluesbutton (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of logvaluesbutton
set(handles.linearvaluesbutton,'Value',0);
set(handles.logvaluesbutton,'Value',1);
Plot_figure(hObject, eventdata, handles)

% --- Executes on button press in linearvaluesbutton.
function linearvaluesbutton_Callback(hObject, eventdata, handles)
% hObject    handle to linearvaluesbutton (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
set(handles.logvaluesbutton,'Value',0);
set(handles.linearvaluesbutton,'Value',1);
Plot_figure(hObject, eventdata, handles)
% Hint: get(hObject,'Value') returns toggle state of linearvaluesbutton



function visualangle_Callback(hObject, eventdata, handles)
% hObject    handle to visualangle (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of visualangle as text
%        str2double(get(hObject,'String')) returns contents of visualangle as a double
Plot_figure(hObject, eventdata, handles)

% --- Executes during object creation, after setting all properties.
function visualangle_CreateFcn(hObject, eventdata, handles)
% hObject    handle to visualangle (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function bandwidthfreq_Callback(hObject, eventdata, handles)
% hObject    handle to bandwidthfreq (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of bandwidthfreq as text
%        str2double(get(hObject,'String')) returns contents of bandwidthfreq as a double
expt = getexpt(handles);
BOCT=expt.bandwidthfreq;
u1=expt.Spatial_frequency;
expt.SizeX=sqrt(log(2)).*(1+2.^BOCT)./(pi*sqrt(2).*u1.*(2.^BOCT-1));%%Serrano-Pedraza et al. (2007) JoV.
set(handles.SizeX, 'String', num2str(expt.SizeX,'%10.3f'));
Plot_figure(hObject, eventdata, handles)

% --- Executes during object creation, after setting all properties.
function bandwidthfreq_CreateFcn(hObject, eventdata, handles)
% hObject    handle to bandwidthfreq (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function bandwidthori_Callback(hObject, eventdata, handles)
% hObject    handle to bandwidthori (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of bandwidthori as text
%        str2double(get(hObject,'String')) returns contents of bandwidthori as a double
expt = getexpt(handles);
gradosABO=expt.bandwidthori*pi/180;
u1=expt.Spatial_frequency;
expt.SizeY=sqrt(log(2))/(sqrt(2)*pi*u1*tan(gradosABO/2));%%Serrano-Pedraza et al. (2007) JoV.
set(handles.SizeY, 'String', num2str(expt.SizeY,'%10.3f'));
Plot_figure(hObject, eventdata, handles)

% --- Executes during object creation, after setting all properties.
function bandwidthori_CreateFcn(hObject, eventdata, handles)
% hObject    handle to bandwidthori (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function numberofdots_Callback(hObject, eventdata, handles)
% hObject    handle to numberofdots (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of numberofdots as text
%        str2double(get(hObject,'String')) returns contents of numberofdots as a double
Plot_figure(hObject, eventdata, handles)


% --- Executes during object creation, after setting all properties.
function numberofdots_CreateFcn(hObject, eventdata, handles)
% hObject    handle to numberofdots (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on slider movement.
function phaseslider_Callback(hObject, eventdata, handles)
% hObject    handle to phaseslider (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'Value') returns position of slider
%        get(hObject,'Min') and get(hObject,'Max') to determine range of slider
expt = getexpt(handles);
set(handles.Phase,  'String', expt.phaseslider);
Plot_figure(hObject, eventdata, handles)

% --- Executes during object creation, after setting all properties.
function phaseslider_CreateFcn(hObject, eventdata, handles)
% hObject    handle to phaseslider (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor',[.9 .9 .9]);
end


% --- Executes on slider movement.
function disparityslider_Callback(hObject, eventdata, handles)
% hObject    handle to disparityslider (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'Value') returns position of slider
%        get(hObject,'Min') and get(hObject,'Max') to determine range of slider
expt = getexpt(handles);
set(handles.Disparity,  'String', expt.disparityslider);
Plot_figure(hObject, eventdata, handles)


% --- Executes during object creation, after setting all properties.
function disparityslider_CreateFcn(hObject, eventdata, handles)
% hObject    handle to disparityslider (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor',[.9 .9 .9]);
end


% --- Executes on slider movement.
function orientationslider_Callback(hObject, eventdata, handles)
% hObject    handle to orientationslider (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'Value') returns position of slider
%        get(hObject,'Min') and get(hObject,'Max') to determine range of slider
expt = getexpt(handles);
set(handles.Orientation,  'String', expt.orientationslider);
Plot_figure(hObject, eventdata, handles)


% --- Executes during object creation, after setting all properties.
function orientationslider_CreateFcn(hObject, eventdata, handles)
% hObject    handle to orientationslider (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor',[.9 .9 .9]);
end
