/// <summary>将ROI绘制到提供的窗口中</summary> /// <param name="window">HALCON window</param> public override void draw(HalconDotNet.HWindow window) { window.DispLine(midR + Math.Sin(phi) * length1, midC + Math.Cos(phi) * length1, midR + (Math.Sin(phi) * (length1 + 30)), midC + (Math.Cos(phi) * (length1 + 30))); for (int i = 0; i < PointNum; i++) { window.DispRectangle2(midR + (-length1 + length1 / PointNum + length1 * 2 / PointNum * i) * Math.Sin(phi), midC + (-length1 + length1 / PointNum + length1 * 2 / PointNum * i) * Math.Cos(phi), -phi, length1 / PointNum, length2); } window.SetDraw("fill"); for (int i = 0; i < NumHandles - 1; i++) { window.DispRectangle2(rows[i].D, cols[i].D, -phi, 10, 10); } window.DispCircle((midR + Math.Sin(phi) * (length1 + 36)), (midC + Math.Cos(phi) * (length1 + 36)), 12); window.SetLineWidth(5); window.DispArrow(midR - (Math.Sin(phi - Math.PI / 2) * (length2 - 10)), midC - (Math.Cos(phi - Math.PI / 2) * (length2 - 10)), midR - (Math.Sin(phi - Math.PI / 2) * length2), midC - (Math.Cos(phi - Math.PI / 2) * length2), 2.0); window.SetLineWidth(1); window.SetDraw("margin"); }
/// <summary> /// Paints the active handle of the ROI object into the supplied window /// </summary> /// <param name="window">HALCON window</param> public override void displayActive(HalconDotNet.HWindow window) { //20180315 //window.DispRectangle2(rows[activeHandleIdx].D, // cols[activeHandleIdx].D, // -phi, 5, 5); //if (activeHandleIdx == 5) // window.DispArrow(midR, midC, // midR + (Math.Sin(phi) * length1 * 1.2), // midC + (Math.Cos(phi) * length1 * 1.2), // 2.0); window.DispRectangle2(rows[activeHandleIdx].D, cols[activeHandleIdx].D, -phi, 5, 5); if (activeHandleIdx == 5) { window.DispArrow(midR, midC, midR + (Math.Sin(-phi) * length1 * 1.2), midC + (Math.Cos(phi) * length1 * 1.2), 2.0); } }
/// <summary> /// Paints the active handle of the ROI object into the supplied window /// </summary> /// <param name="window">HALCON window</param> public override void displayActive(HalconDotNet.HWindow window) { if (!SizeEnable || !ShowRect) { return; } int hrow, hcol, hw, hh; window.GetPart(out hrow, out hcol, out hh, out hw); int wrow, wcol, ww, wh; window.GetWindowExtents(out wrow, out wcol, out ww, out wh); double smallregionwidth = (hw - hcol) * windowsmallregionwidth / ww; double smallregionheight = (hh - hrow) * windowsmallregionwidth / wh; window.DispRectangle2(rows[activeHandleIdx].D, cols[activeHandleIdx].D, phi, smallregionwidth, smallregionheight); if (activeHandleIdx == 5) { window.DispArrow(midR, midC, midR + (Math.Sin(-phi) * length1 * 1.2), midC + (Math.Cos(-phi) * length1 * 1.2), 2.0); } }
/// <summary>Paints the ROI into the supplied window</summary> /// <param name="window">HALCON window</param> public override void draw(HalconDotNet.HWindow window) { window.DispRectangle2(midR, midC, -phi, length1, length2); for (int i = 0; i < NumHandles; i++) { window.DispRectangle2(rows[i].D, cols[i].D, -phi, 5, 5); } window.DispArrow(midR, midC, midR + (Math.Sin(phi) * length1 * 1.2), midC + (Math.Cos(phi) * length1 * 1.2), 2.0); }
public void Draw2(HalconDotNet.HWindow window) { HTuple data = base.GetModeData(); //ROI矩形 window.DispRectangle2(data[0].D, data[1], data[2], data[3], data[4]); window.DispRectangle2(data[0].D, data[1], data[2], 5, 5); window.DispRectangle2(data[0] - (0.8 * data[3] * Math.Sin(data[2])), data[1] + 0.8 * (data[3] * Math.Cos(data[2])), data[2], 5, 5); //注:矩形右边的中点坐标(_locateRow-_length1*Sine(angle),_locateCol+_length2*Cosine(angle)),为使箭头超出一点,故而用系数1.3修正 window.DispArrow(data[0], data[1], data[0] - (1.3 * data[3] * Math.Sin(data[2])), data[1] + 1.3 * (data[3] * Math.Cos(data[2])), 6); }
/// <summary> /// Paints the active handle of the ROI object into the supplied window /// </summary> /// <param name="window">HALCON window</param> public override void displayActive(HalconDotNet.HWindow window) { window.DispRectangle2(rows[activeHandleIdx].D, cols[activeHandleIdx].D, -phi, 25, 25); if (activeHandleIdx == 5) { window.DispArrow(midR, midC, midR + (Math.Sin(phi) * length1 * 1.2), midC + (Math.Cos(phi) * length1 * 1.2), 5.0); } }
/// <summary>Paints the ROI into the supplied window</summary> /// <param name="window">HALCON window</param> public override void draw(HalconDotNet.HWindow window) { var w = _HandleRectangleWidth * _ZoomRatio; var h = _HandleRectangleHeight * _ZoomRatio; var arrowSize = _ArrowSize * _ZoomRatio; window.DispRectangle2(midR, midC, -phi, length1, length2); for (int i = 0; i < NumHandles; i++) { window.DispRectangle2(rows[i].D, cols[i].D, -phi, w, h); } window.DispArrow(midR, midC, midR + (Math.Sin(phi) * length1 * 1.2), midC + (Math.Cos(phi) * length1 * 1.2), arrowSize); }
/// <summary> /// Paints the active handle of the ROI object into the supplied window /// </summary> /// <param name="window">HALCON window</param> public override void DisplayActive(HalconDotNet.HWindow window) { int width = GetHandleWidth(); window.DispRectangle2(rows[activeHandleIdx].D, cols[activeHandleIdx].D, -phi, width, width); if (activeHandleIdx == 5) { window.DispArrow(midR, midC, midR + (Math.Sin(phi) * length1 * 1.2), midC + (Math.Cos(phi) * length1 * 1.2), width / 3.0); } }
/// <summary> /// Paints the active handle of the ROI object into the supplied window /// </summary> /// <param name="window">HALCON window</param> public override void displayActive(HalconDotNet.HWindow window) { if (!_initPointsDone) { return; } window.DispRectangle2(rows[activeHandleIdx].D, cols[activeHandleIdx].D, -phi, 5, 5); if (activeHandleIdx == 5) { window.DispArrow(midR, midC, midR + (Math.Sin(phi) * length1 * 1.2), midC + (Math.Cos(phi) * length1 * 1.2), 2.0); } }
/// <summary> /// Paints the active handle of the ROI object into the supplied window /// </summary> /// <param name="window">HALCON window</param> public override void displayActive(HalconDotNet.HWindow window) { if (activeHandleIdx == 4) { window.DispCross(rows[activeHandleIdx].D, cols[activeHandleIdx].D, 50, -phi); } else if (activeHandleIdx == 5) { window.DispArrow(midR, midC, midR + (Math.Sin(phi) * length1 * 1.2), midC + (Math.Cos(phi) * length1 * 1.2), 2.0); } else { window.DispRectangle2(rows[activeHandleIdx].D, cols[activeHandleIdx].D, -phi, 10, 10); } }
/// <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 } }
public int windowsmallregionwidth = 5;//4边小矩形的大小 /// <summary>Paints the ROI into the supplied window</summary> /// <param name="window">HALCON window</param> public override void draw(HalconDotNet.HWindow window) { window.DispRectangle2(midR, midC, phi, length1, length2); if (SizeEnable && ShowRect) { int hrow, hcol, hw, hh; window.GetPart(out hrow, out hcol, out hh, out hw); int wrow, wcol, ww, wh; window.GetWindowExtents(out wrow, out wcol, out ww, out wh); double smallregionwidth = (hw - hcol) * windowsmallregionwidth / ww; double smallregionheight = (hh - hrow) * windowsmallregionwidth / wh; for (int i = 0; i < NumHandles; i++) { window.DispRectangle2(rows[i].D, cols[i].D, phi, smallregionwidth, smallregionheight); } window.DispArrow(midR, midC, midR + (Math.Sin(-phi) * length1 * 1.2), midC + (Math.Cos(-phi) * length1 * 1.2), 2.0); } }
/// <summary> /// draw, 決定要畫什麼在 window 上 /// </summary> /// <param name="window">Halcon Window</param> public override void draw(HalconDotNet.HWindow window) { double arrowSize = 2; double crossSize = 12; double crossAngle = 0.785398; HTuple dotLineStyle = new HTuple(new int[4] { 7, 7, 7, 7 }); //Reset line Style HOperatorSet.SetLineStyle(window, null); //寫字 if (!String.IsNullOrEmpty(Name)) { HOperatorSet.SetTposition(window, this.NewCenterRow, this.NewCenterCol); if (!this.IsActive) { HOperatorSet.SetColor(window, "red"); } window.WriteString(Name); } // 畫箭頭, 由線段的中心點向兩端畫箭頭 window.SetLineWidth(1); //計算兩箭頭端點位置 var arrowPointRowBegin = _arrowLineRowBegin = this.NewCenterRow + (Math.Sin(_phiStart) * _halfDistance); var arrowPointColBegin = _arrowLineColBegin = this.NewCenterCol + (Math.Cos(_phiStart) * _halfDistance); var arrowPointRowEnd = _arrowLineRowEnd = this.NewCenterRow + (Math.Sin(_phiEnd) * _halfDistance); var arrowPointColEnd = _arrowLineColEnd = this.NewCenterCol + (Math.Cos(_phiEnd) * _halfDistance); window.DispArrow(this.NewCenterRow, this.NewCenterCol, arrowPointRowBegin, arrowPointColBegin, arrowSize); window.DispArrow(this.NewCenterRow, this.NewCenterCol, arrowPointRowEnd, arrowPointColEnd, arrowSize); //畫虛線,如果使用者改變了原始中心點的位置 //由兩箭頭端點連結原始的起始兩端點 if (_rawCenterRow != this.NewCenterRow || _rawCenterCol != this.NewCenterCol) { HOperatorSet.SetLineStyle(window, dotLineStyle); //決定兩個端點的連結,將座標點 以左上排序 var arrowPoints = new List <PositionModel>() { new PositionModel() { RowBegin = arrowPointRowBegin, ColBegin = arrowPointColBegin }, new PositionModel() { RowBegin = arrowPointRowEnd, ColBegin = arrowPointColEnd }, }; arrowPoints = arrowPoints.OrderBy(x => x.ColBegin).OrderBy(y => y.RowBegin).ToList(); for (int i = 0; i < _ROIModelPoints.Count; i++) { window.DispLine(arrowPoints[i].RowBegin, arrowPoints[i].ColBegin, _ROIModelPoints[i].RowBegin, _ROIModelPoints[i].ColBegin); } } //reset Style HOperatorSet.SetLineStyle(window, null); //畫ROI window.SetLineWidth(1); if (!this.IsActive) { HOperatorSet.SetColor(window, "magenta"); } for (var i = 0; i < _dependROIModels.Count; i++) { var line = _dependROIModels[i]; if (isLine(line)) { //draw line,ROI 的線 window.DispLine(line.RowBegin, line.ColBegin, line.RowEnd, line.ColEnd); } else { //draw point,ROI 的點 HXLDCont crossPoint = new HXLDCont(); crossPoint.GenEmptyObj(); crossPoint.GenCrossContourXld(line.RowBegin, line.ColBegin, crossSize, crossAngle); crossPoint.DispObj(window); //window.DispCross(line.RowBegin, line.ColBegin, crossSize, crossAngle); } } }
/// <summary> /// draw, 決定要畫什麼在 window 上 /// </summary> /// <param name="window">Halcon Window</param> public override void draw(HalconDotNet.HWindow window) { double arrowSize = 2; //double crossSize = 12; //double crossAngle = 0.785398; HTuple dotLineStyle = new HTuple(new int[4] { 7, 7, 7, 7 }); //Reset line Style HOperatorSet.SetLineStyle(window, null); //寫字 if (!String.IsNullOrEmpty(Name)) { if (!this.IsActive) { HOperatorSet.SetColor(window, "red"); } HOperatorSet.SetTposition(window, this.NewCenterRow, this.NewCenterCol); window.WriteString(Name); } //畫線段,水平 + 30 度角 var lineLength = 50; var angle = Math.PI / 6.0; var hLineRow = this.NewCenterRow + Math.Sin(Math.PI) * lineLength; var hLineCol = this.NewCenterCol - Math.Cos(Math.PI) * lineLength; var degLineRow = this.NewCenterRow - Math.Sin(angle) * lineLength; var degLineCol = this.NewCenterCol + Math.Cos(angle) * lineLength; HOperatorSet.DispLine(window, this.NewCenterRow, this.NewCenterCol, hLineRow, hLineCol); HOperatorSet.DispLine(window, this.NewCenterRow, this.NewCenterCol, degLineRow, degLineCol); //畫 arc // angle 為正時,會順時針畫, // angle 為負時,會逆時針畫, // 因此要注意兩線段夾角的開口方向來選擇 var arcBeginRow = this.NewCenterRow - Math.Sin(angle) * (lineLength / 2.0); var arcBeginCol = this.NewCenterCol + Math.Cos(angle) * (lineLength / 2.0); window.DispArc(this.NewCenterRow, this.NewCenterCol, angle, arcBeginRow, arcBeginCol); // 畫箭頭, window.SetLineWidth(1); HOperatorSet.SetLineStyle(window, dotLineStyle); window.DispArrow(this.NewCenterRow, this.NewCenterCol, _lineACenterRow, _lineACenterCol, arrowSize); window.DispArrow(this.NewCenterRow, this.NewCenterCol, _lineBCenterRow, _lineBCenterCol, arrowSize); //Reset line Style HOperatorSet.SetLineStyle(window, null); //畫ROI window.SetLineWidth(2); if (!this.IsActive) { HOperatorSet.SetColor(window, "magenta"); } for (var i = 0; i < _lines.Count; i++) { var line = _lines[i]; if (isLine(line)) { //draw line,ROI 的線 window.DispLine(line.RowBegin, line.ColBegin, line.RowEnd, line.ColEnd); } } }
/// <summary> /// Paints the active handle of the ROI object into the supplied window /// </summary> /// <param name="window">HALCON window</param> public override void displayActive(HalconDotNet.HWindow window, int imageWidth, int imageHeight) { 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; } if (littleRecSize % 2 != 0) { littleRecSize++; } window.DispRectangle2(rows[activeHandleIdx].D, cols[activeHandleIdx].D, -phi, littleRecSize, littleRecSize); if (activeHandleIdx == 5) { window.DispArrow(midR, midC, midR + (Math.Sin(phi) * length1 * 1.8), midC + (Math.Cos(phi) * length1 * 1.8), littleRecSize); } }
/// <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) { 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; } if (littleRecSize % 2 != 0) { littleRecSize++; } HOperatorSet.SetDraw(window, "margin"); window.DispRectangle2(midR, midC, -phi, length1, length2); HOperatorSet.SetDraw(window, "fill"); for (int i = 0; i < NumHandles; i++) { window.DispRectangle2(rows[i].D, cols[i].D, -phi, littleRecSize, littleRecSize); Application.DoEvents(); } window.DispArrow(midR, midC, midR + (Math.Sin(phi) * length1 * 1.8), midC + (Math.Cos(phi) * length1 * 1.8), littleRecSize); }