예제 #1
0
        void FState_Initialised(object sender, EventArgs e)
        {
            try
            {
                //initialise
                FUserGenerator              = new UserGenerator(FState.Context);
                FUserGenerator.NewUser     += new EventHandler <NewUserEventArgs>(FUserGenerator_NewUser);
                FUserGenerator.LostUser    += new EventHandler <UserLostEventArgs>(FUserGenerator_LostUser);
                FUserGenerator.UserReEnter += new EventHandler <UserReEnterEventArgs>(FUserGenerator_UserReEnter);
                FUserGenerator.UserExit    += new EventHandler <UserExitEventArgs>(FUserGenerator_UserExit);
                FUserGenerator.StartGenerating();

                FPinOutMask[0] = FImageMask.Link;
                FImageMask.Image.Initialise(new Size(640, 480), TColorFormat.L16);

                FState.Update += new EventHandler(FState_Update);

                FStarted         = true;
                FPinOutStatus[0] = "OK";
            }
            catch (StatusException err)
            {
                Close();
                FPinOutStatus[0] = err.Message;
            }
        }
예제 #2
0
        //called when data for any output pin is requested
        public void Evaluate(int SpreadMax)
        {
            if (FContextChanged)
            {
                if (FContextIn.PluginIO.IsConnected)
                {
                    if (FContextIn[0] != null)
                    {
                        try
                        {
                            // Creates the User Generator from the Context Object
                            FUserGenerator = new UserGenerator(FContextIn[0]);

                            //Set the resolution of the texture
                            FTexWidth  = FUserGenerator.GetUserPixels(0).FullXRes;
                            FTexHeight = FUserGenerator.GetUserPixels(0).FullYRes;

                            //Reinitalie the vvvv texture
                            Reinitialize();

                            FUserGenerator.StartGenerating();

                            FContextChanged = false;
                        }
                        catch (Exception ex)
                        {
                            FLogger.Log(ex);
                        }
                    }
                }
                else
                {
                    CleanUp();
                    FContextChanged = false;
                }
            }

            //create new texture if outputmode changed
            if (FOutputMode.IsChanged)
            {
                Reinitialize();
            }

            if (FUserGenerator != null)
            {
                if (FEnabledIn.IsChanged)
                {
                    if (FEnabledIn[0])
                    {
                        FUserGenerator.StartGenerating();
                    }
                    else
                    {
                        FUserGenerator.StopGenerating();
                    }
                }

                if (FUserGenerator.IsDataNew)
                {
                    FUserIdOut.SliceCount   = FUserGenerator.NumberOfUsers;
                    FPositionOut.SliceCount = FUserGenerator.NumberOfUsers;
                    FTextureOut.SliceCount  = 1;

                    if (FUserGenerator.NumberOfUsers > 0)
                    {
                        //copies a list of all users and sort them
                        int[] tUsers = FUserGenerator.GetUsers();
                        int[] Users  = (int[])tUsers.Clone();
                        Array.Sort(Users);

                        for (int i = 0; i < Users.Length; i++)
                        {
                            FUserIdOut[i] = Users[i];
                            try
                            {
                                //middle point of the User
                                Point3D  Point    = FUserGenerator.GetCoM(Users[i]);
                                Vector3D Position = new Vector3D(Point.X, Point.Y, Point.Z);

                                //map postion values to vvvv coordinates
                                FPositionOut[i] = Position / 1000;
                            }
                            catch (StatusException ex)
                            {
                                FLogger.Log(ex);
                            }
                        }
                    }

                    //update the vvvv texture
                    Update();
                }
            }
            else
            {
                FUserIdOut.SliceCount   = 0;
                FPositionOut.SliceCount = 0;
                FTextureOut.SliceCount  = 0;
            }
        }
예제 #3
0
        //called when data for any output pin is requested
        public void Evaluate(int SpreadMax)
        {
            if (FContextChanged)
            {
                if (FContextIn.PluginIO.IsConnected)
                {
                    if (FContextIn[0] != null)
                    {
                        try
                        {
                            FUserGenerator           = new UserGenerator(FContextIn[0]);
                            FSkeletonCapability      = FUserGenerator.SkeletonCapability;
                            FPoseDetectionCapability = FUserGenerator.PoseDetectionCapability;
                            FCalibPose = FSkeletonCapability.CalibrationPose;

                            FUserGenerator.NewUser  += userGenerator_NewUser;
                            FUserGenerator.LostUser += userGenerator_LostUser;
                            FPoseDetectionCapability.PoseDetected   += poseDetectionCapability_PoseDetected;
                            FSkeletonCapability.CalibrationComplete += skeletonCapbility_CalibrationComplete;

                            FSkeletonCapability.SetSkeletonProfile(FSkeletonProfileIn[0]);
                            FJoints = new Dictionary <int, Dictionary <SkeletonJoint, SkeletonJointTransformation> >();

                            FUserGenerator.StartGenerating();

                            FContextChanged = false;
                        }
                        catch (Exception ex)
                        {
                            FLogger.Log(ex);
                        }
                    }
                }
                else
                {
                    CleanUp();
                    FContextChanged = false;
                }
            }

            if (FUserGenerator != null)
            {
                if (FEnabledIn.IsChanged)
                {
                    if (FEnabledIn[0])
                    {
                        FUserGenerator.StartGenerating();
                    }
                    else
                    {
                        FUserGenerator.StopGenerating();
                    }
                }

                if (FUserGenerator.IsDataNew)
                {
                    if (FSkeletonProfileIn.IsChanged)
                    {
                        FSkeletonCapability.SetSkeletonProfile(FSkeletonProfileIn[0]);
                    }

                    if (FSmoothingIn.IsChanged)
                    {
                        FSkeletonCapability.SetSmoothing(FSmoothingIn[0]);
                    }

                    FUserIdOut.SliceCount            = FUserGenerator.NumberOfUsers;
                    FStatusOut.SliceCount            = FUserGenerator.NumberOfUsers;
                    FJointPositionOut.SliceCount     = FUserGenerator.NumberOfUsers;
                    FJointOrientationXOut.SliceCount = FUserGenerator.NumberOfUsers;
                    FJointOrientationYOut.SliceCount = FUserGenerator.NumberOfUsers;
                    FJointOrientationZOut.SliceCount = FUserGenerator.NumberOfUsers;

                    if (FUserGenerator.NumberOfUsers > 0)
                    {
                        //get all Users and sort them
                        int[] users = FUserGenerator.GetUsers();
                        Array.Sort(users);

                        int slice = 0;
                        foreach (int user in users)
                        {
                            FUserIdOut[slice] = user;
                            if (FSkeletonCapability.IsTracking(user))
                            {
                                FStatusOut[slice] = "Tracking user " + user;

                                int u       = user - 1;
                                int binSize = FJointIn[u].SliceCount;
                                FJointPositionOut[u].SliceCount     = binSize;
                                FJointOrientationXOut[u].SliceCount = FJointOrientationYOut[u].SliceCount = FJointOrientationZOut[u].SliceCount = binSize;
                                for (int i = 0; i < binSize; i++)
                                {
                                    var j = GetJoint(user, FJointIn[u][i]);

                                    var p = j.Position.Position;
                                    if (j.Position.Confidence > 0.5)
                                    {
                                        FJointPositionOut[u][i] = new Vector3D(p.X, p.Y, p.Z) / 1000;
                                    }

                                    var o = j.Orientation;
                                    if (o.Confidence > FConfidenceIn[slice])
                                    {
                                        FJointOrientationXOut[u][i] = new Vector3D(o.X1, o.Y1, o.Z1);
                                        FJointOrientationYOut[u][i] = new Vector3D(o.X2, o.Y2, o.Z2);
                                        FJointOrientationZOut[u][i] = new Vector3D(o.X3, o.Y3, o.Z3);
                                    }
                                }
                            }
                            else if (FSkeletonCapability.IsCalibrating(user))
                            {
                                FStatusOut[slice] = "Calibrating user " + user;
                            }
                            else
                            {
                                FStatusOut[slice] = "Looking for pose on user " + user;
                            }

                            slice++;
                        }
                    }
                }
            }
            else
            {
                FUserIdOut.SliceCount            = 0;
                FStatusOut.SliceCount            = 0;
                FJointPositionOut.SliceCount     = 0;
                FJointOrientationXOut.SliceCount = 0;
                FJointOrientationYOut.SliceCount = 0;
                FJointOrientationZOut.SliceCount = 0;
            }
        }