Ejemplo n.º 1
0
        private void AddUserTouchEvents(User user)
        {
            //Need to lock. If the user is lost, you don't want that the user is getting set to null during adding of events
            lock (_syncRoot)
            {
                if (ConfigurationViewModel.EnableNextSlide)
                {
                    _nextSlideSelfTouch = user.AddSelfTouchGesture(ConfigurationViewModel.NextSlideCorrection,
                                                                   ConfigurationViewModel.NextSlide1,
                                                                   ConfigurationViewModel.NextSlide2);
                    _nextSlideSelfTouch.SelfTouchDetected +=
                        ((s, evt) =>
                             {
                                 if (CheckEventInterval())
                                 {
                                     _log.DebugFormat("Next Slide \tUser:{0}", evt.UserID);
                                     OnNextSlide(evt.UserID);
                                 }
                             });
                    _log.DebugFormat("Added NextSlideEvent\tUser:{0}\tCorrection:{1}\t({2} on {3})", user.Id,
                                     ConfigurationViewModel.NextSlideCorrection.GetDebugString(),
                                     ConfigurationViewModel.NextSlide1, ConfigurationViewModel.NextSlide2);
                }

                if (ConfigurationViewModel.EnablePreviousSlide)
                {
                    _previousSlideSelfTouch = user.AddSelfTouchGesture(ConfigurationViewModel.PreviousSlideCorrection,
                                                                       ConfigurationViewModel.PreviousSlide1,
                                                                       ConfigurationViewModel.PreviousSlide2);
                    _previousSlideSelfTouch.SelfTouchDetected +=
                        ((s, evt) =>
                             {
                                 if (CheckEventInterval())
                                 {
                                     _log.DebugFormat("Previous Slide \tUser:{0}", evt.UserID);
                                     OnPreviousSlide(evt.UserID);
                                 }
                             });
                    _log.DebugFormat("Added PreviousSlideEvent\tUser:{0}\tCorrection:{1}\t({2} on {3})", user.Id,
                                     ConfigurationViewModel.PreviousSlideCorrection.GetDebugString(),
                                     ConfigurationViewModel.PreviousSlide1, ConfigurationViewModel.PreviousSlide2);
                }

                if (ConfigurationViewModel.EnableTogglePointer)
                {
                    _togglePointerSelfTouch = user.AddSelfTouchGesture(ConfigurationViewModel.TogglePointerCorrection,
                                                                       ConfigurationViewModel.TogglePointer1,
                                                                       ConfigurationViewModel.TogglePointer2);
                    _togglePointerSelfTouch.SelfTouchDetected +=
                        ((s, evt) =>
                             {
                                 if (CheckEventInterval())
                                 {
                                     _log.DebugFormat("TogglePointer \tUser:{0}", evt.UserID);
                                     OnTogglePointer(evt.UserID);
                                 }
                             });
                    _log.DebugFormat("Added TogglePointerEvent\tUser:{0}\tCorrection:{1}\t({2} on {3})", user.Id,
                                     ConfigurationViewModel.TogglePointerCorrection.GetDebugString(),
                                     ConfigurationViewModel.TogglePointer1, ConfigurationViewModel.TogglePointer2);
                }
            }
        }
Ejemplo n.º 2
0
        public static SelfTouchGesture AddSelfTouchGesture(this User user, Point3D correction, params JointID[] joints)
        {
            if (joints.Length < 2)
            {
                throw new ArgumentException("At least 2 joints are expected for a SelfTouchGesture", "joints");
            }

            XDocument xmlDoc = XDocument.Load(GestureXmlFiles.GesturesXmlFile);
            IEnumerable<XElement> selfTouchGestureNodes = xmlDoc.Root.Descendants("SelfTouchGesture");

            var selfTouchGestures = new List<SelfTouchGesture>(selfTouchGestureNodes.Count());
            SelfTouchGesture selfTouchGesture = null;
            List<Filter<IUserChangedEvent>> filters;

            foreach (XElement node in selfTouchGestureNodes)
            {
                if (!Convert.ToBoolean(node.Attribute(XName.Get("Active")).Value))
                {
                    continue;
                }

                if (!AreJointsMatching(node.Element(XName.Get("PointsToCheck")), joints))
                {
                    continue;
                }

                filters = GetFilters(node.Element(XName.Get("Filters")), joints);
                if (filters == null || filters.Count == 0)
                {
                    filters = GetStandardSelfTouchFilters(joints);
                }

                for (int i = 0; i < filters.Count; i++)
                {
                    if (i == 0)
                    {
                        user.AttachPipeline(filters[i]);
                    }
                    else
                    {
                        filters[i - 1].AttachPipeline(filters[i]);
                    }

                    var correctionFilter = filters[i] as CorrectionFilter;
                    if (correctionFilter != null && joints[1].Equals(correctionFilter.JointToCorrect))
                    {
                        correctionFilter.Correction = correction;
                    }
                }

                int historyCount = 10;
                string history = node.Attribute(XName.Get("History")).Value;
                int.TryParse(history, out historyCount);
                selfTouchGesture = new SelfTouchGesture
                                       {
                                           HistoryCount = historyCount,
                                           Joints = joints
                                       };

                filters[filters.Count - 1].AttachPipeline(selfTouchGesture);
            }

            if (selfTouchGesture == null)
            {
                var sb = new StringBuilder();
                sb.Append("No SelfTouch configuration in \"");
                sb.Append(GestureXmlFiles.GesturesXmlFile);
                sb.Append("\" found for joints: ");

                for (int i = 0; i < joints.Length; i++)
                {
                    sb.Append("{"+i+"}");
                }
                _log.IfErrorFormat(sb.ToString(), joints);
                throw new NullReferenceException(string.Format(sb.ToString(), joints));
            }

            return selfTouchGesture;
        }
Ejemplo n.º 3
0
        private void KinectUserCreated(object sender, KinectUserEventArgs e)
        {
            WindowMessage = "User found";
            lock (SyncRoot)
            {
                if (_activeUser != null)
                {
                    return;
                }
                _activeUser = _kinect.GetUser(e.User.Id);
                _activeUser.Updated += ActiveUserUpdated;

                var framesFilter = new FramesFilter(15);

                //Initialize filters
                _lefthandRighthandCollision = new CollisionFilter(new Point3D(100, 50, 130), JointID.HandLeft, JointID.HandRight);
                _lefthandHeadCollision = new CollisionFilter(new Point3D(150, 30, 500), JointID.HandLeft, JointID.Head);
                _lefthandRightShoulderCollision = new CollisionFilter(new Point3D(50, 50, 300), JointID.HandLeft, JointID.ShoulderRight);
                _righthandHeadCollision = new CollisionFilter(new Point3D(125, 40, 150), JointID.HandRight, JointID.Head);
                _righthandLeftShoulderCollision = new CollisionFilter(new Point3D(50, 50, 300), JointID.HandRight, JointID.ShoulderLeft);
                _righthandRightHipCollision = new CollisionFilter(new Point3D(80, 30, 200), JointID.HandRight, JointID.HipRight);

                //Initialize gestures
                _lefthandRighthandGesture = new SelfTouchGesture(1);
                _lefthandHeadGesture = new SelfTouchGesture(1);
                _lefthandRightShoulderGesture = new SelfTouchGesture(1);
                _righthandHeadGesture = new SelfTouchGesture(1);
                _righthandLeftShoulderGesture = new SelfTouchGesture(1);
                _righthandRightHipGesture = new SelfTouchGesture(1);

                //Attach filters and gestures
                _activeUser.AttachPipeline(framesFilter);
                framesFilter.AttachPipeline(_lefthandRighthandCollision);
                framesFilter.AttachPipeline(_lefthandHeadCollision);
                framesFilter.AttachPipeline(_lefthandRightShoulderCollision);
                framesFilter.AttachPipeline(_righthandHeadCollision);
                framesFilter.AttachPipeline(_righthandLeftShoulderCollision);
                framesFilter.AttachPipeline(_righthandRightHipCollision);
                _lefthandRighthandCollision.AttachPipeline(_lefthandRighthandGesture);
                _lefthandHeadCollision.AttachPipeline(_lefthandHeadGesture);
                _lefthandRightShoulderCollision.AttachPipeline(_lefthandRightShoulderGesture);
                _righthandHeadCollision.AttachPipeline(_righthandHeadGesture);
                _righthandLeftShoulderCollision.AttachPipeline(_righthandLeftShoulderGesture);
                _righthandRightHipCollision.AttachPipeline(_righthandRightHipGesture);

                _righthandLeftShoulderGesture.SelfTouchDetected += SwitchMode;

                //Debug info
                //_righthandLeftShoulderCollision.Filtered += (s, args) => ShowDebugInfo(args, "Filter info: ");
                _lefthandRightShoulderGesture.SelfTouchDetected += FireCustomEvent;
                SwitchMode(null, null);
            }
        }
Ejemplo n.º 4
0
        public static List<SelfTouchGesture> AddSelfTouchGestures(this User user)
        {
            XDocument xmlDoc = XDocument.Load(GestureXmlFiles.GesturesXmlFile);
            IEnumerable<XElement> selfTouchGestureNodes = xmlDoc.Root.Descendants("SelfTouchGesture");

            var selfTouchGestures = new List<SelfTouchGesture>(selfTouchGestureNodes.Count());
            foreach (XElement node in selfTouchGestureNodes)
            {
                if (!Convert.ToBoolean(node.Attribute(XName.Get("Active")).Value))
                {
                    continue;
                }

                JointID[] joints = null;
                joints = GetJoints(node.Element(XName.Get("PointsToCheck"))).ToArray();

                if (joints != null)
                {
                    List<Filter<IUserChangedEvent>> filters;
                    filters = GetFilters(node.Element(XName.Get("Filters")), joints);

                    for (int i = 0; i < filters.Count; i++)
                    {
                        if (i == 0)
                        {
                            user.AttachPipeline(filters[i]);
                        }
                        else
                        {
                            filters[i - 1].AttachPipeline(filters[i]);
                        }
                    }

                    SelfTouchGesture gesture = null;
                    int historyCount;
                    string history = node.Attribute(XName.Get("History")).Value;

                    if (int.TryParse(history, out historyCount))
                    {
                        gesture = new SelfTouchGesture {HistoryCount = historyCount, Joints = joints};
                    }
                    else
                    {
                        gesture = new SelfTouchGesture {HistoryCount = 10, Joints = joints};
                    }

                    filters[filters.Count - 1].AttachPipeline(gesture);
                    selfTouchGestures.Add(gesture);
                }
            }

            return selfTouchGestures;
        }