Example #1
0
        /// <summary>
        /// 是否选中圆
        /// </summary>
        /// <returns></returns>
        public override int isSelected(double x, double y)
        {
            _operationing = -1;

            double max = 35;

            double[] value = new double[_operation_piont_number];
            value[0] = HMisc.DistancePp(y, x, _row_r_y, _col_r_x);
            value[1] = HMisc.DistancePp(y, x, _center_row_y, _center_column_x);
            for (int i = 0; i < _operation_piont_number; i++)
            {
                if (value[i] < max)
                {
                    max           = value[i];
                    _operationing = i;
                }
            }
            return(_operationing);
        }
Example #2
0
        public void SetCrossActive(double x, double y)
        {
            double[] val = new double[crossList.Count];
            for (int i = 0; i < crossList.Count; i++)
            {
                crossList[i].Color = InActiveColor;
                val[i]             = HMisc.DistancePp(crossList[i].Pixel.Y, crossList[i].Pixel.X, y, x);
            }

            if (val.Length > 0 && val.Min() < FAR_ACTIVE_DISTANCE)
            {
                ActiveIndex = Array.IndexOf(val, val.Min());
                crossList[ActiveIndex].Color = AcitveColor;
            }
            else
            {
                ActiveIndex = -1;
            }
        }
Example #3
0
        /// <summary>
        /// 求出鼠标与最近控制点的距离
        /// </summary>
        /// <param name="x">鼠标x</param>
        /// <param name="y">鼠标y</param>
        /// <returns>距离值</returns>
        public override double DistToClosestHandle(double x, double y)
        {
            double max = 10000;

            double [] val = new double[NumHandles];

            val[0] = HMisc.DistancePp(y, x, row1, col1);             // border handle
            val[1] = HMisc.DistancePp(y, x, midR, midC);             // midpoint

            for (int i = 0; i < NumHandles; i++)
            {
                if (val[i] < max)
                {
                    max             = val[i];
                    activeHandleIdx = i;
                }
            }            // end of for
            return(val[activeHandleIdx]);
        }
Example #4
0
        /// <summary>
        /// Auxiliary method
        /// </summary>
        private void UpdateArrowHandle()
        {
            double length, dr, dc, halfHW;
            double rrow1, ccol1, rowP1, colP1, rowP2, colP2;

            //double headLength = 15;
            //double headWidth  = 15;
            double headLength = RoiDrawConfig.Height / 10;
            double headWidth  = RoiDrawConfig.Height / 10;

            arrowHandleXLD.Dispose();
            arrowHandleXLD.GenEmptyObj();

            rrow1 = row1 + (row2 - row1) * 0.8;
            ccol1 = col1 + (col2 - col1) * 0.8;

            length = HMisc.DistancePp(rrow1, ccol1, row2, col2);
            if (length == 0)
            {
                length = -1;
            }

            dr = (row2 - rrow1) / length;
            dc = (col2 - ccol1) / length;

            halfHW = headWidth / 2.0;
            rowP1  = rrow1 + (length - headLength) * dr + halfHW * dc;
            rowP2  = rrow1 + (length - headLength) * dr - halfHW * dc;
            colP1  = ccol1 + (length - headLength) * dc - halfHW * dr;
            colP2  = ccol1 + (length - headLength) * dc + halfHW * dr;

            if (length == -1)
            {
                arrowHandleXLD.GenContourPolygonXld(rrow1, ccol1);
            }
            else
            {
                arrowHandleXLD.GenContourPolygonXld(new HTuple(new double[] { rrow1, row2, rowP1, row2, rowP2, row2 }),
                                                    new HTuple(new double[] { ccol1, col2, colP1, col2, colP2, col2 }));
            }
        }
Example #5
0
        /// <summary>
        /// 求出鼠标坐标与ROI的最近控制点的距离
        /// </summary>
        /// <param name="x">鼠标坐标X</param>
        /// <param name="y">鼠标坐标Y</param>
        /// <returns>鼠标与ROI的控制框的最近距离值</returns>
        public override double DistToClosestHandle(double x, double y)
        {
            double max = 10000;

            double[] val = new double[NumHandles];

            val[0] = HMisc.DistancePp(y, x, startRow, startCol); // upper left
            val[1] = HMisc.DistancePp(y, x, endRow, endCol);     // upper right
            val[2] = HMisc.DistancePp(y, x, midRow, midCol);     // midpoint

            for (int i = 0; i < NumHandles; i++)
            {
                if (val[i] < max)
                {
                    max             = val[i];
                    activeHandleIdx = i;
                }
            }// end of for

            return(val[activeHandleIdx]);
        }
Example #6
0
        /// <summary>
        /// Returns the distance of the ROI handle being
        /// closest to the image point(x,y)
        /// </summary>
        public override double distToClosestHandle(double x, double y)
        {
            double max = 10000;

            double [] val = new double[NumHandles];

            val[0] = HMisc.DistancePp(y, x, midR, midC);                   // midpoint
            val[1] = HMisc.DistancePp(y, x, sizeR, sizeC);                 // border handle
            val[2] = HMisc.DistancePp(y, x, startR, startC);               // border handle
            val[3] = HMisc.DistancePp(y, x, extentR, extentC);             // border handle

            for (int i = 0; i < NumHandles; i++)
            {
                if (val[i] < max)
                {
                    max             = val[i];
                    activeHandleIdx = i;
                }
            }            // end of for
            return(val[activeHandleIdx]);
        }
Example #7
0
        /// <summary> Auxiliary method </summary>
        private void updateArrowHandle()
        {
            double length, dr, dc, halfHW;
            double rrow1, ccol1, rowP1, colP1, rowP2, colP2;

            double headLength = 15;
            double headWidth  = 15;


            _AuxLineHandleXLD.Dispose();
            _AuxLineHandleXLD.GenEmptyObj();

            rrow1 = _StartRow + (_EndRow - _StartRow) * 0.8;
            ccol1 = _StartColumn + (_EndCol - _StartColumn) * 0.8;

            length = HMisc.DistancePp(rrow1, ccol1, _EndRow, _EndCol);
            if (length == 0)
            {
                length = -1;
            }

            dr = (_EndRow - rrow1) / length;
            dc = (_EndCol - ccol1) / length;

            halfHW = headWidth / 2.0;
            rowP1  = rrow1 + (length - headLength) * dr + halfHW * dc;
            rowP2  = rrow1 + (length - headLength) * dr - halfHW * dc;
            colP1  = ccol1 + (length - headLength) * dc - halfHW * dr;
            colP2  = ccol1 + (length - headLength) * dc + halfHW * dr;

            if (length == -1)
            {
                _AuxLineHandleXLD.GenContourPolygonXld(rrow1, ccol1);
            }
            else
            {
                _AuxLineHandleXLD.GenContourPolygonXld(new HTuple(new double[] { rrow1, _EndRow, rowP1, _EndRow, rowP2, _EndRow }),
                                                       new HTuple(new double[] { ccol1, _EndCol, colP1, _EndCol, colP2, _EndCol }));
            }
        }
Example #8
0
        /// <summary> Auxiliary method </summary>
        private void updateArrowHandle()
        {
            double length, dr, dc, halfHW;
            double rrow1, ccol1, rowP1, colP1, rowP2, colP2;

            double headLength = 16;
            double headWidth  = 16;


            arrowHandleXLD.Dispose();
            arrowHandleXLD.GenEmptyObj();

            rrow1 = row1 + (row2 - row1) * 0.9;
            ccol1 = col1 + (col2 - col1) * 0.9;

            length = HMisc.DistancePp(rrow1, ccol1, row2, col2);
            if (length == 0)
            {
                length = -1;
            }

            dr = (row2 - rrow1) / length;
            dc = (col2 - ccol1) / length;

            halfHW = headWidth / 2.0;
            rowP1  = rrow1 + (length - headLength) * dr + halfHW * dc;
            rowP2  = rrow1 + (length - headLength) * dr - halfHW * dc;
            colP1  = ccol1 + (length - headLength) * dc - halfHW * dr;
            colP2  = ccol1 + (length - headLength) * dc + halfHW * dr;

            if (length == -1)
            {
                HOperatorSet.GenContourPolygonXld(out arrowHandleXLD, rrow1, ccol1);
            }
            else
            {
                HOperatorSet.GenContourPolygonXld(out arrowHandleXLD, new HTuple(new double[] { rrow1, row2, rowP1, row2, rowP2, row2 }),
                                                  new HTuple(new double[] { ccol1, col2, colP1, col2, colP2, col2 }));
            }
        }
Example #9
0
        /// <summary>
        /// ROI是否被选中
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <returns></returns>
        public override int isSelected(double x, double y)
        {
            _operationing = -1;

            double max = 35;

            double[] value = new double[_operation_piont_number];

            value[0] = HMisc.DistancePp(y, x, this._row_y1, this._cols_x1);
            value[1] = HMisc.DistancePp(y, x, this._row_y2, this._cols_x2);
            value[2] = HMisc.DistancePp(y, x, this._mid_row_y, this._mid_col_x);

            for (int i = 0; i < _operation_piont_number; i++)
            {
                if (value[i] < max)
                {
                    max           = value[i];
                    _operationing = i;
                }
            }
            return(_operationing);
        }
Example #10
0
        /// <summary>
        /// Returns the distance of the ROI handle being
        /// closest to the image point(x,y)
        /// </summary>
        /// <param name="x">x (=column) coordinate</param>
        /// <param name="y">y (=row) coordinate</param>
        /// <returns>
        /// Distance of the closest ROI handle.
        /// </returns>
        public override double distToClosestHandle(double x, double y)         //计算点到最近的句柄的距离
        {
            double max = 10000;

            double [] val = new double[NumHandles];
            midR   = ((row2 - row1) / 2) + row1;
            midC   = ((col2 - col1) / 2) + col1;
            val[0] = HMisc.DistancePp(y, x, row1, col1);             // upper left
            val[1] = HMisc.DistancePp(y, x, row1, col2);             // upper right
            val[2] = HMisc.DistancePp(y, x, row2, col2);             // lower right
            val[3] = HMisc.DistancePp(y, x, row2, col1);             // lower left
            val[4] = HMisc.DistancePp(y, x, midR, midC);             // midpoint
            for (int i = 0; i < NumHandles; i++)
            {
                if (val[i] < max)
                {
                    max             = val[i];
                    activeHandleIdx = i;
                }
            }            // end of for
            return(val[activeHandleIdx]);
        }
        /// <summary>
        /// Defines the measuring field of a linear ROI.
        /// </summary>
        /// <param name="line">
        /// Model data for a linear interactive ROI
        /// </param>
        /// <param name="width">Half width of (rectangular) measure ROI</param>
        /// <returns>Model data describing a linear measuring field</returns>
        private HTuple GenSurRect2(HTuple line, double width)
        {
            double row1 = line[0];
            double col1 = line[1];
            double row2 = line[2];
            double col2 = line[3];

            //half 長
            double length1 = (HMisc.DistancePp(row1, col1, row2, col2)) / 2.0;
            //half 寬
            double length2 = width;

            if (mRoi is ROIRectangle2 || mRoi is ViewROI.SmartROIs.SmartPoint)
            {
                var midR      = line[0];
                var midC      = line[1];
                var mPhi      = line[2];
                var mlength1  = line[3];
                var mlength2  = line[4];
                var yDistance = (Math.Sin(mPhi) * mlength1);
                var xDistance = (Math.Cos(mPhi) * mlength1);

                row1 = midR - yDistance;            //起點R
                col1 = midC - xDistance;            //起點C
                row2 = midR + yDistance;            //終點R
                col2 = midC + xDistance;            //終點C

                length1 = mlength1;                 //half 長
                length2 = mlength2;                 // half 寬
            }


            double phi = HMisc.AngleLx(row1, col1, row2, col2);

            double rowM = (row1 + row2) / 2;
            double colM = (col1 + col2) / 2;

            return(new HTuple(new double[] { rowM, colM, phi, length1, length2 }));
        }
        /// <summary>
        /// Returns the distance of the ROI handle being
        /// closest to the image point(x,y)
        /// </summary>
        /// <param name="x">x (=column) coordinate</param>
        /// <param name="y">y (=row) coordinate</param>
        /// <returns>
        /// Distance of the closest ROI handle.
        /// </returns>
        public override double distToClosestHandle(double x, double y)
        {
            double max = 10000;

            double [] val = new double[NumHandles];


            for (int i = 0; i < NumHandles; i++)
            {
                val[i] = HMisc.DistancePp(y, x, rows[i].D, cols[i].D);
            }

            for (int i = 0; i < NumHandles; i++)
            {
                if (val[i] < max)
                {
                    max             = val[i];
                    activeHandleIdx = i;
                }
            }
            return(val[activeHandleIdx]);
        }
Example #13
0
        /// <summary>
        /// 是否选中
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <returns></returns>
        public override int isSelected(double x, double y)
        {
            //return base.isSelected(x, y);
            this._operationing = -1;
            double max = 35;

            double[] val = new double[this._operation_piont_number];

            for (int i = 0; i < this._operation_piont_number; i++)
            {
                val[i] = HMisc.DistancePp(y, x, _rows_y[i].D, _cols_x[i].D);
            }

            for (int i = 0; i < this._operation_piont_number; i++)
            {
                if (val[i] < max)
                {
                    this._operationing = i;
                    break;
                }
            }
            return(this._operationing);
        }
Example #14
0
        /// <summary>
        /// Returns the distance of the ROI handle being
        /// closest to the image point(x,y)
        /// </summary>
        /// <param name="x">x (=column) coordinate</param>
        /// <param name="y">y (=row) coordinate</param>
        /// <returns>
        /// Distance of the closest ROI handle.
        /// </returns>
        public override double distToClosestHandle(double x, double y, out int iHandleIndex)
        {
            double max = 10000;

            double[] val = new double[rows.Length];

            //midR = ((row2 - row1) / 2) + row1;
            //midC = ((col2 - col1) / 2) + col1;

            for (int i = 0; i < rows.Length; i++)
            {
                val[i] = HMisc.DistancePp(y, x, rows[i], cols[i]); // upper left
            }
            //////val[0] = HMisc.DistancePp(y, x, row1, col1); // upper left
            //////val[1] = HMisc.DistancePp(y, x, row1, col2); // upper right
            //////val[2] = HMisc.DistancePp(y, x, row2, col2); // lower right
            //////val[3] = HMisc.DistancePp(y, x, row2, col1); // lower left
            //////val[4] = HMisc.DistancePp(y, x, midR, midC); // midpoint
            //////val[5] = HMisc.DistancePp(y, x, (row1 + row2) / 2, col1);
            //////val[6] = HMisc.DistancePp(y, x, (row1 + row2) / 2, col2);
            //////val[7] = HMisc.DistancePp(y, x, row1, (col1 + col2) / 2);
            //////val[8] = HMisc.DistancePp(y, x, row2, (col1 + col2) / 2);

            for (int i = 0; i < rows.Length; i++)
            {
                if (val[i] < max)
                {
                    max             = val[i];
                    activeHandleIdx = i;
                }
            }// end of for

            iHandleIndex = activeHandleIdx;


            return(val[activeHandleIdx]);
        }
Example #15
0
        /// <summary>
        /// Returns the distance of the ROI handle being
        /// closest to the image point(x,y).
        /// </summary>
        public override double distToClosestHandle(double x, double y, out int iHandleIndex)
        {
            double max = 10000;

            double [] val = new double[NumHandles];

            val[0] = HMisc.DistancePp(y, x, row1, col1);             // upper left
            val[1] = HMisc.DistancePp(y, x, row2, col2);             // upper right
            val[2] = HMisc.DistancePp(y, x, midR, midC);             // midpoint

            for (int i = 0; i < NumHandles; i++)
            {
                if (val[i] < max)
                {
                    max             = val[i];
                    activeHandleIdx = i;
                }
            }// end of for

            iHandleIndex = activeHandleIdx;


            return(val[activeHandleIdx]);
        }
Example #16
0
 /// <summary>
 /// 刷新下半径
 /// </summary>
 void sheild_R()
 {
     _radius = HMisc.DistancePp(Center_row_y, Center_column_x, _row_r_y, _col_r_x);
 }
Example #17
0
        public override double getDistanceFromStartPoint(double row, double col)
        {
            double distance = HMisc.DistancePp(row, col, row1, col1);

            return(distance);
        }
Example #18
0
        /// <summary>
        /// If calibration data is available and valid, then transform the
        /// distance between measure result edges into world coordinates,
        /// else leave them the same.
        /// </summary>
        public HTuple Distance(HTuple row1, HTuple col1, HTuple row2, HTuple col2, int shift)
        {
            HTuple   rows, cols, rowRect, colRect;
            HTuple   distance = new HTuple();
            HXLDCont contour;


            if (shift == 0)
            {
                if (mROIType == ROI.ROI_TYPE_CIRCLEARC)
                {
                    double cRow, cCol, radius, extent, phi1, phi2, phi, res, length, tmp;

                    cRow   = mROICoord[0].D;
                    cCol   = mROICoord[1].D;
                    radius = mROICoord[2].D;
                    extent = mROICoord[4].D;

                    HOperatorSet.TupleGenConst(new HTuple(row1.Length), 0.0, out distance);

                    for (int i = 0; i < distance.Length; i++)
                    {
                        phi1 = HMisc.AngleLx(cRow, cCol, row1[i].D, col1[i].D);
                        phi2 = HMisc.AngleLx(cRow, cCol, row2[i].D, col2[i].D);

                        if (extent < 0)
                        {
                            tmp  = phi1;
                            phi1 = phi2;
                            phi2 = tmp;
                        }

                        phi = phi2 - phi1;

                        if (phi < 0)
                        {
                            phi += 2 * Math.PI;
                        }

                        res = 0.05 * 24.0 / (radius * phi);

                        contour = new HXLDCont();
                        contour.GenEllipseContourXld(cRow, cCol, 0, radius, radius, phi1, phi2, "positive", res);
                        contour.GetContourXld(out rows, out cols);
                        Rectify(rows, cols, out rowRect, out colRect);
                        contour.Dispose();
                        contour.GenContourPolygonXld(rowRect, colRect);
                        length        = contour.LengthXld();
                        distance[i].D = length;
                        contour.Dispose();
                    }
                }
                else if (mROIType == ROI.ROI_TYPE_LINE)
                {
                    HTuple rRect1, cRect1, rRect2, cRect2;
                    Rectify(row1, col1, out rRect1, out cRect1);
                    Rectify(row2, col2, out rRect2, out cRect2);
                    distance = HMisc.DistancePp(rRect1, cRect1, rRect2, cRect2);
                }
                return(distance);
            }
            else
            {
                HTuple rClip1, cClip1, rShift2, cShift2;

                rClip1  = row1.TupleSelectRange(new HTuple(0), new HTuple(row1.Length - shift - 1));
                cClip1  = col1.TupleSelectRange(new HTuple(0), new HTuple(col1.Length - shift - 1));
                rShift2 = row2.TupleSelectRange(new HTuple(shift), new HTuple(row2.Length - 1));
                cShift2 = col2.TupleSelectRange(new HTuple(shift), new HTuple(col2.Length - 1));

                return(this.Distance(rClip1, cClip1, rShift2, cShift2, 0));
            }
        }
Example #19
0
        public bool FindCircle(HObject img)
        {
            HTuple  Row         = new HTuple();
            HTuple  Col         = new HTuple();
            HTuple  Distance    = new HTuple();
            HTuple  outRow      = new HTuple();
            HTuple  outCol      = new HTuple();
            HTuple  outAmp      = new HTuple();
            HTuple  outDistance = new HTuple();
            HRegion regionCount = new HRegion();

            regionCount.GenEmptyRegion();
            HXLDCont contour = new HXLDCont();

            if (img == null)
            {
                return(false);
            }
            HTuple imgWidth, imgHeight;
            HTuple hms = null;

            HOperatorSet.GetImageSize(img, out imgWidth, out imgHeight);

            double xCenter, yCenter, Center_radius, angle, angleSplit;

            angle = 0;
            //分割角度
            angleSplit    = 2 * 3.1415926 / (Hnum);
            xCenter       = in_col[0].D + data_col;
            yCenter       = in_row[0].D + data_row;
            Center_radius = in_radius[0].D;

            HHomMat2D hom = new HHomMat2D();

            hom.HomMat2dIdentity();
            hom = hom.HomMat2dRotate(angleSplit, yCenter, xCenter);
            double rect_row, rect_col, angleStart, L1, L2;

            //分割矩形的中心坐标
            rect_row = yCenter;
            rect_col = xCenter + Center_radius;
            L1       = HLengh[0].D / 2;
            L2       = Hwid[0].D / 2;
            if (Hdirection != "in2out")
            {
                //由外向内
                angleStart = angle + (new HTuple(180)).TupleRad();
            }
            else
            {
                angleStart = angle;
            }

            for (int i = 0; i < Hnum[0].I; ++i)
            {
                if (m_bShowRectang2)
                {
                    contour.Dispose();
                    contour.GenRectangle2ContourXld(rect_row, rect_col, angleStart + angleSplit * i, L1, L2);
                    HRegion region;
                    region      = contour.GenRegionContourXld("margin");
                    regionCount = regionCount.Union2(region);
                    region.Dispose();
                }
                try
                {//out_row, out_col, out_radius;
                    HOperatorSet.GenMeasureRectangle2(rect_row, rect_col, angleStart + angleSplit * i, L1,
                                                      L2, imgWidth, imgHeight, "nearest_neighbor", out hms);
                    HOperatorSet.MeasurePos(img, hms, Hsomth, Hamp, Htransition, Hselect,
                                            out outRow, out outCol, out outAmp, out outDistance);
                }
                catch { continue; }
                if (Hselect == "all" && outRow.Length > 1)
                {
                    HTuple hIndex = outAmp.TupleSortIndex();
                    int    nMax   = hIndex[hIndex.Length - 1];
                    Row.Append(outRow[nMax]);
                    Col.Append(outCol[nMax]);
                }
                else
                {
                    Row.Append(outRow);
                    Col.Append(outCol);
                }
                hom.AffineTransPixel(rect_row, rect_col, out rect_row, out rect_col);
            }
            HOperatorSet.CloseMeasure(hms);
            if (m_bShowRectang2)
            {
                m_hRectang2.Dispose();
                m_hRectang2 = regionCount.GenContoursSkeletonXld(1, "filter");
            }
            if (Row.Length > Hnum[0].D / 3)
            {
                HXLDCont counter = new HXLDCont();
                counter.GenContourPolygonXld(Row, Col);

                HTuple startphi, endphi;
                HTuple pointorder;
                counter.FitCircleContourXld("atukey", -1, 0, 0, 3, 2,
                                            out out_row, out out_col, out out_radius, out startphi, out endphi, out pointorder);

                HTuple rowDrop = new HTuple();
                HTuple colDrop = new HTuple();
                if (Row.Length - 5 > m_nNumDropPoints && m_nNumDropPoints > 0)
                {
                    HTuple distance = new HTuple();
                    for (int i = 0; i < Row.Length; ++i)
                    {
                        double dis = HMisc.DistancePp(Row[i], Col[i], xCenter, yCenter);
                        distance.Append(Math.Abs(dis - Center_radius));
                    }
                    HTuple index = distance.TupleSortIndex();
                    index = index.TupleInverse();
                    for (int i = 0; i < m_nNumDropPoints; ++i)
                    {
                        int n = index[i];
                        rowDrop.Append(Row[n]);
                        colDrop.Append(Col[n]);
                    }
                    index = index.TupleFirstN(m_nNumDropPoints - 1);
                    Row   = Row.TupleRemove(index);
                    Col   = Col.TupleRemove(index);

                    counter.GenContourPolygonXld(Row, Col);
                    counter.FitCircleContourXld("atukey", -1, 0, 0, 3, 2,
                                                out out_row, out out_col, out out_radius, out startphi, out endphi, out pointorder);
                }
                m_hCircle.Dispose();
                m_centerCross.Dispose();
                if (m_bShowCircle)
                {
                    HOperatorSet.GenCrossContourXld(out m_centerCross, out_row, out_col, (out_radius / 2) + 1, (new HTuple(0)).TupleRad());
                    HOperatorSet.GenCircleContourXld(out m_hCircle, out_row, out_col, out_radius,
                                                     0, 3.1415926 * 2, "positive", 1);
                }
                m_hCross.Dispose();
                if (m_bShowCross)
                {
                    HOperatorSet.GenCrossContourXld(out m_hCross, Row, Col, 17, (new HTuple(45)).TupleRad());
                }

                Result_Array[0] = out_row;
                Result_Array[1] = out_col;
                Result_Array[2] = out_radius;
                return(true);
            }
            return(false);
        }
Example #20
0
        public override double getDistanceFromStartPoint(double row, double col)
        {
            double distance = HMisc.DistancePp(row, col, _StartRow, _StartColumn);

            return(distance);
        }
Example #21
0
        /// <summary>
        /// Returns the distance of the ROI handle being
        /// closest to the image point(x,y)
        /// </summary>
        /// <param name="x">x (=column) coordinate</param>
        /// <param name="y">y (=row) coordinate</param>
        /// <returns>
        /// Distance of the closest ROI handle.
        /// </returns>
        public override double distToClosestHandle(double x, double y)
        {
            this.row0        = y;
            this.col0        = x;
            this.minDistance = 0.0;
            double[] array  = new double[this.row1.TupleLength()];
            double[] array2 = new double[this.row2.TupleLength()];
            for (int i = 0; i < this.row1.TupleLength(); i++)
            {
                array[i] = HMisc.DistancePp(y, x, this.row1[i].D, this.col1[i].D);
            }
            for (int j = 0; j < this.row2.TupleLength(); j++)
            {
                array2[j] = HMisc.DistancePp(y, x, this.row2[j].D, this.col2[j].D);
            }
            double num = HMisc.DistancePp(this.row1[0].D, this.col1[0].D, this.row1[1].D, this.col1[1].D);

            for (int k = 1; k < this.row1.TupleLength() - 1; k++)
            {
                double num2 = HMisc.DistancePp(this.row1[k].D, this.col1[k].D, this.row1[k + 1].D, this.col1[k + 1].D);
                if (num > num2)
                {
                    num = num2;
                }
            }
            double num3   = (num / 10.0 < 3.0) ? 3.0 : (num / 10.0);
            double result = 20000;

            for (int l = 0; l < array.Length; l++)
            {
                if (array[l] < num3)
                {
                    num3 = array[l];
                    this.activeHandleIdx = l;
                }
            }
            for (int m = 0; m < array2.Length; m++)
            {
                if (array2[m] < num3)
                {
                    num3 = array2[m];
                    this.activeHandleIdx = this.row1.TupleLength() + m;
                }
            }
            double num4 = HMisc.DistancePp(y, x, midR, midC);

            if (num4 < num3)
            {
                num3 = num4;
                this.activeHandleIdx = this.row1.TupleLength() + this.row2.TupleLength();
            }
            if (this.activeHandleIdx < this.row1.TupleLength())
            {
                result = array[this.activeHandleIdx];
            }
            else if (this.activeHandleIdx < this.row1.TupleLength() + this.row2.TupleLength())
            {
                result = array2[this.activeHandleIdx - this.row1.TupleLength()];
            }
            else if (this.activeHandleIdx == this.row1.TupleLength() + this.row2.TupleLength())
            {
                result = num4;
            }
            return(result);
        }
Example #22
0
        /// <summary>
        /// Determine s(or updates) the basic information for this
        /// calibration image, which are the values for the region
        /// plate, the center marks, and the estimated pose.
        /// The flag <c>mPlateStatus</c> describes the evaluation
        /// of the computation process.
        /// If desired the quality assessment can be recalculated
        /// as well.
        /// </summary>
        /// <param name="updateQuality">
        /// Triggers the recalculation of the quality assessment for
        /// this calibration image
        /// </param>
        public void UpdateCaltab(bool updateQuality)
        {
            HTuple worldX, worldY;
            HTuple unit = new HTuple("m");

            bool failed            = false;
            QualityProcedures proc = new QualityProcedures();
            string            descrFile;
            HTuple            startCamp;

            mErrorMessage = "";


            mCaltabRegion.Dispose();
            mMarkCenter.Dispose();
            mEstimatedWCS.Dispose();

            //reset this variable
            mMarkCenterRows = new HTuple();

            mPlateStatus = CalibrationAssistant.PS_NOT_FOUND;

            descrFile = mAssistant.getDesrcFile();

            try
            {
                mCaltabRegion = mImage.FindCaltab(descrFile,
                                                  (int)mAssistant.mFilterSize,
                                                  (int)mAssistant.mMarkThresh,
                                                  (int)mAssistant.mMinMarkDiam);

                mPlateStatus = CalibrationAssistant.PS_MARKS_FAILED;

                //-- Quality issue measurements --
                if (updateQuality)
                {
                    mQualityIssuesList.Clear();
                    failed = mAssistant.testQualityIssues(this);
                }

                startCamp       = mAssistant.getCameraParams(this);
                mMarkCenterRows = mImage.FindMarksAndPose(mCaltabRegion,
                                                          descrFile,
                                                          startCamp,
                                                          (int)mAssistant.mInitThresh,
                                                          (int)mAssistant.mThreshDecr,
                                                          (int)mAssistant.mMinThresh,
                                                          mAssistant.mSmoothing,
                                                          mAssistant.mMinContLength,
                                                          mAssistant.mMaxMarkDiam,
                                                          out mMarkCenterCols,
                                                          out mEstimatedPose);


                mMarkCenter.GenCrossContourXld(mMarkCenterRows,
                                               mMarkCenterCols,
                                               new HTuple(6.0),
                                               0.785398);

                if (failed)
                {
                    mAssistant.addQualityIssue(this, CalibrationAssistant.QUALITY_ISSUE_FAILURE, 0.0);
                }


                HOperatorSet.ImagePointsToWorldPlane(startCamp, mEstimatedPose,
                                                     mMarkCenterRows, mMarkCenterCols,
                                                     unit, out worldX, out worldY);
                mEstimatedPlateSize = HMisc.DistancePp(worldY[0].D, worldX[0].D,
                                                       worldY[1].D, worldX[1].D);
                mEstimatedPlateSize *= 10.0;
                proc.get_3d_coord_system(mImage, out mEstimatedWCS,
                                         startCamp, mEstimatedPose,
                                         new HTuple(mEstimatedPlateSize / 2.0));

                mPlateStatus = mQualityIssuesList.Count > 0 ? CalibrationAssistant.PS_QUALITY_ISSUES:CalibrationAssistant.PS_OK; // "Quality Issues found": "OK";
                mCanCalib    = 0;
            }
            catch (HOperatorException e)
            {
                this.mErrorMessage = e.Message;
                mCanCalib          = 1;

                /* if exception was raised due to lack of memory,
                 * forward the error to the calling method */
                if (e.Message.IndexOf("not enough") != -1)
                {
                    throw(e);
                }
            }
        }