/// <summary> /// Вызывает событие ParallelFractalCreatingFinished. /// </summary> /// <param name="FAP">Экземпляр готового фрактала.</param> protected void f_activate_ParallelFractalCreatingFinished(FractalAssociationParametrs FAP) { if (ParallelFractalCreatingFinished != null) { ParallelFractalCreatingFinished(this, FAP); } }
public override System.Drawing.Bitmap GetDrawnBitmap(FractalAssociationParametrs FAP, object Extra = null) { int width = FAP.Width, height = FAP.Height; Bitmap Result = new Bitmap(width, height); double[][] dm = FAP.Get2DRatioMatrix(); BitmapData ResultData = Result.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb); unsafe { double dmi; int param = 255 << 24, x, y; int * ptr = (int *)ResultData.Scan0.ToPointer(); for (y = 0; y < height; ++y) { for (x = 0; x < width; ++x) { dmi = dm[x][y] / 4D; *(ptr++) = param | (get_cos_color(dmi, _red, _red_scale) << 16) | (get_cos_color(dmi, _green, _green_scale) << 8) | (get_cos_color(dmi, _blue, _blue_scale)); } } } Result.UnlockBits(ResultData); return(Result); }
/*______________________________________________________Реализация_абстрактных_методов_класса_________________________________________________________*/ #region Realization of abstract methods of class public override System.Drawing.Bitmap GetDrawnBitmap(FractalAssociationParametrs FAP, object Extra = null) { int width = FAP.Width, height = FAP.Height; Bitmap Result = new Bitmap(width, height); ulong iter, grad_void_iters = _gradient_void_iterations_count + _gradient_iterations_count; ulong[][] iter_matrix = FAP.Get2DOriginalIterationsMatrix(); double[][] Radian_matrix = ((RadianMatrix)FAP.GetUniqueParameter(typeof(RadianMatrix))).Matrix; int deg; Color color; _optimizer = _using_mod.Optimize(FAP); for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { deg = ((int)((Radian_matrix[x][y] / Math.PI) * 180D) + 360) % 360; iter = iter_matrix[x][y]; if (iter <= _gradient_iterations_count) { color = cycle_get_gradient_color(_percents, _color, deg); } else if (iter <= grad_void_iters) { color = _gradient_void; } else { color = _using_mod.GetColor(_optimizer, x, y); } Result.SetPixel(x, y, color); } } return(Result); }
public override System.Drawing.Bitmap GetDrawnBitmap(FractalAssociationParametrs FAP, object Extra = null) { int width = FAP.Width, height = FAP.Height; Bitmap bmp = new Bitmap(width, height); double[][] dm = ((RadianMatrix)FAP.GetUniqueParameter(typeof(RadianMatrix))).Matrix; Color cl = Color.Black; ; ulong[][] iter_matrix=FAP.Get2DOriginalIterationsMatrix(); ulong iter; int deg; for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { iter = (ulong)(iter_matrix[x][y]*0.8); cl =Color.FromArgb((255 - iter / 1.85) >= 0 ? (int)(255 - iter / 1.85) : 0, (255 - iter / 1.4) >= 0 ? (int)(255 - iter / 1.4) : 0, (255 - iter / 1.8) >= 0 ? (int)(255 - iter / 1.8) : 0); bmp.SetPixel(x, y,cl); if (iter < 85) { deg = (int)((dm[x][y] / Math.PI) * 180); if (deg < 0) deg = 360 + deg; if (deg < 181) cl = Color.FromArgb(255 - 255 * deg / 180,255- 255 * deg / 180, 255 -255 * deg / 180); else { deg -= 180; cl = Color.FromArgb(255 * deg / 180, 255 * deg / 180, 255 * deg / 180); } bmp.SetPixel(x, y,cl);} } } return bmp; }
public override System.Drawing.Bitmap GetDrawnBitmap(FractalAssociationParametrs FAP,object Extra=null) { if (FAP == null) throw new ArgumentNullException("FAP не содержить значения!"); if (!IsCompatible(FAP)) throw new ArgumentException("Переданный FractalAssociationParameters не совместим с данной цветовой моделью, используйте другую цветовую модель!"); if (FAP.FractalType != FractalType._2DStandartIterationTypeWithCloudPoints) throw new ArgumentException("Данный фрактал не имеет трёхмерную матрицу FractalCloudPoint!"); int width=FAP.Width, height=FAP.Height; Bitmap Result = new Bitmap(width, height); Graphics g = Graphics.FromImage(Result); g.FillRectangle(Brushes.Black, 0, 0, width, height); g.Dispose(); FractalCloudPoints fcps = (FractalCloudPoints)FAP.GetUniqueParameter(); FractalCloudPoint[][][] fcp_matrix = (FractalCloudPoint[][][])fcps.fractalCloudPoint; Color using_color; Random rand = new Random(); for(int _x=0;_x<fcp_matrix.Length;_x++) { for(int _y=0;_y<fcp_matrix[0].Length;_y++) { if (fcp_matrix[_x][_y].Length <fcps.MaxAmmountAtTrace) continue; using_color = Color.FromArgb(rand.Next(256), rand.Next(256), rand.Next(256)); for(int i=0;i<fcp_matrix[_x][_y].Length;i++) { if (fcp_matrix[_x][_y][i].AbcissLocation < 0 || fcp_matrix[_x][_y][i].OrdinateLocation < 0 || fcp_matrix[_x][_y][i].AbcissLocation >=width|| fcp_matrix[_x][_y][i].OrdinateLocation >=height) continue; Result.SetPixel(fcp_matrix[_x][_y][i].AbcissLocation, fcp_matrix[_x][_y][i].OrdinateLocation, using_color); } } } return Result; }
public override System.Drawing.Bitmap GetDrawnBitmap(FractalAssociationParametrs FAP, object Extra = null) { int width = FAP.Width,height=FAP.Height; Bitmap Result = new Bitmap(width,height); double[][] dm = FAP.Get2DRatioMatrix(); BitmapData ResultData = Result.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb); unsafe { double dmi; int param = 255 << 24,x,y; int* ptr = (int*)ResultData.Scan0.ToPointer(); for ( y = 0; y < height; ++y) { for ( x = 0; x < width; ++x) { dmi = dm[x][y] / 4D; *(ptr++) = param| (get_cos_color(dmi, _red, _red_scale) << 16)| (get_cos_color(dmi,_green,_green_scale)<<8)| (get_cos_color(dmi,_blue,_blue_scale)); } } } Result.UnlockBits(ResultData); return Result; }
public override System.Drawing.Bitmap GetDrawnBitmap(FractalAssociationParametrs FAP,object Extra=null) { if (FAP == null) throw new ArgumentNullException("FAP не содержить значения!"); if (!IsCompatible(FAP)) throw new ArgumentException("Переданный FractalAssociationParameters не совместим с данной цветовой моделью, используйте другую цветовую модель!"); if (_color_array == null) throw new InvalidOperationException("Требуеться задать массив цветов (используйте CreateRandColorArray)."); if (_color_array.Length < 1) throw new InvalidOperationException("Нельзя использовать пустой массив цветов (используйте CreateRandColorArray)."); int width = FAP.Width, height = FAP.Height; Bitmap Result = new Bitmap(width, height); Graphics g = Graphics.FromImage(Result); g.FillRectangle(Brushes.Black, 0, 0, width, height); g.Dispose(); FractalCloudPoint[][][] fcp_matrix = ((FractalCloudPoints)FAP.GetUniqueParameter()).fractalCloudPoint; int abciss_step_size = width / fcp_matrix.Length + (width % fcp_matrix.Length != 0 ? 1 : 0); int ordinate_step_size = height / fcp_matrix[0].Length + (height % fcp_matrix[0].Length != 0 ? 1 : 0); Color using_color; int TraceLimit=((FractalCloudPoints)FAP.GetUniqueParameter()).MaxAmmountAtTrace; for (int _x = 0; _x < fcp_matrix.Length; _x++) { for (int _y = 0; _y < fcp_matrix[0].Length; _y++) { if (fcp_matrix[_x][_y].Length < TraceLimit) continue; using_color = _color_array[(_x + _y) % _color_array.Length]; for (int i = 0; i < fcp_matrix[_x][_y].Length; i++) { if (fcp_matrix[_x][_y][i].AbcissLocation < 0 || fcp_matrix[_x][_y][i].OrdinateLocation < 0 || fcp_matrix[_x][_y][i].AbcissLocation >= width || fcp_matrix[_x][_y][i].OrdinateLocation >= height) continue; Result.SetPixel(fcp_matrix[_x][_y][i].AbcissLocation, fcp_matrix[_x][_y][i].OrdinateLocation, using_color); } } } return Result; }
public override bool IsCompatible(FractalAssociationParametrs FAP) { if (FAP == null) { throw new ArgumentNullException("Нельзя передавать значение null в данный метод!"); } return(FAP.Is2D && (FAP.GetUniqueParameter() is FractalCloudPoints)); }
public VisualColorControler(Fractal fractal, FractalColorMode FractalColorMode, int OldWidth, int OldHeight, FractalAssociationParametrs fap) { _fractal = fractal; this.FractalColorMode = FractalColorMode; InitializeComponent(); _old_height = OldHeight; _old_width = OldWidth; _fap = fap; }
private void FirstSetColorModes(Fractal fractal, FractalAssociationParametrs FAP) { Action act = () => { _fap = FAP; list_up(FractalColorMode); comboBox1.SelectedIndex = 0; }; Invoke(act); fractal.ParallelFractalCreatingFinished -= FirstSetColorModes; }
/*__________________________________________________________Конструкторы_класса_________________________________________________________________*/ #region Constructors public FractalDataHandler(Control Owner,Fractal Fractal,FractalPictureBox FPB,FractalColorMode FCM,Size Size,FractalAssociationParametrs FAP=null) { if (Owner==null||Fractal == null || FPB == null || FCM == null) throw new ArgumentNullException("Нельзя передавать пустые значения!"); if (Size.Width < 1 || Size.Height < 1) throw new ArgumentException("Ширина и Высота не могут быть меньше единицы!"); _fractal = Fractal; _fpb = FPB; _fcm = FCM; _width = Size.Width; _height = Size.Height; _fap = FAP; _owner=Owner; Connect(); }
public override Bitmap GetDrawnBitmap(FractalAssociationParametrs FAP, object Extra = null) { check_all_functions(); int width = FAP.Width, height = FAP.Height; Bitmap Result = new Bitmap(width, height); ulong[][] Iter_matrix = FAP.Get2DOriginalIterationsMatrix(); //double maxiters= double[][] Ratio_matrix = FAP.Get2DRatioMatrix(); double[][] Radian_Matrix = ((RadianMatrix)FAP.GetUniqueParameter(typeof(RadianMatrix))).Matrix; BitmapData ResultData = Result.LockBits(new Rectangle(new Point(), Result.Size), ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb); unsafe { double[] arg = new double[8]; int Parameter = -1; byte * blue = (byte *)&Parameter, green = blue + 1, red = green + 1; int * ptr = (int *)ResultData.Scan0.ToPointer(); int x, y; double * iter, ratio, radian, maxofiter, xloc, yloc; fixed(double *iterator = arg) { iter = iterator; ratio = iter + 1; radian = ratio + 1; maxofiter = radian + 1; xloc = maxofiter + 1; yloc = xloc + 1; arg[7] = height; arg[6] = width; *maxofiter = FAP.ItersCount; for (y = 0; y < height; ++y) { for (x = 0; x < width; ++x) { *iter = Iter_matrix[x][y]; *ratio = Ratio_matrix[x][y]; *radian = Radian_Matrix[x][y]; *xloc = x; *yloc = y; *red = (byte)(_m_red_func(arg) % 256D); *green = (byte)(_m_green_func(arg) % 256D); *blue = (byte)(_m_blue_func(arg) % 256D); *(ptr++) = Parameter; } } } } Result.UnlockBits(ResultData); return(Result); }
/*_________________________________________________________Реализация_асбтрактных_методов_______________________________________________________*/ #region Realization of abstract methods public override System.Drawing.Bitmap GetDrawnBitmap(FractalAssociationParametrs FAP, object Extra = null) { if (FAP == null) { throw new ArgumentNullException("FAP не содержить значения!"); } if (!IsCompatible(FAP)) { throw new ArgumentException("Переданный FractalAssociationParameters не совместим с данной цветовой моделью, используйте другую цветовую модель!"); } if (_color_array == null) { throw new InvalidOperationException("Требуеться задать массив цветов (используйте CreateRandColorArray)."); } if (_color_array.Length < 1) { throw new InvalidOperationException("Нельзя использовать пустой массив цветов (используйте CreateRandColorArray)."); } int width = FAP.Width, height = FAP.Height; Bitmap Result = new Bitmap(width, height); Graphics g = Graphics.FromImage(Result); g.FillRectangle(Brushes.Black, 0, 0, width, height); g.Dispose(); FractalCloudPoint[][][] fcp_matrix = ((FractalCloudPoints)FAP.GetUniqueParameter()).fractalCloudPoint; int abciss_step_size = width / fcp_matrix.Length + (width % fcp_matrix.Length != 0 ? 1 : 0); int ordinate_step_size = height / fcp_matrix[0].Length + (height % fcp_matrix[0].Length != 0 ? 1 : 0); Color using_color; int TraceLimit = ((FractalCloudPoints)FAP.GetUniqueParameter()).MaxAmmountAtTrace; for (int _x = 0; _x < fcp_matrix.Length; _x++) { for (int _y = 0; _y < fcp_matrix[0].Length; _y++) { if (fcp_matrix[_x][_y].Length < TraceLimit) { continue; } using_color = _color_array[(_x + _y) % _color_array.Length]; for (int i = 0; i < fcp_matrix[_x][_y].Length; i++) { if (fcp_matrix[_x][_y][i].AbcissLocation < 0 || fcp_matrix[_x][_y][i].OrdinateLocation < 0 || fcp_matrix[_x][_y][i].AbcissLocation >= width || fcp_matrix[_x][_y][i].OrdinateLocation >= height) { continue; } Result.SetPixel(fcp_matrix[_x][_y][i].AbcissLocation, fcp_matrix[_x][_y][i].OrdinateLocation, using_color); } } } return(Result); }
public override Bitmap GetDrawnBitmap(FractalAssociationParametrs FAP, object Extra = null) { check_all_functions(); int width=FAP.Width, height=FAP.Height; Bitmap Result = new Bitmap(width, height); ulong[][] Iter_matrix = FAP.Get2DOriginalIterationsMatrix(); //double maxiters= double[][] Ratio_matrix = FAP.Get2DRatioMatrix(); double[][] Radian_Matrix = ((RadianMatrix)FAP.GetUniqueParameter(typeof(RadianMatrix))).Matrix; BitmapData ResultData=Result.LockBits(new Rectangle(new Point(),Result.Size),ImageLockMode.WriteOnly,PixelFormat.Format32bppArgb); unsafe { double[] arg = new double[8]; int Parameter=-1; byte* blue = (byte*)&Parameter, green = blue + 1, red = green + 1; int* ptr = (int*)ResultData.Scan0.ToPointer(); int x, y; double* iter, ratio, radian,maxofiter,xloc,yloc; fixed(double* iterator = arg) { iter = iterator; ratio = iter + 1; radian = ratio + 1; maxofiter = radian + 1; xloc = maxofiter + 1; yloc = xloc + 1; arg[7] = height; arg[6] = width; *maxofiter = FAP.ItersCount; for (y = 0; y < height; ++y) { for (x = 0; x < width; ++x) { *iter = Iter_matrix[x][y]; *ratio = Ratio_matrix[x][y]; *radian = Radian_Matrix[x][y]; *xloc = x; *yloc = y; *red = (byte)(_m_red_func(arg)%256D); *green = (byte)(_m_green_func(arg) % 256D); *blue = (byte)(_m_blue_func(arg) % 256D); *(ptr++) = Parameter; } } } } Result.UnlockBits(ResultData); return Result; }
public override System.Drawing.Bitmap GetDrawnBitmap(FractalAssociationParametrs FAP, object Extra = null) { int width = FAP.Width, height = FAP.Height; Bitmap bmp = new Bitmap(width, height); double[][] dm = (double[][])FAP.Get2DRatioMatrix(); double[][][] trio_matrix = (double[][][])FAP.GetUniqueParameter(typeof(double[][][])); for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { bmp.SetPixel(x, y, Color.FromArgb(get_cos_color(trio_matrix[x][y][0],_red, _red_scale), get_cos_color(trio_matrix[x][y][1], _green, _green_scale), get_cos_color(trio_matrix[x][y][2], _blue, _blue_scale))); } } return bmp; }
public override System.Drawing.Bitmap GetDrawnBitmap(FractalAssociationParametrs FAP, object Extra = null) { int width = FAP.Width, height = FAP.Height; Bitmap bmp = new Bitmap(width, height); double[][] dm = (double[][])FAP.Get2DRatioMatrix(); double[][][] trio_matrix = (double[][][])FAP.GetUniqueParameter(typeof(double[][][])); for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { bmp.SetPixel(x, y, Color.FromArgb(get_cos_color(trio_matrix[x][y][0], _red, _red_scale), get_cos_color(trio_matrix[x][y][1], _green, _green_scale), get_cos_color(trio_matrix[x][y][2], _blue, _blue_scale))); } } return(bmp); }
public override System.Drawing.Bitmap GetDrawnBitmap(FractalAssociationParametrs FAP, object Extra = null) { if (FAP == null) { throw new ArgumentNullException("FAP не содержить значения!"); } if (!IsCompatible(FAP)) { throw new ArgumentException("Переданный FractalAssociationParameters не совместим с данной цветовой моделью, используйте другую цветовую модель!"); } if (FAP.FractalType != FractalType._2DStandartIterationTypeWithCloudPoints) { throw new ArgumentException("Данный фрактал не имеет трёхмерную матрицу FractalCloudPoint!"); } int width = FAP.Width, height = FAP.Height; Bitmap Result = new Bitmap(width, height); Graphics g = Graphics.FromImage(Result); g.FillRectangle(Brushes.Black, 0, 0, width, height); g.Dispose(); FractalCloudPoints fcps = (FractalCloudPoints)FAP.GetUniqueParameter(); FractalCloudPoint[][][] fcp_matrix = (FractalCloudPoint[][][])fcps.fractalCloudPoint; Color using_color; Random rand = new Random(); for (int _x = 0; _x < fcp_matrix.Length; _x++) { for (int _y = 0; _y < fcp_matrix[0].Length; _y++) { if (fcp_matrix[_x][_y].Length < fcps.MaxAmmountAtTrace) { continue; } using_color = Color.FromArgb(rand.Next(256), rand.Next(256), rand.Next(256)); for (int i = 0; i < fcp_matrix[_x][_y].Length; i++) { if (fcp_matrix[_x][_y][i].AbcissLocation < 0 || fcp_matrix[_x][_y][i].OrdinateLocation < 0 || fcp_matrix[_x][_y][i].AbcissLocation >= width || fcp_matrix[_x][_y][i].OrdinateLocation >= height) { continue; } Result.SetPixel(fcp_matrix[_x][_y][i].AbcissLocation, fcp_matrix[_x][_y][i].OrdinateLocation, using_color); } } } return(Result); }
private void Create_in_other_window(Fractal Fractal, int Width, int Height, int HorizontalStart, int VerticalStart, int SelectedWidth, int SelectedHeight, FractalDataHandlerControler Controler) { IsolatedFractalWindowsCreator OtherWindow = new IsolatedFractalWindowsCreator(Fractal, _fcm); OtherWindow.FractalToken += (fractal, fap) => { Disconnect(); _fractal = fractal; Connect(); _fap = fap; _width = fap.Width; _height = fap.Height; Controler.DeactivateHandlers(); Show(); }; OtherWindow.StartProcess(Width, Height, HorizontalStart, VerticalStart, SelectedWidth, SelectedHeight, UseSafeZoom); }
public override System.Drawing.Bitmap GetDrawnBitmap(FractalAssociationParametrs FAP, object Extra = null) { int width = FAP.Width, height = FAP.Height; Bitmap bmp = new Bitmap(width, height); double[][] dm = ((RadianMatrix)FAP.GetUniqueParameter(typeof(RadianMatrix))).Matrix; Color cl = Color.Black;; ulong[][] iter_matrix = FAP.Get2DOriginalIterationsMatrix(); ulong iter; int deg; for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { iter = (ulong)(iter_matrix[x][y] * 0.8); cl = Color.FromArgb((255 - iter / 1.85) >= 0 ? (int)(255 - iter / 1.85) : 0, (255 - iter / 1.4) >= 0 ? (int)(255 - iter / 1.4) : 0, (255 - iter / 1.8) >= 0 ? (int)(255 - iter / 1.8) : 0); bmp.SetPixel(x, y, cl); if (iter < 85) { deg = (int)((dm[x][y] / Math.PI) * 180); if (deg < 0) { deg = 360 + deg; } if (deg < 181) { cl = Color.FromArgb(255 - 255 * deg / 180, 255 - 255 * deg / 180, 255 - 255 * deg / 180); } else { deg -= 180; cl = Color.FromArgb(255 * deg / 180, 255 * deg / 180, 255 * deg / 180); } bmp.SetPixel(x, y, cl); } } } return(bmp); }
private void FractalCreatingFinishedHandler(Fractal f, FractalAssociationParametrs fap) { ThreadPool.QueueUserWorkItem((Parallel) => { if (_fap != null) { if ((ulong)_fap.Width * (ulong)_fap.Height * 4UL > int.MaxValue) { MessageBox.Show("Размер данного фрактала слишком велик, чтобы быть преобразованным в изображение!", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } _fap = fap; try { if (FractalShowing != null) { _owner.Invoke(FractalShowing, this); } Showing = true; Bitmap bmp = _fcm.GetDrawnBitmap(fap); if (_isactive) { _owner.Invoke(SetNewBitmap, bmp, _fpb); } Showing = false; if (FractalShowed != null) { _owner.Invoke(FractalShowed, this); } } catch { Showing = false; MessageBox.Show("При преобразовании фрактала в изображение произошла ошибка!", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); if (FractalRenderingFailed != null) { _owner.Invoke(FractalRenderingFailed, this); } //if ((ulong)_fap.Width * (ulong)_fap.Height * 4UL > int.MaxValue) MessageBox.Show("Размер данного фрактала слишком велик, чтобы быть преобразованным в изображение!","Ошибка",MessageBoxButtons.OK,MessageBoxIcon.Error); } Showing = false; GC.Collect(); }); }
/*_____________________________________________________________Реализация_абстрактных_методов____________________________________________________________*/ #region Realization abstract methods public override Bitmap GetDrawnBitmap(FractalAssociationParametrs FAP, object Extra = null) { if (!FAP.Is2D) { throw new ArgumentException("Данный цветовой режим может визуализировать только двухмерные фракталы!"); } int width = FAP.Width, height = FAP.Height, x, y; ulong[][] matrix = FAP._2DIterMatrix; Bitmap Result = new Bitmap(width, height, PixelFormat.Format24bppRgb); BitmapData ResultData = Result.LockBits(new Rectangle(new Point(), Result.Size), ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb); unsafe { int Parametr = -1; byte * Blue = (byte *)&Parametr, Green = Blue + 1, Red = Green + 1; int * ResultPtr = (int *)ResultData.Scan0.ToPointer(); double iter_count; for (y = 0; y < height; ++y) { for (x = 0; x < width; ++x) { iter_count = matrix[x][y]; *Red = (byte)(255 - (int)(iter_count * _red) % 256); *Green = (byte)(255 - (int)(iter_count * _green) % 256); *Blue = (byte)(255 - (int)(iter_count * _blue) % 256); *(ResultPtr++) = Parametr; } } } /*int y; * for (int x = 0; x < width; x++) * { * for (y = 0; y < height; y++) * { * iter_count = (int)matrix[x][y]; * Result.SetPixel(x, y, Color.FromArgb(255 - (int)(iter_count * _red) % 256, 255 - (int)(iter_count * _green) % 256,255- (int)(iter_count * _blue) % 256)); ; * } * }*/ Result.UnlockBits(ResultData); return(Result); }
/*_____________________________________________________________Реализация_абстрактных_методов____________________________________________________________*/ #region Realization abstract methods public override Bitmap GetDrawnBitmap(FractalAssociationParametrs FAP, object Extra = null) { if (!FAP.Is2D) { throw new ArgumentException("Данный цветовой режим может визуализировать только двухмерные фракталы!"); } int width = FAP.Width, height = FAP.Height, x, y = 0; ulong[][] matrix = FAP._2DIterMatrix; int iter_count; Bitmap Result = new Bitmap(width, height, PixelFormat.Format24bppRgb); BitmapData ResultData = Result.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb); unsafe { int * pointer = (int *)ResultData.Scan0; int parameter = -1; byte *red = (byte *)¶meter, green = red + 1, blue = green + 1; for (y = 0; y < height; y++) { for (x = 0; x < width; x++) { iter_count = (int)matrix[x][y]; *red = (byte)((iter_count * _red) % 256); *green = (byte)((iter_count * _green) % 256); *blue = (byte)((iter_count * _blue) % 256); *(pointer++) = parameter; } } } /*int y; * for(int x=0;x<width;x++) * { * for(y=0;y<height;y++) * { * iter_count = (int)matrix[x][y]; * Result.SetPixel(x, y, Color.FromArgb((int)(iter_count*_red)%256,(int)(iter_count*_green)%256,(int)(iter_count*_blue)%256));; * } * }*/ Result.UnlockBits(ResultData); return(Result); }
/*__________________________________________________________Конструкторы_класса_________________________________________________________________*/ #region Constructors public FractalDataHandler(Control Owner, Fractal Fractal, FractalPictureBox FPB, FractalColorMode FCM, Size Size, FractalAssociationParametrs FAP = null) { if (Owner == null || Fractal == null || FPB == null || FCM == null) { throw new ArgumentNullException("Нельзя передавать пустые значения!"); } if (Size.Width < 1 || Size.Height < 1) { throw new ArgumentException("Ширина и Высота не могут быть меньше единицы!"); } _fractal = Fractal; _fpb = FPB; _fcm = FCM; _width = Size.Width; _height = Size.Height; _fap = FAP; _owner = Owner; Connect(); }
/*__________________________________________________________________Реализация_абстрактных_методов_______________________________________________________*/ #region Realization abstract methods public override Bitmap GetDrawnBitmap(FractalAssociationParametrs FAP, object Extra = null) { int width = FAP.Width, height = FAP.Height, x, y; Bitmap Result = new Bitmap(width, height, PixelFormat.Format24bppRgb); BitmapData ResultData = Result.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb); ulong[][] iter_matrix = FAP.Get2DOriginalIterationsMatrix(); double iter; unsafe { int * pointer = (int *)ResultData.Scan0; int parameter = -1; byte *blue = (byte *)¶meter, green = blue + 1, red = green + 1; for (y = 0; y < height; y++) { for (x = 0; x < width; x++) { iter = (iter_matrix[x][y] * Muller); *red = (255 - iter / Red) >= 0D ? (byte)(255 - iter / Red) : (byte)0; *green = (255 - iter / Green) >= 0D ? (byte)(255 - iter / Green) : (byte)0; *blue = (255 - iter / Blue) >= 0D ? (byte)(255 - iter / Blue) : (byte)0; *(pointer++) = parameter; } } } Result.UnlockBits(ResultData); /*for(x=0;x<width;x++) * { * for(y=0;y<height;y++) * { * iter = (ulong)(iter_matrix[x][y]*Muller); * Result.SetPixel(x, y, Color.FromArgb((255 - iter / Red) >= 0 ? (int)(255 - iter / Red) : 0, * (255 - iter / Green) >= 0 ? (int)(255 - iter / Green) : 0, * (255 - iter / Blue) >= 0 ? (int)(255 - iter / Blue) : 0)); * } * }*/ return(Result); }
public void StartProcess(int Width,int Height) { if (Width < 1 || Height < 1) return; this.Show(); this.Text = this.Text + " (" + Width + "x" + Height + ")"; _fractal.MaxPercent = progressBar1.Maximum; Action<ProgressBar, int> SetProcessProgress = (bar, percent) => { bar.Increment(percent - bar.Value); }; _fractal.ProgressChanged += (sender, percent) => { Invoke(SetProcessProgress,progressBar1,percent); }; Action<Button> SetButton = (button) => { button.Text = "Забрать"; button2.Visible = true; button.Click -= First_main_button_Click_Worker; button.Click += (sender, e) => { if (FractalToken != null)FractalToken(_fractal, _fap); this.Dispose(); }; }; _fractal.ParallelFractalCreatingFinished += (fractal, FAP) => {if (FractalReady != null)Invoke(FractalReady, fractal, FAP); _fap = FAP; Invoke(SetButton, button1); Fractal.ClearProgressChangedEvents(fractal); Fractal.ClearParallelFractalCreatingFinishedEvents(fractal); }; _fractal.CreateParallelFractal(Width, Height); }
public override Bitmap GetDrawnBitmap(FractalAssociationParametrs FAP,object Extra=null) { if (!FAP.Is2D) throw new ArgumentException("Данный цветовой режим может визуализировать только двухмерные фракталы!"); int width=FAP.Width, height=FAP.Height,x,y=0; ulong[][] matrix = FAP._2DIterMatrix; int iter_count; Bitmap Result = new Bitmap(width, height,PixelFormat.Format24bppRgb); BitmapData ResultData = Result.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb); unsafe { int* pointer = (int*)ResultData.Scan0; int parameter = -1; byte* red = (byte*)¶meter, green = red + 1, blue = green + 1; for (y = 0; y < height; y++) { for (x = 0; x < width; x++) { iter_count = (int)matrix[x][y]; *red = (byte)((iter_count * _red) % 256); *green = (byte)((iter_count * _green) % 256); *blue = (byte)((iter_count * _blue) % 256); *(pointer++) = parameter; } } } /*int y; for(int x=0;x<width;x++) { for(y=0;y<height;y++) { iter_count = (int)matrix[x][y]; Result.SetPixel(x, y, Color.FromArgb((int)(iter_count*_red)%256,(int)(iter_count*_green)%256,(int)(iter_count*_blue)%256));; } }*/ Result.UnlockBits(ResultData); return Result; }
public override Bitmap GetDrawnBitmap(FractalAssociationParametrs FAP, object Extra = null) { if (!FAP.Is2D) throw new ArgumentException("Данный цветовой режим может визуализировать только двухмерные фракталы!"); int width = FAP.Width, height = FAP.Height,x,y; ulong[][] matrix = FAP._2DIterMatrix; Bitmap Result = new Bitmap(width, height,PixelFormat.Format24bppRgb); BitmapData ResultData = Result.LockBits(new Rectangle(new Point(), Result.Size), ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb); unsafe { int Parametr = -1; byte* Blue = (byte*)&Parametr, Green = Blue + 1, Red = Green + 1; int* ResultPtr = (int*)ResultData.Scan0.ToPointer(); double iter_count; for(y=0;y<height;++y) { for(x=0;x<width;++x) { iter_count = matrix[x][y]; *Red = (byte)(255 - (int)(iter_count * _red) % 256); *Green = (byte)(255 - (int)(iter_count * _green) % 256); *Blue = (byte)(255 - (int)(iter_count * _blue) % 256); *(ResultPtr++) = Parametr; } } } /*int y; for (int x = 0; x < width; x++) { for (y = 0; y < height; y++) { iter_count = (int)matrix[x][y]; Result.SetPixel(x, y, Color.FromArgb(255 - (int)(iter_count * _red) % 256, 255 - (int)(iter_count * _green) % 256,255- (int)(iter_count * _blue) % 256)); ; } }*/ Result.UnlockBits(ResultData); return Result; }
private void _finish_creating(Fractal f,FractalAssociationParametrs fap) { _fractal.f_parallel_canceled -= _end_creating; _fractal.ParallelFractalCreatingFinished -= _finish_creating; }
object IColorReturnable.Optimize(FractalAssociationParametrs FAP, object Extra) { return FAP._2DIterMatrix; }
public override bool IsCompatible(FractalAssociationParametrs FAP) { return(FAP.Is2D && FAP.Get2DRatioMatrix() is double[][]); }
public override bool IsCompatible(FractalAssociationParametrs FAP) { return FAP.Is2D && FAP.GetUniqueParameter(typeof(double[][][])) != null; }
object IColorReturnable.Optimize(FractalAssociationParametrs FAP, object Extra) { return(null); }
object IColorReturnable.Optimize(FractalAssociationParametrs FAP, object Extra) { return(FAP._2DIterMatrix); }
public object Optimize(FractalAssociationParametrs FAP, object Extra = null) { return FAP.Get2DOriginalIterationsMatrix(); }
private void Create_in_other_window(Fractal Fractal, int Width, int Height, int HorizontalStart, int VerticalStart, int SelectedWidth, int SelectedHeight, FractalDataHandlerControler Controler) { IsolatedFractalWindowsCreator OtherWindow = new IsolatedFractalWindowsCreator(Fractal,_fcm); OtherWindow.FractalToken += (fractal, fap) => { Disconnect(); _fractal = fractal; Connect(); _fap = fap; _width = fap.Width; _height = fap.Height; Controler.DeactivateHandlers(); Show(); }; OtherWindow.StartProcess(Width, Height,HorizontalStart,VerticalStart,SelectedWidth,SelectedHeight,UseSafeZoom); }
public object Optimize(FractalAssociationParametrs FAP, object Extra = null) { return(FAP.Get2DOriginalIterationsMatrix()); }
public override System.Drawing.Bitmap GetDrawnBitmap(FractalAssociationParametrs FAP, object Extra = null) { int width = FAP.Width, height = FAP.Height; Bitmap Result = new Bitmap(width, height); ulong iter, grad_void_iters = _gradient_void_iterations_count+_gradient_iterations_count; ulong[][] iter_matrix = FAP.Get2DOriginalIterationsMatrix(); double[][] Radian_matrix = ((RadianMatrix)FAP.GetUniqueParameter(typeof(RadianMatrix))).Matrix; int deg; Color color; _optimizer = _using_mod.Optimize(FAP); for(int x=0;x<width;x++) { for(int y=0;y<height;y++) { deg=((int)((Radian_matrix[x][y]/Math.PI)*180D)+360)%360; iter=iter_matrix[x][y]; if (iter <= _gradient_iterations_count) color = cycle_get_gradient_color(_percents, _color, deg); else if (iter <= grad_void_iters) color = _gradient_void; else color = _using_mod.GetColor(_optimizer, x, y); Result.SetPixel(x, y, color); } } return Result; }
/// <summary> /// Вызывает событие ParallelFractalCreatingFinished. /// </summary> /// <param name="FAP">Экземпляр готового фрактала.</param> protected void f_activate_ParallelFractalCreatingFinished(FractalAssociationParametrs FAP) { if (ParallelFractalCreatingFinished != null) ParallelFractalCreatingFinished(this, FAP); }
public override bool IsCompatible(FractalAssociationParametrs FAP) { return(FAP.Is2D && FAP.GetUniqueParameter(typeof(RadianMatrix)) != null); }
public override bool IsCompatible(FractalAssociationParametrs FAP) { return FAP.Is2D && FAP.Get2DRatioMatrix() is double[][]; }
/*_________________________________________________Общедостуные_абстрактные_методы_класса__________________________________________________*/ #region Public abstract methods /// <summary> /// Возвращает экземпляр класса Bitmap, в котором был визуализирован фрактал. /// </summary> /// <param name="FAP">FractalAssociationParameters содержащий фрактал, который нужно визуализировать.</param> /// <returns>Экземпляр класса Bitmap, в котором был визуализирован фрактал.</returns> public abstract Bitmap GetDrawnBitmap(FractalAssociationParametrs FAP, object Extra = null);
object IColorReturnable.Optimize(FractalAssociationParametrs FAP, object Extra) { return null; }
object IColorReturnable.Optimize(FractalAssociationParametrs FAP, object Extra) { return(FAP.Get2DOriginalIterationsMatrix()); }
public override bool IsCompatible(FractalAssociationParametrs FAP) { return(FAP.Is2D); }
private void list_up(FractalAssociationParametrs fap) { }
private void _finish_creating(Fractal f, FractalAssociationParametrs fap) { _fractal.f_parallel_canceled -= _end_creating; _fractal.ParallelFractalCreatingFinished -= _finish_creating; }
public void StartProcess(int Width,int Height,int HorizontalStart,int VerticalStart,int SelectedWidth,int SelectedHeight,bool UseSafeZoom=false) { this.Show(); this.Text = this.Text + " (" + Width + "x" + Height + ")"; _fractal.MaxPercent = progressBar1.Maximum; Action<ProgressBar, int> SetProcessProgress = (bar, percent) => { bar.Increment(percent - bar.Value); }; _fractal.ProgressChanged += (sender, percent) => { Invoke(SetProcessProgress, progressBar1, percent); }; Action<Button> SetButton = (button) => { button.Text = "Забрать"; button.Click -= First_main_button_Click_Worker; button.Click += (sender, e) => { if (FractalToken != null)FractalToken(_fractal, _fap); this.Dispose(); }; button2.Visible = true; }; _fractal.ParallelFractalCreatingFinished += (fractal, FAP) => { if(FractalReady!=null)Invoke(FractalReady, fractal, FAP); _fap = FAP; Invoke(SetButton, button1); }; _fractal.CreateParallelFractal(Width, Height,HorizontalStart,VerticalStart,SelectedWidth,SelectedHeight,UseSafeZoom); }
public void finish(Fractal fr, FractalAssociationParametrs fap) { _fractal.f_parallel_canceled -= _cancel; _fractal.ParallelFractalCreatingFinished -= finish; }
public override bool IsCompatible(FractalAssociationParametrs FAP) { return FAP.Is2D; }
public override BigInteger[] FindFirstInserts(BigInteger Width, BigInteger Height, ulong MinIters) { int width = (int)Width; int height = (int)Height; _2DFractal temp = (_2DFractal)this.GetClone(); FractalAssociationParametrs fap = temp.CreateFractal(width, height); BigInteger[] Result = new BigInteger[4]; bool con = true; ulong[][] itermatrix = fap.Get2DOriginalIterationsMatrix(); for (int x = 0; x < width && con; x++) { for (int y = 0; y < height; y++) { if (itermatrix[x][y] >= MinIters) { con = false; Result[0] = x; break; } } } if (con) { Result[0] = -1; } con = true; for (int x = width - 1; x >= 0 && con; x--) { for (int y = 0; y < height; y++) { if (itermatrix[x][y] >= MinIters) { con = false; Result[1] = x; break; } } } if (con) { Result[1] = -1; } con = true; for (int y = height - 1; y >= 0 && con; y--) { for (int x = 0; x < width; x++) { if (itermatrix[x][y] >= MinIters) { con = false; Result[3] = y; break; } } } if (con) { Result[3] = -1; } con = true; for (int y = 0; y < height && con; y++) { for (int x = 0; x < width; x++) { if (itermatrix[x][y] >= MinIters) { con = false; Result[2] = y; break; } } } if (con) { Result[2] = -1; } con = true; return(Result); }
public override bool IsCompatible(FractalAssociationParametrs FAP) { return FAP.GetUniqueParameter(typeof(RadianMatrix)) != null && FAP.Get2DRatioMatrix() != null; }
private void JuliaSearcher_Load(object sender, EventArgs e) { fpb1 = new FractalPictureBox(); fpb1.SizeMode = PictureBoxSizeMode.AutoSize; fpb1.ContextMenuStrip = contextMenuStrip1; if(_m_fcm==null)_m_fcm = new Simple2DFractalColorMode(); panel1.Controls.Add(fpb1); fpb1.ToClickMode(); if(_mandelbrot==null)_mandelbrot = new Mandelbrot(); _m_fap = _mandelbrot.CreateFractal(panel1.Width, panel1.Height); fpb1.Image = _m_fcm.GetDrawnBitmap(_m_fap); fpb1.MouseMove += (_sender, _e) => {label1.Text = _get_complex_loc(_mandelbrot,_e.X,_e.Y).ToString(); }; fpb2 = new FractalPictureBox(); fpb2.SizeMode = PictureBoxSizeMode.AutoSize; panel2.Controls.Add(fpb2); fpb1.MouseDown += (_sender, _e) => { if (!clickable) return; if (_e.Button != MouseButtons.Left) return; _using_complex = _get_complex_loc(_mandelbrot, _e.X, _e.Y); label2.Text=_using_complex.ToString(); _julia.SetComplex(_using_complex); fpb2.Image = _j_fcm.GetDrawnBitmap(((_2DFractal)_julia).CreateFractal(panel2.Width, panel2.Height)); }; fpb2.RectangleSelected += (_sender, rec) => { ((_2DFractal)_julia).CreateParallelFractal(panel2.Width, panel2.Height, rec.X, rec.Y, rec.Width, rec.Height, true); }; ((_2DFractal)_julia).ParallelFractalCreatingFinished += (s, fap) => { Action<Bitmap> act=(bmp)=>{fpb2.Image=bmp;}; Invoke(act, _j_fcm.GetDrawnBitmap(fap)); }; fpb2.SelectionPen = null; fpb1.RectangleSelected += (_s, rec) => { _mandelbrot.CreateParallelFractal(panel1.Width, panel1.Height, rec.X, rec.Y, rec.Width, rec.Height,true); }; _mandelbrot.ParallelFractalCreatingFinished += (s, fap) => { Action<Bitmap> act = (bmp) => { fpb1.Image = bmp; }; Invoke(act, _m_fcm.GetDrawnBitmap(fap)); }; fpb2.ContextMenuStrip = contextMenuStrip2; fpb1.SelectionPen = null; clickable = true; _fpb1_h_scale = this.Width / (double)panel1.Width; _fpb1_v_scale = this.Height / (double)panel1.Height; _fpb2_h_scale = this.Width / (double)panel2.Width; _fpb2_v_scale = this.Height / (double)panel2.Height; oldheight = panel1.Height; oldwidth = panel1.Width; вРежимВращенияToolStripMenuItem.Visible = вРежимВращенияToolStripMenuItem.Enabled = _mandelbrot is IUsingQuaternion; }
public abstract bool IsCompatible(FractalAssociationParametrs FAP);
public void finish(Fractal fr,FractalAssociationParametrs fap) { _fractal.f_parallel_canceled -= _cancel; _fractal.ParallelFractalCreatingFinished -= finish; }
private void FractalCreatingFinishedHandler(Fractal f,FractalAssociationParametrs fap) { ThreadPool.QueueUserWorkItem((Parallel) => { if (_fap != null) if ((ulong)_fap.Width * (ulong)_fap.Height * 4UL > int.MaxValue) { MessageBox.Show("Размер данного фрактала слишком велик, чтобы быть преобразованным в изображение!", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } _fap = fap; try { if (FractalShowing != null) _owner.Invoke(FractalShowing,this); Showing = true; Bitmap bmp = _fcm.GetDrawnBitmap(fap); if(_isactive)_owner.Invoke(SetNewBitmap, bmp, _fpb); Showing = false; if (FractalShowed != null)_owner.Invoke(FractalShowed,this); } catch { Showing = false; MessageBox.Show("При преобразовании фрактала в изображение произошла ошибка!", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); if (FractalRenderingFailed != null) _owner.Invoke(FractalRenderingFailed,this); //if ((ulong)_fap.Width * (ulong)_fap.Height * 4UL > int.MaxValue) MessageBox.Show("Размер данного фрактала слишком велик, чтобы быть преобразованным в изображение!","Ошибка",MessageBoxButtons.OK,MessageBoxIcon.Error); } Showing = false; GC.Collect(); }); }
/// <summary> /// Возвращает экземпляр класса Bitmap, в котором был визуализирован фрактал. /// </summary> /// <param name="FAP">FractalAssociationParameters содержащий фрактал, который нужно визуализировать.</param> /// <returns>Экземпляр класса Bitmap, в котором был визуализирован фрактал.</returns> public abstract Bitmap GetDrawnBitmap(FractalAssociationParametrs FAP,object Extra=null);
public override bool IsCompatible(FractalAssociationParametrs FAP) { if (FAP == null) throw new ArgumentNullException("Нельзя передавать значение null в данный метод!"); return FAP.Is2D && (FAP.GetUniqueParameter() is FractalCloudPoints); }
public abstract bool IsCompatible(FractalAssociationParametrs FAP);