Commit b5b0bfc9 authored by Alexander Krause's avatar Alexander Krause

Refactoring of GestureDatabase 2

parent 55fc6bc4
......@@ -16,12 +16,14 @@ namespace ExplorVizGestureControl.General
public class JointAccumulator
{
// 25 joints
private Vector3D[] accumulatedJoints = new Vector3D[25];
private Vector3D[] accumulatedJoints = new Vector3D[Enum.GetNames(typeof(JointType)).Length];
private CameraSpacePoint[] filteredJoints;
private bool initialAccumulation = true;
private float accumulationCount = 1;
// Not passed by reference as design choice. You may use filteredJoints'
// unaltered data
public Vector3D[] accumulateJoints(CameraSpacePoint[] filteredJoints)
{
this.filteredJoints = filteredJoints;
......
......@@ -187,7 +187,7 @@ namespace ExplorVizGestureControl.Gestures
double distanceX = GestureDatabase.Joints[(int)JointType.HandRight].X - GestureDatabase.PreviousFrameJoints[(int)JointType.HandRight].X;
double distanceY = GestureDatabase.Joints[(int)JointType.HandRight].Y - GestureDatabase.PreviousFrameJoints[(int)JointType.HandRight].Y;
int moveX = (int)(distanceX * 1000);
int moveY = (int)(distanceY * 1000);
......
......@@ -56,7 +56,9 @@ namespace ExplorVizGestureControl.Gestures
phiz = new PhIZ();
maxCapacity = 10;
headsStack = new CameraSpacePoint[maxCapacity];
headsStack = new CameraSpacePoint[maxCapacity];
joints = new CameraSpacePoint[Enum.GetNames(typeof(JointType)).Length];
}
#endregion
......@@ -68,15 +70,16 @@ namespace ExplorVizGestureControl.Gestures
int flagIndex = 0;
if (flags[flagIndex] == 0)
{
previousFrameJoints = filteredJoints;
{
previousFrameJoints = (CameraSpacePoint[])filteredJoints.Clone();
flags[flagIndex] = 1;
}
else
{
previousFrameJoints = joints;
CopyCameraSpacePoints(joints, ref previousFrameJoints);
}
joints = filteredJoints;
CopyCameraSpacePoints(filteredJoints, ref joints);
joints[(int)JointType.ShoulderRight].X = (float)accumulatedJoint[(int)JointType.ShoulderRight].X;
joints[(int)JointType.ShoulderRight].Y = (float)accumulatedJoint[(int)JointType.ShoulderRight].Y;
......@@ -94,24 +97,33 @@ namespace ExplorVizGestureControl.Gestures
headsStack[newestOldHead] = joints[(int)JointType.Head];
newestOldHead = ++newestOldHead % maxCapacity;
// newestOldHead == 0 <=> one circle <=> full array
if (newestOldHead == 0) flags[1] = 1;
}
#endregion
private static void CopyCameraSpacePoints(CameraSpacePoint[] source, ref CameraSpacePoint[] dest)
{
int length = source.Length;
for (int i = 0; i < length; i++)
{
dest[i].X = source[i].X;
dest[i].Y = source[i].Y;
dest[i].Z = source[i].Z;
}
}
#region HandStates
public static bool RightHandClosed()
{
return handRightState == HandState.Closed ? true : false;
return handRightState == HandState.Closed ? true : false;
}
public static bool LeftHandClosed()
{
return handLeftState == HandState.Closed ? true : false;
}
#endregion
......@@ -119,42 +131,42 @@ namespace ExplorVizGestureControl.Gestures
public static Boolean RightElbowBelowRightHand()
{
return joints[(int)JointType.ElbowLeft].Y < joints[(int)JointType.HandRight].Y;
return joints[(int)JointType.ElbowLeft].Y < joints[(int)JointType.HandRight].Y;
}
public static Boolean RightHandBelowRightShoulder()
{
return joints[(int)JointType.HandRight].Y < joints[(int)JointType.ShoulderRight].Y;
return joints[(int)JointType.HandRight].Y < joints[(int)JointType.ShoulderRight].Y;
}
public static Boolean RightHandMoreToTheRightThanRightElbow()
{
return joints[(int)JointType.HandRight].X < joints[(int)JointType.ElbowRight].X;
return joints[(int)JointType.HandRight].X < joints[(int)JointType.ElbowRight].X;
}
public static Boolean RightShoulderBelowRightElbow()
{
return joints[(int)JointType.ElbowRight].Y < joints[(int)JointType.ShoulderRight].Y;
return joints[(int)JointType.ElbowRight].Y < joints[(int)JointType.ShoulderRight].Y;
}
public static Boolean LeftElbowBelowLeftHand()
{
return joints[(int)JointType.ElbowLeft].Y < joints[(int)JointType.HandLeft].Y;
return joints[(int)JointType.ElbowLeft].Y < joints[(int)JointType.HandLeft].Y;
}
public static Boolean LeftHandBelowLeftShoulder()
{
return joints[(int)JointType.HandLeft].Y < joints[(int)JointType.ShoulderLeft].Y;
return joints[(int)JointType.HandLeft].Y < joints[(int)JointType.ShoulderLeft].Y;
}
public static Boolean LeftHandMoreToTheLeftThanLeftElbow()
{
return joints[(int)JointType.HandLeft].X < joints[(int)JointType.ElbowLeft].X;
return joints[(int)JointType.HandLeft].X < joints[(int)JointType.ElbowLeft].X;
}
public static Boolean LeftShoulderBelowLeftElbow()
{
return joints[(int)JointType.ElbowLeft].Y < joints[(int)JointType.ShoulderLeft].Y;
return joints[(int)JointType.ElbowLeft].Y < joints[(int)JointType.ShoulderLeft].Y;
}
public static Boolean BothHandsOpen()
......@@ -189,7 +201,7 @@ namespace ExplorVizGestureControl.Gestures
public static Boolean HandsHaveAcceptableDistance(double offset = 0.0, char axis = 'x')
{
if (axis.Equals('x')) return Math.Abs(Math.Abs(joints[(int)JointType.HandLeft].X) -
if (axis.Equals('x')) return Math.Abs(Math.Abs(joints[(int)JointType.HandLeft].X) -
Math.Abs(joints[(int)JointType.HandRight].X)) <=
Math.Abs(Math.Abs(joints[(int)JointType.ShoulderLeft].X) - Math.Abs(joints[(int)JointType.ShoulderRight].X)) + offset;
......@@ -229,11 +241,15 @@ namespace ExplorVizGestureControl.Gestures
int arrayLength = headsStack.Length;
for(int i = 0; i < arrayLength; i++) {
for (int i = 0; i < arrayLength; i++)
{
if (joints[(int)JointType.Head].Y > headsStack[i].Y + 0.05) {
if (joints[(int)JointType.Head].Y > headsStack[i].Y + 0.05)
{
confidenceArray[i] = true;
} else {
}
else
{
confidenceArray[i] = false;
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment