<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using ProtoBuf;

namespace Arges.KinectRemote.Data
{
    /// <summary>
    /// Encapsulates data for a single body
    /// </summary>
    [Serializable, ProtoContract]
    public class KinectBody
    {
        #region Properties

        /// <summary>
        /// Current Body Id
        /// </summary>
        [ProtoMember(1)] public readonly string BodyId;

        /// <summary>
        /// Collection of Joints
        /// </summary>
        [ProtoMember(2)] public KinectJoint[] Joints;

        /// <summary>
        /// Indicates if there is any ambiguity in the body
        /// </summary>
        [ProtoMember(3), ProtoEnum] public BodyAmbiguity Ambiguity = BodyAmbiguity.Clear;

        /// <summary>
        /// Left hand state from the list of possible Kinect hand states
        /// </summary>
        [ProtoMember(4)] public KinectHandState HandLeftState;

        /// <summary>
        /// Right hand state from the list of possible Kinect hand states
        /// </summary>
        [ProtoMember(5)] public KinectHandState HandRightState;

        /// <summary>
        /// Confidence for the left hand state
        /// </summary>
        [ProtoMember(6)] public float HandLeftConfidence;

        /// <summary>
        /// Confidence for the right hand state
        /// </summary>
        [ProtoMember(7)] public float HandRightConfidence;

        /// <summary>
        /// Application-specific body priority
        /// </summary>
        /// <remarks>
        /// Meant for processing in the remote, for example to indicate if
        /// here is a particular user who we want to designate as the main
        /// one. The meaning will be application-specific.
        /// </remarks>
        [ProtoMember(8)] public int Priority;

        /// <summary>
        /// Lean amounts for the body. Left/Right corresponds to the X,
        /// Forward/Back to the Y.
        /// </summary>
        [ProtoMember(9)] public KinectPoint Lean;

        /// <summary>
        /// Lean tracking state.
        /// </summary>
        [ProtoMember(10)] public KinectTrackingState LeanTrackingState;

        /// <summary>
        /// Original Tracking ID for the body from the sensor
        /// </summary>
        [ProtoMember(11)] public readonly ulong TrackingId;

        /// <summary>
        /// Custom float values calculated by a body processor to be sent over the wire
        /// </summary>
        /// <remarks>
        /// We may want to have a body processor calculate some body- or joint-
        /// related information, to relieve the load from the client site. Use
        /// this property to send these values.
        /// </remarks>
        [ProtoMember(12)] public Dictionary<string, float> FloatData = new Dictionary<string, float>();

        /// <summary>
        /// Custom Vector3 values calculated by a body processor to be sent over the wire
        /// </summary>
        /// <remarks>
        /// We may want to have a body processor calculate some body- or joint-
        /// related information, to relieve the load from the client site. Use
        /// this property to send these values if they're vectors.
        /// </remarks>
        [ProtoMember(13)]
        public Dictionary<string, KinectVector3> Vector3Data = new Dictionary<string, KinectVector3>();


        /// <summary>
        /// Indexes the joints by KinectJointType
        /// </summary>
        /// <param name="jointType">Joint type</param>
        /// <returns>Corresponding KinectJoint</returns>
        public KinectJoint this[KinectJointType jointType]
        {
            get { return Joints[(int) jointType]; }
            set { Joints[(int) jointType] = value; }
        }

        #endregion

        public KinectBody()
        {
        }

        public KinectBody(string sensorId, ulong trackingId)
        {
            // Add an identifier using the sensor ID to keep the body entity unique across all devices.
            BodyId = string.Format("{0}.{1}", sensorId, trackingId);
            TrackingId = trackingId;
        }

        /// <summary>
        /// Offsets joints to a particular distance.
        /// </summary>
        /// <param name="x">X offset</param>
        /// <param name="y">Y offset</param>
        /// <param name="z">Z offset</param>
        public void ApplyOffset(float x, float y, float z)
        {
            if (Joints == null)
            {
                return;
            }
            foreach (var joint in Joints)
            {
                joint.Position.X += x;
                joint.Position.Y += y;
                joint.Position.Z += z;
            }
        }

        public override string ToString()
        {
            return string.Format("Id: {0} Ambiguity: {1:F}", BodyId, Ambiguity);
        }

        /// <summary>
        /// Evaluates if a joint in the body is inferred
        /// </summary>
        /// <param name="jointType">Joint type to look for</param>
        /// <returns>Returns true if the joint is inferred, false if it is not or it isn't found</returns>
        public bool IsJointInferred(KinectJointType jointType)
        {
            var joint =
                Joints.FirstOrDefault(x => x.JointType == jointType && x.TrackingState == KinectTrackingState.Inferred);
            return joint != null;
        }
    }


    [ProtoContract]
    public enum KinectHandState
    {
        Unknown = 0,
        NotTracked = 1,
        Open = 2,
        Closed = 3,
        Lasso = 4,
    }


    [ProtoContract]
    public enum KinectJointType
    {
        SpineBase = 0,
        SpineMid = 1,
        Neck = 2,
        Head = 3,
        ShoulderLeft = 4,
        ElbowLeft = 5,
        WristLeft = 6,
        HandLeft = 7,
        ShoulderRight = 8,
        ElbowRight = 9,
        WristRight = 10,
        HandRight = 11,<commit_msg>No need to use LINQ to see if a joint is inferred<commit_after>﻿using System;
using System.Collections.Generic;
using ProtoBuf;

namespace Arges.KinectRemote.Data
{
    /// <summary>
    /// Encapsulates data for a single body
    /// </summary>
    [Serializable, ProtoContract]
    public class KinectBody
    {
        #region Properties

        /// <summary>
        /// Current Body Id
        /// </summary>
        [ProtoMember(1)] public readonly string BodyId;

        /// <summary>
        /// Collection of Joints
        /// </summary>
        [ProtoMember(2)] public KinectJoint[] Joints;

        /// <summary>
        /// Indicates if there is any ambiguity in the body
        /// </summary>
        [ProtoMember(3), ProtoEnum] public BodyAmbiguity Ambiguity = BodyAmbiguity.Clear;

        /// <summary>
        /// Left hand state from the list of possible Kinect hand states
        /// </summary>
        [ProtoMember(4)] public KinectHandState HandLeftState;

        /// <summary>
        /// Right hand state from the list of possible Kinect hand states
        /// </summary>
        [ProtoMember(5)] public KinectHandState HandRightState;

        /// <summary>
        /// Confidence for the left hand state
        /// </summary>
        [ProtoMember(6)] public float HandLeftConfidence;

        /// <summary>
        /// Confidence for the right hand state
        /// </summary>
        [ProtoMember(7)] public float HandRightConfidence;

        /// <summary>
        /// Application-specific body priority
        /// </summary>
        /// <remarks>
        /// Meant for processing in the remote, for example to indicate if
        /// here is a particular user who we want to designate as the main
        /// one. The meaning will be application-specific.
        /// </remarks>
        [ProtoMember(8)] public int Priority;

        /// <summary>
        /// Lean amounts for the body. Left/Right corresponds to the X,
        /// Forward/Back to the Y.
        /// </summary>
        [ProtoMember(9)] public KinectPoint Lean;

        /// <summary>
        /// Lean tracking state.
        /// </summary>
        [ProtoMember(10)] public KinectTrackingState LeanTrackingState;

        /// <summary>
        /// Original Tracking ID for the body from the sensor
        /// </summary>
        [ProtoMember(11)] public readonly ulong TrackingId;

        /// <summary>
        /// Custom float values calculated by a body processor to be sent over the wire
        /// </summary>
        /// <remarks>
        /// We may want to have a body processor calculate some body- or joint-
        /// related information, to relieve the load from the client site. Use
        /// this property to send these values.
        /// </remarks>
        [ProtoMember(12)] public Dictionary<string, float> FloatData = new Dictionary<string, float>();

        /// <summary>
        /// Custom Vector3 values calculated by a body processor to be sent over the wire
        /// </summary>
        /// <remarks>
        /// We may want to have a body processor calculate some body- or joint-
        /// related information, to relieve the load from the client site. Use
        /// this property to send these values if they're vectors.
        /// </remarks>
        [ProtoMember(13)]
        public Dictionary<string, KinectVector3> Vector3Data = new Dictionary<string, KinectVector3>();


        /// <summary>
        /// Indexes the joints by KinectJointType
        /// </summary>
        /// <param name="jointType">Joint type</param>
        /// <returns>Corresponding KinectJoint</returns>
        public KinectJoint this[KinectJointType jointType]
        {
            get { return Joints[(int) jointType]; }
            set { Joints[(int) jointType] = value; }
        }

        #endregion

        public KinectBody()
        {
        }

        public KinectBody(string sensorId, ulong trackingId)
        {
            // Add an identifier using the sensor ID to keep the body entity unique across all devices.
            BodyId = string.Format("{0}.{1}", sensorId, trackingId);
            TrackingId = trackingId;
        }

        /// <summary>
        /// Offsets joints to a particular distance.
        /// </summary>
        /// <param name="x">X offset</param>
        /// <param name="y">Y offset</param>
        /// <param name="z">Z offset</param>
        public void ApplyOffset(float x, float y, float z)
        {
            if (Joints == null)
            {
                return;
            }
            foreach (var joint in Joints)
            {
                joint.Position.X += x;
                joint.Position.Y += y;
                joint.Position.Z += z;
            }
        }

        public override string ToString()
        {
            return string.Format("Id: {0} Ambiguity: {1:F}", BodyId, Ambiguity);
        }

        /// <summary>
        /// Evaluates if a joint in the body is inferred
        /// </summary>
        /// <param name="jointType">Joint type to look for</param>
        /// <returns>Returns true if the joint is inferred or null, false if it is not or it isn't found</returns>
        public bool IsJointInferred(KinectJointType jointType)
        {
            return this[jointType] == null || this[jointType].TrackingState == KinectTrackingState.Inferred;
        }
    }


    [ProtoContract]
    public enum KinectHandState
    {
        Unknown = 0,
        NotTracked = 1,
        Open = 2,
        Closed = 3,
        Lasso = 4,
    }


    [ProtoContract]
    public enum KinectJointType
    {
        SpineBase = 0,
        SpineMid = 1,
        Neck = 2,
        Head = 3,
        ShoulderLeft = 4,
        ElbowLeft = 5,
        WristLeft = 6,
        HandLeft = 7,
        ShoulderRight = 8,
        ElbowRight = 9,
        WristRight = 10,
        HandRight = 11,
{'fraction_non_alphanumeric': 0.11251376768618147, 'fraction_numerical': 0.007455731593662628, 'mean_word_length': 1.6484182185326453, 'pattern_counts': {'":': 0, '<': 119, '<?xml version=': 0, '>': 120, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1671622', 'n_tokens_mistral': 3259, 'n_tokens_neox': 3098, 'n_words': 1033}