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

% Last Modified by GUIDE v2.5 31-May-2012 14:27:30

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @FORWARD_TRACKER_OpeningFcn, ...
                   'gui_OutputFcn',  @FORWARD_TRACKER_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 FORWARD_TRACKER is made visible.
function FORWARD_TRACKER_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 FORWARD_TRACKER (see VARARGIN)

% Choose default command line output for FORWARD_TRACKER
load('V_CELL');load('V_DATA');load('V_ORIG');

set(handles.move_slider, 'Min', 0);
set(handles.move_slider, 'Max', 100);
set(handles.move_slider, 'Value', 0);
set(handles.move_slider, 'SliderStep', [1/100, 1/10]);
set(handles.move_disp, 'String', num2str(get(handles.move_slider, 'Value')));

handles.Vx = V_x_o;
handles.Vz = V_y_o;
handles.Vy = V_z_o;

handles.Nx = Nx;
handles.Ny = Ny;

handles.Nc = Nc;
handles.Nv = Nv;

handles.x_start = x_start;
handles.x_stop = x_stop;

handles.sigma_a = 1.0; handles.mag = 0.1;


axes(handles.axes1);
set(handles.axes1, 'nextplot' ,'add');
Plot_Vert(handles.Vx, handles.Vy, handles.Vz, handles.Nx, handles.Ny, handles.x_start, handles.x_stop, 1);
xlabel('X', 'Fontsize', 20);zlabel('Z', 'Fontsize', 20);
axis([-15 15 -15 15]);


handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

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


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


% --- Executes on slider movement.
function move_slider_Callback(hObject, eventdata, handles)
% hObject    handle to move_slider (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
% Update handles structure
set(handles.move_slider, 'Value', round(get(handles.move_slider, 'Value')));
set(handles.move_disp, 'String', num2str(get(handles.move_slider, 'Value')));

Vx = handles.Vx;
Vy = handles.Vy;
Vz = handles.Vz;

V = [Vx', Vy', Vz'];

for i=1:get(handles.move_slider, 'Value'),
   V = V + Calc_Apical_Con_Force(V, handles.Nx, handles.Ny, handles.sigma_a, handles.mag);
end

axes(handles.axes1);
set(handles.axes1, 'nextplot' ,'replace');
plot(0);
set(handles.axes1, 'nextplot', 'add');
Plot_Vert(V(:, 1), V(:, 2), V(:, 3), handles.Nx, handles.Ny, handles.x_start, handles.x_stop, 1);
xlabel('X', 'Fontsize', 20);zlabel('Z', 'Fontsize', 20);
axis([-15 15 -15 15]);


guidata(hObject, handles);

% --- Executes during object creation, after setting all properties.
function move_slider_CreateFcn(hObject, eventdata, handles)
% hObject    handle to move_slider (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
