public void DrawPoint(out double x, out double y) { viewPort.Focus(); #if NativeCode Wrapper.ShowUnit.ShowText(viewPort.HalconWindow, "鼠标左键点击点位置,鼠标右键完成。", 20, 20, 20, "green", "window"); #else HWndMessage message = new HWndMessage("鼠标左键点击点位置,鼠标右键完成", 20, 20, 20, "green"); message.DispMessage(viewPort.HalconWindow, "window", 1); #endif inMeasureLine = true; viewPort.ContextMenuStrip = null; //获取当前显示信息 HTuple hv_Red = null, hv_Green = null, hv_Blue = null; int hv_lineWidth; HWindow window = viewPort.HalconWindow; window.GetRgb(out hv_Red, out hv_Green, out hv_Blue); hv_lineWidth = (int)window.GetLineWidth(); string hv_Draw = window.GetDraw(); window.SetLineWidth(1); //设置线宽 window.SetLineStyle(new HTuple()); window.SetColor("green"); //画点的颜色 window.DrawPoint(out y, out x); //恢复窗口显示信息 window.SetRgb(hv_Red, hv_Green, hv_Blue); window.SetLineWidth(hv_lineWidth); window.SetDraw(hv_Draw); viewPort.ContextMenuStrip = hv_MenuStrip; inMeasureLine = false; Repaint(); }
public void AddIconicVar(HWndMessage message) { HObjectEntry entry; if (message == null) { return; } entry = new HObjectEntry(message); HObjList.Add(entry); if (HObjList.Count > MAX_NUM_OBJ_LIST) { HObjList.RemoveAt(1); } }
private void MeasureLine_strip_Click(object sender, EventArgs e) { viewPort.Focus(); HWndMessage message = new HWndMessage("鼠标点击两个位置后,单击鼠标右键完成。", 20, 20, 20, "green"); message.DispMessage(viewPort.HalconWindow, "window", 1); inMeasureLine = true; viewPort.ContextMenuStrip = null; double r1, c1, r2, c2; HTuple dd; //获取当前显示信息 HTuple hv_Red = null, hv_Green = null, hv_Blue = null; int hv_lineWidth; HWindow window = viewPort.HalconWindow; window.GetRgb(out hv_Red, out hv_Green, out hv_Blue); hv_lineWidth = (int)window.GetLineWidth(); string hv_Draw = window.GetDraw(); window.SetLineWidth(1); //设置线宽 window.SetLineStyle(new HTuple()); window.SetColor("green"); //画点的颜色 window.DrawLine(out r1, out c1, out r2, out c2); window.DispLine(r1, c1, r2, c2); //恢复窗口显示信息 window.SetRgb(hv_Red, hv_Green, hv_Blue); window.SetLineWidth(hv_lineWidth); window.SetDraw(hv_Draw); HOperatorSet.DistancePp(r1, c1, r2, c2, out dd); double dr = Math.Abs(r2 - r1); double dc = Math.Abs(c2 - c1); MessageBox.Show(string.Format("直线距离{0:f2}px\rx轴距离{1:f2}px\ry轴距离{2:f2}px", dd.D, dc, dr), "结果", MessageBoxButtons.OK, MessageBoxIcon.Information); //hv_MenuStrip.Visible = true; viewPort.ContextMenuStrip = hv_MenuStrip; inMeasureLine = false; Repaint(); }
/// <summary>Paints the ROI into the supplied window</summary> /// <param name="window">HALCON window</param> public override void Draw(HalconDotNet.HWindow window) { int width = GetHandleWidth(); window.DispRectangle2(midR, midC, -phi, length1, length2); for (int i = 0; i < NumHandles; i++) { window.DispRectangle2(rows[i].D, cols[i].D, -phi, width, width); } window.DispArrow(midR, midC, midR + (Math.Sin(phi) * length1 * 1.2), midC + (Math.Cos(phi) * length1 * 1.2), width / 3.0); if (info != null && info.Length > 0) { #if NativeCode Wrapper.ShowUnit.ShowText(window, info, (int)rows[0].D, (int)cols[0].D, (int)(20.0 * TxtScale), "green", "image"); #else HWndMessage message = new HWndMessage(info, (int)rows[0].D, (int)cols[0].D, 20, "green"); message.DispMessage(window, "image", TxtScale); #endif } }
private void ShowHistogram_strip_Click(object sender, EventArgs e) { viewPort.Focus(); #if NativeCode ShowUnit.ShowText(viewPort.HalconWindow, "鼠标左键点击并拉取矩形区域,鼠标右键完成", 20, 20, 20, "green", "window"); #else HWndMessage message = new HWndMessage("鼠标左键点击并拉取矩形区域,鼠标右键完成", 20, 20, 20, "green"); message.DispMessage(viewPort.HalconWindow, "window", 1); #endif inMeasureLine = true; viewPort.ContextMenuStrip = null; double r1, c1, r2, c2; //HTuple dd; //获取当前显示信息 HTuple hv_Red = null, hv_Green = null, hv_Blue = null; int hv_lineWidth; HWindow window = viewPort.HalconWindow; window.GetRgb(out hv_Red, out hv_Green, out hv_Blue); hv_lineWidth = (int)window.GetLineWidth(); string hv_Draw = window.GetDraw(); window.SetLineWidth(1); //设置线宽 window.SetLineStyle(new HTuple()); window.SetColor("green"); //画点的颜色 window.DrawRectangle1(out r1, out c1, out r2, out c2); window.DispRectangle1(r1, c1, r2, c2); Form frm = new Form(); FunctionPlotUnit pointUnit = new FunctionPlotUnit(); Size size = pointUnit.Size; size.Height = (int)(size.Height + 50); size.Width = (int)(size.Width + 50); frm.Size = size; frm.Controls.Add(pointUnit); pointUnit.Dock = DockStyle.Fill; HTuple grayVals; #if NativeCode grayVals = Wrapper.ShowUnit.GetGrayHisto(viewPort.HalconWindow, new HTuple(r1, c1, r2, c2)); #else grayVals = GetGrayHisto(new HTuple(r1, c1, r2, c2)); #endif pointUnit.SetAxisAdaption(FunctionPlot.AXIS_RANGE_INCREASING); pointUnit.SetLabel("灰度值", "频率"); pointUnit.SetFunctionPlotValue(grayVals); pointUnit.ComputeStatistics(grayVals); frm.ShowDialog(); //window.DrawLine(out r1, out c1, out r2, out c2); //window.DispLine(r1, c1, r2, c2); //恢复窗口显示信息 window.SetRgb(hv_Red, hv_Green, hv_Blue); window.SetLineWidth(hv_lineWidth); window.SetDraw(hv_Draw); //HOperatorSet.DistancePp(r1, c1, r2, c2, out dd); //double dr = Math.Abs(r2 - r1); //double dc = Math.Abs(c2 - c1); //MessageBox.Show(string.Format("直线距离{0:f2}px\rx轴距离{1:f2}px\ry轴距离{2:f2}px", dd.D, dc, dr), "结果", MessageBoxButtons.OK, MessageBoxIcon.Information); //hv_MenuStrip.Visible = true; viewPort.ContextMenuStrip = hv_MenuStrip; inMeasureLine = false; Repaint(); }
public HObjectEntry(HWndMessage message) { this.Message = message; }