/// <summary> /// 显示鼠标点中的瑕疵 /// </summary> public void addIconicVarShow(HObject obj) { if (obj is HImage) { return; } if (HObjList == null) { return; } if (HObjList.Count == 0) { return; } HObjectEntry entry; entry = new HObjectEntry(obj, mGC.copyContextList()); if (IsFirst) { IsFirst = false; } else { HObjList.RemoveAt(HObjList.Count - 1); } HObjList.Add(entry); }
/********************************************************************/ /* GRAPHICSSTACK */ /********************************************************************/ /// <summary> /// Adds an iconic object to the graphics stack similar to the way /// it is defined for the HDevelop graphics stack. /// </summary> /// <param name="obj">Iconic object</param> public void addIconicVar(HObject obj) { HObjectEntry entry; if (obj == null) { return; } if (obj is HImage) { double r, c; int h, w, area; string s; viewPort.HMouseUp -= new HalconDotNet.HMouseEventHandler(this.mouseUp); viewPort.HMouseDown -= new HalconDotNet.HMouseEventHandler(this.mouseDown); viewPort.HMouseMove -= new HalconDotNet.HMouseEventHandler(this.mouseMoved); viewPort.HMouseWheel -= new HalconDotNet.HMouseEventHandler(this.HMouseWheel); area = ((HImage)obj).GetDomain().AreaCenter(out r, out c); ((HImage)obj).GetImagePointer1(out s, out w, out h); //if (area == (w * h)) //{ clearList(); if ((h != imageHeight) || (w != imageWidth)) { imageHeight = h; imageWidth = w; zoomWndFactor = (double)imageWidth / viewPort.Width; Size WindSize = viewPort.Size; double WindC = ((double)WindSize.Height) / ((double)WindSize.Width); double ImgC = ((double)imageHeight) / ((double)imageWidth); if (WindC > ImgC) { h = (int)(w * WindC); setImagePart(0 - (h - imageHeight) / 2, 0, h - (h - imageHeight) / 2, w); } else { w = (int)(h / WindC); setImagePart(0, 0, h, w); } zoomImage(imageHeight / 2, imageHeight / 2, 1); } //}//if viewPort.HMouseUp += new HalconDotNet.HMouseEventHandler(this.mouseUp); viewPort.HMouseDown += new HalconDotNet.HMouseEventHandler(this.mouseDown); viewPort.HMouseMove += new HalconDotNet.HMouseEventHandler(this.mouseMoved); viewPort.HMouseWheel += new HalconDotNet.HMouseEventHandler(this.HMouseWheel); } //if entry = new HObjectEntry(obj, mGC.copyContextList()); // HObjList.Add(entry); if (HObjList.Count > MAXNUMOBJLIST) { HObjList.RemoveAt(1); } }
public void FitImage() { if (HObjList.Count == 0) { return; } HObjectEntry entry = HObjList[0] as HObjectEntry; if (entry.HObj is HImage) { double r, c; int h, w, area; string s; area = ((HImage)entry.HObj).GetDomain().AreaCenter(out r, out c); ((HImage)entry.HObj).GetImagePointer1(out s, out w, out h); if ((h != imageHeight) || (w != imageWidth)) { int _beginRow, _begin_Col, _endRow, _endCol; double ratio_win = (double)viewPort.ActualWidth / (double)viewPort.ActualHeight; double ratio_img = (double)w / (double)h; imageHeight = h; imageWidth = w; if (ratio_win >= ratio_img) { _beginRow = 0; _endRow = h - 1; _begin_Col = (int)(-w * (ratio_win / ratio_img - 1d) / 2d); _endCol = (int)(w + w * (ratio_win / ratio_img - 1d) / 2d); zoomWndFactor = (double)h / viewPort.ActualHeight; } else { _begin_Col = 0; _endCol = w - 1; _beginRow = (int)(-h * (ratio_img / ratio_win - 1d) / 2d); _endRow = (int)(h + h * (ratio_img / ratio_win - 1d) / 2d); zoomWndFactor = (double)w / viewPort.ActualWidth; } //viewPort.HalconWindow.SetPart(_beginRow, _begin_Col, _endRow, _endCol); setImagePart(_beginRow, _begin_Col, (int)viewPort.ActualHeight, (int)viewPort.ActualWidth); //setImagePart(_beginRow, _begin_Col, _endRow-_beginRow, _endCol-_begin_Col); zoomImage(zoomWndFactor); } } }
public void addIconicVar(HObject obj) { if (obj == null) { return; } //if (entry != null) //viewPort.HalconWindow.DispObj(entry.HObj); // HRegion ddd = new HRegion(); tempImage.Dispose(); tempImage = new HImage(obj); if (tempImage != null) //if (obj is HImage) { double r, c; int h, w, area; string s; area = tempImage.GetDomain().AreaCenter(out r, out c); tempImage.GetImagePointer1(out s, out w, out h); //area = ((HImage)obj).GetDomain().AreaCenter(out r, out c); //((HImage)obj).GetImagePointer1(out s, out w, out h); if (area == (w * h)) { clearList(); if ((h != imageHeight) || (w != imageWidth)) { imageHeight = h; imageWidth = w; zoomWndFactor = (double)imageWidth / viewPort.Width; setImagePart(0, 0, h, w); } }//if } //if //entry. entry = new HObjectEntry(tempImage, mGC.copyContextList()); //HObjList.Add(entry); //if (HObjList.Count > MAXNUMOBJLIST) // HObjList.RemoveAt(1); repaint(); }
public void addImg(HObject obj) { HObjectEntry entry; if (obj == null) { return; } entry = new HObjectEntry(obj, mGC.copyContextList()); // HObjList.Add(entry); if (HObjList.Count > MAXNUMOBJLIST) { HObjList.RemoveAt(1); } }
public void addIconicVar_obj(HObject obj) { HObjectEntry entry; if (obj == null) { return; } if (obj is HImage) { double r, c; int h, w, area; string s; area = ((HImage)obj).GetDomain().AreaCenter(out r, out c); ((HImage)obj).GetImagePointer1(out s, out w, out h); if (area == (w * h)) { clearList(); if ((h != imageHeight) || (w != imageWidth)) { imageHeight = h; imageWidth = w; zoomWndFactor = (double)imageWidth / viewPort.Width; setImagePart(0, 0, h, w); } }//if } else { clearList(); } entry = new HObjectEntry(obj, mGC.copyContextList()); HObjList.Add(entry); if (HObjList.Count > MAXNUMOBJLIST) { HObjList.RemoveAt(1); } }
/********************************************************************/ /* GRAPHICSSTACK */ /********************************************************************/ /// <summary> /// Adds an iconic object to the graphics stack similar to the way /// it is defined for the HDevelop graphics stack. /// </summary> /// <param name="obj">Iconic object</param> public void AddHObject(HObject obj, string color, bool isImage) { HObjectEntry entry; HTuple hv_Width = null, hv_Height = null; if (obj == null) { return; } if (isImage) { if (obj.IsInitialized()) { HOperatorSet.GetImageSize(obj, out hv_Width, out hv_Height); clearList(); if ((hv_Height != imageHeight) || (hv_Width != imageWidth)) { viewPort.HalconWindow.SetDraw("margin"); imageHeight = hv_Height; imageWidth = hv_Width; setImagePart(0, 0, hv_Width, hv_Height); } HObjList.Clear(); StrList.Clear(); } else { viewPort.HalconWindow.ClearWindow(); HObjList.Clear(); StrList.Clear(); } } if (obj.IsInitialized()) { entry = new HObjectEntry(obj, color, mGC.copyContextList()); HObjList.Add(entry); } //if (HObjList.Count > MAXNUMOBJLIST) // HObjList.RemoveAt(1); }
/********************************************************************/ /* GRAPHICSSTACK */ /********************************************************************/ /// <summary> /// Adds an iconic object to the graphics stack similar to the way /// it is defined for the HDevelop graphics stack. /// </summary> /// <param name="obj">Iconic object</param> public void addIconicVar(HObject obj) { HObjectEntry entry; if (obj == null) return; var image = obj as HImage; if (image != null) { double r, c; int h, w, area; string s; area = image.GetDomain().AreaCenter(out r, out c); image.GetImagePointer1(out s, out w, out h); if (area == (w * h)) { clearList(); if ((h != imageHeight) || (w != imageWidth)) { imageHeight = h; imageWidth = w; zoomWndFactor = (double)imageWidth / viewPort.Width; int d = w < h ? w : h; setImagePart(0, 0, d, d); } }//if }//if entry = new HObjectEntry(obj, mGC.copyContextList()); HObjList.Add(entry); if (HObjList.Count > MAXNUMOBJLIST) HObjList.RemoveAt(1); }
/********************************************************************/ /* GRAPHICSSTACK */ /********************************************************************/ /// <summary> /// Adds an iconic object to the graphics stack similar to the way /// it is defined for the HDevelop graphics stack. /// </summary> /// <param name="obj">Iconic object</param> public void addIconicVar(HObject obj) { HObjectEntry entry; if (obj == null) { return; } if (obj is HImage) { double r, c; int h, w, area; string s; area = ((HImage)obj).GetDomain().AreaCenter(out r, out c); ((HImage)obj).GetImagePointer1(out s, out w, out h); imgHeight = h; imgWidth = w; if (true)//area == (w * h))//大小不同也清除原来的 { clearList(); if ((h != imageHeight) || (w != imageWidth)) { int _beginRow, _begin_Col, _endRow, _endCol; double ratio_win = (double)viewPort.ActualWidth / (double)viewPort.ActualHeight; double ratio_img = (double)w / (double)h; imageHeight = h; imageWidth = w; if (ratio_win >= ratio_img) { _beginRow = 0; _endRow = h - 1; _begin_Col = (int)(-w * (ratio_win / ratio_img - 1d) / 2d); _endCol = (int)(w + w * (ratio_win / ratio_img - 1d) / 2d); zoomWndFactor = (double)h / viewPort.ActualHeight; } else { _begin_Col = 0; _endCol = w - 1; _beginRow = (int)(-h * (ratio_img / ratio_win - 1d) / 2d); _endRow = (int)(h + h * (ratio_img / ratio_win - 1d) / 2d); zoomWndFactor = (double)w / viewPort.ActualWidth; } //viewPort.HalconWindow.SetPart(_beginRow, _begin_Col, _endRow, _endCol); setImagePart(_beginRow, _begin_Col, (int)viewPort.ActualHeight, (int)viewPort.ActualWidth); //setImagePart(_beginRow, _begin_Col, _endRow-_beginRow, _endCol-_begin_Col); clearList(); zoomImage(zoomWndFactor); } } //if } //if entry = new HObjectEntry(obj, mGC.copyContextList()); HObjList.Add(entry); if (HObjList.Count > MAXNUMOBJLIST) { HObjList.RemoveAt(1); } }
/********************************************************************/ /* GRAPHICSSTACK */ /********************************************************************/ /// <summary> /// Adds an iconic object to the graphics stack similar to the way /// it is defined for the HDevelop graphics stack. /// </summary> /// <param name="obj">Iconic object</param> public void addIconicVar(HObject obj) { HObjectEntry entry; bool BeScale = false; if (obj == null) { return; } HObject outimage = new HObject(); if (obj is HImage) { double r, c; int h, w, area; string s; area = ((HImage)obj).GetDomain().AreaCenter(out r, out c); ((HImage)obj).GetImagePointer1(out s, out w, out h); setNewImage(obj as HImage, out outimage, w, h); if (area == (w * h)) { clearList(); if ((h != imageHeight) || (w != imageWidth)) { imageHeight = h; imageWidth = w; BeScale = true; zoomWndFactor = (double)imageWidth / viewPort.Width; setImagePart1(0, 0, h, w); } } //if entry = new HObjectEntry(obj, mGC.copyContextList()); if (area == (w * h)) { if (BeScale) { if (obj is HImage) { if (hv_scale < 1) { HTuple width_new = viewPort.Size.Width - w * hv_scale; switch (w) { case 5472: zoomImage(width_new * 0.6, 0, 1 / hv_scale); break; case 2448: zoomImage(width_new * 0.7, 0, 1 / hv_scale); break; case 2560: case 2592: zoomImage(width_new * 0.7, 0, 1 / hv_scale); break; case 1280: zoomImage(width_new * 1.2, 0, 1 / hv_scale); break; default: break; } BeScale = false; } else { HTuple width_small = -(viewPort.Size.Width - w * hv_scale); zoomImage(width_small * 2.5, 0, 1 / hv_scale); BeScale = false; } } } } } //if else { entry = new HObjectEntry(obj, mGC.copyContextList()); } HObjList.Add(entry); if (HObjList.Count > MAXNUMOBJLIST) { HObjList.RemoveAt(1); } }
/********************************************************************/ /* GRAPHICSSTACK */ /********************************************************************/ /// <summary> /// Adds an iconic object to the graphics stack similar to the way /// it is defined for the HDevelop graphics stack. /// </summary> /// <param name="obj">Iconic object</param> public void addIconicVar(HObject obj) { //HObjectEntry entry; if (obj == null) return; if (obj is HImage) { double r, c; int h, w, area; string s; _lastImage = (HImage)obj; area = ((HImage)obj).GetDomain().AreaCenter(out r, out c); ((HImage)obj).GetImagePointer1(out s, out w, out h); if (area == (w * h)) { clearList(); if ((h != imageHeight) || (w != imageWidth)) { imageHeight = h; imageWidth = w; zoomWndFactor = (double)imageWidth / _viewPort.Width; setImagePart(0, 0, h, w); } }//if }//if var entry = new HObjectEntry(obj, mGC.copyContextList()); HObjList.Add(entry); if (HObjList.Count > MAXNUMOBJLIST) HObjList.RemoveAt(1); }
/*******************************************************************/ private void mouseMoved(object sender, HalconDotNet.HMouseEventArgs e) { double motionX, motionY; double posX, posY; double zoomZone; //if (viewPort.) int count = HObjList.Count; foreach (var item in HObjList) //实时显示图片的灰度 灰度显示 { HObjectEntry objNow = (HObjectEntry)item; if (objNow.HObj is HImage) { try{ HObject myImg = new HObject(); if (!objNow.HObj.IsInitialized()) { break; } //HOperatorSet.CopyObj(objNow.HObj, out myImg, 1, -1); HTuple Gray = new HTuple(); HTuple Wid, Hei; HOperatorSet.GetImageSize(objNow.HObj, out Wid, out Hei); if (0 < e.Y && e.Y < Hei && 0 < e.X && e.X < Wid) { repaint(viewPort.HalconWindow); HOperatorSet.GetGrayval(objNow.HObj, e.Y, e.X, out Gray); double scale = (ImgRow2 - ImgRow1) / Hei.D; //HOperatorSet.SetTposition(viewPort.HalconWindow, ImgRow2 - 400 * scale, ImgCol2 - 400 * scale); HOperatorSet.SetTposition(viewPort.HalconWindow, e.Y + 20 * scale, e.X + 50 * scale); HOperatorSet.SetColor(viewPort.HalconWindow, "red"); HOperatorSet.WriteString(viewPort.HalconWindow, "R:" + ((int)e.Y).ToString() + " " + "C:" + ((int)e.X).ToString() + " " + ((int)Gray[0].D).ToString()); } //myImg.Dispose(); break; } catch { break; } } } if (!mousePressed) { return; } if (roiManager != null && (roiManager.activeROIidx != -1) && (dispROI == MODE_INCLUDE_ROI)) { roiManager.mouseMoveAction(e.X, e.Y); } else if (stateView == MODE_VIEW_MOVE) //平移视图 { motionX = ((e.X - startX)); motionY = ((e.Y - startY)); if (((int)motionX != 0) || ((int)motionY != 0)) { moveImage(motionX, motionY); startX = e.X - motionX; startY = e.Y - motionY; } } else if (stateView == MODE_VIEW_ZOOMWINDOW) //缩放视图 { HSystem.SetSystem("flush_graphic", "false"); ZoomWindow.ClearWindow(); posX = ((e.X - ImgCol1) / (ImgCol2 - ImgCol1)) * viewPort.Width; posY = ((e.Y - ImgRow1) / (ImgRow2 - ImgRow1)) * viewPort.Height; zoomZone = (zoomWndSize / 2) * zoomWndFactor * zoomAddOn; ZoomWindow.SetWindowExtents((int)posY - (zoomWndSize / 2), (int)posX - (zoomWndSize / 2), zoomWndSize, zoomWndSize); ZoomWindow.SetPart((int)(e.Y - zoomZone), (int)(e.X - zoomZone), (int)(e.Y + zoomZone), (int)(e.X + zoomZone)); repaint(ZoomWindow); HSystem.SetSystem("flush_graphic", "true"); ZoomWindow.DispLine(-100.0, -100.0, -100.0, -100.0); } }
/*******************************************************************/ private void mouseMoved(object sender, HalconDotNet.HMouseEventArgs e) { if (e.Button != MouseButtons.Left) { mousePressed = true; int activeROIidx = -1; //double scale; startX = e.X; startY = e.Y; if (roiManager != null) { activeROIidx = roiManager.mouseDownAction(e.X, e.Y); } MouseMove me = new MouseMove(); try { if (HObjList.Count > 0) { HTuple gray = 0; HObjectEntry entry = (HObjectEntry)HObjList[0]; if ((e.Y >= 0) && (e.X >= 0)) { HOperatorSet.GetGrayval(entry.HObj, e.Y, e.X, out gray); me.Gray = (uint)gray.I; } } } catch { me.Gray = 0; } me.X = (int)e.X + 1; //图像从0开始,显示数据从1开始 me.Y = (int)e.Y + 1; MouseMoveEventOutput(me); } else { double motionX, motionY; if (!mousePressed) { return; } if (roiManager != null && (roiManager.activeROIidx != -1)) { roiManager.mouseMoveAction(e.X, e.Y); } else { if (!isCancelImageMove) { motionX = ((e.X - startX)); motionY = ((e.Y - startY)); if (((int)motionX != 0) || ((int)motionY != 0)) { moveImage(motionX, motionY); startX = e.X - motionX; startY = e.Y - motionY; } } } } }
/********************************************************************/ /* GRAPHICSSTACK */ /********************************************************************/ /// <summary> /// Adds an iconic object to the graphics stack similar to the way /// it is defined for the HDevelop graphics stack. /// </summary> /// <param name="obj">Iconic object</param> public void addIconicVar(HObject obj) { HObjectEntry entry; if (obj == null) { return; } if (obj is HImage) { //double r, c; //int area; int h, w; string s; //area = ((HImage)obj).GetDomain().AreaCenter(out r, out c); ((HImage)obj).GetImagePointer1(out s, out w, out h); HTuple width, height; HOperatorSet.GetSystem("width", out width); HOperatorSet.GetSystem("height", out height); //在某种情况下,Get的值正确的也未生效,需要再设置一遍,原因未知 HOperatorSet.SetSystem("width", width); HOperatorSet.SetSystem("height", height); if (Image_Auto_Fit)//area == (w * h))//大小不同也清除原来的 { clearList(); clearMsgList(); if ((h != imageHeight) || (w != imageWidth)) { int _beginRow, _begin_Col, _endRow, _endCol; double ratio_win = (double)viewPort.ActualWidth / (double)viewPort.ActualHeight; double ratio_img = (double)w / (double)h; imageHeight = h; imageWidth = w; if (ratio_win >= ratio_img) { _beginRow = 0; _endRow = h - 1; _begin_Col = (int)(-w * (ratio_win / ratio_img - 1d) / 2d); _endCol = (int)(w + w * (ratio_win / ratio_img - 1d) / 2d); zoomWndFactor = (double)h / viewPort.ActualHeight; } else { _begin_Col = 0; _endCol = w - 1; _beginRow = (int)(-h * (ratio_img / ratio_win - 1d) / 2d); _endRow = (int)(h + h * (ratio_img / ratio_win - 1d) / 2d); zoomWndFactor = (double)w / viewPort.ActualWidth; } //viewPort.HalconWindow.SetPart(_beginRow, _begin_Col, _endRow, _endCol); setImagePart(_beginRow, _begin_Col, (int)viewPort.ActualHeight, (int)viewPort.ActualWidth); //setImagePart(_beginRow, _begin_Col, _endRow-_beginRow, _endCol-_begin_Col); //clearList(); zoomImage(zoomWndFactor); } } //if } //if entry = new HObjectEntry(obj, mGC.copyContextList()); HObjList.Add(entry); if (HObjList.Count > MAXNUMOBJLIST) { HObjList.RemoveAt(1); } if (HObjListChanged != null) { HObjListChanged(null, null); } }