253 lines
11 KiB
C#
253 lines
11 KiB
C#
using Aurora;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Drawing;
|
|
using System.Linq;
|
|
using System.Runtime.InteropServices;
|
|
using VisionCommon;
|
|
using VisionCommonUI;
|
|
using WeldingCommon.Settings;
|
|
|
|
namespace WeldingCommon.Data {
|
|
public class FieldScanParams
|
|
{
|
|
private static FieldScanParams _instance = null;
|
|
private static int _ImageSizeWidthChild;
|
|
private static int _ImageSizeHeightChild;
|
|
private static int _RowCount;
|
|
private static int _ColCount;
|
|
|
|
public static FieldScanParams GetInstance()
|
|
{
|
|
if (_instance == null) {
|
|
_instance = new FieldScanParams();
|
|
}
|
|
return _instance;
|
|
}
|
|
|
|
public FieldScanParams()
|
|
{
|
|
|
|
}
|
|
|
|
public FieldScanParams(IAuroraEnvironment aurora)
|
|
{
|
|
Initialize(aurora);
|
|
}
|
|
|
|
public void Initialize(IAuroraEnvironment aurora)
|
|
{
|
|
var camConfig = aurora.DeviceManager.GetDeviceConfig(eCamId.CAM1.ToString()) as CamConfig;
|
|
var imageSize = camConfig.ImageSize;
|
|
|
|
//FieldScanParams 클래스를 SeqScout에서 객체 생성하여 ImageSize를 쓸수 있도록 하자.. 이렇게쓰면 변경할때마다 SeqScout도 함께 바꿔줘야함
|
|
_ImageSizeWidthChild = (int)(camConfig.ImageSize.Width * camConfig.ImageSizeRatioX);
|
|
_ImageSizeHeightChild = (int)(camConfig.ImageSize.Height * camConfig.ImageSizeRatioY);
|
|
|
|
var systemParam = aurora.SettingEntry[CommonSettingIds.SystemParameter] as SystemParameter;
|
|
var scoutField = systemParam.ScoutField;
|
|
var pixelSize = systemParam.CameraPixelSize;
|
|
var lensMagnification = systemParam.LensMagnification;
|
|
|
|
var cameraROIWidth = (float)(((_ImageSizeWidthChild * pixelSize) / lensMagnification) / 1000.0);
|
|
var cameraROIHeight = (float)(((_ImageSizeHeightChild * pixelSize) / lensMagnification) / 1000.0);
|
|
|
|
var initRowCount = (int)Math.Ceiling(scoutField.Height / cameraROIHeight);
|
|
var initColCount = (int)Math.Ceiling(scoutField.Width / cameraROIWidth);
|
|
|
|
var scoutImageSize = new ILSOSSizeF(initColCount * cameraROIWidth, initRowCount * cameraROIHeight);
|
|
|
|
//InitCount를 SystemParameter로 한번 계산해 준 후 다시 count를 계산해준다..
|
|
_RowCount = (int)Math.Ceiling(scoutImageSize.Height / cameraROIHeight);
|
|
_ColCount = (int)Math.Ceiling(scoutImageSize.Width / cameraROIWidth);
|
|
|
|
systemParam.ScoutFieldCal = scoutImageSize;
|
|
aurora.SettingEntry.Save(CommonSettingIds.SystemParameter, systemParam, nameof(FieldScanParams));
|
|
|
|
var scannerInitPosX = -1 * scoutImageSize.Width / 2 + cameraROIWidth / 2;
|
|
var scannerInitPosY = scoutImageSize.Height / 2 - cameraROIHeight / 2;
|
|
|
|
var scanPosX = scannerInitPosX;
|
|
var scanPosY = scannerInitPosY;
|
|
|
|
var oldChildBufRowCols = camConfig.ChildImage.ChildBufRowCols.ConvertAll(o => o.Clone() as ChildBufRowCol);
|
|
camConfig.ChildImage.ChildBufRowCols.Clear();
|
|
camConfig.ChildImage.RowCnt = _RowCount;
|
|
camConfig.ChildImage.ColCnt = _ColCount;
|
|
|
|
for (var row = 0; row < _RowCount; row++) {
|
|
scanPosY = scannerInitPosY - cameraROIHeight * row;
|
|
for (var col = 0; col < _ColCount; col++) {
|
|
if (row % 2 == 0) {
|
|
scanPosX = scannerInitPosX + cameraROIWidth * col;
|
|
} else {
|
|
scanPosX = scannerInitPosX + cameraROIWidth * (_ColCount - col - 1);
|
|
}
|
|
|
|
var childBufRowCol = new ChildBufRowCol();
|
|
|
|
// 1.스캐너 위치값 저장
|
|
childBufRowCol.MotorPos = new MotionPoint(scanPosX, scanPosY);
|
|
|
|
// 2.이미지 Column, Row 저장
|
|
childBufRowCol.ColIdx = (row % 2 == 0) ? col : _ColCount - col - 1;
|
|
childBufRowCol.RowIdx = row;
|
|
childBufRowCol.Rect = new Rectangle(
|
|
_ImageSizeWidthChild * childBufRowCol.ColIdx,
|
|
_ImageSizeHeightChild * childBufRowCol.RowIdx,
|
|
_ImageSizeWidthChild,
|
|
_ImageSizeHeightChild);
|
|
|
|
// 3. 기존에 저장된 MotorPosOffset 그대로 유지
|
|
var existingChildBufRowCol = oldChildBufRowCols.FirstOrDefault(o => o.RowIdx == childBufRowCol.RowIdx && o.ColIdx == childBufRowCol.ColIdx);
|
|
if (existingChildBufRowCol != null) {
|
|
childBufRowCol.MotorPosOffset = existingChildBufRowCol.MotorPosOffset.Clone() as MotionPoint;
|
|
}
|
|
|
|
camConfig.ChildImage.ChildBufRowCols.Add(childBufRowCol);
|
|
}
|
|
}
|
|
|
|
for (int i = 0; i < oldChildBufRowCols.Count; i++) {
|
|
for (int j = 0; j < camConfig.ChildImage.ChildBufRowCols.Count; j++) {
|
|
if (camConfig.ChildImage.ChildBufRowCols[j].RowIdx == oldChildBufRowCols[i].RowIdx &&
|
|
camConfig.ChildImage.ChildBufRowCols[j].ColIdx == oldChildBufRowCols[i].ColIdx) {
|
|
// 기존에 저장된 Enabled 원복
|
|
camConfig.ChildImage.ChildBufRowCols[j].Enabled = oldChildBufRowCols[i].Enabled;
|
|
// 기존에 저장된 PosIdx 원복
|
|
camConfig.ChildImage.ChildBufRowCols[j].PosIdx = oldChildBufRowCols[i].PosIdx;
|
|
}
|
|
}
|
|
}
|
|
|
|
VisionEnv.AuroraEnv.DeviceManager.SaveDeviceConfig(eCamId.CAM1.ToString());
|
|
}
|
|
|
|
public int GetimageSizeWidthChild()
|
|
{
|
|
return _ImageSizeWidthChild;
|
|
}
|
|
|
|
public int GetimageSizeHeightChild()
|
|
{
|
|
return _ImageSizeHeightChild;
|
|
}
|
|
|
|
public int GetrowCount()
|
|
{
|
|
return _RowCount;
|
|
}
|
|
|
|
public int GetcolCount()
|
|
{
|
|
return _ColCount;
|
|
}
|
|
}
|
|
|
|
//public class FieldScanParams
|
|
//{
|
|
// private static int imageSizeWidthChild;
|
|
// private static int imageSizeHeightChild;
|
|
// private static int rowCount;
|
|
// private static int colCount;
|
|
|
|
// public static void Initialize(IAuroraEnvironment aurora)
|
|
// {
|
|
// var camConfig = aurora.DeviceManager.GetDeviceConfig(eCamId.CAM1.ToString()) as CamConfig;
|
|
// var imageSize = camConfig.ImageSize;
|
|
|
|
// //FieldScanParams 클래스를 SeqScout에서 객체 생성하여 ImageSize를 쓸수 있도록 하자.. 이렇게쓰면 변경할때마다 SeqScout도 함께 바꿔줘야함
|
|
// imageSizeWidthChild = (int)(camConfig.ImageSize.Width * camConfig.ImageSizeRatioX);
|
|
// imageSizeHeightChild = (int)(camConfig.ImageSize.Height * camConfig.ImageSizeRatioY);
|
|
|
|
// var systemParam = aurora.SettingEntry[CommonSettingIds.SystemParameter] as SystemParameter;
|
|
// var scoutField = systemParam.ScoutField;
|
|
// var pixelSize = systemParam.CameraPixelSize;
|
|
// var lensMagnification = systemParam.LensMagnification;
|
|
|
|
// var cameraROIWidth = (float)(((imageSizeWidthChild * pixelSize) / lensMagnification) / 1000.0);
|
|
// var cameraROIHeight = (float)(((imageSizeHeightChild * pixelSize) / lensMagnification) / 1000.0);
|
|
|
|
// var initRowCount = (int)Math.Ceiling(scoutField.Height / cameraROIHeight);
|
|
// var initColCount = (int)Math.Ceiling(scoutField.Width / cameraROIWidth);
|
|
|
|
// var scoutImageSize = new ILSOSSizeF(initColCount * cameraROIWidth, initRowCount * cameraROIHeight);
|
|
|
|
// //InitCount를 SystemParameter로 한번 계산해 준 후 다시 count를 계산해준다..
|
|
// rowCount = (int)Math.Ceiling(scoutImageSize.Height / cameraROIHeight);
|
|
// colCount = (int)Math.Ceiling(scoutImageSize.Width / cameraROIWidth);
|
|
|
|
// systemParam.ScoutFieldCal = scoutImageSize;
|
|
// aurora.SettingEntry.Save(CommonSettingIds.SystemParameter, systemParam, nameof(FieldScanParams));
|
|
|
|
// var scannerInitPosX = -1 * scoutImageSize.Width / 2 + cameraROIWidth / 2;
|
|
// var scannerInitPosY = scoutImageSize.Height / 2 - cameraROIHeight / 2;
|
|
|
|
// var scanPosX = scannerInitPosX;
|
|
// var scanPosY = scannerInitPosY;
|
|
|
|
// var fieldScanParams = new List<FieldScanParam>();
|
|
// for (var row = 0; row < rowCount; row++) {
|
|
// scanPosY = scannerInitPosY - cameraROIHeight * row;
|
|
|
|
// for (var col = 0; col < colCount; col++) {
|
|
// if (row % 2 == 0) {
|
|
// scanPosX = scannerInitPosX + cameraROIWidth * col;
|
|
// } else {
|
|
// scanPosX = scannerInitPosX + cameraROIWidth * (colCount - col - 1);
|
|
// }
|
|
// var param = new DB.Recipe.RecipeFieldScan.FieldScanParam();
|
|
|
|
// //1.스캐너 위치값 저장
|
|
// param.ScannerPos = new PointF(scanPosX, scanPosY);
|
|
|
|
// //2.이미지 Column, Row 저장
|
|
// if (row % 2 == 0) {
|
|
// param.Column = col;
|
|
// } else {
|
|
// param.Column = colCount - col - 1;
|
|
// }
|
|
// param.Row = row;
|
|
|
|
// var location = new System.Drawing.Point(imageSizeWidthChild * param.Column, imageSizeHeightChild * param.Row);
|
|
|
|
// param.ImageRect = new Rectangle(location, new System.Drawing.Size(imageSizeWidthChild, imageSizeHeightChild));
|
|
// fieldScanParams.Add(new FieldScanParam(param));
|
|
// }
|
|
// }
|
|
|
|
// DB.Dao.FieldScanRecipe.FieldScanParams = fieldScanParams.Select(
|
|
// param => new DB.Recipe.RecipeFieldScan.FieldScanParam {
|
|
// Column = param.Column,
|
|
// Row = param.Row,
|
|
// ScannerPos = param.ScannerPos,
|
|
// EnableScan = param.EnableScan,
|
|
// ImageRect = param.ImageRect,
|
|
// OffsetPos = param.OffsetPos,
|
|
// }).ToList();
|
|
|
|
// DB.Dao.FieldScanRecipe.Save();
|
|
// }
|
|
|
|
// public int GetimageSizeWidthChild()
|
|
// {
|
|
// return imageSizeWidthChild;
|
|
// }
|
|
|
|
// public int GetimageSizeHeightChild()
|
|
// {
|
|
// return imageSizeHeightChild;
|
|
// }
|
|
|
|
// public int GetrowCount()
|
|
// {
|
|
// return rowCount;
|
|
// }
|
|
|
|
// public int GetcolCount()
|
|
// {
|
|
// return colCount;
|
|
// }
|
|
//}
|
|
}
|