/// an internal method to initialize the internal structures
    /// @note in most cases, inheriting methods should NOT override the base InitTracking but
    /// rather override this method.
    /// @return true on success and false otherwise.
    protected override bool InitInternalStructures()
    {
        if (m_context == null || m_context.Valid == false)
        {
            return(false); // we need hands for this...
        }
        m_handsManager = FindObjectOfType(typeof(NITEHandsManager)) as NITEHandsManager;
        if (m_handsManager == null || m_handsManager.ValidWithInit == false)
        {
            throw new System.Exception("There is no NITEHandsManager in the scene!");
        }
        // need to make sure we don't get errors in initialization
        try
        {
            NINITECheckVersion.Instance.ValidatePrerequisite();
            // set up the raw control point (to get raw data)
            m_pointControlRaw = new PointControl();
            m_handsManager.Hands.SessionManager.AddListener(m_pointControlRaw);

            // set up the denoiser filter
            m_pointControlSmoothFilter = new PointDenoiser();
            m_handsManager.Hands.SessionManager.AddListener(m_pointControlSmoothFilter);
            // set up the smoothed control point (to get smoothed data).
            m_pointControlSmooth = new PointControl();
            m_pointControlSmoothFilter.AddListener(m_pointControlSmooth);

            // register the relevant callbacks
            m_pointControlRaw.PrimaryPointUpdate    += new System.EventHandler <HandEventArgs>(myControl_PrimaryPointUpdate);
            m_pointControlRaw.PrimaryPointCreate    += new System.EventHandler <HandFocusEventArgs>(myControl_PrimaryPointCreate);
            m_pointControlRaw.PrimaryPointDestroy   += new System.EventHandler <IdEventArgs>(myControl_PrimaryPointDestroy);
            m_pointControlSmooth.PrimaryPointUpdate += new System.EventHandler <HandEventArgs>(myControl_PrimaryPointUpdateSmooth);
        }
        catch (System.Exception ex)
        {
            Debug.Log("failed to initialize. Error=" + ex.Message);
            StopTracking();
            return(false);
        }
        m_lastFrameCurPoint    = new NIPositionTrackerFrameManager();
        m_lastFrameCurPointRaw = new NIPositionTrackerFrameManager();
        return(true);
    }
        private void CreateAndRun()
        {
            m_context        = new Context(@"data\openNI.xml");
            m_imageGenerator = new ImageGenerator(m_context);
            m_depthGenerator = new DepthGenerator(m_context);

            SessionManager sessionManager = new SessionManager(m_context, "Wave", "RaiseHand");

            // update the state
            Dispatcher.BeginInvoke(() => { State = SessionState.Idle; });

            sessionManager.SessionStart += SessionManager_SessionStart;
            sessionManager.SessionEnd   += SessionManager_SessionEnd;

            PointControl pointControl = new PointControl();

            pointControl.PrimaryPointCreate  += PointControl_PrimaryPointCreate;
            pointControl.PrimaryPointDestroy += PointControl_PrimaryPointDestroy;
            pointControl.PrimaryPointUpdate  += PointControl_PrimaryPointUpdate;

            SwipeDetector swipeDetector = new SwipeDetector();

            swipeDetector.UseSteady   = true;
            swipeDetector.SwipeLeft  += SwipeDetector_SwipeLeft;
            swipeDetector.SwipeRight += SwipeDetector_SwipeRight;

            PointDenoiser denoiser = new PointDenoiser();

            denoiser.AddListener(pointControl);
            denoiser.AddListener(swipeDetector);
            sessionManager.AddListener(denoiser);

            while (m_running)
            {
                m_context.WaitAndUpdateAll();
                sessionManager.Update(m_context);
            }
        }
Example #3
0
    void Start()
    {
        InitializeCharacter ();
        context = new Context (XML_SETUP_FILE);
        sessionManager = new SessionManager(context, "Wave", "RaiseHand");
        depthGenerator = context.FindExistingNode(NodeType.Depth) as DepthGenerator;
        handsGenerator = context.FindExistingNode(NodeType.Hands) as HandsGenerator;

        //image = context.FindExistingNode(NodeType.Image) as ImageGenerator;
        //gesture = context.FindExistingNode(NodeType.Gesture) as GestureGenerator;
        if (depthGenerator == null) throw new Exception("Viewer must have a depth node!");
        //if (gesture == null) throw new Exception("Viewer must have a gesture node!");
        //if (image == null) throw new Exception("Viewer must have a image node!");

        userGenerator = new UserGenerator (context);
        skeletonCapability = userGenerator.SkeletonCapability;
        poseDetectionCapability = userGenerator.PoseDetectionCapability;
        calibPose = skeletonCapability.CalibrationPose;
        //gestureGenerator = new GestureGenerator(context);

        foreach (String s in poseDetectionCapability.GetAllAvailablePoses())
            Debug.LogWarning("available pose found: " +s);

        //foreach (String s in gestureGenerator.EnumerateAllGestures())
        //	Debug.LogWarning("available gesture found: " + s);

        //gestureGenerator.GestureRecognized += HandleGestureGestureRecognized;
        //gesture.AddGesture("Click");
        //gestureGenerator.AddGesture("RaiseHand"); //seems buggy
        //gestureGenerator.AddGesture("Wave");

        swipeDetector = new SwipeDetector();
        //steadyDetector = new SteadyDetector();//(3, 1f);

        //swipeDetector.SwipeLeft += HandleSwipeDetectorSwipeLeft;

        //Session Managment
        sessionManager.SessionStart += HandleSessionManagerSessionStart;
        sessionManager.SessionEnd += HandleSessionManagerSessionEnd;

        //User Generator
        userGenerator.NewUser += HandleUserGeneratorNewUser;
        userGenerator.LostUser += HandleUserGeneratorLostUser;
        poseDetectionCapability.PoseDetected += HandlePoseDetectionCapabilityPoseDetected;
        skeletonCapability.CalibrationEnd += HandleSkeletonCapabilityCalibrationEnd;

        skeletonCapability.SetSkeletonProfile (SkeletonProfile.All);
        skeletonCapability.SetSmoothing(.5f); // give us some smooothing

        //Start generating
        userGenerator.StartGenerating();
        //handsGenerator.MirrorCapability.SetMirror(true); // TODO: should this be true?
        handsGenerator.StartGenerating();
        //gestureGenerator.StartGenerating();

        //slider selector
        //selectableSlider2D = new SelectableSlider2D(Screen.width, Screen.height);
        //selectableSlider2D.ValueChange += HandleSelectableSlider2DValueChange;
        //selectableSlider2D.ItemHover += HandleSelectableSlider2DItemHover;
        //selectableSlider2D.ItemSelect += HandleSelectableSlider2DItemSelect;

        pointDenoiser = new PointDenoiser();
        pointDenoiser.AddListener(swipeDetector);
        //pointDenoiser.AddListener(steadyDetector);
        //pointDenoiser.AddListener(selectableSlider2D);

        //flowRouter = new FlowRouter();
        //flowRouter.ActiveListener = pointDenoiser;

        sessionManager.AddListener(pointDenoiser);

        MapOutputMode mapMode = depthGenerator.MapOutputMode;

        // Init depth & label map related stuff
        usersMapSize = mapMode.XRes * mapMode.YRes;
        //usersLabelTexture = new Texture2D(mapMode.XRes, mapMode.YRes); //nonPOT slow
        usersLabelTexture = new Texture2D(1024,512);
        //speed up by using power of two and then setpixel() with blockwidth (640) and blockheight (480)
        usersMapColors = new Color[usersMapSize];
        usersMapRect = new Rect(Screen.width - usersLabelTexture.width / 2, Screen.height - usersLabelTexture.height / 2, usersLabelTexture.width / 2, usersLabelTexture.height / 2);
        usersLabelMap = new short[usersMapSize];
        usersDepthMap = new short[usersMapSize];
        usersHistogramMap = new float[5000];

        this.shouldRun = true;

        if (NiteInitializingEvent != null) //notify others that we're done initializing
            NiteInitializingEvent(this, EventArgs.Empty);
    }
Example #4
0
        private void CreateAndRun()
        {
            m_context = new Context(@"data\openNI.xml");
            m_imageGenerator = new ImageGenerator(m_context);
            m_depthGenerator = new DepthGenerator(m_context);

            SessionManager sessionManager = new SessionManager(m_context, "Wave", "RaiseHand");

            // update the state
            Dispatcher.BeginInvoke(() => { State = SessionState.Idle; });

            sessionManager.SessionStart += SessionManager_SessionStart;
            sessionManager.SessionEnd += SessionManager_SessionEnd;

            PointControl pointControl = new PointControl();
            pointControl.PrimaryPointCreate += PointControl_PrimaryPointCreate;
            pointControl.PrimaryPointDestroy += PointControl_PrimaryPointDestroy;
            pointControl.PrimaryPointUpdate += PointControl_PrimaryPointUpdate;

            SwipeDetector swipeDetector = new SwipeDetector();
            swipeDetector.UseSteady = true;
            swipeDetector.SwipeLeft += SwipeDetector_SwipeLeft;
            swipeDetector.SwipeRight += SwipeDetector_SwipeRight;

            PointDenoiser denoiser = new PointDenoiser();
            denoiser.AddListener(pointControl);
            denoiser.AddListener(swipeDetector);
            sessionManager.AddListener(denoiser);

            while (m_running)
            {
                m_context.WaitAndUpdateAll();
                sessionManager.Update(m_context);
            }
        }