コード例 #1
0
ファイル: Util.cs プロジェクト: brocny/Rocnikovy-Projekt
        /// <summary>
        ///     Get a rectangle containing a body's face based on the position of its neck and head
        /// </summary>
        /// <param name="body">The body of which we want the face rectangle</param>
        /// <param name="mapper">A coordinate mapper, used for mapping body's joints' positions to color space</param>
        /// <param name="faceRect">A <c>Rectangle</c> containing <c>body</c>'s face</param>
        /// <returns>True if succesful</returns>
        public static bool TryGetHeadRectangle(IBody body, ICoordinateMapper mapper, out Rectangle faceRect)
        {
            faceRect = Rectangle.Empty;

            if (!body.Joints.TryGetValue(JointType.Head, out var headJoint) ||
                !body.Joints.TryGetValue(JointType.Neck, out var neckJoint))
            {
                return(false);
            }
            if (!headJoint.IsTracked || !neckJoint.IsTracked)
            {
                return(false);
            }

            var   headJointColorPos = mapper.MapCameraPointToColorSpace(headJoint.Position);
            var   neckJointColorPos = mapper.MapCameraPointToColorSpace(neckJoint.Position);
            float headNeckDistance  = headJointColorPos.DistanceFrom(neckJointColorPos);

            bool isFaceVertical = Math.Abs(headJointColorPos.Y - neckJointColorPos.Y) >
                                  Math.Abs(headJointColorPos.X - neckJointColorPos.X);

            float width  = isFaceVertical ? headNeckDistance * FaceWidthMultiplier : headNeckDistance * FaceHeightMultiplier;
            float height = isFaceVertical ? headNeckDistance * FaceHeightMultiplier : headNeckDistance * FaceWidthMultiplier;

            faceRect = new Rectangle(
                (int)(headJointColorPos.X - width / 2),
                (int)(headJointColorPos.Y - height / 2),
                (int)width,
                (int)height);

            return(true);
        }
コード例 #2
0
        public override void Draw(System.Drawing.Graphics g, ICoordinateMapper coordinateMapper)
        {
            if (g == null)
            {
                throw new System.ArgumentNullException("g");
            }
            if (coordinateMapper == null)
            {
                throw new System.ArgumentNullException("coordinateMapper");
            }

            if (!base.Enabled || _path == null)
            {
                return;
            }

            System.Drawing.Point drawPnt = coordinateMapper.WorkspaceToControl(base.Location, Aurigma.GraphicsMill.Unit.Point);
            using (System.Drawing.Drawing2D.Matrix m = new System.Drawing.Drawing2D.Matrix(1.0f, 0.0f, 0.0f, 1.0f, drawPnt.X, drawPnt.Y))
            {
                g.Transform = m;

                if (_brush != null)
                {
                    g.FillPath(_brush, _path);
                }
                if (this.Pen != null)
                {
                    g.DrawPath(_pen, _path);
                }

                g.Transform = new System.Drawing.Drawing2D.Matrix();
            }
        }
コード例 #3
0
 public KinectFaceTracker(FSDKFacePipeline facePipeline, IKinect kinect, CancellationTokenSource cts)
 {
     _kinect                  = kinect;
     FacePipeline             = facePipeline;
     _cancellationTokenSource = cts;
     _coordinateMapper        = _kinect.CoordinateMapper;
 }
コード例 #4
0
        public override bool HitTest(System.Drawing.Point point, ICoordinateMapper coordinateMapper)
        {
            if (coordinateMapper == null)
            {
                throw new System.ArgumentNullException("coordinateMapper");
            }

            bool result = false;

            if (base.Enabled && _path != null)
            {
                System.Drawing.Point convertedPoint = coordinateMapper.WorkspaceToControl(base.Location, Aurigma.GraphicsMill.Unit.Point);

                point.X -= convertedPoint.X;
                point.Y -= convertedPoint.Y;

                result = _path.IsVisible(point);
                if (!result && this.Pen != null)
                {
                    result = _path.IsOutlineVisible(point, this.Pen);
                }
            }

            return(result);
        }
コード例 #5
0
ファイル: TestTrackSimulator.cs プロジェクト: mat0pad/SWT-ATM
        public void SetUp()
        {
            mapper = Substitute.For <ICoordinateMapper>();

            receiver = Substitute.For <ITransponderReceiver>();

            simulator = new TrackSimulator(mapper, receiver);
        }
コード例 #6
0
ファイル: TrackSimulator.cs プロジェクト: mat0pad/SWT-ATM
        public TrackSimulator(ICoordinateMapper mapper, ITransponderReceiver receiver)
        {
            _mapper = mapper;

            // Create transponder receiver
            _transponderReceiver = receiver;

            //TransponderReceiverFactory.CreateTransponderDataReceiver();
        }
コード例 #7
0
ファイル: PathVObject.cs プロジェクト: lanicon/WinControls
        protected System.Drawing.Pen CreateViewportPen(ICoordinateMapper coordinateMapper)
        {
            if (_pen == null)
            {
                return(null);
            }

            System.Drawing.Pen result = (System.Drawing.Pen)_pen.Clone();
            result.Width = _pen.Width * coordinateMapper.GetControlPixelsPerUnitX(Aurigma.GraphicsMill.Unit.Point);
            return(result);
        }
コード例 #8
0
ファイル: FormMain.cs プロジェクト: brocny/Rocnikovy-Projekt
        public FormMain()
        {
            var kinect = KinectInitializeHelper.InitializeKinect();

            if (kinect == null)
            {
                Environment.Exit(1);
            }

            InitializeComponent();

            var faceDatabase = new DictionaryFaceDatabase <byte[]>(new FSDKFaceInfo());

            _databaseHelper = new DatabaseHelper <byte[]>(faceDatabase);

            var cts          = new CancellationTokenSource();
            var facePipeline = new FSDKFacePipeline(faceDatabase, TaskScheduler.Default, cts.Token);

            if (KinectTrackedAppSettings.Default.RenderFace)
            {
                facePipeline.FaceCuttingComplete += FacePipelineOnFaceCuttingComplete;
            }

            if (FsdkSettings.Default.FsdkDetectFeatures || FsdkSettings.Default.FsdkDetectExpression)
            {
                facePipeline.FacialFeatureDetectionComplete += FacePipelineOnFeatureDetection;
            }

            if (KinectTrackedAppSettings.Default.RenderMatch)
            {
                facePipeline.TemplateProcessingComplete += FacePipelineOnTemplateProcessingComplete;
            }

            FsdkInitializeHelper.InitializeLibrary();

            _kinectFrameWidth  = kinect.ColorFrameStream.FrameHeight;
            _kinectFrameHeight = kinect.ColorFrameStream.FrameWidth;
            _coordinateMapper  = kinect.CoordinateMapper;
            _kft = new KinectFaceTracker(facePipeline, kinect, cts);
            _kft.FrameArrived += KftOnFrameArrived;

            _kft.FacePipeline.FacialFeatureDetectionComplete += FacePipelineOnFeatureDetection;
            _kft.Start();

            _imageHeight = mainPictureBox.Height;
            _imageWidth  = mainPictureBox.Width;

            startStopToolStripMenuItem.Text =
                _programState == ProgramState.Running ? "Stop (Space)" : "Start (Space)";

            _renderer = new Renderer(_kinectFrameHeight, _kinectFrameWidth);
        }
コード例 #9
0
ファイル: ImageVObject.cs プロジェクト: lanicon/WinControls
        private void DrawInternal(System.Drawing.Graphics g, ICoordinateMapper coordinateMapper, System.Drawing.Rectangle renderingRect)
        {
            System.Drawing.Region oldClip = g.Clip;
            g.SetClip(renderingRect);

            System.Drawing.Drawing2D.Matrix oldMatrix = (System.Drawing.Drawing2D.Matrix)g.Transform.Clone();

            try
            {
                if (_rect.DrawMode == VObjectDrawMode.Normal)
                {
                    g.SmoothingMode     = normalSmoothingMode;
                    g.InterpolationMode = normalInterpolationMode;
                }
                else
                {
                    g.SmoothingMode     = draftSmoothingMode;
                    g.InterpolationMode = draftInterpolationMode;
                }

                System.Drawing.RectangleF bounds            = _rect.GetVObjectBounds();
                System.Drawing.RectangleF transformedBounds = _rect.GetTransformedVObjectBounds();
                System.Drawing.Rectangle  mappedBounds      = coordinateMapper.WorkspaceToControl(transformedBounds, Aurigma.GraphicsMill.Unit.Point);

                if (transformedBounds.Width > VObject.Eps && transformedBounds.Height > VObject.Eps)
                {
                    float scaleX = mappedBounds.Width / transformedBounds.Width,
                          scaleY = mappedBounds.Height / transformedBounds.Height;

                    using (System.Drawing.Drawing2D.Matrix outputMatrix = (System.Drawing.Drawing2D.Matrix)_rect.Transform.Clone())
                    {
                        outputMatrix.Translate(-transformedBounds.X, -transformedBounds.Y, System.Drawing.Drawing2D.MatrixOrder.Append);
                        outputMatrix.Scale(scaleX, scaleY, System.Drawing.Drawing2D.MatrixOrder.Append);
                        outputMatrix.Translate(mappedBounds.X, mappedBounds.Y, System.Drawing.Drawing2D.MatrixOrder.Append);

                        g.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;
                        g.Transform       = outputMatrix;
                        g.DrawImage(this.DrawnImage, 0, 0, bounds.Width, bounds.Height);
                    }
                }
            }
            finally
            {
                g.Transform = oldMatrix;
                g.SetClip(oldClip, System.Drawing.Drawing2D.CombineMode.Replace);
            }
        }
コード例 #10
0
ファイル: PathVObject.cs プロジェクト: lanicon/WinControls
        protected void AdaptBrushToViewport(ICoordinateMapper coordinateMapper)
        {
            if (coordinateMapper == null)
            {
                throw new System.ArgumentNullException("coordinateMapper");
            }

            if (_brush != null && _brush.GetType() != typeof(System.Drawing.SolidBrush) && _brush.GetType() != typeof(System.Drawing.Drawing2D.HatchBrush))
            {
                System.Drawing.Drawing2D.Matrix originalMatrix = VObjectsUtils.GetBrushMatrix(_brush);
                _brushMatrices.Push(originalMatrix);

                System.Drawing.Point viewportTranslation = coordinateMapper.WorkspaceToControl(System.Drawing.PointF.Empty, Aurigma.GraphicsMill.Unit.Pixel);
                float scale = coordinateMapper.GetControlPixelsPerUnitX(Aurigma.GraphicsMill.Unit.Point);

                System.Drawing.Drawing2D.Matrix brushMatrix = (System.Drawing.Drawing2D.Matrix)_matrix.Clone();
                brushMatrix.Scale(scale, scale, System.Drawing.Drawing2D.MatrixOrder.Append);
                brushMatrix.Translate(viewportTranslation.X, viewportTranslation.Y, System.Drawing.Drawing2D.MatrixOrder.Append);
                brushMatrix.Multiply(originalMatrix, System.Drawing.Drawing2D.MatrixOrder.Prepend);

                VObjectsUtils.SetBrushMatrix(_brush, brushMatrix);
            }
        }
コード例 #11
0
ファイル: PathVObject.cs プロジェクト: lanicon/WinControls
        private System.Drawing.Drawing2D.GraphicsPath CreateViewportPath(ICoordinateMapper coordinateMapper)
        {
            System.Drawing.Drawing2D.GraphicsPath result = (System.Drawing.Drawing2D.GraphicsPath) this.Path.Clone();

            result.Transform(_matrix);
            System.Drawing.RectangleF pathBounds   = this.Path.GetBounds(_matrix);
            System.Drawing.Rectangle  mappedBounds = coordinateMapper.WorkspaceToControl(pathBounds, Aurigma.GraphicsMill.Unit.Point);

            if (pathBounds.Width > VObject.Eps && pathBounds.Height > VObject.Eps)
            {
                float scaleX = (float)mappedBounds.Width / pathBounds.Width,
                      scaleY = (float)mappedBounds.Height / pathBounds.Height;

                using (System.Drawing.Drawing2D.Matrix m = new System.Drawing.Drawing2D.Matrix())
                {
                    m.Translate(mappedBounds.X, mappedBounds.Y);
                    m.Scale(scaleX, scaleY);
                    m.Translate(-pathBounds.X, -pathBounds.Y);
                    result.Transform(m);
                }
            }

            return(result);
        }
コード例 #12
0
ファイル: ImageVObject.cs プロジェクト: lanicon/WinControls
        public override void Draw(System.Drawing.Rectangle renderingRect, System.Drawing.Graphics g, ICoordinateMapper coordinateMapper)
        {
            if (g == null)
            {
                throw new System.ArgumentNullException("g");
            }
            if (coordinateMapper == null)
            {
                throw new System.ArgumentNullException("coordinateMapper");
            }

            System.Drawing.Rectangle screenBounds = coordinateMapper.WorkspaceToControl(_rect.GetTransformedVObjectBounds(), Aurigma.GraphicsMill.Unit.Point);
            System.Drawing.Rectangle visiblePart  = System.Drawing.Rectangle.Intersect(screenBounds, renderingRect);

            if (visiblePart.Width > 0 && visiblePart.Height > 0)
            {
                DrawInternal(g, coordinateMapper, renderingRect);
            }
        }
コード例 #13
0
 public abstract bool HitTest(System.Drawing.Point point, ICoordinateMapper coordinateMapper);
コード例 #14
0
 public abstract void Draw(System.Drawing.Rectangle renderingRect, System.Drawing.Graphics g, ICoordinateMapper coordinateMapper);
コード例 #15
0
        public override void Draw(System.Drawing.Rectangle renderingRect, System.Drawing.Graphics g, ICoordinateMapper coordinateMapper)
        {
            if (g == null)
            {
                throw new System.ArgumentNullException("g");
            }
            if (coordinateMapper == null)
            {
                throw new System.ArgumentNullException("coordinateMapper");
            }

            SynchronizeChildMatrices();
            for (int i = 0; i < _children.Count; i++)
            {
                _children[i].Draw(renderingRect, g, coordinateMapper);
            }
        }
コード例 #16
0
 public abstract void Draw(System.Drawing.Graphics g, ICoordinateMapper coordinateMapper);
コード例 #17
0
 public void SetUp()
 {
     mapper    = Substitute.For <ICoordinateMapper>();
     simulator = new TrackSimulator(mapper, TransponderReceiverFactory.CreateTransponderDataReceiver());
 }
コード例 #18
0
        public override void Draw(System.Drawing.Rectangle renderingRect, System.Drawing.Graphics g, ICoordinateMapper coordinateMapper)
        {
            if (g == null)
            {
                throw new System.ArgumentNullException("g");
            }
            if (coordinateMapper == null)
            {
                throw new System.ArgumentNullException("coordinateMapper");
            }

            // FillPath doesn't support specifying FillMode, it always uses FillMode.Alternate,
            // so we have to use Graphics.FillPolygon method in other cases.
            if (!_closePath || base.Brush == null || _fillMode == System.Drawing.Drawing2D.FillMode.Alternate)
            {
                base.Draw(renderingRect, g, coordinateMapper);
            }
            else
            {
                System.Drawing.PointF[] transformedPoints = VObjectsUtils.TransformPoints(base.Transform, _points);
                for (int i = 0; i < transformedPoints.Length; i++)
                {
                    transformedPoints[i] = coordinateMapper.WorkspaceToControl(transformedPoints[i], Aurigma.GraphicsMill.Unit.Point);
                }

                System.Drawing.Drawing2D.SmoothingMode oldSmoothingMode = g.SmoothingMode;
                System.Drawing.Pen pen = base.CreateViewportPen(coordinateMapper);
                try
                {
                    switch (base.DrawMode)
                    {
                    case VObjectDrawMode.Draft:
                        g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighSpeed;
                        break;

                    case VObjectDrawMode.Normal:
                        g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
                        break;

                    default:
                        throw new Aurigma.GraphicsMill.UnexpectedException(StringResources.GetString("ExStrUnexpectedDrawMode"));
                    }

                    if (base.Brush != null)
                    {
                        AdaptBrushToViewport(coordinateMapper);
                        try
                        {
                            g.FillPolygon(base.Brush, transformedPoints, _fillMode);
                        }
                        finally
                        {
                            RestoreBrush();
                        }
                    }
                    if (pen != null)
                    {
                        g.DrawPolygon(pen, transformedPoints);
                    }
                }
                finally
                {
                    pen.Dispose();
                    g.SmoothingMode = oldSmoothingMode;
                }
            }
        }
コード例 #19
0
ファイル: PathVObject.cs プロジェクト: lanicon/WinControls
        public override void Draw(System.Drawing.Rectangle renderingRect, System.Drawing.Graphics g, ICoordinateMapper coordinateMapper)
        {
            if (g == null)
            {
                throw new System.ArgumentNullException("g");
            }
            if (coordinateMapper == null)
            {
                throw new System.ArgumentNullException("coordinateMapper");
            }

            System.Drawing.Drawing2D.GraphicsPath drawPath = CreateViewportPath(coordinateMapper);
            System.Drawing.Pen pen = CreateViewportPen(coordinateMapper);

            System.Drawing.Drawing2D.SmoothingMode oldSmoothingMode = g.SmoothingMode;
            try
            {
                switch (base.DrawMode)
                {
                case VObjectDrawMode.Draft:
                    g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.Default;
                    break;

                case VObjectDrawMode.Normal:
                    g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
                    break;

                default:
                    throw new Aurigma.GraphicsMill.UnexpectedException(StringResources.GetString("ExStrUnexpectedDrawMode"));
                }

                if (_brush != null)
                {
                    AdaptBrushToViewport(coordinateMapper);
                    try
                    {
                        g.FillPath(_brush, drawPath);
                    }
                    finally
                    {
                        RestoreBrush();
                    }
                }
                if (pen != null)
                {
                    g.DrawPath(pen, drawPath);
                }
            }
            finally
            {
                if (pen != null)
                {
                    pen.Dispose();
                }
                drawPath.Dispose();
                g.SmoothingMode = oldSmoothingMode;
            }
        }
コード例 #20
0
ファイル: Util.cs プロジェクト: brocny/Rocnikovy-Projekt
        public static IDictionary <JointType, Vector2> MapJointsToColorSpace(IBody body, ICoordinateMapper mapper)
        {
            var ret = new Dictionary <JointType, Vector2>();

            foreach (var joint in body.Joints)
            {
                var cameraPoint = joint.Value.Position;
                if (cameraPoint.Z < 0)
                {
                    cameraPoint.Z = 0.1f;
                }

                var colorPoint =
                    mapper.MapCameraPointToColorSpace(joint.Value.Position);

                ret.Add(joint.Key, colorPoint);
            }

            return(ret);
        }
コード例 #21
0
        public void DrawContent(System.Drawing.Graphics g, System.Drawing.Rectangle rect, ICoordinateMapper coordinateMapper)
        {
            for (int i = 0; i < _layers.Count; i++)
            {
                if (!_layers[i].Visible)
                {
                    continue;
                }

                for (int j = 0; j < _layers[i].VObjects.Count; j++)
                {
                    IVObject obj = _layers[i].VObjects[j];
                    if (rect.IntersectsWith(coordinateMapper.WorkspaceToControl(obj.GetTransformedVObjectBounds(), Aurigma.GraphicsMill.Unit.Point)))
                    {
                        obj.Draw(rect, g, coordinateMapper);
                    }
                }
            }
        }