/// <summary>
        /// Check if submatrix ranges indices are valid.
        /// Rows and columns are indicated counting from 0 to n-1.
        /// </summary>
        /// <param name="m">Matrix.</param>
        /// <param name="selectedRows">Array of row indices.</param>
        /// <param name="selectedColumns">Array of column indices.</param>
        /// <exception cref="NullArgumentException"> if <c>selectedRows</c> or
        /// <c>selectedColumns</c> are <c>null</c>.</exception>
        /// <exception cref="NoDataException"> if the row or column selections are empty (zero
        /// length).</exception>
        /// <exception cref="OutOfRangeException"> if row or column selections are not valid.
        /// </exception>
        public static void checkSubMatrixIndex(AnyMatrix m, int[] selectedRows, int[] selectedColumns)
        {
            if (selectedRows == null)
            {
                throw new NullArgumentException();
            }
            if (selectedColumns == null)
            {
                throw new NullArgumentException();
            }
            if (selectedRows.Length == 0)
            {
                throw new NoDataException(new LocalizedFormats("EMPTY_SELECTED_ROW_INDEX_ARRAY"));
            }
            if (selectedColumns.Length == 0)
            {
                throw new NoDataException(new LocalizedFormats("EMPTY_SELECTED_COLUMN_INDEX_ARRAY"));
            }

            foreach (int row in selectedRows)
            {
                checkRowIndex(m, row);
            }
            foreach (int column in selectedColumns)
            {
                checkColumnIndex(m, column);
            }
        }
 /// <summary>
 /// Check if a column index is valid.
 /// </summary>
 /// <param name="m">Matrix.</param>
 /// <param name="column">Column index to check.</param>
 /// <exception cref="OutOfRangeException"> if <c>column</c> is not a valid index.
 /// </exception>
 public static void checkColumnIndex(AnyMatrix m, int column)
 {
     if (column < 0 || column >= m.getColumnDimension())
     {
         throw new OutOfRangeException <Int32>(new LocalizedFormats("COLUMN_INDEX"), column, 0, m.getColumnDimension() - 1);
     }
 }
 /// <summary>
 /// Check if matrices are multiplication compatible
 /// </summary>
 /// <param name="left">Left hand side matrix.</param>
 /// <param name="right">Right hand side matrix.</param>
 /// <exception cref="DimensionMismatchException"> if matrices are not multiplication
 /// compatible.</exception>
 public static void checkMultiplicationCompatible(AnyMatrix left, AnyMatrix right)
 {
     if (left.getColumnDimension() != right.getRowDimension())
     {
         throw new DimensionMismatchException(left.getColumnDimension(),
                                              right.getRowDimension());
     }
 }
 /// <summary>
 /// Check if a row index is valid.
 /// </summary>
 /// <param name="m">Matrix.</param>
 /// <param name="row">Row index to check.</param>
 /// <exception cref="OutOfRangeException"> if <c>row</c> is not a valid index.</exception>
 public static void checkRowIndex(AnyMatrix m, int row)
 {
     if (row < 0 ||
         row >= m.getRowDimension())
     {
         throw new OutOfRangeException <Int32>(new LocalizedFormats("ROW_INDEX"), row, 0, m.getRowDimension() - 1);
     }
 }
 /// <summary>
 /// Check if matrices are subtraction compatible
 /// </summary>
 /// <param name="left">Left hand side matrix.</param>
 /// <param name="right">Right hand side matrix.</param>
 /// <exception cref="MatrixDimensionMismatchException"> if the matrices are not addition
 /// compatible.</exception>
 public static void checkSubtractionCompatible(AnyMatrix left, AnyMatrix right)
 {
     if ((left.getRowDimension() != right.getRowDimension()) ||
         (left.getColumnDimension() != right.getColumnDimension()))
     {
         throw new MatrixDimensionMismatchException(left.getRowDimension(), left.getColumnDimension(),
                                                    right.getRowDimension(), right.getColumnDimension());
     }
 }
        /// <summary>
        /// Check if submatrix ranges indices are valid.
        /// Rows and columns are indicated counting from 0 to <c>n - 1</c>.
        /// </summary>
        /// <param name="m">Matrix.</param>
        /// <param name="startRow">Initial row index.</param>
        /// <param name="endRow">Final row index.</param>
        /// <param name="startColumn">Initial column index.</param>
        /// <param name="endColumn">Final column index.</param>
        /// <exception cref="OutOfRangeException"> if the indices are invalid.</exception>
        /// <exception cref="NumberIsTooSmallException"> if <c>endRow < startRow</c> or
        /// <c>endColumn < startColumn</c>.</exception>
        public static void checkSubMatrixIndex(AnyMatrix m, int startRow, int endRow, int startColumn, int endColumn)
        {
            checkRowIndex(m, startRow);
            checkRowIndex(m, endRow);
            if (endRow < startRow)
            {
                throw new NumberIsTooSmallException <Int32, Int32>(new LocalizedFormats("INITIAL_ROW_AFTER_FINAL_ROW"), endRow, startRow, false);
            }

            checkColumnIndex(m, startColumn);
            checkColumnIndex(m, endColumn);
            if (endColumn < startColumn)
            {
                throw new NumberIsTooSmallException <Int32, Int32>(new LocalizedFormats("INITIAL_COLUMN_AFTER_FINAL_COLUMN"), endColumn, startColumn, false);
            }
        }
예제 #7
0
        static public List <int> GetAreas(MyByteColor[,] src, int w, int h, ProgressBar p1, int MinSize, Rectangle r, PictureBox main, double dydx, double PatLength)
        {
            p1.Value = 0;
            int pvalue = 0;

            int        AreaToadd;
            List <int> answ = new List <int>();

            bool[,] Visited = new bool[w, h];
            int xst, xfin, yst, yfin;

            if (r.Bottom == -2)
            {
                xst  = yst = 0;
                xfin = w;
                yfin = h;
            }
            else
            {
                xst  = Math.Max(0, r.Left);
                xfin = Math.Min(w, r.Right);
                yst  = Math.Max(r.Top, 0);
                yfin = Math.Min(r.Bottom, h);
            }
            p1.Maximum = (xfin - xst + 1) / 10;
            List <MyShortPoint> Boundary = new List <MyShortPoint>();

            for (int x = xst; x < xfin; x++)
            {
                for (int y = yst; y < yfin; y++)
                {
                    if (src[x, y].R == 255 && src[x, y].G == 0 && src[x, y].B == 0)
                    {
                        continue;
                    }
                    if (src[x, y].R == 0 && src[x, y].G == 0 && src[x, y].B == 0)
                    {
                        continue;
                    }
                    Boundary.Clear();
                    AreaToadd = AreaCalculator.GetArea(Visited, src, x, y, w, h, Boundary);

                    int index = 0;
                    if (AreaToadd >= MinSize)
                    {
                        //      answ.Add(AreaToadd);
                        AnyMatrix <Double> E = ValueGetter.GetBestFitEllipse(Boundary);

                        double[] a = new double[6];
                        for (int i = 0; i < 6; i++)
                        {
                            a[i] = E[i, 0];
                        }
                        a[1] /= 2;
                        a[3] /= 2;
                        a[4] /= 2;
                        if ((a[1] * a[1] - a[0] * a[2]) == 0)
                        {
                            continue;
                        }
                        if ((a[0] - a[2]) * (a[0] - a[2]) + 4 * a[1] * a[1] < 0)
                        {
                            continue;
                        }
                        if ((a[0] * a[4] * a[4] + a[2] * a[3] * a[3] + a[5] * a[1] * a[1] - 2 * a[1] * a[3] * a[4] - a[0] * a[2] * a[5]) / ((a[1] * a[1] - a[0] * a[2]) * (Math.Sqrt((a[0] - a[2]) * (a[0] - a[2]) + 4 * a[1] * a[1]) - (a[0] + a[2]))) < 0)
                        {
                            continue;
                        }
                        double     a1 = 2 * Math.Sqrt(2 * (a[0] * a[4] * a[4] + a[2] * a[3] * a[3] + a[5] * a[1] * a[1] - 2 * a[1] * a[3] * a[4] - a[0] * a[2] * a[5]) / ((a[1] * a[1] - a[0] * a[2]) * (Math.Sqrt((a[0] - a[2]) * (a[0] - a[2]) + 4 * a[1] * a[1]) - (a[0] + a[2]))));
                        double     a2 = 2 * Math.Sqrt(2 * (a[0] * a[4] * a[4] + a[2] * a[3] * a[3] + a[5] * a[1] * a[1] - 2 * a[1] * a[3] * a[4] - a[0] * a[2] * a[5]) / ((a[1] * a[1] - a[0] * a[2]) * (-Math.Sqrt((a[0] - a[2]) * (a[0] - a[2]) + 4 * a[1] * a[1]) - (a[0] + a[2]))));
                        PictureBox p  = (PictureBox)PictureBox.FromHandle(MainForm.MPicture);
                        double     dx = 1.0 * p.Image.Width / p.Size.Width;
                        double     dy = 1.0 * p.Image.Height / p.Size.Height;
                        a1 /= dx;
                        a2 /= dy;
                        //get Angle--------------------------
                        double fi = 0;
                        if (a[1] == 0 && a[0] < a[2])
                        {
                            fi = 0;
                        }
                        if (a[1] == 0 && a[0] >= a[2])
                        {
                            fi = Math.PI / 2;
                        }
                        if (a[1] != 0 && a[0] < a[2])
                        {
                            fi = 1.0 / 2 * (Math.PI / 2 - Math.Atan((a[0] - a[2]) / a[1]));
                        }
                        if (a[1] != 0 && a[0] >= a[2])
                        {
                            fi = 1.0 / 2 * (Math.PI - Math.Atan((a[0] - a[2]) / a[1]));
                        }
                        double a1y = a1 * Math.Sin(fi);
                        double a1x = a1 * Math.Cos(fi);
                        a1y *= dydx;
                        double a2y = a2 * Math.Sin(fi);
                        double a2x = a2 * Math.Cos(fi);
                        a2y *= dydx;
                        a1   = Math.Sqrt(a1x * a1x + a1y * a1y);
                        a2   = Math.Sqrt(a2x * a2x + a2y * a2y);
                        double div = MainForm.Nat_pat_size * PatLength;
                        a1 /= div;
                        a2 /= div;


                        double Value = AreaToadd / (div * div) * Math.Sqrt(a1 * a2) * MainForm.Density;
                        answ.Add((int)(Value * 1000));
                        if (MainForm.ShowBestFitEllipses)
                        {
                            if (main.Visible)
                            {
                                ValueGetter.DrawEllipse(a, Graphics.FromHwnd(MainForm.MPicture), dx, dy, true);
                            }
                            else
                            {
                                ValueGetter.DrawEllipse(a, Graphics.FromHwnd(MainForm.SPicture), dx, dy, true);
                            }
                        }
                    }
                }
                pvalue++;
                if (pvalue == 10)
                {
                    pvalue = 0;
                    p1.Value++;
                }
            }
            return(answ);
        }
 /// <summary>
 /// Check if matrix indices are valid.
 /// </summary>
 /// <param name="m">Matrix.</param>
 /// <param name="row">Row index to check.</param>
 /// <param name="column"Column index to check.></param>
 /// <exception cref="OutOfRangeException"> if <c>row</c> or <c>column</c> is not
 /// a valid index.</exception>
 public static void checkMatrixIndex(AnyMatrix m, int row, int column)
 {
     checkRowIndex(m, row);
     checkColumnIndex(m, column);
 }