반응형
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
using VoidUtility;
using System.Runtime.InteropServices;
using Markdig;
using System.IO;
using System.Text.RegularExpressions;
using MetroFramework;
using MetroFramework.Forms;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using System.Threading;
using System.ComponentModel;
using System.Globalization;
using VoidLogger;
using System.Text;
using System.Drawing.Imaging;
using System.Linq;
namespace AVIDefectImageReview
{
public partial class ReportForm : Form
{
private List<float> height_list = new List<float>();
public ReportForm()
{
InitializeComponent();
CenterToScreen();
DataTable dt = new DataTable();
dt.Columns.Add("zone", typeof(long));
dt.Columns.Add("x", typeof(float));
dt.Columns.Add("y", typeof(float));
dt.Columns.Add("ActualX", typeof(float));
dt.Columns.Add("ActualY", typeof(float));
dt.Columns.Add("id", typeof(int));
dt.Columns.Add("height", typeof(float));
string url = "C:/Users/raine/Desktop/s_Height.md";
StreamReader SR = new System.IO.StreamReader(File.Open(url,FileMode.Open));
string result = "";
result = SR.ReadToEnd();
Console.WriteLine($"result : {result}");
string hey = Markdown.ToHtml(result);
Console.WriteLine($"hey : {hey}");
Console.WriteLine($"!!!!!!!!!!!!!!!!!!!!url : {url}");
var parts = Regex.Split(hey, @"Offset=(.+?) Vartype");
foreach (var part in parts)
{
Console.WriteLine($"part : {part}");
}
Console.WriteLine(parts.Length);
byte[] rbuff = new byte[28];
using (FileStream fileStream = new FileStream("C:/Users/raine/Desktop/s_Height.dat", FileMode.Open))
{
BinaryReader br = new BinaryReader(fileStream,System.Text.Encoding.UTF8);
for(int i=0; i< br.BaseStream.Length/28; i++)
{
DataRow dr = dt.NewRow();
br.Read(rbuff, 0, rbuff.Length); //28바이트를 다 읽은거
if (BitConverter.IsLittleEndian)
{
Array.Reverse(rbuff);
}
string readvalue = BitConverter.ToString(rbuff, 0);
string readvalue_no = readvalue.Replace("-", "");
for(int j=0; j<56; j+=8)
{
int k = j / 8;
if(k == 6)
{ //zone : long
int m = Convert.ToInt32(parts[-2 * k + 13]);
int n = Convert.ToInt32(parts[-2 * k + 15]);
string value = readvalue_no.Substring(j, 2*(n-m));
uint num = uint.Parse(value, System.Globalization.NumberStyles.AllowHexSpecifier);
byte[] floatVals = BitConverter.GetBytes(num);
ulong f = BitConverter.ToUInt32(floatVals, 0);
dr[0] = f;
}
if(k==5)
{ //x : float
string value = readvalue_no.Substring(j, 8);
uint num = uint.Parse(value, System.Globalization.NumberStyles.AllowHexSpecifier);
byte[] floatVals = BitConverter.GetBytes(num);
float f = BitConverter.ToSingle(floatVals, 0);
dr[1] = f;
}
if (k == 4)
{ //Y : float
string value = readvalue_no.Substring(j, 8);
uint num = uint.Parse(value, System.Globalization.NumberStyles.AllowHexSpecifier);
byte[] floatVals = BitConverter.GetBytes(num);
float f = BitConverter.ToSingle(floatVals, 0);
dr[2] = f;
}
if (k == 3)
{ //actualX : float
string value = readvalue_no.Substring(j, 8);
uint num = uint.Parse(value, System.Globalization.NumberStyles.AllowHexSpecifier);
byte[] floatVals = BitConverter.GetBytes(num);
float f = BitConverter.ToSingle(floatVals, 0);
dr[3] = f;
}
if (k == 2)
{ //actual Y : float
string value = readvalue_no.Substring(j, 8);
uint num = uint.Parse(value, System.Globalization.NumberStyles.AllowHexSpecifier);
byte[] floatVals = BitConverter.GetBytes(num);
float f = BitConverter.ToSingle(floatVals, 0);
dr[4] = f;
}
if (k == 1)
{
//id : int
string value = readvalue_no.Substring(j, 8);
uint num = uint.Parse(value, System.Globalization.NumberStyles.AllowHexSpecifier);
byte[] floatVals = BitConverter.GetBytes(num);
int f = BitConverter.ToInt32(floatVals, 0);
dr[5] = f;
}
if (k == 0)
{
//height : float
string value = readvalue_no.Substring(j, 8);
uint num = uint.Parse(value, System.Globalization.NumberStyles.AllowHexSpecifier);
byte[] floatVals = BitConverter.GetBytes(num);
float f = BitConverter.ToSingle(floatVals, 0);
dr[6] = f;
height_list.Add(f);
}
}
dt.Rows.Add(dr);
}
metroGridWaferReview.DataSource = dt;
metroGridWaferReview.Columns[0].HeaderText = "Zone";
metroGridWaferReview.Columns[1].HeaderText = "X";
metroGridWaferReview.Columns[2].HeaderText = "Y";
metroGridWaferReview.Columns[3].HeaderText = "ActualX";
metroGridWaferReview.Columns[4].HeaderText = "ActualY";
metroGridWaferReview.Columns[5].HeaderText = "id";
metroGridWaferReview.Columns[6].HeaderText = "height";
metroGridWaferReview.Focus();
br.Close();
Console.WriteLine($"height list count : {height_list.Count()}");
var results = height_list.Distinct();
Console.WriteLine($"distinct list count : {results.Count()}");
}
//br.Close();
}
}
}
반응형
'Language > C#' 카테고리의 다른 글
C# (0) | 2022.05.09 |
---|---|
C# 정규표현식 (0) | 2022.04.29 |
.dat file .md file 불러오고 읽기 (0) | 2022.04.28 |
[Magick package] 이미지 명도 채도 조정 (0) | 2022.04.25 |
GridView Image Column 추가 (0) | 2022.04.22 |