示例#1
0
        /// <summary>
        /// 計算滑鼠位置接近控制點 (Handle) 的距離
        /// </summary>
        /// <param name="x">x position of mouse</param>
        /// <param name="y">y position of mouse</param>
        /// <returns></returns>
        public override double distToClosestHandle(double x, double y)
        {
            double max = 10000;

            double[] val = new double[NumHandles];

            val[0] = HMisc.DistancePl(y, x, _model.RowBegin, _model.ColBegin, _model.RowEnd, _model.ColEnd);

            for (int i = 0; i < NumHandles; i++)
            {
                if (val[i] < max)
                {
                    max             = val[i];
                    activeHandleIdx = i;
                }
            }            // end of for
            return(val[activeHandleIdx]);
        }
示例#2
0
        /// <summary>
        /// 計算滑鼠位置接近控制點 (Handle) 的距離
        /// </summary>
        /// <param name="x">x position of mouse</param>
        /// <param name="y">y position of mouse</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, this.NewCenterRow, this.NewCenterCol);             // midpoint
            val[1] = HMisc.DistancePl(y, x, this._arrowLineRowBegin, this._arrowLineColBegin, this._arrowLineRowEnd, this._arrowLineColEnd);
            for (int i = 0; i < NumHandles; i++)
            {
                if (val[i] < max)
                {
                    max             = val[i];
                    activeHandleIdx = i;
                }
            }            // end of for
            return(val[activeHandleIdx]);
        }
示例#3
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)
        {
            var dist = HMisc.DistancePl(y, x, _StartRow, _StartColumn, _EndRow, _EndCol);

            return(dist);
        }
示例#4
0
文件: ROIPolygon2.cs 项目: Gz1d/Gz
 //public  HXLDCont GetXLDCont()
 //{
 //    HTuple row = this.row1.TupleConcat(this.row1[0]);
 //    HTuple col = this.col1.TupleConcat(this.col1[0]);
 //    HXLDCont hXLDCont = new HXLDCont();
 //    hXLDCont.GenEmptyObj();
 //    hXLDCont.GenContourPolygonXld(row, col);
 //    return hXLDCont;
 //}
 /// <summary>
 /// Recalculates the shape of the ROI instance. Translation is
 /// performed at the active handle of the ROI object
 /// for the image coordinate (x,y)
 /// </summary>
 /// <param name="newX">x mouse coordinate</param>
 /// <param name="newY">y mouse coordinate</param>
 public override void moveByHandle(double newX, double newY)
 {
     if (this.minDistance >= 0.0)
     {
         if (this.activeHandleIdx < this.row1.TupleLength())
         {
             double num;
             double d;
             if (this.activeHandleIdx != 0 && this.activeHandleIdx != this.row1.TupleLength() - 1)
             {
                 num = HMisc.DistancePl(newY, newX, this.row1[this.activeHandleIdx - 1].D, this.col1[this.activeHandleIdx - 1].D,
                                        this.row1[this.activeHandleIdx + 1].D, this.col1[this.activeHandleIdx + 1].D);
                 d = Math.Abs(HMisc.AngleLl(newY, newX, this.row1[this.activeHandleIdx - 1].D,
                                            this.col1[this.activeHandleIdx - 1].D, newY, newX, this.row1[this.activeHandleIdx + 1].D,
                                            this.col1[this.activeHandleIdx + 1].D));
             }
             else if (this.activeHandleIdx == 0)
             {
                 num = HMisc.DistancePl(newY, newX, this.row1[this.row1.TupleLength() - 1].D, this.col1[this.col1.TupleLength()
                                                                                                        - 1].D, this.row1[this.activeHandleIdx + 1].D, this.col1[this.activeHandleIdx + 1].D);
                 d = Math.Abs(HMisc.AngleLl(newY, newX, this.row1[this.row1.TupleLength() - 1].D,
                                            this.col1[this.col1.TupleLength() - 1].D, newY, newX, this.row1[this.activeHandleIdx + 1].D,
                                            this.col1[this.activeHandleIdx + 1].D));
             }
             else
             {
                 num = HMisc.DistancePl(newY, newX, this.row1[this.activeHandleIdx - 1].D,
                                        this.col1[this.activeHandleIdx - 1].D, this.row1[0].D, this.col1[0].D);
                 d = Math.Abs(HMisc.AngleLl(newY, newX, this.row1[this.activeHandleIdx - 1].D,
                                            this.col1[this.activeHandleIdx - 1].D, newY, newX, this.row1[0].D, this.col1[0].D));
             }
             if (this.minDistance == 0.0)
             {
                 this.row1[this.activeHandleIdx] = newY;
                 this.col1[this.activeHandleIdx] = newX;
                 this.minDistance = num;
             }
             else if (num >= this.minDistance)
             {
                 this.row1[this.activeHandleIdx] = newY;
                 this.col1[this.activeHandleIdx] = newX;
                 this.minDistance = num;
             }
             else
             {
                 HTuple hTuple = null;
                 HOperatorSet.TupleDeg(d, out hTuple);
                 if (Math.Abs(hTuple.D) > 179.5 && this.row1.TupleLength() > 2)
                 {
                     this.row1        = this.row1.TupleRemove(this.activeHandleIdx);
                     this.col1        = this.col1.TupleRemove(this.activeHandleIdx);
                     this.minDistance = -1.0;
                 }
                 else
                 {
                     this.row1[this.activeHandleIdx] = newY;
                     this.col1[this.activeHandleIdx] = newX;
                     this.minDistance = num;
                 }
             }
         }
         else if (this.activeHandleIdx < this.row1.TupleLength() + this.row2.TupleLength())
         {
             midR = newY;
             midC = newX;
             int num2 = this.activeHandleIdx - this.row1.TupleLength() + 1;
             this.row1            = this.row1.TupleInsert(num2, this.row2[num2 - 1].D);
             this.col1            = this.col1.TupleInsert(num2, this.col2[num2 - 1].D);
             this.activeHandleIdx = num2;
         }
         else if (this.activeHandleIdx == this.row1.TupleLength() + this.row2.TupleLength())
         {
             double t  = this.row0 - newY;
             double t2 = this.col0 - newX;
             this.row1 -= t;
             this.row2 -= t;
             this.col1 -= t2;
             this.col2 -= t2;
         }
         else
         {
             double t  = this.row0 - newY;
             double t2 = this.col0 - newX;
             this.row1 -= t;
             this.row2 -= t;
             this.col1 -= t2;
             this.col2 -= t2;
         }
         midR = (row1.TupleMean() + row2.TupleMean()) / 2;
         midC = (col1.TupleMean() + col2.TupleMean()) / 2;
         this.updateRow2();
         this.row0 = newY;
         this.col0 = newX;
     }
 } //end of class
示例#5
0
        /// <summary>
        /// 在当前图像上按单元配置查找直线
        /// </summary>
        /// <param name="img"></param>
        /// <param name="hFixTool"></param>
        /// <returns></returns>
        public bool FindLine(HObject img)
        {
            m_rowBegin = new HTuple();
            m_colBegin = new HTuple();
            m_rowEnd   = new HTuple();
            m_colEnd   = new HTuple();

            m_hLine.Dispose();
            m_hCross.Dispose();
            m_hCrossDrop.Dispose();
            if (img == null)
            {
                return(false);
            }

            string strSelect = string.Empty;

            if (Hselect == "strongest")
            {
                strSelect = "all";
            }
            else
            {
                strSelect = Hselect;
            }

            HTuple imgWidth, imgHeight;

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

            m_imageWidth  = imgWidth;
            m_imageHeight = imgHeight;

            double x1, y1, x2, y2;
            HTuple in_phi_t = in_phi + data_from_phi + data_phi * 3.1415926 / 180;
            double angle    = in_phi_t[0].D + 3.1415926 / 2;

            x1 = (in_col + data_col)[0].D + L2 * Math.Cos(angle);
            x2 = (in_col + data_col)[0].D - L2 * Math.Cos(angle);
            y1 = (in_row + data_row)[0].D - L2 * Math.Sin(angle);
            y2 = (in_row + data_row)[0].D + L2 * Math.Sin(angle);

            HHomMat2D hom = new HHomMat2D();

            hom.HomMat2dIdentity();
            hom = hom.HomMat2dTranslate((y2 - y1) / (Hnum - 1), (x2 - x1) / (Hnum - 1));

            double rect_row  = y1;
            double rect_col  = x1;
            double rect_phi  = in_phi_t[0].D;
            double rect_len1 = L1;
            double rect_len2 = (double)Hwid / 2.0;
            HTuple hms       = null;

            HOperatorSet.GenMeasureRectangle2(rect_row, rect_col, rect_phi, rect_len1,
                                              rect_len2, imgWidth, imgHeight, "nearest_neighbor", out hms);

            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();

            for (int i = 0; i < Hnum[0].I; ++i)
            {
                if (m_bShowRectang2)
                {
                    contour.Dispose();
                    contour.GenRectangle2ContourXld(rect_row, rect_col, rect_phi, rect_len1, rect_len2);
                    HRegion region;
                    region      = contour.GenRegionContourXld("margin");
                    regionCount = regionCount.Union2(region);
                }
                try
                {
                    HOperatorSet.MeasurePos(img, hms, Hsomth, Hamp, Htransition, strSelect,
                                            out outRow, out outCol, out outAmp, out outDistance);
                }
                catch { continue; }

                if (strSelect == "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.TranslateMeasure(hms, rect_row, rect_col);
            }
            HOperatorSet.CloseMeasure(hms);
            if (m_bShowRectang2)
            {
                m_hRectang2 = regionCount.GenContoursSkeletonXld(1, "filter");
            }

            if (Row.Length > 1)
            {
                HXLDCont counter = new HXLDCont();
                counter.GenContourPolygonXld(Row, Col);

                HTuple nr, nc, dist;
                counter.FitLineContourXld("tukey", -1, 0, 5, 2,
                                          out m_rowBegin, out m_colBegin, out m_rowEnd, out m_colEnd, out nr, out nc, out dist);

                HTuple rowDrop = new HTuple();
                HTuple colDrop = new HTuple();
                if (Row.Length - 3 > m_nNumDropPoints && m_nNumDropPoints > 0)
                {
                    HTuple distance = new HTuple();

                    for (int i = 0; i < Row.Length; ++i)
                    {
                        double dis = HMisc.DistancePl(Row[i], Col[i], m_rowBegin, m_colBegin, m_rowEnd, m_colEnd);
                        distance.Append(dis);
                    }
                    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.FitLineContourXld("tukey", -1, 0, 5, 2,
                                              out m_rowBegin, out m_colBegin, out m_rowEnd, out m_colEnd, out nr, out nc, out dist);
                }

                if (m_bShowLine)
                {
                    HTuple rrow = new HTuple(m_rowBegin);
                    HTuple ccol = new HTuple(m_colBegin);
                    rrow.Append(m_rowEnd);
                    ccol.Append(m_colEnd);
                    m_hLine.GenContourPolygonXld(rrow, ccol);
                }

                if (m_bShowCross)
                {
                    m_hCross.GenEmptyObj();
                    m_hCross.GenCrossContourXld(Row, Col, 17, (new HTuple(45)).TupleRad());
                }

                if (m_bShowCrossDrop)
                {
                    m_hCrossDrop.GenEmptyObj();
                    m_hCrossDrop.GenCrossContourXld(rowDrop, colDrop, 17, (new HTuple(45)).TupleRad());
                }

                Result_Array[0] = m_rowBegin;
                Result_Array[1] = m_colBegin;
                Result_Array[2] = m_rowEnd;
                Result_Array[3] = m_colEnd;
                return(true);
            }
            return(false);
        }