protected virtual _2DFractalHelper m_create_fractal_double_version(int width, int height) { _2DFractalHelper fractal_helper = new _2DFractalHelper(this, width, height); Action <object> act = (abc) => { _m_create_part_of_fractal((AbcissOrdinateHandler)abc, fractal_helper); }; AbcissOrdinateHandler[] p_aoh = fractal_helper.CreateDataForParallelWork(f_number_of_using_threads_for_parallel); Task[] ts = new Task[f_number_of_using_threads_for_parallel]; fractal_helper.GiveUnique(new RadianMatrix(width)); for (int i = 0; i < ts.Length; i++) { ts[i] = new Task(act, p_aoh[i]); ts[i].Start(); } for (int i = 0; i < ts.Length; i++) { ts[i].Wait(); } return(fractal_helper); }
/*________________________________________________________Частные_методы_для_реализации_класса____________________________________________________________*/ #region Private methods for realizations protected virtual _2DFractalHelper _create_fractal_double_version(int Width, int Height) { ulong iterations_count = f_iterations_count, iteration; _2DFractalHelper fractal_helper = new _2DFractalHelper(this, Width, Height); ulong[][] matrix = fractal_helper.CommonMatrix; double[] abciss_points = fractal_helper.AbcissRealValues, ordinate_points = fractal_helper.OrdinateRealValues; double abciss_point, p, _2d3d = 2d / 3d; int percent_length = fractal_helper.PercentLength, _current_percent = percent_length; AbcissOrdinateHandler aoh = fractal_helper.AOH; Complex z = new Complex(), t = new Complex(), d = new Complex(); for (; aoh.abciss < Width; aoh.abciss++) { abciss_point = abciss_points[aoh.abciss]; for (aoh.ordinate = 0; aoh.ordinate < Height; aoh.ordinate++) { z.Real = abciss_point; z.Imagine = ordinate_points[aoh.ordinate]; d.Real = z.Real; d.Imagine = z.Imagine; for (iteration = 0; iteration <= iterations_count && (z.Real * z.Real + z.Imagine * z.Imagine <= 1000000) && (d.Real * d.Real + d.Imagine * d.Imagine > 0.000001); iteration++) { t.Real = z.Real; t.Imagine = z.Imagine; p = Math.Pow(t.Real * t.Real + t.Imagine + t.Imagine, 2); z.Real = _2d3d * t.Real + (t.Real * t.Real - t.Imagine * t.Imagine) / (3 * p); z.Imagine = _2d3d * t.Imagine * (1 - t.Real / p); d.Real = Math.Abs(z.Real - t.Real); d.Imagine = Math.Abs(z.Imagine - t.Imagine); } matrix[aoh.abciss][aoh.ordinate] = iteration; } if ((--_current_percent) == 0) { _current_percent = percent_length; f_new_percent_in_parallel_activate(); } } return(fractal_helper); }
protected override _2DFractal._2DFractalHelper m_create_fractal_double_version(int width, int height) { _2DFractalHelper fractal_helper = new _2DFractalHelper(this, width, height); Action<object> act = (abc) => { _m_create_part_of_fractal((AbcissOrdinateHandler)abc, fractal_helper); }; AbcissOrdinateHandler[] p_aoh = fractal_helper.CreateDataForParallelWork(f_number_of_using_threads_for_parallel); Task[] ts = new Task[f_number_of_using_threads_for_parallel]; FractalCloudPoints fcps=new FractalCloudPoints(_max_ammount_at_trace,new FractalCloudPoint[width/_abciss_step_length+(width%_abciss_step_length!=0?1:0)][][]); fractal_helper.GiveUnique(fcps); fractal_helper.GiveUnique(new RadianMatrix(width)); for (int i = 0; i < ts.Length; i++) { ts[i] = new Task(act, p_aoh[i]); ts[i].Start(); } for (int i = 0; i < ts.Length; i++) { ts[i].Wait(); } fcps.Clear(); return fractal_helper; }
protected virtual _2DFractalHelper _create_fractal_double_version(int Width,int Height) { ulong iterations_count = f_iterations_count,iteration; _2DFractalHelper fractal_helper = new _2DFractalHelper(this, Width, Height); ulong[][] matrix = fractal_helper.CommonMatrix; double[] abciss_points = fractal_helper.AbcissRealValues, ordinate_points = fractal_helper.OrdinateRealValues; double abciss_point,p,_2d3d=2d/3d; int percent_length=fractal_helper.PercentLength, _current_percent=percent_length; AbcissOrdinateHandler aoh = fractal_helper.AOH; Complex z=new Complex(), t=new Complex(), d=new Complex(); for(;aoh.abciss<Width;aoh.abciss++) { abciss_point = abciss_points[aoh.abciss]; for(aoh.ordinate=0;aoh.ordinate<Height;aoh.ordinate++) { z.Real = abciss_point; z.Imagine = ordinate_points[aoh.ordinate]; d.Real = z.Real; d.Imagine = z.Imagine; for(iteration=0;iteration<=iterations_count&&(z.Real * z.Real + z.Imagine * z.Imagine <= 1000000)&&(d.Real*d.Real+d.Imagine*d.Imagine>0.000001);iteration++) { t.Real = z.Real; t.Imagine = z.Imagine; p=Math.Pow(t.Real * t.Real + t.Imagine + t.Imagine, 2); z.Real = _2d3d * t.Real + (t.Real * t.Real - t.Imagine * t.Imagine) / (3 * p); z.Imagine = _2d3d * t.Imagine * (1 - t.Real / p); d.Real = Math.Abs(z.Real - t.Real); d.Imagine = Math.Abs(z.Imagine - t.Imagine); } matrix[aoh.abciss][aoh.ordinate] = iteration; } if((--_current_percent)==0) { _current_percent = percent_length; f_new_percent_in_parallel_activate(); } } return fractal_helper; }
//protected override Fractal.fractal_resume_data get_resume_data() //{ // return new julia_resume_data(_2df_imagine_left, _2df_imagine_top,j_complex_const); //} #endregion /Realization of abstract methods /*___________________________________________________________Частные_методы_класса____________________________________________________________*/ #region Private methods for realization protected virtual _2DFractalHelper _j_parallel_create_fractal_double_version(int width, int height) { ulong max_iterations = f_iterations_count, iterations; _2DFractalHelper fractal_helper = new _2DFractalHelper(this, width, height); AbcissOrdinateHandler aoh = fractal_helper.AOH; ulong[][] result_matrix = fractal_helper.CommonMatrix; int percent_length = fractal_helper.PercentLength, percent_counter = percent_length; double[] abciss_points = fractal_helper.AbcissRealValues, ordinate_points = fractal_helper.OrdinateRealValues; double abciss_point; Complex complex_iterator = new Complex(); for (; aoh.abciss < width; ++aoh.abciss) { abciss_point = abciss_points[aoh.abciss]; for (; aoh.ordinate < height; ++aoh.ordinate) { complex_iterator.Real = abciss_point; complex_iterator.Imagine = ordinate_points[aoh.ordinate]; for (iterations = 0; (complex_iterator.Real * complex_iterator.Real + complex_iterator.Imagine * complex_iterator.Imagine) < 4D && iterations < max_iterations; ++iterations) { complex_iterator.tsqr(); complex_iterator.Real += j_complex_const.Real; complex_iterator.Imagine += j_complex_const.Imagine; } result_matrix[aoh.abciss][aoh.ordinate] = iterations; } aoh.ordinate = 0; if ((--percent_counter) == 0) { percent_counter = percent_length; f_new_percent_in_parallel_activate(); } } fractal_helper.GiveUnique(j_complex_const); return(fractal_helper); }
protected override _2DFractal._2DFractalHelper m_create_fractal_double_version(int width, int height) { _2DFractalHelper fractal_helper = new _2DFractalHelper(this, width, height); Action <object> act = (abc) => { _m_create_part_of_fractal((AbcissOrdinateHandler)abc, fractal_helper); }; AbcissOrdinateHandler[] p_aoh = fractal_helper.CreateDataForParallelWork(f_number_of_using_threads_for_parallel); Task[] ts = new Task[f_number_of_using_threads_for_parallel]; FractalCloudPoints fcps = new FractalCloudPoints(_max_ammount_at_trace, new FractalCloudPoint[width / _abciss_step_length + (width % _abciss_step_length != 0?1:0)][][]); fractal_helper.GiveUnique(fcps); fractal_helper.GiveUnique(new RadianMatrix(width)); for (int i = 0; i < ts.Length; i++) { ts[i] = new Task(act, p_aoh[i]); ts[i].Start(); } for (int i = 0; i < ts.Length; i++) { ts[i].Wait(); } fcps.Clear(); return(fractal_helper); }
/*__________________________________________________________Защищённые_методы_для_реализации___________________________________________________________*/ #region Protected methods for realization protected virtual _2DFractalHelper m_old_create_fractal_double_version(int width, int height) { ulong iter_count = f_iterations_count, iteration; _2DFractalHelper fractal_helper = new _2DFractalHelper(this, width, height); AbcissOrdinateHandler aoh = fractal_helper.AOH; ulong[][] matrix = fractal_helper.CommonMatrix; double[] abciss_points = fractal_helper.AbcissRealValues, ordinate_points = fractal_helper.OrdinateRealValues; double abciss_point; int percent_length = fractal_helper.PercentLength, current_percent = percent_length; Complex z = new Complex(), z0 = new Complex(); for (; aoh.abciss < width; aoh.abciss++) { abciss_point = abciss_points[aoh.abciss]; for (aoh.ordinate = 0; aoh.ordinate < height; aoh.ordinate++) { z0.Real = abciss_point; z0.Imagine = ordinate_points[aoh.ordinate]; z.Real = z0.Real; z.Imagine = z0.Imagine; for (iteration = 0; iteration < iter_count && (z.Real * z.Real + z.Imagine * z.Imagine) < 4D; iteration++) { z.tsqr(); z.Real += z0.Real; z.Imagine += z0.Imagine; } matrix[aoh.abciss][aoh.ordinate] = iteration; if ((--current_percent) == 0) { current_percent = percent_length; f_new_percent_in_parallel_activate(); } } } return(fractal_helper); }
/*__________________________________________________________________Частные_методы_класса_____________________________________________________________*/ #region Private methods private _2DFractalHelper CreateFractalInParralels(int Width, int Height) { _2DFractalHelper fractal_helper = new _2DFractalHelper(this, Width, Height); fractal_helper.GiveUnique(new double[Width][][]); Task[] tasks = new Task[f_number_of_using_threads_for_parallel]; AbcissOrdinateHandler[] aohs = fractal_helper.CreateDataForParallelWork(f_number_of_using_threads_for_parallel); Action <object> act = (aoh) => { Create_part_of_fractal(fractal_helper, (AbcissOrdinateHandler)aoh); }; //fractal_helper.AOH.end_of_abciss = Width; //fractal_helper.AOH.end_of_ordinate = Height; // Create_part_of_fractal(fractal_helper, fractal_helper.AOH); for (int i = 0; i < tasks.Length; i++) { tasks[i] = new Task(act, aohs[i]); tasks[i].Start(); } for (int i = 0; i < tasks.Length; i++) { tasks[i].Wait(); tasks[i].Dispose(); } return(fractal_helper); }
protected virtual void _m_create_part_of_fractal(AbcissOrdinateHandler p_aoh, _2DFractalHelper fractal_helper) { ulong iter_count = f_iterations_count, iteration; ulong[][] matrix = fractal_helper.CommonMatrix; double[] abciss_points = fractal_helper.AbcissRealValues, ordinate_points = fractal_helper.OrdinateRealValues; double abciss_point, dist, pdist = 0D; double[][] Ratio_matrix = (double[][])fractal_helper.GetRatioMatrix(); int percent_length = fractal_helper.PercentLength, current_percent = percent_length; Complex z = new Complex(), z0 = new Complex(), last_valid_z = new Complex(); double[][] Radian_matrix = ((RadianMatrix)fractal_helper.GetUnique(typeof(RadianMatrix))).Matrix; int height = ordinate_points.Length; for (; p_aoh.abciss < p_aoh.end_of_abciss; p_aoh.abciss++) { abciss_point = abciss_points[p_aoh.abciss]; Radian_matrix[p_aoh.abciss] = new double[height]; for (; p_aoh.ordinate < p_aoh.end_of_ordinate; ++p_aoh.ordinate) { z0.Real = abciss_point; z0.Imagine = ordinate_points[p_aoh.ordinate]; z.Real = z0.Real; z.Imagine = z0.Imagine; dist = 0D; for (iteration = 0; iteration < iter_count && dist < 4D; iteration++) { pdist = dist; last_valid_z.Real = z.Real; last_valid_z.Imagine = z.Imagine; z.tsqr(); z.Real += z0.Real; z.Imagine += z0.Imagine; dist = (z.Real * z.Real + z.Imagine * z.Imagine); } Ratio_matrix[p_aoh.abciss][p_aoh.ordinate] = pdist; matrix[p_aoh.abciss][p_aoh.ordinate] = iteration; Radian_matrix[p_aoh.abciss][p_aoh.ordinate] = Math.Atan2(last_valid_z.Imagine, last_valid_z.Real); } p_aoh.ordinate = 0; if ((--current_percent) == 0) { current_percent = percent_length; f_new_percent_in_parallel_activate(); } } }
protected virtual void inc_create_part_of_fractal(AbcissOrdinateHandler p_aoh, _2DFractalHelper fractal_helper) { ulong iter_count = f_iterations_count, iteration; ulong[][] matrix = fractal_helper.CommonMatrix; double[] abciss_points = fractal_helper.AbcissRealValues, ordinate_points = fractal_helper.OrdinateRealValues; double abciss_point, dist, pdist = 0D; double[][] Ratio_matrix = (double[][])fractal_helper.GetRatioMatrix(); int percent_length = fractal_helper.PercentLength, current_percent = percent_length; double[][] Radian_matrix = ((RadianMatrix)fractal_helper.GetUnique(typeof(RadianMatrix))).Matrix; int height = ordinate_points.Length; double cosrad = Math.Cos(inc_rotater.Radian), sinrad = Math.Sin(inc_rotater.Radian); Triplex z = new Triplex(), z0 = (Triplex)inc_const.Clone(), last_valid_z = new Triplex(); inc_rotater.Rotate(z0); for (; p_aoh.abciss < p_aoh.end_of_abciss; p_aoh.abciss++) { abciss_point = abciss_points[p_aoh.abciss]; Radian_matrix[p_aoh.abciss] = new double[height]; for (; p_aoh.ordinate < p_aoh.end_of_ordinate; ++p_aoh.ordinate) { z.x = abciss_point; z.y = ordinate_points[p_aoh.ordinate]; z.z = 0; inc_rotater.Rotate(z); dist = 0D; for (iteration = 0; iteration < iter_count && dist < 4D; iteration++) { pdist = dist; last_valid_z.x = z.x; last_valid_z.y = z.y; last_valid_z.z = z.z; z.tsqr(); z.tadd(z0); dist = (z.x * z.x + z.y * z.y + z.z * z.z); } Ratio_matrix[p_aoh.abciss][p_aoh.ordinate] = pdist; matrix[p_aoh.abciss][p_aoh.ordinate] = iteration; Radian_matrix[p_aoh.abciss][p_aoh.ordinate] = Math.Atan2(last_valid_z.y, last_valid_z.x) * cosrad + sinrad * Math.Atan2(last_valid_z.z, last_valid_z.x); } p_aoh.ordinate = 0; if ((--current_percent) == 0) { current_percent = percent_length; f_new_percent_in_parallel_activate(); } } }
private _2DFractalHelper CreateFractalInParralels(int Width,int Height) { _2DFractalHelper fractal_helper = new _2DFractalHelper(this, Width, Height); fractal_helper.GiveUnique(new double[Width][][]); Task[] tasks = new Task[f_number_of_using_threads_for_parallel]; AbcissOrdinateHandler[] aohs = fractal_helper.CreateDataForParallelWork(f_number_of_using_threads_for_parallel); Action<object> act = (aoh) => { Create_part_of_fractal(fractal_helper, (AbcissOrdinateHandler)aoh); }; //fractal_helper.AOH.end_of_abciss = Width; //fractal_helper.AOH.end_of_ordinate = Height; // Create_part_of_fractal(fractal_helper, fractal_helper.AOH); for (int i = 0; i < tasks.Length;i++ ) { tasks[i] = new Task(act, aohs[i]); tasks[i].Start(); } for (int i = 0; i < tasks.Length;i++ ) { tasks[i].Wait(); tasks[i].Dispose(); } return fractal_helper; }
private void Create_part_of_fractal(_2DFractalHelper fractal_helper,AbcissOrdinateHandler p_aoh) { ulong iterations; int percent_length=fractal_helper.PercentLength, current_percent=percent_length,trio_height; ulong[][] iter_matrix = fractal_helper.CommonMatrix; double[] abciss_points = fractal_helper.AbcissRealValues, ordinate_points = fractal_helper.OrdinateRealValues; double abciss_point,ratio,lratio; double[][] Ratio_matrix = fractal_helper.GetRatioMatrix(); double[][][] trio_matrix = (double[][][])fractal_helper.GetUnique(typeof(double[][][])); double v1, v2, v3, v1total, v2total, v3total, v1min, v1max, v2min, v2max, v3min, v3max; Complex value=new Complex(), z=new Complex(); trio_height=Ratio_matrix[0].Length; for(;p_aoh.abciss<p_aoh.end_of_abciss;p_aoh.abciss++) { abciss_point = abciss_points[p_aoh.abciss]; trio_matrix[p_aoh.abciss] = new double[trio_height][]; for(;p_aoh.ordinate<p_aoh.end_of_ordinate;p_aoh.ordinate++) { z.Real=abciss_point; z.Imagine = ordinate_points[p_aoh.ordinate]; //z0 = z.getclone(); v1 = v2 = v3 = v1total = v1max = v1min = v2total = v2max = v2min = v3total = v3max = v3min = 0D; ratio = (z.Real * z.Real + z.Imagine * z.Imagine); lratio = 0; for(iterations=0;iterations<f_iterations_count&&ratio<400D;iterations++) { lratio = ratio; z = Complex.SSin(z); z.Real += _P.Real; z.Imagine += _P.Imagine; value = Complex.Sec(z); ratio = z.Real*z.Real+z.Imagine*z.Imagine; if (double.IsNaN(value.Real) || double.IsNaN(value.Imagine)) { v1 = v2 = v3 = 0; } else{v1 = value.abs; v2 = value.sqr().abs; v3 = value.Pow(3).abs; v1total += v1; v2total += v2; v3total += v3; if (v1 < v1min) v1min = v1; else if (v1 > v1max) v1max = v1; if (v2 < v2min) v2min = v2; else if (v2 > v2max) v2max = v2; if (v3 < v3min) v3min = v3; else if (v3 > v3max) v3max = v3;} } //$r = (($v1total / $count) - $v1min) / ($v1max - $v1min); Ratio_matrix[p_aoh.abciss][p_aoh.ordinate] = lratio; if (iterations > 0) { trio_matrix[p_aoh.abciss][p_aoh.ordinate] = new double[] {((v1total/(double)iterations)-v1min)/(v1max-v1min), ((v2total/(double)iterations)-v2min)/(v2max-v2min), ((v3total/(double)iterations)-v3min)/(v3max-v3min)}; } else trio_matrix[p_aoh.abciss][p_aoh.ordinate] = new double[3]; iter_matrix[p_aoh.abciss][p_aoh.ordinate] = iterations; } p_aoh.ordinate = 0; if((--current_percent)==0) { current_percent = percent_length; f_new_percent_in_parallel_activate(); } } }
protected override _2DFractalHelper m_old_create_fractal_double_version(int width, int height) { ulong iter_count = f_iterations_count, iteration; _2DFractalHelper fractal_helper = new _2DFractalHelper(this, width, height); AbcissOrdinateHandler aoh = fractal_helper.AOH; ulong[][] matrix = fractal_helper.CommonMatrix; double[] abciss_points = fractal_helper.AbcissRealValues, ordinate_points = fractal_helper.OrdinateRealValues; double abciss_point,abciss_interval_length=_2df_get_double_abciss_interval_length(),ordinate_interval_length=_2df_get_double_ordinate_interval_length(), abciss_start=_2df_get_double_abciss_start(),ordinate_start=_2df_get_double_ordinate_start(); int percent_length = fractal_helper.PercentLength, current_percent = percent_length; Complex z = new Complex(), z0 = new Complex(); int fcp_width = width / _abciss_step_length + (width % _abciss_step_length!=0?1:0), fcp_height = height / _ordinate_step_length+(height%_ordinate_step_length!=0?1:0); FractalCloudPoint[][][] fcp=new FractalCloudPoint[fcp_width][][]; List<FractalCloudPoint> fcp_list = new List<FractalCloudPoint>(); FractalCloudPoint cfcp; for (; aoh.abciss < width; aoh.abciss++) { abciss_point = abciss_points[aoh.abciss]; if ((aoh.abciss % _abciss_step_length) == 0) fcp[aoh.abciss / _abciss_step_length] = new FractalCloudPoint[fcp_height][]; for (aoh.ordinate = 0; aoh.ordinate < height; aoh.ordinate++) { z0.Real = abciss_point; z0.Imagine = ordinate_points[aoh.ordinate]; z.Real = z0.Real; z.Imagine = z0.Imagine; iteration = 0; if ((aoh.abciss % _abciss_step_length) == 0 && (aoh.ordinate % _ordinate_step_length) == 0) { fcp_list.Clear(); for (; iteration < (ulong)_max_ammount_at_trace && (z.Real * z.Real + z.Imagine * z.Imagine) < _max_sqr_radius; iteration++) { z.tsqr(); z.Real += z0.Real; z.Imagine += z0.Imagine; cfcp = new FractalCloudPoint(); cfcp.AbcissLocation=(int)((z.Real-abciss_start)/abciss_interval_length); cfcp.OrdinateLocation=(int)((z.Imagine-ordinate_start)/ordinate_interval_length); fcp_list.Add(cfcp); } fcp[aoh.abciss / _abciss_step_length][aoh.ordinate / _ordinate_step_length] = fcp_list.ToArray(); } for (; iteration < iter_count && (z.Real * z.Real + z.Imagine * z.Imagine) < 4D; iteration++) { z.tsqr(); z.Real += z0.Real; z.Imagine += z0.Imagine; } matrix[aoh.abciss][aoh.ordinate] = iteration; } if ((--current_percent) == 0) { current_percent = percent_length; f_new_percent_in_parallel_activate(); } } fractal_helper.GiveUnique(new FractalCloudPoints(_max_ammount_at_trace,fcp)); return fractal_helper; }
unsafe protected override void _j_create_part_of_fractal(AbcissOrdinateHandler p_aoh, _2DFractalHelper fractal_helper) { ulong max_iterations = f_iterations_count, iterations; ulong[][] result_matrix = fractal_helper.CommonMatrix; int percent_length = fractal_helper.PercentLength, percent_counter = percent_length, height; double dist, pdist = 0D, sqr, abciss_interval_length = _2df_get_double_abciss_interval_length(), ordinate_interval_length = _2df_get_double_ordinate_interval_length(), abciss_start = _2df_get_double_abciss_start(), ordinate_start = _2df_get_double_ordinate_start(); double[][] ratio_matrix = fractal_helper.GetRatioMatrix(); Complex complex_iterator = new Complex(), last_valid_complex = new Complex(); double[][] radiad_matrix = ((RadianMatrix)fractal_helper.GetUnique(typeof(RadianMatrix))).Matrix; height = fractal_helper.Height; int fcp_height = height / _ordinate_step_length + (height % _ordinate_step_length != 0 ? 1 : 0); FractalCloudPoint[][][] fcp_matrix = ((FractalCloudPoints)fractal_helper.GetUnique(typeof(FractalCloudPoints))).fractalCloudPoint; List <FractalCloudPoint> fcp_list = new List <FractalCloudPoint>(); FractalCloudPoint fcp; double *abciss_point, ordinate_point = fractal_helper.OrdinateRealPointer; abciss_point = fractal_helper.AbscissPointer + (p_aoh.abciss - 1); for (; p_aoh.abciss < p_aoh.end_of_abciss; ++p_aoh.abciss) { ++abciss_point; radiad_matrix[p_aoh.abciss] = new double[height]; if (p_aoh.abciss % _abciss_step_length == 0) { fcp_matrix[p_aoh.abciss / _abciss_step_length] = new FractalCloudPoint[fcp_height][]; } for (; p_aoh.ordinate < p_aoh.end_of_ordinate; ++p_aoh.ordinate) { complex_iterator.Real = *abciss_point; complex_iterator.Imagine = *(ordinate_point++); dist = 0D; iterations = 0; if (((p_aoh.abciss % _abciss_step_length) == 0) && ((p_aoh.ordinate % _ordinate_step_length) == 0)) { fcp_list.Clear(); for (; dist < 4D && iterations <= (ulong)_max_ammount_at_trace; ++iterations) { pdist = dist; last_valid_complex.Real = complex_iterator.Real; last_valid_complex.Imagine = complex_iterator.Imagine; sqr = complex_iterator.Real * 2; complex_iterator.Real = complex_iterator.Real * complex_iterator.Real - complex_iterator.Imagine * complex_iterator.Imagine; complex_iterator.Imagine *= sqr; complex_iterator.Real += j_complex_const.Real; complex_iterator.Imagine += j_complex_const.Imagine; dist = (complex_iterator.Real * complex_iterator.Real + complex_iterator.Imagine * complex_iterator.Imagine); fcp.AbcissLocation = (int)((complex_iterator.Real - abciss_start) / abciss_interval_length); fcp.OrdinateLocation = (int)((complex_iterator.Imagine - ordinate_start) / ordinate_interval_length); fcp_list.Add(fcp); } fcp_matrix[p_aoh.abciss / _abciss_step_length][p_aoh.ordinate / _ordinate_step_length] = fcp_list.ToArray(); } for (; dist < 4D && iterations < max_iterations; ++iterations) { pdist = dist; last_valid_complex.Real = complex_iterator.Real; last_valid_complex.Imagine = complex_iterator.Imagine; sqr = complex_iterator.Real * 2; complex_iterator.Real = complex_iterator.Real * complex_iterator.Real - complex_iterator.Imagine * complex_iterator.Imagine; complex_iterator.Imagine *= sqr; complex_iterator.Real += j_complex_const.Real; complex_iterator.Imagine += j_complex_const.Imagine; dist = (complex_iterator.Real * complex_iterator.Real + complex_iterator.Imagine * complex_iterator.Imagine); } result_matrix[p_aoh.abciss][p_aoh.ordinate] = iterations; ratio_matrix[p_aoh.abciss][p_aoh.ordinate] = pdist; radiad_matrix[p_aoh.abciss][p_aoh.ordinate] = Math.Atan2(last_valid_complex.Imagine, last_valid_complex.Real); } ordinate_point -= height; p_aoh.ordinate = 0; if ((--percent_counter) == 0) { percent_counter = percent_length; f_new_percent_in_parallel_activate(); } } }
protected virtual void _j_create_part_of_fractal(AbcissOrdinateHandler p_aoh, _2DFractalHelper fractal_helper) { ulong max_iterations = f_iterations_count, iterations; ulong[][] result_matrix = fractal_helper.CommonMatrix; int percent_length = fractal_helper.PercentLength, percent_counter = percent_length, height; double[] abciss_points = fractal_helper.AbcissRealValues, ordinate_points = fractal_helper.OrdinateRealValues; double abciss_point, dist, pdist = 0D, sqr; double[][] ratio_matrix = (double[][])fractal_helper.GetRatioMatrix(); Complex complex_iterator = new Complex(), last_valid_complex = new Complex(); double[][] radiad_matrix = ((RadianMatrix)fractal_helper.GetUnique(typeof(RadianMatrix))).Matrix; height = ordinate_points.Length; for (; p_aoh.abciss < p_aoh.end_of_abciss; ++p_aoh.abciss) { abciss_point = abciss_points[p_aoh.abciss]; radiad_matrix[p_aoh.abciss] = new double[height]; for (; p_aoh.ordinate < p_aoh.end_of_ordinate; ++p_aoh.ordinate) { complex_iterator.Real = abciss_point; complex_iterator.Imagine = ordinate_points[p_aoh.ordinate]; dist = 0D; for (iterations = 0; dist < 4D && iterations < max_iterations; ++iterations) { pdist = dist; last_valid_complex.Real = complex_iterator.Real; last_valid_complex.Imagine = complex_iterator.Imagine; sqr = complex_iterator.Real * 2; complex_iterator.Real = complex_iterator.Real * complex_iterator.Real - complex_iterator.Imagine * complex_iterator.Imagine; complex_iterator.Imagine *= sqr; complex_iterator.Real += j_complex_const.Real; complex_iterator.Imagine += j_complex_const.Imagine; dist = (complex_iterator.Real * complex_iterator.Real + complex_iterator.Imagine * complex_iterator.Imagine); } result_matrix[p_aoh.abciss][p_aoh.ordinate] = iterations; ratio_matrix[p_aoh.abciss][p_aoh.ordinate] = pdist; radiad_matrix[p_aoh.abciss][p_aoh.ordinate] = Math.Atan2(last_valid_complex.Imagine, last_valid_complex.Real); } p_aoh.ordinate = 0; if ((--percent_counter) == 0) { percent_counter = percent_length; f_new_percent_in_parallel_activate(); } } }
private void Create_part_of_fractal(_2DFractalHelper fractal_helper, AbcissOrdinateHandler p_aoh) { ulong iterations; int percent_length = fractal_helper.PercentLength, current_percent = percent_length, trio_height; ulong[][] iter_matrix = fractal_helper.CommonMatrix; double[] abciss_points = fractal_helper.AbcissRealValues, ordinate_points = fractal_helper.OrdinateRealValues; double abciss_point, ratio, lratio; double[][] Ratio_matrix = fractal_helper.GetRatioMatrix(); double[][][] trio_matrix = (double[][][])fractal_helper.GetUnique(typeof(double[][][])); double v1, v2, v3, v1total, v2total, v3total, v1min, v1max, v2min, v2max, v3min, v3max; Complex value = new Complex(), z = new Complex(); trio_height = Ratio_matrix[0].Length; for (; p_aoh.abciss < p_aoh.end_of_abciss; p_aoh.abciss++) { abciss_point = abciss_points[p_aoh.abciss]; trio_matrix[p_aoh.abciss] = new double[trio_height][]; for (; p_aoh.ordinate < p_aoh.end_of_ordinate; p_aoh.ordinate++) { z.Real = abciss_point; z.Imagine = ordinate_points[p_aoh.ordinate]; //z0 = z.getclone(); v1 = v2 = v3 = v1total = v1max = v1min = v2total = v2max = v2min = v3total = v3max = v3min = 0D; ratio = (z.Real * z.Real + z.Imagine * z.Imagine); lratio = 0; for (iterations = 0; iterations < f_iterations_count && ratio < 400D; iterations++) { lratio = ratio; z = Complex.SSin(z); z.Real += _P.Real; z.Imagine += _P.Imagine; value = Complex.Sec(z); ratio = z.Real * z.Real + z.Imagine * z.Imagine; if (double.IsNaN(value.Real) || double.IsNaN(value.Imagine)) { v1 = v2 = v3 = 0; } else { v1 = value.abs; v2 = value.sqr().abs; v3 = value.Pow(3).abs; v1total += v1; v2total += v2; v3total += v3; if (v1 < v1min) { v1min = v1; } else if (v1 > v1max) { v1max = v1; } if (v2 < v2min) { v2min = v2; } else if (v2 > v2max) { v2max = v2; } if (v3 < v3min) { v3min = v3; } else if (v3 > v3max) { v3max = v3; } } } //$r = (($v1total / $count) - $v1min) / ($v1max - $v1min); Ratio_matrix[p_aoh.abciss][p_aoh.ordinate] = lratio; if (iterations > 0) { trio_matrix[p_aoh.abciss][p_aoh.ordinate] = new double[] { ((v1total / (double)iterations) - v1min) / (v1max - v1min), ((v2total / (double)iterations) - v2min) / (v2max - v2min), ((v3total / (double)iterations) - v3min) / (v3max - v3min) }; } else { trio_matrix[p_aoh.abciss][p_aoh.ordinate] = new double[3]; } iter_matrix[p_aoh.abciss][p_aoh.ordinate] = iterations; } p_aoh.ordinate = 0; if ((--current_percent) == 0) { current_percent = percent_length; f_new_percent_in_parallel_activate(); } } }
protected virtual _2DFractalHelper inc_create_fractal(int width,int height) { _2DFractalHelper fractal_helper = new _2DFractalHelper(this, width, height); Action<object> act = (abc) => { inc_create_part_of_fractal((AbcissOrdinateHandler)abc, fractal_helper); }; AbcissOrdinateHandler[] p_aoh = fractal_helper.CreateDataForParallelWork(f_number_of_using_threads_for_parallel); Task[] ts = new Task[f_number_of_using_threads_for_parallel]; fractal_helper.GiveUnique(new RadianMatrix(width)); for (int i = 0; i < ts.Length; i++) { ts[i] = new Task(act, p_aoh[i]); ts[i].Start(); } for (int i = 0; i < ts.Length; i++) { ts[i].Wait(); } return fractal_helper; }
protected virtual void inc_create_part_of_fractal(AbcissOrdinateHandler p_aoh,_2DFractalHelper fractal_helper) { ulong iter_count = f_iterations_count, iteration; ulong[][] matrix = fractal_helper.CommonMatrix; double[] abciss_points = fractal_helper.AbcissRealValues, ordinate_points = fractal_helper.OrdinateRealValues; double abciss_point, dist, pdist = 0D; double[][] Ratio_matrix = (double[][])fractal_helper.GetRatioMatrix(); int percent_length = fractal_helper.PercentLength, current_percent = percent_length; double[][] Radian_matrix = ((RadianMatrix)fractal_helper.GetUnique(typeof(RadianMatrix))).Matrix; int height = ordinate_points.Length; double cosrad = Math.Cos(inc_rotater.Radian),sinrad=Math.Sin(inc_rotater.Radian); Triplex z=new Triplex(), z0=(Triplex)inc_const.Clone(),last_valid_z=new Triplex(); inc_rotater.Rotate(z0); for (; p_aoh.abciss < p_aoh.end_of_abciss; p_aoh.abciss++) { abciss_point = abciss_points[p_aoh.abciss]; Radian_matrix[p_aoh.abciss] = new double[height]; for (; p_aoh.ordinate < p_aoh.end_of_ordinate; ++p_aoh.ordinate) { z.x = abciss_point; z.y = ordinate_points[p_aoh.ordinate]; z.z =0; inc_rotater.Rotate(z); dist = 0D; for (iteration = 0; iteration < iter_count && dist < 4D; iteration++) { pdist = dist; last_valid_z.x = z.x; last_valid_z.y = z.y; last_valid_z.z = z.z; z.tsqr(); z.tadd(z0); dist = (z.x * z.x + z.y * z.y + z.z * z.z); } Ratio_matrix[p_aoh.abciss][p_aoh.ordinate] = pdist; matrix[p_aoh.abciss][p_aoh.ordinate] = iteration; Radian_matrix[p_aoh.abciss][p_aoh.ordinate] = Math.Atan2(last_valid_z.y, last_valid_z.x) * cosrad + sinrad * Math.Atan2(last_valid_z.z, last_valid_z.x); } p_aoh.ordinate = 0; if ((--current_percent) == 0) { current_percent = percent_length; f_new_percent_in_parallel_activate(); } } }
protected unsafe override void _j_create_part_of_fractal(AbcissOrdinateHandler p_aoh, _2DFractalHelper fractal_helper) { ulong max_iterations = f_iterations_count, iterations; ulong[][] result_matrix = fractal_helper.CommonMatrix; int percent_length = fractal_helper.PercentLength, percent_counter = percent_length, height; double dist, pdist = 0D, sqr,abciss_interval_length=_2df_get_double_abciss_interval_length(), ordinate_interval_length=_2df_get_double_ordinate_interval_length(),abciss_start=_2df_get_double_abciss_start(), ordinate_start=_2df_get_double_ordinate_start(); double[][] ratio_matrix = fractal_helper.GetRatioMatrix(); Complex complex_iterator = new Complex(), last_valid_complex = new Complex(); double[][] radiad_matrix = ((RadianMatrix)fractal_helper.GetUnique(typeof(RadianMatrix))).Matrix; height = fractal_helper.Height; int fcp_height=height / _ordinate_step_length + (height % _ordinate_step_length != 0 ? 1 : 0); FractalCloudPoint[][][] fcp_matrix = ((FractalCloudPoints)fractal_helper.GetUnique(typeof(FractalCloudPoints))).fractalCloudPoint; List<FractalCloudPoint> fcp_list = new List<FractalCloudPoint>(); FractalCloudPoint fcp; double* abciss_point,ordinate_point= fractal_helper.OrdinateRealPointer; abciss_point = fractal_helper.AbscissPointer + (p_aoh.abciss - 1); for (; p_aoh.abciss < p_aoh.end_of_abciss; ++p_aoh.abciss) { ++abciss_point; radiad_matrix[p_aoh.abciss] = new double[height]; if (p_aoh.abciss % _abciss_step_length == 0) fcp_matrix[p_aoh.abciss / _abciss_step_length] = new FractalCloudPoint[fcp_height][]; for (; p_aoh.ordinate < p_aoh.end_of_ordinate; ++p_aoh.ordinate) { complex_iterator.Real = *abciss_point; complex_iterator.Imagine = *(ordinate_point++); dist = 0D; iterations = 0; if (((p_aoh.abciss % _abciss_step_length) == 0) && ((p_aoh.ordinate % _ordinate_step_length) == 0)) { fcp_list.Clear(); for (; dist < 4D && iterations <= (ulong)_max_ammount_at_trace; ++iterations) { pdist = dist; last_valid_complex.Real = complex_iterator.Real; last_valid_complex.Imagine = complex_iterator.Imagine; sqr = complex_iterator.Real * 2; complex_iterator.Real = complex_iterator.Real * complex_iterator.Real - complex_iterator.Imagine * complex_iterator.Imagine; complex_iterator.Imagine *= sqr; complex_iterator.Real += j_complex_const.Real; complex_iterator.Imagine += j_complex_const.Imagine; dist = (complex_iterator.Real * complex_iterator.Real + complex_iterator.Imagine * complex_iterator.Imagine); fcp.AbcissLocation=(int)((complex_iterator.Real-abciss_start)/abciss_interval_length); fcp.OrdinateLocation = (int)((complex_iterator.Imagine - ordinate_start) / ordinate_interval_length); fcp_list.Add(fcp); } fcp_matrix[p_aoh.abciss / _abciss_step_length][p_aoh.ordinate / _ordinate_step_length] = fcp_list.ToArray(); } for (; dist < 4D && iterations < max_iterations; ++iterations) { pdist = dist; last_valid_complex.Real = complex_iterator.Real; last_valid_complex.Imagine = complex_iterator.Imagine; sqr = complex_iterator.Real * 2; complex_iterator.Real = complex_iterator.Real * complex_iterator.Real - complex_iterator.Imagine * complex_iterator.Imagine; complex_iterator.Imagine *= sqr; complex_iterator.Real += j_complex_const.Real; complex_iterator.Imagine += j_complex_const.Imagine; dist = (complex_iterator.Real * complex_iterator.Real + complex_iterator.Imagine * complex_iterator.Imagine); } result_matrix[p_aoh.abciss][p_aoh.ordinate] = iterations; ratio_matrix[p_aoh.abciss][p_aoh.ordinate] = pdist; radiad_matrix[p_aoh.abciss][p_aoh.ordinate] = Math.Atan2(last_valid_complex.Imagine, last_valid_complex.Real); } ordinate_point -= height; p_aoh.ordinate = 0; if ((--percent_counter) == 0) { percent_counter = percent_length; f_new_percent_in_parallel_activate(); } } }
/*_______________________________________________Перегруженные_методы_класса________________________________________________________________*/ #region Override methods protected override _2DFractalHelper m_old_create_fractal_double_version(int width, int height) { ulong iter_count = f_iterations_count, iteration; _2DFractalHelper fractal_helper = new _2DFractalHelper(this, width, height); AbcissOrdinateHandler aoh = fractal_helper.AOH; ulong[][] matrix = fractal_helper.CommonMatrix; double[] abciss_points = fractal_helper.AbcissRealValues, ordinate_points = fractal_helper.OrdinateRealValues; double abciss_point, abciss_interval_length = _2df_get_double_abciss_interval_length(), ordinate_interval_length = _2df_get_double_ordinate_interval_length(), abciss_start = _2df_get_double_abciss_start(), ordinate_start = _2df_get_double_ordinate_start(); int percent_length = fractal_helper.PercentLength, current_percent = percent_length; Complex z = new Complex(), z0 = new Complex(); int fcp_width = width / _abciss_step_length + (width % _abciss_step_length != 0?1:0), fcp_height = height / _ordinate_step_length + (height % _ordinate_step_length != 0?1:0); FractalCloudPoint[][][] fcp = new FractalCloudPoint[fcp_width][][]; List <FractalCloudPoint> fcp_list = new List <FractalCloudPoint>(); FractalCloudPoint cfcp; for (; aoh.abciss < width; aoh.abciss++) { abciss_point = abciss_points[aoh.abciss]; if ((aoh.abciss % _abciss_step_length) == 0) { fcp[aoh.abciss / _abciss_step_length] = new FractalCloudPoint[fcp_height][]; } for (aoh.ordinate = 0; aoh.ordinate < height; aoh.ordinate++) { z0.Real = abciss_point; z0.Imagine = ordinate_points[aoh.ordinate]; z.Real = z0.Real; z.Imagine = z0.Imagine; iteration = 0; if ((aoh.abciss % _abciss_step_length) == 0 && (aoh.ordinate % _ordinate_step_length) == 0) { fcp_list.Clear(); for (; iteration < (ulong)_max_ammount_at_trace && (z.Real * z.Real + z.Imagine * z.Imagine) < _max_sqr_radius; iteration++) { z.tsqr(); z.Real += z0.Real; z.Imagine += z0.Imagine; cfcp = new FractalCloudPoint(); cfcp.AbcissLocation = (int)((z.Real - abciss_start) / abciss_interval_length); cfcp.OrdinateLocation = (int)((z.Imagine - ordinate_start) / ordinate_interval_length); fcp_list.Add(cfcp); } fcp[aoh.abciss / _abciss_step_length][aoh.ordinate / _ordinate_step_length] = fcp_list.ToArray(); } for (; iteration < iter_count && (z.Real * z.Real + z.Imagine * z.Imagine) < 4D; iteration++) { z.tsqr(); z.Real += z0.Real; z.Imagine += z0.Imagine; } matrix[aoh.abciss][aoh.ordinate] = iteration; } if ((--current_percent) == 0) { current_percent = percent_length; f_new_percent_in_parallel_activate(); } } fractal_helper.GiveUnique(new FractalCloudPoints(_max_ammount_at_trace, fcp)); return(fractal_helper); }