Filling_in.m


%
%Filling-in microcircuit GUI 
%
function varargout = Filling_in(varargin)
% FILLING_IN M-file for Filling_in.fig
%      FILLING_IN, by itself, creates a new FILLING_IN or raises the existing
%      singleton*.
%
%      H = FILLING_IN returns the handle to a new FILLING_IN or the handle to
%      the existing singleton*.
%
%      FILLING_IN('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in FILLING_IN.M with the given input arguments.
%
%      FILLING_IN('Property','Value',...) creates a new FILLING_IN or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before Filling_in_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to Filling_in_OpeningFcn via varargin.
%
%      *See GUI Options on GUIDE 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 Filling_in

% Last Modified by GUIDE v2.5 05-Jul-2009 17:15:20

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @Filling_in_OpeningFcn, ...
                   'gui_OutputFcn',  @Filling_in_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


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

% Choose default command line output for Filling_in
global COCE;
global h;

InitCOCE; % Initialize exanple data

handles.output = hObject;

% set file names and other data as specified in 'names.m' file
names;
handles.abstract_pdf       = abstract_pdf;
handles.article_pdf        = article_pdf;
handles.code_listing_html  = code_listing_html;
handles.description_pdf    = description_pdf;
handles.how_to_run_pdf     = how_to_run_pdf;
handles.inputs_pdf         = inputs_pdf;
handles.model_name         = model_name;
handles.system_diagram_pdf = system_diagram_pdf;
handles.system_diagram_png = system_diagram_png;
handles.tutorial_pdf       = tutorial_pdf;
set(handles.sliderCask,'Value',COCE.CaskContrast/10);
set(handles.sliderExternalArea,'Value',COCE.ExternalValue/10);
set(handles.sliderInternalArea,'Value',COCE.InternalValue/10);

% show system diagram on main GUI
set(hObject, 'Units', 'pixels');
h = axes();
[X,map] = imread(system_diagram_png);
imshow(X,map);



% set title
htitle = findobj('String','hello');
set(htitle,'String',handles.model_name);

% Update handles structure
guidata(hObject, handles);


% UIWAIT makes Filling_in wait for user response (see UIRESUME)
% uiwait(handles.figure1);


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

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

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

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

% --------------------------------------------------------------------
% File -> Exit
% --------------------------------------------------------------------
function exit_menu_item_Callback(hObject, eventdata, handles)
% hObject    handle to exit_menu_item (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
clf
close

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

% --------------------------------------------------------------------
% Model -> Description
% --------------------------------------------------------------------
function article_Callback(hObject, eventdata, handles)
% hObject    handle to article (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
open(handles.description_pdf);

% --------------------------------------------------------------------
% Model -> System Diagram
% --------------------------------------------------------------------
function system_diagram_menu_item_Callback(hObject, eventdata, handles)
% hObject    handle to system_diagram_menu_item (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
open(handles.system_diagram_pdf);

% --------------------------------------------------------------------
% Model -> Inputs
% --------------------------------------------------------------------
function inputs_Callback(hObject, eventdata, handles)
% hObject    handle to inputs (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
open(handles.inputs_pdf);

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

% --------------------------------------------------------------------
% Run -> Complement - Disabled for Microcircuits
% --------------------------------------------------------------------
function run_complement_menu_item_Callback(hObject, eventdata, handles)
% hObject    handle to run_complement_menu_item (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

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

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

global COCE;
cla;
set(handles.examplepanel,'Visible','on');

SetInternalArea;
ShowCOCEInput;

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

% --------------------------------------------------------------------
% Article -> Author, year
% --------------------------------------------------------------------
function Paper_Callback(hObject, eventdata, handles)
% hObject    handle to Paper (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
open(handles.article_pdf);

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

% --------------------------------------------------------------------
% Tutorial -> Abstract
% --------------------------------------------------------------------
function abstract_Callback(hObject, eventdata, handles)
% hObject    handle to abstract (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
open(handles.abstract_pdf);

% --------------------------------------------------------------------
% Tutorial -> Tutorial
% --------------------------------------------------------------------
function tutorial_sub_Callback(hObject, eventdata, handles)
% hObject    handle to tutorial_sub (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
open(handles.tutorial_pdf);

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

% --------------------------------------------------------------------
% Code -> code_name
% --------------------------------------------------------------------
function complement_code_Callback(hObject, eventdata, handles)
% hObject    handle to complement_code (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
open(handles.code_listing_html);

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

% --------------------------------------------------------------------
% Help -> How to Run
% --------------------------------------------------------------------
function how_to_run_menu_item_Callback(hObject, eventdata, handles)
% hObject    handle to how_to_run_menu_item (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
open(handles.how_to_run_pdf)

% --------------------------------------------------------------------
% Help -> Contact
% --------------------------------------------------------------------
function contact_menu_item_Callback(hObject, eventdata, handles)
% hObject    handle to contact_menu_item (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% Contact information are stored in a local html file
open('Contact.html')

% --------------------------------------------------------------------
% Help -> Credits
% --------------------------------------------------------------------
function credit_menu_item_Callback(hObject, eventdata, handles)
% hObject    handle to credit_menu_item (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% Credit information are stored at a website
open('Credits.html')

% --------------------------------------------------------------------
% Help -> License
% --------------------------------------------------------------------
function license_menu_item_Callback(hObject, eventdata, handles)
% hObject    handle to license_menu_item (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
open('License.html')


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


% --- Executes on slider movement.
function sliderCask_Callback(hObject, eventdata, handles)
% hObject    handle to sliderCask (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

global COCE;
%
COCE.CaskContrast = get(handles.sliderCask,'Value')*10;
SetInternalArea;
ShowCOCEInput;



% --- Executes during object creation, after setting all properties.
function sliderCask_CreateFcn(hObject, eventdata, handles)
% hObject    handle to sliderCask (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 during object creation, after setting all properties.
function sliderExternalArea_CreateFcn(hObject, eventdata, handles)
% hObject    handle to sliderExternalArea (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 sliderInternalArea_Callback(hObject, eventdata, handles)
% hObject    handle to sliderInternalArea (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

global COCE;

COCE.InternalValue = get(handles.sliderInternalArea,'Value')*10;
SetInternalArea;
ShowCOCEInput;

% --- Executes during object creation, after setting all properties.
function sliderInternalArea_CreateFcn(hObject, eventdata, handles)
% hObject    handle to sliderInternalArea (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 button press in buttonClose.
function buttonClose_Callback(hObject, eventdata, handles)
% hObject    handle to buttonClose (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global h;
set(handles.examplepanel,'Visible','off');
[X,map] = imread(handles.system_diagram_png);
axes(h);
imshow(X,map);


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

global COCE;
%BCS1D;
L=.5;

BCS1D;
COCE.Boundary = max(COCE.Boundary,0);
COCE.Boundary(:,1) = max(COCE.Boundary(:,2)+COCE.Boundary(:,1)-L,0);
COCE.Boundary(:,2) = COCE.Boundary(:,1);
subplot(5,1,3);
%plot(max(COCE.Boundary-L,0));
plot(max(abs(COCE.Boundary(:,1))+abs(COCE.Boundary(:,2))-L,0));
xlim([1 COCE.PopulationSize(2)]);
Title ('Boundaries');

COCE.Feature=CenterSurround1D(COCE.Data(COCE.PopulationSize(1)/2,:));
subplot(5,1,4);
plot(COCE.Feature);
xlim([1 COCE.PopulationSize(2)]);
Title ('Feature');

%COCE.Percept    = Fillingin1D2N(COCE.Feature,COCE.Boundary);
Filling1d2N_Equil;
subplot(5,1,5);
plot(COCE.Percept);
xlim([1 COCE.PopulationSize(2)]);
Title ('Percept');



% --- Executes on button press in CloseButton.
function CloseButton_Callback(hObject, eventdata, handles)
% hObject    handle to CloseButton (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global h;
set(handles.examplepanel,'Visible','off');
[X,map] = imread(handles.system_diagram_png);
axes(h);
imshow(X,map);




% --- Executes on slider movement.
function sliderExternalArea_Callback(hObject, eventdata, handles)
% hObject    handle to sliderExternalArea (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

global COCE;

COCE.ExternalValue = get(handles.sliderExternalArea,'Value')*10;
SetExternalArea;
SetInternalArea;
ShowCOCEInput;


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


% --------------------------------------------------------------------
function MathModel_Callback(hObject, eventdata, handles)
% hObject    handle to MathModel (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
open(handles.system_diagram_pdf);