Example #1
0
        private SpacePointBase ScaleTo(double width, double height, float mapMaxX, float mapMaxY)
        {
            float scaledX = X * (float)width / mapMaxX;

            if (scaledX < 0)
            {
                scaledX = 0;
            }
            else if (scaledX > width)
            {
                scaledX = (float)width;
            }

            float scaledY = Y * (float)height / mapMaxY;

            if (scaledY < 0)
            {
                scaledY = 0;
            }
            else if (scaledY > height)
            {
                scaledY = (float)height;
            }


            SpacePointBase scaledPt = new SpacePointBase(scaledX, scaledY, _pointType);

            return(scaledPt);
        }
Example #2
0
        public static Shape DrawPoint(this Canvas canvas, Joint joint, CoordinateMapper mapper, SpaceMode mode, Brush brush)
        {
            Shape shapeToReturn = null;

            // 0) Check whether the joint is tracked.
            if (joint.TrackingState == TrackingState.NotTracked)
            {
                return(null);
            }

            SpacePointBase spPt;

            switch (mode)
            {
            case SpaceMode.Color:
            default:
                // 1a) Convert Joint positions to Color space coordinates.
                ColorSpacePoint colSpaceJoint = mapper.MapCameraPointToColorSpace(joint.Position);
                spPt = new SpacePointBase(colSpaceJoint);

                break;

            case SpaceMode.Depth:
                // 1b) Convert Joint positions to Depth space coordinates.
                DepthSpacePoint depSpacePoint = mapper.MapCameraPointToDepthSpace(joint.Position);
                spPt = new SpacePointBase(depSpacePoint);

                break;
            }


            #region Joint Mapping Messages

            if (spPt.X == float.NegativeInfinity || spPt.Y == float.NegativeInfinity)
            {
                //Debug.WriteLine($"Joint Mapping Error: Joint[{joint.JointType.ToString()}] ( {spPt.X} , {spPt.Y} )");
            }
            else if ((spPt.X < 0 || spPt.Y < 0 || spPt.X > FrameDimensions[mode].Item1 || spPt.Y > FrameDimensions[mode].Item2))
            {
                //Debug.WriteLine($"Joint Mapping Overflow: Joint[{joint.JointType.ToString()}] ( {spPt.X} , {spPt.Y} )");
            }

            #endregion


            //-inf meaning Joint is not detected and no corresponding mapped space point
            if (spPt.IsValid)
            {
                // 2) Scale the mapped coordinates to window dimensions.
                spPt = spPt.ScaleTo(canvas.ActualWidth, canvas.ActualHeight, mode);
                //if (joint.JointType == 0) Debug.WriteLine($"Head Position in Color Space = {spPt.X}, {spPt.Y}");

                // 3) Draw the point on Canvas
                shapeToReturn = spPt.DrawPoint(canvas, brush);
            }

            return(shapeToReturn);
        }
Example #3
0
        public static Shape DrawLine(Canvas canvas, SpacePointBase first, SpacePointBase second,
                                     double thickness, Brush brush)
        {
            Shape lineToReturn = null;

            if (first.IsValid && second.IsValid)
            {
                lineToReturn = canvas.DrawLine(
                    new Point(first.X, first.Y),
                    new Point(second.X, second.Y),
                    thickness,
                    brush);
            }

            return(lineToReturn);
        }
Example #4
0
        public static void DrawLine(this Canvas canvas, Joint first, Joint second, CoordinateMapper mapper, SpaceMode mode)
        {
            if (first.TrackingState == TrackingState.NotTracked || second.TrackingState == TrackingState.NotTracked)
            {
                return;
            }

            SpacePointBase myFirstPoint;
            SpacePointBase mySecondPoint;

            switch (mode)
            {
            case SpaceMode.Color:
            default:
                myFirstPoint  = new SpacePointBase(mapper.MapCameraPointToColorSpace(first.Position));
                mySecondPoint = new SpacePointBase(mapper.MapCameraPointToColorSpace(second.Position));

                break;

            case SpaceMode.Depth:
                myFirstPoint  = new SpacePointBase(mapper.MapCameraPointToDepthSpace(first.Position));
                mySecondPoint = new SpacePointBase(mapper.MapCameraPointToDepthSpace(second.Position));

                break;
            }

            //Both points that the line joins must be mapped correctly
            if (
                (!float.IsNegativeInfinity(myFirstPoint.X) &&
                 !float.IsNegativeInfinity(myFirstPoint.Y)) ||
                (!float.IsNegativeInfinity(mySecondPoint.X) &&
                 !float.IsNegativeInfinity(mySecondPoint.Y))
                )
            {
                myFirstPoint  = myFirstPoint.ScaleTo(canvas.ActualWidth, canvas.ActualHeight, mode);
                mySecondPoint = mySecondPoint.ScaleTo(canvas.ActualWidth, canvas.ActualHeight, mode);

                //call static DrawLine from class SpacePointBae
                SpacePointBase.DrawLine(canvas, myFirstPoint, mySecondPoint);
            }
        }
Example #5
0
        public static Shape DrawLine(this Canvas canvas, Joint first, Joint second, CoordinateMapper mapper, SpaceMode mode,
                                     double thickness, Brush brush)
        {
            Shape lineToReturn = null;

            if (first.TrackingState == TrackingState.NotTracked || second.TrackingState == TrackingState.NotTracked)
            {
                return(null);
            }

            SpacePointBase myFirstPoint;
            SpacePointBase mySecondPoint;

            switch (mode)
            {
            case SpaceMode.Color:
            default:
                myFirstPoint  = new SpacePointBase(mapper.MapCameraPointToColorSpace(first.Position));
                mySecondPoint = new SpacePointBase(mapper.MapCameraPointToColorSpace(second.Position));

                break;

            case SpaceMode.Depth:
                myFirstPoint  = new SpacePointBase(mapper.MapCameraPointToDepthSpace(first.Position));
                mySecondPoint = new SpacePointBase(mapper.MapCameraPointToDepthSpace(second.Position));

                break;
            }

            //Both points that the line joins must be mapped correctly
            if (myFirstPoint.IsValid && mySecondPoint.IsValid)
            {
                myFirstPoint  = myFirstPoint.ScaleTo(canvas.ActualWidth, canvas.ActualHeight, mode);
                mySecondPoint = mySecondPoint.ScaleTo(canvas.ActualWidth, canvas.ActualHeight, mode);

                //call static DrawLine from class SpacePointBae
                lineToReturn = SpacePointBase.DrawLine(canvas, myFirstPoint, mySecondPoint, thickness, brush);
            }

            return(lineToReturn);
        }
Example #6
0
        public static void DrawLine(Canvas canvas, SpacePointBase first, SpacePointBase second)
        {
            if (first.IsValid && second.IsValid)
            {
                Line line = new Line
                {
                    X1 = first.X,
                    Y1 = first.Y,
                    X2 = second.X,
                    Y2 = second.Y,
                    StrokeThickness = 8,
                    Stroke          = new SolidColorBrush(Colors.LightBlue)
                };

                canvas.Children.Add(line);
            }
            else
            {
                return;
            }
        }