// Конструктор для заполнения фазы (Амплитуда постоянная) public ZComplexDescriptor(ZArrayDescriptor descriptorToCopy, double am) { if (descriptorToCopy == null) { MessageBox.Show("ZComplexDescriptor == NULL"); return; } width = descriptorToCopy.width; height = descriptorToCopy.height; array = new Complex[width, height]; double max = SumClass.getMax(descriptorToCopy); double min = SumClass.getMin(descriptorToCopy); //MessageBox.Show("width =" + Convert.ToString(width) + "height =" + Convert.ToString(height)); for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { double a = descriptorToCopy.array[i, j]; a = (a - min) * 2.0 * Math.PI / (max - min); a = a - Math.PI; array[i, j] = Complex.FromPolarCoordinates(am, a); //array[i, j] = new Complex(1.0, descriptorToCopy.array[i, j]); } } }
// Конструктор для случайного заполнения фазы (RANDOM) (Амплитуда из файла, k=1) public ZComplexDescriptor(ZArrayDescriptor descriptorToCopy, ZArrayDescriptor amp, int k) { if (amp == null) { MessageBox.Show("Ampl == NULL"); return; } if (descriptorToCopy == null) { MessageBox.Show("ZArrayDescriptor == NULL"); return; } if (k != 1) { MessageBox.Show(" k!=1 "); return; } width = amp.width; height = amp.height; array = new Complex[width, height]; double max = SumClass.getMax(descriptorToCopy); double min = SumClass.getMin(descriptorToCopy); int NX = descriptorToCopy.width; int NY = descriptorToCopy.height; if (NX > width) { NX = width; } if (NY > height) { NY = height; } //MessageBox.Show("width =" + Convert.ToString(width) + "height =" + Convert.ToString(height)); Random rnd = new Random(); for (int i = 0; i < NX; i++) { for (int j = 0; j < NY; j++) { double am = amp.array[i, j]; double fz = descriptorToCopy.array[i, j]; double fa = rnd.NextDouble() * 2.0 * Math.PI - Math.PI; fz = fz + fa; //if (fz > Math.PI) fz = fz - Math.PI; //if (fz < -Math.PI) fz = fz + Math.PI; if (am <= 0) { fz = 0; // По шаблону } //if (a > 0) a = rnd.NextDouble() * Math.PI ; else a = 0; array[i, j] = Complex.FromPolarCoordinates(am, fz); } } }
public static void Vizual_Circle(ZArrayDescriptor zArrayDescriptor, PictureBox pictureBox01, int x0, int y0, int radius) { // c1 = ImageProcessor.getPixel(i, j, data1); // c1 = bmp1.GetPixel(i, j); // ImageProcessor.setPixel(data5, i, j, Color.FromArgb(r, r, r)); // bmp2.SetPixel(j, i, c1); // bmp5.UnlockBits(data5); if (pictureBox01 == null) { MessageBox.Show("pictureBox01 == null"); return; } if (zArrayDescriptor == null) { MessageBox.Show("ZArrayDescriptor array == null"); return; } int width = zArrayDescriptor.width; int height = zArrayDescriptor.height; if (width == 0 || height == 0) { MessageBox.Show("width == 0 || height == 0"); return; } Bitmap bmp2 = new Bitmap(width, height); BitmapData data2 = ImageProcessor.getBitmapData(bmp2); double max = SumClass.getMax(zArrayDescriptor); double min = SumClass.getMin(zArrayDescriptor); //MessageBox.Show("max = " + Convert.ToString(max) + " min = " + Convert.ToString(min)); if (Math.Abs(max - min) < 0.0000001) { // MessageBox.Show("max = min"); int c = 0; if (max < 255 && max > 0.0) { c = Convert.ToInt32(max); } if (max > 255) { c = 255; } if (max < 0) { c = 0; } for (int j = 0; j < width; j++) { for (int i = 0; i < height; i++) { Color c1 = Color.FromArgb(c, c, c); ImageProcessor.setPixel(data2, j, i, c1); } } pictureBox01.Image = bmp2; bmp2.UnlockBits(data2); return; } if (max != min) { double mxmn = 255.0 / (max - min); for (int j = 0; j < width; j++) { for (int i = 0; i < height; i++) { int c = Convert.ToInt32((zArrayDescriptor.array[j, i] - min) * mxmn); Color c1 = Color.FromArgb(c, c, c); ImageProcessor.setPixel(data2, j, i, c1); } } Color c2 = Color.FromArgb(255, 128, 255); DrawCircle(data2, x0, y0, radius, c2); // Рисование окружности цветом Fill_Circle_Outside(zArrayDescriptor, data2, width, height, c2); // Заполнение цветом снаружи pictureBox01.Image = bmp2; bmp2.UnlockBits(data2); return; } }
//--------------------------------------------------------------------------------------------------------------------- // // Из ZArrayDescriptor.array в PictureBox // public static void Vizual_Picture(ZArrayDescriptor zArrayDescriptor, PictureBox pictureBox01) { // c1 = ImageProcessor.getPixel(i, j, data1); // c1 = bmp1.GetPixel(i, j); // ImageProcessor.setPixel(data5, i, j, Color.FromArgb(r, r, r)); // bmp2.SetPixel(j, i, c1); // bmp5.UnlockBits(data5); if (pictureBox01 == null) { MessageBox.Show("Vizual_Picture: pictureBox01 == null"); return; } if (zArrayDescriptor == null) { MessageBox.Show("Vizual_Picture: ZArrayDescriptor array == null"); return; } int width = zArrayDescriptor.width; int height = zArrayDescriptor.height; if (width == 0 || height == 0) { MessageBox.Show("Vizual_Picture: width == 0 || height == 0"); return; } Bitmap bmp2 = new Bitmap(width, height); BitmapData data2 = ImageProcessor.getBitmapData(bmp2); double max = SumClass.getMax(zArrayDescriptor); double min = SumClass.getMin(zArrayDescriptor); //MessageBox.Show("max = " + Convert.ToString(max) + " min = " + Convert.ToString(min)); if (Math.Abs(max - min) < 0.0000001) { // MessageBox.Show("max = min"); int c = 0; if (max < 255 && max > 0.0) { c = Convert.ToInt32(max); } if (max > 255) { c = 255; } if (max < 0) { c = 0; } for (int j = 0; j < width; j++) { for (int i = 0; i < height; i++) { Color c1 = Color.FromArgb(c, c, c); ImageProcessor.setPixel(data2, j, i, c1); } } pictureBox01.Image = bmp2; bmp2.UnlockBits(data2); return; } if (max != min) { double mxmn = 255.0 / (max - min); for (int j = 0; j < width; j++) { for (int i = 0; i < height; i++) { int c; try { c = Convert.ToInt32((zArrayDescriptor.array[j, i] - min) * mxmn); } catch (System.OverflowException) { c = 0; } Color c1 = Color.FromArgb(c, c, c); ImageProcessor.setPixel(data2, j, i, c1); } } pictureBox01.Image = bmp2; bmp2.UnlockBits(data2); return; } }