145 lines
4.3 KiB
C#
145 lines
4.3 KiB
C#
using Aurora.Api;
|
|
using MilCommon;
|
|
using VisionCommon;
|
|
using Hermes;
|
|
using Matrox.MatroxImagingLibrary;
|
|
using System;
|
|
using System.IO;
|
|
using System.Drawing;
|
|
using VisionCommonUI;
|
|
|
|
namespace MilPattern {
|
|
public class Brightness : PatternBase, IPatternFinder, IDisposable {
|
|
public string FILE_EXT_PATTERN { get; set; } // 불필요
|
|
private BrightnessParamExt _paramExt = null;
|
|
|
|
private Logger _logger;
|
|
private PatternInfo _patternInfo;
|
|
|
|
public Brightness(PatternInfo patternInfo) {
|
|
_patternInfo = patternInfo;
|
|
_logger = new Logger(
|
|
$"Brightness_{patternInfo.GetPatternIndex()}");
|
|
InitContext();
|
|
}
|
|
|
|
private void InitContext() {
|
|
if (E1.OK != Load()) {
|
|
Create();
|
|
}
|
|
}
|
|
|
|
public string GetPatternFilePath(string patternName = PatternConstants.FILE_NAME_PATTERN) {
|
|
return Path.Combine(new string[] {
|
|
PatternConstants.GetSubPatternDirPath(_patternInfo),
|
|
patternName + FILE_EXT_PATTERN
|
|
});
|
|
}
|
|
|
|
public int Load() {
|
|
var patternFilePath = GetPatternFilePath();
|
|
|
|
if (!File.Exists(patternFilePath)) {
|
|
_logger.I($"Pattern File does NOT exist : {patternFilePath}");
|
|
return E2.NOT_FOUND;
|
|
}
|
|
|
|
_paramExt = LoadParamExt();
|
|
|
|
return E1.OK;
|
|
}
|
|
|
|
public int Save() {
|
|
var patternFilePath = GetPatternFilePath();
|
|
var patternDirPath = Path.GetDirectoryName(patternFilePath);
|
|
if (!Directory.Exists(patternDirPath)) {
|
|
Directory.CreateDirectory(patternDirPath);
|
|
}
|
|
|
|
return SaveParamExt(_paramExt);
|
|
}
|
|
|
|
public int Create() {
|
|
_paramExt = LoadParamExt();
|
|
return E1.OK;
|
|
}
|
|
|
|
public int Remove() {
|
|
var patternFilePath = GetPatternFilePath();
|
|
var patternDirPath = Path.GetDirectoryName(patternFilePath);
|
|
if (Directory.Exists(patternDirPath)) {
|
|
Directory.Delete(patternDirPath, recursive: true);
|
|
}
|
|
|
|
return E1.OK;
|
|
}
|
|
|
|
public ROI GetFindROI() {
|
|
return _paramExt.FindROI.Clone() as ROI;
|
|
}
|
|
|
|
public int SetFindROI(ROI findRoi) {
|
|
if (ROI.IsNullOrEmpty(findRoi)) {
|
|
return E1.GENERIC;
|
|
}
|
|
|
|
_paramExt.FindROI = findRoi.Clone() as ROI;
|
|
|
|
return E1.OK;
|
|
}
|
|
|
|
public IRunParam GetRunParam() {
|
|
return new BrightnessRunParam() {
|
|
BrightnessParamExt = _paramExt.Clone() as BrightnessParamExt
|
|
};
|
|
}
|
|
|
|
public int SetRunParam(IRunParam runParam) {
|
|
_paramExt = ((BrightnessRunParam)runParam).BrightnessParamExt.Clone() as BrightnessParamExt;
|
|
return E1.OK;
|
|
}
|
|
|
|
public PatternResult Find(object image) {
|
|
return MilBrightness.Find((MIL_ID)image, _paramExt.FindROI.Clone() as ROI, _paramExt);
|
|
}
|
|
|
|
public PatternResult Find(object image, ROI findRoi) {
|
|
return MilBrightness.Find((MIL_ID)image, findRoi, _paramExt);
|
|
}
|
|
|
|
public PatternResult GetNotFoundPatternResult() {
|
|
return MilBrightness.GetNotFoundPatternResult();
|
|
}
|
|
|
|
public object GetTool() {
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public void Draw(
|
|
PatternResult patternResult, ICameraDisplay cameraDisplay, bool isFixturePattern = false) {
|
|
MilBrightness.Draw(patternResult, cameraDisplay as IMilCameraDisplay);
|
|
}
|
|
|
|
public Bitmap GetThumbnail() {
|
|
return ThumbnailImage.Brightness();
|
|
}
|
|
|
|
#region IDisposible
|
|
public void Dispose() {
|
|
}
|
|
#endregion
|
|
|
|
#region Brightness Specific
|
|
internal BrightnessParamExt LoadParamExt() {
|
|
return BrightnessParamExt.Load(PatternConstants.GetSubPatternDirPath(_patternInfo));
|
|
}
|
|
|
|
internal int SaveParamExt(BrightnessParamExt brightnessParamExt) {
|
|
return BrightnessParamExt.Save(
|
|
PatternConstants.GetSubPatternDirPath(_patternInfo),
|
|
brightnessParamExt);
|
|
}
|
|
#endregion
|
|
}
|
|
}
|