% This function draws/plots the skeleton, frame by frame, for a given example activity
function drawSkeletonForOneExample( Vin, noOfFrames )
	% Vin = the row vector of one example, comprising of frames of joints of x,y,z coordinates
	% noOfFrames = in one example

    %% Enumerate 15 joints
    SKEL_HEAD = 1;
    SKEL_NECK = 2;
    SKEL_TORSO = 3;
    SKEL_LEFT_SHOULDER = 4;
    SKEL_LEFT_ELBOW = 5;
    SKEL_LEFT_HAND = 6;
    SKEL_RIGHT_SHOULDER = 7;
    SKEL_RIGHT_ELBOW = 8;
    SKEL_RIGHT_HAND = 9;
    SKEL_LEFT_HIP = 10;
    SKEL_LEFT_KNEE = 11;
    SKEL_LEFT_FOOT = 12;
    SKEL_RIGHT_HIP = 13;
    SKEL_RIGHT_KNEE = 14;
    SKEL_RIGHT_FOOT = 15;
	
	[ m n ] = size( Vin );
	noOfCoordinatesPerFrame = n / noOfFrames;
	noOfJoints = noOfCoordinatesPerFrame / 3;
	
	for j=1:noOfFrames,
		XframeFlat = Vin( noOfCoordinatesPerFrame*(j-1)+1:j*noOfCoordinatesPerFrame ); %coordinates for this frame
		Xtemp = zeros( 3,noOfJoints ); %3 coordinates per joints

		for k=1:noOfJoints,
			Xtemp(:,k) = XframeFlat(3*(k-1)+1:k*3)';
		endfor
		
		%swap axes such that plot y = z, z = y, while x = x; Octave is ( x, z, y) i.e. left handed
		Xframe = Xtemp;
		Xframe( 2,: ) = Xtemp( 3,: );
		Xframe( 3,: ) = Xtemp( 2,: );
		
		plot3( Xframe(1,:), Xframe(2,:), Xframe(3,:), 'o', 'linewidth', 2, 'color', 'r' ); % plot all joints
		line( Xframe( 1, SKEL_HEAD:SKEL_NECK ), Xframe( 2, SKEL_HEAD:SKEL_NECK ), Xframe( 3, SKEL_HEAD:SKEL_NECK ), 'linewidth', 2, 'color', 'g' );
		line( Xframe( 1, SKEL_LEFT_SHOULDER:SKEL_LEFT_HAND ), Xframe( 2, SKEL_LEFT_SHOULDER:SKEL_LEFT_HAND ), Xframe( 3, SKEL_LEFT_SHOULDER:SKEL_LEFT_HAND ), 'linewidth', 2, 'color', 'g' );
		line( Xframe( 1, SKEL_RIGHT_SHOULDER:SKEL_RIGHT_HAND ), Xframe( 2, SKEL_RIGHT_SHOULDER:SKEL_RIGHT_HAND ), Xframe( 3, SKEL_RIGHT_SHOULDER:SKEL_RIGHT_HAND ), 'linewidth', 2, 'color', 'g' );
		line( Xframe( 1, SKEL_LEFT_HIP:SKEL_LEFT_FOOT ), Xframe( 2, SKEL_LEFT_HIP:SKEL_LEFT_FOOT ), Xframe( 3, SKEL_LEFT_HIP:SKEL_LEFT_FOOT ), 'linewidth', 2, 'color', 'g' );
		line( Xframe( 1, SKEL_RIGHT_HIP:SKEL_RIGHT_FOOT ), Xframe( 2, SKEL_RIGHT_HIP:SKEL_RIGHT_FOOT ), Xframe( 3, SKEL_RIGHT_HIP:SKEL_RIGHT_FOOT ), 'linewidth', 2, 'color', 'g' );
		line( Xframe( 1, [ SKEL_LEFT_SHOULDER SKEL_NECK SKEL_RIGHT_SHOULDER SKEL_TORSO SKEL_LEFT_HIP SKEL_RIGHT_HIP SKEL_TORSO SKEL_LEFT_SHOULDER ] ),
			  Xframe( 2, [ SKEL_LEFT_SHOULDER SKEL_NECK SKEL_RIGHT_SHOULDER SKEL_TORSO SKEL_LEFT_HIP SKEL_RIGHT_HIP SKEL_TORSO SKEL_LEFT_SHOULDER ] ),
			  Xframe( 3, [ SKEL_LEFT_SHOULDER SKEL_NECK SKEL_RIGHT_SHOULDER SKEL_TORSO SKEL_LEFT_HIP SKEL_RIGHT_HIP SKEL_TORSO SKEL_LEFT_SHOULDER ] ),
			  'linewidth', 2, 'color', 'g' );
		axis( [ -2500,2500,-4500,4500,-2000,2000 ],"equal" );
		line( [ 0 1000 ], [ 0 0 ] , [ 0 0 ], 'linewidth',2,'color','b'); % x-axis
		line( [ 0 0 ], [ 0 1000 ] , [ 0 0 ], 'linewidth',2,'color','b'); % z-axis ( of kinect )
		line( [ 0 0 ], [ 0 0 ] , [ 0 1000 ], 'linewidth',2,'color','b'); % y-axis ( of kinect )
		usleep(1000);
	endfor
	
	

endfunction