//仿射变换后的全部轮廓
        public void GenDetectionXLDResults(HXLDCont modelXldCont)
        {
            if (resultXLDCont == null)
            {
                resultXLDCont = new HXLDCont();
            }
            if (resultXLDCont != null && resultXLDCont.IsInitialized())
            {
                resultXLDCont.Dispose();
            }
            resultXLDCont.GenEmptyObj();

            HXLDCont rContours;

            for (int i = 0; i < row.Length; i++)
            {
                HHomMat2D mat1 = new HHomMat2D();
                mat1.VectorAngleToRigid(0, 0, 0, row[i].D, column[i].D, angle[i].D);
                mat1 = mat1.HomMat2dScale(scale[i].D, scale[i].D, row[i].D, column[i].D);
                //图像偏移
                rContours = mat1.AffineTransContourXld(modelXldCont);
                //获取模板集合
                resultXLDCont = resultXLDCont.ConcatObj(rContours);
                rContours.Dispose();
                rContours.GenCrossContourXld(row[i].D, column[i].D, 10, angle[i].D);
                resultXLDCont = resultXLDCont.ConcatObj(rContours);
                rContours.Dispose();
            }
        }
        /// <summary>
        /// Creates a measure object based on the model data
        /// defined by the ROI instance and the parameters
        /// describing the measure context.
        /// </summary>
        protected void UpdateMeasure()
        {
            double extent, sPhi, radius;

            if (mHandle != null)
            {
                mHandle.Dispose();
            }

            mMeasAssist.exceptionText = "";

            try
            {
                switch (mROIType)
                {
                case ROI.ROI_TYPE_CIRCLEARC:

                    radius = mROICoord[2].D;
                    sPhi   = mROICoord[3].D;
                    extent = mROICoord[4].D;


                    mMeasROI = GenSurCircle(mROICoord, mMeasAssist.mRoiWidth);
                    mHandle  = new HMeasure(mROICoord[0].D, mROICoord[1].D, radius,
                                            sPhi, extent,
                                            mMeasAssist.mRoiWidth,
                                            mMeasAssist.mWidth, mMeasAssist.mHeight,
                                            mMeasAssist.mInterpolation);

                    break;

                case ROI.ROI_TYPE_CIRCLE:
                    //記錄 ROI 範圍
                    mMeasROI = GenSurCircle2(mROICoord, mMeasAssist.mRoiWidth);

                    break;

                case ROI.ROI_TYPE_LINE:
                case ROI.ROI_TYPE_POINT:


                    mMeasROI = GenSurRect2(mROICoord, mROICoord[4]);
                    mHandle  = new HMeasure(mMeasROI[0].D, mMeasROI[1].D,
                                            mMeasROI[2].D, mMeasROI[3].D, mMeasROI[4].D,
                                            mMeasAssist.mWidth, mMeasAssist.mHeight,
                                            mMeasAssist.mInterpolation);
                    break;
                }
            }
            catch (HOperatorException e)
            {
                mEdgeXLD.Dispose();
                mMeasureRegion.Dispose();
                mMeasAssist.exceptionText = e.Message;
                ClearResultData();
                return;
            }
            UpdateResults();
            UpdateMeasureRegion();
        }
Пример #3
0
        /// <summary>Paints the ROI into the supplied window</summary>
        /// <param name="window">HALCON window</param>
        public override void draw(HalconDotNet.HWindow window)
        {
            //畫個 x
            double crossSize  = 12;
            double crossAngle = 0.785398;

            //Reset line Style
            HOperatorSet.SetLineStyle(window, null);
            if (!_initPointsDone)
            {
                foreach (var dot in _clickedPointsPositionList)
                {
                    HOperatorSet.DispCross(window, dot.RowBegin, dot.ColBegin, crossSize, crossAngle);
                }
            }
            else
            {
                //畫弧線
                contour.Dispose();
                contour.GenCircleContourXld(midR, midC, radius, _startPhi,
                                            (_startPhi + _extentPhi), _pointOrder, 1.0);

                this._beginRow = midR + Math.Sin(_startPhi) * radius;
                this._beginCol = midC + Math.Cos(_startPhi) * radius;

                window.DispObj(contour);
                drawOuterArc(window);

                //畫控制點
                window.DispRectangle2(sizeR, sizeC, 0, 5, 5);
                window.DispRectangle2(midR, midC, 0, 5, 5);
                window.DispRectangle2(startR, startC, _startPhi, 10, 2);
                window.DispObj(arrowHandleXLD);
            }
        }
        public bool setTarget(List <HHomMat2D> mat2DsList)
        {
            if (mat2DsList == null || mat2DsList.Count < 1)
            {
                return(false);
            }

            if (GrabXld != null && GrabXld.IsInitialized())
            {
                GrabXld.Dispose();
            }
            else
            {
                GrabXld = new HXLDCont();
                GrabXld.GenEmptyObj();
            }

            GrabRowTarget = new HTuple();
            GrabColTarget = new HTuple();
            HTuple rowTemp, colTemp;

            for (int i = 0; i < mat2DsList.Count; i++)
            {
                HOperatorSet.AffineTransPixel(mat2DsList[i], new HTuple(GrabRowOrg), new HTuple(GrabColOrg), out rowTemp, out colTemp);
                GrabRowTarget = GrabRowTarget.TupleConcat(rowTemp);
                GrabColTarget = GrabColTarget.TupleConcat(colTemp);
            }
            return(true);
        }
Пример #5
0
        public bool CreateShapeModelAct(HImage modelImage)
        {
            if (modelImage == null || !modelImage.IsInitialized())
            {
                return(false);
            }
            this.modelImage = modelImage;

            if (modelRegion == null || !modelRegion.IsInitialized())
            {
                return(false);
            }
            try
            {
                HImage ROIImage = new HImage();
                ROIImage.GenEmptyObj();
                ROIImage = modelImage.ReduceDomain(modelRegion);
                HImage temp = ROIImage.GaussFilter(7);
                ROIImage.Dispose();
                ROIImage    = temp;
                hShapeModel = ROIImage.CreateScaledShapeModel(
                    new HTuple(numLevels),
                    angleStart, angleExtent, new HTuple(angleStep),
                    scaleMin, scaleMax, new HTuple(scaleStep),
                    new HTuple(optimization).TupleConcat("no_pregeneration"),
                    metric,
                    ((new HTuple(contrastLow)).TupleConcat(contrastHigh)).TupleConcat(minLength),
                    new HTuple(minContrast));



                ROIImage.Dispose();
                double row, col;
                modelRegion.AreaCenter(out row, out col);
                refCoordinates   = new HTuple(row, col, 0);
                createNewModelID = false;
                //初始化modelContours
                if (modelXLDCont == null)
                {
                    modelXLDCont = new HXLDCont();
                }
                if (modelXLDCont != null && modelXLDCont.IsInitialized())
                {
                    modelXLDCont.Dispose();
                }
                modelXLDCont = hShapeModel.GetShapeModelContours(1);
            }
            catch
            {
                hShapeModel      = null;
                createNewModelID = true;
                return(false);
            }

            return(true);
        }
Пример #6
0
 /// <summary>Paints the ROI into the supplied window</summary>
 /// <param name="window">HALCON window</param>
 public override void draw(HalconDotNet.HWindow window)
 {
     contour.Dispose();
     contour.GenCircleContourXld(midR, midC, radius, startPhi,
                                 (startPhi + extentPhi), circDir, 1.0);
     window.DispObj(contour);
     window.DispRectangle2(sizeR, sizeC, 0, 5, 5);
     window.DispRectangle2(midR, midC, 0, 5, 5);
     window.DispRectangle2(startR, startC, startPhi, 10, 2);
     window.DispObj(arrowHandleXLD);
 }
 /// <summary>Paints the ROI into the supplied window</summary>
 /// <param name="window">HALCON window</param>
 public override void Draw(HWindow window)
 {
     contour.Dispose();
     contour.GenCircleContourXld(midR, midC, radius, startPhi,
                                 (startPhi + extentPhi), circDir, 1.0);
     window.DispObj(contour);
     window.DispRectangle2(sizeR, sizeC, 0, RoiDrawConfig.PaneWidth, RoiDrawConfig.PaneWidth);
     window.DispRectangle2(midR, midC, 0, RoiDrawConfig.PaneWidth, RoiDrawConfig.PaneWidth);
     //window.DispRectangle2(startR, startC, startPhi, 10, 2);
     window.DispRectangle2(startR, startC, startPhi, RoiDrawConfig.PaneWidth * 2, RoiDrawConfig.PaneWidth / 2);
     window.DispObj(arrowHandleXLD);
 }
Пример #8
0
 public override void DisplayDetail(HWindow_Final window)
 {
     window.DispObj(contours, "green");
     window.DispObj(cross, "red");
     contours.Dispose();
     cross.Dispose();
     base.DisplayDetail(window);
 }
Пример #9
0
        /// <summary>Paints the ROI into the supplied window</summary>
        /// <param name="window">HALCON window</param>
        public override void draw(hvppleDotNet.HWindow window, int imageWidth, int imageHeight)
        {
            contour.Dispose();
            contour.GenCircleContourXld(midR, midC, radius, startPhi,
                                        (startPhi + extentPhi), circDir, 1.0);

            double littleRecSize = getHandleWidth(imageWidth, imageHeight);

            window.DispObj(contour);
            window.DispLine(startR, startC, midR, midC);
            window.DispLine(extentR, extentC, midR, midC);

            window.SetDraw("fill");
            window.DispRectangle2(sizeR, sizeC, 0, littleRecSize, littleRecSize);
            window.DispRectangle2(midR, midC, 0, littleRecSize, littleRecSize);
            window.DispRectangle2(startR, startC, startPhi, littleRecSize, littleRecSize);
            window.DispRectangle2(extentR, extentC, 0, littleRecSize, littleRecSize);
            window.SetDraw("margin");
        }
Пример #10
0
        public void ShowShapeModel(HWndCtrl viewCtrl)
        {
            if (modelRegion == null || !modelRegion.IsInitialized())
            {
                return;
            }
            if (ModelXLDCont == null || !ModelXLDCont.IsInitialized())
            {
                return;
            }
            viewCtrl.ChangeGraphicSettings(Mode.DRAWMODE, "margin");
            if (modelRegion != null && modelRegion.IsInitialized())
            {
                viewCtrl.ChangeGraphicSettings(Mode.COLOR, "blue");
                viewCtrl.ChangeGraphicSettings(Mode.LINEWIDTH, 2);
                viewCtrl.AddIconicVar(modelRegion);
            }

            if (modelXLDContAffine == null)
            {
                modelXLDContAffine = new HXLDCont();
            }
            if (modelXLDContAffine != null && modelXLDContAffine.IsInitialized())
            {
                modelXLDContAffine.Dispose();
            }
            if (refCoordinates == null || refCoordinates.Length != 3)
            {
                return;
            }

            HHomMat2D homMat2D = new HHomMat2D();

            homMat2D.VectorAngleToRigid(0.0, 0.0, 0.0, refCoordinates[0].D, refCoordinates[1].D, refCoordinates[2].D);
            modelXLDContAffine = homMat2D.AffineTransContourXld(ModelXLDCont);

            if (modelXLDContAffine != null && modelXLDContAffine.IsInitialized())
            {
                viewCtrl.ChangeGraphicSettings(Mode.COLOR, "red");
                viewCtrl.ChangeGraphicSettings(Mode.LINEWIDTH, 1);
                viewCtrl.AddIconicVar(modelXLDContAffine);
            }
        }
Пример #11
0
        /// <summary>Paints the ROI into the supplied window</summary>
        /// <param name="window">HALCON window</param>
        public override void Draw(HalconDotNet.HWindow window)
        {
            if (contour == null)
            {
                contour = new HXLDCont();
            }
            contour.Dispose();
            contour.GenCircleContourXld(midR, midC, radius, startPhi,
                                        (startPhi + extentPhi), circDir, 1.0);
            window.DispObj(contour);

            int width = GetHandleWidth();

            window.DispRectangle2(sizeR, sizeC, 0, width, width);
            window.DispRectangle2(midR, midC, 0, width, width);

            window.DispObj(startRect2XLD);
            window.DispObj(arrowHandleXLD);
        }
Пример #12
0
        private void MouseTestPoint(object sender, MouseEventArgs e)
        {
            int state;

            try
            {
                mView.viewPort.HalconWindow.GetMpositionSubPix(out row, out col, out state);
                txt_Row.Text = string.Format("{0:F3}", row);
                txt_Col.Text = string.Format("{0:F3}", col);
                if (modelPointXld == null)
                {
                    modelPointXld = new HXLDCont();
                }
                if (modelPointXld != null && modelPointXld.IsInitialized())
                {
                    modelPointXld.Dispose();
                }
                modelPointXld.GenCrossContourXld(row, col, 30, 0);
                mView.ClearList();
                mView.SetDispLevel(ShowMode.ExcludeROI);
                mView.ChangeGraphicSettings(Mode.LINESTYLE, new HTuple());
                mView.AddIconicVar(tool.ModelImage);
                if (modelPointXld != null)
                {
                    mView.ChangeGraphicSettings(Mode.COLOR, "red");
                    mView.ChangeGraphicSettings(Mode.LINEWIDTH, 2);
                    mView.AddIconicVar(modelPointXld);
                }
                HTuple x_temp, y_temp;
                HOperatorSet.ImagePointsToWorldPlane(tool.cameraParam, tool.worldPose, row, col, 1, out x_temp, out y_temp);
                mView.AddText("X:=" + (1000 * x_temp.D).ToString("F2") + ";" + "Y:= " + (1000 * y_temp.D).ToString("F2"), (int)(row + 20), (int)col, 20, "green");
                txt_Verify_X.Text = (1000 * x_temp.D).ToString("F2");
                txt_Verify_Y.Text = (1000 * y_temp.D).ToString("F2");
                mView.Repaint();
            }

            catch (HalconException)
            {
                return;
            }
        }
Пример #13
0
        /// <summary>
        /// 更新起始点的矩形框
        /// </summary>
        private void updateStartRect2XLDHandle()
        {
            if (startRect2XLD == null)
            {
                startRect2XLD = new HXLDCont();
            }
            startRect2XLD.Dispose();
            startRect2XLD.GenEmptyObj();
            int width = GetHandleWidth();

            startRect2XLD.GenRectangle2ContourXld(startR, startC, startPhi, width, width / 5);
        }
Пример #14
0
        /// <summary>
        /// Auxiliary method to display an arrow at the extent arc position
        /// </summary>
        private void updateArrowHandle()
        {
            double row1, col1, row2, col2;
            double rowP1, colP1, rowP2, colP2;
            double length, dr, dc, halfHW, sign, angleRad;
            double headLength = 15;
            double headWidth  = 15;

            try
            {
                arrowHandleXLD.Dispose();
                arrowHandleXLD.GenEmptyObj();

                row2     = extentR;
                col2     = extentC;
                angleRad = (_startPhi + _extentPhi) + Math.PI * 0.5;

                sign = (_pointOrder == "negative") ? -1.0 : 1.0;
                row1 = row2 + sign * Math.Sin(angleRad) * 20;
                col1 = col2 - sign * Math.Cos(angleRad) * 20;

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

                dr = (row2 - row1) / length;
                dc = (col2 - col1) / length;

                halfHW = headWidth / 2.0;
                rowP1  = row1 + (length - headLength) * dr + halfHW * dc;
                rowP2  = row1 + (length - headLength) * dr - halfHW * dc;
                colP1  = col1 + (length - headLength) * dc - halfHW * dr;
                colP2  = col1 + (length - headLength) * dc + halfHW * dr;
                if (length == -1)
                {
                    arrowHandleXLD.GenContourPolygonXld(row1, col1);
                }
                else
                {
                    arrowHandleXLD.GenContourPolygonXld(new HTuple(new double[] { row1, row2, rowP1, row2, rowP2, row2 }),
                                                        new HTuple(new double[] { col1, col2, colP1, col2, colP2, col2 }));
                }
            }
            catch (Exception ex)
            {
                Hanbo.Log.LogManager.Error(ex);
            }
        }
Пример #15
0
        /// <summary>
        /// Auxiliary method to display an arrow at the extent arc position
        /// </summary>
        private void updateArrowHandle()
        {
            double row1, col1, row2, col2;
            double rowP1, colP1, rowP2, colP2;
            double length, dr, dc, halfHW, sign, angleRad;

            int    width      = GetHandleWidth();
            double headLength = width;
            double headWidth  = width;

            if (arrowHandleXLD == null)
            {
                arrowHandleXLD = new HXLDCont();
            }
            arrowHandleXLD.Dispose();
            arrowHandleXLD.GenEmptyObj();

            row2     = extentR;
            col2     = extentC;
            angleRad = (startPhi + extentPhi) + Math.PI * 0.5;

            sign = (circDir == "negative") ? -1.0 : 1.0;
            row1 = row2 + sign * Math.Sin(angleRad) * 20;
            col1 = col2 - sign * Math.Cos(angleRad) * 20;

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

            dr = (row2 - row1) / length;
            dc = (col2 - col1) / length;

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

            if (length == -1)
            {
                arrowHandleXLD.GenContourPolygonXld(row1, col1);
            }
            else
            {
                arrowHandleXLD.GenContourPolygonXld(new HTuple(new double[] { row1, row2, rowP1, row2, rowP2, row2 }),
                                                    new HTuple(new double[] { col1, col2, colP1, col2, colP2, col2 }));
            }
        }
        /// <summary>
        /// Creates an iconic object depicting the
        /// measuring field.
        /// </summary>
        public void UpdateMeasureRegion()
        {
            mMeasureRegion.Dispose();
            mMeasureRegion.GenEmptyObj();
            switch (mROIType)
            {
            case ROI.ROI_TYPE_CIRCLEARC:
                double   sPhi, extent, innerRad, outerRad;
                HTuple   innerR, outerR, innerC, outerC;
                HXLDCont outCont, innerCont, contour;

                outCont   = new HXLDCont();
                innerCont = new HXLDCont();

                sPhi     = mMeasROI[2].D;
                extent   = mMeasROI[3].D;
                outerRad = mMeasROI[4].D;
                innerRad = mMeasROI[5].D;


                innerCont.GenCircleContourXld(mMeasROI[0].D, mMeasROI[1].D, innerRad, sPhi, (sPhi + extent), (extent > 0) ? "positive" : "negative", 1.0);
                outCont.GenCircleContourXld(mMeasROI[0].D, mMeasROI[1].D, outerRad, (sPhi + extent), sPhi, (extent > 0) ? "negative" : "positive", 1.0);

                innerCont.GetContourXld(out innerR, out innerC);
                outCont.GetContourXld(out outerR, out outerC);
                innerR = innerR.TupleConcat(outerR);
                innerC = innerC.TupleConcat(outerC);

                contour = new HXLDCont(innerR, innerC);
                contour = contour.CloseContoursXld();

                mMeasureRegion = contour.GenRegionContourXld("margin");

                contour.Dispose();
                innerCont.Dispose();
                outCont.Dispose();
                break;

            case ROI.ROI_TYPE_CIRCLE:
                //
                break;

            default:
                mMeasureRegion.GenRectangle2(mMeasROI[0].D, mMeasROI[1].D,
                                             mMeasROI[2].D, mMeasROI[3].D,
                                             mMeasROI[4].D);
                break;
            }
        }
Пример #17
0
        /// <summary>
        /// A helper method to convert an HObject containing an XLD contour to an HXLDCont.
        /// </summary>
        /// <param name="from">From.</param>
        /// <returns>HXLDCont.</returns>
        /// <exception cref="NotImplementedException"></exception>
        public static HXLDCont ToHXLDCont(this HObject from)
        {
            HXLDCont newXldCont = new HXLDCont();

            if (from.IsValid())
            {
                if (from.GetObjClass().S == "xld_cont")
                {
                    newXldCont.Dispose();
                    newXldCont = new HXLDCont(from);
                }
            }

            return(newXldCont);
        }
Пример #18
0
        /// <summary>
        /// Gets the detected contour.
        /// </summary>
        /// <returns>Detected contour</returns>
        public HXLDCont getDetectionResults()
        {
            HXLDCont rContours = new HXLDCont();

            hmat.HomMat2dIdentity();

            if (mContResults != null)
            {
                mContResults.Dispose();
            }
            mContResults.GenEmptyObj();



            for (int i = 0; i < count; i++)
            {
                if (mImageScale < 0.1 || mImageScale > 2)
                {
                    mImageScale = 1.0;
                }
                hmat.VectorAngleToRigid(0, 0, 0, mRow[i].D * mImageScale, mCol[i].D * mImageScale, mAngle[i].D);
                //2020.11.7 gengxmÐÞ¸Ä £¬ÂÖÀª·Å´óÈý±¶
                hmat = hmat.HomMat2dScale(1.0000 / mImageScale, 1.0000 / mImageScale, 0, 0);

                rContours = hmat.AffineTransContourXld(mContour);



                mContResults = mContResults.ConcatObj(rContours);
            }
            if (rContours != null)
            {
                rContours.Dispose();
            }

            if (true)
            {
                HTuple convexity;
                HTuple col1, col2, row1, row2;
                HOperatorSet.SmallestRectangle1Xld(mContResults, out row1, out col1, out row2, out col2);
                HOperatorSet.ConvexityXld(mContResults, out convexity);
                // wid = col2 - col1;
                //hei = row2 - row1;
            }

            return(mContResults);
        }
Пример #19
0
        /// <summary>
        /// 辅助的箭头显示方法
        /// </summary>
        private void updateArrowHandle()
        {
            double length, dr, dc, halfHW;
            double rrow1, ccol1, rowP1, colP1, rowP2, colP2;

            int    width      = GetHandleWidth();
            double headLength = width;
            double headWidth  = width;

            if (arrowHandleXLD == null)
            {
                arrowHandleXLD = new HXLDCont();
            }
            arrowHandleXLD.Dispose();
            arrowHandleXLD.GenEmptyObj();

            //箭头起始点为直线长度的0.8位置
            rrow1 = startRow + (endRow - startRow) * 0.8;
            ccol1 = startCol + (endCol - startCol) * 0.8;
            //测量箭头起始点到直线终点的距离
            length = HMisc.DistancePp(rrow1, ccol1, endRow, endCol);
            //如果距离为0说明直线长度为0
            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)
            {
                arrowHandleXLD.GenContourPolygonXld(rrow1, ccol1);
            }
            else
            {
                arrowHandleXLD.GenContourPolygonXld(new HTuple(new double[] { rrow1, endRow, rowP1, endRow, rowP2, endRow }),
                                                    new HTuple(new double[] { ccol1, endCol, colP1, endCol, colP2, endCol }));
            }
        }
Пример #20
0
        /// <summary>
        /// Returns the convex hull from a collection of XLD contours.
        /// </summary>
        /// <param name="from">The collection of XLD contours to be processed.</param>
        /// <returns>An XLD contour that is the convex hull.</returns>
        /// <example> HXLDCont convexHullXld = MyXldContours.ConvexHull (); .</example>
        public static HXLDCont ConvexHull(this HXLDCont from)
        {
            HXLDCont tempContour = new HXLDCont(), convexHull = new HXLDCont();
            HTuple   cumulativeRows = new HTuple(), cumulativeColumns = new HTuple();

            try
            {
                if (@from != null && @from.IsValid())
                {
                    int count = @from.CountObj();
                    if (count > 1)
                    {
                        HTuple rows, columns;
                        for (int i = 1; i <= count; i++)
                        {
                            @from[i].GetContourXld(out rows, out columns);
                            cumulativeRows    = cumulativeRows.TupleConcat(rows);
                            cumulativeColumns = cumulativeColumns.TupleConcat(columns);
                        }

                        tempContour.GenContourPolygonXld(
                            cumulativeRows,
                            cumulativeColumns);
                        convexHull = tempContour.ShapeTransXld("convex");
                    }
                    else
                    {
                        convexHull = @from.ShapeTransXld("convex");
                    }
                }

                if (convexHull.IsInitialized())
                {
                    return(convexHull.CopyObj(1, -1));
                }
                else
                {
                    return(new HXLDCont());
                }
            }
            finally
            {
                tempContour.Dispose();
                convexHull.Dispose();
            }
        }
Пример #21
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 }));
            }
        }
Пример #22
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 }));
            }
        }
Пример #23
0
        private void drawOuterArc(HalconDotNet.HWindow window)
        {
            double   sPhi, extent, innerRad, outerRad;
            HTuple   innerR, outerR, innerC, outerC;
            HXLDCont outCont, innerCont, contour;

            outCont   = new HXLDCont();
            innerCont = new HXLDCont();

            var roiModel = this.getModelData();
            var mMeasROI = genArcRegionModel(roiModel);

            sPhi     = mMeasROI[2];
            extent   = mMeasROI[3];
            outerRad = mMeasROI[4];
            innerRad = mMeasROI[5];

            //畫內圓
            innerCont.GenCircleContourXld(mMeasROI[0], mMeasROI[1], innerRad, sPhi, (sPhi + extent), (extent > 0) ? "positive" : "negative", 1.0);

            //畫外圓
            outCont.GenCircleContourXld(mMeasROI[0], mMeasROI[1], outerRad, (sPhi + extent), sPhi, (extent > 0) ? "negative" : "positive", 1.0);

            innerCont.GetContourXld(out innerR, out innerC);
            outCont.GetContourXld(out outerR, out outerC);

            innerR = innerR.TupleConcat(outerR);
            innerC = innerC.TupleConcat(outerC);

            contour = new HXLDCont(innerR, innerC);
            contour = contour.CloseContoursXld();

            _ArcRegion.Dispose();
            _ArcRegion = contour.GenRegionContourXld("margin");
            window.DispObj(_ArcRegion);

            contour.Dispose();
            innerCont.Dispose();
            outCont.Dispose();
        }
        private void DisplayModelControur()
        {
            hWndCtrller.AddIconicVar(Model.ModelImg);
            hWndCtrller.ChangeGraphicSettings("Color", "blue");
            hWndCtrller.AddIconicVar(Model.SearchRegion);
            hWndCtrller.ChangeGraphicSettings("Color", "green");
            hWndCtrller.ChangeGraphicSettings("DrawMode", "margin");

            HHomMat2D mat2D = new HHomMat2D();

            mat2D.VectorAngleToRigid(0.0, 0.0, 0.0, Model.ModelImgRow, Model.ModelImgCol, Model.ModelimgAng);
            HXLDCont cont = Model.GetModelCont();

            if (cont != null)
            {
                double row, col;
                Model.shapeModel.GetShapeModelOrigin(out row, out col);
                mat2D = mat2D.HomMat2dTranslateLocal(row, col);

                hWndCtrller.AddIconicVar(cont.AffineTransContourXld(mat2D));
                cont.Dispose();
            }
        }
        /// <summary>
        /// 圓的顯示模式,文字顯示在圓心
        /// </summary>
        /// <returns></returns>
        public override ResultDisplayViewModel CreateDisplayViewModel()
        {
            var dispXLD = new HXLDCont();

            dispXLD.Dispose();
            dispXLD.GenEmptyObj();

            var row = 0.0;
            var col = 0.0;

            for (int i = 0; i < this.Row.Length; i++)
            {
                var radius = this.Radius[i].D;
                dispXLD.GenCircleContourXld(this.Row[i].D, this.Col[i].D, radius, 0.0, 6.28318, "positive", 1.0);
                row = this.Row[0].D;
                col = this.Col[0].D;
            }
            return(new ResultDisplayViewModel()
            {
                ImageXLD = dispXLD,
                PositionX = col,
                PositionY = row,
            });
        }
Пример #26
0
        private void btnLine_Click(object sender, EventArgs e)
        {
            if (this.HwControl != null)
            {
                double row1, column1, row2, column2;
                this.HwControl.HalconWindow.SetColor(this.LineColor);
                this.HwControl.Focus();
                this.HwControl.HalconWindow.DrawLine(out row1, out column1, out row2, out column2);
                this.linedata["Row1"]    = row1;
                this.linedata["Column1"] = column1;
                this.linedata["Row2"]    = row2;
                this.linedata["Column2"] = column2;

                if (this.DispLine)
                {
                    HXLDCont hLine = GetLine(this.linedata);
                    this.HwControl.HalconWindow.SetColor(this.LineColor);
                    this.HwControl.HalconWindow.DispObj(hLine);
                    hLine.Dispose();
                }
            }

            OnClick(e);
        }
Пример #27
0
        /// <summary>
        /// Creates an iconic object depicting the 
        /// measuring field.
        /// </summary>
        public void UpdateMeasureRegion()
        {
            mMeasureRegion.Dispose();
            mMeasureRegion.GenEmptyObj();

            if (mROIType == ROI.ROI_TYPE_CIRCLEARC)
            {
                double sPhi, extent, innerRad, outerRad;
                HTuple innerR, outerR, innerC, outerC;
                HXLDCont outCont, innerCont, contour;

                outCont = new HXLDCont();
                innerCont = new HXLDCont();

                sPhi = mMeasROI[2].D;
                extent = mMeasROI[3].D;
                outerRad = mMeasROI[4].D;
                innerRad = mMeasROI[5].D;

                innerCont.GenCircleContourXld(mMeasROI[0].D, mMeasROI[1].D, innerRad, sPhi, (sPhi + extent), (extent > 0) ? "positive" : "negative", 1.0);
                outCont.GenCircleContourXld(mMeasROI[0].D, mMeasROI[1].D, outerRad, (sPhi + extent), sPhi, (extent > 0) ? "negative" : "positive", 1.0);

                innerCont.GetContourXld(out innerR, out innerC);
                outCont.GetContourXld(out outerR, out outerC);
                innerR = innerR.TupleConcat(outerR);
                innerC = innerC.TupleConcat(outerC);

                contour = new HXLDCont(innerR, innerC);
                contour = contour.CloseContoursXld();

                mMeasureRegion = contour.GenRegionContourXld("margin");

                contour.Dispose();
                innerCont.Dispose();
                outCont.Dispose();
            }
            else
            {
                mMeasureRegion.GenRectangle2(mMeasROI[0].D, mMeasROI[1].D,
                                             mMeasROI[2].D, mMeasROI[3].D,
                                             mMeasROI[4].D);
            }
        }
Пример #28
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);
            }
        }
Пример #29
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));
            }
        }
Пример #30
0
        /// <summary>
        /// 圓的顯示模式,文字顯示在圓心
        /// </summary>
        /// <returns></returns>
        public override ResultDisplayViewModel CreateDisplayViewModel()
        {
            var dispXLD = new HXLDCont();
            dispXLD.Dispose();
            dispXLD.GenEmptyObj();

            var row = 0.0;
            var col = 0.0;
            for (int i = 0; i < this.Row.Length; i++)
            {
                var radius = this.Radius[i].D;
                dispXLD.GenCircleContourXld(this.Row[i].D, this.Col[i].D, radius, 0.0, 6.28318, "positive", 1.0);
                row = this.Row[0].D;
                col = this.Col[0].D;
            }
            return new ResultDisplayViewModel()
            {
                ImageXLD = dispXLD,
                PositionX = col,
                PositionY = row,
            };
        }
Пример #31
0
        public bool FindDataCode(HImage img, HRegion region, bool train = false)
        {
            if (!region.IsInitialized())
            {
                region = img.GetDomain();
            }

            if (!train)
            {
                Display(0, region);
            }


            HImage reduceImg = img.ReduceDomain(region);
            HImage searchImg = reduceImg.CropDomain();

            reduceImg.Dispose();

            int width, height;

            searchImg.GetImageSize(out width, out height);

            HImage zoomImg = searchImg.ZoomImageFactor(DateCodeZoomImg, DateCodeZoomImg, "constant");

            DataCodeContour.Dispose();
            searchImg.Dispose();

            HTuple ResultHandles, DecodedDataStrings;

            if (train)
            {
                DataCodeContour = CodeReaderHand.FindDataCode2d(zoomImg, "train", "all", out ResultHandles, out DecodedDataStrings);
            }
            else
            {
                DataCodeContour = CodeReaderHand.FindDataCode2d(zoomImg, "stop_after_result_num", 1, out ResultHandles, out DecodedDataStrings);
            }


            if (DecodedDataStrings.Length > 0)
            {
                DataCodeString = DecodedDataStrings[0].S;

                HHomMat2D mat = new HHomMat2D();
                HHomMat2D scalMat = mat.HomMat2dScale(1 / DateCodeZoomImg, 1 / DateCodeZoomImg, 0.0, 0.0);
                double    row, col;
                region.AreaCenter(out row, out col);
                HHomMat2D tranMat = scalMat.HomMat2dTranslate(row - height / 2.0, col - width / 2.0);

                HXLDCont tranDataCodeContour = tranMat.AffineTransContourXld(DataCodeContour);
                DataCodeContour.Dispose();
                DataCodeContour = tranDataCodeContour;

                if (!train)
                {
                    Display(2);
                    Display(3);
                }
            }
            else
            {
                if (UseBrighten)
                {
                    HImage brightenImg = zoomImg.ScaleImage(UseBrightenValue, 0.0);
                    DataCodeContour = CodeReaderHand.FindDataCode2d(brightenImg, "stop_after_result_num", 1, out ResultHandles, out DecodedDataStrings);
                    if (DecodedDataStrings.Length > 0)
                    {
                        DataCodeString = DecodedDataStrings[0].S;

                        HHomMat2D mat = new HHomMat2D();
                        HHomMat2D scalMat = mat.HomMat2dScale(1 / DateCodeZoomImg, 1 / DateCodeZoomImg, 0.0, 0.0);
                        double    row, col;
                        region.AreaCenter(out row, out col);
                        HHomMat2D tranMat = scalMat.HomMat2dTranslate(row - height / 2.0, col - width / 2.0);

                        HXLDCont tranDataCodeContour = tranMat.AffineTransContourXld(DataCodeContour);
                        DataCodeContour.Dispose();
                        DataCodeContour = tranDataCodeContour;
                        if (!train)
                        {
                            Display(2);
                            Display(3);
                        }

                        return(true);
                    }
                }



                DataCodeString = string.Empty;

                if (!train)
                {
                    Display(4);
                }
                return(false);
            }



            return(true);
        }
Пример #32
0
        /// <summary>Paints the ROI into the supplied window</summary>
        /// <param name="window">HALCON window</param>
        public override void draw(HalconDotNet.HWindow window, int imageWidth, int imageHeight)
        {
            contour.Dispose();
            contour.GenCircleContourXld(midR, midC, radius, startPhi,
                                        (startPhi + extentPhi), circDir, 1.0);
            double littleRecSize = 0;

            if (imageHeight < 300)
            {
                littleRecSize = 1;
            }
            else if (imageHeight < 600)
            {
                littleRecSize = 2;
            }
            else if (imageHeight < 900)
            {
                littleRecSize = 3;
            }
            else if (imageHeight < 1200)
            {
                littleRecSize = 4;
            }
            else if (imageHeight < 1500)
            {
                littleRecSize = 5;
            }
            else if (imageHeight < 1800)
            {
                littleRecSize = 6;
            }
            else if (imageHeight < 2100)
            {
                littleRecSize = 7;
            }
            else if (imageHeight < 2400)
            {
                littleRecSize = 8;
            }
            else if (imageHeight < 2700)
            {
                littleRecSize = 9;
            }
            else if (imageHeight < 3000)
            {
                littleRecSize = 10;
            }
            else if (imageHeight < 3300)
            {
                littleRecSize = 11;
            }
            else if (imageHeight < 3600)
            {
                littleRecSize = 12;
            }
            else if (imageHeight < 3900)
            {
                littleRecSize = 13;
            }
            else if (imageHeight < 4200)
            {
                littleRecSize = 14;
            }
            else if (imageHeight < 4500)
            {
                littleRecSize = 15;
            }
            else if (imageHeight < 4800)
            {
                littleRecSize = 16;
            }
            else if (imageHeight < 5100)
            {
                littleRecSize = 17;
            }
            else
            {
                littleRecSize = 18;
            }

            window.DispObj(contour);
            window.DispRectangle2(sizeR, sizeC, 0, littleRecSize, littleRecSize);
            window.DispRectangle2(midR, midC, 0, littleRecSize, littleRecSize);
            window.DispRectangle2(startR, startC, startPhi, littleRecSize, littleRecSize);
            window.DispRectangle2(extentR, extentC, 0, littleRecSize, littleRecSize);
            window.DispLine(startR, startC, midR, midC);
            window.DispLine(extentR, extentC, midR, midC);
        }
        public static ResultDisplayViewModel CreateDisplayViewModel(GeoDataGridViewModel model, bool textOnly, int circleDistanceSetting)
        {
            ResultDisplayViewModel viewModel = null;

            try
            {
                //init
                var dispXLD = new HXLDCont();
                dispXLD.Dispose();
                dispXLD.GenEmptyObj();

                double posX = model.Col1, posY = model.Row1;
                string dispName = model.Name;

                switch (model.GeoType)
                {
                    case ViewROI.MeasureType.Angle:
                        break;

                    case ViewROI.MeasureType.Circle:
                    case ViewROI.MeasureType.PointCircle:
                        var radius = model.Distance / circleDistanceSetting;
                        dispXLD.GenCircleContourXld(model.Row1, model.Col1, radius, 0.0, 6.28318, "positive", 1.0);
                        viewModel = new ResultDisplayViewModel()
                        {
                            DisplayText = dispName,
                            PositionX = posX,
                            PositionY = posY,
                        };
                        break;

                    case ViewROI.MeasureType.CrossPoint:
                    case ViewROI.MeasureType.Point:
                        dispXLD.GenCrossContourXld(model.Row1, model.Col1, 12, 0.785398);
                        viewModel = new ResultDisplayViewModel()
                        {
                            DisplayText = dispName,
                            PositionX = posX,
                            PositionY = posY,
                        };
                        break;

                    case ViewROI.MeasureType.Distance:
                    case ViewROI.MeasureType.DistanceX:
                    case ViewROI.MeasureType.DistanceY:
                    case ViewROI.MeasureType.FitLine:
                    case ViewROI.MeasureType.Line:
                    case ViewROI.MeasureType.SymmetryLine:
                        var arrowXLD = new HXLDCont();
                        //dispXLD.GenContourPolygonXld(new double[] { model.Row1, model.Row2 }, new double[] { model.Col1, model.Col2 });
                        posX = (model.Col1 + model.Col2) / 2.0;
                        posY = (model.Row1 + model.Row2) / 2.0;

                        viewModel = new ResultDisplayViewModel()
                        {
                            DisplayText = dispName,
                            PositionX = posX,
                            PositionY = posY,
                            FirstArrowX = model.Col1,
                            FirstArrowY = model.Row1,
                            SecArrowX = model.Col2,
                            SecArrowY = model.Row2,
                        };
                        break;
                }
                //
                if (!textOnly && viewModel != null)
                    viewModel.ImageXLD = dispXLD;

            }
            catch (Exception ex)
            {
                Hanbo.Log.LogManager.Error(ex);
            }

            return viewModel;
        }
Пример #34
0
        private void drawOuterArc(HalconDotNet.HWindow window)
        {
            double sPhi, extent, innerRad, outerRad;
            HTuple innerR, outerR, innerC, outerC;
            HXLDCont outCont, innerCont, contour;

            outCont = new HXLDCont();
            innerCont = new HXLDCont();

            var roiModel = this.getModelData();
            var mMeasROI = genArcRegionModel(roiModel);

            sPhi = mMeasROI[2];
            extent = mMeasROI[3];
            outerRad = mMeasROI[4];
            innerRad = mMeasROI[5];

            //畫內圓
            innerCont.GenCircleContourXld(mMeasROI[0], mMeasROI[1], innerRad, sPhi, (sPhi + extent), (extent > 0) ? "positive" : "negative", 1.0);

            //畫外圓
            outCont.GenCircleContourXld(mMeasROI[0], mMeasROI[1], outerRad, (sPhi + extent), sPhi, (extent > 0) ? "negative" : "positive", 1.0);

            innerCont.GetContourXld(out innerR, out innerC);
            outCont.GetContourXld(out outerR, out outerC);

            innerR = innerR.TupleConcat(outerR);
            innerC = innerC.TupleConcat(outerC);

            contour = new HXLDCont(innerR, innerC);
            contour = contour.CloseContoursXld();

            _ArcRegion.Dispose();
            _ArcRegion = contour.GenRegionContourXld("margin");
            window.DispObj(_ArcRegion);

            contour.Dispose();
            innerCont.Dispose();
            outCont.Dispose();
        }
Пример #35
0
        public static ResultDisplayViewModel CreateDisplayViewModel(GeoDataGridViewModel model, bool textOnly, int circleDistanceSetting)
        {
            ResultDisplayViewModel viewModel = null;

            try
            {
                //init
                var dispXLD = new HXLDCont();
                dispXLD.Dispose();
                dispXLD.GenEmptyObj();

                double posX = model.Col1, posY = model.Row1;
                string dispName = model.Name;

                switch (model.GeoType)
                {
                case ViewROI.MeasureType.Angle:
                    break;

                case ViewROI.MeasureType.Circle:
                case ViewROI.MeasureType.PointCircle:
                    var radius = model.Distance / circleDistanceSetting;
                    dispXLD.GenCircleContourXld(model.Row1, model.Col1, radius, 0.0, 6.28318, "positive", 1.0);
                    viewModel = new ResultDisplayViewModel()
                    {
                        DisplayText = dispName,
                        PositionX   = posX,
                        PositionY   = posY,
                    };
                    break;

                case ViewROI.MeasureType.CrossPoint:
                case ViewROI.MeasureType.Point:
                    dispXLD.GenCrossContourXld(model.Row1, model.Col1, 12, 0.785398);
                    viewModel = new ResultDisplayViewModel()
                    {
                        DisplayText = dispName,
                        PositionX   = posX,
                        PositionY   = posY,
                    };
                    break;

                case ViewROI.MeasureType.Distance:
                case ViewROI.MeasureType.DistanceX:
                case ViewROI.MeasureType.DistanceY:
                case ViewROI.MeasureType.FitLine:
                case ViewROI.MeasureType.Line:
                case ViewROI.MeasureType.SymmetryLine:
                    var arrowXLD = new HXLDCont();
                    //dispXLD.GenContourPolygonXld(new double[] { model.Row1, model.Row2 }, new double[] { model.Col1, model.Col2 });
                    posX = (model.Col1 + model.Col2) / 2.0;
                    posY = (model.Row1 + model.Row2) / 2.0;

                    viewModel = new ResultDisplayViewModel()
                    {
                        DisplayText = dispName,
                        PositionX   = posX,
                        PositionY   = posY,
                        FirstArrowX = model.Col1,
                        FirstArrowY = model.Row1,
                        SecArrowX   = model.Col2,
                        SecArrowY   = model.Row2,
                    };
                    break;
                }
                //
                if (!textOnly && viewModel != null)
                {
                    viewModel.ImageXLD = dispXLD;
                }
            }
            catch (Exception ex)
            {
                Hanbo.Log.LogManager.Error(ex);
            }

            return(viewModel);
        }