test parallel run

This commit is contained in:
2025-11-26 16:32:08 +08:00
parent dc5b1b94a5
commit 5e70315b9a
5 changed files with 163 additions and 89 deletions

View File

@@ -10,7 +10,7 @@ using System.Threading.Tasks;
namespace WaferAdjust namespace WaferAdjust
{ {
public delegate void OnFitCircleResult(double x, double y, double r, double rms); public delegate void OnFitCircleResult(int index, double x, double y, double r, double rms);
internal class FitCircleToolBlock internal class FitCircleToolBlock
{ {
private CogToolBlock cogToolBlock; private CogToolBlock cogToolBlock;
@@ -18,7 +18,8 @@ namespace WaferAdjust
public event OnToolReady OnToolReady; public event OnToolReady OnToolReady;
public event OnFitCircleResult OnFitCircleResult; public event OnFitCircleResult OnFitCircleResult;
public CogImage8Grey FitCircleImage; public CogImage8Grey FitCircleImage;
public void Initialize(string vpp) private int m_index;
public void Initialize(int index, string vpp)
{ {
try try
{ {
@@ -28,11 +29,12 @@ namespace WaferAdjust
cogToolBlock.Dispose(); cogToolBlock.Dispose();
cogToolBlock = null; cogToolBlock = null;
} }
m_index = index;
initialized = false; initialized = false;
cogToolBlock = CogSerializer.LoadObjectFromFile(vpp) as CogToolBlock; cogToolBlock = CogSerializer.LoadObjectFromFile(vpp) as CogToolBlock;
cogToolBlock.Ran += CogToolBlock_Ran; cogToolBlock.Ran += CogToolBlock_Ran;
initialized = true; initialized = true;
OnToolReady?.Invoke(initialized); OnToolReady?.Invoke(m_index, initialized);
LogHelper.LogInfo("FitCircleToolBlock initialized successfully: " + vpp); LogHelper.LogInfo("FitCircleToolBlock initialized successfully: " + vpp);
} }
catch (Exception ex) catch (Exception ex)
@@ -45,7 +47,7 @@ namespace WaferAdjust
try try
{ {
FitCircleImage = cogToolBlock.Outputs["OutputImage"].Value as CogImage8Grey; FitCircleImage = cogToolBlock.Outputs["OutputImage"].Value as CogImage8Grey;
OnFitCircleResult?.Invoke(Math.Round((double)cogToolBlock.Outputs["CenterX"].Value, 3), OnFitCircleResult?.Invoke(m_index, Math.Round((double)cogToolBlock.Outputs["CenterX"].Value, 3),
Math.Round((double)cogToolBlock.Outputs["CenterY"].Value, 3), Math.Round((double)cogToolBlock.Outputs["CenterY"].Value, 3),
Math.Round((double)cogToolBlock.Outputs["Radius"].Value, 3), Math.Round((double)cogToolBlock.Outputs["Radius"].Value, 3),
Math.Round((double)cogToolBlock.Outputs["RMSError"].Value, 3)); Math.Round((double)cogToolBlock.Outputs["RMSError"].Value, 3));

View File

@@ -58,11 +58,11 @@
this.textBox4 = new System.Windows.Forms.TextBox(); this.textBox4 = new System.Windows.Forms.TextBox();
this.groupBox1 = new System.Windows.Forms.GroupBox(); this.groupBox1 = new System.Windows.Forms.GroupBox();
this.button2 = new System.Windows.Forms.Button(); this.button2 = new System.Windows.Forms.Button();
this.button4 = new System.Windows.Forms.Button();
this.button3 = new System.Windows.Forms.Button(); this.button3 = new System.Windows.Forms.Button();
this.textBox1 = new System.Windows.Forms.TextBox(); this.textBox1 = new System.Windows.Forms.TextBox();
this.button1 = new System.Windows.Forms.Button(); this.button1 = new System.Windows.Forms.Button();
this.richTextBox1 = new System.Windows.Forms.RichTextBox(); this.richTextBox1 = new System.Windows.Forms.RichTextBox();
this.button4 = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit();
this.splitContainer1.Panel1.SuspendLayout(); this.splitContainer1.Panel1.SuspendLayout();
this.splitContainer1.Panel2.SuspendLayout(); this.splitContainer1.Panel2.SuspendLayout();
@@ -86,6 +86,7 @@
// //
// splitContainer1.Panel2 // splitContainer1.Panel2
// //
this.splitContainer1.Panel2.Controls.Add(this.button4);
this.splitContainer1.Panel2.Controls.Add(this.groupBox2); this.splitContainer1.Panel2.Controls.Add(this.groupBox2);
this.splitContainer1.Panel2.Controls.Add(this.groupBox1); this.splitContainer1.Panel2.Controls.Add(this.groupBox1);
this.splitContainer1.Panel2.Controls.Add(this.button3); this.splitContainer1.Panel2.Controls.Add(this.button3);
@@ -139,9 +140,9 @@
this.groupBox2.Controls.Add(this.label2); this.groupBox2.Controls.Add(this.label2);
this.groupBox2.Controls.Add(this.label3); this.groupBox2.Controls.Add(this.label3);
this.groupBox2.Controls.Add(this.textBox4); this.groupBox2.Controls.Add(this.textBox4);
this.groupBox2.Location = new System.Drawing.Point(358, 133); this.groupBox2.Location = new System.Drawing.Point(358, 110);
this.groupBox2.Name = "groupBox2"; this.groupBox2.Name = "groupBox2";
this.groupBox2.Size = new System.Drawing.Size(515, 99); this.groupBox2.Size = new System.Drawing.Size(515, 122);
this.groupBox2.TabIndex = 17; this.groupBox2.TabIndex = 17;
this.groupBox2.TabStop = false; this.groupBox2.TabStop = false;
this.groupBox2.Text = "标定后寻边测试"; this.groupBox2.Text = "标定后寻边测试";
@@ -149,7 +150,7 @@
// checkBox2 // checkBox2
// //
this.checkBox2.AutoSize = true; this.checkBox2.AutoSize = true;
this.checkBox2.Location = new System.Drawing.Point(269, 59); this.checkBox2.Location = new System.Drawing.Point(268, 76);
this.checkBox2.Name = "checkBox2"; this.checkBox2.Name = "checkBox2";
this.checkBox2.Size = new System.Drawing.Size(78, 16); this.checkBox2.Size = new System.Drawing.Size(78, 16);
this.checkBox2.TabIndex = 28; this.checkBox2.TabIndex = 28;
@@ -161,7 +162,7 @@
this.checkBox1.AutoSize = true; this.checkBox1.AutoSize = true;
this.checkBox1.Checked = true; this.checkBox1.Checked = true;
this.checkBox1.CheckState = System.Windows.Forms.CheckState.Checked; this.checkBox1.CheckState = System.Windows.Forms.CheckState.Checked;
this.checkBox1.Location = new System.Drawing.Point(185, 59); this.checkBox1.Location = new System.Drawing.Point(184, 76);
this.checkBox1.Name = "checkBox1"; this.checkBox1.Name = "checkBox1";
this.checkBox1.Size = new System.Drawing.Size(78, 16); this.checkBox1.Size = new System.Drawing.Size(78, 16);
this.checkBox1.TabIndex = 27; this.checkBox1.TabIndex = 27;
@@ -170,7 +171,7 @@
// //
// button7 // button7
// //
this.button7.Location = new System.Drawing.Point(284, 76); this.button7.Location = new System.Drawing.Point(283, 93);
this.button7.Name = "button7"; this.button7.Name = "button7";
this.button7.Size = new System.Drawing.Size(75, 23); this.button7.Size = new System.Drawing.Size(75, 23);
this.button7.TabIndex = 26; this.button7.TabIndex = 26;
@@ -181,7 +182,7 @@
// label9 // label9
// //
this.label9.AutoSize = true; this.label9.AutoSize = true;
this.label9.Location = new System.Drawing.Point(428, 63); this.label9.Location = new System.Drawing.Point(427, 80);
this.label9.Name = "label9"; this.label9.Name = "label9";
this.label9.Size = new System.Drawing.Size(47, 12); this.label9.Size = new System.Drawing.Size(47, 12);
this.label9.TabIndex = 25; this.label9.TabIndex = 25;
@@ -189,7 +190,7 @@
// //
// textBox10 // textBox10
// //
this.textBox10.Location = new System.Drawing.Point(430, 78); this.textBox10.Location = new System.Drawing.Point(429, 95);
this.textBox10.Name = "textBox10"; this.textBox10.Name = "textBox10";
this.textBox10.Size = new System.Drawing.Size(55, 21); this.textBox10.Size = new System.Drawing.Size(55, 21);
this.textBox10.TabIndex = 24; this.textBox10.TabIndex = 24;
@@ -198,7 +199,7 @@
// label8 // label8
// //
this.label8.AutoSize = true; this.label8.AutoSize = true;
this.label8.Location = new System.Drawing.Point(363, 63); this.label8.Location = new System.Drawing.Point(362, 80);
this.label8.Name = "label8"; this.label8.Name = "label8";
this.label8.Size = new System.Drawing.Size(47, 12); this.label8.Size = new System.Drawing.Size(47, 12);
this.label8.TabIndex = 23; this.label8.TabIndex = 23;
@@ -206,7 +207,7 @@
// //
// textBox9 // textBox9
// //
this.textBox9.Location = new System.Drawing.Point(365, 78); this.textBox9.Location = new System.Drawing.Point(364, 95);
this.textBox9.Name = "textBox9"; this.textBox9.Name = "textBox9";
this.textBox9.Size = new System.Drawing.Size(55, 21); this.textBox9.Size = new System.Drawing.Size(55, 21);
this.textBox9.TabIndex = 22; this.textBox9.TabIndex = 22;
@@ -214,7 +215,7 @@
// //
// button6 // button6
// //
this.button6.Location = new System.Drawing.Point(213, 76); this.button6.Location = new System.Drawing.Point(212, 93);
this.button6.Name = "button6"; this.button6.Name = "button6";
this.button6.Size = new System.Drawing.Size(75, 23); this.button6.Size = new System.Drawing.Size(75, 23);
this.button6.TabIndex = 21; this.button6.TabIndex = 21;
@@ -225,7 +226,7 @@
// label7 // label7
// //
this.label7.AutoSize = true; this.label7.AutoSize = true;
this.label7.Location = new System.Drawing.Point(150, 63); this.label7.Location = new System.Drawing.Point(149, 80);
this.label7.Name = "label7"; this.label7.Name = "label7";
this.label7.Size = new System.Drawing.Size(29, 12); this.label7.Size = new System.Drawing.Size(29, 12);
this.label7.TabIndex = 20; this.label7.TabIndex = 20;
@@ -233,7 +234,7 @@
// //
// textBox8 // textBox8
// //
this.textBox8.Location = new System.Drawing.Point(152, 78); this.textBox8.Location = new System.Drawing.Point(151, 95);
this.textBox8.Name = "textBox8"; this.textBox8.Name = "textBox8";
this.textBox8.Size = new System.Drawing.Size(55, 21); this.textBox8.Size = new System.Drawing.Size(55, 21);
this.textBox8.TabIndex = 19; this.textBox8.TabIndex = 19;
@@ -242,7 +243,7 @@
// label6 // label6
// //
this.label6.AutoSize = true; this.label6.AutoSize = true;
this.label6.Location = new System.Drawing.Point(78, 63); this.label6.Location = new System.Drawing.Point(77, 80);
this.label6.Name = "label6"; this.label6.Name = "label6";
this.label6.Size = new System.Drawing.Size(47, 12); this.label6.Size = new System.Drawing.Size(47, 12);
this.label6.TabIndex = 18; this.label6.TabIndex = 18;
@@ -250,7 +251,7 @@
// //
// textBox7 // textBox7
// //
this.textBox7.Location = new System.Drawing.Point(80, 78); this.textBox7.Location = new System.Drawing.Point(79, 95);
this.textBox7.Name = "textBox7"; this.textBox7.Name = "textBox7";
this.textBox7.Size = new System.Drawing.Size(55, 21); this.textBox7.Size = new System.Drawing.Size(55, 21);
this.textBox7.TabIndex = 17; this.textBox7.TabIndex = 17;
@@ -259,7 +260,7 @@
// label5 // label5
// //
this.label5.AutoSize = true; this.label5.AutoSize = true;
this.label5.Location = new System.Drawing.Point(10, 63); this.label5.Location = new System.Drawing.Point(9, 80);
this.label5.Name = "label5"; this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(47, 12); this.label5.Size = new System.Drawing.Size(47, 12);
this.label5.TabIndex = 16; this.label5.TabIndex = 16;
@@ -267,7 +268,7 @@
// //
// textBox6 // textBox6
// //
this.textBox6.Location = new System.Drawing.Point(12, 78); this.textBox6.Location = new System.Drawing.Point(11, 95);
this.textBox6.Name = "textBox6"; this.textBox6.Name = "textBox6";
this.textBox6.Size = new System.Drawing.Size(55, 21); this.textBox6.Size = new System.Drawing.Size(55, 21);
this.textBox6.TabIndex = 15; this.textBox6.TabIndex = 15;
@@ -275,7 +276,7 @@
// //
// button5 // button5
// //
this.button5.Location = new System.Drawing.Point(141, 35); this.button5.Location = new System.Drawing.Point(141, 33);
this.button5.Name = "button5"; this.button5.Name = "button5";
this.button5.Size = new System.Drawing.Size(212, 23); this.button5.Size = new System.Drawing.Size(212, 23);
this.button5.TabIndex = 6; this.button5.TabIndex = 6;
@@ -285,7 +286,7 @@
// //
// textBox2 // textBox2
// //
this.textBox2.Location = new System.Drawing.Point(369, 37); this.textBox2.Location = new System.Drawing.Point(369, 35);
this.textBox2.Name = "textBox2"; this.textBox2.Name = "textBox2";
this.textBox2.Size = new System.Drawing.Size(55, 21); this.textBox2.Size = new System.Drawing.Size(55, 21);
this.textBox2.TabIndex = 7; this.textBox2.TabIndex = 7;
@@ -294,7 +295,7 @@
// label1 // label1
// //
this.label1.AutoSize = true; this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(367, 22); this.label1.Location = new System.Drawing.Point(367, 20);
this.label1.Name = "label1"; this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(53, 12); this.label1.Size = new System.Drawing.Size(53, 12);
this.label1.TabIndex = 8; this.label1.TabIndex = 8;
@@ -303,7 +304,7 @@
// label4 // label4
// //
this.label4.AutoSize = true; this.label4.AutoSize = true;
this.label4.Location = new System.Drawing.Point(78, 22); this.label4.Location = new System.Drawing.Point(78, 20);
this.label4.Name = "label4"; this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(59, 12); this.label4.Size = new System.Drawing.Size(59, 12);
this.label4.TabIndex = 14; this.label4.TabIndex = 14;
@@ -311,7 +312,7 @@
// //
// textBox3 // textBox3
// //
this.textBox3.Location = new System.Drawing.Point(430, 37); this.textBox3.Location = new System.Drawing.Point(430, 35);
this.textBox3.Name = "textBox3"; this.textBox3.Name = "textBox3";
this.textBox3.Size = new System.Drawing.Size(55, 21); this.textBox3.Size = new System.Drawing.Size(55, 21);
this.textBox3.TabIndex = 9; this.textBox3.TabIndex = 9;
@@ -319,7 +320,7 @@
// //
// textBox5 // textBox5
// //
this.textBox5.Location = new System.Drawing.Point(80, 37); this.textBox5.Location = new System.Drawing.Point(80, 35);
this.textBox5.Name = "textBox5"; this.textBox5.Name = "textBox5";
this.textBox5.Size = new System.Drawing.Size(55, 21); this.textBox5.Size = new System.Drawing.Size(55, 21);
this.textBox5.TabIndex = 13; this.textBox5.TabIndex = 13;
@@ -328,7 +329,7 @@
// label2 // label2
// //
this.label2.AutoSize = true; this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(428, 22); this.label2.Location = new System.Drawing.Point(428, 20);
this.label2.Name = "label2"; this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(41, 12); this.label2.Size = new System.Drawing.Size(41, 12);
this.label2.TabIndex = 10; this.label2.TabIndex = 10;
@@ -337,7 +338,7 @@
// label3 // label3
// //
this.label3.AutoSize = true; this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(8, 22); this.label3.Location = new System.Drawing.Point(8, 20);
this.label3.Name = "label3"; this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(59, 12); this.label3.Size = new System.Drawing.Size(59, 12);
this.label3.TabIndex = 12; this.label3.TabIndex = 12;
@@ -345,7 +346,7 @@
// //
// textBox4 // textBox4
// //
this.textBox4.Location = new System.Drawing.Point(10, 37); this.textBox4.Location = new System.Drawing.Point(10, 35);
this.textBox4.Name = "textBox4"; this.textBox4.Name = "textBox4";
this.textBox4.Size = new System.Drawing.Size(55, 21); this.textBox4.Size = new System.Drawing.Size(55, 21);
this.textBox4.TabIndex = 11; this.textBox4.TabIndex = 11;
@@ -354,17 +355,16 @@
// groupBox1 // groupBox1
// //
this.groupBox1.Controls.Add(this.button2); this.groupBox1.Controls.Add(this.button2);
this.groupBox1.Controls.Add(this.button4);
this.groupBox1.Location = new System.Drawing.Point(438, 45); this.groupBox1.Location = new System.Drawing.Point(438, 45);
this.groupBox1.Name = "groupBox1"; this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(340, 82); this.groupBox1.Size = new System.Drawing.Size(340, 59);
this.groupBox1.TabIndex = 16; this.groupBox1.TabIndex = 16;
this.groupBox1.TabStop = false; this.groupBox1.TabStop = false;
this.groupBox1.Text = "九点标定"; this.groupBox1.Text = "九点标定";
// //
// button2 // button2
// //
this.button2.Location = new System.Drawing.Point(61, 40); this.button2.Location = new System.Drawing.Point(61, 20);
this.button2.Name = "button2"; this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(212, 23); this.button2.Size = new System.Drawing.Size(212, 23);
this.button2.TabIndex = 3; this.button2.TabIndex = 3;
@@ -372,17 +372,6 @@
this.button2.UseVisualStyleBackColor = true; this.button2.UseVisualStyleBackColor = true;
this.button2.Click += new System.EventHandler(this.button2_Click); this.button2.Click += new System.EventHandler(this.button2_Click);
// //
// button4
//
this.button4.Location = new System.Drawing.Point(61, 11);
this.button4.Name = "button4";
this.button4.Size = new System.Drawing.Size(212, 23);
this.button4.TabIndex = 5;
this.button4.Text = "计算各图的圆中心(相机坐标)";
this.button4.UseVisualStyleBackColor = true;
this.button4.Visible = false;
this.button4.Click += new System.EventHandler(this.button4_Click);
//
// button3 // button3
// //
this.button3.Location = new System.Drawing.Point(736, 16); this.button3.Location = new System.Drawing.Point(736, 16);
@@ -418,6 +407,16 @@
this.richTextBox1.TabIndex = 0; this.richTextBox1.TabIndex = 0;
this.richTextBox1.Text = ""; this.richTextBox1.Text = "";
// //
// button4
//
this.button4.Location = new System.Drawing.Point(787, 65);
this.button4.Name = "button4";
this.button4.Size = new System.Drawing.Size(75, 23);
this.button4.TabIndex = 18;
this.button4.Text = "并行测试";
this.button4.UseVisualStyleBackColor = true;
this.button4.Click += new System.EventHandler(this.button4_Click);
//
// Form1 // Form1
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
@@ -450,7 +449,6 @@
private System.Windows.Forms.RichTextBox richTextBox1; private System.Windows.Forms.RichTextBox richTextBox1;
private System.Windows.Forms.Button button2; private System.Windows.Forms.Button button2;
private System.Windows.Forms.Button button3; private System.Windows.Forms.Button button3;
private System.Windows.Forms.Button button4;
private System.Windows.Forms.Label label2; private System.Windows.Forms.Label label2;
private System.Windows.Forms.TextBox textBox3; private System.Windows.Forms.TextBox textBox3;
private System.Windows.Forms.Label label1; private System.Windows.Forms.Label label1;
@@ -476,6 +474,7 @@
private System.Windows.Forms.TextBox textBox6; private System.Windows.Forms.TextBox textBox6;
private System.Windows.Forms.CheckBox checkBox2; private System.Windows.Forms.CheckBox checkBox2;
private System.Windows.Forms.CheckBox checkBox1; private System.Windows.Forms.CheckBox checkBox1;
private System.Windows.Forms.Button button4;
} }
} }

View File

@@ -28,7 +28,7 @@ namespace WaferAdjust
{ {
public partial class Form1 : Form public partial class Form1 : Form
{ {
GetCircleToolBlock getCircleCameraToolBlock; GetCircleToolBlock[] getCircleCameraToolBlock;
GetCircleToolBlock getCircleMachineToolBlock; GetCircleToolBlock getCircleMachineToolBlock;
FitCircleToolBlock fitCircleCameraToolBlock; FitCircleToolBlock fitCircleCameraToolBlock;
FitCircleToolBlock FitCircleMachineToolBlock; FitCircleToolBlock FitCircleMachineToolBlock;
@@ -42,26 +42,30 @@ namespace WaferAdjust
{ {
try try
{ {
getCircleCameraToolBlock = new GetCircleToolBlock(); getCircleCameraToolBlock = new GetCircleToolBlock[64];
getCircleCameraToolBlock.OnGetCircleResult += GetCircleCameraToolBlock_OnGetCircleResult; for (int i = 0; i < 64; i++)
getCircleCameraToolBlock.OnToolReady += GetCircleCameraToolBlock_OnToolReady; {
getCircleCameraToolBlock.Initialize("vpp\\GetCircleC.vpp"); getCircleCameraToolBlock[i] = new GetCircleToolBlock();
getCircleCameraToolBlock[i].OnGetCircleResult += GetCircleCameraToolBlock_OnGetCircleResult;
getCircleCameraToolBlock[i].OnToolReady += GetCircleCameraToolBlock_OnToolReady;
getCircleCameraToolBlock[i].Initialize(i, "vpp\\GetCircleC.vpp");
}
fitCircleCameraToolBlock = new FitCircleToolBlock(); fitCircleCameraToolBlock = new FitCircleToolBlock();
fitCircleCameraToolBlock.OnFitCircleResult += FitCircleCameraToolBlock_OnFitCircleResult; fitCircleCameraToolBlock.OnFitCircleResult += FitCircleCameraToolBlock_OnFitCircleResult;
fitCircleCameraToolBlock.OnToolReady += FitCircleCameraToolBlock_OnToolReady; fitCircleCameraToolBlock.OnToolReady += FitCircleCameraToolBlock_OnToolReady;
fitCircleCameraToolBlock.Initialize("vpp\\FitCircleC.vpp"); fitCircleCameraToolBlock.Initialize(0, "vpp\\FitCircleC.vpp");
getCircleMachineToolBlock = new GetCircleToolBlock(); getCircleMachineToolBlock = new GetCircleToolBlock();
getCircleMachineToolBlock.OnGetCircleResult += GetCircleMachineToolBlock_OnGetCircleResult; getCircleMachineToolBlock.OnGetCircleResult += GetCircleMachineToolBlock_OnGetCircleResult;
getCircleMachineToolBlock.OnGetNashResult += GetCircleMachineToolBlock_OnGetNashResult; getCircleMachineToolBlock.OnGetNashResult += GetCircleMachineToolBlock_OnGetNashResult;
getCircleMachineToolBlock.OnToolReady += GetCircleMachineToolBlock_OnToolReady; getCircleMachineToolBlock.OnToolReady += GetCircleMachineToolBlock_OnToolReady;
getCircleMachineToolBlock.Initialize("vpp\\GetCircleM.vpp"); getCircleMachineToolBlock.Initialize(0, "vpp\\GetCircleM.vpp");
FitCircleMachineToolBlock = new FitCircleToolBlock(); FitCircleMachineToolBlock = new FitCircleToolBlock();
FitCircleMachineToolBlock.OnFitCircleResult += FitCircleMachineToolBlock_OnFitCircleResult; FitCircleMachineToolBlock.OnFitCircleResult += FitCircleMachineToolBlock_OnFitCircleResult;
FitCircleMachineToolBlock.OnToolReady += FitCircleMachineToolBlock_OnToolReady; FitCircleMachineToolBlock.OnToolReady += FitCircleMachineToolBlock_OnToolReady;
FitCircleMachineToolBlock.Initialize("vpp\\FitCircleM.vpp"); FitCircleMachineToolBlock.Initialize(0, "vpp\\FitCircleM.vpp");
translateCirclePoint = new TranslateCirclePoint(); translateCirclePoint = new TranslateCirclePoint();
@@ -73,13 +77,13 @@ namespace WaferAdjust
} }
} }
private void GetCircleMachineToolBlock_OnGetNashResult(double x, double y) private void GetCircleMachineToolBlock_OnGetNashResult(int index, double x, double y)
{ {
translateCirclePoint.AddNashPoint(x, y); translateCirclePoint.AddNashPoint(x, y);
ShowMessage($"Update Nash X:{x}, Y:{y}{Environment.NewLine}"); ShowMessage($"Update Nash X:{x}, Y:{y}{Environment.NewLine}");
} }
private void FitCircleMachineToolBlock_OnToolReady(bool ready) private void FitCircleMachineToolBlock_OnToolReady(int index, bool ready)
{ {
} }
@@ -137,7 +141,7 @@ namespace WaferAdjust
return Math.Round(angleDegrees, 3); return Math.Round(angleDegrees, 3);
} }
private void FitCircleMachineToolBlock_OnFitCircleResult(double x, double y, double r, double rms) private void FitCircleMachineToolBlock_OnFitCircleResult(int index, double x, double y, double r, double rms)
{ {
AddPointMarker(m_graphics2, x, y); AddPointMarker(m_graphics2, x, y);
AddPointMarker(m_graphics2, translateCirclePoint.GetRotateX(), translateCirclePoint.GetRotateY(), CogColorConstants.Red); AddPointMarker(m_graphics2, translateCirclePoint.GetRotateX(), translateCirclePoint.GetRotateY(), CogColorConstants.Red);
@@ -161,24 +165,24 @@ namespace WaferAdjust
ImageDisplayFit(); ImageDisplayFit();
} }
private void GetCircleMachineToolBlock_OnToolReady(bool ready) private void GetCircleMachineToolBlock_OnToolReady(int index, bool ready)
{ {
} }
private void GetCircleMachineToolBlock_OnGetCircleResult(double x, double y, double r) private void GetCircleMachineToolBlock_OnGetCircleResult(int index, double x, double y, double r)
{ {
translateCirclePoint.AddCircleCenter(x, y, r); translateCirclePoint.AddCircleCenter(x, y, r);
translateCirclePoint.AddCirclePoint(getCircleMachineToolBlock.PointInfos); translateCirclePoint.AddCirclePoint(getCircleMachineToolBlock.PointInfos);
ShowMessage($"X:{x}, Y:{y}, R:{r}{Environment.NewLine}"); ShowMessage($"X:{x}, Y:{y}, R:{r}{Environment.NewLine}");
} }
private void FitCircleCameraToolBlock_OnToolReady(bool ready) private void FitCircleCameraToolBlock_OnToolReady(int index, bool ready)
{ {
} }
private void FitCircleCameraToolBlock_OnFitCircleResult(double x, double y, double r, double rms) private void FitCircleCameraToolBlock_OnFitCircleResult(int index, double x, double y, double r, double rms)
{ {
AddPointMarker(m_graphics2, x, y); AddPointMarker(m_graphics2, x, y);
ShowMessage($"{Environment.NewLine}X:{x}, Y:{y}, RMS:{rms}{Environment.NewLine}"); ShowMessage($"{Environment.NewLine}X:{x}, Y:{y}, RMS:{rms}{Environment.NewLine}");
@@ -188,14 +192,14 @@ namespace WaferAdjust
ImageDisplayFit(); ImageDisplayFit();
} }
private void GetCircleCameraToolBlock_OnToolReady(bool ready) private void GetCircleCameraToolBlock_OnToolReady(int index, bool ready)
{ {
} }
private void GetCircleCameraToolBlock_OnGetCircleResult(double x, double y, double r) private void GetCircleCameraToolBlock_OnGetCircleResult(int index, double x, double y, double r)
{ {
ShowMessage($"X:{x}, Y:{y}, R:{r}{Environment.NewLine}"); ShowMessage($"{index.ToString().PadLeft(2, '0')} X:{x}, Y:{y}, R:{r}{Environment.NewLine}");
m_circlePoints.Add(new PointInfo(x, y, r)); m_circlePoints.Add(new PointInfo(x, y, r));
} }
@@ -238,7 +242,7 @@ namespace WaferAdjust
{ {
Bitmap bmp = new Bitmap(file); Bitmap bmp = new Bitmap(file);
m_lastBMP = bmp; m_lastBMP = bmp;
getCircleCameraToolBlock.Run(bmp); getCircleCameraToolBlock[0].Run(bmp);
} }
if (m_circlePoints == null || m_circlePoints.Count < 4) if (m_circlePoints == null || m_circlePoints.Count < 4)
@@ -300,21 +304,6 @@ namespace WaferAdjust
richTextBox1.ScrollToCaret(); richTextBox1.ScrollToCaret();
} }
private void button4_Click(object sender, EventArgs e)
{
if (!Directory.Exists(m_lastPath))
return;
ShowMessage("计算相机坐标系下各圆弧的圆中心:\n");
m_circlePoints = new List<PointInfo>();
string[] files = Directory.GetFiles(m_lastPath, "*.bmp");
foreach (string file in files)
{
Bitmap bmp = new Bitmap(file);
m_lastBMP = bmp;
getCircleCameraToolBlock.Run(bmp);
}
}
private void button5_Click(object sender, EventArgs e) private void button5_Click(object sender, EventArgs e)
{ {
if (!Directory.Exists(m_lastPath)) if (!Directory.Exists(m_lastPath))
@@ -362,5 +351,82 @@ namespace WaferAdjust
textBox6.Text = Math.Round(res.x, 3).ToString(); textBox6.Text = Math.Round(res.x, 3).ToString();
textBox7.Text = Math.Round(res.y, 3).ToString(); textBox7.Text = Math.Round(res.y, 3).ToString();
} }
private Object syncLock = new Object();
private void button4_Click(object sender, EventArgs e)
{
if (!Directory.Exists(m_lastPath))
return;
ShowMessage("计算相机坐标系下各圆弧的圆中心:\n");
m_circlePoints = new List<PointInfo>();
string[] files = Directory.GetFiles(m_lastPath, "*.bmp");
//parallel1
//Parallel.For(0, files.Length, (i) =>
//{
// Bitmap bmp = new Bitmap(files[i]);
// m_lastBMP = bmp;
// getCircleCameraToolBlock[i].Run(bmp);
//});
// ✅ 正确Parallel.For 天然同步等待
//Parallel.For(0, files.Length, i =>
//{
// using (Bitmap bmp = new Bitmap(files[i]))
// {
// // 直接执行,不创建新 Task
// getCircleCameraToolBlock[i].Run(bmp);
// // 如需保存最后一个,必须加锁
// lock (syncLock)
// {
// m_lastBMP = bmp; // 注意bmp 已释放,这里应保存副本或路径
// }
// }
//});
// 执行到这里,所有迭代已完成
List<Task> tasks = new List<Task>();
string lastProcessedFile = null; // 改用路径代替位图对象
//Parallel.For(0, files.Length, (i) =>
//{
for (int i = 0; i < files.Length; i++)
{
int localIndex = i; // 避免闭包捕获
tasks.Add(Task.Run(() =>
{
using (Bitmap bmp = new Bitmap(files[localIndex]))
{
getCircleCameraToolBlock[localIndex].Run(bmp);
// 线程安全地记录最后处理的文件
lock (syncLock)
{
lastProcessedFile = files[localIndex];
}
}
}));
}
//});
Task.WhenAll(tasks.ToArray()).Wait();
// 后续代码:所有任务已完成
if (lastProcessedFile != null)
{
m_lastBMP = new Bitmap(lastProcessedFile);
}
if (m_circlePoints == null || m_circlePoints.Count < 4)
return;
if (m_lastBMP == null)
return;
ShowMessage("计算相机坐标系下各圆弧的圆中心拟合出的旋转中心:\n");
var aa = m_circlePoints;//.OrderBy(x => x.Radius).Skip(2).Take(m_circlePoints.Count - 4).ToList();
m_graphics = new CogGraphicCollection();
foreach (PointInfo pointInfo in aa)
{
AddPointMarker(m_graphics, pointInfo.X, pointInfo.Y);
}
fitCircleCameraToolBlock.Run(m_lastBMP, aa);
}
} }
} }

View File

@@ -11,9 +11,9 @@ using System.Threading.Tasks;
namespace WaferAdjust namespace WaferAdjust
{ {
public delegate void OnGetCircleResult(double x, double y, double r); public delegate void OnGetCircleResult(int index, double x, double y, double r);
public delegate void OnToolReady(bool ready); public delegate void OnToolReady(int index, bool ready);
public delegate void OnGetNashResult(double x, double y); public delegate void OnGetNashResult(int index, double x, double y);
internal class GetCircleToolBlock internal class GetCircleToolBlock
{ {
private CogToolBlock cogToolBlock; private CogToolBlock cogToolBlock;
@@ -22,7 +22,8 @@ namespace WaferAdjust
public event OnGetCircleResult OnGetCircleResult; public event OnGetCircleResult OnGetCircleResult;
public event OnGetNashResult OnGetNashResult; public event OnGetNashResult OnGetNashResult;
public List<PointInfo> PointInfos; public List<PointInfo> PointInfos;
public void Initialize(string vpp) private int m_index;
public void Initialize(int index, string vpp)
{ {
try try
{ {
@@ -32,12 +33,13 @@ namespace WaferAdjust
cogToolBlock.Dispose(); cogToolBlock.Dispose();
cogToolBlock = null; cogToolBlock = null;
} }
m_index = index;
initialized = false; initialized = false;
PointInfos = new List<PointInfo>(); PointInfos = new List<PointInfo>();
cogToolBlock = CogSerializer.LoadObjectFromFile(vpp) as CogToolBlock; cogToolBlock = CogSerializer.LoadObjectFromFile(vpp) as CogToolBlock;
cogToolBlock.Ran += CogToolBlock_Ran; cogToolBlock.Ran += CogToolBlock_Ran;
initialized = true; initialized = true;
OnToolReady?.Invoke(initialized); OnToolReady?.Invoke(m_index, initialized);
LogHelper.LogInfo($"{vpp} initialized successfully: " + vpp); LogHelper.LogInfo($"{vpp} initialized successfully: " + vpp);
} }
catch (Exception ex) catch (Exception ex)
@@ -61,16 +63,19 @@ namespace WaferAdjust
} }
} }
OnGetCircleResult?.Invoke(Math.Round((double)cogToolBlock.Outputs["CenterX"].Value, 3), OnGetCircleResult?.Invoke(m_index, Math.Round((double)cogToolBlock.Outputs["CenterX"].Value, 3),
Math.Round((double)cogToolBlock.Outputs["CenterY"].Value, 3), Math.Round((double)cogToolBlock.Outputs["CenterY"].Value, 3),
Math.Round((double)cogToolBlock.Outputs["Radius"].Value, 3)); Math.Round((double)cogToolBlock.Outputs["Radius"].Value, 3));
if (cogToolBlock.Outputs.Contains("Results_Count"))
{
if ((int)cogToolBlock.Outputs["Results_Count"].Value == 1) if ((int)cogToolBlock.Outputs["Results_Count"].Value == 1)
{ {
OnGetNashResult?.Invoke(Math.Round((double)cogToolBlock.Outputs["TranslationX"].Value, 3), OnGetNashResult?.Invoke(m_index, Math.Round((double)cogToolBlock.Outputs["TranslationX"].Value, 3),
Math.Round((double)cogToolBlock.Outputs["TranslationY"].Value, 3)); Math.Round((double)cogToolBlock.Outputs["TranslationY"].Value, 3));
} }
} }
}
catch (Exception ex) catch (Exception ex)
{ {
LogHelper.LogError(ex.Message + ex.StackTrace); LogHelper.LogError(ex.Message + ex.StackTrace);

View File

@@ -122,7 +122,9 @@
<DependentUpon>Resources.resx</DependentUpon> <DependentUpon>Resources.resx</DependentUpon>
<DesignTime>True</DesignTime> <DesignTime>True</DesignTime>
</Compile> </Compile>
<None Include="Nlog.config" /> <None Include="Nlog.config">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="packages.config" /> <None Include="packages.config" />
<None Include="Properties\Settings.settings"> <None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator> <Generator>SettingsSingleFileGenerator</Generator>