%{ -------------------------------------------------------------------------- GUI FOR RUNNING THE MODEL -------------------------------------------------------------------------- File Description: This is the main file for running the EPFL shoulder model. creates the GUI and loads all the raw anatomical data. The data contains the following : 1) BLDATA : Bony landmark data 2) MEDATA : Bone Meshing data for plotting purposes 3) MWDATA : Muscle Origin/Insertion & Wrapping data 4) REDATA : Ribcage Ellipsoid data 5) JCDATA : Joint sinus cone data (which Ehsan has deactivated) 6) KEDATA : Kinematic Motion data 7) DYDATA : Dynamics data. Contains all static parameters Moment arms, Muscle forces, and Joint reaction forces are not initially available. They are computed on demand. They will be stored in the following structures: 8) MADATA : Muscle Moment Arms 9) EFDATA : Estimated Muscle Forces 10) JFDATA : Joint Reaction Forces -------------------------------------------------------------------------- File Structure : This file creates the primary GUI. On the main GUI only visulisation options can be changed. Access to all the different parts of the model is done by pushbuttons which open other sub-GUI's. The pushbuttons are created using MATLAB's uicontrol handle structures. When a button is pushed, the callback script is executed. These scripts are generated by the function MAIN_TOOL_script_generator.m. Files associated to sub-GUI's are designated with the word 'TOOL' in their title. The main file of each sub-GUI is defined by ..._TOOL_main_file.m Each tool has certain functions which are unique to that tool. Such files are designated by ..._TOOL_function_name.m All the files for each tool are located in a sub-folder. Access to these folders is granted when the main file is run. This is done straight after the masthead script. -------------------------------------------------------------------------- Contents of the Interactive GUI structure : PushButton Section MAINGUIHandle.Close_Button MAINGUIHandle.Save_Visualisation_Button MAINGUIHandle.Save_Data_Button Visualisation Update Section MAINGUIHandle.VisFrame MAINGUIHandle.VisTitle MAINGUIHandle.VisMuscleOption MAINGUIHandle.VisJointSinusConeOption MAINGUIHandle.VisEllipsoidOption MAINGUIHandle.Update_Visualisation_Button ToolBox Push Buttons MAINGUIHandle.ToolTitle MAINGUIHandle.InitialPosition_Tool_Button MAINGUIHandle.Muscle_Tool_Button MAINGUIHandle.Sinus_Cone_Tool_Button MAINGUIHandle.Ellipsoid_Tool_Button MAINGUIHandle.Kinematics_Tool_Button MAINGUIHandle.Check_Motion_Button MAINGUIHandle.Check_MA_Button MAINGUIHandle.Estimate_Forces_Button -------------------------------------------------------------------------- The graphical hierarchy is : MAINHandle -> MAINVisualisationAxes -> PlotHandles -------------------------------------------------------------------------- WARNING : THIS FILE IS LOCATED IN THE PRIMARY FOLDER. IF YOU SWITCH LOCATIONS (FOLDER) WHILE THE GUI IS RUNNING AND DO NOT SWITCH BACK TO THE PRIMARY FOLDER, MATLAB WILL THROW AN ERROR. IF THIS HAPPENS, IT IS NOT NECESSARY TO RESTART. YOU ONLY NEED TO SWITCH BACK TO THE PRIMARY FOLDER. -------------------------------------------------------------------------- %} % Clean Workspace clc; clear all; %close all; % Run a MASTHEAD script. (Set to 0 to turn off) MastHeadOn = 1; if MastHeadOn MASTHEAD_script; end %-------------------------------------------------------------------------- % GRANT ACCESS TO ALL SUBFOLDERS %-------------------------------------------------------------------------- CurrentPath = pwd; SubFolderList = {'INITIALISATION_Dataset',... 'TOOLBOX_Initial_Configuration',... 'TOOLBOX_Ribcage_Ellipsoid',... 'TOOLBOX_Subject_Specific',... 'TOOLBOX_Muscle_Geometry',... 'TOOLBOX_Kinematics',... 'TOOLBOX_Moment_Arms',... 'TOOLBOX_Force_Estimation',... 'Visualisation_Functions',... 'Visualisation_Original_Meshings',... 'EMG_based_muscle_force'}; for i = 1:size(SubFolderList,2) % Differentiate between UNIX and non-UNIX systems if isunix addpath([CurrentPath, '/', SubFolderList{1,i}]); else addpath([CurrentPath, '\', SubFolderList{1,i}]); end end %-------------------------------------------------------------------------- % CREATE THE FIGURE & PUSHBUTTON FOR CLOSING GUI. %-------------------------------------------------------------------------- MAINHandle = figure(... 'color', 'white',... 'units', 'normalized',... 'position', [0, 0, 0.5, 1],... 'toolbar', 'figure',... 'name', 'EPFL - LBO Upper Extremity Model MAIN GUI.'); %-------------------------------------------------------------------------- %-------------------------------------------------------------------------- % LIST OF TOOLBOX PUSHBUTTONS %-------------------------------------------------------------------------- %-------------------------------------------------------------------------- % Frame MAINGUIHandle.PBFrame = uicontrol(... 'units', 'normalized',... 'position', [0.7, 0.64, 0.3, 0.32],... 'style', 'frame',... 'fontsize', 14,... 'backgroundcolor', 'white',... 'fontweight', 'bold'); % Title MAINGUIHandle.ToolTitle = uicontrol(... 'units', 'normalized',... 'position', [0.8, 0.95, 0.1, 0.02],... 'style', 'text',... 'string', 'List of Toolboxes',... 'fontsize', 14,... 'backgroundcolor', 'white',... 'fontweight', 'bold'); % Push Button for opening the Subject Specific Toolbox MAINGUIHandle.Subject_Specific_Tool_Button = uicontrol(... 'units', 'normalized',... 'position', [0.7, 0.90, 0.3, 0.05],... 'style', 'pushbutton',... 'max', 2,... 'string', ' - SUBJECT SPECIFIC TOOL -----------------------------

Tool for adapting the generic model to a specific subject

',... 'fontsize', 14,... 'callback', MAIN_TOOL_script_generator('Open Subject Specific Tool')); % Push Button for opening the muscle wrapping toolbox MAINGUIHandle.Muscle_Tool_Button = uicontrol(... 'units', 'normalized',... 'position', [0.7, 0.85, 0.3, 0.05],... 'style', 'pushbutton',... 'string', ' - MUSCLE WRAPPING TOOL ---------------------------------

Tool for defining the muscle segement structure

',... 'fontsize', 14,... 'callback', MAIN_TOOL_script_generator('Open Muscle Tool')); % Push Button for opening the Initial Position toolbox MAINGUIHandle.InitialPosition_Tool_Button = uicontrol(... 'units', 'normalized',... 'position', [0.7, 0.80, 0.3, 0.05],... 'style', 'pushbutton',... 'max', 2,... 'string', ' - JOINT INITIALIZATION TOOL -----------------------------

Tool for setting the initial configuration of the joints

',... 'fontsize', 14,... 'callback', MAIN_TOOL_script_generator('Open Initial Configuration Tool')); %{ Push Button for opening the joint sinus cone toolbox MAINGUIHandle.Sinus_Cone_Tool_Button = uicontrol(... 'units', 'normalized',... 'position', [0.7, 0.8, 0.3, 0.05],... 'style', 'pushbutton',... 'string', ' - JOINT SINUS CONE TOOL ----------------------------------

Tool for setting the configuration of the joint sinus cones

',... 'fontsize', 14,... 'callback', MAIN_TOOL_script_generator('Open Joint Tool')); %} %%%%%%%%%%%%%%%% having discussed with Alex, I moved this part to the %%%%%%%%%%%%%%%% subject-specific window % % Push Button for opening the ellipsoid toolbox % MAINGUIHandle.Ellipsoid_Tool_Button = uicontrol(... % 'units', 'normalized',... % 'position', [0.7, 0.80, 0.3, 0.05],... % 'style', 'pushbutton',... % 'string', ' - RIBCAGE ELLIPSOID TOOL --------------------------------

Tool for setting the ribcage ellipsoid

',... % 'fontsize', 14,... % 'callback', MAIN_TOOL_script_generator('Open Ellipsoid Tool')); % Push Button for opening the kinematics toolbox MAINGUIHandle.Kinematics_Tool_Button = uicontrol(... 'units', 'normalized',... 'position', [0.7, 0.75, 0.3, 0.05],... 'style', 'pushbutton',... 'string', ' - KINEMATICS TOOL -------------------------------------------

Tool for designing the kinematics

',... 'fontsize', 14,... 'callback', MAIN_TOOL_script_generator('Open Kinematics Tool')); % Push Button for checking the moment arms MAINGUIHandle.Check_MA_Button = uicontrol(... 'units', 'normalized',... 'position', [0.7, 0.70, 0.3, 0.05],... 'style', 'pushbutton',... 'string', ' - CHECK INDIVIDUAL MOMENT ARMS ---------------------

Tool for checking that the moment arms are continuous

',... 'fontsize', 14,... 'callback', MAIN_TOOL_script_generator('Check Moment Arms')); % Push Button for force estimation MAINGUIHandle.Estimate_Forces_Button = uicontrol(... 'units', 'normalized',... 'position', [0.7, 0.65, 0.3, 0.05],... 'style', 'pushbutton',... 'string', ' - ESTIMATE FORCES ------------------------------------------

Tool for estimating the muscle forces

',... 'fontsize', 14,... 'callback', MAIN_TOOL_script_generator('Estimate Forces')); %-------------------------------------------------------------------------- %-------------------------------------------------------------------------- % VISUALISATION INTERFACE (RADIOBUTTONS) %-------------------------------------------------------------------------- %-------------------------------------------------------------------------- % Frame MAINGUIHandle.VisFrame = uicontrol(... 'units', 'normalized',... 'position', [0.7, 0.19, 0.3, 0.35],... 'style', 'frame',... 'fontsize', 14,... 'backgroundcolor', 'white',... 'fontweight', 'bold'); % Title MAINGUIHandle.VisTitle = uicontrol(... 'units', 'normalized',... 'position', [0.79, 0.52, 0.13, 0.03],... 'style', 'text',... 'string', 'Visualization Options',... 'fontsize', 14,... 'backgroundcolor', 'white',... 'fontweight', 'bold'); % Clavicula Visibility Option MAINGUIHandle.VisClaviculaOption = uicontrol(... 'units', 'normalized',... 'position', [0.72, 0.5, 0.2, 0.02],... 'style', 'radiobutton',... 'string', 'View Clavicula',... 'Value', 1,... 'fontsize', 14,... 'backgroundcolor', 'white',... 'fontweight', 'bold'); % Scapula Visibility Option MAINGUIHandle.VisScapulaOption = uicontrol(... 'units', 'normalized',... 'position', [0.72, 0.47, 0.2, 0.02],... 'style', 'radiobutton',... 'string', 'View Scapula',... 'Value', 1,... 'fontsize', 14,... 'backgroundcolor', 'white',... 'fontweight', 'bold'); % Humerus Visibility Option MAINGUIHandle.VisHumerusOption = uicontrol(... 'units', 'normalized',... 'position', [0.72, 0.44, 0.2, 0.02],... 'style', 'radiobutton',... 'string', 'View Humerus',... 'Value', 1,... 'fontsize', 14,... 'backgroundcolor', 'white',... 'fontweight', 'bold'); % Ulna Visibility Option MAINGUIHandle.VisUlnaOption = uicontrol(... 'units', 'normalized',... 'position', [0.72, 0.41, 0.2, 0.02],... 'style', 'radiobutton',... 'string', 'View Ulna',... 'Value', 1,... 'fontsize', 14,... 'backgroundcolor', 'white',... 'fontweight', 'bold'); % Radius Visibility Option MAINGUIHandle.VisRadiusOption = uicontrol(... 'units', 'normalized',... 'position', [0.72, 0.38, 0.2, 0.02],... 'style', 'radiobutton',... 'string', 'View Radius',... 'Value', 1,... 'fontsize', 14,... 'backgroundcolor', 'white',... 'fontweight', 'bold'); % Muscle Visibility Option MAINGUIHandle.VisMuscleOption = uicontrol(... 'units', 'normalized',... 'position', [0.72, 0.35, 0.2, 0.02],... 'style', 'radiobutton',... 'string', 'View Muscles',... 'Value', 1,... 'fontsize', 14,... 'backgroundcolor', 'white',... 'fontweight', 'bold'); % Muscle Origins Visibility Option MAINGUIHandle.VisMuscleOOption = uicontrol(... 'units', 'normalized',... 'position', [0.72, 0.32, 0.2, 0.02],... 'style', 'radiobutton',... 'string', 'View Muscle Origins',... 'Value', 1,... 'fontsize', 14,... 'backgroundcolor', 'white',... 'fontweight', 'bold'); % Muscle Insertions Visibility Option MAINGUIHandle.VisMuscleIOption = uicontrol(... 'units', 'normalized',... 'position', [0.72, 0.29, 0.2, 0.02],... 'style', 'radiobutton',... 'string', 'View Muscle Insertions',... 'Value', 1,...5 'fontsize', 14,... 'backgroundcolor', 'white',... 'fontweight', 'bold'); %{ Joint Sinus Cone Visibility Option MAINGUIHandle.VisJointSinusConeOption = uicontrol(... 'units', 'normalized',... 'position', [0.72, 0.24, 0.2, 0.02],... 'style', 'radiobutton',... 'string', 'View Joint Sinus Cones',... 'Value', 0,... 'fontsize', 14,... 'backgroundcolor', 'white',... 'fontweight', 'bold'); %} % Ribcage Ellipsoid Visibility Option MAINGUIHandle.VisEllipsoidOption = uicontrol(... 'units', 'normalized',... 'position', [0.72, 0.26, 0.2, 0.02],... 'style', 'radiobutton',... 'string', 'View Ribcage Ellipsoid',... 'Value', 1,... 'fontsize', 14,... 'backgroundcolor', 'white',... 'fontweight', 'bold'); % Push Button for Updating the Visualisation MAINGUIHandle.Update_Visualisation_Button = uicontrol(... 'units', 'normalized',... 'position', [0.7, 0.20, 0.3, 0.05],... 'style', 'pushbutton',... 'string', '- UPDATE VISUALIZATION ---------------------------------------

Updates the visualization

',... 'fontsize', 14,... 'callback', MAIN_TOOL_script_generator('Update Visualisation')); %-------------------------------------------------------------------------- %-------------------------------------------------------------------------- % SAVE DATA & VISUALISATION PUSHBUTTONS %-------------------------------------------------------------------------- %-------------------------------------------------------------------------- % Push Button for Saving the Visualisation MAINGUIHandle.Save_Visualisation_Button = uicontrol(... 'units', 'normalized',... 'position', [0.7, 0.1, 0.3, 0.05],... 'style', 'pushbutton',... 'string', '- SAVE VISUALISATION ----------------------------------------

Saves the visualization to an EPS file

',... 'fontsize', 14,... 'callback', MAIN_TOOL_script_generator('Save Visualisation')); % Push Button for Saving the Visualisation MAINGUIHandle.Save_Data_Button = uicontrol(... 'units', 'normalized',... 'position', [0.7, 0.05, 0.3, 0.05],... 'style', 'pushbutton',... 'string', '- SAVE DATA ---------------------------------------------------------

Saves the current data structures

',... 'fontsize', 14,... 'callback', MAIN_TOOL_script_generator('Save All Data Structures')); % Push Button for Closing the GUI MAINGUIHandle.Close_GUI_Button = uicontrol(... 'units', 'normalized',... 'position', [0.7, 0.0, 0.3, 0.05],... 'style', 'pushbutton',... 'string', '- CLOSE GUI ---------------------------------------------------------

Closes and saves the current data structures

',... 'fontsize', 14,... 'callback', MAIN_TOOL_script_generator('Save & Close')); % Create a Help UI Menu MAINGUIHandle.Help(1,1) = uimenu(MAINHandle,... 'label', 'MAIN GUI HELP'); % Create a Help UI Menu MAINGUIHandle.Help(2,1) = uimenu(MAINGUIHandle.Help(1,1),... 'label', 'About?',... 'callback', MAIN_TOOL_script_generator('Help')); %-------------------------------------------------------------------------- %-------------------------------------------------------------------------- % INITIALISATION SCRIPT: BUILD THE INITIAL DATA STRUCTURES %-------------------------------------------------------------------------- %-------------------------------------------------------------------------- % Display a message to inform the user that something is happening disp('Building the model data, please wait ...'); SSDATA = []; % Create Bony Landmark Data BLDATA = MAIN_INITIALISATION_build_data_bony_landmark(); % Create Bony Meshing Data MEDATA = MAIN_INITIALISATION_build_data_3D_meshing(); % Create Ribcage Ellipsoid Data (ATTENTION : DATA HAS NOT BEEN OPTIMISED!!) REDATA = MAIN_INITIALISATION_build_data_ribcage_ellipsoid(BLDATA); % Create Muscle Wrapping Data MWDATA = MAIN_INITIALISATION_build_data_muscle_wrapping(BLDATA); %MWDATA = MAIN_INITIALISATION_build_data_muscle_wrapping_new(BLDATA); %MWDATA = MAIN_INITIALISATION_build_data_muscle_wrapping_old(BLDATA); % Create Joint Sinus Cone Data %JCDATA = MAIN_INITIALISATION_build_data_joint_sinus_cone(); % Create the Kinematics Data KEDATA = MAIN_INITIALISATION_build_data_kinematics(REDATA, BLDATA); % Creat the Dynamics Data (This function takes time, builds and saves % symbolic equations) DYDATA = MAIN_INITIALISATION_build_data_dynamics(REDATA, BLDATA); % Display a message to inform the user that the model is ready to be used disp('The model has been constructed, ...'); % Initialise the MADATA structure MADATA = cell(42, 1); % Each element in the cell will contain an Nx15 matrix for MuscleId = 1:42 MADATA{MuscleId, 1}.MomentArms = cell(1,20); MADATA{MuscleId, 1}.MomentArmsNum = cell(1,20); MADATA{MuscleId, 1}.FDirection = cell(1,20); MADATA{MuscleId, 1}.ScapularPlane_GnP = cell(1,20); MADATA{MuscleId, 1}.ScapularPlane = cell(1,20); for SegmentId = 1:20 MADATA{MuscleId, 1}.MomentArms{1,SegmentId} = zeros(size(KEDATA.Joint_Angle_Evolution,2),15); MADATA{MuscleId, 1}.MomentArmsNum{1,SegmentId} = zeros(size(KEDATA.Joint_Angle_Evolution,2),15); MADATA{MuscleId, 1}.FDirection{1,SegmentId} = zeros(size(KEDATA.Joint_Angle_Evolution,2),15); MADATA{MuscleId, 1}.MuscleLength(:,SegmentId) = zeros(size(KEDATA.Joint_Angle_Evolution,2),1); MADATA{MuscleId, 1}.ScapularPlane_GnP{1,SegmentId} = zeros(size(KEDATA.Joint_Angle_Evolution,2),15); MADATA{MuscleId, 1}.ScapularPlane {1,SegmentId} = zeros(size(KEDATA.Joint_Angle_Evolution,2),15); end end % Initialise the EFDATA structure % Initialise the output EFDATA = cell(44,1); % we have 42 muscles plus two consraint forces at TS and AI JRDATA = zeros(size(KEDATA.Joint_Angle_Evolution,2),7); % Contains vector and intensity % Each element in the cell will contain a 9 x N matrix for MuscleId = 1:44 EFDATA{MuscleId, 1}.MomentArms = cell(1,20); for SegmentId = 1:20 EFDATA{MuscleId, 1}.Forces(:,SegmentId) = zeros(size(KEDATA.Joint_Angle_Evolution,2),1); EFDATA{MuscleId, 1}.MomentArms{1,SegmentId} = zeros(size(KEDATA.Joint_Angle_Evolution,2),9); end end % Clear the Masthead data if Masthead is turned on if MastHeadOn clear MainAxis EPFLAxis LBOAxis CHUVAxis; % LAAxis clear TextList PositionList TextHandle; clear EPFLLogo LBOLogo MAINPic CHUVLogo; % LALogo clear CurrentDirectory LogoHandle; set(0, 'currentfigure', MASThead); close gcf; else end %-------------------------------------------------------------------------- %-------------------------------------------------------------------------- % INITIALISATION OF THE VISUALISATION %-------------------------------------------------------------------------- %-------------------------------------------------------------------------- % Create the visualisation MAINVisualisationAxes = axes(... 'units', 'normalized',... 'position', [0.1, 0.05, 0.6, 0.9]); % Set the current axis (this is not necessary but ensures MATLAB is doing % the right thing) set(MAINHandle, 'currentaxes', MAINVisualisationAxes); hold on; % Create the 3-D Meshing Visualisations PlotHandles.MeshHandle(1) = VISUALISATION_view_bone_meshing([], MEDATA, 0, BLDATA); PlotHandles.MeshHandle(2) = VISUALISATION_view_bone_meshing([], MEDATA, 1, BLDATA); PlotHandles.MeshHandle(3) = VISUALISATION_view_bone_meshing([], MEDATA, 2, BLDATA); PlotHandles.MeshHandle(4) = VISUALISATION_view_bone_meshing([], MEDATA, 3, BLDATA); PlotHandles.MeshHandle(5) = VISUALISATION_view_bone_meshing([], MEDATA, 4, BLDATA); PlotHandles.MeshHandle(6) = VISUALISATION_view_bone_meshing([], MEDATA, 5, BLDATA); PlotHandles.MeshHandle(7) = VISUALISATION_view_bone_meshing([], MEDATA, 6, BLDATA); % Create the 3-D Wire Frame Visualisations PlotHandles.WireFrameHandle(1) = VISUALISATION_view_bone_wireframe([], 0, BLDATA); PlotHandles.WireFrameHandle(2) = VISUALISATION_view_bone_wireframe([], 1, BLDATA); PlotHandles.WireFrameHandle(3) = VISUALISATION_view_bone_wireframe([], 2, BLDATA); PlotHandles.WireFrameHandle(4) = VISUALISATION_view_bone_wireframe([], 3, BLDATA); PlotHandles.WireFrameHandle(5) = VISUALISATION_view_bone_wireframe([], 4, BLDATA); PlotHandles.WireFrameHandle(6) = VISUALISATION_view_bone_wireframe([], 5, BLDATA); % Create the 3-D Muscle elements for MuscleId = 1:42 % Origin & Insertion PlotHandles.MuscleOriginHandle(MuscleId) = VISUALISATION_view_muscle_origins([], MWDATA, BLDATA, MuscleId); PlotHandles.MuscleInsertionHandle(MuscleId) = VISUALISATION_view_muscle_insertions([], MWDATA, BLDATA, MuscleId); % Muscle Segements for SegmentId = 1:20 % Only one segment per muscle to start. if SegmentId > 1 PlotHandles.MuscleSegments(MuscleId, SegmentId) = plot3(0, 0, 0,... 'color', 'red', 'linewidth', 2, 'marker', 'o', 'markerfacecolor', 'red', 'markersize', 6); else PlotHandles.MuscleSegments(MuscleId, SegmentId) = VISUALISATION_view_muscle_segement([], MWDATA, BLDATA, MuscleId, SegmentId); end end end % Initialise the Joint Sinus Cone Visualisations %PlotHandles.JointSinusCone(1,1) = surf(zeros(2,2), zeros(2,2), zeros(2,2)); %PlotHandles.JointSinusCone(1,2) = surf(zeros(2,2), zeros(2,2), zeros(2,2)); %PlotHandles.JointSinusCone(1,3) = surf(zeros(2,2), zeros(2,2), zeros(2,2)); % Initialise the Ribcage Ellipsoid Visualisation PlotHandles.Ellispoid = surf(zeros(2,2), zeros(2,2), zeros(2,2)); %-------------------------------------------------------------------------- % SET THE APPEARANCE OF THE VISUALISATION %-------------------------------------------------------------------------- % Set some lights to help visualise the model light('Position',[ 1, 0, 0],'Style','infinite'); light('Position',[ 0, 0, -10],'Style','local'); light('Position',[10, -50, 0],'Style','infinite'); colormap copper; % Give the bone meshings a bone color. box on; % Turn the axes box on. It makes is easier to keep track of the orientation. material dull; % Define the bone meshing material. It removes the shiny effect. axis equal; % Correct the apsect ratio. zoom(1); % Zoom in on the visualisation. otherwise it looks very small. view([135, 25]); % Setup the initial camera postion [0,0] is behind horizontally.