Beispiel #1
0
        /**
         * Updates HandRepresentations based in the specified HandRepresentation Dictionary.
         * Active HandRepresentation instances are updated if the hand they represent is still
         * present in the Provider's CurrentFrame; otherwise, the HandRepresentation is removed. If new
         * Leap Hand objects are present in the Leap HandRepresentation Dictionary, new HandRepresentations are
         * created and added to the dictionary.
         * @param all_hand_reps = A dictionary of Leap Hand ID's with a paired HandRepresentation
         * @param modelType Filters for a type of hand model, for example, physics or graphics hands.
         * @param frame The Leap Frame containing Leap Hand data for each currently tracked hand
         */
        void UpdateHandRepresentations(Dictionary <int, HandRepresentation> all_hand_reps, ModelType modelType, Frame frame)
        {
            foreach (Leap.Hand curHand in frame.Hands)
            {
                // Skip disabled hands
                if (curHand.IsLeft && !enableLeft)
                {
                    continue;
                }
                if (curHand.IsRight && !enableRight)
                {
                    continue;
                }

                HandRepresentation rep;
                if (!all_hand_reps.TryGetValue(curHand.Id, out rep))
                {
                    rep = Factory.MakeHandRepresentation(curHand, modelType);
                    if (rep != null)
                    {
                        all_hand_reps.Add(curHand.Id, rep);
                    }
                }
                if (rep != null)
                {
                    rep.IsMarked = true;
                    rep.UpdateRepresentation(curHand, modelType);
                    rep.LastUpdatedTime = (int)frame.Timestamp;
                }
            }

            /** Mark-and-sweep to finish unused HandRepresentations */
            HandRepresentation toBeDeleted = null;

            foreach (KeyValuePair <int, HandRepresentation> r in all_hand_reps)
            {
                if (r.Value != null)
                {
                    if (r.Value.IsMarked)
                    {
                        r.Value.IsMarked = false;
                    }
                    else
                    {
                        /** Initialize toBeDeleted with a value to be deleted */
                        //Debug.Log("Finishing");
                        toBeDeleted = r.Value;
                    }
                }
            }

            /**Inform the representation that we will no longer be giving it any hand updates
             * because the corresponding hand has gone away */
            if (toBeDeleted != null)
            {
                all_hand_reps.Remove(toBeDeleted.HandID);
                toBeDeleted.Finish();
            }
        }
Beispiel #2
0
        //Felix
        void UpdateHandRepresentations(List <Hand> list, Dictionary <int, HandRepresentation> all_hand_reps, ModelType modelType)
        {
            foreach (Leap.Hand curHand in list)
            {
                HandRepresentation rep;
                if (!all_hand_reps.TryGetValue(curHand.Id, out rep))
                {
                    rep = factory.MakeHandRepresentation(curHand, modelType);
                    if (rep != null)
                    {
                        all_hand_reps.Add(curHand.Id, rep);
                        //float hand_scale = curHand.PalmWidth / rep.handModel.handModelPalmWidth;
                        //rep.handModel.transform.localScale = hand_scale * Vector3.one;
                    }
                }
                if (rep != null)
                {
                    rep.IsMarked = true;
                    //float hand_scale = curHand.PalmWidth / rep.handModel.handModelPalmWidth;
                    //rep.handModel.transform.localScale = hand_scale * Vector3.one;
                    rep.UpdateRepresentation(curHand);
                    rep.LastUpdatedTime = (int)provider.CurrentFrame.Timestamp;
                }
            }

            //Mark-and-sweep or set difference implementation
            HandRepresentation toBeDeleted = null;

            foreach (KeyValuePair <int, HandRepresentation> r in all_hand_reps)
            {
                if (r.Value != null)
                {
                    if (r.Value.IsMarked)
                    {
                        //Debug.Log("LeapHandController Marking False");
                        r.Value.IsMarked = false;
                    }
                    else
                    {
                        //Initialize toBeDeleted with a value to be deleted
                        //Debug.Log("Finishing");
                        toBeDeleted = r.Value;
                    }
                }
            }
            //Inform the representation that we will no longer be giving it any hand updates
            //because the corresponding hand has gone away
            if (toBeDeleted != null)
            {
                all_hand_reps.Remove(toBeDeleted.HandID);
                toBeDeleted.Finish();
            }
        }
        /**
         * Updates HandRepresentations based in the specified HandRepresentation Dictionary.
         * Active HandRepresentation instances are updated if the hand they represent is still
         * present in the Provider's CurrentFrame; otherwise, the HandRepresentation is removed. If new
         * Leap Hand objects are present in the Leap HandRepresentation Dictionary, new HandRepresentations are
         * created and added to the dictionary.
         * @param all_hand_reps = A dictionary of Leap Hand ID's with a paired HandRepresentation
         * @param modelType Filters for a type of hand model, for example, physics or graphics hands.
         * @param frame The Leap Frame containing Leap Hand data for each currently tracked hand
         */
        protected virtual void UpdateHandRepresentations(Dictionary <int, HandRepresentation> all_hand_reps, ModelType modelType, Frame frame)
        {
            for (int i = 0; i < frame.Hands.Count; i++)
            {
                var curHand = frame.Hands[i];
                HandRepresentation rep;
                if (!all_hand_reps.TryGetValue(curHand.Id, out rep))
                {
                    rep = pool.MakeHandRepresentation(curHand, modelType);
                    if (rep != null)
                    {
                        all_hand_reps.Add(curHand.Id, rep);
                    }
                }
                if (rep != null)
                {
                    rep.IsMarked = true;
                    rep.UpdateRepresentation(curHand);
                    rep.LastUpdatedTime = (int)frame.Timestamp;
                }
            }

            /** Mark-and-sweep to finish unused HandRepresentations */
            HandRepresentation toBeDeleted = null;

            for (var it = all_hand_reps.GetEnumerator(); it.MoveNext();)
            {
                var r = it.Current;
                if (r.Value != null)
                {
                    if (r.Value.IsMarked)
                    {
                        r.Value.IsMarked = false;
                    }
                    else
                    {
                        /** Initialize toBeDeleted with a value to be deleted */
                        //Debug.Log("Finishing");
                        toBeDeleted = r.Value;
                    }
                }
            }

            /**Inform the representation that we will no longer be giving it any hand updates
             * because the corresponding hand has gone away */
            if (toBeDeleted != null)
            {
                all_hand_reps.Remove(toBeDeleted.HandID);
                toBeDeleted.Finish();
            }
        }
        //Felix
        void UpdateHandRepresentations(List <Hand> list, Dictionary <int, HandRepresentation> all_hand_reps, ModelType modelType)
        {
            foreach (Leap.Hand curHand in list)
            {
                HandRepresentation rep;
                if (!all_hand_reps.TryGetValue(curHand.Id, out rep))
                {
                    rep = Factory.MakeHandRepresentation(curHand, modelType);
                    if (rep != null)
                    {
                        all_hand_reps.Add(curHand.Id, rep);
                    }
                }
                if (rep != null)
                {
                    rep.IsMarked = true;
                    rep.UpdateRepresentation(curHand);
                    rep.LastUpdatedTime = (int)Provider.CurrentFrame.Timestamp;
                }
            }

            //Mark-and-sweep or set difference implementation
            HandRepresentation toBeDeleted = null;

            foreach (KeyValuePair <int, HandRepresentation> r in all_hand_reps)
            {
                if (r.Value != null)
                {
                    if (r.Value.IsMarked)
                    {
                        r.Value.IsMarked = false;
                    }
                    else
                    {
                        toBeDeleted = r.Value;
                    }
                }
            }
            //Inform the representation that we will no longer be giving it any hand updates
            //because the corresponding hand has gone away
            if (toBeDeleted != null)
            {
                all_hand_reps.Remove(toBeDeleted.HandID);
                toBeDeleted.Finish();
            }
        }
Beispiel #5
0
        /**
         * Updates HandRepresentations based in the specified HandRepresentation Dictionary.
         * Active HandRepresentation instances are updated if the hand they represent is still
         * present in the Provider's CurrentFrame; otherwise, the HandRepresentation is removed. If new
         * Leap Hand objects are present in the Leap HandRepresentation Dictionary, new HandRepresentations are
         * created and added to the dictionary.
         * @param all_hand_reps = A dictionary of Leap Hand ID's with a paired HandRepresentation
         * @param modelType Filters for a type of hand model, for example, physics or graphics hands.
         * @param frame The Leap Frame containing Leap Hand data for each currently tracked hand
         */
        protected virtual void UpdateHandRepresentations(Dictionary <int, HandRepresentation> all_hand_reps, ModelType modelType, Frame frame)
        {
            //------------------------------------------------------------------------------
            //Local Hands  -- Unremote
            if (!IsRemoteServer)
            {
                foreach (Leap.Hand curHand in frame.Hands)
                {
                    HandRepresentation rep;
                    if (!all_hand_reps.TryGetValue(curHand.Id, out rep))
                    {
                        rep = factory.MakeHandRepresentation(curHand, modelType, false);
                        if (rep != null)
                        {
                            all_hand_reps.Add(curHand.Id, rep);
                        }
                    }
                    if (rep != null)
                    {
                        rep.IsMarked = true;
                        rep.UpdateRepresentation(curHand);
                        rep.LastUpdatedTime = (int)frame.Timestamp;
                    }
                }
            }

            //------------------------------------------------------------------------------
            // Remote Hands -- remote
            else
            {
                foreach (Leap.Hand curHand in remoteHandServer.RemoteFrame.Hands)
                {
                    HandRepresentation rep;
                    if (!all_hand_reps.TryGetValue(curHand.Id, out rep))
                    {
                        rep = factory.MakeHandRepresentation(curHand, modelType, true);
                        if (rep != null)
                        {
                            all_hand_reps.Add(curHand.Id, rep);
                        }
                    }
                    if (rep != null)
                    {
                        rep.IsMarked = true;
                        rep.UpdateRepresentation(curHand);
                        rep.LastUpdatedTime = (int)frame.Timestamp;
                    }
                }
            }

            //------------------------------------------------------------------------------

            /** Mark-and-sweep to finish unused HandRepresentations */
            HandRepresentation toBeDeleted = null;

            foreach (KeyValuePair <int, HandRepresentation> r in all_hand_reps)
            {
                if (r.Value != null)
                {
                    if (r.Value.IsMarked)
                    {
                        r.Value.IsMarked = false;
                    }
                    else
                    {
                        /** Initialize toBeDeleted with a value to be deleted */
                        //Debug.Log("Finishing");
                        toBeDeleted = r.Value;
                    }
                }
            }

            /**Inform the representation that we will no longer be giving it any hand updates
             * because the corresponding hand has gone away */
            if (toBeDeleted != null)
            {
                all_hand_reps.Remove(toBeDeleted.HandID);
                toBeDeleted.Finish();
            }

            // Fixe ModelPool
        }