Structure for representing a pair of coordinates of integer type.

The structure is used to store a pair of integer coordinates.

Sample usage:

// assigning coordinates in the constructor IntPoint p1 = new IntPoint( 10, 20 ); // creating a point and assigning coordinates later IntPoint p2; p2.X = 30; p2.Y = 40; // calculating distance between two points float distance = p1.DistanceTo( p2 );
        private Bitmap AddWarpEffect(ref Bitmap image)
        {
            // build warp map
            int width = image.Width;
            int height = image.Height;

            IntPoint[,] warpMap = new IntPoint[height, width];

            int size = 8;
            int maxOffset = -size + 1;

            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    int dx = (x / size) * size - x;
                    int dy = (y / size) * size - y;

                    if (dx + dy <= maxOffset)
                    {
                        dx = (x / size + 1) * size - 1 - x;
                    }

                    warpMap[y, x] = new IntPoint(dx, dy);
                }
            }
            // create filter
            ImageWarp filter = new ImageWarp(warpMap);
            // apply the filter
            Bitmap newImage = filter.Apply(image);
            return newImage;
        }
Example #2
0
        /// <summary>
        /// Get bounding rectangle of the specified list of points.
        /// </summary>
        /// 
        /// <param name="cloud">Collection of points to get bounding rectangle for.</param>
        /// <param name="minXY">Point comprised of smallest X and Y coordinates.</param>
        /// <param name="maxXY">Point comprised of biggest X and Y coordinates.</param>
        /// 
        public static void GetBoundingRectangle( IEnumerable<IntPoint> cloud, out IntPoint minXY, out IntPoint maxXY )
        {
            int minX = int.MaxValue;
            int maxX = int.MinValue;
            int minY = int.MaxValue;
            int maxY = int.MinValue;

            foreach ( IntPoint pt in cloud )
            {
                int x = pt.X;
                int y = pt.Y;

                // check X coordinate
                if ( x < minX )
                    minX = x;
                if ( x > maxX )
                    maxX = x;

                // check Y coordinate
                if ( y < minY )
                    minY = y;
                if ( y > maxY )
                    maxY = y;
            }

            if ( minX > maxX ) // if no point appeared to set either minX or maxX
                throw new ArgumentException( "List of points can not be empty." );

            minXY = new IntPoint( minX, minY );
            maxXY = new IntPoint( maxX, maxY );
        }
Example #3
0
        public void RoundTest( double x, double y, int expectedX, int expectedY )
        {
            DoublePoint dPoint = new DoublePoint( x, y );
            IntPoint    iPoint = new IntPoint( expectedX, expectedY );

            Assert.AreEqual( iPoint, dPoint.Round( ) );
        }
Example #4
0
 /// <summary>
 /// Shift cloud by adding specified value to all points in the collection.
 /// </summary>
 /// 
 /// <param name="cloud">Collection of points to shift their coordinates.</param>
 /// <param name="shift">Point to shift by.</param>
 /// 
 public static void Shift( IList<IntPoint> cloud, IntPoint shift )
 {
     for ( int i = 0, n = cloud.Count; i < n; i++ )
     {
         cloud[i] = cloud[i] + shift;
     }
 }
Example #5
0
        public void RoundTest( float x, float y, int expectedX, int expectedY )
        {
            Point point = new Point( x, y );
            IntPoint iPoint = new IntPoint( expectedX, expectedY );

            Assert.AreEqual( iPoint, point.Round( ) );
        }
        private void initTracking(Image <Bgr, byte> frame)
        {
            initializeKalman(roi.Center());

            //get hue channel from search area
            var hsvImg = frame.Convert <Hsv, byte>(); //<<parallel operation>>
            //user constraints...

            Image <Gray, byte> mask = hsvImg.InRange(new Hsv(0, 0, minV), new Hsv(0, 0, maxV), Byte.MaxValue, 2);

            originalObjHist.Calculate(hsvImg.GetSubRect(roi).SplitChannels(0, 1), false, mask.GetSubRect(roi));
            originalObjHist.Scale((float)1 / roi.Area());
            //originalObjHist.Normalize(Byte.MaxValue);

            var backgroundArea = roi.Inflate(1.5, 1.5, frame.Size);
            var backgroundMask = mask.GetSubRect(backgroundArea).Clone();

            backgroundMask.GetSubRect(new Rectangle(Point.Subtract(roi.Location, backgroundArea.Location), roi.Size)).SetValue(0);

            backgroundHist.Calculate(hsvImg.GetSubRect(backgroundArea).SplitChannels(0, 1), false, mask.GetSubRect(backgroundArea));
            backgroundHist.Scale((float)1 / (backgroundArea.Area() - roi.Area()));
            //backgroundHist.Normalize(Byte.MaxValue);

            //how good originalObjHist and objHist match (suppresses possible selected background)
            ratioHist = originalObjHist.CreateRatioHistogram(backgroundHist, Byte.MaxValue, 3);

            searchArea = roi;
            roi        = Rectangle.Empty;
        }
Example #7
0
        /// <summary>
        /// Calculate Euclidean distance between two points.
        /// </summary>
        /// 
        /// <param name="anotherPoint">Point to calculate distance to.</param>
        /// 
        /// <returns>Returns Euclidean distance between this point and
        /// <paramref name="anotherPoint"/> points.</returns>
        /// 
        public float DistanceTo( IntPoint anotherPoint )
        {
            int dx = X - anotherPoint.X;
            int dy = Y - anotherPoint.Y;

            return (float) System.Math.Sqrt( dx * dx + dy * dy );
        }
Example #8
0
        public static void GridInPlace(Bitmap img, uint rows, uint cols, Color colour)
        {
            //Lock image for read write so we can alter it
            BitmapData imgData = img.LockBits(new Rectangle(0, 0, img.Width, img.Height),
                ImageLockMode.ReadWrite, img.PixelFormat);

            //Draw lines at regular intervals along the image both vertically & horizontally
            //TODO: Fix bug where sometimes draws a line at the end, other times doesn't (because of double precision)
            double colWidth = img.Width / (double)cols;
            for (double i = colWidth; i < img.Width; i += colWidth)
            {
                IntPoint p1 = new IntPoint((int)i, 0);
                IntPoint p2 = new IntPoint((int)i, img.Height);
                Drawing.Line(imgData, p1, p2, colour);
            }

            double rowHeight = img.Height / (double)rows;
            for (double i = rowHeight; i < img.Height; i += rowHeight)
            {
                IntPoint p1 = new IntPoint(0, (int)i);
                IntPoint p2 = new IntPoint(img.Width, (int)i);
                Drawing.Line(imgData, p1, p2, colour);
            }

            img.UnlockBits(imgData);
        }
Example #9
0
        /// <summary>
        /// Calculate Euclidean distance between two points.
        /// </summary>
        /// 
        /// <param name="anotherPoint">Point to calculate distance to.</param>
        /// 
        /// <returns>Returns Euclidean distance between this point and
        /// <paramref name="anotherPoint"/> points.</returns>
        /// 
        public double DistanceTo( IntPoint anotherPoint )
        {
            int dx = X - anotherPoint.X;
            int dy = Y - anotherPoint.Y;

            return System.Math.Sqrt( dx * dx + dy * dy );
        }
        public void InequalityOperatorTest( int x1, int y1, int x2, int y2, bool areNotEqual )
        {
            IntPoint point1 = new IntPoint( x1, y1 );
            IntPoint point2 = new IntPoint( x2, y2 );

            Assert.AreEqual( point1 != point2, areNotEqual );
        }
Example #11
0
        private void initTracking(Bgr <byte>[,] frame)
        {
            initializeKalman(roi.Center());

            //get hue channel from search area
            var hsvImg = frame.ToHsv();

            //user constraints...

            Gray <byte>[,] mask = hsvImg.InRange(new Hsv <byte>(0, 0, (byte)minV), new Hsv <byte>(0, 0, (byte)maxV), Byte.MaxValue, 2);

            originalObjHist.Calculate(hsvImg.SplitChannels <Hsv <byte>, byte>(roi, 0, 1), false, mask, roi.Location);
            originalObjHist.Scale((float)1 / roi.Area());
            //originalObjHist.Normalize(Byte.MaxValue);

            var backgroundArea = roi.Inflate(1.5, 1.5, frame.Size());
            var backgroundMask = mask.Clone(backgroundArea);

            backgroundMask.SetValue <Gray <byte> >(0, new Rectangle(Point.Subtract(roi.Location, backgroundArea.Location), roi.Size));

            backgroundHist.Calculate(hsvImg.SplitChannels <Hsv <byte>, byte>(backgroundArea, 0, 1), false, mask, backgroundArea.Location);
            backgroundHist.Scale((float)1 / (backgroundArea.Area() - roi.Area()));
            //backgroundHist.Normalize(Byte.MaxValue);

            //how good originalObjHist and objHist match (suppresses possible selected background)
            ratioHist = originalObjHist.CreateRatioHistogram(backgroundHist, Byte.MaxValue, 3);

            searchArea = roi;
            roi        = Rectangle.Empty;
        }
 /// <summary>
 /// Negates point coordinates.
 /// </summary>
 /// <param name="point">The point to negate.</param>
 /// <returns>Point with negated coordinates.</returns>
 public static Point Negate(this Point point)
 {
     return(new Point
     {
         X = -point.X,
         Y = -point.Y
     });
 }
 /// <summary>
 /// Clamps point coordinate according to the specified size (0,0, size.Width, size.Height).
 /// </summary>
 /// <param name="point">The point to clamp.</param>
 /// <param name="size">The valid region.</param>
 /// <returns>Clamped point.</returns>
 public static Point Clamp(this Point point, Size size)
 {
     return(new Point
     {
         X = System.Math.Min(System.Math.Max(0, point.X), size.Width),
         Y = System.Math.Min(System.Math.Max(0, point.Y), size.Height)
     });
 }
Example #14
0
 public void Add(IntPoint point)
 {
     if (Points.Count != 0)
     {
         Length += point.DistanceTo(Points.Last());
     }
     Points.Add(point);
 }
 /// <summary>
 /// Clamps point coordinate according to the specified size (rect.X, rect.Y, rect.Right, rect.Bottom).
 /// </summary>
 /// <param name="point">The point to clamp.</param>
 /// <param name="rect">The valid region.</param>
 /// <returns>Clamped point.</returns>
 public static Point Clamp(this Point point, Rectangle rect)
 {
     return(new Point
     {
         X = System.Math.Min(System.Math.Max(rect.X, point.X), rect.Right),
         Y = System.Math.Min(System.Math.Max(rect.Y, point.Y), rect.Bottom)
     });
 }
Example #16
0
        public void TestEuclideanDistance1()
        {
            //Basic test
            IntPoint a = new IntPoint(1, 1);
            IntPoint b = new IntPoint(2, 2);

            double distance = Geometry.EuclideanDistance(a, b);
            Assert.AreEqual(Math.Sqrt(2), distance);
        }
Example #17
0
        public void TestEuclideanDistance5()
        {
            //0 distance / points equal
            IntPoint a = new IntPoint(0, 0);
            IntPoint b = new IntPoint(0, 0);

            double distance = Geometry.EuclideanDistance(a, b);
            Assert.AreEqual(0, distance);
        }
Example #18
0
        public void TestEuclideanDistance4()
        {
            //Negative coordinates
            IntPoint a = new IntPoint(-1, -1);
            IntPoint b = new IntPoint(-2, -2);

            double distance = Geometry.EuclideanDistance(a, b);
            Assert.AreEqual(Math.Sqrt(2), distance);
        }
Example #19
0
        public void TestEuclideanDistance3()
        {
            //Non-unit lengths test
            IntPoint a = new IntPoint(324, 12);
            IntPoint b = new IntPoint(12, 123);

            double distance = Geometry.EuclideanDistance(a, b);
            Assert.AreEqual(3 * Math.Sqrt(12185), distance);
        }
Example #20
0
        public void TestEuclideanDistance2()
        {
            //Parameter order doesn't matter
            IntPoint a = new IntPoint(2, 2);
            IntPoint b = new IntPoint(1, 1);

            double distance = Geometry.EuclideanDistance(a, b);
            Assert.AreEqual(Math.Sqrt(2), distance);
        }
Example #21
0
        public static double AreaQuadrilateral(IntPoint[] points)
        {
            if(!IsQuadrilateral(points))
            {
                throw new InvalidShapeException("Expected Quadrilateral");
            }

            return Area(points[0], points[1], points[2], points[3]);
        }
Example #22
0
        public void GetAngleBetweenVectorsTest( int sx, int sy, int ex1, int ey1, int ex2, int ey2, float expectedAngle )
        {
            IntPoint startPoint = new IntPoint( sx, sy );
            IntPoint vector1end = new IntPoint( ex1, ey1 );
            IntPoint vector2end = new IntPoint( ex2, ey2 );

            float angle = GeometryTools.GetAngleBetweenVectors( startPoint, vector1end, vector2end );

            Assert.AreApproximatelyEqual<float, float>( expectedAngle,  angle, 0.00001f );
        }
Example #23
0
 public void dessinePoint(IntPoint point, UnmanagedImage img,int nbPixel,Color col)
 {
     for (int i = point.X - nbPixel / 2; i < point.X + nbPixel / 2 + 1; i++)
     {
         for (int j = point.Y - nbPixel / 2; j < point.Y + nbPixel / 2 + 1; j++)
         {
             img.SetPixel(i, j, col);
         }
     }
 }
Example #24
0
        public void GetAngleBetweenLinesTest( int sx1, int sy1, int ex1, int ey1, int sx2, int sy2, int ex2, int ey2, float expectedAngle )
        {
            IntPoint line1start = new IntPoint( sx1, sy1 );
            IntPoint line1end   = new IntPoint( ex1, ey1 );
            IntPoint line2start = new IntPoint( sx2, sy2 );
            IntPoint line2end   = new IntPoint( ex2, ey2 );

            float angle = GeometryTools.GetAngleBetweenLines( line1start, line1end, line2start, line2end );

            Assert.AreApproximatelyEqual<float, float>( expectedAngle, angle, 0.00001f );
        }
Example #25
0
        private Suit suit; //Suit of card

        #endregion Fields

        #region Constructors

        //Constructor
        public Card(Bitmap cardImg, IntPoint[] cornerIntPoints)
        {
            this.image = cardImg;

            //Convert AForge.IntPoint Array to System.Drawing.Point Array
            int total = cornerIntPoints.Length;
            corners = new Point[total];

            for(int i = 0 ; i < total ; i++)
            {
                this.corners[i].X = cornerIntPoints[i].X;
                this.corners[i].Y = cornerIntPoints[i].Y;
            }
        }
Example #26
0
        //calculating rotation angle (form the law of cosines)
        public int calculateRotateAngle(List<IntPoint> blobCorners, List<IntPoint> frameCorners)
        {
            IntPoint center = new IntPoint(frameCorners[2].X/2, frameCorners[2].Y/2);
            float a = Math.Abs(blobCorners[1].DistanceTo(frameCorners[1]));
            float b = Math.Abs(blobCorners[1].DistanceTo(center));
            float c = Math.Abs(frameCorners[1].DistanceTo(center));

            float cosAlpha = (-1)*(a * a - b * b - c * c) / (2 * b * c);

            int angle = (int)Math.Acos(cosAlpha);

              //  if (blobCorners[0].Y > blobCorners[1].Y) angle = angle * (-1);

            return angle;
        }
Example #27
0
        private Suit suit; //Suit of card

        #endregion Fields

        #region Constructors

        //Constructor
        public Card(Bitmap cardImg, IntPoint[] cornerIntPoints)
        {
            //This has nothing to do with the rest of the framework, so it can be refactored
            this.image = cardImg;

            //Convert AForge.IntPoint Array to System.Drawing.Point Array
            int total = cornerIntPoints.Length;
            corners = new AForge.Point[total];

            for (int i = 0; i < total; i++)
            {
                this.corners[i].X = cornerIntPoints[i].X;
                this.corners[i].Y = cornerIntPoints[i].Y;
            }
        }
Example #28
0
        void CamProc_NewTargetPosition(IntPoint Center, System.Drawing.Bitmap image)
        {
            IntPtr hBitMap = image.GetHbitmap();
            BitmapSource bmaps = Imaging.CreateBitmapSourceFromHBitmap(hBitMap, IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
            bmaps.Freeze();
            Dispatcher.Invoke((Action)(() =>
            {

                if (Center.X > 0)
                {
                    try
                    {

                        prova.Content = String.Format("   Codigo: {0}", Center.X);
                        item.Content = String.Format(" NÂș Itens: {0}", Center.Y);
                        TextReader respostas = new StreamReader(@"" + Center.X + ".txt");
                        string R_1 = respostas.ReadLine();
                        string R_2 = respostas.ReadLine();
                        string R_3 = respostas.ReadLine();
                        string R_4 = respostas.ReadLine();
                        string R_5 = respostas.ReadLine();
                        string R_6 = respostas.ReadLine();
                        string R_7 = respostas.ReadLine();
                        string R_8 = respostas.ReadLine();
                        string R_9 = respostas.ReadLine();
                        string R_0 = respostas.ReadLine();
                        item1.Content = String.Format(" Item 01: {0}", R_1);
                        item2.Content = String.Format(" Item 02: {0}", R_2);
                        item3.Content = String.Format(" Item 03: {0}", R_3);
                        item4.Content = String.Format(" Item 04: {0}", R_4);
                        item5.Content = String.Format(" Item 05: {0}", R_5);
                        item6.Content = String.Format(" Item 06: {0}", R_6);
                        item7.Content = String.Format(" Item 07: {0}", R_7);
                        item8.Content = String.Format(" Item 08: {0}", R_8);
                        item9.Content = String.Format(" Item 09: {0}", R_9);
                        item10.Content = String.Format(" Item 10: {0}", R_0);
                        string resps = R_1 + ";" + R_2 + ";" + R_3 + ";" + R_4 + ";" + R_5 + ";" + R_6 + ";" + R_7 + ";" + R_8 + ";" + R_9 + ";" + R_0;

                        refer.Content = String.Format("todas: {0}", resps);
                        conexao((int)Center.X, resps);
                        respostas.Close();
                    }
                    catch { }
                }
                pictureBoxMain.Source = bmaps;
            }), DispatcherPriority.Render, null);
            DeleteObject(hBitMap);
        }
Example #29
0
        private void pictureBox_MouseMove(object sender, MouseEventArgs e)
        {
            if (e.Button != MouseButtons.Left)
            {
                return;
            }

            Point ptSecond = e.Location.ToPt();

            roi = new Rectangle
            {
                X      = System.Math.Min(ptFirst.X, ptSecond.X),
                Y      = System.Math.Min(ptFirst.Y, ptSecond.Y),
                Width  = System.Math.Abs(ptFirst.X - ptSecond.X),
                Height = System.Math.Abs(ptFirst.Y - ptSecond.Y)
            };
        }
Example #30
0
        //Draws a solution onto a Bitmap, using a specified Segmentation to split the image into characters.
        //  Draws each line from the centre of each segmentation cell
        public static void SolutionInPlace(Bitmap img, Segmentation segmentation, Solution solution, Color colour)
        {
            //Validation: Check that the image dimensions & segmentation dimensions match
            if (img.Width != segmentation.Width || img.Height != segmentation.Height)
            {
                throw new ArgumentException("Bitmap dimensions do not match Segmentation dimensions");
            }

            //Work out the centre point for each character
            IntPoint[,] charCentres = new IntPoint[segmentation.NumCols, segmentation.NumRows];
            for(int i = 0; i < segmentation.NumCols; i++)
            {
                int colStart = (i == 0) ? 0 : segmentation.Cols[i - 1];
                int colEnd = (i == segmentation.NumCols - 1) ? segmentation.Width : segmentation.Cols[i];
                int colCentre = (int)Math.Round((((double)colEnd - colStart) / 2) + colStart);

                for(int j = 0; j < segmentation.NumRows; j++)
                {
                    int rowStart = (j == 0) ? 0 : segmentation.Rows[j - 1];
                    int rowEnd = (j == segmentation.NumRows - 1) ? segmentation.Height : segmentation.Rows[j];
                    int rowCentre = (int)Math.Round(rowStart + (((double)rowEnd - rowStart) / 2));

                    charCentres[i, j] = new IntPoint(colCentre, rowCentre);
                }
            }

            //Lock the image for write so we can alter it
            BitmapData imgData = img.LockBits(new Rectangle(0, 0, img.Width, img.Height),
                ImageLockMode.WriteOnly, img.PixelFormat);

            //Draw on the word positions
            foreach (WordPosition position in solution.Values)
            {
                IntPoint startPoint = charCentres[position.StartCol, position.StartRow];
                IntPoint endPoint = charCentres[position.EndCol, position.EndRow];

                Drawing.Line(imgData, startPoint, endPoint, colour);
            }

            img.UnlockBits(imgData);
        }
Example #31
0
        //Calculates the area of an arbitrary polygon using the Shoelace algorithm http://en.wikipedia.org/wiki/Shoelace_formula
        public static double Area(IntPoint[] points)
        {
            //There must be at least 3 points in any shape with an area
            if(points.Length < 3)
            {
                throw new InvalidShapeException("A shape requires at least 3 points in order to have an Area");
            }

            //Order the points before computing the area (since the algorithm requires them to be ordered)
            IntPoint[] clockwisePoints = SortPointsClockwise(points);

            ulong sumA = 0;
            ulong sumB = 0;
            for(int i = 0; i < clockwisePoints.Length - 1; i++)
            {
                sumA += (ulong)(clockwisePoints[i].X * clockwisePoints[i + 1].Y);
                sumB += (ulong)(clockwisePoints[i + 1].X * clockwisePoints[i].Y);
            }
            sumA += (ulong)(clockwisePoints[clockwisePoints.Length - 1].X * clockwisePoints[0].Y);
            sumB += (ulong)(clockwisePoints[0].X * clockwisePoints[clockwisePoints.Length - 1].Y);

            //Because the points are ordered clockwise, sumB will always be greater than sumA so for half their difference we don't need to check for neg
            return (double)(sumB - sumA) / 2;
        }
Example #32
0
 public static System.Drawing.Point ToGDIPoint(this AForge.IntPoint point)
 {
     return(new System.Drawing.Point(point.X, point.Y));
 }
Example #33
0
        /// <summary>
        /// Find the furthest point from the specified line.
        /// </summary>
        /// 
        /// <param name="cloud">Collection of points to search furthest points in.</param>
        /// <param name="linePoint1">First point forming the line.</param>
        /// <param name="linePoint2">Second point forming the line.</param>
        /// <param name="distance">Distance between the furthest found point and the given line.</param>
        /// 
        /// <returns>Returns a point, which is the furthest away from the
        /// specified line.</returns>
        /// 
        /// <remarks><para>The method finds the furthest point from the specified line.
        /// Unlike the <see cref="GetFurthestPointsFromLine( IEnumerable{IntPoint}, IntPoint, IntPoint, out IntPoint, out float, out IntPoint, out float )"/>
        /// method, this method find only one point, which is the furthest away from the line
        /// regardless of side from the line.</para></remarks>
        ///
        public static IntPoint GetFurthestPointFromLine( IEnumerable<IntPoint> cloud, IntPoint linePoint1, IntPoint linePoint2, out float distance )
        {
            IntPoint furthestPoint = linePoint1;
            distance = 0;

            if ( linePoint2.X != linePoint1.X )
            {
                // line's equation y(x) = k * x + b
                float k = (float) ( linePoint2.Y - linePoint1.Y ) / ( linePoint2.X - linePoint1.X );
                float b = linePoint1.Y - k * linePoint1.X;

                float div = (float) System.Math.Sqrt( k * k + 1 );
                float pointDistance = 0;

                foreach ( IntPoint point in cloud )
                {
                    pointDistance = System.Math.Abs( ( k * point.X + b - point.Y ) / div );

                    if ( pointDistance > distance )
                    {
                        distance = pointDistance;
                        furthestPoint = point;
                    }
                }
            }
            else
            {
                int lineX = linePoint1.X;
                float pointDistance = 0;

                foreach ( IntPoint point in cloud )
                {
                    distance = System.Math.Abs( lineX - point.X );

                    if ( pointDistance > distance )
                    {
                        distance = pointDistance;
                        furthestPoint = point;
                    }
                }
            }

            return furthestPoint;
        }
Example #34
0
        /// <summary>
        /// Find the furthest point from the specified line.
        /// </summary>
        /// 
        /// <param name="cloud">Collection of points to search furthest point in.</param>
        /// <param name="linePoint1">First point forming the line.</param>
        /// <param name="linePoint2">Second point forming the line.</param>
        /// 
        /// <returns>Returns a point, which is the furthest away from the
        /// specified line.</returns>
        /// 
        /// <remarks><para>The method finds the furthest point from the specified line.
        /// Unlike the <see cref="GetFurthestPointsFromLine( IEnumerable{IntPoint}, IntPoint, IntPoint, out IntPoint, out IntPoint )"/>
        /// method, this method find only one point, which is the furthest away from the line
        /// regardless of side from the line.</para></remarks>
        ///
        public static IntPoint GetFurthestPointFromLine( IEnumerable<IntPoint> cloud, IntPoint linePoint1, IntPoint linePoint2 )
        {
            float d;

            return GetFurthestPointFromLine( cloud, linePoint1, linePoint2, out d );
        }
Example #35
0
        /// <summary>
        /// Find two furthest points from the specified line.
        /// </summary>
        /// 
        /// <param name="cloud">Collection of points to search furthest points in.</param>
        /// <param name="linePoint1">First point forming the line.</param>
        /// <param name="linePoint2">Second point forming the line.</param>
        /// <param name="furthestPoint1">First found furthest point.</param>
        /// <param name="distance1">Distance between the first found point and the given line.</param>
        /// <param name="furthestPoint2">Second found furthest point (which is on the
        /// opposite side from the line compared to the <paramref name="furthestPoint1"/>);</param>
        /// <param name="distance2">Distance between the second found point and the given line.</param>
        /// 
        /// <remarks><para>The method finds two furthest points from the specified line,
        /// where one point is on one side from the line and the second point is on
        /// another side from the line.</para></remarks>
        ///
        public static void GetFurthestPointsFromLine( IEnumerable<IntPoint> cloud, IntPoint linePoint1, IntPoint linePoint2,
            out IntPoint furthestPoint1, out float distance1, out IntPoint furthestPoint2, out float distance2 )
        {
            furthestPoint1 = linePoint1;
            distance1 = 0;

            furthestPoint2 = linePoint2;
            distance2 = 0;

            if ( linePoint2.X != linePoint1.X )
            {
                // line's equation y(x) = k * x + b
                float k = (float) ( linePoint2.Y - linePoint1.Y ) / ( linePoint2.X - linePoint1.X );
                float b = linePoint1.Y - k * linePoint1.X;

                float div = (float) System.Math.Sqrt( k * k + 1 );
                float distance = 0;

                foreach ( IntPoint point in cloud )
                {
                    distance = ( k * point.X + b - point.Y ) / div;

                    if ( distance > distance1 )
                    {
                        distance1 = distance;
                        furthestPoint1 = point;
                    }
                    if ( distance < distance2 )
                    {
                        distance2 = distance;
                        furthestPoint2 = point;
                    }
                }
            }
            else
            {
                int lineX = linePoint1.X;
                float distance = 0;

                foreach ( IntPoint point in cloud )
                {
                    distance = lineX - point.X;

                    if ( distance > distance1 )
                    {
                        distance1 = distance;
                        furthestPoint1 = point;
                    }
                    if ( distance < distance2 )
                    {
                        distance2 = distance;
                        furthestPoint2 = point;
                    }
                }
            }

            distance2 = -distance2;
        }
Example #36
0
        /// <summary>
        /// Find two furthest points from the specified line.
        /// </summary>
        /// 
        /// <param name="cloud">Collection of points to search furthest points in.</param>
        /// <param name="linePoint1">First point forming the line.</param>
        /// <param name="linePoint2">Second point forming the line.</param>
        /// <param name="furthestPoint1">First found furthest point.</param>
        /// <param name="furthestPoint2">Second found furthest point (which is on the
        /// opposite side from the line compared to the <paramref name="furthestPoint1"/>);</param>
        /// 
        /// <remarks><para>The method finds two furthest points from the specified line,
        /// where one point is on one side from the line and the second point is on
        /// another side from the line.</para></remarks>
        /// 
        public static void GetFurthestPointsFromLine( IEnumerable<IntPoint> cloud, IntPoint linePoint1, IntPoint linePoint2,
            out IntPoint furthestPoint1, out IntPoint furthestPoint2 )
        {
            float d1, d2;

            GetFurthestPointsFromLine( cloud, linePoint1, linePoint2,
                out furthestPoint1, out d1, out furthestPoint2, out d2 );
        }
Example #37
0
        /// <summary>
        /// Find furthest point from the specified point.
        /// </summary>
        /// 
        /// <param name="cloud">Collection of points to search furthest point in.</param>
        /// <param name="referencePoint">The point to search furthest point from.</param>
        /// 
        /// <returns>Returns a point, which is the furthest away from the <paramref name="referencePoint"/>.</returns>
        /// 
        public static IntPoint GetFurthestPoint( IEnumerable<IntPoint> cloud, IntPoint referencePoint )
        {
            IntPoint furthestPoint = referencePoint;
            float maxDistance = -1;

            int rx = referencePoint.X;
            int ry = referencePoint.Y;

            foreach ( IntPoint point in cloud )
            {
                int dx = rx - point.X;
                int dy = ry - point.Y;
                // we are not calculating square root for finding "real" distance,
                // since it is really not important for finding furthest point
                float distance = dx * dx + dy * dy;

                if ( distance > maxDistance )
                {
                    maxDistance = distance;
                    furthestPoint = point;
                }
            }

            return furthestPoint;
        }
Example #38
0
 private void pictureBox_MouseDown(object sender, MouseEventArgs e)
 {
     ptFirst       = e.Location.ToPt();
     isROISelected = false;
 }