using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using CvBase;
using HalconDotNet;
using CWindowTool;
namespace CvImageTool
{
public partial class AffineTransPoint2DForm : Form
{
private int ProcessIndex { set; get; }
private int ImageOptIndex { set; get; }
private string Description { set; get; }
private AffineTransPoint2DTool affineTransPoint2DTool;
private List<BaseProcess> processes;
private CWindows[] cCWindows;
public AffineTransPoint2DForm()
{
InitializeComponent();
}
public AffineTransPoint2DForm(int processIndex, int imageOptIndex,
string cProcessSettingFilePath, string cImageOptSettingFilePath, string cDescription,
List<BaseProcess> baseProcesses, CWindows[] cWindows)
{
this.StartPosition = FormStartPosition.CenterParent;
InitializeComponent();
this.ProcessIndex = processIndex;
this.ImageOptIndex = imageOptIndex;
this.Description = cDescription;
this.processes = baseProcesses;
this.cCWindows = cWindows;
affineTransPoint2DTool = new AffineTransPoint2DTool(processIndex, imageOptIndex, cProcessSettingFilePath, cImageOptSettingFilePath, processes, cWindows);
}
private void AffineTransPoint2DForm_Load(object sender, EventArgs e)
{
this.Text = processes[ProcessIndex].Name + "#" + Description;
Affine_OptNameCMBox.Items.Clear();
for (int i = 0; i < ImageOptIndex; i++)
{
string cDes = processes[ProcessIndex].BaseImageOpts[i].Description;
Affine_OptNameCMBox.Items.Add(cDes);
}
if (affineTransPoint2DTool.ReadFile(Description))
{
string[] values = affineTransPoint2DTool.AffinePositSelect.Split('_');
if (values.Length == 2)
{
Affine_OptNameCMBox.Text = values[0];
Affine_ParamNameCMBox.Text = values[1];
}
else if (values.Length == 1)
{
Affine_OptNameCMBox.Text = values[0];
}
values = affineTransPoint2DTool.affinMatrixSelect.Split('_');
if (values.Length == 2)
{
Matrix_OptNameCMBox.Text = values[0];
Matrix_ParamNameCMBox.Text = values[1];
}
else if (values.Length == 1)
{
Matrix_OptNameCMBox.Text = values[0];
}
}
}
private void Affine_OptNameCMBox_SelectedIndexChanged(object sender, EventArgs e)
{
if (Affine_OptNameCMBox.SelectedIndex >= 0)
{
Affine_ParamNameCMBox.Items.Clear();
foreach (string value in processes[ProcessIndex].BaseImageOutParams[Affine_OptNameCMBox.SelectedIndex].OutputHTupleNames)
Affine_ParamNameCMBox.Items.Add(value);
}
}
private void SaveBtn_Click(object sender, EventArgs e)
{
affineTransPoint2DTool.AffinePositSelect = Affine_OptNameCMBox.Text + "_" + Affine_ParamNameCMBox.Text;
affineTransPoint2DTool.affinMatrixSelect = Matrix_OptNameCMBox.Text + "_" + Matrix_ParamNameCMBox.Text;
affineTransPoint2DTool.WriteFile(Description);
}
private void RunBtn_Click(object sender, EventArgs e)
{
affineTransPoint2DTool.ReadFile(Description);
affineTransPoint2DTool.Running(out HTuple x, out HTuple y);
if (x.Length > 0)
{
for (int i = 0; i < x.Length; i++)
{
dataGridView1.Rows[i].Cells[0].Value = (i + 1).ToString();
dataGridView1.Rows[i].Cells[1].Value = x.D.ToString();
dataGridView1.Rows[i].Cells[2].Value = y.D.ToString();
}
}
}
}
}