Esempio n. 1
0
 public static void addPoint(Mrg.Point p)
 {
     if (controller != null)
     {
         controller.shots.Add(p);
     }
 }
Esempio n. 2
0
        private Mrg.Point findCenterPoint(Mrg.Point p1, Mrg.Point p2)
        {
            double midX = (p1.getX() + p2.getX()) / 2.0;
            double midY = (p1.getY() + p2.getY()) / 2.0;

            return(new Mrg.Point(midX, midY));
        }
Esempio n. 3
0
//------------------------------------------------------------------------------------------------------------------
        private bool isInsideCircle(Mrg.Point testPoint, Mrg.Point midPoint, float radius)
        {
            float dist = findDistance(testPoint, midPoint);

            if (dist < radius)
            {
                return(true);
            }

            return(false);
        }
Esempio n. 4
0
        public LaserDetect()
        {
            point = new Mrg.Point(-1, -1);
            //point = new AForge.Point(-1, -1);
            xPos        = yPos = 0;
            colorFilter = new ColorFiltering();

            colorFilter.Red   = new IntRange(150, 255); //150, 180
            colorFilter.Green = new IntRange(50, 120);  //0,90
            colorFilter.Blue  = new IntRange(80, 220);  //0,100
        }
Esempio n. 5
0
        public float findDistance(Mrg.Point p1, Mrg.Point p2)
        {
            double x = p1.getX() - p2.getX();
            double y = p1.getY() - p2.getY();

            x = Math.Pow(x, 2);
            y = Math.Pow(y, 2);

            float distance = (float)Math.Sqrt(x + y);

            return(distance);
        }
Esempio n. 6
0
        public TargetBox()
        {
            InitializeComponent();
            shotInfo = ShootPointController.getController();

            //Initializeing the contorl
            width           = this.Width;
            height          = this.Height;
            numberOfCircle  = DEFAULT_NUMBER;
            shotRadiusPoint = new ArrayList();
            tempPoints      = new ArrayList();
            groupMid        = new Mrg.Point(0, 0);
            //shotRad = new int[50];
            calculateInfo();
        }
Esempio n. 7
0
        }//validate point

        private int getMirrorX(Mrg.Point retPoint)
        {
            double mirrorPointX = 0;
            double pointX       = 0;

            mirrorPointX = retPoint.getX();
            pointX       = mirrorPointX;
            //double difference = mirrorPointX - IMAGE_CENTER_X;
            //if (difference > 0)
            //{
            //    pointX = IMAGE_CENTER_X - (mirrorPointX - IMAGE_CENTER_X);
            //    //MessageBox.Show("SHOW");
            //}
            //else
            //{
            //    pointX = IMAGE_CENTER_X + (IMAGE_CENTER_X - mirrorPointX);
            //}

            return((int)pointX);
        }
Esempio n. 8
0
        public void showDistanceForm()
        {
            // Lets generate sine and cosine wave
            ArrayList shots = TargetBoxController.getTargetBox().tempPoints;

            shotPoint = new ArrayList();
            for (int i = 0; i < shots.Count; i++)
            {
                Mrg.Point p        = (Mrg.Point)shots[i];
                float     distance = tb.findDistance(new Mrg.Point(tb.centerX, tb.centerY), new Mrg.Point(p.getX(), p.getY()));
                //distance = (10 - (((float)distance / tb.radius)) * 10);

                int distancePoint = (10 - ((int)(distance * (10.0 / tb.radius))));
                shotPoint.Add(distancePoint);
            }

            shotsTaken   = (short)shotInfo.shots.Count;
            hitsTergeted = (short)ShootPointController.getController().shotAffected;

            double[] x = new double[shotPoint.Count];
            double[] y = new double[shotPoint.Count];

            averageDistance = 0;

            for (int i = 0; i < shotPoint.Count; i++)
            {
                x[i]             = i + 1;
                y[i]             = (int)shotPoint[i];
                averageDistance += (int)y[i];
            }

            if (shotPoint.Count != 0)
            {
                averageDistance = (int)((float)averageDistance / shotPoint.Count);
            }

            avgAccuracy = (short)averageDistance;

            // This is to remove all plots
            //if (distanceZedGraphControl.GraphPane != null)

            distanceZedGraphControl.GraphPane.CurveList.Clear();


            // GraphPane object holds one or more Curve objects (or plots)
            GraphPane myPane = distanceZedGraphControl.GraphPane;

            // PointPairList holds the data for plotting, X and Y arrays
            PointPairList spl1 = new PointPairList(x, y);
            //PointPairList spl2 = new PointPairList(x, z);

            // Add cruves to myPane object
            BarItem myCurve1 = myPane.AddBar("Distance", spl1, Color.Blue);

            //LineItem myCurve2 = myPane.AddCurve("Cosine Wave", spl2, Color.Red, SymbolType.None);

            myCurve1.Bar.Border = new Border();
            //myCurve2.Line.Width = 3.0F;
            myPane.Title.Text = "Distance Summary";

            // I add all three functions just to be sure it refeshes the plot.
            distanceZedGraphControl.AxisChange();
            distanceZedGraphControl.Invalidate();
            distanceZedGraphControl.Refresh();

            MessageBox.Show(averageDistance.ToString());
        }
Esempio n. 9
0
        private void MainForm_KeyDown(object sender, KeyEventArgs e)
        {
            //float distance = 0;
            if (e.KeyCode == Keys.S && ShootPointController.getController().isProjectLaser == false)
            {
                Mrg.Point p = new Mrg.Point();
                //MessageBox.Show("");
                player.Play();
                allShots = ShootPointController.getController();
                Color c;
                vp.getCurrentImageShotInfo(out p, out c);

                if (p.getX() != -1 && p.getY() != -1)
                {
                    allShots.shots.Add(new Mrg.Point(p.getX(), p.getY()));
                    allShots.incrementShot(true, true);
                }
                else
                {
                    allShots.incrementShot(false, true);
                }

                mainTargetBox.Invalidate();
                //mainTargetInfo.setShotLabelInfo(allShots.shotAffected, allShots.shotTaken);

                if (ShootPointController.getController().shotTaken == shootTime)
                {
                    if (MessageBox.Show("Do you want to save current shooting records?", "Confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                    {
                        GraphForm graphForm = new GraphForm(mainTargetBox);
                        graphForm.saveData = true;
                        graphForm.showTimerForm();
                        graphForm.showDistanceForm();
                        graphForm.showCircleForm();
                        graphForm.calculateAverage();
                        if (graphForm.doneSave)
                        {
                            MessageBox.Show("Data has been saved successfully.");
                        }
                    }
                    else
                    {
                        if (File.Exists(@"G:\Target\kjhkh\QBD-2011\QBD-2011\" + Login.ShooterName + "Log" + ".txt"))
                        {
                            File.Delete(@"G:\Target\kjhkh\QBD-2011\QBD-2011\" + Login.ShooterName + "Log" + ".txt");
                        }
                        if (File.Exists(@"G:\Target\kjhkh\QBD-2011\QBD-2011\" + Login.ShooterName + ".txt"))
                        {
                            File.Delete(@"G:\Target\kjhkh\QBD-2011\QBD-2011\" + Login.ShooterName + ".txt");
                        }
                    }

                    setControlToolButton(true, true, true);

                    mainTargetBox.isCircleDrawn   = true;
                    mainTargetBox.isDistanceDrawn = true;
                    targetTimer.hangTimer();
                }


                //time adding
                ShootPointController.getController().shotTime.Add(targetTimer.singleShotTime);
                //MessageBox.Show(targetTimer.singleShotTime.ToString());
                //MessageBox.Show(targetTimer.singleShotTime.ToString());
                targetTimer.singleShotTime = 0;
            }

            if (e.KeyCode == Keys.Escape)
            {
                if (totalFullScreen == true)
                {
                    Fullscreen(false);
                    totalFullScreen = false;
                }
            }
        }
Esempio n. 10
0
        }//function

        private int calculateRectangle(out Mrg.Point gcMidPoint)
        {
            int minX = 10000, maxX = 0;
            int minY = 10000, maxY = 0;

            Mrg.Point minXPoint = new Mrg.Point();
            Mrg.Point minYPoint = new Mrg.Point();
            Mrg.Point maxXPoint = new Mrg.Point();
            Mrg.Point maxYPoint = new Mrg.Point();

            //tempPoints
            //shotInfo.shots.Count
            for (int i = 0; i < tempPoints.Count; i++)
            {
                for (int j = 0; j < tempPoints.Count; j++)
                {
                    Mrg.Point p = (Mrg.Point)tempPoints[i];

                    if (p.getX() > maxX)
                    {
                        maxX      = (int)p.getX();
                        maxXPoint = p;
                    }
                    if (p.getX() < minX)
                    {
                        minX      = (int)p.getX();
                        minXPoint = p;
                    }

                    if (p.getY() > maxY)
                    {
                        maxY      = (int)p.getY();
                        maxYPoint = p;
                    }
                    if (p.getY() < minY)
                    {
                        minY      = (int)p.getY();
                        minYPoint = p;
                    }
                } //nesed for
            }     //outee for


            int diffX    = 0;
            int diffY    = 0;
            int gcradius = 0;

            Mrg.Point gcmidPoint;
            diffX = maxX - minX;
            diffY = maxY - minY;

            if (diffX > diffY)
            {
                gcradius   = (int)(findDistance(maxXPoint, minXPoint) / 2.0);
                gcmidPoint = findCenterPoint(maxXPoint, minXPoint);
            }
            else
            {
                gcradius   = (int)(findDistance(maxYPoint, minYPoint) / 2.0);
                gcmidPoint = findCenterPoint(maxYPoint, minYPoint);
            }
            //for cheking
            for (int i = 0; i < tempPoints.Count; i++)
            {
                if (!isInsideCircle((Mrg.Point)tempPoints[i], gcmidPoint, gcradius))
                {
                    gcradius = (int)(findDistance((Mrg.Point)tempPoints[i], gcmidPoint));
                }
            }
            gcMidPoint = gcmidPoint;
            string str = string.Format("mx {0}, my {1}\nminx {2} miny {3}", maxX.ToString(), maxY.ToString(), minX.ToString(), minY.ToString());

            str += string.Format("\nradius: {0} midPoint {1}", gcradius.ToString(), gcmidPoint.ToString());
            //MessageBox.Show(str);
            return(gcradius);
        }
Esempio n. 11
0
//----------------------------------------------------------------------------------------------------------------------------------
        public int getCircleInfo(out int x, out int y)
        {
            Mrg.Point newRadiusPoint;
            float     newRadiusDistance = 0;

            maxRadiusDistace = 0;
            int pr = 0;


            if (tempPoints.Count == 0)
            {
                x           = 0;
                y           = 0;
                groupRadius = 0;
                return(groupRadius);
            }

            if (tempPoints.Count == 1)
            {
                Mrg.Point p = (Mrg.Point)tempPoints[0];
                x           = (int)p.getX();
                y           = (int)p.getY();
                groupRadius = 10;
                shotRadiusPoint.Add(10);
                //ShootPointController.getController().shotRadius.Add(groupRadius);

                return(groupRadius);
            }



            if (tempPoints.Count == 2)
            {
                Mrg.Point p1 = (Mrg.Point)tempPoints[0];
                Mrg.Point p2 = (Mrg.Point)tempPoints[1];
                groupMidPoint1 = p1;
                groupMidPoint2 = p2;

                groupMid = findCenterPoint(p1, p2);
                x        = (int)groupMid.getX();
                y        = (int)groupMid.getY();
                float d = findDistance(p1, p2);
                groupRadius = (int)(d / 2.0);
                //pr = (int)(10 - ((float)(groupRadius / radius) * 10));

                //ShootPointController.getController().shotRadius.Add(pr);
                int point = (int)(groupRadius * (10.0 / 81.75)); // 272.5
                shotRadiusPoint.Add(point);
                return(groupRadius);
            }


            Mrg.Point tempPoint = new Mrg.Point();
            groupRadius = calculateRectangle(out tempPoint);
            x           = (int)tempPoint.getX();
            y           = (int)tempPoint.getY();

            #region blokced codes

            /*
             * for(int i=0; i<tempPoints.Count; i++)
             * {
             *  for(int j=0; j < tempPoints.Count; j++)
             *  {
             *      newRadiusDistance = findDistance((Point)tempPoints[i], (Point)tempPoints[j]);
             *
             *      if (newRadiusDistance > maxRadiusDistace)
             *      {
             *          maxRadiusDistace = newRadiusDistance;
             *          groupMidPoint1 = (Point)tempPoints[i];
             *          groupMidPoint2 = (Point)tempPoints[j];
             *
             *      }
             *  }
             *
             * }//end of for
             * groupMid = findCenterPoint(groupMidPoint1, groupMidPoint2);
             */

            /*
             * Point latestPoint = (Point)tempPoints[tempPoints.Count - 1];
             *
             * float maxRadius = 0;
             * float newMaxRadius = 0;
             * int maxRadiusIndex = 0;
             *
             * if (isInsideCircle(latestPoint, this.groupMid, groupRadius))
             * {
             *  //MessageBox.Show("Inside");
             *  x = (int)groupMid.getX();
             *  y = (int)groupMid.getY();
             *
             *  return groupRadius;
             *
             * }
             * else
             * {
             *
             *  for (int i = 0; i < tempPoints.Count - 1; i++)
             *  {
             *      newMaxRadius = findDistance(latestPoint, (Point)tempPoints[i]);
             *
             *      if (newMaxRadius > maxRadius)
             *      {
             *          maxRadius = newMaxRadius;
             *          maxRadiusIndex = i;
             *      }
             *
             *  }
             *
             *  groupMidPoint2 = latestPoint;
             *  groupMidPoint1 = (Point)tempPoints[maxRadiusIndex];
             *  newRadiusPoint = findCenterPoint(groupMidPoint2, groupMidPoint1);
             *  newRadiusDistance = findDistance(groupMidPoint2, groupMidPoint1) / 2;
             */

            /*
             *
             * //MessageBox.Show("Outside");
             *
             * float distance1, distance2;
             *
             * distance1 = findDistance(latestPoint, groupMidPoint1);
             * distance2 = findDistance(latestPoint, groupMidPoint2);
             *
             *
             *
             * if (distance1 > distance2)
             * {
             *  newRadiusPoint = findCenterPoint(groupMidPoint1, latestPoint);
             *  newRadiusDistance = findDistance(groupMidPoint1, latestPoint) / 2;
             *
             * }
             * else
             * {
             *  newRadiusPoint = findCenterPoint(groupMidPoint2, latestPoint);
             *  newRadiusDistance = findDistance(groupMidPoint2, latestPoint) / 2;
             *  groupMidPoint1 = groupMidPoint2;
             * }
             * }
             */

            //x = (int)groupMid.getX();
            //y = (int)groupMid.getY();
            //groupRadius = (int)maxRadiusDistace/2;
            //groupMidPoint2 = latestPoint;
            #endregion

            int radiusPoint = (int)(groupRadius * (10.0 / 272.5));
            shotRadiusPoint.Add(radiusPoint);
            return(groupRadius);
        }
Esempio n. 12
0
        public void validatePoints()
        {
            tempPoints.Clear();

            int   imageX    = 0;
            int   imageY    = 0;
            float relativeX = 0;
            float relativeY = 0;
            float filterX   = 0;
            float filterY   = 0;

            Mrg.Point p         = new Mrg.Point(-1, -1);
            int       mirroredX = 0;
            int       sPointX   = 0;
            int       sPointY   = 0;

            for (int i = 0; i < shotInfo.shots.Count; i++)
            {
                //calculation for validated point

                //getting original image x, y
                p = (Mrg.Point)shotInfo.shots[i];
                string po = p.ToString();
                imageX = (int)p.getX() + 360; //335
                imageY = (int)p.getY() + 60;  //+97



                relativeX = imageX - centerX;
                relativeX = relativeX * 1.40f;//1.45

                //------------
                relativeY = imageY - centerY;
                relativeY = relativeY * 1.60f;//1.42
                imageY    = (int)relativeY + centerY;
                //------

                imageX = (int)(centerX + relativeX);
                if (imageX > centerX)
                {
                }
                else
                {
                    imageX = imageX - 15;
                }
                if (isFullScreen == true)
                {
                    imageX = (int)p.getX() + 360;     //335
                    imageY = (int)p.getY() + 60 + 43; //+97

                    relativeX = imageX - centerX;
                    relativeX = relativeX * 1.636f;//1.636
                    imageX    = (int)(centerX + relativeX);
                    //------------
                    relativeY = imageY - centerY;
                    relativeY = relativeY * 1.604f;//1.604
                    imageY    = (int)relativeY + centerY;
                    //------


                    /*
                     * Point centerPoint = new Point(0, 0);
                     * Point result = new Point(imageX - centerX, imageY - centerY);
                     * double distance = Math.Sqrt(Math.Pow((centerPoint.getX() + result.getX()), 2) + Math.Pow((centerPoint.getY() + result.getY()), 2));
                     * double angle = Angle(centerPoint.getX(), centerPoint.getY(), result.getX(), result.getY());
                     * distance = distance * 1.13f;
                     *
                     * imageX = (int)centerPoint.getX() + (int)Math.Round(distance * Math.Cos(angle));
                     * imageY = (int)centerPoint.getY() + (int)Math.Round(distance * Math.Sin(angle));
                     * //imageY += 40;
                     *
                     * imageX += centerX;
                     * imageY += centerY;
                     *
                     */
                }
                float distance = findDistance(new Mrg.Point(imageX, imageY), new Mrg.Point(centerX, centerY));
                //MessageBox.Show(distance.ToString() + ">" + radius.ToString());
                if (distance <= radius)
                {
                    tempPoints.Add(new Mrg.Point(imageX, imageY));
                    ShootPointController.getController().shotAffected = tempPoints.Count;
                    ti.setShotLabelInfo(ShootPointController.getController().shotAffected, ShootPointController.getController().shotTaken);
                }

                /*
                 * mirroredX = getMirrorX(p);
                 *
                 * relativeX = ((float)targetBoxWidth / IMAGE_WIDTH) * mirroredX;
                 * relativeY = ((float)targetBoxHeight / IMAGE_HEIGHT) * imageY;
                 *
                 * //filter x is the final x,y with paddiing added
                 *
                 * filterX = startX + relativeX;
                 * filterY = startY + relativeY;
                 *
                 * tempPoints.Add(new Point(filterX, filterY));
                 */


                //Debbug Messages
                string str = string.Format("x {0} y {1}\nrx {2} ry {3}\nfx {4} fy {5}\n", imageX.ToString(), imageY.ToString(), relativeX.ToString(), relativeY.ToString(), filterX.ToString(), filterY.ToString());
                str += string.Format("tbw {0} tbh {1} \nih {2} iw {3}\n", targetBoxWidth.ToString(), targetBoxHeight.ToString(), IMAGE_WIDTH.ToString(), IMAGE_HEIGHT.ToString());
                str += string.Format("sx {0} sy{1}\nmx{2}\n", startX.ToString(), startY.ToString(), mirroredX.ToString());
                str += string.Format("cx {0}, cy{1}", centerX.ToString(), centerY.ToString());
                //MessageBox.Show(str);
            }
        }//validate point
Esempio n. 13
0
        public Mrg.Point ProcessFrame(ref Bitmap image, out Color returnColor)
        {
            Bitmap bitmap = new Bitmap(image);

            //Bitmap bitmap = image;
            point = new Mrg.Point(-1, -1);
            //point = new AForge.Point(-1, -1);

            //currently not needed
            BitmapData bitmapData = bitmap.LockBits(
                new Rectangle(0, 0, bitmap.Width, bitmap.Height),
                ImageLockMode.ReadWrite, bitmap.PixelFormat);


            //ColorFiltering colorFilter = new ColorFiltering();


            colorFilter.FillOutsideRange = true;

            colorFilter.ApplyInPlace(bitmapData);

            bitmap.UnlockBits(bitmapData);

            //previous function findPoint()
            bool found = false;
            //bool found = true;

            Graphics g       = Graphics.FromImage(image);
            Pen      bluePen = new Pen(Color.Blue, 2);


            Color black = Color.FromArgb(0, 0, 0);


            for (int i = 120; i < 560; i += 4)// 0-120 >(tatgetbox)< 550 - inf
            {
                for (int j = 0; j < bitmap.Height; j += 5)
                {
                    c = bitmap.GetPixel(i, j);
                    //MessageBox.Show("i:" + i.ToString() + "j:" + j.ToString() + "> " + c.R.ToString() + "-" + c.G.ToString() + "-" +c.B.ToString());
                    //if ((c.R >= 150 && c.R <= 255) && (c.G >= 0 && c.G <= 255) && (c.B >= 0 && c.B <= 255))
                    if ((c.R >= colorFilter.Red.Min && c.R <= colorFilter.Red.Max) && (c.G >= colorFilter.Green.Min && c.G <= colorFilter.Green.Max) && (c.B >= colorFilter.Blue.Min && c.B <= colorFilter.Blue.Max))
                    {
                        found = true;
                        xPos  = i;
                        yPos  = j;
                        point.setXY(i, j);
                    }
                    returnColor = Color.FromArgb(255, 0, 0, 0);
                    if (found == true)
                    {
                        //g.DrawEllipse(bluePen, i - 5, j - 5, 10, 10);
                        Pen p = new Pen(Color.Yellow, 1);
                        g.DrawLine(p, 0, yPos, image.Width, yPos);  // Draw yellow horizontal line
                        g.DrawLine(p, xPos, 0, xPos, image.Height); // Draw yellow vertical line

                        Font       drawFont  = new Font("Arial", 12);
                        SolidBrush drawBrush = new SolidBrush(Color.White);
                        string     str       = "X: " + xPos.ToString() + ",   Y: " + yPos.ToString();
                        g.DrawString(str, drawFont, drawBrush, new PointF(5, 5));
                        g.Dispose();
                        break;
                    }
                }//for
                if (found == true)
                {
                    break;
                }
            }//for-main
            returnColor = c;
            return(point);
        }//func