Ejemplo n.º 1
0
        /// <summary>
        /// 计算从ROI起始点,逆时针沿着ROI
        /// 到达ROI中点与指定点连线交ROI于某点时的曲线距离
        /// [弧长]
        /// </summary>
        /// <param name="row"></param>
        /// <param name="col"></param>
        /// <returns></returns>
        public override double GetDistanceFromStartPoint(double row, double col)
        {
            //计算向量A到向量B的角度,角度范围[-π,π];计算弧长时,圆心角范围[0,2π]
            HalconDotNet.HTuple hvAngle = new HalconDotNet.HTuple();
            HalconDotNet.HOperatorSet.AngleLl(new HalconDotNet.HTuple(_locateRow),
                                              new HalconDotNet.HTuple(_locateCol),
                                              new HalconDotNet.HTuple(_sizeRow),
                                              new HalconDotNet.HTuple(_sizeCol),
                                              new HalconDotNet.HTuple(_locateRow),
                                              new HalconDotNet.HTuple(_locateCol),
                                              new HalconDotNet.HTuple(row),
                                              new HalconDotNet.HTuple(col), out hvAngle);

            if (hvAngle.TupleNotEqual(new HalconDotNet.HTuple()))
            {
                if (hvAngle[0].D < 0)
                {
                    hvAngle[0] += 2 * Math.PI;
                }
            }

            return(_radius * hvAngle[0].D);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 添加图形对象
        /// </summary>
        /// <param name="hobj"></param>
        public void AddHobjEntity(HalconDotNet.HObject hobj)
        {
            InteractiveROI.HObjectEntity entry;
            if (hobj == null)
            {
                return;
            }
            HalconDotNet.HObject obj = hobj as HalconDotNet.HObject;

            if (obj != null &&
                obj.IsInitialized())
            {
                HalconDotNet.HTuple cls = new HalconDotNet.HTuple();
                HalconDotNet.HOperatorSet.GetObjClass(obj, out cls);

                if (cls.TupleNotEqual(new HalconDotNet.HTuple()))
                {
                    switch (cls[0].S)
                    {
                    case "image":
                    {
                        HalconDotNet.HTuple  r, c, h = new HalconDotNet.HTuple(), w = new HalconDotNet.HTuple(), area = new HalconDotNet.HTuple();
                        HalconDotNet.HObject domain;
                        HalconDotNet.HOperatorSet.GetDomain(obj, out domain);
                        if (domain != null &&
                            domain.IsInitialized())
                        {
                            HalconDotNet.HOperatorSet.AreaCenter(domain, out area, out r, out c);
                        }

                        if (area != null &&
                            area.TupleNotEqual(new HalconDotNet.HTuple()))
                        {
                            HalconDotNet.HOperatorSet.GetImageSize(obj, out w, out h);
                        }

                        if (w != null &&
                            w.TupleNotEqual(new HalconDotNet.HTuple()))
                        {
                            if (area[0].I == (w * h)[0].I)        //有效图像(即定义域面积等于其宽高乘积)
                            {
                                ClearEntities();

                                if ((h[0].I != _imageHeight) || (w[0].I != _imageWidth))
                                {
                                    _imageHeight  = h;
                                    _imageWidth   = w;
                                    ZoomWndFactor = (double)_imageWidth / _hWndCtrl.Width;
                                    SetImagePart(0, 0, h[0].I, w[0].I);
                                }
                            }
                        }

                        entry = new HObjectEntity(hobj, _grpCntx.CopyGraphicSettings());
                        _hObjEntityList.Add(entry);
                    }
                    break;

                    case "region":
                    case "xld_cont":
                        entry = new HObjectEntity(hobj, _grpCntx.CopyGraphicSettings());
                        _hObjEntityList.Add(entry);
                        break;

                    case "xld_poly":
                        break;

                    case "xld_parallel":
                        break;

                    default: break;
                    }
                }

                if (_hObjEntityList.Count > _MaxNum)
                {
                    _hObjEntityList.RemoveAt(1);
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Calculates the ModelROI region for all objects contained
        /// in ROIList, by adding and subtracting the positive and
        /// negative ROI objects.
        /// 计算合成区域(联合结果)
        /// </summary>
        public bool CalculateSyntheticalRegion()
        {
            HalconDotNet.HObject tmpAdd, tmpDiff, tmp;
            HalconDotNet.HTuple  area = new HalconDotNet.HTuple(), row = new HalconDotNet.HTuple(), col = new HalconDotNet.HTuple();

            if (_operationFlag == ROI_MODE_NONE)
            {
                return(true);
            }

            tmpAdd = new HalconDotNet.HObject();
            tmpAdd.GenEmptyObj();
            tmpDiff = new HalconDotNet.HObject();
            tmpDiff.GenEmptyObj();
            tmp = new HalconDotNet.HObject();
            tmp.GenEmptyObj();

            for (int i = 0; i < ROIList.Count; i++)
            {
                switch (((ROI)ROIList[i]).GetOperationFlag())
                {
                case ROI.MODE_NEGATIVE:
                    HalconDotNet.HOperatorSet.Union2(tmpDiff, ((ROI)ROIList[i]).GetModelRegion(), out tmpDiff);
                    break;

                case ROI.MODE_POSITIVE:
                    HalconDotNet.HOperatorSet.Union2(tmpAdd, ((ROI)ROIList[i]).GetModelRegion(), out tmpAdd);
                    break;
                }
            }

            if (_syntheticalRegion != null &&
                _syntheticalRegion.IsInitialized())
            {
                _syntheticalRegion.Dispose();
            }
            HalconDotNet.HOperatorSet.AreaCenter(tmpAdd, out area, out row, out col);

            if (area.TupleNotEqual(new HalconDotNet.HTuple()) &&
                area[0].D > 0)
            {
                if (tmp != null && tmp.IsInitialized())
                {
                    tmp.Dispose();
                }
                HalconDotNet.HOperatorSet.Difference(tmpAdd, tmpDiff, out tmp);

                HalconDotNet.HOperatorSet.AreaCenter(tmp, out area, out row, out col);
                if (area.TupleNotEqual(new HalconDotNet.HTuple()) &&
                    area[0].D > 0)
                {
                    _syntheticalRegion = tmp;
                }
            }

            if (_syntheticalRegion == null || ROIList.Count == 0)
            {
                return(false);
            }

            return(true);
        }