Example #1
0
        public override void Draw(HalconDotNet.HTuple hwndHandle)
        {
            HalconDotNet.HObject line = new HalconDotNet.HObject(), rec1 = new HalconDotNet.HObject(), rec2 = new HalconDotNet.HObject();
            line.Dispose();
            HalconDotNet.HOperatorSet.GenRegionLine(out line,
                                                    new HalconDotNet.HTuple(_startRow),
                                                    new HalconDotNet.HTuple(_startCol),
                                                    new HalconDotNet.HTuple(_extentRow),
                                                    new HalconDotNet.HTuple(_extentCol));
            HalconDotNet.HOperatorSet.DispObj(line, hwndHandle);

            rec1.Dispose();
            HalconDotNet.HOperatorSet.GenRectangle2(out rec1,
                                                    new HalconDotNet.HTuple(_startRow),
                                                    new HalconDotNet.HTuple(_startCol),
                                                    new HalconDotNet.HTuple(0),
                                                    new HalconDotNet.HTuple(5),
                                                    new HalconDotNet.HTuple(5));
            HalconDotNet.HOperatorSet.DispObj(rec1, hwndHandle);

            rec2.Dispose();
            HalconDotNet.HOperatorSet.GenRectangle2(out rec2,
                                                    new HalconDotNet.HTuple(_locateRow),
                                                    new HalconDotNet.HTuple(_locateCol),
                                                    new HalconDotNet.HTuple(0),
                                                    new HalconDotNet.HTuple(5),
                                                    new HalconDotNet.HTuple(5));
            HalconDotNet.HOperatorSet.DispObj(rec2, hwndHandle);
            if (_arrowHandle != null &&
                _arrowHandle.IsInitialized())
            {
                HalconDotNet.HOperatorSet.DispObj(_arrowHandle, hwndHandle);
            }
        }
Example #2
0
        protected internal virtual void FrmInteractiveROI_Load(object sender, EventArgs e)
        {
            InitFieldAndProperty();
            UpdateControl();

            if (_hoImage != null &&
                _hoImage.IsInitialized())
            {
                _HwndCtrller.AddHobjEntity(_hoImage);
                _HwndCtrller.Repaint();//ROI--传递图像,重新渲染图形
            }
        }
        /// <summary>
        /// 窗口1显示的内容
        /// [可以自定义显示的内容]
        /// </summary>
        /// <param name="appProData"></param>
        private void Camera0UpdateIconic(ProVisionEbd.Data.AppProcessData appProData)
        {
            try
            {
                if (_hwndCtrller0 != null)
                {
                    if (appProData != null)
                    {
                        this.Invoke(new System.Windows.Forms.MethodInvoker(() => {
                            _hwndCtrller0.ClearEntities();
                            _hwndCtrller0.ClearMessageLineList();

                            if (_hoImage0 != null &&
                                _hoImage0.IsInitialized())
                            {
                                _hoImage0.Dispose();
                            }

                            _hoImage0 = appProData.RawImage.Clone();
                            _hwndCtrller0.AddHobjEntity(_hoImage0);

                            _hwndCtrller0.ChangeGraphicSettings(ProVision.InteractiveROI.GraphicContext.GC_COLOR, "yellow");
                            _hwndCtrller0.AddHobjEntity(appProData.InspetcRegion);
                            ProVision.Communal.MessageLine msl = new ProVision.Communal.MessageLine();

                            if (appProData.ImgProcessOK)
                            {
                                if (appProData.ImgResultOK)
                                {
                                    msl.Context  = "处理结果满足要求";
                                    msl.CtxColor = "green";
                                    _hwndCtrller0.ChangeGraphicSettings(ProVision.InteractiveROI.GraphicContext.GC_COLOR, "green");
                                }
                                else
                                {
                                    msl.Context  = "处理结果不满足要求";
                                    msl.CtxColor = "red";
                                    _hwndCtrller0.ChangeGraphicSettings(ProVision.InteractiveROI.GraphicContext.GC_COLOR, "red");
                                }
                            }
                            else
                            {
                                msl.Context  = "图像处理异常";
                                msl.CtxColor = "red";
                                _hwndCtrller0.ChangeGraphicSettings(ProVision.InteractiveROI.GraphicContext.GC_COLOR, "red");
                            }

                            _hwndCtrller0.AddMessageLine(msl);
                            _hwndCtrller0.AddHobjEntity(appProData.ResultRegion);
                            _hwndCtrller0.Repaint();
                            appProData.Dispose();
                        }));
                    }
                }
            }
            catch (HalconDotNet.HalconException hex) { }
            catch (System.Exception ex) { }
        }
Example #4
0
 protected void GetImageSize(HalconDotNet.HObject img, out HalconDotNet.HTuple wdth, out HalconDotNet.HTuple hgh)
 {
     wdth = null;
     hgh  = null;
     if (img != null &&
         img.IsInitialized())
     {
         HalconDotNet.HOperatorSet.GetImageSize(img, out wdth, out hgh);
     }
 }
Example #5
0
        protected CameraDriver(ProCommon.Communal.CameraProperty camProperty)
        {
            if (HoImage != null &&
                HoImage.IsInitialized())
            {
                HoImage.Dispose();
            }
            HalconDotNet.HOperatorSet.GenEmptyObj(out HoImage);

            DriverExceptionDel  = new DriverExceptionOccuredDel(OnDriverExceptionOccured);
            this.CameraProperty = camProperty;
        }
Example #6
0
        public override bool Process(HalconDotNet.HObject hobjRaw)
        {
            bool rt = false;

            ResultOK = false;

            try
            {
                if (_IsLaunchAllowed)
                {
                    _RawImage = hobjRaw;

                    if (_IsEnableAlgorithm)
                    {
                        //1-算法需要的参数是否有效,进行图像处理
                        if (InspectArea != null &&
                            InspectArea.IsInitialized())
                        {
                            //2-进行算法处理,更新函数返回值
                            if (LocationMembrane2())
                            {
                                //3-更新图像处理结果标记:根据是否达标,更新图像处理结果标记
                                //4-显示图像处理结果图形变量,信息变量
                                Row = _matchModelAssistant.Result.Row;
                                Col = _matchModelAssistant.Result.Col;
                                Agl = _matchModelAssistant.Result.Angle;

                                ResultOK = rt = true;
                            }
                        }
                    }
                }
            }
            catch (HalconDotNet.HalconException hex) { ErrorMessage = hex.Message; }
            catch (System.Exception ex) { ErrorMessage = ex.Message; }
            finally { }
            return(rt);
        }
 private void OnCameraImageGrabbed(ProCommon.Communal.Camera cam, HalconDotNet.HObject hoImage)
 {
     if (hoImage != null &&
         hoImage.IsInitialized())
     {
         if (HoImage != null &&
             HoImage.IsInitialized())
         {
             HoImage.Dispose();
         }
         HoImage = hoImage;
         if (ImageGrabbedEvt != null)
         {
             ImageGrabbedEvt(cam, HoImage);
         }
     }
 }
Example #8
0
        /// <summary>
        /// Clears all variables managing ROI objects
        /// 删除ROI列表
        /// </summary>
        public void Reset()
        {
            ROIList.Clear();
            ResetInstantROI();
            if (_syntheticalRegion != null &&
                _syntheticalRegion.IsInitialized())
            {
                _syntheticalRegion.Dispose();
            }
            _syntheticalRegion = null;

            if (_nonUnionPositiveRegion != null &&
                _nonUnionPositiveRegion.IsInitialized())
            {
                _nonUnionPositiveRegion.Dispose();
            }
            _nonUnionPositiveRegion = null;

            IconicUpdatedDel(EVENT_DELETED_ALL_ROIS);
        }
Example #9
0
        public override HalconDotNet.HObject GetModelRegion()
        {
            if (_circularArc != null &&
                _circularArc.IsInitialized())
            {
                _circularArc.Dispose();
            }

            HalconDotNet.HOperatorSet.GenCircleContourXld(out _circularArc,
                                                          new HalconDotNet.HTuple(_locateRow),
                                                          new HalconDotNet.HTuple(_locateCol),
                                                          new HalconDotNet.HTuple(_radius),
                                                          new HalconDotNet.HTuple(_startPhi),
                                                          new HalconDotNet.HTuple(_startPhi + _extentPhi),
                                                          new HalconDotNet.HTuple(_circularArcDir),
                                                          new HalconDotNet.HTuple(1.0));
            HalconDotNet.HObject rg = new HalconDotNet.HObject();
            rg.Dispose();
            HalconDotNet.HOperatorSet.GenRegionContourXld(_circularArc, out rg, "margin");
            return(rg);
        }
Example #10
0
        /// <summary>
        /// Releases the memory for all iconic HALCON objects contained in
        /// this instance.
        /// 释放包含在该类中的图形对象
        /// </summary>
        public void Clear()
        {
            _hImage.Dispose();
            _caltabRegion.Dispose();

            if (_caltabRegion != null &&
                _caltabRegion.IsInitialized())
            {
                _caltabRegion.Dispose();
            }

            if (_markCenterXLD != null &&
                _markCenterXLD.IsInitialized())
            {
                _markCenterXLD.Dispose();
            }

            if (_estimatedWorldCoordinateSystem != null &&
                _estimatedWorldCoordinateSystem.IsInitialized())
            {
                _estimatedWorldCoordinateSystem.Dispose();
            }
        }
Example #11
0
        protected override bool DoSoftTriggerOnce()
        {
            bool rt = false;

            try
            {
                if (!AcqHandle.TupleEqual(new HalconDotNet.HTuple()))
                {
                    if (!_imgData.IsInitialized())
                    {
                        _imgData = new HalconDotNet.HObject();
                    }

                    _imgData.Dispose();
                    HalconDotNet.HOperatorSet.GrabImageAsync(out _imgData, AcqHandle, GrabTimeOut);

                    if (_imgData != null)
                    {
                        //触发图像采集完成事件
                        OnImgDataOut();
                        rt = true;
                    }
                }
            }
            catch (HalconDotNet.HalconException hex)
            {
                if (DriverExceptionDel != null)
                {
                    DriverExceptionDel(string.Format("错误:Halcon模拟相机异步抓取失败!\n错误代码:{0}", hex.GetErrorCode()));
                }
            }
            finally
            {
            }
            return(rt);
        }
Example #12
0
        private void ModifyRegion()
        {
            bool   isChs   = LanguageVersion == ProCommon.Communal.Language.Chinese;
            string txt     = isChs ? "修改区域异常!" : "Error occured when modify region!";
            string caption = isChs ? "警告信息" : "Warning Message";

            HalconDotNet.HTuple  mr, mc, mbtntype;
            HalconDotNet.HObject tmpModify = null;
            HalconDotNet.HObject tmpKeep = null, tmpSelect = null;

            HalconDotNet.HOperatorSet.GenEmptyObj(out tmpKeep);
            HalconDotNet.HOperatorSet.GenEmptyObj(out tmpSelect);

            int cnt = 0;

            this.hwndcDisplay.Focus();
            UpdateRegionForDisplay();

            while (_isModifying)
            {
                try
                {
                    HalconDotNet.HOperatorSet.GetMposition(this.hwndcDisplay.HalconWindow, out mr, out mc, out mbtntype);

                    if (_hoBrushRegion != null &&
                        _hoBrushRegion.IsInitialized())
                    {
                        _hoBrushRegion.Dispose();
                    }

                    HalconDotNet.HOperatorSet.GenRectangle1(out _hoBrushRegion, mr - _zoomFactorForBrush, mc - _zoomFactorForBrush, mr + _zoomFactorForBrush, mc + _zoomFactorForBrush);

                    UpdateRegionForDisplay();
                    if (mbtntype.TupleEqual(new HalconDotNet.HTuple(1))) //按下鼠标左键
                    {
                        HalconDotNet.HOperatorSet.Difference(_hoSelectedRegion, _hoBrushRegion, out tmpModify);

                        _hoSelectedRegion.Dispose();
                        _hoSelectedRegion = tmpModify;

                        //若初始区域为数组型
                        cnt = _hoModifiedRegion.CountObj();

                        for (int i = 0; i < cnt; i++)
                        {
                            tmpSelect.Dispose();

                            //未选择的区域,不修改,需要保留
                            if (i != this.lstbRegion.SelectedIndex)
                            {
                                HalconDotNet.HOperatorSet.SelectObj(_hoModifiedRegion, out tmpSelect, i + 1);
                            }
                            //选择的区域,更新为上述修改后的区域
                            else
                            {
                                HalconDotNet.HOperatorSet.CopyObj(_hoSelectedRegion, out tmpSelect, 1, 1);
                            }

                            HalconDotNet.HOperatorSet.ConcatObj(tmpKeep, tmpSelect, out tmpKeep);
                        }

                        tmpSelect.Dispose();

                        _hoModifiedRegion.Dispose();
                        _hoModifiedRegion = tmpKeep;

                        HalconDotNet.HOperatorSet.WaitSeconds(0.001);
                    }
                    else if (mbtntype.TupleEqual(new HalconDotNet.HTuple(4))) //按下鼠标右键
                    {
                        _isModifying = false;

                        if (_hoBrushRegion != null &&
                            _hoBrushRegion.IsInitialized())
                        {
                            _hoBrushRegion.Dispose();
                        }

                        //UpdateRegionForDisplay();

                        _isModified = true;
                    }
                }
                catch (HalconDotNet.HalconException hex)
                {
                    //_isModifying = false;
                    //ProCommon.DerivedForm.FrmMsgBox.Show(txt + "\r\n" + hex.Message, caption,
                    //    ProCommon.DerivedForm.MyButtons.OK,
                    //    ProCommon.DerivedForm.MyIcon.Error, isChs);
                }

                //System.Threading.Thread.Sleep(1);
                Application.DoEvents();
            }
        }
Example #13
0
        private void Bbi_Click(object sender, ItemClickEventArgs e)
        {
            switch (e.Item.Tag.ToString())
            {
            case "BBI_LOADIMAGE":
                LoadImage();
                break;

            case "BBI_LINE":
                if (_hoImage != null &&
                    _hoImage.IsInitialized())
                {
                    if (_ROIManager != null)
                    {
                        _ROIManager.SetROIShape(new ProVision.InteractiveROI.ROILine());     //定义区域时,矢量线段不响应;主要用在定义测量
                    }
                }
                break;

            case "BBI_RECTANGLE1":
                if (_hoImage != null &&
                    _hoImage.IsInitialized())
                {
                    if (_ROIManager != null)
                    {
                        _ROIManager.SetROIShape(new ProVision.InteractiveROI.ROIRectangle1());
                    }
                }
                break;

            case "BBI_RECTANGLE2":
                if (_hoImage != null &&
                    _hoImage.IsInitialized())
                {
                    if (_ROIManager != null)
                    {
                        _ROIManager.SetROIShape(new ProVision.InteractiveROI.ROIRectangle2());
                    }
                }
                break;

            case "BBI_CIRCULARARC":
                if (_hoImage != null &&
                    _hoImage.IsInitialized())
                {
                    if (_ROIManager != null)
                    {
                        _ROIManager.SetROIShape(new ProVision.InteractiveROI.ROICircularArc());     //定义区域时,有向圆弧不响应;主要用在定义测量
                    }
                }
                break;

            case "BBI_CIRCLE":
                if (_hoImage != null &&
                    _hoImage.IsInitialized())
                {
                    if (_ROIManager != null)
                    {
                        _ROIManager.SetROIShape(new ProVision.InteractiveROI.ROICircle());
                    }
                }
                break;

            case "BBI_ANNULUS":
                if (_hoImage != null &&
                    _hoImage.IsInitialized())
                {
                    if (_ROIManager != null)
                    {
                        _ROIManager.SetROIShape(new ProVision.InteractiveROI.ROIAnnulus());
                    }
                }
                break;

            case "BBI_DELETEACTIVEROI":
                if (_hoImage != null &&
                    _hoImage.IsInitialized())
                {
                    if (_ROIManager != null)
                    {
                        _ROIManager.RemoveActiveROI();
                    }
                }
                break;

            case "BBI_DELETEALLROI":
                if (_hoImage != null &&
                    _hoImage.IsInitialized())
                {
                    if (_ROIManager != null)
                    {
                        _HwndCtrller.ResetAll();
                        _HwndCtrller.Repaint();
                    }
                }
                break;

            case "BBI_RESETWINDOW":
                if (_hoImage != null &&
                    _hoImage.IsInitialized())
                {
                    if (_ROIManager != null)
                    {
                        _HwndCtrller.ResetWindow();
                        _HwndCtrller.Repaint();
                    }
                }
                break;

            case "BBI_CLEARICONIC":
                if (_hoImage != null &&
                    _hoImage.IsInitialized())
                {
                    if (_ROIManager != null)
                    {
                        _HwndCtrller.ResetAll();

                        if (_hoModifiedRegion != null &&
                            _hoModifiedRegion.IsInitialized())
                        {
                            _hoModifiedRegion.Dispose();
                        }

                        if (_hoSelectedRegion != null &&
                            _hoSelectedRegion.IsInitialized())
                        {
                            _hoSelectedRegion.Dispose();
                        }

                        this.bchkiModifyRegion.Checked = false;
                        this.lstbRegion.Items.Clear();
                        _isUpdated = false;
                    }
                }
                break;

            case "BBI_UPDATEREGION":

                _isUpdated = false;
                if (_hoImage != null &&
                    _hoImage.IsInitialized())
                {
                    //若非传入区域
                    if (!_isTransmitted)
                    {
                        if (_ROIManager != null)
                        {
                            if (_hoRawRegion != null &&
                                _hoRawRegion.IsInitialized())
                            {
                                _hoRawRegion.Dispose();
                            }
                            HalconDotNet.HOperatorSet.GenEmptyObj(out _hoRawRegion);

                            _roiList = _ROIManager.ROIList;

                            if (_roiList != null &&
                                _roiList.Count > 0)
                            {
                                this.lstbRegion.Items.Clear();
                                string roiType = "";

                                for (int i = 0; i < _roiList.Count; i++)
                                {
                                    HalconDotNet.HOperatorSet.ConcatObj(_hoRawRegion, ((ProVision.InteractiveROI.ROI)_roiList[i]).GetModelRegion(), out _hoRawRegion);
                                    roiType = ((ProVision.InteractiveROI.ROI)_roiList[i]).ROIShape.ToString();
                                    this.lstbRegion.Items.Add(i.ToString("00") + "[" + roiType + "]");
                                }

                                if (_hoModifiedRegion != null &&
                                    _hoModifiedRegion.IsInitialized())
                                {
                                    _hoModifiedRegion.Dispose();
                                }

                                _hoModifiedRegion             = _hoRawRegion.Clone();
                                this.lstbRegion.SelectedIndex = 0;
                                HalconDotNet.HOperatorSet.SelectObj(_hoModifiedRegion, out _hoSelectedRegion, 1);
                                _isUpdated = true;
                            }
                        }
                    }
                    else
                    {
                        //传入区域--作为单一区域
                        this.lstbRegion.Items.Clear();
                        this.lstbRegion.Items.Add("00" + "[Arbitrary]");
                        if (_hoModifiedRegion != null &&
                            _hoModifiedRegion.IsInitialized())
                        {
                            _hoModifiedRegion.Dispose();
                        }

                        //修改区域与选择区域为同一指向
                        HalconDotNet.HOperatorSet.SelectObj(_hoRawRegion, out _hoModifiedRegion, 1);
                        _hoSelectedRegion = _hoModifiedRegion;
                    }
                }
                break;

            default: break;
            }
        }
Example #14
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);
        }
Example #15
0
        private void Bbi_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            switch (e.Item.Tag.ToString())
            {
            case "BBI_RECTANGLE1":
                if (_tstImage != null &&
                    _tstImage.IsInitialized())
                {
                    if (_roiMgr != null)
                    {
                        _roiMgr.ROIList.Clear();
                        _rectangle1 = null;
                        _rectangle2 = null;
                        _circle     = null;
                        _cross      = null;

                        if (_rectangle1 == null)
                        {
                            _rectangle1 = new ProVision.InteractiveROI.ROIRectangle1();
                        }

                        HalconDotNet.HOperatorSet.GetImageSize(_tstImage, out _imgWidth, out _imgHeight);
                        _rectangle1.CreateROI(_imgHeight / 2, _imgWidth / 2);
                        _roiMgr.SetROIShape(_rectangle1);

                        _hwndCtrller.Repaint();
                    }
                }

                break;

            case "BBI_RECTANGLE2":
                if (_tstImage != null &&
                    _tstImage.IsInitialized())
                {
                    if (_roiMgr != null)
                    {
                        _roiMgr.ROIList.Clear();
                        _rectangle1 = null;
                        _rectangle2 = null;
                        _circle     = null;
                        _cross      = null;

                        if (_rectangle2 == null)
                        {
                            _rectangle2 = new ProVision.InteractiveROI.ROIRectangle2();
                        }

                        HalconDotNet.HOperatorSet.GetImageSize(_tstImage, out _imgWidth, out _imgHeight);
                        _rectangle2.CreateROI(_imgHeight / 2, _imgWidth / 2);
                        _roiMgr.SetROIShape(_rectangle2);

                        _hwndCtrller.Repaint();
                    }
                }

                break;

            case "BBI_CIRCLE":
                if (_tstImage != null &&
                    _tstImage.IsInitialized())
                {
                    if (_roiMgr != null)
                    {
                        _roiMgr.ROIList.Clear();
                        _rectangle1 = null;
                        _rectangle2 = null;
                        _circle     = null;
                        _cross      = null;

                        if (_circle == null)
                        {
                            _circle = new ProVision.InteractiveROI.ROICircle();
                        }

                        HalconDotNet.HOperatorSet.GetImageSize(_tstImage, out _imgWidth, out _imgHeight);
                        _circle.CreateROI(_imgHeight / 2, _imgWidth / 2);
                        _roiMgr.SetROIShape(_circle);

                        _hwndCtrller.Repaint();
                    }
                }

                break;

            case "BBI_CENTERCROSS":
                if (_tstImage != null &&
                    _tstImage.IsInitialized())
                {
                    if (_roiMgr != null)
                    {
                        _roiMgr.ROIList.Clear();
                        _rectangle1 = null;
                        _rectangle2 = null;
                        _circle     = null;
                        _cross      = null;

                        if (_cross == null)
                        {
                            _cross = new ProVision.InteractiveROI.ROICross();
                        }

                        HalconDotNet.HOperatorSet.GetImageSize(_tstImage, out _imgWidth, out _imgHeight);
                        _cross.CreateROI(_imgHeight / 2, _imgWidth / 2);
                        _roiMgr.SetROIShape(_cross);

                        _hwndCtrller.Repaint();
                    }
                }
                break;

            case "BBI_CLEARICONIC":
                if (_roiMgr != null)
                {
                    _roiMgr.ROIList.Clear();
                    _rectangle1 = null;
                    _rectangle2 = null;
                    _circle     = null;
                    _cross      = null;

                    _hwndCtrller.Repaint();
                }
                break;

            default: break;
            }
        }
Example #16
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);
                }
            }
        }
Example #17
0
        protected internal virtual void UpdateControl()
        {
            bool   isChs = (LanguageVersion == ProCommon.Communal.Language.Chinese);
            string str   = this.Tag.ToString();

            this.Text = isChs ? ProCommon.Properties.Resources.ResourceManager.GetString("chs_" + str) : ProCommon.Properties.Resources.ResourceManager.GetString("en_" + str);

            UpdateBarButtonItem(this.bbiLoadImage, LanguageVersion, ProCommon.Properties.Resources.ResourceManager);
            UpdateBarButtonItem(this.bbiLine, LanguageVersion, ProCommon.Properties.Resources.ResourceManager);
            UpdateBarButtonItem(this.bbiRectangle1, LanguageVersion, ProCommon.Properties.Resources.ResourceManager);
            UpdateBarButtonItem(this.bbiRectangle2, LanguageVersion, ProCommon.Properties.Resources.ResourceManager);
            UpdateBarButtonItem(this.bbiCircle, LanguageVersion, ProCommon.Properties.Resources.ResourceManager);
            UpdateBarButtonItem(this.bbiCircularArc, LanguageVersion, ProCommon.Properties.Resources.ResourceManager);
            UpdateBarButtonItem(this.bbiAnnulus, LanguageVersion, ProCommon.Properties.Resources.ResourceManager);
            UpdateBarButtonItem(this.bbiDeleteActiveROI, LanguageVersion, ProCommon.Properties.Resources.ResourceManager);
            UpdateBarButtonItem(this.bbiDeleteAllROI, LanguageVersion, ProCommon.Properties.Resources.ResourceManager);
            UpdateBarButtonItem(this.bbiResetWindow, LanguageVersion, ProCommon.Properties.Resources.ResourceManager);
            UpdateBarButtonItem(this.bbiClearIconic, LanguageVersion, ProCommon.Properties.Resources.ResourceManager);

            UpdateBarCheckItem(this.bchkiNone, LanguageVersion, ProCommon.Properties.Resources.ResourceManager);
            UpdateBarCheckItem(this.bchkiMove, LanguageVersion, ProCommon.Properties.Resources.ResourceManager);
            UpdateBarCheckItem(this.bchkiZoom, LanguageVersion, ProCommon.Properties.Resources.ResourceManager);
            UpdateBarCheckItem(this.bchkiMagnify, LanguageVersion, ProCommon.Properties.Resources.ResourceManager);
            UpdateBarButtonItem(this.bbiUpdateRegion, LanguageVersion, ProCommon.Properties.Resources.ResourceManager);
            UpdateBarCheckItem(this.bchkiModifyRegion, LanguageVersion, ProCommon.Properties.Resources.ResourceManager);


            this.lstbRegion.SelectedIndexChanged -= LstbRegion_SelectedIndexChanged;
            this.lstbRegion.SelectedIndexChanged += LstbRegion_SelectedIndexChanged;

            if (_hoImage != null &&
                _hoImage.IsInitialized())
            {
                _HwndCtrller.ClearEntities();
                if (_ROIManager != null)
                {
                    _ROIManager.ROIList.Clear();
                }

                HalconDotNet.HOperatorSet.GetImageSize(_hoImage, out _imgWidth, out _imgHeight);
                HalconDotNet.HOperatorSet.SetSystem("tsp_height", _imgHeight);
                HalconDotNet.HOperatorSet.SetSystem("tsp_width", _imgWidth);

                _HwndCtrller.AddHobjEntity(_hoImage);
                _HwndCtrller.Repaint();
            }
        }