private void DrawDiagram(List <float> values) { using (Graphics gr = pictureBox1.CreateGraphics()) { gr.FillRectangle(Brushes.White, 0, 0, pictureBox1.Width, pictureBox1.Height); float min = float.MaxValue; float max = float.MinValue; for (int i = 0; i < values.Count; i++) { if (values[i] < min) { min = values[i]; } if (values[i] > max) { max = values[i]; } } Point[] points = new Point[500]; /*for (int i = 0; i < values.Count; i++) * { * points[i].X = i * (pictureBox1.Width - 1) / values.Count; * points[i].Y = (pictureBox1.Height - 1) - (int)((values[i] - min) / (max - min) * (pictureBox1.Height - 1)); * } * gr.DrawLines(Pens.Maroon, points); */ for (int i = 0; i < 500; i++) { points[i].X = i * (pictureBox1.Width - 1) / 500; points[i].Y = (pictureBox1.Height - 1) - (int)((values[i + 1000] - min) / (max - min) * (pictureBox1.Height - 1)); } gr.DrawLines(Pens.Maroon, points); float peakFloat = peak1.GetCOG(values); peakTrace1.AddPeak(peak1.GetCOGinWaveLength(), 1.123); Console.WriteLine("Peak: {0}", peakFloat); Console.WriteLine("PeakTrace: {0}", peakTrace1.GetPeak(peakTrace1.GetLength() - 1)); int peakInt = (int)(peakFloat * ((float)pictureBox1.Width - 1f) / (float)500); int WaveAInt = (int)((float)peak1.GetPixelLeft() * ((float)pictureBox1.Width - 1f) / (float)values.Count); int WaveBInt = (int)((float)peak1.GetPixelRight() * ((float)pictureBox1.Width - 1f) / (float)values.Count); int thresholdeInt = (pictureBox1.Height - 1) - (int)((peak1.GetPeakThresholde() - min) / (max - min) * (float)(pictureBox1.Height - 1)); gr.DrawLine(Pens.Blue, peakInt, 0f, peakInt, pictureBox1.Height); gr.DrawLine(Pens.Green, WaveAInt, 0f, WaveAInt, pictureBox1.Height); gr.DrawLine(Pens.Yellow, WaveBInt, 0f, WaveBInt, pictureBox1.Height); gr.DrawLine(Pens.Violet, 0, thresholdeInt, pictureBox1.Width, thresholdeInt); gr.DrawRectangle(Pens.Black, 0, 0, pictureBox1.Width - 1, pictureBox1.Height - 1); } }
private void DrawRollerDiagram(float [] values) { using (Graphics gr = pictureBox2.CreateGraphics()) { gr.FillRectangle(Brushes.White, 0, 0, pictureBox2.Width, pictureBox2.Height); float peakFloat = peak1.GetCOG(values); Console.WriteLine("Peak: {0}", peakFloat); float min = float.MaxValue; float max = float.MinValue; for (int i = 0; i < values.Length; i++) { if (values[i] < min) { min = values[i]; } if (values[i] > max) { max = values[i]; } } Point[] points = new Point[values.Length]; for (int i = 0; i < 500; i++) { points[i].X = i * (pictureBox2.Width - 1) / 500; points[i].Y = (pictureBox2.Height - 1) - (int)((peakFloat - min) / (max - min) * (pictureBox2.Height - 1)); //points[i].Y = (pictureBox2.Height - 1) - (int)((peakFloat) / 900 * (pictureBox2.Height - 1)); } int peakInt = (int)(peakFloat * ((float)pictureBox2.Width - 1f) / (float)values.Length); gr.DrawLine(Pens.Blue, peakInt, 0f, peakInt, pictureBox2.Height); gr.DrawRectangle(Pens.Black, 0, 0, pictureBox2.Width - 1, pictureBox2.Height - 1); } // labelPeak.Text = "Peak [nm]: " + peak1.COGinWaveLength; }
private void DrawDiagram(List <float> values) { using (Graphics gr = pictureBox1.CreateGraphics()) { gr.FillRectangle(Brushes.White, 0, 0, pictureBox1.Width, pictureBox1.Height); float min = float.MaxValue; float max = float.MinValue; for (int i = 0; i < values.Count; i++) { if (values[i] < min) { min = values[i]; } if (values[i] > max) { max = values[i]; } } Point[] points = new Point[500]; /*for (int i = 0; i < values.Count; i++) * { * points[i].X = i * (pictureBox1.Width - 1) / values.Count; * points[i].Y = (pictureBox1.Height - 1) - (int)((values[i] - min) / (max - min) * (pictureBox1.Height - 1)); * } * gr.DrawLines(Pens.Maroon, points); */ for (int i = 0; i < 500; i++) { points[i].X = i * (pictureBox1.Width - 1) / 500; points[i].Y = (pictureBox1.Height - 1) - (int)((values[i + 1000] - min) / (max - min) * (pictureBox1.Height - 1)); } gr.DrawLines(Pens.Maroon, points); float peakFloat1 = peak1.GetCOG(values); //float peakFloat1 = peak1.GetCOG((float)numericUpDown1.Value, (float)numericUpDown2.Value, (float)numericUpDowntr1.Value, values); peakTrace1.AddPeak(peak1.GetCOGinWaveLength(), 1.123); // float peakFloat2 = peak2.GetCOG(values); // float peakFloat2 = peak1.GetCOG((float)numericUpDown3.Value, (float)numericUpDown4.Value, (float)numericUpDowntr2.Value, values); ; // peakTrace2.AddPeak(peak2.GetCOGinWaveLength(), 1.123); Debug.WriteLine($"PEAK FLOAT 1 {peakFloat1}"); //Debug.WriteLine($"PEAK FLOAT 2 {peakFloat2}"); int peakInt1 = (int)(peakFloat1 * ((float)pictureBox1.Width - 1f) / (float)values.Count); int WaveAInt = (int)((float)peak1.GetPixelLeft() * ((float)pictureBox1.Width - 1f) / (float)values.Count); int WaveBInt = (int)((float)peak1.GetPixelRight() * ((float)pictureBox1.Width - 1f) / (float)values.Count); int thresholdeInt = (pictureBox1.Height - 1) - (int)((peak1.GetPeakThresholde() - min) / (max - min) * (float)(pictureBox1.Height - 1)); gr.DrawLine(Pens.Blue, peakInt1, 0f, peakInt1, pictureBox1.Height); gr.DrawLine(Pens.Green, WaveAInt, 0f, WaveAInt, pictureBox1.Height); gr.DrawLine(Pens.Yellow, WaveBInt, 0f, WaveBInt, pictureBox1.Height); gr.DrawLine(Pens.Violet, 0, thresholdeInt, pictureBox1.Width, thresholdeInt); /*int peakInt2 = (int)(peakFloat2 * ((float)pictureBox1.Width - 1f) / (float)values.Count); * int WaveAInt2 = (int)((float)peak2.GetPixelLeft() * ((float)pictureBox1.Width - 1f) / (float)values.Count); * int WaveBInt2 = (int)((float)peak2.GetPixelRight() * ((float)pictureBox1.Width - 1f) / (float)values.Count); * int thresholdeInt2 = (pictureBox1.Height - 1) - (int)((peak2.GetPeakThresholde() - min) / (max - min) * (float)(pictureBox1.Height - 1)); * gr.DrawLine(Pens.Aqua, peakInt2, 0f, peakInt2, pictureBox1.Height); * gr.DrawLine(Pens.DarkGreen, WaveAInt2, 0f, WaveAInt2, pictureBox1.Height); * gr.DrawLine(Pens.DarkOrange, WaveBInt2, 0f, WaveBInt2, pictureBox1.Height); * gr.DrawLine(Pens.Magenta, 0, thresholdeInt2, pictureBox1.Width, thresholdeInt2); */ Debug.WriteLine($"PEAK 1 COG {peak1.GetCOGresult()}"); // Debug.WriteLine($"PEAK 2 COG {peak2.GetCOGresult()}"); Console.WriteLine("Peak: {0}", peakFloat1); Console.WriteLine("PeakTrace: {0}", peakTrace1.GetPeak(peakTrace1.GetLength() - 1)); gr.DrawRectangle(Pens.Black, 0, 0, pictureBox1.Width - 1, pictureBox1.Height - 1); } }