Example a_backup/knee_kinematics: Transforming bone structures using field variables stored in a dummy node

This example demonstrates the use of field variables to transform bones and visualise anatomical coordinate systems during knee flexion-extension.

The femur, tibia, fibula and patella mesh are read in (.exnode and .exelem files). The tibia and fibula are then transformed throughout 40 time steps by reading in dummy nodes in each time frame which contain the 4 x 4 transformation matrix (field 3: trans) and the direction of the axes of the anatomical coordinate system (field 2: anatomicalCS).

The anatomical coordinate systems and the transformation matrices are computed based on the positions of anatomical landmarks from optical motion capture. The corresponding matlab scripts are given in the folder matlab/ which also contains the initial position of the landmarks (landmarks.txt) and the position of the landmarks during the movement (111.txt).

The application of this example to the entire lower limbs during walking can be viewed at ABI gait research.

Created by Katja Oberhofer, May 2009

Screenshot of example a_backup/knee_kinematics


The comfile run by this example is as follows:

# ***** BEGIN LICENSE BLOCK *****
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
#
# The contents of this file are subject to the Mozilla Public License Version
# 1.1 (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
# http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
# for the specific language governing rights and limitations under the
# License.
#
# The Original Code is CMISS knee kinematics example.
#
# The Initial Developer of the Original Code is Katja Oberhofer
#
# Portions created by the Initial Developer are Copyright (C) 2009
# the Initial Developer. All Rights Reserved.
#
# Alternatively, the contents of this file may be used under the terms of
# either the GNU General Public License Version 2 or later (the "GPL"), or
# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
# in which case the provisions of the GPL or the LGPL are applicable instead
# of those above. If you wish to allow use of your version of this file only
# under the terms of either the GPL or the LGPL, and not to allow others to
# use your version of this file under the terms of the MPL, indicate your
# decision by deleting the provisions above and replace them with the notice
# and other provisions required by the GPL or the LGPL. If you do not delete
# the provisions above, a recipient may use your version of this file under
# the terms of any one of the MPL, the GPL or the LGPL.
#
# ***** END LICENSE BLOCK *****

# Script:	knee_kinematics.com
# Purpose:	Demonstrating the use of field variables, stored in a dummy node,
# 		to rigidly transform bones and visualise coordinate systems.
# Author:	Katja Oberhofer (k.oberhofer@auckland.ac.nz)
# Date:		12 May 2009
#
#*******************************************************************

$first_frame = 1;
$total_lines = 40;

# **************************** subroutines *************************

sub view_cmgui
 	{
	
	($st_name) = @_;
	
	#********* reading in bone exnode and exelem file *********
	
	gfx read node $example/structures/${st_name}.exnode;             
	gfx read elem $example/structures/${st_name}.exelem;
	
	gfx modify g_element ${st_name} general clear;
	gfx modify g_element ${st_name} surfaces exterior select_on material bone selected_material default_selected render_shaded;
	gfx modify g_element ${st_name} lines select_on invisible selected_material none;

	gfx read data $example/structures/${st_name}_dummy.exnode;
		
	gfx define field "${st_name}/e1" coordinate_system rectangular_cartesian composite anatomicalCS.1 anatomicalCS.2 anatomicalCS.3;
	gfx define field "${st_name}/e2" coordinate_system rectangular_cartesian composite anatomicalCS.4 anatomicalCS.5 anatomicalCS.6;
	gfx define field "${st_name}/e3" coordinate_system rectangular_cartesian composite anatomicalCS.7 anatomicalCS.8 anatomicalCS.9;

	gfx modify g_element "${st_name}/dummy_${st_name}" data_points glyph arrow_solid centre 0,0,0 orientation e1 material blue scale_factors "150*20*20";
	gfx modify g_element "${st_name}/dummy_${st_name}" data_points glyph arrow_solid centre 0,0,0 orientation e2 material green scale_factors "150*20*20";
	gfx modify g_element "${st_name}/dummy_${st_name}" data_points glyph arrow_solid centre 0,0,0 orientation e3 material red scale_factors "150*20*20";
	 
 	}
	
sub simul_cmgui
 	{
	
	($st_name,${node}) = @_;
	
	#********* reading in bone exnode and exelem file *********
	
	gfx read node $example/structures/${st_name}.exnode;             
	gfx read elem $example/structures/${st_name}.exelem;
	
	$t = 1;
 
	gfx modify g_element ${st_name} general clear;
 	gfx modify g_element ${st_name} surfaces coordinate coordinates exterior select_on material bone selected_material default_selected render_shaded;
	gfx modify g_element ${st_name} lines coordinate coordinates select_on invisible selected_material none;
	
	for ($c = $first_frame; $c < $first_frame+$total_lines; $c++) {
	
		#******** reading in dummy node which contains the transformation matrix as field variable ********
		
	 	gfx read data "$example/simul/${st_name}_${c}.exnode" time ${t} region ${st_name};
	 
	 	$t = $t + 1;
		
	 	}
		
	 gfx define field "${st_name}/e1" coordinate_system rectangular_cartesian composite anatomicalCS.1 anatomicalCS.2 anatomicalCS.3;
	 gfx define field "${st_name}/e2" coordinate_system rectangular_cartesian composite anatomicalCS.4 anatomicalCS.5 anatomicalCS.6;
	 gfx define field "${st_name}/e3" coordinate_system rectangular_cartesian composite anatomicalCS.7 anatomicalCS.8 anatomicalCS.9;

	 gfx modify g_element "${st_name}/dummy_${st_name}" data_points WORLD coordinate coordinates glyph arrow_solid centre 0,0,0 orientation e1 material blue scale_factors "150*20*20";
	 gfx modify g_element "${st_name}/dummy_${st_name}" data_points WORLD coordinate coordinates glyph arrow_solid centre 0,0,0 orientation e2 material green scale_factors "150*20*20";
	 gfx modify g_element "${st_name}/dummy_${st_name}" data_points WORLD coordinate coordinates glyph arrow_solid centre 0,0,0 orientation e3 material red scale_factors "150*20*20";
		
	 # transforming the bones
		
	 gfx define field "${st_name}/transform_${st_name}" nodal_lookup field trans node ${node} nodeset cmiss_data;
	 gfx set transformation name ${st_name} field transform_${st_name};
		
 	}   
	
# ************ draw bone into different scenes ****************

view_cmgui('right_femur');
view_cmgui('right_patella');

simul_cmgui('right_tibia','100003');
simul_cmgui('right_fibula','100003');

gfx timekeeper default set_time 1;

#*************** create window and light **********************

$h = '600';
$w = '400';

gfx create window;
gfx modify window 1 background colour 1 1 1;
gfx modify win 1 layout height $h width $w; 

gfx modify win 1 view parallel eye_point 1679.5 -105.274 1.98629
gfx modify win 1 view parallel interest_point 13.7433 -105.274 1.98629
gfx modify win 1 view parallel up_vector 0 0 1
gfx modify win 1 view parallel view_angle 28.274
gfx modify win 1 view parallel near_clipping_plane 16.6576  far_clipping_plane 5952.86; 
gfx modify win 1 view parallel relative_viewport ndc_placement -1 1 2 2 viewport_coordinates 0 0 1 1;

Files used by this example are:

Name                 Modified     Size

knee_kinematics.com 20-Apr-2012 6.2k COPYRIGHT 20-Apr-2012 504 matlab/ 19-Apr-2012 - simul/ 19-Apr-2012 - structures/ 19-Apr-2012 -

Download the entire example:

Name                                      Modified     Size

examples_a_backup_knee_kinematics.tar.gz 12-Aug-2014 833k

Testing status by version:

StatusTestedReal time (s)
i686-linux
cmgui-wxSuccessSun Mar 6 00:10:39 20163
cmgui-wx-debugSuccessSun Mar 6 00:13:45 20164
cmgui-wx-debug-memorycheckSuccessSun Mar 6 00:15:00 20164
cmgui-wx-debug-valgrindFailureSun Mar 6 01:15:44 201656
last breakSun Mar 6 01:14:00 201656
last successTue Feb 10 01:07:00 201557
x86_64-linux
cmgui-wxFailureSun Mar 6 00:01:37 20160
last breakSun Mar 6 00:01:00 20160
last successWed Jun 3 00:05:00 20151
cmgui-wx-debugFailureSun Mar 6 00:01:37 20160
last breakSun Mar 6 00:01:00 20160
last successWed Jun 3 00:05:00 20151
cmgui-wx-debug-memorycheckFailureSun Mar 6 00:01:37 20160
last breakSun Mar 6 00:01:00 20160
last successWed Jun 3 00:05:00 20151
cmgui-wx-debug-valgrindFailureSun Mar 6 00:03:31 20169
last breakSun Mar 6 00:03:00 20169
last successWed Jun 3 00:38:00 201546
cmgui-wx-gcc-cad-debug-valgrindSuccessThu Jan 7 00:02:17 20167

Testing status by file:


Html last generated: Sun Mar 6 05:50:58 2016

Input last modified: Fri Apr 20 16:00:00 2012


CMISS Help / Examples / a_backup / knee_kinematics