test parallel nash test

This commit is contained in:
2025-11-27 10:55:33 +08:00
parent 5e70315b9a
commit 3d068aeaeb
3 changed files with 110 additions and 26 deletions

View File

@@ -32,6 +32,7 @@
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1));
this.splitContainer1 = new System.Windows.Forms.SplitContainer();
this.cogRecordDisplay1 = new Cognex.VisionPro.CogRecordDisplay();
this.button4 = new System.Windows.Forms.Button();
this.groupBox2 = new System.Windows.Forms.GroupBox();
this.checkBox2 = new System.Windows.Forms.CheckBox();
this.checkBox1 = new System.Windows.Forms.CheckBox();
@@ -62,7 +63,7 @@
this.textBox1 = new System.Windows.Forms.TextBox();
this.button1 = new System.Windows.Forms.Button();
this.richTextBox1 = new System.Windows.Forms.RichTextBox();
this.button4 = new System.Windows.Forms.Button();
this.button8 = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit();
this.splitContainer1.Panel1.SuspendLayout();
this.splitContainer1.Panel2.SuspendLayout();
@@ -115,8 +116,19 @@
this.cogRecordDisplay1.Size = new System.Drawing.Size(885, 558);
this.cogRecordDisplay1.TabIndex = 0;
//
// 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);
//
// groupBox2
//
this.groupBox2.Controls.Add(this.button8);
this.groupBox2.Controls.Add(this.checkBox2);
this.groupBox2.Controls.Add(this.checkBox1);
this.groupBox2.Controls.Add(this.button7);
@@ -407,15 +419,15 @@
this.richTextBox1.TabIndex = 0;
this.richTextBox1.Text = "";
//
// button4
// button8
//
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);
this.button8.Location = new System.Drawing.Point(429, 54);
this.button8.Name = "button8";
this.button8.Size = new System.Drawing.Size(75, 23);
this.button8.TabIndex = 29;
this.button8.Text = "并行测试";
this.button8.UseVisualStyleBackColor = true;
this.button8.Click += new System.EventHandler(this.button8_Click);
//
// Form1
//
@@ -475,6 +487,7 @@
private System.Windows.Forms.CheckBox checkBox2;
private System.Windows.Forms.CheckBox checkBox1;
private System.Windows.Forms.Button button4;
private System.Windows.Forms.Button button8;
}
}

View File

@@ -29,7 +29,7 @@ namespace WaferAdjust
public partial class Form1 : Form
{
GetCircleToolBlock[] getCircleCameraToolBlock;
GetCircleToolBlock getCircleMachineToolBlock;
GetCircleToolBlock[] getCircleMachineToolBlock;
FitCircleToolBlock fitCircleCameraToolBlock;
FitCircleToolBlock FitCircleMachineToolBlock;
List<PointInfo> m_circlePoints;
@@ -56,11 +56,15 @@ namespace WaferAdjust
fitCircleCameraToolBlock.OnToolReady += FitCircleCameraToolBlock_OnToolReady;
fitCircleCameraToolBlock.Initialize(0, "vpp\\FitCircleC.vpp");
getCircleMachineToolBlock = new GetCircleToolBlock();
getCircleMachineToolBlock.OnGetCircleResult += GetCircleMachineToolBlock_OnGetCircleResult;
getCircleMachineToolBlock.OnGetNashResult += GetCircleMachineToolBlock_OnGetNashResult;
getCircleMachineToolBlock.OnToolReady += GetCircleMachineToolBlock_OnToolReady;
getCircleMachineToolBlock.Initialize(0, "vpp\\GetCircleM.vpp");
getCircleMachineToolBlock = new GetCircleToolBlock[64];
for (int i = 0; i < 64; i++)
{
getCircleMachineToolBlock[i] = new GetCircleToolBlock();
getCircleMachineToolBlock[i].OnGetCircleResult += GetCircleMachineToolBlock_OnGetCircleResult;
getCircleMachineToolBlock[i].OnGetNashResult += GetCircleMachineToolBlock_OnGetNashResult;
getCircleMachineToolBlock[i].OnToolReady += GetCircleMachineToolBlock_OnToolReady;
getCircleMachineToolBlock[i].Initialize(i, "vpp\\GetCircleM.vpp");
}
FitCircleMachineToolBlock = new FitCircleToolBlock();
FitCircleMachineToolBlock.OnFitCircleResult += FitCircleMachineToolBlock_OnFitCircleResult;
@@ -79,8 +83,11 @@ namespace WaferAdjust
private void GetCircleMachineToolBlock_OnGetNashResult(int index, double x, double y)
{
translateCirclePoint.AddNashPoint(x, y);
ShowMessage($"Update Nash X:{x}, Y:{y}{Environment.NewLine}");
lock (m_lock1)
{
translateCirclePoint.AddNashPoint(x, y, index);
ShowMessage($"Update Nash X:{x}, Y:{y}{Environment.NewLine}");
}
}
private void FitCircleMachineToolBlock_OnToolReady(int index, bool ready)
@@ -169,12 +176,15 @@ namespace WaferAdjust
{
}
private Object m_lock1 = new Object();
private void GetCircleMachineToolBlock_OnGetCircleResult(int index, double x, double y, double r)
{
translateCirclePoint.AddCircleCenter(x, y, r);
translateCirclePoint.AddCirclePoint(getCircleMachineToolBlock.PointInfos);
ShowMessage($"X:{x}, Y:{y}, R:{r}{Environment.NewLine}");
lock (m_lock1)
{
translateCirclePoint.AddCircleCenter(x, y, r);
translateCirclePoint.AddCirclePoint(getCircleMachineToolBlock[index].PointInfos, index);
ShowMessage($"X:{x}, Y:{y}, R:{r}{Environment.NewLine}");
}
}
private void FitCircleCameraToolBlock_OnToolReady(int index, bool ready)
@@ -316,7 +326,7 @@ namespace WaferAdjust
Bitmap bmp = new Bitmap(file);
m_lastBMP = bmp;
translateCirclePoint.AddCircleIndex();
getCircleMachineToolBlock.Run(m_lastBMP);
getCircleMachineToolBlock[0].Run(m_lastBMP);
}
ShowMessage("转换机械坐标系下圆弧各点的原始坐标:\n");
@@ -428,5 +438,60 @@ namespace WaferAdjust
}
fitCircleCameraToolBlock.Run(m_lastBMP, aa);
}
private void button8_Click(object sender, EventArgs e)
{
if (!Directory.Exists(m_lastPath))
return;
ShowMessage("读取机械坐标系下圆弧各点的坐标:\n");
translateCirclePoint.SetRotateXY(Convert.ToDouble(textBox4.Text), Convert.ToDouble(textBox5.Text), 360 * Convert.ToDouble(textBox2.Text) / Convert.ToDouble(textBox3.Text));
string[] files = Directory.GetFiles(m_lastPath, "*.bmp");
//foreach (string file in files)
//{
// Bitmap bmp = new Bitmap(file);
// m_lastBMP = bmp;
// translateCirclePoint.AddCircleIndex();
// getCircleMachineToolBlock[0].Run(m_lastBMP);
//}
List<Task> tasks = new List<Task>();
string lastProcessedFile = null; // 改用路径代替位图对象
for (int i = 0; i < files.Length; i++)
{
int localIndex = i; // 避免闭包捕获
tasks.Add(Task.Run(() =>
{
using (Bitmap bmp = new Bitmap(files[localIndex]))
{
getCircleMachineToolBlock[localIndex].Run(bmp);
// 线程安全地记录最后处理的文件
lock (syncLock)
{
lastProcessedFile = files[localIndex];
}
}
}));
}
Task.WhenAll(tasks.ToArray()).Wait();
// 后续代码:所有任务已完成
if (lastProcessedFile != null)
{
m_lastBMP = new Bitmap(lastProcessedFile);
}
ShowMessage("转换机械坐标系下圆弧各点的原始坐标:\n");
var points = translateCirclePoint.DoTranslatePoint();
translateCirclePoint.DoTranslateNashPoint();
ShowMessage("拟合机械坐标系下的圆中心:\n");
m_graphics = new CogGraphicCollection();
m_graphics2 = new CogGraphicCollection();
foreach (PointInfo pointInfo in points)
{
AddPointMarker(m_graphics, pointInfo.X, pointInfo.Y);
}
FitCircleMachineToolBlock.Run(m_lastBMP, points);
}
}
}

View File

@@ -32,20 +32,26 @@ namespace WaferAdjust
{
return rotateY;
}
public void AddCirclePoint(List<PointInfo> pointInfos)
public void AddCirclePoint(List<PointInfo> pointInfos, int index)
{
foreach (var item in pointInfos)
{
totalPoints.Add(new PointInfo(item.X, item.Y, circleIndex * perAngle));
if (circleIndex == 0)
totalPoints.Add(new PointInfo(item.X, item.Y, (index + 1) * perAngle));
else
totalPoints.Add(new PointInfo(item.X, item.Y, circleIndex * perAngle));
}
}
public void AddCircleIndex()
{
circleIndex++;
}
public void AddNashPoint(double x, double y)
public void AddNashPoint(double x, double y, int index)
{
nashPoint = new PointInfo(x, y, circleIndex * perAngle);
if (circleIndex == 0)
nashPoint = new PointInfo(x, y, (index + 1) * perAngle);
else
nashPoint = new PointInfo(x, y, circleIndex * perAngle);
}
public void AddCircleCenter(double x, double y, double r)
{