classdef clu < matlab.apps.AppBase

    % Properties that correspond to app components
    properties (Access = public)
        UIFigure                        matlab.ui.Figure
        insecondsLabel                  matlab.ui.control.Label
        ChimpLocomotionUtilityCLULabel  matlab.ui.control.Label
        tibialengthssecondLabel         matlab.ui.control.Label
        RelSpeedEditField               matlab.ui.control.NumericEditField
        RelSpeedEditFieldLabel          matlab.ui.control.Label
        CalcRelativeSpeedButton         matlab.ui.control.Button
        StrideTibiaEditField            matlab.ui.control.NumericEditField
        StrideTibiaEditFieldLabel       matlab.ui.control.Label
        StrideEditField                 matlab.ui.control.NumericEditField
        StrideEditFieldLabel            matlab.ui.control.Label
        TibiaEditField                  matlab.ui.control.NumericEditField
        TibiaEditFieldLabel             matlab.ui.control.Label
        StrideLengthButton              matlab.ui.control.Button
        CalcStrideTibiaButton           matlab.ui.control.Button
        TibiaLengthButton               matlab.ui.control.Button
        StrideDurationEditField         matlab.ui.control.NumericEditField
        StrideDurationEditFieldLabel    matlab.ui.control.Label
        SelectImageButton               matlab.ui.control.Button
        UIAxes                          matlab.ui.control.UIAxes
    end

    % Callbacks that handle component events
    methods (Access = private)

        % Button pushed function: SelectImageButton
        function SelectImageButtonPushed(app, event)
[file, path] = uigetfile('*.jpg;*.png', 'Select Image File');

if isequal(file, 0)
    disp('User selected cancel');
else
    disp(['User selected ', fullfile(path,file)]);
    %Displaying Video on Axes
    input_image_file = fullfile(path,file);
    imshow(input_image_file, 'Parent', app.UIAxes);
end


%X = [0,0;2,1];
%d = pdist(X,'euclidean')

        end

        % Callback function
        function ProximalLabelButtonPushed(app, event)
            
            % Draw line
            h = drawline(app.UIAxes)
            ep = h.Position;
            x1 = ep(1,1); y1 = ep(1,2); x2 = ep(2,1); y2 = ep(2,2);
            app.TextArea.Value = x1;
            

        end

        % Button pushed function: TibiaLengthButton
        function TibiaLengthButtonPushed(app, event)
            imdistline(app.UIAxes)
        end

        % Button pushed function: StrideLengthButton
        function StrideLengthButtonPushed(app, event)
            imdistline(app.UIAxes)
        end

        % Button pushed function: CalcStrideTibiaButton
        function CalcStrideTibiaButtonPushed(app, event)
            tibia = app.TibiaEditField.Value;
            stridelen = app.StrideEditField.Value;
           % "distance" refers to relative distance, i.e. distance
           % expressed as number of tibia lengths the chimp walks
           distance = stridelen / tibia;
            app.StrideTibiaEditField.Value = distance;
        end

        % Button pushed function: CalcRelativeSpeedButton
        function CalcRelativeSpeedButtonPushed(app, event)
            distance = app.StrideTibiaEditField.Value;
            time = app.StrideDurationEditField.Value;
           speed = distance / time;
            app.RelSpeedEditField.Value = speed;
        end
    end

    % Component initialization
    methods (Access = private)

        % Create UIFigure and components
        function createComponents(app)

            % Create UIFigure and hide until all components are created
            app.UIFigure = uifigure('Visible', 'off');
            app.UIFigure.Position = [100 100 682 480];
            app.UIFigure.Name = 'MATLAB App';

            % Create UIAxes
            app.UIAxes = uiaxes(app.UIFigure);
            app.UIAxes.XTick = [];
            app.UIAxes.YTick = [];
            app.UIAxes.ZTick = [];
            app.UIAxes.Box = 'on';
            app.UIAxes.Position = [110 176 464 275];

            % Create SelectImageButton
            app.SelectImageButton = uibutton(app.UIFigure, 'push');
            app.SelectImageButton.ButtonPushedFcn = createCallbackFcn(app, @SelectImageButtonPushed, true);
            app.SelectImageButton.Position = [17 142 100 23];
            app.SelectImageButton.Text = 'Select Image';

            % Create StrideDurationEditFieldLabel
            app.StrideDurationEditFieldLabel = uilabel(app.UIFigure);
            app.StrideDurationEditFieldLabel.HorizontalAlignment = 'right';
            app.StrideDurationEditFieldLabel.Position = [198 38 86 22];
            app.StrideDurationEditFieldLabel.Text = 'Stride Duration';

            % Create StrideDurationEditField
            app.StrideDurationEditField = uieditfield(app.UIFigure, 'numeric');
            app.StrideDurationEditField.Position = [299 38 100 22];

            % Create TibiaLengthButton
            app.TibiaLengthButton = uibutton(app.UIFigure, 'push');
            app.TibiaLengthButton.ButtonPushedFcn = createCallbackFcn(app, @TibiaLengthButtonPushed, true);
            app.TibiaLengthButton.Position = [165 142 100 23];
            app.TibiaLengthButton.Text = 'Tibia Length';

            % Create CalcStrideTibiaButton
            app.CalcStrideTibiaButton = uibutton(app.UIFigure, 'push');
            app.CalcStrideTibiaButton.ButtonPushedFcn = createCallbackFcn(app, @CalcStrideTibiaButtonPushed, true);
            app.CalcStrideTibiaButton.Position = [516 142 107 23];
            app.CalcStrideTibiaButton.Text = 'Calc. Stride/Tibia';

            % Create StrideLengthButton
            app.StrideLengthButton = uibutton(app.UIFigure, 'push');
            app.StrideLengthButton.ButtonPushedFcn = createCallbackFcn(app, @StrideLengthButtonPushed, true);
            app.StrideLengthButton.Position = [311 142 100 23];
            app.StrideLengthButton.Text = 'Stride Length';

            % Create TibiaEditFieldLabel
            app.TibiaEditFieldLabel = uilabel(app.UIFigure);
            app.TibiaEditFieldLabel.HorizontalAlignment = 'right';
            app.TibiaEditFieldLabel.Position = [165 98 34 22];
            app.TibiaEditFieldLabel.Text = 'Tibia:';

            % Create TibiaEditField
            app.TibiaEditField = uieditfield(app.UIFigure, 'numeric');
            app.TibiaEditField.Position = [214 98 51 22];

            % Create StrideEditFieldLabel
            app.StrideEditFieldLabel = uilabel(app.UIFigure);
            app.StrideEditFieldLabel.HorizontalAlignment = 'right';
            app.StrideEditFieldLabel.Position = [311 98 40 22];
            app.StrideEditFieldLabel.Text = 'Stride:';

            % Create StrideEditField
            app.StrideEditField = uieditfield(app.UIFigure, 'numeric');
            app.StrideEditField.Position = [366 98 45 22];

            % Create StrideTibiaEditFieldLabel
            app.StrideTibiaEditFieldLabel = uilabel(app.UIFigure);
            app.StrideTibiaEditFieldLabel.HorizontalAlignment = 'right';
            app.StrideTibiaEditFieldLabel.Position = [496 109 86 22];
            app.StrideTibiaEditFieldLabel.Text = 'Stride/Tibia =';

            % Create StrideTibiaEditField
            app.StrideTibiaEditField = uieditfield(app.UIFigure, 'numeric');
            app.StrideTibiaEditField.Position = [597 109 46 22];

            % Create CalcRelativeSpeedButton
            app.CalcRelativeSpeedButton = uibutton(app.UIFigure, 'push');
            app.CalcRelativeSpeedButton.ButtonPushedFcn = createCallbackFcn(app, @CalcRelativeSpeedButtonPushed, true);
            app.CalcRelativeSpeedButton.Position = [516 60 127 23];
            app.CalcRelativeSpeedButton.Text = 'Calc. Relative Speed';

            % Create RelSpeedEditFieldLabel
            app.RelSpeedEditFieldLabel = uilabel(app.UIFigure);
            app.RelSpeedEditFieldLabel.HorizontalAlignment = 'right';
            app.RelSpeedEditFieldLabel.Position = [511 26 74 22];
            app.RelSpeedEditFieldLabel.Text = 'Rel. Speed =';

            % Create RelSpeedEditField
            app.RelSpeedEditField = uieditfield(app.UIFigure, 'numeric');
            app.RelSpeedEditField.Position = [600 26 49 22];

            % Create tibialengthssecondLabel
            app.tibialengthssecondLabel = uilabel(app.UIFigure);
            app.tibialengthssecondLabel.Position = [522 5 127 22];
            app.tibialengthssecondLabel.Text = '(tibia lengths / second)';

            % Create ChimpLocomotionUtilityCLULabel
            app.ChimpLocomotionUtilityCLULabel = uilabel(app.UIFigure);
            app.ChimpLocomotionUtilityCLULabel.Position = [264 450 175 22];
            app.ChimpLocomotionUtilityCLULabel.Text = 'Chimp Locomotion Utility (CLU)';

            % Create insecondsLabel
            app.insecondsLabel = uilabel(app.UIFigure);
            app.insecondsLabel.Position = [206 17 69 22];
            app.insecondsLabel.Text = '(in seconds)';

            % Show the figure after all components are created
            app.UIFigure.Visible = 'on';
        end
    end

    % App creation and deletion
    methods (Access = public)

        % Construct app
        function app = clu

            % Create UIFigure and components
            createComponents(app)

            % Register the app with App Designer
            registerApp(app, app.UIFigure)

            if nargout == 0
                clear app
            end
        end

        % Code that executes before app deletion
        function delete(app)

            % Delete UIFigure when app is deleted
            delete(app.UIFigure)
        end
    end
end