public static void Point_N(ZArrayDescriptor arr, int N1_sin, int N2_sin, int scale, Graphics g) { double max = SumClass.getMax(arr); double c4 = max / 4; double c2 = max / 2; double c3 = c4 + c2; for (int i = 0; i < N2_sin; i++) { for (int j = 0; j < N1_sin; j++) { int x = i * scale; int y = j * scale; if (arr.array[i, j] == 0) { continue; } if (arr.array[i, j] < c4) { g.FillRectangle(new SolidBrush(Color.FromArgb(0, 0, 0)), x, y, 1, 1); continue; } if (arr.array[i, j] < c2) { g.FillRectangle(new SolidBrush(Color.FromArgb(0, 250, 0)), x, y, 1, 1); continue; } if (arr.array[i, j] < c3) { g.FillRectangle(new SolidBrush(Color.FromArgb(250, 150, 0)), x, y, 1, 1); continue; } } } }
// Рисование таблицы чисел по двум массивам k1 и k2 с сдвигом public static void Tabl_int(ZArrayDescriptor[] zArrayPicture, PictureBox pictureBox1, int k1, int k2, int N1_sin, int N2_sin, int scale, int d, int sdvig) { China(N1_sin, N2_sin); //MessageBox.Show(" M1 " + M1 + " N1 " + N1 + " M2 " + M2 + " N2 " + N2); if (zArrayPicture[k1] == null) { MessageBox.Show("zArrayPicture[k1] == NULL Unrup.Tabl_int "); return; } if (zArrayPicture[k2] == null) { MessageBox.Show("zArrayPicture[k2] == NULL Unrup.Tabl_int "); return; } int nx = zArrayPicture[k1].width; int ny = zArrayPicture[k1].height; //ZArrayDescriptor res = new ZArrayDescriptor(N1_sin, N2_sin); double max1 = SumClass.getMax(zArrayPicture[k1]); double min1 = SumClass.getMin(zArrayPicture[k1]); double max2 = SumClass.getMax(zArrayPicture[k2]); double min2 = SumClass.getMin(zArrayPicture[k2]); // China(N1_sin, N2_sin); Graphics g = Graphics.FromHwnd(pictureBox1.Handle); g.Clear(Color.White); ZArrayDescriptor arr = new ZArrayDescriptor(N2_sin, N1_sin); int M = M1 * N1; int N = M2 * N2; int MN = N1_sin * N2_sin; for (int i = 0; i < nx; i++) { for (int j = 0; j < ny; j++) { //double a = res.array[i, j]; int x = (int)((zArrayPicture[k1].array[i, j] - min1) * (N2_sin - 1) / (max1 - min1)); int b2 = sdv(x, sdvig, N2_sin); int y = (int)((zArrayPicture[k2].array[i, j] - min1) * (N1_sin - 1) / (max1 - min1)); int X0 = (M * b2 + N * y) % MN; //if (X0 < d ) Point(b2 * scale, y * scale, g); if (X0 < d) { arr.array[b2, y] += 1; } } } Point_N(arr, N1_sin, N2_sin, scale, g); }
public static void Diapazon1(ZArrayDescriptor[] zArrayPicture, int regImage, int imax) { int nx = zArrayPicture[regImage].width; int ny = zArrayPicture[regImage].height; //MessageBox.Show("max= " + max + "min= "+min); double max = SumClass.getMax(zArrayPicture[regImage]); double min = SumClass.getMin(zArrayPicture[regImage]); for (int i = 0; i < nx; i++) { for (int j = 0; j < ny; j++) { int c = (int)((zArrayPicture[regImage].array[i, j] - min) * imax / (max - min)); zArrayPicture[regImage].array[i, j] = c; } } }
private void Gr3D() { ns = Convert.ToInt32(textBox1.Text); ZArrayDescriptor zArray3D = new ZArrayDescriptor(nx1, ny1); int[] arr_max = new int[nx1]; int[] arr_tmp = new int[nx1]; int[] arr_tmp_gr = new int[nx1]; //for (int i = 0; i < nx1; i++) //{ // arr_max[i] = 0; //arr_tmp[i] = -1000; // } int ys = 2; int y0 = 250; // Сдвиг снизу для красоты //int ns1 = ns; double max = SumClass.getMax(zArray2D); double min = SumClass.getMin(zArray2D); int k = 0; for (int j = 0; j < ny1; j += ns, k++) { for (int i = 0; i < nx1; i++) { int ix = i - k; if (ix < nx1 && ix > 0) { arr_tmp[i] = (int)((zArray2D.array[ix, j] - min) * 128 / (max - min)) + ys * k; } } for (int i = 0; i < nx1; i++) { if (arr_tmp[i] > arr_max[i]) { arr_max[i] = arr_tmp[i]; } } int x1 = 0; int y1 = (int)(arr_max[0]); for (int i = 1; i < nx1 - 100 + k; i++) { if (i >= nx1) { break; } int x2 = i; int y2 = (int)(arr_max[i]); lineDDA(x1, y1, x2, y2, y0, zArray3D); y1 = y2; x1 = x2; } } Vizual.Vizual_Picture(zArray3D, picture3D); }
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; } }