예제 #1
0
 public BodyData(MarkersNames m)
 {
     this.m = m;
     Height = 175; // cm
     Mass = 75; //kg
     ShoulderWidth = 400; //mm
 }
 /// <summary>
 /// Constructor sets the markers name in the MarkesName class used for joint localization
 /// </summary>
 /// <param name="labelMarkers">The list of labelmarkets</param>
 /// <param name="markerNames">A reference to the markers names</param>
 /// <param name="bodyPrefix">Any possible prefix of the markersname</param>
 public MarkersPreprocessor(List<Marker> labelMarkers, out MarkersNames markerNames, string bodyPrefix = "")
 {
     this.prefix = bodyPrefix;
     markers = new Dictionary<string, Vector3>();
     //Converting markers
     for (int i = 0; i < labelMarkers.Count; i++)
     {
         markers.Add(labelMarkers[i].Label, labelMarkers[i].Position);
     }
     //Finding the markers aliases
     markerNames  = NameSet(markers.Keys);
     //foreach (var n in markerNames) UnityEngine.Debug.Log(n);
     m = markerNames;
     // adding non existing markers
     markersLastFrame = new Dictionary<string, Vector3>();
     foreach (var mark in m)
     {
         markersLastFrame.Add(mark, Vector3Helper.NaN);
         if (!markers.ContainsKey(mark))
         {
             markers.Add(mark, Vector3Helper.NaN);
         }
     }
     // setting arbitrary hip makres positions
     markersLastFrame[m.bodyBase] = lastSACRUMknown;
     markersLastFrame[m.leftHip] = lastLIASknown;
     markersLastFrame[m.rightHip] = lastRIASknown;
 }
 /// <summary>
 /// Setting up for joint localization
 /// </summary>
 /// <param name="markers">The aliases of the marker names</param>
 public JointLocalization(MarkersNames markers)
 {
     this.m = markers;
     bd = new BodyData(m);
     jcFuncs = new List<Action<Bone>>() {
             (b) => Plevis(b),
             (b) => SpineRoot(b),
             (b) => MidSpine(b),
             (b) => SpineEnd(b),
             (b) => Neck(b),
             (b) => GetHead(b),
             (b) => GetHeadTop(b),
             (b) => GetShoulderLeft(b),
             (b) => GetUpperArmLeft(b),
             (b) => GetLowerArmLeft(b),
             (b) => GetWristLeft(b),
             (b) => GetHandLeft(b),
             (b) => GetIndexLeft(b),
             (b) => GetTrapLeft(b),
             (b) => GetThumbLeft(b),
             (b) => GetShoulderRight(b),
             (b) => GetUpperArmRight(b),
             (b) => GetLowerArmRight(b),
             (b) => GetWristRight(b),
             (b) => GetHandRight(b),
             (b) => GetIndexRight(b),
             (b) => GetTrapRight(b),
             (b) => GetThumbRight(b),
             (b) => UpperLegLeft(b),
             (b) => LowerLegLeft(b),
             (b) => GetAnkleLeft(b),
             (b) => GetFootBaseLeft(b),
             (b) => GetFootLeft(b),
             (b) => UpperLegRight(b),
             (b) => LowerLegRight(b),
             (b) => GetAnkleRight(b),
             (b) => GetFootBaseRight(b),
             (b) => GetFootRight(b),
         };
 }
        /// <summary>
        /// Finds aliases of different markers and replaces the names
        /// </summary>
        /// <param name="markersNames">A collection of the names of the markers</param>
        /// <returns>The set marker names</returns>
        private MarkersNames NameSet(ICollection<string> markersNames)
        {
            MarkersNames m = new MarkersNames();
            #region hip
            var quary = MarkerNames.bodyBaseAKA.FirstOrDefault(n => markersNames.Contains(prefix + n));
            if (quary == null)
            {
                var q2 = MarkerNames.bodyBasebetween.FirstOrDefault(n => markersNames.Contains(prefix + n[0]) && markersNames.Contains(prefix + n[1]));
                if (q2 != null)
                {
                    sacrumBetween = true;
                    sacrumBetweenMarkers = new string[2];
                    sacrumBetweenMarkers[0] = prefix + q2[0];
                    sacrumBetweenMarkers[1] = prefix + q2[1];

                }
            }
            else
            {
                m.bodyBase = prefix + quary;
            }
            SetName(markersNames, MarkerNames.leftHipAKA, ref m.leftHip, prefix);
            SetName(markersNames, MarkerNames.rightHipAKA, ref m.rightHip, prefix);
            #endregion

            #region upperbody
            SetName(markersNames, MarkerNames.spineAKA, ref m.spine, prefix);
            SetName(markersNames, MarkerNames.neckAKA, ref m.neck, prefix);
            SetName(markersNames, MarkerNames.chestAKA, ref m.chest, prefix);
            SetName(markersNames, MarkerNames.leftShoulderAKA, ref m.leftShoulder, prefix);
            SetName(markersNames, MarkerNames.rightShoulderAKA, ref m.rightShoulder, prefix);
            #endregion

            #region head
            quary = MarkerNames.headAKA.FirstOrDefault(n => markersNames.Contains(prefix + n));
            if (quary == null)
            {
                var q2 = MarkerNames.headBetween.FirstOrDefault(n => markersNames.Contains(prefix + n[0]) && markersNames.Contains(prefix + n[1]));
                if (q2 != null)
                {
                    frontHeadBetween = true;
                    frontHeadBetweenMarkers = new string[2];;
                    frontHeadBetweenMarkers[0] = prefix + q2[0];
                    frontHeadBetweenMarkers[1] = prefix + q2[1];
                }
            } else m.head = prefix + quary;

            SetName(markersNames, MarkerNames.leftHeadAKA, ref m.leftHead, prefix);

            SetName(markersNames, MarkerNames.rightHeadAKA, ref m.rightHead, prefix);
            #endregion

            #region legs

            SetName(markersNames, MarkerNames.leftUpperKneeAKA, ref m.leftUpperKnee, prefix);
            SetName(markersNames, MarkerNames.rightUpperKneeAKA, ref m.rightUpperKnee, prefix);
            SetName(markersNames, MarkerNames.leftOuterKneeAKA, ref m.leftOuterKnee, prefix);
            SetName(markersNames, MarkerNames.rightOuterKneeAKA, ref m.rightOuterKnee, prefix);
            SetName(markersNames, MarkerNames.leftInnerKneeAKA, ref m.leftInnerKnee, prefix);
            SetName(markersNames, MarkerNames.rightInnerKneeAKA, ref m.rightInnerKnee, prefix);
            SetName(markersNames, MarkerNames.leftLowerKneeAKA, ref m.leftLowerKnee, prefix);
            SetName(markersNames, MarkerNames.rightLowerKneeAKA, ref m.rightLowerKnee, prefix);
            #endregion

            #region foot
            SetName(markersNames, MarkerNames.leftOuterAnkleAKA, ref m.leftOuterAnkle, prefix);
            SetName(markersNames, MarkerNames.rightOuterAnkleAKA, ref m.rightOuterAnkle, prefix);
            SetName(markersNames, MarkerNames.rightInnerAnkleAKA, ref m.rightInnerAnkle, prefix);
            SetName(markersNames, MarkerNames.leftInnerAnkleAKA, ref m.leftInnerAnkle, prefix);

            SetName(markersNames, MarkerNames.leftHeelAKA, ref m.leftHeel, prefix);
            SetName(markersNames, MarkerNames.rightHeelAKA, ref m.rightHeel, prefix);

            quary = MarkerNames.leftToe2AKA.FirstOrDefault(n => markersNames.Contains(prefix + n));
            if (quary == null)
            {
                quary = MarkerNames.leftToe1AKA.FirstOrDefault(n => markersNames.Contains(prefix + n));
            }
            m.leftToe2 = ((quary == null) ? m.leftToe2 :prefix + quary);

            quary = MarkerNames.rightToe2AKA.FirstOrDefault(n => markersNames.Contains(prefix + n));
            if (quary == null)
            {
                quary = MarkerNames.rightToe1AKA.FirstOrDefault(n => markersNames.Contains(prefix + n));
            }
            m.rightToe2 = ((quary == null) ? m.rightToe2 :prefix + quary);
            #endregion

            #region arms
            SetName(markersNames, MarkerNames.leftElbowAKA, ref m.leftElbow, prefix);
            SetName(markersNames, MarkerNames.rightElbowAKA, ref m.rightElbow, prefix);
            SetName(markersNames, MarkerNames.leftInnerElbowAKA, ref m.leftInnerElbow, prefix);
            SetName(markersNames, MarkerNames.rightInnerElbowAKA, ref m.rightInnerElbow, prefix);
            SetName(markersNames, MarkerNames.leftOuterElbowAKA, ref m.leftOuterElbow, prefix);
            SetName(markersNames, MarkerNames.rightOuterElbowAKA, ref m.rightOuterElbow, prefix);
            SetName(markersNames, MarkerNames.leftWristAKA, ref m.leftWrist, prefix);
            SetName(markersNames, MarkerNames.rightWristAKA, ref m.rightWrist, prefix);
            SetName(markersNames, MarkerNames.leftWristRadiusAKA, ref m.leftWristRadius, prefix);
            SetName(markersNames, MarkerNames.rightWristRadiusAKA, ref m.rightWristRadius, prefix);
            #endregion

            #region hands
            SetName(markersNames, MarkerNames.leftHandAKA, ref m.leftHand, prefix);
            SetName(markersNames, MarkerNames.rightHandAKA, ref m.rightHand, prefix);
            SetName(markersNames, MarkerNames.rightIndexAKA, ref m.rightIndex, prefix);
            SetName(markersNames, MarkerNames.leftIndexAKA, ref m.leftIndex, prefix);
            SetName(markersNames, MarkerNames.rightThumbAKA, ref m.rightThumb, prefix);
            SetName(markersNames, MarkerNames.leftThumbAKA, ref m.leftThumb, prefix);
            #endregion
            return m;
        }