Example #1
0
 public override void OnMouseDown(Object sender, MouseEventArgs e)
 {
     isDrawig              = true;
     ellipse               = new Ellipse(new Point(e.GetPosition(canvas).X, e.GetPosition(canvas).Y), new Point(e.GetPosition(canvas).X, e.GetPosition(canvas).Y));
     ellipseForDraw        = new System.Windows.Shapes.Ellipse();
     ellipseForDraw.Stroke = Brushes.Red;
     ellipseForDraw.SetValue(Canvas.TopProperty, ellipse.GetFirstPoint().getY());
     ellipseForDraw.SetValue(Canvas.LeftProperty, ellipse.GetFirstPoint().getX());
     canvas.Children.Add(ellipseForDraw);
 }
Example #2
0
        void UpdateMarker()
        {
            View.PhosResultsWindow mw = (View.PhosResultsWindow)Application.Current.Windows.OfType <Window>().Last();
            mw.CanvasResult.Children.Clear();

            Tuple <System.Windows.Shapes.Ellipse, TextBlock, Point> t = MarkerList[(int)CurrentListItem];
            string saved = XamlWriter.Save(t.Item1);

            System.Windows.Shapes.Ellipse ellipse = (System.Windows.Shapes.Ellipse)XamlReader.Load(XmlReader.Create(new StringReader(saved)));
            ellipse.Width  *= CurrentListItem == 0 ? 1 : 2;
            ellipse.Height *= CurrentListItem == 0 ? 1 : 2;
            ellipse.SetValue(Canvas.LeftProperty, t.Item3.X - ellipse.Width / 2.0);
            ellipse.SetValue(Canvas.TopProperty, t.Item3.Y - ellipse.Height / 2.0);

            mw.CanvasResult.Children.Add(ellipse);
        }
Example #3
0
        public override void OnMouseMove(Object sender, MouseEventArgs e)
        {
            if (isDrawig)
            {
                ellipse.setSecondPoint(new Point(e.GetPosition(canvas).X, e.GetPosition(canvas).Y));
                if (ellipse.GetSecondPoint().getX() < ellipse.GetFirstPoint().getX())
                {
                    ellipseForDraw.SetValue(Canvas.LeftProperty, ellipse.GetSecondPoint().getX());
                }
                if (ellipse.GetSecondPoint().getY() < ellipse.GetFirstPoint().getY())
                {
                    ellipseForDraw.SetValue(Canvas.TopProperty, ellipse.GetSecondPoint().getY());
                }

                ellipseForDraw.Width  = Math.Abs(ellipse.GetFirstPoint().getX() - ellipse.GetSecondPoint().getX());
                ellipseForDraw.Height = Math.Abs(ellipse.GetFirstPoint().getY() - ellipse.GetSecondPoint().getY());
            }
        }
Example #4
0
        //Gets depth info from kinect and casts to a bitmap
        private void Ksensor_DepthFrameReady(object sender, DepthImageFrameReadyEventArgs e)
        {
            DepthImageFrame depthFrame = e.OpenDepthImageFrame();   //Puts Depthframe into Depthframe

            //Checks if there is a depthFrame
            if (depthFrame != null)
            {
                // Copy the pixel data from the image to a temporary array
                depthFrame.CopyDepthImagePixelDataTo(this.depthPixels);

                // Get the min and max reliable depth for the current frame
                int minDepth = depthFrame.MinDepth;
                int maxDepth = depthFrame.MaxDepth;

                //Convert depth data to bitmapsource
                short[] pixelData = new short[depthFrame.PixelDataLength];
                depthFrame.CopyPixelDataTo(pixelData);

                BitmapSource bmap = BitmapSource.Create(
                    depthFrame.Width,
                    depthFrame.Height,
                    2, 2,
                    PixelFormats.Gray16, null,
                    pixelData,
                    depthFrame.Width * depthFrame.BytesPerPixel);

                double vertF = 571.401, horzF = 557.274; //Focal lengths

                ColorImagePoint[] color = new ColorImagePoint[depthFrame.PixelDataLength];
                ksensor.CoordinateMapper.MapDepthFrameToColorFrame(DepthImageFormat.Resolution640x480Fps30, this.depthPixels, ColorImageFormat.RgbResolution640x480Fps30, color);

                //Seraches mapped RED coordinates
                for (k = 0; k < 640; ++k)
                {
                    if (color[k].X == XR)
                    {
                        break;
                    }
                }
                for (int h = k; h < depthFrame.PixelDataLength; h += 640)
                {
                    if (color[h].Y == YR)
                    {
                        if (h % 640 != 0)
                        {
                            XRMapped = h % 640;
                        }

                        YRMapped = (h - XR) / 640;

                        //Red coordinates
                        ZR = this.depthPixels[(640 - XRMapped) + (YRMapped * 640)].Depth;

                        Rxcoord = (ZR * (320 - XRMapped)) / horzF;
                        Rycoord = (ZR * (240 - YRMapped)) / vertF;

                        RCoordX.Content = Math.Round(Rxcoord);
                        RCoordY.Content = Math.Round(Rycoord);
                        RCoordZ.Content = ZR;
                        break;
                    }
                }

                //Searches mapped Blue coordinates
                for (j = 0; j < 640; ++j)
                {
                    if (color[j].X == XB)
                    {
                        break;
                    }
                }
                for (int h = j; h < depthFrame.PixelDataLength; h += 640)
                {
                    if (color[h].Y == YB)
                    {
                        if (h % 640 != 0)
                        {
                            XBMapped = h % 640;
                        }
                        YBMapped = (h - XB) / 640;

                        //Red coordinates
                        ZB = this.depthPixels[(640 - XBMapped) + (YBMapped * 640)].Depth;

                        Bxcoord = (ZB * (320 - XBMapped)) / horzF;
                        Bycoord = (ZB * (240 - YBMapped)) / vertF;

                        BCoordX.Content = Math.Round(Bxcoord);
                        BCoordY.Content = Math.Round(Bycoord);
                        BCoordZ.Content = ZB;
                        break;
                    }
                }

                //Set stream to image
                Depthstream.Source = bmap;

                //Add points to imageviews for debugging
                Canvas1.Children.Clear();
                Canvas2.Children.Clear();

                System.Windows.Shapes.Ellipse DepthPointRed  = CreateEllipse.CircleRed();
                System.Windows.Shapes.Ellipse DepthPointBlue = CreateEllipse.CircleBlue();
                System.Windows.Shapes.Ellipse ColorPointRed  = CreateEllipse.CircleRed();
                System.Windows.Shapes.Ellipse ColorPointBlue = CreateEllipse.CircleBlue();

                Canvas2.Children.Add(ColorPointRed);
                Canvas2.Children.Add(ColorPointBlue);

                Canvas1.Children.Add(DepthPointRed);
                Canvas1.Children.Add(DepthPointBlue);

                DepthPointRed.SetValue(Canvas.LeftProperty, (depthFrame.Width - XRMapped - 3) * .6);
                DepthPointRed.SetValue(Canvas.TopProperty, (YRMapped - 3) * .6);

                DepthPointBlue.SetValue(Canvas.LeftProperty, (depthFrame.Width - XBMapped - 3) * .6);
                DepthPointBlue.SetValue(Canvas.TopProperty, (YBMapped - 3) * .6);

                ColorPointRed.SetValue(Canvas.LeftProperty, (depthFrame.Width - XR - 3) * .6);
                ColorPointRed.SetValue(Canvas.TopProperty, (YR - 3) * .6);

                ColorPointBlue.SetValue(Canvas.LeftProperty, (depthFrame.Width - XB - 3) * .6);
                ColorPointBlue.SetValue(Canvas.TopProperty, (YB - 3) * .6);

                //Cleanup
                depthFrame.Dispose();
                CoordinateFrameCalc();
            }
        }
Example #5
0
        void UpdateSummary()
        {
            View.PhosResultsWindow mw = (View.PhosResultsWindow)Application.Current.Windows.OfType <Window>().Last();
            for (int i = 0; i < MarkerList.Count; i++)
            {
                if (DisplayName.Equals("PhosResultsViewModelBatchMeasurement") && i == 0)
                {
                    continue;
                }
                Tuple <System.Windows.Shapes.Ellipse, TextBlock, Point> t = MarkerList[i];
                string savedEllipse = XamlWriter.Save(t.Item1);
                string savedText    = XamlWriter.Save(t.Item2);
                System.Windows.Shapes.Ellipse     ellipse = (System.Windows.Shapes.Ellipse)XamlReader.Load(XmlReader.Create(new StringReader(savedEllipse)));
                System.Windows.Controls.TextBlock txt     = (TextBlock)XamlReader.Load(XmlReader.Create(new StringReader(savedText)));
                if (DisplayName.Equals("PhosResultsViewModelBatchMeasurement"))
                {
                    ellipse.Width  *= 2;
                    ellipse.Height *= 2;
                    ellipse.Stroke  = ColorLegendList[(int)DiamondResList[i - 1]];
                    txt.FontSize    = 48;
                    txt.Foreground  = ColorLegendList[(int)DiamondResList[i - 1]];
                }
                else
                {
                    ellipse.Stroke = ColorLegendList[(int)DiamondResult];
                }
                ellipse.SetValue(Canvas.LeftProperty, t.Item3.X - ellipse.Width / 2.0);
                ellipse.SetValue(Canvas.TopProperty, t.Item3.Y - ellipse.Height / 2.0);

                txt.SetValue(Canvas.LeftProperty, t.Item3.X - 15);
                txt.SetValue(Canvas.TopProperty, t.Item3.Y - 76);

                mw.CanvasSummary.Children.Add(ellipse);
                if (DisplayName.Equals("PhosResultsViewModelBatchMeasurement"))
                {
                    mw.CanvasSummary.Children.Add(txt);
                }
                if (!DisplayName.Equals("PhosResultsViewModelBatchMeasurement") && i == 0)
                {
                    break;
                }
            }

            if (!mappingMeasure)
            {
                double x = 50;
                double y = 50;
                for (int i = 0; i < ColorLegendList.Count; i++)
                {
                    DrawCanvas.Rect(x, y, 30, 30, ColorLegendList[i - 2], mw.CanvasSummary);
                    DrawCanvas.Text(x + 50, y, ResultString(i - 2), true, ColorLegendList[i - 2], mw.CanvasSummary, false);
                    y += 40;
                }
            }
            else
            {
                // rectangle mask
                double x = Canvas.GetLeft(RectMark);
                double y = Canvas.GetTop(RectMark);
                double w = RectMark.Width;
                double h = RectMark.Height;

                System.Windows.Shapes.Rectangle tmpRect = DrawCanvas.Rect(x, y, (int)w, (int)h, Brushes.Red, mw.CanvasSummary, 0.3);
            }
        }