% Imperial iGEM 2014 BioHackspace 3D model
% As a collaboration project with London BioHackspace iGEM Team, the model
% adatped GUI to simulate a visualisation of the 3D structure imported by
% the user. Where user can easily manipute the pattern design for each
% layer by 1) altering the matrix entry in the code specified below, or 2)
% import the matrix data from spreadsheets
% Please refer to our wiki page
% (http://2014.igem.org/Team:Imperial/BioHackspace_Model) for further
% information

function varargout = London_BioHackspace_Model(varargin)

% LONDON_BIOHACKSPACE_MODEL MATLAB code for London_BioHackspace_Model.fig

% Begin initialization code
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @London_BioHackspace_Model_OpeningFcn, ...
                   'gui_OutputFcn',  @London_BioHackspace_Model_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 London_BioHackspace_Model is made visible.
function London_BioHackspace_Model_OpeningFcn(hObject, eventdata, handles, varargin)

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

% Update handles structure
guidata(hObject, handles);

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


% --- Outputs from this function are returned to the command line.
function varargout = London_BioHackspace_Model_OutputFcn(hObject, eventdata, handles) 

% Get default command line output from handles structure
varargout{1} = handles.output;


% --- Executes on button press in pushbutton11.
function pushbutton11_Callback(hObject, eventdata, handles)

time = 10;
M = zeros([10 10 10]); % model
P = zeros([10 10 10]); % print, which is built on the fact that the added layer of cellulose will sink down

M(:, :, 1) = [
   0 0 0 0 0 0 0 0 0 0
   0 0 0 0 0 0 0 0 0 0
   0 0 0 0 0 0 0 0 0 0
   0 0 1 1 0 0 1 1 0 0
   0 1 1 1 1 1 1 1 1 0
   0 1 1 1 1 1 1 1 1 0
   0 0 1 1 1 1 1 1 0 0
   0 0 0 1 1 1 1 0 0 0
   0 0 0 0 1 1 0 0 0 0
   0 0 0 0 0 0 0 0 0 0
   ]; 
M(:, :, 2) = [
   0 0 0 0 0 0 0 0 0 0
   0 0 0 0 0 0 0 0 0 0
   0 0 0 0 0 0 0 0 0 0
   0 0 1 1 0 0 1 1 0 0
   0 1 1 1 1 1 1 1 1 0
   0 1 1 1 1 1 1 1 1 0
   0 0 1 1 1 1 1 1 0 0
   0 0 0 1 1 1 1 0 0 0
   0 0 0 0 1 1 0 0 0 0
   0 0 0 0 0 0 0 0 0 0
   ];
M(:, :, 3) = [
   0 0 0 0 0 0 0 0 0 0
   0 0 0 0 0 0 0 0 0 0
   0 0 0 0 0 0 0 0 0 0
   0 0 1 1 0 0 1 1 0 0
   0 1 1 1 1 1 1 1 1 0
   0 1 1 1 1 1 1 1 1 0
   0 0 1 1 1 1 1 1 0 0
   0 0 0 1 1 1 1 0 0 0
   0 0 0 0 1 1 0 0 0 0
   0 0 0 0 0 0 0 0 0 0
   ];
M(:, :, 4) = [
   0 0 0 0 0 0 0 0 0 0
   0 0 0 0 0 0 0 0 0 0
   0 0 0 0 0 0 0 0 0 0
   0 0 1 1 0 0 1 1 0 0
   0 1 1 1 1 1 1 1 1 0
   0 1 1 1 1 1 1 1 1 0
   0 0 1 1 1 1 1 1 0 0
   0 0 0 1 1 1 1 0 0 0
   0 0 0 0 1 1 0 0 0 0
   0 0 0 0 0 0 0 0 0 0
   ];
M(:, :, 5) = [
   0 0 0 0 0 0 0 0 0 0
   0 0 0 0 0 0 0 0 0 0
   0 0 0 0 0 0 0 0 0 0
   0 0 1 1 0 0 1 1 0 0
   0 1 1 1 1 1 1 1 1 0
   0 1 1 1 1 1 1 1 1 0
   0 0 1 1 1 1 1 1 0 0
   0 0 0 1 1 1 1 0 0 0
   0 0 0 0 1 1 0 0 0 0
   0 0 0 0 0 0 0 0 0 0
   ];
M(:, :, 6) = [
   0 0 0 0 0 0 0 0 0 0
   0 0 0 0 0 0 0 0 0 0
   0 0 0 0 0 0 0 0 0 0
   0 0 1 1 0 0 1 1 0 0
   0 1 1 1 1 1 1 1 1 0
   0 1 1 1 1 1 1 1 1 0
   0 0 1 1 1 1 1 1 0 0
   0 0 0 1 1 1 1 0 0 0
   0 0 0 0 1 1 0 0 0 0
   0 0 0 0 0 0 0 0 0 0
   ];
M(:, :, 7) = [
   0 0 0 0 0 0 0 0 0 0
   0 0 0 0 0 0 0 0 0 0
   0 0 0 0 0 0 0 0 0 0
   0 0 1 1 0 0 1 1 0 0
   0 1 1 1 1 1 1 1 1 0
   0 1 1 1 1 1 1 1 1 0
   0 0 1 1 1 1 1 1 0 0
   0 0 0 1 1 1 1 0 0 0
   0 0 0 0 1 1 0 0 0 0
   0 0 0 0 0 0 0 0 0 0
   ];
M(:, :, 8) = [
   0 0 0 0 0 0 0 0 0 0
   0 0 0 0 0 0 0 0 0 0
   0 0 0 0 0 0 0 0 0 0
   0 0 1 1 0 0 1 1 0 0
   0 1 1 1 1 1 1 1 1 0
   0 1 1 1 1 1 1 1 1 0
   0 0 1 1 1 1 1 1 0 0
   0 0 0 1 1 1 1 0 0 0
   0 0 0 0 1 1 0 0 0 0
   0 0 0 0 0 0 0 0 0 0
   ];
M(:, :, 9) = [
   0 0 0 0 0 0 0 0 0 0
   0 0 0 0 0 0 0 0 0 0
   0 0 0 0 0 0 0 0 0 0
   0 0 0 1 0 0 1 0 0 0
   0 0 1 1 1 1 1 1 0 0
   0 0 1 1 1 1 1 1 0 0
   0 0 0 1 1 1 1 0 0 0
   0 0 0 0 1 1 0 0 0 0
   0 0 0 0 0 0 0 0 0 0
   0 0 0 0 0 0 0 0 0 0
   ];
M(:, :, 10) = [
   0 0 0 0 0 0 0 0 0 0
   0 0 0 0 0 0 0 0 0 0
   0 0 0 0 0 0 0 0 0 0
   0 0 0 0 0 0 0 0 0 0
   0 0 0 1 0 0 1 0 0 0
   0 0 0 1 1 1 1 0 0 0
   0 0 0 0 1 1 0 0 0 0
   0 0 0 0 0 0 0 0 0 0
   0 0 0 0 0 0 0 0 0 0
   0 0 0 0 0 0 0 0 0 0
   ];


for k=1:time
    if k==1
        P(:, :, k) = M(:, :, k);
    else
        P(:, :, k) = P(:, :, (k-1)) + M(:, :, k);
    end
end

Max = max(max(P(:, :, time)));
Printout = P(:, :, time)/Max;

total_cells = sum(sum(P(:,:,time)));
set(handles.totalcellunits, 'String', total_cells);

axes(handles.axes2);
surf(Printout(:, :));
caxis([0 1]);
view(3);

guidata(hObject, handles);


% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)

set(handles.layerno, 'String', 1);
M1 = [
   0 0 0 0 0 0 0 0 0 0
   0 0 0 0 0 0 0 0 0 0
   0 0 0 0 0 0 0 0 0 0
   0 0 .1 .1 0 0 .1 .1 0 0
   0 .1 .1 .1 .1 .1 .1 .1 .1 0
   0 .1 .1 .1 .1 .1 .1 .1 .1 0
   0 0 .1 .1 .1 .1 .1 .1 0 0
   0 0 0 .1 .1 .1 .1 0 0 0
   0 0 0 0 .1 .1 0 0 0 0
   0 0 0 0 0 0 0 0 0 0
   ];

axes(handles.axes1);
surf(M1);
caxis([0 1]);
view(2);
guidata(hObject, handles);



% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)

set(handles.layerno, 'String', 2);
M2 = [
   0 0 0 0 0 0 0 0 0 0
   0 0 0 0 0 0 0 0 0 0
   0 0 0 0 0 0 0 0 0 0
   0 0 .2 .2 0 0 .2 .2 0 0
   0 .2 .2 .2 .2 .2 .2 .2 .2 0
   0 .2 .2 .2 .2 .2 .2 .2 .2 0
   0 0 .2 .2 .2 .2 .2 .2 0 0
   0 0 0 .2 .2 .2 .2 0 0 0
   0 0 0 0 .2 .2 0 0 0 0
   0 0 0 0 0 0 0 0 0 0
   ];

axes(handles.axes1);
surf(M2);
caxis([0 1]);
view(2);
guidata(hObject, handles);


% --- Executes on button press in pushbutton3.
function pushbutton3_Callback(hObject, eventdata, handles)

set(handles.layerno, 'String', 3);
M3 = [
   0 0 0 0 0 0 0 0 0 0
   0 0 0 0 0 0 0 0 0 0
   0 0 0 0 0 0 0 0 0 0
   0 0 .3 .3 0 0 .3 .3 0 0
   0 .3 .3 .3 .3 .3 .3 .3 .3 0
   0 .3 .3 .3 .3 .3 .3 .3 .3 0
   0 0 .3 .3 .3 .3 .3 .3 0 0
   0 0 0 .3 .3 .3 .3 0 0 0
   0 0 0 0 .3 .3 0 0 0 0
   0 0 0 0 0 0 0 0 0 0
   ];

axes(handles.axes1);
surf(M3);
caxis([0 1]);
view(2);
guidata(hObject, handles);



% --- Executes on button press in pushbutton4.
function pushbutton4_Callback(hObject, eventdata, handles)

set(handles.layerno, 'String', 4);
M4 = [
   0 0 0 0 0 0 0 0 0 0
   0 0 0 0 0 0 0 0 0 0
   0 0 0 0 0 0 0 0 0 0
   0 0 .4 .4 0 0 .4 .4 0 0
   0 .4 .4 .4 .4 .4 .4 .4 .4 0
   0 .4 .4 .4 .4 .4 .4 .4 .4 0
   0 0 .4 .4 .4 .4 .4 .4 0 0
   0 0 0 .4 .4 .4 .4 0 0 0
   0 0 0 0 .4 .4 0 0 0 0
   0 0 0 0 0 0 0 0 0 0
   ];

axes(handles.axes1);
surf(M4);
caxis([0 1]);
view(2);
guidata(hObject, handles);


% --- Executes on button press in pushbutton5.
function pushbutton5_Callback(hObject, eventdata, handles)

set(handles.layerno, 'String', 5);
M5 = [
   0 0 0 0 0 0 0 0 0 0
   0 0 0 0 0 0 0 0 0 0
   0 0 0 0 0 0 0 0 0 0
   0 0 .5 .5 0 0 .5 .5 0 0
   0 .5 .5 .5 .5 .5 .5 .5 .5 0
   0 .5 .5 .5 .5 .5 .5 .5 .5 0
   0 0 .5 .5 .5 .5 .5 .5 0 0
   0 0 0 .5 .5 .5 .5 0 0 0
   0 0 0 0 .5 .5 0 0 0 0
   0 0 0 0 0 0 0 0 0 0
   ];

axes(handles.axes1);
surf(M5);
caxis([0 1]);
view(2);
guidata(hObject, handles);


% --- Executes on button press in pushbutton6.
function pushbutton6_Callback(hObject, eventdata, handles)

set(handles.layerno, 'String', 6);
M6 = [
   0 0 0 0 0 0 0 0 0 0
   0 0 0 0 0 0 0 0 0 0
   0 0 0 0 0 0 0 0 0 0
   0 0 .6 .6 0 0 .6 .6 0 0
   0 .6 .6 .6 .6 .6 .6 .6 .6 0
   0 .6 .6 .6 .6 .6 .6 .6 .6 0
   0 0 .6 .6 .6 .6 .6 .6 0 0
   0 0 0 .6 .6 .6 .6 0 0 0
   0 0 0 0 .6 .6 0 0 0 0
   0 0 0 0 0 0 0 0 0 0
   ];

axes(handles.axes1);
surf(M6);
caxis([0 1]);
view(2);
guidata(hObject, handles);


% --- Executes on button press in pushbutton7.
function pushbutton7_Callback(hObject, eventdata, handles)

set(handles.layerno, 'String', 7);
M7 = [
   0 0 0 0 0 0 0 0 0 0
   0 0 0 0 0 0 0 0 0 0
   0 0 0 0 0 0 0 0 0 0
   0 0 .7 .7 0 0 .7 .7 0 0
   0 .7 .7 .7 .7 .7 .7 .7 .7 0
   0 .7 .7 .7 .7 .7 .7 .7 .7 0
   0 0 .7 .7 .7 .7 .7 .7 0 0
   0 0 0 .7 .7 .7 .7 0 0 0
   0 0 0 0 .7 .7 0 0 0 0
   0 0 0 0 0 0 0 0 0 0
   ];

axes(handles.axes1);
surf(M7);
caxis([0 1]);
view(2);
guidata(hObject, handles);


% --- Executes on button press in pushbutton8.
function pushbutton8_Callback(hObject, eventdata, handles)

set(handles.layerno, 'String', 8);
M8 = [
   0 0 0 0 0 0 0 0 0 0
   0 0 0 0 0 0 0 0 0 0
   0 0 0 0 0 0 0 0 0 0
   0 0 .8 .8 0 0 .8 .8 0 0
   0 .8 .8 .8 .8 .8 .8 .8 .8 0
   0 .8 .8 .8 .8 .8 .8 .8 .8 0
   0 0 .8 .8 .8 .8 .8 .8 0 0
   0 0 0 .8 .8 .8 .8 0 0 0
   0 0 0 0 .8 .8 0 0 0 0
   0 0 0 0 0 0 0 0 0 0
   ];

axes(handles.axes1);
surf(M8);
caxis([0 1]);
view(2);
guidata(hObject, handles);


% --- Executes on button press in pushbutton9.
function pushbutton9_Callback(hObject, eventdata, handles)

set(handles.layerno, 'String', 9);
M9 = [
   0 0 0 0 0 0 0 0 0 0
   0 0 0 0 0 0 0 0 0 0
   0 0 0 0 0 0 0 0 0 0
   0 0 .8 .9 0 0 .9 .8 0 0
   0 .8 .9 .9 .9 .9 .9 .9 .8 0
   0 .8 .9 .9 .9 .9 .9 .9 .8 0
   0 0 .8 .9 .9 .9 .9 .8 0 0
   0 0 0 .8 .9 .9 .8 0 0 0
   0 0 0 0 .8 .8 0 0 0 0
   0 0 0 0 0 0 0 0 0 0
   ];

axes(handles.axes1);
surf(M9);
caxis([0 1]);
view(2);
guidata(hObject, handles);


% --- Executes on button press in pushbutton10.
function pushbutton10_Callback(hObject, eventdata, handles)

set(handles.layerno, 'String', 10);
M10 = [
   0 0 0 0 0 0 0 0 0 0
   0 0 0 0 0 0 0 0 0 0
   0 0 0 0 0 0 0 0 0 0
   0 0 .8 .9 0 0 .9 .8 0 0
   0 .8 .9 1 .9 .9 1 .9 .8 0
   0 .8 .9 1 1 1 1 .9 .8 0
   0 0 .8 .9 1 1 .9 .8 0 0
   0 0 0 .8 .9 .9 .8 0 0 0
   0 0 0 0 .8 .8 0 0 0 0
   0 0 0 0 0 0 0 0 0 0
   ];

axes(handles.axes1);
surf(M10);
caxis([0 1]);
view(2);
guidata(hObject, handles);

% end of the code
% For enquiries please contact dk3712 AT imperial DOT ac DOT uk