diff --git a/App.config b/App.config index 9b8ca7a..a1a4016 100644 --- a/App.config +++ b/App.config @@ -49,6 +49,15 @@ 0 + + Silver + + + Blue + + + Purple + diff --git a/DataProcessing.cs b/DataProcessing.cs index 4b0a969..11db13d 100644 --- a/DataProcessing.cs +++ b/DataProcessing.cs @@ -10,9 +10,10 @@ using System.IO; using System.Runtime.InteropServices; using System.Windows.Forms; -using System.Xml.Serialization; +using AForge.Imaging; using BinarizationThinning; using ToolsGenGkode.pages; +using ToolsGenGkode.Properties; namespace ToolsGenGkode { @@ -23,7 +24,7 @@ static class ImageProcessing { /// - /// Создание рисунка из текста + /// Создание 8-битного рисунка из текста /// /// Текст /// Имя шрифта @@ -34,6 +35,8 @@ public static Bitmap CreateBitmapFromText(string text, string fontName, float fo { if (text.Trim().Length == 0) text = " "; + // по умолчанию рисунок 1х1 пиксель, и 24 бита на пиксель, т.к. сразу 8 бит использовать не получится, + // т.к. стандартные функции не работают... Bitmap bitmap = new Bitmap(1, 1, PixelFormat.Format24bppRgb); int width = 0; @@ -84,8 +87,8 @@ public static Bitmap CreateBitmapFromText(string text, string fontName, float fo graphics.Flush(); font.Dispose(); - - return (bitmap); + + return CheckAndConvertImageto24bitPerPixel(bitmap); } /// @@ -99,9 +102,9 @@ public static Bitmap GetBlackWhileImage(Bitmap sourceImage, int koeff, bool reve { - Bitmap tempImage = sourceImage; + Bitmap tempImage = CheckAndConvertImageto24bitPerPixel(sourceImage); - BitmapData bmd = tempImage.LockBits(new Rectangle(0, 0, sourceImage.Width, sourceImage.Height), ImageLockMode.ReadWrite, sourceImage.PixelFormat); + BitmapData bmd = tempImage.LockBits(new Rectangle(0, 0, tempImage.Width, tempImage.Height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb); // Получаем адрес первой линии. IntPtr ptr = bmd.Scan0; @@ -210,9 +213,6 @@ public static Bitmap GetBlackWhileImage(Bitmap sourceImage, int koeff, bool reve return tempImage; } - - - private static Color GetPosColor(ref Bitmap bmp, int x, int y) { Color cReturn = Color.FromArgb(255, 255, 255, 255); @@ -228,13 +228,11 @@ private static Color GetPosColor(ref Bitmap bmp, int x, int y) return bmp.GetPixel(x, y); } - - // удаление закрашенных областей public static Bitmap BitmapDeleteContent(Bitmap tmpBmp) { - Bitmap bbb = tmpBmp.Clone(new Rectangle(0, 0, tmpBmp.Width, tmpBmp.Height), PixelFormat.Format24bppRgb); ; + Bitmap bbb = tmpBmp.Clone(new Rectangle(0, 0, tmpBmp.Width, tmpBmp.Height), PixelFormat.Format24bppRgb); @@ -269,8 +267,6 @@ public static Bitmap BitmapDeleteContent(Bitmap tmpBmp) return bbb; } - - public static Bitmap Skeletonization(Bitmap bmpSource) { @@ -280,13 +276,227 @@ public static Bitmap Skeletonization(Bitmap bmpSource) Byte[,] m_DesImage = Thining.ThinPicture(m_SourceImage); - return Thining.BinaryArrayToBinaryBitmap(m_DesImage); + return CheckAndConvertImageto24bitPerPixel(Thining.BinaryArrayToBinaryBitmap(m_DesImage)); } + /// + /// Resizes an image to a certain height + /// + /// Image to resize + /// New width for the final image + /// New height for the final image + /// Quality of the resizing + /// A bitmap object of the resized image + public static Bitmap ResizeImage(Bitmap Image, int Width, int Height, bool Quality = false) + { + Bitmap NewBitmap = new Bitmap(Width, Height,PixelFormat.Format24bppRgb); + using (Graphics NewGraphics = Graphics.FromImage(NewBitmap)) + { + if (Quality) + { + NewGraphics.CompositingQuality = CompositingQuality.HighQuality; + NewGraphics.SmoothingMode = SmoothingMode.HighQuality; + NewGraphics.InterpolationMode = InterpolationMode.HighQualityBicubic; + } + else + { + NewGraphics.CompositingQuality = CompositingQuality.HighSpeed; + NewGraphics.SmoothingMode = SmoothingMode.HighSpeed; + NewGraphics.InterpolationMode = InterpolationMode.NearestNeighbor; + } + NewGraphics.DrawImage(Image, new System.Drawing.Rectangle(0, 0, Width, Height)); + } + return CheckAndConvertImageto24bitPerPixel(NewBitmap); + } + public static Bitmap ConvertToGrayScale(Bitmap Image) + { + if (Image.PixelFormat != PixelFormat.Format24bppRgb) + { + throw new UnsupportedImageFormatException("Оппа! Не поддерживаемый формат изображения!!! (001)"); + } + Bitmap returnMap = new Bitmap(Image.Width, Image.Height, PixelFormat.Format24bppRgb); + BitmapData bitmapData1 = Image.LockBits(new Rectangle(0, 0, Image.Width, Image.Height), ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb); + BitmapData bitmapData2 = returnMap.LockBits(new Rectangle(0, 0, returnMap.Width, returnMap.Height), ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb); + int a = 0; + unsafe + { + byte* imagePointer1 = (byte*)bitmapData1.Scan0; + byte* imagePointer2 = (byte*)bitmapData2.Scan0; + for (int i = 0; i < bitmapData1.Height; i++) + { + for (int j = 0; j < bitmapData1.Width; j++) + { + // write the logic implementation here + a = (imagePointer1[0] + imagePointer1[1] + imagePointer1[2]) / 3; + imagePointer2[0] = (byte)a; + imagePointer2[1] = (byte)a; + imagePointer2[2] = (byte)a; + + imagePointer1 += 3; + imagePointer2 += 3; + }//end for j + imagePointer1 += bitmapData1.Stride - (bitmapData1.Width * 3); + imagePointer2 += bitmapData1.Stride - (bitmapData1.Width * 3); + }//end for i + }//end unsafe + returnMap.UnlockBits(bitmapData2); + Image.UnlockBits(bitmapData1); + return returnMap; + } + + + + + + public static Bitmap CheckAndConvertImageto24bitPerPixel(Bitmap sourceBMP) + { + // Работать будем с 24-битным изображением + if (sourceBMP.PixelFormat == PixelFormat.Format24bppRgb) return sourceBMP; + + // Необходимо сконвертировать в необходимый формат + Bitmap returnMap = new Bitmap(sourceBMP.Width, sourceBMP.Height, PixelFormat.Format24bppRgb); + + int bytePerPixel = 0; + + if (sourceBMP.PixelFormat == PixelFormat.Format32bppArgb) bytePerPixel = 4; + + if (sourceBMP.PixelFormat == PixelFormat.Format8bppIndexed) bytePerPixel = 1; + + //todo: add exceptions + if (bytePerPixel == 0) + { + throw new UnsupportedImageFormatException("Не поддерживаемый формат изображения!!!."); + return null; + } + + // исходное изображение + BitmapData bitmapData1 = sourceBMP.LockBits(new Rectangle(0, 0, sourceBMP.Width, sourceBMP.Height), ImageLockMode.ReadOnly, sourceBMP.PixelFormat); + // итоговое изображение + BitmapData bitmapData2 = returnMap.LockBits(new Rectangle(0, 0, returnMap.Width, returnMap.Height), ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb); + + //int a = 0; + + unsafe + { + // ссылка на область памяти + byte* imagePointer1 = (byte*)bitmapData1.Scan0; + // ссылка на область памяти + byte* imagePointer2 = (byte*)bitmapData2.Scan0; + for (int i = 0; i < bitmapData1.Height; i++) + { + for (int j = 0; j < bitmapData1.Width; j++) + { + if (bytePerPixel == 1) + { + imagePointer2[0] = imagePointer1[0]; + imagePointer2[1] = imagePointer1[0]; + imagePointer2[2] = imagePointer1[0]; + //imagePointer2[3] = imagePointer1[3]; //для 32-х битного + imagePointer1 += 1; + imagePointer2 += 3; + } + + if (bytePerPixel == 4) + { + imagePointer2[0] = imagePointer1[0]; + imagePointer2[1] = imagePointer1[1]; + imagePointer2[2] = imagePointer1[2]; + //imagePointer2[3] = imagePointer1[3]; //для 32-х битного + imagePointer1 += 4; + imagePointer2 += 3; + + } + }//end for j + + if (bytePerPixel == 1) + { + imagePointer1 += bitmapData1.Stride - (bitmapData1.Width * 1); + imagePointer2 += bitmapData2.Stride - (bitmapData1.Width * 3); + } + + if (bytePerPixel == 4) + { + imagePointer1 += bitmapData1.Stride - (bitmapData1.Width * 4); + imagePointer2 += bitmapData2.Stride - (bitmapData1.Width * 3); + } + }//end for i + }//end unsafe + returnMap.UnlockBits(bitmapData2); + sourceBMP.UnlockBits(bitmapData1); + return returnMap; + } + + + public static Bitmap ConvertTo8Bit(Bitmap sourceBMP) + { + // нет смысла конвертировать + if (sourceBMP.PixelFormat == PixelFormat.Format8bppIndexed) return sourceBMP; + + // Необходимо сконвертировать в необходимый формат + Bitmap returnMap = new Bitmap(sourceBMP.Width, sourceBMP.Height, PixelFormat.Format8bppIndexed); + + //todo: add exceptions + if (!(sourceBMP.PixelFormat == PixelFormat.Format24bppRgb || sourceBMP.PixelFormat == PixelFormat.Format32bppRgb || sourceBMP.PixelFormat == PixelFormat.Format32bppArgb)) + { + throw new UnsupportedImageFormatException("На текущий момент изображение имеющее pixelFormat: " + sourceBMP.PixelFormat.ToString() + @" не поддерживатется!"); + return null; + } + + // исходное изображение + BitmapData bitmapData1 = sourceBMP.LockBits(new Rectangle(0, 0, sourceBMP.Width, sourceBMP.Height), ImageLockMode.ReadOnly, sourceBMP.PixelFormat); + // итоговое изображение + BitmapData bitmapData2 = returnMap.LockBits(new Rectangle(0, 0, returnMap.Width, returnMap.Height), ImageLockMode.ReadOnly, PixelFormat.Format8bppIndexed); + + unsafe + { + // ссылка на область памяти + byte* imagePointer1 = (byte*)bitmapData1.Scan0; + // ссылка на область памяти + byte* imagePointer2 = (byte*)bitmapData2.Scan0; + + for (int i = 0; i < bitmapData1.Height; i++) + { + for (int j = 0; j < bitmapData1.Width; j++) + { + + if (sourceBMP.PixelFormat == PixelFormat.Format24bppRgb) + { + imagePointer2[0] = (byte)((imagePointer1[0] + imagePointer1[1] + imagePointer1[2]) / 3); + imagePointer1 += 3; + } + + if (sourceBMP.PixelFormat == PixelFormat.Format32bppRgb) + { + imagePointer2[0] = (byte)((imagePointer1[0] + imagePointer1[1] + imagePointer1[2]) / 3); + imagePointer1 += 4; + } + + if (sourceBMP.PixelFormat == PixelFormat.Format32bppArgb) + { + imagePointer2[0] = (byte)((imagePointer1[0] + imagePointer1[1] + imagePointer1[2]) / 3); + imagePointer1 += 4; + } + + imagePointer2 += 1; + + }//end for j + + if (sourceBMP.PixelFormat == PixelFormat.Format24bppRgb) imagePointer1 += bitmapData1.Stride - (bitmapData1.Width * 3); + if (sourceBMP.PixelFormat == PixelFormat.Format32bppRgb) imagePointer1 += bitmapData1.Stride - (bitmapData1.Width * 4); + if (sourceBMP.PixelFormat == PixelFormat.Format32bppArgb) imagePointer1 += bitmapData1.Stride - (bitmapData1.Width * 4); + + imagePointer2 += bitmapData2.Stride - (bitmapData1.Width * 1); + + }//end for i + }//end unsafe + returnMap.UnlockBits(bitmapData2); + sourceBMP.UnlockBits(bitmapData1); + return returnMap; + } } @@ -355,7 +565,8 @@ public static List GetVectorFromText(string text, string fontName, f ss += "\n" + (StringFormat.GenericDefault).ToString(); MessageBox.Show(ss); - throw; + //throw; + return new List(); } } @@ -414,7 +625,7 @@ public static List GetVectorFromText(string text, string fontName, f } - Lines = VectorProcessing.Rotate(Lines); + Lines = Rotate(Lines); //// получим границы изображения //decimal minX = 99999; @@ -652,7 +863,7 @@ public static List Rotate(List dataCVectors) - if (Properties.Settings.Default.page01AxisVariant == 1) + if (Settings.Default.page01AxisVariant == 1) { //реверс по оси Y @@ -685,7 +896,7 @@ public static List Rotate(List dataCVectors) } - if (Properties.Settings.Default.page01AxisVariant == 2) + if (Settings.Default.page01AxisVariant == 2) { //ничего не делаем foreach (GroupPoint VARIABLE in dataCVectors) @@ -695,7 +906,7 @@ public static List Rotate(List dataCVectors) } - if (Properties.Settings.Default.page01AxisVariant == 3) + if (Settings.Default.page01AxisVariant == 3) { //реверс по оси X @@ -727,7 +938,7 @@ public static List Rotate(List dataCVectors) } - if (Properties.Settings.Default.page01AxisVariant == 4) + if (Settings.Default.page01AxisVariant == 4) { //реверс по обоим осям @@ -785,7 +996,7 @@ public static List Rotate(List dataCPoints) - if (Properties.Settings.Default.page01AxisVariant == 1) + if (Settings.Default.page01AxisVariant == 1) { //реверс по оси Y //вычислим дельту, для смещения векторов @@ -803,12 +1014,12 @@ public static List Rotate(List dataCPoints) } - if (Properties.Settings.Default.page01AxisVariant == 2) + if (Settings.Default.page01AxisVariant == 2) { //ничего не делаем } - if (Properties.Settings.Default.page01AxisVariant == 3) + if (Settings.Default.page01AxisVariant == 3) { //реверс по оси X @@ -829,7 +1040,7 @@ public static List Rotate(List dataCPoints) } - if (Properties.Settings.Default.page01AxisVariant == 4) + if (Settings.Default.page01AxisVariant == 4) { //реверс по обоим осям //вычислим дельту, для смещения векторов @@ -1153,7 +1364,7 @@ public static List GetVectorFromImage(Bitmap _image) - Vectors = VectorProcessing.Rotate(Vectors); + Vectors = Rotate(Vectors); diff --git a/Preview_Image.cs b/Preview_Image.cs index 8fa4a63..e8d2bc5 100644 --- a/Preview_Image.cs +++ b/Preview_Image.cs @@ -271,7 +271,8 @@ public void SetImage(Bitmap bmp) return; } - pictureBoxPreview.Image = DrawAxes(bmp); + //pictureBoxPreview.Image = DrawAxes(bmp); + pictureBoxPreview.Image = bmp; containsData = true; } } diff --git a/Preview_Vectors.Designer.cs b/Preview_Vectors.Designer.cs index a703810..fb7e185 100644 --- a/Preview_Vectors.Designer.cs +++ b/Preview_Vectors.Designer.cs @@ -34,6 +34,7 @@ private void InitializeComponent() this.label4 = new System.Windows.Forms.Label(); this.label3 = new System.Windows.Forms.Label(); this.numericUpDown1 = new System.Windows.Forms.NumericUpDown(); + this.btSetting = new System.Windows.Forms.Button(); ((System.ComponentModel.ISupportInitialize)(this.openGLControl1)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDown2)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).BeginInit(); @@ -43,7 +44,7 @@ private void InitializeComponent() // this.button3DDefault.Location = new System.Drawing.Point(350, 2); this.button3DDefault.Name = "button3DDefault"; - this.button3DDefault.Size = new System.Drawing.Size(107, 24); + this.button3DDefault.Size = new System.Drawing.Size(107, 25); this.button3DDefault.TabIndex = 35; this.button3DDefault.Tag = "_resetPos_"; this.button3DDefault.Text = "Сброс положения"; @@ -56,12 +57,12 @@ private void InitializeComponent() | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.openGLControl1.DrawFPS = true; - this.openGLControl1.Location = new System.Drawing.Point(6, 29); + this.openGLControl1.Location = new System.Drawing.Point(6, 32); this.openGLControl1.Name = "openGLControl1"; this.openGLControl1.OpenGLVersion = SharpGL.Version.OpenGLVersion.OpenGL2_1; this.openGLControl1.RenderContextType = SharpGL.RenderContextType.DIBSection; this.openGLControl1.RenderTrigger = SharpGL.RenderTrigger.Manual; - this.openGLControl1.Size = new System.Drawing.Size(449, 171); + this.openGLControl1.Size = new System.Drawing.Size(497, 168); this.openGLControl1.TabIndex = 30; this.openGLControl1.OpenGLInitialized += new System.EventHandler(this.openGLControl1_OpenGLInitialized); this.openGLControl1.OpenGLDraw += new SharpGL.RenderEventHandler(this.openGLControl1_OpenGLDraw); @@ -139,11 +140,22 @@ private void InitializeComponent() 0}); this.numericUpDown1.ValueChanged += new System.EventHandler(this.numericUpDown1_ValueChanged); // + // btSetting + // + this.btSetting.Image = global::ToolsGenGkode.Properties.Resources.color_swatch; + this.btSetting.Location = new System.Drawing.Point(461, 3); + this.btSetting.Name = "btSetting"; + this.btSetting.Size = new System.Drawing.Size(41, 24); + this.btSetting.TabIndex = 36; + this.btSetting.UseVisualStyleBackColor = true; + this.btSetting.Click += new System.EventHandler(this.btSetting_Click); + // // Preview_Vectors // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.Controls.Add(this.btSetting); this.Controls.Add(this.button3DDefault); this.Controls.Add(this.openGLControl1); this.Controls.Add(this.numericUpDown2); @@ -151,7 +163,7 @@ private void InitializeComponent() this.Controls.Add(this.label3); this.Controls.Add(this.numericUpDown1); this.Name = "Preview_Vectors"; - this.Size = new System.Drawing.Size(461, 206); + this.Size = new System.Drawing.Size(509, 206); this.Load += new System.EventHandler(this.Preview_Vectors_Load); ((System.ComponentModel.ISupportInitialize)(this.openGLControl1)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDown2)).EndInit(); @@ -164,10 +176,11 @@ private void InitializeComponent() #endregion private System.Windows.Forms.Button button3DDefault; - private SharpGL.OpenGLControl openGLControl1; private System.Windows.Forms.NumericUpDown numericUpDown2; private System.Windows.Forms.Label label4; private System.Windows.Forms.Label label3; private System.Windows.Forms.NumericUpDown numericUpDown1; + private System.Windows.Forms.Button btSetting; + public SharpGL.OpenGLControl openGLControl1; } } diff --git a/Preview_Vectors.cs b/Preview_Vectors.cs index 40dc480..a328d32 100644 --- a/Preview_Vectors.cs +++ b/Preview_Vectors.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; +using System.Drawing; using System.Windows.Forms; using SharpGL; using SharpGL.Enumerations; @@ -15,6 +16,10 @@ public partial class Preview_Vectors : UserControl { public bool containsData; + public FColor Color_3DBack; + public FColor Color_3DContur; + public FColor Color_Grid; + List DrawVectors = new List(); public void SetNewData(List _DrawVectors) @@ -40,6 +45,25 @@ public void SetNewData(List _DrawPoints) public Preview_Vectors() { InitializeComponent(); + + try + { + Color_3DBack = new FColor(Properties.Settings.Default.ColorBack); + Color_3DContur = new FColor(Properties.Settings.Default.ColorTraectory); + Color_Grid = new FColor(Properties.Settings.Default.ColorGrid); + } + catch (Exception) + { + + Color_3DBack = new FColor(120, 120, 120); + Color_3DContur = new FColor(0, 255, 0); + Color_Grid = new FColor(100, 0, 204); + } + // + // + // + + } private void openGLControl1_OpenGLDraw(object sender, RenderEventArgs args) @@ -74,8 +98,14 @@ private void openGLControl1_OpenGLDraw(object sender, RenderEventArgs args) OpenGL gl = openGLControl1.OpenGL; + + + gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT); // очистка буфера цвета и буфера глубины - gl.ClearColor(0.5f, 0.5f, 0.5f, 1); + + + //gl.ClearColor(0.5f, 0.5f, 0.5f, 1); + gl.ClearColor(Color_3DBack.R, Color_3DBack.G, Color_3DBack.B, 1); //gl.ClearColor(0.7f, 0.7f, 0.7f, 1); gl.LoadIdentity(); // очищение текущей матрицы @@ -190,7 +220,11 @@ private void openGLControl1_OpenGLDraw(object sender, RenderEventArgs args) if (DrawVectors.Count > 0) { gl.LineWidth(0.1f); - gl.Color(CalcColor(100), 0F, CalcColor(204)); //(1.0f/255)*color + + + + gl.Color(Color_Grid.R, Color_Grid.G, Color_Grid.B); //(1.0f/255)*color + //gl.Color(CalcColor(100), 0F, CalcColor(204)); //(1.0f/255)*color gl.Begin(OpenGL.GL_LINES); int gridStep = (int)numericUpDown2.Value; @@ -247,7 +281,9 @@ private void openGLControl1_OpenGLDraw(object sender, RenderEventArgs args) gl.LineWidth(sizeVec); gl.Begin(OpenGL.GL_LINE_STRIP); - gl.Color(0f, 1.0f, 0); + + gl.Color(Color_3DContur.R, Color_3DContur.G, Color_3DContur.B); + //gl.Color(0f, 1.0f, 0); foreach (cncPoint point in Vector.Points) { @@ -374,6 +410,9 @@ private void openGLControl1_OpenGLInitialized(object sender, EventArgs e) + + + //// инициализация OpenGL //// инициализация бибилиотеки glut //Glut.glutInit(); @@ -445,7 +484,7 @@ private void openGLControl1_KeyDown(object sender, KeyEventArgs e) private void openGLControl1_KeyUp(object sender, KeyEventArgs e) { - Setting.keyShift = e.Shift; + Setting.keyShift = false; openGLControl1.Refresh(); @@ -608,5 +647,74 @@ private void numericUpDown1_ValueChanged(object sender, EventArgs e) { openGLControl1.Refresh(); } + + private void btSetting_Click(object sender, EventArgs e) + { + SelectColor3D colorFRM = new SelectColor3D(this); + DialogResult dlres = colorFRM.ShowDialog(); + + if (dlres == DialogResult.OK) + { + Properties.Settings.Default.ColorBack = Color.FromArgb(Color_3DBack.iR, Color_3DBack.iG, Color_3DBack.iB); + Properties.Settings.Default.ColorTraectory = Color.FromArgb(Color_3DContur.iR, Color_3DContur.iG, Color_3DContur.iB); + Properties.Settings.Default.ColorGrid = Color.FromArgb(Color_Grid.iR, Color_Grid.iG, Color_Grid.iB); + Properties.Settings.Default.Save(); + } + else + { + Color_3DBack = new FColor(Properties.Settings.Default.ColorBack); + Color_3DContur = new FColor(Properties.Settings.Default.ColorTraectory); + Color_Grid = new FColor(Properties.Settings.Default.ColorGrid); + } + openGLControl1.Refresh(); + openGLControl1.Refresh(); + } } + + public class FColor + { + public float R, G, B; + + public int iR, iG, iB; + + + public FColor() + { + R = 1.0F; + G = 1.0F; + B = 1.0F; + + iR = 255; + iG = 255; + iB = 255; + + } + + public FColor(int _R, int _G, int _B) + { + iR = _R; + iG = _G; + iB = _B; + + + R = (1.0f / 255) * _R; + G = (1.0f / 255) * _G; + B = (1.0f / 255) * _B; + } + + public FColor(Color _clr) + { + iR = _clr.R; + iG = _clr.G; + iB = _clr.B; + + + R = (1.0f / 255) * _clr.R; + G = (1.0f / 255) * _clr.G; + B = (1.0f / 255) * _clr.B; + } + + + } + } diff --git a/Program.cs b/Program.cs index be5b444..f993276 100644 --- a/Program.cs +++ b/Program.cs @@ -4,7 +4,7 @@ using System.Windows.Forms; using ToolsGenGkode; -namespace WindowsFormsApplication1 +namespace ToolsGeneratorGCode { static class Program { diff --git a/Properties/AssemblyInfo.cs b/Properties/AssemblyInfo.cs index c0ecb6d..1af13a2 100644 --- a/Properties/AssemblyInfo.cs +++ b/Properties/AssemblyInfo.cs @@ -34,5 +34,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("2.0.0.30")] -[assembly: AssemblyFileVersion("2.0.0.30")] +[assembly: AssemblyVersion("2.0.0.36")] +[assembly: AssemblyFileVersion("2.0.0.36")] diff --git a/Properties/Resources.Designer.cs b/Properties/Resources.Designer.cs index 7c8435a..525863b 100644 --- a/Properties/Resources.Designer.cs +++ b/Properties/Resources.Designer.cs @@ -230,6 +230,16 @@ internal static System.Drawing.Bitmap cancel { } } + /// + /// Поиск локализованного ресурса типа System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap color_swatch { + get { + object obj = ResourceManager.GetObject("color_swatch", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + /// /// Поиск локализованного ресурса типа System.Drawing.Bitmap. /// diff --git a/Properties/Resources.resx b/Properties/Resources.resx index 1ef664c..868674f 100644 --- a/Properties/Resources.resx +++ b/Properties/Resources.resx @@ -211,4 +211,7 @@ ..\Resources\layout_edit.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + ..\Resources\color_swatch.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + \ No newline at end of file diff --git a/Properties/Settings.Designer.cs b/Properties/Settings.Designer.cs index b1a544b..17c6ff2 100644 --- a/Properties/Settings.Designer.cs +++ b/Properties/Settings.Designer.cs @@ -178,5 +178,41 @@ public decimal Setting { this["Setting"] = value; } } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("Silver")] + public global::System.Drawing.Color ColorBack { + get { + return ((global::System.Drawing.Color)(this["ColorBack"])); + } + set { + this["ColorBack"] = value; + } + } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("Blue")] + public global::System.Drawing.Color ColorTraectory { + get { + return ((global::System.Drawing.Color)(this["ColorTraectory"])); + } + set { + this["ColorTraectory"] = value; + } + } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("Purple")] + public global::System.Drawing.Color ColorGrid { + get { + return ((global::System.Drawing.Color)(this["ColorGrid"])); + } + set { + this["ColorGrid"] = value; + } + } } } diff --git a/Properties/Settings.settings b/Properties/Settings.settings index 7dacf61..e61a7f3 100644 --- a/Properties/Settings.settings +++ b/Properties/Settings.settings @@ -41,5 +41,14 @@ 0 + + Silver + + + Blue + + + Purple + \ No newline at end of file diff --git a/Resources/color_swatch.png b/Resources/color_swatch.png new file mode 100644 index 0000000..4d42bec Binary files /dev/null and b/Resources/color_swatch.png differ diff --git a/SelectColor3D.Designer.cs b/SelectColor3D.Designer.cs new file mode 100644 index 0000000..4adc895 --- /dev/null +++ b/SelectColor3D.Designer.cs @@ -0,0 +1,129 @@ +namespace ToolsGenGkode +{ + partial class SelectColor3D + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.colorDialog1 = new System.Windows.Forms.ColorDialog(); + this.button1 = new System.Windows.Forms.Button(); + this.btBackColor = new System.Windows.Forms.Button(); + this.button2 = new System.Windows.Forms.Button(); + this.button3 = new System.Windows.Forms.Button(); + this.button4 = new System.Windows.Forms.Button(); + this.button5 = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // button1 + // + this.button1.Location = new System.Drawing.Point(12, 12); + this.button1.Name = "button1"; + this.button1.Size = new System.Drawing.Size(302, 37); + this.button1.TabIndex = 0; + this.button1.Text = "По умолчанию"; + this.button1.UseVisualStyleBackColor = true; + this.button1.Click += new System.EventHandler(this.button1_Click); + // + // btBackColor + // + this.btBackColor.Location = new System.Drawing.Point(12, 55); + this.btBackColor.Name = "btBackColor"; + this.btBackColor.Size = new System.Drawing.Size(301, 40); + this.btBackColor.TabIndex = 1; + this.btBackColor.Text = "Цвет фона"; + this.btBackColor.UseVisualStyleBackColor = true; + this.btBackColor.Click += new System.EventHandler(this.button2_Click); + // + // button2 + // + this.button2.Location = new System.Drawing.Point(14, 101); + this.button2.Name = "button2"; + this.button2.Size = new System.Drawing.Size(298, 36); + this.button2.TabIndex = 2; + this.button2.Text = "Цвет траектории"; + this.button2.UseVisualStyleBackColor = true; + this.button2.Click += new System.EventHandler(this.button2_Click_1); + // + // button3 + // + this.button3.Location = new System.Drawing.Point(14, 145); + this.button3.Name = "button3"; + this.button3.Size = new System.Drawing.Size(298, 36); + this.button3.TabIndex = 3; + this.button3.Text = "Цвет сетки"; + this.button3.UseVisualStyleBackColor = true; + this.button3.Click += new System.EventHandler(this.button3_Click); + // + // button4 + // + this.button4.DialogResult = System.Windows.Forms.DialogResult.OK; + this.button4.Location = new System.Drawing.Point(14, 216); + this.button4.Name = "button4"; + this.button4.Size = new System.Drawing.Size(114, 40); + this.button4.TabIndex = 4; + this.button4.Text = "Применить"; + this.button4.UseVisualStyleBackColor = true; + // + // button5 + // + this.button5.DialogResult = System.Windows.Forms.DialogResult.Cancel; + this.button5.Location = new System.Drawing.Point(187, 216); + this.button5.Name = "button5"; + this.button5.Size = new System.Drawing.Size(124, 41); + this.button5.TabIndex = 5; + this.button5.Text = "Отмена"; + this.button5.UseVisualStyleBackColor = true; + // + // SelectColor3D + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(326, 268); + this.Controls.Add(this.button5); + this.Controls.Add(this.button4); + this.Controls.Add(this.button3); + this.Controls.Add(this.button2); + this.Controls.Add(this.btBackColor); + this.Controls.Add(this.button1); + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow; + this.Name = "SelectColor3D"; + this.Text = "SelectColor3D"; + this.Load += new System.EventHandler(this.SelectColor3D_Load); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.ColorDialog colorDialog1; + private System.Windows.Forms.Button button1; + public System.Windows.Forms.Button btBackColor; + private System.Windows.Forms.Button button2; + private System.Windows.Forms.Button button3; + private System.Windows.Forms.Button button4; + private System.Windows.Forms.Button button5; + } +} \ No newline at end of file diff --git a/SelectColor3D.cs b/SelectColor3D.cs new file mode 100644 index 0000000..727bf5f --- /dev/null +++ b/SelectColor3D.cs @@ -0,0 +1,82 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Windows.Forms; + +namespace ToolsGenGkode +{ + public partial class SelectColor3D : Form + { + private Preview_Vectors pvf; + public SelectColor3D(Preview_Vectors fff) + { + InitializeComponent(); + pvf = fff; + + btBackColor.BackColor = Color.FromArgb(pvf.Color_3DBack.iR, pvf.Color_3DBack.iG, pvf.Color_3DBack.iB); + btBackColor.ForeColor = Color.FromArgb(255-pvf.Color_3DBack.iR, 0, 0); + + button2.BackColor = Color.FromArgb(pvf.Color_3DContur.iR, pvf.Color_3DContur.iG, pvf.Color_3DContur.iB); + button3.BackColor = Color.FromArgb(pvf.Color_Grid.iR, pvf.Color_Grid.iG, pvf.Color_Grid.iB); + + + } + + private void button2_Click(object sender, EventArgs e) + { + if (colorDialog1.ShowDialog() == DialogResult.OK) + { + btBackColor.BackColor = colorDialog1.Color; + + pvf.Color_3DBack = new FColor(colorDialog1.Color.R, colorDialog1.Color.G, colorDialog1.Color.B); + + pvf.openGLControl1.Refresh(); + pvf.openGLControl1.Refresh(); + } + + + } + + private void button2_Click_1(object sender, EventArgs e) + { + if (colorDialog1.ShowDialog() == DialogResult.OK) + { + button2.BackColor = colorDialog1.Color; + + pvf.Color_3DContur = new FColor(colorDialog1.Color.R, colorDialog1.Color.G, colorDialog1.Color.B); + + pvf.openGLControl1.Refresh(); + pvf.openGLControl1.Refresh(); + } + } + + private void button3_Click(object sender, EventArgs e) + { + if (colorDialog1.ShowDialog() == DialogResult.OK) + { + button3.BackColor = colorDialog1.Color; + + pvf.Color_Grid = new FColor(colorDialog1.Color.R, colorDialog1.Color.G, colorDialog1.Color.B); + + pvf.openGLControl1.Refresh(); + pvf.openGLControl1.Refresh(); + } + } + + private void SelectColor3D_Load(object sender, EventArgs e) + { + + } + + private void button1_Click(object sender, EventArgs e) + { + pvf.Color_3DBack = new FColor(120, 120, 120); + pvf.Color_3DContur = new FColor(0, 255, 0); + pvf.Color_Grid = new FColor(100, 0, 204); + } + } +} diff --git a/SelectColor3D.resx b/SelectColor3D.resx new file mode 100644 index 0000000..aa0ca0f --- /dev/null +++ b/SelectColor3D.resx @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + \ No newline at end of file diff --git a/ToolsGenGkode.csproj b/ToolsGenGkode.csproj index ace76d3..be119d4 100644 --- a/ToolsGenGkode.csproj +++ b/ToolsGenGkode.csproj @@ -130,6 +130,12 @@ True Resources.resx + + Form + + + SelectColor3D.cs + Form @@ -273,6 +279,9 @@ page03_SelectPLT.cs + + SelectColor3D.cs + TestLaser.cs @@ -324,6 +333,7 @@ + diff --git a/pages/page02_EnterText.cs b/pages/page02_EnterText.cs index 1c34fdc..30c9dc8 100644 --- a/pages/page02_EnterText.cs +++ b/pages/page02_EnterText.cs @@ -37,7 +37,7 @@ public page02_EnterText(MainForm mf) installedFontCollection.Dispose(); - comboBoxFont.Text = comboBoxFont.Items[0].ToString(); + if (comboBoxFont.Items.Count > 0) comboBoxFont.Text = comboBoxFont.Items[0].ToString(); rbUseSystemFont.Checked = true; rbFontToVector.Checked = true; diff --git a/pages/page04_ImageToVector.cs b/pages/page04_ImageToVector.cs index 038edb2..12e6816 100644 --- a/pages/page04_ImageToVector.cs +++ b/pages/page04_ImageToVector.cs @@ -86,13 +86,13 @@ private void UserActions() { if (LastPage2) { - pageImageNOW = (Bitmap)pageImageIN.Clone(); + pageImageNOW = ImageProcessing.CheckAndConvertImageto24bitPerPixel((Bitmap)pageImageIN.Clone()); } else { if (File.Exists(textBoxFileName.Text)) { - Bitmap tmp = new Bitmap(textBoxFileName.Text); + Bitmap tmp = ImageProcessing.CheckAndConvertImageto24bitPerPixel(new Bitmap(textBoxFileName.Text)); //TODO: Вот тут обратить внимание!!!!! на ориентацию оей diff --git a/pages/page05_SelectFileImageRastr.cs b/pages/page05_SelectFileImageRastr.cs index 12c2dd3..9f3a544 100644 --- a/pages/page05_SelectFileImageRastr.cs +++ b/pages/page05_SelectFileImageRastr.cs @@ -89,7 +89,7 @@ private void UserActions() if (!File.Exists(textBoxFileName.Text)) return; - Bitmap tmp = new Bitmap(textBoxFileName.Text); + Bitmap tmp = ImageProcessing.CheckAndConvertImageto24bitPerPixel(new Bitmap(textBoxFileName.Text)); //TODO: обратить внимание на ориентацию осей diff --git a/pages/page07_ModifyVectors.cs b/pages/page07_ModifyVectors.cs index fa9a2c5..56a8b2b 100644 --- a/pages/page07_ModifyVectors.cs +++ b/pages/page07_ModifyVectors.cs @@ -429,6 +429,7 @@ private void btRotate_Click(object sender, EventArgs e) UserActions(); + myMatrix.Dispose(); //Rotate(); } diff --git a/pages/page09_ImageRast.Designer.cs b/pages/page09_ImageRast.Designer.cs index 6ee563e..6577482 100644 --- a/pages/page09_ImageRast.Designer.cs +++ b/pages/page09_ImageRast.Designer.cs @@ -363,11 +363,6 @@ private void InitializeComponent() 0, 0, 0}); - this.numYAfter.Minimum = new decimal(new int[] { - 1, - 0, - 0, - 196608}); this.numYAfter.Name = "numYAfter"; this.numYAfter.Size = new System.Drawing.Size(77, 20); this.numYAfter.TabIndex = 14; @@ -389,11 +384,6 @@ private void InitializeComponent() 0, 0, 0}); - this.numXAfter.Minimum = new decimal(new int[] { - 1, - 0, - 0, - 196608}); this.numXAfter.Name = "numXAfter"; this.numXAfter.Size = new System.Drawing.Size(77, 20); this.numXAfter.TabIndex = 13; diff --git a/pages/page09_ImageRast.cs b/pages/page09_ImageRast.cs index 31b027f..48aa0c4 100644 --- a/pages/page09_ImageRast.cs +++ b/pages/page09_ImageRast.cs @@ -30,20 +30,34 @@ public page09_ImageRast(MainForm mf) NextPage = 10; useFilter.Items.Clear(); - useFilter.Items.Add("01 - метод Флойда-Стеинберга (<распыление >)"); //FloydSteinberg Dithering + useFilter.Items.Add("01 - метод Флойда-Стеинберга (<распыление>)"); //FloydSteinberg Dithering useFilter.Items.Add("02 - метод Байера (<матрица>)"); //Bayer Dithering useFilter.Items.Add("03 - Получение оттенков серого (bright)"); + try + { + cbKeepAspectRatio.Checked = Settings.Default.page09UserUseRation; + numSizePoint.Value = Settings.Default.page09SizePoint; + LaserTimeOut.Value = Settings.Default.page09LaserTimeOut; + numericUpDownPercent.Value = Settings.Default.page09PercentValue; - cbKeepAspectRatio.Checked = Settings.Default.page09UserUseRation; - numSizePoint.Value = Settings.Default.page09SizePoint; - LaserTimeOut.Value = Settings.Default.page09LaserTimeOut; - numericUpDownPercent.Value = Settings.Default.page09PercentValue; + _changeIsUser = false; + numXAfter.Value = Settings.Default.page09sizeDestX; + numYAfter.Value = Settings.Default.page09sizeDestY; + _changeIsUser = true; + } + catch (Exception ex) + { + cbKeepAspectRatio.Checked = true; + numSizePoint.Value = 1; + LaserTimeOut.Value = 1000; + numericUpDownPercent.Value = 100; - _changeIsUser = false; - numXAfter.Value = Settings.Default.page09sizeDestX; - numYAfter.Value = Settings.Default.page09sizeDestY; - _changeIsUser = true; + _changeIsUser = false; + numXAfter.Value = 100; + numYAfter.Value = 100; + _changeIsUser = true; + } switch (Settings.Default.page09VariantSize) { @@ -62,9 +76,10 @@ public page09_ImageRast(MainForm mf) case 4: radioButtonUserSize.Checked = true; break; + default: + radioButtonSizePoint.Checked = true; + break; } - - //RecalculateSize(); } private void page09_SelectImage_Load(object sender, EventArgs e) @@ -88,7 +103,7 @@ public void actionBefore() pageImageNOW = (Bitmap)pageImageIN.Clone(); GetInfoSize(); - + UserActions(); RecalculateSize(); @@ -96,9 +111,8 @@ public void actionBefore() public void actionAfter() { - // throw new NotImplementedException(); - } + } private void GetInfoSize() { @@ -108,19 +122,6 @@ private void GetInfoSize() numYbefore.Value = pageImageNOW.Height; } - public static Bitmap ConvertToGrayScale(Bitmap me) - { - if (me == null) - return null; - - // first convert to a grey scale image - var filterGreyScale = new Grayscale(0.2125, 0.7154, 0.0721); - - me = filterGreyScale.Apply(me); - return me; - } - - private void preparationImage() { //decimal newSizeX = numXAfter.Value / numSizePoint.Value; @@ -135,29 +136,29 @@ private void preparationImage() pageImageNOW = (Bitmap)pageImageIN.Clone(); pageVectorNOW = new List(); - Bitmap newBitmap = ConvertToGrayScale(pageImageNOW); + Bitmap newBitmap = ImageProcessing.ConvertToGrayScale(pageImageNOW); int Xsize = (int)(numXAfter.Value / numSizePoint.Value); int Ysize = (int)(numYAfter.Value / numSizePoint.Value); - ResizeBicubic filterResize = new ResizeBicubic(Xsize, Ysize); - newBitmap = filterResize.Apply(newBitmap); - - + newBitmap = ImageProcessing.ResizeImage(newBitmap,Xsize, Ysize); if (useFilter.Text.StartsWith("01")) //FloydSteinbergDithering" { + newBitmap = ImageProcessing.ConvertTo8Bit(newBitmap); + FloydSteinbergDithering filter = new FloydSteinbergDithering(); filter.ApplyInPlace(newBitmap); } if (useFilter.Text.StartsWith("02")) //@"BayerDithering" { + newBitmap = ImageProcessing.ConvertTo8Bit(newBitmap); + BayerDithering filter = new BayerDithering(); filter.ApplyInPlace(newBitmap); } - if (useFilter.Text.StartsWith("03")) //@"получение оттенков серого" { //получим новое перемасштабированное изображение @@ -232,88 +233,182 @@ private void GenVar1And2() } + + // тут зигзагом будем идти по файлу, и получать цвет private void GenVar3() { - double sizeOnePoint = (double)numSizePoint.Value; + // работа заточена только под 24-х битный пиксель + if (pageImageNOW.PixelFormat != PixelFormat.Format24bppRgb) + { + //throw new UnsupportedImageFormatException("Оппа! Не поддерживаемый формат изображения!!!"); + MessageBox.Show( + "Для генерации данных, требуется изображение имеющее 24 бита на пиксель, а получилось иначе, очень подозрительно....!!"); + return; + } - Bitmap bb = pageImageNOW; - BitmapData data = bb.LockBits(new Rectangle(0, 0, bb.Width, bb.Height), ImageLockMode.ReadOnly, bb.PixelFormat); // make sure you check the pixel format as you will be looking directly at memory + BitmapData bitmapData1 = pageImageNOW.LockBits(new Rectangle(0, 0, pageImageNOW.Width, pageImageNOW.Height), ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb); - //направление движения - DirrectionGroupPoint dir = DirrectionGroupPoint.Right; + //значение текущего цвета + int lastColor = -1; // прошлый цвет + int currColor = -1; // текущий цвет - unsafe - { - byte* ptrSrc = (byte*)data.Scan0; + pageVectorNOW = new List(); - int diff = data.Stride - data.Width; - - pageVectorNOW = new List(); + - for (int y = 0; y < data.Height; ++y) //проход по линии - { - List tmp = new List(); + double sizeOnePoint = (double)numSizePoint.Value; - byte lastValueColor = 0; - bool firstPoint = true; - bool lastPoint = false; + bool isFirst = true; + bool isLast = false; + unsafe + { + byte* imagePointer1 = (byte*)bitmapData1.Scan0; + for (int i = 0; i < bitmapData1.Height; i++) + { + //TODO: Доделать............ + isFirst = true; + isLast = false; + + GroupPoint tmpGroup = new GroupPoint(); - for (int x = 0; x < data.Width; ++x)//проход по точкам + for (int j = 0; j < bitmapData1.Width; j++) { - lastPoint = (x == data.Width - 1); //будем знать последняя ли это точка линии по которой идем - - // windows stores images in BGR pixel order - byte r = ptrSrc[0]; //тут получили нужный цвет + // дошли до последней строки в текущей линии + if (j == (bitmapData1.Width - 1)) isLast = true; + + // получим текущий цвет + currColor = (imagePointer1[0] + imagePointer1[1] + imagePointer1[2]) / 3; - if (firstPoint || lastPoint) //первую и последнюю точку добавим в любом случае + if (isFirst || isLast) { - firstPoint = false; + lastColor = currColor; + tmpGroup.Points.Add(new cncPoint((j * sizeOnePoint) + (double)deltaX.Value, (i * sizeOnePoint) + (double)deltaY.Value, 0, 0, 0, false, currColor)); - cncPoint lk = new cncPoint((x * sizeOnePoint) + (double)deltaX.Value, (y * sizeOnePoint) + (double)deltaY.Value,0,0,0,false,(int)r); + if (isLast) pageVectorNOW.Add(tmpGroup.Clone()); - tmp.Add(lk); - - lastValueColor = r; + isFirst = false; } else { - if (lastValueColor != r) + if (lastColor != currColor) { - cncPoint lk = new cncPoint((x * sizeOnePoint) + (double)deltaX.Value, (y * sizeOnePoint) + (double)deltaY.Value, 0, 0, 0, false, (int)r); + tmpGroup.Points.Add(new cncPoint((j * sizeOnePoint) + (double)deltaX.Value, (i * sizeOnePoint) + (double)deltaY.Value, 0, 0, 0, false, lastColor)); + lastColor = currColor; + tmpGroup.Points.Add(new cncPoint((j * sizeOnePoint) + (double)deltaX.Value, (i * sizeOnePoint) + (double)deltaY.Value, 0,0,0,false,currColor)); - tmp.Add(lk); - lastValueColor = r; } } - ptrSrc += 1; - } + imagePointer1 += 3; + }//end for j + imagePointer1 += bitmapData1.Stride - (bitmapData1.Width * 3); - // а теперь временный массив скопируем в основной, но с определенным направлением - if (dir == DirrectionGroupPoint.Right) - { - dir = DirrectionGroupPoint.Left; - } - else - { - tmp.Reverse(); - dir = DirrectionGroupPoint.Right; - } + }//end for i + }//end unsafe + pageImageNOW.UnlockBits(bitmapData1); - pageVectorNOW.Add(new GroupPoint(tmp, false, dir, true)); + //теперь у нечентных линий нужно сменить направление + bool needRevers = false; - // ReSharper disable once RedundantAssignment - tmp = new List(); + foreach (GroupPoint gpGroupPoint in pageVectorNOW) + { + if (needRevers) gpGroupPoint.Points.Reverse(); - ptrSrc += diff; - } + needRevers = !needRevers; } - bb.UnlockBits(data); + pageVectorNOW.Reverse(); - // тут нужно сделать преворот согластно текущй ориентации осей + + ////****************************** + + ////направление движения + ////DirrectionGroupPoint dir = DirrectionGroupPoint.Right; + + // //if (dir == DirrectionGroupPoint.Left) dir = DirrectionGroupPoint.Right; + // //else dir = DirrectionGroupPoint.Left; + + + //Bitmap bb = pageImageNOW; + //BitmapData data = bb.LockBits(new Rectangle(0, 0, bb.Width, bb.Height), ImageLockMode.ReadOnly, bb.PixelFormat); // make sure you check the pixel format as you will be looking directly at memory + + ////направление движения + ////DirrectionGroupPoint dir = DirrectionGroupPoint.Right; + + //unsafe + //{ + // byte* ptrSrc = (byte*)data.Scan0; + + // int diff = data.Stride - data.Width; + + // pageVectorNOW = new List(); + + // for (int y = 0; y < data.Height; ++y) //проход по линии + // { + // List tmp = new List(); + + // byte lastValueColor = 0; + // bool firstPoint = true; + // bool lastPoint = false; + + + // for (int x = 0; x < data.Width; ++x)//проход по точкам + // { + // lastPoint = (x == data.Width - 1); //будем знать последняя ли это точка линии по которой идем + + // // windows stores images in BGR pixel order + // byte r = ptrSrc[0]; //тут получили нужный цвет + + // if (firstPoint || lastPoint) //первую и последнюю точку добавим в любом случае + // { + // firstPoint = false; + + // cncPoint lk = new cncPoint((x * sizeOnePoint) + (double)deltaX.Value, (y * sizeOnePoint) + (double)deltaY.Value,0,0,0,false,(int)r); + + // tmp.Add(lk); + + // lastValueColor = r; + // } + // else + // { + // if (lastValueColor != r) + // { + // cncPoint lk = new cncPoint((x * sizeOnePoint) + (double)deltaX.Value, (y * sizeOnePoint) + (double)deltaY.Value, 0, 0, 0, false, (int)r); + + // tmp.Add(lk); + + // lastValueColor = r; + // } + // } + // ptrSrc += 1; + // } + + + // // а теперь временный массив скопируем в основной, но с определенным направлением + // if (dir == DirrectionGroupPoint.Right) + // { + // dir = DirrectionGroupPoint.Left; + // } + // else + // { + // tmp.Reverse(); + // dir = DirrectionGroupPoint.Right; + // } + + // pageVectorNOW.Add(new GroupPoint(tmp, false, dir, true)); + + // // ReSharper disable once RedundantAssignment + // tmp = new List(); + + // ptrSrc += diff; + // } + //} + + //bb.UnlockBits(data); + + //// тут нужно сделать преворот согластно текущй ориентации осей pageVectorNOW = VectorProcessing.Rotate(pageVectorNOW); } @@ -355,12 +450,14 @@ private void btCalcTraectory_Click(object sender, EventArgs e) Cursor.Current = Cursors.WaitCursor; preparationImage(); - GenerateData(); + UserActions(); + + Cursor.Current = Cursors.Default; - UserActions(); + //UserActions(); //CreateEvent("RefreshImage_09"); } diff --git a/pages/page11_DXF.cs b/pages/page11_DXF.cs index 0f33d5b..43e199e 100644 --- a/pages/page11_DXF.cs +++ b/pages/page11_DXF.cs @@ -209,8 +209,9 @@ private List GetVectorDXF(string FileNAME) foreach (DXFVertex pl_e in lp.Children) { - ListPoint.Add(new cncPoint((double)pl_e.Location.X, (double)pl_e.Location.Y)); - + if (pl_e.GetType() == typeof(DXFVertex)) + if (pl_e.Location.X != null && pl_e.Location.Y != null) + ListPoint.Add(new cncPoint((double)pl_e.Location.X, (double)pl_e.Location.Y)); } ListLines.Add(new GroupPoint( ListPoint)); ListPoint = new List();